1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03,04
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
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
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Margin around tool bar buttons in pixels. */
269 Lisp_Object Vtool_bar_button_margin
;
271 /* Thickness of shadow to draw around tool bar buttons. */
273 EMACS_INT tool_bar_button_relief
;
275 /* Non-zero means automatically resize tool-bars so that all tool-bar
276 items are visible, and no blank lines remain. */
278 int auto_resize_tool_bars_p
;
280 /* Non-zero means draw block and hollow cursor as wide as the glyph
281 under it. For example, if a block cursor is over a tab, it will be
282 drawn as wide as that tab on the display. */
284 int x_stretch_cursor_p
;
286 /* Non-nil means don't actually do any redisplay. */
288 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
290 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
292 int inhibit_eval_during_redisplay
;
294 /* Names of text properties relevant for redisplay. */
296 Lisp_Object Qdisplay
;
297 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
299 /* Symbols used in text property values. */
301 Lisp_Object Vdisplay_pixels_per_inch
;
302 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
303 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
304 Lisp_Object Qmargin
, Qpointer
;
305 extern Lisp_Object Qheight
;
306 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
307 extern Lisp_Object Qscroll_bar
;
309 /* Non-nil means highlight trailing whitespace. */
311 Lisp_Object Vshow_trailing_whitespace
;
313 #ifdef HAVE_WINDOW_SYSTEM
314 extern Lisp_Object Voverflow_newline_into_fringe
;
316 /* Test if overflow newline into fringe. Called with iterator IT
317 at or past right window margin, and with IT->current_x set. */
319 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
320 (!NILP (Voverflow_newline_into_fringe) \
321 && FRAME_WINDOW_P (it->f) \
322 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
323 && it->current_x == it->last_visible_x)
325 #endif /* HAVE_WINDOW_SYSTEM */
327 /* Non-nil means show the text cursor in void text areas
328 i.e. in blank areas after eol and eob. This used to be
329 the default in 21.3. */
331 Lisp_Object Vvoid_text_area_pointer
;
333 /* Name of the face used to highlight trailing whitespace. */
335 Lisp_Object Qtrailing_whitespace
;
337 /* The symbol `image' which is the car of the lists used to represent
342 /* The image map types. */
343 Lisp_Object QCmap
, QCpointer
;
344 Lisp_Object Qrect
, Qcircle
, Qpoly
;
346 /* Non-zero means print newline to stdout before next mini-buffer
349 int noninteractive_need_newline
;
351 /* Non-zero means print newline to message log before next message. */
353 static int message_log_need_newline
;
355 /* Three markers that message_dolog uses.
356 It could allocate them itself, but that causes trouble
357 in handling memory-full errors. */
358 static Lisp_Object message_dolog_marker1
;
359 static Lisp_Object message_dolog_marker2
;
360 static Lisp_Object message_dolog_marker3
;
362 /* The buffer position of the first character appearing entirely or
363 partially on the line of the selected window which contains the
364 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
365 redisplay optimization in redisplay_internal. */
367 static struct text_pos this_line_start_pos
;
369 /* Number of characters past the end of the line above, including the
370 terminating newline. */
372 static struct text_pos this_line_end_pos
;
374 /* The vertical positions and the height of this line. */
376 static int this_line_vpos
;
377 static int this_line_y
;
378 static int this_line_pixel_height
;
380 /* X position at which this display line starts. Usually zero;
381 negative if first character is partially visible. */
383 static int this_line_start_x
;
385 /* Buffer that this_line_.* variables are referring to. */
387 static struct buffer
*this_line_buffer
;
389 /* Nonzero means truncate lines in all windows less wide than the
392 int truncate_partial_width_windows
;
394 /* A flag to control how to display unibyte 8-bit character. */
396 int unibyte_display_via_language_environment
;
398 /* Nonzero means we have more than one non-mini-buffer-only frame.
399 Not guaranteed to be accurate except while parsing
400 frame-title-format. */
404 Lisp_Object Vglobal_mode_string
;
407 /* List of variables (symbols) which hold markers for overlay arrows.
408 The symbols on this list are examined during redisplay to determine
409 where to display overlay arrows. */
411 Lisp_Object Voverlay_arrow_variable_list
;
413 /* Marker for where to display an arrow on top of the buffer text. */
415 Lisp_Object Voverlay_arrow_position
;
417 /* String to display for the arrow. Only used on terminal frames. */
419 Lisp_Object Voverlay_arrow_string
;
421 /* Values of those variables at last redisplay are stored as
422 properties on `overlay-arrow-position' symbol. However, if
423 Voverlay_arrow_position is a marker, last-arrow-position is its
424 numerical position. */
426 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
428 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
429 properties on a symbol in overlay-arrow-variable-list. */
431 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
433 /* Like mode-line-format, but for the title bar on a visible frame. */
435 Lisp_Object Vframe_title_format
;
437 /* Like mode-line-format, but for the title bar on an iconified frame. */
439 Lisp_Object Vicon_title_format
;
441 /* List of functions to call when a window's size changes. These
442 functions get one arg, a frame on which one or more windows' sizes
445 static Lisp_Object Vwindow_size_change_functions
;
447 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
449 /* Nonzero if overlay arrow has been displayed once in this window. */
451 static int overlay_arrow_seen
;
453 /* Nonzero means highlight the region even in nonselected windows. */
455 int highlight_nonselected_windows
;
457 /* If cursor motion alone moves point off frame, try scrolling this
458 many lines up or down if that will bring it back. */
460 static EMACS_INT scroll_step
;
462 /* Nonzero means scroll just far enough to bring point back on the
463 screen, when appropriate. */
465 static EMACS_INT scroll_conservatively
;
467 /* Recenter the window whenever point gets within this many lines of
468 the top or bottom of the window. This value is translated into a
469 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
470 that there is really a fixed pixel height scroll margin. */
472 EMACS_INT scroll_margin
;
474 /* Number of windows showing the buffer of the selected window (or
475 another buffer with the same base buffer). keyboard.c refers to
480 /* Vector containing glyphs for an ellipsis `...'. */
482 static Lisp_Object default_invis_vector
[3];
484 /* Zero means display the mode-line/header-line/menu-bar in the default face
485 (this slightly odd definition is for compatibility with previous versions
486 of emacs), non-zero means display them using their respective faces.
488 This variable is deprecated. */
490 int mode_line_inverse_video
;
492 /* Prompt to display in front of the mini-buffer contents. */
494 Lisp_Object minibuf_prompt
;
496 /* Width of current mini-buffer prompt. Only set after display_line
497 of the line that contains the prompt. */
499 int minibuf_prompt_width
;
501 /* This is the window where the echo area message was displayed. It
502 is always a mini-buffer window, but it may not be the same window
503 currently active as a mini-buffer. */
505 Lisp_Object echo_area_window
;
507 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
508 pushes the current message and the value of
509 message_enable_multibyte on the stack, the function restore_message
510 pops the stack and displays MESSAGE again. */
512 Lisp_Object Vmessage_stack
;
514 /* Nonzero means multibyte characters were enabled when the echo area
515 message was specified. */
517 int message_enable_multibyte
;
519 /* Nonzero if we should redraw the mode lines on the next redisplay. */
521 int update_mode_lines
;
523 /* Nonzero if window sizes or contents have changed since last
524 redisplay that finished. */
526 int windows_or_buffers_changed
;
528 /* Nonzero means a frame's cursor type has been changed. */
530 int cursor_type_changed
;
532 /* Nonzero after display_mode_line if %l was used and it displayed a
535 int line_number_displayed
;
537 /* Maximum buffer size for which to display line numbers. */
539 Lisp_Object Vline_number_display_limit
;
541 /* Line width to consider when repositioning for line number display. */
543 static EMACS_INT line_number_display_limit_width
;
545 /* Number of lines to keep in the message log buffer. t means
546 infinite. nil means don't log at all. */
548 Lisp_Object Vmessage_log_max
;
550 /* The name of the *Messages* buffer, a string. */
552 static Lisp_Object Vmessages_buffer_name
;
554 /* Current, index 0, and last displayed echo area message. Either
555 buffers from echo_buffers, or nil to indicate no message. */
557 Lisp_Object echo_area_buffer
[2];
559 /* The buffers referenced from echo_area_buffer. */
561 static Lisp_Object echo_buffer
[2];
563 /* A vector saved used in with_area_buffer to reduce consing. */
565 static Lisp_Object Vwith_echo_area_save_vector
;
567 /* Non-zero means display_echo_area should display the last echo area
568 message again. Set by redisplay_preserve_echo_area. */
570 static int display_last_displayed_message_p
;
572 /* Nonzero if echo area is being used by print; zero if being used by
575 int message_buf_print
;
577 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
579 Lisp_Object Qinhibit_menubar_update
;
580 int inhibit_menubar_update
;
582 /* Maximum height for resizing mini-windows. Either a float
583 specifying a fraction of the available height, or an integer
584 specifying a number of lines. */
586 Lisp_Object Vmax_mini_window_height
;
588 /* Non-zero means messages should be displayed with truncated
589 lines instead of being continued. */
591 int message_truncate_lines
;
592 Lisp_Object Qmessage_truncate_lines
;
594 /* Set to 1 in clear_message to make redisplay_internal aware
595 of an emptied echo area. */
597 static int message_cleared_p
;
599 /* Non-zero means we want a hollow cursor in windows that are not
600 selected. Zero means there's no cursor in such windows. */
602 Lisp_Object Vcursor_in_non_selected_windows
;
603 Lisp_Object Qcursor_in_non_selected_windows
;
605 /* How to blink the default frame cursor off. */
606 Lisp_Object Vblink_cursor_alist
;
608 /* A scratch glyph row with contents used for generating truncation
609 glyphs. Also used in direct_output_for_insert. */
611 #define MAX_SCRATCH_GLYPHS 100
612 struct glyph_row scratch_glyph_row
;
613 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
615 /* Ascent and height of the last line processed by move_it_to. */
617 static int last_max_ascent
, last_height
;
619 /* Non-zero if there's a help-echo in the echo area. */
621 int help_echo_showing_p
;
623 /* If >= 0, computed, exact values of mode-line and header-line height
624 to use in the macros CURRENT_MODE_LINE_HEIGHT and
625 CURRENT_HEADER_LINE_HEIGHT. */
627 int current_mode_line_height
, current_header_line_height
;
629 /* The maximum distance to look ahead for text properties. Values
630 that are too small let us call compute_char_face and similar
631 functions too often which is expensive. Values that are too large
632 let us call compute_char_face and alike too often because we
633 might not be interested in text properties that far away. */
635 #define TEXT_PROP_DISTANCE_LIMIT 100
639 /* Variables to turn off display optimizations from Lisp. */
641 int inhibit_try_window_id
, inhibit_try_window_reusing
;
642 int inhibit_try_cursor_movement
;
644 /* Non-zero means print traces of redisplay if compiled with
647 int trace_redisplay_p
;
649 #endif /* GLYPH_DEBUG */
651 #ifdef DEBUG_TRACE_MOVE
652 /* Non-zero means trace with TRACE_MOVE to stderr. */
655 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
657 #define TRACE_MOVE(x) (void) 0
660 /* Non-zero means automatically scroll windows horizontally to make
663 int automatic_hscrolling_p
;
665 /* How close to the margin can point get before the window is scrolled
667 EMACS_INT hscroll_margin
;
669 /* How much to scroll horizontally when point is inside the above margin. */
670 Lisp_Object Vhscroll_step
;
672 /* A list of symbols, one for each supported image type. */
674 Lisp_Object Vimage_types
;
676 /* The variable `resize-mini-windows'. If nil, don't resize
677 mini-windows. If t, always resize them to fit the text they
678 display. If `grow-only', let mini-windows grow only until they
681 Lisp_Object Vresize_mini_windows
;
683 /* Buffer being redisplayed -- for redisplay_window_error. */
685 struct buffer
*displayed_buffer
;
687 /* Value returned from text property handlers (see below). */
692 HANDLED_RECOMPUTE_PROPS
,
693 HANDLED_OVERLAY_STRING_CONSUMED
,
697 /* A description of text properties that redisplay is interested
702 /* The name of the property. */
705 /* A unique index for the property. */
708 /* A handler function called to set up iterator IT from the property
709 at IT's current position. Value is used to steer handle_stop. */
710 enum prop_handled (*handler
) P_ ((struct it
*it
));
713 static enum prop_handled handle_face_prop
P_ ((struct it
*));
714 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
715 static enum prop_handled handle_display_prop
P_ ((struct it
*));
716 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
717 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
718 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
720 /* Properties handled by iterators. */
722 static struct props it_props
[] =
724 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
725 /* Handle `face' before `display' because some sub-properties of
726 `display' need to know the face. */
727 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
728 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
729 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
730 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
734 /* Value is the position described by X. If X is a marker, value is
735 the marker_position of X. Otherwise, value is X. */
737 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
739 /* Enumeration returned by some move_it_.* functions internally. */
743 /* Not used. Undefined value. */
746 /* Move ended at the requested buffer position or ZV. */
747 MOVE_POS_MATCH_OR_ZV
,
749 /* Move ended at the requested X pixel position. */
752 /* Move within a line ended at the end of a line that must be
756 /* Move within a line ended at the end of a line that would
757 be displayed truncated. */
760 /* Move within a line ended at a line end. */
764 /* This counter is used to clear the face cache every once in a while
765 in redisplay_internal. It is incremented for each redisplay.
766 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
769 #define CLEAR_FACE_CACHE_COUNT 500
770 static int clear_face_cache_count
;
772 /* Non-zero while redisplay_internal is in progress. */
776 /* Non-zero means don't free realized faces. Bound while freeing
777 realized faces is dangerous because glyph matrices might still
780 int inhibit_free_realized_faces
;
781 Lisp_Object Qinhibit_free_realized_faces
;
783 /* If a string, XTread_socket generates an event to display that string.
784 (The display is done in read_char.) */
786 Lisp_Object help_echo_string
;
787 Lisp_Object help_echo_window
;
788 Lisp_Object help_echo_object
;
791 /* Temporary variable for XTread_socket. */
793 Lisp_Object previous_help_echo_string
;
797 /* Function prototypes. */
799 static void setup_for_ellipsis
P_ ((struct it
*));
800 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
801 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
802 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
803 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
804 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
805 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
808 static int invisible_text_between_p
P_ ((struct it
*, int, int));
811 static int next_element_from_ellipsis
P_ ((struct it
*));
812 static void pint2str
P_ ((char *, int, int));
813 static void pint2hrstr
P_ ((char *, int, int));
814 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
816 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
817 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
818 static void store_frame_title_char
P_ ((char));
819 static int store_frame_title
P_ ((const unsigned char *, int, int));
820 static void x_consider_frame_title
P_ ((Lisp_Object
));
821 static void handle_stop
P_ ((struct it
*));
822 static int tool_bar_lines_needed
P_ ((struct frame
*));
823 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
824 static void ensure_echo_area_buffers
P_ ((void));
825 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
826 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
827 static int with_echo_area_buffer
P_ ((struct window
*, int,
828 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
829 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
830 static void clear_garbaged_frames
P_ ((void));
831 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
832 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
833 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
834 static int display_echo_area
P_ ((struct window
*));
835 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
836 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
837 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
838 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
839 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
841 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
842 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
843 static void insert_left_trunc_glyphs
P_ ((struct it
*));
844 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
846 static void extend_face_to_end_of_line
P_ ((struct it
*));
847 static int append_space
P_ ((struct it
*, int));
848 static int make_cursor_line_fully_visible
P_ ((struct window
*));
849 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
850 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
851 static int trailing_whitespace_p
P_ ((int));
852 static int message_log_check_duplicate
P_ ((int, int, int, int));
853 static void push_it
P_ ((struct it
*));
854 static void pop_it
P_ ((struct it
*));
855 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
856 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
857 static void redisplay_internal
P_ ((int));
858 static int echo_area_display
P_ ((int));
859 static void redisplay_windows
P_ ((Lisp_Object
));
860 static void redisplay_window
P_ ((Lisp_Object
, int));
861 static Lisp_Object
redisplay_window_error ();
862 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
863 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
864 static void update_menu_bar
P_ ((struct frame
*, int));
865 static int try_window_reusing_current_matrix
P_ ((struct window
*));
866 static int try_window_id
P_ ((struct window
*));
867 static int display_line
P_ ((struct it
*));
868 static int display_mode_lines
P_ ((struct window
*));
869 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
870 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
871 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
872 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
873 static void display_menu_bar
P_ ((struct window
*));
874 static int display_count_lines
P_ ((int, int, int, int, int *));
875 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
876 int, int, struct it
*, int, int, int, int));
877 static void compute_line_metrics
P_ ((struct it
*));
878 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
879 static int get_overlay_strings
P_ ((struct it
*, int));
880 static void next_overlay_string
P_ ((struct it
*));
881 static void reseat
P_ ((struct it
*, struct text_pos
, int));
882 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
883 static void back_to_previous_visible_line_start
P_ ((struct it
*));
884 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
885 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
886 static int next_element_from_display_vector
P_ ((struct it
*));
887 static int next_element_from_string
P_ ((struct it
*));
888 static int next_element_from_c_string
P_ ((struct it
*));
889 static int next_element_from_buffer
P_ ((struct it
*));
890 static int next_element_from_composition
P_ ((struct it
*));
891 static int next_element_from_image
P_ ((struct it
*));
892 static int next_element_from_stretch
P_ ((struct it
*));
893 static void load_overlay_strings
P_ ((struct it
*, int));
894 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
895 struct display_pos
*));
896 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
897 Lisp_Object
, int, int, int, int));
898 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
900 void move_it_vertically_backward
P_ ((struct it
*, int));
901 static void init_to_row_start
P_ ((struct it
*, struct window
*,
902 struct glyph_row
*));
903 static int init_to_row_end
P_ ((struct it
*, struct window
*,
904 struct glyph_row
*));
905 static void back_to_previous_line_start
P_ ((struct it
*));
906 static int forward_to_next_line_start
P_ ((struct it
*, int *));
907 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
909 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
910 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
911 static int number_of_chars
P_ ((unsigned char *, int));
912 static void compute_stop_pos
P_ ((struct it
*));
913 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
915 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
916 static int next_overlay_change
P_ ((int));
917 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
918 Lisp_Object
, struct text_pos
*,
920 static int underlying_face_id
P_ ((struct it
*));
921 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
924 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
925 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
927 #ifdef HAVE_WINDOW_SYSTEM
929 static void update_tool_bar
P_ ((struct frame
*, int));
930 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
931 static int redisplay_tool_bar
P_ ((struct frame
*));
932 static void display_tool_bar_line
P_ ((struct it
*));
933 static void notice_overwritten_cursor
P_ ((struct window
*,
935 int, int, int, int));
939 #endif /* HAVE_WINDOW_SYSTEM */
942 /***********************************************************************
943 Window display dimensions
944 ***********************************************************************/
946 /* Return the bottom boundary y-position for text lines in window W.
947 This is the first y position at which a line cannot start.
948 It is relative to the top of the window.
950 This is the height of W minus the height of a mode line, if any. */
953 window_text_bottom_y (w
)
956 int height
= WINDOW_TOTAL_HEIGHT (w
);
958 if (WINDOW_WANTS_MODELINE_P (w
))
959 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
963 /* Return the pixel width of display area AREA of window W. AREA < 0
964 means return the total width of W, not including fringes to
965 the left and right of the window. */
968 window_box_width (w
, area
)
972 int cols
= XFASTINT (w
->total_cols
);
975 if (!w
->pseudo_window_p
)
977 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
979 if (area
== TEXT_AREA
)
981 if (INTEGERP (w
->left_margin_cols
))
982 cols
-= XFASTINT (w
->left_margin_cols
);
983 if (INTEGERP (w
->right_margin_cols
))
984 cols
-= XFASTINT (w
->right_margin_cols
);
985 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
987 else if (area
== LEFT_MARGIN_AREA
)
989 cols
= (INTEGERP (w
->left_margin_cols
)
990 ? XFASTINT (w
->left_margin_cols
) : 0);
993 else if (area
== RIGHT_MARGIN_AREA
)
995 cols
= (INTEGERP (w
->right_margin_cols
)
996 ? XFASTINT (w
->right_margin_cols
) : 0);
1001 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1005 /* Return the pixel height of the display area of window W, not
1006 including mode lines of W, if any. */
1009 window_box_height (w
)
1012 struct frame
*f
= XFRAME (w
->frame
);
1013 int height
= WINDOW_TOTAL_HEIGHT (w
);
1015 xassert (height
>= 0);
1017 /* Note: the code below that determines the mode-line/header-line
1018 height is essentially the same as that contained in the macro
1019 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1020 the appropriate glyph row has its `mode_line_p' flag set,
1021 and if it doesn't, uses estimate_mode_line_height instead. */
1023 if (WINDOW_WANTS_MODELINE_P (w
))
1025 struct glyph_row
*ml_row
1026 = (w
->current_matrix
&& w
->current_matrix
->rows
1027 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1029 if (ml_row
&& ml_row
->mode_line_p
)
1030 height
-= ml_row
->height
;
1032 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1035 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1037 struct glyph_row
*hl_row
1038 = (w
->current_matrix
&& w
->current_matrix
->rows
1039 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1041 if (hl_row
&& hl_row
->mode_line_p
)
1042 height
-= hl_row
->height
;
1044 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1047 /* With a very small font and a mode-line that's taller than
1048 default, we might end up with a negative height. */
1049 return max (0, height
);
1052 /* Return the window-relative coordinate of the left edge of display
1053 area AREA of window W. AREA < 0 means return the left edge of the
1054 whole window, to the right of the left fringe of W. */
1057 window_box_left_offset (w
, area
)
1063 if (w
->pseudo_window_p
)
1066 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1068 if (area
== TEXT_AREA
)
1069 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1070 + window_box_width (w
, LEFT_MARGIN_AREA
));
1071 else if (area
== RIGHT_MARGIN_AREA
)
1072 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1073 + window_box_width (w
, LEFT_MARGIN_AREA
)
1074 + window_box_width (w
, TEXT_AREA
)
1075 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1077 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1078 else if (area
== LEFT_MARGIN_AREA
1079 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1080 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1086 /* Return the window-relative coordinate of the right edge of display
1087 area AREA of window W. AREA < 0 means return the left edge of the
1088 whole window, to the left of the right fringe of W. */
1091 window_box_right_offset (w
, area
)
1095 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1098 /* Return the frame-relative coordinate of the left edge of display
1099 area AREA of window W. AREA < 0 means return the left edge of the
1100 whole window, to the right of the left fringe of W. */
1103 window_box_left (w
, area
)
1107 struct frame
*f
= XFRAME (w
->frame
);
1110 if (w
->pseudo_window_p
)
1111 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1113 x
= (WINDOW_LEFT_EDGE_X (w
)
1114 + window_box_left_offset (w
, area
));
1120 /* Return the frame-relative coordinate of the right edge of display
1121 area AREA of window W. AREA < 0 means return the left edge of the
1122 whole window, to the left of the right fringe of W. */
1125 window_box_right (w
, area
)
1129 return window_box_left (w
, area
) + window_box_width (w
, area
);
1132 /* Get the bounding box of the display area AREA of window W, without
1133 mode lines, in frame-relative coordinates. AREA < 0 means the
1134 whole window, not including the left and right fringes of
1135 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1136 coordinates of the upper-left corner of the box. Return in
1137 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1140 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1143 int *box_x
, *box_y
, *box_width
, *box_height
;
1146 *box_width
= window_box_width (w
, area
);
1148 *box_height
= window_box_height (w
);
1150 *box_x
= window_box_left (w
, area
);
1153 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1154 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1155 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1160 /* Get the bounding box of the display area AREA of window W, without
1161 mode lines. AREA < 0 means the whole window, not including the
1162 left and right fringe of the window. Return in *TOP_LEFT_X
1163 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1164 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1165 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1169 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1170 bottom_right_x
, bottom_right_y
)
1173 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1175 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1177 *bottom_right_x
+= *top_left_x
;
1178 *bottom_right_y
+= *top_left_y
;
1183 /***********************************************************************
1185 ***********************************************************************/
1187 /* Return the bottom y-position of the line the iterator IT is in.
1188 This can modify IT's settings. */
1194 int line_height
= it
->max_ascent
+ it
->max_descent
;
1195 int line_top_y
= it
->current_y
;
1197 if (line_height
== 0)
1200 line_height
= last_height
;
1201 else if (IT_CHARPOS (*it
) < ZV
)
1203 move_it_by_lines (it
, 1, 1);
1204 line_height
= (it
->max_ascent
|| it
->max_descent
1205 ? it
->max_ascent
+ it
->max_descent
1210 struct glyph_row
*row
= it
->glyph_row
;
1212 /* Use the default character height. */
1213 it
->glyph_row
= NULL
;
1214 it
->what
= IT_CHARACTER
;
1217 PRODUCE_GLYPHS (it
);
1218 line_height
= it
->ascent
+ it
->descent
;
1219 it
->glyph_row
= row
;
1223 return line_top_y
+ line_height
;
1227 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1228 1 if POS is visible and the line containing POS is fully visible.
1229 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1230 and header-lines heights. */
1233 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1235 int charpos
, *fully
, exact_mode_line_heights_p
;
1238 struct text_pos top
;
1240 struct buffer
*old_buffer
= NULL
;
1242 if (XBUFFER (w
->buffer
) != current_buffer
)
1244 old_buffer
= current_buffer
;
1245 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1248 *fully
= visible_p
= 0;
1249 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1251 /* Compute exact mode line heights, if requested. */
1252 if (exact_mode_line_heights_p
)
1254 if (WINDOW_WANTS_MODELINE_P (w
))
1255 current_mode_line_height
1256 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1257 current_buffer
->mode_line_format
);
1259 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1260 current_header_line_height
1261 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1262 current_buffer
->header_line_format
);
1265 start_display (&it
, w
, top
);
1266 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1267 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1269 /* Note that we may overshoot because of invisible text. */
1270 if (IT_CHARPOS (it
) >= charpos
)
1272 int top_y
= it
.current_y
;
1273 int bottom_y
= line_bottom_y (&it
);
1274 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1276 if (top_y
< window_top_y
)
1277 visible_p
= bottom_y
> window_top_y
;
1278 else if (top_y
< it
.last_visible_y
)
1281 *fully
= bottom_y
<= it
.last_visible_y
;
1284 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1286 move_it_by_lines (&it
, 1, 0);
1287 if (charpos
< IT_CHARPOS (it
))
1295 set_buffer_internal_1 (old_buffer
);
1297 current_header_line_height
= current_mode_line_height
= -1;
1302 /* Return the next character from STR which is MAXLEN bytes long.
1303 Return in *LEN the length of the character. This is like
1304 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1305 we find one, we return a `?', but with the length of the invalid
1309 string_char_and_length (str
, maxlen
, len
)
1310 const unsigned char *str
;
1315 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1316 if (!CHAR_VALID_P (c
, 1))
1317 /* We may not change the length here because other places in Emacs
1318 don't use this function, i.e. they silently accept invalid
1327 /* Given a position POS containing a valid character and byte position
1328 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1330 static struct text_pos
1331 string_pos_nchars_ahead (pos
, string
, nchars
)
1332 struct text_pos pos
;
1336 xassert (STRINGP (string
) && nchars
>= 0);
1338 if (STRING_MULTIBYTE (string
))
1340 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1341 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1346 string_char_and_length (p
, rest
, &len
);
1347 p
+= len
, rest
-= len
;
1348 xassert (rest
>= 0);
1350 BYTEPOS (pos
) += len
;
1354 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1360 /* Value is the text position, i.e. character and byte position,
1361 for character position CHARPOS in STRING. */
1363 static INLINE
struct text_pos
1364 string_pos (charpos
, string
)
1368 struct text_pos pos
;
1369 xassert (STRINGP (string
));
1370 xassert (charpos
>= 0);
1371 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1376 /* Value is a text position, i.e. character and byte position, for
1377 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1378 means recognize multibyte characters. */
1380 static struct text_pos
1381 c_string_pos (charpos
, s
, multibyte_p
)
1386 struct text_pos pos
;
1388 xassert (s
!= NULL
);
1389 xassert (charpos
>= 0);
1393 int rest
= strlen (s
), len
;
1395 SET_TEXT_POS (pos
, 0, 0);
1398 string_char_and_length (s
, rest
, &len
);
1399 s
+= len
, rest
-= len
;
1400 xassert (rest
>= 0);
1402 BYTEPOS (pos
) += len
;
1406 SET_TEXT_POS (pos
, charpos
, charpos
);
1412 /* Value is the number of characters in C string S. MULTIBYTE_P
1413 non-zero means recognize multibyte characters. */
1416 number_of_chars (s
, multibyte_p
)
1424 int rest
= strlen (s
), len
;
1425 unsigned char *p
= (unsigned char *) s
;
1427 for (nchars
= 0; rest
> 0; ++nchars
)
1429 string_char_and_length (p
, rest
, &len
);
1430 rest
-= len
, p
+= len
;
1434 nchars
= strlen (s
);
1440 /* Compute byte position NEWPOS->bytepos corresponding to
1441 NEWPOS->charpos. POS is a known position in string STRING.
1442 NEWPOS->charpos must be >= POS.charpos. */
1445 compute_string_pos (newpos
, pos
, string
)
1446 struct text_pos
*newpos
, pos
;
1449 xassert (STRINGP (string
));
1450 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1452 if (STRING_MULTIBYTE (string
))
1453 *newpos
= string_pos_nchars_ahead (pos
, string
,
1454 CHARPOS (*newpos
) - CHARPOS (pos
));
1456 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1460 Return an estimation of the pixel height of mode or top lines on
1461 frame F. FACE_ID specifies what line's height to estimate. */
1464 estimate_mode_line_height (f
, face_id
)
1466 enum face_id face_id
;
1468 #ifdef HAVE_WINDOW_SYSTEM
1469 if (FRAME_WINDOW_P (f
))
1471 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1473 /* This function is called so early when Emacs starts that the face
1474 cache and mode line face are not yet initialized. */
1475 if (FRAME_FACE_CACHE (f
))
1477 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1481 height
= FONT_HEIGHT (face
->font
);
1482 if (face
->box_line_width
> 0)
1483 height
+= 2 * face
->box_line_width
;
1494 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1495 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1496 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1497 not force the value into range. */
1500 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1502 register int pix_x
, pix_y
;
1504 NativeRectangle
*bounds
;
1508 #ifdef HAVE_WINDOW_SYSTEM
1509 if (FRAME_WINDOW_P (f
))
1511 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1512 even for negative values. */
1514 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1516 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1518 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1519 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1522 STORE_NATIVE_RECT (*bounds
,
1523 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1524 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1525 FRAME_COLUMN_WIDTH (f
) - 1,
1526 FRAME_LINE_HEIGHT (f
) - 1);
1532 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1533 pix_x
= FRAME_TOTAL_COLS (f
);
1537 else if (pix_y
> FRAME_LINES (f
))
1538 pix_y
= FRAME_LINES (f
);
1548 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1549 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1550 can't tell the positions because W's display is not up to date,
1554 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1557 int *frame_x
, *frame_y
;
1559 #ifdef HAVE_WINDOW_SYSTEM
1560 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1564 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1565 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1567 if (display_completed
)
1569 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1570 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1571 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1577 hpos
+= glyph
->pixel_width
;
1581 /* If first glyph is partially visible, its first visible position is still 0. */
1593 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1594 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1605 #ifdef HAVE_WINDOW_SYSTEM
1607 /* Find the glyph under window-relative coordinates X/Y in window W.
1608 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1609 strings. Return in *HPOS and *VPOS the row and column number of
1610 the glyph found. Return in *AREA the glyph area containing X.
1611 Value is a pointer to the glyph found or null if X/Y is not on
1612 text, or we can't tell because W's current matrix is not up to
1615 static struct glyph
*
1616 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1619 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1621 struct glyph
*glyph
, *end
;
1622 struct glyph_row
*row
= NULL
;
1625 /* Find row containing Y. Give up if some row is not enabled. */
1626 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1628 row
= MATRIX_ROW (w
->current_matrix
, i
);
1629 if (!row
->enabled_p
)
1631 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1638 /* Give up if Y is not in the window. */
1639 if (i
== w
->current_matrix
->nrows
)
1642 /* Get the glyph area containing X. */
1643 if (w
->pseudo_window_p
)
1650 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1652 *area
= LEFT_MARGIN_AREA
;
1653 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1655 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1658 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1662 *area
= RIGHT_MARGIN_AREA
;
1663 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1667 /* Find glyph containing X. */
1668 glyph
= row
->glyphs
[*area
];
1669 end
= glyph
+ row
->used
[*area
];
1671 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1673 x
-= glyph
->pixel_width
;
1683 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1686 *hpos
= glyph
- row
->glyphs
[*area
];
1692 Convert frame-relative x/y to coordinates relative to window W.
1693 Takes pseudo-windows into account. */
1696 frame_to_window_pixel_xy (w
, x
, y
)
1700 if (w
->pseudo_window_p
)
1702 /* A pseudo-window is always full-width, and starts at the
1703 left edge of the frame, plus a frame border. */
1704 struct frame
*f
= XFRAME (w
->frame
);
1705 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1706 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1710 *x
-= WINDOW_LEFT_EDGE_X (w
);
1711 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1716 Return in *R the clipping rectangle for glyph string S. */
1719 get_glyph_string_clip_rect (s
, nr
)
1720 struct glyph_string
*s
;
1721 NativeRectangle
*nr
;
1725 if (s
->row
->full_width_p
)
1727 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1728 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1729 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1731 /* Unless displaying a mode or menu bar line, which are always
1732 fully visible, clip to the visible part of the row. */
1733 if (s
->w
->pseudo_window_p
)
1734 r
.height
= s
->row
->visible_height
;
1736 r
.height
= s
->height
;
1740 /* This is a text line that may be partially visible. */
1741 r
.x
= window_box_left (s
->w
, s
->area
);
1742 r
.width
= window_box_width (s
->w
, s
->area
);
1743 r
.height
= s
->row
->visible_height
;
1746 /* If S draws overlapping rows, it's sufficient to use the top and
1747 bottom of the window for clipping because this glyph string
1748 intentionally draws over other lines. */
1749 if (s
->for_overlaps_p
)
1751 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1752 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1756 /* Don't use S->y for clipping because it doesn't take partially
1757 visible lines into account. For example, it can be negative for
1758 partially visible lines at the top of a window. */
1759 if (!s
->row
->full_width_p
1760 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1761 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1763 r
.y
= max (0, s
->row
->y
);
1765 /* If drawing a tool-bar window, draw it over the internal border
1766 at the top of the window. */
1767 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1768 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1771 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1773 /* If drawing the cursor, don't let glyph draw outside its
1774 advertised boundaries. Cleartype does this under some circumstances. */
1775 if (s
->hl
== DRAW_CURSOR
)
1777 struct glyph
*glyph
= s
->first_glyph
;
1782 r
.width
-= s
->x
- r
.x
;
1785 r
.width
= min (r
.width
, glyph
->pixel_width
);
1787 /* Don't draw cursor glyph taller than our actual glyph. */
1788 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1789 if (height
< r
.height
)
1791 r
.y
= s
->ybase
+ glyph
->descent
- height
;
1796 #ifdef CONVERT_FROM_XRECT
1797 CONVERT_FROM_XRECT (r
, *nr
);
1803 #endif /* HAVE_WINDOW_SYSTEM */
1806 /***********************************************************************
1807 Lisp form evaluation
1808 ***********************************************************************/
1810 /* Error handler for safe_eval and safe_call. */
1813 safe_eval_handler (arg
)
1816 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1821 /* Evaluate SEXPR and return the result, or nil if something went
1822 wrong. Prevent redisplay during the evaluation. */
1830 if (inhibit_eval_during_redisplay
)
1834 int count
= SPECPDL_INDEX ();
1835 struct gcpro gcpro1
;
1838 specbind (Qinhibit_redisplay
, Qt
);
1839 /* Use Qt to ensure debugger does not run,
1840 so there is no possibility of wanting to redisplay. */
1841 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1844 val
= unbind_to (count
, val
);
1851 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1852 Return the result, or nil if something went wrong. Prevent
1853 redisplay during the evaluation. */
1856 safe_call (nargs
, args
)
1862 if (inhibit_eval_during_redisplay
)
1866 int count
= SPECPDL_INDEX ();
1867 struct gcpro gcpro1
;
1870 gcpro1
.nvars
= nargs
;
1871 specbind (Qinhibit_redisplay
, Qt
);
1872 /* Use Qt to ensure debugger does not run,
1873 so there is no possibility of wanting to redisplay. */
1874 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1877 val
= unbind_to (count
, val
);
1884 /* Call function FN with one argument ARG.
1885 Return the result, or nil if something went wrong. */
1888 safe_call1 (fn
, arg
)
1889 Lisp_Object fn
, arg
;
1891 Lisp_Object args
[2];
1894 return safe_call (2, args
);
1899 /***********************************************************************
1901 ***********************************************************************/
1905 /* Define CHECK_IT to perform sanity checks on iterators.
1906 This is for debugging. It is too slow to do unconditionally. */
1912 if (it
->method
== next_element_from_string
)
1914 xassert (STRINGP (it
->string
));
1915 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1919 xassert (IT_STRING_CHARPOS (*it
) < 0);
1920 if (it
->method
== next_element_from_buffer
)
1922 /* Check that character and byte positions agree. */
1923 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1928 xassert (it
->current
.dpvec_index
>= 0);
1930 xassert (it
->current
.dpvec_index
< 0);
1933 #define CHECK_IT(IT) check_it ((IT))
1937 #define CHECK_IT(IT) (void) 0
1944 /* Check that the window end of window W is what we expect it
1945 to be---the last row in the current matrix displaying text. */
1948 check_window_end (w
)
1951 if (!MINI_WINDOW_P (w
)
1952 && !NILP (w
->window_end_valid
))
1954 struct glyph_row
*row
;
1955 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1956 XFASTINT (w
->window_end_vpos
)),
1958 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1959 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1963 #define CHECK_WINDOW_END(W) check_window_end ((W))
1965 #else /* not GLYPH_DEBUG */
1967 #define CHECK_WINDOW_END(W) (void) 0
1969 #endif /* not GLYPH_DEBUG */
1973 /***********************************************************************
1974 Iterator initialization
1975 ***********************************************************************/
1977 /* Initialize IT for displaying current_buffer in window W, starting
1978 at character position CHARPOS. CHARPOS < 0 means that no buffer
1979 position is specified which is useful when the iterator is assigned
1980 a position later. BYTEPOS is the byte position corresponding to
1981 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1983 If ROW is not null, calls to produce_glyphs with IT as parameter
1984 will produce glyphs in that row.
1986 BASE_FACE_ID is the id of a base face to use. It must be one of
1987 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1988 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1989 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1991 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1992 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1993 will be initialized to use the corresponding mode line glyph row of
1994 the desired matrix of W. */
1997 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2000 int charpos
, bytepos
;
2001 struct glyph_row
*row
;
2002 enum face_id base_face_id
;
2004 int highlight_region_p
;
2006 /* Some precondition checks. */
2007 xassert (w
!= NULL
&& it
!= NULL
);
2008 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2011 /* If face attributes have been changed since the last redisplay,
2012 free realized faces now because they depend on face definitions
2013 that might have changed. Don't free faces while there might be
2014 desired matrices pending which reference these faces. */
2015 if (face_change_count
&& !inhibit_free_realized_faces
)
2017 face_change_count
= 0;
2018 free_all_realized_faces (Qnil
);
2021 /* Use one of the mode line rows of W's desired matrix if
2025 if (base_face_id
== MODE_LINE_FACE_ID
2026 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2027 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2028 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2029 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2033 bzero (it
, sizeof *it
);
2034 it
->current
.overlay_string_index
= -1;
2035 it
->current
.dpvec_index
= -1;
2036 it
->base_face_id
= base_face_id
;
2038 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2040 /* The window in which we iterate over current_buffer: */
2041 XSETWINDOW (it
->window
, w
);
2043 it
->f
= XFRAME (w
->frame
);
2045 /* Extra space between lines (on window systems only). */
2046 if (base_face_id
== DEFAULT_FACE_ID
2047 && FRAME_WINDOW_P (it
->f
))
2049 if (NATNUMP (current_buffer
->extra_line_spacing
))
2050 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2051 else if (it
->f
->extra_line_spacing
> 0)
2052 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2055 /* If realized faces have been removed, e.g. because of face
2056 attribute changes of named faces, recompute them. When running
2057 in batch mode, the face cache of the initial frame is null. If
2058 we happen to get called, make a dummy face cache. */
2059 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2060 init_frame_faces (it
->f
);
2061 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2062 recompute_basic_faces (it
->f
);
2064 /* Current value of the `space-width', and 'height' properties. */
2065 it
->space_width
= Qnil
;
2066 it
->font_height
= Qnil
;
2068 /* Are control characters displayed as `^C'? */
2069 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2071 /* -1 means everything between a CR and the following line end
2072 is invisible. >0 means lines indented more than this value are
2074 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2075 ? XFASTINT (current_buffer
->selective_display
)
2076 : (!NILP (current_buffer
->selective_display
)
2078 it
->selective_display_ellipsis_p
2079 = !NILP (current_buffer
->selective_display_ellipses
);
2081 /* Display table to use. */
2082 it
->dp
= window_display_table (w
);
2084 /* Are multibyte characters enabled in current_buffer? */
2085 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2087 /* Non-zero if we should highlight the region. */
2089 = (!NILP (Vtransient_mark_mode
)
2090 && !NILP (current_buffer
->mark_active
)
2091 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2093 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2094 start and end of a visible region in window IT->w. Set both to
2095 -1 to indicate no region. */
2096 if (highlight_region_p
2097 /* Maybe highlight only in selected window. */
2098 && (/* Either show region everywhere. */
2099 highlight_nonselected_windows
2100 /* Or show region in the selected window. */
2101 || w
== XWINDOW (selected_window
)
2102 /* Or show the region if we are in the mini-buffer and W is
2103 the window the mini-buffer refers to. */
2104 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2105 && WINDOWP (minibuf_selected_window
)
2106 && w
== XWINDOW (minibuf_selected_window
))))
2108 int charpos
= marker_position (current_buffer
->mark
);
2109 it
->region_beg_charpos
= min (PT
, charpos
);
2110 it
->region_end_charpos
= max (PT
, charpos
);
2113 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2115 /* Get the position at which the redisplay_end_trigger hook should
2116 be run, if it is to be run at all. */
2117 if (MARKERP (w
->redisplay_end_trigger
)
2118 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2119 it
->redisplay_end_trigger_charpos
2120 = marker_position (w
->redisplay_end_trigger
);
2121 else if (INTEGERP (w
->redisplay_end_trigger
))
2122 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2124 /* Correct bogus values of tab_width. */
2125 it
->tab_width
= XINT (current_buffer
->tab_width
);
2126 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2129 /* Are lines in the display truncated? */
2130 it
->truncate_lines_p
2131 = (base_face_id
!= DEFAULT_FACE_ID
2132 || XINT (it
->w
->hscroll
)
2133 || (truncate_partial_width_windows
2134 && !WINDOW_FULL_WIDTH_P (it
->w
))
2135 || !NILP (current_buffer
->truncate_lines
));
2137 /* Get dimensions of truncation and continuation glyphs. These are
2138 displayed as fringe bitmaps under X, so we don't need them for such
2140 if (!FRAME_WINDOW_P (it
->f
))
2142 if (it
->truncate_lines_p
)
2144 /* We will need the truncation glyph. */
2145 xassert (it
->glyph_row
== NULL
);
2146 produce_special_glyphs (it
, IT_TRUNCATION
);
2147 it
->truncation_pixel_width
= it
->pixel_width
;
2151 /* We will need the continuation glyph. */
2152 xassert (it
->glyph_row
== NULL
);
2153 produce_special_glyphs (it
, IT_CONTINUATION
);
2154 it
->continuation_pixel_width
= it
->pixel_width
;
2157 /* Reset these values to zero because the produce_special_glyphs
2158 above has changed them. */
2159 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2160 it
->phys_ascent
= it
->phys_descent
= 0;
2163 /* Set this after getting the dimensions of truncation and
2164 continuation glyphs, so that we don't produce glyphs when calling
2165 produce_special_glyphs, above. */
2166 it
->glyph_row
= row
;
2167 it
->area
= TEXT_AREA
;
2169 /* Get the dimensions of the display area. The display area
2170 consists of the visible window area plus a horizontally scrolled
2171 part to the left of the window. All x-values are relative to the
2172 start of this total display area. */
2173 if (base_face_id
!= DEFAULT_FACE_ID
)
2175 /* Mode lines, menu bar in terminal frames. */
2176 it
->first_visible_x
= 0;
2177 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2182 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2183 it
->last_visible_x
= (it
->first_visible_x
2184 + window_box_width (w
, TEXT_AREA
));
2186 /* If we truncate lines, leave room for the truncator glyph(s) at
2187 the right margin. Otherwise, leave room for the continuation
2188 glyph(s). Truncation and continuation glyphs are not inserted
2189 for window-based redisplay. */
2190 if (!FRAME_WINDOW_P (it
->f
))
2192 if (it
->truncate_lines_p
)
2193 it
->last_visible_x
-= it
->truncation_pixel_width
;
2195 it
->last_visible_x
-= it
->continuation_pixel_width
;
2198 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2199 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2202 /* Leave room for a border glyph. */
2203 if (!FRAME_WINDOW_P (it
->f
)
2204 && !WINDOW_RIGHTMOST_P (it
->w
))
2205 it
->last_visible_x
-= 1;
2207 it
->last_visible_y
= window_text_bottom_y (w
);
2209 /* For mode lines and alike, arrange for the first glyph having a
2210 left box line if the face specifies a box. */
2211 if (base_face_id
!= DEFAULT_FACE_ID
)
2215 it
->face_id
= base_face_id
;
2217 /* If we have a boxed mode line, make the first character appear
2218 with a left box line. */
2219 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2220 if (face
->box
!= FACE_NO_BOX
)
2221 it
->start_of_box_run_p
= 1;
2224 /* If a buffer position was specified, set the iterator there,
2225 getting overlays and face properties from that position. */
2226 if (charpos
>= BUF_BEG (current_buffer
))
2228 it
->end_charpos
= ZV
;
2230 IT_CHARPOS (*it
) = charpos
;
2232 /* Compute byte position if not specified. */
2233 if (bytepos
< charpos
)
2234 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2236 IT_BYTEPOS (*it
) = bytepos
;
2238 it
->start
= it
->current
;
2240 /* Compute faces etc. */
2241 reseat (it
, it
->current
.pos
, 1);
2248 /* Initialize IT for the display of window W with window start POS. */
2251 start_display (it
, w
, pos
)
2254 struct text_pos pos
;
2256 struct glyph_row
*row
;
2257 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2259 row
= w
->desired_matrix
->rows
+ first_vpos
;
2260 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2261 it
->first_vpos
= first_vpos
;
2263 if (!it
->truncate_lines_p
)
2265 int start_at_line_beg_p
;
2266 int first_y
= it
->current_y
;
2268 /* If window start is not at a line start, skip forward to POS to
2269 get the correct continuation lines width. */
2270 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2271 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2272 if (!start_at_line_beg_p
)
2276 reseat_at_previous_visible_line_start (it
);
2277 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2279 new_x
= it
->current_x
+ it
->pixel_width
;
2281 /* If lines are continued, this line may end in the middle
2282 of a multi-glyph character (e.g. a control character
2283 displayed as \003, or in the middle of an overlay
2284 string). In this case move_it_to above will not have
2285 taken us to the start of the continuation line but to the
2286 end of the continued line. */
2287 if (it
->current_x
> 0
2288 && !it
->truncate_lines_p
/* Lines are continued. */
2289 && (/* And glyph doesn't fit on the line. */
2290 new_x
> it
->last_visible_x
2291 /* Or it fits exactly and we're on a window
2293 || (new_x
== it
->last_visible_x
2294 && FRAME_WINDOW_P (it
->f
))))
2296 if (it
->current
.dpvec_index
>= 0
2297 || it
->current
.overlay_string_index
>= 0)
2299 set_iterator_to_next (it
, 1);
2300 move_it_in_display_line_to (it
, -1, -1, 0);
2303 it
->continuation_lines_width
+= it
->current_x
;
2306 /* We're starting a new display line, not affected by the
2307 height of the continued line, so clear the appropriate
2308 fields in the iterator structure. */
2309 it
->max_ascent
= it
->max_descent
= 0;
2310 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2312 it
->current_y
= first_y
;
2314 it
->current_x
= it
->hpos
= 0;
2318 #if 0 /* Don't assert the following because start_display is sometimes
2319 called intentionally with a window start that is not at a
2320 line start. Please leave this code in as a comment. */
2322 /* Window start should be on a line start, now. */
2323 xassert (it
->continuation_lines_width
2324 || IT_CHARPOS (it
) == BEGV
2325 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2330 /* Return 1 if POS is a position in ellipses displayed for invisible
2331 text. W is the window we display, for text property lookup. */
2334 in_ellipses_for_invisible_text_p (pos
, w
)
2335 struct display_pos
*pos
;
2338 Lisp_Object prop
, window
;
2340 int charpos
= CHARPOS (pos
->pos
);
2342 /* If POS specifies a position in a display vector, this might
2343 be for an ellipsis displayed for invisible text. We won't
2344 get the iterator set up for delivering that ellipsis unless
2345 we make sure that it gets aware of the invisible text. */
2346 if (pos
->dpvec_index
>= 0
2347 && pos
->overlay_string_index
< 0
2348 && CHARPOS (pos
->string_pos
) < 0
2350 && (XSETWINDOW (window
, w
),
2351 prop
= Fget_char_property (make_number (charpos
),
2352 Qinvisible
, window
),
2353 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2355 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2357 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2364 /* Initialize IT for stepping through current_buffer in window W,
2365 starting at position POS that includes overlay string and display
2366 vector/ control character translation position information. Value
2367 is zero if there are overlay strings with newlines at POS. */
2370 init_from_display_pos (it
, w
, pos
)
2373 struct display_pos
*pos
;
2375 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2376 int i
, overlay_strings_with_newlines
= 0;
2378 /* If POS specifies a position in a display vector, this might
2379 be for an ellipsis displayed for invisible text. We won't
2380 get the iterator set up for delivering that ellipsis unless
2381 we make sure that it gets aware of the invisible text. */
2382 if (in_ellipses_for_invisible_text_p (pos
, w
))
2388 /* Keep in mind: the call to reseat in init_iterator skips invisible
2389 text, so we might end up at a position different from POS. This
2390 is only a problem when POS is a row start after a newline and an
2391 overlay starts there with an after-string, and the overlay has an
2392 invisible property. Since we don't skip invisible text in
2393 display_line and elsewhere immediately after consuming the
2394 newline before the row start, such a POS will not be in a string,
2395 but the call to init_iterator below will move us to the
2397 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2399 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2401 const char *s
= SDATA (it
->overlay_strings
[i
]);
2402 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2404 while (s
< e
&& *s
!= '\n')
2409 overlay_strings_with_newlines
= 1;
2414 /* If position is within an overlay string, set up IT to the right
2416 if (pos
->overlay_string_index
>= 0)
2420 /* If the first overlay string happens to have a `display'
2421 property for an image, the iterator will be set up for that
2422 image, and we have to undo that setup first before we can
2423 correct the overlay string index. */
2424 if (it
->method
== next_element_from_image
)
2427 /* We already have the first chunk of overlay strings in
2428 IT->overlay_strings. Load more until the one for
2429 pos->overlay_string_index is in IT->overlay_strings. */
2430 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2432 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2433 it
->current
.overlay_string_index
= 0;
2436 load_overlay_strings (it
, 0);
2437 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2441 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2442 relative_index
= (it
->current
.overlay_string_index
2443 % OVERLAY_STRING_CHUNK_SIZE
);
2444 it
->string
= it
->overlay_strings
[relative_index
];
2445 xassert (STRINGP (it
->string
));
2446 it
->current
.string_pos
= pos
->string_pos
;
2447 it
->method
= next_element_from_string
;
2450 #if 0 /* This is bogus because POS not having an overlay string
2451 position does not mean it's after the string. Example: A
2452 line starting with a before-string and initialization of IT
2453 to the previous row's end position. */
2454 else if (it
->current
.overlay_string_index
>= 0)
2456 /* If POS says we're already after an overlay string ending at
2457 POS, make sure to pop the iterator because it will be in
2458 front of that overlay string. When POS is ZV, we've thereby
2459 also ``processed'' overlay strings at ZV. */
2462 it
->current
.overlay_string_index
= -1;
2463 it
->method
= next_element_from_buffer
;
2464 if (CHARPOS (pos
->pos
) == ZV
)
2465 it
->overlay_strings_at_end_processed_p
= 1;
2469 if (CHARPOS (pos
->string_pos
) >= 0)
2471 /* Recorded position is not in an overlay string, but in another
2472 string. This can only be a string from a `display' property.
2473 IT should already be filled with that string. */
2474 it
->current
.string_pos
= pos
->string_pos
;
2475 xassert (STRINGP (it
->string
));
2478 /* Restore position in display vector translations, control
2479 character translations or ellipses. */
2480 if (pos
->dpvec_index
>= 0)
2482 if (it
->dpvec
== NULL
)
2483 get_next_display_element (it
);
2484 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2485 it
->current
.dpvec_index
= pos
->dpvec_index
;
2489 return !overlay_strings_with_newlines
;
2493 /* Initialize IT for stepping through current_buffer in window W
2494 starting at ROW->start. */
2497 init_to_row_start (it
, w
, row
)
2500 struct glyph_row
*row
;
2502 init_from_display_pos (it
, w
, &row
->start
);
2503 it
->start
= row
->start
;
2504 it
->continuation_lines_width
= row
->continuation_lines_width
;
2509 /* Initialize IT for stepping through current_buffer in window W
2510 starting in the line following ROW, i.e. starting at ROW->end.
2511 Value is zero if there are overlay strings with newlines at ROW's
2515 init_to_row_end (it
, w
, row
)
2518 struct glyph_row
*row
;
2522 if (init_from_display_pos (it
, w
, &row
->end
))
2524 if (row
->continued_p
)
2525 it
->continuation_lines_width
2526 = row
->continuation_lines_width
+ row
->pixel_width
;
2537 /***********************************************************************
2539 ***********************************************************************/
2541 /* Called when IT reaches IT->stop_charpos. Handle text property and
2542 overlay changes. Set IT->stop_charpos to the next position where
2549 enum prop_handled handled
;
2550 int handle_overlay_change_p
= 1;
2554 it
->current
.dpvec_index
= -1;
2558 handled
= HANDLED_NORMALLY
;
2560 /* Call text property handlers. */
2561 for (p
= it_props
; p
->handler
; ++p
)
2563 handled
= p
->handler (it
);
2565 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2567 else if (handled
== HANDLED_RETURN
)
2569 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2570 handle_overlay_change_p
= 0;
2573 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2575 /* Don't check for overlay strings below when set to deliver
2576 characters from a display vector. */
2577 if (it
->method
== next_element_from_display_vector
)
2578 handle_overlay_change_p
= 0;
2580 /* Handle overlay changes. */
2581 if (handle_overlay_change_p
)
2582 handled
= handle_overlay_change (it
);
2584 /* Determine where to stop next. */
2585 if (handled
== HANDLED_NORMALLY
)
2586 compute_stop_pos (it
);
2589 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2593 /* Compute IT->stop_charpos from text property and overlay change
2594 information for IT's current position. */
2597 compute_stop_pos (it
)
2600 register INTERVAL iv
, next_iv
;
2601 Lisp_Object object
, limit
, position
;
2603 /* If nowhere else, stop at the end. */
2604 it
->stop_charpos
= it
->end_charpos
;
2606 if (STRINGP (it
->string
))
2608 /* Strings are usually short, so don't limit the search for
2610 object
= it
->string
;
2612 position
= make_number (IT_STRING_CHARPOS (*it
));
2618 /* If next overlay change is in front of the current stop pos
2619 (which is IT->end_charpos), stop there. Note: value of
2620 next_overlay_change is point-max if no overlay change
2622 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2623 if (charpos
< it
->stop_charpos
)
2624 it
->stop_charpos
= charpos
;
2626 /* If showing the region, we have to stop at the region
2627 start or end because the face might change there. */
2628 if (it
->region_beg_charpos
> 0)
2630 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2631 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2632 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2633 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2636 /* Set up variables for computing the stop position from text
2637 property changes. */
2638 XSETBUFFER (object
, current_buffer
);
2639 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2640 position
= make_number (IT_CHARPOS (*it
));
2644 /* Get the interval containing IT's position. Value is a null
2645 interval if there isn't such an interval. */
2646 iv
= validate_interval_range (object
, &position
, &position
, 0);
2647 if (!NULL_INTERVAL_P (iv
))
2649 Lisp_Object values_here
[LAST_PROP_IDX
];
2652 /* Get properties here. */
2653 for (p
= it_props
; p
->handler
; ++p
)
2654 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2656 /* Look for an interval following iv that has different
2658 for (next_iv
= next_interval (iv
);
2659 (!NULL_INTERVAL_P (next_iv
)
2661 || XFASTINT (limit
) > next_iv
->position
));
2662 next_iv
= next_interval (next_iv
))
2664 for (p
= it_props
; p
->handler
; ++p
)
2666 Lisp_Object new_value
;
2668 new_value
= textget (next_iv
->plist
, *p
->name
);
2669 if (!EQ (values_here
[p
->idx
], new_value
))
2677 if (!NULL_INTERVAL_P (next_iv
))
2679 if (INTEGERP (limit
)
2680 && next_iv
->position
>= XFASTINT (limit
))
2681 /* No text property change up to limit. */
2682 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2684 /* Text properties change in next_iv. */
2685 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2689 xassert (STRINGP (it
->string
)
2690 || (it
->stop_charpos
>= BEGV
2691 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2695 /* Return the position of the next overlay change after POS in
2696 current_buffer. Value is point-max if no overlay change
2697 follows. This is like `next-overlay-change' but doesn't use
2701 next_overlay_change (pos
)
2706 Lisp_Object
*overlays
;
2710 /* Get all overlays at the given position. */
2712 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2713 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2714 if (noverlays
> len
)
2717 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2718 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2721 /* If any of these overlays ends before endpos,
2722 use its ending point instead. */
2723 for (i
= 0; i
< noverlays
; ++i
)
2728 oend
= OVERLAY_END (overlays
[i
]);
2729 oendpos
= OVERLAY_POSITION (oend
);
2730 endpos
= min (endpos
, oendpos
);
2738 /***********************************************************************
2740 ***********************************************************************/
2742 /* Handle changes in the `fontified' property of the current buffer by
2743 calling hook functions from Qfontification_functions to fontify
2746 static enum prop_handled
2747 handle_fontified_prop (it
)
2750 Lisp_Object prop
, pos
;
2751 enum prop_handled handled
= HANDLED_NORMALLY
;
2753 /* Get the value of the `fontified' property at IT's current buffer
2754 position. (The `fontified' property doesn't have a special
2755 meaning in strings.) If the value is nil, call functions from
2756 Qfontification_functions. */
2757 if (!STRINGP (it
->string
)
2759 && !NILP (Vfontification_functions
)
2760 && !NILP (Vrun_hooks
)
2761 && (pos
= make_number (IT_CHARPOS (*it
)),
2762 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2765 int count
= SPECPDL_INDEX ();
2768 val
= Vfontification_functions
;
2769 specbind (Qfontification_functions
, Qnil
);
2771 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2772 safe_call1 (val
, pos
);
2775 Lisp_Object globals
, fn
;
2776 struct gcpro gcpro1
, gcpro2
;
2779 GCPRO2 (val
, globals
);
2781 for (; CONSP (val
); val
= XCDR (val
))
2787 /* A value of t indicates this hook has a local
2788 binding; it means to run the global binding too.
2789 In a global value, t should not occur. If it
2790 does, we must ignore it to avoid an endless
2792 for (globals
= Fdefault_value (Qfontification_functions
);
2794 globals
= XCDR (globals
))
2796 fn
= XCAR (globals
);
2798 safe_call1 (fn
, pos
);
2802 safe_call1 (fn
, pos
);
2808 unbind_to (count
, Qnil
);
2810 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2811 something. This avoids an endless loop if they failed to
2812 fontify the text for which reason ever. */
2813 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2814 handled
= HANDLED_RECOMPUTE_PROPS
;
2822 /***********************************************************************
2824 ***********************************************************************/
2826 /* Set up iterator IT from face properties at its current position.
2827 Called from handle_stop. */
2829 static enum prop_handled
2830 handle_face_prop (it
)
2833 int new_face_id
, next_stop
;
2835 if (!STRINGP (it
->string
))
2838 = face_at_buffer_position (it
->w
,
2840 it
->region_beg_charpos
,
2841 it
->region_end_charpos
,
2844 + TEXT_PROP_DISTANCE_LIMIT
),
2847 /* Is this a start of a run of characters with box face?
2848 Caveat: this can be called for a freshly initialized
2849 iterator; face_id is -1 in this case. We know that the new
2850 face will not change until limit, i.e. if the new face has a
2851 box, all characters up to limit will have one. But, as
2852 usual, we don't know whether limit is really the end. */
2853 if (new_face_id
!= it
->face_id
)
2855 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2857 /* If new face has a box but old face has not, this is
2858 the start of a run of characters with box, i.e. it has
2859 a shadow on the left side. The value of face_id of the
2860 iterator will be -1 if this is the initial call that gets
2861 the face. In this case, we have to look in front of IT's
2862 position and see whether there is a face != new_face_id. */
2863 it
->start_of_box_run_p
2864 = (new_face
->box
!= FACE_NO_BOX
2865 && (it
->face_id
>= 0
2866 || IT_CHARPOS (*it
) == BEG
2867 || new_face_id
!= face_before_it_pos (it
)));
2868 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2873 int base_face_id
, bufpos
;
2875 if (it
->current
.overlay_string_index
>= 0)
2876 bufpos
= IT_CHARPOS (*it
);
2880 /* For strings from a buffer, i.e. overlay strings or strings
2881 from a `display' property, use the face at IT's current
2882 buffer position as the base face to merge with, so that
2883 overlay strings appear in the same face as surrounding
2884 text, unless they specify their own faces. */
2885 base_face_id
= underlying_face_id (it
);
2887 new_face_id
= face_at_string_position (it
->w
,
2889 IT_STRING_CHARPOS (*it
),
2891 it
->region_beg_charpos
,
2892 it
->region_end_charpos
,
2896 #if 0 /* This shouldn't be neccessary. Let's check it. */
2897 /* If IT is used to display a mode line we would really like to
2898 use the mode line face instead of the frame's default face. */
2899 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2900 && new_face_id
== DEFAULT_FACE_ID
)
2901 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2904 /* Is this a start of a run of characters with box? Caveat:
2905 this can be called for a freshly allocated iterator; face_id
2906 is -1 is this case. We know that the new face will not
2907 change until the next check pos, i.e. if the new face has a
2908 box, all characters up to that position will have a
2909 box. But, as usual, we don't know whether that position
2910 is really the end. */
2911 if (new_face_id
!= it
->face_id
)
2913 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2914 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2916 /* If new face has a box but old face hasn't, this is the
2917 start of a run of characters with box, i.e. it has a
2918 shadow on the left side. */
2919 it
->start_of_box_run_p
2920 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2921 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2925 it
->face_id
= new_face_id
;
2926 return HANDLED_NORMALLY
;
2930 /* Return the ID of the face ``underlying'' IT's current position,
2931 which is in a string. If the iterator is associated with a
2932 buffer, return the face at IT's current buffer position.
2933 Otherwise, use the iterator's base_face_id. */
2936 underlying_face_id (it
)
2939 int face_id
= it
->base_face_id
, i
;
2941 xassert (STRINGP (it
->string
));
2943 for (i
= it
->sp
- 1; i
>= 0; --i
)
2944 if (NILP (it
->stack
[i
].string
))
2945 face_id
= it
->stack
[i
].face_id
;
2951 /* Compute the face one character before or after the current position
2952 of IT. BEFORE_P non-zero means get the face in front of IT's
2953 position. Value is the id of the face. */
2956 face_before_or_after_it_pos (it
, before_p
)
2961 int next_check_charpos
;
2962 struct text_pos pos
;
2964 xassert (it
->s
== NULL
);
2966 if (STRINGP (it
->string
))
2968 int bufpos
, base_face_id
;
2970 /* No face change past the end of the string (for the case
2971 we are padding with spaces). No face change before the
2973 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2974 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2977 /* Set pos to the position before or after IT's current position. */
2979 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2981 /* For composition, we must check the character after the
2983 pos
= (it
->what
== IT_COMPOSITION
2984 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2985 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2987 if (it
->current
.overlay_string_index
>= 0)
2988 bufpos
= IT_CHARPOS (*it
);
2992 base_face_id
= underlying_face_id (it
);
2994 /* Get the face for ASCII, or unibyte. */
2995 face_id
= face_at_string_position (it
->w
,
2999 it
->region_beg_charpos
,
3000 it
->region_end_charpos
,
3001 &next_check_charpos
,
3004 /* Correct the face for charsets different from ASCII. Do it
3005 for the multibyte case only. The face returned above is
3006 suitable for unibyte text if IT->string is unibyte. */
3007 if (STRING_MULTIBYTE (it
->string
))
3009 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3010 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3012 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3014 c
= string_char_and_length (p
, rest
, &len
);
3015 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3020 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3021 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3024 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3025 pos
= it
->current
.pos
;
3028 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3031 if (it
->what
== IT_COMPOSITION
)
3032 /* For composition, we must check the position after the
3034 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3036 INC_TEXT_POS (pos
, it
->multibyte_p
);
3039 /* Determine face for CHARSET_ASCII, or unibyte. */
3040 face_id
= face_at_buffer_position (it
->w
,
3042 it
->region_beg_charpos
,
3043 it
->region_end_charpos
,
3044 &next_check_charpos
,
3047 /* Correct the face for charsets different from ASCII. Do it
3048 for the multibyte case only. The face returned above is
3049 suitable for unibyte text if current_buffer is unibyte. */
3050 if (it
->multibyte_p
)
3052 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3053 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3054 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3063 /***********************************************************************
3065 ***********************************************************************/
3067 /* Set up iterator IT from invisible properties at its current
3068 position. Called from handle_stop. */
3070 static enum prop_handled
3071 handle_invisible_prop (it
)
3074 enum prop_handled handled
= HANDLED_NORMALLY
;
3076 if (STRINGP (it
->string
))
3078 extern Lisp_Object Qinvisible
;
3079 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3081 /* Get the value of the invisible text property at the
3082 current position. Value will be nil if there is no such
3084 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3085 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3088 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3090 handled
= HANDLED_RECOMPUTE_PROPS
;
3092 /* Get the position at which the next change of the
3093 invisible text property can be found in IT->string.
3094 Value will be nil if the property value is the same for
3095 all the rest of IT->string. */
3096 XSETINT (limit
, SCHARS (it
->string
));
3097 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3100 /* Text at current position is invisible. The next
3101 change in the property is at position end_charpos.
3102 Move IT's current position to that position. */
3103 if (INTEGERP (end_charpos
)
3104 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3106 struct text_pos old
;
3107 old
= it
->current
.string_pos
;
3108 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3109 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3113 /* The rest of the string is invisible. If this is an
3114 overlay string, proceed with the next overlay string
3115 or whatever comes and return a character from there. */
3116 if (it
->current
.overlay_string_index
>= 0)
3118 next_overlay_string (it
);
3119 /* Don't check for overlay strings when we just
3120 finished processing them. */
3121 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3125 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3126 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3133 int invis_p
, newpos
, next_stop
, start_charpos
;
3134 Lisp_Object pos
, prop
, overlay
;
3136 /* First of all, is there invisible text at this position? */
3137 start_charpos
= IT_CHARPOS (*it
);
3138 pos
= make_number (IT_CHARPOS (*it
));
3139 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3141 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3143 /* If we are on invisible text, skip over it. */
3144 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3146 /* Record whether we have to display an ellipsis for the
3148 int display_ellipsis_p
= invis_p
== 2;
3150 handled
= HANDLED_RECOMPUTE_PROPS
;
3152 /* Loop skipping over invisible text. The loop is left at
3153 ZV or with IT on the first char being visible again. */
3156 /* Try to skip some invisible text. Return value is the
3157 position reached which can be equal to IT's position
3158 if there is nothing invisible here. This skips both
3159 over invisible text properties and overlays with
3160 invisible property. */
3161 newpos
= skip_invisible (IT_CHARPOS (*it
),
3162 &next_stop
, ZV
, it
->window
);
3164 /* If we skipped nothing at all we weren't at invisible
3165 text in the first place. If everything to the end of
3166 the buffer was skipped, end the loop. */
3167 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3171 /* We skipped some characters but not necessarily
3172 all there are. Check if we ended up on visible
3173 text. Fget_char_property returns the property of
3174 the char before the given position, i.e. if we
3175 get invis_p = 0, this means that the char at
3176 newpos is visible. */
3177 pos
= make_number (newpos
);
3178 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3179 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3182 /* If we ended up on invisible text, proceed to
3183 skip starting with next_stop. */
3185 IT_CHARPOS (*it
) = next_stop
;
3189 /* The position newpos is now either ZV or on visible text. */
3190 IT_CHARPOS (*it
) = newpos
;
3191 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3193 /* If there are before-strings at the start of invisible
3194 text, and the text is invisible because of a text
3195 property, arrange to show before-strings because 20.x did
3196 it that way. (If the text is invisible because of an
3197 overlay property instead of a text property, this is
3198 already handled in the overlay code.) */
3200 && get_overlay_strings (it
, start_charpos
))
3202 handled
= HANDLED_RECOMPUTE_PROPS
;
3203 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3205 else if (display_ellipsis_p
)
3206 setup_for_ellipsis (it
);
3214 /* Make iterator IT return `...' next. */
3217 setup_for_ellipsis (it
)
3221 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3223 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3224 it
->dpvec
= v
->contents
;
3225 it
->dpend
= v
->contents
+ v
->size
;
3229 /* Default `...'. */
3230 it
->dpvec
= default_invis_vector
;
3231 it
->dpend
= default_invis_vector
+ 3;
3234 /* The ellipsis display does not replace the display of the
3235 character at the new position. Indicate this by setting
3236 IT->dpvec_char_len to zero. */
3237 it
->dpvec_char_len
= 0;
3239 it
->current
.dpvec_index
= 0;
3240 it
->method
= next_element_from_display_vector
;
3245 /***********************************************************************
3247 ***********************************************************************/
3249 /* Set up iterator IT from `display' property at its current position.
3250 Called from handle_stop. */
3252 static enum prop_handled
3253 handle_display_prop (it
)
3256 Lisp_Object prop
, object
;
3257 struct text_pos
*position
;
3258 int display_replaced_p
= 0;
3260 if (STRINGP (it
->string
))
3262 object
= it
->string
;
3263 position
= &it
->current
.string_pos
;
3267 object
= it
->w
->buffer
;
3268 position
= &it
->current
.pos
;
3271 /* Reset those iterator values set from display property values. */
3272 it
->font_height
= Qnil
;
3273 it
->space_width
= Qnil
;
3276 /* We don't support recursive `display' properties, i.e. string
3277 values that have a string `display' property, that have a string
3278 `display' property etc. */
3279 if (!it
->string_from_display_prop_p
)
3280 it
->area
= TEXT_AREA
;
3282 prop
= Fget_char_property (make_number (position
->charpos
),
3285 return HANDLED_NORMALLY
;
3288 /* Simple properties. */
3289 && !EQ (XCAR (prop
), Qimage
)
3290 && !EQ (XCAR (prop
), Qspace
)
3291 && !EQ (XCAR (prop
), Qwhen
)
3292 && !EQ (XCAR (prop
), Qspace_width
)
3293 && !EQ (XCAR (prop
), Qheight
)
3294 && !EQ (XCAR (prop
), Qraise
)
3295 /* Marginal area specifications. */
3296 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3297 && !EQ (XCAR (prop
), Qleft_fringe
)
3298 && !EQ (XCAR (prop
), Qright_fringe
)
3299 && !NILP (XCAR (prop
)))
3301 for (; CONSP (prop
); prop
= XCDR (prop
))
3303 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3304 position
, display_replaced_p
))
3305 display_replaced_p
= 1;
3308 else if (VECTORP (prop
))
3311 for (i
= 0; i
< ASIZE (prop
); ++i
)
3312 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3313 position
, display_replaced_p
))
3314 display_replaced_p
= 1;
3318 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3319 display_replaced_p
= 1;
3322 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3326 /* Value is the position of the end of the `display' property starting
3327 at START_POS in OBJECT. */
3329 static struct text_pos
3330 display_prop_end (it
, object
, start_pos
)
3333 struct text_pos start_pos
;
3336 struct text_pos end_pos
;
3338 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3339 Qdisplay
, object
, Qnil
);
3340 CHARPOS (end_pos
) = XFASTINT (end
);
3341 if (STRINGP (object
))
3342 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3344 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3350 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3351 is the object in which the `display' property was found. *POSITION
3352 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3353 means that we previously saw a display sub-property which already
3354 replaced text display with something else, for example an image;
3355 ignore such properties after the first one has been processed.
3357 If PROP is a `space' or `image' sub-property, set *POSITION to the
3358 end position of the `display' property.
3360 Value is non-zero if something was found which replaces the display
3361 of buffer or string text. */
3364 handle_single_display_prop (it
, prop
, object
, position
,
3365 display_replaced_before_p
)
3369 struct text_pos
*position
;
3370 int display_replaced_before_p
;
3373 int replaces_text_display_p
= 0;
3376 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3377 evaluated. If the result is nil, VALUE is ignored. */
3379 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3388 if (!NILP (form
) && !EQ (form
, Qt
))
3390 int count
= SPECPDL_INDEX ();
3391 struct gcpro gcpro1
;
3393 /* Bind `object' to the object having the `display' property, a
3394 buffer or string. Bind `position' to the position in the
3395 object where the property was found, and `buffer-position'
3396 to the current position in the buffer. */
3397 specbind (Qobject
, object
);
3398 specbind (Qposition
, make_number (CHARPOS (*position
)));
3399 specbind (Qbuffer_position
,
3400 make_number (STRINGP (object
)
3401 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3403 form
= safe_eval (form
);
3405 unbind_to (count
, Qnil
);
3412 && EQ (XCAR (prop
), Qheight
)
3413 && CONSP (XCDR (prop
)))
3415 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3418 /* `(height HEIGHT)'. */
3419 it
->font_height
= XCAR (XCDR (prop
));
3420 if (!NILP (it
->font_height
))
3422 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3423 int new_height
= -1;
3425 if (CONSP (it
->font_height
)
3426 && (EQ (XCAR (it
->font_height
), Qplus
)
3427 || EQ (XCAR (it
->font_height
), Qminus
))
3428 && CONSP (XCDR (it
->font_height
))
3429 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3431 /* `(+ N)' or `(- N)' where N is an integer. */
3432 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3433 if (EQ (XCAR (it
->font_height
), Qplus
))
3435 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3437 else if (FUNCTIONP (it
->font_height
))
3439 /* Call function with current height as argument.
3440 Value is the new height. */
3442 height
= safe_call1 (it
->font_height
,
3443 face
->lface
[LFACE_HEIGHT_INDEX
]);
3444 if (NUMBERP (height
))
3445 new_height
= XFLOATINT (height
);
3447 else if (NUMBERP (it
->font_height
))
3449 /* Value is a multiple of the canonical char height. */
3452 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3453 new_height
= (XFLOATINT (it
->font_height
)
3454 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3458 /* Evaluate IT->font_height with `height' bound to the
3459 current specified height to get the new height. */
3461 int count
= SPECPDL_INDEX ();
3463 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3464 value
= safe_eval (it
->font_height
);
3465 unbind_to (count
, Qnil
);
3467 if (NUMBERP (value
))
3468 new_height
= XFLOATINT (value
);
3472 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3475 else if (CONSP (prop
)
3476 && EQ (XCAR (prop
), Qspace_width
)
3477 && CONSP (XCDR (prop
)))
3479 /* `(space_width WIDTH)'. */
3480 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3483 value
= XCAR (XCDR (prop
));
3484 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3485 it
->space_width
= value
;
3487 else if (CONSP (prop
)
3488 && EQ (XCAR (prop
), Qraise
)
3489 && CONSP (XCDR (prop
)))
3491 /* `(raise FACTOR)'. */
3492 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3495 #ifdef HAVE_WINDOW_SYSTEM
3496 value
= XCAR (XCDR (prop
));
3497 if (NUMBERP (value
))
3499 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3500 it
->voffset
= - (XFLOATINT (value
)
3501 * (FONT_HEIGHT (face
->font
)));
3503 #endif /* HAVE_WINDOW_SYSTEM */
3505 else if (!it
->string_from_display_prop_p
)
3507 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3508 VALUE) or `((margin nil) VALUE)' or VALUE. */
3509 Lisp_Object location
, value
;
3510 struct text_pos start_pos
;
3513 /* Characters having this form of property are not displayed, so
3514 we have to find the end of the property. */
3515 start_pos
= *position
;
3516 *position
= display_prop_end (it
, object
, start_pos
);
3519 /* Let's stop at the new position and assume that all
3520 text properties change there. */
3521 it
->stop_charpos
= position
->charpos
;
3524 && (EQ (XCAR (prop
), Qleft_fringe
)
3525 || EQ (XCAR (prop
), Qright_fringe
))
3526 && CONSP (XCDR (prop
)))
3528 unsigned face_id
= DEFAULT_FACE_ID
;
3530 /* Save current settings of IT so that we can restore them
3531 when we are finished with the glyph property value. */
3533 /* `(left-fringe BITMAP FACE)'. */
3534 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3537 #ifdef HAVE_WINDOW_SYSTEM
3538 value
= XCAR (XCDR (prop
));
3539 if (!NUMBERP (value
)
3540 || !valid_fringe_bitmap_id_p (XINT (value
)))
3543 if (CONSP (XCDR (XCDR (prop
))))
3545 Lisp_Object face_name
= XCAR (XCDR (XCDR (prop
)));
3547 face_id
= lookup_named_face (it
->f
, face_name
, 'A');
3554 it
->area
= TEXT_AREA
;
3555 it
->what
= IT_IMAGE
;
3556 it
->image_id
= -1; /* no image */
3557 it
->position
= start_pos
;
3558 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3559 it
->method
= next_element_from_image
;
3560 it
->face_id
= face_id
;
3562 /* Say that we haven't consumed the characters with
3563 `display' property yet. The call to pop_it in
3564 set_iterator_to_next will clean this up. */
3565 *position
= start_pos
;
3567 if (EQ (XCAR (prop
), Qleft_fringe
))
3569 it
->left_user_fringe_bitmap
= XINT (value
);
3570 it
->left_user_fringe_face_id
= face_id
;
3574 it
->right_user_fringe_bitmap
= XINT (value
);
3575 it
->right_user_fringe_face_id
= face_id
;
3577 #endif /* HAVE_WINDOW_SYSTEM */
3581 location
= Qunbound
;
3582 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3586 value
= XCDR (prop
);
3588 value
= XCAR (value
);
3591 if (EQ (XCAR (tem
), Qmargin
)
3592 && (tem
= XCDR (tem
),
3593 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3595 || EQ (tem
, Qleft_margin
)
3596 || EQ (tem
, Qright_margin
))))
3600 if (EQ (location
, Qunbound
))
3606 #ifdef HAVE_WINDOW_SYSTEM
3607 if (FRAME_TERMCAP_P (it
->f
))
3608 valid_p
= STRINGP (value
);
3610 valid_p
= (STRINGP (value
)
3611 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3612 || valid_image_p (value
));
3613 #else /* not HAVE_WINDOW_SYSTEM */
3614 valid_p
= STRINGP (value
);
3615 #endif /* not HAVE_WINDOW_SYSTEM */
3617 if ((EQ (location
, Qleft_margin
)
3618 || EQ (location
, Qright_margin
)
3621 && !display_replaced_before_p
)
3623 replaces_text_display_p
= 1;
3625 /* Save current settings of IT so that we can restore them
3626 when we are finished with the glyph property value. */
3629 if (NILP (location
))
3630 it
->area
= TEXT_AREA
;
3631 else if (EQ (location
, Qleft_margin
))
3632 it
->area
= LEFT_MARGIN_AREA
;
3634 it
->area
= RIGHT_MARGIN_AREA
;
3636 if (STRINGP (value
))
3639 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3640 it
->current
.overlay_string_index
= -1;
3641 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3642 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3643 it
->method
= next_element_from_string
;
3644 it
->stop_charpos
= 0;
3645 it
->string_from_display_prop_p
= 1;
3646 /* Say that we haven't consumed the characters with
3647 `display' property yet. The call to pop_it in
3648 set_iterator_to_next will clean this up. */
3649 *position
= start_pos
;
3651 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3653 it
->method
= next_element_from_stretch
;
3655 it
->current
.pos
= it
->position
= start_pos
;
3657 #ifdef HAVE_WINDOW_SYSTEM
3660 it
->what
= IT_IMAGE
;
3661 it
->image_id
= lookup_image (it
->f
, value
);
3662 it
->position
= start_pos
;
3663 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3664 it
->method
= next_element_from_image
;
3666 /* Say that we haven't consumed the characters with
3667 `display' property yet. The call to pop_it in
3668 set_iterator_to_next will clean this up. */
3669 *position
= start_pos
;
3671 #endif /* HAVE_WINDOW_SYSTEM */
3674 /* Invalid property or property not supported. Restore
3675 the position to what it was before. */
3676 *position
= start_pos
;
3679 return replaces_text_display_p
;
3683 /* Check if PROP is a display sub-property value whose text should be
3684 treated as intangible. */
3687 single_display_prop_intangible_p (prop
)
3690 /* Skip over `when FORM'. */
3691 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3705 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3706 we don't need to treat text as intangible. */
3707 if (EQ (XCAR (prop
), Qmargin
))
3715 || EQ (XCAR (prop
), Qleft_margin
)
3716 || EQ (XCAR (prop
), Qright_margin
))
3720 return (CONSP (prop
)
3721 && (EQ (XCAR (prop
), Qimage
)
3722 || EQ (XCAR (prop
), Qspace
)));
3726 /* Check if PROP is a display property value whose text should be
3727 treated as intangible. */
3730 display_prop_intangible_p (prop
)
3734 && CONSP (XCAR (prop
))
3735 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3737 /* A list of sub-properties. */
3738 while (CONSP (prop
))
3740 if (single_display_prop_intangible_p (XCAR (prop
)))
3745 else if (VECTORP (prop
))
3747 /* A vector of sub-properties. */
3749 for (i
= 0; i
< ASIZE (prop
); ++i
)
3750 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3754 return single_display_prop_intangible_p (prop
);
3760 /* Return 1 if PROP is a display sub-property value containing STRING. */
3763 single_display_prop_string_p (prop
, string
)
3764 Lisp_Object prop
, string
;
3766 if (EQ (string
, prop
))
3769 /* Skip over `when FORM'. */
3770 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3779 /* Skip over `margin LOCATION'. */
3780 if (EQ (XCAR (prop
), Qmargin
))
3791 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3795 /* Return 1 if STRING appears in the `display' property PROP. */
3798 display_prop_string_p (prop
, string
)
3799 Lisp_Object prop
, string
;
3802 && CONSP (XCAR (prop
))
3803 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3805 /* A list of sub-properties. */
3806 while (CONSP (prop
))
3808 if (single_display_prop_string_p (XCAR (prop
), string
))
3813 else if (VECTORP (prop
))
3815 /* A vector of sub-properties. */
3817 for (i
= 0; i
< ASIZE (prop
); ++i
)
3818 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3822 return single_display_prop_string_p (prop
, string
);
3828 /* Determine from which buffer position in W's buffer STRING comes
3829 from. AROUND_CHARPOS is an approximate position where it could
3830 be from. Value is the buffer position or 0 if it couldn't be
3833 W's buffer must be current.
3835 This function is necessary because we don't record buffer positions
3836 in glyphs generated from strings (to keep struct glyph small).
3837 This function may only use code that doesn't eval because it is
3838 called asynchronously from note_mouse_highlight. */
3841 string_buffer_position (w
, string
, around_charpos
)
3846 Lisp_Object limit
, prop
, pos
;
3847 const int MAX_DISTANCE
= 1000;
3850 pos
= make_number (around_charpos
);
3851 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3852 while (!found
&& !EQ (pos
, limit
))
3854 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3855 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3858 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3863 pos
= make_number (around_charpos
);
3864 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3865 while (!found
&& !EQ (pos
, limit
))
3867 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3868 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3871 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3876 return found
? XINT (pos
) : 0;
3881 /***********************************************************************
3882 `composition' property
3883 ***********************************************************************/
3885 /* Set up iterator IT from `composition' property at its current
3886 position. Called from handle_stop. */
3888 static enum prop_handled
3889 handle_composition_prop (it
)
3892 Lisp_Object prop
, string
;
3893 int pos
, pos_byte
, end
;
3894 enum prop_handled handled
= HANDLED_NORMALLY
;
3896 if (STRINGP (it
->string
))
3898 pos
= IT_STRING_CHARPOS (*it
);
3899 pos_byte
= IT_STRING_BYTEPOS (*it
);
3900 string
= it
->string
;
3904 pos
= IT_CHARPOS (*it
);
3905 pos_byte
= IT_BYTEPOS (*it
);
3909 /* If there's a valid composition and point is not inside of the
3910 composition (in the case that the composition is from the current
3911 buffer), draw a glyph composed from the composition components. */
3912 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3913 && COMPOSITION_VALID_P (pos
, end
, prop
)
3914 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3916 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3920 it
->method
= next_element_from_composition
;
3922 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3923 /* For a terminal, draw only the first character of the
3925 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3926 it
->len
= (STRINGP (it
->string
)
3927 ? string_char_to_byte (it
->string
, end
)
3928 : CHAR_TO_BYTE (end
)) - pos_byte
;
3929 it
->stop_charpos
= end
;
3930 handled
= HANDLED_RETURN
;
3939 /***********************************************************************
3941 ***********************************************************************/
3943 /* The following structure is used to record overlay strings for
3944 later sorting in load_overlay_strings. */
3946 struct overlay_entry
3948 Lisp_Object overlay
;
3955 /* Set up iterator IT from overlay strings at its current position.
3956 Called from handle_stop. */
3958 static enum prop_handled
3959 handle_overlay_change (it
)
3962 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3963 return HANDLED_RECOMPUTE_PROPS
;
3965 return HANDLED_NORMALLY
;
3969 /* Set up the next overlay string for delivery by IT, if there is an
3970 overlay string to deliver. Called by set_iterator_to_next when the
3971 end of the current overlay string is reached. If there are more
3972 overlay strings to display, IT->string and
3973 IT->current.overlay_string_index are set appropriately here.
3974 Otherwise IT->string is set to nil. */
3977 next_overlay_string (it
)
3980 ++it
->current
.overlay_string_index
;
3981 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3983 /* No more overlay strings. Restore IT's settings to what
3984 they were before overlay strings were processed, and
3985 continue to deliver from current_buffer. */
3986 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3989 xassert (it
->stop_charpos
>= BEGV
3990 && it
->stop_charpos
<= it
->end_charpos
);
3992 it
->current
.overlay_string_index
= -1;
3993 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3994 it
->n_overlay_strings
= 0;
3995 it
->method
= next_element_from_buffer
;
3997 /* If we're at the end of the buffer, record that we have
3998 processed the overlay strings there already, so that
3999 next_element_from_buffer doesn't try it again. */
4000 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4001 it
->overlay_strings_at_end_processed_p
= 1;
4003 /* If we have to display `...' for invisible text, set
4004 the iterator up for that. */
4005 if (display_ellipsis_p
)
4006 setup_for_ellipsis (it
);
4010 /* There are more overlay strings to process. If
4011 IT->current.overlay_string_index has advanced to a position
4012 where we must load IT->overlay_strings with more strings, do
4014 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4016 if (it
->current
.overlay_string_index
&& i
== 0)
4017 load_overlay_strings (it
, 0);
4019 /* Initialize IT to deliver display elements from the overlay
4021 it
->string
= it
->overlay_strings
[i
];
4022 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4023 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4024 it
->method
= next_element_from_string
;
4025 it
->stop_charpos
= 0;
4032 /* Compare two overlay_entry structures E1 and E2. Used as a
4033 comparison function for qsort in load_overlay_strings. Overlay
4034 strings for the same position are sorted so that
4036 1. All after-strings come in front of before-strings, except
4037 when they come from the same overlay.
4039 2. Within after-strings, strings are sorted so that overlay strings
4040 from overlays with higher priorities come first.
4042 2. Within before-strings, strings are sorted so that overlay
4043 strings from overlays with higher priorities come last.
4045 Value is analogous to strcmp. */
4049 compare_overlay_entries (e1
, e2
)
4052 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4053 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4056 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4058 /* Let after-strings appear in front of before-strings if
4059 they come from different overlays. */
4060 if (EQ (entry1
->overlay
, entry2
->overlay
))
4061 result
= entry1
->after_string_p
? 1 : -1;
4063 result
= entry1
->after_string_p
? -1 : 1;
4065 else if (entry1
->after_string_p
)
4066 /* After-strings sorted in order of decreasing priority. */
4067 result
= entry2
->priority
- entry1
->priority
;
4069 /* Before-strings sorted in order of increasing priority. */
4070 result
= entry1
->priority
- entry2
->priority
;
4076 /* Load the vector IT->overlay_strings with overlay strings from IT's
4077 current buffer position, or from CHARPOS if that is > 0. Set
4078 IT->n_overlays to the total number of overlay strings found.
4080 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4081 a time. On entry into load_overlay_strings,
4082 IT->current.overlay_string_index gives the number of overlay
4083 strings that have already been loaded by previous calls to this
4086 IT->add_overlay_start contains an additional overlay start
4087 position to consider for taking overlay strings from, if non-zero.
4088 This position comes into play when the overlay has an `invisible'
4089 property, and both before and after-strings. When we've skipped to
4090 the end of the overlay, because of its `invisible' property, we
4091 nevertheless want its before-string to appear.
4092 IT->add_overlay_start will contain the overlay start position
4095 Overlay strings are sorted so that after-string strings come in
4096 front of before-string strings. Within before and after-strings,
4097 strings are sorted by overlay priority. See also function
4098 compare_overlay_entries. */
4101 load_overlay_strings (it
, charpos
)
4105 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4106 Lisp_Object overlay
, window
, str
, invisible
;
4107 struct Lisp_Overlay
*ov
;
4110 int n
= 0, i
, j
, invis_p
;
4111 struct overlay_entry
*entries
4112 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4115 charpos
= IT_CHARPOS (*it
);
4117 /* Append the overlay string STRING of overlay OVERLAY to vector
4118 `entries' which has size `size' and currently contains `n'
4119 elements. AFTER_P non-zero means STRING is an after-string of
4121 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4124 Lisp_Object priority; \
4128 int new_size = 2 * size; \
4129 struct overlay_entry *old = entries; \
4131 (struct overlay_entry *) alloca (new_size \
4132 * sizeof *entries); \
4133 bcopy (old, entries, size * sizeof *entries); \
4137 entries[n].string = (STRING); \
4138 entries[n].overlay = (OVERLAY); \
4139 priority = Foverlay_get ((OVERLAY), Qpriority); \
4140 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4141 entries[n].after_string_p = (AFTER_P); \
4146 /* Process overlay before the overlay center. */
4147 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4149 XSETMISC (overlay
, ov
);
4150 xassert (OVERLAYP (overlay
));
4151 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4152 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4157 /* Skip this overlay if it doesn't start or end at IT's current
4159 if (end
!= charpos
&& start
!= charpos
)
4162 /* Skip this overlay if it doesn't apply to IT->w. */
4163 window
= Foverlay_get (overlay
, Qwindow
);
4164 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4167 /* If the text ``under'' the overlay is invisible, both before-
4168 and after-strings from this overlay are visible; start and
4169 end position are indistinguishable. */
4170 invisible
= Foverlay_get (overlay
, Qinvisible
);
4171 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4173 /* If overlay has a non-empty before-string, record it. */
4174 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4175 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4177 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4179 /* If overlay has a non-empty after-string, record it. */
4180 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4181 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4183 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4186 /* Process overlays after the overlay center. */
4187 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4189 XSETMISC (overlay
, ov
);
4190 xassert (OVERLAYP (overlay
));
4191 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4192 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4194 if (start
> charpos
)
4197 /* Skip this overlay if it doesn't start or end at IT's current
4199 if (end
!= charpos
&& start
!= charpos
)
4202 /* Skip this overlay if it doesn't apply to IT->w. */
4203 window
= Foverlay_get (overlay
, Qwindow
);
4204 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4207 /* If the text ``under'' the overlay is invisible, it has a zero
4208 dimension, and both before- and after-strings apply. */
4209 invisible
= Foverlay_get (overlay
, Qinvisible
);
4210 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4212 /* If overlay has a non-empty before-string, record it. */
4213 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4214 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4216 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4218 /* If overlay has a non-empty after-string, record it. */
4219 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4220 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4222 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4225 #undef RECORD_OVERLAY_STRING
4229 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4231 /* Record the total number of strings to process. */
4232 it
->n_overlay_strings
= n
;
4234 /* IT->current.overlay_string_index is the number of overlay strings
4235 that have already been consumed by IT. Copy some of the
4236 remaining overlay strings to IT->overlay_strings. */
4238 j
= it
->current
.overlay_string_index
;
4239 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4240 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4246 /* Get the first chunk of overlay strings at IT's current buffer
4247 position, or at CHARPOS if that is > 0. Value is non-zero if at
4248 least one overlay string was found. */
4251 get_overlay_strings (it
, charpos
)
4255 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4256 process. This fills IT->overlay_strings with strings, and sets
4257 IT->n_overlay_strings to the total number of strings to process.
4258 IT->pos.overlay_string_index has to be set temporarily to zero
4259 because load_overlay_strings needs this; it must be set to -1
4260 when no overlay strings are found because a zero value would
4261 indicate a position in the first overlay string. */
4262 it
->current
.overlay_string_index
= 0;
4263 load_overlay_strings (it
, charpos
);
4265 /* If we found overlay strings, set up IT to deliver display
4266 elements from the first one. Otherwise set up IT to deliver
4267 from current_buffer. */
4268 if (it
->n_overlay_strings
)
4270 /* Make sure we know settings in current_buffer, so that we can
4271 restore meaningful values when we're done with the overlay
4273 compute_stop_pos (it
);
4274 xassert (it
->face_id
>= 0);
4276 /* Save IT's settings. They are restored after all overlay
4277 strings have been processed. */
4278 xassert (it
->sp
== 0);
4281 /* Set up IT to deliver display elements from the first overlay
4283 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4284 it
->string
= it
->overlay_strings
[0];
4285 it
->stop_charpos
= 0;
4286 xassert (STRINGP (it
->string
));
4287 it
->end_charpos
= SCHARS (it
->string
);
4288 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4289 it
->method
= next_element_from_string
;
4294 it
->current
.overlay_string_index
= -1;
4295 it
->method
= next_element_from_buffer
;
4300 /* Value is non-zero if we found at least one overlay string. */
4301 return STRINGP (it
->string
);
4306 /***********************************************************************
4307 Saving and restoring state
4308 ***********************************************************************/
4310 /* Save current settings of IT on IT->stack. Called, for example,
4311 before setting up IT for an overlay string, to be able to restore
4312 IT's settings to what they were after the overlay string has been
4319 struct iterator_stack_entry
*p
;
4321 xassert (it
->sp
< 2);
4322 p
= it
->stack
+ it
->sp
;
4324 p
->stop_charpos
= it
->stop_charpos
;
4325 xassert (it
->face_id
>= 0);
4326 p
->face_id
= it
->face_id
;
4327 p
->string
= it
->string
;
4328 p
->pos
= it
->current
;
4329 p
->end_charpos
= it
->end_charpos
;
4330 p
->string_nchars
= it
->string_nchars
;
4332 p
->multibyte_p
= it
->multibyte_p
;
4333 p
->space_width
= it
->space_width
;
4334 p
->font_height
= it
->font_height
;
4335 p
->voffset
= it
->voffset
;
4336 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4337 p
->display_ellipsis_p
= 0;
4342 /* Restore IT's settings from IT->stack. Called, for example, when no
4343 more overlay strings must be processed, and we return to delivering
4344 display elements from a buffer, or when the end of a string from a
4345 `display' property is reached and we return to delivering display
4346 elements from an overlay string, or from a buffer. */
4352 struct iterator_stack_entry
*p
;
4354 xassert (it
->sp
> 0);
4356 p
= it
->stack
+ it
->sp
;
4357 it
->stop_charpos
= p
->stop_charpos
;
4358 it
->face_id
= p
->face_id
;
4359 it
->string
= p
->string
;
4360 it
->current
= p
->pos
;
4361 it
->end_charpos
= p
->end_charpos
;
4362 it
->string_nchars
= p
->string_nchars
;
4364 it
->multibyte_p
= p
->multibyte_p
;
4365 it
->space_width
= p
->space_width
;
4366 it
->font_height
= p
->font_height
;
4367 it
->voffset
= p
->voffset
;
4368 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4373 /***********************************************************************
4375 ***********************************************************************/
4377 /* Set IT's current position to the previous line start. */
4380 back_to_previous_line_start (it
)
4383 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4384 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4388 /* Move IT to the next line start.
4390 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4391 we skipped over part of the text (as opposed to moving the iterator
4392 continuously over the text). Otherwise, don't change the value
4395 Newlines may come from buffer text, overlay strings, or strings
4396 displayed via the `display' property. That's the reason we can't
4397 simply use find_next_newline_no_quit.
4399 Note that this function may not skip over invisible text that is so
4400 because of text properties and immediately follows a newline. If
4401 it would, function reseat_at_next_visible_line_start, when called
4402 from set_iterator_to_next, would effectively make invisible
4403 characters following a newline part of the wrong glyph row, which
4404 leads to wrong cursor motion. */
4407 forward_to_next_line_start (it
, skipped_p
)
4411 int old_selective
, newline_found_p
, n
;
4412 const int MAX_NEWLINE_DISTANCE
= 500;
4414 /* If already on a newline, just consume it to avoid unintended
4415 skipping over invisible text below. */
4416 if (it
->what
== IT_CHARACTER
4418 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4420 set_iterator_to_next (it
, 0);
4425 /* Don't handle selective display in the following. It's (a)
4426 unnecessary because it's done by the caller, and (b) leads to an
4427 infinite recursion because next_element_from_ellipsis indirectly
4428 calls this function. */
4429 old_selective
= it
->selective
;
4432 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4433 from buffer text. */
4434 for (n
= newline_found_p
= 0;
4435 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4436 n
+= STRINGP (it
->string
) ? 0 : 1)
4438 if (!get_next_display_element (it
))
4440 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4441 set_iterator_to_next (it
, 0);
4444 /* If we didn't find a newline near enough, see if we can use a
4446 if (!newline_found_p
)
4448 int start
= IT_CHARPOS (*it
);
4449 int limit
= find_next_newline_no_quit (start
, 1);
4452 xassert (!STRINGP (it
->string
));
4454 /* If there isn't any `display' property in sight, and no
4455 overlays, we can just use the position of the newline in
4457 if (it
->stop_charpos
>= limit
4458 || ((pos
= Fnext_single_property_change (make_number (start
),
4460 Qnil
, make_number (limit
)),
4462 && next_overlay_change (start
) == ZV
))
4464 IT_CHARPOS (*it
) = limit
;
4465 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4466 *skipped_p
= newline_found_p
= 1;
4470 while (get_next_display_element (it
)
4471 && !newline_found_p
)
4473 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4474 set_iterator_to_next (it
, 0);
4479 it
->selective
= old_selective
;
4480 return newline_found_p
;
4484 /* Set IT's current position to the previous visible line start. Skip
4485 invisible text that is so either due to text properties or due to
4486 selective display. Caution: this does not change IT->current_x and
4490 back_to_previous_visible_line_start (it
)
4495 /* Go back one newline if not on BEGV already. */
4496 if (IT_CHARPOS (*it
) > BEGV
)
4497 back_to_previous_line_start (it
);
4499 /* Move over lines that are invisible because of selective display
4500 or text properties. */
4501 while (IT_CHARPOS (*it
) > BEGV
4506 /* If selective > 0, then lines indented more than that values
4508 if (it
->selective
> 0
4509 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4510 (double) it
->selective
)) /* iftc */
4516 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4517 Qinvisible
, it
->window
);
4518 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4522 /* Back one more newline if the current one is invisible. */
4524 back_to_previous_line_start (it
);
4527 xassert (IT_CHARPOS (*it
) >= BEGV
);
4528 xassert (IT_CHARPOS (*it
) == BEGV
4529 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4534 /* Reseat iterator IT at the previous visible line start. Skip
4535 invisible text that is so either due to text properties or due to
4536 selective display. At the end, update IT's overlay information,
4537 face information etc. */
4540 reseat_at_previous_visible_line_start (it
)
4543 back_to_previous_visible_line_start (it
);
4544 reseat (it
, it
->current
.pos
, 1);
4549 /* Reseat iterator IT on the next visible line start in the current
4550 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4551 preceding the line start. Skip over invisible text that is so
4552 because of selective display. Compute faces, overlays etc at the
4553 new position. Note that this function does not skip over text that
4554 is invisible because of text properties. */
4557 reseat_at_next_visible_line_start (it
, on_newline_p
)
4561 int newline_found_p
, skipped_p
= 0;
4563 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4565 /* Skip over lines that are invisible because they are indented
4566 more than the value of IT->selective. */
4567 if (it
->selective
> 0)
4568 while (IT_CHARPOS (*it
) < ZV
4569 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4570 (double) it
->selective
)) /* iftc */
4572 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4573 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4576 /* Position on the newline if that's what's requested. */
4577 if (on_newline_p
&& newline_found_p
)
4579 if (STRINGP (it
->string
))
4581 if (IT_STRING_CHARPOS (*it
) > 0)
4583 --IT_STRING_CHARPOS (*it
);
4584 --IT_STRING_BYTEPOS (*it
);
4587 else if (IT_CHARPOS (*it
) > BEGV
)
4591 reseat (it
, it
->current
.pos
, 0);
4595 reseat (it
, it
->current
.pos
, 0);
4602 /***********************************************************************
4603 Changing an iterator's position
4604 ***********************************************************************/
4606 /* Change IT's current position to POS in current_buffer. If FORCE_P
4607 is non-zero, always check for text properties at the new position.
4608 Otherwise, text properties are only looked up if POS >=
4609 IT->check_charpos of a property. */
4612 reseat (it
, pos
, force_p
)
4614 struct text_pos pos
;
4617 int original_pos
= IT_CHARPOS (*it
);
4619 reseat_1 (it
, pos
, 0);
4621 /* Determine where to check text properties. Avoid doing it
4622 where possible because text property lookup is very expensive. */
4624 || CHARPOS (pos
) > it
->stop_charpos
4625 || CHARPOS (pos
) < original_pos
)
4632 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4633 IT->stop_pos to POS, also. */
4636 reseat_1 (it
, pos
, set_stop_p
)
4638 struct text_pos pos
;
4641 /* Don't call this function when scanning a C string. */
4642 xassert (it
->s
== NULL
);
4644 /* POS must be a reasonable value. */
4645 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4647 it
->current
.pos
= it
->position
= pos
;
4648 XSETBUFFER (it
->object
, current_buffer
);
4649 it
->end_charpos
= ZV
;
4651 it
->current
.dpvec_index
= -1;
4652 it
->current
.overlay_string_index
= -1;
4653 IT_STRING_CHARPOS (*it
) = -1;
4654 IT_STRING_BYTEPOS (*it
) = -1;
4656 it
->method
= next_element_from_buffer
;
4657 /* RMS: I added this to fix a bug in move_it_vertically_backward
4658 where it->area continued to relate to the starting point
4659 for the backward motion. Bug report from
4660 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4661 However, I am not sure whether reseat still does the right thing
4662 in general after this change. */
4663 it
->area
= TEXT_AREA
;
4664 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4666 it
->face_before_selective_p
= 0;
4669 it
->stop_charpos
= CHARPOS (pos
);
4673 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4674 If S is non-null, it is a C string to iterate over. Otherwise,
4675 STRING gives a Lisp string to iterate over.
4677 If PRECISION > 0, don't return more then PRECISION number of
4678 characters from the string.
4680 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4681 characters have been returned. FIELD_WIDTH < 0 means an infinite
4684 MULTIBYTE = 0 means disable processing of multibyte characters,
4685 MULTIBYTE > 0 means enable it,
4686 MULTIBYTE < 0 means use IT->multibyte_p.
4688 IT must be initialized via a prior call to init_iterator before
4689 calling this function. */
4692 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4697 int precision
, field_width
, multibyte
;
4699 /* No region in strings. */
4700 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4702 /* No text property checks performed by default, but see below. */
4703 it
->stop_charpos
= -1;
4705 /* Set iterator position and end position. */
4706 bzero (&it
->current
, sizeof it
->current
);
4707 it
->current
.overlay_string_index
= -1;
4708 it
->current
.dpvec_index
= -1;
4709 xassert (charpos
>= 0);
4711 /* If STRING is specified, use its multibyteness, otherwise use the
4712 setting of MULTIBYTE, if specified. */
4714 it
->multibyte_p
= multibyte
> 0;
4718 xassert (STRINGP (string
));
4719 it
->string
= string
;
4721 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4722 it
->method
= next_element_from_string
;
4723 it
->current
.string_pos
= string_pos (charpos
, string
);
4730 /* Note that we use IT->current.pos, not it->current.string_pos,
4731 for displaying C strings. */
4732 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4733 if (it
->multibyte_p
)
4735 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4736 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4740 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4741 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4744 it
->method
= next_element_from_c_string
;
4747 /* PRECISION > 0 means don't return more than PRECISION characters
4749 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4750 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4752 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4753 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4754 FIELD_WIDTH < 0 means infinite field width. This is useful for
4755 padding with `-' at the end of a mode line. */
4756 if (field_width
< 0)
4757 field_width
= INFINITY
;
4758 if (field_width
> it
->end_charpos
- charpos
)
4759 it
->end_charpos
= charpos
+ field_width
;
4761 /* Use the standard display table for displaying strings. */
4762 if (DISP_TABLE_P (Vstandard_display_table
))
4763 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4765 it
->stop_charpos
= charpos
;
4771 /***********************************************************************
4773 ***********************************************************************/
4775 /* Load IT's display element fields with information about the next
4776 display element from the current position of IT. Value is zero if
4777 end of buffer (or C string) is reached. */
4780 get_next_display_element (it
)
4783 /* Non-zero means that we found a display element. Zero means that
4784 we hit the end of what we iterate over. Performance note: the
4785 function pointer `method' used here turns out to be faster than
4786 using a sequence of if-statements. */
4787 int success_p
= (*it
->method
) (it
);
4789 if (it
->what
== IT_CHARACTER
)
4791 /* Map via display table or translate control characters.
4792 IT->c, IT->len etc. have been set to the next character by
4793 the function call above. If we have a display table, and it
4794 contains an entry for IT->c, translate it. Don't do this if
4795 IT->c itself comes from a display table, otherwise we could
4796 end up in an infinite recursion. (An alternative could be to
4797 count the recursion depth of this function and signal an
4798 error when a certain maximum depth is reached.) Is it worth
4800 if (success_p
&& it
->dpvec
== NULL
)
4805 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4808 struct Lisp_Vector
*v
= XVECTOR (dv
);
4810 /* Return the first character from the display table
4811 entry, if not empty. If empty, don't display the
4812 current character. */
4815 it
->dpvec_char_len
= it
->len
;
4816 it
->dpvec
= v
->contents
;
4817 it
->dpend
= v
->contents
+ v
->size
;
4818 it
->current
.dpvec_index
= 0;
4819 it
->method
= next_element_from_display_vector
;
4820 success_p
= get_next_display_element (it
);
4824 set_iterator_to_next (it
, 0);
4825 success_p
= get_next_display_element (it
);
4829 /* Translate control characters into `\003' or `^C' form.
4830 Control characters coming from a display table entry are
4831 currently not translated because we use IT->dpvec to hold
4832 the translation. This could easily be changed but I
4833 don't believe that it is worth doing.
4835 If it->multibyte_p is nonzero, eight-bit characters and
4836 non-printable multibyte characters are also translated to
4839 If it->multibyte_p is zero, eight-bit characters that
4840 don't have corresponding multibyte char code are also
4841 translated to octal form. */
4842 else if ((it
->c
< ' '
4843 && (it
->area
!= TEXT_AREA
4844 || (it
->c
!= '\n' && it
->c
!= '\t')))
4848 || !CHAR_PRINTABLE_P (it
->c
))
4850 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4852 /* IT->c is a control character which must be displayed
4853 either as '\003' or as `^C' where the '\\' and '^'
4854 can be defined in the display table. Fill
4855 IT->ctl_chars with glyphs for what we have to
4856 display. Then, set IT->dpvec to these glyphs. */
4859 if (it
->c
< 128 && it
->ctl_arrow_p
)
4861 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4863 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4864 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4865 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4867 g
= FAST_MAKE_GLYPH ('^', 0);
4868 XSETINT (it
->ctl_chars
[0], g
);
4870 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4871 XSETINT (it
->ctl_chars
[1], g
);
4873 /* Set up IT->dpvec and return first character from it. */
4874 it
->dpvec_char_len
= it
->len
;
4875 it
->dpvec
= it
->ctl_chars
;
4876 it
->dpend
= it
->dpvec
+ 2;
4877 it
->current
.dpvec_index
= 0;
4878 it
->method
= next_element_from_display_vector
;
4879 get_next_display_element (it
);
4883 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4888 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4890 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4891 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4892 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4894 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4896 if (SINGLE_BYTE_CHAR_P (it
->c
))
4897 str
[0] = it
->c
, len
= 1;
4900 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4903 /* It's an invalid character, which
4904 shouldn't happen actually, but due to
4905 bugs it may happen. Let's print the char
4906 as is, there's not much meaningful we can
4909 str
[1] = it
->c
>> 8;
4910 str
[2] = it
->c
>> 16;
4911 str
[3] = it
->c
>> 24;
4916 for (i
= 0; i
< len
; i
++)
4918 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4919 /* Insert three more glyphs into IT->ctl_chars for
4920 the octal display of the character. */
4921 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4922 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4923 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4924 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4925 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4926 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4929 /* Set up IT->dpvec and return the first character
4931 it
->dpvec_char_len
= it
->len
;
4932 it
->dpvec
= it
->ctl_chars
;
4933 it
->dpend
= it
->dpvec
+ len
* 4;
4934 it
->current
.dpvec_index
= 0;
4935 it
->method
= next_element_from_display_vector
;
4936 get_next_display_element (it
);
4941 /* Adjust face id for a multibyte character. There are no
4942 multibyte character in unibyte text. */
4945 && FRAME_WINDOW_P (it
->f
))
4947 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4948 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4952 /* Is this character the last one of a run of characters with
4953 box? If yes, set IT->end_of_box_run_p to 1. */
4960 it
->end_of_box_run_p
4961 = ((face_id
= face_after_it_pos (it
),
4962 face_id
!= it
->face_id
)
4963 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4964 face
->box
== FACE_NO_BOX
));
4967 /* Value is 0 if end of buffer or string reached. */
4972 /* Move IT to the next display element.
4974 RESEAT_P non-zero means if called on a newline in buffer text,
4975 skip to the next visible line start.
4977 Functions get_next_display_element and set_iterator_to_next are
4978 separate because I find this arrangement easier to handle than a
4979 get_next_display_element function that also increments IT's
4980 position. The way it is we can first look at an iterator's current
4981 display element, decide whether it fits on a line, and if it does,
4982 increment the iterator position. The other way around we probably
4983 would either need a flag indicating whether the iterator has to be
4984 incremented the next time, or we would have to implement a
4985 decrement position function which would not be easy to write. */
4988 set_iterator_to_next (it
, reseat_p
)
4992 /* Reset flags indicating start and end of a sequence of characters
4993 with box. Reset them at the start of this function because
4994 moving the iterator to a new position might set them. */
4995 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4997 if (it
->method
== next_element_from_buffer
)
4999 /* The current display element of IT is a character from
5000 current_buffer. Advance in the buffer, and maybe skip over
5001 invisible lines that are so because of selective display. */
5002 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5003 reseat_at_next_visible_line_start (it
, 0);
5006 xassert (it
->len
!= 0);
5007 IT_BYTEPOS (*it
) += it
->len
;
5008 IT_CHARPOS (*it
) += 1;
5009 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5012 else if (it
->method
== next_element_from_composition
)
5014 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5015 if (STRINGP (it
->string
))
5017 IT_STRING_BYTEPOS (*it
) += it
->len
;
5018 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5019 it
->method
= next_element_from_string
;
5020 goto consider_string_end
;
5024 IT_BYTEPOS (*it
) += it
->len
;
5025 IT_CHARPOS (*it
) += it
->cmp_len
;
5026 it
->method
= next_element_from_buffer
;
5029 else if (it
->method
== next_element_from_c_string
)
5031 /* Current display element of IT is from a C string. */
5032 IT_BYTEPOS (*it
) += it
->len
;
5033 IT_CHARPOS (*it
) += 1;
5035 else if (it
->method
== next_element_from_display_vector
)
5037 /* Current display element of IT is from a display table entry.
5038 Advance in the display table definition. Reset it to null if
5039 end reached, and continue with characters from buffers/
5041 ++it
->current
.dpvec_index
;
5043 /* Restore face of the iterator to what they were before the
5044 display vector entry (these entries may contain faces). */
5045 it
->face_id
= it
->saved_face_id
;
5047 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5050 it
->method
= next_element_from_c_string
;
5051 else if (STRINGP (it
->string
))
5052 it
->method
= next_element_from_string
;
5054 it
->method
= next_element_from_buffer
;
5057 it
->current
.dpvec_index
= -1;
5059 /* Skip over characters which were displayed via IT->dpvec. */
5060 if (it
->dpvec_char_len
< 0)
5061 reseat_at_next_visible_line_start (it
, 1);
5062 else if (it
->dpvec_char_len
> 0)
5064 it
->len
= it
->dpvec_char_len
;
5065 set_iterator_to_next (it
, reseat_p
);
5069 else if (it
->method
== next_element_from_string
)
5071 /* Current display element is a character from a Lisp string. */
5072 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5073 IT_STRING_BYTEPOS (*it
) += it
->len
;
5074 IT_STRING_CHARPOS (*it
) += 1;
5076 consider_string_end
:
5078 if (it
->current
.overlay_string_index
>= 0)
5080 /* IT->string is an overlay string. Advance to the
5081 next, if there is one. */
5082 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5083 next_overlay_string (it
);
5087 /* IT->string is not an overlay string. If we reached
5088 its end, and there is something on IT->stack, proceed
5089 with what is on the stack. This can be either another
5090 string, this time an overlay string, or a buffer. */
5091 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5095 if (!STRINGP (it
->string
))
5096 it
->method
= next_element_from_buffer
;
5098 goto consider_string_end
;
5102 else if (it
->method
== next_element_from_image
5103 || it
->method
== next_element_from_stretch
)
5105 /* The position etc with which we have to proceed are on
5106 the stack. The position may be at the end of a string,
5107 if the `display' property takes up the whole string. */
5110 if (STRINGP (it
->string
))
5112 it
->method
= next_element_from_string
;
5113 goto consider_string_end
;
5116 it
->method
= next_element_from_buffer
;
5119 /* There are no other methods defined, so this should be a bug. */
5122 xassert (it
->method
!= next_element_from_string
5123 || (STRINGP (it
->string
)
5124 && IT_STRING_CHARPOS (*it
) >= 0));
5128 /* Load IT's display element fields with information about the next
5129 display element which comes from a display table entry or from the
5130 result of translating a control character to one of the forms `^C'
5131 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5134 next_element_from_display_vector (it
)
5138 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5140 /* Remember the current face id in case glyphs specify faces.
5141 IT's face is restored in set_iterator_to_next. */
5142 it
->saved_face_id
= it
->face_id
;
5144 if (INTEGERP (*it
->dpvec
)
5145 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5150 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5151 it
->c
= FAST_GLYPH_CHAR (g
);
5152 it
->len
= CHAR_BYTES (it
->c
);
5154 /* The entry may contain a face id to use. Such a face id is
5155 the id of a Lisp face, not a realized face. A face id of
5156 zero means no face is specified. */
5157 lface_id
= FAST_GLYPH_FACE (g
);
5160 /* The function returns -1 if lface_id is invalid. */
5161 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5163 it
->face_id
= face_id
;
5167 /* Display table entry is invalid. Return a space. */
5168 it
->c
= ' ', it
->len
= 1;
5170 /* Don't change position and object of the iterator here. They are
5171 still the values of the character that had this display table
5172 entry or was translated, and that's what we want. */
5173 it
->what
= IT_CHARACTER
;
5178 /* Load IT with the next display element from Lisp string IT->string.
5179 IT->current.string_pos is the current position within the string.
5180 If IT->current.overlay_string_index >= 0, the Lisp string is an
5184 next_element_from_string (it
)
5187 struct text_pos position
;
5189 xassert (STRINGP (it
->string
));
5190 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5191 position
= it
->current
.string_pos
;
5193 /* Time to check for invisible text? */
5194 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5195 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5199 /* Since a handler may have changed IT->method, we must
5201 return get_next_display_element (it
);
5204 if (it
->current
.overlay_string_index
>= 0)
5206 /* Get the next character from an overlay string. In overlay
5207 strings, There is no field width or padding with spaces to
5209 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5214 else if (STRING_MULTIBYTE (it
->string
))
5216 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5217 const unsigned char *s
= (SDATA (it
->string
)
5218 + IT_STRING_BYTEPOS (*it
));
5219 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5223 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5229 /* Get the next character from a Lisp string that is not an
5230 overlay string. Such strings come from the mode line, for
5231 example. We may have to pad with spaces, or truncate the
5232 string. See also next_element_from_c_string. */
5233 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5238 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5240 /* Pad with spaces. */
5241 it
->c
= ' ', it
->len
= 1;
5242 CHARPOS (position
) = BYTEPOS (position
) = -1;
5244 else if (STRING_MULTIBYTE (it
->string
))
5246 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5247 const unsigned char *s
= (SDATA (it
->string
)
5248 + IT_STRING_BYTEPOS (*it
));
5249 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5253 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5258 /* Record what we have and where it came from. Note that we store a
5259 buffer position in IT->position although it could arguably be a
5261 it
->what
= IT_CHARACTER
;
5262 it
->object
= it
->string
;
5263 it
->position
= position
;
5268 /* Load IT with next display element from C string IT->s.
5269 IT->string_nchars is the maximum number of characters to return
5270 from the string. IT->end_charpos may be greater than
5271 IT->string_nchars when this function is called, in which case we
5272 may have to return padding spaces. Value is zero if end of string
5273 reached, including padding spaces. */
5276 next_element_from_c_string (it
)
5282 it
->what
= IT_CHARACTER
;
5283 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5286 /* IT's position can be greater IT->string_nchars in case a field
5287 width or precision has been specified when the iterator was
5289 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5291 /* End of the game. */
5295 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5297 /* Pad with spaces. */
5298 it
->c
= ' ', it
->len
= 1;
5299 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5301 else if (it
->multibyte_p
)
5303 /* Implementation note: The calls to strlen apparently aren't a
5304 performance problem because there is no noticeable performance
5305 difference between Emacs running in unibyte or multibyte mode. */
5306 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5307 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5311 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5317 /* Set up IT to return characters from an ellipsis, if appropriate.
5318 The definition of the ellipsis glyphs may come from a display table
5319 entry. This function Fills IT with the first glyph from the
5320 ellipsis if an ellipsis is to be displayed. */
5323 next_element_from_ellipsis (it
)
5326 if (it
->selective_display_ellipsis_p
)
5328 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5330 /* Use the display table definition for `...'. Invalid glyphs
5331 will be handled by the method returning elements from dpvec. */
5332 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5333 it
->dpvec_char_len
= it
->len
;
5334 it
->dpvec
= v
->contents
;
5335 it
->dpend
= v
->contents
+ v
->size
;
5336 it
->current
.dpvec_index
= 0;
5337 it
->method
= next_element_from_display_vector
;
5341 /* Use default `...' which is stored in default_invis_vector. */
5342 it
->dpvec_char_len
= it
->len
;
5343 it
->dpvec
= default_invis_vector
;
5344 it
->dpend
= default_invis_vector
+ 3;
5345 it
->current
.dpvec_index
= 0;
5346 it
->method
= next_element_from_display_vector
;
5351 /* The face at the current position may be different from the
5352 face we find after the invisible text. Remember what it
5353 was in IT->saved_face_id, and signal that it's there by
5354 setting face_before_selective_p. */
5355 it
->saved_face_id
= it
->face_id
;
5356 it
->method
= next_element_from_buffer
;
5357 reseat_at_next_visible_line_start (it
, 1);
5358 it
->face_before_selective_p
= 1;
5361 return get_next_display_element (it
);
5365 /* Deliver an image display element. The iterator IT is already
5366 filled with image information (done in handle_display_prop). Value
5371 next_element_from_image (it
)
5374 it
->what
= IT_IMAGE
;
5379 /* Fill iterator IT with next display element from a stretch glyph
5380 property. IT->object is the value of the text property. Value is
5384 next_element_from_stretch (it
)
5387 it
->what
= IT_STRETCH
;
5392 /* Load IT with the next display element from current_buffer. Value
5393 is zero if end of buffer reached. IT->stop_charpos is the next
5394 position at which to stop and check for text properties or buffer
5398 next_element_from_buffer (it
)
5403 /* Check this assumption, otherwise, we would never enter the
5404 if-statement, below. */
5405 xassert (IT_CHARPOS (*it
) >= BEGV
5406 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5408 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5410 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5412 int overlay_strings_follow_p
;
5414 /* End of the game, except when overlay strings follow that
5415 haven't been returned yet. */
5416 if (it
->overlay_strings_at_end_processed_p
)
5417 overlay_strings_follow_p
= 0;
5420 it
->overlay_strings_at_end_processed_p
= 1;
5421 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5424 if (overlay_strings_follow_p
)
5425 success_p
= get_next_display_element (it
);
5429 it
->position
= it
->current
.pos
;
5436 return get_next_display_element (it
);
5441 /* No face changes, overlays etc. in sight, so just return a
5442 character from current_buffer. */
5445 /* Maybe run the redisplay end trigger hook. Performance note:
5446 This doesn't seem to cost measurable time. */
5447 if (it
->redisplay_end_trigger_charpos
5449 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5450 run_redisplay_end_trigger_hook (it
);
5452 /* Get the next character, maybe multibyte. */
5453 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5454 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5456 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5457 - IT_BYTEPOS (*it
));
5458 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5461 it
->c
= *p
, it
->len
= 1;
5463 /* Record what we have and where it came from. */
5464 it
->what
= IT_CHARACTER
;;
5465 it
->object
= it
->w
->buffer
;
5466 it
->position
= it
->current
.pos
;
5468 /* Normally we return the character found above, except when we
5469 really want to return an ellipsis for selective display. */
5474 /* A value of selective > 0 means hide lines indented more
5475 than that number of columns. */
5476 if (it
->selective
> 0
5477 && IT_CHARPOS (*it
) + 1 < ZV
5478 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5479 IT_BYTEPOS (*it
) + 1,
5480 (double) it
->selective
)) /* iftc */
5482 success_p
= next_element_from_ellipsis (it
);
5483 it
->dpvec_char_len
= -1;
5486 else if (it
->c
== '\r' && it
->selective
== -1)
5488 /* A value of selective == -1 means that everything from the
5489 CR to the end of the line is invisible, with maybe an
5490 ellipsis displayed for it. */
5491 success_p
= next_element_from_ellipsis (it
);
5492 it
->dpvec_char_len
= -1;
5497 /* Value is zero if end of buffer reached. */
5498 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5503 /* Run the redisplay end trigger hook for IT. */
5506 run_redisplay_end_trigger_hook (it
)
5509 Lisp_Object args
[3];
5511 /* IT->glyph_row should be non-null, i.e. we should be actually
5512 displaying something, or otherwise we should not run the hook. */
5513 xassert (it
->glyph_row
);
5515 /* Set up hook arguments. */
5516 args
[0] = Qredisplay_end_trigger_functions
;
5517 args
[1] = it
->window
;
5518 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5519 it
->redisplay_end_trigger_charpos
= 0;
5521 /* Since we are *trying* to run these functions, don't try to run
5522 them again, even if they get an error. */
5523 it
->w
->redisplay_end_trigger
= Qnil
;
5524 Frun_hook_with_args (3, args
);
5526 /* Notice if it changed the face of the character we are on. */
5527 handle_face_prop (it
);
5531 /* Deliver a composition display element. The iterator IT is already
5532 filled with composition information (done in
5533 handle_composition_prop). Value is always 1. */
5536 next_element_from_composition (it
)
5539 it
->what
= IT_COMPOSITION
;
5540 it
->position
= (STRINGP (it
->string
)
5541 ? it
->current
.string_pos
5548 /***********************************************************************
5549 Moving an iterator without producing glyphs
5550 ***********************************************************************/
5552 /* Move iterator IT to a specified buffer or X position within one
5553 line on the display without producing glyphs.
5555 OP should be a bit mask including some or all of these bits:
5556 MOVE_TO_X: Stop on reaching x-position TO_X.
5557 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5558 Regardless of OP's value, stop in reaching the end of the display line.
5560 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5561 This means, in particular, that TO_X includes window's horizontal
5564 The return value has several possible values that
5565 say what condition caused the scan to stop:
5567 MOVE_POS_MATCH_OR_ZV
5568 - when TO_POS or ZV was reached.
5571 -when TO_X was reached before TO_POS or ZV were reached.
5574 - when we reached the end of the display area and the line must
5578 - when we reached the end of the display area and the line is
5582 - when we stopped at a line end, i.e. a newline or a CR and selective
5585 static enum move_it_result
5586 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5588 int to_charpos
, to_x
, op
;
5590 enum move_it_result result
= MOVE_UNDEFINED
;
5591 struct glyph_row
*saved_glyph_row
;
5593 /* Don't produce glyphs in produce_glyphs. */
5594 saved_glyph_row
= it
->glyph_row
;
5595 it
->glyph_row
= NULL
;
5599 int x
, i
, ascent
= 0, descent
= 0;
5601 /* Stop when ZV or TO_CHARPOS reached. */
5602 if (!get_next_display_element (it
)
5603 || ((op
& MOVE_TO_POS
) != 0
5604 && BUFFERP (it
->object
)
5605 && IT_CHARPOS (*it
) >= to_charpos
))
5607 result
= MOVE_POS_MATCH_OR_ZV
;
5611 /* The call to produce_glyphs will get the metrics of the
5612 display element IT is loaded with. We record in x the
5613 x-position before this display element in case it does not
5617 /* Remember the line height so far in case the next element doesn't
5619 if (!it
->truncate_lines_p
)
5621 ascent
= it
->max_ascent
;
5622 descent
= it
->max_descent
;
5625 PRODUCE_GLYPHS (it
);
5627 if (it
->area
!= TEXT_AREA
)
5629 set_iterator_to_next (it
, 1);
5633 /* The number of glyphs we get back in IT->nglyphs will normally
5634 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5635 character on a terminal frame, or (iii) a line end. For the
5636 second case, IT->nglyphs - 1 padding glyphs will be present
5637 (on X frames, there is only one glyph produced for a
5638 composite character.
5640 The behavior implemented below means, for continuation lines,
5641 that as many spaces of a TAB as fit on the current line are
5642 displayed there. For terminal frames, as many glyphs of a
5643 multi-glyph character are displayed in the current line, too.
5644 This is what the old redisplay code did, and we keep it that
5645 way. Under X, the whole shape of a complex character must
5646 fit on the line or it will be completely displayed in the
5649 Note that both for tabs and padding glyphs, all glyphs have
5653 /* More than one glyph or glyph doesn't fit on line. All
5654 glyphs have the same width. */
5655 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5658 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5660 new_x
= x
+ single_glyph_width
;
5662 /* We want to leave anything reaching TO_X to the caller. */
5663 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5666 result
= MOVE_X_REACHED
;
5669 else if (/* Lines are continued. */
5670 !it
->truncate_lines_p
5671 && (/* And glyph doesn't fit on the line. */
5672 new_x
> it
->last_visible_x
5673 /* Or it fits exactly and we're on a window
5675 || (new_x
== it
->last_visible_x
5676 && FRAME_WINDOW_P (it
->f
))))
5678 if (/* IT->hpos == 0 means the very first glyph
5679 doesn't fit on the line, e.g. a wide image. */
5681 || (new_x
== it
->last_visible_x
5682 && FRAME_WINDOW_P (it
->f
)))
5685 it
->current_x
= new_x
;
5686 if (i
== it
->nglyphs
- 1)
5688 set_iterator_to_next (it
, 1);
5689 #ifdef HAVE_WINDOW_SYSTEM
5690 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5692 if (!get_next_display_element (it
))
5694 result
= MOVE_POS_MATCH_OR_ZV
;
5697 if (ITERATOR_AT_END_OF_LINE_P (it
))
5699 result
= MOVE_NEWLINE_OR_CR
;
5703 #endif /* HAVE_WINDOW_SYSTEM */
5709 it
->max_ascent
= ascent
;
5710 it
->max_descent
= descent
;
5713 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5715 result
= MOVE_LINE_CONTINUED
;
5718 else if (new_x
> it
->first_visible_x
)
5720 /* Glyph is visible. Increment number of glyphs that
5721 would be displayed. */
5726 /* Glyph is completely off the left margin of the display
5727 area. Nothing to do. */
5731 if (result
!= MOVE_UNDEFINED
)
5734 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5736 /* Stop when TO_X specified and reached. This check is
5737 necessary here because of lines consisting of a line end,
5738 only. The line end will not produce any glyphs and we
5739 would never get MOVE_X_REACHED. */
5740 xassert (it
->nglyphs
== 0);
5741 result
= MOVE_X_REACHED
;
5745 /* Is this a line end? If yes, we're done. */
5746 if (ITERATOR_AT_END_OF_LINE_P (it
))
5748 result
= MOVE_NEWLINE_OR_CR
;
5752 /* The current display element has been consumed. Advance
5754 set_iterator_to_next (it
, 1);
5756 /* Stop if lines are truncated and IT's current x-position is
5757 past the right edge of the window now. */
5758 if (it
->truncate_lines_p
5759 && it
->current_x
>= it
->last_visible_x
)
5761 #ifdef HAVE_WINDOW_SYSTEM
5762 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5764 if (!get_next_display_element (it
))
5766 result
= MOVE_POS_MATCH_OR_ZV
;
5769 if (ITERATOR_AT_END_OF_LINE_P (it
))
5771 result
= MOVE_NEWLINE_OR_CR
;
5775 #endif /* HAVE_WINDOW_SYSTEM */
5776 result
= MOVE_LINE_TRUNCATED
;
5781 /* Restore the iterator settings altered at the beginning of this
5783 it
->glyph_row
= saved_glyph_row
;
5788 /* Move IT forward until it satisfies one or more of the criteria in
5789 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5791 OP is a bit-mask that specifies where to stop, and in particular,
5792 which of those four position arguments makes a difference. See the
5793 description of enum move_operation_enum.
5795 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5796 screen line, this function will set IT to the next position >
5800 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5802 int to_charpos
, to_x
, to_y
, to_vpos
;
5805 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5811 if (op
& MOVE_TO_VPOS
)
5813 /* If no TO_CHARPOS and no TO_X specified, stop at the
5814 start of the line TO_VPOS. */
5815 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5817 if (it
->vpos
== to_vpos
)
5823 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5827 /* TO_VPOS >= 0 means stop at TO_X in the line at
5828 TO_VPOS, or at TO_POS, whichever comes first. */
5829 if (it
->vpos
== to_vpos
)
5835 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5837 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5842 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5844 /* We have reached TO_X but not in the line we want. */
5845 skip
= move_it_in_display_line_to (it
, to_charpos
,
5847 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5855 else if (op
& MOVE_TO_Y
)
5857 struct it it_backup
;
5859 /* TO_Y specified means stop at TO_X in the line containing
5860 TO_Y---or at TO_CHARPOS if this is reached first. The
5861 problem is that we can't really tell whether the line
5862 contains TO_Y before we have completely scanned it, and
5863 this may skip past TO_X. What we do is to first scan to
5866 If TO_X is not specified, use a TO_X of zero. The reason
5867 is to make the outcome of this function more predictable.
5868 If we didn't use TO_X == 0, we would stop at the end of
5869 the line which is probably not what a caller would expect
5871 skip
= move_it_in_display_line_to (it
, to_charpos
,
5875 | (op
& MOVE_TO_POS
)));
5877 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5878 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5884 /* If TO_X was reached, we would like to know whether TO_Y
5885 is in the line. This can only be said if we know the
5886 total line height which requires us to scan the rest of
5888 if (skip
== MOVE_X_REACHED
)
5891 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5892 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5894 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5897 /* Now, decide whether TO_Y is in this line. */
5898 line_height
= it
->max_ascent
+ it
->max_descent
;
5899 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5901 if (to_y
>= it
->current_y
5902 && to_y
< it
->current_y
+ line_height
)
5904 if (skip
== MOVE_X_REACHED
)
5905 /* If TO_Y is in this line and TO_X was reached above,
5906 we scanned too far. We have to restore IT's settings
5907 to the ones before skipping. */
5911 else if (skip
== MOVE_X_REACHED
)
5914 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5922 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5926 case MOVE_POS_MATCH_OR_ZV
:
5930 case MOVE_NEWLINE_OR_CR
:
5931 set_iterator_to_next (it
, 1);
5932 it
->continuation_lines_width
= 0;
5935 case MOVE_LINE_TRUNCATED
:
5936 it
->continuation_lines_width
= 0;
5937 reseat_at_next_visible_line_start (it
, 0);
5938 if ((op
& MOVE_TO_POS
) != 0
5939 && IT_CHARPOS (*it
) > to_charpos
)
5946 case MOVE_LINE_CONTINUED
:
5947 it
->continuation_lines_width
+= it
->current_x
;
5954 /* Reset/increment for the next run. */
5955 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5956 it
->current_x
= it
->hpos
= 0;
5957 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5959 last_height
= it
->max_ascent
+ it
->max_descent
;
5960 last_max_ascent
= it
->max_ascent
;
5961 it
->max_ascent
= it
->max_descent
= 0;
5966 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5970 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5972 If DY > 0, move IT backward at least that many pixels. DY = 0
5973 means move IT backward to the preceding line start or BEGV. This
5974 function may move over more than DY pixels if IT->current_y - DY
5975 ends up in the middle of a line; in this case IT->current_y will be
5976 set to the top of the line moved to. */
5979 move_it_vertically_backward (it
, dy
)
5985 int start_pos
= IT_CHARPOS (*it
);
5989 /* Estimate how many newlines we must move back. */
5990 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
5992 /* Set the iterator's position that many lines back. */
5993 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5994 back_to_previous_visible_line_start (it
);
5996 /* Reseat the iterator here. When moving backward, we don't want
5997 reseat to skip forward over invisible text, set up the iterator
5998 to deliver from overlay strings at the new position etc. So,
5999 use reseat_1 here. */
6000 reseat_1 (it
, it
->current
.pos
, 1);
6002 /* We are now surely at a line start. */
6003 it
->current_x
= it
->hpos
= 0;
6004 it
->continuation_lines_width
= 0;
6006 /* Move forward and see what y-distance we moved. First move to the
6007 start of the next line so that we get its height. We need this
6008 height to be able to tell whether we reached the specified
6011 it2
.max_ascent
= it2
.max_descent
= 0;
6012 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6013 MOVE_TO_POS
| MOVE_TO_VPOS
);
6014 xassert (IT_CHARPOS (*it
) >= BEGV
);
6017 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6018 xassert (IT_CHARPOS (*it
) >= BEGV
);
6019 /* H is the actual vertical distance from the position in *IT
6020 and the starting position. */
6021 h
= it2
.current_y
- it
->current_y
;
6022 /* NLINES is the distance in number of lines. */
6023 nlines
= it2
.vpos
- it
->vpos
;
6025 /* Correct IT's y and vpos position
6026 so that they are relative to the starting point. */
6032 /* DY == 0 means move to the start of the screen line. The
6033 value of nlines is > 0 if continuation lines were involved. */
6035 move_it_by_lines (it
, nlines
, 1);
6036 xassert (IT_CHARPOS (*it
) <= start_pos
);
6040 /* The y-position we try to reach, relative to *IT.
6041 Note that H has been subtracted in front of the if-statement. */
6042 int target_y
= it
->current_y
+ h
- dy
;
6043 int y0
= it3
.current_y
;
6044 int y1
= line_bottom_y (&it3
);
6045 int line_height
= y1
- y0
;
6047 /* If we did not reach target_y, try to move further backward if
6048 we can. If we moved too far backward, try to move forward. */
6049 if (target_y
< it
->current_y
6050 /* This is heuristic. In a window that's 3 lines high, with
6051 a line height of 13 pixels each, recentering with point
6052 on the bottom line will try to move -39/2 = 19 pixels
6053 backward. Try to avoid moving into the first line. */
6054 && it
->current_y
- target_y
> line_height
/ 3 * 2
6055 && IT_CHARPOS (*it
) > BEGV
)
6057 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6058 target_y
- it
->current_y
));
6059 move_it_vertically (it
, target_y
- it
->current_y
);
6060 xassert (IT_CHARPOS (*it
) >= BEGV
);
6062 else if (target_y
>= it
->current_y
+ line_height
6063 && IT_CHARPOS (*it
) < ZV
)
6065 /* Should move forward by at least one line, maybe more.
6067 Note: Calling move_it_by_lines can be expensive on
6068 terminal frames, where compute_motion is used (via
6069 vmotion) to do the job, when there are very long lines
6070 and truncate-lines is nil. That's the reason for
6071 treating terminal frames specially here. */
6073 if (!FRAME_WINDOW_P (it
->f
))
6074 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6079 move_it_by_lines (it
, 1, 1);
6081 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6084 xassert (IT_CHARPOS (*it
) >= BEGV
);
6090 /* Move IT by a specified amount of pixel lines DY. DY negative means
6091 move backwards. DY = 0 means move to start of screen line. At the
6092 end, IT will be on the start of a screen line. */
6095 move_it_vertically (it
, dy
)
6100 move_it_vertically_backward (it
, -dy
);
6103 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6104 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6105 MOVE_TO_POS
| MOVE_TO_Y
);
6106 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6108 /* If buffer ends in ZV without a newline, move to the start of
6109 the line to satisfy the post-condition. */
6110 if (IT_CHARPOS (*it
) == ZV
6111 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6112 move_it_by_lines (it
, 0, 0);
6117 /* Move iterator IT past the end of the text line it is in. */
6120 move_it_past_eol (it
)
6123 enum move_it_result rc
;
6125 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6126 if (rc
== MOVE_NEWLINE_OR_CR
)
6127 set_iterator_to_next (it
, 0);
6131 #if 0 /* Currently not used. */
6133 /* Return non-zero if some text between buffer positions START_CHARPOS
6134 and END_CHARPOS is invisible. IT->window is the window for text
6138 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6140 int start_charpos
, end_charpos
;
6142 Lisp_Object prop
, limit
;
6143 int invisible_found_p
;
6145 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6147 /* Is text at START invisible? */
6148 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6150 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6151 invisible_found_p
= 1;
6154 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6156 make_number (end_charpos
));
6157 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6160 return invisible_found_p
;
6166 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6167 negative means move up. DVPOS == 0 means move to the start of the
6168 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6169 NEED_Y_P is zero, IT->current_y will be left unchanged.
6171 Further optimization ideas: If we would know that IT->f doesn't use
6172 a face with proportional font, we could be faster for
6173 truncate-lines nil. */
6176 move_it_by_lines (it
, dvpos
, need_y_p
)
6178 int dvpos
, need_y_p
;
6180 struct position pos
;
6182 if (!FRAME_WINDOW_P (it
->f
))
6184 struct text_pos textpos
;
6186 /* We can use vmotion on frames without proportional fonts. */
6187 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6188 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6189 reseat (it
, textpos
, 1);
6190 it
->vpos
+= pos
.vpos
;
6191 it
->current_y
+= pos
.vpos
;
6193 else if (dvpos
== 0)
6195 /* DVPOS == 0 means move to the start of the screen line. */
6196 move_it_vertically_backward (it
, 0);
6197 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6200 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6204 int start_charpos
, i
;
6206 /* Start at the beginning of the screen line containing IT's
6208 move_it_vertically_backward (it
, 0);
6210 /* Go back -DVPOS visible lines and reseat the iterator there. */
6211 start_charpos
= IT_CHARPOS (*it
);
6212 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6213 back_to_previous_visible_line_start (it
);
6214 reseat (it
, it
->current
.pos
, 1);
6215 it
->current_x
= it
->hpos
= 0;
6217 /* Above call may have moved too far if continuation lines
6218 are involved. Scan forward and see if it did. */
6220 it2
.vpos
= it2
.current_y
= 0;
6221 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6222 it
->vpos
-= it2
.vpos
;
6223 it
->current_y
-= it2
.current_y
;
6224 it
->current_x
= it
->hpos
= 0;
6226 /* If we moved too far, move IT some lines forward. */
6227 if (it2
.vpos
> -dvpos
)
6229 int delta
= it2
.vpos
+ dvpos
;
6230 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6235 /* Return 1 if IT points into the middle of a display vector. */
6238 in_display_vector_p (it
)
6241 return (it
->method
== next_element_from_display_vector
6242 && it
->current
.dpvec_index
> 0
6243 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6247 /***********************************************************************
6249 ***********************************************************************/
6252 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6256 add_to_log (format
, arg1
, arg2
)
6258 Lisp_Object arg1
, arg2
;
6260 Lisp_Object args
[3];
6261 Lisp_Object msg
, fmt
;
6264 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6266 /* Do nothing if called asynchronously. Inserting text into
6267 a buffer may call after-change-functions and alike and
6268 that would means running Lisp asynchronously. */
6269 if (handling_signal
)
6273 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6275 args
[0] = fmt
= build_string (format
);
6278 msg
= Fformat (3, args
);
6280 len
= SBYTES (msg
) + 1;
6281 buffer
= (char *) alloca (len
);
6282 bcopy (SDATA (msg
), buffer
, len
);
6284 message_dolog (buffer
, len
- 1, 1, 0);
6289 /* Output a newline in the *Messages* buffer if "needs" one. */
6292 message_log_maybe_newline ()
6294 if (message_log_need_newline
)
6295 message_dolog ("", 0, 1, 0);
6299 /* Add a string M of length NBYTES to the message log, optionally
6300 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6301 nonzero, means interpret the contents of M as multibyte. This
6302 function calls low-level routines in order to bypass text property
6303 hooks, etc. which might not be safe to run. */
6306 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6308 int nbytes
, nlflag
, multibyte
;
6310 if (!NILP (Vmemory_full
))
6313 if (!NILP (Vmessage_log_max
))
6315 struct buffer
*oldbuf
;
6316 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6317 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6318 int point_at_end
= 0;
6320 Lisp_Object old_deactivate_mark
, tem
;
6321 struct gcpro gcpro1
;
6323 old_deactivate_mark
= Vdeactivate_mark
;
6324 oldbuf
= current_buffer
;
6325 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6326 current_buffer
->undo_list
= Qt
;
6328 oldpoint
= message_dolog_marker1
;
6329 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6330 oldbegv
= message_dolog_marker2
;
6331 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6332 oldzv
= message_dolog_marker3
;
6333 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6334 GCPRO1 (old_deactivate_mark
);
6342 BEGV_BYTE
= BEG_BYTE
;
6345 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6347 /* Insert the string--maybe converting multibyte to single byte
6348 or vice versa, so that all the text fits the buffer. */
6350 && NILP (current_buffer
->enable_multibyte_characters
))
6352 int i
, c
, char_bytes
;
6353 unsigned char work
[1];
6355 /* Convert a multibyte string to single-byte
6356 for the *Message* buffer. */
6357 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6359 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6360 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6362 : multibyte_char_to_unibyte (c
, Qnil
));
6363 insert_1_both (work
, 1, 1, 1, 0, 0);
6366 else if (! multibyte
6367 && ! NILP (current_buffer
->enable_multibyte_characters
))
6369 int i
, c
, char_bytes
;
6370 unsigned char *msg
= (unsigned char *) m
;
6371 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6372 /* Convert a single-byte string to multibyte
6373 for the *Message* buffer. */
6374 for (i
= 0; i
< nbytes
; i
++)
6376 c
= unibyte_char_to_multibyte (msg
[i
]);
6377 char_bytes
= CHAR_STRING (c
, str
);
6378 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6382 insert_1 (m
, nbytes
, 1, 0, 0);
6386 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6387 insert_1 ("\n", 1, 1, 0, 0);
6389 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6391 this_bol_byte
= PT_BYTE
;
6393 /* See if this line duplicates the previous one.
6394 If so, combine duplicates. */
6397 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6399 prev_bol_byte
= PT_BYTE
;
6401 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6402 this_bol
, this_bol_byte
);
6405 del_range_both (prev_bol
, prev_bol_byte
,
6406 this_bol
, this_bol_byte
, 0);
6412 /* If you change this format, don't forget to also
6413 change message_log_check_duplicate. */
6414 sprintf (dupstr
, " [%d times]", dup
);
6415 duplen
= strlen (dupstr
);
6416 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6417 insert_1 (dupstr
, duplen
, 1, 0, 1);
6422 /* If we have more than the desired maximum number of lines
6423 in the *Messages* buffer now, delete the oldest ones.
6424 This is safe because we don't have undo in this buffer. */
6426 if (NATNUMP (Vmessage_log_max
))
6428 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6429 -XFASTINT (Vmessage_log_max
) - 1, 0);
6430 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6433 BEGV
= XMARKER (oldbegv
)->charpos
;
6434 BEGV_BYTE
= marker_byte_position (oldbegv
);
6443 ZV
= XMARKER (oldzv
)->charpos
;
6444 ZV_BYTE
= marker_byte_position (oldzv
);
6448 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6450 /* We can't do Fgoto_char (oldpoint) because it will run some
6452 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6453 XMARKER (oldpoint
)->bytepos
);
6456 unchain_marker (XMARKER (oldpoint
));
6457 unchain_marker (XMARKER (oldbegv
));
6458 unchain_marker (XMARKER (oldzv
));
6460 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6461 set_buffer_internal (oldbuf
);
6463 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6464 message_log_need_newline
= !nlflag
;
6465 Vdeactivate_mark
= old_deactivate_mark
;
6470 /* We are at the end of the buffer after just having inserted a newline.
6471 (Note: We depend on the fact we won't be crossing the gap.)
6472 Check to see if the most recent message looks a lot like the previous one.
6473 Return 0 if different, 1 if the new one should just replace it, or a
6474 value N > 1 if we should also append " [N times]". */
6477 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6478 int prev_bol
, this_bol
;
6479 int prev_bol_byte
, this_bol_byte
;
6482 int len
= Z_BYTE
- 1 - this_bol_byte
;
6484 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6485 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6487 for (i
= 0; i
< len
; i
++)
6489 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6497 if (*p1
++ == ' ' && *p1
++ == '[')
6500 while (*p1
>= '0' && *p1
<= '9')
6501 n
= n
* 10 + *p1
++ - '0';
6502 if (strncmp (p1
, " times]\n", 8) == 0)
6509 /* Display an echo area message M with a specified length of NBYTES
6510 bytes. The string may include null characters. If M is 0, clear
6511 out any existing message, and let the mini-buffer text show
6514 The buffer M must continue to exist until after the echo area gets
6515 cleared or some other message gets displayed there. This means do
6516 not pass text that is stored in a Lisp string; do not pass text in
6517 a buffer that was alloca'd. */
6520 message2 (m
, nbytes
, multibyte
)
6525 /* First flush out any partial line written with print. */
6526 message_log_maybe_newline ();
6528 message_dolog (m
, nbytes
, 1, multibyte
);
6529 message2_nolog (m
, nbytes
, multibyte
);
6533 /* The non-logging counterpart of message2. */
6536 message2_nolog (m
, nbytes
, multibyte
)
6538 int nbytes
, multibyte
;
6540 struct frame
*sf
= SELECTED_FRAME ();
6541 message_enable_multibyte
= multibyte
;
6545 if (noninteractive_need_newline
)
6546 putc ('\n', stderr
);
6547 noninteractive_need_newline
= 0;
6549 fwrite (m
, nbytes
, 1, stderr
);
6550 if (cursor_in_echo_area
== 0)
6551 fprintf (stderr
, "\n");
6554 /* A null message buffer means that the frame hasn't really been
6555 initialized yet. Error messages get reported properly by
6556 cmd_error, so this must be just an informative message; toss it. */
6557 else if (INTERACTIVE
6558 && sf
->glyphs_initialized_p
6559 && FRAME_MESSAGE_BUF (sf
))
6561 Lisp_Object mini_window
;
6564 /* Get the frame containing the mini-buffer
6565 that the selected frame is using. */
6566 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6567 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6569 FRAME_SAMPLE_VISIBILITY (f
);
6570 if (FRAME_VISIBLE_P (sf
)
6571 && ! FRAME_VISIBLE_P (f
))
6572 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6576 set_message (m
, Qnil
, nbytes
, multibyte
);
6577 if (minibuffer_auto_raise
)
6578 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6581 clear_message (1, 1);
6583 do_pending_window_change (0);
6584 echo_area_display (1);
6585 do_pending_window_change (0);
6586 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6587 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6592 /* Display an echo area message M with a specified length of NBYTES
6593 bytes. The string may include null characters. If M is not a
6594 string, clear out any existing message, and let the mini-buffer
6595 text show through. */
6598 message3 (m
, nbytes
, multibyte
)
6603 struct gcpro gcpro1
;
6607 /* First flush out any partial line written with print. */
6608 message_log_maybe_newline ();
6610 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6611 message3_nolog (m
, nbytes
, multibyte
);
6617 /* The non-logging version of message3. */
6620 message3_nolog (m
, nbytes
, multibyte
)
6622 int nbytes
, multibyte
;
6624 struct frame
*sf
= SELECTED_FRAME ();
6625 message_enable_multibyte
= multibyte
;
6629 if (noninteractive_need_newline
)
6630 putc ('\n', stderr
);
6631 noninteractive_need_newline
= 0;
6633 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6634 if (cursor_in_echo_area
== 0)
6635 fprintf (stderr
, "\n");
6638 /* A null message buffer means that the frame hasn't really been
6639 initialized yet. Error messages get reported properly by
6640 cmd_error, so this must be just an informative message; toss it. */
6641 else if (INTERACTIVE
6642 && sf
->glyphs_initialized_p
6643 && FRAME_MESSAGE_BUF (sf
))
6645 Lisp_Object mini_window
;
6649 /* Get the frame containing the mini-buffer
6650 that the selected frame is using. */
6651 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6652 frame
= XWINDOW (mini_window
)->frame
;
6655 FRAME_SAMPLE_VISIBILITY (f
);
6656 if (FRAME_VISIBLE_P (sf
)
6657 && !FRAME_VISIBLE_P (f
))
6658 Fmake_frame_visible (frame
);
6660 if (STRINGP (m
) && SCHARS (m
) > 0)
6662 set_message (NULL
, m
, nbytes
, multibyte
);
6663 if (minibuffer_auto_raise
)
6664 Fraise_frame (frame
);
6667 clear_message (1, 1);
6669 do_pending_window_change (0);
6670 echo_area_display (1);
6671 do_pending_window_change (0);
6672 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6673 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6678 /* Display a null-terminated echo area message M. If M is 0, clear
6679 out any existing message, and let the mini-buffer text show through.
6681 The buffer M must continue to exist until after the echo area gets
6682 cleared or some other message gets displayed there. Do not pass
6683 text that is stored in a Lisp string. Do not pass text in a buffer
6684 that was alloca'd. */
6690 message2 (m
, (m
? strlen (m
) : 0), 0);
6694 /* The non-logging counterpart of message1. */
6700 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6703 /* Display a message M which contains a single %s
6704 which gets replaced with STRING. */
6707 message_with_string (m
, string
, log
)
6712 CHECK_STRING (string
);
6718 if (noninteractive_need_newline
)
6719 putc ('\n', stderr
);
6720 noninteractive_need_newline
= 0;
6721 fprintf (stderr
, m
, SDATA (string
));
6722 if (cursor_in_echo_area
== 0)
6723 fprintf (stderr
, "\n");
6727 else if (INTERACTIVE
)
6729 /* The frame whose minibuffer we're going to display the message on.
6730 It may be larger than the selected frame, so we need
6731 to use its buffer, not the selected frame's buffer. */
6732 Lisp_Object mini_window
;
6733 struct frame
*f
, *sf
= SELECTED_FRAME ();
6735 /* Get the frame containing the minibuffer
6736 that the selected frame is using. */
6737 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6738 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6740 /* A null message buffer means that the frame hasn't really been
6741 initialized yet. Error messages get reported properly by
6742 cmd_error, so this must be just an informative message; toss it. */
6743 if (FRAME_MESSAGE_BUF (f
))
6745 Lisp_Object args
[2], message
;
6746 struct gcpro gcpro1
, gcpro2
;
6748 args
[0] = build_string (m
);
6749 args
[1] = message
= string
;
6750 GCPRO2 (args
[0], message
);
6753 message
= Fformat (2, args
);
6756 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6758 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6762 /* Print should start at the beginning of the message
6763 buffer next time. */
6764 message_buf_print
= 0;
6770 /* Dump an informative message to the minibuf. If M is 0, clear out
6771 any existing message, and let the mini-buffer text show through. */
6775 message (m
, a1
, a2
, a3
)
6777 EMACS_INT a1
, a2
, a3
;
6783 if (noninteractive_need_newline
)
6784 putc ('\n', stderr
);
6785 noninteractive_need_newline
= 0;
6786 fprintf (stderr
, m
, a1
, a2
, a3
);
6787 if (cursor_in_echo_area
== 0)
6788 fprintf (stderr
, "\n");
6792 else if (INTERACTIVE
)
6794 /* The frame whose mini-buffer we're going to display the message
6795 on. It may be larger than the selected frame, so we need to
6796 use its buffer, not the selected frame's buffer. */
6797 Lisp_Object mini_window
;
6798 struct frame
*f
, *sf
= SELECTED_FRAME ();
6800 /* Get the frame containing the mini-buffer
6801 that the selected frame is using. */
6802 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6803 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6805 /* A null message buffer means that the frame hasn't really been
6806 initialized yet. Error messages get reported properly by
6807 cmd_error, so this must be just an informative message; toss
6809 if (FRAME_MESSAGE_BUF (f
))
6820 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6821 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6823 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6824 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6826 #endif /* NO_ARG_ARRAY */
6828 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6833 /* Print should start at the beginning of the message
6834 buffer next time. */
6835 message_buf_print
= 0;
6841 /* The non-logging version of message. */
6844 message_nolog (m
, a1
, a2
, a3
)
6846 EMACS_INT a1
, a2
, a3
;
6848 Lisp_Object old_log_max
;
6849 old_log_max
= Vmessage_log_max
;
6850 Vmessage_log_max
= Qnil
;
6851 message (m
, a1
, a2
, a3
);
6852 Vmessage_log_max
= old_log_max
;
6856 /* Display the current message in the current mini-buffer. This is
6857 only called from error handlers in process.c, and is not time
6863 if (!NILP (echo_area_buffer
[0]))
6866 string
= Fcurrent_message ();
6867 message3 (string
, SBYTES (string
),
6868 !NILP (current_buffer
->enable_multibyte_characters
));
6873 /* Make sure echo area buffers in `echo_buffers' are live.
6874 If they aren't, make new ones. */
6877 ensure_echo_area_buffers ()
6881 for (i
= 0; i
< 2; ++i
)
6882 if (!BUFFERP (echo_buffer
[i
])
6883 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6886 Lisp_Object old_buffer
;
6889 old_buffer
= echo_buffer
[i
];
6890 sprintf (name
, " *Echo Area %d*", i
);
6891 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6892 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6894 for (j
= 0; j
< 2; ++j
)
6895 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6896 echo_area_buffer
[j
] = echo_buffer
[i
];
6901 /* Call FN with args A1..A4 with either the current or last displayed
6902 echo_area_buffer as current buffer.
6904 WHICH zero means use the current message buffer
6905 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6906 from echo_buffer[] and clear it.
6908 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6909 suitable buffer from echo_buffer[] and clear it.
6911 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6912 that the current message becomes the last displayed one, make
6913 choose a suitable buffer for echo_area_buffer[0], and clear it.
6915 Value is what FN returns. */
6918 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6921 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6927 int this_one
, the_other
, clear_buffer_p
, rc
;
6928 int count
= SPECPDL_INDEX ();
6930 /* If buffers aren't live, make new ones. */
6931 ensure_echo_area_buffers ();
6936 this_one
= 0, the_other
= 1;
6938 this_one
= 1, the_other
= 0;
6941 this_one
= 0, the_other
= 1;
6944 /* We need a fresh one in case the current echo buffer equals
6945 the one containing the last displayed echo area message. */
6946 if (!NILP (echo_area_buffer
[this_one
])
6947 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6948 echo_area_buffer
[this_one
] = Qnil
;
6951 /* Choose a suitable buffer from echo_buffer[] is we don't
6953 if (NILP (echo_area_buffer
[this_one
]))
6955 echo_area_buffer
[this_one
]
6956 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6957 ? echo_buffer
[the_other
]
6958 : echo_buffer
[this_one
]);
6962 buffer
= echo_area_buffer
[this_one
];
6964 /* Don't get confused by reusing the buffer used for echoing
6965 for a different purpose. */
6966 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6969 record_unwind_protect (unwind_with_echo_area_buffer
,
6970 with_echo_area_buffer_unwind_data (w
));
6972 /* Make the echo area buffer current. Note that for display
6973 purposes, it is not necessary that the displayed window's buffer
6974 == current_buffer, except for text property lookup. So, let's
6975 only set that buffer temporarily here without doing a full
6976 Fset_window_buffer. We must also change w->pointm, though,
6977 because otherwise an assertions in unshow_buffer fails, and Emacs
6979 set_buffer_internal_1 (XBUFFER (buffer
));
6983 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6986 current_buffer
->undo_list
= Qt
;
6987 current_buffer
->read_only
= Qnil
;
6988 specbind (Qinhibit_read_only
, Qt
);
6989 specbind (Qinhibit_modification_hooks
, Qt
);
6991 if (clear_buffer_p
&& Z
> BEG
)
6994 xassert (BEGV
>= BEG
);
6995 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6997 rc
= fn (a1
, a2
, a3
, a4
);
6999 xassert (BEGV
>= BEG
);
7000 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7002 unbind_to (count
, Qnil
);
7007 /* Save state that should be preserved around the call to the function
7008 FN called in with_echo_area_buffer. */
7011 with_echo_area_buffer_unwind_data (w
)
7017 /* Reduce consing by keeping one vector in
7018 Vwith_echo_area_save_vector. */
7019 vector
= Vwith_echo_area_save_vector
;
7020 Vwith_echo_area_save_vector
= Qnil
;
7023 vector
= Fmake_vector (make_number (7), Qnil
);
7025 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7026 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7027 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7031 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7032 AREF (vector
, i
) = w
->buffer
; ++i
;
7033 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7034 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7039 for (; i
< end
; ++i
)
7040 AREF (vector
, i
) = Qnil
;
7043 xassert (i
== ASIZE (vector
));
7048 /* Restore global state from VECTOR which was created by
7049 with_echo_area_buffer_unwind_data. */
7052 unwind_with_echo_area_buffer (vector
)
7055 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7056 Vdeactivate_mark
= AREF (vector
, 1);
7057 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7059 if (WINDOWP (AREF (vector
, 3)))
7062 Lisp_Object buffer
, charpos
, bytepos
;
7064 w
= XWINDOW (AREF (vector
, 3));
7065 buffer
= AREF (vector
, 4);
7066 charpos
= AREF (vector
, 5);
7067 bytepos
= AREF (vector
, 6);
7070 set_marker_both (w
->pointm
, buffer
,
7071 XFASTINT (charpos
), XFASTINT (bytepos
));
7074 Vwith_echo_area_save_vector
= vector
;
7079 /* Set up the echo area for use by print functions. MULTIBYTE_P
7080 non-zero means we will print multibyte. */
7083 setup_echo_area_for_printing (multibyte_p
)
7086 /* If we can't find an echo area any more, exit. */
7087 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7090 ensure_echo_area_buffers ();
7092 if (!message_buf_print
)
7094 /* A message has been output since the last time we printed.
7095 Choose a fresh echo area buffer. */
7096 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7097 echo_area_buffer
[0] = echo_buffer
[1];
7099 echo_area_buffer
[0] = echo_buffer
[0];
7101 /* Switch to that buffer and clear it. */
7102 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7103 current_buffer
->truncate_lines
= Qnil
;
7107 int count
= SPECPDL_INDEX ();
7108 specbind (Qinhibit_read_only
, Qt
);
7109 /* Note that undo recording is always disabled. */
7111 unbind_to (count
, Qnil
);
7113 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7115 /* Set up the buffer for the multibyteness we need. */
7117 != !NILP (current_buffer
->enable_multibyte_characters
))
7118 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7120 /* Raise the frame containing the echo area. */
7121 if (minibuffer_auto_raise
)
7123 struct frame
*sf
= SELECTED_FRAME ();
7124 Lisp_Object mini_window
;
7125 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7126 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7129 message_log_maybe_newline ();
7130 message_buf_print
= 1;
7134 if (NILP (echo_area_buffer
[0]))
7136 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7137 echo_area_buffer
[0] = echo_buffer
[1];
7139 echo_area_buffer
[0] = echo_buffer
[0];
7142 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7144 /* Someone switched buffers between print requests. */
7145 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7146 current_buffer
->truncate_lines
= Qnil
;
7152 /* Display an echo area message in window W. Value is non-zero if W's
7153 height is changed. If display_last_displayed_message_p is
7154 non-zero, display the message that was last displayed, otherwise
7155 display the current message. */
7158 display_echo_area (w
)
7161 int i
, no_message_p
, window_height_changed_p
, count
;
7163 /* Temporarily disable garbage collections while displaying the echo
7164 area. This is done because a GC can print a message itself.
7165 That message would modify the echo area buffer's contents while a
7166 redisplay of the buffer is going on, and seriously confuse
7168 count
= inhibit_garbage_collection ();
7170 /* If there is no message, we must call display_echo_area_1
7171 nevertheless because it resizes the window. But we will have to
7172 reset the echo_area_buffer in question to nil at the end because
7173 with_echo_area_buffer will sets it to an empty buffer. */
7174 i
= display_last_displayed_message_p
? 1 : 0;
7175 no_message_p
= NILP (echo_area_buffer
[i
]);
7177 window_height_changed_p
7178 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7179 display_echo_area_1
,
7180 (EMACS_INT
) w
, Qnil
, 0, 0);
7183 echo_area_buffer
[i
] = Qnil
;
7185 unbind_to (count
, Qnil
);
7186 return window_height_changed_p
;
7190 /* Helper for display_echo_area. Display the current buffer which
7191 contains the current echo area message in window W, a mini-window,
7192 a pointer to which is passed in A1. A2..A4 are currently not used.
7193 Change the height of W so that all of the message is displayed.
7194 Value is non-zero if height of W was changed. */
7197 display_echo_area_1 (a1
, a2
, a3
, a4
)
7202 struct window
*w
= (struct window
*) a1
;
7204 struct text_pos start
;
7205 int window_height_changed_p
= 0;
7207 /* Do this before displaying, so that we have a large enough glyph
7208 matrix for the display. */
7209 window_height_changed_p
= resize_mini_window (w
, 0);
7212 clear_glyph_matrix (w
->desired_matrix
);
7213 XSETWINDOW (window
, w
);
7214 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7215 try_window (window
, start
);
7217 return window_height_changed_p
;
7221 /* Resize the echo area window to exactly the size needed for the
7222 currently displayed message, if there is one. If a mini-buffer
7223 is active, don't shrink it. */
7226 resize_echo_area_exactly ()
7228 if (BUFFERP (echo_area_buffer
[0])
7229 && WINDOWP (echo_area_window
))
7231 struct window
*w
= XWINDOW (echo_area_window
);
7233 Lisp_Object resize_exactly
;
7235 if (minibuf_level
== 0)
7236 resize_exactly
= Qt
;
7238 resize_exactly
= Qnil
;
7240 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7241 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7244 ++windows_or_buffers_changed
;
7245 ++update_mode_lines
;
7246 redisplay_internal (0);
7252 /* Callback function for with_echo_area_buffer, when used from
7253 resize_echo_area_exactly. A1 contains a pointer to the window to
7254 resize, EXACTLY non-nil means resize the mini-window exactly to the
7255 size of the text displayed. A3 and A4 are not used. Value is what
7256 resize_mini_window returns. */
7259 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7261 Lisp_Object exactly
;
7264 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7268 /* Resize mini-window W to fit the size of its contents. EXACT:P
7269 means size the window exactly to the size needed. Otherwise, it's
7270 only enlarged until W's buffer is empty. Value is non-zero if
7271 the window height has been changed. */
7274 resize_mini_window (w
, exact_p
)
7278 struct frame
*f
= XFRAME (w
->frame
);
7279 int window_height_changed_p
= 0;
7281 xassert (MINI_WINDOW_P (w
));
7283 /* Don't resize windows while redisplaying a window; it would
7284 confuse redisplay functions when the size of the window they are
7285 displaying changes from under them. Such a resizing can happen,
7286 for instance, when which-func prints a long message while
7287 we are running fontification-functions. We're running these
7288 functions with safe_call which binds inhibit-redisplay to t. */
7289 if (!NILP (Vinhibit_redisplay
))
7292 /* Nil means don't try to resize. */
7293 if (NILP (Vresize_mini_windows
)
7294 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7297 if (!FRAME_MINIBUF_ONLY_P (f
))
7300 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7301 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7302 int height
, max_height
;
7303 int unit
= FRAME_LINE_HEIGHT (f
);
7304 struct text_pos start
;
7305 struct buffer
*old_current_buffer
= NULL
;
7307 if (current_buffer
!= XBUFFER (w
->buffer
))
7309 old_current_buffer
= current_buffer
;
7310 set_buffer_internal (XBUFFER (w
->buffer
));
7313 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7315 /* Compute the max. number of lines specified by the user. */
7316 if (FLOATP (Vmax_mini_window_height
))
7317 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7318 else if (INTEGERP (Vmax_mini_window_height
))
7319 max_height
= XINT (Vmax_mini_window_height
);
7321 max_height
= total_height
/ 4;
7323 /* Correct that max. height if it's bogus. */
7324 max_height
= max (1, max_height
);
7325 max_height
= min (total_height
, max_height
);
7327 /* Find out the height of the text in the window. */
7328 if (it
.truncate_lines_p
)
7333 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7334 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7335 height
= it
.current_y
+ last_height
;
7337 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7338 height
-= it
.extra_line_spacing
;
7339 height
= (height
+ unit
- 1) / unit
;
7342 /* Compute a suitable window start. */
7343 if (height
> max_height
)
7345 height
= max_height
;
7346 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7347 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7348 start
= it
.current
.pos
;
7351 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7352 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7354 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7356 /* Let it grow only, until we display an empty message, in which
7357 case the window shrinks again. */
7358 if (height
> WINDOW_TOTAL_LINES (w
))
7360 int old_height
= WINDOW_TOTAL_LINES (w
);
7361 freeze_window_starts (f
, 1);
7362 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7363 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7365 else if (height
< WINDOW_TOTAL_LINES (w
)
7366 && (exact_p
|| BEGV
== ZV
))
7368 int old_height
= WINDOW_TOTAL_LINES (w
);
7369 freeze_window_starts (f
, 0);
7370 shrink_mini_window (w
);
7371 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7376 /* Always resize to exact size needed. */
7377 if (height
> WINDOW_TOTAL_LINES (w
))
7379 int old_height
= WINDOW_TOTAL_LINES (w
);
7380 freeze_window_starts (f
, 1);
7381 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7382 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7384 else if (height
< WINDOW_TOTAL_LINES (w
))
7386 int old_height
= WINDOW_TOTAL_LINES (w
);
7387 freeze_window_starts (f
, 0);
7388 shrink_mini_window (w
);
7392 freeze_window_starts (f
, 1);
7393 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7396 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7400 if (old_current_buffer
)
7401 set_buffer_internal (old_current_buffer
);
7404 return window_height_changed_p
;
7408 /* Value is the current message, a string, or nil if there is no
7416 if (NILP (echo_area_buffer
[0]))
7420 with_echo_area_buffer (0, 0, current_message_1
,
7421 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7423 echo_area_buffer
[0] = Qnil
;
7431 current_message_1 (a1
, a2
, a3
, a4
)
7436 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7439 *msg
= make_buffer_string (BEG
, Z
, 1);
7446 /* Push the current message on Vmessage_stack for later restauration
7447 by restore_message. Value is non-zero if the current message isn't
7448 empty. This is a relatively infrequent operation, so it's not
7449 worth optimizing. */
7455 msg
= current_message ();
7456 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7457 return STRINGP (msg
);
7461 /* Restore message display from the top of Vmessage_stack. */
7468 xassert (CONSP (Vmessage_stack
));
7469 msg
= XCAR (Vmessage_stack
);
7471 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7473 message3_nolog (msg
, 0, 0);
7477 /* Handler for record_unwind_protect calling pop_message. */
7480 pop_message_unwind (dummy
)
7487 /* Pop the top-most entry off Vmessage_stack. */
7492 xassert (CONSP (Vmessage_stack
));
7493 Vmessage_stack
= XCDR (Vmessage_stack
);
7497 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7498 exits. If the stack is not empty, we have a missing pop_message
7502 check_message_stack ()
7504 if (!NILP (Vmessage_stack
))
7509 /* Truncate to NCHARS what will be displayed in the echo area the next
7510 time we display it---but don't redisplay it now. */
7513 truncate_echo_area (nchars
)
7517 echo_area_buffer
[0] = Qnil
;
7518 /* A null message buffer means that the frame hasn't really been
7519 initialized yet. Error messages get reported properly by
7520 cmd_error, so this must be just an informative message; toss it. */
7521 else if (!noninteractive
7523 && !NILP (echo_area_buffer
[0]))
7525 struct frame
*sf
= SELECTED_FRAME ();
7526 if (FRAME_MESSAGE_BUF (sf
))
7527 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7532 /* Helper function for truncate_echo_area. Truncate the current
7533 message to at most NCHARS characters. */
7536 truncate_message_1 (nchars
, a2
, a3
, a4
)
7541 if (BEG
+ nchars
< Z
)
7542 del_range (BEG
+ nchars
, Z
);
7544 echo_area_buffer
[0] = Qnil
;
7549 /* Set the current message to a substring of S or STRING.
7551 If STRING is a Lisp string, set the message to the first NBYTES
7552 bytes from STRING. NBYTES zero means use the whole string. If
7553 STRING is multibyte, the message will be displayed multibyte.
7555 If S is not null, set the message to the first LEN bytes of S. LEN
7556 zero means use the whole string. MULTIBYTE_P non-zero means S is
7557 multibyte. Display the message multibyte in that case. */
7560 set_message (s
, string
, nbytes
, multibyte_p
)
7563 int nbytes
, multibyte_p
;
7565 message_enable_multibyte
7566 = ((s
&& multibyte_p
)
7567 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7569 with_echo_area_buffer (0, -1, set_message_1
,
7570 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7571 message_buf_print
= 0;
7572 help_echo_showing_p
= 0;
7576 /* Helper function for set_message. Arguments have the same meaning
7577 as there, with A1 corresponding to S and A2 corresponding to STRING
7578 This function is called with the echo area buffer being
7582 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7585 EMACS_INT nbytes
, multibyte_p
;
7587 const char *s
= (const char *) a1
;
7588 Lisp_Object string
= a2
;
7592 /* Change multibyteness of the echo buffer appropriately. */
7593 if (message_enable_multibyte
7594 != !NILP (current_buffer
->enable_multibyte_characters
))
7595 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7597 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7599 /* Insert new message at BEG. */
7600 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7602 if (STRINGP (string
))
7607 nbytes
= SBYTES (string
);
7608 nchars
= string_byte_to_char (string
, nbytes
);
7610 /* This function takes care of single/multibyte conversion. We
7611 just have to ensure that the echo area buffer has the right
7612 setting of enable_multibyte_characters. */
7613 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7618 nbytes
= strlen (s
);
7620 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7622 /* Convert from multi-byte to single-byte. */
7624 unsigned char work
[1];
7626 /* Convert a multibyte string to single-byte. */
7627 for (i
= 0; i
< nbytes
; i
+= n
)
7629 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7630 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7632 : multibyte_char_to_unibyte (c
, Qnil
));
7633 insert_1_both (work
, 1, 1, 1, 0, 0);
7636 else if (!multibyte_p
7637 && !NILP (current_buffer
->enable_multibyte_characters
))
7639 /* Convert from single-byte to multi-byte. */
7641 const unsigned char *msg
= (const unsigned char *) s
;
7642 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7644 /* Convert a single-byte string to multibyte. */
7645 for (i
= 0; i
< nbytes
; i
++)
7647 c
= unibyte_char_to_multibyte (msg
[i
]);
7648 n
= CHAR_STRING (c
, str
);
7649 insert_1_both (str
, 1, n
, 1, 0, 0);
7653 insert_1 (s
, nbytes
, 1, 0, 0);
7660 /* Clear messages. CURRENT_P non-zero means clear the current
7661 message. LAST_DISPLAYED_P non-zero means clear the message
7665 clear_message (current_p
, last_displayed_p
)
7666 int current_p
, last_displayed_p
;
7670 echo_area_buffer
[0] = Qnil
;
7671 message_cleared_p
= 1;
7674 if (last_displayed_p
)
7675 echo_area_buffer
[1] = Qnil
;
7677 message_buf_print
= 0;
7680 /* Clear garbaged frames.
7682 This function is used where the old redisplay called
7683 redraw_garbaged_frames which in turn called redraw_frame which in
7684 turn called clear_frame. The call to clear_frame was a source of
7685 flickering. I believe a clear_frame is not necessary. It should
7686 suffice in the new redisplay to invalidate all current matrices,
7687 and ensure a complete redisplay of all windows. */
7690 clear_garbaged_frames ()
7694 Lisp_Object tail
, frame
;
7695 int changed_count
= 0;
7697 FOR_EACH_FRAME (tail
, frame
)
7699 struct frame
*f
= XFRAME (frame
);
7701 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7705 Fredraw_frame (frame
);
7706 f
->force_flush_display_p
= 1;
7708 clear_current_matrices (f
);
7717 ++windows_or_buffers_changed
;
7722 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7723 is non-zero update selected_frame. Value is non-zero if the
7724 mini-windows height has been changed. */
7727 echo_area_display (update_frame_p
)
7730 Lisp_Object mini_window
;
7733 int window_height_changed_p
= 0;
7734 struct frame
*sf
= SELECTED_FRAME ();
7736 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7737 w
= XWINDOW (mini_window
);
7738 f
= XFRAME (WINDOW_FRAME (w
));
7740 /* Don't display if frame is invisible or not yet initialized. */
7741 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7744 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7746 #ifdef HAVE_WINDOW_SYSTEM
7747 /* When Emacs starts, selected_frame may be the initial terminal
7748 frame. If we let this through, a message would be displayed on
7750 if (FRAME_TERMCAP_P (XFRAME (selected_frame
))
7751 && FRAME_TTY (XFRAME (selected_frame
))->type
== NULL
)
7753 #endif /* HAVE_WINDOW_SYSTEM */
7756 /* Redraw garbaged frames. */
7758 clear_garbaged_frames ();
7760 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7762 echo_area_window
= mini_window
;
7763 window_height_changed_p
= display_echo_area (w
);
7764 w
->must_be_updated_p
= 1;
7766 /* Update the display, unless called from redisplay_internal.
7767 Also don't update the screen during redisplay itself. The
7768 update will happen at the end of redisplay, and an update
7769 here could cause confusion. */
7770 if (update_frame_p
&& !redisplaying_p
)
7774 /* If the display update has been interrupted by pending
7775 input, update mode lines in the frame. Due to the
7776 pending input, it might have been that redisplay hasn't
7777 been called, so that mode lines above the echo area are
7778 garbaged. This looks odd, so we prevent it here. */
7779 if (!display_completed
)
7780 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7782 if (window_height_changed_p
7783 /* Don't do this if Emacs is shutting down. Redisplay
7784 needs to run hooks. */
7785 && !NILP (Vrun_hooks
))
7787 /* Must update other windows. Likewise as in other
7788 cases, don't let this update be interrupted by
7790 int count
= SPECPDL_INDEX ();
7791 specbind (Qredisplay_dont_pause
, Qt
);
7792 windows_or_buffers_changed
= 1;
7793 redisplay_internal (0);
7794 unbind_to (count
, Qnil
);
7796 else if (FRAME_WINDOW_P (f
) && n
== 0)
7798 /* Window configuration is the same as before.
7799 Can do with a display update of the echo area,
7800 unless we displayed some mode lines. */
7801 update_single_window (w
, 1);
7802 FRAME_RIF (f
)->flush_display (f
);
7805 update_frame (f
, 1, 1);
7807 /* If cursor is in the echo area, make sure that the next
7808 redisplay displays the minibuffer, so that the cursor will
7809 be replaced with what the minibuffer wants. */
7810 if (cursor_in_echo_area
)
7811 ++windows_or_buffers_changed
;
7814 else if (!EQ (mini_window
, selected_window
))
7815 windows_or_buffers_changed
++;
7817 /* Last displayed message is now the current message. */
7818 echo_area_buffer
[1] = echo_area_buffer
[0];
7820 /* Prevent redisplay optimization in redisplay_internal by resetting
7821 this_line_start_pos. This is done because the mini-buffer now
7822 displays the message instead of its buffer text. */
7823 if (EQ (mini_window
, selected_window
))
7824 CHARPOS (this_line_start_pos
) = 0;
7826 return window_height_changed_p
;
7831 /***********************************************************************
7833 ***********************************************************************/
7836 /* The frame title buffering code is also used by Fformat_mode_line.
7837 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7839 /* A buffer for constructing frame titles in it; allocated from the
7840 heap in init_xdisp and resized as needed in store_frame_title_char. */
7842 static char *frame_title_buf
;
7844 /* The buffer's end, and a current output position in it. */
7846 static char *frame_title_buf_end
;
7847 static char *frame_title_ptr
;
7850 /* Store a single character C for the frame title in frame_title_buf.
7851 Re-allocate frame_title_buf if necessary. */
7855 store_frame_title_char (char c
)
7857 store_frame_title_char (c
)
7861 /* If output position has reached the end of the allocated buffer,
7862 double the buffer's size. */
7863 if (frame_title_ptr
== frame_title_buf_end
)
7865 int len
= frame_title_ptr
- frame_title_buf
;
7866 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7867 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7868 frame_title_buf_end
= frame_title_buf
+ new_size
;
7869 frame_title_ptr
= frame_title_buf
+ len
;
7872 *frame_title_ptr
++ = c
;
7876 /* Store part of a frame title in frame_title_buf, beginning at
7877 frame_title_ptr. STR is the string to store. Do not copy
7878 characters that yield more columns than PRECISION; PRECISION <= 0
7879 means copy the whole string. Pad with spaces until FIELD_WIDTH
7880 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7881 pad. Called from display_mode_element when it is used to build a
7885 store_frame_title (str
, field_width
, precision
)
7886 const unsigned char *str
;
7887 int field_width
, precision
;
7892 /* Copy at most PRECISION chars from STR. */
7893 nbytes
= strlen (str
);
7894 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7896 store_frame_title_char (*str
++);
7898 /* Fill up with spaces until FIELD_WIDTH reached. */
7899 while (field_width
> 0
7902 store_frame_title_char (' ');
7909 #ifdef HAVE_WINDOW_SYSTEM
7911 /* Set the title of FRAME, if it has changed. The title format is
7912 Vicon_title_format if FRAME is iconified, otherwise it is
7913 frame_title_format. */
7916 x_consider_frame_title (frame
)
7919 struct frame
*f
= XFRAME (frame
);
7921 if (FRAME_WINDOW_P (f
)
7922 || FRAME_MINIBUF_ONLY_P (f
)
7923 || f
->explicit_name
)
7925 /* Do we have more than one visible frame on this X display? */
7928 struct buffer
*obuf
;
7932 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7934 Lisp_Object other_frame
= XCAR (tail
);
7935 struct frame
*tf
= XFRAME (other_frame
);
7938 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7939 && !FRAME_MINIBUF_ONLY_P (tf
)
7940 && !EQ (other_frame
, tip_frame
)
7941 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7945 /* Set global variable indicating that multiple frames exist. */
7946 multiple_frames
= CONSP (tail
);
7948 /* Switch to the buffer of selected window of the frame. Set up
7949 frame_title_ptr so that display_mode_element will output into it;
7950 then display the title. */
7951 obuf
= current_buffer
;
7952 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7953 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7954 frame_title_ptr
= frame_title_buf
;
7955 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7956 NULL
, DEFAULT_FACE_ID
);
7957 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7958 len
= frame_title_ptr
- frame_title_buf
;
7959 frame_title_ptr
= NULL
;
7960 set_buffer_internal_1 (obuf
);
7962 /* Set the title only if it's changed. This avoids consing in
7963 the common case where it hasn't. (If it turns out that we've
7964 already wasted too much time by walking through the list with
7965 display_mode_element, then we might need to optimize at a
7966 higher level than this.) */
7967 if (! STRINGP (f
->name
)
7968 || SBYTES (f
->name
) != len
7969 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7970 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7974 #endif /* not HAVE_WINDOW_SYSTEM */
7979 /***********************************************************************
7981 ***********************************************************************/
7984 /* Prepare for redisplay by updating menu-bar item lists when
7985 appropriate. This can call eval. */
7988 prepare_menu_bars ()
7991 struct gcpro gcpro1
, gcpro2
;
7993 Lisp_Object tooltip_frame
;
7995 #ifdef HAVE_WINDOW_SYSTEM
7996 tooltip_frame
= tip_frame
;
7998 tooltip_frame
= Qnil
;
8001 /* Update all frame titles based on their buffer names, etc. We do
8002 this before the menu bars so that the buffer-menu will show the
8003 up-to-date frame titles. */
8004 #ifdef HAVE_WINDOW_SYSTEM
8005 if (windows_or_buffers_changed
|| update_mode_lines
)
8007 Lisp_Object tail
, frame
;
8009 FOR_EACH_FRAME (tail
, frame
)
8012 if (!EQ (frame
, tooltip_frame
)
8013 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8014 x_consider_frame_title (frame
);
8017 #endif /* HAVE_WINDOW_SYSTEM */
8019 /* Update the menu bar item lists, if appropriate. This has to be
8020 done before any actual redisplay or generation of display lines. */
8021 all_windows
= (update_mode_lines
8022 || buffer_shared
> 1
8023 || windows_or_buffers_changed
);
8026 Lisp_Object tail
, frame
;
8027 int count
= SPECPDL_INDEX ();
8029 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8031 FOR_EACH_FRAME (tail
, frame
)
8035 /* Ignore tooltip frame. */
8036 if (EQ (frame
, tooltip_frame
))
8039 /* If a window on this frame changed size, report that to
8040 the user and clear the size-change flag. */
8041 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8043 Lisp_Object functions
;
8045 /* Clear flag first in case we get an error below. */
8046 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8047 functions
= Vwindow_size_change_functions
;
8048 GCPRO2 (tail
, functions
);
8050 while (CONSP (functions
))
8052 call1 (XCAR (functions
), frame
);
8053 functions
= XCDR (functions
);
8059 update_menu_bar (f
, 0);
8060 #ifdef HAVE_WINDOW_SYSTEM
8061 update_tool_bar (f
, 0);
8066 unbind_to (count
, Qnil
);
8070 struct frame
*sf
= SELECTED_FRAME ();
8071 update_menu_bar (sf
, 1);
8072 #ifdef HAVE_WINDOW_SYSTEM
8073 update_tool_bar (sf
, 1);
8077 /* Motif needs this. See comment in xmenu.c. Turn it off when
8078 pending_menu_activation is not defined. */
8079 #ifdef USE_X_TOOLKIT
8080 pending_menu_activation
= 0;
8085 /* Update the menu bar item list for frame F. This has to be done
8086 before we start to fill in any display lines, because it can call
8089 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8092 update_menu_bar (f
, save_match_data
)
8094 int save_match_data
;
8097 register struct window
*w
;
8099 /* If called recursively during a menu update, do nothing. This can
8100 happen when, for instance, an activate-menubar-hook causes a
8102 if (inhibit_menubar_update
)
8105 window
= FRAME_SELECTED_WINDOW (f
);
8106 w
= XWINDOW (window
);
8108 #if 0 /* The if statement below this if statement used to include the
8109 condition !NILP (w->update_mode_line), rather than using
8110 update_mode_lines directly, and this if statement may have
8111 been added to make that condition work. Now the if
8112 statement below matches its comment, this isn't needed. */
8113 if (update_mode_lines
)
8114 w
->update_mode_line
= Qt
;
8117 if (FRAME_WINDOW_P (f
)
8119 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8120 || defined (USE_GTK)
8121 FRAME_EXTERNAL_MENU_BAR (f
)
8123 FRAME_MENU_BAR_LINES (f
) > 0
8125 : FRAME_MENU_BAR_LINES (f
) > 0)
8127 /* If the user has switched buffers or windows, we need to
8128 recompute to reflect the new bindings. But we'll
8129 recompute when update_mode_lines is set too; that means
8130 that people can use force-mode-line-update to request
8131 that the menu bar be recomputed. The adverse effect on
8132 the rest of the redisplay algorithm is about the same as
8133 windows_or_buffers_changed anyway. */
8134 if (windows_or_buffers_changed
8135 /* This used to test w->update_mode_line, but we believe
8136 there is no need to recompute the menu in that case. */
8137 || update_mode_lines
8138 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8139 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8140 != !NILP (w
->last_had_star
))
8141 || ((!NILP (Vtransient_mark_mode
)
8142 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8143 != !NILP (w
->region_showing
)))
8145 struct buffer
*prev
= current_buffer
;
8146 int count
= SPECPDL_INDEX ();
8148 specbind (Qinhibit_menubar_update
, Qt
);
8150 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8151 if (save_match_data
)
8152 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8153 if (NILP (Voverriding_local_map_menu_flag
))
8155 specbind (Qoverriding_terminal_local_map
, Qnil
);
8156 specbind (Qoverriding_local_map
, Qnil
);
8159 /* Run the Lucid hook. */
8160 safe_run_hooks (Qactivate_menubar_hook
);
8162 /* If it has changed current-menubar from previous value,
8163 really recompute the menu-bar from the value. */
8164 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8165 call0 (Qrecompute_lucid_menubar
);
8167 safe_run_hooks (Qmenu_bar_update_hook
);
8168 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8170 /* Redisplay the menu bar in case we changed it. */
8171 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8172 || defined (USE_GTK)
8173 if (FRAME_WINDOW_P (f
)
8174 #if defined (MAC_OS)
8175 /* All frames on Mac OS share the same menubar. So only the
8176 selected frame should be allowed to set it. */
8177 && f
== SELECTED_FRAME ()
8180 set_frame_menubar (f
, 0, 0);
8182 /* On a terminal screen, the menu bar is an ordinary screen
8183 line, and this makes it get updated. */
8184 w
->update_mode_line
= Qt
;
8185 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8186 /* In the non-toolkit version, the menu bar is an ordinary screen
8187 line, and this makes it get updated. */
8188 w
->update_mode_line
= Qt
;
8189 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8191 unbind_to (count
, Qnil
);
8192 set_buffer_internal_1 (prev
);
8199 /***********************************************************************
8201 ***********************************************************************/
8203 #ifdef HAVE_WINDOW_SYSTEM
8206 Nominal cursor position -- where to draw output.
8207 HPOS and VPOS are window relative glyph matrix coordinates.
8208 X and Y are window relative pixel coordinates. */
8210 struct cursor_pos output_cursor
;
8214 Set the global variable output_cursor to CURSOR. All cursor
8215 positions are relative to updated_window. */
8218 set_output_cursor (cursor
)
8219 struct cursor_pos
*cursor
;
8221 output_cursor
.hpos
= cursor
->hpos
;
8222 output_cursor
.vpos
= cursor
->vpos
;
8223 output_cursor
.x
= cursor
->x
;
8224 output_cursor
.y
= cursor
->y
;
8229 Set a nominal cursor position.
8231 HPOS and VPOS are column/row positions in a window glyph matrix. X
8232 and Y are window text area relative pixel positions.
8234 If this is done during an update, updated_window will contain the
8235 window that is being updated and the position is the future output
8236 cursor position for that window. If updated_window is null, use
8237 selected_window and display the cursor at the given position. */
8240 x_cursor_to (vpos
, hpos
, y
, x
)
8241 int vpos
, hpos
, y
, x
;
8245 /* If updated_window is not set, work on selected_window. */
8249 w
= XWINDOW (selected_window
);
8251 /* Set the output cursor. */
8252 output_cursor
.hpos
= hpos
;
8253 output_cursor
.vpos
= vpos
;
8254 output_cursor
.x
= x
;
8255 output_cursor
.y
= y
;
8257 /* If not called as part of an update, really display the cursor.
8258 This will also set the cursor position of W. */
8259 if (updated_window
== NULL
)
8262 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8263 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
8264 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
8269 #endif /* HAVE_WINDOW_SYSTEM */
8272 /***********************************************************************
8274 ***********************************************************************/
8276 #ifdef HAVE_WINDOW_SYSTEM
8278 /* Where the mouse was last time we reported a mouse event. */
8280 FRAME_PTR last_mouse_frame
;
8282 /* Tool-bar item index of the item on which a mouse button was pressed
8285 int last_tool_bar_item
;
8288 /* Update the tool-bar item list for frame F. This has to be done
8289 before we start to fill in any display lines. Called from
8290 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8291 and restore it here. */
8294 update_tool_bar (f
, save_match_data
)
8296 int save_match_data
;
8299 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8301 int do_update
= WINDOWP (f
->tool_bar_window
)
8302 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8310 window
= FRAME_SELECTED_WINDOW (f
);
8311 w
= XWINDOW (window
);
8313 /* If the user has switched buffers or windows, we need to
8314 recompute to reflect the new bindings. But we'll
8315 recompute when update_mode_lines is set too; that means
8316 that people can use force-mode-line-update to request
8317 that the menu bar be recomputed. The adverse effect on
8318 the rest of the redisplay algorithm is about the same as
8319 windows_or_buffers_changed anyway. */
8320 if (windows_or_buffers_changed
8321 || !NILP (w
->update_mode_line
)
8322 || update_mode_lines
8323 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8324 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8325 != !NILP (w
->last_had_star
))
8326 || ((!NILP (Vtransient_mark_mode
)
8327 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8328 != !NILP (w
->region_showing
)))
8330 struct buffer
*prev
= current_buffer
;
8331 int count
= SPECPDL_INDEX ();
8332 Lisp_Object old_tool_bar
;
8333 struct gcpro gcpro1
;
8335 /* Set current_buffer to the buffer of the selected
8336 window of the frame, so that we get the right local
8338 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8340 /* Save match data, if we must. */
8341 if (save_match_data
)
8342 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8344 /* Make sure that we don't accidentally use bogus keymaps. */
8345 if (NILP (Voverriding_local_map_menu_flag
))
8347 specbind (Qoverriding_terminal_local_map
, Qnil
);
8348 specbind (Qoverriding_local_map
, Qnil
);
8351 old_tool_bar
= f
->tool_bar_items
;
8352 GCPRO1 (old_tool_bar
);
8354 /* Build desired tool-bar items from keymaps. */
8357 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8360 /* Redisplay the tool-bar if we changed it. */
8361 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8362 w
->update_mode_line
= Qt
;
8366 unbind_to (count
, Qnil
);
8367 set_buffer_internal_1 (prev
);
8373 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8374 F's desired tool-bar contents. F->tool_bar_items must have
8375 been set up previously by calling prepare_menu_bars. */
8378 build_desired_tool_bar_string (f
)
8381 int i
, size
, size_needed
;
8382 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8383 Lisp_Object image
, plist
, props
;
8385 image
= plist
= props
= Qnil
;
8386 GCPRO3 (image
, plist
, props
);
8388 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8389 Otherwise, make a new string. */
8391 /* The size of the string we might be able to reuse. */
8392 size
= (STRINGP (f
->desired_tool_bar_string
)
8393 ? SCHARS (f
->desired_tool_bar_string
)
8396 /* We need one space in the string for each image. */
8397 size_needed
= f
->n_tool_bar_items
;
8399 /* Reuse f->desired_tool_bar_string, if possible. */
8400 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8401 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8405 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8406 Fremove_text_properties (make_number (0), make_number (size
),
8407 props
, f
->desired_tool_bar_string
);
8410 /* Put a `display' property on the string for the images to display,
8411 put a `menu_item' property on tool-bar items with a value that
8412 is the index of the item in F's tool-bar item vector. */
8413 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8415 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8417 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8418 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8419 int hmargin
, vmargin
, relief
, idx
, end
;
8420 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8422 /* If image is a vector, choose the image according to the
8424 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8425 if (VECTORP (image
))
8429 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8430 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8433 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8434 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8436 xassert (ASIZE (image
) >= idx
);
8437 image
= AREF (image
, idx
);
8442 /* Ignore invalid image specifications. */
8443 if (!valid_image_p (image
))
8446 /* Display the tool-bar button pressed, or depressed. */
8447 plist
= Fcopy_sequence (XCDR (image
));
8449 /* Compute margin and relief to draw. */
8450 relief
= (tool_bar_button_relief
>= 0
8451 ? tool_bar_button_relief
8452 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8453 hmargin
= vmargin
= relief
;
8455 if (INTEGERP (Vtool_bar_button_margin
)
8456 && XINT (Vtool_bar_button_margin
) > 0)
8458 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8459 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8461 else if (CONSP (Vtool_bar_button_margin
))
8463 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8464 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8465 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8467 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8468 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8469 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8472 if (auto_raise_tool_bar_buttons_p
)
8474 /* Add a `:relief' property to the image spec if the item is
8478 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8485 /* If image is selected, display it pressed, i.e. with a
8486 negative relief. If it's not selected, display it with a
8488 plist
= Fplist_put (plist
, QCrelief
,
8490 ? make_number (-relief
)
8491 : make_number (relief
)));
8496 /* Put a margin around the image. */
8497 if (hmargin
|| vmargin
)
8499 if (hmargin
== vmargin
)
8500 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8502 plist
= Fplist_put (plist
, QCmargin
,
8503 Fcons (make_number (hmargin
),
8504 make_number (vmargin
)));
8507 /* If button is not enabled, and we don't have special images
8508 for the disabled state, make the image appear disabled by
8509 applying an appropriate algorithm to it. */
8510 if (!enabled_p
&& idx
< 0)
8511 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8513 /* Put a `display' text property on the string for the image to
8514 display. Put a `menu-item' property on the string that gives
8515 the start of this item's properties in the tool-bar items
8517 image
= Fcons (Qimage
, plist
);
8518 props
= list4 (Qdisplay
, image
,
8519 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8521 /* Let the last image hide all remaining spaces in the tool bar
8522 string. The string can be longer than needed when we reuse a
8524 if (i
+ 1 == f
->n_tool_bar_items
)
8525 end
= SCHARS (f
->desired_tool_bar_string
);
8528 Fadd_text_properties (make_number (i
), make_number (end
),
8529 props
, f
->desired_tool_bar_string
);
8537 /* Display one line of the tool-bar of frame IT->f. */
8540 display_tool_bar_line (it
)
8543 struct glyph_row
*row
= it
->glyph_row
;
8544 int max_x
= it
->last_visible_x
;
8547 prepare_desired_row (row
);
8548 row
->y
= it
->current_y
;
8550 /* Note that this isn't made use of if the face hasn't a box,
8551 so there's no need to check the face here. */
8552 it
->start_of_box_run_p
= 1;
8554 while (it
->current_x
< max_x
)
8556 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8558 /* Get the next display element. */
8559 if (!get_next_display_element (it
))
8562 /* Produce glyphs. */
8563 x_before
= it
->current_x
;
8564 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8565 PRODUCE_GLYPHS (it
);
8567 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8572 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8574 if (x
+ glyph
->pixel_width
> max_x
)
8576 /* Glyph doesn't fit on line. */
8577 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8583 x
+= glyph
->pixel_width
;
8587 /* Stop at line ends. */
8588 if (ITERATOR_AT_END_OF_LINE_P (it
))
8591 set_iterator_to_next (it
, 1);
8596 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8597 extend_face_to_end_of_line (it
);
8598 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8599 last
->right_box_line_p
= 1;
8600 if (last
== row
->glyphs
[TEXT_AREA
])
8601 last
->left_box_line_p
= 1;
8602 compute_line_metrics (it
);
8604 /* If line is empty, make it occupy the rest of the tool-bar. */
8605 if (!row
->displays_text_p
)
8607 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8608 row
->ascent
= row
->phys_ascent
= 0;
8611 row
->full_width_p
= 1;
8612 row
->continued_p
= 0;
8613 row
->truncated_on_left_p
= 0;
8614 row
->truncated_on_right_p
= 0;
8616 it
->current_x
= it
->hpos
= 0;
8617 it
->current_y
+= row
->height
;
8623 /* Value is the number of screen lines needed to make all tool-bar
8624 items of frame F visible. */
8627 tool_bar_lines_needed (f
)
8630 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8633 /* Initialize an iterator for iteration over
8634 F->desired_tool_bar_string in the tool-bar window of frame F. */
8635 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8636 it
.first_visible_x
= 0;
8637 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8638 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8640 while (!ITERATOR_AT_END_P (&it
))
8642 it
.glyph_row
= w
->desired_matrix
->rows
;
8643 clear_glyph_row (it
.glyph_row
);
8644 display_tool_bar_line (&it
);
8647 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8651 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8653 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8662 frame
= selected_frame
;
8664 CHECK_FRAME (frame
);
8667 if (WINDOWP (f
->tool_bar_window
)
8668 || (w
= XWINDOW (f
->tool_bar_window
),
8669 WINDOW_TOTAL_LINES (w
) > 0))
8671 update_tool_bar (f
, 1);
8672 if (f
->n_tool_bar_items
)
8674 build_desired_tool_bar_string (f
);
8675 nlines
= tool_bar_lines_needed (f
);
8679 return make_number (nlines
);
8683 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8684 height should be changed. */
8687 redisplay_tool_bar (f
)
8692 struct glyph_row
*row
;
8693 int change_height_p
= 0;
8696 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8697 update_frame_tool_bar (f
);
8701 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8702 do anything. This means you must start with tool-bar-lines
8703 non-zero to get the auto-sizing effect. Or in other words, you
8704 can turn off tool-bars by specifying tool-bar-lines zero. */
8705 if (!WINDOWP (f
->tool_bar_window
)
8706 || (w
= XWINDOW (f
->tool_bar_window
),
8707 WINDOW_TOTAL_LINES (w
) == 0))
8710 /* Set up an iterator for the tool-bar window. */
8711 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8712 it
.first_visible_x
= 0;
8713 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8716 /* Build a string that represents the contents of the tool-bar. */
8717 build_desired_tool_bar_string (f
);
8718 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8720 /* Display as many lines as needed to display all tool-bar items. */
8721 while (it
.current_y
< it
.last_visible_y
)
8722 display_tool_bar_line (&it
);
8724 /* It doesn't make much sense to try scrolling in the tool-bar
8725 window, so don't do it. */
8726 w
->desired_matrix
->no_scrolling_p
= 1;
8727 w
->must_be_updated_p
= 1;
8729 if (auto_resize_tool_bars_p
)
8733 /* If we couldn't display everything, change the tool-bar's
8735 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8736 change_height_p
= 1;
8738 /* If there are blank lines at the end, except for a partially
8739 visible blank line at the end that is smaller than
8740 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8741 row
= it
.glyph_row
- 1;
8742 if (!row
->displays_text_p
8743 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8744 change_height_p
= 1;
8746 /* If row displays tool-bar items, but is partially visible,
8747 change the tool-bar's height. */
8748 if (row
->displays_text_p
8749 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8750 change_height_p
= 1;
8752 /* Resize windows as needed by changing the `tool-bar-lines'
8755 && (nlines
= tool_bar_lines_needed (f
),
8756 nlines
!= WINDOW_TOTAL_LINES (w
)))
8758 extern Lisp_Object Qtool_bar_lines
;
8760 int old_height
= WINDOW_TOTAL_LINES (w
);
8762 XSETFRAME (frame
, f
);
8763 clear_glyph_matrix (w
->desired_matrix
);
8764 Fmodify_frame_parameters (frame
,
8765 Fcons (Fcons (Qtool_bar_lines
,
8766 make_number (nlines
)),
8768 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8769 fonts_changed_p
= 1;
8773 return change_height_p
;
8777 /* Get information about the tool-bar item which is displayed in GLYPH
8778 on frame F. Return in *PROP_IDX the index where tool-bar item
8779 properties start in F->tool_bar_items. Value is zero if
8780 GLYPH doesn't display a tool-bar item. */
8783 tool_bar_item_info (f
, glyph
, prop_idx
)
8785 struct glyph
*glyph
;
8792 /* This function can be called asynchronously, which means we must
8793 exclude any possibility that Fget_text_property signals an
8795 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8796 charpos
= max (0, charpos
);
8798 /* Get the text property `menu-item' at pos. The value of that
8799 property is the start index of this item's properties in
8800 F->tool_bar_items. */
8801 prop
= Fget_text_property (make_number (charpos
),
8802 Qmenu_item
, f
->current_tool_bar_string
);
8803 if (INTEGERP (prop
))
8805 *prop_idx
= XINT (prop
);
8815 /* Get information about the tool-bar item at position X/Y on frame F.
8816 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8817 the current matrix of the tool-bar window of F, or NULL if not
8818 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8819 item in F->tool_bar_items. Value is
8821 -1 if X/Y is not on a tool-bar item
8822 0 if X/Y is on the same item that was highlighted before.
8826 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8829 struct glyph
**glyph
;
8830 int *hpos
, *vpos
, *prop_idx
;
8832 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8833 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8836 /* Find the glyph under X/Y. */
8837 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8841 /* Get the start of this tool-bar item's properties in
8842 f->tool_bar_items. */
8843 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8846 /* Is mouse on the highlighted item? */
8847 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8848 && *vpos
>= dpyinfo
->mouse_face_beg_row
8849 && *vpos
<= dpyinfo
->mouse_face_end_row
8850 && (*vpos
> dpyinfo
->mouse_face_beg_row
8851 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8852 && (*vpos
< dpyinfo
->mouse_face_end_row
8853 || *hpos
< dpyinfo
->mouse_face_end_col
8854 || dpyinfo
->mouse_face_past_end
))
8862 Handle mouse button event on the tool-bar of frame F, at
8863 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8864 0 for button release. MODIFIERS is event modifiers for button
8868 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8871 unsigned int modifiers
;
8873 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8874 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8875 int hpos
, vpos
, prop_idx
;
8876 struct glyph
*glyph
;
8877 Lisp_Object enabled_p
;
8879 /* If not on the highlighted tool-bar item, return. */
8880 frame_to_window_pixel_xy (w
, &x
, &y
);
8881 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8884 /* If item is disabled, do nothing. */
8885 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8886 if (NILP (enabled_p
))
8891 /* Show item in pressed state. */
8892 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8893 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8894 last_tool_bar_item
= prop_idx
;
8898 Lisp_Object key
, frame
;
8899 struct input_event event
;
8902 /* Show item in released state. */
8903 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8904 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8906 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8908 XSETFRAME (frame
, f
);
8909 event
.kind
= TOOL_BAR_EVENT
;
8910 event
.frame_or_window
= frame
;
8912 kbd_buffer_store_event (&event
);
8914 event
.kind
= TOOL_BAR_EVENT
;
8915 event
.frame_or_window
= frame
;
8917 event
.modifiers
= modifiers
;
8918 kbd_buffer_store_event (&event
);
8919 last_tool_bar_item
= -1;
8924 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8925 tool-bar window-relative coordinates X/Y. Called from
8926 note_mouse_highlight. */
8929 note_tool_bar_highlight (f
, x
, y
)
8933 Lisp_Object window
= f
->tool_bar_window
;
8934 struct window
*w
= XWINDOW (window
);
8935 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8937 struct glyph
*glyph
;
8938 struct glyph_row
*row
;
8940 Lisp_Object enabled_p
;
8942 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
8943 int mouse_down_p
, rc
;
8945 /* Function note_mouse_highlight is called with negative x(y
8946 values when mouse moves outside of the frame. */
8947 if (x
<= 0 || y
<= 0)
8949 clear_mouse_face (dpyinfo
);
8953 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
8956 /* Not on tool-bar item. */
8957 clear_mouse_face (dpyinfo
);
8961 /* On same tool-bar item as before. */
8964 clear_mouse_face (dpyinfo
);
8966 /* Mouse is down, but on different tool-bar item? */
8967 mouse_down_p
= (dpyinfo
->grabbed
8968 && f
== last_mouse_frame
8969 && FRAME_LIVE_P (f
));
8971 && last_tool_bar_item
!= prop_idx
)
8974 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
8975 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
8977 /* If tool-bar item is not enabled, don't highlight it. */
8978 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8979 if (!NILP (enabled_p
))
8981 /* Compute the x-position of the glyph. In front and past the
8982 image is a space. We include this in the highlighted area. */
8983 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
8984 for (i
= x
= 0; i
< hpos
; ++i
)
8985 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
8987 /* Record this as the current active region. */
8988 dpyinfo
->mouse_face_beg_col
= hpos
;
8989 dpyinfo
->mouse_face_beg_row
= vpos
;
8990 dpyinfo
->mouse_face_beg_x
= x
;
8991 dpyinfo
->mouse_face_beg_y
= row
->y
;
8992 dpyinfo
->mouse_face_past_end
= 0;
8994 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
8995 dpyinfo
->mouse_face_end_row
= vpos
;
8996 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
8997 dpyinfo
->mouse_face_end_y
= row
->y
;
8998 dpyinfo
->mouse_face_window
= window
;
8999 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9001 /* Display it as active. */
9002 show_mouse_face (dpyinfo
, draw
);
9003 dpyinfo
->mouse_face_image_state
= draw
;
9008 /* Set help_echo_string to a help string to display for this tool-bar item.
9009 XTread_socket does the rest. */
9010 help_echo_object
= help_echo_window
= Qnil
;
9012 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9013 if (NILP (help_echo_string
))
9014 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9017 #endif /* HAVE_WINDOW_SYSTEM */
9021 /************************************************************************
9022 Horizontal scrolling
9023 ************************************************************************/
9025 static int hscroll_window_tree
P_ ((Lisp_Object
));
9026 static int hscroll_windows
P_ ((Lisp_Object
));
9028 /* For all leaf windows in the window tree rooted at WINDOW, set their
9029 hscroll value so that PT is (i) visible in the window, and (ii) so
9030 that it is not within a certain margin at the window's left and
9031 right border. Value is non-zero if any window's hscroll has been
9035 hscroll_window_tree (window
)
9038 int hscrolled_p
= 0;
9039 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9040 int hscroll_step_abs
= 0;
9041 double hscroll_step_rel
= 0;
9043 if (hscroll_relative_p
)
9045 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9046 if (hscroll_step_rel
< 0)
9048 hscroll_relative_p
= 0;
9049 hscroll_step_abs
= 0;
9052 else if (INTEGERP (Vhscroll_step
))
9054 hscroll_step_abs
= XINT (Vhscroll_step
);
9055 if (hscroll_step_abs
< 0)
9056 hscroll_step_abs
= 0;
9059 hscroll_step_abs
= 0;
9061 while (WINDOWP (window
))
9063 struct window
*w
= XWINDOW (window
);
9065 if (WINDOWP (w
->hchild
))
9066 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9067 else if (WINDOWP (w
->vchild
))
9068 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9069 else if (w
->cursor
.vpos
>= 0)
9072 int text_area_width
;
9073 struct glyph_row
*current_cursor_row
9074 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9075 struct glyph_row
*desired_cursor_row
9076 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9077 struct glyph_row
*cursor_row
9078 = (desired_cursor_row
->enabled_p
9079 ? desired_cursor_row
9080 : current_cursor_row
);
9082 text_area_width
= window_box_width (w
, TEXT_AREA
);
9084 /* Scroll when cursor is inside this scroll margin. */
9085 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9087 if ((XFASTINT (w
->hscroll
)
9088 && w
->cursor
.x
<= h_margin
)
9089 || (cursor_row
->enabled_p
9090 && cursor_row
->truncated_on_right_p
9091 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9095 struct buffer
*saved_current_buffer
;
9099 /* Find point in a display of infinite width. */
9100 saved_current_buffer
= current_buffer
;
9101 current_buffer
= XBUFFER (w
->buffer
);
9103 if (w
== XWINDOW (selected_window
))
9104 pt
= BUF_PT (current_buffer
);
9107 pt
= marker_position (w
->pointm
);
9108 pt
= max (BEGV
, pt
);
9112 /* Move iterator to pt starting at cursor_row->start in
9113 a line with infinite width. */
9114 init_to_row_start (&it
, w
, cursor_row
);
9115 it
.last_visible_x
= INFINITY
;
9116 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9117 current_buffer
= saved_current_buffer
;
9119 /* Position cursor in window. */
9120 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9121 hscroll
= max (0, (it
.current_x
9122 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9123 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9124 : (text_area_width
/ 2))))
9125 / FRAME_COLUMN_WIDTH (it
.f
);
9126 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9128 if (hscroll_relative_p
)
9129 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9132 wanted_x
= text_area_width
9133 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9136 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9140 if (hscroll_relative_p
)
9141 wanted_x
= text_area_width
* hscroll_step_rel
9144 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9147 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9149 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9151 /* Don't call Fset_window_hscroll if value hasn't
9152 changed because it will prevent redisplay
9154 if (XFASTINT (w
->hscroll
) != hscroll
)
9156 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9157 w
->hscroll
= make_number (hscroll
);
9166 /* Value is non-zero if hscroll of any leaf window has been changed. */
9171 /* Set hscroll so that cursor is visible and not inside horizontal
9172 scroll margins for all windows in the tree rooted at WINDOW. See
9173 also hscroll_window_tree above. Value is non-zero if any window's
9174 hscroll has been changed. If it has, desired matrices on the frame
9175 of WINDOW are cleared. */
9178 hscroll_windows (window
)
9183 if (automatic_hscrolling_p
)
9185 hscrolled_p
= hscroll_window_tree (window
);
9187 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9196 /************************************************************************
9198 ************************************************************************/
9200 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9201 to a non-zero value. This is sometimes handy to have in a debugger
9206 /* First and last unchanged row for try_window_id. */
9208 int debug_first_unchanged_at_end_vpos
;
9209 int debug_last_unchanged_at_beg_vpos
;
9211 /* Delta vpos and y. */
9213 int debug_dvpos
, debug_dy
;
9215 /* Delta in characters and bytes for try_window_id. */
9217 int debug_delta
, debug_delta_bytes
;
9219 /* Values of window_end_pos and window_end_vpos at the end of
9222 EMACS_INT debug_end_pos
, debug_end_vpos
;
9224 /* Append a string to W->desired_matrix->method. FMT is a printf
9225 format string. A1...A9 are a supplement for a variable-length
9226 argument list. If trace_redisplay_p is non-zero also printf the
9227 resulting string to stderr. */
9230 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9233 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9236 char *method
= w
->desired_matrix
->method
;
9237 int len
= strlen (method
);
9238 int size
= sizeof w
->desired_matrix
->method
;
9239 int remaining
= size
- len
- 1;
9241 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9242 if (len
&& remaining
)
9248 strncpy (method
+ len
, buffer
, remaining
);
9250 if (trace_redisplay_p
)
9251 fprintf (stderr
, "%p (%s): %s\n",
9253 ((BUFFERP (w
->buffer
)
9254 && STRINGP (XBUFFER (w
->buffer
)->name
))
9255 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9260 #endif /* GLYPH_DEBUG */
9263 /* Value is non-zero if all changes in window W, which displays
9264 current_buffer, are in the text between START and END. START is a
9265 buffer position, END is given as a distance from Z. Used in
9266 redisplay_internal for display optimization. */
9269 text_outside_line_unchanged_p (w
, start
, end
)
9273 int unchanged_p
= 1;
9275 /* If text or overlays have changed, see where. */
9276 if (XFASTINT (w
->last_modified
) < MODIFF
9277 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9279 /* Gap in the line? */
9280 if (GPT
< start
|| Z
- GPT
< end
)
9283 /* Changes start in front of the line, or end after it? */
9285 && (BEG_UNCHANGED
< start
- 1
9286 || END_UNCHANGED
< end
))
9289 /* If selective display, can't optimize if changes start at the
9290 beginning of the line. */
9292 && INTEGERP (current_buffer
->selective_display
)
9293 && XINT (current_buffer
->selective_display
) > 0
9294 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9297 /* If there are overlays at the start or end of the line, these
9298 may have overlay strings with newlines in them. A change at
9299 START, for instance, may actually concern the display of such
9300 overlay strings as well, and they are displayed on different
9301 lines. So, quickly rule out this case. (For the future, it
9302 might be desirable to implement something more telling than
9303 just BEG/END_UNCHANGED.) */
9306 if (BEG
+ BEG_UNCHANGED
== start
9307 && overlay_touches_p (start
))
9309 if (END_UNCHANGED
== end
9310 && overlay_touches_p (Z
- end
))
9319 /* Do a frame update, taking possible shortcuts into account. This is
9320 the main external entry point for redisplay.
9322 If the last redisplay displayed an echo area message and that message
9323 is no longer requested, we clear the echo area or bring back the
9324 mini-buffer if that is in use. */
9329 redisplay_internal (0);
9334 overlay_arrow_string_or_property (var
, pbitmap
)
9338 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9344 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9345 *pbitmap
= XINT (bitmap
);
9350 return Voverlay_arrow_string
;
9353 /* Return 1 if there are any overlay-arrows in current_buffer. */
9355 overlay_arrow_in_current_buffer_p ()
9359 for (vlist
= Voverlay_arrow_variable_list
;
9361 vlist
= XCDR (vlist
))
9363 Lisp_Object var
= XCAR (vlist
);
9368 val
= find_symbol_value (var
);
9370 && current_buffer
== XMARKER (val
)->buffer
)
9377 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9381 overlay_arrows_changed_p ()
9385 for (vlist
= Voverlay_arrow_variable_list
;
9387 vlist
= XCDR (vlist
))
9389 Lisp_Object var
= XCAR (vlist
);
9390 Lisp_Object val
, pstr
;
9394 val
= find_symbol_value (var
);
9397 if (! EQ (COERCE_MARKER (val
),
9398 Fget (var
, Qlast_arrow_position
))
9399 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9400 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9406 /* Mark overlay arrows to be updated on next redisplay. */
9409 update_overlay_arrows (up_to_date
)
9414 for (vlist
= Voverlay_arrow_variable_list
;
9416 vlist
= XCDR (vlist
))
9418 Lisp_Object var
= XCAR (vlist
);
9425 Lisp_Object val
= find_symbol_value (var
);
9426 Fput (var
, Qlast_arrow_position
,
9427 COERCE_MARKER (val
));
9428 Fput (var
, Qlast_arrow_string
,
9429 overlay_arrow_string_or_property (var
, 0));
9431 else if (up_to_date
< 0
9432 || !NILP (Fget (var
, Qlast_arrow_position
)))
9434 Fput (var
, Qlast_arrow_position
, Qt
);
9435 Fput (var
, Qlast_arrow_string
, Qt
);
9441 /* Return overlay arrow string at row, or nil. */
9444 overlay_arrow_at_row (f
, row
, pbitmap
)
9446 struct glyph_row
*row
;
9451 for (vlist
= Voverlay_arrow_variable_list
;
9453 vlist
= XCDR (vlist
))
9455 Lisp_Object var
= XCAR (vlist
);
9461 val
= find_symbol_value (var
);
9464 && current_buffer
== XMARKER (val
)->buffer
9465 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9467 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9468 if (FRAME_WINDOW_P (f
))
9470 else if (STRINGP (val
))
9480 /* Return 1 if point moved out of or into a composition. Otherwise
9481 return 0. PREV_BUF and PREV_PT are the last point buffer and
9482 position. BUF and PT are the current point buffer and position. */
9485 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9486 struct buffer
*prev_buf
, *buf
;
9493 XSETBUFFER (buffer
, buf
);
9494 /* Check a composition at the last point if point moved within the
9496 if (prev_buf
== buf
)
9499 /* Point didn't move. */
9502 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9503 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9504 && COMPOSITION_VALID_P (start
, end
, prop
)
9505 && start
< prev_pt
&& end
> prev_pt
)
9506 /* The last point was within the composition. Return 1 iff
9507 point moved out of the composition. */
9508 return (pt
<= start
|| pt
>= end
);
9511 /* Check a composition at the current point. */
9512 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9513 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9514 && COMPOSITION_VALID_P (start
, end
, prop
)
9515 && start
< pt
&& end
> pt
);
9519 /* Reconsider the setting of B->clip_changed which is displayed
9523 reconsider_clip_changes (w
, b
)
9528 && !NILP (w
->window_end_valid
)
9529 && w
->current_matrix
->buffer
== b
9530 && w
->current_matrix
->zv
== BUF_ZV (b
)
9531 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9532 b
->clip_changed
= 0;
9534 /* If display wasn't paused, and W is not a tool bar window, see if
9535 point has been moved into or out of a composition. In that case,
9536 we set b->clip_changed to 1 to force updating the screen. If
9537 b->clip_changed has already been set to 1, we can skip this
9539 if (!b
->clip_changed
9540 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9544 if (w
== XWINDOW (selected_window
))
9545 pt
= BUF_PT (current_buffer
);
9547 pt
= marker_position (w
->pointm
);
9549 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9550 || pt
!= XINT (w
->last_point
))
9551 && check_point_in_composition (w
->current_matrix
->buffer
,
9552 XINT (w
->last_point
),
9553 XBUFFER (w
->buffer
), pt
))
9554 b
->clip_changed
= 1;
9559 /* Select FRAME to forward the values of frame-local variables into C
9560 variables so that the redisplay routines can access those values
9564 select_frame_for_redisplay (frame
)
9567 Lisp_Object tail
, sym
, val
;
9568 Lisp_Object old
= selected_frame
;
9570 selected_frame
= frame
;
9572 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9573 if (CONSP (XCAR (tail
))
9574 && (sym
= XCAR (XCAR (tail
)),
9576 && (sym
= indirect_variable (sym
),
9577 val
= SYMBOL_VALUE (sym
),
9578 (BUFFER_LOCAL_VALUEP (val
)
9579 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9580 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9581 Fsymbol_value (sym
);
9583 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9584 if (CONSP (XCAR (tail
))
9585 && (sym
= XCAR (XCAR (tail
)),
9587 && (sym
= indirect_variable (sym
),
9588 val
= SYMBOL_VALUE (sym
),
9589 (BUFFER_LOCAL_VALUEP (val
)
9590 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9591 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9592 Fsymbol_value (sym
);
9596 #define STOP_POLLING \
9597 do { if (! polling_stopped_here) stop_polling (); \
9598 polling_stopped_here = 1; } while (0)
9600 #define RESUME_POLLING \
9601 do { if (polling_stopped_here) start_polling (); \
9602 polling_stopped_here = 0; } while (0)
9605 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9606 response to any user action; therefore, we should preserve the echo
9607 area. (Actually, our caller does that job.) Perhaps in the future
9608 avoid recentering windows if it is not necessary; currently that
9609 causes some problems. */
9612 redisplay_internal (preserve_echo_area
)
9613 int preserve_echo_area
;
9615 struct window
*w
= XWINDOW (selected_window
);
9616 struct frame
*f
= XFRAME (w
->frame
);
9618 int must_finish
= 0;
9619 struct text_pos tlbufpos
, tlendpos
;
9620 int number_of_visible_frames
;
9622 struct frame
*sf
= SELECTED_FRAME ();
9623 int polling_stopped_here
= 0;
9625 /* Non-zero means redisplay has to consider all windows on all
9626 frames. Zero means, only selected_window is considered. */
9627 int consider_all_windows_p
;
9629 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9631 /* No redisplay if running in batch mode or frame is not yet fully
9632 initialized, or redisplay is explicitly turned off by setting
9633 Vinhibit_redisplay. */
9635 || !NILP (Vinhibit_redisplay
)
9636 || !f
->glyphs_initialized_p
)
9639 /* The flag redisplay_performed_directly_p is set by
9640 direct_output_for_insert when it already did the whole screen
9641 update necessary. */
9642 if (redisplay_performed_directly_p
)
9644 redisplay_performed_directly_p
= 0;
9645 if (!hscroll_windows (selected_window
))
9649 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9650 if (popup_activated ())
9654 /* I don't think this happens but let's be paranoid. */
9658 /* Record a function that resets redisplaying_p to its old value
9659 when we leave this function. */
9660 count
= SPECPDL_INDEX ();
9661 record_unwind_protect (unwind_redisplay
,
9662 Fcons (make_number (redisplaying_p
), selected_frame
));
9664 specbind (Qinhibit_free_realized_faces
, Qnil
);
9668 reconsider_clip_changes (w
, current_buffer
);
9670 /* If new fonts have been loaded that make a glyph matrix adjustment
9671 necessary, do it. */
9672 if (fonts_changed_p
)
9674 adjust_glyphs (NULL
);
9675 ++windows_or_buffers_changed
;
9676 fonts_changed_p
= 0;
9679 /* If face_change_count is non-zero, init_iterator will free all
9680 realized faces, which includes the faces referenced from current
9681 matrices. So, we can't reuse current matrices in this case. */
9682 if (face_change_count
)
9683 ++windows_or_buffers_changed
;
9685 if (FRAME_TERMCAP_P (sf
)
9686 && FRAME_TTY (sf
)->previous_terminal_frame
!= sf
)
9688 /* Since frames on a single ASCII terminal share the same
9689 display area, displaying a different frame means redisplay
9691 windows_or_buffers_changed
++;
9692 SET_FRAME_GARBAGED (sf
);
9693 FRAME_TTY (sf
)->previous_terminal_frame
= sf
;
9696 /* Set the visible flags for all frames. Do this before checking
9697 for resized or garbaged frames; they want to know if their frames
9698 are visible. See the comment in frame.h for
9699 FRAME_SAMPLE_VISIBILITY. */
9701 Lisp_Object tail
, frame
;
9703 number_of_visible_frames
= 0;
9705 FOR_EACH_FRAME (tail
, frame
)
9707 struct frame
*f
= XFRAME (frame
);
9709 FRAME_SAMPLE_VISIBILITY (f
);
9710 if (FRAME_VISIBLE_P (f
))
9711 ++number_of_visible_frames
;
9712 clear_desired_matrices (f
);
9717 /* Notice any pending interrupt request to change frame size. */
9718 do_pending_window_change (1);
9720 /* Clear frames marked as garbaged. */
9722 clear_garbaged_frames ();
9724 /* Build menubar and tool-bar items. */
9725 prepare_menu_bars ();
9727 if (windows_or_buffers_changed
)
9728 update_mode_lines
++;
9730 /* Detect case that we need to write or remove a star in the mode line. */
9731 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9733 w
->update_mode_line
= Qt
;
9734 if (buffer_shared
> 1)
9735 update_mode_lines
++;
9738 /* If %c is in the mode line, update it if needed. */
9739 if (!NILP (w
->column_number_displayed
)
9740 /* This alternative quickly identifies a common case
9741 where no change is needed. */
9742 && !(PT
== XFASTINT (w
->last_point
)
9743 && XFASTINT (w
->last_modified
) >= MODIFF
9744 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9745 && (XFASTINT (w
->column_number_displayed
)
9746 != (int) current_column ())) /* iftc */
9747 w
->update_mode_line
= Qt
;
9749 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9751 /* The variable buffer_shared is set in redisplay_window and
9752 indicates that we redisplay a buffer in different windows. See
9754 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9755 || cursor_type_changed
);
9757 /* If specs for an arrow have changed, do thorough redisplay
9758 to ensure we remove any arrow that should no longer exist. */
9759 if (overlay_arrows_changed_p ())
9760 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9762 /* Normally the message* functions will have already displayed and
9763 updated the echo area, but the frame may have been trashed, or
9764 the update may have been preempted, so display the echo area
9765 again here. Checking message_cleared_p captures the case that
9766 the echo area should be cleared. */
9767 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9768 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9769 || (message_cleared_p
9770 && minibuf_level
== 0
9771 /* If the mini-window is currently selected, this means the
9772 echo-area doesn't show through. */
9773 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9775 int window_height_changed_p
= echo_area_display (0);
9778 /* If we don't display the current message, don't clear the
9779 message_cleared_p flag, because, if we did, we wouldn't clear
9780 the echo area in the next redisplay which doesn't preserve
9782 if (!display_last_displayed_message_p
)
9783 message_cleared_p
= 0;
9785 if (fonts_changed_p
)
9787 else if (window_height_changed_p
)
9789 consider_all_windows_p
= 1;
9790 ++update_mode_lines
;
9791 ++windows_or_buffers_changed
;
9793 /* If window configuration was changed, frames may have been
9794 marked garbaged. Clear them or we will experience
9795 surprises wrt scrolling. */
9797 clear_garbaged_frames ();
9800 else if (EQ (selected_window
, minibuf_window
)
9801 && (current_buffer
->clip_changed
9802 || XFASTINT (w
->last_modified
) < MODIFF
9803 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9804 && resize_mini_window (w
, 0))
9806 /* Resized active mini-window to fit the size of what it is
9807 showing if its contents might have changed. */
9809 consider_all_windows_p
= 1;
9810 ++windows_or_buffers_changed
;
9811 ++update_mode_lines
;
9813 /* If window configuration was changed, frames may have been
9814 marked garbaged. Clear them or we will experience
9815 surprises wrt scrolling. */
9817 clear_garbaged_frames ();
9821 /* If showing the region, and mark has changed, we must redisplay
9822 the whole window. The assignment to this_line_start_pos prevents
9823 the optimization directly below this if-statement. */
9824 if (((!NILP (Vtransient_mark_mode
)
9825 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9826 != !NILP (w
->region_showing
))
9827 || (!NILP (w
->region_showing
)
9828 && !EQ (w
->region_showing
,
9829 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9830 CHARPOS (this_line_start_pos
) = 0;
9832 /* Optimize the case that only the line containing the cursor in the
9833 selected window has changed. Variables starting with this_ are
9834 set in display_line and record information about the line
9835 containing the cursor. */
9836 tlbufpos
= this_line_start_pos
;
9837 tlendpos
= this_line_end_pos
;
9838 if (!consider_all_windows_p
9839 && CHARPOS (tlbufpos
) > 0
9840 && NILP (w
->update_mode_line
)
9841 && !current_buffer
->clip_changed
9842 && !current_buffer
->prevent_redisplay_optimizations_p
9843 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9844 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9845 /* Make sure recorded data applies to current buffer, etc. */
9846 && this_line_buffer
== current_buffer
9847 && current_buffer
== XBUFFER (w
->buffer
)
9848 && NILP (w
->force_start
)
9849 && NILP (w
->optional_new_start
)
9850 /* Point must be on the line that we have info recorded about. */
9851 && PT
>= CHARPOS (tlbufpos
)
9852 && PT
<= Z
- CHARPOS (tlendpos
)
9853 /* All text outside that line, including its final newline,
9854 must be unchanged */
9855 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9856 CHARPOS (tlendpos
)))
9858 if (CHARPOS (tlbufpos
) > BEGV
9859 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9860 && (CHARPOS (tlbufpos
) == ZV
9861 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9862 /* Former continuation line has disappeared by becoming empty */
9864 else if (XFASTINT (w
->last_modified
) < MODIFF
9865 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9866 || MINI_WINDOW_P (w
))
9868 /* We have to handle the case of continuation around a
9869 wide-column character (See the comment in indent.c around
9872 For instance, in the following case:
9874 -------- Insert --------
9875 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9876 J_I_ ==> J_I_ `^^' are cursors.
9880 As we have to redraw the line above, we should goto cancel. */
9883 int line_height_before
= this_line_pixel_height
;
9885 /* Note that start_display will handle the case that the
9886 line starting at tlbufpos is a continuation lines. */
9887 start_display (&it
, w
, tlbufpos
);
9889 /* Implementation note: It this still necessary? */
9890 if (it
.current_x
!= this_line_start_x
)
9893 TRACE ((stderr
, "trying display optimization 1\n"));
9894 w
->cursor
.vpos
= -1;
9895 overlay_arrow_seen
= 0;
9896 it
.vpos
= this_line_vpos
;
9897 it
.current_y
= this_line_y
;
9898 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9901 /* If line contains point, is not continued,
9902 and ends at same distance from eob as before, we win */
9903 if (w
->cursor
.vpos
>= 0
9904 /* Line is not continued, otherwise this_line_start_pos
9905 would have been set to 0 in display_line. */
9906 && CHARPOS (this_line_start_pos
)
9907 /* Line ends as before. */
9908 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9909 /* Line has same height as before. Otherwise other lines
9910 would have to be shifted up or down. */
9911 && this_line_pixel_height
== line_height_before
)
9913 /* If this is not the window's last line, we must adjust
9914 the charstarts of the lines below. */
9915 if (it
.current_y
< it
.last_visible_y
)
9917 struct glyph_row
*row
9918 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9919 int delta
, delta_bytes
;
9921 if (Z
- CHARPOS (tlendpos
) == ZV
)
9923 /* This line ends at end of (accessible part of)
9924 buffer. There is no newline to count. */
9926 - CHARPOS (tlendpos
)
9927 - MATRIX_ROW_START_CHARPOS (row
));
9928 delta_bytes
= (Z_BYTE
9929 - BYTEPOS (tlendpos
)
9930 - MATRIX_ROW_START_BYTEPOS (row
));
9934 /* This line ends in a newline. Must take
9935 account of the newline and the rest of the
9936 text that follows. */
9938 - CHARPOS (tlendpos
)
9939 - MATRIX_ROW_START_CHARPOS (row
));
9940 delta_bytes
= (Z_BYTE
9941 - BYTEPOS (tlendpos
)
9942 - MATRIX_ROW_START_BYTEPOS (row
));
9945 increment_matrix_positions (w
->current_matrix
,
9947 w
->current_matrix
->nrows
,
9948 delta
, delta_bytes
);
9951 /* If this row displays text now but previously didn't,
9952 or vice versa, w->window_end_vpos may have to be
9954 if ((it
.glyph_row
- 1)->displays_text_p
)
9956 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
9957 XSETINT (w
->window_end_vpos
, this_line_vpos
);
9959 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
9960 && this_line_vpos
> 0)
9961 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
9962 w
->window_end_valid
= Qnil
;
9964 /* Update hint: No need to try to scroll in update_window. */
9965 w
->desired_matrix
->no_scrolling_p
= 1;
9968 *w
->desired_matrix
->method
= 0;
9969 debug_method_add (w
, "optimization 1");
9971 #ifdef HAVE_WINDOW_SYSTEM
9972 update_window_fringes (w
, 0);
9979 else if (/* Cursor position hasn't changed. */
9980 PT
== XFASTINT (w
->last_point
)
9981 /* Make sure the cursor was last displayed
9982 in this window. Otherwise we have to reposition it. */
9983 && 0 <= w
->cursor
.vpos
9984 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
9988 do_pending_window_change (1);
9990 /* We used to always goto end_of_redisplay here, but this
9991 isn't enough if we have a blinking cursor. */
9992 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
9993 goto end_of_redisplay
;
9997 /* If highlighting the region, or if the cursor is in the echo area,
9998 then we can't just move the cursor. */
9999 else if (! (!NILP (Vtransient_mark_mode
)
10000 && !NILP (current_buffer
->mark_active
))
10001 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10002 || highlight_nonselected_windows
)
10003 && NILP (w
->region_showing
)
10004 && NILP (Vshow_trailing_whitespace
)
10005 && !cursor_in_echo_area
)
10008 struct glyph_row
*row
;
10010 /* Skip from tlbufpos to PT and see where it is. Note that
10011 PT may be in invisible text. If so, we will end at the
10012 next visible position. */
10013 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10014 NULL
, DEFAULT_FACE_ID
);
10015 it
.current_x
= this_line_start_x
;
10016 it
.current_y
= this_line_y
;
10017 it
.vpos
= this_line_vpos
;
10019 /* The call to move_it_to stops in front of PT, but
10020 moves over before-strings. */
10021 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10023 if (it
.vpos
== this_line_vpos
10024 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10027 xassert (this_line_vpos
== it
.vpos
);
10028 xassert (this_line_y
== it
.current_y
);
10029 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10031 *w
->desired_matrix
->method
= 0;
10032 debug_method_add (w
, "optimization 3");
10041 /* Text changed drastically or point moved off of line. */
10042 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10045 CHARPOS (this_line_start_pos
) = 0;
10046 consider_all_windows_p
|= buffer_shared
> 1;
10047 ++clear_face_cache_count
;
10050 /* Build desired matrices, and update the display. If
10051 consider_all_windows_p is non-zero, do it for all windows on all
10052 frames. Otherwise do it for selected_window, only. */
10054 if (consider_all_windows_p
)
10056 Lisp_Object tail
, frame
;
10057 int i
, n
= 0, size
= 50;
10058 struct frame
**updated
10059 = (struct frame
**) alloca (size
* sizeof *updated
);
10061 /* Clear the face cache eventually. */
10062 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10064 clear_face_cache (0);
10065 clear_face_cache_count
= 0;
10068 /* Recompute # windows showing selected buffer. This will be
10069 incremented each time such a window is displayed. */
10072 FOR_EACH_FRAME (tail
, frame
)
10074 struct frame
*f
= XFRAME (frame
);
10076 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10078 if (! EQ (frame
, selected_frame
))
10079 /* Select the frame, for the sake of frame-local
10081 select_frame_for_redisplay (frame
);
10083 #ifdef HAVE_WINDOW_SYSTEM
10084 if (clear_face_cache_count
% 50 == 0
10085 && FRAME_WINDOW_P (f
))
10086 clear_image_cache (f
, 0);
10087 #endif /* HAVE_WINDOW_SYSTEM */
10089 /* Mark all the scroll bars to be removed; we'll redeem
10090 the ones we want when we redisplay their windows. */
10091 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
10092 FRAME_DISPLAY (f
)->condemn_scroll_bars_hook (f
);
10094 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10095 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10097 /* Any scroll bars which redisplay_windows should have
10098 nuked should now go away. */
10099 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
10100 FRAME_DISPLAY (f
)->judge_scroll_bars_hook (f
);
10102 /* If fonts changed, display again. */
10103 /* ??? rms: I suspect it is a mistake to jump all the way
10104 back to retry here. It should just retry this frame. */
10105 if (fonts_changed_p
)
10108 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10110 /* See if we have to hscroll. */
10111 if (hscroll_windows (f
->root_window
))
10114 /* Prevent various kinds of signals during display
10115 update. stdio is not robust about handling
10116 signals, which can cause an apparent I/O
10118 if (interrupt_input
)
10119 unrequest_sigio ();
10122 /* Update the display. */
10123 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10124 pause
|= update_frame (f
, 0, 0);
10125 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10132 int nbytes
= size
* sizeof *updated
;
10133 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10134 bcopy (updated
, p
, nbytes
);
10145 /* Do the mark_window_display_accurate after all windows have
10146 been redisplayed because this call resets flags in buffers
10147 which are needed for proper redisplay. */
10148 for (i
= 0; i
< n
; ++i
)
10150 struct frame
*f
= updated
[i
];
10151 mark_window_display_accurate (f
->root_window
, 1);
10152 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
)
10153 FRAME_DISPLAY (f
)->frame_up_to_date_hook (f
);
10157 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10159 Lisp_Object mini_window
;
10160 struct frame
*mini_frame
;
10162 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10163 /* Use list_of_error, not Qerror, so that
10164 we catch only errors and don't run the debugger. */
10165 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10167 redisplay_window_error
);
10169 /* Compare desired and current matrices, perform output. */
10172 /* If fonts changed, display again. */
10173 if (fonts_changed_p
)
10176 /* Prevent various kinds of signals during display update.
10177 stdio is not robust about handling signals,
10178 which can cause an apparent I/O error. */
10179 if (interrupt_input
)
10180 unrequest_sigio ();
10183 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10185 if (hscroll_windows (selected_window
))
10188 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10189 pause
= update_frame (sf
, 0, 0);
10192 /* We may have called echo_area_display at the top of this
10193 function. If the echo area is on another frame, that may
10194 have put text on a frame other than the selected one, so the
10195 above call to update_frame would not have caught it. Catch
10197 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10198 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10200 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10202 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10203 pause
|= update_frame (mini_frame
, 0, 0);
10204 if (!pause
&& hscroll_windows (mini_window
))
10209 /* If display was paused because of pending input, make sure we do a
10210 thorough update the next time. */
10213 /* Prevent the optimization at the beginning of
10214 redisplay_internal that tries a single-line update of the
10215 line containing the cursor in the selected window. */
10216 CHARPOS (this_line_start_pos
) = 0;
10218 /* Let the overlay arrow be updated the next time. */
10219 update_overlay_arrows (0);
10221 /* If we pause after scrolling, some rows in the current
10222 matrices of some windows are not valid. */
10223 if (!WINDOW_FULL_WIDTH_P (w
)
10224 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10225 update_mode_lines
= 1;
10229 if (!consider_all_windows_p
)
10231 /* This has already been done above if
10232 consider_all_windows_p is set. */
10233 mark_window_display_accurate_1 (w
, 1);
10235 /* Say overlay arrows are up to date. */
10236 update_overlay_arrows (1);
10238 if (FRAME_DISPLAY (sf
)->frame_up_to_date_hook
!= 0)
10239 FRAME_DISPLAY (sf
)->frame_up_to_date_hook (sf
);
10242 update_mode_lines
= 0;
10243 windows_or_buffers_changed
= 0;
10244 cursor_type_changed
= 0;
10247 /* Start SIGIO interrupts coming again. Having them off during the
10248 code above makes it less likely one will discard output, but not
10249 impossible, since there might be stuff in the system buffer here.
10250 But it is much hairier to try to do anything about that. */
10251 if (interrupt_input
)
10255 /* If a frame has become visible which was not before, redisplay
10256 again, so that we display it. Expose events for such a frame
10257 (which it gets when becoming visible) don't call the parts of
10258 redisplay constructing glyphs, so simply exposing a frame won't
10259 display anything in this case. So, we have to display these
10260 frames here explicitly. */
10263 Lisp_Object tail
, frame
;
10266 FOR_EACH_FRAME (tail
, frame
)
10268 int this_is_visible
= 0;
10270 if (XFRAME (frame
)->visible
)
10271 this_is_visible
= 1;
10272 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10273 if (XFRAME (frame
)->visible
)
10274 this_is_visible
= 1;
10276 if (this_is_visible
)
10280 if (new_count
!= number_of_visible_frames
)
10281 windows_or_buffers_changed
++;
10284 /* Change frame size now if a change is pending. */
10285 do_pending_window_change (1);
10287 /* If we just did a pending size change, or have additional
10288 visible frames, redisplay again. */
10289 if (windows_or_buffers_changed
&& !pause
)
10293 unbind_to (count
, Qnil
);
10298 /* Redisplay, but leave alone any recent echo area message unless
10299 another message has been requested in its place.
10301 This is useful in situations where you need to redisplay but no
10302 user action has occurred, making it inappropriate for the message
10303 area to be cleared. See tracking_off and
10304 wait_reading_process_input for examples of these situations.
10306 FROM_WHERE is an integer saying from where this function was
10307 called. This is useful for debugging. */
10310 redisplay_preserve_echo_area (from_where
)
10313 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10315 if (!NILP (echo_area_buffer
[1]))
10317 /* We have a previously displayed message, but no current
10318 message. Redisplay the previous message. */
10319 display_last_displayed_message_p
= 1;
10320 redisplay_internal (1);
10321 display_last_displayed_message_p
= 0;
10324 redisplay_internal (1);
10328 /* Function registered with record_unwind_protect in
10329 redisplay_internal. Reset redisplaying_p to the value it had
10330 before redisplay_internal was called, and clear
10331 prevent_freeing_realized_faces_p. It also selects the previously
10335 unwind_redisplay (val
)
10338 Lisp_Object old_redisplaying_p
, old_frame
;
10340 old_redisplaying_p
= XCAR (val
);
10341 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10342 old_frame
= XCDR (val
);
10343 if (! EQ (old_frame
, selected_frame
))
10344 select_frame_for_redisplay (old_frame
);
10349 /* Mark the display of window W as accurate or inaccurate. If
10350 ACCURATE_P is non-zero mark display of W as accurate. If
10351 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10352 redisplay_internal is called. */
10355 mark_window_display_accurate_1 (w
, accurate_p
)
10359 if (BUFFERP (w
->buffer
))
10361 struct buffer
*b
= XBUFFER (w
->buffer
);
10364 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10365 w
->last_overlay_modified
10366 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10368 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10372 b
->clip_changed
= 0;
10373 b
->prevent_redisplay_optimizations_p
= 0;
10375 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10376 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10377 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10378 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10380 w
->current_matrix
->buffer
= b
;
10381 w
->current_matrix
->begv
= BUF_BEGV (b
);
10382 w
->current_matrix
->zv
= BUF_ZV (b
);
10384 w
->last_cursor
= w
->cursor
;
10385 w
->last_cursor_off_p
= w
->cursor_off_p
;
10387 if (w
== XWINDOW (selected_window
))
10388 w
->last_point
= make_number (BUF_PT (b
));
10390 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10396 w
->window_end_valid
= w
->buffer
;
10397 #if 0 /* This is incorrect with variable-height lines. */
10398 xassert (XINT (w
->window_end_vpos
)
10399 < (WINDOW_TOTAL_LINES (w
)
10400 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10402 w
->update_mode_line
= Qnil
;
10407 /* Mark the display of windows in the window tree rooted at WINDOW as
10408 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10409 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10410 be redisplayed the next time redisplay_internal is called. */
10413 mark_window_display_accurate (window
, accurate_p
)
10414 Lisp_Object window
;
10419 for (; !NILP (window
); window
= w
->next
)
10421 w
= XWINDOW (window
);
10422 mark_window_display_accurate_1 (w
, accurate_p
);
10424 if (!NILP (w
->vchild
))
10425 mark_window_display_accurate (w
->vchild
, accurate_p
);
10426 if (!NILP (w
->hchild
))
10427 mark_window_display_accurate (w
->hchild
, accurate_p
);
10432 update_overlay_arrows (1);
10436 /* Force a thorough redisplay the next time by setting
10437 last_arrow_position and last_arrow_string to t, which is
10438 unequal to any useful value of Voverlay_arrow_... */
10439 update_overlay_arrows (-1);
10444 /* Return value in display table DP (Lisp_Char_Table *) for character
10445 C. Since a display table doesn't have any parent, we don't have to
10446 follow parent. Do not call this function directly but use the
10447 macro DISP_CHAR_VECTOR. */
10450 disp_char_vector (dp
, c
)
10451 struct Lisp_Char_Table
*dp
;
10457 if (SINGLE_BYTE_CHAR_P (c
))
10458 return (dp
->contents
[c
]);
10460 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10463 else if (code
[2] < 32)
10466 /* Here, the possible range of code[0] (== charset ID) is
10467 128..max_charset. Since the top level char table contains data
10468 for multibyte characters after 256th element, we must increment
10469 code[0] by 128 to get a correct index. */
10471 code
[3] = -1; /* anchor */
10473 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10475 val
= dp
->contents
[code
[i
]];
10476 if (!SUB_CHAR_TABLE_P (val
))
10477 return (NILP (val
) ? dp
->defalt
: val
);
10480 /* Here, val is a sub char table. We return the default value of
10482 return (dp
->defalt
);
10487 /***********************************************************************
10489 ***********************************************************************/
10491 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10494 redisplay_windows (window
)
10495 Lisp_Object window
;
10497 while (!NILP (window
))
10499 struct window
*w
= XWINDOW (window
);
10501 if (!NILP (w
->hchild
))
10502 redisplay_windows (w
->hchild
);
10503 else if (!NILP (w
->vchild
))
10504 redisplay_windows (w
->vchild
);
10507 displayed_buffer
= XBUFFER (w
->buffer
);
10508 /* Use list_of_error, not Qerror, so that
10509 we catch only errors and don't run the debugger. */
10510 internal_condition_case_1 (redisplay_window_0
, window
,
10512 redisplay_window_error
);
10520 redisplay_window_error ()
10522 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10527 redisplay_window_0 (window
)
10528 Lisp_Object window
;
10530 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10531 redisplay_window (window
, 0);
10536 redisplay_window_1 (window
)
10537 Lisp_Object window
;
10539 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10540 redisplay_window (window
, 1);
10545 /* Increment GLYPH until it reaches END or CONDITION fails while
10546 adding (GLYPH)->pixel_width to X. */
10548 #define SKIP_GLYPHS(glyph, end, x, condition) \
10551 (x) += (glyph)->pixel_width; \
10554 while ((glyph) < (end) && (condition))
10557 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10558 DELTA is the number of bytes by which positions recorded in ROW
10559 differ from current buffer positions. */
10562 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10564 struct glyph_row
*row
;
10565 struct glyph_matrix
*matrix
;
10566 int delta
, delta_bytes
, dy
, dvpos
;
10568 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10569 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10570 /* The first glyph that starts a sequence of glyphs from string. */
10571 struct glyph
*string_start
;
10572 /* The X coordinate of string_start. */
10573 int string_start_x
;
10574 /* The last known character position. */
10575 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10576 /* The last known character position before string_start. */
10577 int string_before_pos
;
10579 int pt_old
= PT
- delta
;
10581 /* Skip over glyphs not having an object at the start of the row.
10582 These are special glyphs like truncation marks on terminal
10584 if (row
->displays_text_p
)
10586 && INTEGERP (glyph
->object
)
10587 && glyph
->charpos
< 0)
10589 x
+= glyph
->pixel_width
;
10593 string_start
= NULL
;
10595 && !INTEGERP (glyph
->object
)
10596 && (!BUFFERP (glyph
->object
)
10597 || (last_pos
= glyph
->charpos
) < pt_old
))
10599 if (! STRINGP (glyph
->object
))
10601 string_start
= NULL
;
10602 x
+= glyph
->pixel_width
;
10607 string_before_pos
= last_pos
;
10608 string_start
= glyph
;
10609 string_start_x
= x
;
10610 /* Skip all glyphs from string. */
10611 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10616 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10618 /* We may have skipped over point because the previous glyphs
10619 are from string. As there's no easy way to know the
10620 character position of the current glyph, find the correct
10621 glyph on point by scanning from string_start again. */
10623 Lisp_Object string
;
10626 limit
= make_number (pt_old
+ 1);
10628 glyph
= string_start
;
10629 x
= string_start_x
;
10630 string
= glyph
->object
;
10631 pos
= string_buffer_position (w
, string
, string_before_pos
);
10632 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10633 because we always put cursor after overlay strings. */
10634 while (pos
== 0 && glyph
< end
)
10636 string
= glyph
->object
;
10637 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10639 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10642 while (glyph
< end
)
10644 pos
= XINT (Fnext_single_char_property_change
10645 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10648 /* Skip glyphs from the same string. */
10649 string
= glyph
->object
;
10650 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10651 /* Skip glyphs from an overlay. */
10653 && ! string_buffer_position (w
, glyph
->object
, pos
))
10655 string
= glyph
->object
;
10656 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10661 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10663 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10664 w
->cursor
.y
= row
->y
+ dy
;
10666 if (w
== XWINDOW (selected_window
))
10668 if (!row
->continued_p
10669 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10672 this_line_buffer
= XBUFFER (w
->buffer
);
10674 CHARPOS (this_line_start_pos
)
10675 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10676 BYTEPOS (this_line_start_pos
)
10677 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10679 CHARPOS (this_line_end_pos
)
10680 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10681 BYTEPOS (this_line_end_pos
)
10682 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10684 this_line_y
= w
->cursor
.y
;
10685 this_line_pixel_height
= row
->height
;
10686 this_line_vpos
= w
->cursor
.vpos
;
10687 this_line_start_x
= row
->x
;
10690 CHARPOS (this_line_start_pos
) = 0;
10695 /* Run window scroll functions, if any, for WINDOW with new window
10696 start STARTP. Sets the window start of WINDOW to that position.
10698 We assume that the window's buffer is really current. */
10700 static INLINE
struct text_pos
10701 run_window_scroll_functions (window
, startp
)
10702 Lisp_Object window
;
10703 struct text_pos startp
;
10705 struct window
*w
= XWINDOW (window
);
10706 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10708 if (current_buffer
!= XBUFFER (w
->buffer
))
10711 if (!NILP (Vwindow_scroll_functions
))
10713 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10714 make_number (CHARPOS (startp
)));
10715 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10716 /* In case the hook functions switch buffers. */
10717 if (current_buffer
!= XBUFFER (w
->buffer
))
10718 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10725 /* Make sure the line containing the cursor is fully visible.
10726 A value of 1 means there is nothing to be done.
10727 (Either the line is fully visible, or it cannot be made so,
10728 or we cannot tell.)
10729 A value of 0 means the caller should do scrolling
10730 as if point had gone off the screen. */
10733 make_cursor_line_fully_visible (w
)
10736 struct glyph_matrix
*matrix
;
10737 struct glyph_row
*row
;
10740 /* It's not always possible to find the cursor, e.g, when a window
10741 is full of overlay strings. Don't do anything in that case. */
10742 if (w
->cursor
.vpos
< 0)
10745 matrix
= w
->desired_matrix
;
10746 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10748 /* If the cursor row is not partially visible, there's nothing to do. */
10749 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10752 /* If the row the cursor is in is taller than the window's height,
10753 it's not clear what to do, so do nothing. */
10754 window_height
= window_box_height (w
);
10755 if (row
->height
>= window_height
)
10761 /* This code used to try to scroll the window just enough to make
10762 the line visible. It returned 0 to say that the caller should
10763 allocate larger glyph matrices. */
10765 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10767 int dy
= row
->height
- row
->visible_height
;
10770 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10772 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10774 int dy
= - (row
->height
- row
->visible_height
);
10777 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10780 /* When we change the cursor y-position of the selected window,
10781 change this_line_y as well so that the display optimization for
10782 the cursor line of the selected window in redisplay_internal uses
10783 the correct y-position. */
10784 if (w
== XWINDOW (selected_window
))
10785 this_line_y
= w
->cursor
.y
;
10787 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10788 redisplay with larger matrices. */
10789 if (matrix
->nrows
< required_matrix_height (w
))
10791 fonts_changed_p
= 1;
10800 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10801 non-zero means only WINDOW is redisplayed in redisplay_internal.
10802 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10803 in redisplay_window to bring a partially visible line into view in
10804 the case that only the cursor has moved.
10806 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10807 last screen line's vertical height extends past the end of the screen.
10811 1 if scrolling succeeded
10813 0 if scrolling didn't find point.
10815 -1 if new fonts have been loaded so that we must interrupt
10816 redisplay, adjust glyph matrices, and try again. */
10822 SCROLLING_NEED_LARGER_MATRICES
10826 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10827 scroll_step
, temp_scroll_step
, last_line_misfit
)
10828 Lisp_Object window
;
10829 int just_this_one_p
;
10830 EMACS_INT scroll_conservatively
, scroll_step
;
10831 int temp_scroll_step
;
10832 int last_line_misfit
;
10834 struct window
*w
= XWINDOW (window
);
10835 struct frame
*f
= XFRAME (w
->frame
);
10836 struct text_pos scroll_margin_pos
;
10837 struct text_pos pos
;
10838 struct text_pos startp
;
10840 Lisp_Object window_end
;
10841 int this_scroll_margin
;
10845 int amount_to_scroll
= 0;
10846 Lisp_Object aggressive
;
10848 int end_scroll_margin
;
10851 debug_method_add (w
, "try_scrolling");
10854 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10856 /* Compute scroll margin height in pixels. We scroll when point is
10857 within this distance from the top or bottom of the window. */
10858 if (scroll_margin
> 0)
10860 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
10861 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
10864 this_scroll_margin
= 0;
10866 /* Compute how much we should try to scroll maximally to bring point
10868 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10869 scroll_max
= max (scroll_step
,
10870 max (scroll_conservatively
, temp_scroll_step
));
10871 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10872 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10873 /* We're trying to scroll because of aggressive scrolling
10874 but no scroll_step is set. Choose an arbitrary one. Maybe
10875 there should be a variable for this. */
10879 scroll_max
*= FRAME_LINE_HEIGHT (f
);
10881 /* Decide whether we have to scroll down. Start at the window end
10882 and move this_scroll_margin up to find the position of the scroll
10884 window_end
= Fwindow_end (window
, Qt
);
10888 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10889 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10891 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
10892 if (end_scroll_margin
)
10894 start_display (&it
, w
, scroll_margin_pos
);
10895 move_it_vertically (&it
, - end_scroll_margin
);
10896 scroll_margin_pos
= it
.current
.pos
;
10899 if (PT
>= CHARPOS (scroll_margin_pos
))
10903 /* Point is in the scroll margin at the bottom of the window, or
10904 below. Compute a new window start that makes point visible. */
10906 /* Compute the distance from the scroll margin to PT.
10907 Give up if the distance is greater than scroll_max. */
10908 start_display (&it
, w
, scroll_margin_pos
);
10910 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10911 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10913 /* To make point visible, we have to move the window start
10914 down so that the line the cursor is in is visible, which
10915 means we have to add in the height of the cursor line. */
10916 dy
= line_bottom_y (&it
) - y0
;
10918 if (dy
> scroll_max
)
10919 return SCROLLING_FAILED
;
10921 /* Move the window start down. If scrolling conservatively,
10922 move it just enough down to make point visible. If
10923 scroll_step is set, move it down by scroll_step. */
10924 start_display (&it
, w
, startp
);
10926 if (scroll_conservatively
)
10927 /* Set AMOUNT_TO_SCROLL to at least one line,
10928 and at most scroll_conservatively lines. */
10930 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
10931 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
10932 else if (scroll_step
|| temp_scroll_step
)
10933 amount_to_scroll
= scroll_max
;
10936 aggressive
= current_buffer
->scroll_up_aggressively
;
10937 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
10938 if (NUMBERP (aggressive
))
10939 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10942 if (amount_to_scroll
<= 0)
10943 return SCROLLING_FAILED
;
10945 /* If moving by amount_to_scroll leaves STARTP unchanged,
10946 move it down one screen line. */
10948 move_it_vertically (&it
, amount_to_scroll
);
10949 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
10950 move_it_by_lines (&it
, 1, 1);
10951 startp
= it
.current
.pos
;
10955 /* See if point is inside the scroll margin at the top of the
10957 scroll_margin_pos
= startp
;
10958 if (this_scroll_margin
)
10960 start_display (&it
, w
, startp
);
10961 move_it_vertically (&it
, this_scroll_margin
);
10962 scroll_margin_pos
= it
.current
.pos
;
10965 if (PT
< CHARPOS (scroll_margin_pos
))
10967 /* Point is in the scroll margin at the top of the window or
10968 above what is displayed in the window. */
10971 /* Compute the vertical distance from PT to the scroll
10972 margin position. Give up if distance is greater than
10974 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
10975 start_display (&it
, w
, pos
);
10977 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
10978 it
.last_visible_y
, -1,
10979 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10980 dy
= it
.current_y
- y0
;
10981 if (dy
> scroll_max
)
10982 return SCROLLING_FAILED
;
10984 /* Compute new window start. */
10985 start_display (&it
, w
, startp
);
10987 if (scroll_conservatively
)
10989 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
10990 else if (scroll_step
|| temp_scroll_step
)
10991 amount_to_scroll
= scroll_max
;
10994 aggressive
= current_buffer
->scroll_down_aggressively
;
10995 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
10996 if (NUMBERP (aggressive
))
10997 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11000 if (amount_to_scroll
<= 0)
11001 return SCROLLING_FAILED
;
11003 move_it_vertically (&it
, - amount_to_scroll
);
11004 startp
= it
.current
.pos
;
11008 /* Run window scroll functions. */
11009 startp
= run_window_scroll_functions (window
, startp
);
11011 /* Display the window. Give up if new fonts are loaded, or if point
11013 if (!try_window (window
, startp
))
11014 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11015 else if (w
->cursor
.vpos
< 0)
11017 clear_glyph_matrix (w
->desired_matrix
);
11018 rc
= SCROLLING_FAILED
;
11022 /* Maybe forget recorded base line for line number display. */
11023 if (!just_this_one_p
11024 || current_buffer
->clip_changed
11025 || BEG_UNCHANGED
< CHARPOS (startp
))
11026 w
->base_line_number
= Qnil
;
11028 /* If cursor ends up on a partially visible line,
11029 treat that as being off the bottom of the screen. */
11030 if (! make_cursor_line_fully_visible (w
))
11032 clear_glyph_matrix (w
->desired_matrix
);
11033 last_line_misfit
= 1;
11036 rc
= SCROLLING_SUCCESS
;
11043 /* Compute a suitable window start for window W if display of W starts
11044 on a continuation line. Value is non-zero if a new window start
11047 The new window start will be computed, based on W's width, starting
11048 from the start of the continued line. It is the start of the
11049 screen line with the minimum distance from the old start W->start. */
11052 compute_window_start_on_continuation_line (w
)
11055 struct text_pos pos
, start_pos
;
11056 int window_start_changed_p
= 0;
11058 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11060 /* If window start is on a continuation line... Window start may be
11061 < BEGV in case there's invisible text at the start of the
11062 buffer (M-x rmail, for example). */
11063 if (CHARPOS (start_pos
) > BEGV
11064 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11067 struct glyph_row
*row
;
11069 /* Handle the case that the window start is out of range. */
11070 if (CHARPOS (start_pos
) < BEGV
)
11071 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11072 else if (CHARPOS (start_pos
) > ZV
)
11073 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11075 /* Find the start of the continued line. This should be fast
11076 because scan_buffer is fast (newline cache). */
11077 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11078 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11079 row
, DEFAULT_FACE_ID
);
11080 reseat_at_previous_visible_line_start (&it
);
11082 /* If the line start is "too far" away from the window start,
11083 say it takes too much time to compute a new window start. */
11084 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11085 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11087 int min_distance
, distance
;
11089 /* Move forward by display lines to find the new window
11090 start. If window width was enlarged, the new start can
11091 be expected to be > the old start. If window width was
11092 decreased, the new window start will be < the old start.
11093 So, we're looking for the display line start with the
11094 minimum distance from the old window start. */
11095 pos
= it
.current
.pos
;
11096 min_distance
= INFINITY
;
11097 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11098 distance
< min_distance
)
11100 min_distance
= distance
;
11101 pos
= it
.current
.pos
;
11102 move_it_by_lines (&it
, 1, 0);
11105 /* Set the window start there. */
11106 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11107 window_start_changed_p
= 1;
11111 return window_start_changed_p
;
11115 /* Try cursor movement in case text has not changed in window WINDOW,
11116 with window start STARTP. Value is
11118 CURSOR_MOVEMENT_SUCCESS if successful
11120 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11122 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11123 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11124 we want to scroll as if scroll-step were set to 1. See the code.
11126 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11127 which case we have to abort this redisplay, and adjust matrices
11132 CURSOR_MOVEMENT_SUCCESS
,
11133 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11134 CURSOR_MOVEMENT_MUST_SCROLL
,
11135 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11139 try_cursor_movement (window
, startp
, scroll_step
)
11140 Lisp_Object window
;
11141 struct text_pos startp
;
11144 struct window
*w
= XWINDOW (window
);
11145 struct frame
*f
= XFRAME (w
->frame
);
11146 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11149 if (inhibit_try_cursor_movement
)
11153 /* Handle case where text has not changed, only point, and it has
11154 not moved off the frame. */
11155 if (/* Point may be in this window. */
11156 PT
>= CHARPOS (startp
)
11157 /* Selective display hasn't changed. */
11158 && !current_buffer
->clip_changed
11159 /* Function force-mode-line-update is used to force a thorough
11160 redisplay. It sets either windows_or_buffers_changed or
11161 update_mode_lines. So don't take a shortcut here for these
11163 && !update_mode_lines
11164 && !windows_or_buffers_changed
11165 && !cursor_type_changed
11166 /* Can't use this case if highlighting a region. When a
11167 region exists, cursor movement has to do more than just
11169 && !(!NILP (Vtransient_mark_mode
)
11170 && !NILP (current_buffer
->mark_active
))
11171 && NILP (w
->region_showing
)
11172 && NILP (Vshow_trailing_whitespace
)
11173 /* Right after splitting windows, last_point may be nil. */
11174 && INTEGERP (w
->last_point
)
11175 /* This code is not used for mini-buffer for the sake of the case
11176 of redisplaying to replace an echo area message; since in
11177 that case the mini-buffer contents per se are usually
11178 unchanged. This code is of no real use in the mini-buffer
11179 since the handling of this_line_start_pos, etc., in redisplay
11180 handles the same cases. */
11181 && !EQ (window
, minibuf_window
)
11182 /* When splitting windows or for new windows, it happens that
11183 redisplay is called with a nil window_end_vpos or one being
11184 larger than the window. This should really be fixed in
11185 window.c. I don't have this on my list, now, so we do
11186 approximately the same as the old redisplay code. --gerd. */
11187 && INTEGERP (w
->window_end_vpos
)
11188 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11189 && (FRAME_WINDOW_P (f
)
11190 || !overlay_arrow_in_current_buffer_p ()))
11192 int this_scroll_margin
;
11193 struct glyph_row
*row
= NULL
;
11196 debug_method_add (w
, "cursor movement");
11199 /* Scroll if point within this distance from the top or bottom
11200 of the window. This is a pixel value. */
11201 this_scroll_margin
= max (0, scroll_margin
);
11202 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11203 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11205 /* Start with the row the cursor was displayed during the last
11206 not paused redisplay. Give up if that row is not valid. */
11207 if (w
->last_cursor
.vpos
< 0
11208 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11209 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11212 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11213 if (row
->mode_line_p
)
11215 if (!row
->enabled_p
)
11216 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11219 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11222 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11224 if (PT
> XFASTINT (w
->last_point
))
11226 /* Point has moved forward. */
11227 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11228 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11230 xassert (row
->enabled_p
);
11234 /* The end position of a row equals the start position
11235 of the next row. If PT is there, we would rather
11236 display it in the next line. */
11237 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11238 && MATRIX_ROW_END_CHARPOS (row
) == PT
11239 && !cursor_row_p (w
, row
))
11242 /* If within the scroll margin, scroll. Note that
11243 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11244 the next line would be drawn, and that
11245 this_scroll_margin can be zero. */
11246 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11247 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11248 /* Line is completely visible last line in window
11249 and PT is to be set in the next line. */
11250 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11251 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11252 && !row
->ends_at_zv_p
11253 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11256 else if (PT
< XFASTINT (w
->last_point
))
11258 /* Cursor has to be moved backward. Note that PT >=
11259 CHARPOS (startp) because of the outer
11261 while (!row
->mode_line_p
11262 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11263 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11264 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11265 && (row
->y
> this_scroll_margin
11266 || CHARPOS (startp
) == BEGV
))
11268 xassert (row
->enabled_p
);
11272 /* Consider the following case: Window starts at BEGV,
11273 there is invisible, intangible text at BEGV, so that
11274 display starts at some point START > BEGV. It can
11275 happen that we are called with PT somewhere between
11276 BEGV and START. Try to handle that case. */
11277 if (row
< w
->current_matrix
->rows
11278 || row
->mode_line_p
)
11280 row
= w
->current_matrix
->rows
;
11281 if (row
->mode_line_p
)
11285 /* Due to newlines in overlay strings, we may have to
11286 skip forward over overlay strings. */
11287 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11288 && MATRIX_ROW_END_CHARPOS (row
) == PT
11289 && !cursor_row_p (w
, row
))
11292 /* If within the scroll margin, scroll. */
11293 if (row
->y
< this_scroll_margin
11294 && CHARPOS (startp
) != BEGV
)
11298 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11299 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11301 /* if PT is not in the glyph row, give up. */
11302 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11304 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11306 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11307 && !row
->ends_at_zv_p
11308 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11309 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11310 else if (row
->height
> window_box_height (w
))
11312 /* If we end up in a partially visible line, let's
11313 make it fully visible, except when it's taller
11314 than the window, in which case we can't do much
11317 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11321 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11322 if (!make_cursor_line_fully_visible (w
))
11323 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11325 rc
= CURSOR_MOVEMENT_SUCCESS
;
11329 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11332 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11333 rc
= CURSOR_MOVEMENT_SUCCESS
;
11342 set_vertical_scroll_bar (w
)
11345 int start
, end
, whole
;
11347 /* Calculate the start and end positions for the current window.
11348 At some point, it would be nice to choose between scrollbars
11349 which reflect the whole buffer size, with special markers
11350 indicating narrowing, and scrollbars which reflect only the
11353 Note that mini-buffers sometimes aren't displaying any text. */
11354 if (!MINI_WINDOW_P (w
)
11355 || (w
== XWINDOW (minibuf_window
)
11356 && NILP (echo_area_buffer
[0])))
11358 struct buffer
*buf
= XBUFFER (w
->buffer
);
11359 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11360 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11361 /* I don't think this is guaranteed to be right. For the
11362 moment, we'll pretend it is. */
11363 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11367 if (whole
< (end
- start
))
11368 whole
= end
- start
;
11371 start
= end
= whole
= 0;
11373 /* Indicate what this scroll bar ought to be displaying now. */
11374 if (FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11375 (*FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11376 (w
, end
- start
, whole
, start
);
11380 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11381 selected_window is redisplayed.
11383 We can return without actually redisplaying the window if
11384 fonts_changed_p is nonzero. In that case, redisplay_internal will
11388 redisplay_window (window
, just_this_one_p
)
11389 Lisp_Object window
;
11390 int just_this_one_p
;
11392 struct window
*w
= XWINDOW (window
);
11393 struct frame
*f
= XFRAME (w
->frame
);
11394 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11395 struct buffer
*old
= current_buffer
;
11396 struct text_pos lpoint
, opoint
, startp
;
11397 int update_mode_line
;
11400 /* Record it now because it's overwritten. */
11401 int current_matrix_up_to_date_p
= 0;
11402 int used_current_matrix_p
= 0;
11403 /* This is less strict than current_matrix_up_to_date_p.
11404 It indictes that the buffer contents and narrowing are unchanged. */
11405 int buffer_unchanged_p
= 0;
11406 int temp_scroll_step
= 0;
11407 int count
= SPECPDL_INDEX ();
11409 int centering_position
;
11410 int last_line_misfit
= 0;
11412 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11415 /* W must be a leaf window here. */
11416 xassert (!NILP (w
->buffer
));
11418 *w
->desired_matrix
->method
= 0;
11421 specbind (Qinhibit_point_motion_hooks
, Qt
);
11423 reconsider_clip_changes (w
, buffer
);
11425 /* Has the mode line to be updated? */
11426 update_mode_line
= (!NILP (w
->update_mode_line
)
11427 || update_mode_lines
11428 || buffer
->clip_changed
11429 || buffer
->prevent_redisplay_optimizations_p
);
11431 if (MINI_WINDOW_P (w
))
11433 if (w
== XWINDOW (echo_area_window
)
11434 && !NILP (echo_area_buffer
[0]))
11436 if (update_mode_line
)
11437 /* We may have to update a tty frame's menu bar or a
11438 tool-bar. Example `M-x C-h C-h C-g'. */
11439 goto finish_menu_bars
;
11441 /* We've already displayed the echo area glyphs in this window. */
11442 goto finish_scroll_bars
;
11444 else if ((w
!= XWINDOW (minibuf_window
)
11445 || minibuf_level
== 0)
11446 /* When buffer is nonempty, redisplay window normally. */
11447 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11448 /* Quail displays non-mini buffers in minibuffer window.
11449 In that case, redisplay the window normally. */
11450 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11452 /* W is a mini-buffer window, but it's not active, so clear
11454 int yb
= window_text_bottom_y (w
);
11455 struct glyph_row
*row
;
11458 for (y
= 0, row
= w
->desired_matrix
->rows
;
11460 y
+= row
->height
, ++row
)
11461 blank_row (w
, row
, y
);
11462 goto finish_scroll_bars
;
11465 clear_glyph_matrix (w
->desired_matrix
);
11468 /* Otherwise set up data on this window; select its buffer and point
11470 /* Really select the buffer, for the sake of buffer-local
11472 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11473 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11475 current_matrix_up_to_date_p
11476 = (!NILP (w
->window_end_valid
)
11477 && !current_buffer
->clip_changed
11478 && !current_buffer
->prevent_redisplay_optimizations_p
11479 && XFASTINT (w
->last_modified
) >= MODIFF
11480 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11483 = (!NILP (w
->window_end_valid
)
11484 && !current_buffer
->clip_changed
11485 && XFASTINT (w
->last_modified
) >= MODIFF
11486 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11488 /* When windows_or_buffers_changed is non-zero, we can't rely on
11489 the window end being valid, so set it to nil there. */
11490 if (windows_or_buffers_changed
)
11492 /* If window starts on a continuation line, maybe adjust the
11493 window start in case the window's width changed. */
11494 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11495 compute_window_start_on_continuation_line (w
);
11497 w
->window_end_valid
= Qnil
;
11500 /* Some sanity checks. */
11501 CHECK_WINDOW_END (w
);
11502 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11504 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11507 /* If %c is in mode line, update it if needed. */
11508 if (!NILP (w
->column_number_displayed
)
11509 /* This alternative quickly identifies a common case
11510 where no change is needed. */
11511 && !(PT
== XFASTINT (w
->last_point
)
11512 && XFASTINT (w
->last_modified
) >= MODIFF
11513 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11514 && (XFASTINT (w
->column_number_displayed
)
11515 != (int) current_column ())) /* iftc */
11516 update_mode_line
= 1;
11518 /* Count number of windows showing the selected buffer. An indirect
11519 buffer counts as its base buffer. */
11520 if (!just_this_one_p
)
11522 struct buffer
*current_base
, *window_base
;
11523 current_base
= current_buffer
;
11524 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11525 if (current_base
->base_buffer
)
11526 current_base
= current_base
->base_buffer
;
11527 if (window_base
->base_buffer
)
11528 window_base
= window_base
->base_buffer
;
11529 if (current_base
== window_base
)
11533 /* Point refers normally to the selected window. For any other
11534 window, set up appropriate value. */
11535 if (!EQ (window
, selected_window
))
11537 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11538 int new_pt_byte
= marker_byte_position (w
->pointm
);
11542 new_pt_byte
= BEGV_BYTE
;
11543 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11545 else if (new_pt
> (ZV
- 1))
11548 new_pt_byte
= ZV_BYTE
;
11549 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11552 /* We don't use SET_PT so that the point-motion hooks don't run. */
11553 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11556 /* If any of the character widths specified in the display table
11557 have changed, invalidate the width run cache. It's true that
11558 this may be a bit late to catch such changes, but the rest of
11559 redisplay goes (non-fatally) haywire when the display table is
11560 changed, so why should we worry about doing any better? */
11561 if (current_buffer
->width_run_cache
)
11563 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11565 if (! disptab_matches_widthtab (disptab
,
11566 XVECTOR (current_buffer
->width_table
)))
11568 invalidate_region_cache (current_buffer
,
11569 current_buffer
->width_run_cache
,
11571 recompute_width_table (current_buffer
, disptab
);
11575 /* If window-start is screwed up, choose a new one. */
11576 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11579 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11581 /* If someone specified a new starting point but did not insist,
11582 check whether it can be used. */
11583 if (!NILP (w
->optional_new_start
)
11584 && CHARPOS (startp
) >= BEGV
11585 && CHARPOS (startp
) <= ZV
)
11587 w
->optional_new_start
= Qnil
;
11588 start_display (&it
, w
, startp
);
11589 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11590 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11591 if (IT_CHARPOS (it
) == PT
)
11592 w
->force_start
= Qt
;
11593 /* IT may overshoot PT if text at PT is invisible. */
11594 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11595 w
->force_start
= Qt
;
11600 /* Handle case where place to start displaying has been specified,
11601 unless the specified location is outside the accessible range. */
11602 if (!NILP (w
->force_start
)
11603 || w
->frozen_window_start_p
)
11605 /* We set this later on if we have to adjust point. */
11608 w
->force_start
= Qnil
;
11610 w
->window_end_valid
= Qnil
;
11612 /* Forget any recorded base line for line number display. */
11613 if (!buffer_unchanged_p
)
11614 w
->base_line_number
= Qnil
;
11616 /* Redisplay the mode line. Select the buffer properly for that.
11617 Also, run the hook window-scroll-functions
11618 because we have scrolled. */
11619 /* Note, we do this after clearing force_start because
11620 if there's an error, it is better to forget about force_start
11621 than to get into an infinite loop calling the hook functions
11622 and having them get more errors. */
11623 if (!update_mode_line
11624 || ! NILP (Vwindow_scroll_functions
))
11626 update_mode_line
= 1;
11627 w
->update_mode_line
= Qt
;
11628 startp
= run_window_scroll_functions (window
, startp
);
11631 w
->last_modified
= make_number (0);
11632 w
->last_overlay_modified
= make_number (0);
11633 if (CHARPOS (startp
) < BEGV
)
11634 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11635 else if (CHARPOS (startp
) > ZV
)
11636 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11638 /* Redisplay, then check if cursor has been set during the
11639 redisplay. Give up if new fonts were loaded. */
11640 if (!try_window (window
, startp
))
11642 w
->force_start
= Qt
;
11643 clear_glyph_matrix (w
->desired_matrix
);
11644 goto need_larger_matrices
;
11647 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11649 /* If point does not appear, try to move point so it does
11650 appear. The desired matrix has been built above, so we
11651 can use it here. */
11652 new_vpos
= window_box_height (w
) / 2;
11655 if (!make_cursor_line_fully_visible (w
))
11657 /* Point does appear, but on a line partly visible at end of window.
11658 Move it back to a fully-visible line. */
11659 new_vpos
= window_box_height (w
);
11662 /* If we need to move point for either of the above reasons,
11663 now actually do it. */
11666 struct glyph_row
*row
;
11668 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11669 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11672 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11673 MATRIX_ROW_START_BYTEPOS (row
));
11675 if (w
!= XWINDOW (selected_window
))
11676 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11677 else if (current_buffer
== old
)
11678 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11680 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11682 /* If we are highlighting the region, then we just changed
11683 the region, so redisplay to show it. */
11684 if (!NILP (Vtransient_mark_mode
)
11685 && !NILP (current_buffer
->mark_active
))
11687 clear_glyph_matrix (w
->desired_matrix
);
11688 if (!try_window (window
, startp
))
11689 goto need_larger_matrices
;
11694 debug_method_add (w
, "forced window start");
11699 /* Handle case where text has not changed, only point, and it has
11700 not moved off the frame, and we are not retrying after hscroll.
11701 (current_matrix_up_to_date_p is nonzero when retrying.) */
11702 if (current_matrix_up_to_date_p
11703 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11704 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11708 case CURSOR_MOVEMENT_SUCCESS
:
11709 used_current_matrix_p
= 1;
11712 #if 0 /* try_cursor_movement never returns this value. */
11713 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11714 goto need_larger_matrices
;
11717 case CURSOR_MOVEMENT_MUST_SCROLL
:
11718 goto try_to_scroll
;
11724 /* If current starting point was originally the beginning of a line
11725 but no longer is, find a new starting point. */
11726 else if (!NILP (w
->start_at_line_beg
)
11727 && !(CHARPOS (startp
) <= BEGV
11728 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11731 debug_method_add (w
, "recenter 1");
11736 /* Try scrolling with try_window_id. Value is > 0 if update has
11737 been done, it is -1 if we know that the same window start will
11738 not work. It is 0 if unsuccessful for some other reason. */
11739 else if ((tem
= try_window_id (w
)) != 0)
11742 debug_method_add (w
, "try_window_id %d", tem
);
11745 if (fonts_changed_p
)
11746 goto need_larger_matrices
;
11750 /* Otherwise try_window_id has returned -1 which means that we
11751 don't want the alternative below this comment to execute. */
11753 else if (CHARPOS (startp
) >= BEGV
11754 && CHARPOS (startp
) <= ZV
11755 && PT
>= CHARPOS (startp
)
11756 && (CHARPOS (startp
) < ZV
11757 /* Avoid starting at end of buffer. */
11758 || CHARPOS (startp
) == BEGV
11759 || (XFASTINT (w
->last_modified
) >= MODIFF
11760 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11763 debug_method_add (w
, "same window start");
11766 /* Try to redisplay starting at same place as before.
11767 If point has not moved off frame, accept the results. */
11768 if (!current_matrix_up_to_date_p
11769 /* Don't use try_window_reusing_current_matrix in this case
11770 because a window scroll function can have changed the
11772 || !NILP (Vwindow_scroll_functions
)
11773 || MINI_WINDOW_P (w
)
11774 || !(used_current_matrix_p
=
11775 try_window_reusing_current_matrix (w
)))
11777 IF_DEBUG (debug_method_add (w
, "1"));
11778 try_window (window
, startp
);
11781 if (fonts_changed_p
)
11782 goto need_larger_matrices
;
11784 if (w
->cursor
.vpos
>= 0)
11786 if (!just_this_one_p
11787 || current_buffer
->clip_changed
11788 || BEG_UNCHANGED
< CHARPOS (startp
))
11789 /* Forget any recorded base line for line number display. */
11790 w
->base_line_number
= Qnil
;
11792 if (!make_cursor_line_fully_visible (w
))
11794 clear_glyph_matrix (w
->desired_matrix
);
11795 last_line_misfit
= 1;
11797 /* Drop through and scroll. */
11802 clear_glyph_matrix (w
->desired_matrix
);
11807 w
->last_modified
= make_number (0);
11808 w
->last_overlay_modified
= make_number (0);
11810 /* Redisplay the mode line. Select the buffer properly for that. */
11811 if (!update_mode_line
)
11813 update_mode_line
= 1;
11814 w
->update_mode_line
= Qt
;
11817 /* Try to scroll by specified few lines. */
11818 if ((scroll_conservatively
11820 || temp_scroll_step
11821 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11822 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11823 && !current_buffer
->clip_changed
11824 && CHARPOS (startp
) >= BEGV
11825 && CHARPOS (startp
) <= ZV
)
11827 /* The function returns -1 if new fonts were loaded, 1 if
11828 successful, 0 if not successful. */
11829 int rc
= try_scrolling (window
, just_this_one_p
,
11830 scroll_conservatively
,
11832 temp_scroll_step
, last_line_misfit
);
11835 case SCROLLING_SUCCESS
:
11838 case SCROLLING_NEED_LARGER_MATRICES
:
11839 goto need_larger_matrices
;
11841 case SCROLLING_FAILED
:
11849 /* Finally, just choose place to start which centers point */
11852 centering_position
= window_box_height (w
) / 2;
11855 /* Jump here with centering_position already set to 0. */
11858 debug_method_add (w
, "recenter");
11861 /* w->vscroll = 0; */
11863 /* Forget any previously recorded base line for line number display. */
11864 if (!buffer_unchanged_p
)
11865 w
->base_line_number
= Qnil
;
11867 /* Move backward half the height of the window. */
11868 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11869 it
.current_y
= it
.last_visible_y
;
11870 move_it_vertically_backward (&it
, centering_position
);
11871 xassert (IT_CHARPOS (it
) >= BEGV
);
11873 /* The function move_it_vertically_backward may move over more
11874 than the specified y-distance. If it->w is small, e.g. a
11875 mini-buffer window, we may end up in front of the window's
11876 display area. Start displaying at the start of the line
11877 containing PT in this case. */
11878 if (it
.current_y
<= 0)
11880 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11881 move_it_vertically (&it
, 0);
11882 xassert (IT_CHARPOS (it
) <= PT
);
11886 it
.current_x
= it
.hpos
= 0;
11888 /* Set startp here explicitly in case that helps avoid an infinite loop
11889 in case the window-scroll-functions functions get errors. */
11890 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11892 /* Run scroll hooks. */
11893 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11895 /* Redisplay the window. */
11896 if (!current_matrix_up_to_date_p
11897 || windows_or_buffers_changed
11898 || cursor_type_changed
11899 /* Don't use try_window_reusing_current_matrix in this case
11900 because it can have changed the buffer. */
11901 || !NILP (Vwindow_scroll_functions
)
11902 || !just_this_one_p
11903 || MINI_WINDOW_P (w
)
11904 || !(used_current_matrix_p
=
11905 try_window_reusing_current_matrix (w
)))
11906 try_window (window
, startp
);
11908 /* If new fonts have been loaded (due to fontsets), give up. We
11909 have to start a new redisplay since we need to re-adjust glyph
11911 if (fonts_changed_p
)
11912 goto need_larger_matrices
;
11914 /* If cursor did not appear assume that the middle of the window is
11915 in the first line of the window. Do it again with the next line.
11916 (Imagine a window of height 100, displaying two lines of height
11917 60. Moving back 50 from it->last_visible_y will end in the first
11919 if (w
->cursor
.vpos
< 0)
11921 if (!NILP (w
->window_end_valid
)
11922 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11924 clear_glyph_matrix (w
->desired_matrix
);
11925 move_it_by_lines (&it
, 1, 0);
11926 try_window (window
, it
.current
.pos
);
11928 else if (PT
< IT_CHARPOS (it
))
11930 clear_glyph_matrix (w
->desired_matrix
);
11931 move_it_by_lines (&it
, -1, 0);
11932 try_window (window
, it
.current
.pos
);
11936 /* Not much we can do about it. */
11940 /* Consider the following case: Window starts at BEGV, there is
11941 invisible, intangible text at BEGV, so that display starts at
11942 some point START > BEGV. It can happen that we are called with
11943 PT somewhere between BEGV and START. Try to handle that case. */
11944 if (w
->cursor
.vpos
< 0)
11946 struct glyph_row
*row
= w
->current_matrix
->rows
;
11947 if (row
->mode_line_p
)
11949 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11952 if (!make_cursor_line_fully_visible (w
))
11954 /* If vscroll is enabled, disable it and try again. */
11958 clear_glyph_matrix (w
->desired_matrix
);
11962 /* If centering point failed to make the whole line visible,
11963 put point at the top instead. That has to make the whole line
11964 visible, if it can be done. */
11965 centering_position
= 0;
11971 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11972 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
11973 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
11976 /* Display the mode line, if we must. */
11977 if ((update_mode_line
11978 /* If window not full width, must redo its mode line
11979 if (a) the window to its side is being redone and
11980 (b) we do a frame-based redisplay. This is a consequence
11981 of how inverted lines are drawn in frame-based redisplay. */
11982 || (!just_this_one_p
11983 && !FRAME_WINDOW_P (f
)
11984 && !WINDOW_FULL_WIDTH_P (w
))
11985 /* Line number to display. */
11986 || INTEGERP (w
->base_line_pos
)
11987 /* Column number is displayed and different from the one displayed. */
11988 || (!NILP (w
->column_number_displayed
)
11989 && (XFASTINT (w
->column_number_displayed
)
11990 != (int) current_column ()))) /* iftc */
11991 /* This means that the window has a mode line. */
11992 && (WINDOW_WANTS_MODELINE_P (w
)
11993 || WINDOW_WANTS_HEADER_LINE_P (w
)))
11995 display_mode_lines (w
);
11997 /* If mode line height has changed, arrange for a thorough
11998 immediate redisplay using the correct mode line height. */
11999 if (WINDOW_WANTS_MODELINE_P (w
)
12000 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12002 fonts_changed_p
= 1;
12003 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12004 = DESIRED_MODE_LINE_HEIGHT (w
);
12007 /* If top line height has changed, arrange for a thorough
12008 immediate redisplay using the correct mode line height. */
12009 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12010 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12012 fonts_changed_p
= 1;
12013 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12014 = DESIRED_HEADER_LINE_HEIGHT (w
);
12017 if (fonts_changed_p
)
12018 goto need_larger_matrices
;
12021 if (!line_number_displayed
12022 && !BUFFERP (w
->base_line_pos
))
12024 w
->base_line_pos
= Qnil
;
12025 w
->base_line_number
= Qnil
;
12030 /* When we reach a frame's selected window, redo the frame's menu bar. */
12031 if (update_mode_line
12032 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12034 int redisplay_menu_p
= 0;
12035 int redisplay_tool_bar_p
= 0;
12037 if (FRAME_WINDOW_P (f
))
12039 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12040 || defined (USE_GTK)
12041 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12043 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12047 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12049 if (redisplay_menu_p
)
12050 display_menu_bar (w
);
12052 #ifdef HAVE_WINDOW_SYSTEM
12054 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12056 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12057 && (FRAME_TOOL_BAR_LINES (f
) > 0
12058 || auto_resize_tool_bars_p
);
12062 if (redisplay_tool_bar_p
)
12063 redisplay_tool_bar (f
);
12067 #ifdef HAVE_WINDOW_SYSTEM
12068 if (update_window_fringes (w
, 0)
12069 && !just_this_one_p
12070 && (used_current_matrix_p
|| overlay_arrow_seen
)
12071 && !w
->pseudo_window_p
)
12075 draw_window_fringes (w
);
12079 #endif /* HAVE_WINDOW_SYSTEM */
12081 /* We go to this label, with fonts_changed_p nonzero,
12082 if it is necessary to try again using larger glyph matrices.
12083 We have to redeem the scroll bar even in this case,
12084 because the loop in redisplay_internal expects that. */
12085 need_larger_matrices
:
12087 finish_scroll_bars
:
12089 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12091 /* Set the thumb's position and size. */
12092 set_vertical_scroll_bar (w
);
12094 /* Note that we actually used the scroll bar attached to this
12095 window, so it shouldn't be deleted at the end of redisplay. */
12096 if (FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
)
12097 (*FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
) (w
);
12100 /* Restore current_buffer and value of point in it. */
12101 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12102 set_buffer_internal_1 (old
);
12103 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12105 unbind_to (count
, Qnil
);
12109 /* Build the complete desired matrix of WINDOW with a window start
12110 buffer position POS. Value is non-zero if successful. It is zero
12111 if fonts were loaded during redisplay which makes re-adjusting
12112 glyph matrices necessary. */
12115 try_window (window
, pos
)
12116 Lisp_Object window
;
12117 struct text_pos pos
;
12119 struct window
*w
= XWINDOW (window
);
12121 struct glyph_row
*last_text_row
= NULL
;
12123 /* Make POS the new window start. */
12124 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12126 /* Mark cursor position as unknown. No overlay arrow seen. */
12127 w
->cursor
.vpos
= -1;
12128 overlay_arrow_seen
= 0;
12130 /* Initialize iterator and info to start at POS. */
12131 start_display (&it
, w
, pos
);
12133 /* Display all lines of W. */
12134 while (it
.current_y
< it
.last_visible_y
)
12136 if (display_line (&it
))
12137 last_text_row
= it
.glyph_row
- 1;
12138 if (fonts_changed_p
)
12142 /* If bottom moved off end of frame, change mode line percentage. */
12143 if (XFASTINT (w
->window_end_pos
) <= 0
12144 && Z
!= IT_CHARPOS (it
))
12145 w
->update_mode_line
= Qt
;
12147 /* Set window_end_pos to the offset of the last character displayed
12148 on the window from the end of current_buffer. Set
12149 window_end_vpos to its row number. */
12152 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12153 w
->window_end_bytepos
12154 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12156 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12158 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12159 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12160 ->displays_text_p
);
12164 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12165 w
->window_end_pos
= make_number (Z
- ZV
);
12166 w
->window_end_vpos
= make_number (0);
12169 /* But that is not valid info until redisplay finishes. */
12170 w
->window_end_valid
= Qnil
;
12176 /************************************************************************
12177 Window redisplay reusing current matrix when buffer has not changed
12178 ************************************************************************/
12180 /* Try redisplay of window W showing an unchanged buffer with a
12181 different window start than the last time it was displayed by
12182 reusing its current matrix. Value is non-zero if successful.
12183 W->start is the new window start. */
12186 try_window_reusing_current_matrix (w
)
12189 struct frame
*f
= XFRAME (w
->frame
);
12190 struct glyph_row
*row
, *bottom_row
;
12193 struct text_pos start
, new_start
;
12194 int nrows_scrolled
, i
;
12195 struct glyph_row
*last_text_row
;
12196 struct glyph_row
*last_reused_text_row
;
12197 struct glyph_row
*start_row
;
12198 int start_vpos
, min_y
, max_y
;
12201 if (inhibit_try_window_reusing
)
12205 if (/* This function doesn't handle terminal frames. */
12206 !FRAME_WINDOW_P (f
)
12207 /* Don't try to reuse the display if windows have been split
12209 || windows_or_buffers_changed
12210 || cursor_type_changed
)
12213 /* Can't do this if region may have changed. */
12214 if ((!NILP (Vtransient_mark_mode
)
12215 && !NILP (current_buffer
->mark_active
))
12216 || !NILP (w
->region_showing
)
12217 || !NILP (Vshow_trailing_whitespace
))
12220 /* If top-line visibility has changed, give up. */
12221 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12222 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12225 /* Give up if old or new display is scrolled vertically. We could
12226 make this function handle this, but right now it doesn't. */
12227 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12228 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12231 /* The variable new_start now holds the new window start. The old
12232 start `start' can be determined from the current matrix. */
12233 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12234 start
= start_row
->start
.pos
;
12235 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12237 /* Clear the desired matrix for the display below. */
12238 clear_glyph_matrix (w
->desired_matrix
);
12240 if (CHARPOS (new_start
) <= CHARPOS (start
))
12244 /* Don't use this method if the display starts with an ellipsis
12245 displayed for invisible text. It's not easy to handle that case
12246 below, and it's certainly not worth the effort since this is
12247 not a frequent case. */
12248 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12251 IF_DEBUG (debug_method_add (w
, "twu1"));
12253 /* Display up to a row that can be reused. The variable
12254 last_text_row is set to the last row displayed that displays
12255 text. Note that it.vpos == 0 if or if not there is a
12256 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12257 start_display (&it
, w
, new_start
);
12258 first_row_y
= it
.current_y
;
12259 w
->cursor
.vpos
= -1;
12260 last_text_row
= last_reused_text_row
= NULL
;
12262 while (it
.current_y
< it
.last_visible_y
12263 && IT_CHARPOS (it
) < CHARPOS (start
)
12264 && !fonts_changed_p
)
12265 if (display_line (&it
))
12266 last_text_row
= it
.glyph_row
- 1;
12268 /* A value of current_y < last_visible_y means that we stopped
12269 at the previous window start, which in turn means that we
12270 have at least one reusable row. */
12271 if (it
.current_y
< it
.last_visible_y
)
12273 /* IT.vpos always starts from 0; it counts text lines. */
12274 nrows_scrolled
= it
.vpos
;
12276 /* Find PT if not already found in the lines displayed. */
12277 if (w
->cursor
.vpos
< 0)
12279 int dy
= it
.current_y
- first_row_y
;
12281 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12282 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12284 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12285 dy
, nrows_scrolled
);
12288 clear_glyph_matrix (w
->desired_matrix
);
12293 /* Scroll the display. Do it before the current matrix is
12294 changed. The problem here is that update has not yet
12295 run, i.e. part of the current matrix is not up to date.
12296 scroll_run_hook will clear the cursor, and use the
12297 current matrix to get the height of the row the cursor is
12299 run
.current_y
= first_row_y
;
12300 run
.desired_y
= it
.current_y
;
12301 run
.height
= it
.last_visible_y
- it
.current_y
;
12303 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12306 FRAME_RIF (f
)->update_window_begin_hook (w
);
12307 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12308 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12309 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12313 /* Shift current matrix down by nrows_scrolled lines. */
12314 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12315 rotate_matrix (w
->current_matrix
,
12317 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12320 /* Disable lines that must be updated. */
12321 for (i
= 0; i
< it
.vpos
; ++i
)
12322 (start_row
+ i
)->enabled_p
= 0;
12324 /* Re-compute Y positions. */
12325 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12326 max_y
= it
.last_visible_y
;
12327 for (row
= start_row
+ nrows_scrolled
;
12331 row
->y
= it
.current_y
;
12332 row
->visible_height
= row
->height
;
12334 if (row
->y
< min_y
)
12335 row
->visible_height
-= min_y
- row
->y
;
12336 if (row
->y
+ row
->height
> max_y
)
12337 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12338 row
->redraw_fringe_bitmaps_p
= 1;
12340 it
.current_y
+= row
->height
;
12342 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12343 last_reused_text_row
= row
;
12344 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12348 /* Disable lines in the current matrix which are now
12349 below the window. */
12350 for (++row
; row
< bottom_row
; ++row
)
12351 row
->enabled_p
= 0;
12354 /* Update window_end_pos etc.; last_reused_text_row is the last
12355 reused row from the current matrix containing text, if any.
12356 The value of last_text_row is the last displayed line
12357 containing text. */
12358 if (last_reused_text_row
)
12360 w
->window_end_bytepos
12361 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12363 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12365 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12366 w
->current_matrix
));
12368 else if (last_text_row
)
12370 w
->window_end_bytepos
12371 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12373 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12375 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12379 /* This window must be completely empty. */
12380 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12381 w
->window_end_pos
= make_number (Z
- ZV
);
12382 w
->window_end_vpos
= make_number (0);
12384 w
->window_end_valid
= Qnil
;
12386 /* Update hint: don't try scrolling again in update_window. */
12387 w
->desired_matrix
->no_scrolling_p
= 1;
12390 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12394 else if (CHARPOS (new_start
) > CHARPOS (start
))
12396 struct glyph_row
*pt_row
, *row
;
12397 struct glyph_row
*first_reusable_row
;
12398 struct glyph_row
*first_row_to_display
;
12400 int yb
= window_text_bottom_y (w
);
12402 /* Find the row starting at new_start, if there is one. Don't
12403 reuse a partially visible line at the end. */
12404 first_reusable_row
= start_row
;
12405 while (first_reusable_row
->enabled_p
12406 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12407 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12408 < CHARPOS (new_start
)))
12409 ++first_reusable_row
;
12411 /* Give up if there is no row to reuse. */
12412 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12413 || !first_reusable_row
->enabled_p
12414 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12415 != CHARPOS (new_start
)))
12418 /* We can reuse fully visible rows beginning with
12419 first_reusable_row to the end of the window. Set
12420 first_row_to_display to the first row that cannot be reused.
12421 Set pt_row to the row containing point, if there is any. */
12423 for (first_row_to_display
= first_reusable_row
;
12424 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12425 ++first_row_to_display
)
12427 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12428 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12429 pt_row
= first_row_to_display
;
12432 /* Start displaying at the start of first_row_to_display. */
12433 xassert (first_row_to_display
->y
< yb
);
12434 init_to_row_start (&it
, w
, first_row_to_display
);
12436 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12438 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12440 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12441 + WINDOW_HEADER_LINE_HEIGHT (w
));
12443 /* Display lines beginning with first_row_to_display in the
12444 desired matrix. Set last_text_row to the last row displayed
12445 that displays text. */
12446 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12447 if (pt_row
== NULL
)
12448 w
->cursor
.vpos
= -1;
12449 last_text_row
= NULL
;
12450 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12451 if (display_line (&it
))
12452 last_text_row
= it
.glyph_row
- 1;
12454 /* Give up If point isn't in a row displayed or reused. */
12455 if (w
->cursor
.vpos
< 0)
12457 clear_glyph_matrix (w
->desired_matrix
);
12461 /* If point is in a reused row, adjust y and vpos of the cursor
12465 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12466 w
->current_matrix
);
12467 w
->cursor
.y
-= first_reusable_row
->y
;
12470 /* Scroll the display. */
12471 run
.current_y
= first_reusable_row
->y
;
12472 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12473 run
.height
= it
.last_visible_y
- run
.current_y
;
12474 dy
= run
.current_y
- run
.desired_y
;
12479 FRAME_RIF (f
)->update_window_begin_hook (w
);
12480 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12481 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12482 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12486 /* Adjust Y positions of reused rows. */
12487 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12488 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12489 max_y
= it
.last_visible_y
;
12490 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12493 row
->visible_height
= row
->height
;
12494 if (row
->y
< min_y
)
12495 row
->visible_height
-= min_y
- row
->y
;
12496 if (row
->y
+ row
->height
> max_y
)
12497 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12498 row
->redraw_fringe_bitmaps_p
= 1;
12501 /* Scroll the current matrix. */
12502 xassert (nrows_scrolled
> 0);
12503 rotate_matrix (w
->current_matrix
,
12505 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12508 /* Disable rows not reused. */
12509 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12510 row
->enabled_p
= 0;
12512 /* Adjust window end. A null value of last_text_row means that
12513 the window end is in reused rows which in turn means that
12514 only its vpos can have changed. */
12517 w
->window_end_bytepos
12518 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12520 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12522 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12527 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12530 w
->window_end_valid
= Qnil
;
12531 w
->desired_matrix
->no_scrolling_p
= 1;
12534 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12544 /************************************************************************
12545 Window redisplay reusing current matrix when buffer has changed
12546 ************************************************************************/
12548 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12549 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12551 static struct glyph_row
*
12552 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12553 struct glyph_row
*));
12556 /* Return the last row in MATRIX displaying text. If row START is
12557 non-null, start searching with that row. IT gives the dimensions
12558 of the display. Value is null if matrix is empty; otherwise it is
12559 a pointer to the row found. */
12561 static struct glyph_row
*
12562 find_last_row_displaying_text (matrix
, it
, start
)
12563 struct glyph_matrix
*matrix
;
12565 struct glyph_row
*start
;
12567 struct glyph_row
*row
, *row_found
;
12569 /* Set row_found to the last row in IT->w's current matrix
12570 displaying text. The loop looks funny but think of partially
12573 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12574 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12576 xassert (row
->enabled_p
);
12578 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12587 /* Return the last row in the current matrix of W that is not affected
12588 by changes at the start of current_buffer that occurred since W's
12589 current matrix was built. Value is null if no such row exists.
12591 BEG_UNCHANGED us the number of characters unchanged at the start of
12592 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12593 first changed character in current_buffer. Characters at positions <
12594 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12595 when the current matrix was built. */
12597 static struct glyph_row
*
12598 find_last_unchanged_at_beg_row (w
)
12601 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12602 struct glyph_row
*row
;
12603 struct glyph_row
*row_found
= NULL
;
12604 int yb
= window_text_bottom_y (w
);
12606 /* Find the last row displaying unchanged text. */
12607 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12608 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12609 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12611 if (/* If row ends before first_changed_pos, it is unchanged,
12612 except in some case. */
12613 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12614 /* When row ends in ZV and we write at ZV it is not
12616 && !row
->ends_at_zv_p
12617 /* When first_changed_pos is the end of a continued line,
12618 row is not unchanged because it may be no longer
12620 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12621 && (row
->continued_p
12622 || row
->exact_window_width_line_p
)))
12625 /* Stop if last visible row. */
12626 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12636 /* Find the first glyph row in the current matrix of W that is not
12637 affected by changes at the end of current_buffer since the
12638 time W's current matrix was built.
12640 Return in *DELTA the number of chars by which buffer positions in
12641 unchanged text at the end of current_buffer must be adjusted.
12643 Return in *DELTA_BYTES the corresponding number of bytes.
12645 Value is null if no such row exists, i.e. all rows are affected by
12648 static struct glyph_row
*
12649 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12651 int *delta
, *delta_bytes
;
12653 struct glyph_row
*row
;
12654 struct glyph_row
*row_found
= NULL
;
12656 *delta
= *delta_bytes
= 0;
12658 /* Display must not have been paused, otherwise the current matrix
12659 is not up to date. */
12660 if (NILP (w
->window_end_valid
))
12663 /* A value of window_end_pos >= END_UNCHANGED means that the window
12664 end is in the range of changed text. If so, there is no
12665 unchanged row at the end of W's current matrix. */
12666 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12669 /* Set row to the last row in W's current matrix displaying text. */
12670 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12672 /* If matrix is entirely empty, no unchanged row exists. */
12673 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12675 /* The value of row is the last glyph row in the matrix having a
12676 meaningful buffer position in it. The end position of row
12677 corresponds to window_end_pos. This allows us to translate
12678 buffer positions in the current matrix to current buffer
12679 positions for characters not in changed text. */
12680 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12681 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12682 int last_unchanged_pos
, last_unchanged_pos_old
;
12683 struct glyph_row
*first_text_row
12684 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12686 *delta
= Z
- Z_old
;
12687 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12689 /* Set last_unchanged_pos to the buffer position of the last
12690 character in the buffer that has not been changed. Z is the
12691 index + 1 of the last character in current_buffer, i.e. by
12692 subtracting END_UNCHANGED we get the index of the last
12693 unchanged character, and we have to add BEG to get its buffer
12695 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12696 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12698 /* Search backward from ROW for a row displaying a line that
12699 starts at a minimum position >= last_unchanged_pos_old. */
12700 for (; row
> first_text_row
; --row
)
12702 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12705 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12710 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12717 /* Make sure that glyph rows in the current matrix of window W
12718 reference the same glyph memory as corresponding rows in the
12719 frame's frame matrix. This function is called after scrolling W's
12720 current matrix on a terminal frame in try_window_id and
12721 try_window_reusing_current_matrix. */
12724 sync_frame_with_window_matrix_rows (w
)
12727 struct frame
*f
= XFRAME (w
->frame
);
12728 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12730 /* Preconditions: W must be a leaf window and full-width. Its frame
12731 must have a frame matrix. */
12732 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12733 xassert (WINDOW_FULL_WIDTH_P (w
));
12734 xassert (!FRAME_WINDOW_P (f
));
12736 /* If W is a full-width window, glyph pointers in W's current matrix
12737 have, by definition, to be the same as glyph pointers in the
12738 corresponding frame matrix. Note that frame matrices have no
12739 marginal areas (see build_frame_matrix). */
12740 window_row
= w
->current_matrix
->rows
;
12741 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12742 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12743 while (window_row
< window_row_end
)
12745 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12746 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12748 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12749 frame_row
->glyphs
[TEXT_AREA
] = start
;
12750 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12751 frame_row
->glyphs
[LAST_AREA
] = end
;
12753 /* Disable frame rows whose corresponding window rows have
12754 been disabled in try_window_id. */
12755 if (!window_row
->enabled_p
)
12756 frame_row
->enabled_p
= 0;
12758 ++window_row
, ++frame_row
;
12763 /* Find the glyph row in window W containing CHARPOS. Consider all
12764 rows between START and END (not inclusive). END null means search
12765 all rows to the end of the display area of W. Value is the row
12766 containing CHARPOS or null. */
12769 row_containing_pos (w
, charpos
, start
, end
, dy
)
12772 struct glyph_row
*start
, *end
;
12775 struct glyph_row
*row
= start
;
12778 /* If we happen to start on a header-line, skip that. */
12779 if (row
->mode_line_p
)
12782 if ((end
&& row
>= end
) || !row
->enabled_p
)
12785 last_y
= window_text_bottom_y (w
) - dy
;
12789 /* Give up if we have gone too far. */
12790 if (end
&& row
>= end
)
12792 /* This formerly returned if they were equal.
12793 I think that both quantities are of a "last plus one" type;
12794 if so, when they are equal, the row is within the screen. -- rms. */
12795 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12798 /* If it is in this row, return this row. */
12799 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12800 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12801 /* The end position of a row equals the start
12802 position of the next row. If CHARPOS is there, we
12803 would rather display it in the next line, except
12804 when this line ends in ZV. */
12805 && !row
->ends_at_zv_p
12806 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12807 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12814 /* Try to redisplay window W by reusing its existing display. W's
12815 current matrix must be up to date when this function is called,
12816 i.e. window_end_valid must not be nil.
12820 1 if display has been updated
12821 0 if otherwise unsuccessful
12822 -1 if redisplay with same window start is known not to succeed
12824 The following steps are performed:
12826 1. Find the last row in the current matrix of W that is not
12827 affected by changes at the start of current_buffer. If no such row
12830 2. Find the first row in W's current matrix that is not affected by
12831 changes at the end of current_buffer. Maybe there is no such row.
12833 3. Display lines beginning with the row + 1 found in step 1 to the
12834 row found in step 2 or, if step 2 didn't find a row, to the end of
12837 4. If cursor is not known to appear on the window, give up.
12839 5. If display stopped at the row found in step 2, scroll the
12840 display and current matrix as needed.
12842 6. Maybe display some lines at the end of W, if we must. This can
12843 happen under various circumstances, like a partially visible line
12844 becoming fully visible, or because newly displayed lines are displayed
12845 in smaller font sizes.
12847 7. Update W's window end information. */
12853 struct frame
*f
= XFRAME (w
->frame
);
12854 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12855 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12856 struct glyph_row
*last_unchanged_at_beg_row
;
12857 struct glyph_row
*first_unchanged_at_end_row
;
12858 struct glyph_row
*row
;
12859 struct glyph_row
*bottom_row
;
12862 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12863 struct text_pos start_pos
;
12865 int first_unchanged_at_end_vpos
= 0;
12866 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12867 struct text_pos start
;
12868 int first_changed_charpos
, last_changed_charpos
;
12871 if (inhibit_try_window_id
)
12875 /* This is handy for debugging. */
12877 #define GIVE_UP(X) \
12879 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12883 #define GIVE_UP(X) return 0
12886 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12888 /* Don't use this for mini-windows because these can show
12889 messages and mini-buffers, and we don't handle that here. */
12890 if (MINI_WINDOW_P (w
))
12893 /* This flag is used to prevent redisplay optimizations. */
12894 if (windows_or_buffers_changed
|| cursor_type_changed
)
12897 /* Verify that narrowing has not changed.
12898 Also verify that we were not told to prevent redisplay optimizations.
12899 It would be nice to further
12900 reduce the number of cases where this prevents try_window_id. */
12901 if (current_buffer
->clip_changed
12902 || current_buffer
->prevent_redisplay_optimizations_p
)
12905 /* Window must either use window-based redisplay or be full width. */
12906 if (!FRAME_WINDOW_P (f
)
12907 && (!FRAME_LINE_INS_DEL_OK (f
)
12908 || !WINDOW_FULL_WIDTH_P (w
)))
12911 /* Give up if point is not known NOT to appear in W. */
12912 if (PT
< CHARPOS (start
))
12915 /* Another way to prevent redisplay optimizations. */
12916 if (XFASTINT (w
->last_modified
) == 0)
12919 /* Verify that window is not hscrolled. */
12920 if (XFASTINT (w
->hscroll
) != 0)
12923 /* Verify that display wasn't paused. */
12924 if (NILP (w
->window_end_valid
))
12927 /* Can't use this if highlighting a region because a cursor movement
12928 will do more than just set the cursor. */
12929 if (!NILP (Vtransient_mark_mode
)
12930 && !NILP (current_buffer
->mark_active
))
12933 /* Likewise if highlighting trailing whitespace. */
12934 if (!NILP (Vshow_trailing_whitespace
))
12937 /* Likewise if showing a region. */
12938 if (!NILP (w
->region_showing
))
12941 /* Can use this if overlay arrow position and or string have changed. */
12942 if (overlay_arrows_changed_p ())
12946 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
12947 only if buffer has really changed. The reason is that the gap is
12948 initially at Z for freshly visited files. The code below would
12949 set end_unchanged to 0 in that case. */
12950 if (MODIFF
> SAVE_MODIFF
12951 /* This seems to happen sometimes after saving a buffer. */
12952 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12954 if (GPT
- BEG
< BEG_UNCHANGED
)
12955 BEG_UNCHANGED
= GPT
- BEG
;
12956 if (Z
- GPT
< END_UNCHANGED
)
12957 END_UNCHANGED
= Z
- GPT
;
12960 /* The position of the first and last character that has been changed. */
12961 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
12962 last_changed_charpos
= Z
- END_UNCHANGED
;
12964 /* If window starts after a line end, and the last change is in
12965 front of that newline, then changes don't affect the display.
12966 This case happens with stealth-fontification. Note that although
12967 the display is unchanged, glyph positions in the matrix have to
12968 be adjusted, of course. */
12969 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12970 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12971 && ((last_changed_charpos
< CHARPOS (start
)
12972 && CHARPOS (start
) == BEGV
)
12973 || (last_changed_charpos
< CHARPOS (start
) - 1
12974 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
12976 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
12977 struct glyph_row
*r0
;
12979 /* Compute how many chars/bytes have been added to or removed
12980 from the buffer. */
12981 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12982 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12984 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12986 /* Give up if PT is not in the window. Note that it already has
12987 been checked at the start of try_window_id that PT is not in
12988 front of the window start. */
12989 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
12992 /* If window start is unchanged, we can reuse the whole matrix
12993 as is, after adjusting glyph positions. No need to compute
12994 the window end again, since its offset from Z hasn't changed. */
12995 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12996 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
12997 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
12998 /* PT must not be in a partially visible line. */
12999 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13000 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13002 /* Adjust positions in the glyph matrix. */
13003 if (delta
|| delta_bytes
)
13005 struct glyph_row
*r1
13006 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13007 increment_matrix_positions (w
->current_matrix
,
13008 MATRIX_ROW_VPOS (r0
, current_matrix
),
13009 MATRIX_ROW_VPOS (r1
, current_matrix
),
13010 delta
, delta_bytes
);
13013 /* Set the cursor. */
13014 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13016 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13023 /* Handle the case that changes are all below what is displayed in
13024 the window, and that PT is in the window. This shortcut cannot
13025 be taken if ZV is visible in the window, and text has been added
13026 there that is visible in the window. */
13027 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13028 /* ZV is not visible in the window, or there are no
13029 changes at ZV, actually. */
13030 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13031 || first_changed_charpos
== last_changed_charpos
))
13033 struct glyph_row
*r0
;
13035 /* Give up if PT is not in the window. Note that it already has
13036 been checked at the start of try_window_id that PT is not in
13037 front of the window start. */
13038 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13041 /* If window start is unchanged, we can reuse the whole matrix
13042 as is, without changing glyph positions since no text has
13043 been added/removed in front of the window end. */
13044 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13045 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13046 /* PT must not be in a partially visible line. */
13047 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13048 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13050 /* We have to compute the window end anew since text
13051 can have been added/removed after it. */
13053 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13054 w
->window_end_bytepos
13055 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13057 /* Set the cursor. */
13058 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13060 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13067 /* Give up if window start is in the changed area.
13069 The condition used to read
13071 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13073 but why that was tested escapes me at the moment. */
13074 if (CHARPOS (start
) >= first_changed_charpos
13075 && CHARPOS (start
) <= last_changed_charpos
)
13078 /* Check that window start agrees with the start of the first glyph
13079 row in its current matrix. Check this after we know the window
13080 start is not in changed text, otherwise positions would not be
13082 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13083 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13086 /* Give up if the window ends in strings. Overlay strings
13087 at the end are difficult to handle, so don't try. */
13088 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13089 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13092 /* Compute the position at which we have to start displaying new
13093 lines. Some of the lines at the top of the window might be
13094 reusable because they are not displaying changed text. Find the
13095 last row in W's current matrix not affected by changes at the
13096 start of current_buffer. Value is null if changes start in the
13097 first line of window. */
13098 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13099 if (last_unchanged_at_beg_row
)
13101 /* Avoid starting to display in the moddle of a character, a TAB
13102 for instance. This is easier than to set up the iterator
13103 exactly, and it's not a frequent case, so the additional
13104 effort wouldn't really pay off. */
13105 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13106 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13107 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13108 --last_unchanged_at_beg_row
;
13110 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13113 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13115 start_pos
= it
.current
.pos
;
13117 /* Start displaying new lines in the desired matrix at the same
13118 vpos we would use in the current matrix, i.e. below
13119 last_unchanged_at_beg_row. */
13120 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13122 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13123 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13125 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13129 /* There are no reusable lines at the start of the window.
13130 Start displaying in the first text line. */
13131 start_display (&it
, w
, start
);
13132 it
.vpos
= it
.first_vpos
;
13133 start_pos
= it
.current
.pos
;
13136 /* Find the first row that is not affected by changes at the end of
13137 the buffer. Value will be null if there is no unchanged row, in
13138 which case we must redisplay to the end of the window. delta
13139 will be set to the value by which buffer positions beginning with
13140 first_unchanged_at_end_row have to be adjusted due to text
13142 first_unchanged_at_end_row
13143 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13144 IF_DEBUG (debug_delta
= delta
);
13145 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13147 /* Set stop_pos to the buffer position up to which we will have to
13148 display new lines. If first_unchanged_at_end_row != NULL, this
13149 is the buffer position of the start of the line displayed in that
13150 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13151 that we don't stop at a buffer position. */
13153 if (first_unchanged_at_end_row
)
13155 xassert (last_unchanged_at_beg_row
== NULL
13156 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13158 /* If this is a continuation line, move forward to the next one
13159 that isn't. Changes in lines above affect this line.
13160 Caution: this may move first_unchanged_at_end_row to a row
13161 not displaying text. */
13162 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13163 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13164 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13165 < it
.last_visible_y
))
13166 ++first_unchanged_at_end_row
;
13168 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13169 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13170 >= it
.last_visible_y
))
13171 first_unchanged_at_end_row
= NULL
;
13174 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13176 first_unchanged_at_end_vpos
13177 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13178 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13181 else if (last_unchanged_at_beg_row
== NULL
)
13187 /* Either there is no unchanged row at the end, or the one we have
13188 now displays text. This is a necessary condition for the window
13189 end pos calculation at the end of this function. */
13190 xassert (first_unchanged_at_end_row
== NULL
13191 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13193 debug_last_unchanged_at_beg_vpos
13194 = (last_unchanged_at_beg_row
13195 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13197 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13199 #endif /* GLYPH_DEBUG != 0 */
13202 /* Display new lines. Set last_text_row to the last new line
13203 displayed which has text on it, i.e. might end up as being the
13204 line where the window_end_vpos is. */
13205 w
->cursor
.vpos
= -1;
13206 last_text_row
= NULL
;
13207 overlay_arrow_seen
= 0;
13208 while (it
.current_y
< it
.last_visible_y
13209 && !fonts_changed_p
13210 && (first_unchanged_at_end_row
== NULL
13211 || IT_CHARPOS (it
) < stop_pos
))
13213 if (display_line (&it
))
13214 last_text_row
= it
.glyph_row
- 1;
13217 if (fonts_changed_p
)
13221 /* Compute differences in buffer positions, y-positions etc. for
13222 lines reused at the bottom of the window. Compute what we can
13224 if (first_unchanged_at_end_row
13225 /* No lines reused because we displayed everything up to the
13226 bottom of the window. */
13227 && it
.current_y
< it
.last_visible_y
)
13230 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13232 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13233 run
.current_y
= first_unchanged_at_end_row
->y
;
13234 run
.desired_y
= run
.current_y
+ dy
;
13235 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13239 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13240 first_unchanged_at_end_row
= NULL
;
13242 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13245 /* Find the cursor if not already found. We have to decide whether
13246 PT will appear on this window (it sometimes doesn't, but this is
13247 not a very frequent case.) This decision has to be made before
13248 the current matrix is altered. A value of cursor.vpos < 0 means
13249 that PT is either in one of the lines beginning at
13250 first_unchanged_at_end_row or below the window. Don't care for
13251 lines that might be displayed later at the window end; as
13252 mentioned, this is not a frequent case. */
13253 if (w
->cursor
.vpos
< 0)
13255 /* Cursor in unchanged rows at the top? */
13256 if (PT
< CHARPOS (start_pos
)
13257 && last_unchanged_at_beg_row
)
13259 row
= row_containing_pos (w
, PT
,
13260 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13261 last_unchanged_at_beg_row
+ 1, 0);
13263 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13266 /* Start from first_unchanged_at_end_row looking for PT. */
13267 else if (first_unchanged_at_end_row
)
13269 row
= row_containing_pos (w
, PT
- delta
,
13270 first_unchanged_at_end_row
, NULL
, 0);
13272 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13273 delta_bytes
, dy
, dvpos
);
13276 /* Give up if cursor was not found. */
13277 if (w
->cursor
.vpos
< 0)
13279 clear_glyph_matrix (w
->desired_matrix
);
13284 /* Don't let the cursor end in the scroll margins. */
13286 int this_scroll_margin
, cursor_height
;
13288 this_scroll_margin
= max (0, scroll_margin
);
13289 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13290 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13291 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13293 if ((w
->cursor
.y
< this_scroll_margin
13294 && CHARPOS (start
) > BEGV
)
13295 /* Don't take scroll margin into account at the bottom because
13296 old redisplay didn't do it either. */
13297 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13299 w
->cursor
.vpos
= -1;
13300 clear_glyph_matrix (w
->desired_matrix
);
13305 /* Scroll the display. Do it before changing the current matrix so
13306 that xterm.c doesn't get confused about where the cursor glyph is
13308 if (dy
&& run
.height
)
13312 if (FRAME_WINDOW_P (f
))
13314 FRAME_RIF (f
)->update_window_begin_hook (w
);
13315 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13316 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13317 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13321 /* Terminal frame. In this case, dvpos gives the number of
13322 lines to scroll by; dvpos < 0 means scroll up. */
13323 int first_unchanged_at_end_vpos
13324 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13325 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13326 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13327 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13328 + window_internal_height (w
));
13330 /* Perform the operation on the screen. */
13333 /* Scroll last_unchanged_at_beg_row to the end of the
13334 window down dvpos lines. */
13335 set_terminal_window (end
);
13337 /* On dumb terminals delete dvpos lines at the end
13338 before inserting dvpos empty lines. */
13339 if (!FRAME_SCROLL_REGION_OK (f
))
13340 ins_del_lines (end
- dvpos
, -dvpos
);
13342 /* Insert dvpos empty lines in front of
13343 last_unchanged_at_beg_row. */
13344 ins_del_lines (from
, dvpos
);
13346 else if (dvpos
< 0)
13348 /* Scroll up last_unchanged_at_beg_vpos to the end of
13349 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13350 set_terminal_window (end
);
13352 /* Delete dvpos lines in front of
13353 last_unchanged_at_beg_vpos. ins_del_lines will set
13354 the cursor to the given vpos and emit |dvpos| delete
13356 ins_del_lines (from
+ dvpos
, dvpos
);
13358 /* On a dumb terminal insert dvpos empty lines at the
13360 if (!FRAME_SCROLL_REGION_OK (f
))
13361 ins_del_lines (end
+ dvpos
, -dvpos
);
13364 set_terminal_window (0);
13370 /* Shift reused rows of the current matrix to the right position.
13371 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13373 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13374 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13377 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13378 bottom_vpos
, dvpos
);
13379 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13382 else if (dvpos
> 0)
13384 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13385 bottom_vpos
, dvpos
);
13386 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13387 first_unchanged_at_end_vpos
+ dvpos
, 0);
13390 /* For frame-based redisplay, make sure that current frame and window
13391 matrix are in sync with respect to glyph memory. */
13392 if (!FRAME_WINDOW_P (f
))
13393 sync_frame_with_window_matrix_rows (w
);
13395 /* Adjust buffer positions in reused rows. */
13397 increment_matrix_positions (current_matrix
,
13398 first_unchanged_at_end_vpos
+ dvpos
,
13399 bottom_vpos
, delta
, delta_bytes
);
13401 /* Adjust Y positions. */
13403 shift_glyph_matrix (w
, current_matrix
,
13404 first_unchanged_at_end_vpos
+ dvpos
,
13407 if (first_unchanged_at_end_row
)
13408 first_unchanged_at_end_row
+= dvpos
;
13410 /* If scrolling up, there may be some lines to display at the end of
13412 last_text_row_at_end
= NULL
;
13415 /* Scrolling up can leave for example a partially visible line
13416 at the end of the window to be redisplayed. */
13417 /* Set last_row to the glyph row in the current matrix where the
13418 window end line is found. It has been moved up or down in
13419 the matrix by dvpos. */
13420 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13421 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13423 /* If last_row is the window end line, it should display text. */
13424 xassert (last_row
->displays_text_p
);
13426 /* If window end line was partially visible before, begin
13427 displaying at that line. Otherwise begin displaying with the
13428 line following it. */
13429 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13431 init_to_row_start (&it
, w
, last_row
);
13432 it
.vpos
= last_vpos
;
13433 it
.current_y
= last_row
->y
;
13437 init_to_row_end (&it
, w
, last_row
);
13438 it
.vpos
= 1 + last_vpos
;
13439 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13443 /* We may start in a continuation line. If so, we have to
13444 get the right continuation_lines_width and current_x. */
13445 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13446 it
.hpos
= it
.current_x
= 0;
13448 /* Display the rest of the lines at the window end. */
13449 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13450 while (it
.current_y
< it
.last_visible_y
13451 && !fonts_changed_p
)
13453 /* Is it always sure that the display agrees with lines in
13454 the current matrix? I don't think so, so we mark rows
13455 displayed invalid in the current matrix by setting their
13456 enabled_p flag to zero. */
13457 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13458 if (display_line (&it
))
13459 last_text_row_at_end
= it
.glyph_row
- 1;
13463 /* Update window_end_pos and window_end_vpos. */
13464 if (first_unchanged_at_end_row
13465 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13466 && !last_text_row_at_end
)
13468 /* Window end line if one of the preserved rows from the current
13469 matrix. Set row to the last row displaying text in current
13470 matrix starting at first_unchanged_at_end_row, after
13472 xassert (first_unchanged_at_end_row
->displays_text_p
);
13473 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13474 first_unchanged_at_end_row
);
13475 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13477 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13478 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13480 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13481 xassert (w
->window_end_bytepos
>= 0);
13482 IF_DEBUG (debug_method_add (w
, "A"));
13484 else if (last_text_row_at_end
)
13487 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13488 w
->window_end_bytepos
13489 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13491 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13492 xassert (w
->window_end_bytepos
>= 0);
13493 IF_DEBUG (debug_method_add (w
, "B"));
13495 else if (last_text_row
)
13497 /* We have displayed either to the end of the window or at the
13498 end of the window, i.e. the last row with text is to be found
13499 in the desired matrix. */
13501 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13502 w
->window_end_bytepos
13503 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13505 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13506 xassert (w
->window_end_bytepos
>= 0);
13508 else if (first_unchanged_at_end_row
== NULL
13509 && last_text_row
== NULL
13510 && last_text_row_at_end
== NULL
)
13512 /* Displayed to end of window, but no line containing text was
13513 displayed. Lines were deleted at the end of the window. */
13514 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13515 int vpos
= XFASTINT (w
->window_end_vpos
);
13516 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13517 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13520 row
== NULL
&& vpos
>= first_vpos
;
13521 --vpos
, --current_row
, --desired_row
)
13523 if (desired_row
->enabled_p
)
13525 if (desired_row
->displays_text_p
)
13528 else if (current_row
->displays_text_p
)
13532 xassert (row
!= NULL
);
13533 w
->window_end_vpos
= make_number (vpos
+ 1);
13534 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13535 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13536 xassert (w
->window_end_bytepos
>= 0);
13537 IF_DEBUG (debug_method_add (w
, "C"));
13542 #if 0 /* This leads to problems, for instance when the cursor is
13543 at ZV, and the cursor line displays no text. */
13544 /* Disable rows below what's displayed in the window. This makes
13545 debugging easier. */
13546 enable_glyph_matrix_rows (current_matrix
,
13547 XFASTINT (w
->window_end_vpos
) + 1,
13551 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13552 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13554 /* Record that display has not been completed. */
13555 w
->window_end_valid
= Qnil
;
13556 w
->desired_matrix
->no_scrolling_p
= 1;
13564 /***********************************************************************
13565 More debugging support
13566 ***********************************************************************/
13570 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13571 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13572 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13575 /* Dump the contents of glyph matrix MATRIX on stderr.
13577 GLYPHS 0 means don't show glyph contents.
13578 GLYPHS 1 means show glyphs in short form
13579 GLYPHS > 1 means show glyphs in long form. */
13582 dump_glyph_matrix (matrix
, glyphs
)
13583 struct glyph_matrix
*matrix
;
13587 for (i
= 0; i
< matrix
->nrows
; ++i
)
13588 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13592 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13593 the glyph row and area where the glyph comes from. */
13596 dump_glyph (row
, glyph
, area
)
13597 struct glyph_row
*row
;
13598 struct glyph
*glyph
;
13601 if (glyph
->type
== CHAR_GLYPH
)
13604 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13605 glyph
- row
->glyphs
[TEXT_AREA
],
13608 (BUFFERP (glyph
->object
)
13610 : (STRINGP (glyph
->object
)
13613 glyph
->pixel_width
,
13615 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13619 glyph
->left_box_line_p
,
13620 glyph
->right_box_line_p
);
13622 else if (glyph
->type
== STRETCH_GLYPH
)
13625 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13626 glyph
- row
->glyphs
[TEXT_AREA
],
13629 (BUFFERP (glyph
->object
)
13631 : (STRINGP (glyph
->object
)
13634 glyph
->pixel_width
,
13638 glyph
->left_box_line_p
,
13639 glyph
->right_box_line_p
);
13641 else if (glyph
->type
== IMAGE_GLYPH
)
13644 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13645 glyph
- row
->glyphs
[TEXT_AREA
],
13648 (BUFFERP (glyph
->object
)
13650 : (STRINGP (glyph
->object
)
13653 glyph
->pixel_width
,
13657 glyph
->left_box_line_p
,
13658 glyph
->right_box_line_p
);
13663 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13664 GLYPHS 0 means don't show glyph contents.
13665 GLYPHS 1 means show glyphs in short form
13666 GLYPHS > 1 means show glyphs in long form. */
13669 dump_glyph_row (row
, vpos
, glyphs
)
13670 struct glyph_row
*row
;
13675 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13676 fprintf (stderr
, "=======================================================================\n");
13678 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13679 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13681 MATRIX_ROW_START_CHARPOS (row
),
13682 MATRIX_ROW_END_CHARPOS (row
),
13683 row
->used
[TEXT_AREA
],
13684 row
->contains_overlapping_glyphs_p
,
13686 row
->truncated_on_left_p
,
13687 row
->truncated_on_right_p
,
13688 row
->overlay_arrow_p
,
13690 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13691 row
->displays_text_p
,
13694 row
->ends_in_middle_of_char_p
,
13695 row
->starts_in_middle_of_char_p
,
13701 row
->visible_height
,
13704 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13705 row
->end
.overlay_string_index
,
13706 row
->continuation_lines_width
);
13707 fprintf (stderr
, "%9d %5d\n",
13708 CHARPOS (row
->start
.string_pos
),
13709 CHARPOS (row
->end
.string_pos
));
13710 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13711 row
->end
.dpvec_index
);
13718 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13720 struct glyph
*glyph
= row
->glyphs
[area
];
13721 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13723 /* Glyph for a line end in text. */
13724 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13727 if (glyph
< glyph_end
)
13728 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13730 for (; glyph
< glyph_end
; ++glyph
)
13731 dump_glyph (row
, glyph
, area
);
13734 else if (glyphs
== 1)
13738 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13740 char *s
= (char *) alloca (row
->used
[area
] + 1);
13743 for (i
= 0; i
< row
->used
[area
]; ++i
)
13745 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13746 if (glyph
->type
== CHAR_GLYPH
13747 && glyph
->u
.ch
< 0x80
13748 && glyph
->u
.ch
>= ' ')
13749 s
[i
] = glyph
->u
.ch
;
13755 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13761 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13762 Sdump_glyph_matrix
, 0, 1, "p",
13763 doc
: /* Dump the current matrix of the selected window to stderr.
13764 Shows contents of glyph row structures. With non-nil
13765 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13766 glyphs in short form, otherwise show glyphs in long form. */)
13768 Lisp_Object glyphs
;
13770 struct window
*w
= XWINDOW (selected_window
);
13771 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13773 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13774 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13775 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13776 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13777 fprintf (stderr
, "=============================================\n");
13778 dump_glyph_matrix (w
->current_matrix
,
13779 NILP (glyphs
) ? 0 : XINT (glyphs
));
13784 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13785 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13788 struct frame
*f
= XFRAME (selected_frame
);
13789 dump_glyph_matrix (f
->current_matrix
, 1);
13794 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13795 doc
: /* Dump glyph row ROW to stderr.
13796 GLYPH 0 means don't dump glyphs.
13797 GLYPH 1 means dump glyphs in short form.
13798 GLYPH > 1 or omitted means dump glyphs in long form. */)
13800 Lisp_Object row
, glyphs
;
13802 struct glyph_matrix
*matrix
;
13805 CHECK_NUMBER (row
);
13806 matrix
= XWINDOW (selected_window
)->current_matrix
;
13808 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13809 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13811 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13816 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13817 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13818 GLYPH 0 means don't dump glyphs.
13819 GLYPH 1 means dump glyphs in short form.
13820 GLYPH > 1 or omitted means dump glyphs in long form. */)
13822 Lisp_Object row
, glyphs
;
13824 struct frame
*sf
= SELECTED_FRAME ();
13825 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13828 CHECK_NUMBER (row
);
13830 if (vpos
>= 0 && vpos
< m
->nrows
)
13831 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13832 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13837 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13838 doc
: /* Toggle tracing of redisplay.
13839 With ARG, turn tracing on if and only if ARG is positive. */)
13844 trace_redisplay_p
= !trace_redisplay_p
;
13847 arg
= Fprefix_numeric_value (arg
);
13848 trace_redisplay_p
= XINT (arg
) > 0;
13855 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13856 doc
: /* Like `format', but print result to stderr.
13857 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13862 Lisp_Object s
= Fformat (nargs
, args
);
13863 fprintf (stderr
, "%s", SDATA (s
));
13867 #endif /* GLYPH_DEBUG */
13871 /***********************************************************************
13872 Building Desired Matrix Rows
13873 ***********************************************************************/
13875 /* Return a temporary glyph row holding the glyphs of an overlay
13876 arrow. Only used for non-window-redisplay windows. */
13878 static struct glyph_row
*
13879 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
13881 Lisp_Object overlay_arrow_string
;
13883 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13884 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13885 struct buffer
*old
= current_buffer
;
13886 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
13887 int arrow_len
= SCHARS (overlay_arrow_string
);
13888 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13889 const unsigned char *p
;
13892 int n_glyphs_before
;
13894 set_buffer_temp (buffer
);
13895 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13896 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13897 SET_TEXT_POS (it
.position
, 0, 0);
13899 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13901 while (p
< arrow_end
)
13903 Lisp_Object face
, ilisp
;
13905 /* Get the next character. */
13907 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13909 it
.c
= *p
, it
.len
= 1;
13912 /* Get its face. */
13913 ilisp
= make_number (p
- arrow_string
);
13914 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
13915 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13917 /* Compute its width, get its glyphs. */
13918 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13919 SET_TEXT_POS (it
.position
, -1, -1);
13920 PRODUCE_GLYPHS (&it
);
13922 /* If this character doesn't fit any more in the line, we have
13923 to remove some glyphs. */
13924 if (it
.current_x
> it
.last_visible_x
)
13926 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13931 set_buffer_temp (old
);
13932 return it
.glyph_row
;
13936 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
13937 glyphs are only inserted for terminal frames since we can't really
13938 win with truncation glyphs when partially visible glyphs are
13939 involved. Which glyphs to insert is determined by
13940 produce_special_glyphs. */
13943 insert_left_trunc_glyphs (it
)
13946 struct it truncate_it
;
13947 struct glyph
*from
, *end
, *to
, *toend
;
13949 xassert (!FRAME_WINDOW_P (it
->f
));
13951 /* Get the truncation glyphs. */
13953 truncate_it
.current_x
= 0;
13954 truncate_it
.face_id
= DEFAULT_FACE_ID
;
13955 truncate_it
.glyph_row
= &scratch_glyph_row
;
13956 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
13957 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
13958 truncate_it
.object
= make_number (0);
13959 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
13961 /* Overwrite glyphs from IT with truncation glyphs. */
13962 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13963 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
13964 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
13965 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
13970 /* There may be padding glyphs left over. Overwrite them too. */
13971 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
13973 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13979 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
13983 /* Compute the pixel height and width of IT->glyph_row.
13985 Most of the time, ascent and height of a display line will be equal
13986 to the max_ascent and max_height values of the display iterator
13987 structure. This is not the case if
13989 1. We hit ZV without displaying anything. In this case, max_ascent
13990 and max_height will be zero.
13992 2. We have some glyphs that don't contribute to the line height.
13993 (The glyph row flag contributes_to_line_height_p is for future
13994 pixmap extensions).
13996 The first case is easily covered by using default values because in
13997 these cases, the line height does not really matter, except that it
13998 must not be zero. */
14001 compute_line_metrics (it
)
14004 struct glyph_row
*row
= it
->glyph_row
;
14007 if (FRAME_WINDOW_P (it
->f
))
14009 int i
, min_y
, max_y
;
14011 /* The line may consist of one space only, that was added to
14012 place the cursor on it. If so, the row's height hasn't been
14014 if (row
->height
== 0)
14016 if (it
->max_ascent
+ it
->max_descent
== 0)
14017 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14018 row
->ascent
= it
->max_ascent
;
14019 row
->height
= it
->max_ascent
+ it
->max_descent
;
14020 row
->phys_ascent
= it
->max_phys_ascent
;
14021 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14024 /* Compute the width of this line. */
14025 row
->pixel_width
= row
->x
;
14026 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14027 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14029 xassert (row
->pixel_width
>= 0);
14030 xassert (row
->ascent
>= 0 && row
->height
> 0);
14032 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14033 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14035 /* If first line's physical ascent is larger than its logical
14036 ascent, use the physical ascent, and make the row taller.
14037 This makes accented characters fully visible. */
14038 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14039 && row
->phys_ascent
> row
->ascent
)
14041 row
->height
+= row
->phys_ascent
- row
->ascent
;
14042 row
->ascent
= row
->phys_ascent
;
14045 /* Compute how much of the line is visible. */
14046 row
->visible_height
= row
->height
;
14048 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14049 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14051 if (row
->y
< min_y
)
14052 row
->visible_height
-= min_y
- row
->y
;
14053 if (row
->y
+ row
->height
> max_y
)
14054 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14058 row
->pixel_width
= row
->used
[TEXT_AREA
];
14059 if (row
->continued_p
)
14060 row
->pixel_width
-= it
->continuation_pixel_width
;
14061 else if (row
->truncated_on_right_p
)
14062 row
->pixel_width
-= it
->truncation_pixel_width
;
14063 row
->ascent
= row
->phys_ascent
= 0;
14064 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14067 /* Compute a hash code for this row. */
14069 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14070 for (i
= 0; i
< row
->used
[area
]; ++i
)
14071 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14072 + row
->glyphs
[area
][i
].u
.val
14073 + row
->glyphs
[area
][i
].face_id
14074 + row
->glyphs
[area
][i
].padding_p
14075 + (row
->glyphs
[area
][i
].type
<< 2));
14077 it
->max_ascent
= it
->max_descent
= 0;
14078 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14082 /* Append one space to the glyph row of iterator IT if doing a
14083 window-based redisplay. DEFAULT_FACE_P non-zero means let the
14084 space have the default face, otherwise let it have the same face as
14085 IT->face_id. Value is non-zero if a space was added.
14087 This function is called to make sure that there is always one glyph
14088 at the end of a glyph row that the cursor can be set on under
14089 window-systems. (If there weren't such a glyph we would not know
14090 how wide and tall a box cursor should be displayed).
14092 At the same time this space let's a nicely handle clearing to the
14093 end of the line if the row ends in italic text. */
14096 append_space (it
, default_face_p
)
14098 int default_face_p
;
14100 if (FRAME_WINDOW_P (it
->f
))
14102 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14104 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14105 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14107 /* Save some values that must not be changed.
14108 Must save IT->c and IT->len because otherwise
14109 ITERATOR_AT_END_P wouldn't work anymore after
14110 append_space has been called. */
14111 enum display_element_type saved_what
= it
->what
;
14112 int saved_c
= it
->c
, saved_len
= it
->len
;
14113 int saved_x
= it
->current_x
;
14114 int saved_face_id
= it
->face_id
;
14115 struct text_pos saved_pos
;
14116 Lisp_Object saved_object
;
14119 saved_object
= it
->object
;
14120 saved_pos
= it
->position
;
14122 it
->what
= IT_CHARACTER
;
14123 bzero (&it
->position
, sizeof it
->position
);
14124 it
->object
= make_number (0);
14128 if (default_face_p
)
14129 it
->face_id
= DEFAULT_FACE_ID
;
14130 else if (it
->face_before_selective_p
)
14131 it
->face_id
= it
->saved_face_id
;
14132 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14133 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14135 PRODUCE_GLYPHS (it
);
14137 it
->current_x
= saved_x
;
14138 it
->object
= saved_object
;
14139 it
->position
= saved_pos
;
14140 it
->what
= saved_what
;
14141 it
->face_id
= saved_face_id
;
14142 it
->len
= saved_len
;
14152 /* Extend the face of the last glyph in the text area of IT->glyph_row
14153 to the end of the display line. Called from display_line.
14154 If the glyph row is empty, add a space glyph to it so that we
14155 know the face to draw. Set the glyph row flag fill_line_p. */
14158 extend_face_to_end_of_line (it
)
14162 struct frame
*f
= it
->f
;
14164 /* If line is already filled, do nothing. */
14165 if (it
->current_x
>= it
->last_visible_x
)
14168 /* Face extension extends the background and box of IT->face_id
14169 to the end of the line. If the background equals the background
14170 of the frame, we don't have to do anything. */
14171 if (it
->face_before_selective_p
)
14172 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14174 face
= FACE_FROM_ID (f
, it
->face_id
);
14176 if (FRAME_WINDOW_P (f
)
14177 && face
->box
== FACE_NO_BOX
14178 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14182 /* Set the glyph row flag indicating that the face of the last glyph
14183 in the text area has to be drawn to the end of the text area. */
14184 it
->glyph_row
->fill_line_p
= 1;
14186 /* If current character of IT is not ASCII, make sure we have the
14187 ASCII face. This will be automatically undone the next time
14188 get_next_display_element returns a multibyte character. Note
14189 that the character will always be single byte in unibyte text. */
14190 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14192 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14195 if (FRAME_WINDOW_P (f
))
14197 /* If the row is empty, add a space with the current face of IT,
14198 so that we know which face to draw. */
14199 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14201 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14202 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14203 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14208 /* Save some values that must not be changed. */
14209 int saved_x
= it
->current_x
;
14210 struct text_pos saved_pos
;
14211 Lisp_Object saved_object
;
14212 enum display_element_type saved_what
= it
->what
;
14213 int saved_face_id
= it
->face_id
;
14215 saved_object
= it
->object
;
14216 saved_pos
= it
->position
;
14218 it
->what
= IT_CHARACTER
;
14219 bzero (&it
->position
, sizeof it
->position
);
14220 it
->object
= make_number (0);
14223 it
->face_id
= face
->id
;
14225 PRODUCE_GLYPHS (it
);
14227 while (it
->current_x
<= it
->last_visible_x
)
14228 PRODUCE_GLYPHS (it
);
14230 /* Don't count these blanks really. It would let us insert a left
14231 truncation glyph below and make us set the cursor on them, maybe. */
14232 it
->current_x
= saved_x
;
14233 it
->object
= saved_object
;
14234 it
->position
= saved_pos
;
14235 it
->what
= saved_what
;
14236 it
->face_id
= saved_face_id
;
14241 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14242 trailing whitespace. */
14245 trailing_whitespace_p (charpos
)
14248 int bytepos
= CHAR_TO_BYTE (charpos
);
14251 while (bytepos
< ZV_BYTE
14252 && (c
= FETCH_CHAR (bytepos
),
14253 c
== ' ' || c
== '\t'))
14256 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14258 if (bytepos
!= PT_BYTE
)
14265 /* Highlight trailing whitespace, if any, in ROW. */
14268 highlight_trailing_whitespace (f
, row
)
14270 struct glyph_row
*row
;
14272 int used
= row
->used
[TEXT_AREA
];
14276 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14277 struct glyph
*glyph
= start
+ used
- 1;
14279 /* Skip over glyphs inserted to display the cursor at the
14280 end of a line, for extending the face of the last glyph
14281 to the end of the line on terminals, and for truncation
14282 and continuation glyphs. */
14283 while (glyph
>= start
14284 && glyph
->type
== CHAR_GLYPH
14285 && INTEGERP (glyph
->object
))
14288 /* If last glyph is a space or stretch, and it's trailing
14289 whitespace, set the face of all trailing whitespace glyphs in
14290 IT->glyph_row to `trailing-whitespace'. */
14292 && BUFFERP (glyph
->object
)
14293 && (glyph
->type
== STRETCH_GLYPH
14294 || (glyph
->type
== CHAR_GLYPH
14295 && glyph
->u
.ch
== ' '))
14296 && trailing_whitespace_p (glyph
->charpos
))
14298 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14300 while (glyph
>= start
14301 && BUFFERP (glyph
->object
)
14302 && (glyph
->type
== STRETCH_GLYPH
14303 || (glyph
->type
== CHAR_GLYPH
14304 && glyph
->u
.ch
== ' ')))
14305 (glyph
--)->face_id
= face_id
;
14311 /* Value is non-zero if glyph row ROW in window W should be
14312 used to hold the cursor. */
14315 cursor_row_p (w
, row
)
14317 struct glyph_row
*row
;
14319 int cursor_row_p
= 1;
14321 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14323 /* If the row ends with a newline from a string, we don't want
14324 the cursor there (if the row is continued it doesn't end in a
14326 if (CHARPOS (row
->end
.string_pos
) >= 0
14327 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14328 cursor_row_p
= row
->continued_p
;
14330 /* If the row ends at ZV, display the cursor at the end of that
14331 row instead of at the start of the row below. */
14332 else if (row
->ends_at_zv_p
)
14338 return cursor_row_p
;
14342 /* Construct the glyph row IT->glyph_row in the desired matrix of
14343 IT->w from text at the current position of IT. See dispextern.h
14344 for an overview of struct it. Value is non-zero if
14345 IT->glyph_row displays text, as opposed to a line displaying ZV
14352 struct glyph_row
*row
= it
->glyph_row
;
14353 int overlay_arrow_bitmap
;
14354 Lisp_Object overlay_arrow_string
;
14356 /* We always start displaying at hpos zero even if hscrolled. */
14357 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14359 /* We must not display in a row that's not a text row. */
14360 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14361 < it
->w
->desired_matrix
->nrows
);
14363 /* Is IT->w showing the region? */
14364 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14366 /* Clear the result glyph row and enable it. */
14367 prepare_desired_row (row
);
14369 row
->y
= it
->current_y
;
14370 row
->start
= it
->start
;
14371 row
->continuation_lines_width
= it
->continuation_lines_width
;
14372 row
->displays_text_p
= 1;
14373 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14374 it
->starts_in_middle_of_char_p
= 0;
14376 /* Arrange the overlays nicely for our purposes. Usually, we call
14377 display_line on only one line at a time, in which case this
14378 can't really hurt too much, or we call it on lines which appear
14379 one after another in the buffer, in which case all calls to
14380 recenter_overlay_lists but the first will be pretty cheap. */
14381 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14383 /* Move over display elements that are not visible because we are
14384 hscrolled. This may stop at an x-position < IT->first_visible_x
14385 if the first glyph is partially visible or if we hit a line end. */
14386 if (it
->current_x
< it
->first_visible_x
)
14387 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14388 MOVE_TO_POS
| MOVE_TO_X
);
14390 /* Get the initial row height. This is either the height of the
14391 text hscrolled, if there is any, or zero. */
14392 row
->ascent
= it
->max_ascent
;
14393 row
->height
= it
->max_ascent
+ it
->max_descent
;
14394 row
->phys_ascent
= it
->max_phys_ascent
;
14395 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14397 /* Loop generating characters. The loop is left with IT on the next
14398 character to display. */
14401 int n_glyphs_before
, hpos_before
, x_before
;
14403 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14405 /* Retrieve the next thing to display. Value is zero if end of
14407 if (!get_next_display_element (it
))
14409 /* Maybe add a space at the end of this line that is used to
14410 display the cursor there under X. Set the charpos of the
14411 first glyph of blank lines not corresponding to any text
14413 #ifdef HAVE_WINDOW_SYSTEM
14414 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14415 row
->exact_window_width_line_p
= 1;
14417 #endif /* HAVE_WINDOW_SYSTEM */
14418 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14419 || row
->used
[TEXT_AREA
] == 0)
14421 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14422 row
->displays_text_p
= 0;
14424 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14425 && (!MINI_WINDOW_P (it
->w
)
14426 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14427 row
->indicate_empty_line_p
= 1;
14430 it
->continuation_lines_width
= 0;
14431 row
->ends_at_zv_p
= 1;
14435 /* Now, get the metrics of what we want to display. This also
14436 generates glyphs in `row' (which is IT->glyph_row). */
14437 n_glyphs_before
= row
->used
[TEXT_AREA
];
14440 /* Remember the line height so far in case the next element doesn't
14441 fit on the line. */
14442 if (!it
->truncate_lines_p
)
14444 ascent
= it
->max_ascent
;
14445 descent
= it
->max_descent
;
14446 phys_ascent
= it
->max_phys_ascent
;
14447 phys_descent
= it
->max_phys_descent
;
14450 PRODUCE_GLYPHS (it
);
14452 /* If this display element was in marginal areas, continue with
14454 if (it
->area
!= TEXT_AREA
)
14456 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14457 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14458 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14459 row
->phys_height
= max (row
->phys_height
,
14460 it
->max_phys_ascent
+ it
->max_phys_descent
);
14461 set_iterator_to_next (it
, 1);
14465 /* Does the display element fit on the line? If we truncate
14466 lines, we should draw past the right edge of the window. If
14467 we don't truncate, we want to stop so that we can display the
14468 continuation glyph before the right margin. If lines are
14469 continued, there are two possible strategies for characters
14470 resulting in more than 1 glyph (e.g. tabs): Display as many
14471 glyphs as possible in this line and leave the rest for the
14472 continuation line, or display the whole element in the next
14473 line. Original redisplay did the former, so we do it also. */
14474 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14475 hpos_before
= it
->hpos
;
14478 if (/* Not a newline. */
14480 /* Glyphs produced fit entirely in the line. */
14481 && it
->current_x
< it
->last_visible_x
)
14483 it
->hpos
+= nglyphs
;
14484 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14485 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14486 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14487 row
->phys_height
= max (row
->phys_height
,
14488 it
->max_phys_ascent
+ it
->max_phys_descent
);
14489 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14490 row
->x
= x
- it
->first_visible_x
;
14495 struct glyph
*glyph
;
14497 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14499 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14500 new_x
= x
+ glyph
->pixel_width
;
14502 if (/* Lines are continued. */
14503 !it
->truncate_lines_p
14504 && (/* Glyph doesn't fit on the line. */
14505 new_x
> it
->last_visible_x
14506 /* Or it fits exactly on a window system frame. */
14507 || (new_x
== it
->last_visible_x
14508 && FRAME_WINDOW_P (it
->f
))))
14510 /* End of a continued line. */
14513 || (new_x
== it
->last_visible_x
14514 && FRAME_WINDOW_P (it
->f
)))
14516 /* Current glyph is the only one on the line or
14517 fits exactly on the line. We must continue
14518 the line because we can't draw the cursor
14519 after the glyph. */
14520 row
->continued_p
= 1;
14521 it
->current_x
= new_x
;
14522 it
->continuation_lines_width
+= new_x
;
14524 if (i
== nglyphs
- 1)
14526 set_iterator_to_next (it
, 1);
14527 #ifdef HAVE_WINDOW_SYSTEM
14528 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14530 if (!get_next_display_element (it
))
14532 row
->exact_window_width_line_p
= 1;
14533 it
->continuation_lines_width
= 0;
14534 row
->continued_p
= 0;
14535 row
->ends_at_zv_p
= 1;
14537 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14539 row
->continued_p
= 0;
14540 row
->exact_window_width_line_p
= 1;
14543 #endif /* HAVE_WINDOW_SYSTEM */
14546 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14547 && !FRAME_WINDOW_P (it
->f
))
14549 /* A padding glyph that doesn't fit on this line.
14550 This means the whole character doesn't fit
14552 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14554 /* Fill the rest of the row with continuation
14555 glyphs like in 20.x. */
14556 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14557 < row
->glyphs
[1 + TEXT_AREA
])
14558 produce_special_glyphs (it
, IT_CONTINUATION
);
14560 row
->continued_p
= 1;
14561 it
->current_x
= x_before
;
14562 it
->continuation_lines_width
+= x_before
;
14564 /* Restore the height to what it was before the
14565 element not fitting on the line. */
14566 it
->max_ascent
= ascent
;
14567 it
->max_descent
= descent
;
14568 it
->max_phys_ascent
= phys_ascent
;
14569 it
->max_phys_descent
= phys_descent
;
14571 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14573 /* A TAB that extends past the right edge of the
14574 window. This produces a single glyph on
14575 window system frames. We leave the glyph in
14576 this row and let it fill the row, but don't
14577 consume the TAB. */
14578 it
->continuation_lines_width
+= it
->last_visible_x
;
14579 row
->ends_in_middle_of_char_p
= 1;
14580 row
->continued_p
= 1;
14581 glyph
->pixel_width
= it
->last_visible_x
- x
;
14582 it
->starts_in_middle_of_char_p
= 1;
14586 /* Something other than a TAB that draws past
14587 the right edge of the window. Restore
14588 positions to values before the element. */
14589 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14591 /* Display continuation glyphs. */
14592 if (!FRAME_WINDOW_P (it
->f
))
14593 produce_special_glyphs (it
, IT_CONTINUATION
);
14594 row
->continued_p
= 1;
14596 it
->continuation_lines_width
+= x
;
14598 if (nglyphs
> 1 && i
> 0)
14600 row
->ends_in_middle_of_char_p
= 1;
14601 it
->starts_in_middle_of_char_p
= 1;
14604 /* Restore the height to what it was before the
14605 element not fitting on the line. */
14606 it
->max_ascent
= ascent
;
14607 it
->max_descent
= descent
;
14608 it
->max_phys_ascent
= phys_ascent
;
14609 it
->max_phys_descent
= phys_descent
;
14614 else if (new_x
> it
->first_visible_x
)
14616 /* Increment number of glyphs actually displayed. */
14619 if (x
< it
->first_visible_x
)
14620 /* Glyph is partially visible, i.e. row starts at
14621 negative X position. */
14622 row
->x
= x
- it
->first_visible_x
;
14626 /* Glyph is completely off the left margin of the
14627 window. This should not happen because of the
14628 move_it_in_display_line at the start of this
14629 function, unless the text display area of the
14630 window is empty. */
14631 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14635 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14636 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14637 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14638 row
->phys_height
= max (row
->phys_height
,
14639 it
->max_phys_ascent
+ it
->max_phys_descent
);
14641 /* End of this display line if row is continued. */
14642 if (row
->continued_p
|| row
->ends_at_zv_p
)
14647 /* Is this a line end? If yes, we're also done, after making
14648 sure that a non-default face is extended up to the right
14649 margin of the window. */
14650 if (ITERATOR_AT_END_OF_LINE_P (it
))
14652 int used_before
= row
->used
[TEXT_AREA
];
14654 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14656 #ifdef HAVE_WINDOW_SYSTEM
14657 /* Add a space at the end of the line that is used to
14658 display the cursor there. */
14659 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14660 append_space (it
, 0);
14661 #endif /* HAVE_WINDOW_SYSTEM */
14663 /* Extend the face to the end of the line. */
14664 extend_face_to_end_of_line (it
);
14666 /* Make sure we have the position. */
14667 if (used_before
== 0)
14668 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14670 /* Consume the line end. This skips over invisible lines. */
14671 set_iterator_to_next (it
, 1);
14672 it
->continuation_lines_width
= 0;
14676 /* Proceed with next display element. Note that this skips
14677 over lines invisible because of selective display. */
14678 set_iterator_to_next (it
, 1);
14680 /* If we truncate lines, we are done when the last displayed
14681 glyphs reach past the right margin of the window. */
14682 if (it
->truncate_lines_p
14683 && (FRAME_WINDOW_P (it
->f
)
14684 ? (it
->current_x
>= it
->last_visible_x
)
14685 : (it
->current_x
> it
->last_visible_x
)))
14687 /* Maybe add truncation glyphs. */
14688 if (!FRAME_WINDOW_P (it
->f
))
14692 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14693 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14696 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14698 row
->used
[TEXT_AREA
] = i
;
14699 produce_special_glyphs (it
, IT_TRUNCATION
);
14702 #ifdef HAVE_WINDOW_SYSTEM
14705 /* Don't truncate if we can overflow newline into fringe. */
14706 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14708 if (!get_next_display_element (it
))
14710 #ifdef HAVE_WINDOW_SYSTEM
14711 it
->continuation_lines_width
= 0;
14712 row
->ends_at_zv_p
= 1;
14713 row
->exact_window_width_line_p
= 1;
14715 #endif /* HAVE_WINDOW_SYSTEM */
14717 if (ITERATOR_AT_END_OF_LINE_P (it
))
14719 row
->exact_window_width_line_p
= 1;
14720 goto at_end_of_line
;
14724 #endif /* HAVE_WINDOW_SYSTEM */
14726 row
->truncated_on_right_p
= 1;
14727 it
->continuation_lines_width
= 0;
14728 reseat_at_next_visible_line_start (it
, 0);
14729 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14730 it
->hpos
= hpos_before
;
14731 it
->current_x
= x_before
;
14736 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14737 at the left window margin. */
14738 if (it
->first_visible_x
14739 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14741 if (!FRAME_WINDOW_P (it
->f
))
14742 insert_left_trunc_glyphs (it
);
14743 row
->truncated_on_left_p
= 1;
14746 /* If the start of this line is the overlay arrow-position, then
14747 mark this glyph row as the one containing the overlay arrow.
14748 This is clearly a mess with variable size fonts. It would be
14749 better to let it be displayed like cursors under X. */
14750 if (! overlay_arrow_seen
14751 && (overlay_arrow_string
14752 = overlay_arrow_at_row (it
->f
, row
, &overlay_arrow_bitmap
),
14753 !NILP (overlay_arrow_string
)))
14755 /* Overlay arrow in window redisplay is a fringe bitmap. */
14756 if (!FRAME_WINDOW_P (it
->f
))
14758 struct glyph_row
*arrow_row
14759 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
14760 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14761 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14762 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14763 struct glyph
*p2
, *end
;
14765 /* Copy the arrow glyphs. */
14766 while (glyph
< arrow_end
)
14769 /* Throw away padding glyphs. */
14771 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14772 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14778 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14782 overlay_arrow_seen
= 1;
14783 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
14784 row
->overlay_arrow_p
= 1;
14787 /* Compute pixel dimensions of this line. */
14788 compute_line_metrics (it
);
14790 /* Remember the position at which this line ends. */
14791 row
->end
= it
->current
;
14793 /* Save fringe bitmaps in this row. */
14794 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
14795 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
14796 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
14797 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
14799 it
->left_user_fringe_bitmap
= 0;
14800 it
->left_user_fringe_face_id
= 0;
14801 it
->right_user_fringe_bitmap
= 0;
14802 it
->right_user_fringe_face_id
= 0;
14804 /* Maybe set the cursor. */
14805 if (it
->w
->cursor
.vpos
< 0
14806 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14807 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14808 && cursor_row_p (it
->w
, row
))
14809 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14811 /* Highlight trailing whitespace. */
14812 if (!NILP (Vshow_trailing_whitespace
))
14813 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14815 /* Prepare for the next line. This line starts horizontally at (X
14816 HPOS) = (0 0). Vertical positions are incremented. As a
14817 convenience for the caller, IT->glyph_row is set to the next
14819 it
->current_x
= it
->hpos
= 0;
14820 it
->current_y
+= row
->height
;
14823 it
->start
= it
->current
;
14824 return row
->displays_text_p
;
14829 /***********************************************************************
14831 ***********************************************************************/
14833 /* Redisplay the menu bar in the frame for window W.
14835 The menu bar of X frames that don't have X toolkit support is
14836 displayed in a special window W->frame->menu_bar_window.
14838 The menu bar of terminal frames is treated specially as far as
14839 glyph matrices are concerned. Menu bar lines are not part of
14840 windows, so the update is done directly on the frame matrix rows
14841 for the menu bar. */
14844 display_menu_bar (w
)
14847 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14852 /* Don't do all this for graphical frames. */
14854 if (!NILP (Vwindow_system
))
14857 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14862 if (FRAME_MAC_P (f
))
14866 #ifdef USE_X_TOOLKIT
14867 xassert (!FRAME_WINDOW_P (f
));
14868 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14869 it
.first_visible_x
= 0;
14870 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14871 #else /* not USE_X_TOOLKIT */
14872 if (FRAME_WINDOW_P (f
))
14874 /* Menu bar lines are displayed in the desired matrix of the
14875 dummy window menu_bar_window. */
14876 struct window
*menu_w
;
14877 xassert (WINDOWP (f
->menu_bar_window
));
14878 menu_w
= XWINDOW (f
->menu_bar_window
);
14879 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14881 it
.first_visible_x
= 0;
14882 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14886 /* This is a TTY frame, i.e. character hpos/vpos are used as
14888 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14890 it
.first_visible_x
= 0;
14891 it
.last_visible_x
= FRAME_COLS (f
);
14893 #endif /* not USE_X_TOOLKIT */
14895 if (! mode_line_inverse_video
)
14896 /* Force the menu-bar to be displayed in the default face. */
14897 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14899 /* Clear all rows of the menu bar. */
14900 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14902 struct glyph_row
*row
= it
.glyph_row
+ i
;
14903 clear_glyph_row (row
);
14904 row
->enabled_p
= 1;
14905 row
->full_width_p
= 1;
14908 /* Display all items of the menu bar. */
14909 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14910 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14912 Lisp_Object string
;
14914 /* Stop at nil string. */
14915 string
= AREF (items
, i
+ 1);
14919 /* Remember where item was displayed. */
14920 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14922 /* Display the item, pad with one space. */
14923 if (it
.current_x
< it
.last_visible_x
)
14924 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14925 SCHARS (string
) + 1, 0, 0, -1);
14928 /* Fill out the line with spaces. */
14929 if (it
.current_x
< it
.last_visible_x
)
14930 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
14932 /* Compute the total height of the lines. */
14933 compute_line_metrics (&it
);
14938 /***********************************************************************
14940 ***********************************************************************/
14942 /* Redisplay mode lines in the window tree whose root is WINDOW. If
14943 FORCE is non-zero, redisplay mode lines unconditionally.
14944 Otherwise, redisplay only mode lines that are garbaged. Value is
14945 the number of windows whose mode lines were redisplayed. */
14948 redisplay_mode_lines (window
, force
)
14949 Lisp_Object window
;
14954 while (!NILP (window
))
14956 struct window
*w
= XWINDOW (window
);
14958 if (WINDOWP (w
->hchild
))
14959 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
14960 else if (WINDOWP (w
->vchild
))
14961 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
14963 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
14964 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
14966 struct text_pos lpoint
;
14967 struct buffer
*old
= current_buffer
;
14969 /* Set the window's buffer for the mode line display. */
14970 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14971 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14973 /* Point refers normally to the selected window. For any
14974 other window, set up appropriate value. */
14975 if (!EQ (window
, selected_window
))
14977 struct text_pos pt
;
14979 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
14980 if (CHARPOS (pt
) < BEGV
)
14981 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14982 else if (CHARPOS (pt
) > (ZV
- 1))
14983 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
14985 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
14988 /* Display mode lines. */
14989 clear_glyph_matrix (w
->desired_matrix
);
14990 if (display_mode_lines (w
))
14993 w
->must_be_updated_p
= 1;
14996 /* Restore old settings. */
14997 set_buffer_internal_1 (old
);
14998 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15008 /* Display the mode and/or top line of window W. Value is the number
15009 of mode lines displayed. */
15012 display_mode_lines (w
)
15015 Lisp_Object old_selected_window
, old_selected_frame
;
15018 old_selected_frame
= selected_frame
;
15019 selected_frame
= w
->frame
;
15020 old_selected_window
= selected_window
;
15021 XSETWINDOW (selected_window
, w
);
15023 /* These will be set while the mode line specs are processed. */
15024 line_number_displayed
= 0;
15025 w
->column_number_displayed
= Qnil
;
15027 if (WINDOW_WANTS_MODELINE_P (w
))
15029 struct window
*sel_w
= XWINDOW (old_selected_window
);
15031 /* Select mode line face based on the real selected window. */
15032 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15033 current_buffer
->mode_line_format
);
15037 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15039 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15040 current_buffer
->header_line_format
);
15044 selected_frame
= old_selected_frame
;
15045 selected_window
= old_selected_window
;
15050 /* Display mode or top line of window W. FACE_ID specifies which line
15051 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15052 FORMAT is the mode line format to display. Value is the pixel
15053 height of the mode line displayed. */
15056 display_mode_line (w
, face_id
, format
)
15058 enum face_id face_id
;
15059 Lisp_Object format
;
15064 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15065 prepare_desired_row (it
.glyph_row
);
15067 if (! mode_line_inverse_video
)
15068 /* Force the mode-line to be displayed in the default face. */
15069 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15071 /* Temporarily make frame's keyboard the current kboard so that
15072 kboard-local variables in the mode_line_format will get the right
15074 push_frame_kboard (it
.f
);
15075 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15076 pop_frame_kboard ();
15078 /* Fill up with spaces. */
15079 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15081 compute_line_metrics (&it
);
15082 it
.glyph_row
->full_width_p
= 1;
15083 it
.glyph_row
->mode_line_p
= 1;
15084 it
.glyph_row
->continued_p
= 0;
15085 it
.glyph_row
->truncated_on_left_p
= 0;
15086 it
.glyph_row
->truncated_on_right_p
= 0;
15088 /* Make a 3D mode-line have a shadow at its right end. */
15089 face
= FACE_FROM_ID (it
.f
, face_id
);
15090 extend_face_to_end_of_line (&it
);
15091 if (face
->box
!= FACE_NO_BOX
)
15093 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15094 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15095 last
->right_box_line_p
= 1;
15098 return it
.glyph_row
->height
;
15101 /* Alist that caches the results of :propertize.
15102 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15103 Lisp_Object mode_line_proptrans_alist
;
15105 /* List of strings making up the mode-line. */
15106 Lisp_Object mode_line_string_list
;
15108 /* Base face property when building propertized mode line string. */
15109 static Lisp_Object mode_line_string_face
;
15110 static Lisp_Object mode_line_string_face_prop
;
15113 /* Contribute ELT to the mode line for window IT->w. How it
15114 translates into text depends on its data type.
15116 IT describes the display environment in which we display, as usual.
15118 DEPTH is the depth in recursion. It is used to prevent
15119 infinite recursion here.
15121 FIELD_WIDTH is the number of characters the display of ELT should
15122 occupy in the mode line, and PRECISION is the maximum number of
15123 characters to display from ELT's representation. See
15124 display_string for details.
15126 Returns the hpos of the end of the text generated by ELT.
15128 PROPS is a property list to add to any string we encounter.
15130 If RISKY is nonzero, remove (disregard) any properties in any string
15131 we encounter, and ignore :eval and :propertize.
15133 If the global variable `frame_title_ptr' is non-NULL, then the output
15134 is passed to `store_frame_title' instead of `display_string'. */
15137 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15140 int field_width
, precision
;
15141 Lisp_Object elt
, props
;
15144 int n
= 0, field
, prec
;
15149 elt
= build_string ("*too-deep*");
15153 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15157 /* A string: output it and check for %-constructs within it. */
15159 const unsigned char *this, *lisp_string
;
15161 if (!NILP (props
) || risky
)
15163 Lisp_Object oprops
, aelt
;
15164 oprops
= Ftext_properties_at (make_number (0), elt
);
15166 if (NILP (Fequal (props
, oprops
)) || risky
)
15168 /* If the starting string has properties,
15169 merge the specified ones onto the existing ones. */
15170 if (! NILP (oprops
) && !risky
)
15174 oprops
= Fcopy_sequence (oprops
);
15176 while (CONSP (tem
))
15178 oprops
= Fplist_put (oprops
, XCAR (tem
),
15179 XCAR (XCDR (tem
)));
15180 tem
= XCDR (XCDR (tem
));
15185 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15186 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15188 mode_line_proptrans_alist
15189 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15196 elt
= Fcopy_sequence (elt
);
15197 Fset_text_properties (make_number (0), Flength (elt
),
15199 /* Add this item to mode_line_proptrans_alist. */
15200 mode_line_proptrans_alist
15201 = Fcons (Fcons (elt
, props
),
15202 mode_line_proptrans_alist
);
15203 /* Truncate mode_line_proptrans_alist
15204 to at most 50 elements. */
15205 tem
= Fnthcdr (make_number (50),
15206 mode_line_proptrans_alist
);
15208 XSETCDR (tem
, Qnil
);
15213 this = SDATA (elt
);
15214 lisp_string
= this;
15218 prec
= precision
- n
;
15219 if (frame_title_ptr
)
15220 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15221 else if (!NILP (mode_line_string_list
))
15222 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15224 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15225 0, prec
, 0, STRING_MULTIBYTE (elt
));
15230 while ((precision
<= 0 || n
< precision
)
15232 && (frame_title_ptr
15233 || !NILP (mode_line_string_list
)
15234 || it
->current_x
< it
->last_visible_x
))
15236 const unsigned char *last
= this;
15238 /* Advance to end of string or next format specifier. */
15239 while ((c
= *this++) != '\0' && c
!= '%')
15242 if (this - 1 != last
)
15244 /* Output to end of string or up to '%'. Field width
15245 is length of string. Don't output more than
15246 PRECISION allows us. */
15249 prec
= chars_in_text (last
, this - last
);
15250 if (precision
> 0 && prec
> precision
- n
)
15251 prec
= precision
- n
;
15253 if (frame_title_ptr
)
15254 n
+= store_frame_title (last
, 0, prec
);
15255 else if (!NILP (mode_line_string_list
))
15257 int bytepos
= last
- lisp_string
;
15258 int charpos
= string_byte_to_char (elt
, bytepos
);
15259 n
+= store_mode_line_string (NULL
,
15260 Fsubstring (elt
, make_number (charpos
),
15261 make_number (charpos
+ prec
)),
15266 int bytepos
= last
- lisp_string
;
15267 int charpos
= string_byte_to_char (elt
, bytepos
);
15268 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15270 STRING_MULTIBYTE (elt
));
15273 else /* c == '%' */
15275 const unsigned char *percent_position
= this;
15277 /* Get the specified minimum width. Zero means
15280 while ((c
= *this++) >= '0' && c
<= '9')
15281 field
= field
* 10 + c
- '0';
15283 /* Don't pad beyond the total padding allowed. */
15284 if (field_width
- n
> 0 && field
> field_width
- n
)
15285 field
= field_width
- n
;
15287 /* Note that either PRECISION <= 0 or N < PRECISION. */
15288 prec
= precision
- n
;
15291 n
+= display_mode_element (it
, depth
, field
, prec
,
15292 Vglobal_mode_string
, props
,
15297 int bytepos
, charpos
;
15298 unsigned char *spec
;
15300 bytepos
= percent_position
- lisp_string
;
15301 charpos
= (STRING_MULTIBYTE (elt
)
15302 ? string_byte_to_char (elt
, bytepos
)
15306 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15308 if (frame_title_ptr
)
15309 n
+= store_frame_title (spec
, field
, prec
);
15310 else if (!NILP (mode_line_string_list
))
15312 int len
= strlen (spec
);
15313 Lisp_Object tem
= make_string (spec
, len
);
15314 props
= Ftext_properties_at (make_number (charpos
), elt
);
15315 /* Should only keep face property in props */
15316 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15320 int nglyphs_before
, nwritten
;
15322 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15323 nwritten
= display_string (spec
, Qnil
, elt
,
15328 /* Assign to the glyphs written above the
15329 string where the `%x' came from, position
15333 struct glyph
*glyph
15334 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15338 for (i
= 0; i
< nwritten
; ++i
)
15340 glyph
[i
].object
= elt
;
15341 glyph
[i
].charpos
= charpos
;
15356 /* A symbol: process the value of the symbol recursively
15357 as if it appeared here directly. Avoid error if symbol void.
15358 Special case: if value of symbol is a string, output the string
15361 register Lisp_Object tem
;
15363 /* If the variable is not marked as risky to set
15364 then its contents are risky to use. */
15365 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15368 tem
= Fboundp (elt
);
15371 tem
= Fsymbol_value (elt
);
15372 /* If value is a string, output that string literally:
15373 don't check for % within it. */
15377 if (!EQ (tem
, elt
))
15379 /* Give up right away for nil or t. */
15389 register Lisp_Object car
, tem
;
15391 /* A cons cell: five distinct cases.
15392 If first element is :eval or :propertize, do something special.
15393 If first element is a string or a cons, process all the elements
15394 and effectively concatenate them.
15395 If first element is a negative number, truncate displaying cdr to
15396 at most that many characters. If positive, pad (with spaces)
15397 to at least that many characters.
15398 If first element is a symbol, process the cadr or caddr recursively
15399 according to whether the symbol's value is non-nil or nil. */
15401 if (EQ (car
, QCeval
))
15403 /* An element of the form (:eval FORM) means evaluate FORM
15404 and use the result as mode line elements. */
15409 if (CONSP (XCDR (elt
)))
15412 spec
= safe_eval (XCAR (XCDR (elt
)));
15413 n
+= display_mode_element (it
, depth
, field_width
- n
,
15414 precision
- n
, spec
, props
,
15418 else if (EQ (car
, QCpropertize
))
15420 /* An element of the form (:propertize ELT PROPS...)
15421 means display ELT but applying properties PROPS. */
15426 if (CONSP (XCDR (elt
)))
15427 n
+= display_mode_element (it
, depth
, field_width
- n
,
15428 precision
- n
, XCAR (XCDR (elt
)),
15429 XCDR (XCDR (elt
)), risky
);
15431 else if (SYMBOLP (car
))
15433 tem
= Fboundp (car
);
15437 /* elt is now the cdr, and we know it is a cons cell.
15438 Use its car if CAR has a non-nil value. */
15441 tem
= Fsymbol_value (car
);
15448 /* Symbol's value is nil (or symbol is unbound)
15449 Get the cddr of the original list
15450 and if possible find the caddr and use that. */
15454 else if (!CONSP (elt
))
15459 else if (INTEGERP (car
))
15461 register int lim
= XINT (car
);
15465 /* Negative int means reduce maximum width. */
15466 if (precision
<= 0)
15469 precision
= min (precision
, -lim
);
15473 /* Padding specified. Don't let it be more than
15474 current maximum. */
15476 lim
= min (precision
, lim
);
15478 /* If that's more padding than already wanted, queue it.
15479 But don't reduce padding already specified even if
15480 that is beyond the current truncation point. */
15481 field_width
= max (lim
, field_width
);
15485 else if (STRINGP (car
) || CONSP (car
))
15487 register int limit
= 50;
15488 /* Limit is to protect against circular lists. */
15491 && (precision
<= 0 || n
< precision
))
15493 n
+= display_mode_element (it
, depth
, field_width
- n
,
15494 precision
- n
, XCAR (elt
),
15504 elt
= build_string ("*invalid*");
15508 /* Pad to FIELD_WIDTH. */
15509 if (field_width
> 0 && n
< field_width
)
15511 if (frame_title_ptr
)
15512 n
+= store_frame_title ("", field_width
- n
, 0);
15513 else if (!NILP (mode_line_string_list
))
15514 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15516 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15523 /* Store a mode-line string element in mode_line_string_list.
15525 If STRING is non-null, display that C string. Otherwise, the Lisp
15526 string LISP_STRING is displayed.
15528 FIELD_WIDTH is the minimum number of output glyphs to produce.
15529 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15530 with spaces. FIELD_WIDTH <= 0 means don't pad.
15532 PRECISION is the maximum number of characters to output from
15533 STRING. PRECISION <= 0 means don't truncate the string.
15535 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15536 properties to the string.
15538 PROPS are the properties to add to the string.
15539 The mode_line_string_face face property is always added to the string.
15542 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15544 Lisp_Object lisp_string
;
15553 if (string
!= NULL
)
15555 len
= strlen (string
);
15556 if (precision
> 0 && len
> precision
)
15558 lisp_string
= make_string (string
, len
);
15560 props
= mode_line_string_face_prop
;
15561 else if (!NILP (mode_line_string_face
))
15563 Lisp_Object face
= Fplist_get (props
, Qface
);
15564 props
= Fcopy_sequence (props
);
15566 face
= mode_line_string_face
;
15568 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15569 props
= Fplist_put (props
, Qface
, face
);
15571 Fadd_text_properties (make_number (0), make_number (len
),
15572 props
, lisp_string
);
15576 len
= XFASTINT (Flength (lisp_string
));
15577 if (precision
> 0 && len
> precision
)
15580 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15583 if (!NILP (mode_line_string_face
))
15587 props
= Ftext_properties_at (make_number (0), lisp_string
);
15588 face
= Fplist_get (props
, Qface
);
15590 face
= mode_line_string_face
;
15592 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15593 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15595 lisp_string
= Fcopy_sequence (lisp_string
);
15598 Fadd_text_properties (make_number (0), make_number (len
),
15599 props
, lisp_string
);
15604 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15608 if (field_width
> len
)
15610 field_width
-= len
;
15611 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15613 Fadd_text_properties (make_number (0), make_number (field_width
),
15614 props
, lisp_string
);
15615 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15623 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15625 doc
: /* Return the mode-line of selected window as a string.
15626 First optional arg FORMAT specifies a different format string (see
15627 `mode-line-format' for details) to use. If FORMAT is t, return
15628 the buffer's header-line. Second optional arg WINDOW specifies a
15629 different window to use as the context for the formatting.
15630 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15631 (format
, window
, no_props
)
15632 Lisp_Object format
, window
, no_props
;
15637 struct buffer
*old_buffer
= NULL
;
15638 enum face_id face_id
= DEFAULT_FACE_ID
;
15641 window
= selected_window
;
15642 CHECK_WINDOW (window
);
15643 w
= XWINDOW (window
);
15644 CHECK_BUFFER (w
->buffer
);
15646 if (XBUFFER (w
->buffer
) != current_buffer
)
15648 old_buffer
= current_buffer
;
15649 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15652 if (NILP (format
) || EQ (format
, Qt
))
15654 face_id
= NILP (format
)
15655 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15656 HEADER_LINE_FACE_ID
;
15657 format
= NILP (format
)
15658 ? current_buffer
->mode_line_format
15659 : current_buffer
->header_line_format
;
15662 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15664 if (NILP (no_props
))
15666 mode_line_string_face
=
15667 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15668 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15669 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15671 mode_line_string_face_prop
=
15672 NILP (mode_line_string_face
) ? Qnil
:
15673 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15675 /* We need a dummy last element in mode_line_string_list to
15676 indicate we are building the propertized mode-line string.
15677 Using mode_line_string_face_prop here GC protects it. */
15678 mode_line_string_list
=
15679 Fcons (mode_line_string_face_prop
, Qnil
);
15680 frame_title_ptr
= NULL
;
15684 mode_line_string_face_prop
= Qnil
;
15685 mode_line_string_list
= Qnil
;
15686 frame_title_ptr
= frame_title_buf
;
15689 push_frame_kboard (it
.f
);
15690 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15691 pop_frame_kboard ();
15694 set_buffer_internal_1 (old_buffer
);
15696 if (NILP (no_props
))
15699 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15700 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15701 make_string ("", 0));
15702 mode_line_string_face_prop
= Qnil
;
15703 mode_line_string_list
= Qnil
;
15707 len
= frame_title_ptr
- frame_title_buf
;
15708 if (len
> 0 && frame_title_ptr
[-1] == '-')
15710 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15711 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15713 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15714 if (len
> frame_title_ptr
- frame_title_buf
)
15715 len
= frame_title_ptr
- frame_title_buf
;
15718 frame_title_ptr
= NULL
;
15719 return make_string (frame_title_buf
, len
);
15722 /* Write a null-terminated, right justified decimal representation of
15723 the positive integer D to BUF using a minimal field width WIDTH. */
15726 pint2str (buf
, width
, d
)
15727 register char *buf
;
15728 register int width
;
15731 register char *p
= buf
;
15739 *p
++ = d
% 10 + '0';
15744 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15755 /* Write a null-terminated, right justified decimal and "human
15756 readable" representation of the nonnegative integer D to BUF using
15757 a minimal field width WIDTH. D should be smaller than 999.5e24. */
15759 static const char power_letter
[] =
15773 pint2hrstr (buf
, width
, d
)
15778 /* We aim to represent the nonnegative integer D as
15779 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
15782 /* -1 means: do not use TENTHS. */
15786 /* Length of QUOTIENT.TENTHS as a string. */
15792 if (1000 <= quotient
)
15794 /* Scale to the appropriate EXPONENT. */
15797 remainder
= quotient
% 1000;
15801 while (1000 <= quotient
);
15803 /* Round to nearest and decide whether to use TENTHS or not. */
15806 tenths
= remainder
/ 100;
15807 if (50 <= remainder
% 100)
15813 if (quotient
== 10)
15820 if (500 <= remainder
)
15821 if (quotient
< 999)
15831 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
15832 if (tenths
== -1 && quotient
<= 99)
15839 p
= psuffix
= buf
+ max (width
, length
);
15841 /* Print EXPONENT. */
15843 *psuffix
++ = power_letter
[exponent
];
15846 /* Print TENTHS. */
15849 *--p
= '0' + tenths
;
15853 /* Print QUOTIENT. */
15856 int digit
= quotient
% 10;
15857 *--p
= '0' + digit
;
15859 while ((quotient
/= 10) != 0);
15861 /* Print leading spaces. */
15866 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15867 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15868 type of CODING_SYSTEM. Return updated pointer into BUF. */
15870 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15873 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15874 Lisp_Object coding_system
;
15875 register char *buf
;
15879 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15880 const unsigned char *eol_str
;
15882 /* The EOL conversion we are using. */
15883 Lisp_Object eoltype
;
15885 val
= Fget (coding_system
, Qcoding_system
);
15888 if (!VECTORP (val
)) /* Not yet decided. */
15893 eoltype
= eol_mnemonic_undecided
;
15894 /* Don't mention EOL conversion if it isn't decided. */
15898 Lisp_Object eolvalue
;
15900 eolvalue
= Fget (coding_system
, Qeol_type
);
15903 *buf
++ = XFASTINT (AREF (val
, 1));
15907 /* The EOL conversion that is normal on this system. */
15909 if (NILP (eolvalue
)) /* Not yet decided. */
15910 eoltype
= eol_mnemonic_undecided
;
15911 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15912 eoltype
= eol_mnemonic_undecided
;
15913 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15914 eoltype
= (XFASTINT (eolvalue
) == 0
15915 ? eol_mnemonic_unix
15916 : (XFASTINT (eolvalue
) == 1
15917 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
15923 /* Mention the EOL conversion if it is not the usual one. */
15924 if (STRINGP (eoltype
))
15926 eol_str
= SDATA (eoltype
);
15927 eol_str_len
= SBYTES (eoltype
);
15929 else if (INTEGERP (eoltype
)
15930 && CHAR_VALID_P (XINT (eoltype
), 0))
15932 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
15933 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
15938 eol_str
= invalid_eol_type
;
15939 eol_str_len
= sizeof (invalid_eol_type
) - 1;
15941 bcopy (eol_str
, buf
, eol_str_len
);
15942 buf
+= eol_str_len
;
15948 /* Return a string for the output of a mode line %-spec for window W,
15949 generated by character C. PRECISION >= 0 means don't return a
15950 string longer than that value. FIELD_WIDTH > 0 means pad the
15951 string returned with spaces to that value. Return 1 in *MULTIBYTE
15952 if the result is multibyte text. */
15954 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
15957 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
15960 int field_width
, precision
;
15964 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15965 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
15966 struct buffer
*b
= XBUFFER (w
->buffer
);
15974 if (!NILP (b
->read_only
))
15976 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15981 /* This differs from %* only for a modified read-only buffer. */
15982 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15984 if (!NILP (b
->read_only
))
15989 /* This differs from %* in ignoring read-only-ness. */
15990 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16002 if (command_loop_level
> 5)
16004 p
= decode_mode_spec_buf
;
16005 for (i
= 0; i
< command_loop_level
; i
++)
16008 return decode_mode_spec_buf
;
16016 if (command_loop_level
> 5)
16018 p
= decode_mode_spec_buf
;
16019 for (i
= 0; i
< command_loop_level
; i
++)
16022 return decode_mode_spec_buf
;
16029 /* Let lots_of_dashes be a string of infinite length. */
16030 if (!NILP (mode_line_string_list
))
16032 if (field_width
<= 0
16033 || field_width
> sizeof (lots_of_dashes
))
16035 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16036 decode_mode_spec_buf
[i
] = '-';
16037 decode_mode_spec_buf
[i
] = '\0';
16038 return decode_mode_spec_buf
;
16041 return lots_of_dashes
;
16050 int col
= (int) current_column (); /* iftc */
16051 w
->column_number_displayed
= make_number (col
);
16052 pint2str (decode_mode_spec_buf
, field_width
, col
);
16053 return decode_mode_spec_buf
;
16057 /* %F displays the frame name. */
16058 if (!NILP (f
->title
))
16059 return (char *) SDATA (f
->title
);
16060 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16061 return (char *) SDATA (f
->name
);
16070 int size
= ZV
- BEGV
;
16071 pint2str (decode_mode_spec_buf
, field_width
, size
);
16072 return decode_mode_spec_buf
;
16077 int size
= ZV
- BEGV
;
16078 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16079 return decode_mode_spec_buf
;
16084 int startpos
= XMARKER (w
->start
)->charpos
;
16085 int startpos_byte
= marker_byte_position (w
->start
);
16086 int line
, linepos
, linepos_byte
, topline
;
16088 int height
= WINDOW_TOTAL_LINES (w
);
16090 /* If we decided that this buffer isn't suitable for line numbers,
16091 don't forget that too fast. */
16092 if (EQ (w
->base_line_pos
, w
->buffer
))
16094 /* But do forget it, if the window shows a different buffer now. */
16095 else if (BUFFERP (w
->base_line_pos
))
16096 w
->base_line_pos
= Qnil
;
16098 /* If the buffer is very big, don't waste time. */
16099 if (INTEGERP (Vline_number_display_limit
)
16100 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16102 w
->base_line_pos
= Qnil
;
16103 w
->base_line_number
= Qnil
;
16107 if (!NILP (w
->base_line_number
)
16108 && !NILP (w
->base_line_pos
)
16109 && XFASTINT (w
->base_line_pos
) <= startpos
)
16111 line
= XFASTINT (w
->base_line_number
);
16112 linepos
= XFASTINT (w
->base_line_pos
);
16113 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16118 linepos
= BUF_BEGV (b
);
16119 linepos_byte
= BUF_BEGV_BYTE (b
);
16122 /* Count lines from base line to window start position. */
16123 nlines
= display_count_lines (linepos
, linepos_byte
,
16127 topline
= nlines
+ line
;
16129 /* Determine a new base line, if the old one is too close
16130 or too far away, or if we did not have one.
16131 "Too close" means it's plausible a scroll-down would
16132 go back past it. */
16133 if (startpos
== BUF_BEGV (b
))
16135 w
->base_line_number
= make_number (topline
);
16136 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16138 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16139 || linepos
== BUF_BEGV (b
))
16141 int limit
= BUF_BEGV (b
);
16142 int limit_byte
= BUF_BEGV_BYTE (b
);
16144 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16146 if (startpos
- distance
> limit
)
16148 limit
= startpos
- distance
;
16149 limit_byte
= CHAR_TO_BYTE (limit
);
16152 nlines
= display_count_lines (startpos
, startpos_byte
,
16154 - (height
* 2 + 30),
16156 /* If we couldn't find the lines we wanted within
16157 line_number_display_limit_width chars per line,
16158 give up on line numbers for this window. */
16159 if (position
== limit_byte
&& limit
== startpos
- distance
)
16161 w
->base_line_pos
= w
->buffer
;
16162 w
->base_line_number
= Qnil
;
16166 w
->base_line_number
= make_number (topline
- nlines
);
16167 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16170 /* Now count lines from the start pos to point. */
16171 nlines
= display_count_lines (startpos
, startpos_byte
,
16172 PT_BYTE
, PT
, &junk
);
16174 /* Record that we did display the line number. */
16175 line_number_displayed
= 1;
16177 /* Make the string to show. */
16178 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16179 return decode_mode_spec_buf
;
16182 char* p
= decode_mode_spec_buf
;
16183 int pad
= field_width
- 2;
16189 return decode_mode_spec_buf
;
16195 obj
= b
->mode_name
;
16199 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16205 int pos
= marker_position (w
->start
);
16206 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16208 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16210 if (pos
<= BUF_BEGV (b
))
16215 else if (pos
<= BUF_BEGV (b
))
16219 if (total
> 1000000)
16220 /* Do it differently for a large value, to avoid overflow. */
16221 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16223 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16224 /* We can't normally display a 3-digit number,
16225 so get us a 2-digit number that is close. */
16228 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16229 return decode_mode_spec_buf
;
16233 /* Display percentage of size above the bottom of the screen. */
16236 int toppos
= marker_position (w
->start
);
16237 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16238 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16240 if (botpos
>= BUF_ZV (b
))
16242 if (toppos
<= BUF_BEGV (b
))
16249 if (total
> 1000000)
16250 /* Do it differently for a large value, to avoid overflow. */
16251 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16253 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16254 /* We can't normally display a 3-digit number,
16255 so get us a 2-digit number that is close. */
16258 if (toppos
<= BUF_BEGV (b
))
16259 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16261 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16262 return decode_mode_spec_buf
;
16267 /* status of process */
16268 obj
= Fget_buffer_process (w
->buffer
);
16270 return "no process";
16271 #ifdef subprocesses
16272 obj
= Fsymbol_name (Fprocess_status (obj
));
16276 case 't': /* indicate TEXT or BINARY */
16277 #ifdef MODE_LINE_BINARY_TEXT
16278 return MODE_LINE_BINARY_TEXT (b
);
16284 /* coding-system (not including end-of-line format) */
16286 /* coding-system (including end-of-line type) */
16288 int eol_flag
= (c
== 'Z');
16289 char *p
= decode_mode_spec_buf
;
16291 if (! FRAME_WINDOW_P (f
))
16293 /* No need to mention EOL here--the terminal never needs
16294 to do EOL conversion. */
16295 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16296 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16298 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16301 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16302 #ifdef subprocesses
16303 obj
= Fget_buffer_process (Fcurrent_buffer ());
16304 if (PROCESSP (obj
))
16306 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16308 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16311 #endif /* subprocesses */
16314 return decode_mode_spec_buf
;
16320 *multibyte
= STRING_MULTIBYTE (obj
);
16321 return (char *) SDATA (obj
);
16328 /* Count up to COUNT lines starting from START / START_BYTE.
16329 But don't go beyond LIMIT_BYTE.
16330 Return the number of lines thus found (always nonnegative).
16332 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16335 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16336 int start
, start_byte
, limit_byte
, count
;
16339 register unsigned char *cursor
;
16340 unsigned char *base
;
16342 register int ceiling
;
16343 register unsigned char *ceiling_addr
;
16344 int orig_count
= count
;
16346 /* If we are not in selective display mode,
16347 check only for newlines. */
16348 int selective_display
= (!NILP (current_buffer
->selective_display
)
16349 && !INTEGERP (current_buffer
->selective_display
));
16353 while (start_byte
< limit_byte
)
16355 ceiling
= BUFFER_CEILING_OF (start_byte
);
16356 ceiling
= min (limit_byte
- 1, ceiling
);
16357 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16358 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16361 if (selective_display
)
16362 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16365 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16368 if (cursor
!= ceiling_addr
)
16372 start_byte
+= cursor
- base
+ 1;
16373 *byte_pos_ptr
= start_byte
;
16377 if (++cursor
== ceiling_addr
)
16383 start_byte
+= cursor
- base
;
16388 while (start_byte
> limit_byte
)
16390 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16391 ceiling
= max (limit_byte
, ceiling
);
16392 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16393 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16396 if (selective_display
)
16397 while (--cursor
!= ceiling_addr
16398 && *cursor
!= '\n' && *cursor
!= 015)
16401 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16404 if (cursor
!= ceiling_addr
)
16408 start_byte
+= cursor
- base
+ 1;
16409 *byte_pos_ptr
= start_byte
;
16410 /* When scanning backwards, we should
16411 not count the newline posterior to which we stop. */
16412 return - orig_count
- 1;
16418 /* Here we add 1 to compensate for the last decrement
16419 of CURSOR, which took it past the valid range. */
16420 start_byte
+= cursor
- base
+ 1;
16424 *byte_pos_ptr
= limit_byte
;
16427 return - orig_count
+ count
;
16428 return orig_count
- count
;
16434 /***********************************************************************
16436 ***********************************************************************/
16438 /* Display a NUL-terminated string, starting with index START.
16440 If STRING is non-null, display that C string. Otherwise, the Lisp
16441 string LISP_STRING is displayed.
16443 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16444 FACE_STRING. Display STRING or LISP_STRING with the face at
16445 FACE_STRING_POS in FACE_STRING:
16447 Display the string in the environment given by IT, but use the
16448 standard display table, temporarily.
16450 FIELD_WIDTH is the minimum number of output glyphs to produce.
16451 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16452 with spaces. If STRING has more characters, more than FIELD_WIDTH
16453 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16455 PRECISION is the maximum number of characters to output from
16456 STRING. PRECISION < 0 means don't truncate the string.
16458 This is roughly equivalent to printf format specifiers:
16460 FIELD_WIDTH PRECISION PRINTF
16461 ----------------------------------------
16467 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16468 display them, and < 0 means obey the current buffer's value of
16469 enable_multibyte_characters.
16471 Value is the number of glyphs produced. */
16474 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16475 start
, it
, field_width
, precision
, max_x
, multibyte
)
16476 unsigned char *string
;
16477 Lisp_Object lisp_string
;
16478 Lisp_Object face_string
;
16479 int face_string_pos
;
16482 int field_width
, precision
, max_x
;
16485 int hpos_at_start
= it
->hpos
;
16486 int saved_face_id
= it
->face_id
;
16487 struct glyph_row
*row
= it
->glyph_row
;
16489 /* Initialize the iterator IT for iteration over STRING beginning
16490 with index START. */
16491 reseat_to_string (it
, string
, lisp_string
, start
,
16492 precision
, field_width
, multibyte
);
16494 /* If displaying STRING, set up the face of the iterator
16495 from LISP_STRING, if that's given. */
16496 if (STRINGP (face_string
))
16502 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16503 0, it
->region_beg_charpos
,
16504 it
->region_end_charpos
,
16505 &endptr
, it
->base_face_id
, 0);
16506 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16507 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16510 /* Set max_x to the maximum allowed X position. Don't let it go
16511 beyond the right edge of the window. */
16513 max_x
= it
->last_visible_x
;
16515 max_x
= min (max_x
, it
->last_visible_x
);
16517 /* Skip over display elements that are not visible. because IT->w is
16519 if (it
->current_x
< it
->first_visible_x
)
16520 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16521 MOVE_TO_POS
| MOVE_TO_X
);
16523 row
->ascent
= it
->max_ascent
;
16524 row
->height
= it
->max_ascent
+ it
->max_descent
;
16525 row
->phys_ascent
= it
->max_phys_ascent
;
16526 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16528 /* This condition is for the case that we are called with current_x
16529 past last_visible_x. */
16530 while (it
->current_x
< max_x
)
16532 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16534 /* Get the next display element. */
16535 if (!get_next_display_element (it
))
16538 /* Produce glyphs. */
16539 x_before
= it
->current_x
;
16540 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16541 PRODUCE_GLYPHS (it
);
16543 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16546 while (i
< nglyphs
)
16548 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16550 if (!it
->truncate_lines_p
16551 && x
+ glyph
->pixel_width
> max_x
)
16553 /* End of continued line or max_x reached. */
16554 if (CHAR_GLYPH_PADDING_P (*glyph
))
16556 /* A wide character is unbreakable. */
16557 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16558 it
->current_x
= x_before
;
16562 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16567 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16569 /* Glyph is at least partially visible. */
16571 if (x
< it
->first_visible_x
)
16572 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16576 /* Glyph is off the left margin of the display area.
16577 Should not happen. */
16581 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16582 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16583 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16584 row
->phys_height
= max (row
->phys_height
,
16585 it
->max_phys_ascent
+ it
->max_phys_descent
);
16586 x
+= glyph
->pixel_width
;
16590 /* Stop if max_x reached. */
16594 /* Stop at line ends. */
16595 if (ITERATOR_AT_END_OF_LINE_P (it
))
16597 it
->continuation_lines_width
= 0;
16601 set_iterator_to_next (it
, 1);
16603 /* Stop if truncating at the right edge. */
16604 if (it
->truncate_lines_p
16605 && it
->current_x
>= it
->last_visible_x
)
16607 /* Add truncation mark, but don't do it if the line is
16608 truncated at a padding space. */
16609 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16611 if (!FRAME_WINDOW_P (it
->f
))
16615 if (it
->current_x
> it
->last_visible_x
)
16617 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16618 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16620 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16622 row
->used
[TEXT_AREA
] = i
;
16623 produce_special_glyphs (it
, IT_TRUNCATION
);
16626 produce_special_glyphs (it
, IT_TRUNCATION
);
16628 it
->glyph_row
->truncated_on_right_p
= 1;
16634 /* Maybe insert a truncation at the left. */
16635 if (it
->first_visible_x
16636 && IT_CHARPOS (*it
) > 0)
16638 if (!FRAME_WINDOW_P (it
->f
))
16639 insert_left_trunc_glyphs (it
);
16640 it
->glyph_row
->truncated_on_left_p
= 1;
16643 it
->face_id
= saved_face_id
;
16645 /* Value is number of columns displayed. */
16646 return it
->hpos
- hpos_at_start
;
16651 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16652 appears as an element of LIST or as the car of an element of LIST.
16653 If PROPVAL is a list, compare each element against LIST in that
16654 way, and return 1/2 if any element of PROPVAL is found in LIST.
16655 Otherwise return 0. This function cannot quit.
16656 The return value is 2 if the text is invisible but with an ellipsis
16657 and 1 if it's invisible and without an ellipsis. */
16660 invisible_p (propval
, list
)
16661 register Lisp_Object propval
;
16664 register Lisp_Object tail
, proptail
;
16666 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16668 register Lisp_Object tem
;
16670 if (EQ (propval
, tem
))
16672 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16673 return NILP (XCDR (tem
)) ? 1 : 2;
16676 if (CONSP (propval
))
16678 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16680 Lisp_Object propelt
;
16681 propelt
= XCAR (proptail
);
16682 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16684 register Lisp_Object tem
;
16686 if (EQ (propelt
, tem
))
16688 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16689 return NILP (XCDR (tem
)) ? 1 : 2;
16698 /***********************************************************************
16700 ***********************************************************************/
16702 #ifdef HAVE_WINDOW_SYSTEM
16707 dump_glyph_string (s
)
16708 struct glyph_string
*s
;
16710 fprintf (stderr
, "glyph string\n");
16711 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
16712 s
->x
, s
->y
, s
->width
, s
->height
);
16713 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
16714 fprintf (stderr
, " hl = %d\n", s
->hl
);
16715 fprintf (stderr
, " left overhang = %d, right = %d\n",
16716 s
->left_overhang
, s
->right_overhang
);
16717 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
16718 fprintf (stderr
, " extends to end of line = %d\n",
16719 s
->extends_to_end_of_line_p
);
16720 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
16721 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
16724 #endif /* GLYPH_DEBUG */
16726 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
16727 of XChar2b structures for S; it can't be allocated in
16728 init_glyph_string because it must be allocated via `alloca'. W
16729 is the window on which S is drawn. ROW and AREA are the glyph row
16730 and area within the row from which S is constructed. START is the
16731 index of the first glyph structure covered by S. HL is a
16732 face-override for drawing S. */
16735 #define OPTIONAL_HDC(hdc) hdc,
16736 #define DECLARE_HDC(hdc) HDC hdc;
16737 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
16738 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
16741 #ifndef OPTIONAL_HDC
16742 #define OPTIONAL_HDC(hdc)
16743 #define DECLARE_HDC(hdc)
16744 #define ALLOCATE_HDC(hdc, f)
16745 #define RELEASE_HDC(hdc, f)
16749 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
16750 struct glyph_string
*s
;
16754 struct glyph_row
*row
;
16755 enum glyph_row_area area
;
16757 enum draw_glyphs_face hl
;
16759 bzero (s
, sizeof *s
);
16761 s
->f
= XFRAME (w
->frame
);
16765 s
->display
= FRAME_X_DISPLAY (s
->f
);
16766 s
->window
= FRAME_X_WINDOW (s
->f
);
16767 s
->char2b
= char2b
;
16771 s
->first_glyph
= row
->glyphs
[area
] + start
;
16772 s
->height
= row
->height
;
16773 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
16775 /* Display the internal border below the tool-bar window. */
16776 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
16777 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
16779 s
->ybase
= s
->y
+ row
->ascent
;
16783 /* Append the list of glyph strings with head H and tail T to the list
16784 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
16787 append_glyph_string_lists (head
, tail
, h
, t
)
16788 struct glyph_string
**head
, **tail
;
16789 struct glyph_string
*h
, *t
;
16803 /* Prepend the list of glyph strings with head H and tail T to the
16804 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
16808 prepend_glyph_string_lists (head
, tail
, h
, t
)
16809 struct glyph_string
**head
, **tail
;
16810 struct glyph_string
*h
, *t
;
16824 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
16825 Set *HEAD and *TAIL to the resulting list. */
16828 append_glyph_string (head
, tail
, s
)
16829 struct glyph_string
**head
, **tail
;
16830 struct glyph_string
*s
;
16832 s
->next
= s
->prev
= NULL
;
16833 append_glyph_string_lists (head
, tail
, s
, s
);
16837 /* Get face and two-byte form of character glyph GLYPH on frame F.
16838 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
16839 a pointer to a realized face that is ready for display. */
16841 static INLINE
struct face
*
16842 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
16844 struct glyph
*glyph
;
16850 xassert (glyph
->type
== CHAR_GLYPH
);
16851 face
= FACE_FROM_ID (f
, glyph
->face_id
);
16856 if (!glyph
->multibyte_p
)
16858 /* Unibyte case. We don't have to encode, but we have to make
16859 sure to use a face suitable for unibyte. */
16860 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16862 else if (glyph
->u
.ch
< 128
16863 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
16865 /* Case of ASCII in a face known to fit ASCII. */
16866 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16870 int c1
, c2
, charset
;
16872 /* Split characters into bytes. If c2 is -1 afterwards, C is
16873 really a one-byte character so that byte1 is zero. */
16874 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
16876 STORE_XCHAR2B (char2b
, c1
, c2
);
16878 STORE_XCHAR2B (char2b
, 0, c1
);
16880 /* Maybe encode the character in *CHAR2B. */
16881 if (charset
!= CHARSET_ASCII
)
16883 struct font_info
*font_info
16884 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16887 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
16891 /* Make sure X resources of the face are allocated. */
16892 xassert (face
!= NULL
);
16893 PREPARE_FACE_FOR_DISPLAY (f
, face
);
16898 /* Fill glyph string S with composition components specified by S->cmp.
16900 FACES is an array of faces for all components of this composition.
16901 S->gidx is the index of the first component for S.
16902 OVERLAPS_P non-zero means S should draw the foreground only, and
16903 use its physical height for clipping.
16905 Value is the index of a component not in S. */
16908 fill_composite_glyph_string (s
, faces
, overlaps_p
)
16909 struct glyph_string
*s
;
16910 struct face
**faces
;
16917 s
->for_overlaps_p
= overlaps_p
;
16919 s
->face
= faces
[s
->gidx
];
16920 s
->font
= s
->face
->font
;
16921 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16923 /* For all glyphs of this composition, starting at the offset
16924 S->gidx, until we reach the end of the definition or encounter a
16925 glyph that requires the different face, add it to S. */
16927 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
16930 /* All glyph strings for the same composition has the same width,
16931 i.e. the width set for the first component of the composition. */
16933 s
->width
= s
->first_glyph
->pixel_width
;
16935 /* If the specified font could not be loaded, use the frame's
16936 default font, but record the fact that we couldn't load it in
16937 the glyph string so that we can draw rectangles for the
16938 characters of the glyph string. */
16939 if (s
->font
== NULL
)
16941 s
->font_not_found_p
= 1;
16942 s
->font
= FRAME_FONT (s
->f
);
16945 /* Adjust base line for subscript/superscript text. */
16946 s
->ybase
+= s
->first_glyph
->voffset
;
16948 xassert (s
->face
&& s
->face
->gc
);
16950 /* This glyph string must always be drawn with 16-bit functions. */
16953 return s
->gidx
+ s
->nchars
;
16957 /* Fill glyph string S from a sequence of character glyphs.
16959 FACE_ID is the face id of the string. START is the index of the
16960 first glyph to consider, END is the index of the last + 1.
16961 OVERLAPS_P non-zero means S should draw the foreground only, and
16962 use its physical height for clipping.
16964 Value is the index of the first glyph not in S. */
16967 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
16968 struct glyph_string
*s
;
16970 int start
, end
, overlaps_p
;
16972 struct glyph
*glyph
, *last
;
16974 int glyph_not_available_p
;
16976 xassert (s
->f
== XFRAME (s
->w
->frame
));
16977 xassert (s
->nchars
== 0);
16978 xassert (start
>= 0 && end
> start
);
16980 s
->for_overlaps_p
= overlaps_p
,
16981 glyph
= s
->row
->glyphs
[s
->area
] + start
;
16982 last
= s
->row
->glyphs
[s
->area
] + end
;
16983 voffset
= glyph
->voffset
;
16985 glyph_not_available_p
= glyph
->glyph_not_available_p
;
16987 while (glyph
< last
16988 && glyph
->type
== CHAR_GLYPH
16989 && glyph
->voffset
== voffset
16990 /* Same face id implies same font, nowadays. */
16991 && glyph
->face_id
== face_id
16992 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
16996 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
16997 s
->char2b
+ s
->nchars
,
16999 s
->two_byte_p
= two_byte_p
;
17001 xassert (s
->nchars
<= end
- start
);
17002 s
->width
+= glyph
->pixel_width
;
17006 s
->font
= s
->face
->font
;
17007 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17009 /* If the specified font could not be loaded, use the frame's font,
17010 but record the fact that we couldn't load it in
17011 S->font_not_found_p so that we can draw rectangles for the
17012 characters of the glyph string. */
17013 if (s
->font
== NULL
|| glyph_not_available_p
)
17015 s
->font_not_found_p
= 1;
17016 s
->font
= FRAME_FONT (s
->f
);
17019 /* Adjust base line for subscript/superscript text. */
17020 s
->ybase
+= voffset
;
17022 xassert (s
->face
&& s
->face
->gc
);
17023 return glyph
- s
->row
->glyphs
[s
->area
];
17027 /* Fill glyph string S from image glyph S->first_glyph. */
17030 fill_image_glyph_string (s
)
17031 struct glyph_string
*s
;
17033 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17034 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17036 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17037 s
->font
= s
->face
->font
;
17038 s
->width
= s
->first_glyph
->pixel_width
;
17040 /* Adjust base line for subscript/superscript text. */
17041 s
->ybase
+= s
->first_glyph
->voffset
;
17045 /* Fill glyph string S from a sequence of stretch glyphs.
17047 ROW is the glyph row in which the glyphs are found, AREA is the
17048 area within the row. START is the index of the first glyph to
17049 consider, END is the index of the last + 1.
17051 Value is the index of the first glyph not in S. */
17054 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17055 struct glyph_string
*s
;
17056 struct glyph_row
*row
;
17057 enum glyph_row_area area
;
17060 struct glyph
*glyph
, *last
;
17061 int voffset
, face_id
;
17063 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17065 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17066 last
= s
->row
->glyphs
[s
->area
] + end
;
17067 face_id
= glyph
->face_id
;
17068 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17069 s
->font
= s
->face
->font
;
17070 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17071 s
->width
= glyph
->pixel_width
;
17072 voffset
= glyph
->voffset
;
17076 && glyph
->type
== STRETCH_GLYPH
17077 && glyph
->voffset
== voffset
17078 && glyph
->face_id
== face_id
);
17080 s
->width
+= glyph
->pixel_width
;
17082 /* Adjust base line for subscript/superscript text. */
17083 s
->ybase
+= voffset
;
17085 /* The case that face->gc == 0 is handled when drawing the glyph
17086 string by calling PREPARE_FACE_FOR_DISPLAY. */
17088 return glyph
- s
->row
->glyphs
[s
->area
];
17093 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17094 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17095 assumed to be zero. */
17098 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17099 struct glyph
*glyph
;
17103 *left
= *right
= 0;
17105 if (glyph
->type
== CHAR_GLYPH
)
17109 struct font_info
*font_info
;
17113 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17115 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17116 if (font
/* ++KFS: Should this be font_info ? */
17117 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17119 if (pcm
->rbearing
> pcm
->width
)
17120 *right
= pcm
->rbearing
- pcm
->width
;
17121 if (pcm
->lbearing
< 0)
17122 *left
= -pcm
->lbearing
;
17128 /* Return the index of the first glyph preceding glyph string S that
17129 is overwritten by S because of S's left overhang. Value is -1
17130 if no glyphs are overwritten. */
17133 left_overwritten (s
)
17134 struct glyph_string
*s
;
17138 if (s
->left_overhang
)
17141 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17142 int first
= s
->first_glyph
- glyphs
;
17144 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17145 x
-= glyphs
[i
].pixel_width
;
17156 /* Return the index of the first glyph preceding glyph string S that
17157 is overwriting S because of its right overhang. Value is -1 if no
17158 glyph in front of S overwrites S. */
17161 left_overwriting (s
)
17162 struct glyph_string
*s
;
17165 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17166 int first
= s
->first_glyph
- glyphs
;
17170 for (i
= first
- 1; i
>= 0; --i
)
17173 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17176 x
-= glyphs
[i
].pixel_width
;
17183 /* Return the index of the last glyph following glyph string S that is
17184 not overwritten by S because of S's right overhang. Value is -1 if
17185 no such glyph is found. */
17188 right_overwritten (s
)
17189 struct glyph_string
*s
;
17193 if (s
->right_overhang
)
17196 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17197 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17198 int end
= s
->row
->used
[s
->area
];
17200 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17201 x
+= glyphs
[i
].pixel_width
;
17210 /* Return the index of the last glyph following glyph string S that
17211 overwrites S because of its left overhang. Value is negative
17212 if no such glyph is found. */
17215 right_overwriting (s
)
17216 struct glyph_string
*s
;
17219 int end
= s
->row
->used
[s
->area
];
17220 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17221 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17225 for (i
= first
; i
< end
; ++i
)
17228 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17231 x
+= glyphs
[i
].pixel_width
;
17238 /* Get face and two-byte form of character C in face FACE_ID on frame
17239 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17240 means we want to display multibyte text. DISPLAY_P non-zero means
17241 make sure that X resources for the face returned are allocated.
17242 Value is a pointer to a realized face that is ready for display if
17243 DISPLAY_P is non-zero. */
17245 static INLINE
struct face
*
17246 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17250 int multibyte_p
, display_p
;
17252 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17256 /* Unibyte case. We don't have to encode, but we have to make
17257 sure to use a face suitable for unibyte. */
17258 STORE_XCHAR2B (char2b
, 0, c
);
17259 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17260 face
= FACE_FROM_ID (f
, face_id
);
17262 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17264 /* Case of ASCII in a face known to fit ASCII. */
17265 STORE_XCHAR2B (char2b
, 0, c
);
17269 int c1
, c2
, charset
;
17271 /* Split characters into bytes. If c2 is -1 afterwards, C is
17272 really a one-byte character so that byte1 is zero. */
17273 SPLIT_CHAR (c
, charset
, c1
, c2
);
17275 STORE_XCHAR2B (char2b
, c1
, c2
);
17277 STORE_XCHAR2B (char2b
, 0, c1
);
17279 /* Maybe encode the character in *CHAR2B. */
17280 if (face
->font
!= NULL
)
17282 struct font_info
*font_info
17283 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17285 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
17289 /* Make sure X resources of the face are allocated. */
17290 #ifdef HAVE_X_WINDOWS
17294 xassert (face
!= NULL
);
17295 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17302 /* Set background width of glyph string S. START is the index of the
17303 first glyph following S. LAST_X is the right-most x-position + 1
17304 in the drawing area. */
17307 set_glyph_string_background_width (s
, start
, last_x
)
17308 struct glyph_string
*s
;
17312 /* If the face of this glyph string has to be drawn to the end of
17313 the drawing area, set S->extends_to_end_of_line_p. */
17314 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17316 if (start
== s
->row
->used
[s
->area
]
17317 && s
->area
== TEXT_AREA
17318 && ((s
->hl
== DRAW_NORMAL_TEXT
17319 && (s
->row
->fill_line_p
17320 || s
->face
->background
!= default_face
->background
17321 || s
->face
->stipple
!= default_face
->stipple
17322 || s
->row
->mouse_face_p
))
17323 || s
->hl
== DRAW_MOUSE_FACE
17324 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17325 && s
->row
->fill_line_p
)))
17326 s
->extends_to_end_of_line_p
= 1;
17328 /* If S extends its face to the end of the line, set its
17329 background_width to the distance to the right edge of the drawing
17331 if (s
->extends_to_end_of_line_p
)
17332 s
->background_width
= last_x
- s
->x
+ 1;
17334 s
->background_width
= s
->width
;
17338 /* Compute overhangs and x-positions for glyph string S and its
17339 predecessors, or successors. X is the starting x-position for S.
17340 BACKWARD_P non-zero means process predecessors. */
17343 compute_overhangs_and_x (s
, x
, backward_p
)
17344 struct glyph_string
*s
;
17352 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17353 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17363 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17364 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17374 /* The following macros are only called from draw_glyphs below.
17375 They reference the following parameters of that function directly:
17376 `w', `row', `area', and `overlap_p'
17377 as well as the following local variables:
17378 `s', `f', and `hdc' (in W32) */
17381 /* On W32, silently add local `hdc' variable to argument list of
17382 init_glyph_string. */
17383 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17384 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17386 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17387 init_glyph_string (s, char2b, w, row, area, start, hl)
17390 /* Add a glyph string for a stretch glyph to the list of strings
17391 between HEAD and TAIL. START is the index of the stretch glyph in
17392 row area AREA of glyph row ROW. END is the index of the last glyph
17393 in that glyph row area. X is the current output position assigned
17394 to the new glyph string constructed. HL overrides that face of the
17395 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17396 is the right-most x-position of the drawing area. */
17398 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17399 and below -- keep them on one line. */
17400 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17403 s = (struct glyph_string *) alloca (sizeof *s); \
17404 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17405 START = fill_stretch_glyph_string (s, row, area, START, END); \
17406 append_glyph_string (&HEAD, &TAIL, s); \
17412 /* Add a glyph string for an image glyph to the list of strings
17413 between HEAD and TAIL. START is the index of the image glyph in
17414 row area AREA of glyph row ROW. END is the index of the last glyph
17415 in that glyph row area. X is the current output position assigned
17416 to the new glyph string constructed. HL overrides that face of the
17417 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17418 is the right-most x-position of the drawing area. */
17420 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17423 s = (struct glyph_string *) alloca (sizeof *s); \
17424 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17425 fill_image_glyph_string (s); \
17426 append_glyph_string (&HEAD, &TAIL, s); \
17433 /* Add a glyph string for a sequence of character glyphs to the list
17434 of strings between HEAD and TAIL. START is the index of the first
17435 glyph in row area AREA of glyph row ROW that is part of the new
17436 glyph string. END is the index of the last glyph in that glyph row
17437 area. X is the current output position assigned to the new glyph
17438 string constructed. HL overrides that face of the glyph; e.g. it
17439 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17440 right-most x-position of the drawing area. */
17442 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17448 c = (row)->glyphs[area][START].u.ch; \
17449 face_id = (row)->glyphs[area][START].face_id; \
17451 s = (struct glyph_string *) alloca (sizeof *s); \
17452 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17453 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17454 append_glyph_string (&HEAD, &TAIL, s); \
17456 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17461 /* Add a glyph string for a composite sequence to the list of strings
17462 between HEAD and TAIL. START is the index of the first glyph in
17463 row area AREA of glyph row ROW that is part of the new glyph
17464 string. END is the index of the last glyph in that glyph row area.
17465 X is the current output position assigned to the new glyph string
17466 constructed. HL overrides that face of the glyph; e.g. it is
17467 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17468 x-position of the drawing area. */
17470 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17472 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17473 int face_id = (row)->glyphs[area][START].face_id; \
17474 struct face *base_face = FACE_FROM_ID (f, face_id); \
17475 struct composition *cmp = composition_table[cmp_id]; \
17476 int glyph_len = cmp->glyph_len; \
17478 struct face **faces; \
17479 struct glyph_string *first_s = NULL; \
17482 base_face = base_face->ascii_face; \
17483 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17484 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17485 /* At first, fill in `char2b' and `faces'. */ \
17486 for (n = 0; n < glyph_len; n++) \
17488 int c = COMPOSITION_GLYPH (cmp, n); \
17489 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17490 faces[n] = FACE_FROM_ID (f, this_face_id); \
17491 get_char_face_and_encoding (f, c, this_face_id, \
17492 char2b + n, 1, 1); \
17495 /* Make glyph_strings for each glyph sequence that is drawable by \
17496 the same face, and append them to HEAD/TAIL. */ \
17497 for (n = 0; n < cmp->glyph_len;) \
17499 s = (struct glyph_string *) alloca (sizeof *s); \
17500 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17501 append_glyph_string (&(HEAD), &(TAIL), s); \
17509 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17517 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17518 of AREA of glyph row ROW on window W between indices START and END.
17519 HL overrides the face for drawing glyph strings, e.g. it is
17520 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17521 x-positions of the drawing area.
17523 This is an ugly monster macro construct because we must use alloca
17524 to allocate glyph strings (because draw_glyphs can be called
17525 asynchronously). */
17527 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17530 HEAD = TAIL = NULL; \
17531 while (START < END) \
17533 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17534 switch (first_glyph->type) \
17537 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17541 case COMPOSITE_GLYPH: \
17542 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17546 case STRETCH_GLYPH: \
17547 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17551 case IMAGE_GLYPH: \
17552 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17560 set_glyph_string_background_width (s, START, LAST_X); \
17567 /* Draw glyphs between START and END in AREA of ROW on window W,
17568 starting at x-position X. X is relative to AREA in W. HL is a
17569 face-override with the following meaning:
17571 DRAW_NORMAL_TEXT draw normally
17572 DRAW_CURSOR draw in cursor face
17573 DRAW_MOUSE_FACE draw in mouse face.
17574 DRAW_INVERSE_VIDEO draw in mode line face
17575 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17576 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17578 If OVERLAPS_P is non-zero, draw only the foreground of characters
17579 and clip to the physical height of ROW.
17581 Value is the x-position reached, relative to AREA of W. */
17584 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17587 struct glyph_row
*row
;
17588 enum glyph_row_area area
;
17590 enum draw_glyphs_face hl
;
17593 struct glyph_string
*head
, *tail
;
17594 struct glyph_string
*s
;
17595 int last_x
, area_width
;
17598 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17601 ALLOCATE_HDC (hdc
, f
);
17603 /* Let's rather be paranoid than getting a SEGV. */
17604 end
= min (end
, row
->used
[area
]);
17605 start
= max (0, start
);
17606 start
= min (end
, start
);
17608 /* Translate X to frame coordinates. Set last_x to the right
17609 end of the drawing area. */
17610 if (row
->full_width_p
)
17612 /* X is relative to the left edge of W, without scroll bars
17614 x
+= WINDOW_LEFT_EDGE_X (w
);
17615 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
17619 int area_left
= window_box_left (w
, area
);
17621 area_width
= window_box_width (w
, area
);
17622 last_x
= area_left
+ area_width
;
17625 /* Build a doubly-linked list of glyph_string structures between
17626 head and tail from what we have to draw. Note that the macro
17627 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17628 the reason we use a separate variable `i'. */
17630 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17632 x_reached
= tail
->x
+ tail
->background_width
;
17636 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17637 the row, redraw some glyphs in front or following the glyph
17638 strings built above. */
17639 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17642 struct glyph_string
*h
, *t
;
17644 /* Compute overhangs for all glyph strings. */
17645 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
17646 for (s
= head
; s
; s
= s
->next
)
17647 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
17649 /* Prepend glyph strings for glyphs in front of the first glyph
17650 string that are overwritten because of the first glyph
17651 string's left overhang. The background of all strings
17652 prepended must be drawn because the first glyph string
17654 i
= left_overwritten (head
);
17658 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17659 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17661 compute_overhangs_and_x (t
, head
->x
, 1);
17662 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17665 /* Prepend glyph strings for glyphs in front of the first glyph
17666 string that overwrite that glyph string because of their
17667 right overhang. For these strings, only the foreground must
17668 be drawn, because it draws over the glyph string at `head'.
17669 The background must not be drawn because this would overwrite
17670 right overhangs of preceding glyphs for which no glyph
17672 i
= left_overwriting (head
);
17675 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
17676 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17677 for (s
= h
; s
; s
= s
->next
)
17678 s
->background_filled_p
= 1;
17679 compute_overhangs_and_x (t
, head
->x
, 1);
17680 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17683 /* Append glyphs strings for glyphs following the last glyph
17684 string tail that are overwritten by tail. The background of
17685 these strings has to be drawn because tail's foreground draws
17687 i
= right_overwritten (tail
);
17690 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17691 DRAW_NORMAL_TEXT
, x
, last_x
);
17692 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17693 append_glyph_string_lists (&head
, &tail
, h
, t
);
17696 /* Append glyph strings for glyphs following the last glyph
17697 string tail that overwrite tail. The foreground of such
17698 glyphs has to be drawn because it writes into the background
17699 of tail. The background must not be drawn because it could
17700 paint over the foreground of following glyphs. */
17701 i
= right_overwriting (tail
);
17704 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17705 DRAW_NORMAL_TEXT
, x
, last_x
);
17706 for (s
= h
; s
; s
= s
->next
)
17707 s
->background_filled_p
= 1;
17708 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17709 append_glyph_string_lists (&head
, &tail
, h
, t
);
17713 /* Draw all strings. */
17714 for (s
= head
; s
; s
= s
->next
)
17715 FRAME_RIF (f
)->draw_glyph_string (s
);
17717 if (area
== TEXT_AREA
17718 && !row
->full_width_p
17719 /* When drawing overlapping rows, only the glyph strings'
17720 foreground is drawn, which doesn't erase a cursor
17724 int x0
= head
? head
->x
: x
;
17725 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
17727 int text_left
= window_box_left (w
, TEXT_AREA
);
17731 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
17732 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
17735 /* Value is the x-position up to which drawn, relative to AREA of W.
17736 This doesn't include parts drawn because of overhangs. */
17737 if (row
->full_width_p
)
17738 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
17740 x_reached
-= window_box_left (w
, area
);
17742 RELEASE_HDC (hdc
, f
);
17748 /* Store one glyph for IT->char_to_display in IT->glyph_row.
17749 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17755 struct glyph
*glyph
;
17756 enum glyph_row_area area
= it
->area
;
17758 xassert (it
->glyph_row
);
17759 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
17761 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17762 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17764 glyph
->charpos
= CHARPOS (it
->position
);
17765 glyph
->object
= it
->object
;
17766 glyph
->pixel_width
= it
->pixel_width
;
17767 glyph
->ascent
= it
->ascent
;
17768 glyph
->descent
= it
->descent
;
17769 glyph
->voffset
= it
->voffset
;
17770 glyph
->type
= CHAR_GLYPH
;
17771 glyph
->multibyte_p
= it
->multibyte_p
;
17772 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17773 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17774 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17775 || it
->phys_descent
> it
->descent
);
17776 glyph
->padding_p
= 0;
17777 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
17778 glyph
->face_id
= it
->face_id
;
17779 glyph
->u
.ch
= it
->char_to_display
;
17780 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17781 ++it
->glyph_row
->used
[area
];
17785 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
17786 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17789 append_composite_glyph (it
)
17792 struct glyph
*glyph
;
17793 enum glyph_row_area area
= it
->area
;
17795 xassert (it
->glyph_row
);
17797 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17798 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17800 glyph
->charpos
= CHARPOS (it
->position
);
17801 glyph
->object
= it
->object
;
17802 glyph
->pixel_width
= it
->pixel_width
;
17803 glyph
->ascent
= it
->ascent
;
17804 glyph
->descent
= it
->descent
;
17805 glyph
->voffset
= it
->voffset
;
17806 glyph
->type
= COMPOSITE_GLYPH
;
17807 glyph
->multibyte_p
= it
->multibyte_p
;
17808 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17809 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17810 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17811 || it
->phys_descent
> it
->descent
);
17812 glyph
->padding_p
= 0;
17813 glyph
->glyph_not_available_p
= 0;
17814 glyph
->face_id
= it
->face_id
;
17815 glyph
->u
.cmp_id
= it
->cmp_id
;
17816 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17817 ++it
->glyph_row
->used
[area
];
17822 /* Change IT->ascent and IT->height according to the setting of
17826 take_vertical_position_into_account (it
)
17831 if (it
->voffset
< 0)
17832 /* Increase the ascent so that we can display the text higher
17834 it
->ascent
+= abs (it
->voffset
);
17836 /* Increase the descent so that we can display the text lower
17838 it
->descent
+= it
->voffset
;
17843 /* Produce glyphs/get display metrics for the image IT is loaded with.
17844 See the description of struct display_iterator in dispextern.h for
17845 an overview of struct display_iterator. */
17848 produce_image_glyph (it
)
17853 int face_ascent
, glyph_ascent
;
17855 xassert (it
->what
== IT_IMAGE
);
17857 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17859 /* Make sure X resources of the face is loaded. */
17860 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
17862 if (it
->image_id
< 0)
17864 /* Fringe bitmap. */
17865 it
->ascent
= it
->phys_ascent
= 0;
17866 it
->descent
= it
->phys_descent
= 0;
17867 it
->pixel_width
= 0;
17872 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
17874 /* Make sure X resources of the image is loaded. */
17875 prepare_image_for_display (it
->f
, img
);
17877 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
);
17878 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
17879 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
17881 /* It's quite possible for images to have an ascent greater than
17882 their height, so don't get confused in that case. */
17883 if (it
->descent
< 0)
17886 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
17887 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
17888 if (face_ascent
> it
->ascent
)
17889 it
->ascent
= it
->phys_ascent
= face_ascent
;
17893 if (face
->box
!= FACE_NO_BOX
)
17895 if (face
->box_line_width
> 0)
17897 it
->ascent
+= face
->box_line_width
;
17898 it
->descent
+= face
->box_line_width
;
17901 if (it
->start_of_box_run_p
)
17902 it
->pixel_width
+= abs (face
->box_line_width
);
17903 if (it
->end_of_box_run_p
)
17904 it
->pixel_width
+= abs (face
->box_line_width
);
17907 take_vertical_position_into_account (it
);
17911 struct glyph
*glyph
;
17912 enum glyph_row_area area
= it
->area
;
17914 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17915 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17917 glyph
->charpos
= CHARPOS (it
->position
);
17918 glyph
->object
= it
->object
;
17919 glyph
->pixel_width
= it
->pixel_width
;
17920 glyph
->ascent
= glyph_ascent
;
17921 glyph
->descent
= it
->descent
;
17922 glyph
->voffset
= it
->voffset
;
17923 glyph
->type
= IMAGE_GLYPH
;
17924 glyph
->multibyte_p
= it
->multibyte_p
;
17925 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17926 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17927 glyph
->overlaps_vertically_p
= 0;
17928 glyph
->padding_p
= 0;
17929 glyph
->glyph_not_available_p
= 0;
17930 glyph
->face_id
= it
->face_id
;
17931 glyph
->u
.img_id
= img
->id
;
17932 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17933 ++it
->glyph_row
->used
[area
];
17939 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
17940 of the glyph, WIDTH and HEIGHT are the width and height of the
17941 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
17944 append_stretch_glyph (it
, object
, width
, height
, ascent
)
17946 Lisp_Object object
;
17950 struct glyph
*glyph
;
17951 enum glyph_row_area area
= it
->area
;
17953 xassert (ascent
>= 0 && ascent
<= height
);
17955 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17956 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17958 glyph
->charpos
= CHARPOS (it
->position
);
17959 glyph
->object
= object
;
17960 glyph
->pixel_width
= width
;
17961 glyph
->ascent
= ascent
;
17962 glyph
->descent
= height
- ascent
;
17963 glyph
->voffset
= it
->voffset
;
17964 glyph
->type
= STRETCH_GLYPH
;
17965 glyph
->multibyte_p
= it
->multibyte_p
;
17966 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17967 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17968 glyph
->overlaps_vertically_p
= 0;
17969 glyph
->padding_p
= 0;
17970 glyph
->glyph_not_available_p
= 0;
17971 glyph
->face_id
= it
->face_id
;
17972 glyph
->u
.stretch
.ascent
= ascent
;
17973 glyph
->u
.stretch
.height
= height
;
17974 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17975 ++it
->glyph_row
->used
[area
];
17980 /* Calculate a width or height in pixels from a specification using
17981 the following elements:
17984 NUM - a (fractional) multiple of the default font width/height
17985 (NUM) - specifies exactly NUM pixels
17986 UNIT - a fixed number of pixels, see below.
17987 ELEMENT - size of a display element in pixels, see below.
17988 (NUM . SPEC) - equals NUM * SPEC
17989 (+ SPEC SPEC ...) - add pixel values
17990 (- SPEC SPEC ...) - subtract pixel values
17991 (- SPEC) - negate pixel value
17994 INT or FLOAT - a number constant
17995 SYMBOL - use symbol's (buffer local) variable binding.
17998 in - pixels per inch *)
17999 mm - pixels per 1/1000 meter *)
18000 cm - pixels per 1/100 meter *)
18001 width - width of current font in pixels.
18002 height - height of current font in pixels.
18004 *) using the ratio(s) defined in display-pixels-per-inch.
18008 left-fringe - left fringe width in pixels
18009 (left-fringe . nil) - left fringe width if inside margins, else 0
18010 (left-fringe . t) - left fringe width if outside margins, else 0
18012 right-fringe - right fringe width in pixels
18013 (right-fringe . nil) - right fringe width if inside margins, else 0
18014 (right-fringe . t) - right fringe width if outside margins, else 0
18016 left-margin - left margin width in pixels
18017 right-margin - right margin width in pixels
18019 scroll-bar - scroll-bar area width in pixels
18020 (scroll-bar . left) - scroll-bar width if on left, else 0
18021 (scroll-bar . right) - scroll-bar width if on right, else 0
18025 Pixels corresponding to 5 inches:
18028 Total width of non-text areas on left side of window:
18029 (+ left-fringe left-margin (scroll-bar . left))
18031 Total width of fringes if inside display margins:
18032 (+ (left-fringe) (right-fringe))
18034 Width of left margin minus width of 1 character in the default font:
18037 Width of left margin minus width of 2 characters in the current font:
18038 (- left-margin (2 . width))
18040 Width of left fringe plus left margin minus one pixel:
18041 (- (+ left-fringe left-margin) (1))
18042 (+ left-fringe left-margin (- (1)))
18043 (+ left-fringe left-margin (-1))
18047 #define NUMVAL(X) \
18048 ((INTEGERP (X) || FLOATP (X)) \
18053 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
)
18062 #define OK_PIXELS(val) ((*res = (val)), 1)
18064 if (SYMBOLP (prop
))
18066 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18068 char *unit
= SDATA (SYMBOL_NAME (prop
));
18070 if (unit
[0] == 'i' && unit
[1] == 'n')
18072 else if (unit
[0] == 'm' && unit
[1] == 'm')
18074 else if (unit
[0] == 'c' && unit
[1] == 'm')
18081 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18082 || (CONSP (Vdisplay_pixels_per_inch
)
18084 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18085 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18087 return OK_PIXELS (ppi
/ pixels
);
18093 if (EQ (prop
, Qheight
))
18094 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
18095 if (EQ (prop
, Qwidth
))
18096 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
18097 if (EQ (prop
, Qleft_fringe
))
18098 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18099 if (EQ (prop
, Qright_fringe
))
18100 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18101 if (EQ (prop
, Qleft_margin
))
18102 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18103 if (EQ (prop
, Qright_margin
))
18104 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18105 if (EQ (prop
, Qscroll_bar
))
18106 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18108 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18111 if (INTEGERP (prop
) || FLOATP (prop
))
18113 int base_unit
= (width_p
18114 ? FRAME_COLUMN_WIDTH (it
->f
)
18115 : FRAME_LINE_HEIGHT (it
->f
));
18116 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18121 Lisp_Object car
= XCAR (prop
);
18122 Lisp_Object cdr
= XCDR (prop
);
18126 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18132 while (CONSP (cdr
))
18134 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
), font
, width_p
))
18137 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18142 if (EQ (car
, Qminus
))
18144 return OK_PIXELS (pixels
);
18147 if (EQ (car
, Qleft_fringe
))
18148 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18150 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
18152 if (EQ (car
, Qright_fringe
))
18153 return OK_PIXELS ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18155 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18157 if (EQ (car
, Qscroll_bar
))
18158 return OK_PIXELS ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18159 == EQ (cdr
, Qleft
))
18160 ? WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
)
18163 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18166 if (INTEGERP (car
) || FLOATP (car
))
18169 pixels
= XFLOATINT (car
);
18171 return OK_PIXELS (pixels
);
18172 if (calc_pixel_width_or_height (&fact
, it
, cdr
, font
, width_p
))
18173 return OK_PIXELS (pixels
* fact
);
18183 /* Produce a stretch glyph for iterator IT. IT->object is the value
18184 of the glyph property displayed. The value must be a list
18185 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18188 1. `:width WIDTH' specifies that the space should be WIDTH *
18189 canonical char width wide. WIDTH may be an integer or floating
18192 2. `:relative-width FACTOR' specifies that the width of the stretch
18193 should be computed from the width of the first character having the
18194 `glyph' property, and should be FACTOR times that width.
18196 3. `:align-to HPOS' specifies that the space should be wide enough
18197 to reach HPOS, a value in canonical character units.
18199 Exactly one of the above pairs must be present.
18201 4. `:height HEIGHT' specifies that the height of the stretch produced
18202 should be HEIGHT, measured in canonical character units.
18204 5. `:relative-height FACTOR' specifies that the height of the
18205 stretch should be FACTOR times the height of the characters having
18206 the glyph property.
18208 Either none or exactly one of 4 or 5 must be present.
18210 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18211 of the stretch should be used for the ascent of the stretch.
18212 ASCENT must be in the range 0 <= ASCENT <= 100. */
18215 produce_stretch_glyph (it
)
18218 /* (space :width WIDTH :height HEIGHT ...) */
18219 Lisp_Object prop
, plist
;
18220 int width
= 0, height
= 0;
18221 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18224 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18225 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18227 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18229 /* List should start with `space'. */
18230 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18231 plist
= XCDR (it
->object
);
18233 /* Compute the width of the stretch. */
18234 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18235 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18237 /* Absolute width `:width WIDTH' specified and valid. */
18238 zero_width_ok_p
= 1;
18241 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18244 /* Relative width `:relative-width FACTOR' specified and valid.
18245 Compute the width of the characters having the `glyph'
18248 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18251 if (it
->multibyte_p
)
18253 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18254 - IT_BYTEPOS (*it
));
18255 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18258 it2
.c
= *p
, it2
.len
= 1;
18260 it2
.glyph_row
= NULL
;
18261 it2
.what
= IT_CHARACTER
;
18262 x_produce_glyphs (&it2
);
18263 width
= NUMVAL (prop
) * it2
.pixel_width
;
18265 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18266 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1))
18268 width
= max (0, (int)tem
- it
->current_x
);
18269 zero_width_ok_p
= 1;
18272 /* Nothing specified -> width defaults to canonical char width. */
18273 width
= FRAME_COLUMN_WIDTH (it
->f
);
18275 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18278 /* Compute height. */
18279 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18280 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18283 zero_height_ok_p
= 1;
18285 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18287 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18289 height
= FONT_HEIGHT (font
);
18291 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18294 /* Compute percentage of height used for ascent. If
18295 `:ascent ASCENT' is present and valid, use that. Otherwise,
18296 derive the ascent from the font in use. */
18297 if (prop
= Fplist_get (plist
, QCascent
),
18298 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18299 ascent
= height
* NUMVAL (prop
) / 100.0;
18300 else if (!NILP (prop
)
18301 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0))
18302 ascent
= min (max (0, (int)tem
), height
);
18304 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18306 if (width
> 0 && height
> 0 && it
->glyph_row
)
18308 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18309 if (!STRINGP (object
))
18310 object
= it
->w
->buffer
;
18311 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18314 it
->pixel_width
= width
;
18315 it
->ascent
= it
->phys_ascent
= ascent
;
18316 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18317 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18319 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18321 if (face
->box_line_width
> 0)
18323 it
->ascent
+= face
->box_line_width
;
18324 it
->descent
+= face
->box_line_width
;
18327 if (it
->start_of_box_run_p
)
18328 it
->pixel_width
+= abs (face
->box_line_width
);
18329 if (it
->end_of_box_run_p
)
18330 it
->pixel_width
+= abs (face
->box_line_width
);
18333 take_vertical_position_into_account (it
);
18337 Produce glyphs/get display metrics for the display element IT is
18338 loaded with. See the description of struct display_iterator in
18339 dispextern.h for an overview of struct display_iterator. */
18342 x_produce_glyphs (it
)
18345 it
->glyph_not_available_p
= 0;
18347 if (it
->what
== IT_CHARACTER
)
18351 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18353 int font_not_found_p
;
18354 struct font_info
*font_info
;
18355 int boff
; /* baseline offset */
18356 /* We may change it->multibyte_p upon unibyte<->multibyte
18357 conversion. So, save the current value now and restore it
18360 Note: It seems that we don't have to record multibyte_p in
18361 struct glyph because the character code itself tells if or
18362 not the character is multibyte. Thus, in the future, we must
18363 consider eliminating the field `multibyte_p' in the struct
18365 int saved_multibyte_p
= it
->multibyte_p
;
18367 /* Maybe translate single-byte characters to multibyte, or the
18369 it
->char_to_display
= it
->c
;
18370 if (!ASCII_BYTE_P (it
->c
))
18372 if (unibyte_display_via_language_environment
18373 && SINGLE_BYTE_CHAR_P (it
->c
)
18375 || !NILP (Vnonascii_translation_table
)))
18377 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18378 it
->multibyte_p
= 1;
18379 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18380 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18382 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18383 && !it
->multibyte_p
)
18385 it
->multibyte_p
= 1;
18386 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18387 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18391 /* Get font to use. Encode IT->char_to_display. */
18392 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18393 &char2b
, it
->multibyte_p
, 0);
18396 /* When no suitable font found, use the default font. */
18397 font_not_found_p
= font
== NULL
;
18398 if (font_not_found_p
)
18400 font
= FRAME_FONT (it
->f
);
18401 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18406 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18407 boff
= font_info
->baseline_offset
;
18408 if (font_info
->vertical_centering
)
18409 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18412 if (it
->char_to_display
>= ' '
18413 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18415 /* Either unibyte or ASCII. */
18420 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18421 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18422 it
->ascent
= FONT_BASE (font
) + boff
;
18423 it
->descent
= FONT_DESCENT (font
) - boff
;
18427 it
->phys_ascent
= pcm
->ascent
+ boff
;
18428 it
->phys_descent
= pcm
->descent
- boff
;
18429 it
->pixel_width
= pcm
->width
;
18433 it
->glyph_not_available_p
= 1;
18434 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18435 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18436 it
->pixel_width
= FONT_WIDTH (font
);
18439 /* If this is a space inside a region of text with
18440 `space-width' property, change its width. */
18441 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18443 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18445 /* If face has a box, add the box thickness to the character
18446 height. If character has a box line to the left and/or
18447 right, add the box line width to the character's width. */
18448 if (face
->box
!= FACE_NO_BOX
)
18450 int thick
= face
->box_line_width
;
18454 it
->ascent
+= thick
;
18455 it
->descent
+= thick
;
18460 if (it
->start_of_box_run_p
)
18461 it
->pixel_width
+= thick
;
18462 if (it
->end_of_box_run_p
)
18463 it
->pixel_width
+= thick
;
18466 /* If face has an overline, add the height of the overline
18467 (1 pixel) and a 1 pixel margin to the character height. */
18468 if (face
->overline_p
)
18471 take_vertical_position_into_account (it
);
18473 /* If we have to actually produce glyphs, do it. */
18478 /* Translate a space with a `space-width' property
18479 into a stretch glyph. */
18480 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18481 / FONT_HEIGHT (font
));
18482 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18483 it
->ascent
+ it
->descent
, ascent
);
18488 /* If characters with lbearing or rbearing are displayed
18489 in this line, record that fact in a flag of the
18490 glyph row. This is used to optimize X output code. */
18491 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18492 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18495 else if (it
->char_to_display
== '\n')
18497 /* A newline has no width but we need the height of the line. */
18498 it
->pixel_width
= 0;
18500 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18501 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18503 if (face
->box
!= FACE_NO_BOX
18504 && face
->box_line_width
> 0)
18506 it
->ascent
+= face
->box_line_width
;
18507 it
->descent
+= face
->box_line_width
;
18510 else if (it
->char_to_display
== '\t')
18512 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18513 int x
= it
->current_x
+ it
->continuation_lines_width
;
18514 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18516 /* If the distance from the current position to the next tab
18517 stop is less than a canonical character width, use the
18518 tab stop after that. */
18519 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18520 next_tab_x
+= tab_width
;
18522 it
->pixel_width
= next_tab_x
- x
;
18524 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18525 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18529 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18530 it
->ascent
+ it
->descent
, it
->ascent
);
18535 /* A multi-byte character. Assume that the display width of the
18536 character is the width of the character multiplied by the
18537 width of the font. */
18539 /* If we found a font, this font should give us the right
18540 metrics. If we didn't find a font, use the frame's
18541 default font and calculate the width of the character
18542 from the charset width; this is what old redisplay code
18545 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18546 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18548 if (font_not_found_p
|| !pcm
)
18550 int charset
= CHAR_CHARSET (it
->char_to_display
);
18552 it
->glyph_not_available_p
= 1;
18553 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18554 * CHARSET_WIDTH (charset
));
18555 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18556 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18560 it
->pixel_width
= pcm
->width
;
18561 it
->phys_ascent
= pcm
->ascent
+ boff
;
18562 it
->phys_descent
= pcm
->descent
- boff
;
18564 && (pcm
->lbearing
< 0
18565 || pcm
->rbearing
> pcm
->width
))
18566 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18569 it
->ascent
= FONT_BASE (font
) + boff
;
18570 it
->descent
= FONT_DESCENT (font
) - boff
;
18571 if (face
->box
!= FACE_NO_BOX
)
18573 int thick
= face
->box_line_width
;
18577 it
->ascent
+= thick
;
18578 it
->descent
+= thick
;
18583 if (it
->start_of_box_run_p
)
18584 it
->pixel_width
+= thick
;
18585 if (it
->end_of_box_run_p
)
18586 it
->pixel_width
+= thick
;
18589 /* If face has an overline, add the height of the overline
18590 (1 pixel) and a 1 pixel margin to the character height. */
18591 if (face
->overline_p
)
18594 take_vertical_position_into_account (it
);
18599 it
->multibyte_p
= saved_multibyte_p
;
18601 else if (it
->what
== IT_COMPOSITION
)
18603 /* Note: A composition is represented as one glyph in the
18604 glyph matrix. There are no padding glyphs. */
18607 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18609 int font_not_found_p
;
18610 struct font_info
*font_info
;
18611 int boff
; /* baseline offset */
18612 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18614 /* Maybe translate single-byte characters to multibyte. */
18615 it
->char_to_display
= it
->c
;
18616 if (unibyte_display_via_language_environment
18617 && SINGLE_BYTE_CHAR_P (it
->c
)
18620 && !NILP (Vnonascii_translation_table
))))
18622 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18625 /* Get face and font to use. Encode IT->char_to_display. */
18626 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18627 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18628 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18629 &char2b
, it
->multibyte_p
, 0);
18632 /* When no suitable font found, use the default font. */
18633 font_not_found_p
= font
== NULL
;
18634 if (font_not_found_p
)
18636 font
= FRAME_FONT (it
->f
);
18637 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18642 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18643 boff
= font_info
->baseline_offset
;
18644 if (font_info
->vertical_centering
)
18645 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18648 /* There are no padding glyphs, so there is only one glyph to
18649 produce for the composition. Important is that pixel_width,
18650 ascent and descent are the values of what is drawn by
18651 draw_glyphs (i.e. the values of the overall glyphs composed). */
18654 /* If we have not yet calculated pixel size data of glyphs of
18655 the composition for the current face font, calculate them
18656 now. Theoretically, we have to check all fonts for the
18657 glyphs, but that requires much time and memory space. So,
18658 here we check only the font of the first glyph. This leads
18659 to incorrect display very rarely, and C-l (recenter) can
18660 correct the display anyway. */
18661 if (cmp
->font
!= (void *) font
)
18663 /* Ascent and descent of the font of the first character of
18664 this composition (adjusted by baseline offset). Ascent
18665 and descent of overall glyphs should not be less than
18666 them respectively. */
18667 int font_ascent
= FONT_BASE (font
) + boff
;
18668 int font_descent
= FONT_DESCENT (font
) - boff
;
18669 /* Bounding box of the overall glyphs. */
18670 int leftmost
, rightmost
, lowest
, highest
;
18671 int i
, width
, ascent
, descent
;
18673 cmp
->font
= (void *) font
;
18675 /* Initialize the bounding box. */
18677 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18678 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
18680 width
= pcm
->width
;
18681 ascent
= pcm
->ascent
;
18682 descent
= pcm
->descent
;
18686 width
= FONT_WIDTH (font
);
18687 ascent
= FONT_BASE (font
);
18688 descent
= FONT_DESCENT (font
);
18692 lowest
= - descent
+ boff
;
18693 highest
= ascent
+ boff
;
18697 && font_info
->default_ascent
18698 && CHAR_TABLE_P (Vuse_default_ascent
)
18699 && !NILP (Faref (Vuse_default_ascent
,
18700 make_number (it
->char_to_display
))))
18701 highest
= font_info
->default_ascent
+ boff
;
18703 /* Draw the first glyph at the normal position. It may be
18704 shifted to right later if some other glyphs are drawn at
18706 cmp
->offsets
[0] = 0;
18707 cmp
->offsets
[1] = boff
;
18709 /* Set cmp->offsets for the remaining glyphs. */
18710 for (i
= 1; i
< cmp
->glyph_len
; i
++)
18712 int left
, right
, btm
, top
;
18713 int ch
= COMPOSITION_GLYPH (cmp
, i
);
18714 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
18716 face
= FACE_FROM_ID (it
->f
, face_id
);
18717 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
18718 &char2b
, it
->multibyte_p
, 0);
18722 font
= FRAME_FONT (it
->f
);
18723 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18729 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18730 boff
= font_info
->baseline_offset
;
18731 if (font_info
->vertical_centering
)
18732 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18736 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
18737 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
18739 width
= pcm
->width
;
18740 ascent
= pcm
->ascent
;
18741 descent
= pcm
->descent
;
18745 width
= FONT_WIDTH (font
);
18750 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
18752 /* Relative composition with or without
18753 alternate chars. */
18754 left
= (leftmost
+ rightmost
- width
) / 2;
18755 btm
= - descent
+ boff
;
18756 if (font_info
&& font_info
->relative_compose
18757 && (! CHAR_TABLE_P (Vignore_relative_composition
)
18758 || NILP (Faref (Vignore_relative_composition
,
18759 make_number (ch
)))))
18762 if (- descent
>= font_info
->relative_compose
)
18763 /* One extra pixel between two glyphs. */
18765 else if (ascent
<= 0)
18766 /* One extra pixel between two glyphs. */
18767 btm
= lowest
- 1 - ascent
- descent
;
18772 /* A composition rule is specified by an integer
18773 value that encodes global and new reference
18774 points (GREF and NREF). GREF and NREF are
18775 specified by numbers as below:
18777 0---1---2 -- ascent
18781 9--10--11 -- center
18783 ---3---4---5--- baseline
18785 6---7---8 -- descent
18787 int rule
= COMPOSITION_RULE (cmp
, i
);
18788 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
18790 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
18791 grefx
= gref
% 3, nrefx
= nref
% 3;
18792 grefy
= gref
/ 3, nrefy
= nref
/ 3;
18795 + grefx
* (rightmost
- leftmost
) / 2
18796 - nrefx
* width
/ 2);
18797 btm
= ((grefy
== 0 ? highest
18799 : grefy
== 2 ? lowest
18800 : (highest
+ lowest
) / 2)
18801 - (nrefy
== 0 ? ascent
+ descent
18802 : nrefy
== 1 ? descent
- boff
18804 : (ascent
+ descent
) / 2));
18807 cmp
->offsets
[i
* 2] = left
;
18808 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
18810 /* Update the bounding box of the overall glyphs. */
18811 right
= left
+ width
;
18812 top
= btm
+ descent
+ ascent
;
18813 if (left
< leftmost
)
18815 if (right
> rightmost
)
18823 /* If there are glyphs whose x-offsets are negative,
18824 shift all glyphs to the right and make all x-offsets
18828 for (i
= 0; i
< cmp
->glyph_len
; i
++)
18829 cmp
->offsets
[i
* 2] -= leftmost
;
18830 rightmost
-= leftmost
;
18833 cmp
->pixel_width
= rightmost
;
18834 cmp
->ascent
= highest
;
18835 cmp
->descent
= - lowest
;
18836 if (cmp
->ascent
< font_ascent
)
18837 cmp
->ascent
= font_ascent
;
18838 if (cmp
->descent
< font_descent
)
18839 cmp
->descent
= font_descent
;
18842 it
->pixel_width
= cmp
->pixel_width
;
18843 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
18844 it
->descent
= it
->phys_descent
= cmp
->descent
;
18846 if (face
->box
!= FACE_NO_BOX
)
18848 int thick
= face
->box_line_width
;
18852 it
->ascent
+= thick
;
18853 it
->descent
+= thick
;
18858 if (it
->start_of_box_run_p
)
18859 it
->pixel_width
+= thick
;
18860 if (it
->end_of_box_run_p
)
18861 it
->pixel_width
+= thick
;
18864 /* If face has an overline, add the height of the overline
18865 (1 pixel) and a 1 pixel margin to the character height. */
18866 if (face
->overline_p
)
18869 take_vertical_position_into_account (it
);
18872 append_composite_glyph (it
);
18874 else if (it
->what
== IT_IMAGE
)
18875 produce_image_glyph (it
);
18876 else if (it
->what
== IT_STRETCH
)
18877 produce_stretch_glyph (it
);
18879 /* Accumulate dimensions. Note: can't assume that it->descent > 0
18880 because this isn't true for images with `:ascent 100'. */
18881 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
18882 if (it
->area
== TEXT_AREA
)
18883 it
->current_x
+= it
->pixel_width
;
18885 it
->descent
+= it
->extra_line_spacing
;
18887 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
18888 it
->max_descent
= max (it
->max_descent
, it
->descent
);
18889 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
18890 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
18894 Output LEN glyphs starting at START at the nominal cursor position.
18895 Advance the nominal cursor over the text. The global variable
18896 updated_window contains the window being updated, updated_row is
18897 the glyph row being updated, and updated_area is the area of that
18898 row being updated. */
18901 x_write_glyphs (start
, len
)
18902 struct glyph
*start
;
18907 xassert (updated_window
&& updated_row
);
18910 /* Write glyphs. */
18912 hpos
= start
- updated_row
->glyphs
[updated_area
];
18913 x
= draw_glyphs (updated_window
, output_cursor
.x
,
18914 updated_row
, updated_area
,
18916 DRAW_NORMAL_TEXT
, 0);
18918 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
18919 if (updated_area
== TEXT_AREA
18920 && updated_window
->phys_cursor_on_p
18921 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
18922 && updated_window
->phys_cursor
.hpos
>= hpos
18923 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
18924 updated_window
->phys_cursor_on_p
= 0;
18928 /* Advance the output cursor. */
18929 output_cursor
.hpos
+= len
;
18930 output_cursor
.x
= x
;
18935 Insert LEN glyphs from START at the nominal cursor position. */
18938 x_insert_glyphs (start
, len
)
18939 struct glyph
*start
;
18944 int line_height
, shift_by_width
, shifted_region_width
;
18945 struct glyph_row
*row
;
18946 struct glyph
*glyph
;
18947 int frame_x
, frame_y
, hpos
;
18949 xassert (updated_window
&& updated_row
);
18951 w
= updated_window
;
18952 f
= XFRAME (WINDOW_FRAME (w
));
18954 /* Get the height of the line we are in. */
18956 line_height
= row
->height
;
18958 /* Get the width of the glyphs to insert. */
18959 shift_by_width
= 0;
18960 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
18961 shift_by_width
+= glyph
->pixel_width
;
18963 /* Get the width of the region to shift right. */
18964 shifted_region_width
= (window_box_width (w
, updated_area
)
18969 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
18970 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
18972 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
18973 line_height
, shift_by_width
);
18975 /* Write the glyphs. */
18976 hpos
= start
- row
->glyphs
[updated_area
];
18977 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
18979 DRAW_NORMAL_TEXT
, 0);
18981 /* Advance the output cursor. */
18982 output_cursor
.hpos
+= len
;
18983 output_cursor
.x
+= shift_by_width
;
18989 Erase the current text line from the nominal cursor position
18990 (inclusive) to pixel column TO_X (exclusive). The idea is that
18991 everything from TO_X onward is already erased.
18993 TO_X is a pixel position relative to updated_area of
18994 updated_window. TO_X == -1 means clear to the end of this area. */
18997 x_clear_end_of_line (to_x
)
19001 struct window
*w
= updated_window
;
19002 int max_x
, min_y
, max_y
;
19003 int from_x
, from_y
, to_y
;
19005 xassert (updated_window
&& updated_row
);
19006 f
= XFRAME (w
->frame
);
19008 if (updated_row
->full_width_p
)
19009 max_x
= WINDOW_TOTAL_WIDTH (w
);
19011 max_x
= window_box_width (w
, updated_area
);
19012 max_y
= window_text_bottom_y (w
);
19014 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19015 of window. For TO_X > 0, truncate to end of drawing area. */
19021 to_x
= min (to_x
, max_x
);
19023 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19025 /* Notice if the cursor will be cleared by this operation. */
19026 if (!updated_row
->full_width_p
)
19027 notice_overwritten_cursor (w
, updated_area
,
19028 output_cursor
.x
, -1,
19030 MATRIX_ROW_BOTTOM_Y (updated_row
));
19032 from_x
= output_cursor
.x
;
19034 /* Translate to frame coordinates. */
19035 if (updated_row
->full_width_p
)
19037 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19038 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19042 int area_left
= window_box_left (w
, updated_area
);
19043 from_x
+= area_left
;
19047 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19048 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19049 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19051 /* Prevent inadvertently clearing to end of the X window. */
19052 if (to_x
> from_x
&& to_y
> from_y
)
19055 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
19056 to_x
- from_x
, to_y
- from_y
);
19061 #endif /* HAVE_WINDOW_SYSTEM */
19065 /***********************************************************************
19067 ***********************************************************************/
19069 /* Value is the internal representation of the specified cursor type
19070 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19071 of the bar cursor. */
19073 static enum text_cursor_kinds
19074 get_specified_cursor_type (arg
, width
)
19078 enum text_cursor_kinds type
;
19083 if (EQ (arg
, Qbox
))
19084 return FILLED_BOX_CURSOR
;
19086 if (EQ (arg
, Qhollow
))
19087 return HOLLOW_BOX_CURSOR
;
19089 if (EQ (arg
, Qbar
))
19096 && EQ (XCAR (arg
), Qbar
)
19097 && INTEGERP (XCDR (arg
))
19098 && XINT (XCDR (arg
)) >= 0)
19100 *width
= XINT (XCDR (arg
));
19104 if (EQ (arg
, Qhbar
))
19107 return HBAR_CURSOR
;
19111 && EQ (XCAR (arg
), Qhbar
)
19112 && INTEGERP (XCDR (arg
))
19113 && XINT (XCDR (arg
)) >= 0)
19115 *width
= XINT (XCDR (arg
));
19116 return HBAR_CURSOR
;
19119 /* Treat anything unknown as "hollow box cursor".
19120 It was bad to signal an error; people have trouble fixing
19121 .Xdefaults with Emacs, when it has something bad in it. */
19122 type
= HOLLOW_BOX_CURSOR
;
19127 /* Set the default cursor types for specified frame. */
19129 set_frame_cursor_types (f
, arg
)
19136 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19137 FRAME_CURSOR_WIDTH (f
) = width
;
19139 /* By default, set up the blink-off state depending on the on-state. */
19141 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19144 FRAME_BLINK_OFF_CURSOR (f
)
19145 = get_specified_cursor_type (XCDR (tem
), &width
);
19146 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19149 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19153 /* Return the cursor we want to be displayed in window W. Return
19154 width of bar/hbar cursor through WIDTH arg. Return with
19155 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19156 (i.e. if the `system caret' should track this cursor).
19158 In a mini-buffer window, we want the cursor only to appear if we
19159 are reading input from this window. For the selected window, we
19160 want the cursor type given by the frame parameter or buffer local
19161 setting of cursor-type. If explicitly marked off, draw no cursor.
19162 In all other cases, we want a hollow box cursor. */
19164 static enum text_cursor_kinds
19165 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19167 struct glyph
*glyph
;
19169 int *active_cursor
;
19171 struct frame
*f
= XFRAME (w
->frame
);
19172 struct buffer
*b
= XBUFFER (w
->buffer
);
19173 int cursor_type
= DEFAULT_CURSOR
;
19174 Lisp_Object alt_cursor
;
19175 int non_selected
= 0;
19177 *active_cursor
= 1;
19180 if (cursor_in_echo_area
19181 && FRAME_HAS_MINIBUF_P (f
)
19182 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19184 if (w
== XWINDOW (echo_area_window
))
19186 *width
= FRAME_CURSOR_WIDTH (f
);
19187 return FRAME_DESIRED_CURSOR (f
);
19190 *active_cursor
= 0;
19194 /* Nonselected window or nonselected frame. */
19195 else if (w
!= XWINDOW (f
->selected_window
)
19196 #ifdef HAVE_WINDOW_SYSTEM
19197 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19201 *active_cursor
= 0;
19203 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19209 /* Never display a cursor in a window in which cursor-type is nil. */
19210 if (NILP (b
->cursor_type
))
19213 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19216 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19217 return get_specified_cursor_type (alt_cursor
, width
);
19220 /* Get the normal cursor type for this window. */
19221 if (EQ (b
->cursor_type
, Qt
))
19223 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19224 *width
= FRAME_CURSOR_WIDTH (f
);
19227 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19229 /* Use normal cursor if not blinked off. */
19230 if (!w
->cursor_off_p
)
19232 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19233 if (cursor_type
== FILLED_BOX_CURSOR
)
19234 cursor_type
= HOLLOW_BOX_CURSOR
;
19236 return cursor_type
;
19239 /* Cursor is blinked off, so determine how to "toggle" it. */
19241 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19242 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19243 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19245 /* Then see if frame has specified a specific blink off cursor type. */
19246 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19248 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19249 return FRAME_BLINK_OFF_CURSOR (f
);
19253 /* Some people liked having a permanently visible blinking cursor,
19254 while others had very strong opinions against it. So it was
19255 decided to remove it. KFS 2003-09-03 */
19257 /* Finally perform built-in cursor blinking:
19258 filled box <-> hollow box
19259 wide [h]bar <-> narrow [h]bar
19260 narrow [h]bar <-> no cursor
19261 other type <-> no cursor */
19263 if (cursor_type
== FILLED_BOX_CURSOR
)
19264 return HOLLOW_BOX_CURSOR
;
19266 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19269 return cursor_type
;
19277 #ifdef HAVE_WINDOW_SYSTEM
19279 /* Notice when the text cursor of window W has been completely
19280 overwritten by a drawing operation that outputs glyphs in AREA
19281 starting at X0 and ending at X1 in the line starting at Y0 and
19282 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19283 the rest of the line after X0 has been written. Y coordinates
19284 are window-relative. */
19287 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19289 enum glyph_row_area area
;
19290 int x0
, y0
, x1
, y1
;
19292 int cx0
, cx1
, cy0
, cy1
;
19293 struct glyph_row
*row
;
19295 if (!w
->phys_cursor_on_p
)
19297 if (area
!= TEXT_AREA
)
19300 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19301 if (!row
->displays_text_p
)
19304 if (row
->cursor_in_fringe_p
)
19306 row
->cursor_in_fringe_p
= 0;
19307 draw_fringe_bitmap (w
, row
, 0);
19308 w
->phys_cursor_on_p
= 0;
19312 cx0
= w
->phys_cursor
.x
;
19313 cx1
= cx0
+ w
->phys_cursor_width
;
19314 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19317 /* The cursor image will be completely removed from the
19318 screen if the output area intersects the cursor area in
19319 y-direction. When we draw in [y0 y1[, and some part of
19320 the cursor is at y < y0, that part must have been drawn
19321 before. When scrolling, the cursor is erased before
19322 actually scrolling, so we don't come here. When not
19323 scrolling, the rows above the old cursor row must have
19324 changed, and in this case these rows must have written
19325 over the cursor image.
19327 Likewise if part of the cursor is below y1, with the
19328 exception of the cursor being in the first blank row at
19329 the buffer and window end because update_text_area
19330 doesn't draw that row. (Except when it does, but
19331 that's handled in update_text_area.) */
19333 cy0
= w
->phys_cursor
.y
;
19334 cy1
= cy0
+ w
->phys_cursor_height
;
19335 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19338 w
->phys_cursor_on_p
= 0;
19341 #endif /* HAVE_WINDOW_SYSTEM */
19344 /************************************************************************
19346 ************************************************************************/
19348 #ifdef HAVE_WINDOW_SYSTEM
19351 Fix the display of area AREA of overlapping row ROW in window W. */
19354 x_fix_overlapping_area (w
, row
, area
)
19356 struct glyph_row
*row
;
19357 enum glyph_row_area area
;
19364 for (i
= 0; i
< row
->used
[area
];)
19366 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19368 int start
= i
, start_x
= x
;
19372 x
+= row
->glyphs
[area
][i
].pixel_width
;
19375 while (i
< row
->used
[area
]
19376 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19378 draw_glyphs (w
, start_x
, row
, area
,
19380 DRAW_NORMAL_TEXT
, 1);
19384 x
+= row
->glyphs
[area
][i
].pixel_width
;
19394 Draw the cursor glyph of window W in glyph row ROW. See the
19395 comment of draw_glyphs for the meaning of HL. */
19398 draw_phys_cursor_glyph (w
, row
, hl
)
19400 struct glyph_row
*row
;
19401 enum draw_glyphs_face hl
;
19403 /* If cursor hpos is out of bounds, don't draw garbage. This can
19404 happen in mini-buffer windows when switching between echo area
19405 glyphs and mini-buffer. */
19406 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19408 int on_p
= w
->phys_cursor_on_p
;
19410 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19411 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19413 w
->phys_cursor_on_p
= on_p
;
19415 if (hl
== DRAW_CURSOR
)
19416 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19417 /* When we erase the cursor, and ROW is overlapped by other
19418 rows, make sure that these overlapping parts of other rows
19420 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19422 if (row
> w
->current_matrix
->rows
19423 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19424 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19426 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19427 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19428 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19435 Erase the image of a cursor of window W from the screen. */
19438 erase_phys_cursor (w
)
19441 struct frame
*f
= XFRAME (w
->frame
);
19442 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19443 int hpos
= w
->phys_cursor
.hpos
;
19444 int vpos
= w
->phys_cursor
.vpos
;
19445 int mouse_face_here_p
= 0;
19446 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19447 struct glyph_row
*cursor_row
;
19448 struct glyph
*cursor_glyph
;
19449 enum draw_glyphs_face hl
;
19451 /* No cursor displayed or row invalidated => nothing to do on the
19453 if (w
->phys_cursor_type
== NO_CURSOR
)
19454 goto mark_cursor_off
;
19456 /* VPOS >= active_glyphs->nrows means that window has been resized.
19457 Don't bother to erase the cursor. */
19458 if (vpos
>= active_glyphs
->nrows
)
19459 goto mark_cursor_off
;
19461 /* If row containing cursor is marked invalid, there is nothing we
19463 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19464 if (!cursor_row
->enabled_p
)
19465 goto mark_cursor_off
;
19467 /* If row is completely invisible, don't attempt to delete a cursor which
19468 isn't there. This can happen if cursor is at top of a window, and
19469 we switch to a buffer with a header line in that window. */
19470 if (cursor_row
->visible_height
<= 0)
19471 goto mark_cursor_off
;
19473 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
19474 if (cursor_row
->cursor_in_fringe_p
)
19476 cursor_row
->cursor_in_fringe_p
= 0;
19477 draw_fringe_bitmap (w
, cursor_row
, 0);
19478 goto mark_cursor_off
;
19481 /* This can happen when the new row is shorter than the old one.
19482 In this case, either draw_glyphs or clear_end_of_line
19483 should have cleared the cursor. Note that we wouldn't be
19484 able to erase the cursor in this case because we don't have a
19485 cursor glyph at hand. */
19486 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19487 goto mark_cursor_off
;
19489 /* If the cursor is in the mouse face area, redisplay that when
19490 we clear the cursor. */
19491 if (! NILP (dpyinfo
->mouse_face_window
)
19492 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19493 && (vpos
> dpyinfo
->mouse_face_beg_row
19494 || (vpos
== dpyinfo
->mouse_face_beg_row
19495 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19496 && (vpos
< dpyinfo
->mouse_face_end_row
19497 || (vpos
== dpyinfo
->mouse_face_end_row
19498 && hpos
< dpyinfo
->mouse_face_end_col
))
19499 /* Don't redraw the cursor's spot in mouse face if it is at the
19500 end of a line (on a newline). The cursor appears there, but
19501 mouse highlighting does not. */
19502 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19503 mouse_face_here_p
= 1;
19505 /* Maybe clear the display under the cursor. */
19506 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19509 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19511 cursor_glyph
= get_phys_cursor_glyph (w
);
19512 if (cursor_glyph
== NULL
)
19513 goto mark_cursor_off
;
19515 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19516 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19518 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
,
19519 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19522 /* Erase the cursor by redrawing the character underneath it. */
19523 if (mouse_face_here_p
)
19524 hl
= DRAW_MOUSE_FACE
;
19526 hl
= DRAW_NORMAL_TEXT
;
19527 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19530 w
->phys_cursor_on_p
= 0;
19531 w
->phys_cursor_type
= NO_CURSOR
;
19536 Display or clear cursor of window W. If ON is zero, clear the
19537 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19538 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19541 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19543 int on
, hpos
, vpos
, x
, y
;
19545 struct frame
*f
= XFRAME (w
->frame
);
19546 int new_cursor_type
;
19547 int new_cursor_width
;
19549 struct glyph_row
*glyph_row
;
19550 struct glyph
*glyph
;
19552 /* This is pointless on invisible frames, and dangerous on garbaged
19553 windows and frames; in the latter case, the frame or window may
19554 be in the midst of changing its size, and x and y may be off the
19556 if (! FRAME_VISIBLE_P (f
)
19557 || FRAME_GARBAGED_P (f
)
19558 || vpos
>= w
->current_matrix
->nrows
19559 || hpos
>= w
->current_matrix
->matrix_w
)
19562 /* If cursor is off and we want it off, return quickly. */
19563 if (!on
&& !w
->phys_cursor_on_p
)
19566 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
19567 /* If cursor row is not enabled, we don't really know where to
19568 display the cursor. */
19569 if (!glyph_row
->enabled_p
)
19571 w
->phys_cursor_on_p
= 0;
19576 if (!glyph_row
->exact_window_width_line_p
19577 || hpos
< glyph_row
->used
[TEXT_AREA
])
19578 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19580 xassert (interrupt_input_blocked
);
19582 /* Set new_cursor_type to the cursor we want to be displayed. */
19583 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19584 &new_cursor_width
, &active_cursor
);
19586 /* If cursor is currently being shown and we don't want it to be or
19587 it is in the wrong place, or the cursor type is not what we want,
19589 if (w
->phys_cursor_on_p
19591 || w
->phys_cursor
.x
!= x
19592 || w
->phys_cursor
.y
!= y
19593 || new_cursor_type
!= w
->phys_cursor_type
19594 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19595 && new_cursor_width
!= w
->phys_cursor_width
)))
19596 erase_phys_cursor (w
);
19598 /* Don't check phys_cursor_on_p here because that flag is only set
19599 to zero in some cases where we know that the cursor has been
19600 completely erased, to avoid the extra work of erasing the cursor
19601 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19602 still not be visible, or it has only been partly erased. */
19605 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19606 w
->phys_cursor_height
= glyph_row
->height
;
19608 /* Set phys_cursor_.* before x_draw_.* is called because some
19609 of them may need the information. */
19610 w
->phys_cursor
.x
= x
;
19611 w
->phys_cursor
.y
= glyph_row
->y
;
19612 w
->phys_cursor
.hpos
= hpos
;
19613 w
->phys_cursor
.vpos
= vpos
;
19616 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
19617 new_cursor_type
, new_cursor_width
,
19618 on
, active_cursor
);
19622 /* Switch the display of W's cursor on or off, according to the value
19626 update_window_cursor (w
, on
)
19630 /* Don't update cursor in windows whose frame is in the process
19631 of being deleted. */
19632 if (w
->current_matrix
)
19635 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19636 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19642 /* Call update_window_cursor with parameter ON_P on all leaf windows
19643 in the window tree rooted at W. */
19646 update_cursor_in_window_tree (w
, on_p
)
19652 if (!NILP (w
->hchild
))
19653 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
19654 else if (!NILP (w
->vchild
))
19655 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
19657 update_window_cursor (w
, on_p
);
19659 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
19665 Display the cursor on window W, or clear it, according to ON_P.
19666 Don't change the cursor's position. */
19669 x_update_cursor (f
, on_p
)
19673 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
19678 Clear the cursor of window W to background color, and mark the
19679 cursor as not shown. This is used when the text where the cursor
19680 is is about to be rewritten. */
19686 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
19687 update_window_cursor (w
, 0);
19692 Display the active region described by mouse_face_* according to DRAW. */
19695 show_mouse_face (dpyinfo
, draw
)
19696 Display_Info
*dpyinfo
;
19697 enum draw_glyphs_face draw
;
19699 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
19700 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19702 if (/* If window is in the process of being destroyed, don't bother
19704 w
->current_matrix
!= NULL
19705 /* Don't update mouse highlight if hidden */
19706 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
19707 /* Recognize when we are called to operate on rows that don't exist
19708 anymore. This can happen when a window is split. */
19709 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
19711 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
19712 struct glyph_row
*row
, *first
, *last
;
19714 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
19715 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
19717 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
19719 int start_hpos
, end_hpos
, start_x
;
19721 /* For all but the first row, the highlight starts at column 0. */
19724 start_hpos
= dpyinfo
->mouse_face_beg_col
;
19725 start_x
= dpyinfo
->mouse_face_beg_x
;
19734 end_hpos
= dpyinfo
->mouse_face_end_col
;
19736 end_hpos
= row
->used
[TEXT_AREA
];
19738 if (end_hpos
> start_hpos
)
19740 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
19741 start_hpos
, end_hpos
,
19745 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
19749 /* When we've written over the cursor, arrange for it to
19750 be displayed again. */
19751 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
19754 display_and_set_cursor (w
, 1,
19755 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19756 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19761 /* Change the mouse cursor. */
19762 if (draw
== DRAW_NORMAL_TEXT
)
19763 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
19764 else if (draw
== DRAW_MOUSE_FACE
)
19765 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
19767 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
19771 Clear out the mouse-highlighted active region.
19772 Redraw it un-highlighted first. Value is non-zero if mouse
19773 face was actually drawn unhighlighted. */
19776 clear_mouse_face (dpyinfo
)
19777 Display_Info
*dpyinfo
;
19781 if (!NILP (dpyinfo
->mouse_face_window
))
19783 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
19787 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
19788 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
19789 dpyinfo
->mouse_face_window
= Qnil
;
19790 dpyinfo
->mouse_face_overlay
= Qnil
;
19796 Non-zero if physical cursor of window W is within mouse face. */
19799 cursor_in_mouse_face_p (w
)
19802 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
19803 int in_mouse_face
= 0;
19805 if (WINDOWP (dpyinfo
->mouse_face_window
)
19806 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
19808 int hpos
= w
->phys_cursor
.hpos
;
19809 int vpos
= w
->phys_cursor
.vpos
;
19811 if (vpos
>= dpyinfo
->mouse_face_beg_row
19812 && vpos
<= dpyinfo
->mouse_face_end_row
19813 && (vpos
> dpyinfo
->mouse_face_beg_row
19814 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19815 && (vpos
< dpyinfo
->mouse_face_end_row
19816 || hpos
< dpyinfo
->mouse_face_end_col
19817 || dpyinfo
->mouse_face_past_end
))
19821 return in_mouse_face
;
19827 /* Find the glyph matrix position of buffer position CHARPOS in window
19828 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
19829 current glyphs must be up to date. If CHARPOS is above window
19830 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
19831 of last line in W. In the row containing CHARPOS, stop before glyphs
19832 having STOP as object. */
19834 #if 1 /* This is a version of fast_find_position that's more correct
19835 in the presence of hscrolling, for example. I didn't install
19836 it right away because the problem fixed is minor, it failed
19837 in 20.x as well, and I think it's too risky to install
19838 so near the release of 21.1. 2001-09-25 gerd. */
19841 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
19844 int *hpos
, *vpos
, *x
, *y
;
19847 struct glyph_row
*row
, *first
;
19848 struct glyph
*glyph
, *end
;
19851 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19852 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
19855 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
19857 *x
= *y
= *hpos
= *vpos
= 0;
19862 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
19869 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19871 glyph
= row
->glyphs
[TEXT_AREA
];
19872 end
= glyph
+ row
->used
[TEXT_AREA
];
19874 /* Skip over glyphs not having an object at the start of the row.
19875 These are special glyphs like truncation marks on terminal
19877 if (row
->displays_text_p
)
19879 && INTEGERP (glyph
->object
)
19880 && !EQ (stop
, glyph
->object
)
19881 && glyph
->charpos
< 0)
19883 *x
+= glyph
->pixel_width
;
19888 && !INTEGERP (glyph
->object
)
19889 && !EQ (stop
, glyph
->object
)
19890 && (!BUFFERP (glyph
->object
)
19891 || glyph
->charpos
< charpos
))
19893 *x
+= glyph
->pixel_width
;
19897 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
19904 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
19907 int *hpos
, *vpos
, *x
, *y
;
19912 int maybe_next_line_p
= 0;
19913 int line_start_position
;
19914 int yb
= window_text_bottom_y (w
);
19915 struct glyph_row
*row
, *best_row
;
19916 int row_vpos
, best_row_vpos
;
19919 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19920 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19922 while (row
->y
< yb
)
19924 if (row
->used
[TEXT_AREA
])
19925 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
19927 line_start_position
= 0;
19929 if (line_start_position
> pos
)
19931 /* If the position sought is the end of the buffer,
19932 don't include the blank lines at the bottom of the window. */
19933 else if (line_start_position
== pos
19934 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
19936 maybe_next_line_p
= 1;
19939 else if (line_start_position
> 0)
19942 best_row_vpos
= row_vpos
;
19945 if (row
->y
+ row
->height
>= yb
)
19952 /* Find the right column within BEST_ROW. */
19954 current_x
= best_row
->x
;
19955 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
19957 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
19958 int charpos
= glyph
->charpos
;
19960 if (BUFFERP (glyph
->object
))
19962 if (charpos
== pos
)
19965 *vpos
= best_row_vpos
;
19970 else if (charpos
> pos
)
19973 else if (EQ (glyph
->object
, stop
))
19978 current_x
+= glyph
->pixel_width
;
19981 /* If we're looking for the end of the buffer,
19982 and we didn't find it in the line we scanned,
19983 use the start of the following line. */
19984 if (maybe_next_line_p
)
19989 current_x
= best_row
->x
;
19992 *vpos
= best_row_vpos
;
19993 *hpos
= lastcol
+ 1;
20002 /* Find the position of the glyph for position POS in OBJECT in
20003 window W's current matrix, and return in *X, *Y the pixel
20004 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20006 RIGHT_P non-zero means return the position of the right edge of the
20007 glyph, RIGHT_P zero means return the left edge position.
20009 If no glyph for POS exists in the matrix, return the position of
20010 the glyph with the next smaller position that is in the matrix, if
20011 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20012 exists in the matrix, return the position of the glyph with the
20013 next larger position in OBJECT.
20015 Value is non-zero if a glyph was found. */
20018 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20021 Lisp_Object object
;
20022 int *hpos
, *vpos
, *x
, *y
;
20025 int yb
= window_text_bottom_y (w
);
20026 struct glyph_row
*r
;
20027 struct glyph
*best_glyph
= NULL
;
20028 struct glyph_row
*best_row
= NULL
;
20031 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20032 r
->enabled_p
&& r
->y
< yb
;
20035 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20036 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20039 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20040 if (EQ (g
->object
, object
))
20042 if (g
->charpos
== pos
)
20049 else if (best_glyph
== NULL
20050 || ((abs (g
->charpos
- pos
)
20051 < abs (best_glyph
->charpos
- pos
))
20054 : g
->charpos
> pos
)))
20068 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20072 *x
+= best_glyph
->pixel_width
;
20077 *vpos
= best_row
- w
->current_matrix
->rows
;
20080 return best_glyph
!= NULL
;
20084 /* See if position X, Y is within a hot-spot of an image. */
20087 on_hot_spot_p (hot_spot
, x
, y
)
20088 Lisp_Object hot_spot
;
20091 if (!CONSP (hot_spot
))
20094 if (EQ (XCAR (hot_spot
), Qrect
))
20096 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20097 Lisp_Object rect
= XCDR (hot_spot
);
20101 if (!CONSP (XCAR (rect
)))
20103 if (!CONSP (XCDR (rect
)))
20105 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20107 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20109 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20111 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20115 else if (EQ (XCAR (hot_spot
), Qcircle
))
20117 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20118 Lisp_Object circ
= XCDR (hot_spot
);
20119 Lisp_Object lr
, lx0
, ly0
;
20121 && CONSP (XCAR (circ
))
20122 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20123 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20124 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20126 double r
= XFLOATINT (lr
);
20127 double dx
= XINT (lx0
) - x
;
20128 double dy
= XINT (ly0
) - y
;
20129 return (dx
* dx
+ dy
* dy
<= r
* r
);
20132 else if (EQ (XCAR (hot_spot
), Qpoly
))
20134 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20135 if (VECTORP (XCDR (hot_spot
)))
20137 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20138 Lisp_Object
*poly
= v
->contents
;
20142 Lisp_Object lx
, ly
;
20145 /* Need an even number of coordinates, and at least 3 edges. */
20146 if (n
< 6 || n
& 1)
20149 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20150 If count is odd, we are inside polygon. Pixels on edges
20151 may or may not be included depending on actual geometry of the
20153 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20154 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20156 x0
= XINT (lx
), y0
= XINT (ly
);
20157 for (i
= 0; i
< n
; i
+= 2)
20159 int x1
= x0
, y1
= y0
;
20160 if ((lx
= poly
[i
], !INTEGERP (lx
))
20161 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20163 x0
= XINT (lx
), y0
= XINT (ly
);
20165 /* Does this segment cross the X line? */
20173 if (y
> y0
&& y
> y1
)
20175 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20185 find_hot_spot (map
, x
, y
)
20189 while (CONSP (map
))
20191 if (CONSP (XCAR (map
))
20192 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20200 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20202 doc
: /* Lookup in image map MAP coordinates X and Y.
20203 An image map is an alist where each element has the format (AREA ID PLIST).
20204 An AREA is specified as either a rectangle, a circle, or a polygon:
20205 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20206 pixel coordinates of the upper left and bottom right corners.
20207 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20208 and the radius of the circle; r may be a float or integer.
20209 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20210 vector describes one corner in the polygon.
20211 Returns the alist element for the first matching AREA in MAP. */)
20223 return find_hot_spot (map
, XINT (x
), XINT (y
));
20227 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20229 define_frame_cursor1 (f
, cursor
, pointer
)
20232 Lisp_Object pointer
;
20234 if (!NILP (pointer
))
20236 if (EQ (pointer
, Qarrow
))
20237 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20238 else if (EQ (pointer
, Qhand
))
20239 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20240 else if (EQ (pointer
, Qtext
))
20241 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20242 else if (EQ (pointer
, intern ("hdrag")))
20243 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20244 #ifdef HAVE_X_WINDOWS
20245 else if (EQ (pointer
, intern ("vdrag")))
20246 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20248 else if (EQ (pointer
, intern ("hourglass")))
20249 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20250 else if (EQ (pointer
, Qmodeline
))
20251 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20253 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20256 #ifndef HAVE_CARBON
20257 if (cursor
!= No_Cursor
)
20259 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20261 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
20264 /* Take proper action when mouse has moved to the mode or header line
20265 or marginal area AREA of window W, x-position X and y-position Y.
20266 X is relative to the start of the text display area of W, so the
20267 width of bitmap areas and scroll bars must be subtracted to get a
20268 position relative to the start of the mode line. */
20271 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20274 enum window_part area
;
20276 struct frame
*f
= XFRAME (w
->frame
);
20277 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20278 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20279 Lisp_Object pointer
= Qnil
;
20280 int charpos
, dx
, dy
, width
, height
;
20281 Lisp_Object string
, object
= Qnil
;
20282 Lisp_Object pos
, help
, image
;
20284 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20285 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20286 &object
, &dx
, &dy
, &width
, &height
);
20289 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20290 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20291 &object
, &dx
, &dy
, &width
, &height
);
20296 if (IMAGEP (object
))
20298 Lisp_Object image_map
, hotspot
;
20299 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20301 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20303 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20305 Lisp_Object area_id
, plist
;
20307 area_id
= XCAR (hotspot
);
20308 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20309 If so, we could look for mouse-enter, mouse-leave
20310 properties in PLIST (and do something...). */
20311 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20313 pointer
= Fplist_get (plist
, Qpointer
);
20314 if (NILP (pointer
))
20316 help
= Fplist_get (plist
, Qhelp_echo
);
20319 help_echo_string
= help
;
20320 /* Is this correct? ++kfs */
20321 XSETWINDOW (help_echo_window
, w
);
20322 help_echo_object
= w
->buffer
;
20323 help_echo_pos
= charpos
;
20326 if (NILP (pointer
))
20327 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20331 if (STRINGP (string
))
20333 pos
= make_number (charpos
);
20334 /* If we're on a string with `help-echo' text property, arrange
20335 for the help to be displayed. This is done by setting the
20336 global variable help_echo_string to the help string. */
20337 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20340 help_echo_string
= help
;
20341 XSETWINDOW (help_echo_window
, w
);
20342 help_echo_object
= string
;
20343 help_echo_pos
= charpos
;
20346 if (NILP (pointer
))
20347 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20349 /* Change the mouse pointer according to what is under X/Y. */
20350 if (NILP (pointer
) && area
== ON_MODE_LINE
)
20353 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20354 if (!KEYMAPP (map
))
20355 map
= Fget_text_property (pos
, Qkeymap
, string
);
20356 if (!KEYMAPP (map
))
20357 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20361 define_frame_cursor1 (f
, cursor
, pointer
);
20366 Take proper action when the mouse has moved to position X, Y on
20367 frame F as regards highlighting characters that have mouse-face
20368 properties. Also de-highlighting chars where the mouse was before.
20369 X and Y can be negative or out of range. */
20372 note_mouse_highlight (f
, x
, y
)
20376 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20377 enum window_part part
;
20378 Lisp_Object window
;
20380 Cursor cursor
= No_Cursor
;
20381 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20384 /* When a menu is active, don't highlight because this looks odd. */
20385 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20386 if (popup_activated ())
20390 if (NILP (Vmouse_highlight
)
20391 || !f
->glyphs_initialized_p
)
20394 dpyinfo
->mouse_face_mouse_x
= x
;
20395 dpyinfo
->mouse_face_mouse_y
= y
;
20396 dpyinfo
->mouse_face_mouse_frame
= f
;
20398 if (dpyinfo
->mouse_face_defer
)
20401 if (gc_in_progress
)
20403 dpyinfo
->mouse_face_deferred_gc
= 1;
20407 /* Which window is that in? */
20408 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20410 /* If we were displaying active text in another window, clear that. */
20411 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20412 clear_mouse_face (dpyinfo
);
20414 /* Not on a window -> return. */
20415 if (!WINDOWP (window
))
20418 /* Reset help_echo_string. It will get recomputed below. */
20419 help_echo_string
= Qnil
;
20421 /* Convert to window-relative pixel coordinates. */
20422 w
= XWINDOW (window
);
20423 frame_to_window_pixel_xy (w
, &x
, &y
);
20425 /* Handle tool-bar window differently since it doesn't display a
20427 if (EQ (window
, f
->tool_bar_window
))
20429 note_tool_bar_highlight (f
, x
, y
);
20433 /* Mouse is on the mode, header line or margin? */
20434 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20435 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20437 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20441 if (part
== ON_VERTICAL_BORDER
)
20442 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20443 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20444 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20446 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20448 /* Are we in a window whose display is up to date?
20449 And verify the buffer's text has not changed. */
20450 b
= XBUFFER (w
->buffer
);
20451 if (part
== ON_TEXT
20452 && EQ (w
->window_end_valid
, w
->buffer
)
20453 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20454 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20456 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20457 struct glyph
*glyph
;
20458 Lisp_Object object
;
20459 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20460 Lisp_Object
*overlay_vec
= NULL
;
20461 int len
, noverlays
;
20462 struct buffer
*obuf
;
20463 int obegv
, ozv
, same_region
;
20465 /* Find the glyph under X/Y. */
20466 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20468 /* Look for :pointer property on image. */
20469 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20471 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20472 if (img
!= NULL
&& IMAGEP (img
->spec
))
20474 Lisp_Object image_map
, hotspot
;
20475 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20477 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20479 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20481 Lisp_Object area_id
, plist
;
20483 area_id
= XCAR (hotspot
);
20484 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20485 If so, we could look for mouse-enter, mouse-leave
20486 properties in PLIST (and do something...). */
20487 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20489 pointer
= Fplist_get (plist
, Qpointer
);
20490 if (NILP (pointer
))
20492 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20493 if (!NILP (help_echo_string
))
20495 help_echo_window
= window
;
20496 help_echo_object
= glyph
->object
;
20497 help_echo_pos
= glyph
->charpos
;
20501 if (NILP (pointer
))
20502 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20506 /* Clear mouse face if X/Y not over text. */
20508 || area
!= TEXT_AREA
20509 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20511 if (clear_mouse_face (dpyinfo
))
20512 cursor
= No_Cursor
;
20513 if (NILP (pointer
))
20515 if (area
!= TEXT_AREA
)
20516 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20518 pointer
= Vvoid_text_area_pointer
;
20523 pos
= glyph
->charpos
;
20524 object
= glyph
->object
;
20525 if (!STRINGP (object
) && !BUFFERP (object
))
20528 /* If we get an out-of-range value, return now; avoid an error. */
20529 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20532 /* Make the window's buffer temporarily current for
20533 overlays_at and compute_char_face. */
20534 obuf
= current_buffer
;
20535 current_buffer
= b
;
20541 /* Is this char mouse-active or does it have help-echo? */
20542 position
= make_number (pos
);
20544 if (BUFFERP (object
))
20546 /* Put all the overlays we want in a vector in overlay_vec.
20547 Store the length in len. If there are more than 10, make
20548 enough space for all, and try again. */
20550 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20551 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
20552 if (noverlays
> len
)
20555 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20556 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
20559 /* Sort overlays into increasing priority order. */
20560 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20565 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20566 && vpos
>= dpyinfo
->mouse_face_beg_row
20567 && vpos
<= dpyinfo
->mouse_face_end_row
20568 && (vpos
> dpyinfo
->mouse_face_beg_row
20569 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20570 && (vpos
< dpyinfo
->mouse_face_end_row
20571 || hpos
< dpyinfo
->mouse_face_end_col
20572 || dpyinfo
->mouse_face_past_end
));
20575 cursor
= No_Cursor
;
20577 /* Check mouse-face highlighting. */
20579 /* If there exists an overlay with mouse-face overlapping
20580 the one we are currently highlighting, we have to
20581 check if we enter the overlapping overlay, and then
20582 highlight only that. */
20583 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20584 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20586 /* Find the highest priority overlay that has a mouse-face
20589 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20591 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20592 if (!NILP (mouse_face
))
20593 overlay
= overlay_vec
[i
];
20596 /* If we're actually highlighting the same overlay as
20597 before, there's no need to do that again. */
20598 if (!NILP (overlay
)
20599 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20600 goto check_help_echo
;
20602 dpyinfo
->mouse_face_overlay
= overlay
;
20604 /* Clear the display of the old active region, if any. */
20605 if (clear_mouse_face (dpyinfo
))
20606 cursor
= No_Cursor
;
20608 /* If no overlay applies, get a text property. */
20609 if (NILP (overlay
))
20610 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
20612 /* Handle the overlay case. */
20613 if (!NILP (overlay
))
20615 /* Find the range of text around this char that
20616 should be active. */
20617 Lisp_Object before
, after
;
20620 before
= Foverlay_start (overlay
);
20621 after
= Foverlay_end (overlay
);
20622 /* Record this as the current active region. */
20623 fast_find_position (w
, XFASTINT (before
),
20624 &dpyinfo
->mouse_face_beg_col
,
20625 &dpyinfo
->mouse_face_beg_row
,
20626 &dpyinfo
->mouse_face_beg_x
,
20627 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20629 dpyinfo
->mouse_face_past_end
20630 = !fast_find_position (w
, XFASTINT (after
),
20631 &dpyinfo
->mouse_face_end_col
,
20632 &dpyinfo
->mouse_face_end_row
,
20633 &dpyinfo
->mouse_face_end_x
,
20634 &dpyinfo
->mouse_face_end_y
, Qnil
);
20635 dpyinfo
->mouse_face_window
= window
;
20637 dpyinfo
->mouse_face_face_id
20638 = face_at_buffer_position (w
, pos
, 0, 0,
20640 !dpyinfo
->mouse_face_hidden
);
20642 /* Display it as active. */
20643 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20644 cursor
= No_Cursor
;
20646 /* Handle the text property case. */
20647 else if (!NILP (mouse_face
) && BUFFERP (object
))
20649 /* Find the range of text around this char that
20650 should be active. */
20651 Lisp_Object before
, after
, beginning
, end
;
20654 beginning
= Fmarker_position (w
->start
);
20655 end
= make_number (BUF_Z (XBUFFER (object
))
20656 - XFASTINT (w
->window_end_pos
));
20658 = Fprevious_single_property_change (make_number (pos
+ 1),
20660 object
, beginning
);
20662 = Fnext_single_property_change (position
, Qmouse_face
,
20665 /* Record this as the current active region. */
20666 fast_find_position (w
, XFASTINT (before
),
20667 &dpyinfo
->mouse_face_beg_col
,
20668 &dpyinfo
->mouse_face_beg_row
,
20669 &dpyinfo
->mouse_face_beg_x
,
20670 &dpyinfo
->mouse_face_beg_y
, Qnil
);
20671 dpyinfo
->mouse_face_past_end
20672 = !fast_find_position (w
, XFASTINT (after
),
20673 &dpyinfo
->mouse_face_end_col
,
20674 &dpyinfo
->mouse_face_end_row
,
20675 &dpyinfo
->mouse_face_end_x
,
20676 &dpyinfo
->mouse_face_end_y
, Qnil
);
20677 dpyinfo
->mouse_face_window
= window
;
20679 if (BUFFERP (object
))
20680 dpyinfo
->mouse_face_face_id
20681 = face_at_buffer_position (w
, pos
, 0, 0,
20683 !dpyinfo
->mouse_face_hidden
);
20685 /* Display it as active. */
20686 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20687 cursor
= No_Cursor
;
20689 else if (!NILP (mouse_face
) && STRINGP (object
))
20694 b
= Fprevious_single_property_change (make_number (pos
+ 1),
20697 e
= Fnext_single_property_change (position
, Qmouse_face
,
20700 b
= make_number (0);
20702 e
= make_number (SCHARS (object
) - 1);
20703 fast_find_string_pos (w
, XINT (b
), object
,
20704 &dpyinfo
->mouse_face_beg_col
,
20705 &dpyinfo
->mouse_face_beg_row
,
20706 &dpyinfo
->mouse_face_beg_x
,
20707 &dpyinfo
->mouse_face_beg_y
, 0);
20708 fast_find_string_pos (w
, XINT (e
), object
,
20709 &dpyinfo
->mouse_face_end_col
,
20710 &dpyinfo
->mouse_face_end_row
,
20711 &dpyinfo
->mouse_face_end_x
,
20712 &dpyinfo
->mouse_face_end_y
, 1);
20713 dpyinfo
->mouse_face_past_end
= 0;
20714 dpyinfo
->mouse_face_window
= window
;
20715 dpyinfo
->mouse_face_face_id
20716 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
20717 glyph
->face_id
, 1);
20718 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20719 cursor
= No_Cursor
;
20721 else if (STRINGP (object
) && NILP (mouse_face
))
20723 /* A string which doesn't have mouse-face, but
20724 the text ``under'' it might have. */
20725 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
20726 int start
= MATRIX_ROW_START_CHARPOS (r
);
20728 pos
= string_buffer_position (w
, object
, start
);
20730 mouse_face
= get_char_property_and_overlay (make_number (pos
),
20734 if (!NILP (mouse_face
) && !NILP (overlay
))
20736 Lisp_Object before
= Foverlay_start (overlay
);
20737 Lisp_Object after
= Foverlay_end (overlay
);
20740 /* Note that we might not be able to find position
20741 BEFORE in the glyph matrix if the overlay is
20742 entirely covered by a `display' property. In
20743 this case, we overshoot. So let's stop in
20744 the glyph matrix before glyphs for OBJECT. */
20745 fast_find_position (w
, XFASTINT (before
),
20746 &dpyinfo
->mouse_face_beg_col
,
20747 &dpyinfo
->mouse_face_beg_row
,
20748 &dpyinfo
->mouse_face_beg_x
,
20749 &dpyinfo
->mouse_face_beg_y
,
20752 dpyinfo
->mouse_face_past_end
20753 = !fast_find_position (w
, XFASTINT (after
),
20754 &dpyinfo
->mouse_face_end_col
,
20755 &dpyinfo
->mouse_face_end_row
,
20756 &dpyinfo
->mouse_face_end_x
,
20757 &dpyinfo
->mouse_face_end_y
,
20759 dpyinfo
->mouse_face_window
= window
;
20760 dpyinfo
->mouse_face_face_id
20761 = face_at_buffer_position (w
, pos
, 0, 0,
20763 !dpyinfo
->mouse_face_hidden
);
20765 /* Display it as active. */
20766 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
20767 cursor
= No_Cursor
;
20774 /* Look for a `help-echo' property. */
20775 if (NILP (help_echo_string
)) {
20776 Lisp_Object help
, overlay
;
20778 /* Check overlays first. */
20779 help
= overlay
= Qnil
;
20780 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
20782 overlay
= overlay_vec
[i
];
20783 help
= Foverlay_get (overlay
, Qhelp_echo
);
20788 help_echo_string
= help
;
20789 help_echo_window
= window
;
20790 help_echo_object
= overlay
;
20791 help_echo_pos
= pos
;
20795 Lisp_Object object
= glyph
->object
;
20796 int charpos
= glyph
->charpos
;
20798 /* Try text properties. */
20799 if (STRINGP (object
)
20801 && charpos
< SCHARS (object
))
20803 help
= Fget_text_property (make_number (charpos
),
20804 Qhelp_echo
, object
);
20807 /* If the string itself doesn't specify a help-echo,
20808 see if the buffer text ``under'' it does. */
20809 struct glyph_row
*r
20810 = MATRIX_ROW (w
->current_matrix
, vpos
);
20811 int start
= MATRIX_ROW_START_CHARPOS (r
);
20812 int pos
= string_buffer_position (w
, object
, start
);
20815 help
= Fget_char_property (make_number (pos
),
20816 Qhelp_echo
, w
->buffer
);
20820 object
= w
->buffer
;
20825 else if (BUFFERP (object
)
20828 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
20833 help_echo_string
= help
;
20834 help_echo_window
= window
;
20835 help_echo_object
= object
;
20836 help_echo_pos
= charpos
;
20841 /* Look for a `pointer' property. */
20842 if (NILP (pointer
))
20844 /* Check overlays first. */
20845 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
20846 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
20848 if (NILP (pointer
))
20850 Lisp_Object object
= glyph
->object
;
20851 int charpos
= glyph
->charpos
;
20853 /* Try text properties. */
20854 if (STRINGP (object
)
20856 && charpos
< SCHARS (object
))
20858 pointer
= Fget_text_property (make_number (charpos
),
20860 if (NILP (pointer
))
20862 /* If the string itself doesn't specify a pointer,
20863 see if the buffer text ``under'' it does. */
20864 struct glyph_row
*r
20865 = MATRIX_ROW (w
->current_matrix
, vpos
);
20866 int start
= MATRIX_ROW_START_CHARPOS (r
);
20867 int pos
= string_buffer_position (w
, object
, start
);
20869 pointer
= Fget_char_property (make_number (pos
),
20870 Qpointer
, w
->buffer
);
20873 else if (BUFFERP (object
)
20876 pointer
= Fget_text_property (make_number (charpos
),
20883 current_buffer
= obuf
;
20888 define_frame_cursor1 (f
, cursor
, pointer
);
20893 Clear any mouse-face on window W. This function is part of the
20894 redisplay interface, and is called from try_window_id and similar
20895 functions to ensure the mouse-highlight is off. */
20898 x_clear_window_mouse_face (w
)
20901 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20902 Lisp_Object window
;
20905 XSETWINDOW (window
, w
);
20906 if (EQ (window
, dpyinfo
->mouse_face_window
))
20907 clear_mouse_face (dpyinfo
);
20913 Just discard the mouse face information for frame F, if any.
20914 This is used when the size of F is changed. */
20917 cancel_mouse_face (f
)
20920 Lisp_Object window
;
20921 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20923 window
= dpyinfo
->mouse_face_window
;
20924 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
20926 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20927 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20928 dpyinfo
->mouse_face_window
= Qnil
;
20933 #endif /* HAVE_WINDOW_SYSTEM */
20936 /***********************************************************************
20938 ***********************************************************************/
20940 #ifdef HAVE_WINDOW_SYSTEM
20942 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
20943 which intersects rectangle R. R is in window-relative coordinates. */
20946 expose_area (w
, row
, r
, area
)
20948 struct glyph_row
*row
;
20950 enum glyph_row_area area
;
20952 struct glyph
*first
= row
->glyphs
[area
];
20953 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
20954 struct glyph
*last
;
20955 int first_x
, start_x
, x
;
20957 if (area
== TEXT_AREA
&& row
->fill_line_p
)
20958 /* If row extends face to end of line write the whole line. */
20959 draw_glyphs (w
, 0, row
, area
,
20960 0, row
->used
[area
],
20961 DRAW_NORMAL_TEXT
, 0);
20964 /* Set START_X to the window-relative start position for drawing glyphs of
20965 AREA. The first glyph of the text area can be partially visible.
20966 The first glyphs of other areas cannot. */
20967 start_x
= window_box_left_offset (w
, area
);
20969 if (area
== TEXT_AREA
)
20972 /* Find the first glyph that must be redrawn. */
20974 && x
+ first
->pixel_width
< r
->x
)
20976 x
+= first
->pixel_width
;
20980 /* Find the last one. */
20984 && x
< r
->x
+ r
->width
)
20986 x
+= last
->pixel_width
;
20992 draw_glyphs (w
, first_x
- start_x
, row
, area
,
20993 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
20994 DRAW_NORMAL_TEXT
, 0);
20999 /* Redraw the parts of the glyph row ROW on window W intersecting
21000 rectangle R. R is in window-relative coordinates. Value is
21001 non-zero if mouse-face was overwritten. */
21004 expose_line (w
, row
, r
)
21006 struct glyph_row
*row
;
21009 xassert (row
->enabled_p
);
21011 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21012 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21013 0, row
->used
[TEXT_AREA
],
21014 DRAW_NORMAL_TEXT
, 0);
21017 if (row
->used
[LEFT_MARGIN_AREA
])
21018 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21019 if (row
->used
[TEXT_AREA
])
21020 expose_area (w
, row
, r
, TEXT_AREA
);
21021 if (row
->used
[RIGHT_MARGIN_AREA
])
21022 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21023 draw_row_fringe_bitmaps (w
, row
);
21026 return row
->mouse_face_p
;
21030 /* Redraw those parts of glyphs rows during expose event handling that
21031 overlap other rows. Redrawing of an exposed line writes over parts
21032 of lines overlapping that exposed line; this function fixes that.
21034 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21035 row in W's current matrix that is exposed and overlaps other rows.
21036 LAST_OVERLAPPING_ROW is the last such row. */
21039 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21041 struct glyph_row
*first_overlapping_row
;
21042 struct glyph_row
*last_overlapping_row
;
21044 struct glyph_row
*row
;
21046 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21047 if (row
->overlapping_p
)
21049 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21051 if (row
->used
[LEFT_MARGIN_AREA
])
21052 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21054 if (row
->used
[TEXT_AREA
])
21055 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21057 if (row
->used
[RIGHT_MARGIN_AREA
])
21058 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21063 /* Return non-zero if W's cursor intersects rectangle R. */
21066 phys_cursor_in_rect_p (w
, r
)
21070 XRectangle cr
, result
;
21071 struct glyph
*cursor_glyph
;
21073 cursor_glyph
= get_phys_cursor_glyph (w
);
21076 /* r is relative to W's box, but w->phys_cursor.x is relative
21077 to left edge of W's TEXT area. Adjust it. */
21078 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21079 cr
.y
= w
->phys_cursor
.y
;
21080 cr
.width
= cursor_glyph
->pixel_width
;
21081 cr
.height
= w
->phys_cursor_height
;
21082 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21083 I assume the effect is the same -- and this is portable. */
21084 return x_intersect_rectangles (&cr
, r
, &result
);
21092 Draw a vertical window border to the right of window W if W doesn't
21093 have vertical scroll bars. */
21096 x_draw_vertical_border (w
)
21099 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21101 /* We could do better, if we knew what type of scroll-bar the adjacent
21102 windows (on either side) have... But we don't :-(
21103 However, I think this works ok. ++KFS 2003-04-25 */
21105 /* Redraw borders between horizontally adjacent windows. Don't
21106 do it for frames with vertical scroll bars because either the
21107 right scroll bar of a window, or the left scroll bar of its
21108 neighbor will suffice as a border. */
21109 if (!WINDOW_RIGHTMOST_P (w
)
21110 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21112 int x0
, x1
, y0
, y1
;
21114 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21117 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
21119 else if (!WINDOW_LEFTMOST_P (w
)
21120 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21122 int x0
, x1
, y0
, y1
;
21124 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21127 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
21132 /* Redraw the part of window W intersection rectangle FR. Pixel
21133 coordinates in FR are frame-relative. Call this function with
21134 input blocked. Value is non-zero if the exposure overwrites
21138 expose_window (w
, fr
)
21142 struct frame
*f
= XFRAME (w
->frame
);
21144 int mouse_face_overwritten_p
= 0;
21146 /* If window is not yet fully initialized, do nothing. This can
21147 happen when toolkit scroll bars are used and a window is split.
21148 Reconfiguring the scroll bar will generate an expose for a newly
21150 if (w
->current_matrix
== NULL
)
21153 /* When we're currently updating the window, display and current
21154 matrix usually don't agree. Arrange for a thorough display
21156 if (w
== updated_window
)
21158 SET_FRAME_GARBAGED (f
);
21162 /* Frame-relative pixel rectangle of W. */
21163 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21164 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21165 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21166 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21168 if (x_intersect_rectangles (fr
, &wr
, &r
))
21170 int yb
= window_text_bottom_y (w
);
21171 struct glyph_row
*row
;
21172 int cursor_cleared_p
;
21173 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21175 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21176 r
.x
, r
.y
, r
.width
, r
.height
));
21178 /* Convert to window coordinates. */
21179 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21180 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21182 /* Turn off the cursor. */
21183 if (!w
->pseudo_window_p
21184 && phys_cursor_in_rect_p (w
, &r
))
21186 x_clear_cursor (w
);
21187 cursor_cleared_p
= 1;
21190 cursor_cleared_p
= 0;
21192 /* Update lines intersecting rectangle R. */
21193 first_overlapping_row
= last_overlapping_row
= NULL
;
21194 for (row
= w
->current_matrix
->rows
;
21199 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21201 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21202 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21203 || (r
.y
>= y0
&& r
.y
< y1
)
21204 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21206 if (row
->overlapping_p
)
21208 if (first_overlapping_row
== NULL
)
21209 first_overlapping_row
= row
;
21210 last_overlapping_row
= row
;
21213 if (expose_line (w
, row
, &r
))
21214 mouse_face_overwritten_p
= 1;
21221 /* Display the mode line if there is one. */
21222 if (WINDOW_WANTS_MODELINE_P (w
)
21223 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21225 && row
->y
< r
.y
+ r
.height
)
21227 if (expose_line (w
, row
, &r
))
21228 mouse_face_overwritten_p
= 1;
21231 if (!w
->pseudo_window_p
)
21233 /* Fix the display of overlapping rows. */
21234 if (first_overlapping_row
)
21235 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21237 /* Draw border between windows. */
21238 x_draw_vertical_border (w
);
21240 /* Turn the cursor on again. */
21241 if (cursor_cleared_p
)
21242 update_window_cursor (w
, 1);
21247 /* Display scroll bar for this window. */
21248 if (!NILP (w
->vertical_scroll_bar
))
21251 If this doesn't work here (maybe some header files are missing),
21252 make a function in macterm.c and call it to do the job! */
21254 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21260 return mouse_face_overwritten_p
;
21265 /* Redraw (parts) of all windows in the window tree rooted at W that
21266 intersect R. R contains frame pixel coordinates. Value is
21267 non-zero if the exposure overwrites mouse-face. */
21270 expose_window_tree (w
, r
)
21274 struct frame
*f
= XFRAME (w
->frame
);
21275 int mouse_face_overwritten_p
= 0;
21277 while (w
&& !FRAME_GARBAGED_P (f
))
21279 if (!NILP (w
->hchild
))
21280 mouse_face_overwritten_p
21281 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21282 else if (!NILP (w
->vchild
))
21283 mouse_face_overwritten_p
21284 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21286 mouse_face_overwritten_p
|= expose_window (w
, r
);
21288 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21291 return mouse_face_overwritten_p
;
21296 Redisplay an exposed area of frame F. X and Y are the upper-left
21297 corner of the exposed rectangle. W and H are width and height of
21298 the exposed area. All are pixel values. W or H zero means redraw
21299 the entire frame. */
21302 expose_frame (f
, x
, y
, w
, h
)
21307 int mouse_face_overwritten_p
= 0;
21309 TRACE ((stderr
, "expose_frame "));
21311 /* No need to redraw if frame will be redrawn soon. */
21312 if (FRAME_GARBAGED_P (f
))
21314 TRACE ((stderr
, " garbaged\n"));
21319 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21320 or deactivated here, for unknown reasons, activated scroll bars
21321 are shown in deactivated frames in some instances. */
21322 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21323 activate_scroll_bars (f
);
21325 deactivate_scroll_bars (f
);
21328 /* If basic faces haven't been realized yet, there is no point in
21329 trying to redraw anything. This can happen when we get an expose
21330 event while Emacs is starting, e.g. by moving another window. */
21331 if (FRAME_FACE_CACHE (f
) == NULL
21332 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21334 TRACE ((stderr
, " no faces\n"));
21338 if (w
== 0 || h
== 0)
21341 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21342 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21352 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21353 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21355 if (WINDOWP (f
->tool_bar_window
))
21356 mouse_face_overwritten_p
21357 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21359 #ifdef HAVE_X_WINDOWS
21361 #ifndef USE_X_TOOLKIT
21362 if (WINDOWP (f
->menu_bar_window
))
21363 mouse_face_overwritten_p
21364 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21365 #endif /* not USE_X_TOOLKIT */
21369 /* Some window managers support a focus-follows-mouse style with
21370 delayed raising of frames. Imagine a partially obscured frame,
21371 and moving the mouse into partially obscured mouse-face on that
21372 frame. The visible part of the mouse-face will be highlighted,
21373 then the WM raises the obscured frame. With at least one WM, KDE
21374 2.1, Emacs is not getting any event for the raising of the frame
21375 (even tried with SubstructureRedirectMask), only Expose events.
21376 These expose events will draw text normally, i.e. not
21377 highlighted. Which means we must redo the highlight here.
21378 Subsume it under ``we love X''. --gerd 2001-08-15 */
21379 /* Included in Windows version because Windows most likely does not
21380 do the right thing if any third party tool offers
21381 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21382 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21384 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21385 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21387 int x
= dpyinfo
->mouse_face_mouse_x
;
21388 int y
= dpyinfo
->mouse_face_mouse_y
;
21389 clear_mouse_face (dpyinfo
);
21390 note_mouse_highlight (f
, x
, y
);
21397 Determine the intersection of two rectangles R1 and R2. Return
21398 the intersection in *RESULT. Value is non-zero if RESULT is not
21402 x_intersect_rectangles (r1
, r2
, result
)
21403 XRectangle
*r1
, *r2
, *result
;
21405 XRectangle
*left
, *right
;
21406 XRectangle
*upper
, *lower
;
21407 int intersection_p
= 0;
21409 /* Rearrange so that R1 is the left-most rectangle. */
21411 left
= r1
, right
= r2
;
21413 left
= r2
, right
= r1
;
21415 /* X0 of the intersection is right.x0, if this is inside R1,
21416 otherwise there is no intersection. */
21417 if (right
->x
<= left
->x
+ left
->width
)
21419 result
->x
= right
->x
;
21421 /* The right end of the intersection is the minimum of the
21422 the right ends of left and right. */
21423 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21426 /* Same game for Y. */
21428 upper
= r1
, lower
= r2
;
21430 upper
= r2
, lower
= r1
;
21432 /* The upper end of the intersection is lower.y0, if this is inside
21433 of upper. Otherwise, there is no intersection. */
21434 if (lower
->y
<= upper
->y
+ upper
->height
)
21436 result
->y
= lower
->y
;
21438 /* The lower end of the intersection is the minimum of the lower
21439 ends of upper and lower. */
21440 result
->height
= (min (lower
->y
+ lower
->height
,
21441 upper
->y
+ upper
->height
)
21443 intersection_p
= 1;
21447 return intersection_p
;
21450 #endif /* HAVE_WINDOW_SYSTEM */
21453 /***********************************************************************
21455 ***********************************************************************/
21460 Vwith_echo_area_save_vector
= Qnil
;
21461 staticpro (&Vwith_echo_area_save_vector
);
21463 Vmessage_stack
= Qnil
;
21464 staticpro (&Vmessage_stack
);
21466 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21467 staticpro (&Qinhibit_redisplay
);
21469 message_dolog_marker1
= Fmake_marker ();
21470 staticpro (&message_dolog_marker1
);
21471 message_dolog_marker2
= Fmake_marker ();
21472 staticpro (&message_dolog_marker2
);
21473 message_dolog_marker3
= Fmake_marker ();
21474 staticpro (&message_dolog_marker3
);
21477 defsubr (&Sdump_frame_glyph_matrix
);
21478 defsubr (&Sdump_glyph_matrix
);
21479 defsubr (&Sdump_glyph_row
);
21480 defsubr (&Sdump_tool_bar_row
);
21481 defsubr (&Strace_redisplay
);
21482 defsubr (&Strace_to_stderr
);
21484 #ifdef HAVE_WINDOW_SYSTEM
21485 defsubr (&Stool_bar_lines_needed
);
21486 defsubr (&Slookup_image_map
);
21488 defsubr (&Sformat_mode_line
);
21490 staticpro (&Qmenu_bar_update_hook
);
21491 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21493 staticpro (&Qoverriding_terminal_local_map
);
21494 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21496 staticpro (&Qoverriding_local_map
);
21497 Qoverriding_local_map
= intern ("overriding-local-map");
21499 staticpro (&Qwindow_scroll_functions
);
21500 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21502 staticpro (&Qredisplay_end_trigger_functions
);
21503 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21505 staticpro (&Qinhibit_point_motion_hooks
);
21506 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21508 QCdata
= intern (":data");
21509 staticpro (&QCdata
);
21510 Qdisplay
= intern ("display");
21511 staticpro (&Qdisplay
);
21512 Qspace_width
= intern ("space-width");
21513 staticpro (&Qspace_width
);
21514 Qraise
= intern ("raise");
21515 staticpro (&Qraise
);
21516 Qspace
= intern ("space");
21517 staticpro (&Qspace
);
21518 Qmargin
= intern ("margin");
21519 staticpro (&Qmargin
);
21520 Qpointer
= intern ("pointer");
21521 staticpro (&Qpointer
);
21522 Qleft_margin
= intern ("left-margin");
21523 staticpro (&Qleft_margin
);
21524 Qright_margin
= intern ("right-margin");
21525 staticpro (&Qright_margin
);
21526 QCalign_to
= intern (":align-to");
21527 staticpro (&QCalign_to
);
21528 QCrelative_width
= intern (":relative-width");
21529 staticpro (&QCrelative_width
);
21530 QCrelative_height
= intern (":relative-height");
21531 staticpro (&QCrelative_height
);
21532 QCeval
= intern (":eval");
21533 staticpro (&QCeval
);
21534 QCpropertize
= intern (":propertize");
21535 staticpro (&QCpropertize
);
21536 QCfile
= intern (":file");
21537 staticpro (&QCfile
);
21538 Qfontified
= intern ("fontified");
21539 staticpro (&Qfontified
);
21540 Qfontification_functions
= intern ("fontification-functions");
21541 staticpro (&Qfontification_functions
);
21542 Qtrailing_whitespace
= intern ("trailing-whitespace");
21543 staticpro (&Qtrailing_whitespace
);
21544 Qimage
= intern ("image");
21545 staticpro (&Qimage
);
21546 QCmap
= intern (":map");
21547 staticpro (&QCmap
);
21548 QCpointer
= intern (":pointer");
21549 staticpro (&QCpointer
);
21550 Qrect
= intern ("rect");
21551 staticpro (&Qrect
);
21552 Qcircle
= intern ("circle");
21553 staticpro (&Qcircle
);
21554 Qpoly
= intern ("poly");
21555 staticpro (&Qpoly
);
21556 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21557 staticpro (&Qmessage_truncate_lines
);
21558 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21559 staticpro (&Qcursor_in_non_selected_windows
);
21560 Qgrow_only
= intern ("grow-only");
21561 staticpro (&Qgrow_only
);
21562 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21563 staticpro (&Qinhibit_menubar_update
);
21564 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21565 staticpro (&Qinhibit_eval_during_redisplay
);
21566 Qposition
= intern ("position");
21567 staticpro (&Qposition
);
21568 Qbuffer_position
= intern ("buffer-position");
21569 staticpro (&Qbuffer_position
);
21570 Qobject
= intern ("object");
21571 staticpro (&Qobject
);
21572 Qbar
= intern ("bar");
21574 Qhbar
= intern ("hbar");
21575 staticpro (&Qhbar
);
21576 Qbox
= intern ("box");
21578 Qhollow
= intern ("hollow");
21579 staticpro (&Qhollow
);
21580 Qhand
= intern ("hand");
21581 staticpro (&Qhand
);
21582 Qarrow
= intern ("arrow");
21583 staticpro (&Qarrow
);
21584 Qtext
= intern ("text");
21585 staticpro (&Qtext
);
21586 Qrisky_local_variable
= intern ("risky-local-variable");
21587 staticpro (&Qrisky_local_variable
);
21588 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21589 staticpro (&Qinhibit_free_realized_faces
);
21591 list_of_error
= Fcons (intern ("error"), Qnil
);
21592 staticpro (&list_of_error
);
21594 Qlast_arrow_position
= intern ("last-arrow-position");
21595 staticpro (&Qlast_arrow_position
);
21596 Qlast_arrow_string
= intern ("last-arrow-string");
21597 staticpro (&Qlast_arrow_string
);
21599 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
21600 staticpro (&Qoverlay_arrow_string
);
21601 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
21602 staticpro (&Qoverlay_arrow_bitmap
);
21604 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21605 staticpro (&echo_buffer
[0]);
21606 staticpro (&echo_buffer
[1]);
21608 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21609 staticpro (&echo_area_buffer
[0]);
21610 staticpro (&echo_area_buffer
[1]);
21612 Vmessages_buffer_name
= build_string ("*Messages*");
21613 staticpro (&Vmessages_buffer_name
);
21615 mode_line_proptrans_alist
= Qnil
;
21616 staticpro (&mode_line_proptrans_alist
);
21618 mode_line_string_list
= Qnil
;
21619 staticpro (&mode_line_string_list
);
21621 help_echo_string
= Qnil
;
21622 staticpro (&help_echo_string
);
21623 help_echo_object
= Qnil
;
21624 staticpro (&help_echo_object
);
21625 help_echo_window
= Qnil
;
21626 staticpro (&help_echo_window
);
21627 previous_help_echo_string
= Qnil
;
21628 staticpro (&previous_help_echo_string
);
21629 help_echo_pos
= -1;
21631 #ifdef HAVE_WINDOW_SYSTEM
21632 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
21633 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
21634 For example, if a block cursor is over a tab, it will be drawn as
21635 wide as that tab on the display. */);
21636 x_stretch_cursor_p
= 0;
21639 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
21640 doc
: /* *Non-nil means highlight trailing whitespace.
21641 The face used for trailing whitespace is `trailing-whitespace'. */);
21642 Vshow_trailing_whitespace
= Qnil
;
21644 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
21645 doc
: /* *The pointer shape to show in void text areas.
21646 Nil means to show the text pointer. Other options are `arrow', `text',
21647 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
21648 Vvoid_text_area_pointer
= Qarrow
;
21650 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
21651 doc
: /* Non-nil means don't actually do any redisplay.
21652 This is used for internal purposes. */);
21653 Vinhibit_redisplay
= Qnil
;
21655 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
21656 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
21657 Vglobal_mode_string
= Qnil
;
21659 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
21660 doc
: /* Marker for where to display an arrow on top of the buffer text.
21661 This must be the beginning of a line in order to work.
21662 See also `overlay-arrow-string'. */);
21663 Voverlay_arrow_position
= Qnil
;
21665 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
21666 doc
: /* String to display as an arrow in non-window frames.
21667 See also `overlay-arrow-position'. */);
21668 Voverlay_arrow_string
= Qnil
;
21670 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
21671 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
21672 The symbols on this list are examined during redisplay to determine
21673 where to display overlay arrows. */);
21674 Voverlay_arrow_variable_list
21675 = Fcons (intern ("overlay-arrow-position"), Qnil
);
21677 DEFVAR_INT ("scroll-step", &scroll_step
,
21678 doc
: /* *The number of lines to try scrolling a window by when point moves out.
21679 If that fails to bring point back on frame, point is centered instead.
21680 If this is zero, point is always centered after it moves off frame.
21681 If you want scrolling to always be a line at a time, you should set
21682 `scroll-conservatively' to a large value rather than set this to 1. */);
21684 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
21685 doc
: /* *Scroll up to this many lines, to bring point back on screen.
21686 A value of zero means to scroll the text to center point vertically
21687 in the window. */);
21688 scroll_conservatively
= 0;
21690 DEFVAR_INT ("scroll-margin", &scroll_margin
,
21691 doc
: /* *Number of lines of margin at the top and bottom of a window.
21692 Recenter the window whenever point gets within this many lines
21693 of the top or bottom of the window. */);
21696 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
21697 doc
: /* Pixels per inch on current display.
21698 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
21699 Vdisplay_pixels_per_inch
= make_float (72.0);
21702 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
21705 DEFVAR_BOOL ("truncate-partial-width-windows",
21706 &truncate_partial_width_windows
,
21707 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
21708 truncate_partial_width_windows
= 1;
21710 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
21711 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
21712 Any other value means to use the appropriate face, `mode-line',
21713 `header-line', or `menu' respectively. */);
21714 mode_line_inverse_video
= 1;
21716 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
21717 doc
: /* *Maximum buffer size for which line number should be displayed.
21718 If the buffer is bigger than this, the line number does not appear
21719 in the mode line. A value of nil means no limit. */);
21720 Vline_number_display_limit
= Qnil
;
21722 DEFVAR_INT ("line-number-display-limit-width",
21723 &line_number_display_limit_width
,
21724 doc
: /* *Maximum line width (in characters) for line number display.
21725 If the average length of the lines near point is bigger than this, then the
21726 line number may be omitted from the mode line. */);
21727 line_number_display_limit_width
= 200;
21729 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
21730 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
21731 highlight_nonselected_windows
= 0;
21733 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
21734 doc
: /* Non-nil if more than one frame is visible on this display.
21735 Minibuffer-only frames don't count, but iconified frames do.
21736 This variable is not guaranteed to be accurate except while processing
21737 `frame-title-format' and `icon-title-format'. */);
21739 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
21740 doc
: /* Template for displaying the title bar of visible frames.
21741 \(Assuming the window manager supports this feature.)
21742 This variable has the same structure as `mode-line-format' (which see),
21743 and is used only on frames for which no explicit name has been set
21744 \(see `modify-frame-parameters'). */);
21746 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
21747 doc
: /* Template for displaying the title bar of an iconified frame.
21748 \(Assuming the window manager supports this feature.)
21749 This variable has the same structure as `mode-line-format' (which see),
21750 and is used only on frames for which no explicit name has been set
21751 \(see `modify-frame-parameters'). */);
21753 = Vframe_title_format
21754 = Fcons (intern ("multiple-frames"),
21755 Fcons (build_string ("%b"),
21756 Fcons (Fcons (empty_string
,
21757 Fcons (intern ("invocation-name"),
21758 Fcons (build_string ("@"),
21759 Fcons (intern ("system-name"),
21763 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
21764 doc
: /* Maximum number of lines to keep in the message log buffer.
21765 If nil, disable message logging. If t, log messages but don't truncate
21766 the buffer when it becomes large. */);
21767 Vmessage_log_max
= make_number (50);
21769 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
21770 doc
: /* Functions called before redisplay, if window sizes have changed.
21771 The value should be a list of functions that take one argument.
21772 Just before redisplay, for each frame, if any of its windows have changed
21773 size since the last redisplay, or have been split or deleted,
21774 all the functions in the list are called, with the frame as argument. */);
21775 Vwindow_size_change_functions
= Qnil
;
21777 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
21778 doc
: /* List of Functions to call before redisplaying a window with scrolling.
21779 Each function is called with two arguments, the window
21780 and its new display-start position. Note that the value of `window-end'
21781 is not valid when these functions are called. */);
21782 Vwindow_scroll_functions
= Qnil
;
21784 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
21785 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
21786 mouse_autoselect_window
= 0;
21788 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
21789 doc
: /* *Non-nil means automatically resize tool-bars.
21790 This increases a tool-bar's height if not all tool-bar items are visible.
21791 It decreases a tool-bar's height when it would display blank lines
21793 auto_resize_tool_bars_p
= 1;
21795 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
21796 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
21797 auto_raise_tool_bar_buttons_p
= 1;
21799 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
21800 doc
: /* *Margin around tool-bar buttons in pixels.
21801 If an integer, use that for both horizontal and vertical margins.
21802 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
21803 HORZ specifying the horizontal margin, and VERT specifying the
21804 vertical margin. */);
21805 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
21807 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
21808 doc
: /* *Relief thickness of tool-bar buttons. */);
21809 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
21811 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
21812 doc
: /* List of functions to call to fontify regions of text.
21813 Each function is called with one argument POS. Functions must
21814 fontify a region starting at POS in the current buffer, and give
21815 fontified regions the property `fontified'. */);
21816 Vfontification_functions
= Qnil
;
21817 Fmake_variable_buffer_local (Qfontification_functions
);
21819 DEFVAR_BOOL ("unibyte-display-via-language-environment",
21820 &unibyte_display_via_language_environment
,
21821 doc
: /* *Non-nil means display unibyte text according to language environment.
21822 Specifically this means that unibyte non-ASCII characters
21823 are displayed by converting them to the equivalent multibyte characters
21824 according to the current language environment. As a result, they are
21825 displayed according to the current fontset. */);
21826 unibyte_display_via_language_environment
= 0;
21828 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
21829 doc
: /* *Maximum height for resizing mini-windows.
21830 If a float, it specifies a fraction of the mini-window frame's height.
21831 If an integer, it specifies a number of lines. */);
21832 Vmax_mini_window_height
= make_float (0.25);
21834 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
21835 doc
: /* *How to resize mini-windows.
21836 A value of nil means don't automatically resize mini-windows.
21837 A value of t means resize them to fit the text displayed in them.
21838 A value of `grow-only', the default, means let mini-windows grow
21839 only, until their display becomes empty, at which point the windows
21840 go back to their normal size. */);
21841 Vresize_mini_windows
= Qgrow_only
;
21843 DEFVAR_LISP ("cursor-in-non-selected-windows",
21844 &Vcursor_in_non_selected_windows
,
21845 doc
: /* *Cursor type to display in non-selected windows.
21846 t means to use hollow box cursor. See `cursor-type' for other values. */);
21847 Vcursor_in_non_selected_windows
= Qt
;
21849 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
21850 doc
: /* Alist specifying how to blink the cursor off.
21851 Each element has the form (ON-STATE . OFF-STATE). Whenever the
21852 `cursor-type' frame-parameter or variable equals ON-STATE,
21853 comparing using `equal', Emacs uses OFF-STATE to specify
21854 how to blink it off. */);
21855 Vblink_cursor_alist
= Qnil
;
21857 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
21858 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
21859 automatic_hscrolling_p
= 1;
21861 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
21862 doc
: /* *How many columns away from the window edge point is allowed to get
21863 before automatic hscrolling will horizontally scroll the window. */);
21864 hscroll_margin
= 5;
21866 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
21867 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
21868 When point is less than `automatic-hscroll-margin' columns from the window
21869 edge, automatic hscrolling will scroll the window by the amount of columns
21870 determined by this variable. If its value is a positive integer, scroll that
21871 many columns. If it's a positive floating-point number, it specifies the
21872 fraction of the window's width to scroll. If it's nil or zero, point will be
21873 centered horizontally after the scroll. Any other value, including negative
21874 numbers, are treated as if the value were zero.
21876 Automatic hscrolling always moves point outside the scroll margin, so if
21877 point was more than scroll step columns inside the margin, the window will
21878 scroll more than the value given by the scroll step.
21880 Note that the lower bound for automatic hscrolling specified by `scroll-left'
21881 and `scroll-right' overrides this variable's effect. */);
21882 Vhscroll_step
= make_number (0);
21884 DEFVAR_LISP ("image-types", &Vimage_types
,
21885 doc
: /* List of supported image types.
21886 Each element of the list is a symbol for a supported image type. */);
21887 Vimage_types
= Qnil
;
21889 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
21890 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
21891 Bind this around calls to `message' to let it take effect. */);
21892 message_truncate_lines
= 0;
21894 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
21895 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
21896 Can be used to update submenus whose contents should vary. */);
21897 Vmenu_bar_update_hook
= Qnil
;
21899 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
21900 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
21901 inhibit_menubar_update
= 0;
21903 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
21904 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
21905 inhibit_eval_during_redisplay
= 0;
21907 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
21908 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
21909 inhibit_free_realized_faces
= 0;
21912 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
21913 doc
: /* Inhibit try_window_id display optimization. */);
21914 inhibit_try_window_id
= 0;
21916 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
21917 doc
: /* Inhibit try_window_reusing display optimization. */);
21918 inhibit_try_window_reusing
= 0;
21920 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
21921 doc
: /* Inhibit try_cursor_movement display optimization. */);
21922 inhibit_try_cursor_movement
= 0;
21923 #endif /* GLYPH_DEBUG */
21927 /* Initialize this module when Emacs starts. */
21932 Lisp_Object root_window
;
21933 struct window
*mini_w
;
21935 current_header_line_height
= current_mode_line_height
= -1;
21937 CHARPOS (this_line_start_pos
) = 0;
21939 mini_w
= XWINDOW (minibuf_window
);
21940 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
21942 if (!noninteractive
)
21944 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
21947 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
21948 set_window_height (root_window
,
21949 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
21951 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
21952 set_window_height (minibuf_window
, 1, 0);
21954 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
21955 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
21957 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
21958 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
21959 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
21961 /* The default ellipsis glyphs `...'. */
21962 for (i
= 0; i
< 3; ++i
)
21963 default_invis_vector
[i
] = make_number ('.');
21967 /* Allocate the buffer for frame titles.
21968 Also used for `format-mode-line'. */
21970 frame_title_buf
= (char *) xmalloc (size
);
21971 frame_title_buf_end
= frame_title_buf
+ size
;
21972 frame_title_ptr
= NULL
;
21975 help_echo_showing_p
= 0;
21979 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
21980 (do not change this comment) */