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
;
306 Lisp_Object Qmargin
, Qpointer
;
307 Lisp_Object Qline_height
, Qtotal
;
308 extern Lisp_Object Qheight
;
309 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
310 extern Lisp_Object Qscroll_bar
;
312 /* Non-nil means highlight trailing whitespace. */
314 Lisp_Object Vshow_trailing_whitespace
;
316 #ifdef HAVE_WINDOW_SYSTEM
317 extern Lisp_Object Voverflow_newline_into_fringe
;
319 /* Test if overflow newline into fringe. Called with iterator IT
320 at or past right window margin, and with IT->current_x set. */
322 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
323 (!NILP (Voverflow_newline_into_fringe) \
324 && FRAME_WINDOW_P (it->f) \
325 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
326 && it->current_x == it->last_visible_x)
328 #endif /* HAVE_WINDOW_SYSTEM */
330 /* Non-nil means show the text cursor in void text areas
331 i.e. in blank areas after eol and eob. This used to be
332 the default in 21.3. */
334 Lisp_Object Vvoid_text_area_pointer
;
336 /* Name of the face used to highlight trailing whitespace. */
338 Lisp_Object Qtrailing_whitespace
;
340 /* The symbol `image' which is the car of the lists used to represent
345 /* The image map types. */
346 Lisp_Object QCmap
, QCpointer
;
347 Lisp_Object Qrect
, Qcircle
, Qpoly
;
349 /* Non-zero means print newline to stdout before next mini-buffer
352 int noninteractive_need_newline
;
354 /* Non-zero means print newline to message log before next message. */
356 static int message_log_need_newline
;
358 /* Three markers that message_dolog uses.
359 It could allocate them itself, but that causes trouble
360 in handling memory-full errors. */
361 static Lisp_Object message_dolog_marker1
;
362 static Lisp_Object message_dolog_marker2
;
363 static Lisp_Object message_dolog_marker3
;
365 /* The buffer position of the first character appearing entirely or
366 partially on the line of the selected window which contains the
367 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
368 redisplay optimization in redisplay_internal. */
370 static struct text_pos this_line_start_pos
;
372 /* Number of characters past the end of the line above, including the
373 terminating newline. */
375 static struct text_pos this_line_end_pos
;
377 /* The vertical positions and the height of this line. */
379 static int this_line_vpos
;
380 static int this_line_y
;
381 static int this_line_pixel_height
;
383 /* X position at which this display line starts. Usually zero;
384 negative if first character is partially visible. */
386 static int this_line_start_x
;
388 /* Buffer that this_line_.* variables are referring to. */
390 static struct buffer
*this_line_buffer
;
392 /* Nonzero means truncate lines in all windows less wide than the
395 int truncate_partial_width_windows
;
397 /* A flag to control how to display unibyte 8-bit character. */
399 int unibyte_display_via_language_environment
;
401 /* Nonzero means we have more than one non-mini-buffer-only frame.
402 Not guaranteed to be accurate except while parsing
403 frame-title-format. */
407 Lisp_Object Vglobal_mode_string
;
410 /* List of variables (symbols) which hold markers for overlay arrows.
411 The symbols on this list are examined during redisplay to determine
412 where to display overlay arrows. */
414 Lisp_Object Voverlay_arrow_variable_list
;
416 /* Marker for where to display an arrow on top of the buffer text. */
418 Lisp_Object Voverlay_arrow_position
;
420 /* String to display for the arrow. Only used on terminal frames. */
422 Lisp_Object Voverlay_arrow_string
;
424 /* Values of those variables at last redisplay are stored as
425 properties on `overlay-arrow-position' symbol. However, if
426 Voverlay_arrow_position is a marker, last-arrow-position is its
427 numerical position. */
429 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
431 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
432 properties on a symbol in overlay-arrow-variable-list. */
434 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
436 /* Like mode-line-format, but for the title bar on a visible frame. */
438 Lisp_Object Vframe_title_format
;
440 /* Like mode-line-format, but for the title bar on an iconified frame. */
442 Lisp_Object Vicon_title_format
;
444 /* List of functions to call when a window's size changes. These
445 functions get one arg, a frame on which one or more windows' sizes
448 static Lisp_Object Vwindow_size_change_functions
;
450 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
452 /* Nonzero if overlay arrow has been displayed once in this window. */
454 static int overlay_arrow_seen
;
456 /* Nonzero means highlight the region even in nonselected windows. */
458 int highlight_nonselected_windows
;
460 /* If cursor motion alone moves point off frame, try scrolling this
461 many lines up or down if that will bring it back. */
463 static EMACS_INT scroll_step
;
465 /* Nonzero means scroll just far enough to bring point back on the
466 screen, when appropriate. */
468 static EMACS_INT scroll_conservatively
;
470 /* Recenter the window whenever point gets within this many lines of
471 the top or bottom of the window. This value is translated into a
472 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
473 that there is really a fixed pixel height scroll margin. */
475 EMACS_INT scroll_margin
;
477 /* Number of windows showing the buffer of the selected window (or
478 another buffer with the same base buffer). keyboard.c refers to
483 /* Vector containing glyphs for an ellipsis `...'. */
485 static Lisp_Object default_invis_vector
[3];
487 /* Zero means display the mode-line/header-line/menu-bar in the default face
488 (this slightly odd definition is for compatibility with previous versions
489 of emacs), non-zero means display them using their respective faces.
491 This variable is deprecated. */
493 int mode_line_inverse_video
;
495 /* Prompt to display in front of the mini-buffer contents. */
497 Lisp_Object minibuf_prompt
;
499 /* Width of current mini-buffer prompt. Only set after display_line
500 of the line that contains the prompt. */
502 int minibuf_prompt_width
;
504 /* This is the window where the echo area message was displayed. It
505 is always a mini-buffer window, but it may not be the same window
506 currently active as a mini-buffer. */
508 Lisp_Object echo_area_window
;
510 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
511 pushes the current message and the value of
512 message_enable_multibyte on the stack, the function restore_message
513 pops the stack and displays MESSAGE again. */
515 Lisp_Object Vmessage_stack
;
517 /* Nonzero means multibyte characters were enabled when the echo area
518 message was specified. */
520 int message_enable_multibyte
;
522 /* Nonzero if we should redraw the mode lines on the next redisplay. */
524 int update_mode_lines
;
526 /* Nonzero if window sizes or contents have changed since last
527 redisplay that finished. */
529 int windows_or_buffers_changed
;
531 /* Nonzero means a frame's cursor type has been changed. */
533 int cursor_type_changed
;
535 /* Nonzero after display_mode_line if %l was used and it displayed a
538 int line_number_displayed
;
540 /* Maximum buffer size for which to display line numbers. */
542 Lisp_Object Vline_number_display_limit
;
544 /* Line width to consider when repositioning for line number display. */
546 static EMACS_INT line_number_display_limit_width
;
548 /* Number of lines to keep in the message log buffer. t means
549 infinite. nil means don't log at all. */
551 Lisp_Object Vmessage_log_max
;
553 /* The name of the *Messages* buffer, a string. */
555 static Lisp_Object Vmessages_buffer_name
;
557 /* Current, index 0, and last displayed echo area message. Either
558 buffers from echo_buffers, or nil to indicate no message. */
560 Lisp_Object echo_area_buffer
[2];
562 /* The buffers referenced from echo_area_buffer. */
564 static Lisp_Object echo_buffer
[2];
566 /* A vector saved used in with_area_buffer to reduce consing. */
568 static Lisp_Object Vwith_echo_area_save_vector
;
570 /* Non-zero means display_echo_area should display the last echo area
571 message again. Set by redisplay_preserve_echo_area. */
573 static int display_last_displayed_message_p
;
575 /* Nonzero if echo area is being used by print; zero if being used by
578 int message_buf_print
;
580 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
582 Lisp_Object Qinhibit_menubar_update
;
583 int inhibit_menubar_update
;
585 /* Maximum height for resizing mini-windows. Either a float
586 specifying a fraction of the available height, or an integer
587 specifying a number of lines. */
589 Lisp_Object Vmax_mini_window_height
;
591 /* Non-zero means messages should be displayed with truncated
592 lines instead of being continued. */
594 int message_truncate_lines
;
595 Lisp_Object Qmessage_truncate_lines
;
597 /* Set to 1 in clear_message to make redisplay_internal aware
598 of an emptied echo area. */
600 static int message_cleared_p
;
602 /* Non-zero means we want a hollow cursor in windows that are not
603 selected. Zero means there's no cursor in such windows. */
605 Lisp_Object Vcursor_in_non_selected_windows
;
606 Lisp_Object Qcursor_in_non_selected_windows
;
608 /* How to blink the default frame cursor off. */
609 Lisp_Object Vblink_cursor_alist
;
611 /* A scratch glyph row with contents used for generating truncation
612 glyphs. Also used in direct_output_for_insert. */
614 #define MAX_SCRATCH_GLYPHS 100
615 struct glyph_row scratch_glyph_row
;
616 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
618 /* Ascent and height of the last line processed by move_it_to. */
620 static int last_max_ascent
, last_height
;
622 /* Non-zero if there's a help-echo in the echo area. */
624 int help_echo_showing_p
;
626 /* If >= 0, computed, exact values of mode-line and header-line height
627 to use in the macros CURRENT_MODE_LINE_HEIGHT and
628 CURRENT_HEADER_LINE_HEIGHT. */
630 int current_mode_line_height
, current_header_line_height
;
632 /* The maximum distance to look ahead for text properties. Values
633 that are too small let us call compute_char_face and similar
634 functions too often which is expensive. Values that are too large
635 let us call compute_char_face and alike too often because we
636 might not be interested in text properties that far away. */
638 #define TEXT_PROP_DISTANCE_LIMIT 100
642 /* Variables to turn off display optimizations from Lisp. */
644 int inhibit_try_window_id
, inhibit_try_window_reusing
;
645 int inhibit_try_cursor_movement
;
647 /* Non-zero means print traces of redisplay if compiled with
650 int trace_redisplay_p
;
652 #endif /* GLYPH_DEBUG */
654 #ifdef DEBUG_TRACE_MOVE
655 /* Non-zero means trace with TRACE_MOVE to stderr. */
658 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
660 #define TRACE_MOVE(x) (void) 0
663 /* Non-zero means automatically scroll windows horizontally to make
666 int automatic_hscrolling_p
;
668 /* How close to the margin can point get before the window is scrolled
670 EMACS_INT hscroll_margin
;
672 /* How much to scroll horizontally when point is inside the above margin. */
673 Lisp_Object Vhscroll_step
;
675 /* A list of symbols, one for each supported image type. */
677 Lisp_Object Vimage_types
;
679 /* The variable `resize-mini-windows'. If nil, don't resize
680 mini-windows. If t, always resize them to fit the text they
681 display. If `grow-only', let mini-windows grow only until they
684 Lisp_Object Vresize_mini_windows
;
686 /* Buffer being redisplayed -- for redisplay_window_error. */
688 struct buffer
*displayed_buffer
;
690 /* Value returned from text property handlers (see below). */
695 HANDLED_RECOMPUTE_PROPS
,
696 HANDLED_OVERLAY_STRING_CONSUMED
,
700 /* A description of text properties that redisplay is interested
705 /* The name of the property. */
708 /* A unique index for the property. */
711 /* A handler function called to set up iterator IT from the property
712 at IT's current position. Value is used to steer handle_stop. */
713 enum prop_handled (*handler
) P_ ((struct it
*it
));
716 static enum prop_handled handle_face_prop
P_ ((struct it
*));
717 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
718 static enum prop_handled handle_display_prop
P_ ((struct it
*));
719 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
720 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
721 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
723 /* Properties handled by iterators. */
725 static struct props it_props
[] =
727 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
728 /* Handle `face' before `display' because some sub-properties of
729 `display' need to know the face. */
730 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
731 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
732 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
733 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
737 /* Value is the position described by X. If X is a marker, value is
738 the marker_position of X. Otherwise, value is X. */
740 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
742 /* Enumeration returned by some move_it_.* functions internally. */
746 /* Not used. Undefined value. */
749 /* Move ended at the requested buffer position or ZV. */
750 MOVE_POS_MATCH_OR_ZV
,
752 /* Move ended at the requested X pixel position. */
755 /* Move within a line ended at the end of a line that must be
759 /* Move within a line ended at the end of a line that would
760 be displayed truncated. */
763 /* Move within a line ended at a line end. */
767 /* This counter is used to clear the face cache every once in a while
768 in redisplay_internal. It is incremented for each redisplay.
769 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
772 #define CLEAR_FACE_CACHE_COUNT 500
773 static int clear_face_cache_count
;
775 /* Record the previous terminal frame we displayed. */
777 static struct frame
*previous_terminal_frame
;
779 /* Non-zero while redisplay_internal is in progress. */
783 /* Non-zero means don't free realized faces. Bound while freeing
784 realized faces is dangerous because glyph matrices might still
787 int inhibit_free_realized_faces
;
788 Lisp_Object Qinhibit_free_realized_faces
;
790 /* If a string, XTread_socket generates an event to display that string.
791 (The display is done in read_char.) */
793 Lisp_Object help_echo_string
;
794 Lisp_Object help_echo_window
;
795 Lisp_Object help_echo_object
;
798 /* Temporary variable for XTread_socket. */
800 Lisp_Object previous_help_echo_string
;
802 /* Null glyph slice */
804 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
807 /* Function prototypes. */
809 static void setup_for_ellipsis
P_ ((struct it
*));
810 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
811 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
812 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
813 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
814 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
815 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
818 static int invisible_text_between_p
P_ ((struct it
*, int, int));
821 static int next_element_from_ellipsis
P_ ((struct it
*));
822 static void pint2str
P_ ((char *, int, int));
823 static void pint2hrstr
P_ ((char *, int, int));
824 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
826 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
827 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
828 static void store_frame_title_char
P_ ((char));
829 static int store_frame_title
P_ ((const unsigned char *, int, int));
830 static void x_consider_frame_title
P_ ((Lisp_Object
));
831 static void handle_stop
P_ ((struct it
*));
832 static int tool_bar_lines_needed
P_ ((struct frame
*));
833 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
834 static void ensure_echo_area_buffers
P_ ((void));
835 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
836 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
837 static int with_echo_area_buffer
P_ ((struct window
*, int,
838 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
839 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
840 static void clear_garbaged_frames
P_ ((void));
841 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
842 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
843 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
844 static int display_echo_area
P_ ((struct window
*));
845 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
846 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
847 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
848 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
849 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
851 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
852 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
853 static void insert_left_trunc_glyphs
P_ ((struct it
*));
854 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
856 static void extend_face_to_end_of_line
P_ ((struct it
*));
857 static int append_space_for_newline
P_ ((struct it
*, int));
858 static int make_cursor_line_fully_visible
P_ ((struct window
*, int));
859 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
860 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
861 static int trailing_whitespace_p
P_ ((int));
862 static int message_log_check_duplicate
P_ ((int, int, int, int));
863 static void push_it
P_ ((struct it
*));
864 static void pop_it
P_ ((struct it
*));
865 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
866 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
867 static void redisplay_internal
P_ ((int));
868 static int echo_area_display
P_ ((int));
869 static void redisplay_windows
P_ ((Lisp_Object
));
870 static void redisplay_window
P_ ((Lisp_Object
, int));
871 static Lisp_Object
redisplay_window_error ();
872 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
873 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
874 static void update_menu_bar
P_ ((struct frame
*, int));
875 static int try_window_reusing_current_matrix
P_ ((struct window
*));
876 static int try_window_id
P_ ((struct window
*));
877 static int display_line
P_ ((struct it
*));
878 static int display_mode_lines
P_ ((struct window
*));
879 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
880 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
881 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
882 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
883 static void display_menu_bar
P_ ((struct window
*));
884 static int display_count_lines
P_ ((int, int, int, int, int *));
885 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
886 int, int, struct it
*, int, int, int, int));
887 static void compute_line_metrics
P_ ((struct it
*));
888 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
889 static int get_overlay_strings
P_ ((struct it
*, int));
890 static void next_overlay_string
P_ ((struct it
*));
891 static void reseat
P_ ((struct it
*, struct text_pos
, int));
892 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
893 static void back_to_previous_visible_line_start
P_ ((struct it
*));
894 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
895 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
896 static int next_element_from_display_vector
P_ ((struct it
*));
897 static int next_element_from_string
P_ ((struct it
*));
898 static int next_element_from_c_string
P_ ((struct it
*));
899 static int next_element_from_buffer
P_ ((struct it
*));
900 static int next_element_from_composition
P_ ((struct it
*));
901 static int next_element_from_image
P_ ((struct it
*));
902 static int next_element_from_stretch
P_ ((struct it
*));
903 static void load_overlay_strings
P_ ((struct it
*, int));
904 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
905 struct display_pos
*));
906 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
907 Lisp_Object
, int, int, int, int));
908 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
910 void move_it_vertically_backward
P_ ((struct it
*, int));
911 static void init_to_row_start
P_ ((struct it
*, struct window
*,
912 struct glyph_row
*));
913 static int init_to_row_end
P_ ((struct it
*, struct window
*,
914 struct glyph_row
*));
915 static void back_to_previous_line_start
P_ ((struct it
*));
916 static int forward_to_next_line_start
P_ ((struct it
*, int *));
917 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
919 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
920 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
921 static int number_of_chars
P_ ((unsigned char *, int));
922 static void compute_stop_pos
P_ ((struct it
*));
923 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
925 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
926 static int next_overlay_change
P_ ((int));
927 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
928 Lisp_Object
, struct text_pos
*,
930 static int underlying_face_id
P_ ((struct it
*));
931 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
934 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
935 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
937 #ifdef HAVE_WINDOW_SYSTEM
939 static void update_tool_bar
P_ ((struct frame
*, int));
940 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
941 static int redisplay_tool_bar
P_ ((struct frame
*));
942 static void display_tool_bar_line
P_ ((struct it
*));
943 static void notice_overwritten_cursor
P_ ((struct window
*,
945 int, int, int, int));
949 #endif /* HAVE_WINDOW_SYSTEM */
952 /***********************************************************************
953 Window display dimensions
954 ***********************************************************************/
956 /* Return the bottom boundary y-position for text lines in window W.
957 This is the first y position at which a line cannot start.
958 It is relative to the top of the window.
960 This is the height of W minus the height of a mode line, if any. */
963 window_text_bottom_y (w
)
966 int height
= WINDOW_TOTAL_HEIGHT (w
);
968 if (WINDOW_WANTS_MODELINE_P (w
))
969 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
973 /* Return the pixel width of display area AREA of window W. AREA < 0
974 means return the total width of W, not including fringes to
975 the left and right of the window. */
978 window_box_width (w
, area
)
982 int cols
= XFASTINT (w
->total_cols
);
985 if (!w
->pseudo_window_p
)
987 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
989 if (area
== TEXT_AREA
)
991 if (INTEGERP (w
->left_margin_cols
))
992 cols
-= XFASTINT (w
->left_margin_cols
);
993 if (INTEGERP (w
->right_margin_cols
))
994 cols
-= XFASTINT (w
->right_margin_cols
);
995 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
997 else if (area
== LEFT_MARGIN_AREA
)
999 cols
= (INTEGERP (w
->left_margin_cols
)
1000 ? XFASTINT (w
->left_margin_cols
) : 0);
1003 else if (area
== RIGHT_MARGIN_AREA
)
1005 cols
= (INTEGERP (w
->right_margin_cols
)
1006 ? XFASTINT (w
->right_margin_cols
) : 0);
1011 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1015 /* Return the pixel height of the display area of window W, not
1016 including mode lines of W, if any. */
1019 window_box_height (w
)
1022 struct frame
*f
= XFRAME (w
->frame
);
1023 int height
= WINDOW_TOTAL_HEIGHT (w
);
1025 xassert (height
>= 0);
1027 /* Note: the code below that determines the mode-line/header-line
1028 height is essentially the same as that contained in the macro
1029 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1030 the appropriate glyph row has its `mode_line_p' flag set,
1031 and if it doesn't, uses estimate_mode_line_height instead. */
1033 if (WINDOW_WANTS_MODELINE_P (w
))
1035 struct glyph_row
*ml_row
1036 = (w
->current_matrix
&& w
->current_matrix
->rows
1037 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1039 if (ml_row
&& ml_row
->mode_line_p
)
1040 height
-= ml_row
->height
;
1042 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1045 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1047 struct glyph_row
*hl_row
1048 = (w
->current_matrix
&& w
->current_matrix
->rows
1049 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1051 if (hl_row
&& hl_row
->mode_line_p
)
1052 height
-= hl_row
->height
;
1054 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1057 /* With a very small font and a mode-line that's taller than
1058 default, we might end up with a negative height. */
1059 return max (0, height
);
1062 /* Return the window-relative coordinate of the left edge of display
1063 area AREA of window W. AREA < 0 means return the left edge of the
1064 whole window, to the right of the left fringe of W. */
1067 window_box_left_offset (w
, area
)
1073 if (w
->pseudo_window_p
)
1076 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1078 if (area
== TEXT_AREA
)
1079 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1080 + window_box_width (w
, LEFT_MARGIN_AREA
));
1081 else if (area
== RIGHT_MARGIN_AREA
)
1082 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1083 + window_box_width (w
, LEFT_MARGIN_AREA
)
1084 + window_box_width (w
, TEXT_AREA
)
1085 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1087 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1088 else if (area
== LEFT_MARGIN_AREA
1089 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1090 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1096 /* Return the window-relative coordinate of the right edge of display
1097 area AREA of window W. AREA < 0 means return the left edge of the
1098 whole window, to the left of the right fringe of W. */
1101 window_box_right_offset (w
, area
)
1105 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1108 /* Return the frame-relative coordinate of the left edge of display
1109 area AREA of window W. AREA < 0 means return the left edge of the
1110 whole window, to the right of the left fringe of W. */
1113 window_box_left (w
, area
)
1117 struct frame
*f
= XFRAME (w
->frame
);
1120 if (w
->pseudo_window_p
)
1121 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1123 x
= (WINDOW_LEFT_EDGE_X (w
)
1124 + window_box_left_offset (w
, area
));
1130 /* Return the frame-relative coordinate of the right edge of display
1131 area AREA of window W. AREA < 0 means return the left edge of the
1132 whole window, to the left of the right fringe of W. */
1135 window_box_right (w
, area
)
1139 return window_box_left (w
, area
) + window_box_width (w
, area
);
1142 /* Get the bounding box of the display area AREA of window W, without
1143 mode lines, in frame-relative coordinates. AREA < 0 means the
1144 whole window, not including the left and right fringes of
1145 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1146 coordinates of the upper-left corner of the box. Return in
1147 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1150 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1153 int *box_x
, *box_y
, *box_width
, *box_height
;
1156 *box_width
= window_box_width (w
, area
);
1158 *box_height
= window_box_height (w
);
1160 *box_x
= window_box_left (w
, area
);
1163 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1164 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1165 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1170 /* Get the bounding box of the display area AREA of window W, without
1171 mode lines. AREA < 0 means the whole window, not including the
1172 left and right fringe of the window. Return in *TOP_LEFT_X
1173 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1174 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1175 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1179 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1180 bottom_right_x
, bottom_right_y
)
1183 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1185 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1187 *bottom_right_x
+= *top_left_x
;
1188 *bottom_right_y
+= *top_left_y
;
1193 /***********************************************************************
1195 ***********************************************************************/
1197 /* Return the bottom y-position of the line the iterator IT is in.
1198 This can modify IT's settings. */
1204 int line_height
= it
->max_ascent
+ it
->max_descent
;
1205 int line_top_y
= it
->current_y
;
1207 if (line_height
== 0)
1210 line_height
= last_height
;
1211 else if (IT_CHARPOS (*it
) < ZV
)
1213 move_it_by_lines (it
, 1, 1);
1214 line_height
= (it
->max_ascent
|| it
->max_descent
1215 ? it
->max_ascent
+ it
->max_descent
1220 struct glyph_row
*row
= it
->glyph_row
;
1222 /* Use the default character height. */
1223 it
->glyph_row
= NULL
;
1224 it
->what
= IT_CHARACTER
;
1227 PRODUCE_GLYPHS (it
);
1228 line_height
= it
->ascent
+ it
->descent
;
1229 it
->glyph_row
= row
;
1233 return line_top_y
+ line_height
;
1237 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1238 1 if POS is visible and the line containing POS is fully visible.
1239 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1240 and header-lines heights. */
1243 pos_visible_p (w
, charpos
, fully
, x
, y
, exact_mode_line_heights_p
)
1245 int charpos
, *fully
, *x
, *y
, exact_mode_line_heights_p
;
1248 struct text_pos top
;
1250 struct buffer
*old_buffer
= NULL
;
1252 if (XBUFFER (w
->buffer
) != current_buffer
)
1254 old_buffer
= current_buffer
;
1255 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1258 *fully
= visible_p
= 0;
1259 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1261 /* Compute exact mode line heights, if requested. */
1262 if (exact_mode_line_heights_p
)
1264 if (WINDOW_WANTS_MODELINE_P (w
))
1265 current_mode_line_height
1266 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1267 current_buffer
->mode_line_format
);
1269 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1270 current_header_line_height
1271 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1272 current_buffer
->header_line_format
);
1275 start_display (&it
, w
, top
);
1276 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1277 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1279 /* Note that we may overshoot because of invisible text. */
1280 if (IT_CHARPOS (it
) >= charpos
)
1282 int top_y
= it
.current_y
;
1283 int bottom_y
= line_bottom_y (&it
);
1284 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1286 if (top_y
< window_top_y
)
1287 visible_p
= bottom_y
> window_top_y
;
1288 else if (top_y
< it
.last_visible_y
)
1291 *fully
= bottom_y
<= it
.last_visible_y
;
1296 *y
= max (top_y
+ it
.max_ascent
- it
.ascent
, window_top_y
);
1299 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1304 move_it_by_lines (&it
, 1, 0);
1305 if (charpos
< IT_CHARPOS (it
))
1310 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1312 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1318 set_buffer_internal_1 (old_buffer
);
1320 current_header_line_height
= current_mode_line_height
= -1;
1326 /* Return the next character from STR which is MAXLEN bytes long.
1327 Return in *LEN the length of the character. This is like
1328 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1329 we find one, we return a `?', but with the length of the invalid
1333 string_char_and_length (str
, maxlen
, len
)
1334 const unsigned char *str
;
1339 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1340 if (!CHAR_VALID_P (c
, 1))
1341 /* We may not change the length here because other places in Emacs
1342 don't use this function, i.e. they silently accept invalid
1351 /* Given a position POS containing a valid character and byte position
1352 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1354 static struct text_pos
1355 string_pos_nchars_ahead (pos
, string
, nchars
)
1356 struct text_pos pos
;
1360 xassert (STRINGP (string
) && nchars
>= 0);
1362 if (STRING_MULTIBYTE (string
))
1364 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1365 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1370 string_char_and_length (p
, rest
, &len
);
1371 p
+= len
, rest
-= len
;
1372 xassert (rest
>= 0);
1374 BYTEPOS (pos
) += len
;
1378 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1384 /* Value is the text position, i.e. character and byte position,
1385 for character position CHARPOS in STRING. */
1387 static INLINE
struct text_pos
1388 string_pos (charpos
, string
)
1392 struct text_pos pos
;
1393 xassert (STRINGP (string
));
1394 xassert (charpos
>= 0);
1395 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1400 /* Value is a text position, i.e. character and byte position, for
1401 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1402 means recognize multibyte characters. */
1404 static struct text_pos
1405 c_string_pos (charpos
, s
, multibyte_p
)
1410 struct text_pos pos
;
1412 xassert (s
!= NULL
);
1413 xassert (charpos
>= 0);
1417 int rest
= strlen (s
), len
;
1419 SET_TEXT_POS (pos
, 0, 0);
1422 string_char_and_length (s
, rest
, &len
);
1423 s
+= len
, rest
-= len
;
1424 xassert (rest
>= 0);
1426 BYTEPOS (pos
) += len
;
1430 SET_TEXT_POS (pos
, charpos
, charpos
);
1436 /* Value is the number of characters in C string S. MULTIBYTE_P
1437 non-zero means recognize multibyte characters. */
1440 number_of_chars (s
, multibyte_p
)
1448 int rest
= strlen (s
), len
;
1449 unsigned char *p
= (unsigned char *) s
;
1451 for (nchars
= 0; rest
> 0; ++nchars
)
1453 string_char_and_length (p
, rest
, &len
);
1454 rest
-= len
, p
+= len
;
1458 nchars
= strlen (s
);
1464 /* Compute byte position NEWPOS->bytepos corresponding to
1465 NEWPOS->charpos. POS is a known position in string STRING.
1466 NEWPOS->charpos must be >= POS.charpos. */
1469 compute_string_pos (newpos
, pos
, string
)
1470 struct text_pos
*newpos
, pos
;
1473 xassert (STRINGP (string
));
1474 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1476 if (STRING_MULTIBYTE (string
))
1477 *newpos
= string_pos_nchars_ahead (pos
, string
,
1478 CHARPOS (*newpos
) - CHARPOS (pos
));
1480 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1484 Return an estimation of the pixel height of mode or top lines on
1485 frame F. FACE_ID specifies what line's height to estimate. */
1488 estimate_mode_line_height (f
, face_id
)
1490 enum face_id face_id
;
1492 #ifdef HAVE_WINDOW_SYSTEM
1493 if (FRAME_WINDOW_P (f
))
1495 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1497 /* This function is called so early when Emacs starts that the face
1498 cache and mode line face are not yet initialized. */
1499 if (FRAME_FACE_CACHE (f
))
1501 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1505 height
= FONT_HEIGHT (face
->font
);
1506 if (face
->box_line_width
> 0)
1507 height
+= 2 * face
->box_line_width
;
1518 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1519 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1520 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1521 not force the value into range. */
1524 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1526 register int pix_x
, pix_y
;
1528 NativeRectangle
*bounds
;
1532 #ifdef HAVE_WINDOW_SYSTEM
1533 if (FRAME_WINDOW_P (f
))
1535 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1536 even for negative values. */
1538 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1540 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1542 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1543 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1546 STORE_NATIVE_RECT (*bounds
,
1547 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1548 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1549 FRAME_COLUMN_WIDTH (f
) - 1,
1550 FRAME_LINE_HEIGHT (f
) - 1);
1556 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1557 pix_x
= FRAME_TOTAL_COLS (f
);
1561 else if (pix_y
> FRAME_LINES (f
))
1562 pix_y
= FRAME_LINES (f
);
1572 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1573 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1574 can't tell the positions because W's display is not up to date,
1578 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1581 int *frame_x
, *frame_y
;
1583 #ifdef HAVE_WINDOW_SYSTEM
1584 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1588 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1589 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1591 if (display_completed
)
1593 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1594 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1595 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1601 hpos
+= glyph
->pixel_width
;
1605 /* If first glyph is partially visible, its first visible position is still 0. */
1617 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1618 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1629 #ifdef HAVE_WINDOW_SYSTEM
1631 /* Find the glyph under window-relative coordinates X/Y in window W.
1632 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1633 strings. Return in *HPOS and *VPOS the row and column number of
1634 the glyph found. Return in *AREA the glyph area containing X.
1635 Value is a pointer to the glyph found or null if X/Y is not on
1636 text, or we can't tell because W's current matrix is not up to
1639 static struct glyph
*
1640 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1643 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1645 struct glyph
*glyph
, *end
;
1646 struct glyph_row
*row
= NULL
;
1649 /* Find row containing Y. Give up if some row is not enabled. */
1650 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1652 row
= MATRIX_ROW (w
->current_matrix
, i
);
1653 if (!row
->enabled_p
)
1655 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1662 /* Give up if Y is not in the window. */
1663 if (i
== w
->current_matrix
->nrows
)
1666 /* Get the glyph area containing X. */
1667 if (w
->pseudo_window_p
)
1674 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1676 *area
= LEFT_MARGIN_AREA
;
1677 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1679 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1682 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1686 *area
= RIGHT_MARGIN_AREA
;
1687 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1691 /* Find glyph containing X. */
1692 glyph
= row
->glyphs
[*area
];
1693 end
= glyph
+ row
->used
[*area
];
1695 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1697 x
-= glyph
->pixel_width
;
1707 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1710 *hpos
= glyph
- row
->glyphs
[*area
];
1716 Convert frame-relative x/y to coordinates relative to window W.
1717 Takes pseudo-windows into account. */
1720 frame_to_window_pixel_xy (w
, x
, y
)
1724 if (w
->pseudo_window_p
)
1726 /* A pseudo-window is always full-width, and starts at the
1727 left edge of the frame, plus a frame border. */
1728 struct frame
*f
= XFRAME (w
->frame
);
1729 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1730 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1734 *x
-= WINDOW_LEFT_EDGE_X (w
);
1735 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1740 Return in *R the clipping rectangle for glyph string S. */
1743 get_glyph_string_clip_rect (s
, nr
)
1744 struct glyph_string
*s
;
1745 NativeRectangle
*nr
;
1749 if (s
->row
->full_width_p
)
1751 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1752 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1753 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1755 /* Unless displaying a mode or menu bar line, which are always
1756 fully visible, clip to the visible part of the row. */
1757 if (s
->w
->pseudo_window_p
)
1758 r
.height
= s
->row
->visible_height
;
1760 r
.height
= s
->height
;
1764 /* This is a text line that may be partially visible. */
1765 r
.x
= window_box_left (s
->w
, s
->area
);
1766 r
.width
= window_box_width (s
->w
, s
->area
);
1767 r
.height
= s
->row
->visible_height
;
1770 /* If S draws overlapping rows, it's sufficient to use the top and
1771 bottom of the window for clipping because this glyph string
1772 intentionally draws over other lines. */
1773 if (s
->for_overlaps_p
)
1775 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1776 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1780 /* Don't use S->y for clipping because it doesn't take partially
1781 visible lines into account. For example, it can be negative for
1782 partially visible lines at the top of a window. */
1783 if (!s
->row
->full_width_p
1784 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1785 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1787 r
.y
= max (0, s
->row
->y
);
1789 /* If drawing a tool-bar window, draw it over the internal border
1790 at the top of the window. */
1791 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1792 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1795 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1797 /* If drawing the cursor, don't let glyph draw outside its
1798 advertised boundaries. Cleartype does this under some circumstances. */
1799 if (s
->hl
== DRAW_CURSOR
)
1801 struct glyph
*glyph
= s
->first_glyph
;
1806 r
.width
-= s
->x
- r
.x
;
1809 r
.width
= min (r
.width
, glyph
->pixel_width
);
1811 /* Don't draw cursor glyph taller than our actual glyph. */
1812 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1813 if (height
< r
.height
)
1815 int max_y
= r
.y
+ r
.height
;
1816 r
.y
= min (max_y
, s
->ybase
+ glyph
->descent
- height
);
1817 r
.height
= min (max_y
- r
.y
, height
);
1821 #ifdef CONVERT_FROM_XRECT
1822 CONVERT_FROM_XRECT (r
, *nr
);
1828 #endif /* HAVE_WINDOW_SYSTEM */
1831 /***********************************************************************
1832 Lisp form evaluation
1833 ***********************************************************************/
1835 /* Error handler for safe_eval and safe_call. */
1838 safe_eval_handler (arg
)
1841 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1846 /* Evaluate SEXPR and return the result, or nil if something went
1847 wrong. Prevent redisplay during the evaluation. */
1855 if (inhibit_eval_during_redisplay
)
1859 int count
= SPECPDL_INDEX ();
1860 struct gcpro gcpro1
;
1863 specbind (Qinhibit_redisplay
, Qt
);
1864 /* Use Qt to ensure debugger does not run,
1865 so there is no possibility of wanting to redisplay. */
1866 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1869 val
= unbind_to (count
, val
);
1876 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1877 Return the result, or nil if something went wrong. Prevent
1878 redisplay during the evaluation. */
1881 safe_call (nargs
, args
)
1887 if (inhibit_eval_during_redisplay
)
1891 int count
= SPECPDL_INDEX ();
1892 struct gcpro gcpro1
;
1895 gcpro1
.nvars
= nargs
;
1896 specbind (Qinhibit_redisplay
, Qt
);
1897 /* Use Qt to ensure debugger does not run,
1898 so there is no possibility of wanting to redisplay. */
1899 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1902 val
= unbind_to (count
, val
);
1909 /* Call function FN with one argument ARG.
1910 Return the result, or nil if something went wrong. */
1913 safe_call1 (fn
, arg
)
1914 Lisp_Object fn
, arg
;
1916 Lisp_Object args
[2];
1919 return safe_call (2, args
);
1924 /***********************************************************************
1926 ***********************************************************************/
1930 /* Define CHECK_IT to perform sanity checks on iterators.
1931 This is for debugging. It is too slow to do unconditionally. */
1937 if (it
->method
== next_element_from_string
)
1939 xassert (STRINGP (it
->string
));
1940 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1944 xassert (IT_STRING_CHARPOS (*it
) < 0);
1945 if (it
->method
== next_element_from_buffer
)
1947 /* Check that character and byte positions agree. */
1948 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1953 xassert (it
->current
.dpvec_index
>= 0);
1955 xassert (it
->current
.dpvec_index
< 0);
1958 #define CHECK_IT(IT) check_it ((IT))
1962 #define CHECK_IT(IT) (void) 0
1969 /* Check that the window end of window W is what we expect it
1970 to be---the last row in the current matrix displaying text. */
1973 check_window_end (w
)
1976 if (!MINI_WINDOW_P (w
)
1977 && !NILP (w
->window_end_valid
))
1979 struct glyph_row
*row
;
1980 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1981 XFASTINT (w
->window_end_vpos
)),
1983 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1984 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1988 #define CHECK_WINDOW_END(W) check_window_end ((W))
1990 #else /* not GLYPH_DEBUG */
1992 #define CHECK_WINDOW_END(W) (void) 0
1994 #endif /* not GLYPH_DEBUG */
1998 /***********************************************************************
1999 Iterator initialization
2000 ***********************************************************************/
2002 /* Initialize IT for displaying current_buffer in window W, starting
2003 at character position CHARPOS. CHARPOS < 0 means that no buffer
2004 position is specified which is useful when the iterator is assigned
2005 a position later. BYTEPOS is the byte position corresponding to
2006 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2008 If ROW is not null, calls to produce_glyphs with IT as parameter
2009 will produce glyphs in that row.
2011 BASE_FACE_ID is the id of a base face to use. It must be one of
2012 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2013 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2014 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2016 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2017 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2018 will be initialized to use the corresponding mode line glyph row of
2019 the desired matrix of W. */
2022 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2025 int charpos
, bytepos
;
2026 struct glyph_row
*row
;
2027 enum face_id base_face_id
;
2029 int highlight_region_p
;
2031 /* Some precondition checks. */
2032 xassert (w
!= NULL
&& it
!= NULL
);
2033 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2036 /* If face attributes have been changed since the last redisplay,
2037 free realized faces now because they depend on face definitions
2038 that might have changed. Don't free faces while there might be
2039 desired matrices pending which reference these faces. */
2040 if (face_change_count
&& !inhibit_free_realized_faces
)
2042 face_change_count
= 0;
2043 free_all_realized_faces (Qnil
);
2046 /* Use one of the mode line rows of W's desired matrix if
2050 if (base_face_id
== MODE_LINE_FACE_ID
2051 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2052 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2053 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2054 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2058 bzero (it
, sizeof *it
);
2059 it
->current
.overlay_string_index
= -1;
2060 it
->current
.dpvec_index
= -1;
2061 it
->base_face_id
= base_face_id
;
2063 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2065 /* The window in which we iterate over current_buffer: */
2066 XSETWINDOW (it
->window
, w
);
2068 it
->f
= XFRAME (w
->frame
);
2070 /* Extra space between lines (on window systems only). */
2071 if (base_face_id
== DEFAULT_FACE_ID
2072 && FRAME_WINDOW_P (it
->f
))
2074 if (NATNUMP (current_buffer
->extra_line_spacing
))
2075 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2076 else if (FLOATP (current_buffer
->extra_line_spacing
))
2077 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2078 * FRAME_LINE_HEIGHT (it
->f
));
2079 else if (it
->f
->extra_line_spacing
> 0)
2080 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2083 /* If realized faces have been removed, e.g. because of face
2084 attribute changes of named faces, recompute them. When running
2085 in batch mode, the face cache of Vterminal_frame is null. If
2086 we happen to get called, make a dummy face cache. */
2087 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2088 init_frame_faces (it
->f
);
2089 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2090 recompute_basic_faces (it
->f
);
2092 /* Current value of the `slice', `space-width', and 'height' properties. */
2093 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2094 it
->space_width
= Qnil
;
2095 it
->font_height
= Qnil
;
2096 it
->override_ascent
= -1;
2098 /* Are control characters displayed as `^C'? */
2099 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2101 /* -1 means everything between a CR and the following line end
2102 is invisible. >0 means lines indented more than this value are
2104 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2105 ? XFASTINT (current_buffer
->selective_display
)
2106 : (!NILP (current_buffer
->selective_display
)
2108 it
->selective_display_ellipsis_p
2109 = !NILP (current_buffer
->selective_display_ellipses
);
2111 /* Display table to use. */
2112 it
->dp
= window_display_table (w
);
2114 /* Are multibyte characters enabled in current_buffer? */
2115 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2117 /* Non-zero if we should highlight the region. */
2119 = (!NILP (Vtransient_mark_mode
)
2120 && !NILP (current_buffer
->mark_active
)
2121 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2123 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2124 start and end of a visible region in window IT->w. Set both to
2125 -1 to indicate no region. */
2126 if (highlight_region_p
2127 /* Maybe highlight only in selected window. */
2128 && (/* Either show region everywhere. */
2129 highlight_nonselected_windows
2130 /* Or show region in the selected window. */
2131 || w
== XWINDOW (selected_window
)
2132 /* Or show the region if we are in the mini-buffer and W is
2133 the window the mini-buffer refers to. */
2134 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2135 && WINDOWP (minibuf_selected_window
)
2136 && w
== XWINDOW (minibuf_selected_window
))))
2138 int charpos
= marker_position (current_buffer
->mark
);
2139 it
->region_beg_charpos
= min (PT
, charpos
);
2140 it
->region_end_charpos
= max (PT
, charpos
);
2143 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2145 /* Get the position at which the redisplay_end_trigger hook should
2146 be run, if it is to be run at all. */
2147 if (MARKERP (w
->redisplay_end_trigger
)
2148 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2149 it
->redisplay_end_trigger_charpos
2150 = marker_position (w
->redisplay_end_trigger
);
2151 else if (INTEGERP (w
->redisplay_end_trigger
))
2152 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2154 /* Correct bogus values of tab_width. */
2155 it
->tab_width
= XINT (current_buffer
->tab_width
);
2156 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2159 /* Are lines in the display truncated? */
2160 it
->truncate_lines_p
2161 = (base_face_id
!= DEFAULT_FACE_ID
2162 || XINT (it
->w
->hscroll
)
2163 || (truncate_partial_width_windows
2164 && !WINDOW_FULL_WIDTH_P (it
->w
))
2165 || !NILP (current_buffer
->truncate_lines
));
2167 /* Get dimensions of truncation and continuation glyphs. These are
2168 displayed as fringe bitmaps under X, so we don't need them for such
2170 if (!FRAME_WINDOW_P (it
->f
))
2172 if (it
->truncate_lines_p
)
2174 /* We will need the truncation glyph. */
2175 xassert (it
->glyph_row
== NULL
);
2176 produce_special_glyphs (it
, IT_TRUNCATION
);
2177 it
->truncation_pixel_width
= it
->pixel_width
;
2181 /* We will need the continuation glyph. */
2182 xassert (it
->glyph_row
== NULL
);
2183 produce_special_glyphs (it
, IT_CONTINUATION
);
2184 it
->continuation_pixel_width
= it
->pixel_width
;
2187 /* Reset these values to zero because the produce_special_glyphs
2188 above has changed them. */
2189 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2190 it
->phys_ascent
= it
->phys_descent
= 0;
2193 /* Set this after getting the dimensions of truncation and
2194 continuation glyphs, so that we don't produce glyphs when calling
2195 produce_special_glyphs, above. */
2196 it
->glyph_row
= row
;
2197 it
->area
= TEXT_AREA
;
2199 /* Get the dimensions of the display area. The display area
2200 consists of the visible window area plus a horizontally scrolled
2201 part to the left of the window. All x-values are relative to the
2202 start of this total display area. */
2203 if (base_face_id
!= DEFAULT_FACE_ID
)
2205 /* Mode lines, menu bar in terminal frames. */
2206 it
->first_visible_x
= 0;
2207 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2212 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2213 it
->last_visible_x
= (it
->first_visible_x
2214 + window_box_width (w
, TEXT_AREA
));
2216 /* If we truncate lines, leave room for the truncator glyph(s) at
2217 the right margin. Otherwise, leave room for the continuation
2218 glyph(s). Truncation and continuation glyphs are not inserted
2219 for window-based redisplay. */
2220 if (!FRAME_WINDOW_P (it
->f
))
2222 if (it
->truncate_lines_p
)
2223 it
->last_visible_x
-= it
->truncation_pixel_width
;
2225 it
->last_visible_x
-= it
->continuation_pixel_width
;
2228 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2229 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2232 /* Leave room for a border glyph. */
2233 if (!FRAME_WINDOW_P (it
->f
)
2234 && !WINDOW_RIGHTMOST_P (it
->w
))
2235 it
->last_visible_x
-= 1;
2237 it
->last_visible_y
= window_text_bottom_y (w
);
2239 /* For mode lines and alike, arrange for the first glyph having a
2240 left box line if the face specifies a box. */
2241 if (base_face_id
!= DEFAULT_FACE_ID
)
2245 it
->face_id
= base_face_id
;
2247 /* If we have a boxed mode line, make the first character appear
2248 with a left box line. */
2249 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2250 if (face
->box
!= FACE_NO_BOX
)
2251 it
->start_of_box_run_p
= 1;
2254 /* If a buffer position was specified, set the iterator there,
2255 getting overlays and face properties from that position. */
2256 if (charpos
>= BUF_BEG (current_buffer
))
2258 it
->end_charpos
= ZV
;
2260 IT_CHARPOS (*it
) = charpos
;
2262 /* Compute byte position if not specified. */
2263 if (bytepos
< charpos
)
2264 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2266 IT_BYTEPOS (*it
) = bytepos
;
2268 it
->start
= it
->current
;
2270 /* Compute faces etc. */
2271 reseat (it
, it
->current
.pos
, 1);
2278 /* Initialize IT for the display of window W with window start POS. */
2281 start_display (it
, w
, pos
)
2284 struct text_pos pos
;
2286 struct glyph_row
*row
;
2287 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2289 row
= w
->desired_matrix
->rows
+ first_vpos
;
2290 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2291 it
->first_vpos
= first_vpos
;
2293 if (!it
->truncate_lines_p
)
2295 int start_at_line_beg_p
;
2296 int first_y
= it
->current_y
;
2298 /* If window start is not at a line start, skip forward to POS to
2299 get the correct continuation lines width. */
2300 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2301 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2302 if (!start_at_line_beg_p
)
2306 reseat_at_previous_visible_line_start (it
);
2307 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2309 new_x
= it
->current_x
+ it
->pixel_width
;
2311 /* If lines are continued, this line may end in the middle
2312 of a multi-glyph character (e.g. a control character
2313 displayed as \003, or in the middle of an overlay
2314 string). In this case move_it_to above will not have
2315 taken us to the start of the continuation line but to the
2316 end of the continued line. */
2317 if (it
->current_x
> 0
2318 && !it
->truncate_lines_p
/* Lines are continued. */
2319 && (/* And glyph doesn't fit on the line. */
2320 new_x
> it
->last_visible_x
2321 /* Or it fits exactly and we're on a window
2323 || (new_x
== it
->last_visible_x
2324 && FRAME_WINDOW_P (it
->f
))))
2326 if (it
->current
.dpvec_index
>= 0
2327 || it
->current
.overlay_string_index
>= 0)
2329 set_iterator_to_next (it
, 1);
2330 move_it_in_display_line_to (it
, -1, -1, 0);
2333 it
->continuation_lines_width
+= it
->current_x
;
2336 /* We're starting a new display line, not affected by the
2337 height of the continued line, so clear the appropriate
2338 fields in the iterator structure. */
2339 it
->max_ascent
= it
->max_descent
= 0;
2340 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2342 it
->current_y
= first_y
;
2344 it
->current_x
= it
->hpos
= 0;
2348 #if 0 /* Don't assert the following because start_display is sometimes
2349 called intentionally with a window start that is not at a
2350 line start. Please leave this code in as a comment. */
2352 /* Window start should be on a line start, now. */
2353 xassert (it
->continuation_lines_width
2354 || IT_CHARPOS (it
) == BEGV
2355 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2360 /* Return 1 if POS is a position in ellipses displayed for invisible
2361 text. W is the window we display, for text property lookup. */
2364 in_ellipses_for_invisible_text_p (pos
, w
)
2365 struct display_pos
*pos
;
2368 Lisp_Object prop
, window
;
2370 int charpos
= CHARPOS (pos
->pos
);
2372 /* If POS specifies a position in a display vector, this might
2373 be for an ellipsis displayed for invisible text. We won't
2374 get the iterator set up for delivering that ellipsis unless
2375 we make sure that it gets aware of the invisible text. */
2376 if (pos
->dpvec_index
>= 0
2377 && pos
->overlay_string_index
< 0
2378 && CHARPOS (pos
->string_pos
) < 0
2380 && (XSETWINDOW (window
, w
),
2381 prop
= Fget_char_property (make_number (charpos
),
2382 Qinvisible
, window
),
2383 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2385 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2387 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2394 /* Initialize IT for stepping through current_buffer in window W,
2395 starting at position POS that includes overlay string and display
2396 vector/ control character translation position information. Value
2397 is zero if there are overlay strings with newlines at POS. */
2400 init_from_display_pos (it
, w
, pos
)
2403 struct display_pos
*pos
;
2405 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2406 int i
, overlay_strings_with_newlines
= 0;
2408 /* If POS specifies a position in a display vector, this might
2409 be for an ellipsis displayed for invisible text. We won't
2410 get the iterator set up for delivering that ellipsis unless
2411 we make sure that it gets aware of the invisible text. */
2412 if (in_ellipses_for_invisible_text_p (pos
, w
))
2418 /* Keep in mind: the call to reseat in init_iterator skips invisible
2419 text, so we might end up at a position different from POS. This
2420 is only a problem when POS is a row start after a newline and an
2421 overlay starts there with an after-string, and the overlay has an
2422 invisible property. Since we don't skip invisible text in
2423 display_line and elsewhere immediately after consuming the
2424 newline before the row start, such a POS will not be in a string,
2425 but the call to init_iterator below will move us to the
2427 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2429 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2431 const char *s
= SDATA (it
->overlay_strings
[i
]);
2432 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2434 while (s
< e
&& *s
!= '\n')
2439 overlay_strings_with_newlines
= 1;
2444 /* If position is within an overlay string, set up IT to the right
2446 if (pos
->overlay_string_index
>= 0)
2450 /* If the first overlay string happens to have a `display'
2451 property for an image, the iterator will be set up for that
2452 image, and we have to undo that setup first before we can
2453 correct the overlay string index. */
2454 if (it
->method
== next_element_from_image
)
2457 /* We already have the first chunk of overlay strings in
2458 IT->overlay_strings. Load more until the one for
2459 pos->overlay_string_index is in IT->overlay_strings. */
2460 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2462 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2463 it
->current
.overlay_string_index
= 0;
2466 load_overlay_strings (it
, 0);
2467 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2471 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2472 relative_index
= (it
->current
.overlay_string_index
2473 % OVERLAY_STRING_CHUNK_SIZE
);
2474 it
->string
= it
->overlay_strings
[relative_index
];
2475 xassert (STRINGP (it
->string
));
2476 it
->current
.string_pos
= pos
->string_pos
;
2477 it
->method
= next_element_from_string
;
2480 #if 0 /* This is bogus because POS not having an overlay string
2481 position does not mean it's after the string. Example: A
2482 line starting with a before-string and initialization of IT
2483 to the previous row's end position. */
2484 else if (it
->current
.overlay_string_index
>= 0)
2486 /* If POS says we're already after an overlay string ending at
2487 POS, make sure to pop the iterator because it will be in
2488 front of that overlay string. When POS is ZV, we've thereby
2489 also ``processed'' overlay strings at ZV. */
2492 it
->current
.overlay_string_index
= -1;
2493 it
->method
= next_element_from_buffer
;
2494 if (CHARPOS (pos
->pos
) == ZV
)
2495 it
->overlay_strings_at_end_processed_p
= 1;
2499 if (CHARPOS (pos
->string_pos
) >= 0)
2501 /* Recorded position is not in an overlay string, but in another
2502 string. This can only be a string from a `display' property.
2503 IT should already be filled with that string. */
2504 it
->current
.string_pos
= pos
->string_pos
;
2505 xassert (STRINGP (it
->string
));
2508 /* Restore position in display vector translations, control
2509 character translations or ellipses. */
2510 if (pos
->dpvec_index
>= 0)
2512 if (it
->dpvec
== NULL
)
2513 get_next_display_element (it
);
2514 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2515 it
->current
.dpvec_index
= pos
->dpvec_index
;
2519 return !overlay_strings_with_newlines
;
2523 /* Initialize IT for stepping through current_buffer in window W
2524 starting at ROW->start. */
2527 init_to_row_start (it
, w
, row
)
2530 struct glyph_row
*row
;
2532 init_from_display_pos (it
, w
, &row
->start
);
2533 it
->start
= row
->start
;
2534 it
->continuation_lines_width
= row
->continuation_lines_width
;
2539 /* Initialize IT for stepping through current_buffer in window W
2540 starting in the line following ROW, i.e. starting at ROW->end.
2541 Value is zero if there are overlay strings with newlines at ROW's
2545 init_to_row_end (it
, w
, row
)
2548 struct glyph_row
*row
;
2552 if (init_from_display_pos (it
, w
, &row
->end
))
2554 if (row
->continued_p
)
2555 it
->continuation_lines_width
2556 = row
->continuation_lines_width
+ row
->pixel_width
;
2567 /***********************************************************************
2569 ***********************************************************************/
2571 /* Called when IT reaches IT->stop_charpos. Handle text property and
2572 overlay changes. Set IT->stop_charpos to the next position where
2579 enum prop_handled handled
;
2580 int handle_overlay_change_p
= 1;
2584 it
->current
.dpvec_index
= -1;
2588 handled
= HANDLED_NORMALLY
;
2590 /* Call text property handlers. */
2591 for (p
= it_props
; p
->handler
; ++p
)
2593 handled
= p
->handler (it
);
2595 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2597 else if (handled
== HANDLED_RETURN
)
2599 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2600 handle_overlay_change_p
= 0;
2603 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2605 /* Don't check for overlay strings below when set to deliver
2606 characters from a display vector. */
2607 if (it
->method
== next_element_from_display_vector
)
2608 handle_overlay_change_p
= 0;
2610 /* Handle overlay changes. */
2611 if (handle_overlay_change_p
)
2612 handled
= handle_overlay_change (it
);
2614 /* Determine where to stop next. */
2615 if (handled
== HANDLED_NORMALLY
)
2616 compute_stop_pos (it
);
2619 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2623 /* Compute IT->stop_charpos from text property and overlay change
2624 information for IT's current position. */
2627 compute_stop_pos (it
)
2630 register INTERVAL iv
, next_iv
;
2631 Lisp_Object object
, limit
, position
;
2633 /* If nowhere else, stop at the end. */
2634 it
->stop_charpos
= it
->end_charpos
;
2636 if (STRINGP (it
->string
))
2638 /* Strings are usually short, so don't limit the search for
2640 object
= it
->string
;
2642 position
= make_number (IT_STRING_CHARPOS (*it
));
2648 /* If next overlay change is in front of the current stop pos
2649 (which is IT->end_charpos), stop there. Note: value of
2650 next_overlay_change is point-max if no overlay change
2652 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2653 if (charpos
< it
->stop_charpos
)
2654 it
->stop_charpos
= charpos
;
2656 /* If showing the region, we have to stop at the region
2657 start or end because the face might change there. */
2658 if (it
->region_beg_charpos
> 0)
2660 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2661 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2662 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2663 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2666 /* Set up variables for computing the stop position from text
2667 property changes. */
2668 XSETBUFFER (object
, current_buffer
);
2669 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2670 position
= make_number (IT_CHARPOS (*it
));
2674 /* Get the interval containing IT's position. Value is a null
2675 interval if there isn't such an interval. */
2676 iv
= validate_interval_range (object
, &position
, &position
, 0);
2677 if (!NULL_INTERVAL_P (iv
))
2679 Lisp_Object values_here
[LAST_PROP_IDX
];
2682 /* Get properties here. */
2683 for (p
= it_props
; p
->handler
; ++p
)
2684 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2686 /* Look for an interval following iv that has different
2688 for (next_iv
= next_interval (iv
);
2689 (!NULL_INTERVAL_P (next_iv
)
2691 || XFASTINT (limit
) > next_iv
->position
));
2692 next_iv
= next_interval (next_iv
))
2694 for (p
= it_props
; p
->handler
; ++p
)
2696 Lisp_Object new_value
;
2698 new_value
= textget (next_iv
->plist
, *p
->name
);
2699 if (!EQ (values_here
[p
->idx
], new_value
))
2707 if (!NULL_INTERVAL_P (next_iv
))
2709 if (INTEGERP (limit
)
2710 && next_iv
->position
>= XFASTINT (limit
))
2711 /* No text property change up to limit. */
2712 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2714 /* Text properties change in next_iv. */
2715 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2719 xassert (STRINGP (it
->string
)
2720 || (it
->stop_charpos
>= BEGV
2721 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2725 /* Return the position of the next overlay change after POS in
2726 current_buffer. Value is point-max if no overlay change
2727 follows. This is like `next-overlay-change' but doesn't use
2731 next_overlay_change (pos
)
2736 Lisp_Object
*overlays
;
2740 /* Get all overlays at the given position. */
2742 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2743 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2744 if (noverlays
> len
)
2747 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2748 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2751 /* If any of these overlays ends before endpos,
2752 use its ending point instead. */
2753 for (i
= 0; i
< noverlays
; ++i
)
2758 oend
= OVERLAY_END (overlays
[i
]);
2759 oendpos
= OVERLAY_POSITION (oend
);
2760 endpos
= min (endpos
, oendpos
);
2768 /***********************************************************************
2770 ***********************************************************************/
2772 /* Handle changes in the `fontified' property of the current buffer by
2773 calling hook functions from Qfontification_functions to fontify
2776 static enum prop_handled
2777 handle_fontified_prop (it
)
2780 Lisp_Object prop
, pos
;
2781 enum prop_handled handled
= HANDLED_NORMALLY
;
2783 /* Get the value of the `fontified' property at IT's current buffer
2784 position. (The `fontified' property doesn't have a special
2785 meaning in strings.) If the value is nil, call functions from
2786 Qfontification_functions. */
2787 if (!STRINGP (it
->string
)
2789 && !NILP (Vfontification_functions
)
2790 && !NILP (Vrun_hooks
)
2791 && (pos
= make_number (IT_CHARPOS (*it
)),
2792 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2795 int count
= SPECPDL_INDEX ();
2798 val
= Vfontification_functions
;
2799 specbind (Qfontification_functions
, Qnil
);
2801 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2802 safe_call1 (val
, pos
);
2805 Lisp_Object globals
, fn
;
2806 struct gcpro gcpro1
, gcpro2
;
2809 GCPRO2 (val
, globals
);
2811 for (; CONSP (val
); val
= XCDR (val
))
2817 /* A value of t indicates this hook has a local
2818 binding; it means to run the global binding too.
2819 In a global value, t should not occur. If it
2820 does, we must ignore it to avoid an endless
2822 for (globals
= Fdefault_value (Qfontification_functions
);
2824 globals
= XCDR (globals
))
2826 fn
= XCAR (globals
);
2828 safe_call1 (fn
, pos
);
2832 safe_call1 (fn
, pos
);
2838 unbind_to (count
, Qnil
);
2840 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2841 something. This avoids an endless loop if they failed to
2842 fontify the text for which reason ever. */
2843 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2844 handled
= HANDLED_RECOMPUTE_PROPS
;
2852 /***********************************************************************
2854 ***********************************************************************/
2856 /* Set up iterator IT from face properties at its current position.
2857 Called from handle_stop. */
2859 static enum prop_handled
2860 handle_face_prop (it
)
2863 int new_face_id
, next_stop
;
2865 if (!STRINGP (it
->string
))
2868 = face_at_buffer_position (it
->w
,
2870 it
->region_beg_charpos
,
2871 it
->region_end_charpos
,
2874 + TEXT_PROP_DISTANCE_LIMIT
),
2877 /* Is this a start of a run of characters with box face?
2878 Caveat: this can be called for a freshly initialized
2879 iterator; face_id is -1 in this case. We know that the new
2880 face will not change until limit, i.e. if the new face has a
2881 box, all characters up to limit will have one. But, as
2882 usual, we don't know whether limit is really the end. */
2883 if (new_face_id
!= it
->face_id
)
2885 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2887 /* If new face has a box but old face has not, this is
2888 the start of a run of characters with box, i.e. it has
2889 a shadow on the left side. The value of face_id of the
2890 iterator will be -1 if this is the initial call that gets
2891 the face. In this case, we have to look in front of IT's
2892 position and see whether there is a face != new_face_id. */
2893 it
->start_of_box_run_p
2894 = (new_face
->box
!= FACE_NO_BOX
2895 && (it
->face_id
>= 0
2896 || IT_CHARPOS (*it
) == BEG
2897 || new_face_id
!= face_before_it_pos (it
)));
2898 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2903 int base_face_id
, bufpos
;
2905 if (it
->current
.overlay_string_index
>= 0)
2906 bufpos
= IT_CHARPOS (*it
);
2910 /* For strings from a buffer, i.e. overlay strings or strings
2911 from a `display' property, use the face at IT's current
2912 buffer position as the base face to merge with, so that
2913 overlay strings appear in the same face as surrounding
2914 text, unless they specify their own faces. */
2915 base_face_id
= underlying_face_id (it
);
2917 new_face_id
= face_at_string_position (it
->w
,
2919 IT_STRING_CHARPOS (*it
),
2921 it
->region_beg_charpos
,
2922 it
->region_end_charpos
,
2926 #if 0 /* This shouldn't be neccessary. Let's check it. */
2927 /* If IT is used to display a mode line we would really like to
2928 use the mode line face instead of the frame's default face. */
2929 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2930 && new_face_id
== DEFAULT_FACE_ID
)
2931 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2934 /* Is this a start of a run of characters with box? Caveat:
2935 this can be called for a freshly allocated iterator; face_id
2936 is -1 is this case. We know that the new face will not
2937 change until the next check pos, i.e. if the new face has a
2938 box, all characters up to that position will have a
2939 box. But, as usual, we don't know whether that position
2940 is really the end. */
2941 if (new_face_id
!= it
->face_id
)
2943 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2944 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2946 /* If new face has a box but old face hasn't, this is the
2947 start of a run of characters with box, i.e. it has a
2948 shadow on the left side. */
2949 it
->start_of_box_run_p
2950 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2951 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2955 it
->face_id
= new_face_id
;
2956 return HANDLED_NORMALLY
;
2960 /* Return the ID of the face ``underlying'' IT's current position,
2961 which is in a string. If the iterator is associated with a
2962 buffer, return the face at IT's current buffer position.
2963 Otherwise, use the iterator's base_face_id. */
2966 underlying_face_id (it
)
2969 int face_id
= it
->base_face_id
, i
;
2971 xassert (STRINGP (it
->string
));
2973 for (i
= it
->sp
- 1; i
>= 0; --i
)
2974 if (NILP (it
->stack
[i
].string
))
2975 face_id
= it
->stack
[i
].face_id
;
2981 /* Compute the face one character before or after the current position
2982 of IT. BEFORE_P non-zero means get the face in front of IT's
2983 position. Value is the id of the face. */
2986 face_before_or_after_it_pos (it
, before_p
)
2991 int next_check_charpos
;
2992 struct text_pos pos
;
2994 xassert (it
->s
== NULL
);
2996 if (STRINGP (it
->string
))
2998 int bufpos
, base_face_id
;
3000 /* No face change past the end of the string (for the case
3001 we are padding with spaces). No face change before the
3003 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3004 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3007 /* Set pos to the position before or after IT's current position. */
3009 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3011 /* For composition, we must check the character after the
3013 pos
= (it
->what
== IT_COMPOSITION
3014 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3015 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3017 if (it
->current
.overlay_string_index
>= 0)
3018 bufpos
= IT_CHARPOS (*it
);
3022 base_face_id
= underlying_face_id (it
);
3024 /* Get the face for ASCII, or unibyte. */
3025 face_id
= face_at_string_position (it
->w
,
3029 it
->region_beg_charpos
,
3030 it
->region_end_charpos
,
3031 &next_check_charpos
,
3034 /* Correct the face for charsets different from ASCII. Do it
3035 for the multibyte case only. The face returned above is
3036 suitable for unibyte text if IT->string is unibyte. */
3037 if (STRING_MULTIBYTE (it
->string
))
3039 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3040 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3042 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3044 c
= string_char_and_length (p
, rest
, &len
);
3045 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3050 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3051 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3054 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3055 pos
= it
->current
.pos
;
3058 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3061 if (it
->what
== IT_COMPOSITION
)
3062 /* For composition, we must check the position after the
3064 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3066 INC_TEXT_POS (pos
, it
->multibyte_p
);
3069 /* Determine face for CHARSET_ASCII, or unibyte. */
3070 face_id
= face_at_buffer_position (it
->w
,
3072 it
->region_beg_charpos
,
3073 it
->region_end_charpos
,
3074 &next_check_charpos
,
3077 /* Correct the face for charsets different from ASCII. Do it
3078 for the multibyte case only. The face returned above is
3079 suitable for unibyte text if current_buffer is unibyte. */
3080 if (it
->multibyte_p
)
3082 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3083 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3084 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3093 /***********************************************************************
3095 ***********************************************************************/
3097 /* Set up iterator IT from invisible properties at its current
3098 position. Called from handle_stop. */
3100 static enum prop_handled
3101 handle_invisible_prop (it
)
3104 enum prop_handled handled
= HANDLED_NORMALLY
;
3106 if (STRINGP (it
->string
))
3108 extern Lisp_Object Qinvisible
;
3109 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3111 /* Get the value of the invisible text property at the
3112 current position. Value will be nil if there is no such
3114 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3115 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3118 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3120 handled
= HANDLED_RECOMPUTE_PROPS
;
3122 /* Get the position at which the next change of the
3123 invisible text property can be found in IT->string.
3124 Value will be nil if the property value is the same for
3125 all the rest of IT->string. */
3126 XSETINT (limit
, SCHARS (it
->string
));
3127 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3130 /* Text at current position is invisible. The next
3131 change in the property is at position end_charpos.
3132 Move IT's current position to that position. */
3133 if (INTEGERP (end_charpos
)
3134 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3136 struct text_pos old
;
3137 old
= it
->current
.string_pos
;
3138 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3139 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3143 /* The rest of the string is invisible. If this is an
3144 overlay string, proceed with the next overlay string
3145 or whatever comes and return a character from there. */
3146 if (it
->current
.overlay_string_index
>= 0)
3148 next_overlay_string (it
);
3149 /* Don't check for overlay strings when we just
3150 finished processing them. */
3151 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3155 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3156 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3163 int invis_p
, newpos
, next_stop
, start_charpos
;
3164 Lisp_Object pos
, prop
, overlay
;
3166 /* First of all, is there invisible text at this position? */
3167 start_charpos
= IT_CHARPOS (*it
);
3168 pos
= make_number (IT_CHARPOS (*it
));
3169 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3171 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3173 /* If we are on invisible text, skip over it. */
3174 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3176 /* Record whether we have to display an ellipsis for the
3178 int display_ellipsis_p
= invis_p
== 2;
3180 handled
= HANDLED_RECOMPUTE_PROPS
;
3182 /* Loop skipping over invisible text. The loop is left at
3183 ZV or with IT on the first char being visible again. */
3186 /* Try to skip some invisible text. Return value is the
3187 position reached which can be equal to IT's position
3188 if there is nothing invisible here. This skips both
3189 over invisible text properties and overlays with
3190 invisible property. */
3191 newpos
= skip_invisible (IT_CHARPOS (*it
),
3192 &next_stop
, ZV
, it
->window
);
3194 /* If we skipped nothing at all we weren't at invisible
3195 text in the first place. If everything to the end of
3196 the buffer was skipped, end the loop. */
3197 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3201 /* We skipped some characters but not necessarily
3202 all there are. Check if we ended up on visible
3203 text. Fget_char_property returns the property of
3204 the char before the given position, i.e. if we
3205 get invis_p = 0, this means that the char at
3206 newpos is visible. */
3207 pos
= make_number (newpos
);
3208 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3209 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3212 /* If we ended up on invisible text, proceed to
3213 skip starting with next_stop. */
3215 IT_CHARPOS (*it
) = next_stop
;
3219 /* The position newpos is now either ZV or on visible text. */
3220 IT_CHARPOS (*it
) = newpos
;
3221 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3223 /* If there are before-strings at the start of invisible
3224 text, and the text is invisible because of a text
3225 property, arrange to show before-strings because 20.x did
3226 it that way. (If the text is invisible because of an
3227 overlay property instead of a text property, this is
3228 already handled in the overlay code.) */
3230 && get_overlay_strings (it
, start_charpos
))
3232 handled
= HANDLED_RECOMPUTE_PROPS
;
3233 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3235 else if (display_ellipsis_p
)
3236 setup_for_ellipsis (it
);
3244 /* Make iterator IT return `...' next. */
3247 setup_for_ellipsis (it
)
3251 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3253 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3254 it
->dpvec
= v
->contents
;
3255 it
->dpend
= v
->contents
+ v
->size
;
3259 /* Default `...'. */
3260 it
->dpvec
= default_invis_vector
;
3261 it
->dpend
= default_invis_vector
+ 3;
3264 /* The ellipsis display does not replace the display of the
3265 character at the new position. Indicate this by setting
3266 IT->dpvec_char_len to zero. */
3267 it
->dpvec_char_len
= 0;
3269 it
->current
.dpvec_index
= 0;
3270 it
->method
= next_element_from_display_vector
;
3275 /***********************************************************************
3277 ***********************************************************************/
3279 /* Set up iterator IT from `display' property at its current position.
3280 Called from handle_stop. */
3282 static enum prop_handled
3283 handle_display_prop (it
)
3286 Lisp_Object prop
, object
;
3287 struct text_pos
*position
;
3288 int display_replaced_p
= 0;
3290 if (STRINGP (it
->string
))
3292 object
= it
->string
;
3293 position
= &it
->current
.string_pos
;
3297 object
= it
->w
->buffer
;
3298 position
= &it
->current
.pos
;
3301 /* Reset those iterator values set from display property values. */
3302 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3303 it
->space_width
= Qnil
;
3304 it
->font_height
= Qnil
;
3307 /* We don't support recursive `display' properties, i.e. string
3308 values that have a string `display' property, that have a string
3309 `display' property etc. */
3310 if (!it
->string_from_display_prop_p
)
3311 it
->area
= TEXT_AREA
;
3313 prop
= Fget_char_property (make_number (position
->charpos
),
3316 return HANDLED_NORMALLY
;
3319 /* Simple properties. */
3320 && !EQ (XCAR (prop
), Qimage
)
3321 && !EQ (XCAR (prop
), Qspace
)
3322 && !EQ (XCAR (prop
), Qwhen
)
3323 && !EQ (XCAR (prop
), Qslice
)
3324 && !EQ (XCAR (prop
), Qspace_width
)
3325 && !EQ (XCAR (prop
), Qheight
)
3326 && !EQ (XCAR (prop
), Qraise
)
3327 /* Marginal area specifications. */
3328 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3329 && !EQ (XCAR (prop
), Qleft_fringe
)
3330 && !EQ (XCAR (prop
), Qright_fringe
)
3331 && !NILP (XCAR (prop
)))
3333 for (; CONSP (prop
); prop
= XCDR (prop
))
3335 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3336 position
, display_replaced_p
))
3337 display_replaced_p
= 1;
3340 else if (VECTORP (prop
))
3343 for (i
= 0; i
< ASIZE (prop
); ++i
)
3344 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3345 position
, display_replaced_p
))
3346 display_replaced_p
= 1;
3350 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3351 display_replaced_p
= 1;
3354 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3358 /* Value is the position of the end of the `display' property starting
3359 at START_POS in OBJECT. */
3361 static struct text_pos
3362 display_prop_end (it
, object
, start_pos
)
3365 struct text_pos start_pos
;
3368 struct text_pos end_pos
;
3370 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3371 Qdisplay
, object
, Qnil
);
3372 CHARPOS (end_pos
) = XFASTINT (end
);
3373 if (STRINGP (object
))
3374 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3376 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3382 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3383 is the object in which the `display' property was found. *POSITION
3384 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3385 means that we previously saw a display sub-property which already
3386 replaced text display with something else, for example an image;
3387 ignore such properties after the first one has been processed.
3389 If PROP is a `space' or `image' sub-property, set *POSITION to the
3390 end position of the `display' property.
3392 Value is non-zero if something was found which replaces the display
3393 of buffer or string text. */
3396 handle_single_display_prop (it
, prop
, object
, position
,
3397 display_replaced_before_p
)
3401 struct text_pos
*position
;
3402 int display_replaced_before_p
;
3405 int replaces_text_display_p
= 0;
3408 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3409 evaluated. If the result is nil, VALUE is ignored. */
3411 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3420 if (!NILP (form
) && !EQ (form
, Qt
))
3422 int count
= SPECPDL_INDEX ();
3423 struct gcpro gcpro1
;
3425 /* Bind `object' to the object having the `display' property, a
3426 buffer or string. Bind `position' to the position in the
3427 object where the property was found, and `buffer-position'
3428 to the current position in the buffer. */
3429 specbind (Qobject
, object
);
3430 specbind (Qposition
, make_number (CHARPOS (*position
)));
3431 specbind (Qbuffer_position
,
3432 make_number (STRINGP (object
)
3433 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3435 form
= safe_eval (form
);
3437 unbind_to (count
, Qnil
);
3444 && EQ (XCAR (prop
), Qheight
)
3445 && CONSP (XCDR (prop
)))
3447 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3450 /* `(height HEIGHT)'. */
3451 it
->font_height
= XCAR (XCDR (prop
));
3452 if (!NILP (it
->font_height
))
3454 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3455 int new_height
= -1;
3457 if (CONSP (it
->font_height
)
3458 && (EQ (XCAR (it
->font_height
), Qplus
)
3459 || EQ (XCAR (it
->font_height
), Qminus
))
3460 && CONSP (XCDR (it
->font_height
))
3461 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3463 /* `(+ N)' or `(- N)' where N is an integer. */
3464 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3465 if (EQ (XCAR (it
->font_height
), Qplus
))
3467 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3469 else if (FUNCTIONP (it
->font_height
))
3471 /* Call function with current height as argument.
3472 Value is the new height. */
3474 height
= safe_call1 (it
->font_height
,
3475 face
->lface
[LFACE_HEIGHT_INDEX
]);
3476 if (NUMBERP (height
))
3477 new_height
= XFLOATINT (height
);
3479 else if (NUMBERP (it
->font_height
))
3481 /* Value is a multiple of the canonical char height. */
3484 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3485 new_height
= (XFLOATINT (it
->font_height
)
3486 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3490 /* Evaluate IT->font_height with `height' bound to the
3491 current specified height to get the new height. */
3493 int count
= SPECPDL_INDEX ();
3495 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3496 value
= safe_eval (it
->font_height
);
3497 unbind_to (count
, Qnil
);
3499 if (NUMBERP (value
))
3500 new_height
= XFLOATINT (value
);
3504 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3507 else if (CONSP (prop
)
3508 && EQ (XCAR (prop
), Qspace_width
)
3509 && CONSP (XCDR (prop
)))
3511 /* `(space_width WIDTH)'. */
3512 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3515 value
= XCAR (XCDR (prop
));
3516 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3517 it
->space_width
= value
;
3519 else if (CONSP (prop
)
3520 && EQ (XCAR (prop
), Qslice
))
3522 /* `(slice X Y WIDTH HEIGHT)'. */
3525 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3528 if (tem
= XCDR (prop
), CONSP (tem
))
3530 it
->slice
.x
= XCAR (tem
);
3531 if (tem
= XCDR (tem
), CONSP (tem
))
3533 it
->slice
.y
= XCAR (tem
);
3534 if (tem
= XCDR (tem
), CONSP (tem
))
3536 it
->slice
.width
= XCAR (tem
);
3537 if (tem
= XCDR (tem
), CONSP (tem
))
3538 it
->slice
.height
= XCAR (tem
);
3543 else if (CONSP (prop
)
3544 && EQ (XCAR (prop
), Qraise
)
3545 && CONSP (XCDR (prop
)))
3547 /* `(raise FACTOR)'. */
3548 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3551 #ifdef HAVE_WINDOW_SYSTEM
3552 value
= XCAR (XCDR (prop
));
3553 if (NUMBERP (value
))
3555 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3556 it
->voffset
= - (XFLOATINT (value
)
3557 * (FONT_HEIGHT (face
->font
)));
3559 #endif /* HAVE_WINDOW_SYSTEM */
3561 else if (!it
->string_from_display_prop_p
)
3563 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3564 VALUE) or `((margin nil) VALUE)' or VALUE. */
3565 Lisp_Object location
, value
;
3566 struct text_pos start_pos
;
3569 /* Characters having this form of property are not displayed, so
3570 we have to find the end of the property. */
3571 start_pos
= *position
;
3572 *position
= display_prop_end (it
, object
, start_pos
);
3575 /* Let's stop at the new position and assume that all
3576 text properties change there. */
3577 it
->stop_charpos
= position
->charpos
;
3580 && (EQ (XCAR (prop
), Qleft_fringe
)
3581 || EQ (XCAR (prop
), Qright_fringe
))
3582 && CONSP (XCDR (prop
)))
3584 unsigned face_id
= DEFAULT_FACE_ID
;
3586 /* Save current settings of IT so that we can restore them
3587 when we are finished with the glyph property value. */
3589 /* `(left-fringe BITMAP FACE)'. */
3590 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3593 #ifdef HAVE_WINDOW_SYSTEM
3594 value
= XCAR (XCDR (prop
));
3595 if (!NUMBERP (value
)
3596 || !valid_fringe_bitmap_id_p (XINT (value
)))
3599 if (CONSP (XCDR (XCDR (prop
))))
3601 Lisp_Object face_name
= XCAR (XCDR (XCDR (prop
)));
3603 face_id
= lookup_named_face (it
->f
, face_name
, 'A');
3610 it
->area
= TEXT_AREA
;
3611 it
->what
= IT_IMAGE
;
3612 it
->image_id
= -1; /* no image */
3613 it
->position
= start_pos
;
3614 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3615 it
->method
= next_element_from_image
;
3616 it
->face_id
= face_id
;
3618 /* Say that we haven't consumed the characters with
3619 `display' property yet. The call to pop_it in
3620 set_iterator_to_next will clean this up. */
3621 *position
= start_pos
;
3623 if (EQ (XCAR (prop
), Qleft_fringe
))
3625 it
->left_user_fringe_bitmap
= XINT (value
);
3626 it
->left_user_fringe_face_id
= face_id
;
3630 it
->right_user_fringe_bitmap
= XINT (value
);
3631 it
->right_user_fringe_face_id
= face_id
;
3633 #endif /* HAVE_WINDOW_SYSTEM */
3637 location
= Qunbound
;
3638 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3642 value
= XCDR (prop
);
3644 value
= XCAR (value
);
3647 if (EQ (XCAR (tem
), Qmargin
)
3648 && (tem
= XCDR (tem
),
3649 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3651 || EQ (tem
, Qleft_margin
)
3652 || EQ (tem
, Qright_margin
))))
3656 if (EQ (location
, Qunbound
))
3662 valid_p
= (STRINGP (value
)
3663 #ifdef HAVE_WINDOW_SYSTEM
3664 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3665 #endif /* not HAVE_WINDOW_SYSTEM */
3666 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3668 if ((EQ (location
, Qleft_margin
)
3669 || EQ (location
, Qright_margin
)
3672 && !display_replaced_before_p
)
3674 replaces_text_display_p
= 1;
3676 /* Save current settings of IT so that we can restore them
3677 when we are finished with the glyph property value. */
3680 if (NILP (location
))
3681 it
->area
= TEXT_AREA
;
3682 else if (EQ (location
, Qleft_margin
))
3683 it
->area
= LEFT_MARGIN_AREA
;
3685 it
->area
= RIGHT_MARGIN_AREA
;
3687 if (STRINGP (value
))
3690 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3691 it
->current
.overlay_string_index
= -1;
3692 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3693 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3694 it
->method
= next_element_from_string
;
3695 it
->stop_charpos
= 0;
3696 it
->string_from_display_prop_p
= 1;
3697 /* Say that we haven't consumed the characters with
3698 `display' property yet. The call to pop_it in
3699 set_iterator_to_next will clean this up. */
3700 *position
= start_pos
;
3702 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3704 it
->method
= next_element_from_stretch
;
3706 it
->current
.pos
= it
->position
= start_pos
;
3708 #ifdef HAVE_WINDOW_SYSTEM
3711 it
->what
= IT_IMAGE
;
3712 it
->image_id
= lookup_image (it
->f
, value
);
3713 it
->position
= start_pos
;
3714 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3715 it
->method
= next_element_from_image
;
3717 /* Say that we haven't consumed the characters with
3718 `display' property yet. The call to pop_it in
3719 set_iterator_to_next will clean this up. */
3720 *position
= start_pos
;
3722 #endif /* HAVE_WINDOW_SYSTEM */
3725 /* Invalid property or property not supported. Restore
3726 the position to what it was before. */
3727 *position
= start_pos
;
3730 return replaces_text_display_p
;
3734 /* Check if PROP is a display sub-property value whose text should be
3735 treated as intangible. */
3738 single_display_prop_intangible_p (prop
)
3741 /* Skip over `when FORM'. */
3742 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3756 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3757 we don't need to treat text as intangible. */
3758 if (EQ (XCAR (prop
), Qmargin
))
3766 || EQ (XCAR (prop
), Qleft_margin
)
3767 || EQ (XCAR (prop
), Qright_margin
))
3771 return (CONSP (prop
)
3772 && (EQ (XCAR (prop
), Qimage
)
3773 || EQ (XCAR (prop
), Qspace
)));
3777 /* Check if PROP is a display property value whose text should be
3778 treated as intangible. */
3781 display_prop_intangible_p (prop
)
3785 && CONSP (XCAR (prop
))
3786 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3788 /* A list of sub-properties. */
3789 while (CONSP (prop
))
3791 if (single_display_prop_intangible_p (XCAR (prop
)))
3796 else if (VECTORP (prop
))
3798 /* A vector of sub-properties. */
3800 for (i
= 0; i
< ASIZE (prop
); ++i
)
3801 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3805 return single_display_prop_intangible_p (prop
);
3811 /* Return 1 if PROP is a display sub-property value containing STRING. */
3814 single_display_prop_string_p (prop
, string
)
3815 Lisp_Object prop
, string
;
3817 if (EQ (string
, prop
))
3820 /* Skip over `when FORM'. */
3821 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3830 /* Skip over `margin LOCATION'. */
3831 if (EQ (XCAR (prop
), Qmargin
))
3842 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3846 /* Return 1 if STRING appears in the `display' property PROP. */
3849 display_prop_string_p (prop
, string
)
3850 Lisp_Object prop
, string
;
3853 && CONSP (XCAR (prop
))
3854 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3856 /* A list of sub-properties. */
3857 while (CONSP (prop
))
3859 if (single_display_prop_string_p (XCAR (prop
), string
))
3864 else if (VECTORP (prop
))
3866 /* A vector of sub-properties. */
3868 for (i
= 0; i
< ASIZE (prop
); ++i
)
3869 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3873 return single_display_prop_string_p (prop
, string
);
3879 /* Determine from which buffer position in W's buffer STRING comes
3880 from. AROUND_CHARPOS is an approximate position where it could
3881 be from. Value is the buffer position or 0 if it couldn't be
3884 W's buffer must be current.
3886 This function is necessary because we don't record buffer positions
3887 in glyphs generated from strings (to keep struct glyph small).
3888 This function may only use code that doesn't eval because it is
3889 called asynchronously from note_mouse_highlight. */
3892 string_buffer_position (w
, string
, around_charpos
)
3897 Lisp_Object limit
, prop
, pos
;
3898 const int MAX_DISTANCE
= 1000;
3901 pos
= make_number (around_charpos
);
3902 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3903 while (!found
&& !EQ (pos
, limit
))
3905 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3906 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3909 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3914 pos
= make_number (around_charpos
);
3915 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3916 while (!found
&& !EQ (pos
, limit
))
3918 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3919 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3922 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3927 return found
? XINT (pos
) : 0;
3932 /***********************************************************************
3933 `composition' property
3934 ***********************************************************************/
3936 /* Set up iterator IT from `composition' property at its current
3937 position. Called from handle_stop. */
3939 static enum prop_handled
3940 handle_composition_prop (it
)
3943 Lisp_Object prop
, string
;
3944 int pos
, pos_byte
, end
;
3945 enum prop_handled handled
= HANDLED_NORMALLY
;
3947 if (STRINGP (it
->string
))
3949 pos
= IT_STRING_CHARPOS (*it
);
3950 pos_byte
= IT_STRING_BYTEPOS (*it
);
3951 string
= it
->string
;
3955 pos
= IT_CHARPOS (*it
);
3956 pos_byte
= IT_BYTEPOS (*it
);
3960 /* If there's a valid composition and point is not inside of the
3961 composition (in the case that the composition is from the current
3962 buffer), draw a glyph composed from the composition components. */
3963 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3964 && COMPOSITION_VALID_P (pos
, end
, prop
)
3965 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3967 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3971 it
->method
= next_element_from_composition
;
3973 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3974 /* For a terminal, draw only the first character of the
3976 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3977 it
->len
= (STRINGP (it
->string
)
3978 ? string_char_to_byte (it
->string
, end
)
3979 : CHAR_TO_BYTE (end
)) - pos_byte
;
3980 it
->stop_charpos
= end
;
3981 handled
= HANDLED_RETURN
;
3990 /***********************************************************************
3992 ***********************************************************************/
3994 /* The following structure is used to record overlay strings for
3995 later sorting in load_overlay_strings. */
3997 struct overlay_entry
3999 Lisp_Object overlay
;
4006 /* Set up iterator IT from overlay strings at its current position.
4007 Called from handle_stop. */
4009 static enum prop_handled
4010 handle_overlay_change (it
)
4013 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4014 return HANDLED_RECOMPUTE_PROPS
;
4016 return HANDLED_NORMALLY
;
4020 /* Set up the next overlay string for delivery by IT, if there is an
4021 overlay string to deliver. Called by set_iterator_to_next when the
4022 end of the current overlay string is reached. If there are more
4023 overlay strings to display, IT->string and
4024 IT->current.overlay_string_index are set appropriately here.
4025 Otherwise IT->string is set to nil. */
4028 next_overlay_string (it
)
4031 ++it
->current
.overlay_string_index
;
4032 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4034 /* No more overlay strings. Restore IT's settings to what
4035 they were before overlay strings were processed, and
4036 continue to deliver from current_buffer. */
4037 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4040 xassert (it
->stop_charpos
>= BEGV
4041 && it
->stop_charpos
<= it
->end_charpos
);
4043 it
->current
.overlay_string_index
= -1;
4044 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4045 it
->n_overlay_strings
= 0;
4046 it
->method
= next_element_from_buffer
;
4048 /* If we're at the end of the buffer, record that we have
4049 processed the overlay strings there already, so that
4050 next_element_from_buffer doesn't try it again. */
4051 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4052 it
->overlay_strings_at_end_processed_p
= 1;
4054 /* If we have to display `...' for invisible text, set
4055 the iterator up for that. */
4056 if (display_ellipsis_p
)
4057 setup_for_ellipsis (it
);
4061 /* There are more overlay strings to process. If
4062 IT->current.overlay_string_index has advanced to a position
4063 where we must load IT->overlay_strings with more strings, do
4065 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4067 if (it
->current
.overlay_string_index
&& i
== 0)
4068 load_overlay_strings (it
, 0);
4070 /* Initialize IT to deliver display elements from the overlay
4072 it
->string
= it
->overlay_strings
[i
];
4073 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4074 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4075 it
->method
= next_element_from_string
;
4076 it
->stop_charpos
= 0;
4083 /* Compare two overlay_entry structures E1 and E2. Used as a
4084 comparison function for qsort in load_overlay_strings. Overlay
4085 strings for the same position are sorted so that
4087 1. All after-strings come in front of before-strings, except
4088 when they come from the same overlay.
4090 2. Within after-strings, strings are sorted so that overlay strings
4091 from overlays with higher priorities come first.
4093 2. Within before-strings, strings are sorted so that overlay
4094 strings from overlays with higher priorities come last.
4096 Value is analogous to strcmp. */
4100 compare_overlay_entries (e1
, e2
)
4103 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4104 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4107 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4109 /* Let after-strings appear in front of before-strings if
4110 they come from different overlays. */
4111 if (EQ (entry1
->overlay
, entry2
->overlay
))
4112 result
= entry1
->after_string_p
? 1 : -1;
4114 result
= entry1
->after_string_p
? -1 : 1;
4116 else if (entry1
->after_string_p
)
4117 /* After-strings sorted in order of decreasing priority. */
4118 result
= entry2
->priority
- entry1
->priority
;
4120 /* Before-strings sorted in order of increasing priority. */
4121 result
= entry1
->priority
- entry2
->priority
;
4127 /* Load the vector IT->overlay_strings with overlay strings from IT's
4128 current buffer position, or from CHARPOS if that is > 0. Set
4129 IT->n_overlays to the total number of overlay strings found.
4131 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4132 a time. On entry into load_overlay_strings,
4133 IT->current.overlay_string_index gives the number of overlay
4134 strings that have already been loaded by previous calls to this
4137 IT->add_overlay_start contains an additional overlay start
4138 position to consider for taking overlay strings from, if non-zero.
4139 This position comes into play when the overlay has an `invisible'
4140 property, and both before and after-strings. When we've skipped to
4141 the end of the overlay, because of its `invisible' property, we
4142 nevertheless want its before-string to appear.
4143 IT->add_overlay_start will contain the overlay start position
4146 Overlay strings are sorted so that after-string strings come in
4147 front of before-string strings. Within before and after-strings,
4148 strings are sorted by overlay priority. See also function
4149 compare_overlay_entries. */
4152 load_overlay_strings (it
, charpos
)
4156 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4157 Lisp_Object overlay
, window
, str
, invisible
;
4158 struct Lisp_Overlay
*ov
;
4161 int n
= 0, i
, j
, invis_p
;
4162 struct overlay_entry
*entries
4163 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4166 charpos
= IT_CHARPOS (*it
);
4168 /* Append the overlay string STRING of overlay OVERLAY to vector
4169 `entries' which has size `size' and currently contains `n'
4170 elements. AFTER_P non-zero means STRING is an after-string of
4172 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4175 Lisp_Object priority; \
4179 int new_size = 2 * size; \
4180 struct overlay_entry *old = entries; \
4182 (struct overlay_entry *) alloca (new_size \
4183 * sizeof *entries); \
4184 bcopy (old, entries, size * sizeof *entries); \
4188 entries[n].string = (STRING); \
4189 entries[n].overlay = (OVERLAY); \
4190 priority = Foverlay_get ((OVERLAY), Qpriority); \
4191 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4192 entries[n].after_string_p = (AFTER_P); \
4197 /* Process overlay before the overlay center. */
4198 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4200 XSETMISC (overlay
, ov
);
4201 xassert (OVERLAYP (overlay
));
4202 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4203 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4208 /* Skip this overlay if it doesn't start or end at IT's current
4210 if (end
!= charpos
&& start
!= charpos
)
4213 /* Skip this overlay if it doesn't apply to IT->w. */
4214 window
= Foverlay_get (overlay
, Qwindow
);
4215 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4218 /* If the text ``under'' the overlay is invisible, both before-
4219 and after-strings from this overlay are visible; start and
4220 end position are indistinguishable. */
4221 invisible
= Foverlay_get (overlay
, Qinvisible
);
4222 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4224 /* If overlay has a non-empty before-string, record it. */
4225 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4226 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4228 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4230 /* If overlay has a non-empty after-string, record it. */
4231 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4232 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4234 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4237 /* Process overlays after the overlay center. */
4238 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4240 XSETMISC (overlay
, ov
);
4241 xassert (OVERLAYP (overlay
));
4242 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4243 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4245 if (start
> charpos
)
4248 /* Skip this overlay if it doesn't start or end at IT's current
4250 if (end
!= charpos
&& start
!= charpos
)
4253 /* Skip this overlay if it doesn't apply to IT->w. */
4254 window
= Foverlay_get (overlay
, Qwindow
);
4255 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4258 /* If the text ``under'' the overlay is invisible, it has a zero
4259 dimension, and both before- and after-strings apply. */
4260 invisible
= Foverlay_get (overlay
, Qinvisible
);
4261 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4263 /* If overlay has a non-empty before-string, record it. */
4264 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4265 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4267 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4269 /* If overlay has a non-empty after-string, record it. */
4270 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4271 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4273 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4276 #undef RECORD_OVERLAY_STRING
4280 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4282 /* Record the total number of strings to process. */
4283 it
->n_overlay_strings
= n
;
4285 /* IT->current.overlay_string_index is the number of overlay strings
4286 that have already been consumed by IT. Copy some of the
4287 remaining overlay strings to IT->overlay_strings. */
4289 j
= it
->current
.overlay_string_index
;
4290 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4291 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4297 /* Get the first chunk of overlay strings at IT's current buffer
4298 position, or at CHARPOS if that is > 0. Value is non-zero if at
4299 least one overlay string was found. */
4302 get_overlay_strings (it
, charpos
)
4306 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4307 process. This fills IT->overlay_strings with strings, and sets
4308 IT->n_overlay_strings to the total number of strings to process.
4309 IT->pos.overlay_string_index has to be set temporarily to zero
4310 because load_overlay_strings needs this; it must be set to -1
4311 when no overlay strings are found because a zero value would
4312 indicate a position in the first overlay string. */
4313 it
->current
.overlay_string_index
= 0;
4314 load_overlay_strings (it
, charpos
);
4316 /* If we found overlay strings, set up IT to deliver display
4317 elements from the first one. Otherwise set up IT to deliver
4318 from current_buffer. */
4319 if (it
->n_overlay_strings
)
4321 /* Make sure we know settings in current_buffer, so that we can
4322 restore meaningful values when we're done with the overlay
4324 compute_stop_pos (it
);
4325 xassert (it
->face_id
>= 0);
4327 /* Save IT's settings. They are restored after all overlay
4328 strings have been processed. */
4329 xassert (it
->sp
== 0);
4332 /* Set up IT to deliver display elements from the first overlay
4334 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4335 it
->string
= it
->overlay_strings
[0];
4336 it
->stop_charpos
= 0;
4337 xassert (STRINGP (it
->string
));
4338 it
->end_charpos
= SCHARS (it
->string
);
4339 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4340 it
->method
= next_element_from_string
;
4345 it
->current
.overlay_string_index
= -1;
4346 it
->method
= next_element_from_buffer
;
4351 /* Value is non-zero if we found at least one overlay string. */
4352 return STRINGP (it
->string
);
4357 /***********************************************************************
4358 Saving and restoring state
4359 ***********************************************************************/
4361 /* Save current settings of IT on IT->stack. Called, for example,
4362 before setting up IT for an overlay string, to be able to restore
4363 IT's settings to what they were after the overlay string has been
4370 struct iterator_stack_entry
*p
;
4372 xassert (it
->sp
< 2);
4373 p
= it
->stack
+ it
->sp
;
4375 p
->stop_charpos
= it
->stop_charpos
;
4376 xassert (it
->face_id
>= 0);
4377 p
->face_id
= it
->face_id
;
4378 p
->string
= it
->string
;
4379 p
->pos
= it
->current
;
4380 p
->end_charpos
= it
->end_charpos
;
4381 p
->string_nchars
= it
->string_nchars
;
4383 p
->multibyte_p
= it
->multibyte_p
;
4384 p
->slice
= it
->slice
;
4385 p
->space_width
= it
->space_width
;
4386 p
->font_height
= it
->font_height
;
4387 p
->voffset
= it
->voffset
;
4388 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4389 p
->display_ellipsis_p
= 0;
4394 /* Restore IT's settings from IT->stack. Called, for example, when no
4395 more overlay strings must be processed, and we return to delivering
4396 display elements from a buffer, or when the end of a string from a
4397 `display' property is reached and we return to delivering display
4398 elements from an overlay string, or from a buffer. */
4404 struct iterator_stack_entry
*p
;
4406 xassert (it
->sp
> 0);
4408 p
= it
->stack
+ it
->sp
;
4409 it
->stop_charpos
= p
->stop_charpos
;
4410 it
->face_id
= p
->face_id
;
4411 it
->string
= p
->string
;
4412 it
->current
= p
->pos
;
4413 it
->end_charpos
= p
->end_charpos
;
4414 it
->string_nchars
= p
->string_nchars
;
4416 it
->multibyte_p
= p
->multibyte_p
;
4417 it
->slice
= p
->slice
;
4418 it
->space_width
= p
->space_width
;
4419 it
->font_height
= p
->font_height
;
4420 it
->voffset
= p
->voffset
;
4421 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4426 /***********************************************************************
4428 ***********************************************************************/
4430 /* Set IT's current position to the previous line start. */
4433 back_to_previous_line_start (it
)
4436 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4437 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4441 /* Move IT to the next line start.
4443 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4444 we skipped over part of the text (as opposed to moving the iterator
4445 continuously over the text). Otherwise, don't change the value
4448 Newlines may come from buffer text, overlay strings, or strings
4449 displayed via the `display' property. That's the reason we can't
4450 simply use find_next_newline_no_quit.
4452 Note that this function may not skip over invisible text that is so
4453 because of text properties and immediately follows a newline. If
4454 it would, function reseat_at_next_visible_line_start, when called
4455 from set_iterator_to_next, would effectively make invisible
4456 characters following a newline part of the wrong glyph row, which
4457 leads to wrong cursor motion. */
4460 forward_to_next_line_start (it
, skipped_p
)
4464 int old_selective
, newline_found_p
, n
;
4465 const int MAX_NEWLINE_DISTANCE
= 500;
4467 /* If already on a newline, just consume it to avoid unintended
4468 skipping over invisible text below. */
4469 if (it
->what
== IT_CHARACTER
4471 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4473 set_iterator_to_next (it
, 0);
4478 /* Don't handle selective display in the following. It's (a)
4479 unnecessary because it's done by the caller, and (b) leads to an
4480 infinite recursion because next_element_from_ellipsis indirectly
4481 calls this function. */
4482 old_selective
= it
->selective
;
4485 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4486 from buffer text. */
4487 for (n
= newline_found_p
= 0;
4488 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4489 n
+= STRINGP (it
->string
) ? 0 : 1)
4491 if (!get_next_display_element (it
))
4493 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4494 set_iterator_to_next (it
, 0);
4497 /* If we didn't find a newline near enough, see if we can use a
4499 if (!newline_found_p
)
4501 int start
= IT_CHARPOS (*it
);
4502 int limit
= find_next_newline_no_quit (start
, 1);
4505 xassert (!STRINGP (it
->string
));
4507 /* If there isn't any `display' property in sight, and no
4508 overlays, we can just use the position of the newline in
4510 if (it
->stop_charpos
>= limit
4511 || ((pos
= Fnext_single_property_change (make_number (start
),
4513 Qnil
, make_number (limit
)),
4515 && next_overlay_change (start
) == ZV
))
4517 IT_CHARPOS (*it
) = limit
;
4518 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4519 *skipped_p
= newline_found_p
= 1;
4523 while (get_next_display_element (it
)
4524 && !newline_found_p
)
4526 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4527 set_iterator_to_next (it
, 0);
4532 it
->selective
= old_selective
;
4533 return newline_found_p
;
4537 /* Set IT's current position to the previous visible line start. Skip
4538 invisible text that is so either due to text properties or due to
4539 selective display. Caution: this does not change IT->current_x and
4543 back_to_previous_visible_line_start (it
)
4548 /* Go back one newline if not on BEGV already. */
4549 if (IT_CHARPOS (*it
) > BEGV
)
4550 back_to_previous_line_start (it
);
4552 /* Move over lines that are invisible because of selective display
4553 or text properties. */
4554 while (IT_CHARPOS (*it
) > BEGV
4559 /* If selective > 0, then lines indented more than that values
4561 if (it
->selective
> 0
4562 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4563 (double) it
->selective
)) /* iftc */
4569 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4570 Qinvisible
, it
->window
);
4571 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4575 /* Back one more newline if the current one is invisible. */
4577 back_to_previous_line_start (it
);
4580 xassert (IT_CHARPOS (*it
) >= BEGV
);
4581 xassert (IT_CHARPOS (*it
) == BEGV
4582 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4587 /* Reseat iterator IT at the previous visible line start. Skip
4588 invisible text that is so either due to text properties or due to
4589 selective display. At the end, update IT's overlay information,
4590 face information etc. */
4593 reseat_at_previous_visible_line_start (it
)
4596 back_to_previous_visible_line_start (it
);
4597 reseat (it
, it
->current
.pos
, 1);
4602 /* Reseat iterator IT on the next visible line start in the current
4603 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4604 preceding the line start. Skip over invisible text that is so
4605 because of selective display. Compute faces, overlays etc at the
4606 new position. Note that this function does not skip over text that
4607 is invisible because of text properties. */
4610 reseat_at_next_visible_line_start (it
, on_newline_p
)
4614 int newline_found_p
, skipped_p
= 0;
4616 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4618 /* Skip over lines that are invisible because they are indented
4619 more than the value of IT->selective. */
4620 if (it
->selective
> 0)
4621 while (IT_CHARPOS (*it
) < ZV
4622 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4623 (double) it
->selective
)) /* iftc */
4625 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4626 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4629 /* Position on the newline if that's what's requested. */
4630 if (on_newline_p
&& newline_found_p
)
4632 if (STRINGP (it
->string
))
4634 if (IT_STRING_CHARPOS (*it
) > 0)
4636 --IT_STRING_CHARPOS (*it
);
4637 --IT_STRING_BYTEPOS (*it
);
4640 else if (IT_CHARPOS (*it
) > BEGV
)
4644 reseat (it
, it
->current
.pos
, 0);
4648 reseat (it
, it
->current
.pos
, 0);
4655 /***********************************************************************
4656 Changing an iterator's position
4657 ***********************************************************************/
4659 /* Change IT's current position to POS in current_buffer. If FORCE_P
4660 is non-zero, always check for text properties at the new position.
4661 Otherwise, text properties are only looked up if POS >=
4662 IT->check_charpos of a property. */
4665 reseat (it
, pos
, force_p
)
4667 struct text_pos pos
;
4670 int original_pos
= IT_CHARPOS (*it
);
4672 reseat_1 (it
, pos
, 0);
4674 /* Determine where to check text properties. Avoid doing it
4675 where possible because text property lookup is very expensive. */
4677 || CHARPOS (pos
) > it
->stop_charpos
4678 || CHARPOS (pos
) < original_pos
)
4685 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4686 IT->stop_pos to POS, also. */
4689 reseat_1 (it
, pos
, set_stop_p
)
4691 struct text_pos pos
;
4694 /* Don't call this function when scanning a C string. */
4695 xassert (it
->s
== NULL
);
4697 /* POS must be a reasonable value. */
4698 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4700 it
->current
.pos
= it
->position
= pos
;
4701 XSETBUFFER (it
->object
, current_buffer
);
4702 it
->end_charpos
= ZV
;
4704 it
->current
.dpvec_index
= -1;
4705 it
->current
.overlay_string_index
= -1;
4706 IT_STRING_CHARPOS (*it
) = -1;
4707 IT_STRING_BYTEPOS (*it
) = -1;
4709 it
->method
= next_element_from_buffer
;
4710 /* RMS: I added this to fix a bug in move_it_vertically_backward
4711 where it->area continued to relate to the starting point
4712 for the backward motion. Bug report from
4713 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4714 However, I am not sure whether reseat still does the right thing
4715 in general after this change. */
4716 it
->area
= TEXT_AREA
;
4717 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4719 it
->face_before_selective_p
= 0;
4722 it
->stop_charpos
= CHARPOS (pos
);
4726 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4727 If S is non-null, it is a C string to iterate over. Otherwise,
4728 STRING gives a Lisp string to iterate over.
4730 If PRECISION > 0, don't return more then PRECISION number of
4731 characters from the string.
4733 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4734 characters have been returned. FIELD_WIDTH < 0 means an infinite
4737 MULTIBYTE = 0 means disable processing of multibyte characters,
4738 MULTIBYTE > 0 means enable it,
4739 MULTIBYTE < 0 means use IT->multibyte_p.
4741 IT must be initialized via a prior call to init_iterator before
4742 calling this function. */
4745 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4750 int precision
, field_width
, multibyte
;
4752 /* No region in strings. */
4753 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4755 /* No text property checks performed by default, but see below. */
4756 it
->stop_charpos
= -1;
4758 /* Set iterator position and end position. */
4759 bzero (&it
->current
, sizeof it
->current
);
4760 it
->current
.overlay_string_index
= -1;
4761 it
->current
.dpvec_index
= -1;
4762 xassert (charpos
>= 0);
4764 /* If STRING is specified, use its multibyteness, otherwise use the
4765 setting of MULTIBYTE, if specified. */
4767 it
->multibyte_p
= multibyte
> 0;
4771 xassert (STRINGP (string
));
4772 it
->string
= string
;
4774 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4775 it
->method
= next_element_from_string
;
4776 it
->current
.string_pos
= string_pos (charpos
, string
);
4783 /* Note that we use IT->current.pos, not it->current.string_pos,
4784 for displaying C strings. */
4785 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4786 if (it
->multibyte_p
)
4788 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4789 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4793 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4794 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4797 it
->method
= next_element_from_c_string
;
4800 /* PRECISION > 0 means don't return more than PRECISION characters
4802 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4803 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4805 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4806 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4807 FIELD_WIDTH < 0 means infinite field width. This is useful for
4808 padding with `-' at the end of a mode line. */
4809 if (field_width
< 0)
4810 field_width
= INFINITY
;
4811 if (field_width
> it
->end_charpos
- charpos
)
4812 it
->end_charpos
= charpos
+ field_width
;
4814 /* Use the standard display table for displaying strings. */
4815 if (DISP_TABLE_P (Vstandard_display_table
))
4816 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4818 it
->stop_charpos
= charpos
;
4824 /***********************************************************************
4826 ***********************************************************************/
4828 /* Load IT's display element fields with information about the next
4829 display element from the current position of IT. Value is zero if
4830 end of buffer (or C string) is reached. */
4833 get_next_display_element (it
)
4836 /* Non-zero means that we found a display element. Zero means that
4837 we hit the end of what we iterate over. Performance note: the
4838 function pointer `method' used here turns out to be faster than
4839 using a sequence of if-statements. */
4840 int success_p
= (*it
->method
) (it
);
4842 if (it
->what
== IT_CHARACTER
)
4844 /* Map via display table or translate control characters.
4845 IT->c, IT->len etc. have been set to the next character by
4846 the function call above. If we have a display table, and it
4847 contains an entry for IT->c, translate it. Don't do this if
4848 IT->c itself comes from a display table, otherwise we could
4849 end up in an infinite recursion. (An alternative could be to
4850 count the recursion depth of this function and signal an
4851 error when a certain maximum depth is reached.) Is it worth
4853 if (success_p
&& it
->dpvec
== NULL
)
4858 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4861 struct Lisp_Vector
*v
= XVECTOR (dv
);
4863 /* Return the first character from the display table
4864 entry, if not empty. If empty, don't display the
4865 current character. */
4868 it
->dpvec_char_len
= it
->len
;
4869 it
->dpvec
= v
->contents
;
4870 it
->dpend
= v
->contents
+ v
->size
;
4871 it
->current
.dpvec_index
= 0;
4872 it
->method
= next_element_from_display_vector
;
4873 success_p
= get_next_display_element (it
);
4877 set_iterator_to_next (it
, 0);
4878 success_p
= get_next_display_element (it
);
4882 /* Translate control characters into `\003' or `^C' form.
4883 Control characters coming from a display table entry are
4884 currently not translated because we use IT->dpvec to hold
4885 the translation. This could easily be changed but I
4886 don't believe that it is worth doing.
4888 If it->multibyte_p is nonzero, eight-bit characters and
4889 non-printable multibyte characters are also translated to
4892 If it->multibyte_p is zero, eight-bit characters that
4893 don't have corresponding multibyte char code are also
4894 translated to octal form. */
4895 else if ((it
->c
< ' '
4896 && (it
->area
!= TEXT_AREA
4897 || (it
->c
!= '\n' && it
->c
!= '\t')))
4901 || !CHAR_PRINTABLE_P (it
->c
))
4903 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4905 /* IT->c is a control character which must be displayed
4906 either as '\003' or as `^C' where the '\\' and '^'
4907 can be defined in the display table. Fill
4908 IT->ctl_chars with glyphs for what we have to
4909 display. Then, set IT->dpvec to these glyphs. */
4912 if (it
->c
< 128 && it
->ctl_arrow_p
)
4914 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4916 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4917 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4918 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4920 g
= FAST_MAKE_GLYPH ('^', 0);
4921 XSETINT (it
->ctl_chars
[0], g
);
4923 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4924 XSETINT (it
->ctl_chars
[1], g
);
4926 /* Set up IT->dpvec and return first character from it. */
4927 it
->dpvec_char_len
= it
->len
;
4928 it
->dpvec
= it
->ctl_chars
;
4929 it
->dpend
= it
->dpvec
+ 2;
4930 it
->current
.dpvec_index
= 0;
4931 it
->method
= next_element_from_display_vector
;
4932 get_next_display_element (it
);
4936 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4941 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4943 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4944 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4945 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4947 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4949 if (SINGLE_BYTE_CHAR_P (it
->c
))
4950 str
[0] = it
->c
, len
= 1;
4953 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4956 /* It's an invalid character, which
4957 shouldn't happen actually, but due to
4958 bugs it may happen. Let's print the char
4959 as is, there's not much meaningful we can
4962 str
[1] = it
->c
>> 8;
4963 str
[2] = it
->c
>> 16;
4964 str
[3] = it
->c
>> 24;
4969 for (i
= 0; i
< len
; i
++)
4971 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4972 /* Insert three more glyphs into IT->ctl_chars for
4973 the octal display of the character. */
4974 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4975 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4976 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4977 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4978 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4979 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4982 /* Set up IT->dpvec and return the first character
4984 it
->dpvec_char_len
= it
->len
;
4985 it
->dpvec
= it
->ctl_chars
;
4986 it
->dpend
= it
->dpvec
+ len
* 4;
4987 it
->current
.dpvec_index
= 0;
4988 it
->method
= next_element_from_display_vector
;
4989 get_next_display_element (it
);
4994 /* Adjust face id for a multibyte character. There are no
4995 multibyte character in unibyte text. */
4998 && FRAME_WINDOW_P (it
->f
))
5000 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5001 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5005 /* Is this character the last one of a run of characters with
5006 box? If yes, set IT->end_of_box_run_p to 1. */
5013 it
->end_of_box_run_p
5014 = ((face_id
= face_after_it_pos (it
),
5015 face_id
!= it
->face_id
)
5016 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5017 face
->box
== FACE_NO_BOX
));
5020 /* Value is 0 if end of buffer or string reached. */
5025 /* Move IT to the next display element.
5027 RESEAT_P non-zero means if called on a newline in buffer text,
5028 skip to the next visible line start.
5030 Functions get_next_display_element and set_iterator_to_next are
5031 separate because I find this arrangement easier to handle than a
5032 get_next_display_element function that also increments IT's
5033 position. The way it is we can first look at an iterator's current
5034 display element, decide whether it fits on a line, and if it does,
5035 increment the iterator position. The other way around we probably
5036 would either need a flag indicating whether the iterator has to be
5037 incremented the next time, or we would have to implement a
5038 decrement position function which would not be easy to write. */
5041 set_iterator_to_next (it
, reseat_p
)
5045 /* Reset flags indicating start and end of a sequence of characters
5046 with box. Reset them at the start of this function because
5047 moving the iterator to a new position might set them. */
5048 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5050 if (it
->method
== next_element_from_buffer
)
5052 /* The current display element of IT is a character from
5053 current_buffer. Advance in the buffer, and maybe skip over
5054 invisible lines that are so because of selective display. */
5055 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5056 reseat_at_next_visible_line_start (it
, 0);
5059 xassert (it
->len
!= 0);
5060 IT_BYTEPOS (*it
) += it
->len
;
5061 IT_CHARPOS (*it
) += 1;
5062 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5065 else if (it
->method
== next_element_from_composition
)
5067 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5068 if (STRINGP (it
->string
))
5070 IT_STRING_BYTEPOS (*it
) += it
->len
;
5071 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5072 it
->method
= next_element_from_string
;
5073 goto consider_string_end
;
5077 IT_BYTEPOS (*it
) += it
->len
;
5078 IT_CHARPOS (*it
) += it
->cmp_len
;
5079 it
->method
= next_element_from_buffer
;
5082 else if (it
->method
== next_element_from_c_string
)
5084 /* Current display element of IT is from a C string. */
5085 IT_BYTEPOS (*it
) += it
->len
;
5086 IT_CHARPOS (*it
) += 1;
5088 else if (it
->method
== next_element_from_display_vector
)
5090 /* Current display element of IT is from a display table entry.
5091 Advance in the display table definition. Reset it to null if
5092 end reached, and continue with characters from buffers/
5094 ++it
->current
.dpvec_index
;
5096 /* Restore face of the iterator to what they were before the
5097 display vector entry (these entries may contain faces). */
5098 it
->face_id
= it
->saved_face_id
;
5100 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5103 it
->method
= next_element_from_c_string
;
5104 else if (STRINGP (it
->string
))
5105 it
->method
= next_element_from_string
;
5107 it
->method
= next_element_from_buffer
;
5110 it
->current
.dpvec_index
= -1;
5112 /* Skip over characters which were displayed via IT->dpvec. */
5113 if (it
->dpvec_char_len
< 0)
5114 reseat_at_next_visible_line_start (it
, 1);
5115 else if (it
->dpvec_char_len
> 0)
5117 it
->len
= it
->dpvec_char_len
;
5118 set_iterator_to_next (it
, reseat_p
);
5122 else if (it
->method
== next_element_from_string
)
5124 /* Current display element is a character from a Lisp string. */
5125 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5126 IT_STRING_BYTEPOS (*it
) += it
->len
;
5127 IT_STRING_CHARPOS (*it
) += 1;
5129 consider_string_end
:
5131 if (it
->current
.overlay_string_index
>= 0)
5133 /* IT->string is an overlay string. Advance to the
5134 next, if there is one. */
5135 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5136 next_overlay_string (it
);
5140 /* IT->string is not an overlay string. If we reached
5141 its end, and there is something on IT->stack, proceed
5142 with what is on the stack. This can be either another
5143 string, this time an overlay string, or a buffer. */
5144 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5148 if (!STRINGP (it
->string
))
5149 it
->method
= next_element_from_buffer
;
5151 goto consider_string_end
;
5155 else if (it
->method
== next_element_from_image
5156 || it
->method
== next_element_from_stretch
)
5158 /* The position etc with which we have to proceed are on
5159 the stack. The position may be at the end of a string,
5160 if the `display' property takes up the whole string. */
5163 if (STRINGP (it
->string
))
5165 it
->method
= next_element_from_string
;
5166 goto consider_string_end
;
5169 it
->method
= next_element_from_buffer
;
5172 /* There are no other methods defined, so this should be a bug. */
5175 xassert (it
->method
!= next_element_from_string
5176 || (STRINGP (it
->string
)
5177 && IT_STRING_CHARPOS (*it
) >= 0));
5181 /* Load IT's display element fields with information about the next
5182 display element which comes from a display table entry or from the
5183 result of translating a control character to one of the forms `^C'
5184 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5187 next_element_from_display_vector (it
)
5191 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5193 /* Remember the current face id in case glyphs specify faces.
5194 IT's face is restored in set_iterator_to_next. */
5195 it
->saved_face_id
= it
->face_id
;
5197 if (INTEGERP (*it
->dpvec
)
5198 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5203 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5204 it
->c
= FAST_GLYPH_CHAR (g
);
5205 it
->len
= CHAR_BYTES (it
->c
);
5207 /* The entry may contain a face id to use. Such a face id is
5208 the id of a Lisp face, not a realized face. A face id of
5209 zero means no face is specified. */
5210 lface_id
= FAST_GLYPH_FACE (g
);
5213 /* The function returns -1 if lface_id is invalid. */
5214 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5216 it
->face_id
= face_id
;
5220 /* Display table entry is invalid. Return a space. */
5221 it
->c
= ' ', it
->len
= 1;
5223 /* Don't change position and object of the iterator here. They are
5224 still the values of the character that had this display table
5225 entry or was translated, and that's what we want. */
5226 it
->what
= IT_CHARACTER
;
5231 /* Load IT with the next display element from Lisp string IT->string.
5232 IT->current.string_pos is the current position within the string.
5233 If IT->current.overlay_string_index >= 0, the Lisp string is an
5237 next_element_from_string (it
)
5240 struct text_pos position
;
5242 xassert (STRINGP (it
->string
));
5243 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5244 position
= it
->current
.string_pos
;
5246 /* Time to check for invisible text? */
5247 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5248 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5252 /* Since a handler may have changed IT->method, we must
5254 return get_next_display_element (it
);
5257 if (it
->current
.overlay_string_index
>= 0)
5259 /* Get the next character from an overlay string. In overlay
5260 strings, There is no field width or padding with spaces to
5262 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5267 else if (STRING_MULTIBYTE (it
->string
))
5269 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5270 const unsigned char *s
= (SDATA (it
->string
)
5271 + IT_STRING_BYTEPOS (*it
));
5272 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5276 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5282 /* Get the next character from a Lisp string that is not an
5283 overlay string. Such strings come from the mode line, for
5284 example. We may have to pad with spaces, or truncate the
5285 string. See also next_element_from_c_string. */
5286 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5291 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5293 /* Pad with spaces. */
5294 it
->c
= ' ', it
->len
= 1;
5295 CHARPOS (position
) = BYTEPOS (position
) = -1;
5297 else if (STRING_MULTIBYTE (it
->string
))
5299 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5300 const unsigned char *s
= (SDATA (it
->string
)
5301 + IT_STRING_BYTEPOS (*it
));
5302 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5306 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5311 /* Record what we have and where it came from. Note that we store a
5312 buffer position in IT->position although it could arguably be a
5314 it
->what
= IT_CHARACTER
;
5315 it
->object
= it
->string
;
5316 it
->position
= position
;
5321 /* Load IT with next display element from C string IT->s.
5322 IT->string_nchars is the maximum number of characters to return
5323 from the string. IT->end_charpos may be greater than
5324 IT->string_nchars when this function is called, in which case we
5325 may have to return padding spaces. Value is zero if end of string
5326 reached, including padding spaces. */
5329 next_element_from_c_string (it
)
5335 it
->what
= IT_CHARACTER
;
5336 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5339 /* IT's position can be greater IT->string_nchars in case a field
5340 width or precision has been specified when the iterator was
5342 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5344 /* End of the game. */
5348 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5350 /* Pad with spaces. */
5351 it
->c
= ' ', it
->len
= 1;
5352 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5354 else if (it
->multibyte_p
)
5356 /* Implementation note: The calls to strlen apparently aren't a
5357 performance problem because there is no noticeable performance
5358 difference between Emacs running in unibyte or multibyte mode. */
5359 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5360 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5364 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5370 /* Set up IT to return characters from an ellipsis, if appropriate.
5371 The definition of the ellipsis glyphs may come from a display table
5372 entry. This function Fills IT with the first glyph from the
5373 ellipsis if an ellipsis is to be displayed. */
5376 next_element_from_ellipsis (it
)
5379 if (it
->selective_display_ellipsis_p
)
5381 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5383 /* Use the display table definition for `...'. Invalid glyphs
5384 will be handled by the method returning elements from dpvec. */
5385 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5386 it
->dpvec_char_len
= it
->len
;
5387 it
->dpvec
= v
->contents
;
5388 it
->dpend
= v
->contents
+ v
->size
;
5389 it
->current
.dpvec_index
= 0;
5390 it
->method
= next_element_from_display_vector
;
5394 /* Use default `...' which is stored in default_invis_vector. */
5395 it
->dpvec_char_len
= it
->len
;
5396 it
->dpvec
= default_invis_vector
;
5397 it
->dpend
= default_invis_vector
+ 3;
5398 it
->current
.dpvec_index
= 0;
5399 it
->method
= next_element_from_display_vector
;
5404 /* The face at the current position may be different from the
5405 face we find after the invisible text. Remember what it
5406 was in IT->saved_face_id, and signal that it's there by
5407 setting face_before_selective_p. */
5408 it
->saved_face_id
= it
->face_id
;
5409 it
->method
= next_element_from_buffer
;
5410 reseat_at_next_visible_line_start (it
, 1);
5411 it
->face_before_selective_p
= 1;
5414 return get_next_display_element (it
);
5418 /* Deliver an image display element. The iterator IT is already
5419 filled with image information (done in handle_display_prop). Value
5424 next_element_from_image (it
)
5427 it
->what
= IT_IMAGE
;
5432 /* Fill iterator IT with next display element from a stretch glyph
5433 property. IT->object is the value of the text property. Value is
5437 next_element_from_stretch (it
)
5440 it
->what
= IT_STRETCH
;
5445 /* Load IT with the next display element from current_buffer. Value
5446 is zero if end of buffer reached. IT->stop_charpos is the next
5447 position at which to stop and check for text properties or buffer
5451 next_element_from_buffer (it
)
5456 /* Check this assumption, otherwise, we would never enter the
5457 if-statement, below. */
5458 xassert (IT_CHARPOS (*it
) >= BEGV
5459 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5461 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5463 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5465 int overlay_strings_follow_p
;
5467 /* End of the game, except when overlay strings follow that
5468 haven't been returned yet. */
5469 if (it
->overlay_strings_at_end_processed_p
)
5470 overlay_strings_follow_p
= 0;
5473 it
->overlay_strings_at_end_processed_p
= 1;
5474 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5477 if (overlay_strings_follow_p
)
5478 success_p
= get_next_display_element (it
);
5482 it
->position
= it
->current
.pos
;
5489 return get_next_display_element (it
);
5494 /* No face changes, overlays etc. in sight, so just return a
5495 character from current_buffer. */
5498 /* Maybe run the redisplay end trigger hook. Performance note:
5499 This doesn't seem to cost measurable time. */
5500 if (it
->redisplay_end_trigger_charpos
5502 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5503 run_redisplay_end_trigger_hook (it
);
5505 /* Get the next character, maybe multibyte. */
5506 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5507 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5509 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5510 - IT_BYTEPOS (*it
));
5511 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5514 it
->c
= *p
, it
->len
= 1;
5516 /* Record what we have and where it came from. */
5517 it
->what
= IT_CHARACTER
;;
5518 it
->object
= it
->w
->buffer
;
5519 it
->position
= it
->current
.pos
;
5521 /* Normally we return the character found above, except when we
5522 really want to return an ellipsis for selective display. */
5527 /* A value of selective > 0 means hide lines indented more
5528 than that number of columns. */
5529 if (it
->selective
> 0
5530 && IT_CHARPOS (*it
) + 1 < ZV
5531 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5532 IT_BYTEPOS (*it
) + 1,
5533 (double) it
->selective
)) /* iftc */
5535 success_p
= next_element_from_ellipsis (it
);
5536 it
->dpvec_char_len
= -1;
5539 else if (it
->c
== '\r' && it
->selective
== -1)
5541 /* A value of selective == -1 means that everything from the
5542 CR to the end of the line is invisible, with maybe an
5543 ellipsis displayed for it. */
5544 success_p
= next_element_from_ellipsis (it
);
5545 it
->dpvec_char_len
= -1;
5550 /* Value is zero if end of buffer reached. */
5551 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5556 /* Run the redisplay end trigger hook for IT. */
5559 run_redisplay_end_trigger_hook (it
)
5562 Lisp_Object args
[3];
5564 /* IT->glyph_row should be non-null, i.e. we should be actually
5565 displaying something, or otherwise we should not run the hook. */
5566 xassert (it
->glyph_row
);
5568 /* Set up hook arguments. */
5569 args
[0] = Qredisplay_end_trigger_functions
;
5570 args
[1] = it
->window
;
5571 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5572 it
->redisplay_end_trigger_charpos
= 0;
5574 /* Since we are *trying* to run these functions, don't try to run
5575 them again, even if they get an error. */
5576 it
->w
->redisplay_end_trigger
= Qnil
;
5577 Frun_hook_with_args (3, args
);
5579 /* Notice if it changed the face of the character we are on. */
5580 handle_face_prop (it
);
5584 /* Deliver a composition display element. The iterator IT is already
5585 filled with composition information (done in
5586 handle_composition_prop). Value is always 1. */
5589 next_element_from_composition (it
)
5592 it
->what
= IT_COMPOSITION
;
5593 it
->position
= (STRINGP (it
->string
)
5594 ? it
->current
.string_pos
5601 /***********************************************************************
5602 Moving an iterator without producing glyphs
5603 ***********************************************************************/
5605 /* Move iterator IT to a specified buffer or X position within one
5606 line on the display without producing glyphs.
5608 OP should be a bit mask including some or all of these bits:
5609 MOVE_TO_X: Stop on reaching x-position TO_X.
5610 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5611 Regardless of OP's value, stop in reaching the end of the display line.
5613 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5614 This means, in particular, that TO_X includes window's horizontal
5617 The return value has several possible values that
5618 say what condition caused the scan to stop:
5620 MOVE_POS_MATCH_OR_ZV
5621 - when TO_POS or ZV was reached.
5624 -when TO_X was reached before TO_POS or ZV were reached.
5627 - when we reached the end of the display area and the line must
5631 - when we reached the end of the display area and the line is
5635 - when we stopped at a line end, i.e. a newline or a CR and selective
5638 static enum move_it_result
5639 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5641 int to_charpos
, to_x
, op
;
5643 enum move_it_result result
= MOVE_UNDEFINED
;
5644 struct glyph_row
*saved_glyph_row
;
5646 /* Don't produce glyphs in produce_glyphs. */
5647 saved_glyph_row
= it
->glyph_row
;
5648 it
->glyph_row
= NULL
;
5650 #define BUFFER_POS_REACHED_P() \
5651 ((op & MOVE_TO_POS) != 0 \
5652 && BUFFERP (it->object) \
5653 && IT_CHARPOS (*it) >= to_charpos)
5657 int x
, i
, ascent
= 0, descent
= 0;
5659 /* Stop when ZV or TO_CHARPOS reached. */
5660 if (!get_next_display_element (it
)
5661 || BUFFER_POS_REACHED_P ())
5663 result
= MOVE_POS_MATCH_OR_ZV
;
5667 /* The call to produce_glyphs will get the metrics of the
5668 display element IT is loaded with. We record in x the
5669 x-position before this display element in case it does not
5673 /* Remember the line height so far in case the next element doesn't
5675 if (!it
->truncate_lines_p
)
5677 ascent
= it
->max_ascent
;
5678 descent
= it
->max_descent
;
5681 PRODUCE_GLYPHS (it
);
5683 if (it
->area
!= TEXT_AREA
)
5685 set_iterator_to_next (it
, 1);
5689 /* The number of glyphs we get back in IT->nglyphs will normally
5690 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5691 character on a terminal frame, or (iii) a line end. For the
5692 second case, IT->nglyphs - 1 padding glyphs will be present
5693 (on X frames, there is only one glyph produced for a
5694 composite character.
5696 The behavior implemented below means, for continuation lines,
5697 that as many spaces of a TAB as fit on the current line are
5698 displayed there. For terminal frames, as many glyphs of a
5699 multi-glyph character are displayed in the current line, too.
5700 This is what the old redisplay code did, and we keep it that
5701 way. Under X, the whole shape of a complex character must
5702 fit on the line or it will be completely displayed in the
5705 Note that both for tabs and padding glyphs, all glyphs have
5709 /* More than one glyph or glyph doesn't fit on line. All
5710 glyphs have the same width. */
5711 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5714 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5716 new_x
= x
+ single_glyph_width
;
5718 /* We want to leave anything reaching TO_X to the caller. */
5719 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5722 result
= MOVE_X_REACHED
;
5725 else if (/* Lines are continued. */
5726 !it
->truncate_lines_p
5727 && (/* And glyph doesn't fit on the line. */
5728 new_x
> it
->last_visible_x
5729 /* Or it fits exactly and we're on a window
5731 || (new_x
== it
->last_visible_x
5732 && FRAME_WINDOW_P (it
->f
))))
5734 if (/* IT->hpos == 0 means the very first glyph
5735 doesn't fit on the line, e.g. a wide image. */
5737 || (new_x
== it
->last_visible_x
5738 && FRAME_WINDOW_P (it
->f
)))
5741 it
->current_x
= new_x
;
5742 if (i
== it
->nglyphs
- 1)
5744 set_iterator_to_next (it
, 1);
5745 #ifdef HAVE_WINDOW_SYSTEM
5746 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5748 if (!get_next_display_element (it
)
5749 || BUFFER_POS_REACHED_P ())
5751 result
= MOVE_POS_MATCH_OR_ZV
;
5754 if (ITERATOR_AT_END_OF_LINE_P (it
))
5756 result
= MOVE_NEWLINE_OR_CR
;
5760 #endif /* HAVE_WINDOW_SYSTEM */
5766 it
->max_ascent
= ascent
;
5767 it
->max_descent
= descent
;
5770 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5772 result
= MOVE_LINE_CONTINUED
;
5775 else if (new_x
> it
->first_visible_x
)
5777 /* Glyph is visible. Increment number of glyphs that
5778 would be displayed. */
5783 /* Glyph is completely off the left margin of the display
5784 area. Nothing to do. */
5788 if (result
!= MOVE_UNDEFINED
)
5791 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5793 /* Stop when TO_X specified and reached. This check is
5794 necessary here because of lines consisting of a line end,
5795 only. The line end will not produce any glyphs and we
5796 would never get MOVE_X_REACHED. */
5797 xassert (it
->nglyphs
== 0);
5798 result
= MOVE_X_REACHED
;
5802 /* Is this a line end? If yes, we're done. */
5803 if (ITERATOR_AT_END_OF_LINE_P (it
))
5805 result
= MOVE_NEWLINE_OR_CR
;
5809 /* The current display element has been consumed. Advance
5811 set_iterator_to_next (it
, 1);
5813 /* Stop if lines are truncated and IT's current x-position is
5814 past the right edge of the window now. */
5815 if (it
->truncate_lines_p
5816 && it
->current_x
>= it
->last_visible_x
)
5818 #ifdef HAVE_WINDOW_SYSTEM
5819 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5821 if (!get_next_display_element (it
)
5822 || BUFFER_POS_REACHED_P ())
5824 result
= MOVE_POS_MATCH_OR_ZV
;
5827 if (ITERATOR_AT_END_OF_LINE_P (it
))
5829 result
= MOVE_NEWLINE_OR_CR
;
5833 #endif /* HAVE_WINDOW_SYSTEM */
5834 result
= MOVE_LINE_TRUNCATED
;
5839 #undef BUFFER_POS_REACHED_P
5841 /* Restore the iterator settings altered at the beginning of this
5843 it
->glyph_row
= saved_glyph_row
;
5848 /* Move IT forward until it satisfies one or more of the criteria in
5849 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5851 OP is a bit-mask that specifies where to stop, and in particular,
5852 which of those four position arguments makes a difference. See the
5853 description of enum move_operation_enum.
5855 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5856 screen line, this function will set IT to the next position >
5860 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5862 int to_charpos
, to_x
, to_y
, to_vpos
;
5865 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5871 if (op
& MOVE_TO_VPOS
)
5873 /* If no TO_CHARPOS and no TO_X specified, stop at the
5874 start of the line TO_VPOS. */
5875 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5877 if (it
->vpos
== to_vpos
)
5883 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5887 /* TO_VPOS >= 0 means stop at TO_X in the line at
5888 TO_VPOS, or at TO_POS, whichever comes first. */
5889 if (it
->vpos
== to_vpos
)
5895 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5897 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5902 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5904 /* We have reached TO_X but not in the line we want. */
5905 skip
= move_it_in_display_line_to (it
, to_charpos
,
5907 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5915 else if (op
& MOVE_TO_Y
)
5917 struct it it_backup
;
5919 /* TO_Y specified means stop at TO_X in the line containing
5920 TO_Y---or at TO_CHARPOS if this is reached first. The
5921 problem is that we can't really tell whether the line
5922 contains TO_Y before we have completely scanned it, and
5923 this may skip past TO_X. What we do is to first scan to
5926 If TO_X is not specified, use a TO_X of zero. The reason
5927 is to make the outcome of this function more predictable.
5928 If we didn't use TO_X == 0, we would stop at the end of
5929 the line which is probably not what a caller would expect
5931 skip
= move_it_in_display_line_to (it
, to_charpos
,
5935 | (op
& MOVE_TO_POS
)));
5937 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5938 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5944 /* If TO_X was reached, we would like to know whether TO_Y
5945 is in the line. This can only be said if we know the
5946 total line height which requires us to scan the rest of
5948 if (skip
== MOVE_X_REACHED
)
5951 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5952 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5954 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5957 /* Now, decide whether TO_Y is in this line. */
5958 line_height
= it
->max_ascent
+ it
->max_descent
;
5959 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5961 if (to_y
>= it
->current_y
5962 && to_y
< it
->current_y
+ line_height
)
5964 if (skip
== MOVE_X_REACHED
)
5965 /* If TO_Y is in this line and TO_X was reached above,
5966 we scanned too far. We have to restore IT's settings
5967 to the ones before skipping. */
5971 else if (skip
== MOVE_X_REACHED
)
5974 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5982 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5986 case MOVE_POS_MATCH_OR_ZV
:
5990 case MOVE_NEWLINE_OR_CR
:
5991 set_iterator_to_next (it
, 1);
5992 it
->continuation_lines_width
= 0;
5995 case MOVE_LINE_TRUNCATED
:
5996 it
->continuation_lines_width
= 0;
5997 reseat_at_next_visible_line_start (it
, 0);
5998 if ((op
& MOVE_TO_POS
) != 0
5999 && IT_CHARPOS (*it
) > to_charpos
)
6006 case MOVE_LINE_CONTINUED
:
6007 it
->continuation_lines_width
+= it
->current_x
;
6014 /* Reset/increment for the next run. */
6015 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6016 it
->current_x
= it
->hpos
= 0;
6017 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6019 last_height
= it
->max_ascent
+ it
->max_descent
;
6020 last_max_ascent
= it
->max_ascent
;
6021 it
->max_ascent
= it
->max_descent
= 0;
6026 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6030 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6032 If DY > 0, move IT backward at least that many pixels. DY = 0
6033 means move IT backward to the preceding line start or BEGV. This
6034 function may move over more than DY pixels if IT->current_y - DY
6035 ends up in the middle of a line; in this case IT->current_y will be
6036 set to the top of the line moved to. */
6039 move_it_vertically_backward (it
, dy
)
6045 int start_pos
= IT_CHARPOS (*it
);
6049 /* Estimate how many newlines we must move back. */
6050 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6052 /* Set the iterator's position that many lines back. */
6053 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6054 back_to_previous_visible_line_start (it
);
6056 /* Reseat the iterator here. When moving backward, we don't want
6057 reseat to skip forward over invisible text, set up the iterator
6058 to deliver from overlay strings at the new position etc. So,
6059 use reseat_1 here. */
6060 reseat_1 (it
, it
->current
.pos
, 1);
6062 /* We are now surely at a line start. */
6063 it
->current_x
= it
->hpos
= 0;
6064 it
->continuation_lines_width
= 0;
6066 /* Move forward and see what y-distance we moved. First move to the
6067 start of the next line so that we get its height. We need this
6068 height to be able to tell whether we reached the specified
6071 it2
.max_ascent
= it2
.max_descent
= 0;
6072 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6073 MOVE_TO_POS
| MOVE_TO_VPOS
);
6074 xassert (IT_CHARPOS (*it
) >= BEGV
);
6077 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6078 xassert (IT_CHARPOS (*it
) >= BEGV
);
6079 /* H is the actual vertical distance from the position in *IT
6080 and the starting position. */
6081 h
= it2
.current_y
- it
->current_y
;
6082 /* NLINES is the distance in number of lines. */
6083 nlines
= it2
.vpos
- it
->vpos
;
6085 /* Correct IT's y and vpos position
6086 so that they are relative to the starting point. */
6092 /* DY == 0 means move to the start of the screen line. The
6093 value of nlines is > 0 if continuation lines were involved. */
6095 move_it_by_lines (it
, nlines
, 1);
6096 xassert (IT_CHARPOS (*it
) <= start_pos
);
6100 /* The y-position we try to reach, relative to *IT.
6101 Note that H has been subtracted in front of the if-statement. */
6102 int target_y
= it
->current_y
+ h
- dy
;
6103 int y0
= it3
.current_y
;
6104 int y1
= line_bottom_y (&it3
);
6105 int line_height
= y1
- y0
;
6107 /* If we did not reach target_y, try to move further backward if
6108 we can. If we moved too far backward, try to move forward. */
6109 if (target_y
< it
->current_y
6110 /* This is heuristic. In a window that's 3 lines high, with
6111 a line height of 13 pixels each, recentering with point
6112 on the bottom line will try to move -39/2 = 19 pixels
6113 backward. Try to avoid moving into the first line. */
6114 && it
->current_y
- target_y
> line_height
/ 3 * 2
6115 && IT_CHARPOS (*it
) > BEGV
)
6117 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6118 target_y
- it
->current_y
));
6119 move_it_vertically (it
, target_y
- it
->current_y
);
6120 xassert (IT_CHARPOS (*it
) >= BEGV
);
6122 else if (target_y
>= it
->current_y
+ line_height
6123 && IT_CHARPOS (*it
) < ZV
)
6125 /* Should move forward by at least one line, maybe more.
6127 Note: Calling move_it_by_lines can be expensive on
6128 terminal frames, where compute_motion is used (via
6129 vmotion) to do the job, when there are very long lines
6130 and truncate-lines is nil. That's the reason for
6131 treating terminal frames specially here. */
6133 if (!FRAME_WINDOW_P (it
->f
))
6134 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6139 move_it_by_lines (it
, 1, 1);
6141 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6144 xassert (IT_CHARPOS (*it
) >= BEGV
);
6150 /* Move IT by a specified amount of pixel lines DY. DY negative means
6151 move backwards. DY = 0 means move to start of screen line. At the
6152 end, IT will be on the start of a screen line. */
6155 move_it_vertically (it
, dy
)
6160 move_it_vertically_backward (it
, -dy
);
6163 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6164 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6165 MOVE_TO_POS
| MOVE_TO_Y
);
6166 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6168 /* If buffer ends in ZV without a newline, move to the start of
6169 the line to satisfy the post-condition. */
6170 if (IT_CHARPOS (*it
) == ZV
6171 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6172 move_it_by_lines (it
, 0, 0);
6177 /* Move iterator IT past the end of the text line it is in. */
6180 move_it_past_eol (it
)
6183 enum move_it_result rc
;
6185 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6186 if (rc
== MOVE_NEWLINE_OR_CR
)
6187 set_iterator_to_next (it
, 0);
6191 #if 0 /* Currently not used. */
6193 /* Return non-zero if some text between buffer positions START_CHARPOS
6194 and END_CHARPOS is invisible. IT->window is the window for text
6198 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6200 int start_charpos
, end_charpos
;
6202 Lisp_Object prop
, limit
;
6203 int invisible_found_p
;
6205 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6207 /* Is text at START invisible? */
6208 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6210 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6211 invisible_found_p
= 1;
6214 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6216 make_number (end_charpos
));
6217 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6220 return invisible_found_p
;
6226 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6227 negative means move up. DVPOS == 0 means move to the start of the
6228 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6229 NEED_Y_P is zero, IT->current_y will be left unchanged.
6231 Further optimization ideas: If we would know that IT->f doesn't use
6232 a face with proportional font, we could be faster for
6233 truncate-lines nil. */
6236 move_it_by_lines (it
, dvpos
, need_y_p
)
6238 int dvpos
, need_y_p
;
6240 struct position pos
;
6242 if (!FRAME_WINDOW_P (it
->f
))
6244 struct text_pos textpos
;
6246 /* We can use vmotion on frames without proportional fonts. */
6247 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6248 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6249 reseat (it
, textpos
, 1);
6250 it
->vpos
+= pos
.vpos
;
6251 it
->current_y
+= pos
.vpos
;
6253 else if (dvpos
== 0)
6255 /* DVPOS == 0 means move to the start of the screen line. */
6256 move_it_vertically_backward (it
, 0);
6257 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6260 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6264 int start_charpos
, i
;
6266 /* Start at the beginning of the screen line containing IT's
6268 move_it_vertically_backward (it
, 0);
6270 /* Go back -DVPOS visible lines and reseat the iterator there. */
6271 start_charpos
= IT_CHARPOS (*it
);
6272 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6273 back_to_previous_visible_line_start (it
);
6274 reseat (it
, it
->current
.pos
, 1);
6275 it
->current_x
= it
->hpos
= 0;
6277 /* Above call may have moved too far if continuation lines
6278 are involved. Scan forward and see if it did. */
6280 it2
.vpos
= it2
.current_y
= 0;
6281 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6282 it
->vpos
-= it2
.vpos
;
6283 it
->current_y
-= it2
.current_y
;
6284 it
->current_x
= it
->hpos
= 0;
6286 /* If we moved too far, move IT some lines forward. */
6287 if (it2
.vpos
> -dvpos
)
6289 int delta
= it2
.vpos
+ dvpos
;
6290 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6295 /* Return 1 if IT points into the middle of a display vector. */
6298 in_display_vector_p (it
)
6301 return (it
->method
== next_element_from_display_vector
6302 && it
->current
.dpvec_index
> 0
6303 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6307 /***********************************************************************
6309 ***********************************************************************/
6312 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6316 add_to_log (format
, arg1
, arg2
)
6318 Lisp_Object arg1
, arg2
;
6320 Lisp_Object args
[3];
6321 Lisp_Object msg
, fmt
;
6324 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6326 /* Do nothing if called asynchronously. Inserting text into
6327 a buffer may call after-change-functions and alike and
6328 that would means running Lisp asynchronously. */
6329 if (handling_signal
)
6333 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6335 args
[0] = fmt
= build_string (format
);
6338 msg
= Fformat (3, args
);
6340 len
= SBYTES (msg
) + 1;
6341 buffer
= (char *) alloca (len
);
6342 bcopy (SDATA (msg
), buffer
, len
);
6344 message_dolog (buffer
, len
- 1, 1, 0);
6349 /* Output a newline in the *Messages* buffer if "needs" one. */
6352 message_log_maybe_newline ()
6354 if (message_log_need_newline
)
6355 message_dolog ("", 0, 1, 0);
6359 /* Add a string M of length NBYTES to the message log, optionally
6360 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6361 nonzero, means interpret the contents of M as multibyte. This
6362 function calls low-level routines in order to bypass text property
6363 hooks, etc. which might not be safe to run. */
6366 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6368 int nbytes
, nlflag
, multibyte
;
6370 if (!NILP (Vmemory_full
))
6373 if (!NILP (Vmessage_log_max
))
6375 struct buffer
*oldbuf
;
6376 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6377 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6378 int point_at_end
= 0;
6380 Lisp_Object old_deactivate_mark
, tem
;
6381 struct gcpro gcpro1
;
6383 old_deactivate_mark
= Vdeactivate_mark
;
6384 oldbuf
= current_buffer
;
6385 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6386 current_buffer
->undo_list
= Qt
;
6388 oldpoint
= message_dolog_marker1
;
6389 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6390 oldbegv
= message_dolog_marker2
;
6391 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6392 oldzv
= message_dolog_marker3
;
6393 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6394 GCPRO1 (old_deactivate_mark
);
6402 BEGV_BYTE
= BEG_BYTE
;
6405 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6407 /* Insert the string--maybe converting multibyte to single byte
6408 or vice versa, so that all the text fits the buffer. */
6410 && NILP (current_buffer
->enable_multibyte_characters
))
6412 int i
, c
, char_bytes
;
6413 unsigned char work
[1];
6415 /* Convert a multibyte string to single-byte
6416 for the *Message* buffer. */
6417 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6419 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6420 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6422 : multibyte_char_to_unibyte (c
, Qnil
));
6423 insert_1_both (work
, 1, 1, 1, 0, 0);
6426 else if (! multibyte
6427 && ! NILP (current_buffer
->enable_multibyte_characters
))
6429 int i
, c
, char_bytes
;
6430 unsigned char *msg
= (unsigned char *) m
;
6431 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6432 /* Convert a single-byte string to multibyte
6433 for the *Message* buffer. */
6434 for (i
= 0; i
< nbytes
; i
++)
6436 c
= unibyte_char_to_multibyte (msg
[i
]);
6437 char_bytes
= CHAR_STRING (c
, str
);
6438 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6442 insert_1 (m
, nbytes
, 1, 0, 0);
6446 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6447 insert_1 ("\n", 1, 1, 0, 0);
6449 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6451 this_bol_byte
= PT_BYTE
;
6453 /* See if this line duplicates the previous one.
6454 If so, combine duplicates. */
6457 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6459 prev_bol_byte
= PT_BYTE
;
6461 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6462 this_bol
, this_bol_byte
);
6465 del_range_both (prev_bol
, prev_bol_byte
,
6466 this_bol
, this_bol_byte
, 0);
6472 /* If you change this format, don't forget to also
6473 change message_log_check_duplicate. */
6474 sprintf (dupstr
, " [%d times]", dup
);
6475 duplen
= strlen (dupstr
);
6476 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6477 insert_1 (dupstr
, duplen
, 1, 0, 1);
6482 /* If we have more than the desired maximum number of lines
6483 in the *Messages* buffer now, delete the oldest ones.
6484 This is safe because we don't have undo in this buffer. */
6486 if (NATNUMP (Vmessage_log_max
))
6488 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6489 -XFASTINT (Vmessage_log_max
) - 1, 0);
6490 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6493 BEGV
= XMARKER (oldbegv
)->charpos
;
6494 BEGV_BYTE
= marker_byte_position (oldbegv
);
6503 ZV
= XMARKER (oldzv
)->charpos
;
6504 ZV_BYTE
= marker_byte_position (oldzv
);
6508 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6510 /* We can't do Fgoto_char (oldpoint) because it will run some
6512 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6513 XMARKER (oldpoint
)->bytepos
);
6516 unchain_marker (XMARKER (oldpoint
));
6517 unchain_marker (XMARKER (oldbegv
));
6518 unchain_marker (XMARKER (oldzv
));
6520 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6521 set_buffer_internal (oldbuf
);
6523 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6524 message_log_need_newline
= !nlflag
;
6525 Vdeactivate_mark
= old_deactivate_mark
;
6530 /* We are at the end of the buffer after just having inserted a newline.
6531 (Note: We depend on the fact we won't be crossing the gap.)
6532 Check to see if the most recent message looks a lot like the previous one.
6533 Return 0 if different, 1 if the new one should just replace it, or a
6534 value N > 1 if we should also append " [N times]". */
6537 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6538 int prev_bol
, this_bol
;
6539 int prev_bol_byte
, this_bol_byte
;
6542 int len
= Z_BYTE
- 1 - this_bol_byte
;
6544 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6545 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6547 for (i
= 0; i
< len
; i
++)
6549 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6557 if (*p1
++ == ' ' && *p1
++ == '[')
6560 while (*p1
>= '0' && *p1
<= '9')
6561 n
= n
* 10 + *p1
++ - '0';
6562 if (strncmp (p1
, " times]\n", 8) == 0)
6569 /* Display an echo area message M with a specified length of NBYTES
6570 bytes. The string may include null characters. If M is 0, clear
6571 out any existing message, and let the mini-buffer text show
6574 The buffer M must continue to exist until after the echo area gets
6575 cleared or some other message gets displayed there. This means do
6576 not pass text that is stored in a Lisp string; do not pass text in
6577 a buffer that was alloca'd. */
6580 message2 (m
, nbytes
, multibyte
)
6585 /* First flush out any partial line written with print. */
6586 message_log_maybe_newline ();
6588 message_dolog (m
, nbytes
, 1, multibyte
);
6589 message2_nolog (m
, nbytes
, multibyte
);
6593 /* The non-logging counterpart of message2. */
6596 message2_nolog (m
, nbytes
, multibyte
)
6598 int nbytes
, multibyte
;
6600 struct frame
*sf
= SELECTED_FRAME ();
6601 message_enable_multibyte
= multibyte
;
6605 if (noninteractive_need_newline
)
6606 putc ('\n', stderr
);
6607 noninteractive_need_newline
= 0;
6609 fwrite (m
, nbytes
, 1, stderr
);
6610 if (cursor_in_echo_area
== 0)
6611 fprintf (stderr
, "\n");
6614 /* A null message buffer means that the frame hasn't really been
6615 initialized yet. Error messages get reported properly by
6616 cmd_error, so this must be just an informative message; toss it. */
6617 else if (INTERACTIVE
6618 && sf
->glyphs_initialized_p
6619 && FRAME_MESSAGE_BUF (sf
))
6621 Lisp_Object mini_window
;
6624 /* Get the frame containing the mini-buffer
6625 that the selected frame is using. */
6626 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6627 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6629 FRAME_SAMPLE_VISIBILITY (f
);
6630 if (FRAME_VISIBLE_P (sf
)
6631 && ! FRAME_VISIBLE_P (f
))
6632 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6636 set_message (m
, Qnil
, nbytes
, multibyte
);
6637 if (minibuffer_auto_raise
)
6638 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6641 clear_message (1, 1);
6643 do_pending_window_change (0);
6644 echo_area_display (1);
6645 do_pending_window_change (0);
6646 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6647 (*frame_up_to_date_hook
) (f
);
6652 /* Display an echo area message M with a specified length of NBYTES
6653 bytes. The string may include null characters. If M is not a
6654 string, clear out any existing message, and let the mini-buffer
6655 text show through. */
6658 message3 (m
, nbytes
, multibyte
)
6663 struct gcpro gcpro1
;
6667 /* First flush out any partial line written with print. */
6668 message_log_maybe_newline ();
6670 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6671 message3_nolog (m
, nbytes
, multibyte
);
6677 /* The non-logging version of message3. */
6680 message3_nolog (m
, nbytes
, multibyte
)
6682 int nbytes
, multibyte
;
6684 struct frame
*sf
= SELECTED_FRAME ();
6685 message_enable_multibyte
= multibyte
;
6689 if (noninteractive_need_newline
)
6690 putc ('\n', stderr
);
6691 noninteractive_need_newline
= 0;
6693 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6694 if (cursor_in_echo_area
== 0)
6695 fprintf (stderr
, "\n");
6698 /* A null message buffer means that the frame hasn't really been
6699 initialized yet. Error messages get reported properly by
6700 cmd_error, so this must be just an informative message; toss it. */
6701 else if (INTERACTIVE
6702 && sf
->glyphs_initialized_p
6703 && FRAME_MESSAGE_BUF (sf
))
6705 Lisp_Object mini_window
;
6709 /* Get the frame containing the mini-buffer
6710 that the selected frame is using. */
6711 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6712 frame
= XWINDOW (mini_window
)->frame
;
6715 FRAME_SAMPLE_VISIBILITY (f
);
6716 if (FRAME_VISIBLE_P (sf
)
6717 && !FRAME_VISIBLE_P (f
))
6718 Fmake_frame_visible (frame
);
6720 if (STRINGP (m
) && SCHARS (m
) > 0)
6722 set_message (NULL
, m
, nbytes
, multibyte
);
6723 if (minibuffer_auto_raise
)
6724 Fraise_frame (frame
);
6727 clear_message (1, 1);
6729 do_pending_window_change (0);
6730 echo_area_display (1);
6731 do_pending_window_change (0);
6732 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6733 (*frame_up_to_date_hook
) (f
);
6738 /* Display a null-terminated echo area message M. If M is 0, clear
6739 out any existing message, and let the mini-buffer text show through.
6741 The buffer M must continue to exist until after the echo area gets
6742 cleared or some other message gets displayed there. Do not pass
6743 text that is stored in a Lisp string. Do not pass text in a buffer
6744 that was alloca'd. */
6750 message2 (m
, (m
? strlen (m
) : 0), 0);
6754 /* The non-logging counterpart of message1. */
6760 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6763 /* Display a message M which contains a single %s
6764 which gets replaced with STRING. */
6767 message_with_string (m
, string
, log
)
6772 CHECK_STRING (string
);
6778 if (noninteractive_need_newline
)
6779 putc ('\n', stderr
);
6780 noninteractive_need_newline
= 0;
6781 fprintf (stderr
, m
, SDATA (string
));
6782 if (cursor_in_echo_area
== 0)
6783 fprintf (stderr
, "\n");
6787 else if (INTERACTIVE
)
6789 /* The frame whose minibuffer we're going to display the message on.
6790 It may be larger than the selected frame, so we need
6791 to use its buffer, not the selected frame's buffer. */
6792 Lisp_Object mini_window
;
6793 struct frame
*f
, *sf
= SELECTED_FRAME ();
6795 /* Get the frame containing the minibuffer
6796 that the selected frame is using. */
6797 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6798 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6800 /* A null message buffer means that the frame hasn't really been
6801 initialized yet. Error messages get reported properly by
6802 cmd_error, so this must be just an informative message; toss it. */
6803 if (FRAME_MESSAGE_BUF (f
))
6805 Lisp_Object args
[2], message
;
6806 struct gcpro gcpro1
, gcpro2
;
6808 args
[0] = build_string (m
);
6809 args
[1] = message
= string
;
6810 GCPRO2 (args
[0], message
);
6813 message
= Fformat (2, args
);
6816 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6818 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6822 /* Print should start at the beginning of the message
6823 buffer next time. */
6824 message_buf_print
= 0;
6830 /* Dump an informative message to the minibuf. If M is 0, clear out
6831 any existing message, and let the mini-buffer text show through. */
6835 message (m
, a1
, a2
, a3
)
6837 EMACS_INT a1
, a2
, a3
;
6843 if (noninteractive_need_newline
)
6844 putc ('\n', stderr
);
6845 noninteractive_need_newline
= 0;
6846 fprintf (stderr
, m
, a1
, a2
, a3
);
6847 if (cursor_in_echo_area
== 0)
6848 fprintf (stderr
, "\n");
6852 else if (INTERACTIVE
)
6854 /* The frame whose mini-buffer we're going to display the message
6855 on. It may be larger than the selected frame, so we need to
6856 use its buffer, not the selected frame's buffer. */
6857 Lisp_Object mini_window
;
6858 struct frame
*f
, *sf
= SELECTED_FRAME ();
6860 /* Get the frame containing the mini-buffer
6861 that the selected frame is using. */
6862 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6863 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6865 /* A null message buffer means that the frame hasn't really been
6866 initialized yet. Error messages get reported properly by
6867 cmd_error, so this must be just an informative message; toss
6869 if (FRAME_MESSAGE_BUF (f
))
6880 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6881 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6883 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6884 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6886 #endif /* NO_ARG_ARRAY */
6888 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6893 /* Print should start at the beginning of the message
6894 buffer next time. */
6895 message_buf_print
= 0;
6901 /* The non-logging version of message. */
6904 message_nolog (m
, a1
, a2
, a3
)
6906 EMACS_INT a1
, a2
, a3
;
6908 Lisp_Object old_log_max
;
6909 old_log_max
= Vmessage_log_max
;
6910 Vmessage_log_max
= Qnil
;
6911 message (m
, a1
, a2
, a3
);
6912 Vmessage_log_max
= old_log_max
;
6916 /* Display the current message in the current mini-buffer. This is
6917 only called from error handlers in process.c, and is not time
6923 if (!NILP (echo_area_buffer
[0]))
6926 string
= Fcurrent_message ();
6927 message3 (string
, SBYTES (string
),
6928 !NILP (current_buffer
->enable_multibyte_characters
));
6933 /* Make sure echo area buffers in `echo_buffers' are live.
6934 If they aren't, make new ones. */
6937 ensure_echo_area_buffers ()
6941 for (i
= 0; i
< 2; ++i
)
6942 if (!BUFFERP (echo_buffer
[i
])
6943 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6946 Lisp_Object old_buffer
;
6949 old_buffer
= echo_buffer
[i
];
6950 sprintf (name
, " *Echo Area %d*", i
);
6951 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6952 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6954 for (j
= 0; j
< 2; ++j
)
6955 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6956 echo_area_buffer
[j
] = echo_buffer
[i
];
6961 /* Call FN with args A1..A4 with either the current or last displayed
6962 echo_area_buffer as current buffer.
6964 WHICH zero means use the current message buffer
6965 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6966 from echo_buffer[] and clear it.
6968 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6969 suitable buffer from echo_buffer[] and clear it.
6971 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6972 that the current message becomes the last displayed one, make
6973 choose a suitable buffer for echo_area_buffer[0], and clear it.
6975 Value is what FN returns. */
6978 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6981 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6987 int this_one
, the_other
, clear_buffer_p
, rc
;
6988 int count
= SPECPDL_INDEX ();
6990 /* If buffers aren't live, make new ones. */
6991 ensure_echo_area_buffers ();
6996 this_one
= 0, the_other
= 1;
6998 this_one
= 1, the_other
= 0;
7001 this_one
= 0, the_other
= 1;
7004 /* We need a fresh one in case the current echo buffer equals
7005 the one containing the last displayed echo area message. */
7006 if (!NILP (echo_area_buffer
[this_one
])
7007 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7008 echo_area_buffer
[this_one
] = Qnil
;
7011 /* Choose a suitable buffer from echo_buffer[] is we don't
7013 if (NILP (echo_area_buffer
[this_one
]))
7015 echo_area_buffer
[this_one
]
7016 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7017 ? echo_buffer
[the_other
]
7018 : echo_buffer
[this_one
]);
7022 buffer
= echo_area_buffer
[this_one
];
7024 /* Don't get confused by reusing the buffer used for echoing
7025 for a different purpose. */
7026 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7029 record_unwind_protect (unwind_with_echo_area_buffer
,
7030 with_echo_area_buffer_unwind_data (w
));
7032 /* Make the echo area buffer current. Note that for display
7033 purposes, it is not necessary that the displayed window's buffer
7034 == current_buffer, except for text property lookup. So, let's
7035 only set that buffer temporarily here without doing a full
7036 Fset_window_buffer. We must also change w->pointm, though,
7037 because otherwise an assertions in unshow_buffer fails, and Emacs
7039 set_buffer_internal_1 (XBUFFER (buffer
));
7043 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7046 current_buffer
->undo_list
= Qt
;
7047 current_buffer
->read_only
= Qnil
;
7048 specbind (Qinhibit_read_only
, Qt
);
7049 specbind (Qinhibit_modification_hooks
, Qt
);
7051 if (clear_buffer_p
&& Z
> BEG
)
7054 xassert (BEGV
>= BEG
);
7055 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7057 rc
= fn (a1
, a2
, a3
, a4
);
7059 xassert (BEGV
>= BEG
);
7060 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7062 unbind_to (count
, Qnil
);
7067 /* Save state that should be preserved around the call to the function
7068 FN called in with_echo_area_buffer. */
7071 with_echo_area_buffer_unwind_data (w
)
7077 /* Reduce consing by keeping one vector in
7078 Vwith_echo_area_save_vector. */
7079 vector
= Vwith_echo_area_save_vector
;
7080 Vwith_echo_area_save_vector
= Qnil
;
7083 vector
= Fmake_vector (make_number (7), Qnil
);
7085 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7086 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7087 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7091 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7092 AREF (vector
, i
) = w
->buffer
; ++i
;
7093 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7094 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7099 for (; i
< end
; ++i
)
7100 AREF (vector
, i
) = Qnil
;
7103 xassert (i
== ASIZE (vector
));
7108 /* Restore global state from VECTOR which was created by
7109 with_echo_area_buffer_unwind_data. */
7112 unwind_with_echo_area_buffer (vector
)
7115 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7116 Vdeactivate_mark
= AREF (vector
, 1);
7117 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7119 if (WINDOWP (AREF (vector
, 3)))
7122 Lisp_Object buffer
, charpos
, bytepos
;
7124 w
= XWINDOW (AREF (vector
, 3));
7125 buffer
= AREF (vector
, 4);
7126 charpos
= AREF (vector
, 5);
7127 bytepos
= AREF (vector
, 6);
7130 set_marker_both (w
->pointm
, buffer
,
7131 XFASTINT (charpos
), XFASTINT (bytepos
));
7134 Vwith_echo_area_save_vector
= vector
;
7139 /* Set up the echo area for use by print functions. MULTIBYTE_P
7140 non-zero means we will print multibyte. */
7143 setup_echo_area_for_printing (multibyte_p
)
7146 /* If we can't find an echo area any more, exit. */
7147 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7150 ensure_echo_area_buffers ();
7152 if (!message_buf_print
)
7154 /* A message has been output since the last time we printed.
7155 Choose a fresh echo area buffer. */
7156 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7157 echo_area_buffer
[0] = echo_buffer
[1];
7159 echo_area_buffer
[0] = echo_buffer
[0];
7161 /* Switch to that buffer and clear it. */
7162 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7163 current_buffer
->truncate_lines
= Qnil
;
7167 int count
= SPECPDL_INDEX ();
7168 specbind (Qinhibit_read_only
, Qt
);
7169 /* Note that undo recording is always disabled. */
7171 unbind_to (count
, Qnil
);
7173 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7175 /* Set up the buffer for the multibyteness we need. */
7177 != !NILP (current_buffer
->enable_multibyte_characters
))
7178 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7180 /* Raise the frame containing the echo area. */
7181 if (minibuffer_auto_raise
)
7183 struct frame
*sf
= SELECTED_FRAME ();
7184 Lisp_Object mini_window
;
7185 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7186 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7189 message_log_maybe_newline ();
7190 message_buf_print
= 1;
7194 if (NILP (echo_area_buffer
[0]))
7196 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7197 echo_area_buffer
[0] = echo_buffer
[1];
7199 echo_area_buffer
[0] = echo_buffer
[0];
7202 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7204 /* Someone switched buffers between print requests. */
7205 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7206 current_buffer
->truncate_lines
= Qnil
;
7212 /* Display an echo area message in window W. Value is non-zero if W's
7213 height is changed. If display_last_displayed_message_p is
7214 non-zero, display the message that was last displayed, otherwise
7215 display the current message. */
7218 display_echo_area (w
)
7221 int i
, no_message_p
, window_height_changed_p
, count
;
7223 /* Temporarily disable garbage collections while displaying the echo
7224 area. This is done because a GC can print a message itself.
7225 That message would modify the echo area buffer's contents while a
7226 redisplay of the buffer is going on, and seriously confuse
7228 count
= inhibit_garbage_collection ();
7230 /* If there is no message, we must call display_echo_area_1
7231 nevertheless because it resizes the window. But we will have to
7232 reset the echo_area_buffer in question to nil at the end because
7233 with_echo_area_buffer will sets it to an empty buffer. */
7234 i
= display_last_displayed_message_p
? 1 : 0;
7235 no_message_p
= NILP (echo_area_buffer
[i
]);
7237 window_height_changed_p
7238 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7239 display_echo_area_1
,
7240 (EMACS_INT
) w
, Qnil
, 0, 0);
7243 echo_area_buffer
[i
] = Qnil
;
7245 unbind_to (count
, Qnil
);
7246 return window_height_changed_p
;
7250 /* Helper for display_echo_area. Display the current buffer which
7251 contains the current echo area message in window W, a mini-window,
7252 a pointer to which is passed in A1. A2..A4 are currently not used.
7253 Change the height of W so that all of the message is displayed.
7254 Value is non-zero if height of W was changed. */
7257 display_echo_area_1 (a1
, a2
, a3
, a4
)
7262 struct window
*w
= (struct window
*) a1
;
7264 struct text_pos start
;
7265 int window_height_changed_p
= 0;
7267 /* Do this before displaying, so that we have a large enough glyph
7268 matrix for the display. */
7269 window_height_changed_p
= resize_mini_window (w
, 0);
7272 clear_glyph_matrix (w
->desired_matrix
);
7273 XSETWINDOW (window
, w
);
7274 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7275 try_window (window
, start
);
7277 return window_height_changed_p
;
7281 /* Resize the echo area window to exactly the size needed for the
7282 currently displayed message, if there is one. If a mini-buffer
7283 is active, don't shrink it. */
7286 resize_echo_area_exactly ()
7288 if (BUFFERP (echo_area_buffer
[0])
7289 && WINDOWP (echo_area_window
))
7291 struct window
*w
= XWINDOW (echo_area_window
);
7293 Lisp_Object resize_exactly
;
7295 if (minibuf_level
== 0)
7296 resize_exactly
= Qt
;
7298 resize_exactly
= Qnil
;
7300 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7301 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7304 ++windows_or_buffers_changed
;
7305 ++update_mode_lines
;
7306 redisplay_internal (0);
7312 /* Callback function for with_echo_area_buffer, when used from
7313 resize_echo_area_exactly. A1 contains a pointer to the window to
7314 resize, EXACTLY non-nil means resize the mini-window exactly to the
7315 size of the text displayed. A3 and A4 are not used. Value is what
7316 resize_mini_window returns. */
7319 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7321 Lisp_Object exactly
;
7324 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7328 /* Resize mini-window W to fit the size of its contents. EXACT:P
7329 means size the window exactly to the size needed. Otherwise, it's
7330 only enlarged until W's buffer is empty. Value is non-zero if
7331 the window height has been changed. */
7334 resize_mini_window (w
, exact_p
)
7338 struct frame
*f
= XFRAME (w
->frame
);
7339 int window_height_changed_p
= 0;
7341 xassert (MINI_WINDOW_P (w
));
7343 /* Don't resize windows while redisplaying a window; it would
7344 confuse redisplay functions when the size of the window they are
7345 displaying changes from under them. Such a resizing can happen,
7346 for instance, when which-func prints a long message while
7347 we are running fontification-functions. We're running these
7348 functions with safe_call which binds inhibit-redisplay to t. */
7349 if (!NILP (Vinhibit_redisplay
))
7352 /* Nil means don't try to resize. */
7353 if (NILP (Vresize_mini_windows
)
7354 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7357 if (!FRAME_MINIBUF_ONLY_P (f
))
7360 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7361 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7362 int height
, max_height
;
7363 int unit
= FRAME_LINE_HEIGHT (f
);
7364 struct text_pos start
;
7365 struct buffer
*old_current_buffer
= NULL
;
7367 if (current_buffer
!= XBUFFER (w
->buffer
))
7369 old_current_buffer
= current_buffer
;
7370 set_buffer_internal (XBUFFER (w
->buffer
));
7373 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7375 /* Compute the max. number of lines specified by the user. */
7376 if (FLOATP (Vmax_mini_window_height
))
7377 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7378 else if (INTEGERP (Vmax_mini_window_height
))
7379 max_height
= XINT (Vmax_mini_window_height
);
7381 max_height
= total_height
/ 4;
7383 /* Correct that max. height if it's bogus. */
7384 max_height
= max (1, max_height
);
7385 max_height
= min (total_height
, max_height
);
7387 /* Find out the height of the text in the window. */
7388 if (it
.truncate_lines_p
)
7393 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7394 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7395 height
= it
.current_y
+ last_height
;
7397 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7398 height
-= it
.extra_line_spacing
;
7399 height
= (height
+ unit
- 1) / unit
;
7402 /* Compute a suitable window start. */
7403 if (height
> max_height
)
7405 height
= max_height
;
7406 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7407 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7408 start
= it
.current
.pos
;
7411 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7412 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7414 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7416 /* Let it grow only, until we display an empty message, in which
7417 case the window shrinks again. */
7418 if (height
> WINDOW_TOTAL_LINES (w
))
7420 int old_height
= WINDOW_TOTAL_LINES (w
);
7421 freeze_window_starts (f
, 1);
7422 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7423 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7425 else if (height
< WINDOW_TOTAL_LINES (w
)
7426 && (exact_p
|| BEGV
== ZV
))
7428 int old_height
= WINDOW_TOTAL_LINES (w
);
7429 freeze_window_starts (f
, 0);
7430 shrink_mini_window (w
);
7431 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7436 /* Always resize to exact size needed. */
7437 if (height
> WINDOW_TOTAL_LINES (w
))
7439 int old_height
= WINDOW_TOTAL_LINES (w
);
7440 freeze_window_starts (f
, 1);
7441 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7442 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7444 else if (height
< WINDOW_TOTAL_LINES (w
))
7446 int old_height
= WINDOW_TOTAL_LINES (w
);
7447 freeze_window_starts (f
, 0);
7448 shrink_mini_window (w
);
7452 freeze_window_starts (f
, 1);
7453 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7456 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7460 if (old_current_buffer
)
7461 set_buffer_internal (old_current_buffer
);
7464 return window_height_changed_p
;
7468 /* Value is the current message, a string, or nil if there is no
7476 if (NILP (echo_area_buffer
[0]))
7480 with_echo_area_buffer (0, 0, current_message_1
,
7481 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7483 echo_area_buffer
[0] = Qnil
;
7491 current_message_1 (a1
, a2
, a3
, a4
)
7496 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7499 *msg
= make_buffer_string (BEG
, Z
, 1);
7506 /* Push the current message on Vmessage_stack for later restauration
7507 by restore_message. Value is non-zero if the current message isn't
7508 empty. This is a relatively infrequent operation, so it's not
7509 worth optimizing. */
7515 msg
= current_message ();
7516 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7517 return STRINGP (msg
);
7521 /* Restore message display from the top of Vmessage_stack. */
7528 xassert (CONSP (Vmessage_stack
));
7529 msg
= XCAR (Vmessage_stack
);
7531 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7533 message3_nolog (msg
, 0, 0);
7537 /* Handler for record_unwind_protect calling pop_message. */
7540 pop_message_unwind (dummy
)
7547 /* Pop the top-most entry off Vmessage_stack. */
7552 xassert (CONSP (Vmessage_stack
));
7553 Vmessage_stack
= XCDR (Vmessage_stack
);
7557 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7558 exits. If the stack is not empty, we have a missing pop_message
7562 check_message_stack ()
7564 if (!NILP (Vmessage_stack
))
7569 /* Truncate to NCHARS what will be displayed in the echo area the next
7570 time we display it---but don't redisplay it now. */
7573 truncate_echo_area (nchars
)
7577 echo_area_buffer
[0] = Qnil
;
7578 /* A null message buffer means that the frame hasn't really been
7579 initialized yet. Error messages get reported properly by
7580 cmd_error, so this must be just an informative message; toss it. */
7581 else if (!noninteractive
7583 && !NILP (echo_area_buffer
[0]))
7585 struct frame
*sf
= SELECTED_FRAME ();
7586 if (FRAME_MESSAGE_BUF (sf
))
7587 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7592 /* Helper function for truncate_echo_area. Truncate the current
7593 message to at most NCHARS characters. */
7596 truncate_message_1 (nchars
, a2
, a3
, a4
)
7601 if (BEG
+ nchars
< Z
)
7602 del_range (BEG
+ nchars
, Z
);
7604 echo_area_buffer
[0] = Qnil
;
7609 /* Set the current message to a substring of S or STRING.
7611 If STRING is a Lisp string, set the message to the first NBYTES
7612 bytes from STRING. NBYTES zero means use the whole string. If
7613 STRING is multibyte, the message will be displayed multibyte.
7615 If S is not null, set the message to the first LEN bytes of S. LEN
7616 zero means use the whole string. MULTIBYTE_P non-zero means S is
7617 multibyte. Display the message multibyte in that case. */
7620 set_message (s
, string
, nbytes
, multibyte_p
)
7623 int nbytes
, multibyte_p
;
7625 message_enable_multibyte
7626 = ((s
&& multibyte_p
)
7627 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7629 with_echo_area_buffer (0, -1, set_message_1
,
7630 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7631 message_buf_print
= 0;
7632 help_echo_showing_p
= 0;
7636 /* Helper function for set_message. Arguments have the same meaning
7637 as there, with A1 corresponding to S and A2 corresponding to STRING
7638 This function is called with the echo area buffer being
7642 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7645 EMACS_INT nbytes
, multibyte_p
;
7647 const char *s
= (const char *) a1
;
7648 Lisp_Object string
= a2
;
7652 /* Change multibyteness of the echo buffer appropriately. */
7653 if (message_enable_multibyte
7654 != !NILP (current_buffer
->enable_multibyte_characters
))
7655 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7657 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7659 /* Insert new message at BEG. */
7660 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7662 if (STRINGP (string
))
7667 nbytes
= SBYTES (string
);
7668 nchars
= string_byte_to_char (string
, nbytes
);
7670 /* This function takes care of single/multibyte conversion. We
7671 just have to ensure that the echo area buffer has the right
7672 setting of enable_multibyte_characters. */
7673 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7678 nbytes
= strlen (s
);
7680 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7682 /* Convert from multi-byte to single-byte. */
7684 unsigned char work
[1];
7686 /* Convert a multibyte string to single-byte. */
7687 for (i
= 0; i
< nbytes
; i
+= n
)
7689 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7690 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7692 : multibyte_char_to_unibyte (c
, Qnil
));
7693 insert_1_both (work
, 1, 1, 1, 0, 0);
7696 else if (!multibyte_p
7697 && !NILP (current_buffer
->enable_multibyte_characters
))
7699 /* Convert from single-byte to multi-byte. */
7701 const unsigned char *msg
= (const unsigned char *) s
;
7702 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7704 /* Convert a single-byte string to multibyte. */
7705 for (i
= 0; i
< nbytes
; i
++)
7707 c
= unibyte_char_to_multibyte (msg
[i
]);
7708 n
= CHAR_STRING (c
, str
);
7709 insert_1_both (str
, 1, n
, 1, 0, 0);
7713 insert_1 (s
, nbytes
, 1, 0, 0);
7720 /* Clear messages. CURRENT_P non-zero means clear the current
7721 message. LAST_DISPLAYED_P non-zero means clear the message
7725 clear_message (current_p
, last_displayed_p
)
7726 int current_p
, last_displayed_p
;
7730 echo_area_buffer
[0] = Qnil
;
7731 message_cleared_p
= 1;
7734 if (last_displayed_p
)
7735 echo_area_buffer
[1] = Qnil
;
7737 message_buf_print
= 0;
7740 /* Clear garbaged frames.
7742 This function is used where the old redisplay called
7743 redraw_garbaged_frames which in turn called redraw_frame which in
7744 turn called clear_frame. The call to clear_frame was a source of
7745 flickering. I believe a clear_frame is not necessary. It should
7746 suffice in the new redisplay to invalidate all current matrices,
7747 and ensure a complete redisplay of all windows. */
7750 clear_garbaged_frames ()
7754 Lisp_Object tail
, frame
;
7755 int changed_count
= 0;
7757 FOR_EACH_FRAME (tail
, frame
)
7759 struct frame
*f
= XFRAME (frame
);
7761 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7765 Fredraw_frame (frame
);
7766 f
->force_flush_display_p
= 1;
7768 clear_current_matrices (f
);
7777 ++windows_or_buffers_changed
;
7782 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7783 is non-zero update selected_frame. Value is non-zero if the
7784 mini-windows height has been changed. */
7787 echo_area_display (update_frame_p
)
7790 Lisp_Object mini_window
;
7793 int window_height_changed_p
= 0;
7794 struct frame
*sf
= SELECTED_FRAME ();
7796 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7797 w
= XWINDOW (mini_window
);
7798 f
= XFRAME (WINDOW_FRAME (w
));
7800 /* Don't display if frame is invisible or not yet initialized. */
7801 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7804 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7806 #ifdef HAVE_WINDOW_SYSTEM
7807 /* When Emacs starts, selected_frame may be a visible terminal
7808 frame, even if we run under a window system. If we let this
7809 through, a message would be displayed on the terminal. */
7810 if (EQ (selected_frame
, Vterminal_frame
)
7811 && !NILP (Vwindow_system
))
7813 #endif /* HAVE_WINDOW_SYSTEM */
7816 /* Redraw garbaged frames. */
7818 clear_garbaged_frames ();
7820 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7822 echo_area_window
= mini_window
;
7823 window_height_changed_p
= display_echo_area (w
);
7824 w
->must_be_updated_p
= 1;
7826 /* Update the display, unless called from redisplay_internal.
7827 Also don't update the screen during redisplay itself. The
7828 update will happen at the end of redisplay, and an update
7829 here could cause confusion. */
7830 if (update_frame_p
&& !redisplaying_p
)
7834 /* If the display update has been interrupted by pending
7835 input, update mode lines in the frame. Due to the
7836 pending input, it might have been that redisplay hasn't
7837 been called, so that mode lines above the echo area are
7838 garbaged. This looks odd, so we prevent it here. */
7839 if (!display_completed
)
7840 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7842 if (window_height_changed_p
7843 /* Don't do this if Emacs is shutting down. Redisplay
7844 needs to run hooks. */
7845 && !NILP (Vrun_hooks
))
7847 /* Must update other windows. Likewise as in other
7848 cases, don't let this update be interrupted by
7850 int count
= SPECPDL_INDEX ();
7851 specbind (Qredisplay_dont_pause
, Qt
);
7852 windows_or_buffers_changed
= 1;
7853 redisplay_internal (0);
7854 unbind_to (count
, Qnil
);
7856 else if (FRAME_WINDOW_P (f
) && n
== 0)
7858 /* Window configuration is the same as before.
7859 Can do with a display update of the echo area,
7860 unless we displayed some mode lines. */
7861 update_single_window (w
, 1);
7862 rif
->flush_display (f
);
7865 update_frame (f
, 1, 1);
7867 /* If cursor is in the echo area, make sure that the next
7868 redisplay displays the minibuffer, so that the cursor will
7869 be replaced with what the minibuffer wants. */
7870 if (cursor_in_echo_area
)
7871 ++windows_or_buffers_changed
;
7874 else if (!EQ (mini_window
, selected_window
))
7875 windows_or_buffers_changed
++;
7877 /* Last displayed message is now the current message. */
7878 echo_area_buffer
[1] = echo_area_buffer
[0];
7880 /* Prevent redisplay optimization in redisplay_internal by resetting
7881 this_line_start_pos. This is done because the mini-buffer now
7882 displays the message instead of its buffer text. */
7883 if (EQ (mini_window
, selected_window
))
7884 CHARPOS (this_line_start_pos
) = 0;
7886 return window_height_changed_p
;
7891 /***********************************************************************
7893 ***********************************************************************/
7896 /* The frame title buffering code is also used by Fformat_mode_line.
7897 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7899 /* A buffer for constructing frame titles in it; allocated from the
7900 heap in init_xdisp and resized as needed in store_frame_title_char. */
7902 static char *frame_title_buf
;
7904 /* The buffer's end, and a current output position in it. */
7906 static char *frame_title_buf_end
;
7907 static char *frame_title_ptr
;
7910 /* Store a single character C for the frame title in frame_title_buf.
7911 Re-allocate frame_title_buf if necessary. */
7915 store_frame_title_char (char c
)
7917 store_frame_title_char (c
)
7921 /* If output position has reached the end of the allocated buffer,
7922 double the buffer's size. */
7923 if (frame_title_ptr
== frame_title_buf_end
)
7925 int len
= frame_title_ptr
- frame_title_buf
;
7926 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7927 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7928 frame_title_buf_end
= frame_title_buf
+ new_size
;
7929 frame_title_ptr
= frame_title_buf
+ len
;
7932 *frame_title_ptr
++ = c
;
7936 /* Store part of a frame title in frame_title_buf, beginning at
7937 frame_title_ptr. STR is the string to store. Do not copy
7938 characters that yield more columns than PRECISION; PRECISION <= 0
7939 means copy the whole string. Pad with spaces until FIELD_WIDTH
7940 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7941 pad. Called from display_mode_element when it is used to build a
7945 store_frame_title (str
, field_width
, precision
)
7946 const unsigned char *str
;
7947 int field_width
, precision
;
7952 /* Copy at most PRECISION chars from STR. */
7953 nbytes
= strlen (str
);
7954 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7956 store_frame_title_char (*str
++);
7958 /* Fill up with spaces until FIELD_WIDTH reached. */
7959 while (field_width
> 0
7962 store_frame_title_char (' ');
7969 #ifdef HAVE_WINDOW_SYSTEM
7971 /* Set the title of FRAME, if it has changed. The title format is
7972 Vicon_title_format if FRAME is iconified, otherwise it is
7973 frame_title_format. */
7976 x_consider_frame_title (frame
)
7979 struct frame
*f
= XFRAME (frame
);
7981 if (FRAME_WINDOW_P (f
)
7982 || FRAME_MINIBUF_ONLY_P (f
)
7983 || f
->explicit_name
)
7985 /* Do we have more than one visible frame on this X display? */
7988 struct buffer
*obuf
;
7992 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7994 Lisp_Object other_frame
= XCAR (tail
);
7995 struct frame
*tf
= XFRAME (other_frame
);
7998 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7999 && !FRAME_MINIBUF_ONLY_P (tf
)
8000 && !EQ (other_frame
, tip_frame
)
8001 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8005 /* Set global variable indicating that multiple frames exist. */
8006 multiple_frames
= CONSP (tail
);
8008 /* Switch to the buffer of selected window of the frame. Set up
8009 frame_title_ptr so that display_mode_element will output into it;
8010 then display the title. */
8011 obuf
= current_buffer
;
8012 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8013 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8014 frame_title_ptr
= frame_title_buf
;
8015 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8016 NULL
, DEFAULT_FACE_ID
);
8017 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8018 len
= frame_title_ptr
- frame_title_buf
;
8019 frame_title_ptr
= NULL
;
8020 set_buffer_internal_1 (obuf
);
8022 /* Set the title only if it's changed. This avoids consing in
8023 the common case where it hasn't. (If it turns out that we've
8024 already wasted too much time by walking through the list with
8025 display_mode_element, then we might need to optimize at a
8026 higher level than this.) */
8027 if (! STRINGP (f
->name
)
8028 || SBYTES (f
->name
) != len
8029 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8030 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8034 #endif /* not HAVE_WINDOW_SYSTEM */
8039 /***********************************************************************
8041 ***********************************************************************/
8044 /* Prepare for redisplay by updating menu-bar item lists when
8045 appropriate. This can call eval. */
8048 prepare_menu_bars ()
8051 struct gcpro gcpro1
, gcpro2
;
8053 Lisp_Object tooltip_frame
;
8055 #ifdef HAVE_WINDOW_SYSTEM
8056 tooltip_frame
= tip_frame
;
8058 tooltip_frame
= Qnil
;
8061 /* Update all frame titles based on their buffer names, etc. We do
8062 this before the menu bars so that the buffer-menu will show the
8063 up-to-date frame titles. */
8064 #ifdef HAVE_WINDOW_SYSTEM
8065 if (windows_or_buffers_changed
|| update_mode_lines
)
8067 Lisp_Object tail
, frame
;
8069 FOR_EACH_FRAME (tail
, frame
)
8072 if (!EQ (frame
, tooltip_frame
)
8073 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8074 x_consider_frame_title (frame
);
8077 #endif /* HAVE_WINDOW_SYSTEM */
8079 /* Update the menu bar item lists, if appropriate. This has to be
8080 done before any actual redisplay or generation of display lines. */
8081 all_windows
= (update_mode_lines
8082 || buffer_shared
> 1
8083 || windows_or_buffers_changed
);
8086 Lisp_Object tail
, frame
;
8087 int count
= SPECPDL_INDEX ();
8089 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8091 FOR_EACH_FRAME (tail
, frame
)
8095 /* Ignore tooltip frame. */
8096 if (EQ (frame
, tooltip_frame
))
8099 /* If a window on this frame changed size, report that to
8100 the user and clear the size-change flag. */
8101 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8103 Lisp_Object functions
;
8105 /* Clear flag first in case we get an error below. */
8106 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8107 functions
= Vwindow_size_change_functions
;
8108 GCPRO2 (tail
, functions
);
8110 while (CONSP (functions
))
8112 call1 (XCAR (functions
), frame
);
8113 functions
= XCDR (functions
);
8119 update_menu_bar (f
, 0);
8120 #ifdef HAVE_WINDOW_SYSTEM
8121 update_tool_bar (f
, 0);
8126 unbind_to (count
, Qnil
);
8130 struct frame
*sf
= SELECTED_FRAME ();
8131 update_menu_bar (sf
, 1);
8132 #ifdef HAVE_WINDOW_SYSTEM
8133 update_tool_bar (sf
, 1);
8137 /* Motif needs this. See comment in xmenu.c. Turn it off when
8138 pending_menu_activation is not defined. */
8139 #ifdef USE_X_TOOLKIT
8140 pending_menu_activation
= 0;
8145 /* Update the menu bar item list for frame F. This has to be done
8146 before we start to fill in any display lines, because it can call
8149 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8152 update_menu_bar (f
, save_match_data
)
8154 int save_match_data
;
8157 register struct window
*w
;
8159 /* If called recursively during a menu update, do nothing. This can
8160 happen when, for instance, an activate-menubar-hook causes a
8162 if (inhibit_menubar_update
)
8165 window
= FRAME_SELECTED_WINDOW (f
);
8166 w
= XWINDOW (window
);
8168 #if 0 /* The if statement below this if statement used to include the
8169 condition !NILP (w->update_mode_line), rather than using
8170 update_mode_lines directly, and this if statement may have
8171 been added to make that condition work. Now the if
8172 statement below matches its comment, this isn't needed. */
8173 if (update_mode_lines
)
8174 w
->update_mode_line
= Qt
;
8177 if (FRAME_WINDOW_P (f
)
8179 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8180 || defined (USE_GTK)
8181 FRAME_EXTERNAL_MENU_BAR (f
)
8183 FRAME_MENU_BAR_LINES (f
) > 0
8185 : FRAME_MENU_BAR_LINES (f
) > 0)
8187 /* If the user has switched buffers or windows, we need to
8188 recompute to reflect the new bindings. But we'll
8189 recompute when update_mode_lines is set too; that means
8190 that people can use force-mode-line-update to request
8191 that the menu bar be recomputed. The adverse effect on
8192 the rest of the redisplay algorithm is about the same as
8193 windows_or_buffers_changed anyway. */
8194 if (windows_or_buffers_changed
8195 /* This used to test w->update_mode_line, but we believe
8196 there is no need to recompute the menu in that case. */
8197 || update_mode_lines
8198 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8199 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8200 != !NILP (w
->last_had_star
))
8201 || ((!NILP (Vtransient_mark_mode
)
8202 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8203 != !NILP (w
->region_showing
)))
8205 struct buffer
*prev
= current_buffer
;
8206 int count
= SPECPDL_INDEX ();
8208 specbind (Qinhibit_menubar_update
, Qt
);
8210 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8211 if (save_match_data
)
8212 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8213 if (NILP (Voverriding_local_map_menu_flag
))
8215 specbind (Qoverriding_terminal_local_map
, Qnil
);
8216 specbind (Qoverriding_local_map
, Qnil
);
8219 /* Run the Lucid hook. */
8220 safe_run_hooks (Qactivate_menubar_hook
);
8222 /* If it has changed current-menubar from previous value,
8223 really recompute the menu-bar from the value. */
8224 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8225 call0 (Qrecompute_lucid_menubar
);
8227 safe_run_hooks (Qmenu_bar_update_hook
);
8228 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8230 /* Redisplay the menu bar in case we changed it. */
8231 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8232 || defined (USE_GTK)
8233 if (FRAME_WINDOW_P (f
)
8234 #if defined (MAC_OS)
8235 /* All frames on Mac OS share the same menubar. So only the
8236 selected frame should be allowed to set it. */
8237 && f
== SELECTED_FRAME ()
8240 set_frame_menubar (f
, 0, 0);
8242 /* On a terminal screen, the menu bar is an ordinary screen
8243 line, and this makes it get updated. */
8244 w
->update_mode_line
= Qt
;
8245 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8246 /* In the non-toolkit version, the menu bar is an ordinary screen
8247 line, and this makes it get updated. */
8248 w
->update_mode_line
= Qt
;
8249 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8251 unbind_to (count
, Qnil
);
8252 set_buffer_internal_1 (prev
);
8259 /***********************************************************************
8261 ***********************************************************************/
8263 #ifdef HAVE_WINDOW_SYSTEM
8266 Nominal cursor position -- where to draw output.
8267 HPOS and VPOS are window relative glyph matrix coordinates.
8268 X and Y are window relative pixel coordinates. */
8270 struct cursor_pos output_cursor
;
8274 Set the global variable output_cursor to CURSOR. All cursor
8275 positions are relative to updated_window. */
8278 set_output_cursor (cursor
)
8279 struct cursor_pos
*cursor
;
8281 output_cursor
.hpos
= cursor
->hpos
;
8282 output_cursor
.vpos
= cursor
->vpos
;
8283 output_cursor
.x
= cursor
->x
;
8284 output_cursor
.y
= cursor
->y
;
8289 Set a nominal cursor position.
8291 HPOS and VPOS are column/row positions in a window glyph matrix. X
8292 and Y are window text area relative pixel positions.
8294 If this is done during an update, updated_window will contain the
8295 window that is being updated and the position is the future output
8296 cursor position for that window. If updated_window is null, use
8297 selected_window and display the cursor at the given position. */
8300 x_cursor_to (vpos
, hpos
, y
, x
)
8301 int vpos
, hpos
, y
, x
;
8305 /* If updated_window is not set, work on selected_window. */
8309 w
= XWINDOW (selected_window
);
8311 /* Set the output cursor. */
8312 output_cursor
.hpos
= hpos
;
8313 output_cursor
.vpos
= vpos
;
8314 output_cursor
.x
= x
;
8315 output_cursor
.y
= y
;
8317 /* If not called as part of an update, really display the cursor.
8318 This will also set the cursor position of W. */
8319 if (updated_window
== NULL
)
8322 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8323 if (rif
->flush_display_optional
)
8324 rif
->flush_display_optional (SELECTED_FRAME ());
8329 #endif /* HAVE_WINDOW_SYSTEM */
8332 /***********************************************************************
8334 ***********************************************************************/
8336 #ifdef HAVE_WINDOW_SYSTEM
8338 /* Where the mouse was last time we reported a mouse event. */
8340 FRAME_PTR last_mouse_frame
;
8342 /* Tool-bar item index of the item on which a mouse button was pressed
8345 int last_tool_bar_item
;
8348 /* Update the tool-bar item list for frame F. This has to be done
8349 before we start to fill in any display lines. Called from
8350 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8351 and restore it here. */
8354 update_tool_bar (f
, save_match_data
)
8356 int save_match_data
;
8359 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8361 int do_update
= WINDOWP (f
->tool_bar_window
)
8362 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8370 window
= FRAME_SELECTED_WINDOW (f
);
8371 w
= XWINDOW (window
);
8373 /* If the user has switched buffers or windows, we need to
8374 recompute to reflect the new bindings. But we'll
8375 recompute when update_mode_lines is set too; that means
8376 that people can use force-mode-line-update to request
8377 that the menu bar be recomputed. The adverse effect on
8378 the rest of the redisplay algorithm is about the same as
8379 windows_or_buffers_changed anyway. */
8380 if (windows_or_buffers_changed
8381 || !NILP (w
->update_mode_line
)
8382 || update_mode_lines
8383 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8384 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8385 != !NILP (w
->last_had_star
))
8386 || ((!NILP (Vtransient_mark_mode
)
8387 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8388 != !NILP (w
->region_showing
)))
8390 struct buffer
*prev
= current_buffer
;
8391 int count
= SPECPDL_INDEX ();
8392 Lisp_Object old_tool_bar
;
8393 struct gcpro gcpro1
;
8395 /* Set current_buffer to the buffer of the selected
8396 window of the frame, so that we get the right local
8398 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8400 /* Save match data, if we must. */
8401 if (save_match_data
)
8402 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8404 /* Make sure that we don't accidentally use bogus keymaps. */
8405 if (NILP (Voverriding_local_map_menu_flag
))
8407 specbind (Qoverriding_terminal_local_map
, Qnil
);
8408 specbind (Qoverriding_local_map
, Qnil
);
8411 old_tool_bar
= f
->tool_bar_items
;
8412 GCPRO1 (old_tool_bar
);
8414 /* Build desired tool-bar items from keymaps. */
8417 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8420 /* Redisplay the tool-bar if we changed it. */
8421 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8422 w
->update_mode_line
= Qt
;
8426 unbind_to (count
, Qnil
);
8427 set_buffer_internal_1 (prev
);
8433 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8434 F's desired tool-bar contents. F->tool_bar_items must have
8435 been set up previously by calling prepare_menu_bars. */
8438 build_desired_tool_bar_string (f
)
8441 int i
, size
, size_needed
;
8442 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8443 Lisp_Object image
, plist
, props
;
8445 image
= plist
= props
= Qnil
;
8446 GCPRO3 (image
, plist
, props
);
8448 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8449 Otherwise, make a new string. */
8451 /* The size of the string we might be able to reuse. */
8452 size
= (STRINGP (f
->desired_tool_bar_string
)
8453 ? SCHARS (f
->desired_tool_bar_string
)
8456 /* We need one space in the string for each image. */
8457 size_needed
= f
->n_tool_bar_items
;
8459 /* Reuse f->desired_tool_bar_string, if possible. */
8460 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8461 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8465 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8466 Fremove_text_properties (make_number (0), make_number (size
),
8467 props
, f
->desired_tool_bar_string
);
8470 /* Put a `display' property on the string for the images to display,
8471 put a `menu_item' property on tool-bar items with a value that
8472 is the index of the item in F's tool-bar item vector. */
8473 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8475 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8477 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8478 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8479 int hmargin
, vmargin
, relief
, idx
, end
;
8480 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8482 /* If image is a vector, choose the image according to the
8484 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8485 if (VECTORP (image
))
8489 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8490 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8493 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8494 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8496 xassert (ASIZE (image
) >= idx
);
8497 image
= AREF (image
, idx
);
8502 /* Ignore invalid image specifications. */
8503 if (!valid_image_p (image
))
8506 /* Display the tool-bar button pressed, or depressed. */
8507 plist
= Fcopy_sequence (XCDR (image
));
8509 /* Compute margin and relief to draw. */
8510 relief
= (tool_bar_button_relief
>= 0
8511 ? tool_bar_button_relief
8512 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8513 hmargin
= vmargin
= relief
;
8515 if (INTEGERP (Vtool_bar_button_margin
)
8516 && XINT (Vtool_bar_button_margin
) > 0)
8518 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8519 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8521 else if (CONSP (Vtool_bar_button_margin
))
8523 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8524 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8525 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8527 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8528 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8529 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8532 if (auto_raise_tool_bar_buttons_p
)
8534 /* Add a `:relief' property to the image spec if the item is
8538 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8545 /* If image is selected, display it pressed, i.e. with a
8546 negative relief. If it's not selected, display it with a
8548 plist
= Fplist_put (plist
, QCrelief
,
8550 ? make_number (-relief
)
8551 : make_number (relief
)));
8556 /* Put a margin around the image. */
8557 if (hmargin
|| vmargin
)
8559 if (hmargin
== vmargin
)
8560 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8562 plist
= Fplist_put (plist
, QCmargin
,
8563 Fcons (make_number (hmargin
),
8564 make_number (vmargin
)));
8567 /* If button is not enabled, and we don't have special images
8568 for the disabled state, make the image appear disabled by
8569 applying an appropriate algorithm to it. */
8570 if (!enabled_p
&& idx
< 0)
8571 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8573 /* Put a `display' text property on the string for the image to
8574 display. Put a `menu-item' property on the string that gives
8575 the start of this item's properties in the tool-bar items
8577 image
= Fcons (Qimage
, plist
);
8578 props
= list4 (Qdisplay
, image
,
8579 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8581 /* Let the last image hide all remaining spaces in the tool bar
8582 string. The string can be longer than needed when we reuse a
8584 if (i
+ 1 == f
->n_tool_bar_items
)
8585 end
= SCHARS (f
->desired_tool_bar_string
);
8588 Fadd_text_properties (make_number (i
), make_number (end
),
8589 props
, f
->desired_tool_bar_string
);
8597 /* Display one line of the tool-bar of frame IT->f. */
8600 display_tool_bar_line (it
)
8603 struct glyph_row
*row
= it
->glyph_row
;
8604 int max_x
= it
->last_visible_x
;
8607 prepare_desired_row (row
);
8608 row
->y
= it
->current_y
;
8610 /* Note that this isn't made use of if the face hasn't a box,
8611 so there's no need to check the face here. */
8612 it
->start_of_box_run_p
= 1;
8614 while (it
->current_x
< max_x
)
8616 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8618 /* Get the next display element. */
8619 if (!get_next_display_element (it
))
8622 /* Produce glyphs. */
8623 x_before
= it
->current_x
;
8624 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8625 PRODUCE_GLYPHS (it
);
8627 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8632 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8634 if (x
+ glyph
->pixel_width
> max_x
)
8636 /* Glyph doesn't fit on line. */
8637 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8643 x
+= glyph
->pixel_width
;
8647 /* Stop at line ends. */
8648 if (ITERATOR_AT_END_OF_LINE_P (it
))
8651 set_iterator_to_next (it
, 1);
8656 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8657 extend_face_to_end_of_line (it
);
8658 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8659 last
->right_box_line_p
= 1;
8660 if (last
== row
->glyphs
[TEXT_AREA
])
8661 last
->left_box_line_p
= 1;
8662 compute_line_metrics (it
);
8664 /* If line is empty, make it occupy the rest of the tool-bar. */
8665 if (!row
->displays_text_p
)
8667 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8668 row
->ascent
= row
->phys_ascent
= 0;
8671 row
->full_width_p
= 1;
8672 row
->continued_p
= 0;
8673 row
->truncated_on_left_p
= 0;
8674 row
->truncated_on_right_p
= 0;
8676 it
->current_x
= it
->hpos
= 0;
8677 it
->current_y
+= row
->height
;
8683 /* Value is the number of screen lines needed to make all tool-bar
8684 items of frame F visible. */
8687 tool_bar_lines_needed (f
)
8690 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8693 /* Initialize an iterator for iteration over
8694 F->desired_tool_bar_string in the tool-bar window of frame F. */
8695 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8696 it
.first_visible_x
= 0;
8697 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8698 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8700 while (!ITERATOR_AT_END_P (&it
))
8702 it
.glyph_row
= w
->desired_matrix
->rows
;
8703 clear_glyph_row (it
.glyph_row
);
8704 display_tool_bar_line (&it
);
8707 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8711 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8713 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8722 frame
= selected_frame
;
8724 CHECK_FRAME (frame
);
8727 if (WINDOWP (f
->tool_bar_window
)
8728 || (w
= XWINDOW (f
->tool_bar_window
),
8729 WINDOW_TOTAL_LINES (w
) > 0))
8731 update_tool_bar (f
, 1);
8732 if (f
->n_tool_bar_items
)
8734 build_desired_tool_bar_string (f
);
8735 nlines
= tool_bar_lines_needed (f
);
8739 return make_number (nlines
);
8743 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8744 height should be changed. */
8747 redisplay_tool_bar (f
)
8752 struct glyph_row
*row
;
8753 int change_height_p
= 0;
8756 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8757 update_frame_tool_bar (f
);
8761 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8762 do anything. This means you must start with tool-bar-lines
8763 non-zero to get the auto-sizing effect. Or in other words, you
8764 can turn off tool-bars by specifying tool-bar-lines zero. */
8765 if (!WINDOWP (f
->tool_bar_window
)
8766 || (w
= XWINDOW (f
->tool_bar_window
),
8767 WINDOW_TOTAL_LINES (w
) == 0))
8770 /* Set up an iterator for the tool-bar window. */
8771 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8772 it
.first_visible_x
= 0;
8773 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8776 /* Build a string that represents the contents of the tool-bar. */
8777 build_desired_tool_bar_string (f
);
8778 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8780 /* Display as many lines as needed to display all tool-bar items. */
8781 while (it
.current_y
< it
.last_visible_y
)
8782 display_tool_bar_line (&it
);
8784 /* It doesn't make much sense to try scrolling in the tool-bar
8785 window, so don't do it. */
8786 w
->desired_matrix
->no_scrolling_p
= 1;
8787 w
->must_be_updated_p
= 1;
8789 if (auto_resize_tool_bars_p
)
8793 /* If we couldn't display everything, change the tool-bar's
8795 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8796 change_height_p
= 1;
8798 /* If there are blank lines at the end, except for a partially
8799 visible blank line at the end that is smaller than
8800 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8801 row
= it
.glyph_row
- 1;
8802 if (!row
->displays_text_p
8803 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8804 change_height_p
= 1;
8806 /* If row displays tool-bar items, but is partially visible,
8807 change the tool-bar's height. */
8808 if (row
->displays_text_p
8809 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8810 change_height_p
= 1;
8812 /* Resize windows as needed by changing the `tool-bar-lines'
8815 && (nlines
= tool_bar_lines_needed (f
),
8816 nlines
!= WINDOW_TOTAL_LINES (w
)))
8818 extern Lisp_Object Qtool_bar_lines
;
8820 int old_height
= WINDOW_TOTAL_LINES (w
);
8822 XSETFRAME (frame
, f
);
8823 clear_glyph_matrix (w
->desired_matrix
);
8824 Fmodify_frame_parameters (frame
,
8825 Fcons (Fcons (Qtool_bar_lines
,
8826 make_number (nlines
)),
8828 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8829 fonts_changed_p
= 1;
8833 return change_height_p
;
8837 /* Get information about the tool-bar item which is displayed in GLYPH
8838 on frame F. Return in *PROP_IDX the index where tool-bar item
8839 properties start in F->tool_bar_items. Value is zero if
8840 GLYPH doesn't display a tool-bar item. */
8843 tool_bar_item_info (f
, glyph
, prop_idx
)
8845 struct glyph
*glyph
;
8852 /* This function can be called asynchronously, which means we must
8853 exclude any possibility that Fget_text_property signals an
8855 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8856 charpos
= max (0, charpos
);
8858 /* Get the text property `menu-item' at pos. The value of that
8859 property is the start index of this item's properties in
8860 F->tool_bar_items. */
8861 prop
= Fget_text_property (make_number (charpos
),
8862 Qmenu_item
, f
->current_tool_bar_string
);
8863 if (INTEGERP (prop
))
8865 *prop_idx
= XINT (prop
);
8875 /* Get information about the tool-bar item at position X/Y on frame F.
8876 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8877 the current matrix of the tool-bar window of F, or NULL if not
8878 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8879 item in F->tool_bar_items. Value is
8881 -1 if X/Y is not on a tool-bar item
8882 0 if X/Y is on the same item that was highlighted before.
8886 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8889 struct glyph
**glyph
;
8890 int *hpos
, *vpos
, *prop_idx
;
8892 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8893 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8896 /* Find the glyph under X/Y. */
8897 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8901 /* Get the start of this tool-bar item's properties in
8902 f->tool_bar_items. */
8903 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8906 /* Is mouse on the highlighted item? */
8907 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8908 && *vpos
>= dpyinfo
->mouse_face_beg_row
8909 && *vpos
<= dpyinfo
->mouse_face_end_row
8910 && (*vpos
> dpyinfo
->mouse_face_beg_row
8911 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8912 && (*vpos
< dpyinfo
->mouse_face_end_row
8913 || *hpos
< dpyinfo
->mouse_face_end_col
8914 || dpyinfo
->mouse_face_past_end
))
8922 Handle mouse button event on the tool-bar of frame F, at
8923 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8924 0 for button release. MODIFIERS is event modifiers for button
8928 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8931 unsigned int modifiers
;
8933 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8934 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8935 int hpos
, vpos
, prop_idx
;
8936 struct glyph
*glyph
;
8937 Lisp_Object enabled_p
;
8939 /* If not on the highlighted tool-bar item, return. */
8940 frame_to_window_pixel_xy (w
, &x
, &y
);
8941 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8944 /* If item is disabled, do nothing. */
8945 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8946 if (NILP (enabled_p
))
8951 /* Show item in pressed state. */
8952 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8953 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8954 last_tool_bar_item
= prop_idx
;
8958 Lisp_Object key
, frame
;
8959 struct input_event event
;
8962 /* Show item in released state. */
8963 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8964 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8966 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8968 XSETFRAME (frame
, f
);
8969 event
.kind
= TOOL_BAR_EVENT
;
8970 event
.frame_or_window
= frame
;
8972 kbd_buffer_store_event (&event
);
8974 event
.kind
= TOOL_BAR_EVENT
;
8975 event
.frame_or_window
= frame
;
8977 event
.modifiers
= modifiers
;
8978 kbd_buffer_store_event (&event
);
8979 last_tool_bar_item
= -1;
8984 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8985 tool-bar window-relative coordinates X/Y. Called from
8986 note_mouse_highlight. */
8989 note_tool_bar_highlight (f
, x
, y
)
8993 Lisp_Object window
= f
->tool_bar_window
;
8994 struct window
*w
= XWINDOW (window
);
8995 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8997 struct glyph
*glyph
;
8998 struct glyph_row
*row
;
9000 Lisp_Object enabled_p
;
9002 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9003 int mouse_down_p
, rc
;
9005 /* Function note_mouse_highlight is called with negative x(y
9006 values when mouse moves outside of the frame. */
9007 if (x
<= 0 || y
<= 0)
9009 clear_mouse_face (dpyinfo
);
9013 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9016 /* Not on tool-bar item. */
9017 clear_mouse_face (dpyinfo
);
9021 /* On same tool-bar item as before. */
9024 clear_mouse_face (dpyinfo
);
9026 /* Mouse is down, but on different tool-bar item? */
9027 mouse_down_p
= (dpyinfo
->grabbed
9028 && f
== last_mouse_frame
9029 && FRAME_LIVE_P (f
));
9031 && last_tool_bar_item
!= prop_idx
)
9034 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9035 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9037 /* If tool-bar item is not enabled, don't highlight it. */
9038 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9039 if (!NILP (enabled_p
))
9041 /* Compute the x-position of the glyph. In front and past the
9042 image is a space. We include this in the highlighted area. */
9043 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9044 for (i
= x
= 0; i
< hpos
; ++i
)
9045 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9047 /* Record this as the current active region. */
9048 dpyinfo
->mouse_face_beg_col
= hpos
;
9049 dpyinfo
->mouse_face_beg_row
= vpos
;
9050 dpyinfo
->mouse_face_beg_x
= x
;
9051 dpyinfo
->mouse_face_beg_y
= row
->y
;
9052 dpyinfo
->mouse_face_past_end
= 0;
9054 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9055 dpyinfo
->mouse_face_end_row
= vpos
;
9056 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9057 dpyinfo
->mouse_face_end_y
= row
->y
;
9058 dpyinfo
->mouse_face_window
= window
;
9059 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9061 /* Display it as active. */
9062 show_mouse_face (dpyinfo
, draw
);
9063 dpyinfo
->mouse_face_image_state
= draw
;
9068 /* Set help_echo_string to a help string to display for this tool-bar item.
9069 XTread_socket does the rest. */
9070 help_echo_object
= help_echo_window
= Qnil
;
9072 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9073 if (NILP (help_echo_string
))
9074 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9077 #endif /* HAVE_WINDOW_SYSTEM */
9081 /************************************************************************
9082 Horizontal scrolling
9083 ************************************************************************/
9085 static int hscroll_window_tree
P_ ((Lisp_Object
));
9086 static int hscroll_windows
P_ ((Lisp_Object
));
9088 /* For all leaf windows in the window tree rooted at WINDOW, set their
9089 hscroll value so that PT is (i) visible in the window, and (ii) so
9090 that it is not within a certain margin at the window's left and
9091 right border. Value is non-zero if any window's hscroll has been
9095 hscroll_window_tree (window
)
9098 int hscrolled_p
= 0;
9099 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9100 int hscroll_step_abs
= 0;
9101 double hscroll_step_rel
= 0;
9103 if (hscroll_relative_p
)
9105 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9106 if (hscroll_step_rel
< 0)
9108 hscroll_relative_p
= 0;
9109 hscroll_step_abs
= 0;
9112 else if (INTEGERP (Vhscroll_step
))
9114 hscroll_step_abs
= XINT (Vhscroll_step
);
9115 if (hscroll_step_abs
< 0)
9116 hscroll_step_abs
= 0;
9119 hscroll_step_abs
= 0;
9121 while (WINDOWP (window
))
9123 struct window
*w
= XWINDOW (window
);
9125 if (WINDOWP (w
->hchild
))
9126 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9127 else if (WINDOWP (w
->vchild
))
9128 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9129 else if (w
->cursor
.vpos
>= 0)
9132 int text_area_width
;
9133 struct glyph_row
*current_cursor_row
9134 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9135 struct glyph_row
*desired_cursor_row
9136 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9137 struct glyph_row
*cursor_row
9138 = (desired_cursor_row
->enabled_p
9139 ? desired_cursor_row
9140 : current_cursor_row
);
9142 text_area_width
= window_box_width (w
, TEXT_AREA
);
9144 /* Scroll when cursor is inside this scroll margin. */
9145 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9147 if ((XFASTINT (w
->hscroll
)
9148 && w
->cursor
.x
<= h_margin
)
9149 || (cursor_row
->enabled_p
9150 && cursor_row
->truncated_on_right_p
9151 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9155 struct buffer
*saved_current_buffer
;
9159 /* Find point in a display of infinite width. */
9160 saved_current_buffer
= current_buffer
;
9161 current_buffer
= XBUFFER (w
->buffer
);
9163 if (w
== XWINDOW (selected_window
))
9164 pt
= BUF_PT (current_buffer
);
9167 pt
= marker_position (w
->pointm
);
9168 pt
= max (BEGV
, pt
);
9172 /* Move iterator to pt starting at cursor_row->start in
9173 a line with infinite width. */
9174 init_to_row_start (&it
, w
, cursor_row
);
9175 it
.last_visible_x
= INFINITY
;
9176 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9177 current_buffer
= saved_current_buffer
;
9179 /* Position cursor in window. */
9180 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9181 hscroll
= max (0, (it
.current_x
9182 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9183 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9184 : (text_area_width
/ 2))))
9185 / FRAME_COLUMN_WIDTH (it
.f
);
9186 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9188 if (hscroll_relative_p
)
9189 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9192 wanted_x
= text_area_width
9193 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9196 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9200 if (hscroll_relative_p
)
9201 wanted_x
= text_area_width
* hscroll_step_rel
9204 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9207 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9209 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9211 /* Don't call Fset_window_hscroll if value hasn't
9212 changed because it will prevent redisplay
9214 if (XFASTINT (w
->hscroll
) != hscroll
)
9216 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9217 w
->hscroll
= make_number (hscroll
);
9226 /* Value is non-zero if hscroll of any leaf window has been changed. */
9231 /* Set hscroll so that cursor is visible and not inside horizontal
9232 scroll margins for all windows in the tree rooted at WINDOW. See
9233 also hscroll_window_tree above. Value is non-zero if any window's
9234 hscroll has been changed. If it has, desired matrices on the frame
9235 of WINDOW are cleared. */
9238 hscroll_windows (window
)
9243 if (automatic_hscrolling_p
)
9245 hscrolled_p
= hscroll_window_tree (window
);
9247 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9256 /************************************************************************
9258 ************************************************************************/
9260 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9261 to a non-zero value. This is sometimes handy to have in a debugger
9266 /* First and last unchanged row for try_window_id. */
9268 int debug_first_unchanged_at_end_vpos
;
9269 int debug_last_unchanged_at_beg_vpos
;
9271 /* Delta vpos and y. */
9273 int debug_dvpos
, debug_dy
;
9275 /* Delta in characters and bytes for try_window_id. */
9277 int debug_delta
, debug_delta_bytes
;
9279 /* Values of window_end_pos and window_end_vpos at the end of
9282 EMACS_INT debug_end_pos
, debug_end_vpos
;
9284 /* Append a string to W->desired_matrix->method. FMT is a printf
9285 format string. A1...A9 are a supplement for a variable-length
9286 argument list. If trace_redisplay_p is non-zero also printf the
9287 resulting string to stderr. */
9290 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9293 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9296 char *method
= w
->desired_matrix
->method
;
9297 int len
= strlen (method
);
9298 int size
= sizeof w
->desired_matrix
->method
;
9299 int remaining
= size
- len
- 1;
9301 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9302 if (len
&& remaining
)
9308 strncpy (method
+ len
, buffer
, remaining
);
9310 if (trace_redisplay_p
)
9311 fprintf (stderr
, "%p (%s): %s\n",
9313 ((BUFFERP (w
->buffer
)
9314 && STRINGP (XBUFFER (w
->buffer
)->name
))
9315 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9320 #endif /* GLYPH_DEBUG */
9323 /* Value is non-zero if all changes in window W, which displays
9324 current_buffer, are in the text between START and END. START is a
9325 buffer position, END is given as a distance from Z. Used in
9326 redisplay_internal for display optimization. */
9329 text_outside_line_unchanged_p (w
, start
, end
)
9333 int unchanged_p
= 1;
9335 /* If text or overlays have changed, see where. */
9336 if (XFASTINT (w
->last_modified
) < MODIFF
9337 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9339 /* Gap in the line? */
9340 if (GPT
< start
|| Z
- GPT
< end
)
9343 /* Changes start in front of the line, or end after it? */
9345 && (BEG_UNCHANGED
< start
- 1
9346 || END_UNCHANGED
< end
))
9349 /* If selective display, can't optimize if changes start at the
9350 beginning of the line. */
9352 && INTEGERP (current_buffer
->selective_display
)
9353 && XINT (current_buffer
->selective_display
) > 0
9354 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9357 /* If there are overlays at the start or end of the line, these
9358 may have overlay strings with newlines in them. A change at
9359 START, for instance, may actually concern the display of such
9360 overlay strings as well, and they are displayed on different
9361 lines. So, quickly rule out this case. (For the future, it
9362 might be desirable to implement something more telling than
9363 just BEG/END_UNCHANGED.) */
9366 if (BEG
+ BEG_UNCHANGED
== start
9367 && overlay_touches_p (start
))
9369 if (END_UNCHANGED
== end
9370 && overlay_touches_p (Z
- end
))
9379 /* Do a frame update, taking possible shortcuts into account. This is
9380 the main external entry point for redisplay.
9382 If the last redisplay displayed an echo area message and that message
9383 is no longer requested, we clear the echo area or bring back the
9384 mini-buffer if that is in use. */
9389 redisplay_internal (0);
9394 overlay_arrow_string_or_property (var
, pbitmap
)
9398 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9404 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9405 *pbitmap
= XINT (bitmap
);
9410 return Voverlay_arrow_string
;
9413 /* Return 1 if there are any overlay-arrows in current_buffer. */
9415 overlay_arrow_in_current_buffer_p ()
9419 for (vlist
= Voverlay_arrow_variable_list
;
9421 vlist
= XCDR (vlist
))
9423 Lisp_Object var
= XCAR (vlist
);
9428 val
= find_symbol_value (var
);
9430 && current_buffer
== XMARKER (val
)->buffer
)
9437 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9441 overlay_arrows_changed_p ()
9445 for (vlist
= Voverlay_arrow_variable_list
;
9447 vlist
= XCDR (vlist
))
9449 Lisp_Object var
= XCAR (vlist
);
9450 Lisp_Object val
, pstr
;
9454 val
= find_symbol_value (var
);
9457 if (! EQ (COERCE_MARKER (val
),
9458 Fget (var
, Qlast_arrow_position
))
9459 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9460 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9466 /* Mark overlay arrows to be updated on next redisplay. */
9469 update_overlay_arrows (up_to_date
)
9474 for (vlist
= Voverlay_arrow_variable_list
;
9476 vlist
= XCDR (vlist
))
9478 Lisp_Object var
= XCAR (vlist
);
9485 Lisp_Object val
= find_symbol_value (var
);
9486 Fput (var
, Qlast_arrow_position
,
9487 COERCE_MARKER (val
));
9488 Fput (var
, Qlast_arrow_string
,
9489 overlay_arrow_string_or_property (var
, 0));
9491 else if (up_to_date
< 0
9492 || !NILP (Fget (var
, Qlast_arrow_position
)))
9494 Fput (var
, Qlast_arrow_position
, Qt
);
9495 Fput (var
, Qlast_arrow_string
, Qt
);
9501 /* Return overlay arrow string at row, or nil. */
9504 overlay_arrow_at_row (f
, row
, pbitmap
)
9506 struct glyph_row
*row
;
9511 for (vlist
= Voverlay_arrow_variable_list
;
9513 vlist
= XCDR (vlist
))
9515 Lisp_Object var
= XCAR (vlist
);
9521 val
= find_symbol_value (var
);
9524 && current_buffer
== XMARKER (val
)->buffer
9525 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9527 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9528 if (FRAME_WINDOW_P (f
))
9530 else if (STRINGP (val
))
9540 /* Return 1 if point moved out of or into a composition. Otherwise
9541 return 0. PREV_BUF and PREV_PT are the last point buffer and
9542 position. BUF and PT are the current point buffer and position. */
9545 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9546 struct buffer
*prev_buf
, *buf
;
9553 XSETBUFFER (buffer
, buf
);
9554 /* Check a composition at the last point if point moved within the
9556 if (prev_buf
== buf
)
9559 /* Point didn't move. */
9562 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9563 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9564 && COMPOSITION_VALID_P (start
, end
, prop
)
9565 && start
< prev_pt
&& end
> prev_pt
)
9566 /* The last point was within the composition. Return 1 iff
9567 point moved out of the composition. */
9568 return (pt
<= start
|| pt
>= end
);
9571 /* Check a composition at the current point. */
9572 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9573 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9574 && COMPOSITION_VALID_P (start
, end
, prop
)
9575 && start
< pt
&& end
> pt
);
9579 /* Reconsider the setting of B->clip_changed which is displayed
9583 reconsider_clip_changes (w
, b
)
9588 && !NILP (w
->window_end_valid
)
9589 && w
->current_matrix
->buffer
== b
9590 && w
->current_matrix
->zv
== BUF_ZV (b
)
9591 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9592 b
->clip_changed
= 0;
9594 /* If display wasn't paused, and W is not a tool bar window, see if
9595 point has been moved into or out of a composition. In that case,
9596 we set b->clip_changed to 1 to force updating the screen. If
9597 b->clip_changed has already been set to 1, we can skip this
9599 if (!b
->clip_changed
9600 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9604 if (w
== XWINDOW (selected_window
))
9605 pt
= BUF_PT (current_buffer
);
9607 pt
= marker_position (w
->pointm
);
9609 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9610 || pt
!= XINT (w
->last_point
))
9611 && check_point_in_composition (w
->current_matrix
->buffer
,
9612 XINT (w
->last_point
),
9613 XBUFFER (w
->buffer
), pt
))
9614 b
->clip_changed
= 1;
9619 /* Select FRAME to forward the values of frame-local variables into C
9620 variables so that the redisplay routines can access those values
9624 select_frame_for_redisplay (frame
)
9627 Lisp_Object tail
, sym
, val
;
9628 Lisp_Object old
= selected_frame
;
9630 selected_frame
= frame
;
9632 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9633 if (CONSP (XCAR (tail
))
9634 && (sym
= XCAR (XCAR (tail
)),
9636 && (sym
= indirect_variable (sym
),
9637 val
= SYMBOL_VALUE (sym
),
9638 (BUFFER_LOCAL_VALUEP (val
)
9639 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9640 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9641 Fsymbol_value (sym
);
9643 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9644 if (CONSP (XCAR (tail
))
9645 && (sym
= XCAR (XCAR (tail
)),
9647 && (sym
= indirect_variable (sym
),
9648 val
= SYMBOL_VALUE (sym
),
9649 (BUFFER_LOCAL_VALUEP (val
)
9650 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9651 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9652 Fsymbol_value (sym
);
9656 #define STOP_POLLING \
9657 do { if (! polling_stopped_here) stop_polling (); \
9658 polling_stopped_here = 1; } while (0)
9660 #define RESUME_POLLING \
9661 do { if (polling_stopped_here) start_polling (); \
9662 polling_stopped_here = 0; } while (0)
9665 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9666 response to any user action; therefore, we should preserve the echo
9667 area. (Actually, our caller does that job.) Perhaps in the future
9668 avoid recentering windows if it is not necessary; currently that
9669 causes some problems. */
9672 redisplay_internal (preserve_echo_area
)
9673 int preserve_echo_area
;
9675 struct window
*w
= XWINDOW (selected_window
);
9676 struct frame
*f
= XFRAME (w
->frame
);
9678 int must_finish
= 0;
9679 struct text_pos tlbufpos
, tlendpos
;
9680 int number_of_visible_frames
;
9682 struct frame
*sf
= SELECTED_FRAME ();
9683 int polling_stopped_here
= 0;
9685 /* Non-zero means redisplay has to consider all windows on all
9686 frames. Zero means, only selected_window is considered. */
9687 int consider_all_windows_p
;
9689 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9691 /* No redisplay if running in batch mode or frame is not yet fully
9692 initialized, or redisplay is explicitly turned off by setting
9693 Vinhibit_redisplay. */
9695 || !NILP (Vinhibit_redisplay
)
9696 || !f
->glyphs_initialized_p
)
9699 /* The flag redisplay_performed_directly_p is set by
9700 direct_output_for_insert when it already did the whole screen
9701 update necessary. */
9702 if (redisplay_performed_directly_p
)
9704 redisplay_performed_directly_p
= 0;
9705 if (!hscroll_windows (selected_window
))
9709 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9710 if (popup_activated ())
9714 /* I don't think this happens but let's be paranoid. */
9718 /* Record a function that resets redisplaying_p to its old value
9719 when we leave this function. */
9720 count
= SPECPDL_INDEX ();
9721 record_unwind_protect (unwind_redisplay
,
9722 Fcons (make_number (redisplaying_p
), selected_frame
));
9724 specbind (Qinhibit_free_realized_faces
, Qnil
);
9728 reconsider_clip_changes (w
, current_buffer
);
9730 /* If new fonts have been loaded that make a glyph matrix adjustment
9731 necessary, do it. */
9732 if (fonts_changed_p
)
9734 adjust_glyphs (NULL
);
9735 ++windows_or_buffers_changed
;
9736 fonts_changed_p
= 0;
9739 /* If face_change_count is non-zero, init_iterator will free all
9740 realized faces, which includes the faces referenced from current
9741 matrices. So, we can't reuse current matrices in this case. */
9742 if (face_change_count
)
9743 ++windows_or_buffers_changed
;
9745 if (! FRAME_WINDOW_P (sf
)
9746 && previous_terminal_frame
!= sf
)
9748 /* Since frames on an ASCII terminal share the same display
9749 area, displaying a different frame means redisplay the whole
9751 windows_or_buffers_changed
++;
9752 SET_FRAME_GARBAGED (sf
);
9753 XSETFRAME (Vterminal_frame
, sf
);
9755 previous_terminal_frame
= sf
;
9757 /* Set the visible flags for all frames. Do this before checking
9758 for resized or garbaged frames; they want to know if their frames
9759 are visible. See the comment in frame.h for
9760 FRAME_SAMPLE_VISIBILITY. */
9762 Lisp_Object tail
, frame
;
9764 number_of_visible_frames
= 0;
9766 FOR_EACH_FRAME (tail
, frame
)
9768 struct frame
*f
= XFRAME (frame
);
9770 FRAME_SAMPLE_VISIBILITY (f
);
9771 if (FRAME_VISIBLE_P (f
))
9772 ++number_of_visible_frames
;
9773 clear_desired_matrices (f
);
9777 /* Notice any pending interrupt request to change frame size. */
9778 do_pending_window_change (1);
9780 /* Clear frames marked as garbaged. */
9782 clear_garbaged_frames ();
9784 /* Build menubar and tool-bar items. */
9785 prepare_menu_bars ();
9787 if (windows_or_buffers_changed
)
9788 update_mode_lines
++;
9790 /* Detect case that we need to write or remove a star in the mode line. */
9791 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9793 w
->update_mode_line
= Qt
;
9794 if (buffer_shared
> 1)
9795 update_mode_lines
++;
9798 /* If %c is in the mode line, update it if needed. */
9799 if (!NILP (w
->column_number_displayed
)
9800 /* This alternative quickly identifies a common case
9801 where no change is needed. */
9802 && !(PT
== XFASTINT (w
->last_point
)
9803 && XFASTINT (w
->last_modified
) >= MODIFF
9804 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9805 && (XFASTINT (w
->column_number_displayed
)
9806 != (int) current_column ())) /* iftc */
9807 w
->update_mode_line
= Qt
;
9809 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9811 /* The variable buffer_shared is set in redisplay_window and
9812 indicates that we redisplay a buffer in different windows. See
9814 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9815 || cursor_type_changed
);
9817 /* If specs for an arrow have changed, do thorough redisplay
9818 to ensure we remove any arrow that should no longer exist. */
9819 if (overlay_arrows_changed_p ())
9820 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9822 /* Normally the message* functions will have already displayed and
9823 updated the echo area, but the frame may have been trashed, or
9824 the update may have been preempted, so display the echo area
9825 again here. Checking message_cleared_p captures the case that
9826 the echo area should be cleared. */
9827 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9828 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9829 || (message_cleared_p
9830 && minibuf_level
== 0
9831 /* If the mini-window is currently selected, this means the
9832 echo-area doesn't show through. */
9833 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9835 int window_height_changed_p
= echo_area_display (0);
9838 /* If we don't display the current message, don't clear the
9839 message_cleared_p flag, because, if we did, we wouldn't clear
9840 the echo area in the next redisplay which doesn't preserve
9842 if (!display_last_displayed_message_p
)
9843 message_cleared_p
= 0;
9845 if (fonts_changed_p
)
9847 else if (window_height_changed_p
)
9849 consider_all_windows_p
= 1;
9850 ++update_mode_lines
;
9851 ++windows_or_buffers_changed
;
9853 /* If window configuration was changed, frames may have been
9854 marked garbaged. Clear them or we will experience
9855 surprises wrt scrolling. */
9857 clear_garbaged_frames ();
9860 else if (EQ (selected_window
, minibuf_window
)
9861 && (current_buffer
->clip_changed
9862 || XFASTINT (w
->last_modified
) < MODIFF
9863 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9864 && resize_mini_window (w
, 0))
9866 /* Resized active mini-window to fit the size of what it is
9867 showing if its contents might have changed. */
9869 consider_all_windows_p
= 1;
9870 ++windows_or_buffers_changed
;
9871 ++update_mode_lines
;
9873 /* If window configuration was changed, frames may have been
9874 marked garbaged. Clear them or we will experience
9875 surprises wrt scrolling. */
9877 clear_garbaged_frames ();
9881 /* If showing the region, and mark has changed, we must redisplay
9882 the whole window. The assignment to this_line_start_pos prevents
9883 the optimization directly below this if-statement. */
9884 if (((!NILP (Vtransient_mark_mode
)
9885 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9886 != !NILP (w
->region_showing
))
9887 || (!NILP (w
->region_showing
)
9888 && !EQ (w
->region_showing
,
9889 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9890 CHARPOS (this_line_start_pos
) = 0;
9892 /* Optimize the case that only the line containing the cursor in the
9893 selected window has changed. Variables starting with this_ are
9894 set in display_line and record information about the line
9895 containing the cursor. */
9896 tlbufpos
= this_line_start_pos
;
9897 tlendpos
= this_line_end_pos
;
9898 if (!consider_all_windows_p
9899 && CHARPOS (tlbufpos
) > 0
9900 && NILP (w
->update_mode_line
)
9901 && !current_buffer
->clip_changed
9902 && !current_buffer
->prevent_redisplay_optimizations_p
9903 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9904 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9905 /* Make sure recorded data applies to current buffer, etc. */
9906 && this_line_buffer
== current_buffer
9907 && current_buffer
== XBUFFER (w
->buffer
)
9908 && NILP (w
->force_start
)
9909 && NILP (w
->optional_new_start
)
9910 /* Point must be on the line that we have info recorded about. */
9911 && PT
>= CHARPOS (tlbufpos
)
9912 && PT
<= Z
- CHARPOS (tlendpos
)
9913 /* All text outside that line, including its final newline,
9914 must be unchanged */
9915 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9916 CHARPOS (tlendpos
)))
9918 if (CHARPOS (tlbufpos
) > BEGV
9919 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9920 && (CHARPOS (tlbufpos
) == ZV
9921 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9922 /* Former continuation line has disappeared by becoming empty */
9924 else if (XFASTINT (w
->last_modified
) < MODIFF
9925 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9926 || MINI_WINDOW_P (w
))
9928 /* We have to handle the case of continuation around a
9929 wide-column character (See the comment in indent.c around
9932 For instance, in the following case:
9934 -------- Insert --------
9935 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9936 J_I_ ==> J_I_ `^^' are cursors.
9940 As we have to redraw the line above, we should goto cancel. */
9943 int line_height_before
= this_line_pixel_height
;
9945 /* Note that start_display will handle the case that the
9946 line starting at tlbufpos is a continuation lines. */
9947 start_display (&it
, w
, tlbufpos
);
9949 /* Implementation note: It this still necessary? */
9950 if (it
.current_x
!= this_line_start_x
)
9953 TRACE ((stderr
, "trying display optimization 1\n"));
9954 w
->cursor
.vpos
= -1;
9955 overlay_arrow_seen
= 0;
9956 it
.vpos
= this_line_vpos
;
9957 it
.current_y
= this_line_y
;
9958 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9961 /* If line contains point, is not continued,
9962 and ends at same distance from eob as before, we win */
9963 if (w
->cursor
.vpos
>= 0
9964 /* Line is not continued, otherwise this_line_start_pos
9965 would have been set to 0 in display_line. */
9966 && CHARPOS (this_line_start_pos
)
9967 /* Line ends as before. */
9968 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9969 /* Line has same height as before. Otherwise other lines
9970 would have to be shifted up or down. */
9971 && this_line_pixel_height
== line_height_before
)
9973 /* If this is not the window's last line, we must adjust
9974 the charstarts of the lines below. */
9975 if (it
.current_y
< it
.last_visible_y
)
9977 struct glyph_row
*row
9978 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9979 int delta
, delta_bytes
;
9981 if (Z
- CHARPOS (tlendpos
) == ZV
)
9983 /* This line ends at end of (accessible part of)
9984 buffer. There is no newline to count. */
9986 - CHARPOS (tlendpos
)
9987 - MATRIX_ROW_START_CHARPOS (row
));
9988 delta_bytes
= (Z_BYTE
9989 - BYTEPOS (tlendpos
)
9990 - MATRIX_ROW_START_BYTEPOS (row
));
9994 /* This line ends in a newline. Must take
9995 account of the newline and the rest of the
9996 text that follows. */
9998 - CHARPOS (tlendpos
)
9999 - MATRIX_ROW_START_CHARPOS (row
));
10000 delta_bytes
= (Z_BYTE
10001 - BYTEPOS (tlendpos
)
10002 - MATRIX_ROW_START_BYTEPOS (row
));
10005 increment_matrix_positions (w
->current_matrix
,
10006 this_line_vpos
+ 1,
10007 w
->current_matrix
->nrows
,
10008 delta
, delta_bytes
);
10011 /* If this row displays text now but previously didn't,
10012 or vice versa, w->window_end_vpos may have to be
10014 if ((it
.glyph_row
- 1)->displays_text_p
)
10016 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10017 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10019 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10020 && this_line_vpos
> 0)
10021 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10022 w
->window_end_valid
= Qnil
;
10024 /* Update hint: No need to try to scroll in update_window. */
10025 w
->desired_matrix
->no_scrolling_p
= 1;
10028 *w
->desired_matrix
->method
= 0;
10029 debug_method_add (w
, "optimization 1");
10031 #ifdef HAVE_WINDOW_SYSTEM
10032 update_window_fringes (w
, 0);
10039 else if (/* Cursor position hasn't changed. */
10040 PT
== XFASTINT (w
->last_point
)
10041 /* Make sure the cursor was last displayed
10042 in this window. Otherwise we have to reposition it. */
10043 && 0 <= w
->cursor
.vpos
10044 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10048 do_pending_window_change (1);
10050 /* We used to always goto end_of_redisplay here, but this
10051 isn't enough if we have a blinking cursor. */
10052 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10053 goto end_of_redisplay
;
10057 /* If highlighting the region, or if the cursor is in the echo area,
10058 then we can't just move the cursor. */
10059 else if (! (!NILP (Vtransient_mark_mode
)
10060 && !NILP (current_buffer
->mark_active
))
10061 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10062 || highlight_nonselected_windows
)
10063 && NILP (w
->region_showing
)
10064 && NILP (Vshow_trailing_whitespace
)
10065 && !cursor_in_echo_area
)
10068 struct glyph_row
*row
;
10070 /* Skip from tlbufpos to PT and see where it is. Note that
10071 PT may be in invisible text. If so, we will end at the
10072 next visible position. */
10073 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10074 NULL
, DEFAULT_FACE_ID
);
10075 it
.current_x
= this_line_start_x
;
10076 it
.current_y
= this_line_y
;
10077 it
.vpos
= this_line_vpos
;
10079 /* The call to move_it_to stops in front of PT, but
10080 moves over before-strings. */
10081 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10083 if (it
.vpos
== this_line_vpos
10084 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10087 xassert (this_line_vpos
== it
.vpos
);
10088 xassert (this_line_y
== it
.current_y
);
10089 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10091 *w
->desired_matrix
->method
= 0;
10092 debug_method_add (w
, "optimization 3");
10101 /* Text changed drastically or point moved off of line. */
10102 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10105 CHARPOS (this_line_start_pos
) = 0;
10106 consider_all_windows_p
|= buffer_shared
> 1;
10107 ++clear_face_cache_count
;
10110 /* Build desired matrices, and update the display. If
10111 consider_all_windows_p is non-zero, do it for all windows on all
10112 frames. Otherwise do it for selected_window, only. */
10114 if (consider_all_windows_p
)
10116 Lisp_Object tail
, frame
;
10117 int i
, n
= 0, size
= 50;
10118 struct frame
**updated
10119 = (struct frame
**) alloca (size
* sizeof *updated
);
10121 /* Clear the face cache eventually. */
10122 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10124 clear_face_cache (0);
10125 clear_face_cache_count
= 0;
10128 /* Recompute # windows showing selected buffer. This will be
10129 incremented each time such a window is displayed. */
10132 FOR_EACH_FRAME (tail
, frame
)
10134 struct frame
*f
= XFRAME (frame
);
10136 if (FRAME_WINDOW_P (f
) || f
== sf
)
10138 if (! EQ (frame
, selected_frame
))
10139 /* Select the frame, for the sake of frame-local
10141 select_frame_for_redisplay (frame
);
10143 #ifdef HAVE_WINDOW_SYSTEM
10144 if (clear_face_cache_count
% 50 == 0
10145 && FRAME_WINDOW_P (f
))
10146 clear_image_cache (f
, 0);
10147 #endif /* HAVE_WINDOW_SYSTEM */
10149 /* Mark all the scroll bars to be removed; we'll redeem
10150 the ones we want when we redisplay their windows. */
10151 if (condemn_scroll_bars_hook
)
10152 condemn_scroll_bars_hook (f
);
10154 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10155 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10157 /* Any scroll bars which redisplay_windows should have
10158 nuked should now go away. */
10159 if (judge_scroll_bars_hook
)
10160 judge_scroll_bars_hook (f
);
10162 /* If fonts changed, display again. */
10163 /* ??? rms: I suspect it is a mistake to jump all the way
10164 back to retry here. It should just retry this frame. */
10165 if (fonts_changed_p
)
10168 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10170 /* See if we have to hscroll. */
10171 if (hscroll_windows (f
->root_window
))
10174 /* Prevent various kinds of signals during display
10175 update. stdio is not robust about handling
10176 signals, which can cause an apparent I/O
10178 if (interrupt_input
)
10179 unrequest_sigio ();
10182 /* Update the display. */
10183 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10184 pause
|= update_frame (f
, 0, 0);
10185 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10192 int nbytes
= size
* sizeof *updated
;
10193 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10194 bcopy (updated
, p
, nbytes
);
10205 /* Do the mark_window_display_accurate after all windows have
10206 been redisplayed because this call resets flags in buffers
10207 which are needed for proper redisplay. */
10208 for (i
= 0; i
< n
; ++i
)
10210 struct frame
*f
= updated
[i
];
10211 mark_window_display_accurate (f
->root_window
, 1);
10212 if (frame_up_to_date_hook
)
10213 frame_up_to_date_hook (f
);
10217 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10219 Lisp_Object mini_window
;
10220 struct frame
*mini_frame
;
10222 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10223 /* Use list_of_error, not Qerror, so that
10224 we catch only errors and don't run the debugger. */
10225 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10227 redisplay_window_error
);
10229 /* Compare desired and current matrices, perform output. */
10232 /* If fonts changed, display again. */
10233 if (fonts_changed_p
)
10236 /* Prevent various kinds of signals during display update.
10237 stdio is not robust about handling signals,
10238 which can cause an apparent I/O error. */
10239 if (interrupt_input
)
10240 unrequest_sigio ();
10243 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10245 if (hscroll_windows (selected_window
))
10248 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10249 pause
= update_frame (sf
, 0, 0);
10252 /* We may have called echo_area_display at the top of this
10253 function. If the echo area is on another frame, that may
10254 have put text on a frame other than the selected one, so the
10255 above call to update_frame would not have caught it. Catch
10257 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10258 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10260 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10262 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10263 pause
|= update_frame (mini_frame
, 0, 0);
10264 if (!pause
&& hscroll_windows (mini_window
))
10269 /* If display was paused because of pending input, make sure we do a
10270 thorough update the next time. */
10273 /* Prevent the optimization at the beginning of
10274 redisplay_internal that tries a single-line update of the
10275 line containing the cursor in the selected window. */
10276 CHARPOS (this_line_start_pos
) = 0;
10278 /* Let the overlay arrow be updated the next time. */
10279 update_overlay_arrows (0);
10281 /* If we pause after scrolling, some rows in the current
10282 matrices of some windows are not valid. */
10283 if (!WINDOW_FULL_WIDTH_P (w
)
10284 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10285 update_mode_lines
= 1;
10289 if (!consider_all_windows_p
)
10291 /* This has already been done above if
10292 consider_all_windows_p is set. */
10293 mark_window_display_accurate_1 (w
, 1);
10295 /* Say overlay arrows are up to date. */
10296 update_overlay_arrows (1);
10298 if (frame_up_to_date_hook
!= 0)
10299 frame_up_to_date_hook (sf
);
10302 update_mode_lines
= 0;
10303 windows_or_buffers_changed
= 0;
10304 cursor_type_changed
= 0;
10307 /* Start SIGIO interrupts coming again. Having them off during the
10308 code above makes it less likely one will discard output, but not
10309 impossible, since there might be stuff in the system buffer here.
10310 But it is much hairier to try to do anything about that. */
10311 if (interrupt_input
)
10315 /* If a frame has become visible which was not before, redisplay
10316 again, so that we display it. Expose events for such a frame
10317 (which it gets when becoming visible) don't call the parts of
10318 redisplay constructing glyphs, so simply exposing a frame won't
10319 display anything in this case. So, we have to display these
10320 frames here explicitly. */
10323 Lisp_Object tail
, frame
;
10326 FOR_EACH_FRAME (tail
, frame
)
10328 int this_is_visible
= 0;
10330 if (XFRAME (frame
)->visible
)
10331 this_is_visible
= 1;
10332 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10333 if (XFRAME (frame
)->visible
)
10334 this_is_visible
= 1;
10336 if (this_is_visible
)
10340 if (new_count
!= number_of_visible_frames
)
10341 windows_or_buffers_changed
++;
10344 /* Change frame size now if a change is pending. */
10345 do_pending_window_change (1);
10347 /* If we just did a pending size change, or have additional
10348 visible frames, redisplay again. */
10349 if (windows_or_buffers_changed
&& !pause
)
10353 unbind_to (count
, Qnil
);
10358 /* Redisplay, but leave alone any recent echo area message unless
10359 another message has been requested in its place.
10361 This is useful in situations where you need to redisplay but no
10362 user action has occurred, making it inappropriate for the message
10363 area to be cleared. See tracking_off and
10364 wait_reading_process_input for examples of these situations.
10366 FROM_WHERE is an integer saying from where this function was
10367 called. This is useful for debugging. */
10370 redisplay_preserve_echo_area (from_where
)
10373 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10375 if (!NILP (echo_area_buffer
[1]))
10377 /* We have a previously displayed message, but no current
10378 message. Redisplay the previous message. */
10379 display_last_displayed_message_p
= 1;
10380 redisplay_internal (1);
10381 display_last_displayed_message_p
= 0;
10384 redisplay_internal (1);
10388 /* Function registered with record_unwind_protect in
10389 redisplay_internal. Reset redisplaying_p to the value it had
10390 before redisplay_internal was called, and clear
10391 prevent_freeing_realized_faces_p. It also selects the previously
10395 unwind_redisplay (val
)
10398 Lisp_Object old_redisplaying_p
, old_frame
;
10400 old_redisplaying_p
= XCAR (val
);
10401 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10402 old_frame
= XCDR (val
);
10403 if (! EQ (old_frame
, selected_frame
))
10404 select_frame_for_redisplay (old_frame
);
10409 /* Mark the display of window W as accurate or inaccurate. If
10410 ACCURATE_P is non-zero mark display of W as accurate. If
10411 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10412 redisplay_internal is called. */
10415 mark_window_display_accurate_1 (w
, accurate_p
)
10419 if (BUFFERP (w
->buffer
))
10421 struct buffer
*b
= XBUFFER (w
->buffer
);
10424 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10425 w
->last_overlay_modified
10426 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10428 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10432 b
->clip_changed
= 0;
10433 b
->prevent_redisplay_optimizations_p
= 0;
10435 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10436 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10437 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10438 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10440 w
->current_matrix
->buffer
= b
;
10441 w
->current_matrix
->begv
= BUF_BEGV (b
);
10442 w
->current_matrix
->zv
= BUF_ZV (b
);
10444 w
->last_cursor
= w
->cursor
;
10445 w
->last_cursor_off_p
= w
->cursor_off_p
;
10447 if (w
== XWINDOW (selected_window
))
10448 w
->last_point
= make_number (BUF_PT (b
));
10450 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10456 w
->window_end_valid
= w
->buffer
;
10457 #if 0 /* This is incorrect with variable-height lines. */
10458 xassert (XINT (w
->window_end_vpos
)
10459 < (WINDOW_TOTAL_LINES (w
)
10460 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10462 w
->update_mode_line
= Qnil
;
10467 /* Mark the display of windows in the window tree rooted at WINDOW as
10468 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10469 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10470 be redisplayed the next time redisplay_internal is called. */
10473 mark_window_display_accurate (window
, accurate_p
)
10474 Lisp_Object window
;
10479 for (; !NILP (window
); window
= w
->next
)
10481 w
= XWINDOW (window
);
10482 mark_window_display_accurate_1 (w
, accurate_p
);
10484 if (!NILP (w
->vchild
))
10485 mark_window_display_accurate (w
->vchild
, accurate_p
);
10486 if (!NILP (w
->hchild
))
10487 mark_window_display_accurate (w
->hchild
, accurate_p
);
10492 update_overlay_arrows (1);
10496 /* Force a thorough redisplay the next time by setting
10497 last_arrow_position and last_arrow_string to t, which is
10498 unequal to any useful value of Voverlay_arrow_... */
10499 update_overlay_arrows (-1);
10504 /* Return value in display table DP (Lisp_Char_Table *) for character
10505 C. Since a display table doesn't have any parent, we don't have to
10506 follow parent. Do not call this function directly but use the
10507 macro DISP_CHAR_VECTOR. */
10510 disp_char_vector (dp
, c
)
10511 struct Lisp_Char_Table
*dp
;
10517 if (SINGLE_BYTE_CHAR_P (c
))
10518 return (dp
->contents
[c
]);
10520 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10523 else if (code
[2] < 32)
10526 /* Here, the possible range of code[0] (== charset ID) is
10527 128..max_charset. Since the top level char table contains data
10528 for multibyte characters after 256th element, we must increment
10529 code[0] by 128 to get a correct index. */
10531 code
[3] = -1; /* anchor */
10533 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10535 val
= dp
->contents
[code
[i
]];
10536 if (!SUB_CHAR_TABLE_P (val
))
10537 return (NILP (val
) ? dp
->defalt
: val
);
10540 /* Here, val is a sub char table. We return the default value of
10542 return (dp
->defalt
);
10547 /***********************************************************************
10549 ***********************************************************************/
10551 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10554 redisplay_windows (window
)
10555 Lisp_Object window
;
10557 while (!NILP (window
))
10559 struct window
*w
= XWINDOW (window
);
10561 if (!NILP (w
->hchild
))
10562 redisplay_windows (w
->hchild
);
10563 else if (!NILP (w
->vchild
))
10564 redisplay_windows (w
->vchild
);
10567 displayed_buffer
= XBUFFER (w
->buffer
);
10568 /* Use list_of_error, not Qerror, so that
10569 we catch only errors and don't run the debugger. */
10570 internal_condition_case_1 (redisplay_window_0
, window
,
10572 redisplay_window_error
);
10580 redisplay_window_error ()
10582 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10587 redisplay_window_0 (window
)
10588 Lisp_Object window
;
10590 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10591 redisplay_window (window
, 0);
10596 redisplay_window_1 (window
)
10597 Lisp_Object window
;
10599 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10600 redisplay_window (window
, 1);
10605 /* Increment GLYPH until it reaches END or CONDITION fails while
10606 adding (GLYPH)->pixel_width to X. */
10608 #define SKIP_GLYPHS(glyph, end, x, condition) \
10611 (x) += (glyph)->pixel_width; \
10614 while ((glyph) < (end) && (condition))
10617 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10618 DELTA is the number of bytes by which positions recorded in ROW
10619 differ from current buffer positions. */
10622 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10624 struct glyph_row
*row
;
10625 struct glyph_matrix
*matrix
;
10626 int delta
, delta_bytes
, dy
, dvpos
;
10628 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10629 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10630 /* The first glyph that starts a sequence of glyphs from string. */
10631 struct glyph
*string_start
;
10632 /* The X coordinate of string_start. */
10633 int string_start_x
;
10634 /* The last known character position. */
10635 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10636 /* The last known character position before string_start. */
10637 int string_before_pos
;
10639 int pt_old
= PT
- delta
;
10641 /* Skip over glyphs not having an object at the start of the row.
10642 These are special glyphs like truncation marks on terminal
10644 if (row
->displays_text_p
)
10646 && INTEGERP (glyph
->object
)
10647 && glyph
->charpos
< 0)
10649 x
+= glyph
->pixel_width
;
10653 string_start
= NULL
;
10655 && !INTEGERP (glyph
->object
)
10656 && (!BUFFERP (glyph
->object
)
10657 || (last_pos
= glyph
->charpos
) < pt_old
))
10659 if (! STRINGP (glyph
->object
))
10661 string_start
= NULL
;
10662 x
+= glyph
->pixel_width
;
10667 string_before_pos
= last_pos
;
10668 string_start
= glyph
;
10669 string_start_x
= x
;
10670 /* Skip all glyphs from string. */
10671 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10676 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10678 /* We may have skipped over point because the previous glyphs
10679 are from string. As there's no easy way to know the
10680 character position of the current glyph, find the correct
10681 glyph on point by scanning from string_start again. */
10683 Lisp_Object string
;
10686 limit
= make_number (pt_old
+ 1);
10688 glyph
= string_start
;
10689 x
= string_start_x
;
10690 string
= glyph
->object
;
10691 pos
= string_buffer_position (w
, string
, string_before_pos
);
10692 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10693 because we always put cursor after overlay strings. */
10694 while (pos
== 0 && glyph
< end
)
10696 string
= glyph
->object
;
10697 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10699 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10702 while (glyph
< end
)
10704 pos
= XINT (Fnext_single_char_property_change
10705 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10708 /* Skip glyphs from the same string. */
10709 string
= glyph
->object
;
10710 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10711 /* Skip glyphs from an overlay. */
10713 && ! string_buffer_position (w
, glyph
->object
, pos
))
10715 string
= glyph
->object
;
10716 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10721 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10723 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10724 w
->cursor
.y
= row
->y
+ dy
;
10726 if (w
== XWINDOW (selected_window
))
10728 if (!row
->continued_p
10729 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10732 this_line_buffer
= XBUFFER (w
->buffer
);
10734 CHARPOS (this_line_start_pos
)
10735 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10736 BYTEPOS (this_line_start_pos
)
10737 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10739 CHARPOS (this_line_end_pos
)
10740 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10741 BYTEPOS (this_line_end_pos
)
10742 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10744 this_line_y
= w
->cursor
.y
;
10745 this_line_pixel_height
= row
->height
;
10746 this_line_vpos
= w
->cursor
.vpos
;
10747 this_line_start_x
= row
->x
;
10750 CHARPOS (this_line_start_pos
) = 0;
10755 /* Run window scroll functions, if any, for WINDOW with new window
10756 start STARTP. Sets the window start of WINDOW to that position.
10758 We assume that the window's buffer is really current. */
10760 static INLINE
struct text_pos
10761 run_window_scroll_functions (window
, startp
)
10762 Lisp_Object window
;
10763 struct text_pos startp
;
10765 struct window
*w
= XWINDOW (window
);
10766 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10768 if (current_buffer
!= XBUFFER (w
->buffer
))
10771 if (!NILP (Vwindow_scroll_functions
))
10773 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10774 make_number (CHARPOS (startp
)));
10775 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10776 /* In case the hook functions switch buffers. */
10777 if (current_buffer
!= XBUFFER (w
->buffer
))
10778 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10785 /* Make sure the line containing the cursor is fully visible.
10786 A value of 1 means there is nothing to be done.
10787 (Either the line is fully visible, or it cannot be made so,
10788 or we cannot tell.)
10790 If FORCE_P is non-zero, return 0 even if partial visible cursor row
10791 is higher than window.
10793 A value of 0 means the caller should do scrolling
10794 as if point had gone off the screen. */
10797 make_cursor_line_fully_visible (w
, force_p
)
10801 struct glyph_matrix
*matrix
;
10802 struct glyph_row
*row
;
10805 /* It's not always possible to find the cursor, e.g, when a window
10806 is full of overlay strings. Don't do anything in that case. */
10807 if (w
->cursor
.vpos
< 0)
10810 matrix
= w
->desired_matrix
;
10811 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10813 /* If the cursor row is not partially visible, there's nothing to do. */
10814 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10817 /* If the row the cursor is in is taller than the window's height,
10818 it's not clear what to do, so do nothing. */
10819 window_height
= window_box_height (w
);
10820 if (row
->height
>= window_height
)
10822 if (!force_p
|| w
->vscroll
)
10828 /* This code used to try to scroll the window just enough to make
10829 the line visible. It returned 0 to say that the caller should
10830 allocate larger glyph matrices. */
10832 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10834 int dy
= row
->height
- row
->visible_height
;
10837 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10839 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10841 int dy
= - (row
->height
- row
->visible_height
);
10844 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10847 /* When we change the cursor y-position of the selected window,
10848 change this_line_y as well so that the display optimization for
10849 the cursor line of the selected window in redisplay_internal uses
10850 the correct y-position. */
10851 if (w
== XWINDOW (selected_window
))
10852 this_line_y
= w
->cursor
.y
;
10854 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10855 redisplay with larger matrices. */
10856 if (matrix
->nrows
< required_matrix_height (w
))
10858 fonts_changed_p
= 1;
10867 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10868 non-zero means only WINDOW is redisplayed in redisplay_internal.
10869 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10870 in redisplay_window to bring a partially visible line into view in
10871 the case that only the cursor has moved.
10873 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10874 last screen line's vertical height extends past the end of the screen.
10878 1 if scrolling succeeded
10880 0 if scrolling didn't find point.
10882 -1 if new fonts have been loaded so that we must interrupt
10883 redisplay, adjust glyph matrices, and try again. */
10889 SCROLLING_NEED_LARGER_MATRICES
10893 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10894 scroll_step
, temp_scroll_step
, last_line_misfit
)
10895 Lisp_Object window
;
10896 int just_this_one_p
;
10897 EMACS_INT scroll_conservatively
, scroll_step
;
10898 int temp_scroll_step
;
10899 int last_line_misfit
;
10901 struct window
*w
= XWINDOW (window
);
10902 struct frame
*f
= XFRAME (w
->frame
);
10903 struct text_pos scroll_margin_pos
;
10904 struct text_pos pos
;
10905 struct text_pos startp
;
10907 Lisp_Object window_end
;
10908 int this_scroll_margin
;
10912 int amount_to_scroll
= 0;
10913 Lisp_Object aggressive
;
10915 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
10918 debug_method_add (w
, "try_scrolling");
10921 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10923 /* Compute scroll margin height in pixels. We scroll when point is
10924 within this distance from the top or bottom of the window. */
10925 if (scroll_margin
> 0)
10927 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
10928 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
10931 this_scroll_margin
= 0;
10933 /* Force scroll_conservatively to have a reasonable value so it doesn't
10934 cause an overflow while computing how much to scroll. */
10935 if (scroll_conservatively
)
10936 scroll_conservatively
= min (scroll_conservatively
,
10937 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
10939 /* Compute how much we should try to scroll maximally to bring point
10941 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10942 scroll_max
= max (scroll_step
,
10943 max (scroll_conservatively
, temp_scroll_step
));
10944 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10945 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10946 /* We're trying to scroll because of aggressive scrolling
10947 but no scroll_step is set. Choose an arbitrary one. Maybe
10948 there should be a variable for this. */
10952 scroll_max
*= FRAME_LINE_HEIGHT (f
);
10954 /* Decide whether we have to scroll down. Start at the window end
10955 and move this_scroll_margin up to find the position of the scroll
10957 window_end
= Fwindow_end (window
, Qt
);
10961 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10962 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10964 if (this_scroll_margin
|| extra_scroll_margin_lines
)
10966 start_display (&it
, w
, scroll_margin_pos
);
10967 if (this_scroll_margin
)
10968 move_it_vertically (&it
, - this_scroll_margin
);
10969 if (extra_scroll_margin_lines
)
10970 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
10971 scroll_margin_pos
= it
.current
.pos
;
10974 if (PT
>= CHARPOS (scroll_margin_pos
))
10978 /* Point is in the scroll margin at the bottom of the window, or
10979 below. Compute a new window start that makes point visible. */
10981 /* Compute the distance from the scroll margin to PT.
10982 Give up if the distance is greater than scroll_max. */
10983 start_display (&it
, w
, scroll_margin_pos
);
10985 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10986 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10988 /* To make point visible, we have to move the window start
10989 down so that the line the cursor is in is visible, which
10990 means we have to add in the height of the cursor line. */
10991 dy
= line_bottom_y (&it
) - y0
;
10993 if (dy
> scroll_max
)
10994 return SCROLLING_FAILED
;
10996 /* Move the window start down. If scrolling conservatively,
10997 move it just enough down to make point visible. If
10998 scroll_step is set, move it down by scroll_step. */
10999 start_display (&it
, w
, startp
);
11001 if (scroll_conservatively
)
11002 /* Set AMOUNT_TO_SCROLL to at least one line,
11003 and at most scroll_conservatively lines. */
11005 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11006 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11007 else if (scroll_step
|| temp_scroll_step
)
11008 amount_to_scroll
= scroll_max
;
11011 aggressive
= current_buffer
->scroll_up_aggressively
;
11012 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11013 if (NUMBERP (aggressive
))
11014 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11017 if (amount_to_scroll
<= 0)
11018 return SCROLLING_FAILED
;
11020 /* If moving by amount_to_scroll leaves STARTP unchanged,
11021 move it down one screen line. */
11023 move_it_vertically (&it
, amount_to_scroll
);
11024 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11025 move_it_by_lines (&it
, 1, 1);
11026 startp
= it
.current
.pos
;
11030 /* See if point is inside the scroll margin at the top of the
11032 scroll_margin_pos
= startp
;
11033 if (this_scroll_margin
)
11035 start_display (&it
, w
, startp
);
11036 move_it_vertically (&it
, this_scroll_margin
);
11037 scroll_margin_pos
= it
.current
.pos
;
11040 if (PT
< CHARPOS (scroll_margin_pos
))
11042 /* Point is in the scroll margin at the top of the window or
11043 above what is displayed in the window. */
11046 /* Compute the vertical distance from PT to the scroll
11047 margin position. Give up if distance is greater than
11049 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11050 start_display (&it
, w
, pos
);
11052 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11053 it
.last_visible_y
, -1,
11054 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11055 dy
= it
.current_y
- y0
;
11056 if (dy
> scroll_max
)
11057 return SCROLLING_FAILED
;
11059 /* Compute new window start. */
11060 start_display (&it
, w
, startp
);
11062 if (scroll_conservatively
)
11064 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11065 else if (scroll_step
|| temp_scroll_step
)
11066 amount_to_scroll
= scroll_max
;
11069 aggressive
= current_buffer
->scroll_down_aggressively
;
11070 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11071 if (NUMBERP (aggressive
))
11072 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
11075 if (amount_to_scroll
<= 0)
11076 return SCROLLING_FAILED
;
11078 move_it_vertically (&it
, - amount_to_scroll
);
11079 startp
= it
.current
.pos
;
11083 /* Run window scroll functions. */
11084 startp
= run_window_scroll_functions (window
, startp
);
11086 /* Display the window. Give up if new fonts are loaded, or if point
11088 if (!try_window (window
, startp
))
11089 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11090 else if (w
->cursor
.vpos
< 0)
11092 clear_glyph_matrix (w
->desired_matrix
);
11093 rc
= SCROLLING_FAILED
;
11097 /* Maybe forget recorded base line for line number display. */
11098 if (!just_this_one_p
11099 || current_buffer
->clip_changed
11100 || BEG_UNCHANGED
< CHARPOS (startp
))
11101 w
->base_line_number
= Qnil
;
11103 /* If cursor ends up on a partially visible line,
11104 treat that as being off the bottom of the screen. */
11105 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11107 clear_glyph_matrix (w
->desired_matrix
);
11108 ++extra_scroll_margin_lines
;
11111 rc
= SCROLLING_SUCCESS
;
11118 /* Compute a suitable window start for window W if display of W starts
11119 on a continuation line. Value is non-zero if a new window start
11122 The new window start will be computed, based on W's width, starting
11123 from the start of the continued line. It is the start of the
11124 screen line with the minimum distance from the old start W->start. */
11127 compute_window_start_on_continuation_line (w
)
11130 struct text_pos pos
, start_pos
;
11131 int window_start_changed_p
= 0;
11133 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11135 /* If window start is on a continuation line... Window start may be
11136 < BEGV in case there's invisible text at the start of the
11137 buffer (M-x rmail, for example). */
11138 if (CHARPOS (start_pos
) > BEGV
11139 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11142 struct glyph_row
*row
;
11144 /* Handle the case that the window start is out of range. */
11145 if (CHARPOS (start_pos
) < BEGV
)
11146 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11147 else if (CHARPOS (start_pos
) > ZV
)
11148 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11150 /* Find the start of the continued line. This should be fast
11151 because scan_buffer is fast (newline cache). */
11152 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11153 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11154 row
, DEFAULT_FACE_ID
);
11155 reseat_at_previous_visible_line_start (&it
);
11157 /* If the line start is "too far" away from the window start,
11158 say it takes too much time to compute a new window start. */
11159 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11160 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11162 int min_distance
, distance
;
11164 /* Move forward by display lines to find the new window
11165 start. If window width was enlarged, the new start can
11166 be expected to be > the old start. If window width was
11167 decreased, the new window start will be < the old start.
11168 So, we're looking for the display line start with the
11169 minimum distance from the old window start. */
11170 pos
= it
.current
.pos
;
11171 min_distance
= INFINITY
;
11172 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11173 distance
< min_distance
)
11175 min_distance
= distance
;
11176 pos
= it
.current
.pos
;
11177 move_it_by_lines (&it
, 1, 0);
11180 /* Set the window start there. */
11181 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11182 window_start_changed_p
= 1;
11186 return window_start_changed_p
;
11190 /* Try cursor movement in case text has not changed in window WINDOW,
11191 with window start STARTP. Value is
11193 CURSOR_MOVEMENT_SUCCESS if successful
11195 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11197 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11198 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11199 we want to scroll as if scroll-step were set to 1. See the code.
11201 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11202 which case we have to abort this redisplay, and adjust matrices
11207 CURSOR_MOVEMENT_SUCCESS
,
11208 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11209 CURSOR_MOVEMENT_MUST_SCROLL
,
11210 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11214 try_cursor_movement (window
, startp
, scroll_step
)
11215 Lisp_Object window
;
11216 struct text_pos startp
;
11219 struct window
*w
= XWINDOW (window
);
11220 struct frame
*f
= XFRAME (w
->frame
);
11221 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11224 if (inhibit_try_cursor_movement
)
11228 /* Handle case where text has not changed, only point, and it has
11229 not moved off the frame. */
11230 if (/* Point may be in this window. */
11231 PT
>= CHARPOS (startp
)
11232 /* Selective display hasn't changed. */
11233 && !current_buffer
->clip_changed
11234 /* Function force-mode-line-update is used to force a thorough
11235 redisplay. It sets either windows_or_buffers_changed or
11236 update_mode_lines. So don't take a shortcut here for these
11238 && !update_mode_lines
11239 && !windows_or_buffers_changed
11240 && !cursor_type_changed
11241 /* Can't use this case if highlighting a region. When a
11242 region exists, cursor movement has to do more than just
11244 && !(!NILP (Vtransient_mark_mode
)
11245 && !NILP (current_buffer
->mark_active
))
11246 && NILP (w
->region_showing
)
11247 && NILP (Vshow_trailing_whitespace
)
11248 /* Right after splitting windows, last_point may be nil. */
11249 && INTEGERP (w
->last_point
)
11250 /* This code is not used for mini-buffer for the sake of the case
11251 of redisplaying to replace an echo area message; since in
11252 that case the mini-buffer contents per se are usually
11253 unchanged. This code is of no real use in the mini-buffer
11254 since the handling of this_line_start_pos, etc., in redisplay
11255 handles the same cases. */
11256 && !EQ (window
, minibuf_window
)
11257 /* When splitting windows or for new windows, it happens that
11258 redisplay is called with a nil window_end_vpos or one being
11259 larger than the window. This should really be fixed in
11260 window.c. I don't have this on my list, now, so we do
11261 approximately the same as the old redisplay code. --gerd. */
11262 && INTEGERP (w
->window_end_vpos
)
11263 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11264 && (FRAME_WINDOW_P (f
)
11265 || !overlay_arrow_in_current_buffer_p ()))
11267 int this_scroll_margin
;
11268 struct glyph_row
*row
= NULL
;
11271 debug_method_add (w
, "cursor movement");
11274 /* Scroll if point within this distance from the top or bottom
11275 of the window. This is a pixel value. */
11276 this_scroll_margin
= max (0, scroll_margin
);
11277 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11278 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11280 /* Start with the row the cursor was displayed during the last
11281 not paused redisplay. Give up if that row is not valid. */
11282 if (w
->last_cursor
.vpos
< 0
11283 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11284 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11287 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11288 if (row
->mode_line_p
)
11290 if (!row
->enabled_p
)
11291 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11294 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11297 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11299 if (PT
> XFASTINT (w
->last_point
))
11301 /* Point has moved forward. */
11302 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11303 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11305 xassert (row
->enabled_p
);
11309 /* The end position of a row equals the start position
11310 of the next row. If PT is there, we would rather
11311 display it in the next line. */
11312 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11313 && MATRIX_ROW_END_CHARPOS (row
) == PT
11314 && !cursor_row_p (w
, row
))
11317 /* If within the scroll margin, scroll. Note that
11318 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11319 the next line would be drawn, and that
11320 this_scroll_margin can be zero. */
11321 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11322 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11323 /* Line is completely visible last line in window
11324 and PT is to be set in the next line. */
11325 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11326 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11327 && !row
->ends_at_zv_p
11328 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11331 else if (PT
< XFASTINT (w
->last_point
))
11333 /* Cursor has to be moved backward. Note that PT >=
11334 CHARPOS (startp) because of the outer
11336 while (!row
->mode_line_p
11337 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11338 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11339 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11340 && (row
->y
> this_scroll_margin
11341 || CHARPOS (startp
) == BEGV
))
11343 xassert (row
->enabled_p
);
11347 /* Consider the following case: Window starts at BEGV,
11348 there is invisible, intangible text at BEGV, so that
11349 display starts at some point START > BEGV. It can
11350 happen that we are called with PT somewhere between
11351 BEGV and START. Try to handle that case. */
11352 if (row
< w
->current_matrix
->rows
11353 || row
->mode_line_p
)
11355 row
= w
->current_matrix
->rows
;
11356 if (row
->mode_line_p
)
11360 /* Due to newlines in overlay strings, we may have to
11361 skip forward over overlay strings. */
11362 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11363 && MATRIX_ROW_END_CHARPOS (row
) == PT
11364 && !cursor_row_p (w
, row
))
11367 /* If within the scroll margin, scroll. */
11368 if (row
->y
< this_scroll_margin
11369 && CHARPOS (startp
) != BEGV
)
11373 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11374 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11376 /* if PT is not in the glyph row, give up. */
11377 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11379 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11381 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11382 && !row
->ends_at_zv_p
11383 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11384 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11385 else if (row
->height
> window_box_height (w
))
11387 /* If we end up in a partially visible line, let's
11388 make it fully visible, except when it's taller
11389 than the window, in which case we can't do much
11392 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11396 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11397 if (!make_cursor_line_fully_visible (w
, 0))
11398 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11400 rc
= CURSOR_MOVEMENT_SUCCESS
;
11404 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11407 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11408 rc
= CURSOR_MOVEMENT_SUCCESS
;
11417 set_vertical_scroll_bar (w
)
11420 int start
, end
, whole
;
11422 /* Calculate the start and end positions for the current window.
11423 At some point, it would be nice to choose between scrollbars
11424 which reflect the whole buffer size, with special markers
11425 indicating narrowing, and scrollbars which reflect only the
11428 Note that mini-buffers sometimes aren't displaying any text. */
11429 if (!MINI_WINDOW_P (w
)
11430 || (w
== XWINDOW (minibuf_window
)
11431 && NILP (echo_area_buffer
[0])))
11433 struct buffer
*buf
= XBUFFER (w
->buffer
);
11434 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11435 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11436 /* I don't think this is guaranteed to be right. For the
11437 moment, we'll pretend it is. */
11438 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11442 if (whole
< (end
- start
))
11443 whole
= end
- start
;
11446 start
= end
= whole
= 0;
11448 /* Indicate what this scroll bar ought to be displaying now. */
11449 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11453 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11454 selected_window is redisplayed.
11456 We can return without actually redisplaying the window if
11457 fonts_changed_p is nonzero. In that case, redisplay_internal will
11461 redisplay_window (window
, just_this_one_p
)
11462 Lisp_Object window
;
11463 int just_this_one_p
;
11465 struct window
*w
= XWINDOW (window
);
11466 struct frame
*f
= XFRAME (w
->frame
);
11467 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11468 struct buffer
*old
= current_buffer
;
11469 struct text_pos lpoint
, opoint
, startp
;
11470 int update_mode_line
;
11473 /* Record it now because it's overwritten. */
11474 int current_matrix_up_to_date_p
= 0;
11475 int used_current_matrix_p
= 0;
11476 /* This is less strict than current_matrix_up_to_date_p.
11477 It indictes that the buffer contents and narrowing are unchanged. */
11478 int buffer_unchanged_p
= 0;
11479 int temp_scroll_step
= 0;
11480 int count
= SPECPDL_INDEX ();
11482 int centering_position
;
11483 int last_line_misfit
= 0;
11485 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11488 /* W must be a leaf window here. */
11489 xassert (!NILP (w
->buffer
));
11491 *w
->desired_matrix
->method
= 0;
11494 specbind (Qinhibit_point_motion_hooks
, Qt
);
11496 reconsider_clip_changes (w
, buffer
);
11498 /* Has the mode line to be updated? */
11499 update_mode_line
= (!NILP (w
->update_mode_line
)
11500 || update_mode_lines
11501 || buffer
->clip_changed
11502 || buffer
->prevent_redisplay_optimizations_p
);
11504 if (MINI_WINDOW_P (w
))
11506 if (w
== XWINDOW (echo_area_window
)
11507 && !NILP (echo_area_buffer
[0]))
11509 if (update_mode_line
)
11510 /* We may have to update a tty frame's menu bar or a
11511 tool-bar. Example `M-x C-h C-h C-g'. */
11512 goto finish_menu_bars
;
11514 /* We've already displayed the echo area glyphs in this window. */
11515 goto finish_scroll_bars
;
11517 else if ((w
!= XWINDOW (minibuf_window
)
11518 || minibuf_level
== 0)
11519 /* When buffer is nonempty, redisplay window normally. */
11520 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11521 /* Quail displays non-mini buffers in minibuffer window.
11522 In that case, redisplay the window normally. */
11523 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11525 /* W is a mini-buffer window, but it's not active, so clear
11527 int yb
= window_text_bottom_y (w
);
11528 struct glyph_row
*row
;
11531 for (y
= 0, row
= w
->desired_matrix
->rows
;
11533 y
+= row
->height
, ++row
)
11534 blank_row (w
, row
, y
);
11535 goto finish_scroll_bars
;
11538 clear_glyph_matrix (w
->desired_matrix
);
11541 /* Otherwise set up data on this window; select its buffer and point
11543 /* Really select the buffer, for the sake of buffer-local
11545 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11546 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11548 current_matrix_up_to_date_p
11549 = (!NILP (w
->window_end_valid
)
11550 && !current_buffer
->clip_changed
11551 && !current_buffer
->prevent_redisplay_optimizations_p
11552 && XFASTINT (w
->last_modified
) >= MODIFF
11553 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11556 = (!NILP (w
->window_end_valid
)
11557 && !current_buffer
->clip_changed
11558 && XFASTINT (w
->last_modified
) >= MODIFF
11559 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11561 /* When windows_or_buffers_changed is non-zero, we can't rely on
11562 the window end being valid, so set it to nil there. */
11563 if (windows_or_buffers_changed
)
11565 /* If window starts on a continuation line, maybe adjust the
11566 window start in case the window's width changed. */
11567 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11568 compute_window_start_on_continuation_line (w
);
11570 w
->window_end_valid
= Qnil
;
11573 /* Some sanity checks. */
11574 CHECK_WINDOW_END (w
);
11575 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11577 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11580 /* If %c is in mode line, update it if needed. */
11581 if (!NILP (w
->column_number_displayed
)
11582 /* This alternative quickly identifies a common case
11583 where no change is needed. */
11584 && !(PT
== XFASTINT (w
->last_point
)
11585 && XFASTINT (w
->last_modified
) >= MODIFF
11586 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11587 && (XFASTINT (w
->column_number_displayed
)
11588 != (int) current_column ())) /* iftc */
11589 update_mode_line
= 1;
11591 /* Count number of windows showing the selected buffer. An indirect
11592 buffer counts as its base buffer. */
11593 if (!just_this_one_p
)
11595 struct buffer
*current_base
, *window_base
;
11596 current_base
= current_buffer
;
11597 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11598 if (current_base
->base_buffer
)
11599 current_base
= current_base
->base_buffer
;
11600 if (window_base
->base_buffer
)
11601 window_base
= window_base
->base_buffer
;
11602 if (current_base
== window_base
)
11606 /* Point refers normally to the selected window. For any other
11607 window, set up appropriate value. */
11608 if (!EQ (window
, selected_window
))
11610 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11611 int new_pt_byte
= marker_byte_position (w
->pointm
);
11615 new_pt_byte
= BEGV_BYTE
;
11616 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11618 else if (new_pt
> (ZV
- 1))
11621 new_pt_byte
= ZV_BYTE
;
11622 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11625 /* We don't use SET_PT so that the point-motion hooks don't run. */
11626 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11629 /* If any of the character widths specified in the display table
11630 have changed, invalidate the width run cache. It's true that
11631 this may be a bit late to catch such changes, but the rest of
11632 redisplay goes (non-fatally) haywire when the display table is
11633 changed, so why should we worry about doing any better? */
11634 if (current_buffer
->width_run_cache
)
11636 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11638 if (! disptab_matches_widthtab (disptab
,
11639 XVECTOR (current_buffer
->width_table
)))
11641 invalidate_region_cache (current_buffer
,
11642 current_buffer
->width_run_cache
,
11644 recompute_width_table (current_buffer
, disptab
);
11648 /* If window-start is screwed up, choose a new one. */
11649 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11652 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11654 /* If someone specified a new starting point but did not insist,
11655 check whether it can be used. */
11656 if (!NILP (w
->optional_new_start
)
11657 && CHARPOS (startp
) >= BEGV
11658 && CHARPOS (startp
) <= ZV
)
11660 w
->optional_new_start
= Qnil
;
11661 start_display (&it
, w
, startp
);
11662 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11663 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11664 if (IT_CHARPOS (it
) == PT
)
11665 w
->force_start
= Qt
;
11666 /* IT may overshoot PT if text at PT is invisible. */
11667 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11668 w
->force_start
= Qt
;
11673 /* Handle case where place to start displaying has been specified,
11674 unless the specified location is outside the accessible range. */
11675 if (!NILP (w
->force_start
)
11676 || w
->frozen_window_start_p
)
11678 /* We set this later on if we have to adjust point. */
11681 w
->force_start
= Qnil
;
11683 w
->window_end_valid
= Qnil
;
11685 /* Forget any recorded base line for line number display. */
11686 if (!buffer_unchanged_p
)
11687 w
->base_line_number
= Qnil
;
11689 /* Redisplay the mode line. Select the buffer properly for that.
11690 Also, run the hook window-scroll-functions
11691 because we have scrolled. */
11692 /* Note, we do this after clearing force_start because
11693 if there's an error, it is better to forget about force_start
11694 than to get into an infinite loop calling the hook functions
11695 and having them get more errors. */
11696 if (!update_mode_line
11697 || ! NILP (Vwindow_scroll_functions
))
11699 update_mode_line
= 1;
11700 w
->update_mode_line
= Qt
;
11701 startp
= run_window_scroll_functions (window
, startp
);
11704 w
->last_modified
= make_number (0);
11705 w
->last_overlay_modified
= make_number (0);
11706 if (CHARPOS (startp
) < BEGV
)
11707 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11708 else if (CHARPOS (startp
) > ZV
)
11709 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11711 /* Redisplay, then check if cursor has been set during the
11712 redisplay. Give up if new fonts were loaded. */
11713 if (!try_window (window
, startp
))
11715 w
->force_start
= Qt
;
11716 clear_glyph_matrix (w
->desired_matrix
);
11717 goto need_larger_matrices
;
11720 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11722 /* If point does not appear, try to move point so it does
11723 appear. The desired matrix has been built above, so we
11724 can use it here. */
11725 new_vpos
= window_box_height (w
) / 2;
11728 if (!make_cursor_line_fully_visible (w
, 0))
11730 /* Point does appear, but on a line partly visible at end of window.
11731 Move it back to a fully-visible line. */
11732 new_vpos
= window_box_height (w
);
11735 /* If we need to move point for either of the above reasons,
11736 now actually do it. */
11739 struct glyph_row
*row
;
11741 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11742 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11745 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11746 MATRIX_ROW_START_BYTEPOS (row
));
11748 if (w
!= XWINDOW (selected_window
))
11749 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11750 else if (current_buffer
== old
)
11751 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11753 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11755 /* If we are highlighting the region, then we just changed
11756 the region, so redisplay to show it. */
11757 if (!NILP (Vtransient_mark_mode
)
11758 && !NILP (current_buffer
->mark_active
))
11760 clear_glyph_matrix (w
->desired_matrix
);
11761 if (!try_window (window
, startp
))
11762 goto need_larger_matrices
;
11767 debug_method_add (w
, "forced window start");
11772 /* Handle case where text has not changed, only point, and it has
11773 not moved off the frame, and we are not retrying after hscroll.
11774 (current_matrix_up_to_date_p is nonzero when retrying.) */
11775 if (current_matrix_up_to_date_p
11776 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11777 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11781 case CURSOR_MOVEMENT_SUCCESS
:
11782 used_current_matrix_p
= 1;
11785 #if 0 /* try_cursor_movement never returns this value. */
11786 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11787 goto need_larger_matrices
;
11790 case CURSOR_MOVEMENT_MUST_SCROLL
:
11791 goto try_to_scroll
;
11797 /* If current starting point was originally the beginning of a line
11798 but no longer is, find a new starting point. */
11799 else if (!NILP (w
->start_at_line_beg
)
11800 && !(CHARPOS (startp
) <= BEGV
11801 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11804 debug_method_add (w
, "recenter 1");
11809 /* Try scrolling with try_window_id. Value is > 0 if update has
11810 been done, it is -1 if we know that the same window start will
11811 not work. It is 0 if unsuccessful for some other reason. */
11812 else if ((tem
= try_window_id (w
)) != 0)
11815 debug_method_add (w
, "try_window_id %d", tem
);
11818 if (fonts_changed_p
)
11819 goto need_larger_matrices
;
11823 /* Otherwise try_window_id has returned -1 which means that we
11824 don't want the alternative below this comment to execute. */
11826 else if (CHARPOS (startp
) >= BEGV
11827 && CHARPOS (startp
) <= ZV
11828 && PT
>= CHARPOS (startp
)
11829 && (CHARPOS (startp
) < ZV
11830 /* Avoid starting at end of buffer. */
11831 || CHARPOS (startp
) == BEGV
11832 || (XFASTINT (w
->last_modified
) >= MODIFF
11833 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11836 debug_method_add (w
, "same window start");
11839 /* Try to redisplay starting at same place as before.
11840 If point has not moved off frame, accept the results. */
11841 if (!current_matrix_up_to_date_p
11842 /* Don't use try_window_reusing_current_matrix in this case
11843 because a window scroll function can have changed the
11845 || !NILP (Vwindow_scroll_functions
)
11846 || MINI_WINDOW_P (w
)
11847 || !(used_current_matrix_p
=
11848 try_window_reusing_current_matrix (w
)))
11850 IF_DEBUG (debug_method_add (w
, "1"));
11851 try_window (window
, startp
);
11854 if (fonts_changed_p
)
11855 goto need_larger_matrices
;
11857 if (w
->cursor
.vpos
>= 0)
11859 if (!just_this_one_p
11860 || current_buffer
->clip_changed
11861 || BEG_UNCHANGED
< CHARPOS (startp
))
11862 /* Forget any recorded base line for line number display. */
11863 w
->base_line_number
= Qnil
;
11865 if (!make_cursor_line_fully_visible (w
, 1))
11867 clear_glyph_matrix (w
->desired_matrix
);
11868 last_line_misfit
= 1;
11870 /* Drop through and scroll. */
11875 clear_glyph_matrix (w
->desired_matrix
);
11880 w
->last_modified
= make_number (0);
11881 w
->last_overlay_modified
= make_number (0);
11883 /* Redisplay the mode line. Select the buffer properly for that. */
11884 if (!update_mode_line
)
11886 update_mode_line
= 1;
11887 w
->update_mode_line
= Qt
;
11890 /* Try to scroll by specified few lines. */
11891 if ((scroll_conservatively
11893 || temp_scroll_step
11894 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11895 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11896 && !current_buffer
->clip_changed
11897 && CHARPOS (startp
) >= BEGV
11898 && CHARPOS (startp
) <= ZV
)
11900 /* The function returns -1 if new fonts were loaded, 1 if
11901 successful, 0 if not successful. */
11902 int rc
= try_scrolling (window
, just_this_one_p
,
11903 scroll_conservatively
,
11905 temp_scroll_step
, last_line_misfit
);
11908 case SCROLLING_SUCCESS
:
11911 case SCROLLING_NEED_LARGER_MATRICES
:
11912 goto need_larger_matrices
;
11914 case SCROLLING_FAILED
:
11922 /* Finally, just choose place to start which centers point */
11925 centering_position
= window_box_height (w
) / 2;
11928 /* Jump here with centering_position already set to 0. */
11931 debug_method_add (w
, "recenter");
11934 /* w->vscroll = 0; */
11936 /* Forget any previously recorded base line for line number display. */
11937 if (!buffer_unchanged_p
)
11938 w
->base_line_number
= Qnil
;
11940 /* Move backward half the height of the window. */
11941 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11942 it
.current_y
= it
.last_visible_y
;
11943 move_it_vertically_backward (&it
, centering_position
);
11944 xassert (IT_CHARPOS (it
) >= BEGV
);
11946 /* The function move_it_vertically_backward may move over more
11947 than the specified y-distance. If it->w is small, e.g. a
11948 mini-buffer window, we may end up in front of the window's
11949 display area. Start displaying at the start of the line
11950 containing PT in this case. */
11951 if (it
.current_y
<= 0)
11953 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11954 move_it_vertically (&it
, 0);
11955 xassert (IT_CHARPOS (it
) <= PT
);
11959 it
.current_x
= it
.hpos
= 0;
11961 /* Set startp here explicitly in case that helps avoid an infinite loop
11962 in case the window-scroll-functions functions get errors. */
11963 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11965 /* Run scroll hooks. */
11966 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11968 /* Redisplay the window. */
11969 if (!current_matrix_up_to_date_p
11970 || windows_or_buffers_changed
11971 || cursor_type_changed
11972 /* Don't use try_window_reusing_current_matrix in this case
11973 because it can have changed the buffer. */
11974 || !NILP (Vwindow_scroll_functions
)
11975 || !just_this_one_p
11976 || MINI_WINDOW_P (w
)
11977 || !(used_current_matrix_p
=
11978 try_window_reusing_current_matrix (w
)))
11979 try_window (window
, startp
);
11981 /* If new fonts have been loaded (due to fontsets), give up. We
11982 have to start a new redisplay since we need to re-adjust glyph
11984 if (fonts_changed_p
)
11985 goto need_larger_matrices
;
11987 /* If cursor did not appear assume that the middle of the window is
11988 in the first line of the window. Do it again with the next line.
11989 (Imagine a window of height 100, displaying two lines of height
11990 60. Moving back 50 from it->last_visible_y will end in the first
11992 if (w
->cursor
.vpos
< 0)
11994 if (!NILP (w
->window_end_valid
)
11995 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11997 clear_glyph_matrix (w
->desired_matrix
);
11998 move_it_by_lines (&it
, 1, 0);
11999 try_window (window
, it
.current
.pos
);
12001 else if (PT
< IT_CHARPOS (it
))
12003 clear_glyph_matrix (w
->desired_matrix
);
12004 move_it_by_lines (&it
, -1, 0);
12005 try_window (window
, it
.current
.pos
);
12009 /* Not much we can do about it. */
12013 /* Consider the following case: Window starts at BEGV, there is
12014 invisible, intangible text at BEGV, so that display starts at
12015 some point START > BEGV. It can happen that we are called with
12016 PT somewhere between BEGV and START. Try to handle that case. */
12017 if (w
->cursor
.vpos
< 0)
12019 struct glyph_row
*row
= w
->current_matrix
->rows
;
12020 if (row
->mode_line_p
)
12022 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12025 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12027 /* If vscroll is enabled, disable it and try again. */
12031 clear_glyph_matrix (w
->desired_matrix
);
12035 /* If centering point failed to make the whole line visible,
12036 put point at the top instead. That has to make the whole line
12037 visible, if it can be done. */
12038 clear_glyph_matrix (w
->desired_matrix
);
12039 centering_position
= 0;
12045 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12046 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12047 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12050 /* Display the mode line, if we must. */
12051 if ((update_mode_line
12052 /* If window not full width, must redo its mode line
12053 if (a) the window to its side is being redone and
12054 (b) we do a frame-based redisplay. This is a consequence
12055 of how inverted lines are drawn in frame-based redisplay. */
12056 || (!just_this_one_p
12057 && !FRAME_WINDOW_P (f
)
12058 && !WINDOW_FULL_WIDTH_P (w
))
12059 /* Line number to display. */
12060 || INTEGERP (w
->base_line_pos
)
12061 /* Column number is displayed and different from the one displayed. */
12062 || (!NILP (w
->column_number_displayed
)
12063 && (XFASTINT (w
->column_number_displayed
)
12064 != (int) current_column ()))) /* iftc */
12065 /* This means that the window has a mode line. */
12066 && (WINDOW_WANTS_MODELINE_P (w
)
12067 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12069 display_mode_lines (w
);
12071 /* If mode line height has changed, arrange for a thorough
12072 immediate redisplay using the correct mode line height. */
12073 if (WINDOW_WANTS_MODELINE_P (w
)
12074 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12076 fonts_changed_p
= 1;
12077 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12078 = DESIRED_MODE_LINE_HEIGHT (w
);
12081 /* If top line height has changed, arrange for a thorough
12082 immediate redisplay using the correct mode line height. */
12083 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12084 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12086 fonts_changed_p
= 1;
12087 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12088 = DESIRED_HEADER_LINE_HEIGHT (w
);
12091 if (fonts_changed_p
)
12092 goto need_larger_matrices
;
12095 if (!line_number_displayed
12096 && !BUFFERP (w
->base_line_pos
))
12098 w
->base_line_pos
= Qnil
;
12099 w
->base_line_number
= Qnil
;
12104 /* When we reach a frame's selected window, redo the frame's menu bar. */
12105 if (update_mode_line
12106 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12108 int redisplay_menu_p
= 0;
12109 int redisplay_tool_bar_p
= 0;
12111 if (FRAME_WINDOW_P (f
))
12113 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12114 || defined (USE_GTK)
12115 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12117 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12121 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12123 if (redisplay_menu_p
)
12124 display_menu_bar (w
);
12126 #ifdef HAVE_WINDOW_SYSTEM
12128 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12130 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12131 && (FRAME_TOOL_BAR_LINES (f
) > 0
12132 || auto_resize_tool_bars_p
);
12136 if (redisplay_tool_bar_p
)
12137 redisplay_tool_bar (f
);
12141 #ifdef HAVE_WINDOW_SYSTEM
12142 if (update_window_fringes (w
, 0)
12143 && !just_this_one_p
12144 && (used_current_matrix_p
|| overlay_arrow_seen
)
12145 && !w
->pseudo_window_p
)
12149 draw_window_fringes (w
);
12153 #endif /* HAVE_WINDOW_SYSTEM */
12155 /* We go to this label, with fonts_changed_p nonzero,
12156 if it is necessary to try again using larger glyph matrices.
12157 We have to redeem the scroll bar even in this case,
12158 because the loop in redisplay_internal expects that. */
12159 need_larger_matrices
:
12161 finish_scroll_bars
:
12163 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12165 /* Set the thumb's position and size. */
12166 set_vertical_scroll_bar (w
);
12168 /* Note that we actually used the scroll bar attached to this
12169 window, so it shouldn't be deleted at the end of redisplay. */
12170 redeem_scroll_bar_hook (w
);
12173 /* Restore current_buffer and value of point in it. */
12174 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12175 set_buffer_internal_1 (old
);
12176 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12178 unbind_to (count
, Qnil
);
12182 /* Build the complete desired matrix of WINDOW with a window start
12183 buffer position POS. Value is non-zero if successful. It is zero
12184 if fonts were loaded during redisplay which makes re-adjusting
12185 glyph matrices necessary. */
12188 try_window (window
, pos
)
12189 Lisp_Object window
;
12190 struct text_pos pos
;
12192 struct window
*w
= XWINDOW (window
);
12194 struct glyph_row
*last_text_row
= NULL
;
12196 /* Make POS the new window start. */
12197 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12199 /* Mark cursor position as unknown. No overlay arrow seen. */
12200 w
->cursor
.vpos
= -1;
12201 overlay_arrow_seen
= 0;
12203 /* Initialize iterator and info to start at POS. */
12204 start_display (&it
, w
, pos
);
12206 /* Display all lines of W. */
12207 while (it
.current_y
< it
.last_visible_y
)
12209 if (display_line (&it
))
12210 last_text_row
= it
.glyph_row
- 1;
12211 if (fonts_changed_p
)
12215 /* If bottom moved off end of frame, change mode line percentage. */
12216 if (XFASTINT (w
->window_end_pos
) <= 0
12217 && Z
!= IT_CHARPOS (it
))
12218 w
->update_mode_line
= Qt
;
12220 /* Set window_end_pos to the offset of the last character displayed
12221 on the window from the end of current_buffer. Set
12222 window_end_vpos to its row number. */
12225 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12226 w
->window_end_bytepos
12227 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12229 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12231 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12232 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12233 ->displays_text_p
);
12237 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12238 w
->window_end_pos
= make_number (Z
- ZV
);
12239 w
->window_end_vpos
= make_number (0);
12242 /* But that is not valid info until redisplay finishes. */
12243 w
->window_end_valid
= Qnil
;
12249 /************************************************************************
12250 Window redisplay reusing current matrix when buffer has not changed
12251 ************************************************************************/
12253 /* Try redisplay of window W showing an unchanged buffer with a
12254 different window start than the last time it was displayed by
12255 reusing its current matrix. Value is non-zero if successful.
12256 W->start is the new window start. */
12259 try_window_reusing_current_matrix (w
)
12262 struct frame
*f
= XFRAME (w
->frame
);
12263 struct glyph_row
*row
, *bottom_row
;
12266 struct text_pos start
, new_start
;
12267 int nrows_scrolled
, i
;
12268 struct glyph_row
*last_text_row
;
12269 struct glyph_row
*last_reused_text_row
;
12270 struct glyph_row
*start_row
;
12271 int start_vpos
, min_y
, max_y
;
12274 if (inhibit_try_window_reusing
)
12278 if (/* This function doesn't handle terminal frames. */
12279 !FRAME_WINDOW_P (f
)
12280 /* Don't try to reuse the display if windows have been split
12282 || windows_or_buffers_changed
12283 || cursor_type_changed
)
12286 /* Can't do this if region may have changed. */
12287 if ((!NILP (Vtransient_mark_mode
)
12288 && !NILP (current_buffer
->mark_active
))
12289 || !NILP (w
->region_showing
)
12290 || !NILP (Vshow_trailing_whitespace
))
12293 /* If top-line visibility has changed, give up. */
12294 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12295 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12298 /* Give up if old or new display is scrolled vertically. We could
12299 make this function handle this, but right now it doesn't. */
12300 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12301 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12304 /* The variable new_start now holds the new window start. The old
12305 start `start' can be determined from the current matrix. */
12306 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12307 start
= start_row
->start
.pos
;
12308 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12310 /* Clear the desired matrix for the display below. */
12311 clear_glyph_matrix (w
->desired_matrix
);
12313 if (CHARPOS (new_start
) <= CHARPOS (start
))
12317 /* Don't use this method if the display starts with an ellipsis
12318 displayed for invisible text. It's not easy to handle that case
12319 below, and it's certainly not worth the effort since this is
12320 not a frequent case. */
12321 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12324 IF_DEBUG (debug_method_add (w
, "twu1"));
12326 /* Display up to a row that can be reused. The variable
12327 last_text_row is set to the last row displayed that displays
12328 text. Note that it.vpos == 0 if or if not there is a
12329 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12330 start_display (&it
, w
, new_start
);
12331 first_row_y
= it
.current_y
;
12332 w
->cursor
.vpos
= -1;
12333 last_text_row
= last_reused_text_row
= NULL
;
12335 while (it
.current_y
< it
.last_visible_y
12336 && IT_CHARPOS (it
) < CHARPOS (start
)
12337 && !fonts_changed_p
)
12338 if (display_line (&it
))
12339 last_text_row
= it
.glyph_row
- 1;
12341 /* A value of current_y < last_visible_y means that we stopped
12342 at the previous window start, which in turn means that we
12343 have at least one reusable row. */
12344 if (it
.current_y
< it
.last_visible_y
)
12346 /* IT.vpos always starts from 0; it counts text lines. */
12347 nrows_scrolled
= it
.vpos
;
12349 /* Find PT if not already found in the lines displayed. */
12350 if (w
->cursor
.vpos
< 0)
12352 int dy
= it
.current_y
- first_row_y
;
12354 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12355 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12357 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12358 dy
, nrows_scrolled
);
12361 clear_glyph_matrix (w
->desired_matrix
);
12366 /* Scroll the display. Do it before the current matrix is
12367 changed. The problem here is that update has not yet
12368 run, i.e. part of the current matrix is not up to date.
12369 scroll_run_hook will clear the cursor, and use the
12370 current matrix to get the height of the row the cursor is
12372 run
.current_y
= first_row_y
;
12373 run
.desired_y
= it
.current_y
;
12374 run
.height
= it
.last_visible_y
- it
.current_y
;
12376 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12379 rif
->update_window_begin_hook (w
);
12380 rif
->clear_window_mouse_face (w
);
12381 rif
->scroll_run_hook (w
, &run
);
12382 rif
->update_window_end_hook (w
, 0, 0);
12386 /* Shift current matrix down by nrows_scrolled lines. */
12387 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12388 rotate_matrix (w
->current_matrix
,
12390 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12393 /* Disable lines that must be updated. */
12394 for (i
= 0; i
< it
.vpos
; ++i
)
12395 (start_row
+ i
)->enabled_p
= 0;
12397 /* Re-compute Y positions. */
12398 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12399 max_y
= it
.last_visible_y
;
12400 for (row
= start_row
+ nrows_scrolled
;
12404 row
->y
= it
.current_y
;
12405 row
->visible_height
= row
->height
;
12407 if (row
->y
< min_y
)
12408 row
->visible_height
-= min_y
- row
->y
;
12409 if (row
->y
+ row
->height
> max_y
)
12410 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12411 row
->redraw_fringe_bitmaps_p
= 1;
12413 it
.current_y
+= row
->height
;
12415 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12416 last_reused_text_row
= row
;
12417 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12421 /* Disable lines in the current matrix which are now
12422 below the window. */
12423 for (++row
; row
< bottom_row
; ++row
)
12424 row
->enabled_p
= 0;
12427 /* Update window_end_pos etc.; last_reused_text_row is the last
12428 reused row from the current matrix containing text, if any.
12429 The value of last_text_row is the last displayed line
12430 containing text. */
12431 if (last_reused_text_row
)
12433 w
->window_end_bytepos
12434 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12436 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12438 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12439 w
->current_matrix
));
12441 else if (last_text_row
)
12443 w
->window_end_bytepos
12444 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12446 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12448 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12452 /* This window must be completely empty. */
12453 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12454 w
->window_end_pos
= make_number (Z
- ZV
);
12455 w
->window_end_vpos
= make_number (0);
12457 w
->window_end_valid
= Qnil
;
12459 /* Update hint: don't try scrolling again in update_window. */
12460 w
->desired_matrix
->no_scrolling_p
= 1;
12463 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12467 else if (CHARPOS (new_start
) > CHARPOS (start
))
12469 struct glyph_row
*pt_row
, *row
;
12470 struct glyph_row
*first_reusable_row
;
12471 struct glyph_row
*first_row_to_display
;
12473 int yb
= window_text_bottom_y (w
);
12475 /* Find the row starting at new_start, if there is one. Don't
12476 reuse a partially visible line at the end. */
12477 first_reusable_row
= start_row
;
12478 while (first_reusable_row
->enabled_p
12479 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12480 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12481 < CHARPOS (new_start
)))
12482 ++first_reusable_row
;
12484 /* Give up if there is no row to reuse. */
12485 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12486 || !first_reusable_row
->enabled_p
12487 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12488 != CHARPOS (new_start
)))
12491 /* We can reuse fully visible rows beginning with
12492 first_reusable_row to the end of the window. Set
12493 first_row_to_display to the first row that cannot be reused.
12494 Set pt_row to the row containing point, if there is any. */
12496 for (first_row_to_display
= first_reusable_row
;
12497 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12498 ++first_row_to_display
)
12500 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12501 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12502 pt_row
= first_row_to_display
;
12505 /* Start displaying at the start of first_row_to_display. */
12506 xassert (first_row_to_display
->y
< yb
);
12507 init_to_row_start (&it
, w
, first_row_to_display
);
12509 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12511 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12513 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12514 + WINDOW_HEADER_LINE_HEIGHT (w
));
12516 /* Display lines beginning with first_row_to_display in the
12517 desired matrix. Set last_text_row to the last row displayed
12518 that displays text. */
12519 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12520 if (pt_row
== NULL
)
12521 w
->cursor
.vpos
= -1;
12522 last_text_row
= NULL
;
12523 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12524 if (display_line (&it
))
12525 last_text_row
= it
.glyph_row
- 1;
12527 /* Give up If point isn't in a row displayed or reused. */
12528 if (w
->cursor
.vpos
< 0)
12530 clear_glyph_matrix (w
->desired_matrix
);
12534 /* If point is in a reused row, adjust y and vpos of the cursor
12538 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12539 w
->current_matrix
);
12540 w
->cursor
.y
-= first_reusable_row
->y
;
12543 /* Scroll the display. */
12544 run
.current_y
= first_reusable_row
->y
;
12545 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12546 run
.height
= it
.last_visible_y
- run
.current_y
;
12547 dy
= run
.current_y
- run
.desired_y
;
12552 rif
->update_window_begin_hook (w
);
12553 rif
->clear_window_mouse_face (w
);
12554 rif
->scroll_run_hook (w
, &run
);
12555 rif
->update_window_end_hook (w
, 0, 0);
12559 /* Adjust Y positions of reused rows. */
12560 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12561 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12562 max_y
= it
.last_visible_y
;
12563 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12566 row
->visible_height
= row
->height
;
12567 if (row
->y
< min_y
)
12568 row
->visible_height
-= min_y
- row
->y
;
12569 if (row
->y
+ row
->height
> max_y
)
12570 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12571 row
->redraw_fringe_bitmaps_p
= 1;
12574 /* Scroll the current matrix. */
12575 xassert (nrows_scrolled
> 0);
12576 rotate_matrix (w
->current_matrix
,
12578 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12581 /* Disable rows not reused. */
12582 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12583 row
->enabled_p
= 0;
12585 /* Adjust window end. A null value of last_text_row means that
12586 the window end is in reused rows which in turn means that
12587 only its vpos can have changed. */
12590 w
->window_end_bytepos
12591 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12593 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12595 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12600 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12603 w
->window_end_valid
= Qnil
;
12604 w
->desired_matrix
->no_scrolling_p
= 1;
12607 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12617 /************************************************************************
12618 Window redisplay reusing current matrix when buffer has changed
12619 ************************************************************************/
12621 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12622 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12624 static struct glyph_row
*
12625 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12626 struct glyph_row
*));
12629 /* Return the last row in MATRIX displaying text. If row START is
12630 non-null, start searching with that row. IT gives the dimensions
12631 of the display. Value is null if matrix is empty; otherwise it is
12632 a pointer to the row found. */
12634 static struct glyph_row
*
12635 find_last_row_displaying_text (matrix
, it
, start
)
12636 struct glyph_matrix
*matrix
;
12638 struct glyph_row
*start
;
12640 struct glyph_row
*row
, *row_found
;
12642 /* Set row_found to the last row in IT->w's current matrix
12643 displaying text. The loop looks funny but think of partially
12646 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12647 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12649 xassert (row
->enabled_p
);
12651 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12660 /* Return the last row in the current matrix of W that is not affected
12661 by changes at the start of current_buffer that occurred since W's
12662 current matrix was built. Value is null if no such row exists.
12664 BEG_UNCHANGED us the number of characters unchanged at the start of
12665 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12666 first changed character in current_buffer. Characters at positions <
12667 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12668 when the current matrix was built. */
12670 static struct glyph_row
*
12671 find_last_unchanged_at_beg_row (w
)
12674 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12675 struct glyph_row
*row
;
12676 struct glyph_row
*row_found
= NULL
;
12677 int yb
= window_text_bottom_y (w
);
12679 /* Find the last row displaying unchanged text. */
12680 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12681 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12682 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12684 if (/* If row ends before first_changed_pos, it is unchanged,
12685 except in some case. */
12686 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12687 /* When row ends in ZV and we write at ZV it is not
12689 && !row
->ends_at_zv_p
12690 /* When first_changed_pos is the end of a continued line,
12691 row is not unchanged because it may be no longer
12693 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12694 && (row
->continued_p
12695 || row
->exact_window_width_line_p
)))
12698 /* Stop if last visible row. */
12699 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12709 /* Find the first glyph row in the current matrix of W that is not
12710 affected by changes at the end of current_buffer since the
12711 time W's current matrix was built.
12713 Return in *DELTA the number of chars by which buffer positions in
12714 unchanged text at the end of current_buffer must be adjusted.
12716 Return in *DELTA_BYTES the corresponding number of bytes.
12718 Value is null if no such row exists, i.e. all rows are affected by
12721 static struct glyph_row
*
12722 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12724 int *delta
, *delta_bytes
;
12726 struct glyph_row
*row
;
12727 struct glyph_row
*row_found
= NULL
;
12729 *delta
= *delta_bytes
= 0;
12731 /* Display must not have been paused, otherwise the current matrix
12732 is not up to date. */
12733 if (NILP (w
->window_end_valid
))
12736 /* A value of window_end_pos >= END_UNCHANGED means that the window
12737 end is in the range of changed text. If so, there is no
12738 unchanged row at the end of W's current matrix. */
12739 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12742 /* Set row to the last row in W's current matrix displaying text. */
12743 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12745 /* If matrix is entirely empty, no unchanged row exists. */
12746 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12748 /* The value of row is the last glyph row in the matrix having a
12749 meaningful buffer position in it. The end position of row
12750 corresponds to window_end_pos. This allows us to translate
12751 buffer positions in the current matrix to current buffer
12752 positions for characters not in changed text. */
12753 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12754 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12755 int last_unchanged_pos
, last_unchanged_pos_old
;
12756 struct glyph_row
*first_text_row
12757 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12759 *delta
= Z
- Z_old
;
12760 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12762 /* Set last_unchanged_pos to the buffer position of the last
12763 character in the buffer that has not been changed. Z is the
12764 index + 1 of the last character in current_buffer, i.e. by
12765 subtracting END_UNCHANGED we get the index of the last
12766 unchanged character, and we have to add BEG to get its buffer
12768 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12769 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12771 /* Search backward from ROW for a row displaying a line that
12772 starts at a minimum position >= last_unchanged_pos_old. */
12773 for (; row
> first_text_row
; --row
)
12775 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12778 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12783 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12790 /* Make sure that glyph rows in the current matrix of window W
12791 reference the same glyph memory as corresponding rows in the
12792 frame's frame matrix. This function is called after scrolling W's
12793 current matrix on a terminal frame in try_window_id and
12794 try_window_reusing_current_matrix. */
12797 sync_frame_with_window_matrix_rows (w
)
12800 struct frame
*f
= XFRAME (w
->frame
);
12801 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12803 /* Preconditions: W must be a leaf window and full-width. Its frame
12804 must have a frame matrix. */
12805 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12806 xassert (WINDOW_FULL_WIDTH_P (w
));
12807 xassert (!FRAME_WINDOW_P (f
));
12809 /* If W is a full-width window, glyph pointers in W's current matrix
12810 have, by definition, to be the same as glyph pointers in the
12811 corresponding frame matrix. Note that frame matrices have no
12812 marginal areas (see build_frame_matrix). */
12813 window_row
= w
->current_matrix
->rows
;
12814 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12815 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12816 while (window_row
< window_row_end
)
12818 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12819 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12821 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12822 frame_row
->glyphs
[TEXT_AREA
] = start
;
12823 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12824 frame_row
->glyphs
[LAST_AREA
] = end
;
12826 /* Disable frame rows whose corresponding window rows have
12827 been disabled in try_window_id. */
12828 if (!window_row
->enabled_p
)
12829 frame_row
->enabled_p
= 0;
12831 ++window_row
, ++frame_row
;
12836 /* Find the glyph row in window W containing CHARPOS. Consider all
12837 rows between START and END (not inclusive). END null means search
12838 all rows to the end of the display area of W. Value is the row
12839 containing CHARPOS or null. */
12842 row_containing_pos (w
, charpos
, start
, end
, dy
)
12845 struct glyph_row
*start
, *end
;
12848 struct glyph_row
*row
= start
;
12851 /* If we happen to start on a header-line, skip that. */
12852 if (row
->mode_line_p
)
12855 if ((end
&& row
>= end
) || !row
->enabled_p
)
12858 last_y
= window_text_bottom_y (w
) - dy
;
12862 /* Give up if we have gone too far. */
12863 if (end
&& row
>= end
)
12865 /* This formerly returned if they were equal.
12866 I think that both quantities are of a "last plus one" type;
12867 if so, when they are equal, the row is within the screen. -- rms. */
12868 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12871 /* If it is in this row, return this row. */
12872 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12873 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12874 /* The end position of a row equals the start
12875 position of the next row. If CHARPOS is there, we
12876 would rather display it in the next line, except
12877 when this line ends in ZV. */
12878 && !row
->ends_at_zv_p
12879 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12880 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12887 /* Try to redisplay window W by reusing its existing display. W's
12888 current matrix must be up to date when this function is called,
12889 i.e. window_end_valid must not be nil.
12893 1 if display has been updated
12894 0 if otherwise unsuccessful
12895 -1 if redisplay with same window start is known not to succeed
12897 The following steps are performed:
12899 1. Find the last row in the current matrix of W that is not
12900 affected by changes at the start of current_buffer. If no such row
12903 2. Find the first row in W's current matrix that is not affected by
12904 changes at the end of current_buffer. Maybe there is no such row.
12906 3. Display lines beginning with the row + 1 found in step 1 to the
12907 row found in step 2 or, if step 2 didn't find a row, to the end of
12910 4. If cursor is not known to appear on the window, give up.
12912 5. If display stopped at the row found in step 2, scroll the
12913 display and current matrix as needed.
12915 6. Maybe display some lines at the end of W, if we must. This can
12916 happen under various circumstances, like a partially visible line
12917 becoming fully visible, or because newly displayed lines are displayed
12918 in smaller font sizes.
12920 7. Update W's window end information. */
12926 struct frame
*f
= XFRAME (w
->frame
);
12927 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12928 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12929 struct glyph_row
*last_unchanged_at_beg_row
;
12930 struct glyph_row
*first_unchanged_at_end_row
;
12931 struct glyph_row
*row
;
12932 struct glyph_row
*bottom_row
;
12935 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12936 struct text_pos start_pos
;
12938 int first_unchanged_at_end_vpos
= 0;
12939 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12940 struct text_pos start
;
12941 int first_changed_charpos
, last_changed_charpos
;
12944 if (inhibit_try_window_id
)
12948 /* This is handy for debugging. */
12950 #define GIVE_UP(X) \
12952 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12956 #define GIVE_UP(X) return 0
12959 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12961 /* Don't use this for mini-windows because these can show
12962 messages and mini-buffers, and we don't handle that here. */
12963 if (MINI_WINDOW_P (w
))
12966 /* This flag is used to prevent redisplay optimizations. */
12967 if (windows_or_buffers_changed
|| cursor_type_changed
)
12970 /* Verify that narrowing has not changed.
12971 Also verify that we were not told to prevent redisplay optimizations.
12972 It would be nice to further
12973 reduce the number of cases where this prevents try_window_id. */
12974 if (current_buffer
->clip_changed
12975 || current_buffer
->prevent_redisplay_optimizations_p
)
12978 /* Window must either use window-based redisplay or be full width. */
12979 if (!FRAME_WINDOW_P (f
)
12980 && (!line_ins_del_ok
12981 || !WINDOW_FULL_WIDTH_P (w
)))
12984 /* Give up if point is not known NOT to appear in W. */
12985 if (PT
< CHARPOS (start
))
12988 /* Another way to prevent redisplay optimizations. */
12989 if (XFASTINT (w
->last_modified
) == 0)
12992 /* Verify that window is not hscrolled. */
12993 if (XFASTINT (w
->hscroll
) != 0)
12996 /* Verify that display wasn't paused. */
12997 if (NILP (w
->window_end_valid
))
13000 /* Can't use this if highlighting a region because a cursor movement
13001 will do more than just set the cursor. */
13002 if (!NILP (Vtransient_mark_mode
)
13003 && !NILP (current_buffer
->mark_active
))
13006 /* Likewise if highlighting trailing whitespace. */
13007 if (!NILP (Vshow_trailing_whitespace
))
13010 /* Likewise if showing a region. */
13011 if (!NILP (w
->region_showing
))
13014 /* Can use this if overlay arrow position and or string have changed. */
13015 if (overlay_arrows_changed_p ())
13019 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13020 only if buffer has really changed. The reason is that the gap is
13021 initially at Z for freshly visited files. The code below would
13022 set end_unchanged to 0 in that case. */
13023 if (MODIFF
> SAVE_MODIFF
13024 /* This seems to happen sometimes after saving a buffer. */
13025 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13027 if (GPT
- BEG
< BEG_UNCHANGED
)
13028 BEG_UNCHANGED
= GPT
- BEG
;
13029 if (Z
- GPT
< END_UNCHANGED
)
13030 END_UNCHANGED
= Z
- GPT
;
13033 /* The position of the first and last character that has been changed. */
13034 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13035 last_changed_charpos
= Z
- END_UNCHANGED
;
13037 /* If window starts after a line end, and the last change is in
13038 front of that newline, then changes don't affect the display.
13039 This case happens with stealth-fontification. Note that although
13040 the display is unchanged, glyph positions in the matrix have to
13041 be adjusted, of course. */
13042 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13043 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13044 && ((last_changed_charpos
< CHARPOS (start
)
13045 && CHARPOS (start
) == BEGV
)
13046 || (last_changed_charpos
< CHARPOS (start
) - 1
13047 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13049 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13050 struct glyph_row
*r0
;
13052 /* Compute how many chars/bytes have been added to or removed
13053 from the buffer. */
13054 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13055 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13057 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13059 /* Give up if PT is not in the window. Note that it already has
13060 been checked at the start of try_window_id that PT is not in
13061 front of the window start. */
13062 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13065 /* If window start is unchanged, we can reuse the whole matrix
13066 as is, after adjusting glyph positions. No need to compute
13067 the window end again, since its offset from Z hasn't changed. */
13068 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13069 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13070 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13071 /* PT must not be in a partially visible line. */
13072 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13073 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13075 /* Adjust positions in the glyph matrix. */
13076 if (delta
|| delta_bytes
)
13078 struct glyph_row
*r1
13079 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13080 increment_matrix_positions (w
->current_matrix
,
13081 MATRIX_ROW_VPOS (r0
, current_matrix
),
13082 MATRIX_ROW_VPOS (r1
, current_matrix
),
13083 delta
, delta_bytes
);
13086 /* Set the cursor. */
13087 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13089 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13096 /* Handle the case that changes are all below what is displayed in
13097 the window, and that PT is in the window. This shortcut cannot
13098 be taken if ZV is visible in the window, and text has been added
13099 there that is visible in the window. */
13100 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13101 /* ZV is not visible in the window, or there are no
13102 changes at ZV, actually. */
13103 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13104 || first_changed_charpos
== last_changed_charpos
))
13106 struct glyph_row
*r0
;
13108 /* Give up if PT is not in the window. Note that it already has
13109 been checked at the start of try_window_id that PT is not in
13110 front of the window start. */
13111 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13114 /* If window start is unchanged, we can reuse the whole matrix
13115 as is, without changing glyph positions since no text has
13116 been added/removed in front of the window end. */
13117 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13118 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13119 /* PT must not be in a partially visible line. */
13120 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13121 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13123 /* We have to compute the window end anew since text
13124 can have been added/removed after it. */
13126 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13127 w
->window_end_bytepos
13128 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13130 /* Set the cursor. */
13131 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13133 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13140 /* Give up if window start is in the changed area.
13142 The condition used to read
13144 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13146 but why that was tested escapes me at the moment. */
13147 if (CHARPOS (start
) >= first_changed_charpos
13148 && CHARPOS (start
) <= last_changed_charpos
)
13151 /* Check that window start agrees with the start of the first glyph
13152 row in its current matrix. Check this after we know the window
13153 start is not in changed text, otherwise positions would not be
13155 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13156 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13159 /* Give up if the window ends in strings. Overlay strings
13160 at the end are difficult to handle, so don't try. */
13161 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13162 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13165 /* Compute the position at which we have to start displaying new
13166 lines. Some of the lines at the top of the window might be
13167 reusable because they are not displaying changed text. Find the
13168 last row in W's current matrix not affected by changes at the
13169 start of current_buffer. Value is null if changes start in the
13170 first line of window. */
13171 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13172 if (last_unchanged_at_beg_row
)
13174 /* Avoid starting to display in the moddle of a character, a TAB
13175 for instance. This is easier than to set up the iterator
13176 exactly, and it's not a frequent case, so the additional
13177 effort wouldn't really pay off. */
13178 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13179 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13180 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13181 --last_unchanged_at_beg_row
;
13183 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13186 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13188 start_pos
= it
.current
.pos
;
13190 /* Start displaying new lines in the desired matrix at the same
13191 vpos we would use in the current matrix, i.e. below
13192 last_unchanged_at_beg_row. */
13193 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13195 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13196 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13198 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13202 /* There are no reusable lines at the start of the window.
13203 Start displaying in the first text line. */
13204 start_display (&it
, w
, start
);
13205 it
.vpos
= it
.first_vpos
;
13206 start_pos
= it
.current
.pos
;
13209 /* Find the first row that is not affected by changes at the end of
13210 the buffer. Value will be null if there is no unchanged row, in
13211 which case we must redisplay to the end of the window. delta
13212 will be set to the value by which buffer positions beginning with
13213 first_unchanged_at_end_row have to be adjusted due to text
13215 first_unchanged_at_end_row
13216 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13217 IF_DEBUG (debug_delta
= delta
);
13218 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13220 /* Set stop_pos to the buffer position up to which we will have to
13221 display new lines. If first_unchanged_at_end_row != NULL, this
13222 is the buffer position of the start of the line displayed in that
13223 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13224 that we don't stop at a buffer position. */
13226 if (first_unchanged_at_end_row
)
13228 xassert (last_unchanged_at_beg_row
== NULL
13229 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13231 /* If this is a continuation line, move forward to the next one
13232 that isn't. Changes in lines above affect this line.
13233 Caution: this may move first_unchanged_at_end_row to a row
13234 not displaying text. */
13235 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13236 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13237 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13238 < it
.last_visible_y
))
13239 ++first_unchanged_at_end_row
;
13241 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13242 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13243 >= it
.last_visible_y
))
13244 first_unchanged_at_end_row
= NULL
;
13247 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13249 first_unchanged_at_end_vpos
13250 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13251 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13254 else if (last_unchanged_at_beg_row
== NULL
)
13260 /* Either there is no unchanged row at the end, or the one we have
13261 now displays text. This is a necessary condition for the window
13262 end pos calculation at the end of this function. */
13263 xassert (first_unchanged_at_end_row
== NULL
13264 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13266 debug_last_unchanged_at_beg_vpos
13267 = (last_unchanged_at_beg_row
13268 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13270 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13272 #endif /* GLYPH_DEBUG != 0 */
13275 /* Display new lines. Set last_text_row to the last new line
13276 displayed which has text on it, i.e. might end up as being the
13277 line where the window_end_vpos is. */
13278 w
->cursor
.vpos
= -1;
13279 last_text_row
= NULL
;
13280 overlay_arrow_seen
= 0;
13281 while (it
.current_y
< it
.last_visible_y
13282 && !fonts_changed_p
13283 && (first_unchanged_at_end_row
== NULL
13284 || IT_CHARPOS (it
) < stop_pos
))
13286 if (display_line (&it
))
13287 last_text_row
= it
.glyph_row
- 1;
13290 if (fonts_changed_p
)
13294 /* Compute differences in buffer positions, y-positions etc. for
13295 lines reused at the bottom of the window. Compute what we can
13297 if (first_unchanged_at_end_row
13298 /* No lines reused because we displayed everything up to the
13299 bottom of the window. */
13300 && it
.current_y
< it
.last_visible_y
)
13303 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13305 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13306 run
.current_y
= first_unchanged_at_end_row
->y
;
13307 run
.desired_y
= run
.current_y
+ dy
;
13308 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13312 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13313 first_unchanged_at_end_row
= NULL
;
13315 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13318 /* Find the cursor if not already found. We have to decide whether
13319 PT will appear on this window (it sometimes doesn't, but this is
13320 not a very frequent case.) This decision has to be made before
13321 the current matrix is altered. A value of cursor.vpos < 0 means
13322 that PT is either in one of the lines beginning at
13323 first_unchanged_at_end_row or below the window. Don't care for
13324 lines that might be displayed later at the window end; as
13325 mentioned, this is not a frequent case. */
13326 if (w
->cursor
.vpos
< 0)
13328 /* Cursor in unchanged rows at the top? */
13329 if (PT
< CHARPOS (start_pos
)
13330 && last_unchanged_at_beg_row
)
13332 row
= row_containing_pos (w
, PT
,
13333 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13334 last_unchanged_at_beg_row
+ 1, 0);
13336 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13339 /* Start from first_unchanged_at_end_row looking for PT. */
13340 else if (first_unchanged_at_end_row
)
13342 row
= row_containing_pos (w
, PT
- delta
,
13343 first_unchanged_at_end_row
, NULL
, 0);
13345 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13346 delta_bytes
, dy
, dvpos
);
13349 /* Give up if cursor was not found. */
13350 if (w
->cursor
.vpos
< 0)
13352 clear_glyph_matrix (w
->desired_matrix
);
13357 /* Don't let the cursor end in the scroll margins. */
13359 int this_scroll_margin
, cursor_height
;
13361 this_scroll_margin
= max (0, scroll_margin
);
13362 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13363 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13364 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13366 if ((w
->cursor
.y
< this_scroll_margin
13367 && CHARPOS (start
) > BEGV
)
13368 /* Don't take scroll margin into account at the bottom because
13369 old redisplay didn't do it either. */
13370 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13372 w
->cursor
.vpos
= -1;
13373 clear_glyph_matrix (w
->desired_matrix
);
13378 /* Scroll the display. Do it before changing the current matrix so
13379 that xterm.c doesn't get confused about where the cursor glyph is
13381 if (dy
&& run
.height
)
13385 if (FRAME_WINDOW_P (f
))
13387 rif
->update_window_begin_hook (w
);
13388 rif
->clear_window_mouse_face (w
);
13389 rif
->scroll_run_hook (w
, &run
);
13390 rif
->update_window_end_hook (w
, 0, 0);
13394 /* Terminal frame. In this case, dvpos gives the number of
13395 lines to scroll by; dvpos < 0 means scroll up. */
13396 int first_unchanged_at_end_vpos
13397 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13398 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13399 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13400 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13401 + window_internal_height (w
));
13403 /* Perform the operation on the screen. */
13406 /* Scroll last_unchanged_at_beg_row to the end of the
13407 window down dvpos lines. */
13408 set_terminal_window (end
);
13410 /* On dumb terminals delete dvpos lines at the end
13411 before inserting dvpos empty lines. */
13412 if (!scroll_region_ok
)
13413 ins_del_lines (end
- dvpos
, -dvpos
);
13415 /* Insert dvpos empty lines in front of
13416 last_unchanged_at_beg_row. */
13417 ins_del_lines (from
, dvpos
);
13419 else if (dvpos
< 0)
13421 /* Scroll up last_unchanged_at_beg_vpos to the end of
13422 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13423 set_terminal_window (end
);
13425 /* Delete dvpos lines in front of
13426 last_unchanged_at_beg_vpos. ins_del_lines will set
13427 the cursor to the given vpos and emit |dvpos| delete
13429 ins_del_lines (from
+ dvpos
, dvpos
);
13431 /* On a dumb terminal insert dvpos empty lines at the
13433 if (!scroll_region_ok
)
13434 ins_del_lines (end
+ dvpos
, -dvpos
);
13437 set_terminal_window (0);
13443 /* Shift reused rows of the current matrix to the right position.
13444 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13446 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13447 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13450 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13451 bottom_vpos
, dvpos
);
13452 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13455 else if (dvpos
> 0)
13457 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13458 bottom_vpos
, dvpos
);
13459 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13460 first_unchanged_at_end_vpos
+ dvpos
, 0);
13463 /* For frame-based redisplay, make sure that current frame and window
13464 matrix are in sync with respect to glyph memory. */
13465 if (!FRAME_WINDOW_P (f
))
13466 sync_frame_with_window_matrix_rows (w
);
13468 /* Adjust buffer positions in reused rows. */
13470 increment_matrix_positions (current_matrix
,
13471 first_unchanged_at_end_vpos
+ dvpos
,
13472 bottom_vpos
, delta
, delta_bytes
);
13474 /* Adjust Y positions. */
13476 shift_glyph_matrix (w
, current_matrix
,
13477 first_unchanged_at_end_vpos
+ dvpos
,
13480 if (first_unchanged_at_end_row
)
13481 first_unchanged_at_end_row
+= dvpos
;
13483 /* If scrolling up, there may be some lines to display at the end of
13485 last_text_row_at_end
= NULL
;
13488 /* Scrolling up can leave for example a partially visible line
13489 at the end of the window to be redisplayed. */
13490 /* Set last_row to the glyph row in the current matrix where the
13491 window end line is found. It has been moved up or down in
13492 the matrix by dvpos. */
13493 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13494 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13496 /* If last_row is the window end line, it should display text. */
13497 xassert (last_row
->displays_text_p
);
13499 /* If window end line was partially visible before, begin
13500 displaying at that line. Otherwise begin displaying with the
13501 line following it. */
13502 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13504 init_to_row_start (&it
, w
, last_row
);
13505 it
.vpos
= last_vpos
;
13506 it
.current_y
= last_row
->y
;
13510 init_to_row_end (&it
, w
, last_row
);
13511 it
.vpos
= 1 + last_vpos
;
13512 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13516 /* We may start in a continuation line. If so, we have to
13517 get the right continuation_lines_width and current_x. */
13518 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13519 it
.hpos
= it
.current_x
= 0;
13521 /* Display the rest of the lines at the window end. */
13522 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13523 while (it
.current_y
< it
.last_visible_y
13524 && !fonts_changed_p
)
13526 /* Is it always sure that the display agrees with lines in
13527 the current matrix? I don't think so, so we mark rows
13528 displayed invalid in the current matrix by setting their
13529 enabled_p flag to zero. */
13530 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13531 if (display_line (&it
))
13532 last_text_row_at_end
= it
.glyph_row
- 1;
13536 /* Update window_end_pos and window_end_vpos. */
13537 if (first_unchanged_at_end_row
13538 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13539 && !last_text_row_at_end
)
13541 /* Window end line if one of the preserved rows from the current
13542 matrix. Set row to the last row displaying text in current
13543 matrix starting at first_unchanged_at_end_row, after
13545 xassert (first_unchanged_at_end_row
->displays_text_p
);
13546 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13547 first_unchanged_at_end_row
);
13548 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13550 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13551 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13553 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13554 xassert (w
->window_end_bytepos
>= 0);
13555 IF_DEBUG (debug_method_add (w
, "A"));
13557 else if (last_text_row_at_end
)
13560 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13561 w
->window_end_bytepos
13562 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13564 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13565 xassert (w
->window_end_bytepos
>= 0);
13566 IF_DEBUG (debug_method_add (w
, "B"));
13568 else if (last_text_row
)
13570 /* We have displayed either to the end of the window or at the
13571 end of the window, i.e. the last row with text is to be found
13572 in the desired matrix. */
13574 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13575 w
->window_end_bytepos
13576 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13578 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13579 xassert (w
->window_end_bytepos
>= 0);
13581 else if (first_unchanged_at_end_row
== NULL
13582 && last_text_row
== NULL
13583 && last_text_row_at_end
== NULL
)
13585 /* Displayed to end of window, but no line containing text was
13586 displayed. Lines were deleted at the end of the window. */
13587 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13588 int vpos
= XFASTINT (w
->window_end_vpos
);
13589 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13590 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13593 row
== NULL
&& vpos
>= first_vpos
;
13594 --vpos
, --current_row
, --desired_row
)
13596 if (desired_row
->enabled_p
)
13598 if (desired_row
->displays_text_p
)
13601 else if (current_row
->displays_text_p
)
13605 xassert (row
!= NULL
);
13606 w
->window_end_vpos
= make_number (vpos
+ 1);
13607 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13608 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13609 xassert (w
->window_end_bytepos
>= 0);
13610 IF_DEBUG (debug_method_add (w
, "C"));
13615 #if 0 /* This leads to problems, for instance when the cursor is
13616 at ZV, and the cursor line displays no text. */
13617 /* Disable rows below what's displayed in the window. This makes
13618 debugging easier. */
13619 enable_glyph_matrix_rows (current_matrix
,
13620 XFASTINT (w
->window_end_vpos
) + 1,
13624 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13625 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13627 /* Record that display has not been completed. */
13628 w
->window_end_valid
= Qnil
;
13629 w
->desired_matrix
->no_scrolling_p
= 1;
13637 /***********************************************************************
13638 More debugging support
13639 ***********************************************************************/
13643 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13644 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13645 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13648 /* Dump the contents of glyph matrix MATRIX on stderr.
13650 GLYPHS 0 means don't show glyph contents.
13651 GLYPHS 1 means show glyphs in short form
13652 GLYPHS > 1 means show glyphs in long form. */
13655 dump_glyph_matrix (matrix
, glyphs
)
13656 struct glyph_matrix
*matrix
;
13660 for (i
= 0; i
< matrix
->nrows
; ++i
)
13661 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13665 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13666 the glyph row and area where the glyph comes from. */
13669 dump_glyph (row
, glyph
, area
)
13670 struct glyph_row
*row
;
13671 struct glyph
*glyph
;
13674 if (glyph
->type
== CHAR_GLYPH
)
13677 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13678 glyph
- row
->glyphs
[TEXT_AREA
],
13681 (BUFFERP (glyph
->object
)
13683 : (STRINGP (glyph
->object
)
13686 glyph
->pixel_width
,
13688 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13692 glyph
->left_box_line_p
,
13693 glyph
->right_box_line_p
);
13695 else if (glyph
->type
== STRETCH_GLYPH
)
13698 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13699 glyph
- row
->glyphs
[TEXT_AREA
],
13702 (BUFFERP (glyph
->object
)
13704 : (STRINGP (glyph
->object
)
13707 glyph
->pixel_width
,
13711 glyph
->left_box_line_p
,
13712 glyph
->right_box_line_p
);
13714 else if (glyph
->type
== IMAGE_GLYPH
)
13717 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13718 glyph
- row
->glyphs
[TEXT_AREA
],
13721 (BUFFERP (glyph
->object
)
13723 : (STRINGP (glyph
->object
)
13726 glyph
->pixel_width
,
13730 glyph
->left_box_line_p
,
13731 glyph
->right_box_line_p
);
13736 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13737 GLYPHS 0 means don't show glyph contents.
13738 GLYPHS 1 means show glyphs in short form
13739 GLYPHS > 1 means show glyphs in long form. */
13742 dump_glyph_row (row
, vpos
, glyphs
)
13743 struct glyph_row
*row
;
13748 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13749 fprintf (stderr
, "=======================================================================\n");
13751 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13752 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13754 MATRIX_ROW_START_CHARPOS (row
),
13755 MATRIX_ROW_END_CHARPOS (row
),
13756 row
->used
[TEXT_AREA
],
13757 row
->contains_overlapping_glyphs_p
,
13759 row
->truncated_on_left_p
,
13760 row
->truncated_on_right_p
,
13761 row
->overlay_arrow_p
,
13763 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13764 row
->displays_text_p
,
13767 row
->ends_in_middle_of_char_p
,
13768 row
->starts_in_middle_of_char_p
,
13774 row
->visible_height
,
13777 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13778 row
->end
.overlay_string_index
,
13779 row
->continuation_lines_width
);
13780 fprintf (stderr
, "%9d %5d\n",
13781 CHARPOS (row
->start
.string_pos
),
13782 CHARPOS (row
->end
.string_pos
));
13783 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13784 row
->end
.dpvec_index
);
13791 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13793 struct glyph
*glyph
= row
->glyphs
[area
];
13794 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13796 /* Glyph for a line end in text. */
13797 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13800 if (glyph
< glyph_end
)
13801 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13803 for (; glyph
< glyph_end
; ++glyph
)
13804 dump_glyph (row
, glyph
, area
);
13807 else if (glyphs
== 1)
13811 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13813 char *s
= (char *) alloca (row
->used
[area
] + 1);
13816 for (i
= 0; i
< row
->used
[area
]; ++i
)
13818 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13819 if (glyph
->type
== CHAR_GLYPH
13820 && glyph
->u
.ch
< 0x80
13821 && glyph
->u
.ch
>= ' ')
13822 s
[i
] = glyph
->u
.ch
;
13828 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13834 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13835 Sdump_glyph_matrix
, 0, 1, "p",
13836 doc
: /* Dump the current matrix of the selected window to stderr.
13837 Shows contents of glyph row structures. With non-nil
13838 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13839 glyphs in short form, otherwise show glyphs in long form. */)
13841 Lisp_Object glyphs
;
13843 struct window
*w
= XWINDOW (selected_window
);
13844 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13846 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13847 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13848 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13849 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13850 fprintf (stderr
, "=============================================\n");
13851 dump_glyph_matrix (w
->current_matrix
,
13852 NILP (glyphs
) ? 0 : XINT (glyphs
));
13857 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13858 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13861 struct frame
*f
= XFRAME (selected_frame
);
13862 dump_glyph_matrix (f
->current_matrix
, 1);
13867 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13868 doc
: /* Dump glyph row ROW to stderr.
13869 GLYPH 0 means don't dump glyphs.
13870 GLYPH 1 means dump glyphs in short form.
13871 GLYPH > 1 or omitted means dump glyphs in long form. */)
13873 Lisp_Object row
, glyphs
;
13875 struct glyph_matrix
*matrix
;
13878 CHECK_NUMBER (row
);
13879 matrix
= XWINDOW (selected_window
)->current_matrix
;
13881 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13882 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13884 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13889 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13890 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13891 GLYPH 0 means don't dump glyphs.
13892 GLYPH 1 means dump glyphs in short form.
13893 GLYPH > 1 or omitted means dump glyphs in long form. */)
13895 Lisp_Object row
, glyphs
;
13897 struct frame
*sf
= SELECTED_FRAME ();
13898 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13901 CHECK_NUMBER (row
);
13903 if (vpos
>= 0 && vpos
< m
->nrows
)
13904 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13905 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13910 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13911 doc
: /* Toggle tracing of redisplay.
13912 With ARG, turn tracing on if and only if ARG is positive. */)
13917 trace_redisplay_p
= !trace_redisplay_p
;
13920 arg
= Fprefix_numeric_value (arg
);
13921 trace_redisplay_p
= XINT (arg
) > 0;
13928 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13929 doc
: /* Like `format', but print result to stderr.
13930 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13935 Lisp_Object s
= Fformat (nargs
, args
);
13936 fprintf (stderr
, "%s", SDATA (s
));
13940 #endif /* GLYPH_DEBUG */
13944 /***********************************************************************
13945 Building Desired Matrix Rows
13946 ***********************************************************************/
13948 /* Return a temporary glyph row holding the glyphs of an overlay
13949 arrow. Only used for non-window-redisplay windows. */
13951 static struct glyph_row
*
13952 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
13954 Lisp_Object overlay_arrow_string
;
13956 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13957 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13958 struct buffer
*old
= current_buffer
;
13959 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
13960 int arrow_len
= SCHARS (overlay_arrow_string
);
13961 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13962 const unsigned char *p
;
13965 int n_glyphs_before
;
13967 set_buffer_temp (buffer
);
13968 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13969 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13970 SET_TEXT_POS (it
.position
, 0, 0);
13972 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13974 while (p
< arrow_end
)
13976 Lisp_Object face
, ilisp
;
13978 /* Get the next character. */
13980 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13982 it
.c
= *p
, it
.len
= 1;
13985 /* Get its face. */
13986 ilisp
= make_number (p
- arrow_string
);
13987 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
13988 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13990 /* Compute its width, get its glyphs. */
13991 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13992 SET_TEXT_POS (it
.position
, -1, -1);
13993 PRODUCE_GLYPHS (&it
);
13995 /* If this character doesn't fit any more in the line, we have
13996 to remove some glyphs. */
13997 if (it
.current_x
> it
.last_visible_x
)
13999 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14004 set_buffer_temp (old
);
14005 return it
.glyph_row
;
14009 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14010 glyphs are only inserted for terminal frames since we can't really
14011 win with truncation glyphs when partially visible glyphs are
14012 involved. Which glyphs to insert is determined by
14013 produce_special_glyphs. */
14016 insert_left_trunc_glyphs (it
)
14019 struct it truncate_it
;
14020 struct glyph
*from
, *end
, *to
, *toend
;
14022 xassert (!FRAME_WINDOW_P (it
->f
));
14024 /* Get the truncation glyphs. */
14026 truncate_it
.current_x
= 0;
14027 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14028 truncate_it
.glyph_row
= &scratch_glyph_row
;
14029 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14030 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14031 truncate_it
.object
= make_number (0);
14032 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14034 /* Overwrite glyphs from IT with truncation glyphs. */
14035 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14036 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14037 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14038 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14043 /* There may be padding glyphs left over. Overwrite them too. */
14044 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14046 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14052 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14056 /* Compute the pixel height and width of IT->glyph_row.
14058 Most of the time, ascent and height of a display line will be equal
14059 to the max_ascent and max_height values of the display iterator
14060 structure. This is not the case if
14062 1. We hit ZV without displaying anything. In this case, max_ascent
14063 and max_height will be zero.
14065 2. We have some glyphs that don't contribute to the line height.
14066 (The glyph row flag contributes_to_line_height_p is for future
14067 pixmap extensions).
14069 The first case is easily covered by using default values because in
14070 these cases, the line height does not really matter, except that it
14071 must not be zero. */
14074 compute_line_metrics (it
)
14077 struct glyph_row
*row
= it
->glyph_row
;
14080 if (FRAME_WINDOW_P (it
->f
))
14082 int i
, min_y
, max_y
;
14084 /* The line may consist of one space only, that was added to
14085 place the cursor on it. If so, the row's height hasn't been
14087 if (row
->height
== 0)
14089 if (it
->max_ascent
+ it
->max_descent
== 0)
14090 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14091 row
->ascent
= it
->max_ascent
;
14092 row
->height
= it
->max_ascent
+ it
->max_descent
;
14093 row
->phys_ascent
= it
->max_phys_ascent
;
14094 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14097 /* Compute the width of this line. */
14098 row
->pixel_width
= row
->x
;
14099 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14100 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14102 xassert (row
->pixel_width
>= 0);
14103 xassert (row
->ascent
>= 0 && row
->height
> 0);
14105 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14106 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14108 /* If first line's physical ascent is larger than its logical
14109 ascent, use the physical ascent, and make the row taller.
14110 This makes accented characters fully visible. */
14111 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14112 && row
->phys_ascent
> row
->ascent
)
14114 row
->height
+= row
->phys_ascent
- row
->ascent
;
14115 row
->ascent
= row
->phys_ascent
;
14118 /* Compute how much of the line is visible. */
14119 row
->visible_height
= row
->height
;
14121 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14122 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14124 if (row
->y
< min_y
)
14125 row
->visible_height
-= min_y
- row
->y
;
14126 if (row
->y
+ row
->height
> max_y
)
14127 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14131 row
->pixel_width
= row
->used
[TEXT_AREA
];
14132 if (row
->continued_p
)
14133 row
->pixel_width
-= it
->continuation_pixel_width
;
14134 else if (row
->truncated_on_right_p
)
14135 row
->pixel_width
-= it
->truncation_pixel_width
;
14136 row
->ascent
= row
->phys_ascent
= 0;
14137 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14140 /* Compute a hash code for this row. */
14142 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14143 for (i
= 0; i
< row
->used
[area
]; ++i
)
14144 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14145 + row
->glyphs
[area
][i
].u
.val
14146 + row
->glyphs
[area
][i
].face_id
14147 + row
->glyphs
[area
][i
].padding_p
14148 + (row
->glyphs
[area
][i
].type
<< 2));
14150 it
->max_ascent
= it
->max_descent
= 0;
14151 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14155 /* Append one space to the glyph row of iterator IT if doing a
14156 window-based redisplay. The space has the same face as
14157 IT->face_id. Value is non-zero if a space was added.
14159 This function is called to make sure that there is always one glyph
14160 at the end of a glyph row that the cursor can be set on under
14161 window-systems. (If there weren't such a glyph we would not know
14162 how wide and tall a box cursor should be displayed).
14164 At the same time this space let's a nicely handle clearing to the
14165 end of the line if the row ends in italic text. */
14168 append_space_for_newline (it
, default_face_p
)
14170 int default_face_p
;
14172 if (FRAME_WINDOW_P (it
->f
))
14174 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14176 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14177 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14179 /* Save some values that must not be changed.
14180 Must save IT->c and IT->len because otherwise
14181 ITERATOR_AT_END_P wouldn't work anymore after
14182 append_space_for_newline has been called. */
14183 enum display_element_type saved_what
= it
->what
;
14184 int saved_c
= it
->c
, saved_len
= it
->len
;
14185 int saved_x
= it
->current_x
;
14186 int saved_face_id
= it
->face_id
;
14187 struct text_pos saved_pos
;
14188 Lisp_Object saved_object
;
14191 saved_object
= it
->object
;
14192 saved_pos
= it
->position
;
14194 it
->what
= IT_CHARACTER
;
14195 bzero (&it
->position
, sizeof it
->position
);
14196 it
->object
= make_number (0);
14200 if (default_face_p
)
14201 it
->face_id
= DEFAULT_FACE_ID
;
14202 else if (it
->face_before_selective_p
)
14203 it
->face_id
= it
->saved_face_id
;
14204 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14205 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14207 PRODUCE_GLYPHS (it
);
14209 it
->override_ascent
= -1;
14210 it
->constrain_row_ascent_descent_p
= 0;
14211 it
->current_x
= saved_x
;
14212 it
->object
= saved_object
;
14213 it
->position
= saved_pos
;
14214 it
->what
= saved_what
;
14215 it
->face_id
= saved_face_id
;
14216 it
->len
= saved_len
;
14226 /* Extend the face of the last glyph in the text area of IT->glyph_row
14227 to the end of the display line. Called from display_line.
14228 If the glyph row is empty, add a space glyph to it so that we
14229 know the face to draw. Set the glyph row flag fill_line_p. */
14232 extend_face_to_end_of_line (it
)
14236 struct frame
*f
= it
->f
;
14238 /* If line is already filled, do nothing. */
14239 if (it
->current_x
>= it
->last_visible_x
)
14242 /* Face extension extends the background and box of IT->face_id
14243 to the end of the line. If the background equals the background
14244 of the frame, we don't have to do anything. */
14245 if (it
->face_before_selective_p
)
14246 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14248 face
= FACE_FROM_ID (f
, it
->face_id
);
14250 if (FRAME_WINDOW_P (f
)
14251 && face
->box
== FACE_NO_BOX
14252 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14256 /* Set the glyph row flag indicating that the face of the last glyph
14257 in the text area has to be drawn to the end of the text area. */
14258 it
->glyph_row
->fill_line_p
= 1;
14260 /* If current character of IT is not ASCII, make sure we have the
14261 ASCII face. This will be automatically undone the next time
14262 get_next_display_element returns a multibyte character. Note
14263 that the character will always be single byte in unibyte text. */
14264 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14266 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14269 if (FRAME_WINDOW_P (f
))
14271 /* If the row is empty, add a space with the current face of IT,
14272 so that we know which face to draw. */
14273 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14275 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14276 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14277 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14282 /* Save some values that must not be changed. */
14283 int saved_x
= it
->current_x
;
14284 struct text_pos saved_pos
;
14285 Lisp_Object saved_object
;
14286 enum display_element_type saved_what
= it
->what
;
14287 int saved_face_id
= it
->face_id
;
14289 saved_object
= it
->object
;
14290 saved_pos
= it
->position
;
14292 it
->what
= IT_CHARACTER
;
14293 bzero (&it
->position
, sizeof it
->position
);
14294 it
->object
= make_number (0);
14297 it
->face_id
= face
->id
;
14299 PRODUCE_GLYPHS (it
);
14301 while (it
->current_x
<= it
->last_visible_x
)
14302 PRODUCE_GLYPHS (it
);
14304 /* Don't count these blanks really. It would let us insert a left
14305 truncation glyph below and make us set the cursor on them, maybe. */
14306 it
->current_x
= saved_x
;
14307 it
->object
= saved_object
;
14308 it
->position
= saved_pos
;
14309 it
->what
= saved_what
;
14310 it
->face_id
= saved_face_id
;
14315 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14316 trailing whitespace. */
14319 trailing_whitespace_p (charpos
)
14322 int bytepos
= CHAR_TO_BYTE (charpos
);
14325 while (bytepos
< ZV_BYTE
14326 && (c
= FETCH_CHAR (bytepos
),
14327 c
== ' ' || c
== '\t'))
14330 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14332 if (bytepos
!= PT_BYTE
)
14339 /* Highlight trailing whitespace, if any, in ROW. */
14342 highlight_trailing_whitespace (f
, row
)
14344 struct glyph_row
*row
;
14346 int used
= row
->used
[TEXT_AREA
];
14350 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14351 struct glyph
*glyph
= start
+ used
- 1;
14353 /* Skip over glyphs inserted to display the cursor at the
14354 end of a line, for extending the face of the last glyph
14355 to the end of the line on terminals, and for truncation
14356 and continuation glyphs. */
14357 while (glyph
>= start
14358 && glyph
->type
== CHAR_GLYPH
14359 && INTEGERP (glyph
->object
))
14362 /* If last glyph is a space or stretch, and it's trailing
14363 whitespace, set the face of all trailing whitespace glyphs in
14364 IT->glyph_row to `trailing-whitespace'. */
14366 && BUFFERP (glyph
->object
)
14367 && (glyph
->type
== STRETCH_GLYPH
14368 || (glyph
->type
== CHAR_GLYPH
14369 && glyph
->u
.ch
== ' '))
14370 && trailing_whitespace_p (glyph
->charpos
))
14372 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14374 while (glyph
>= start
14375 && BUFFERP (glyph
->object
)
14376 && (glyph
->type
== STRETCH_GLYPH
14377 || (glyph
->type
== CHAR_GLYPH
14378 && glyph
->u
.ch
== ' ')))
14379 (glyph
--)->face_id
= face_id
;
14385 /* Value is non-zero if glyph row ROW in window W should be
14386 used to hold the cursor. */
14389 cursor_row_p (w
, row
)
14391 struct glyph_row
*row
;
14393 int cursor_row_p
= 1;
14395 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14397 /* If the row ends with a newline from a string, we don't want
14398 the cursor there (if the row is continued it doesn't end in a
14400 if (CHARPOS (row
->end
.string_pos
) >= 0
14401 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14402 cursor_row_p
= row
->continued_p
;
14404 /* If the row ends at ZV, display the cursor at the end of that
14405 row instead of at the start of the row below. */
14406 else if (row
->ends_at_zv_p
)
14412 return cursor_row_p
;
14416 /* Construct the glyph row IT->glyph_row in the desired matrix of
14417 IT->w from text at the current position of IT. See dispextern.h
14418 for an overview of struct it. Value is non-zero if
14419 IT->glyph_row displays text, as opposed to a line displaying ZV
14426 struct glyph_row
*row
= it
->glyph_row
;
14427 int overlay_arrow_bitmap
;
14428 Lisp_Object overlay_arrow_string
;
14430 /* We always start displaying at hpos zero even if hscrolled. */
14431 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14433 /* We must not display in a row that's not a text row. */
14434 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14435 < it
->w
->desired_matrix
->nrows
);
14437 /* Is IT->w showing the region? */
14438 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14440 /* Clear the result glyph row and enable it. */
14441 prepare_desired_row (row
);
14443 row
->y
= it
->current_y
;
14444 row
->start
= it
->start
;
14445 row
->continuation_lines_width
= it
->continuation_lines_width
;
14446 row
->displays_text_p
= 1;
14447 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14448 it
->starts_in_middle_of_char_p
= 0;
14450 /* Arrange the overlays nicely for our purposes. Usually, we call
14451 display_line on only one line at a time, in which case this
14452 can't really hurt too much, or we call it on lines which appear
14453 one after another in the buffer, in which case all calls to
14454 recenter_overlay_lists but the first will be pretty cheap. */
14455 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14457 /* Move over display elements that are not visible because we are
14458 hscrolled. This may stop at an x-position < IT->first_visible_x
14459 if the first glyph is partially visible or if we hit a line end. */
14460 if (it
->current_x
< it
->first_visible_x
)
14461 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14462 MOVE_TO_POS
| MOVE_TO_X
);
14464 /* Get the initial row height. This is either the height of the
14465 text hscrolled, if there is any, or zero. */
14466 row
->ascent
= it
->max_ascent
;
14467 row
->height
= it
->max_ascent
+ it
->max_descent
;
14468 row
->phys_ascent
= it
->max_phys_ascent
;
14469 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14471 /* Loop generating characters. The loop is left with IT on the next
14472 character to display. */
14475 int n_glyphs_before
, hpos_before
, x_before
;
14477 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14479 /* Retrieve the next thing to display. Value is zero if end of
14481 if (!get_next_display_element (it
))
14483 /* Maybe add a space at the end of this line that is used to
14484 display the cursor there under X. Set the charpos of the
14485 first glyph of blank lines not corresponding to any text
14487 #ifdef HAVE_WINDOW_SYSTEM
14488 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14489 row
->exact_window_width_line_p
= 1;
14491 #endif /* HAVE_WINDOW_SYSTEM */
14492 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14493 || row
->used
[TEXT_AREA
] == 0)
14495 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14496 row
->displays_text_p
= 0;
14498 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14499 && (!MINI_WINDOW_P (it
->w
)
14500 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14501 row
->indicate_empty_line_p
= 1;
14504 it
->continuation_lines_width
= 0;
14505 row
->ends_at_zv_p
= 1;
14509 /* Now, get the metrics of what we want to display. This also
14510 generates glyphs in `row' (which is IT->glyph_row). */
14511 n_glyphs_before
= row
->used
[TEXT_AREA
];
14514 /* Remember the line height so far in case the next element doesn't
14515 fit on the line. */
14516 if (!it
->truncate_lines_p
)
14518 ascent
= it
->max_ascent
;
14519 descent
= it
->max_descent
;
14520 phys_ascent
= it
->max_phys_ascent
;
14521 phys_descent
= it
->max_phys_descent
;
14524 PRODUCE_GLYPHS (it
);
14526 /* If this display element was in marginal areas, continue with
14528 if (it
->area
!= TEXT_AREA
)
14530 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14531 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14532 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14533 row
->phys_height
= max (row
->phys_height
,
14534 it
->max_phys_ascent
+ it
->max_phys_descent
);
14535 set_iterator_to_next (it
, 1);
14539 /* Does the display element fit on the line? If we truncate
14540 lines, we should draw past the right edge of the window. If
14541 we don't truncate, we want to stop so that we can display the
14542 continuation glyph before the right margin. If lines are
14543 continued, there are two possible strategies for characters
14544 resulting in more than 1 glyph (e.g. tabs): Display as many
14545 glyphs as possible in this line and leave the rest for the
14546 continuation line, or display the whole element in the next
14547 line. Original redisplay did the former, so we do it also. */
14548 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14549 hpos_before
= it
->hpos
;
14552 if (/* Not a newline. */
14554 /* Glyphs produced fit entirely in the line. */
14555 && it
->current_x
< it
->last_visible_x
)
14557 it
->hpos
+= nglyphs
;
14558 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14559 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14560 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14561 row
->phys_height
= max (row
->phys_height
,
14562 it
->max_phys_ascent
+ it
->max_phys_descent
);
14563 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14564 row
->x
= x
- it
->first_visible_x
;
14569 struct glyph
*glyph
;
14571 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14573 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14574 new_x
= x
+ glyph
->pixel_width
;
14576 if (/* Lines are continued. */
14577 !it
->truncate_lines_p
14578 && (/* Glyph doesn't fit on the line. */
14579 new_x
> it
->last_visible_x
14580 /* Or it fits exactly on a window system frame. */
14581 || (new_x
== it
->last_visible_x
14582 && FRAME_WINDOW_P (it
->f
))))
14584 /* End of a continued line. */
14587 || (new_x
== it
->last_visible_x
14588 && FRAME_WINDOW_P (it
->f
)))
14590 /* Current glyph is the only one on the line or
14591 fits exactly on the line. We must continue
14592 the line because we can't draw the cursor
14593 after the glyph. */
14594 row
->continued_p
= 1;
14595 it
->current_x
= new_x
;
14596 it
->continuation_lines_width
+= new_x
;
14598 if (i
== nglyphs
- 1)
14600 set_iterator_to_next (it
, 1);
14601 #ifdef HAVE_WINDOW_SYSTEM
14602 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14604 if (!get_next_display_element (it
))
14606 row
->exact_window_width_line_p
= 1;
14607 it
->continuation_lines_width
= 0;
14608 row
->continued_p
= 0;
14609 row
->ends_at_zv_p
= 1;
14611 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14613 row
->continued_p
= 0;
14614 row
->exact_window_width_line_p
= 1;
14617 #endif /* HAVE_WINDOW_SYSTEM */
14620 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14621 && !FRAME_WINDOW_P (it
->f
))
14623 /* A padding glyph that doesn't fit on this line.
14624 This means the whole character doesn't fit
14626 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14628 /* Fill the rest of the row with continuation
14629 glyphs like in 20.x. */
14630 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14631 < row
->glyphs
[1 + TEXT_AREA
])
14632 produce_special_glyphs (it
, IT_CONTINUATION
);
14634 row
->continued_p
= 1;
14635 it
->current_x
= x_before
;
14636 it
->continuation_lines_width
+= x_before
;
14638 /* Restore the height to what it was before the
14639 element not fitting on the line. */
14640 it
->max_ascent
= ascent
;
14641 it
->max_descent
= descent
;
14642 it
->max_phys_ascent
= phys_ascent
;
14643 it
->max_phys_descent
= phys_descent
;
14645 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14647 /* A TAB that extends past the right edge of the
14648 window. This produces a single glyph on
14649 window system frames. We leave the glyph in
14650 this row and let it fill the row, but don't
14651 consume the TAB. */
14652 it
->continuation_lines_width
+= it
->last_visible_x
;
14653 row
->ends_in_middle_of_char_p
= 1;
14654 row
->continued_p
= 1;
14655 glyph
->pixel_width
= it
->last_visible_x
- x
;
14656 it
->starts_in_middle_of_char_p
= 1;
14660 /* Something other than a TAB that draws past
14661 the right edge of the window. Restore
14662 positions to values before the element. */
14663 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14665 /* Display continuation glyphs. */
14666 if (!FRAME_WINDOW_P (it
->f
))
14667 produce_special_glyphs (it
, IT_CONTINUATION
);
14668 row
->continued_p
= 1;
14670 it
->continuation_lines_width
+= x
;
14672 if (nglyphs
> 1 && i
> 0)
14674 row
->ends_in_middle_of_char_p
= 1;
14675 it
->starts_in_middle_of_char_p
= 1;
14678 /* Restore the height to what it was before the
14679 element not fitting on the line. */
14680 it
->max_ascent
= ascent
;
14681 it
->max_descent
= descent
;
14682 it
->max_phys_ascent
= phys_ascent
;
14683 it
->max_phys_descent
= phys_descent
;
14688 else if (new_x
> it
->first_visible_x
)
14690 /* Increment number of glyphs actually displayed. */
14693 if (x
< it
->first_visible_x
)
14694 /* Glyph is partially visible, i.e. row starts at
14695 negative X position. */
14696 row
->x
= x
- it
->first_visible_x
;
14700 /* Glyph is completely off the left margin of the
14701 window. This should not happen because of the
14702 move_it_in_display_line at the start of this
14703 function, unless the text display area of the
14704 window is empty. */
14705 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14709 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14710 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14711 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14712 row
->phys_height
= max (row
->phys_height
,
14713 it
->max_phys_ascent
+ it
->max_phys_descent
);
14715 /* End of this display line if row is continued. */
14716 if (row
->continued_p
|| row
->ends_at_zv_p
)
14721 /* Is this a line end? If yes, we're also done, after making
14722 sure that a non-default face is extended up to the right
14723 margin of the window. */
14724 if (ITERATOR_AT_END_OF_LINE_P (it
))
14726 int used_before
= row
->used
[TEXT_AREA
];
14728 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14730 #ifdef HAVE_WINDOW_SYSTEM
14731 /* Add a space at the end of the line that is used to
14732 display the cursor there. */
14733 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14734 append_space_for_newline (it
, 0);
14735 #endif /* HAVE_WINDOW_SYSTEM */
14737 /* Extend the face to the end of the line. */
14738 extend_face_to_end_of_line (it
);
14740 /* Make sure we have the position. */
14741 if (used_before
== 0)
14742 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14744 /* Consume the line end. This skips over invisible lines. */
14745 set_iterator_to_next (it
, 1);
14746 it
->continuation_lines_width
= 0;
14750 /* Proceed with next display element. Note that this skips
14751 over lines invisible because of selective display. */
14752 set_iterator_to_next (it
, 1);
14754 /* If we truncate lines, we are done when the last displayed
14755 glyphs reach past the right margin of the window. */
14756 if (it
->truncate_lines_p
14757 && (FRAME_WINDOW_P (it
->f
)
14758 ? (it
->current_x
>= it
->last_visible_x
)
14759 : (it
->current_x
> it
->last_visible_x
)))
14761 /* Maybe add truncation glyphs. */
14762 if (!FRAME_WINDOW_P (it
->f
))
14766 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14767 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14770 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14772 row
->used
[TEXT_AREA
] = i
;
14773 produce_special_glyphs (it
, IT_TRUNCATION
);
14776 #ifdef HAVE_WINDOW_SYSTEM
14779 /* Don't truncate if we can overflow newline into fringe. */
14780 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14782 if (!get_next_display_element (it
))
14784 #ifdef HAVE_WINDOW_SYSTEM
14785 it
->continuation_lines_width
= 0;
14786 row
->ends_at_zv_p
= 1;
14787 row
->exact_window_width_line_p
= 1;
14789 #endif /* HAVE_WINDOW_SYSTEM */
14791 if (ITERATOR_AT_END_OF_LINE_P (it
))
14793 row
->exact_window_width_line_p
= 1;
14794 goto at_end_of_line
;
14798 #endif /* HAVE_WINDOW_SYSTEM */
14800 row
->truncated_on_right_p
= 1;
14801 it
->continuation_lines_width
= 0;
14802 reseat_at_next_visible_line_start (it
, 0);
14803 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14804 it
->hpos
= hpos_before
;
14805 it
->current_x
= x_before
;
14810 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14811 at the left window margin. */
14812 if (it
->first_visible_x
14813 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14815 if (!FRAME_WINDOW_P (it
->f
))
14816 insert_left_trunc_glyphs (it
);
14817 row
->truncated_on_left_p
= 1;
14820 /* If the start of this line is the overlay arrow-position, then
14821 mark this glyph row as the one containing the overlay arrow.
14822 This is clearly a mess with variable size fonts. It would be
14823 better to let it be displayed like cursors under X. */
14824 if (! overlay_arrow_seen
14825 && (overlay_arrow_string
14826 = overlay_arrow_at_row (it
->f
, row
, &overlay_arrow_bitmap
),
14827 !NILP (overlay_arrow_string
)))
14829 /* Overlay arrow in window redisplay is a fringe bitmap. */
14830 if (!FRAME_WINDOW_P (it
->f
))
14832 struct glyph_row
*arrow_row
14833 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
14834 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14835 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14836 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14837 struct glyph
*p2
, *end
;
14839 /* Copy the arrow glyphs. */
14840 while (glyph
< arrow_end
)
14843 /* Throw away padding glyphs. */
14845 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14846 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14852 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14856 overlay_arrow_seen
= 1;
14857 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
14858 row
->overlay_arrow_p
= 1;
14861 /* Compute pixel dimensions of this line. */
14862 compute_line_metrics (it
);
14864 /* Remember the position at which this line ends. */
14865 row
->end
= it
->current
;
14867 /* Save fringe bitmaps in this row. */
14868 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
14869 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
14870 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
14871 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
14873 it
->left_user_fringe_bitmap
= 0;
14874 it
->left_user_fringe_face_id
= 0;
14875 it
->right_user_fringe_bitmap
= 0;
14876 it
->right_user_fringe_face_id
= 0;
14878 /* Maybe set the cursor. */
14879 if (it
->w
->cursor
.vpos
< 0
14880 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14881 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14882 && cursor_row_p (it
->w
, row
))
14883 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14885 /* Highlight trailing whitespace. */
14886 if (!NILP (Vshow_trailing_whitespace
))
14887 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14889 /* Prepare for the next line. This line starts horizontally at (X
14890 HPOS) = (0 0). Vertical positions are incremented. As a
14891 convenience for the caller, IT->glyph_row is set to the next
14893 it
->current_x
= it
->hpos
= 0;
14894 it
->current_y
+= row
->height
;
14897 it
->start
= it
->current
;
14898 return row
->displays_text_p
;
14903 /***********************************************************************
14905 ***********************************************************************/
14907 /* Redisplay the menu bar in the frame for window W.
14909 The menu bar of X frames that don't have X toolkit support is
14910 displayed in a special window W->frame->menu_bar_window.
14912 The menu bar of terminal frames is treated specially as far as
14913 glyph matrices are concerned. Menu bar lines are not part of
14914 windows, so the update is done directly on the frame matrix rows
14915 for the menu bar. */
14918 display_menu_bar (w
)
14921 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14926 /* Don't do all this for graphical frames. */
14928 if (!NILP (Vwindow_system
))
14931 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14936 if (FRAME_MAC_P (f
))
14940 #ifdef USE_X_TOOLKIT
14941 xassert (!FRAME_WINDOW_P (f
));
14942 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14943 it
.first_visible_x
= 0;
14944 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14945 #else /* not USE_X_TOOLKIT */
14946 if (FRAME_WINDOW_P (f
))
14948 /* Menu bar lines are displayed in the desired matrix of the
14949 dummy window menu_bar_window. */
14950 struct window
*menu_w
;
14951 xassert (WINDOWP (f
->menu_bar_window
));
14952 menu_w
= XWINDOW (f
->menu_bar_window
);
14953 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14955 it
.first_visible_x
= 0;
14956 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14960 /* This is a TTY frame, i.e. character hpos/vpos are used as
14962 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14964 it
.first_visible_x
= 0;
14965 it
.last_visible_x
= FRAME_COLS (f
);
14967 #endif /* not USE_X_TOOLKIT */
14969 if (! mode_line_inverse_video
)
14970 /* Force the menu-bar to be displayed in the default face. */
14971 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14973 /* Clear all rows of the menu bar. */
14974 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14976 struct glyph_row
*row
= it
.glyph_row
+ i
;
14977 clear_glyph_row (row
);
14978 row
->enabled_p
= 1;
14979 row
->full_width_p
= 1;
14982 /* Display all items of the menu bar. */
14983 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14984 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14986 Lisp_Object string
;
14988 /* Stop at nil string. */
14989 string
= AREF (items
, i
+ 1);
14993 /* Remember where item was displayed. */
14994 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14996 /* Display the item, pad with one space. */
14997 if (it
.current_x
< it
.last_visible_x
)
14998 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14999 SCHARS (string
) + 1, 0, 0, -1);
15002 /* Fill out the line with spaces. */
15003 if (it
.current_x
< it
.last_visible_x
)
15004 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15006 /* Compute the total height of the lines. */
15007 compute_line_metrics (&it
);
15012 /***********************************************************************
15014 ***********************************************************************/
15016 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15017 FORCE is non-zero, redisplay mode lines unconditionally.
15018 Otherwise, redisplay only mode lines that are garbaged. Value is
15019 the number of windows whose mode lines were redisplayed. */
15022 redisplay_mode_lines (window
, force
)
15023 Lisp_Object window
;
15028 while (!NILP (window
))
15030 struct window
*w
= XWINDOW (window
);
15032 if (WINDOWP (w
->hchild
))
15033 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15034 else if (WINDOWP (w
->vchild
))
15035 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15037 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15038 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15040 struct text_pos lpoint
;
15041 struct buffer
*old
= current_buffer
;
15043 /* Set the window's buffer for the mode line display. */
15044 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15045 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15047 /* Point refers normally to the selected window. For any
15048 other window, set up appropriate value. */
15049 if (!EQ (window
, selected_window
))
15051 struct text_pos pt
;
15053 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15054 if (CHARPOS (pt
) < BEGV
)
15055 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15056 else if (CHARPOS (pt
) > (ZV
- 1))
15057 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15059 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15062 /* Display mode lines. */
15063 clear_glyph_matrix (w
->desired_matrix
);
15064 if (display_mode_lines (w
))
15067 w
->must_be_updated_p
= 1;
15070 /* Restore old settings. */
15071 set_buffer_internal_1 (old
);
15072 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15082 /* Display the mode and/or top line of window W. Value is the number
15083 of mode lines displayed. */
15086 display_mode_lines (w
)
15089 Lisp_Object old_selected_window
, old_selected_frame
;
15092 old_selected_frame
= selected_frame
;
15093 selected_frame
= w
->frame
;
15094 old_selected_window
= selected_window
;
15095 XSETWINDOW (selected_window
, w
);
15097 /* These will be set while the mode line specs are processed. */
15098 line_number_displayed
= 0;
15099 w
->column_number_displayed
= Qnil
;
15101 if (WINDOW_WANTS_MODELINE_P (w
))
15103 struct window
*sel_w
= XWINDOW (old_selected_window
);
15105 /* Select mode line face based on the real selected window. */
15106 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15107 current_buffer
->mode_line_format
);
15111 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15113 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15114 current_buffer
->header_line_format
);
15118 selected_frame
= old_selected_frame
;
15119 selected_window
= old_selected_window
;
15124 /* Display mode or top line of window W. FACE_ID specifies which line
15125 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15126 FORMAT is the mode line format to display. Value is the pixel
15127 height of the mode line displayed. */
15130 display_mode_line (w
, face_id
, format
)
15132 enum face_id face_id
;
15133 Lisp_Object format
;
15138 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15139 prepare_desired_row (it
.glyph_row
);
15141 it
.glyph_row
->mode_line_p
= 1;
15143 if (! mode_line_inverse_video
)
15144 /* Force the mode-line to be displayed in the default face. */
15145 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15147 /* Temporarily make frame's keyboard the current kboard so that
15148 kboard-local variables in the mode_line_format will get the right
15150 push_frame_kboard (it
.f
);
15151 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15152 pop_frame_kboard ();
15154 /* Fill up with spaces. */
15155 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15157 compute_line_metrics (&it
);
15158 it
.glyph_row
->full_width_p
= 1;
15159 it
.glyph_row
->continued_p
= 0;
15160 it
.glyph_row
->truncated_on_left_p
= 0;
15161 it
.glyph_row
->truncated_on_right_p
= 0;
15163 /* Make a 3D mode-line have a shadow at its right end. */
15164 face
= FACE_FROM_ID (it
.f
, face_id
);
15165 extend_face_to_end_of_line (&it
);
15166 if (face
->box
!= FACE_NO_BOX
)
15168 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15169 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15170 last
->right_box_line_p
= 1;
15173 return it
.glyph_row
->height
;
15176 /* Alist that caches the results of :propertize.
15177 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15178 Lisp_Object mode_line_proptrans_alist
;
15180 /* List of strings making up the mode-line. */
15181 Lisp_Object mode_line_string_list
;
15183 /* Base face property when building propertized mode line string. */
15184 static Lisp_Object mode_line_string_face
;
15185 static Lisp_Object mode_line_string_face_prop
;
15188 /* Contribute ELT to the mode line for window IT->w. How it
15189 translates into text depends on its data type.
15191 IT describes the display environment in which we display, as usual.
15193 DEPTH is the depth in recursion. It is used to prevent
15194 infinite recursion here.
15196 FIELD_WIDTH is the number of characters the display of ELT should
15197 occupy in the mode line, and PRECISION is the maximum number of
15198 characters to display from ELT's representation. See
15199 display_string for details.
15201 Returns the hpos of the end of the text generated by ELT.
15203 PROPS is a property list to add to any string we encounter.
15205 If RISKY is nonzero, remove (disregard) any properties in any string
15206 we encounter, and ignore :eval and :propertize.
15208 If the global variable `frame_title_ptr' is non-NULL, then the output
15209 is passed to `store_frame_title' instead of `display_string'. */
15212 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15215 int field_width
, precision
;
15216 Lisp_Object elt
, props
;
15219 int n
= 0, field
, prec
;
15224 elt
= build_string ("*too-deep*");
15228 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15232 /* A string: output it and check for %-constructs within it. */
15234 const unsigned char *this, *lisp_string
;
15236 if (!NILP (props
) || risky
)
15238 Lisp_Object oprops
, aelt
;
15239 oprops
= Ftext_properties_at (make_number (0), elt
);
15241 if (NILP (Fequal (props
, oprops
)) || risky
)
15243 /* If the starting string has properties,
15244 merge the specified ones onto the existing ones. */
15245 if (! NILP (oprops
) && !risky
)
15249 oprops
= Fcopy_sequence (oprops
);
15251 while (CONSP (tem
))
15253 oprops
= Fplist_put (oprops
, XCAR (tem
),
15254 XCAR (XCDR (tem
)));
15255 tem
= XCDR (XCDR (tem
));
15260 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15261 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15263 mode_line_proptrans_alist
15264 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15271 elt
= Fcopy_sequence (elt
);
15272 Fset_text_properties (make_number (0), Flength (elt
),
15274 /* Add this item to mode_line_proptrans_alist. */
15275 mode_line_proptrans_alist
15276 = Fcons (Fcons (elt
, props
),
15277 mode_line_proptrans_alist
);
15278 /* Truncate mode_line_proptrans_alist
15279 to at most 50 elements. */
15280 tem
= Fnthcdr (make_number (50),
15281 mode_line_proptrans_alist
);
15283 XSETCDR (tem
, Qnil
);
15288 this = SDATA (elt
);
15289 lisp_string
= this;
15293 prec
= precision
- n
;
15294 if (frame_title_ptr
)
15295 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15296 else if (!NILP (mode_line_string_list
))
15297 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15299 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15300 0, prec
, 0, STRING_MULTIBYTE (elt
));
15305 while ((precision
<= 0 || n
< precision
)
15307 && (frame_title_ptr
15308 || !NILP (mode_line_string_list
)
15309 || it
->current_x
< it
->last_visible_x
))
15311 const unsigned char *last
= this;
15313 /* Advance to end of string or next format specifier. */
15314 while ((c
= *this++) != '\0' && c
!= '%')
15317 if (this - 1 != last
)
15319 /* Output to end of string or up to '%'. Field width
15320 is length of string. Don't output more than
15321 PRECISION allows us. */
15324 prec
= chars_in_text (last
, this - last
);
15325 if (precision
> 0 && prec
> precision
- n
)
15326 prec
= precision
- n
;
15328 if (frame_title_ptr
)
15329 n
+= store_frame_title (last
, 0, prec
);
15330 else if (!NILP (mode_line_string_list
))
15332 int bytepos
= last
- lisp_string
;
15333 int charpos
= string_byte_to_char (elt
, bytepos
);
15334 n
+= store_mode_line_string (NULL
,
15335 Fsubstring (elt
, make_number (charpos
),
15336 make_number (charpos
+ prec
)),
15341 int bytepos
= last
- lisp_string
;
15342 int charpos
= string_byte_to_char (elt
, bytepos
);
15343 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15345 STRING_MULTIBYTE (elt
));
15348 else /* c == '%' */
15350 const unsigned char *percent_position
= this;
15352 /* Get the specified minimum width. Zero means
15355 while ((c
= *this++) >= '0' && c
<= '9')
15356 field
= field
* 10 + c
- '0';
15358 /* Don't pad beyond the total padding allowed. */
15359 if (field_width
- n
> 0 && field
> field_width
- n
)
15360 field
= field_width
- n
;
15362 /* Note that either PRECISION <= 0 or N < PRECISION. */
15363 prec
= precision
- n
;
15366 n
+= display_mode_element (it
, depth
, field
, prec
,
15367 Vglobal_mode_string
, props
,
15372 int bytepos
, charpos
;
15373 unsigned char *spec
;
15375 bytepos
= percent_position
- lisp_string
;
15376 charpos
= (STRING_MULTIBYTE (elt
)
15377 ? string_byte_to_char (elt
, bytepos
)
15381 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15383 if (frame_title_ptr
)
15384 n
+= store_frame_title (spec
, field
, prec
);
15385 else if (!NILP (mode_line_string_list
))
15387 int len
= strlen (spec
);
15388 Lisp_Object tem
= make_string (spec
, len
);
15389 props
= Ftext_properties_at (make_number (charpos
), elt
);
15390 /* Should only keep face property in props */
15391 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15395 int nglyphs_before
, nwritten
;
15397 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15398 nwritten
= display_string (spec
, Qnil
, elt
,
15403 /* Assign to the glyphs written above the
15404 string where the `%x' came from, position
15408 struct glyph
*glyph
15409 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15413 for (i
= 0; i
< nwritten
; ++i
)
15415 glyph
[i
].object
= elt
;
15416 glyph
[i
].charpos
= charpos
;
15431 /* A symbol: process the value of the symbol recursively
15432 as if it appeared here directly. Avoid error if symbol void.
15433 Special case: if value of symbol is a string, output the string
15436 register Lisp_Object tem
;
15438 /* If the variable is not marked as risky to set
15439 then its contents are risky to use. */
15440 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15443 tem
= Fboundp (elt
);
15446 tem
= Fsymbol_value (elt
);
15447 /* If value is a string, output that string literally:
15448 don't check for % within it. */
15452 if (!EQ (tem
, elt
))
15454 /* Give up right away for nil or t. */
15464 register Lisp_Object car
, tem
;
15466 /* A cons cell: five distinct cases.
15467 If first element is :eval or :propertize, do something special.
15468 If first element is a string or a cons, process all the elements
15469 and effectively concatenate them.
15470 If first element is a negative number, truncate displaying cdr to
15471 at most that many characters. If positive, pad (with spaces)
15472 to at least that many characters.
15473 If first element is a symbol, process the cadr or caddr recursively
15474 according to whether the symbol's value is non-nil or nil. */
15476 if (EQ (car
, QCeval
))
15478 /* An element of the form (:eval FORM) means evaluate FORM
15479 and use the result as mode line elements. */
15484 if (CONSP (XCDR (elt
)))
15487 spec
= safe_eval (XCAR (XCDR (elt
)));
15488 n
+= display_mode_element (it
, depth
, field_width
- n
,
15489 precision
- n
, spec
, props
,
15493 else if (EQ (car
, QCpropertize
))
15495 /* An element of the form (:propertize ELT PROPS...)
15496 means display ELT but applying properties PROPS. */
15501 if (CONSP (XCDR (elt
)))
15502 n
+= display_mode_element (it
, depth
, field_width
- n
,
15503 precision
- n
, XCAR (XCDR (elt
)),
15504 XCDR (XCDR (elt
)), risky
);
15506 else if (SYMBOLP (car
))
15508 tem
= Fboundp (car
);
15512 /* elt is now the cdr, and we know it is a cons cell.
15513 Use its car if CAR has a non-nil value. */
15516 tem
= Fsymbol_value (car
);
15523 /* Symbol's value is nil (or symbol is unbound)
15524 Get the cddr of the original list
15525 and if possible find the caddr and use that. */
15529 else if (!CONSP (elt
))
15534 else if (INTEGERP (car
))
15536 register int lim
= XINT (car
);
15540 /* Negative int means reduce maximum width. */
15541 if (precision
<= 0)
15544 precision
= min (precision
, -lim
);
15548 /* Padding specified. Don't let it be more than
15549 current maximum. */
15551 lim
= min (precision
, lim
);
15553 /* If that's more padding than already wanted, queue it.
15554 But don't reduce padding already specified even if
15555 that is beyond the current truncation point. */
15556 field_width
= max (lim
, field_width
);
15560 else if (STRINGP (car
) || CONSP (car
))
15562 register int limit
= 50;
15563 /* Limit is to protect against circular lists. */
15566 && (precision
<= 0 || n
< precision
))
15568 n
+= display_mode_element (it
, depth
, field_width
- n
,
15569 precision
- n
, XCAR (elt
),
15579 elt
= build_string ("*invalid*");
15583 /* Pad to FIELD_WIDTH. */
15584 if (field_width
> 0 && n
< field_width
)
15586 if (frame_title_ptr
)
15587 n
+= store_frame_title ("", field_width
- n
, 0);
15588 else if (!NILP (mode_line_string_list
))
15589 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15591 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15598 /* Store a mode-line string element in mode_line_string_list.
15600 If STRING is non-null, display that C string. Otherwise, the Lisp
15601 string LISP_STRING is displayed.
15603 FIELD_WIDTH is the minimum number of output glyphs to produce.
15604 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15605 with spaces. FIELD_WIDTH <= 0 means don't pad.
15607 PRECISION is the maximum number of characters to output from
15608 STRING. PRECISION <= 0 means don't truncate the string.
15610 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15611 properties to the string.
15613 PROPS are the properties to add to the string.
15614 The mode_line_string_face face property is always added to the string.
15617 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15619 Lisp_Object lisp_string
;
15628 if (string
!= NULL
)
15630 len
= strlen (string
);
15631 if (precision
> 0 && len
> precision
)
15633 lisp_string
= make_string (string
, len
);
15635 props
= mode_line_string_face_prop
;
15636 else if (!NILP (mode_line_string_face
))
15638 Lisp_Object face
= Fplist_get (props
, Qface
);
15639 props
= Fcopy_sequence (props
);
15641 face
= mode_line_string_face
;
15643 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15644 props
= Fplist_put (props
, Qface
, face
);
15646 Fadd_text_properties (make_number (0), make_number (len
),
15647 props
, lisp_string
);
15651 len
= XFASTINT (Flength (lisp_string
));
15652 if (precision
> 0 && len
> precision
)
15655 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15658 if (!NILP (mode_line_string_face
))
15662 props
= Ftext_properties_at (make_number (0), lisp_string
);
15663 face
= Fplist_get (props
, Qface
);
15665 face
= mode_line_string_face
;
15667 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15668 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15670 lisp_string
= Fcopy_sequence (lisp_string
);
15673 Fadd_text_properties (make_number (0), make_number (len
),
15674 props
, lisp_string
);
15679 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15683 if (field_width
> len
)
15685 field_width
-= len
;
15686 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15688 Fadd_text_properties (make_number (0), make_number (field_width
),
15689 props
, lisp_string
);
15690 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15698 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15700 doc
: /* Return the mode-line of selected window as a string.
15701 First optional arg FORMAT specifies a different format string (see
15702 `mode-line-format' for details) to use. If FORMAT is t, return
15703 the buffer's header-line. Second optional arg WINDOW specifies a
15704 different window to use as the context for the formatting.
15705 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15706 (format
, window
, no_props
)
15707 Lisp_Object format
, window
, no_props
;
15712 struct buffer
*old_buffer
= NULL
;
15713 enum face_id face_id
= DEFAULT_FACE_ID
;
15716 window
= selected_window
;
15717 CHECK_WINDOW (window
);
15718 w
= XWINDOW (window
);
15719 CHECK_BUFFER (w
->buffer
);
15721 if (XBUFFER (w
->buffer
) != current_buffer
)
15723 old_buffer
= current_buffer
;
15724 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15727 if (NILP (format
) || EQ (format
, Qt
))
15729 face_id
= NILP (format
)
15730 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15731 HEADER_LINE_FACE_ID
;
15732 format
= NILP (format
)
15733 ? current_buffer
->mode_line_format
15734 : current_buffer
->header_line_format
;
15737 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15739 if (NILP (no_props
))
15741 mode_line_string_face
=
15742 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15743 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15744 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15746 mode_line_string_face_prop
=
15747 NILP (mode_line_string_face
) ? Qnil
:
15748 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15750 /* We need a dummy last element in mode_line_string_list to
15751 indicate we are building the propertized mode-line string.
15752 Using mode_line_string_face_prop here GC protects it. */
15753 mode_line_string_list
=
15754 Fcons (mode_line_string_face_prop
, Qnil
);
15755 frame_title_ptr
= NULL
;
15759 mode_line_string_face_prop
= Qnil
;
15760 mode_line_string_list
= Qnil
;
15761 frame_title_ptr
= frame_title_buf
;
15764 push_frame_kboard (it
.f
);
15765 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15766 pop_frame_kboard ();
15769 set_buffer_internal_1 (old_buffer
);
15771 if (NILP (no_props
))
15774 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15775 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15776 make_string ("", 0));
15777 mode_line_string_face_prop
= Qnil
;
15778 mode_line_string_list
= Qnil
;
15782 len
= frame_title_ptr
- frame_title_buf
;
15783 if (len
> 0 && frame_title_ptr
[-1] == '-')
15785 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15786 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15788 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15789 if (len
> frame_title_ptr
- frame_title_buf
)
15790 len
= frame_title_ptr
- frame_title_buf
;
15793 frame_title_ptr
= NULL
;
15794 return make_string (frame_title_buf
, len
);
15797 /* Write a null-terminated, right justified decimal representation of
15798 the positive integer D to BUF using a minimal field width WIDTH. */
15801 pint2str (buf
, width
, d
)
15802 register char *buf
;
15803 register int width
;
15806 register char *p
= buf
;
15814 *p
++ = d
% 10 + '0';
15819 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15830 /* Write a null-terminated, right justified decimal and "human
15831 readable" representation of the nonnegative integer D to BUF using
15832 a minimal field width WIDTH. D should be smaller than 999.5e24. */
15834 static const char power_letter
[] =
15848 pint2hrstr (buf
, width
, d
)
15853 /* We aim to represent the nonnegative integer D as
15854 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
15857 /* -1 means: do not use TENTHS. */
15861 /* Length of QUOTIENT.TENTHS as a string. */
15867 if (1000 <= quotient
)
15869 /* Scale to the appropriate EXPONENT. */
15872 remainder
= quotient
% 1000;
15876 while (1000 <= quotient
);
15878 /* Round to nearest and decide whether to use TENTHS or not. */
15881 tenths
= remainder
/ 100;
15882 if (50 <= remainder
% 100)
15888 if (quotient
== 10)
15895 if (500 <= remainder
)
15896 if (quotient
< 999)
15906 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
15907 if (tenths
== -1 && quotient
<= 99)
15914 p
= psuffix
= buf
+ max (width
, length
);
15916 /* Print EXPONENT. */
15918 *psuffix
++ = power_letter
[exponent
];
15921 /* Print TENTHS. */
15924 *--p
= '0' + tenths
;
15928 /* Print QUOTIENT. */
15931 int digit
= quotient
% 10;
15932 *--p
= '0' + digit
;
15934 while ((quotient
/= 10) != 0);
15936 /* Print leading spaces. */
15941 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15942 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15943 type of CODING_SYSTEM. Return updated pointer into BUF. */
15945 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15948 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15949 Lisp_Object coding_system
;
15950 register char *buf
;
15954 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15955 const unsigned char *eol_str
;
15957 /* The EOL conversion we are using. */
15958 Lisp_Object eoltype
;
15960 val
= Fget (coding_system
, Qcoding_system
);
15963 if (!VECTORP (val
)) /* Not yet decided. */
15968 eoltype
= eol_mnemonic_undecided
;
15969 /* Don't mention EOL conversion if it isn't decided. */
15973 Lisp_Object eolvalue
;
15975 eolvalue
= Fget (coding_system
, Qeol_type
);
15978 *buf
++ = XFASTINT (AREF (val
, 1));
15982 /* The EOL conversion that is normal on this system. */
15984 if (NILP (eolvalue
)) /* Not yet decided. */
15985 eoltype
= eol_mnemonic_undecided
;
15986 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15987 eoltype
= eol_mnemonic_undecided
;
15988 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15989 eoltype
= (XFASTINT (eolvalue
) == 0
15990 ? eol_mnemonic_unix
15991 : (XFASTINT (eolvalue
) == 1
15992 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
15998 /* Mention the EOL conversion if it is not the usual one. */
15999 if (STRINGP (eoltype
))
16001 eol_str
= SDATA (eoltype
);
16002 eol_str_len
= SBYTES (eoltype
);
16004 else if (INTEGERP (eoltype
)
16005 && CHAR_VALID_P (XINT (eoltype
), 0))
16007 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16008 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16013 eol_str
= invalid_eol_type
;
16014 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16016 bcopy (eol_str
, buf
, eol_str_len
);
16017 buf
+= eol_str_len
;
16023 /* Return a string for the output of a mode line %-spec for window W,
16024 generated by character C. PRECISION >= 0 means don't return a
16025 string longer than that value. FIELD_WIDTH > 0 means pad the
16026 string returned with spaces to that value. Return 1 in *MULTIBYTE
16027 if the result is multibyte text. */
16029 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16032 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16035 int field_width
, precision
;
16039 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16040 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16041 struct buffer
*b
= XBUFFER (w
->buffer
);
16049 if (!NILP (b
->read_only
))
16051 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16056 /* This differs from %* only for a modified read-only buffer. */
16057 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16059 if (!NILP (b
->read_only
))
16064 /* This differs from %* in ignoring read-only-ness. */
16065 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16077 if (command_loop_level
> 5)
16079 p
= decode_mode_spec_buf
;
16080 for (i
= 0; i
< command_loop_level
; i
++)
16083 return decode_mode_spec_buf
;
16091 if (command_loop_level
> 5)
16093 p
= decode_mode_spec_buf
;
16094 for (i
= 0; i
< command_loop_level
; i
++)
16097 return decode_mode_spec_buf
;
16104 /* Let lots_of_dashes be a string of infinite length. */
16105 if (!NILP (mode_line_string_list
))
16107 if (field_width
<= 0
16108 || field_width
> sizeof (lots_of_dashes
))
16110 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16111 decode_mode_spec_buf
[i
] = '-';
16112 decode_mode_spec_buf
[i
] = '\0';
16113 return decode_mode_spec_buf
;
16116 return lots_of_dashes
;
16125 int col
= (int) current_column (); /* iftc */
16126 w
->column_number_displayed
= make_number (col
);
16127 pint2str (decode_mode_spec_buf
, field_width
, col
);
16128 return decode_mode_spec_buf
;
16132 /* %F displays the frame name. */
16133 if (!NILP (f
->title
))
16134 return (char *) SDATA (f
->title
);
16135 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16136 return (char *) SDATA (f
->name
);
16145 int size
= ZV
- BEGV
;
16146 pint2str (decode_mode_spec_buf
, field_width
, size
);
16147 return decode_mode_spec_buf
;
16152 int size
= ZV
- BEGV
;
16153 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16154 return decode_mode_spec_buf
;
16159 int startpos
= XMARKER (w
->start
)->charpos
;
16160 int startpos_byte
= marker_byte_position (w
->start
);
16161 int line
, linepos
, linepos_byte
, topline
;
16163 int height
= WINDOW_TOTAL_LINES (w
);
16165 /* If we decided that this buffer isn't suitable for line numbers,
16166 don't forget that too fast. */
16167 if (EQ (w
->base_line_pos
, w
->buffer
))
16169 /* But do forget it, if the window shows a different buffer now. */
16170 else if (BUFFERP (w
->base_line_pos
))
16171 w
->base_line_pos
= Qnil
;
16173 /* If the buffer is very big, don't waste time. */
16174 if (INTEGERP (Vline_number_display_limit
)
16175 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16177 w
->base_line_pos
= Qnil
;
16178 w
->base_line_number
= Qnil
;
16182 if (!NILP (w
->base_line_number
)
16183 && !NILP (w
->base_line_pos
)
16184 && XFASTINT (w
->base_line_pos
) <= startpos
)
16186 line
= XFASTINT (w
->base_line_number
);
16187 linepos
= XFASTINT (w
->base_line_pos
);
16188 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16193 linepos
= BUF_BEGV (b
);
16194 linepos_byte
= BUF_BEGV_BYTE (b
);
16197 /* Count lines from base line to window start position. */
16198 nlines
= display_count_lines (linepos
, linepos_byte
,
16202 topline
= nlines
+ line
;
16204 /* Determine a new base line, if the old one is too close
16205 or too far away, or if we did not have one.
16206 "Too close" means it's plausible a scroll-down would
16207 go back past it. */
16208 if (startpos
== BUF_BEGV (b
))
16210 w
->base_line_number
= make_number (topline
);
16211 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16213 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16214 || linepos
== BUF_BEGV (b
))
16216 int limit
= BUF_BEGV (b
);
16217 int limit_byte
= BUF_BEGV_BYTE (b
);
16219 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16221 if (startpos
- distance
> limit
)
16223 limit
= startpos
- distance
;
16224 limit_byte
= CHAR_TO_BYTE (limit
);
16227 nlines
= display_count_lines (startpos
, startpos_byte
,
16229 - (height
* 2 + 30),
16231 /* If we couldn't find the lines we wanted within
16232 line_number_display_limit_width chars per line,
16233 give up on line numbers for this window. */
16234 if (position
== limit_byte
&& limit
== startpos
- distance
)
16236 w
->base_line_pos
= w
->buffer
;
16237 w
->base_line_number
= Qnil
;
16241 w
->base_line_number
= make_number (topline
- nlines
);
16242 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16245 /* Now count lines from the start pos to point. */
16246 nlines
= display_count_lines (startpos
, startpos_byte
,
16247 PT_BYTE
, PT
, &junk
);
16249 /* Record that we did display the line number. */
16250 line_number_displayed
= 1;
16252 /* Make the string to show. */
16253 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16254 return decode_mode_spec_buf
;
16257 char* p
= decode_mode_spec_buf
;
16258 int pad
= field_width
- 2;
16264 return decode_mode_spec_buf
;
16270 obj
= b
->mode_name
;
16274 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16280 int pos
= marker_position (w
->start
);
16281 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16283 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16285 if (pos
<= BUF_BEGV (b
))
16290 else if (pos
<= BUF_BEGV (b
))
16294 if (total
> 1000000)
16295 /* Do it differently for a large value, to avoid overflow. */
16296 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16298 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16299 /* We can't normally display a 3-digit number,
16300 so get us a 2-digit number that is close. */
16303 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16304 return decode_mode_spec_buf
;
16308 /* Display percentage of size above the bottom of the screen. */
16311 int toppos
= marker_position (w
->start
);
16312 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16313 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16315 if (botpos
>= BUF_ZV (b
))
16317 if (toppos
<= BUF_BEGV (b
))
16324 if (total
> 1000000)
16325 /* Do it differently for a large value, to avoid overflow. */
16326 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16328 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16329 /* We can't normally display a 3-digit number,
16330 so get us a 2-digit number that is close. */
16333 if (toppos
<= BUF_BEGV (b
))
16334 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16336 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16337 return decode_mode_spec_buf
;
16342 /* status of process */
16343 obj
= Fget_buffer_process (w
->buffer
);
16345 return "no process";
16346 #ifdef subprocesses
16347 obj
= Fsymbol_name (Fprocess_status (obj
));
16351 case 't': /* indicate TEXT or BINARY */
16352 #ifdef MODE_LINE_BINARY_TEXT
16353 return MODE_LINE_BINARY_TEXT (b
);
16359 /* coding-system (not including end-of-line format) */
16361 /* coding-system (including end-of-line type) */
16363 int eol_flag
= (c
== 'Z');
16364 char *p
= decode_mode_spec_buf
;
16366 if (! FRAME_WINDOW_P (f
))
16368 /* No need to mention EOL here--the terminal never needs
16369 to do EOL conversion. */
16370 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16371 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16373 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16376 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16377 #ifdef subprocesses
16378 obj
= Fget_buffer_process (Fcurrent_buffer ());
16379 if (PROCESSP (obj
))
16381 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16383 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16386 #endif /* subprocesses */
16389 return decode_mode_spec_buf
;
16395 *multibyte
= STRING_MULTIBYTE (obj
);
16396 return (char *) SDATA (obj
);
16403 /* Count up to COUNT lines starting from START / START_BYTE.
16404 But don't go beyond LIMIT_BYTE.
16405 Return the number of lines thus found (always nonnegative).
16407 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16410 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16411 int start
, start_byte
, limit_byte
, count
;
16414 register unsigned char *cursor
;
16415 unsigned char *base
;
16417 register int ceiling
;
16418 register unsigned char *ceiling_addr
;
16419 int orig_count
= count
;
16421 /* If we are not in selective display mode,
16422 check only for newlines. */
16423 int selective_display
= (!NILP (current_buffer
->selective_display
)
16424 && !INTEGERP (current_buffer
->selective_display
));
16428 while (start_byte
< limit_byte
)
16430 ceiling
= BUFFER_CEILING_OF (start_byte
);
16431 ceiling
= min (limit_byte
- 1, ceiling
);
16432 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16433 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16436 if (selective_display
)
16437 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16440 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16443 if (cursor
!= ceiling_addr
)
16447 start_byte
+= cursor
- base
+ 1;
16448 *byte_pos_ptr
= start_byte
;
16452 if (++cursor
== ceiling_addr
)
16458 start_byte
+= cursor
- base
;
16463 while (start_byte
> limit_byte
)
16465 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16466 ceiling
= max (limit_byte
, ceiling
);
16467 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16468 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16471 if (selective_display
)
16472 while (--cursor
!= ceiling_addr
16473 && *cursor
!= '\n' && *cursor
!= 015)
16476 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16479 if (cursor
!= ceiling_addr
)
16483 start_byte
+= cursor
- base
+ 1;
16484 *byte_pos_ptr
= start_byte
;
16485 /* When scanning backwards, we should
16486 not count the newline posterior to which we stop. */
16487 return - orig_count
- 1;
16493 /* Here we add 1 to compensate for the last decrement
16494 of CURSOR, which took it past the valid range. */
16495 start_byte
+= cursor
- base
+ 1;
16499 *byte_pos_ptr
= limit_byte
;
16502 return - orig_count
+ count
;
16503 return orig_count
- count
;
16509 /***********************************************************************
16511 ***********************************************************************/
16513 /* Display a NUL-terminated string, starting with index START.
16515 If STRING is non-null, display that C string. Otherwise, the Lisp
16516 string LISP_STRING is displayed.
16518 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16519 FACE_STRING. Display STRING or LISP_STRING with the face at
16520 FACE_STRING_POS in FACE_STRING:
16522 Display the string in the environment given by IT, but use the
16523 standard display table, temporarily.
16525 FIELD_WIDTH is the minimum number of output glyphs to produce.
16526 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16527 with spaces. If STRING has more characters, more than FIELD_WIDTH
16528 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16530 PRECISION is the maximum number of characters to output from
16531 STRING. PRECISION < 0 means don't truncate the string.
16533 This is roughly equivalent to printf format specifiers:
16535 FIELD_WIDTH PRECISION PRINTF
16536 ----------------------------------------
16542 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16543 display them, and < 0 means obey the current buffer's value of
16544 enable_multibyte_characters.
16546 Value is the number of glyphs produced. */
16549 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16550 start
, it
, field_width
, precision
, max_x
, multibyte
)
16551 unsigned char *string
;
16552 Lisp_Object lisp_string
;
16553 Lisp_Object face_string
;
16554 int face_string_pos
;
16557 int field_width
, precision
, max_x
;
16560 int hpos_at_start
= it
->hpos
;
16561 int saved_face_id
= it
->face_id
;
16562 struct glyph_row
*row
= it
->glyph_row
;
16564 /* Initialize the iterator IT for iteration over STRING beginning
16565 with index START. */
16566 reseat_to_string (it
, string
, lisp_string
, start
,
16567 precision
, field_width
, multibyte
);
16569 /* If displaying STRING, set up the face of the iterator
16570 from LISP_STRING, if that's given. */
16571 if (STRINGP (face_string
))
16577 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16578 0, it
->region_beg_charpos
,
16579 it
->region_end_charpos
,
16580 &endptr
, it
->base_face_id
, 0);
16581 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16582 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16585 /* Set max_x to the maximum allowed X position. Don't let it go
16586 beyond the right edge of the window. */
16588 max_x
= it
->last_visible_x
;
16590 max_x
= min (max_x
, it
->last_visible_x
);
16592 /* Skip over display elements that are not visible. because IT->w is
16594 if (it
->current_x
< it
->first_visible_x
)
16595 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16596 MOVE_TO_POS
| MOVE_TO_X
);
16598 row
->ascent
= it
->max_ascent
;
16599 row
->height
= it
->max_ascent
+ it
->max_descent
;
16600 row
->phys_ascent
= it
->max_phys_ascent
;
16601 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16603 /* This condition is for the case that we are called with current_x
16604 past last_visible_x. */
16605 while (it
->current_x
< max_x
)
16607 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16609 /* Get the next display element. */
16610 if (!get_next_display_element (it
))
16613 /* Produce glyphs. */
16614 x_before
= it
->current_x
;
16615 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16616 PRODUCE_GLYPHS (it
);
16618 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16621 while (i
< nglyphs
)
16623 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16625 if (!it
->truncate_lines_p
16626 && x
+ glyph
->pixel_width
> max_x
)
16628 /* End of continued line or max_x reached. */
16629 if (CHAR_GLYPH_PADDING_P (*glyph
))
16631 /* A wide character is unbreakable. */
16632 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16633 it
->current_x
= x_before
;
16637 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16642 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16644 /* Glyph is at least partially visible. */
16646 if (x
< it
->first_visible_x
)
16647 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16651 /* Glyph is off the left margin of the display area.
16652 Should not happen. */
16656 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16657 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16658 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16659 row
->phys_height
= max (row
->phys_height
,
16660 it
->max_phys_ascent
+ it
->max_phys_descent
);
16661 x
+= glyph
->pixel_width
;
16665 /* Stop if max_x reached. */
16669 /* Stop at line ends. */
16670 if (ITERATOR_AT_END_OF_LINE_P (it
))
16672 it
->continuation_lines_width
= 0;
16676 set_iterator_to_next (it
, 1);
16678 /* Stop if truncating at the right edge. */
16679 if (it
->truncate_lines_p
16680 && it
->current_x
>= it
->last_visible_x
)
16682 /* Add truncation mark, but don't do it if the line is
16683 truncated at a padding space. */
16684 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16686 if (!FRAME_WINDOW_P (it
->f
))
16690 if (it
->current_x
> it
->last_visible_x
)
16692 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16693 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16695 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16697 row
->used
[TEXT_AREA
] = i
;
16698 produce_special_glyphs (it
, IT_TRUNCATION
);
16701 produce_special_glyphs (it
, IT_TRUNCATION
);
16703 it
->glyph_row
->truncated_on_right_p
= 1;
16709 /* Maybe insert a truncation at the left. */
16710 if (it
->first_visible_x
16711 && IT_CHARPOS (*it
) > 0)
16713 if (!FRAME_WINDOW_P (it
->f
))
16714 insert_left_trunc_glyphs (it
);
16715 it
->glyph_row
->truncated_on_left_p
= 1;
16718 it
->face_id
= saved_face_id
;
16720 /* Value is number of columns displayed. */
16721 return it
->hpos
- hpos_at_start
;
16726 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16727 appears as an element of LIST or as the car of an element of LIST.
16728 If PROPVAL is a list, compare each element against LIST in that
16729 way, and return 1/2 if any element of PROPVAL is found in LIST.
16730 Otherwise return 0. This function cannot quit.
16731 The return value is 2 if the text is invisible but with an ellipsis
16732 and 1 if it's invisible and without an ellipsis. */
16735 invisible_p (propval
, list
)
16736 register Lisp_Object propval
;
16739 register Lisp_Object tail
, proptail
;
16741 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16743 register Lisp_Object tem
;
16745 if (EQ (propval
, tem
))
16747 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16748 return NILP (XCDR (tem
)) ? 1 : 2;
16751 if (CONSP (propval
))
16753 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16755 Lisp_Object propelt
;
16756 propelt
= XCAR (proptail
);
16757 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16759 register Lisp_Object tem
;
16761 if (EQ (propelt
, tem
))
16763 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16764 return NILP (XCDR (tem
)) ? 1 : 2;
16772 /* Calculate a width or height in pixels from a specification using
16773 the following elements:
16776 NUM - a (fractional) multiple of the default font width/height
16777 (NUM) - specifies exactly NUM pixels
16778 UNIT - a fixed number of pixels, see below.
16779 ELEMENT - size of a display element in pixels, see below.
16780 (NUM . SPEC) - equals NUM * SPEC
16781 (+ SPEC SPEC ...) - add pixel values
16782 (- SPEC SPEC ...) - subtract pixel values
16783 (- SPEC) - negate pixel value
16786 INT or FLOAT - a number constant
16787 SYMBOL - use symbol's (buffer local) variable binding.
16790 in - pixels per inch *)
16791 mm - pixels per 1/1000 meter *)
16792 cm - pixels per 1/100 meter *)
16793 width - width of current font in pixels.
16794 height - height of current font in pixels.
16796 *) using the ratio(s) defined in display-pixels-per-inch.
16800 left-fringe - left fringe width in pixels
16801 right-fringe - right fringe width in pixels
16803 left-margin - left margin width in pixels
16804 right-margin - right margin width in pixels
16806 scroll-bar - scroll-bar area width in pixels
16810 Pixels corresponding to 5 inches:
16813 Total width of non-text areas on left side of window (if scroll-bar is on left):
16814 '(space :width (+ left-fringe left-margin scroll-bar))
16816 Align to first text column (in header line):
16817 '(space :align-to 0)
16819 Align to middle of text area minus half the width of variable `my-image'
16820 containing a loaded image:
16821 '(space :align-to (0.5 . (- text my-image)))
16823 Width of left margin minus width of 1 character in the default font:
16824 '(space :width (- left-margin 1))
16826 Width of left margin minus width of 2 characters in the current font:
16827 '(space :width (- left-margin (2 . width)))
16829 Center 1 character over left-margin (in header line):
16830 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
16832 Different ways to express width of left fringe plus left margin minus one pixel:
16833 '(space :width (- (+ left-fringe left-margin) (1)))
16834 '(space :width (+ left-fringe left-margin (- (1))))
16835 '(space :width (+ left-fringe left-margin (-1)))
16839 #define NUMVAL(X) \
16840 ((INTEGERP (X) || FLOATP (X)) \
16845 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
16850 int width_p
, *align_to
;
16854 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
16855 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
16858 return OK_PIXELS (0);
16860 if (SYMBOLP (prop
))
16862 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
16864 char *unit
= SDATA (SYMBOL_NAME (prop
));
16866 if (unit
[0] == 'i' && unit
[1] == 'n')
16868 else if (unit
[0] == 'm' && unit
[1] == 'm')
16870 else if (unit
[0] == 'c' && unit
[1] == 'm')
16877 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
16878 || (CONSP (Vdisplay_pixels_per_inch
)
16880 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
16881 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
16883 return OK_PIXELS (ppi
/ pixels
);
16889 #ifdef HAVE_WINDOW_SYSTEM
16890 if (EQ (prop
, Qheight
))
16891 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
16892 if (EQ (prop
, Qwidth
))
16893 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
16895 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
16896 return OK_PIXELS (1);
16899 if (EQ (prop
, Qtext
))
16900 return OK_PIXELS (width_p
16901 ? window_box_width (it
->w
, TEXT_AREA
)
16902 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
16904 if (align_to
&& *align_to
< 0)
16907 if (EQ (prop
, Qleft
))
16908 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
16909 if (EQ (prop
, Qright
))
16910 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
16911 if (EQ (prop
, Qcenter
))
16912 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
16913 + window_box_width (it
->w
, TEXT_AREA
) / 2);
16914 if (EQ (prop
, Qleft_fringe
))
16915 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16916 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
16917 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
16918 if (EQ (prop
, Qright_fringe
))
16919 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16920 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16921 : window_box_right_offset (it
->w
, TEXT_AREA
));
16922 if (EQ (prop
, Qleft_margin
))
16923 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
16924 if (EQ (prop
, Qright_margin
))
16925 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
16926 if (EQ (prop
, Qscroll_bar
))
16927 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
16929 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
16930 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
16931 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
16936 if (EQ (prop
, Qleft_fringe
))
16937 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
16938 if (EQ (prop
, Qright_fringe
))
16939 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
16940 if (EQ (prop
, Qleft_margin
))
16941 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
16942 if (EQ (prop
, Qright_margin
))
16943 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
16944 if (EQ (prop
, Qscroll_bar
))
16945 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
16948 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
16951 if (INTEGERP (prop
) || FLOATP (prop
))
16953 int base_unit
= (width_p
16954 ? FRAME_COLUMN_WIDTH (it
->f
)
16955 : FRAME_LINE_HEIGHT (it
->f
));
16956 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
16961 Lisp_Object car
= XCAR (prop
);
16962 Lisp_Object cdr
= XCDR (prop
);
16966 #ifdef HAVE_WINDOW_SYSTEM
16967 if (valid_image_p (prop
))
16969 int id
= lookup_image (it
->f
, prop
);
16970 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
16972 return OK_PIXELS (width_p
? img
->width
: img
->height
);
16975 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
16981 while (CONSP (cdr
))
16983 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
16984 font
, width_p
, align_to
))
16987 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
16992 if (EQ (car
, Qminus
))
16994 return OK_PIXELS (pixels
);
16997 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17000 if (INTEGERP (car
) || FLOATP (car
))
17003 pixels
= XFLOATINT (car
);
17005 return OK_PIXELS (pixels
);
17006 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17007 font
, width_p
, align_to
))
17008 return OK_PIXELS (pixels
* fact
);
17019 /***********************************************************************
17021 ***********************************************************************/
17023 #ifdef HAVE_WINDOW_SYSTEM
17028 dump_glyph_string (s
)
17029 struct glyph_string
*s
;
17031 fprintf (stderr
, "glyph string\n");
17032 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17033 s
->x
, s
->y
, s
->width
, s
->height
);
17034 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17035 fprintf (stderr
, " hl = %d\n", s
->hl
);
17036 fprintf (stderr
, " left overhang = %d, right = %d\n",
17037 s
->left_overhang
, s
->right_overhang
);
17038 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17039 fprintf (stderr
, " extends to end of line = %d\n",
17040 s
->extends_to_end_of_line_p
);
17041 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17042 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17045 #endif /* GLYPH_DEBUG */
17047 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17048 of XChar2b structures for S; it can't be allocated in
17049 init_glyph_string because it must be allocated via `alloca'. W
17050 is the window on which S is drawn. ROW and AREA are the glyph row
17051 and area within the row from which S is constructed. START is the
17052 index of the first glyph structure covered by S. HL is a
17053 face-override for drawing S. */
17056 #define OPTIONAL_HDC(hdc) hdc,
17057 #define DECLARE_HDC(hdc) HDC hdc;
17058 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17059 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17062 #ifndef OPTIONAL_HDC
17063 #define OPTIONAL_HDC(hdc)
17064 #define DECLARE_HDC(hdc)
17065 #define ALLOCATE_HDC(hdc, f)
17066 #define RELEASE_HDC(hdc, f)
17070 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17071 struct glyph_string
*s
;
17075 struct glyph_row
*row
;
17076 enum glyph_row_area area
;
17078 enum draw_glyphs_face hl
;
17080 bzero (s
, sizeof *s
);
17082 s
->f
= XFRAME (w
->frame
);
17086 s
->display
= FRAME_X_DISPLAY (s
->f
);
17087 s
->window
= FRAME_X_WINDOW (s
->f
);
17088 s
->char2b
= char2b
;
17092 s
->first_glyph
= row
->glyphs
[area
] + start
;
17093 s
->height
= row
->height
;
17094 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17096 /* Display the internal border below the tool-bar window. */
17097 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17098 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17100 s
->ybase
= s
->y
+ row
->ascent
;
17104 /* Append the list of glyph strings with head H and tail T to the list
17105 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17108 append_glyph_string_lists (head
, tail
, h
, t
)
17109 struct glyph_string
**head
, **tail
;
17110 struct glyph_string
*h
, *t
;
17124 /* Prepend the list of glyph strings with head H and tail T to the
17125 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17129 prepend_glyph_string_lists (head
, tail
, h
, t
)
17130 struct glyph_string
**head
, **tail
;
17131 struct glyph_string
*h
, *t
;
17145 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17146 Set *HEAD and *TAIL to the resulting list. */
17149 append_glyph_string (head
, tail
, s
)
17150 struct glyph_string
**head
, **tail
;
17151 struct glyph_string
*s
;
17153 s
->next
= s
->prev
= NULL
;
17154 append_glyph_string_lists (head
, tail
, s
, s
);
17158 /* Get face and two-byte form of character glyph GLYPH on frame F.
17159 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17160 a pointer to a realized face that is ready for display. */
17162 static INLINE
struct face
*
17163 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17165 struct glyph
*glyph
;
17171 xassert (glyph
->type
== CHAR_GLYPH
);
17172 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17177 if (!glyph
->multibyte_p
)
17179 /* Unibyte case. We don't have to encode, but we have to make
17180 sure to use a face suitable for unibyte. */
17181 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17183 else if (glyph
->u
.ch
< 128
17184 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17186 /* Case of ASCII in a face known to fit ASCII. */
17187 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17191 int c1
, c2
, charset
;
17193 /* Split characters into bytes. If c2 is -1 afterwards, C is
17194 really a one-byte character so that byte1 is zero. */
17195 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17197 STORE_XCHAR2B (char2b
, c1
, c2
);
17199 STORE_XCHAR2B (char2b
, 0, c1
);
17201 /* Maybe encode the character in *CHAR2B. */
17202 if (charset
!= CHARSET_ASCII
)
17204 struct font_info
*font_info
17205 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17208 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17212 /* Make sure X resources of the face are allocated. */
17213 xassert (face
!= NULL
);
17214 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17219 /* Fill glyph string S with composition components specified by S->cmp.
17221 FACES is an array of faces for all components of this composition.
17222 S->gidx is the index of the first component for S.
17223 OVERLAPS_P non-zero means S should draw the foreground only, and
17224 use its physical height for clipping.
17226 Value is the index of a component not in S. */
17229 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17230 struct glyph_string
*s
;
17231 struct face
**faces
;
17238 s
->for_overlaps_p
= overlaps_p
;
17240 s
->face
= faces
[s
->gidx
];
17241 s
->font
= s
->face
->font
;
17242 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17244 /* For all glyphs of this composition, starting at the offset
17245 S->gidx, until we reach the end of the definition or encounter a
17246 glyph that requires the different face, add it to S. */
17248 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17251 /* All glyph strings for the same composition has the same width,
17252 i.e. the width set for the first component of the composition. */
17254 s
->width
= s
->first_glyph
->pixel_width
;
17256 /* If the specified font could not be loaded, use the frame's
17257 default font, but record the fact that we couldn't load it in
17258 the glyph string so that we can draw rectangles for the
17259 characters of the glyph string. */
17260 if (s
->font
== NULL
)
17262 s
->font_not_found_p
= 1;
17263 s
->font
= FRAME_FONT (s
->f
);
17266 /* Adjust base line for subscript/superscript text. */
17267 s
->ybase
+= s
->first_glyph
->voffset
;
17269 xassert (s
->face
&& s
->face
->gc
);
17271 /* This glyph string must always be drawn with 16-bit functions. */
17274 return s
->gidx
+ s
->nchars
;
17278 /* Fill glyph string S from a sequence of character glyphs.
17280 FACE_ID is the face id of the string. START is the index of the
17281 first glyph to consider, END is the index of the last + 1.
17282 OVERLAPS_P non-zero means S should draw the foreground only, and
17283 use its physical height for clipping.
17285 Value is the index of the first glyph not in S. */
17288 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17289 struct glyph_string
*s
;
17291 int start
, end
, overlaps_p
;
17293 struct glyph
*glyph
, *last
;
17295 int glyph_not_available_p
;
17297 xassert (s
->f
== XFRAME (s
->w
->frame
));
17298 xassert (s
->nchars
== 0);
17299 xassert (start
>= 0 && end
> start
);
17301 s
->for_overlaps_p
= overlaps_p
,
17302 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17303 last
= s
->row
->glyphs
[s
->area
] + end
;
17304 voffset
= glyph
->voffset
;
17306 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17308 while (glyph
< last
17309 && glyph
->type
== CHAR_GLYPH
17310 && glyph
->voffset
== voffset
17311 /* Same face id implies same font, nowadays. */
17312 && glyph
->face_id
== face_id
17313 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17317 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17318 s
->char2b
+ s
->nchars
,
17320 s
->two_byte_p
= two_byte_p
;
17322 xassert (s
->nchars
<= end
- start
);
17323 s
->width
+= glyph
->pixel_width
;
17327 s
->font
= s
->face
->font
;
17328 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17330 /* If the specified font could not be loaded, use the frame's font,
17331 but record the fact that we couldn't load it in
17332 S->font_not_found_p so that we can draw rectangles for the
17333 characters of the glyph string. */
17334 if (s
->font
== NULL
|| glyph_not_available_p
)
17336 s
->font_not_found_p
= 1;
17337 s
->font
= FRAME_FONT (s
->f
);
17340 /* Adjust base line for subscript/superscript text. */
17341 s
->ybase
+= voffset
;
17343 xassert (s
->face
&& s
->face
->gc
);
17344 return glyph
- s
->row
->glyphs
[s
->area
];
17348 /* Fill glyph string S from image glyph S->first_glyph. */
17351 fill_image_glyph_string (s
)
17352 struct glyph_string
*s
;
17354 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17355 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17357 s
->slice
= s
->first_glyph
->slice
;
17358 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17359 s
->font
= s
->face
->font
;
17360 s
->width
= s
->first_glyph
->pixel_width
;
17362 /* Adjust base line for subscript/superscript text. */
17363 s
->ybase
+= s
->first_glyph
->voffset
;
17367 /* Fill glyph string S from a sequence of stretch glyphs.
17369 ROW is the glyph row in which the glyphs are found, AREA is the
17370 area within the row. START is the index of the first glyph to
17371 consider, END is the index of the last + 1.
17373 Value is the index of the first glyph not in S. */
17376 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17377 struct glyph_string
*s
;
17378 struct glyph_row
*row
;
17379 enum glyph_row_area area
;
17382 struct glyph
*glyph
, *last
;
17383 int voffset
, face_id
;
17385 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17387 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17388 last
= s
->row
->glyphs
[s
->area
] + end
;
17389 face_id
= glyph
->face_id
;
17390 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17391 s
->font
= s
->face
->font
;
17392 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17393 s
->width
= glyph
->pixel_width
;
17394 voffset
= glyph
->voffset
;
17398 && glyph
->type
== STRETCH_GLYPH
17399 && glyph
->voffset
== voffset
17400 && glyph
->face_id
== face_id
);
17402 s
->width
+= glyph
->pixel_width
;
17404 /* Adjust base line for subscript/superscript text. */
17405 s
->ybase
+= voffset
;
17407 /* The case that face->gc == 0 is handled when drawing the glyph
17408 string by calling PREPARE_FACE_FOR_DISPLAY. */
17410 return glyph
- s
->row
->glyphs
[s
->area
];
17415 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17416 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17417 assumed to be zero. */
17420 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17421 struct glyph
*glyph
;
17425 *left
= *right
= 0;
17427 if (glyph
->type
== CHAR_GLYPH
)
17431 struct font_info
*font_info
;
17435 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17437 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17438 if (font
/* ++KFS: Should this be font_info ? */
17439 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17441 if (pcm
->rbearing
> pcm
->width
)
17442 *right
= pcm
->rbearing
- pcm
->width
;
17443 if (pcm
->lbearing
< 0)
17444 *left
= -pcm
->lbearing
;
17450 /* Return the index of the first glyph preceding glyph string S that
17451 is overwritten by S because of S's left overhang. Value is -1
17452 if no glyphs are overwritten. */
17455 left_overwritten (s
)
17456 struct glyph_string
*s
;
17460 if (s
->left_overhang
)
17463 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17464 int first
= s
->first_glyph
- glyphs
;
17466 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17467 x
-= glyphs
[i
].pixel_width
;
17478 /* Return the index of the first glyph preceding glyph string S that
17479 is overwriting S because of its right overhang. Value is -1 if no
17480 glyph in front of S overwrites S. */
17483 left_overwriting (s
)
17484 struct glyph_string
*s
;
17487 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17488 int first
= s
->first_glyph
- glyphs
;
17492 for (i
= first
- 1; i
>= 0; --i
)
17495 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17498 x
-= glyphs
[i
].pixel_width
;
17505 /* Return the index of the last glyph following glyph string S that is
17506 not overwritten by S because of S's right overhang. Value is -1 if
17507 no such glyph is found. */
17510 right_overwritten (s
)
17511 struct glyph_string
*s
;
17515 if (s
->right_overhang
)
17518 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17519 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17520 int end
= s
->row
->used
[s
->area
];
17522 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17523 x
+= glyphs
[i
].pixel_width
;
17532 /* Return the index of the last glyph following glyph string S that
17533 overwrites S because of its left overhang. Value is negative
17534 if no such glyph is found. */
17537 right_overwriting (s
)
17538 struct glyph_string
*s
;
17541 int end
= s
->row
->used
[s
->area
];
17542 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17543 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17547 for (i
= first
; i
< end
; ++i
)
17550 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17553 x
+= glyphs
[i
].pixel_width
;
17560 /* Get face and two-byte form of character C in face FACE_ID on frame
17561 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17562 means we want to display multibyte text. DISPLAY_P non-zero means
17563 make sure that X resources for the face returned are allocated.
17564 Value is a pointer to a realized face that is ready for display if
17565 DISPLAY_P is non-zero. */
17567 static INLINE
struct face
*
17568 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17572 int multibyte_p
, display_p
;
17574 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17578 /* Unibyte case. We don't have to encode, but we have to make
17579 sure to use a face suitable for unibyte. */
17580 STORE_XCHAR2B (char2b
, 0, c
);
17581 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17582 face
= FACE_FROM_ID (f
, face_id
);
17584 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17586 /* Case of ASCII in a face known to fit ASCII. */
17587 STORE_XCHAR2B (char2b
, 0, c
);
17591 int c1
, c2
, charset
;
17593 /* Split characters into bytes. If c2 is -1 afterwards, C is
17594 really a one-byte character so that byte1 is zero. */
17595 SPLIT_CHAR (c
, charset
, c1
, c2
);
17597 STORE_XCHAR2B (char2b
, c1
, c2
);
17599 STORE_XCHAR2B (char2b
, 0, c1
);
17601 /* Maybe encode the character in *CHAR2B. */
17602 if (face
->font
!= NULL
)
17604 struct font_info
*font_info
17605 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17607 rif
->encode_char (c
, char2b
, font_info
, 0);
17611 /* Make sure X resources of the face are allocated. */
17612 #ifdef HAVE_X_WINDOWS
17616 xassert (face
!= NULL
);
17617 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17624 /* Set background width of glyph string S. START is the index of the
17625 first glyph following S. LAST_X is the right-most x-position + 1
17626 in the drawing area. */
17629 set_glyph_string_background_width (s
, start
, last_x
)
17630 struct glyph_string
*s
;
17634 /* If the face of this glyph string has to be drawn to the end of
17635 the drawing area, set S->extends_to_end_of_line_p. */
17636 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17638 if (start
== s
->row
->used
[s
->area
]
17639 && s
->area
== TEXT_AREA
17640 && ((s
->hl
== DRAW_NORMAL_TEXT
17641 && (s
->row
->fill_line_p
17642 || s
->face
->background
!= default_face
->background
17643 || s
->face
->stipple
!= default_face
->stipple
17644 || s
->row
->mouse_face_p
))
17645 || s
->hl
== DRAW_MOUSE_FACE
17646 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17647 && s
->row
->fill_line_p
)))
17648 s
->extends_to_end_of_line_p
= 1;
17650 /* If S extends its face to the end of the line, set its
17651 background_width to the distance to the right edge of the drawing
17653 if (s
->extends_to_end_of_line_p
)
17654 s
->background_width
= last_x
- s
->x
+ 1;
17656 s
->background_width
= s
->width
;
17660 /* Compute overhangs and x-positions for glyph string S and its
17661 predecessors, or successors. X is the starting x-position for S.
17662 BACKWARD_P non-zero means process predecessors. */
17665 compute_overhangs_and_x (s
, x
, backward_p
)
17666 struct glyph_string
*s
;
17674 if (rif
->compute_glyph_string_overhangs
)
17675 rif
->compute_glyph_string_overhangs (s
);
17685 if (rif
->compute_glyph_string_overhangs
)
17686 rif
->compute_glyph_string_overhangs (s
);
17696 /* The following macros are only called from draw_glyphs below.
17697 They reference the following parameters of that function directly:
17698 `w', `row', `area', and `overlap_p'
17699 as well as the following local variables:
17700 `s', `f', and `hdc' (in W32) */
17703 /* On W32, silently add local `hdc' variable to argument list of
17704 init_glyph_string. */
17705 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17706 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17708 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17709 init_glyph_string (s, char2b, w, row, area, start, hl)
17712 /* Add a glyph string for a stretch glyph to the list of strings
17713 between HEAD and TAIL. START is the index of the stretch glyph in
17714 row area AREA of glyph row ROW. END is the index of the last glyph
17715 in that glyph row area. X is the current output position assigned
17716 to the new glyph string constructed. HL overrides that face of the
17717 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17718 is the right-most x-position of the drawing area. */
17720 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17721 and below -- keep them on one line. */
17722 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17725 s = (struct glyph_string *) alloca (sizeof *s); \
17726 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17727 START = fill_stretch_glyph_string (s, row, area, START, END); \
17728 append_glyph_string (&HEAD, &TAIL, s); \
17734 /* Add a glyph string for an image glyph to the list of strings
17735 between HEAD and TAIL. START is the index of the image glyph in
17736 row area AREA of glyph row ROW. END is the index of the last glyph
17737 in that glyph row area. X is the current output position assigned
17738 to the new glyph string constructed. HL overrides that face of the
17739 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17740 is the right-most x-position of the drawing area. */
17742 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17745 s = (struct glyph_string *) alloca (sizeof *s); \
17746 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17747 fill_image_glyph_string (s); \
17748 append_glyph_string (&HEAD, &TAIL, s); \
17755 /* Add a glyph string for a sequence of character glyphs to the list
17756 of strings between HEAD and TAIL. START is the index of the first
17757 glyph in row area AREA of glyph row ROW that is part of the new
17758 glyph string. END is the index of the last glyph in that glyph row
17759 area. X is the current output position assigned to the new glyph
17760 string constructed. HL overrides that face of the glyph; e.g. it
17761 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17762 right-most x-position of the drawing area. */
17764 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17770 c = (row)->glyphs[area][START].u.ch; \
17771 face_id = (row)->glyphs[area][START].face_id; \
17773 s = (struct glyph_string *) alloca (sizeof *s); \
17774 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17775 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17776 append_glyph_string (&HEAD, &TAIL, s); \
17778 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17783 /* Add a glyph string for a composite sequence to the list of strings
17784 between HEAD and TAIL. START is the index of the first glyph in
17785 row area AREA of glyph row ROW that is part of the new glyph
17786 string. END is the index of the last glyph in that glyph row area.
17787 X is the current output position assigned to the new glyph string
17788 constructed. HL overrides that face of the glyph; e.g. it is
17789 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17790 x-position of the drawing area. */
17792 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17794 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17795 int face_id = (row)->glyphs[area][START].face_id; \
17796 struct face *base_face = FACE_FROM_ID (f, face_id); \
17797 struct composition *cmp = composition_table[cmp_id]; \
17798 int glyph_len = cmp->glyph_len; \
17800 struct face **faces; \
17801 struct glyph_string *first_s = NULL; \
17804 base_face = base_face->ascii_face; \
17805 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17806 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17807 /* At first, fill in `char2b' and `faces'. */ \
17808 for (n = 0; n < glyph_len; n++) \
17810 int c = COMPOSITION_GLYPH (cmp, n); \
17811 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17812 faces[n] = FACE_FROM_ID (f, this_face_id); \
17813 get_char_face_and_encoding (f, c, this_face_id, \
17814 char2b + n, 1, 1); \
17817 /* Make glyph_strings for each glyph sequence that is drawable by \
17818 the same face, and append them to HEAD/TAIL. */ \
17819 for (n = 0; n < cmp->glyph_len;) \
17821 s = (struct glyph_string *) alloca (sizeof *s); \
17822 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17823 append_glyph_string (&(HEAD), &(TAIL), s); \
17831 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17839 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17840 of AREA of glyph row ROW on window W between indices START and END.
17841 HL overrides the face for drawing glyph strings, e.g. it is
17842 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17843 x-positions of the drawing area.
17845 This is an ugly monster macro construct because we must use alloca
17846 to allocate glyph strings (because draw_glyphs can be called
17847 asynchronously). */
17849 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17852 HEAD = TAIL = NULL; \
17853 while (START < END) \
17855 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17856 switch (first_glyph->type) \
17859 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17863 case COMPOSITE_GLYPH: \
17864 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17868 case STRETCH_GLYPH: \
17869 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17873 case IMAGE_GLYPH: \
17874 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17882 set_glyph_string_background_width (s, START, LAST_X); \
17889 /* Draw glyphs between START and END in AREA of ROW on window W,
17890 starting at x-position X. X is relative to AREA in W. HL is a
17891 face-override with the following meaning:
17893 DRAW_NORMAL_TEXT draw normally
17894 DRAW_CURSOR draw in cursor face
17895 DRAW_MOUSE_FACE draw in mouse face.
17896 DRAW_INVERSE_VIDEO draw in mode line face
17897 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17898 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17900 If OVERLAPS_P is non-zero, draw only the foreground of characters
17901 and clip to the physical height of ROW.
17903 Value is the x-position reached, relative to AREA of W. */
17906 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17909 struct glyph_row
*row
;
17910 enum glyph_row_area area
;
17912 enum draw_glyphs_face hl
;
17915 struct glyph_string
*head
, *tail
;
17916 struct glyph_string
*s
;
17917 int last_x
, area_width
;
17920 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17923 ALLOCATE_HDC (hdc
, f
);
17925 /* Let's rather be paranoid than getting a SEGV. */
17926 end
= min (end
, row
->used
[area
]);
17927 start
= max (0, start
);
17928 start
= min (end
, start
);
17930 /* Translate X to frame coordinates. Set last_x to the right
17931 end of the drawing area. */
17932 if (row
->full_width_p
)
17934 /* X is relative to the left edge of W, without scroll bars
17936 x
+= WINDOW_LEFT_EDGE_X (w
);
17937 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
17941 int area_left
= window_box_left (w
, area
);
17943 area_width
= window_box_width (w
, area
);
17944 last_x
= area_left
+ area_width
;
17947 /* Build a doubly-linked list of glyph_string structures between
17948 head and tail from what we have to draw. Note that the macro
17949 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17950 the reason we use a separate variable `i'. */
17952 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17954 x_reached
= tail
->x
+ tail
->background_width
;
17958 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17959 the row, redraw some glyphs in front or following the glyph
17960 strings built above. */
17961 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17964 struct glyph_string
*h
, *t
;
17966 /* Compute overhangs for all glyph strings. */
17967 if (rif
->compute_glyph_string_overhangs
)
17968 for (s
= head
; s
; s
= s
->next
)
17969 rif
->compute_glyph_string_overhangs (s
);
17971 /* Prepend glyph strings for glyphs in front of the first glyph
17972 string that are overwritten because of the first glyph
17973 string's left overhang. The background of all strings
17974 prepended must be drawn because the first glyph string
17976 i
= left_overwritten (head
);
17980 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17981 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17983 compute_overhangs_and_x (t
, head
->x
, 1);
17984 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17987 /* Prepend glyph strings for glyphs in front of the first glyph
17988 string that overwrite that glyph string because of their
17989 right overhang. For these strings, only the foreground must
17990 be drawn, because it draws over the glyph string at `head'.
17991 The background must not be drawn because this would overwrite
17992 right overhangs of preceding glyphs for which no glyph
17994 i
= left_overwriting (head
);
17997 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
17998 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17999 for (s
= h
; s
; s
= s
->next
)
18000 s
->background_filled_p
= 1;
18001 compute_overhangs_and_x (t
, head
->x
, 1);
18002 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18005 /* Append glyphs strings for glyphs following the last glyph
18006 string tail that are overwritten by tail. The background of
18007 these strings has to be drawn because tail's foreground draws
18009 i
= right_overwritten (tail
);
18012 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18013 DRAW_NORMAL_TEXT
, x
, last_x
);
18014 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18015 append_glyph_string_lists (&head
, &tail
, h
, t
);
18018 /* Append glyph strings for glyphs following the last glyph
18019 string tail that overwrite tail. The foreground of such
18020 glyphs has to be drawn because it writes into the background
18021 of tail. The background must not be drawn because it could
18022 paint over the foreground of following glyphs. */
18023 i
= right_overwriting (tail
);
18026 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18027 DRAW_NORMAL_TEXT
, x
, last_x
);
18028 for (s
= h
; s
; s
= s
->next
)
18029 s
->background_filled_p
= 1;
18030 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18031 append_glyph_string_lists (&head
, &tail
, h
, t
);
18035 /* Draw all strings. */
18036 for (s
= head
; s
; s
= s
->next
)
18037 rif
->draw_glyph_string (s
);
18039 if (area
== TEXT_AREA
18040 && !row
->full_width_p
18041 /* When drawing overlapping rows, only the glyph strings'
18042 foreground is drawn, which doesn't erase a cursor
18046 int x0
= head
? head
->x
: x
;
18047 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18049 int text_left
= window_box_left (w
, TEXT_AREA
);
18053 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18054 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18057 /* Value is the x-position up to which drawn, relative to AREA of W.
18058 This doesn't include parts drawn because of overhangs. */
18059 if (row
->full_width_p
)
18060 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18062 x_reached
-= window_box_left (w
, area
);
18064 RELEASE_HDC (hdc
, f
);
18070 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18071 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18077 struct glyph
*glyph
;
18078 enum glyph_row_area area
= it
->area
;
18080 xassert (it
->glyph_row
);
18081 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18083 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18084 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18086 glyph
->charpos
= CHARPOS (it
->position
);
18087 glyph
->object
= it
->object
;
18088 glyph
->pixel_width
= it
->pixel_width
;
18089 glyph
->ascent
= it
->ascent
;
18090 glyph
->descent
= it
->descent
;
18091 glyph
->voffset
= it
->voffset
;
18092 glyph
->type
= CHAR_GLYPH
;
18093 glyph
->multibyte_p
= it
->multibyte_p
;
18094 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18095 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18096 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18097 || it
->phys_descent
> it
->descent
);
18098 glyph
->padding_p
= 0;
18099 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18100 glyph
->face_id
= it
->face_id
;
18101 glyph
->u
.ch
= it
->char_to_display
;
18102 glyph
->slice
= null_glyph_slice
;
18103 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18104 ++it
->glyph_row
->used
[area
];
18108 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18109 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18112 append_composite_glyph (it
)
18115 struct glyph
*glyph
;
18116 enum glyph_row_area area
= it
->area
;
18118 xassert (it
->glyph_row
);
18120 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18121 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18123 glyph
->charpos
= CHARPOS (it
->position
);
18124 glyph
->object
= it
->object
;
18125 glyph
->pixel_width
= it
->pixel_width
;
18126 glyph
->ascent
= it
->ascent
;
18127 glyph
->descent
= it
->descent
;
18128 glyph
->voffset
= it
->voffset
;
18129 glyph
->type
= COMPOSITE_GLYPH
;
18130 glyph
->multibyte_p
= it
->multibyte_p
;
18131 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18132 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18133 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18134 || it
->phys_descent
> it
->descent
);
18135 glyph
->padding_p
= 0;
18136 glyph
->glyph_not_available_p
= 0;
18137 glyph
->face_id
= it
->face_id
;
18138 glyph
->u
.cmp_id
= it
->cmp_id
;
18139 glyph
->slice
= null_glyph_slice
;
18140 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18141 ++it
->glyph_row
->used
[area
];
18146 /* Change IT->ascent and IT->height according to the setting of
18150 take_vertical_position_into_account (it
)
18155 if (it
->voffset
< 0)
18156 /* Increase the ascent so that we can display the text higher
18158 it
->ascent
-= it
->voffset
;
18160 /* Increase the descent so that we can display the text lower
18162 it
->descent
+= it
->voffset
;
18167 /* Produce glyphs/get display metrics for the image IT is loaded with.
18168 See the description of struct display_iterator in dispextern.h for
18169 an overview of struct display_iterator. */
18172 produce_image_glyph (it
)
18177 int face_ascent
, glyph_ascent
;
18178 struct glyph_slice slice
;
18180 xassert (it
->what
== IT_IMAGE
);
18182 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18184 /* Make sure X resources of the face is loaded. */
18185 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18187 if (it
->image_id
< 0)
18189 /* Fringe bitmap. */
18190 it
->ascent
= it
->phys_ascent
= 0;
18191 it
->descent
= it
->phys_descent
= 0;
18192 it
->pixel_width
= 0;
18197 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18199 /* Make sure X resources of the image is loaded. */
18200 prepare_image_for_display (it
->f
, img
);
18202 slice
.x
= slice
.y
= 0;
18203 slice
.width
= img
->width
;
18204 slice
.height
= img
->height
;
18206 if (INTEGERP (it
->slice
.x
))
18207 slice
.x
= XINT (it
->slice
.x
);
18208 else if (FLOATP (it
->slice
.x
))
18209 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18211 if (INTEGERP (it
->slice
.y
))
18212 slice
.y
= XINT (it
->slice
.y
);
18213 else if (FLOATP (it
->slice
.y
))
18214 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18216 if (INTEGERP (it
->slice
.width
))
18217 slice
.width
= XINT (it
->slice
.width
);
18218 else if (FLOATP (it
->slice
.width
))
18219 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18221 if (INTEGERP (it
->slice
.height
))
18222 slice
.height
= XINT (it
->slice
.height
);
18223 else if (FLOATP (it
->slice
.height
))
18224 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18226 if (slice
.x
>= img
->width
)
18227 slice
.x
= img
->width
;
18228 if (slice
.y
>= img
->height
)
18229 slice
.y
= img
->height
;
18230 if (slice
.x
+ slice
.width
>= img
->width
)
18231 slice
.width
= img
->width
- slice
.x
;
18232 if (slice
.y
+ slice
.height
> img
->height
)
18233 slice
.height
= img
->height
- slice
.y
;
18235 if (slice
.width
== 0 || slice
.height
== 0)
18238 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18240 it
->descent
= slice
.height
- glyph_ascent
;
18242 it
->descent
+= img
->vmargin
;
18243 if (slice
.y
+ slice
.height
== img
->height
)
18244 it
->descent
+= img
->vmargin
;
18245 it
->phys_descent
= it
->descent
;
18247 it
->pixel_width
= slice
.width
;
18249 it
->pixel_width
+= img
->hmargin
;
18250 if (slice
.x
+ slice
.width
== img
->width
)
18251 it
->pixel_width
+= img
->hmargin
;
18253 /* It's quite possible for images to have an ascent greater than
18254 their height, so don't get confused in that case. */
18255 if (it
->descent
< 0)
18258 #if 0 /* this breaks image tiling */
18259 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18260 face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18261 if (face_ascent
> it
->ascent
)
18262 it
->ascent
= it
->phys_ascent
= face_ascent
;
18267 if (face
->box
!= FACE_NO_BOX
)
18269 if (face
->box_line_width
> 0)
18272 it
->ascent
+= face
->box_line_width
;
18273 if (slice
.y
+ slice
.height
== img
->height
)
18274 it
->descent
+= face
->box_line_width
;
18277 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18278 it
->pixel_width
+= abs (face
->box_line_width
);
18279 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18280 it
->pixel_width
+= abs (face
->box_line_width
);
18283 take_vertical_position_into_account (it
);
18287 struct glyph
*glyph
;
18288 enum glyph_row_area area
= it
->area
;
18290 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18291 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18293 glyph
->charpos
= CHARPOS (it
->position
);
18294 glyph
->object
= it
->object
;
18295 glyph
->pixel_width
= it
->pixel_width
;
18296 glyph
->ascent
= glyph_ascent
;
18297 glyph
->descent
= it
->descent
;
18298 glyph
->voffset
= it
->voffset
;
18299 glyph
->type
= IMAGE_GLYPH
;
18300 glyph
->multibyte_p
= it
->multibyte_p
;
18301 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18302 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18303 glyph
->overlaps_vertically_p
= 0;
18304 glyph
->padding_p
= 0;
18305 glyph
->glyph_not_available_p
= 0;
18306 glyph
->face_id
= it
->face_id
;
18307 glyph
->u
.img_id
= img
->id
;
18308 glyph
->slice
= slice
;
18309 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18310 ++it
->glyph_row
->used
[area
];
18316 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18317 of the glyph, WIDTH and HEIGHT are the width and height of the
18318 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18321 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18323 Lisp_Object object
;
18327 struct glyph
*glyph
;
18328 enum glyph_row_area area
= it
->area
;
18330 xassert (ascent
>= 0 && ascent
<= height
);
18332 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18333 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18335 glyph
->charpos
= CHARPOS (it
->position
);
18336 glyph
->object
= object
;
18337 glyph
->pixel_width
= width
;
18338 glyph
->ascent
= ascent
;
18339 glyph
->descent
= height
- ascent
;
18340 glyph
->voffset
= it
->voffset
;
18341 glyph
->type
= STRETCH_GLYPH
;
18342 glyph
->multibyte_p
= it
->multibyte_p
;
18343 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18344 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18345 glyph
->overlaps_vertically_p
= 0;
18346 glyph
->padding_p
= 0;
18347 glyph
->glyph_not_available_p
= 0;
18348 glyph
->face_id
= it
->face_id
;
18349 glyph
->u
.stretch
.ascent
= ascent
;
18350 glyph
->u
.stretch
.height
= height
;
18351 glyph
->slice
= null_glyph_slice
;
18352 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18353 ++it
->glyph_row
->used
[area
];
18358 /* Produce a stretch glyph for iterator IT. IT->object is the value
18359 of the glyph property displayed. The value must be a list
18360 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18363 1. `:width WIDTH' specifies that the space should be WIDTH *
18364 canonical char width wide. WIDTH may be an integer or floating
18367 2. `:relative-width FACTOR' specifies that the width of the stretch
18368 should be computed from the width of the first character having the
18369 `glyph' property, and should be FACTOR times that width.
18371 3. `:align-to HPOS' specifies that the space should be wide enough
18372 to reach HPOS, a value in canonical character units.
18374 Exactly one of the above pairs must be present.
18376 4. `:height HEIGHT' specifies that the height of the stretch produced
18377 should be HEIGHT, measured in canonical character units.
18379 5. `:relative-height FACTOR' specifies that the height of the
18380 stretch should be FACTOR times the height of the characters having
18381 the glyph property.
18383 Either none or exactly one of 4 or 5 must be present.
18385 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18386 of the stretch should be used for the ascent of the stretch.
18387 ASCENT must be in the range 0 <= ASCENT <= 100. */
18390 produce_stretch_glyph (it
)
18393 /* (space :width WIDTH :height HEIGHT ...) */
18394 Lisp_Object prop
, plist
;
18395 int width
= 0, height
= 0, align_to
= -1;
18396 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18399 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18400 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18402 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18404 /* List should start with `space'. */
18405 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18406 plist
= XCDR (it
->object
);
18408 /* Compute the width of the stretch. */
18409 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
18410 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18412 /* Absolute width `:width WIDTH' specified and valid. */
18413 zero_width_ok_p
= 1;
18416 else if (prop
= Fplist_get (plist
, QCrelative_width
),
18419 /* Relative width `:relative-width FACTOR' specified and valid.
18420 Compute the width of the characters having the `glyph'
18423 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18426 if (it
->multibyte_p
)
18428 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18429 - IT_BYTEPOS (*it
));
18430 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18433 it2
.c
= *p
, it2
.len
= 1;
18435 it2
.glyph_row
= NULL
;
18436 it2
.what
= IT_CHARACTER
;
18437 x_produce_glyphs (&it2
);
18438 width
= NUMVAL (prop
) * it2
.pixel_width
;
18440 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
18441 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18443 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18444 align_to
= (align_to
< 0
18446 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18447 else if (align_to
< 0)
18448 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18449 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18450 zero_width_ok_p
= 1;
18453 /* Nothing specified -> width defaults to canonical char width. */
18454 width
= FRAME_COLUMN_WIDTH (it
->f
);
18456 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18459 /* Compute height. */
18460 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
18461 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18464 zero_height_ok_p
= 1;
18466 else if (prop
= Fplist_get (plist
, QCrelative_height
),
18468 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18470 height
= FONT_HEIGHT (font
);
18472 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18475 /* Compute percentage of height used for ascent. If
18476 `:ascent ASCENT' is present and valid, use that. Otherwise,
18477 derive the ascent from the font in use. */
18478 if (prop
= Fplist_get (plist
, QCascent
),
18479 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18480 ascent
= height
* NUMVAL (prop
) / 100.0;
18481 else if (!NILP (prop
)
18482 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18483 ascent
= min (max (0, (int)tem
), height
);
18485 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18487 if (width
> 0 && height
> 0 && it
->glyph_row
)
18489 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18490 if (!STRINGP (object
))
18491 object
= it
->w
->buffer
;
18492 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18495 it
->pixel_width
= width
;
18496 it
->ascent
= it
->phys_ascent
= ascent
;
18497 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18498 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18500 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18502 if (face
->box_line_width
> 0)
18504 it
->ascent
+= face
->box_line_width
;
18505 it
->descent
+= face
->box_line_width
;
18508 if (it
->start_of_box_run_p
)
18509 it
->pixel_width
+= abs (face
->box_line_width
);
18510 if (it
->end_of_box_run_p
)
18511 it
->pixel_width
+= abs (face
->box_line_width
);
18514 take_vertical_position_into_account (it
);
18517 /* Calculate line-height and line-spacing properties.
18518 An integer value specifies explicit pixel value.
18519 A float value specifies relative value to current face height.
18520 A cons (float . face-name) specifies relative value to
18521 height of specified face font.
18523 Returns height in pixels, or nil. */
18526 calc_line_height_property (it
, prop
, font
, boff
, total
)
18533 Lisp_Object face_name
= Qnil
;
18534 int ascent
, descent
, height
, override
;
18536 val
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
18542 if (total
&& CONSP (val
) && EQ (XCAR (val
), Qtotal
))
18548 if (INTEGERP (val
))
18553 face_name
= XCDR (val
);
18556 else if (SYMBOLP (val
))
18562 override
= EQ (prop
, Qline_height
);
18564 if (NILP (face_name
))
18566 font
= FRAME_FONT (it
->f
);
18567 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18569 else if (EQ (face_name
, Qt
))
18577 struct font_info
*font_info
;
18579 face_id
= lookup_named_face (it
->f
, face_name
, ' ');
18581 return make_number (-1);
18583 face
= FACE_FROM_ID (it
->f
, face_id
);
18586 return make_number (-1);
18588 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18589 boff
= font_info
->baseline_offset
;
18590 if (font_info
->vertical_centering
)
18591 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18594 ascent
= FONT_BASE (font
) + boff
;
18595 descent
= FONT_DESCENT (font
) - boff
;
18599 it
->override_ascent
= ascent
;
18600 it
->override_descent
= descent
;
18601 it
->override_boff
= boff
;
18604 height
= ascent
+ descent
;
18606 height
= (int)(XFLOAT_DATA (val
) * height
);
18607 else if (INTEGERP (val
))
18608 height
*= XINT (val
);
18610 return make_number (height
);
18615 Produce glyphs/get display metrics for the display element IT is
18616 loaded with. See the description of struct display_iterator in
18617 dispextern.h for an overview of struct display_iterator. */
18620 x_produce_glyphs (it
)
18623 int extra_line_spacing
= it
->extra_line_spacing
;
18625 it
->glyph_not_available_p
= 0;
18627 if (it
->what
== IT_CHARACTER
)
18631 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18633 int font_not_found_p
;
18634 struct font_info
*font_info
;
18635 int boff
; /* baseline offset */
18636 /* We may change it->multibyte_p upon unibyte<->multibyte
18637 conversion. So, save the current value now and restore it
18640 Note: It seems that we don't have to record multibyte_p in
18641 struct glyph because the character code itself tells if or
18642 not the character is multibyte. Thus, in the future, we must
18643 consider eliminating the field `multibyte_p' in the struct
18645 int saved_multibyte_p
= it
->multibyte_p
;
18647 /* Maybe translate single-byte characters to multibyte, or the
18649 it
->char_to_display
= it
->c
;
18650 if (!ASCII_BYTE_P (it
->c
))
18652 if (unibyte_display_via_language_environment
18653 && SINGLE_BYTE_CHAR_P (it
->c
)
18655 || !NILP (Vnonascii_translation_table
)))
18657 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18658 it
->multibyte_p
= 1;
18659 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18660 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18662 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18663 && !it
->multibyte_p
)
18665 it
->multibyte_p
= 1;
18666 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18667 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18671 /* Get font to use. Encode IT->char_to_display. */
18672 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18673 &char2b
, it
->multibyte_p
, 0);
18676 /* When no suitable font found, use the default font. */
18677 font_not_found_p
= font
== NULL
;
18678 if (font_not_found_p
)
18680 font
= FRAME_FONT (it
->f
);
18681 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18686 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18687 boff
= font_info
->baseline_offset
;
18688 if (font_info
->vertical_centering
)
18689 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18692 if (it
->char_to_display
>= ' '
18693 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18695 /* Either unibyte or ASCII. */
18700 pcm
= rif
->per_char_metric (font
, &char2b
,
18701 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18703 if (it
->override_ascent
>= 0)
18705 it
->ascent
= it
->override_ascent
;
18706 it
->descent
= it
->override_descent
;
18707 boff
= it
->override_boff
;
18711 it
->ascent
= FONT_BASE (font
) + boff
;
18712 it
->descent
= FONT_DESCENT (font
) - boff
;
18717 it
->phys_ascent
= pcm
->ascent
+ boff
;
18718 it
->phys_descent
= pcm
->descent
- boff
;
18719 it
->pixel_width
= pcm
->width
;
18723 it
->glyph_not_available_p
= 1;
18724 it
->phys_ascent
= it
->ascent
;
18725 it
->phys_descent
= it
->descent
;
18726 it
->pixel_width
= FONT_WIDTH (font
);
18729 if (it
->constrain_row_ascent_descent_p
)
18731 if (it
->descent
> it
->max_descent
)
18733 it
->ascent
+= it
->descent
- it
->max_descent
;
18734 it
->descent
= it
->max_descent
;
18736 if (it
->ascent
> it
->max_ascent
)
18738 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
18739 it
->ascent
= it
->max_ascent
;
18741 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
18742 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
18743 extra_line_spacing
= 0;
18746 /* If this is a space inside a region of text with
18747 `space-width' property, change its width. */
18748 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18750 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18752 /* If face has a box, add the box thickness to the character
18753 height. If character has a box line to the left and/or
18754 right, add the box line width to the character's width. */
18755 if (face
->box
!= FACE_NO_BOX
)
18757 int thick
= face
->box_line_width
;
18761 it
->ascent
+= thick
;
18762 it
->descent
+= thick
;
18767 if (it
->start_of_box_run_p
)
18768 it
->pixel_width
+= thick
;
18769 if (it
->end_of_box_run_p
)
18770 it
->pixel_width
+= thick
;
18773 /* If face has an overline, add the height of the overline
18774 (1 pixel) and a 1 pixel margin to the character height. */
18775 if (face
->overline_p
)
18778 if (it
->constrain_row_ascent_descent_p
)
18780 if (it
->ascent
> it
->max_ascent
)
18781 it
->ascent
= it
->max_ascent
;
18782 if (it
->descent
> it
->max_descent
)
18783 it
->descent
= it
->max_descent
;
18786 take_vertical_position_into_account (it
);
18788 /* If we have to actually produce glyphs, do it. */
18793 /* Translate a space with a `space-width' property
18794 into a stretch glyph. */
18795 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
18796 / FONT_HEIGHT (font
));
18797 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18798 it
->ascent
+ it
->descent
, ascent
);
18803 /* If characters with lbearing or rbearing are displayed
18804 in this line, record that fact in a flag of the
18805 glyph row. This is used to optimize X output code. */
18806 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
18807 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18810 else if (it
->char_to_display
== '\n')
18812 /* A newline has no width but we need the height of the line.
18813 But if previous part of the line set a height, don't
18814 increase that height */
18816 Lisp_Object height
;
18818 it
->override_ascent
= -1;
18819 it
->pixel_width
= 0;
18822 height
= calc_line_height_property(it
, Qline_height
, font
, boff
, 0);
18824 if (it
->override_ascent
>= 0)
18826 it
->ascent
= it
->override_ascent
;
18827 it
->descent
= it
->override_descent
;
18828 boff
= it
->override_boff
;
18832 it
->ascent
= FONT_BASE (font
) + boff
;
18833 it
->descent
= FONT_DESCENT (font
) - boff
;
18836 if (EQ (height
, make_number(0)))
18838 if (it
->descent
> it
->max_descent
)
18840 it
->ascent
+= it
->descent
- it
->max_descent
;
18841 it
->descent
= it
->max_descent
;
18843 if (it
->ascent
> it
->max_ascent
)
18845 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
18846 it
->ascent
= it
->max_ascent
;
18848 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
18849 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
18850 it
->constrain_row_ascent_descent_p
= 1;
18851 extra_line_spacing
= 0;
18855 Lisp_Object spacing
;
18858 it
->phys_ascent
= it
->ascent
;
18859 it
->phys_descent
= it
->descent
;
18861 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
18862 && face
->box
!= FACE_NO_BOX
18863 && face
->box_line_width
> 0)
18865 it
->ascent
+= face
->box_line_width
;
18866 it
->descent
+= face
->box_line_width
;
18869 && XINT (height
) > it
->ascent
+ it
->descent
)
18870 it
->ascent
= XINT (height
) - it
->descent
;
18872 spacing
= calc_line_height_property(it
, Qline_spacing
, font
, boff
, &total
);
18873 if (INTEGERP (spacing
))
18875 extra_line_spacing
= XINT (spacing
);
18877 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
18881 else if (it
->char_to_display
== '\t')
18883 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
18884 int x
= it
->current_x
+ it
->continuation_lines_width
;
18885 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
18887 /* If the distance from the current position to the next tab
18888 stop is less than a canonical character width, use the
18889 tab stop after that. */
18890 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
18891 next_tab_x
+= tab_width
;
18893 it
->pixel_width
= next_tab_x
- x
;
18895 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
18896 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18900 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
18901 it
->ascent
+ it
->descent
, it
->ascent
);
18906 /* A multi-byte character. Assume that the display width of the
18907 character is the width of the character multiplied by the
18908 width of the font. */
18910 /* If we found a font, this font should give us the right
18911 metrics. If we didn't find a font, use the frame's
18912 default font and calculate the width of the character
18913 from the charset width; this is what old redisplay code
18916 pcm
= rif
->per_char_metric (font
, &char2b
,
18917 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18919 if (font_not_found_p
|| !pcm
)
18921 int charset
= CHAR_CHARSET (it
->char_to_display
);
18923 it
->glyph_not_available_p
= 1;
18924 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18925 * CHARSET_WIDTH (charset
));
18926 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18927 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18931 it
->pixel_width
= pcm
->width
;
18932 it
->phys_ascent
= pcm
->ascent
+ boff
;
18933 it
->phys_descent
= pcm
->descent
- boff
;
18935 && (pcm
->lbearing
< 0
18936 || pcm
->rbearing
> pcm
->width
))
18937 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18940 it
->ascent
= FONT_BASE (font
) + boff
;
18941 it
->descent
= FONT_DESCENT (font
) - boff
;
18942 if (face
->box
!= FACE_NO_BOX
)
18944 int thick
= face
->box_line_width
;
18948 it
->ascent
+= thick
;
18949 it
->descent
+= thick
;
18954 if (it
->start_of_box_run_p
)
18955 it
->pixel_width
+= thick
;
18956 if (it
->end_of_box_run_p
)
18957 it
->pixel_width
+= thick
;
18960 /* If face has an overline, add the height of the overline
18961 (1 pixel) and a 1 pixel margin to the character height. */
18962 if (face
->overline_p
)
18965 take_vertical_position_into_account (it
);
18970 it
->multibyte_p
= saved_multibyte_p
;
18972 else if (it
->what
== IT_COMPOSITION
)
18974 /* Note: A composition is represented as one glyph in the
18975 glyph matrix. There are no padding glyphs. */
18978 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18980 int font_not_found_p
;
18981 struct font_info
*font_info
;
18982 int boff
; /* baseline offset */
18983 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18985 /* Maybe translate single-byte characters to multibyte. */
18986 it
->char_to_display
= it
->c
;
18987 if (unibyte_display_via_language_environment
18988 && SINGLE_BYTE_CHAR_P (it
->c
)
18991 && !NILP (Vnonascii_translation_table
))))
18993 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18996 /* Get face and font to use. Encode IT->char_to_display. */
18997 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18998 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18999 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19000 &char2b
, it
->multibyte_p
, 0);
19003 /* When no suitable font found, use the default font. */
19004 font_not_found_p
= font
== NULL
;
19005 if (font_not_found_p
)
19007 font
= FRAME_FONT (it
->f
);
19008 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19013 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19014 boff
= font_info
->baseline_offset
;
19015 if (font_info
->vertical_centering
)
19016 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19019 /* There are no padding glyphs, so there is only one glyph to
19020 produce for the composition. Important is that pixel_width,
19021 ascent and descent are the values of what is drawn by
19022 draw_glyphs (i.e. the values of the overall glyphs composed). */
19025 /* If we have not yet calculated pixel size data of glyphs of
19026 the composition for the current face font, calculate them
19027 now. Theoretically, we have to check all fonts for the
19028 glyphs, but that requires much time and memory space. So,
19029 here we check only the font of the first glyph. This leads
19030 to incorrect display very rarely, and C-l (recenter) can
19031 correct the display anyway. */
19032 if (cmp
->font
!= (void *) font
)
19034 /* Ascent and descent of the font of the first character of
19035 this composition (adjusted by baseline offset). Ascent
19036 and descent of overall glyphs should not be less than
19037 them respectively. */
19038 int font_ascent
= FONT_BASE (font
) + boff
;
19039 int font_descent
= FONT_DESCENT (font
) - boff
;
19040 /* Bounding box of the overall glyphs. */
19041 int leftmost
, rightmost
, lowest
, highest
;
19042 int i
, width
, ascent
, descent
;
19044 cmp
->font
= (void *) font
;
19046 /* Initialize the bounding box. */
19048 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19049 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19051 width
= pcm
->width
;
19052 ascent
= pcm
->ascent
;
19053 descent
= pcm
->descent
;
19057 width
= FONT_WIDTH (font
);
19058 ascent
= FONT_BASE (font
);
19059 descent
= FONT_DESCENT (font
);
19063 lowest
= - descent
+ boff
;
19064 highest
= ascent
+ boff
;
19068 && font_info
->default_ascent
19069 && CHAR_TABLE_P (Vuse_default_ascent
)
19070 && !NILP (Faref (Vuse_default_ascent
,
19071 make_number (it
->char_to_display
))))
19072 highest
= font_info
->default_ascent
+ boff
;
19074 /* Draw the first glyph at the normal position. It may be
19075 shifted to right later if some other glyphs are drawn at
19077 cmp
->offsets
[0] = 0;
19078 cmp
->offsets
[1] = boff
;
19080 /* Set cmp->offsets for the remaining glyphs. */
19081 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19083 int left
, right
, btm
, top
;
19084 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19085 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19087 face
= FACE_FROM_ID (it
->f
, face_id
);
19088 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19089 &char2b
, it
->multibyte_p
, 0);
19093 font
= FRAME_FONT (it
->f
);
19094 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19100 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19101 boff
= font_info
->baseline_offset
;
19102 if (font_info
->vertical_centering
)
19103 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19107 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19108 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19110 width
= pcm
->width
;
19111 ascent
= pcm
->ascent
;
19112 descent
= pcm
->descent
;
19116 width
= FONT_WIDTH (font
);
19121 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19123 /* Relative composition with or without
19124 alternate chars. */
19125 left
= (leftmost
+ rightmost
- width
) / 2;
19126 btm
= - descent
+ boff
;
19127 if (font_info
&& font_info
->relative_compose
19128 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19129 || NILP (Faref (Vignore_relative_composition
,
19130 make_number (ch
)))))
19133 if (- descent
>= font_info
->relative_compose
)
19134 /* One extra pixel between two glyphs. */
19136 else if (ascent
<= 0)
19137 /* One extra pixel between two glyphs. */
19138 btm
= lowest
- 1 - ascent
- descent
;
19143 /* A composition rule is specified by an integer
19144 value that encodes global and new reference
19145 points (GREF and NREF). GREF and NREF are
19146 specified by numbers as below:
19148 0---1---2 -- ascent
19152 9--10--11 -- center
19154 ---3---4---5--- baseline
19156 6---7---8 -- descent
19158 int rule
= COMPOSITION_RULE (cmp
, i
);
19159 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19161 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19162 grefx
= gref
% 3, nrefx
= nref
% 3;
19163 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19166 + grefx
* (rightmost
- leftmost
) / 2
19167 - nrefx
* width
/ 2);
19168 btm
= ((grefy
== 0 ? highest
19170 : grefy
== 2 ? lowest
19171 : (highest
+ lowest
) / 2)
19172 - (nrefy
== 0 ? ascent
+ descent
19173 : nrefy
== 1 ? descent
- boff
19175 : (ascent
+ descent
) / 2));
19178 cmp
->offsets
[i
* 2] = left
;
19179 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19181 /* Update the bounding box of the overall glyphs. */
19182 right
= left
+ width
;
19183 top
= btm
+ descent
+ ascent
;
19184 if (left
< leftmost
)
19186 if (right
> rightmost
)
19194 /* If there are glyphs whose x-offsets are negative,
19195 shift all glyphs to the right and make all x-offsets
19199 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19200 cmp
->offsets
[i
* 2] -= leftmost
;
19201 rightmost
-= leftmost
;
19204 cmp
->pixel_width
= rightmost
;
19205 cmp
->ascent
= highest
;
19206 cmp
->descent
= - lowest
;
19207 if (cmp
->ascent
< font_ascent
)
19208 cmp
->ascent
= font_ascent
;
19209 if (cmp
->descent
< font_descent
)
19210 cmp
->descent
= font_descent
;
19213 it
->pixel_width
= cmp
->pixel_width
;
19214 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19215 it
->descent
= it
->phys_descent
= cmp
->descent
;
19217 if (face
->box
!= FACE_NO_BOX
)
19219 int thick
= face
->box_line_width
;
19223 it
->ascent
+= thick
;
19224 it
->descent
+= thick
;
19229 if (it
->start_of_box_run_p
)
19230 it
->pixel_width
+= thick
;
19231 if (it
->end_of_box_run_p
)
19232 it
->pixel_width
+= thick
;
19235 /* If face has an overline, add the height of the overline
19236 (1 pixel) and a 1 pixel margin to the character height. */
19237 if (face
->overline_p
)
19240 take_vertical_position_into_account (it
);
19243 append_composite_glyph (it
);
19245 else if (it
->what
== IT_IMAGE
)
19246 produce_image_glyph (it
);
19247 else if (it
->what
== IT_STRETCH
)
19248 produce_stretch_glyph (it
);
19250 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19251 because this isn't true for images with `:ascent 100'. */
19252 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19253 if (it
->area
== TEXT_AREA
)
19254 it
->current_x
+= it
->pixel_width
;
19256 if (extra_line_spacing
> 0)
19257 it
->descent
+= extra_line_spacing
;
19259 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19260 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19261 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19262 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19266 Output LEN glyphs starting at START at the nominal cursor position.
19267 Advance the nominal cursor over the text. The global variable
19268 updated_window contains the window being updated, updated_row is
19269 the glyph row being updated, and updated_area is the area of that
19270 row being updated. */
19273 x_write_glyphs (start
, len
)
19274 struct glyph
*start
;
19279 xassert (updated_window
&& updated_row
);
19282 /* Write glyphs. */
19284 hpos
= start
- updated_row
->glyphs
[updated_area
];
19285 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19286 updated_row
, updated_area
,
19288 DRAW_NORMAL_TEXT
, 0);
19290 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19291 if (updated_area
== TEXT_AREA
19292 && updated_window
->phys_cursor_on_p
19293 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19294 && updated_window
->phys_cursor
.hpos
>= hpos
19295 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19296 updated_window
->phys_cursor_on_p
= 0;
19300 /* Advance the output cursor. */
19301 output_cursor
.hpos
+= len
;
19302 output_cursor
.x
= x
;
19307 Insert LEN glyphs from START at the nominal cursor position. */
19310 x_insert_glyphs (start
, len
)
19311 struct glyph
*start
;
19316 int line_height
, shift_by_width
, shifted_region_width
;
19317 struct glyph_row
*row
;
19318 struct glyph
*glyph
;
19319 int frame_x
, frame_y
, hpos
;
19321 xassert (updated_window
&& updated_row
);
19323 w
= updated_window
;
19324 f
= XFRAME (WINDOW_FRAME (w
));
19326 /* Get the height of the line we are in. */
19328 line_height
= row
->height
;
19330 /* Get the width of the glyphs to insert. */
19331 shift_by_width
= 0;
19332 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19333 shift_by_width
+= glyph
->pixel_width
;
19335 /* Get the width of the region to shift right. */
19336 shifted_region_width
= (window_box_width (w
, updated_area
)
19341 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19342 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19344 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19345 line_height
, shift_by_width
);
19347 /* Write the glyphs. */
19348 hpos
= start
- row
->glyphs
[updated_area
];
19349 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19351 DRAW_NORMAL_TEXT
, 0);
19353 /* Advance the output cursor. */
19354 output_cursor
.hpos
+= len
;
19355 output_cursor
.x
+= shift_by_width
;
19361 Erase the current text line from the nominal cursor position
19362 (inclusive) to pixel column TO_X (exclusive). The idea is that
19363 everything from TO_X onward is already erased.
19365 TO_X is a pixel position relative to updated_area of
19366 updated_window. TO_X == -1 means clear to the end of this area. */
19369 x_clear_end_of_line (to_x
)
19373 struct window
*w
= updated_window
;
19374 int max_x
, min_y
, max_y
;
19375 int from_x
, from_y
, to_y
;
19377 xassert (updated_window
&& updated_row
);
19378 f
= XFRAME (w
->frame
);
19380 if (updated_row
->full_width_p
)
19381 max_x
= WINDOW_TOTAL_WIDTH (w
);
19383 max_x
= window_box_width (w
, updated_area
);
19384 max_y
= window_text_bottom_y (w
);
19386 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19387 of window. For TO_X > 0, truncate to end of drawing area. */
19393 to_x
= min (to_x
, max_x
);
19395 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19397 /* Notice if the cursor will be cleared by this operation. */
19398 if (!updated_row
->full_width_p
)
19399 notice_overwritten_cursor (w
, updated_area
,
19400 output_cursor
.x
, -1,
19402 MATRIX_ROW_BOTTOM_Y (updated_row
));
19404 from_x
= output_cursor
.x
;
19406 /* Translate to frame coordinates. */
19407 if (updated_row
->full_width_p
)
19409 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19410 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19414 int area_left
= window_box_left (w
, updated_area
);
19415 from_x
+= area_left
;
19419 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19420 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19421 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19423 /* Prevent inadvertently clearing to end of the X window. */
19424 if (to_x
> from_x
&& to_y
> from_y
)
19427 rif
->clear_frame_area (f
, from_x
, from_y
,
19428 to_x
- from_x
, to_y
- from_y
);
19433 #endif /* HAVE_WINDOW_SYSTEM */
19437 /***********************************************************************
19439 ***********************************************************************/
19441 /* Value is the internal representation of the specified cursor type
19442 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19443 of the bar cursor. */
19445 static enum text_cursor_kinds
19446 get_specified_cursor_type (arg
, width
)
19450 enum text_cursor_kinds type
;
19455 if (EQ (arg
, Qbox
))
19456 return FILLED_BOX_CURSOR
;
19458 if (EQ (arg
, Qhollow
))
19459 return HOLLOW_BOX_CURSOR
;
19461 if (EQ (arg
, Qbar
))
19468 && EQ (XCAR (arg
), Qbar
)
19469 && INTEGERP (XCDR (arg
))
19470 && XINT (XCDR (arg
)) >= 0)
19472 *width
= XINT (XCDR (arg
));
19476 if (EQ (arg
, Qhbar
))
19479 return HBAR_CURSOR
;
19483 && EQ (XCAR (arg
), Qhbar
)
19484 && INTEGERP (XCDR (arg
))
19485 && XINT (XCDR (arg
)) >= 0)
19487 *width
= XINT (XCDR (arg
));
19488 return HBAR_CURSOR
;
19491 /* Treat anything unknown as "hollow box cursor".
19492 It was bad to signal an error; people have trouble fixing
19493 .Xdefaults with Emacs, when it has something bad in it. */
19494 type
= HOLLOW_BOX_CURSOR
;
19499 /* Set the default cursor types for specified frame. */
19501 set_frame_cursor_types (f
, arg
)
19508 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19509 FRAME_CURSOR_WIDTH (f
) = width
;
19511 /* By default, set up the blink-off state depending on the on-state. */
19513 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19516 FRAME_BLINK_OFF_CURSOR (f
)
19517 = get_specified_cursor_type (XCDR (tem
), &width
);
19518 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19521 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19525 /* Return the cursor we want to be displayed in window W. Return
19526 width of bar/hbar cursor through WIDTH arg. Return with
19527 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19528 (i.e. if the `system caret' should track this cursor).
19530 In a mini-buffer window, we want the cursor only to appear if we
19531 are reading input from this window. For the selected window, we
19532 want the cursor type given by the frame parameter or buffer local
19533 setting of cursor-type. If explicitly marked off, draw no cursor.
19534 In all other cases, we want a hollow box cursor. */
19536 static enum text_cursor_kinds
19537 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19539 struct glyph
*glyph
;
19541 int *active_cursor
;
19543 struct frame
*f
= XFRAME (w
->frame
);
19544 struct buffer
*b
= XBUFFER (w
->buffer
);
19545 int cursor_type
= DEFAULT_CURSOR
;
19546 Lisp_Object alt_cursor
;
19547 int non_selected
= 0;
19549 *active_cursor
= 1;
19552 if (cursor_in_echo_area
19553 && FRAME_HAS_MINIBUF_P (f
)
19554 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19556 if (w
== XWINDOW (echo_area_window
))
19558 *width
= FRAME_CURSOR_WIDTH (f
);
19559 return FRAME_DESIRED_CURSOR (f
);
19562 *active_cursor
= 0;
19566 /* Nonselected window or nonselected frame. */
19567 else if (w
!= XWINDOW (f
->selected_window
)
19568 #ifdef HAVE_WINDOW_SYSTEM
19569 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19573 *active_cursor
= 0;
19575 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19581 /* Never display a cursor in a window in which cursor-type is nil. */
19582 if (NILP (b
->cursor_type
))
19585 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19588 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19589 return get_specified_cursor_type (alt_cursor
, width
);
19592 /* Get the normal cursor type for this window. */
19593 if (EQ (b
->cursor_type
, Qt
))
19595 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19596 *width
= FRAME_CURSOR_WIDTH (f
);
19599 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19601 /* Use normal cursor if not blinked off. */
19602 if (!w
->cursor_off_p
)
19604 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19605 if (cursor_type
== FILLED_BOX_CURSOR
)
19606 cursor_type
= HOLLOW_BOX_CURSOR
;
19608 return cursor_type
;
19611 /* Cursor is blinked off, so determine how to "toggle" it. */
19613 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19614 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19615 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19617 /* Then see if frame has specified a specific blink off cursor type. */
19618 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19620 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19621 return FRAME_BLINK_OFF_CURSOR (f
);
19625 /* Some people liked having a permanently visible blinking cursor,
19626 while others had very strong opinions against it. So it was
19627 decided to remove it. KFS 2003-09-03 */
19629 /* Finally perform built-in cursor blinking:
19630 filled box <-> hollow box
19631 wide [h]bar <-> narrow [h]bar
19632 narrow [h]bar <-> no cursor
19633 other type <-> no cursor */
19635 if (cursor_type
== FILLED_BOX_CURSOR
)
19636 return HOLLOW_BOX_CURSOR
;
19638 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19641 return cursor_type
;
19649 #ifdef HAVE_WINDOW_SYSTEM
19651 /* Notice when the text cursor of window W has been completely
19652 overwritten by a drawing operation that outputs glyphs in AREA
19653 starting at X0 and ending at X1 in the line starting at Y0 and
19654 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19655 the rest of the line after X0 has been written. Y coordinates
19656 are window-relative. */
19659 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19661 enum glyph_row_area area
;
19662 int x0
, y0
, x1
, y1
;
19664 int cx0
, cx1
, cy0
, cy1
;
19665 struct glyph_row
*row
;
19667 if (!w
->phys_cursor_on_p
)
19669 if (area
!= TEXT_AREA
)
19672 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19673 if (!row
->displays_text_p
)
19676 if (row
->cursor_in_fringe_p
)
19678 row
->cursor_in_fringe_p
= 0;
19679 draw_fringe_bitmap (w
, row
, 0);
19680 w
->phys_cursor_on_p
= 0;
19684 cx0
= w
->phys_cursor
.x
;
19685 cx1
= cx0
+ w
->phys_cursor_width
;
19686 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19689 /* The cursor image will be completely removed from the
19690 screen if the output area intersects the cursor area in
19691 y-direction. When we draw in [y0 y1[, and some part of
19692 the cursor is at y < y0, that part must have been drawn
19693 before. When scrolling, the cursor is erased before
19694 actually scrolling, so we don't come here. When not
19695 scrolling, the rows above the old cursor row must have
19696 changed, and in this case these rows must have written
19697 over the cursor image.
19699 Likewise if part of the cursor is below y1, with the
19700 exception of the cursor being in the first blank row at
19701 the buffer and window end because update_text_area
19702 doesn't draw that row. (Except when it does, but
19703 that's handled in update_text_area.) */
19705 cy0
= w
->phys_cursor
.y
;
19706 cy1
= cy0
+ w
->phys_cursor_height
;
19707 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19710 w
->phys_cursor_on_p
= 0;
19713 #endif /* HAVE_WINDOW_SYSTEM */
19716 /************************************************************************
19718 ************************************************************************/
19720 #ifdef HAVE_WINDOW_SYSTEM
19723 Fix the display of area AREA of overlapping row ROW in window W. */
19726 x_fix_overlapping_area (w
, row
, area
)
19728 struct glyph_row
*row
;
19729 enum glyph_row_area area
;
19736 for (i
= 0; i
< row
->used
[area
];)
19738 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19740 int start
= i
, start_x
= x
;
19744 x
+= row
->glyphs
[area
][i
].pixel_width
;
19747 while (i
< row
->used
[area
]
19748 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19750 draw_glyphs (w
, start_x
, row
, area
,
19752 DRAW_NORMAL_TEXT
, 1);
19756 x
+= row
->glyphs
[area
][i
].pixel_width
;
19766 Draw the cursor glyph of window W in glyph row ROW. See the
19767 comment of draw_glyphs for the meaning of HL. */
19770 draw_phys_cursor_glyph (w
, row
, hl
)
19772 struct glyph_row
*row
;
19773 enum draw_glyphs_face hl
;
19775 /* If cursor hpos is out of bounds, don't draw garbage. This can
19776 happen in mini-buffer windows when switching between echo area
19777 glyphs and mini-buffer. */
19778 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
19780 int on_p
= w
->phys_cursor_on_p
;
19782 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
19783 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
19785 w
->phys_cursor_on_p
= on_p
;
19787 if (hl
== DRAW_CURSOR
)
19788 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
19789 /* When we erase the cursor, and ROW is overlapped by other
19790 rows, make sure that these overlapping parts of other rows
19792 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
19794 if (row
> w
->current_matrix
->rows
19795 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
19796 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
19798 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
19799 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
19800 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
19807 Erase the image of a cursor of window W from the screen. */
19810 erase_phys_cursor (w
)
19813 struct frame
*f
= XFRAME (w
->frame
);
19814 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19815 int hpos
= w
->phys_cursor
.hpos
;
19816 int vpos
= w
->phys_cursor
.vpos
;
19817 int mouse_face_here_p
= 0;
19818 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
19819 struct glyph_row
*cursor_row
;
19820 struct glyph
*cursor_glyph
;
19821 enum draw_glyphs_face hl
;
19823 /* No cursor displayed or row invalidated => nothing to do on the
19825 if (w
->phys_cursor_type
== NO_CURSOR
)
19826 goto mark_cursor_off
;
19828 /* VPOS >= active_glyphs->nrows means that window has been resized.
19829 Don't bother to erase the cursor. */
19830 if (vpos
>= active_glyphs
->nrows
)
19831 goto mark_cursor_off
;
19833 /* If row containing cursor is marked invalid, there is nothing we
19835 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
19836 if (!cursor_row
->enabled_p
)
19837 goto mark_cursor_off
;
19839 /* If row is completely invisible, don't attempt to delete a cursor which
19840 isn't there. This can happen if cursor is at top of a window, and
19841 we switch to a buffer with a header line in that window. */
19842 if (cursor_row
->visible_height
<= 0)
19843 goto mark_cursor_off
;
19845 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
19846 if (cursor_row
->cursor_in_fringe_p
)
19848 cursor_row
->cursor_in_fringe_p
= 0;
19849 draw_fringe_bitmap (w
, cursor_row
, 0);
19850 goto mark_cursor_off
;
19853 /* This can happen when the new row is shorter than the old one.
19854 In this case, either draw_glyphs or clear_end_of_line
19855 should have cleared the cursor. Note that we wouldn't be
19856 able to erase the cursor in this case because we don't have a
19857 cursor glyph at hand. */
19858 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
19859 goto mark_cursor_off
;
19861 /* If the cursor is in the mouse face area, redisplay that when
19862 we clear the cursor. */
19863 if (! NILP (dpyinfo
->mouse_face_window
)
19864 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
19865 && (vpos
> dpyinfo
->mouse_face_beg_row
19866 || (vpos
== dpyinfo
->mouse_face_beg_row
19867 && hpos
>= dpyinfo
->mouse_face_beg_col
))
19868 && (vpos
< dpyinfo
->mouse_face_end_row
19869 || (vpos
== dpyinfo
->mouse_face_end_row
19870 && hpos
< dpyinfo
->mouse_face_end_col
))
19871 /* Don't redraw the cursor's spot in mouse face if it is at the
19872 end of a line (on a newline). The cursor appears there, but
19873 mouse highlighting does not. */
19874 && cursor_row
->used
[TEXT_AREA
] > hpos
)
19875 mouse_face_here_p
= 1;
19877 /* Maybe clear the display under the cursor. */
19878 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
19881 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
19883 cursor_glyph
= get_phys_cursor_glyph (w
);
19884 if (cursor_glyph
== NULL
)
19885 goto mark_cursor_off
;
19887 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
19888 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
19890 rif
->clear_frame_area (f
, x
, y
,
19891 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
19894 /* Erase the cursor by redrawing the character underneath it. */
19895 if (mouse_face_here_p
)
19896 hl
= DRAW_MOUSE_FACE
;
19898 hl
= DRAW_NORMAL_TEXT
;
19899 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
19902 w
->phys_cursor_on_p
= 0;
19903 w
->phys_cursor_type
= NO_CURSOR
;
19908 Display or clear cursor of window W. If ON is zero, clear the
19909 cursor. If it is non-zero, display the cursor. If ON is nonzero,
19910 where to put the cursor is specified by HPOS, VPOS, X and Y. */
19913 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
19915 int on
, hpos
, vpos
, x
, y
;
19917 struct frame
*f
= XFRAME (w
->frame
);
19918 int new_cursor_type
;
19919 int new_cursor_width
;
19921 struct glyph_row
*glyph_row
;
19922 struct glyph
*glyph
;
19924 /* This is pointless on invisible frames, and dangerous on garbaged
19925 windows and frames; in the latter case, the frame or window may
19926 be in the midst of changing its size, and x and y may be off the
19928 if (! FRAME_VISIBLE_P (f
)
19929 || FRAME_GARBAGED_P (f
)
19930 || vpos
>= w
->current_matrix
->nrows
19931 || hpos
>= w
->current_matrix
->matrix_w
)
19934 /* If cursor is off and we want it off, return quickly. */
19935 if (!on
&& !w
->phys_cursor_on_p
)
19938 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
19939 /* If cursor row is not enabled, we don't really know where to
19940 display the cursor. */
19941 if (!glyph_row
->enabled_p
)
19943 w
->phys_cursor_on_p
= 0;
19948 if (!glyph_row
->exact_window_width_line_p
19949 || hpos
< glyph_row
->used
[TEXT_AREA
])
19950 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
19952 xassert (interrupt_input_blocked
);
19954 /* Set new_cursor_type to the cursor we want to be displayed. */
19955 new_cursor_type
= get_window_cursor_type (w
, glyph
,
19956 &new_cursor_width
, &active_cursor
);
19958 /* If cursor is currently being shown and we don't want it to be or
19959 it is in the wrong place, or the cursor type is not what we want,
19961 if (w
->phys_cursor_on_p
19963 || w
->phys_cursor
.x
!= x
19964 || w
->phys_cursor
.y
!= y
19965 || new_cursor_type
!= w
->phys_cursor_type
19966 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19967 && new_cursor_width
!= w
->phys_cursor_width
)))
19968 erase_phys_cursor (w
);
19970 /* Don't check phys_cursor_on_p here because that flag is only set
19971 to zero in some cases where we know that the cursor has been
19972 completely erased, to avoid the extra work of erasing the cursor
19973 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19974 still not be visible, or it has only been partly erased. */
19977 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19978 w
->phys_cursor_height
= glyph_row
->height
;
19980 /* Set phys_cursor_.* before x_draw_.* is called because some
19981 of them may need the information. */
19982 w
->phys_cursor
.x
= x
;
19983 w
->phys_cursor
.y
= glyph_row
->y
;
19984 w
->phys_cursor
.hpos
= hpos
;
19985 w
->phys_cursor
.vpos
= vpos
;
19988 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
19989 new_cursor_type
, new_cursor_width
,
19990 on
, active_cursor
);
19994 /* Switch the display of W's cursor on or off, according to the value
19998 update_window_cursor (w
, on
)
20002 /* Don't update cursor in windows whose frame is in the process
20003 of being deleted. */
20004 if (w
->current_matrix
)
20007 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20008 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20014 /* Call update_window_cursor with parameter ON_P on all leaf windows
20015 in the window tree rooted at W. */
20018 update_cursor_in_window_tree (w
, on_p
)
20024 if (!NILP (w
->hchild
))
20025 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20026 else if (!NILP (w
->vchild
))
20027 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20029 update_window_cursor (w
, on_p
);
20031 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20037 Display the cursor on window W, or clear it, according to ON_P.
20038 Don't change the cursor's position. */
20041 x_update_cursor (f
, on_p
)
20045 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20050 Clear the cursor of window W to background color, and mark the
20051 cursor as not shown. This is used when the text where the cursor
20052 is is about to be rewritten. */
20058 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20059 update_window_cursor (w
, 0);
20064 Display the active region described by mouse_face_* according to DRAW. */
20067 show_mouse_face (dpyinfo
, draw
)
20068 Display_Info
*dpyinfo
;
20069 enum draw_glyphs_face draw
;
20071 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20072 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20074 if (/* If window is in the process of being destroyed, don't bother
20076 w
->current_matrix
!= NULL
20077 /* Don't update mouse highlight if hidden */
20078 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20079 /* Recognize when we are called to operate on rows that don't exist
20080 anymore. This can happen when a window is split. */
20081 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20083 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20084 struct glyph_row
*row
, *first
, *last
;
20086 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20087 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20089 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20091 int start_hpos
, end_hpos
, start_x
;
20093 /* For all but the first row, the highlight starts at column 0. */
20096 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20097 start_x
= dpyinfo
->mouse_face_beg_x
;
20106 end_hpos
= dpyinfo
->mouse_face_end_col
;
20108 end_hpos
= row
->used
[TEXT_AREA
];
20110 if (end_hpos
> start_hpos
)
20112 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20113 start_hpos
, end_hpos
,
20117 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20121 /* When we've written over the cursor, arrange for it to
20122 be displayed again. */
20123 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20126 display_and_set_cursor (w
, 1,
20127 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20128 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20133 /* Change the mouse cursor. */
20134 if (draw
== DRAW_NORMAL_TEXT
)
20135 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20136 else if (draw
== DRAW_MOUSE_FACE
)
20137 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20139 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20143 Clear out the mouse-highlighted active region.
20144 Redraw it un-highlighted first. Value is non-zero if mouse
20145 face was actually drawn unhighlighted. */
20148 clear_mouse_face (dpyinfo
)
20149 Display_Info
*dpyinfo
;
20153 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20155 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20159 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20160 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20161 dpyinfo
->mouse_face_window
= Qnil
;
20162 dpyinfo
->mouse_face_overlay
= Qnil
;
20168 Non-zero if physical cursor of window W is within mouse face. */
20171 cursor_in_mouse_face_p (w
)
20174 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20175 int in_mouse_face
= 0;
20177 if (WINDOWP (dpyinfo
->mouse_face_window
)
20178 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20180 int hpos
= w
->phys_cursor
.hpos
;
20181 int vpos
= w
->phys_cursor
.vpos
;
20183 if (vpos
>= dpyinfo
->mouse_face_beg_row
20184 && vpos
<= dpyinfo
->mouse_face_end_row
20185 && (vpos
> dpyinfo
->mouse_face_beg_row
20186 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20187 && (vpos
< dpyinfo
->mouse_face_end_row
20188 || hpos
< dpyinfo
->mouse_face_end_col
20189 || dpyinfo
->mouse_face_past_end
))
20193 return in_mouse_face
;
20199 /* Find the glyph matrix position of buffer position CHARPOS in window
20200 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20201 current glyphs must be up to date. If CHARPOS is above window
20202 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20203 of last line in W. In the row containing CHARPOS, stop before glyphs
20204 having STOP as object. */
20206 #if 1 /* This is a version of fast_find_position that's more correct
20207 in the presence of hscrolling, for example. I didn't install
20208 it right away because the problem fixed is minor, it failed
20209 in 20.x as well, and I think it's too risky to install
20210 so near the release of 21.1. 2001-09-25 gerd. */
20213 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20216 int *hpos
, *vpos
, *x
, *y
;
20219 struct glyph_row
*row
, *first
;
20220 struct glyph
*glyph
, *end
;
20223 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20224 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20227 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20229 *x
= *y
= *hpos
= *vpos
= 0;
20234 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20241 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20243 glyph
= row
->glyphs
[TEXT_AREA
];
20244 end
= glyph
+ row
->used
[TEXT_AREA
];
20246 /* Skip over glyphs not having an object at the start of the row.
20247 These are special glyphs like truncation marks on terminal
20249 if (row
->displays_text_p
)
20251 && INTEGERP (glyph
->object
)
20252 && !EQ (stop
, glyph
->object
)
20253 && glyph
->charpos
< 0)
20255 *x
+= glyph
->pixel_width
;
20260 && !INTEGERP (glyph
->object
)
20261 && !EQ (stop
, glyph
->object
)
20262 && (!BUFFERP (glyph
->object
)
20263 || glyph
->charpos
< charpos
))
20265 *x
+= glyph
->pixel_width
;
20269 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20276 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20279 int *hpos
, *vpos
, *x
, *y
;
20284 int maybe_next_line_p
= 0;
20285 int line_start_position
;
20286 int yb
= window_text_bottom_y (w
);
20287 struct glyph_row
*row
, *best_row
;
20288 int row_vpos
, best_row_vpos
;
20291 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20292 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20294 while (row
->y
< yb
)
20296 if (row
->used
[TEXT_AREA
])
20297 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20299 line_start_position
= 0;
20301 if (line_start_position
> pos
)
20303 /* If the position sought is the end of the buffer,
20304 don't include the blank lines at the bottom of the window. */
20305 else if (line_start_position
== pos
20306 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20308 maybe_next_line_p
= 1;
20311 else if (line_start_position
> 0)
20314 best_row_vpos
= row_vpos
;
20317 if (row
->y
+ row
->height
>= yb
)
20324 /* Find the right column within BEST_ROW. */
20326 current_x
= best_row
->x
;
20327 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20329 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20330 int charpos
= glyph
->charpos
;
20332 if (BUFFERP (glyph
->object
))
20334 if (charpos
== pos
)
20337 *vpos
= best_row_vpos
;
20342 else if (charpos
> pos
)
20345 else if (EQ (glyph
->object
, stop
))
20350 current_x
+= glyph
->pixel_width
;
20353 /* If we're looking for the end of the buffer,
20354 and we didn't find it in the line we scanned,
20355 use the start of the following line. */
20356 if (maybe_next_line_p
)
20361 current_x
= best_row
->x
;
20364 *vpos
= best_row_vpos
;
20365 *hpos
= lastcol
+ 1;
20374 /* Find the position of the glyph for position POS in OBJECT in
20375 window W's current matrix, and return in *X, *Y the pixel
20376 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20378 RIGHT_P non-zero means return the position of the right edge of the
20379 glyph, RIGHT_P zero means return the left edge position.
20381 If no glyph for POS exists in the matrix, return the position of
20382 the glyph with the next smaller position that is in the matrix, if
20383 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20384 exists in the matrix, return the position of the glyph with the
20385 next larger position in OBJECT.
20387 Value is non-zero if a glyph was found. */
20390 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20393 Lisp_Object object
;
20394 int *hpos
, *vpos
, *x
, *y
;
20397 int yb
= window_text_bottom_y (w
);
20398 struct glyph_row
*r
;
20399 struct glyph
*best_glyph
= NULL
;
20400 struct glyph_row
*best_row
= NULL
;
20403 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20404 r
->enabled_p
&& r
->y
< yb
;
20407 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20408 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20411 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20412 if (EQ (g
->object
, object
))
20414 if (g
->charpos
== pos
)
20421 else if (best_glyph
== NULL
20422 || ((abs (g
->charpos
- pos
)
20423 < abs (best_glyph
->charpos
- pos
))
20426 : g
->charpos
> pos
)))
20440 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20444 *x
+= best_glyph
->pixel_width
;
20449 *vpos
= best_row
- w
->current_matrix
->rows
;
20452 return best_glyph
!= NULL
;
20456 /* See if position X, Y is within a hot-spot of an image. */
20459 on_hot_spot_p (hot_spot
, x
, y
)
20460 Lisp_Object hot_spot
;
20463 if (!CONSP (hot_spot
))
20466 if (EQ (XCAR (hot_spot
), Qrect
))
20468 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20469 Lisp_Object rect
= XCDR (hot_spot
);
20473 if (!CONSP (XCAR (rect
)))
20475 if (!CONSP (XCDR (rect
)))
20477 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20479 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20481 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20483 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20487 else if (EQ (XCAR (hot_spot
), Qcircle
))
20489 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20490 Lisp_Object circ
= XCDR (hot_spot
);
20491 Lisp_Object lr
, lx0
, ly0
;
20493 && CONSP (XCAR (circ
))
20494 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20495 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20496 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20498 double r
= XFLOATINT (lr
);
20499 double dx
= XINT (lx0
) - x
;
20500 double dy
= XINT (ly0
) - y
;
20501 return (dx
* dx
+ dy
* dy
<= r
* r
);
20504 else if (EQ (XCAR (hot_spot
), Qpoly
))
20506 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20507 if (VECTORP (XCDR (hot_spot
)))
20509 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20510 Lisp_Object
*poly
= v
->contents
;
20514 Lisp_Object lx
, ly
;
20517 /* Need an even number of coordinates, and at least 3 edges. */
20518 if (n
< 6 || n
& 1)
20521 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20522 If count is odd, we are inside polygon. Pixels on edges
20523 may or may not be included depending on actual geometry of the
20525 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20526 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20528 x0
= XINT (lx
), y0
= XINT (ly
);
20529 for (i
= 0; i
< n
; i
+= 2)
20531 int x1
= x0
, y1
= y0
;
20532 if ((lx
= poly
[i
], !INTEGERP (lx
))
20533 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20535 x0
= XINT (lx
), y0
= XINT (ly
);
20537 /* Does this segment cross the X line? */
20545 if (y
> y0
&& y
> y1
)
20547 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20553 /* If we don't understand the format, pretend we're not in the hot-spot. */
20558 find_hot_spot (map
, x
, y
)
20562 while (CONSP (map
))
20564 if (CONSP (XCAR (map
))
20565 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20573 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20575 doc
: /* Lookup in image map MAP coordinates X and Y.
20576 An image map is an alist where each element has the format (AREA ID PLIST).
20577 An AREA is specified as either a rectangle, a circle, or a polygon:
20578 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20579 pixel coordinates of the upper left and bottom right corners.
20580 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20581 and the radius of the circle; r may be a float or integer.
20582 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20583 vector describes one corner in the polygon.
20584 Returns the alist element for the first matching AREA in MAP. */)
20595 return find_hot_spot (map
, XINT (x
), XINT (y
));
20599 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20601 define_frame_cursor1 (f
, cursor
, pointer
)
20604 Lisp_Object pointer
;
20606 if (!NILP (pointer
))
20608 if (EQ (pointer
, Qarrow
))
20609 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20610 else if (EQ (pointer
, Qhand
))
20611 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20612 else if (EQ (pointer
, Qtext
))
20613 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20614 else if (EQ (pointer
, intern ("hdrag")))
20615 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20616 #ifdef HAVE_X_WINDOWS
20617 else if (EQ (pointer
, intern ("vdrag")))
20618 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20620 else if (EQ (pointer
, intern ("hourglass")))
20621 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20622 else if (EQ (pointer
, Qmodeline
))
20623 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20625 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20628 #ifndef HAVE_CARBON
20629 if (cursor
!= No_Cursor
)
20631 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20633 rif
->define_frame_cursor (f
, cursor
);
20636 /* Take proper action when mouse has moved to the mode or header line
20637 or marginal area AREA of window W, x-position X and y-position Y.
20638 X is relative to the start of the text display area of W, so the
20639 width of bitmap areas and scroll bars must be subtracted to get a
20640 position relative to the start of the mode line. */
20643 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20646 enum window_part area
;
20648 struct frame
*f
= XFRAME (w
->frame
);
20649 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20650 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20651 Lisp_Object pointer
= Qnil
;
20652 int charpos
, dx
, dy
, width
, height
;
20653 Lisp_Object string
, object
= Qnil
;
20654 Lisp_Object pos
, help
;
20656 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20657 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20658 &object
, &dx
, &dy
, &width
, &height
);
20661 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20662 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20663 &object
, &dx
, &dy
, &width
, &height
);
20668 if (IMAGEP (object
))
20670 Lisp_Object image_map
, hotspot
;
20671 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
20673 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20675 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20677 Lisp_Object area_id
, plist
;
20679 area_id
= XCAR (hotspot
);
20680 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20681 If so, we could look for mouse-enter, mouse-leave
20682 properties in PLIST (and do something...). */
20683 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20685 pointer
= Fplist_get (plist
, Qpointer
);
20686 if (NILP (pointer
))
20688 help
= Fplist_get (plist
, Qhelp_echo
);
20691 help_echo_string
= help
;
20692 /* Is this correct? ++kfs */
20693 XSETWINDOW (help_echo_window
, w
);
20694 help_echo_object
= w
->buffer
;
20695 help_echo_pos
= charpos
;
20698 if (NILP (pointer
))
20699 pointer
= Fplist_get (XCDR (object
), QCpointer
);
20703 if (STRINGP (string
))
20705 pos
= make_number (charpos
);
20706 /* If we're on a string with `help-echo' text property, arrange
20707 for the help to be displayed. This is done by setting the
20708 global variable help_echo_string to the help string. */
20709 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20712 help_echo_string
= help
;
20713 XSETWINDOW (help_echo_window
, w
);
20714 help_echo_object
= string
;
20715 help_echo_pos
= charpos
;
20718 if (NILP (pointer
))
20719 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20721 /* Change the mouse pointer according to what is under X/Y. */
20722 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
20725 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20726 if (!KEYMAPP (map
))
20727 map
= Fget_text_property (pos
, Qkeymap
, string
);
20728 if (!KEYMAPP (map
))
20729 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20733 define_frame_cursor1 (f
, cursor
, pointer
);
20738 Take proper action when the mouse has moved to position X, Y on
20739 frame F as regards highlighting characters that have mouse-face
20740 properties. Also de-highlighting chars where the mouse was before.
20741 X and Y can be negative or out of range. */
20744 note_mouse_highlight (f
, x
, y
)
20748 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20749 enum window_part part
;
20750 Lisp_Object window
;
20752 Cursor cursor
= No_Cursor
;
20753 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
20756 /* When a menu is active, don't highlight because this looks odd. */
20757 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
20758 if (popup_activated ())
20762 if (NILP (Vmouse_highlight
)
20763 || !f
->glyphs_initialized_p
)
20766 dpyinfo
->mouse_face_mouse_x
= x
;
20767 dpyinfo
->mouse_face_mouse_y
= y
;
20768 dpyinfo
->mouse_face_mouse_frame
= f
;
20770 if (dpyinfo
->mouse_face_defer
)
20773 if (gc_in_progress
)
20775 dpyinfo
->mouse_face_deferred_gc
= 1;
20779 /* Which window is that in? */
20780 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
20782 /* If we were displaying active text in another window, clear that. */
20783 if (! EQ (window
, dpyinfo
->mouse_face_window
))
20784 clear_mouse_face (dpyinfo
);
20786 /* Not on a window -> return. */
20787 if (!WINDOWP (window
))
20790 /* Reset help_echo_string. It will get recomputed below. */
20791 help_echo_string
= Qnil
;
20793 /* Convert to window-relative pixel coordinates. */
20794 w
= XWINDOW (window
);
20795 frame_to_window_pixel_xy (w
, &x
, &y
);
20797 /* Handle tool-bar window differently since it doesn't display a
20799 if (EQ (window
, f
->tool_bar_window
))
20801 note_tool_bar_highlight (f
, x
, y
);
20805 /* Mouse is on the mode, header line or margin? */
20806 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
20807 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
20809 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
20813 if (part
== ON_VERTICAL_BORDER
)
20814 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20815 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
)
20816 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20818 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20820 /* Are we in a window whose display is up to date?
20821 And verify the buffer's text has not changed. */
20822 b
= XBUFFER (w
->buffer
);
20823 if (part
== ON_TEXT
20824 && EQ (w
->window_end_valid
, w
->buffer
)
20825 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
20826 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
20828 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
20829 struct glyph
*glyph
;
20830 Lisp_Object object
;
20831 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
20832 Lisp_Object
*overlay_vec
= NULL
;
20833 int len
, noverlays
;
20834 struct buffer
*obuf
;
20835 int obegv
, ozv
, same_region
;
20837 /* Find the glyph under X/Y. */
20838 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
20840 /* Look for :pointer property on image. */
20841 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
20843 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
20844 if (img
!= NULL
&& IMAGEP (img
->spec
))
20846 Lisp_Object image_map
, hotspot
;
20847 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
20849 && (hotspot
= find_hot_spot (image_map
,
20850 glyph
->slice
.x
+ dx
,
20851 glyph
->slice
.y
+ dy
),
20853 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20855 Lisp_Object area_id
, plist
;
20857 area_id
= XCAR (hotspot
);
20858 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20859 If so, we could look for mouse-enter, mouse-leave
20860 properties in PLIST (and do something...). */
20861 if ((plist
= XCDR (hotspot
), CONSP (plist
)))
20863 pointer
= Fplist_get (plist
, Qpointer
);
20864 if (NILP (pointer
))
20866 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
20867 if (!NILP (help_echo_string
))
20869 help_echo_window
= window
;
20870 help_echo_object
= glyph
->object
;
20871 help_echo_pos
= glyph
->charpos
;
20875 if (NILP (pointer
))
20876 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
20880 /* Clear mouse face if X/Y not over text. */
20882 || area
!= TEXT_AREA
20883 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
20885 if (clear_mouse_face (dpyinfo
))
20886 cursor
= No_Cursor
;
20887 if (NILP (pointer
))
20889 if (area
!= TEXT_AREA
)
20890 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20892 pointer
= Vvoid_text_area_pointer
;
20897 pos
= glyph
->charpos
;
20898 object
= glyph
->object
;
20899 if (!STRINGP (object
) && !BUFFERP (object
))
20902 /* If we get an out-of-range value, return now; avoid an error. */
20903 if (BUFFERP (object
) && pos
> BUF_Z (b
))
20906 /* Make the window's buffer temporarily current for
20907 overlays_at and compute_char_face. */
20908 obuf
= current_buffer
;
20909 current_buffer
= b
;
20915 /* Is this char mouse-active or does it have help-echo? */
20916 position
= make_number (pos
);
20918 if (BUFFERP (object
))
20920 /* Put all the overlays we want in a vector in overlay_vec.
20921 Store the length in len. If there are more than 40, make
20922 enough space for all, and try again. */
20924 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20925 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
20926 if (noverlays
> len
)
20929 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
20930 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
20933 /* Sort overlays into increasing priority order. */
20934 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
20939 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
20940 && vpos
>= dpyinfo
->mouse_face_beg_row
20941 && vpos
<= dpyinfo
->mouse_face_end_row
20942 && (vpos
> dpyinfo
->mouse_face_beg_row
20943 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20944 && (vpos
< dpyinfo
->mouse_face_end_row
20945 || hpos
< dpyinfo
->mouse_face_end_col
20946 || dpyinfo
->mouse_face_past_end
));
20949 cursor
= No_Cursor
;
20951 /* Check mouse-face highlighting. */
20953 /* If there exists an overlay with mouse-face overlapping
20954 the one we are currently highlighting, we have to
20955 check if we enter the overlapping overlay, and then
20956 highlight only that. */
20957 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
20958 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
20960 /* Find the highest priority overlay that has a mouse-face
20963 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
20965 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
20966 if (!NILP (mouse_face
))
20967 overlay
= overlay_vec
[i
];
20970 /* If we're actually highlighting the same overlay as
20971 before, there's no need to do that again. */
20972 if (!NILP (overlay
)
20973 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
20974 goto check_help_echo
;
20976 dpyinfo
->mouse_face_overlay
= overlay
;
20978 /* Clear the display of the old active region, if any. */
20979 if (clear_mouse_face (dpyinfo
))
20980 cursor
= No_Cursor
;
20982 /* If no overlay applies, get a text property. */
20983 if (NILP (overlay
))
20984 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
20986 /* Handle the overlay case. */
20987 if (!NILP (overlay
))
20989 /* Find the range of text around this char that
20990 should be active. */
20991 Lisp_Object before
, after
;
20994 before
= Foverlay_start (overlay
);
20995 after
= Foverlay_end (overlay
);
20996 /* Record this as the current active region. */
20997 fast_find_position (w
, XFASTINT (before
),
20998 &dpyinfo
->mouse_face_beg_col
,
20999 &dpyinfo
->mouse_face_beg_row
,
21000 &dpyinfo
->mouse_face_beg_x
,
21001 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21003 dpyinfo
->mouse_face_past_end
21004 = !fast_find_position (w
, XFASTINT (after
),
21005 &dpyinfo
->mouse_face_end_col
,
21006 &dpyinfo
->mouse_face_end_row
,
21007 &dpyinfo
->mouse_face_end_x
,
21008 &dpyinfo
->mouse_face_end_y
, Qnil
);
21009 dpyinfo
->mouse_face_window
= window
;
21011 dpyinfo
->mouse_face_face_id
21012 = face_at_buffer_position (w
, pos
, 0, 0,
21014 !dpyinfo
->mouse_face_hidden
);
21016 /* Display it as active. */
21017 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21018 cursor
= No_Cursor
;
21020 /* Handle the text property case. */
21021 else if (!NILP (mouse_face
) && BUFFERP (object
))
21023 /* Find the range of text around this char that
21024 should be active. */
21025 Lisp_Object before
, after
, beginning
, end
;
21028 beginning
= Fmarker_position (w
->start
);
21029 end
= make_number (BUF_Z (XBUFFER (object
))
21030 - XFASTINT (w
->window_end_pos
));
21032 = Fprevious_single_property_change (make_number (pos
+ 1),
21034 object
, beginning
);
21036 = Fnext_single_property_change (position
, Qmouse_face
,
21039 /* Record this as the current active region. */
21040 fast_find_position (w
, XFASTINT (before
),
21041 &dpyinfo
->mouse_face_beg_col
,
21042 &dpyinfo
->mouse_face_beg_row
,
21043 &dpyinfo
->mouse_face_beg_x
,
21044 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21045 dpyinfo
->mouse_face_past_end
21046 = !fast_find_position (w
, XFASTINT (after
),
21047 &dpyinfo
->mouse_face_end_col
,
21048 &dpyinfo
->mouse_face_end_row
,
21049 &dpyinfo
->mouse_face_end_x
,
21050 &dpyinfo
->mouse_face_end_y
, Qnil
);
21051 dpyinfo
->mouse_face_window
= window
;
21053 if (BUFFERP (object
))
21054 dpyinfo
->mouse_face_face_id
21055 = face_at_buffer_position (w
, pos
, 0, 0,
21057 !dpyinfo
->mouse_face_hidden
);
21059 /* Display it as active. */
21060 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21061 cursor
= No_Cursor
;
21063 else if (!NILP (mouse_face
) && STRINGP (object
))
21068 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21071 e
= Fnext_single_property_change (position
, Qmouse_face
,
21074 b
= make_number (0);
21076 e
= make_number (SCHARS (object
) - 1);
21077 fast_find_string_pos (w
, XINT (b
), object
,
21078 &dpyinfo
->mouse_face_beg_col
,
21079 &dpyinfo
->mouse_face_beg_row
,
21080 &dpyinfo
->mouse_face_beg_x
,
21081 &dpyinfo
->mouse_face_beg_y
, 0);
21082 fast_find_string_pos (w
, XINT (e
), object
,
21083 &dpyinfo
->mouse_face_end_col
,
21084 &dpyinfo
->mouse_face_end_row
,
21085 &dpyinfo
->mouse_face_end_x
,
21086 &dpyinfo
->mouse_face_end_y
, 1);
21087 dpyinfo
->mouse_face_past_end
= 0;
21088 dpyinfo
->mouse_face_window
= window
;
21089 dpyinfo
->mouse_face_face_id
21090 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21091 glyph
->face_id
, 1);
21092 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21093 cursor
= No_Cursor
;
21095 else if (STRINGP (object
) && NILP (mouse_face
))
21097 /* A string which doesn't have mouse-face, but
21098 the text ``under'' it might have. */
21099 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21100 int start
= MATRIX_ROW_START_CHARPOS (r
);
21102 pos
= string_buffer_position (w
, object
, start
);
21104 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21108 if (!NILP (mouse_face
) && !NILP (overlay
))
21110 Lisp_Object before
= Foverlay_start (overlay
);
21111 Lisp_Object after
= Foverlay_end (overlay
);
21114 /* Note that we might not be able to find position
21115 BEFORE in the glyph matrix if the overlay is
21116 entirely covered by a `display' property. In
21117 this case, we overshoot. So let's stop in
21118 the glyph matrix before glyphs for OBJECT. */
21119 fast_find_position (w
, XFASTINT (before
),
21120 &dpyinfo
->mouse_face_beg_col
,
21121 &dpyinfo
->mouse_face_beg_row
,
21122 &dpyinfo
->mouse_face_beg_x
,
21123 &dpyinfo
->mouse_face_beg_y
,
21126 dpyinfo
->mouse_face_past_end
21127 = !fast_find_position (w
, XFASTINT (after
),
21128 &dpyinfo
->mouse_face_end_col
,
21129 &dpyinfo
->mouse_face_end_row
,
21130 &dpyinfo
->mouse_face_end_x
,
21131 &dpyinfo
->mouse_face_end_y
,
21133 dpyinfo
->mouse_face_window
= window
;
21134 dpyinfo
->mouse_face_face_id
21135 = face_at_buffer_position (w
, pos
, 0, 0,
21137 !dpyinfo
->mouse_face_hidden
);
21139 /* Display it as active. */
21140 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21141 cursor
= No_Cursor
;
21148 /* Look for a `help-echo' property. */
21149 if (NILP (help_echo_string
)) {
21150 Lisp_Object help
, overlay
;
21152 /* Check overlays first. */
21153 help
= overlay
= Qnil
;
21154 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21156 overlay
= overlay_vec
[i
];
21157 help
= Foverlay_get (overlay
, Qhelp_echo
);
21162 help_echo_string
= help
;
21163 help_echo_window
= window
;
21164 help_echo_object
= overlay
;
21165 help_echo_pos
= pos
;
21169 Lisp_Object object
= glyph
->object
;
21170 int charpos
= glyph
->charpos
;
21172 /* Try text properties. */
21173 if (STRINGP (object
)
21175 && charpos
< SCHARS (object
))
21177 help
= Fget_text_property (make_number (charpos
),
21178 Qhelp_echo
, object
);
21181 /* If the string itself doesn't specify a help-echo,
21182 see if the buffer text ``under'' it does. */
21183 struct glyph_row
*r
21184 = MATRIX_ROW (w
->current_matrix
, vpos
);
21185 int start
= MATRIX_ROW_START_CHARPOS (r
);
21186 int pos
= string_buffer_position (w
, object
, start
);
21189 help
= Fget_char_property (make_number (pos
),
21190 Qhelp_echo
, w
->buffer
);
21194 object
= w
->buffer
;
21199 else if (BUFFERP (object
)
21202 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21207 help_echo_string
= help
;
21208 help_echo_window
= window
;
21209 help_echo_object
= object
;
21210 help_echo_pos
= charpos
;
21215 /* Look for a `pointer' property. */
21216 if (NILP (pointer
))
21218 /* Check overlays first. */
21219 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21220 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21222 if (NILP (pointer
))
21224 Lisp_Object object
= glyph
->object
;
21225 int charpos
= glyph
->charpos
;
21227 /* Try text properties. */
21228 if (STRINGP (object
)
21230 && charpos
< SCHARS (object
))
21232 pointer
= Fget_text_property (make_number (charpos
),
21234 if (NILP (pointer
))
21236 /* If the string itself doesn't specify a pointer,
21237 see if the buffer text ``under'' it does. */
21238 struct glyph_row
*r
21239 = MATRIX_ROW (w
->current_matrix
, vpos
);
21240 int start
= MATRIX_ROW_START_CHARPOS (r
);
21241 int pos
= string_buffer_position (w
, object
, start
);
21243 pointer
= Fget_char_property (make_number (pos
),
21244 Qpointer
, w
->buffer
);
21247 else if (BUFFERP (object
)
21250 pointer
= Fget_text_property (make_number (charpos
),
21257 current_buffer
= obuf
;
21262 define_frame_cursor1 (f
, cursor
, pointer
);
21267 Clear any mouse-face on window W. This function is part of the
21268 redisplay interface, and is called from try_window_id and similar
21269 functions to ensure the mouse-highlight is off. */
21272 x_clear_window_mouse_face (w
)
21275 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21276 Lisp_Object window
;
21279 XSETWINDOW (window
, w
);
21280 if (EQ (window
, dpyinfo
->mouse_face_window
))
21281 clear_mouse_face (dpyinfo
);
21287 Just discard the mouse face information for frame F, if any.
21288 This is used when the size of F is changed. */
21291 cancel_mouse_face (f
)
21294 Lisp_Object window
;
21295 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21297 window
= dpyinfo
->mouse_face_window
;
21298 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21300 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21301 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21302 dpyinfo
->mouse_face_window
= Qnil
;
21307 #endif /* HAVE_WINDOW_SYSTEM */
21310 /***********************************************************************
21312 ***********************************************************************/
21314 #ifdef HAVE_WINDOW_SYSTEM
21316 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21317 which intersects rectangle R. R is in window-relative coordinates. */
21320 expose_area (w
, row
, r
, area
)
21322 struct glyph_row
*row
;
21324 enum glyph_row_area area
;
21326 struct glyph
*first
= row
->glyphs
[area
];
21327 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21328 struct glyph
*last
;
21329 int first_x
, start_x
, x
;
21331 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21332 /* If row extends face to end of line write the whole line. */
21333 draw_glyphs (w
, 0, row
, area
,
21334 0, row
->used
[area
],
21335 DRAW_NORMAL_TEXT
, 0);
21338 /* Set START_X to the window-relative start position for drawing glyphs of
21339 AREA. The first glyph of the text area can be partially visible.
21340 The first glyphs of other areas cannot. */
21341 start_x
= window_box_left_offset (w
, area
);
21343 if (area
== TEXT_AREA
)
21346 /* Find the first glyph that must be redrawn. */
21348 && x
+ first
->pixel_width
< r
->x
)
21350 x
+= first
->pixel_width
;
21354 /* Find the last one. */
21358 && x
< r
->x
+ r
->width
)
21360 x
+= last
->pixel_width
;
21366 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21367 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21368 DRAW_NORMAL_TEXT
, 0);
21373 /* Redraw the parts of the glyph row ROW on window W intersecting
21374 rectangle R. R is in window-relative coordinates. Value is
21375 non-zero if mouse-face was overwritten. */
21378 expose_line (w
, row
, r
)
21380 struct glyph_row
*row
;
21383 xassert (row
->enabled_p
);
21385 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21386 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21387 0, row
->used
[TEXT_AREA
],
21388 DRAW_NORMAL_TEXT
, 0);
21391 if (row
->used
[LEFT_MARGIN_AREA
])
21392 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21393 if (row
->used
[TEXT_AREA
])
21394 expose_area (w
, row
, r
, TEXT_AREA
);
21395 if (row
->used
[RIGHT_MARGIN_AREA
])
21396 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21397 draw_row_fringe_bitmaps (w
, row
);
21400 return row
->mouse_face_p
;
21404 /* Redraw those parts of glyphs rows during expose event handling that
21405 overlap other rows. Redrawing of an exposed line writes over parts
21406 of lines overlapping that exposed line; this function fixes that.
21408 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21409 row in W's current matrix that is exposed and overlaps other rows.
21410 LAST_OVERLAPPING_ROW is the last such row. */
21413 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21415 struct glyph_row
*first_overlapping_row
;
21416 struct glyph_row
*last_overlapping_row
;
21418 struct glyph_row
*row
;
21420 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21421 if (row
->overlapping_p
)
21423 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21425 if (row
->used
[LEFT_MARGIN_AREA
])
21426 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21428 if (row
->used
[TEXT_AREA
])
21429 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21431 if (row
->used
[RIGHT_MARGIN_AREA
])
21432 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21437 /* Return non-zero if W's cursor intersects rectangle R. */
21440 phys_cursor_in_rect_p (w
, r
)
21444 XRectangle cr
, result
;
21445 struct glyph
*cursor_glyph
;
21447 cursor_glyph
= get_phys_cursor_glyph (w
);
21450 /* r is relative to W's box, but w->phys_cursor.x is relative
21451 to left edge of W's TEXT area. Adjust it. */
21452 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21453 cr
.y
= w
->phys_cursor
.y
;
21454 cr
.width
= cursor_glyph
->pixel_width
;
21455 cr
.height
= w
->phys_cursor_height
;
21456 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21457 I assume the effect is the same -- and this is portable. */
21458 return x_intersect_rectangles (&cr
, r
, &result
);
21466 Draw a vertical window border to the right of window W if W doesn't
21467 have vertical scroll bars. */
21470 x_draw_vertical_border (w
)
21473 /* We could do better, if we knew what type of scroll-bar the adjacent
21474 windows (on either side) have... But we don't :-(
21475 However, I think this works ok. ++KFS 2003-04-25 */
21477 /* Redraw borders between horizontally adjacent windows. Don't
21478 do it for frames with vertical scroll bars because either the
21479 right scroll bar of a window, or the left scroll bar of its
21480 neighbor will suffice as a border. */
21481 if (!WINDOW_RIGHTMOST_P (w
)
21482 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21484 int x0
, x1
, y0
, y1
;
21486 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21489 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
21491 else if (!WINDOW_LEFTMOST_P (w
)
21492 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21494 int x0
, x1
, y0
, y1
;
21496 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21499 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
21504 /* Redraw the part of window W intersection rectangle FR. Pixel
21505 coordinates in FR are frame-relative. Call this function with
21506 input blocked. Value is non-zero if the exposure overwrites
21510 expose_window (w
, fr
)
21514 struct frame
*f
= XFRAME (w
->frame
);
21516 int mouse_face_overwritten_p
= 0;
21518 /* If window is not yet fully initialized, do nothing. This can
21519 happen when toolkit scroll bars are used and a window is split.
21520 Reconfiguring the scroll bar will generate an expose for a newly
21522 if (w
->current_matrix
== NULL
)
21525 /* When we're currently updating the window, display and current
21526 matrix usually don't agree. Arrange for a thorough display
21528 if (w
== updated_window
)
21530 SET_FRAME_GARBAGED (f
);
21534 /* Frame-relative pixel rectangle of W. */
21535 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21536 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21537 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21538 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21540 if (x_intersect_rectangles (fr
, &wr
, &r
))
21542 int yb
= window_text_bottom_y (w
);
21543 struct glyph_row
*row
;
21544 int cursor_cleared_p
;
21545 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21547 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21548 r
.x
, r
.y
, r
.width
, r
.height
));
21550 /* Convert to window coordinates. */
21551 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21552 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21554 /* Turn off the cursor. */
21555 if (!w
->pseudo_window_p
21556 && phys_cursor_in_rect_p (w
, &r
))
21558 x_clear_cursor (w
);
21559 cursor_cleared_p
= 1;
21562 cursor_cleared_p
= 0;
21564 /* Update lines intersecting rectangle R. */
21565 first_overlapping_row
= last_overlapping_row
= NULL
;
21566 for (row
= w
->current_matrix
->rows
;
21571 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21573 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21574 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21575 || (r
.y
>= y0
&& r
.y
< y1
)
21576 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21578 if (row
->overlapping_p
)
21580 if (first_overlapping_row
== NULL
)
21581 first_overlapping_row
= row
;
21582 last_overlapping_row
= row
;
21585 if (expose_line (w
, row
, &r
))
21586 mouse_face_overwritten_p
= 1;
21593 /* Display the mode line if there is one. */
21594 if (WINDOW_WANTS_MODELINE_P (w
)
21595 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21597 && row
->y
< r
.y
+ r
.height
)
21599 if (expose_line (w
, row
, &r
))
21600 mouse_face_overwritten_p
= 1;
21603 if (!w
->pseudo_window_p
)
21605 /* Fix the display of overlapping rows. */
21606 if (first_overlapping_row
)
21607 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21609 /* Draw border between windows. */
21610 x_draw_vertical_border (w
);
21612 /* Turn the cursor on again. */
21613 if (cursor_cleared_p
)
21614 update_window_cursor (w
, 1);
21619 /* Display scroll bar for this window. */
21620 if (!NILP (w
->vertical_scroll_bar
))
21623 If this doesn't work here (maybe some header files are missing),
21624 make a function in macterm.c and call it to do the job! */
21626 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21632 return mouse_face_overwritten_p
;
21637 /* Redraw (parts) of all windows in the window tree rooted at W that
21638 intersect R. R contains frame pixel coordinates. Value is
21639 non-zero if the exposure overwrites mouse-face. */
21642 expose_window_tree (w
, r
)
21646 struct frame
*f
= XFRAME (w
->frame
);
21647 int mouse_face_overwritten_p
= 0;
21649 while (w
&& !FRAME_GARBAGED_P (f
))
21651 if (!NILP (w
->hchild
))
21652 mouse_face_overwritten_p
21653 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21654 else if (!NILP (w
->vchild
))
21655 mouse_face_overwritten_p
21656 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21658 mouse_face_overwritten_p
|= expose_window (w
, r
);
21660 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21663 return mouse_face_overwritten_p
;
21668 Redisplay an exposed area of frame F. X and Y are the upper-left
21669 corner of the exposed rectangle. W and H are width and height of
21670 the exposed area. All are pixel values. W or H zero means redraw
21671 the entire frame. */
21674 expose_frame (f
, x
, y
, w
, h
)
21679 int mouse_face_overwritten_p
= 0;
21681 TRACE ((stderr
, "expose_frame "));
21683 /* No need to redraw if frame will be redrawn soon. */
21684 if (FRAME_GARBAGED_P (f
))
21686 TRACE ((stderr
, " garbaged\n"));
21691 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21692 or deactivated here, for unknown reasons, activated scroll bars
21693 are shown in deactivated frames in some instances. */
21694 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21695 activate_scroll_bars (f
);
21697 deactivate_scroll_bars (f
);
21700 /* If basic faces haven't been realized yet, there is no point in
21701 trying to redraw anything. This can happen when we get an expose
21702 event while Emacs is starting, e.g. by moving another window. */
21703 if (FRAME_FACE_CACHE (f
) == NULL
21704 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21706 TRACE ((stderr
, " no faces\n"));
21710 if (w
== 0 || h
== 0)
21713 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21714 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21724 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21725 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21727 if (WINDOWP (f
->tool_bar_window
))
21728 mouse_face_overwritten_p
21729 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21731 #ifdef HAVE_X_WINDOWS
21733 #ifndef USE_X_TOOLKIT
21734 if (WINDOWP (f
->menu_bar_window
))
21735 mouse_face_overwritten_p
21736 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21737 #endif /* not USE_X_TOOLKIT */
21741 /* Some window managers support a focus-follows-mouse style with
21742 delayed raising of frames. Imagine a partially obscured frame,
21743 and moving the mouse into partially obscured mouse-face on that
21744 frame. The visible part of the mouse-face will be highlighted,
21745 then the WM raises the obscured frame. With at least one WM, KDE
21746 2.1, Emacs is not getting any event for the raising of the frame
21747 (even tried with SubstructureRedirectMask), only Expose events.
21748 These expose events will draw text normally, i.e. not
21749 highlighted. Which means we must redo the highlight here.
21750 Subsume it under ``we love X''. --gerd 2001-08-15 */
21751 /* Included in Windows version because Windows most likely does not
21752 do the right thing if any third party tool offers
21753 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
21754 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
21756 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21757 if (f
== dpyinfo
->mouse_face_mouse_frame
)
21759 int x
= dpyinfo
->mouse_face_mouse_x
;
21760 int y
= dpyinfo
->mouse_face_mouse_y
;
21761 clear_mouse_face (dpyinfo
);
21762 note_mouse_highlight (f
, x
, y
);
21769 Determine the intersection of two rectangles R1 and R2. Return
21770 the intersection in *RESULT. Value is non-zero if RESULT is not
21774 x_intersect_rectangles (r1
, r2
, result
)
21775 XRectangle
*r1
, *r2
, *result
;
21777 XRectangle
*left
, *right
;
21778 XRectangle
*upper
, *lower
;
21779 int intersection_p
= 0;
21781 /* Rearrange so that R1 is the left-most rectangle. */
21783 left
= r1
, right
= r2
;
21785 left
= r2
, right
= r1
;
21787 /* X0 of the intersection is right.x0, if this is inside R1,
21788 otherwise there is no intersection. */
21789 if (right
->x
<= left
->x
+ left
->width
)
21791 result
->x
= right
->x
;
21793 /* The right end of the intersection is the minimum of the
21794 the right ends of left and right. */
21795 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
21798 /* Same game for Y. */
21800 upper
= r1
, lower
= r2
;
21802 upper
= r2
, lower
= r1
;
21804 /* The upper end of the intersection is lower.y0, if this is inside
21805 of upper. Otherwise, there is no intersection. */
21806 if (lower
->y
<= upper
->y
+ upper
->height
)
21808 result
->y
= lower
->y
;
21810 /* The lower end of the intersection is the minimum of the lower
21811 ends of upper and lower. */
21812 result
->height
= (min (lower
->y
+ lower
->height
,
21813 upper
->y
+ upper
->height
)
21815 intersection_p
= 1;
21819 return intersection_p
;
21822 #endif /* HAVE_WINDOW_SYSTEM */
21825 /***********************************************************************
21827 ***********************************************************************/
21832 Vwith_echo_area_save_vector
= Qnil
;
21833 staticpro (&Vwith_echo_area_save_vector
);
21835 Vmessage_stack
= Qnil
;
21836 staticpro (&Vmessage_stack
);
21838 Qinhibit_redisplay
= intern ("inhibit-redisplay");
21839 staticpro (&Qinhibit_redisplay
);
21841 message_dolog_marker1
= Fmake_marker ();
21842 staticpro (&message_dolog_marker1
);
21843 message_dolog_marker2
= Fmake_marker ();
21844 staticpro (&message_dolog_marker2
);
21845 message_dolog_marker3
= Fmake_marker ();
21846 staticpro (&message_dolog_marker3
);
21849 defsubr (&Sdump_frame_glyph_matrix
);
21850 defsubr (&Sdump_glyph_matrix
);
21851 defsubr (&Sdump_glyph_row
);
21852 defsubr (&Sdump_tool_bar_row
);
21853 defsubr (&Strace_redisplay
);
21854 defsubr (&Strace_to_stderr
);
21856 #ifdef HAVE_WINDOW_SYSTEM
21857 defsubr (&Stool_bar_lines_needed
);
21858 defsubr (&Slookup_image_map
);
21860 defsubr (&Sformat_mode_line
);
21862 staticpro (&Qmenu_bar_update_hook
);
21863 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
21865 staticpro (&Qoverriding_terminal_local_map
);
21866 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
21868 staticpro (&Qoverriding_local_map
);
21869 Qoverriding_local_map
= intern ("overriding-local-map");
21871 staticpro (&Qwindow_scroll_functions
);
21872 Qwindow_scroll_functions
= intern ("window-scroll-functions");
21874 staticpro (&Qredisplay_end_trigger_functions
);
21875 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
21877 staticpro (&Qinhibit_point_motion_hooks
);
21878 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
21880 QCdata
= intern (":data");
21881 staticpro (&QCdata
);
21882 Qdisplay
= intern ("display");
21883 staticpro (&Qdisplay
);
21884 Qspace_width
= intern ("space-width");
21885 staticpro (&Qspace_width
);
21886 Qraise
= intern ("raise");
21887 staticpro (&Qraise
);
21888 Qslice
= intern ("slice");
21889 staticpro (&Qslice
);
21890 Qspace
= intern ("space");
21891 staticpro (&Qspace
);
21892 Qmargin
= intern ("margin");
21893 staticpro (&Qmargin
);
21894 Qpointer
= intern ("pointer");
21895 staticpro (&Qpointer
);
21896 Qleft_margin
= intern ("left-margin");
21897 staticpro (&Qleft_margin
);
21898 Qright_margin
= intern ("right-margin");
21899 staticpro (&Qright_margin
);
21900 Qcenter
= intern ("center");
21901 staticpro (&Qcenter
);
21902 Qline_height
= intern ("line-height");
21903 staticpro (&Qline_height
);
21904 Qtotal
= intern ("total");
21905 staticpro (&Qtotal
);
21906 QCalign_to
= intern (":align-to");
21907 staticpro (&QCalign_to
);
21908 QCrelative_width
= intern (":relative-width");
21909 staticpro (&QCrelative_width
);
21910 QCrelative_height
= intern (":relative-height");
21911 staticpro (&QCrelative_height
);
21912 QCeval
= intern (":eval");
21913 staticpro (&QCeval
);
21914 QCpropertize
= intern (":propertize");
21915 staticpro (&QCpropertize
);
21916 QCfile
= intern (":file");
21917 staticpro (&QCfile
);
21918 Qfontified
= intern ("fontified");
21919 staticpro (&Qfontified
);
21920 Qfontification_functions
= intern ("fontification-functions");
21921 staticpro (&Qfontification_functions
);
21922 Qtrailing_whitespace
= intern ("trailing-whitespace");
21923 staticpro (&Qtrailing_whitespace
);
21924 Qimage
= intern ("image");
21925 staticpro (&Qimage
);
21926 QCmap
= intern (":map");
21927 staticpro (&QCmap
);
21928 QCpointer
= intern (":pointer");
21929 staticpro (&QCpointer
);
21930 Qrect
= intern ("rect");
21931 staticpro (&Qrect
);
21932 Qcircle
= intern ("circle");
21933 staticpro (&Qcircle
);
21934 Qpoly
= intern ("poly");
21935 staticpro (&Qpoly
);
21936 Qmessage_truncate_lines
= intern ("message-truncate-lines");
21937 staticpro (&Qmessage_truncate_lines
);
21938 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
21939 staticpro (&Qcursor_in_non_selected_windows
);
21940 Qgrow_only
= intern ("grow-only");
21941 staticpro (&Qgrow_only
);
21942 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
21943 staticpro (&Qinhibit_menubar_update
);
21944 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
21945 staticpro (&Qinhibit_eval_during_redisplay
);
21946 Qposition
= intern ("position");
21947 staticpro (&Qposition
);
21948 Qbuffer_position
= intern ("buffer-position");
21949 staticpro (&Qbuffer_position
);
21950 Qobject
= intern ("object");
21951 staticpro (&Qobject
);
21952 Qbar
= intern ("bar");
21954 Qhbar
= intern ("hbar");
21955 staticpro (&Qhbar
);
21956 Qbox
= intern ("box");
21958 Qhollow
= intern ("hollow");
21959 staticpro (&Qhollow
);
21960 Qhand
= intern ("hand");
21961 staticpro (&Qhand
);
21962 Qarrow
= intern ("arrow");
21963 staticpro (&Qarrow
);
21964 Qtext
= intern ("text");
21965 staticpro (&Qtext
);
21966 Qrisky_local_variable
= intern ("risky-local-variable");
21967 staticpro (&Qrisky_local_variable
);
21968 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
21969 staticpro (&Qinhibit_free_realized_faces
);
21971 list_of_error
= Fcons (Fcons (intern ("error"),
21972 Fcons (intern ("void-variable"), Qnil
)),
21974 staticpro (&list_of_error
);
21976 Qlast_arrow_position
= intern ("last-arrow-position");
21977 staticpro (&Qlast_arrow_position
);
21978 Qlast_arrow_string
= intern ("last-arrow-string");
21979 staticpro (&Qlast_arrow_string
);
21981 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
21982 staticpro (&Qoverlay_arrow_string
);
21983 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
21984 staticpro (&Qoverlay_arrow_bitmap
);
21986 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
21987 staticpro (&echo_buffer
[0]);
21988 staticpro (&echo_buffer
[1]);
21990 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
21991 staticpro (&echo_area_buffer
[0]);
21992 staticpro (&echo_area_buffer
[1]);
21994 Vmessages_buffer_name
= build_string ("*Messages*");
21995 staticpro (&Vmessages_buffer_name
);
21997 mode_line_proptrans_alist
= Qnil
;
21998 staticpro (&mode_line_proptrans_alist
);
22000 mode_line_string_list
= Qnil
;
22001 staticpro (&mode_line_string_list
);
22003 help_echo_string
= Qnil
;
22004 staticpro (&help_echo_string
);
22005 help_echo_object
= Qnil
;
22006 staticpro (&help_echo_object
);
22007 help_echo_window
= Qnil
;
22008 staticpro (&help_echo_window
);
22009 previous_help_echo_string
= Qnil
;
22010 staticpro (&previous_help_echo_string
);
22011 help_echo_pos
= -1;
22013 #ifdef HAVE_WINDOW_SYSTEM
22014 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22015 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22016 For example, if a block cursor is over a tab, it will be drawn as
22017 wide as that tab on the display. */);
22018 x_stretch_cursor_p
= 0;
22021 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22022 doc
: /* *Non-nil means highlight trailing whitespace.
22023 The face used for trailing whitespace is `trailing-whitespace'. */);
22024 Vshow_trailing_whitespace
= Qnil
;
22026 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22027 doc
: /* *The pointer shape to show in void text areas.
22028 Nil means to show the text pointer. Other options are `arrow', `text',
22029 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22030 Vvoid_text_area_pointer
= Qarrow
;
22032 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22033 doc
: /* Non-nil means don't actually do any redisplay.
22034 This is used for internal purposes. */);
22035 Vinhibit_redisplay
= Qnil
;
22037 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22038 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22039 Vglobal_mode_string
= Qnil
;
22041 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22042 doc
: /* Marker for where to display an arrow on top of the buffer text.
22043 This must be the beginning of a line in order to work.
22044 See also `overlay-arrow-string'. */);
22045 Voverlay_arrow_position
= Qnil
;
22047 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22048 doc
: /* String to display as an arrow in non-window frames.
22049 See also `overlay-arrow-position'. */);
22050 Voverlay_arrow_string
= Qnil
;
22052 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22053 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22054 The symbols on this list are examined during redisplay to determine
22055 where to display overlay arrows. */);
22056 Voverlay_arrow_variable_list
22057 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22059 DEFVAR_INT ("scroll-step", &scroll_step
,
22060 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22061 If that fails to bring point back on frame, point is centered instead.
22062 If this is zero, point is always centered after it moves off frame.
22063 If you want scrolling to always be a line at a time, you should set
22064 `scroll-conservatively' to a large value rather than set this to 1. */);
22066 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22067 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22068 A value of zero means to scroll the text to center point vertically
22069 in the window. */);
22070 scroll_conservatively
= 0;
22072 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22073 doc
: /* *Number of lines of margin at the top and bottom of a window.
22074 Recenter the window whenever point gets within this many lines
22075 of the top or bottom of the window. */);
22078 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22079 doc
: /* Pixels per inch on current display.
22080 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22081 Vdisplay_pixels_per_inch
= make_float (72.0);
22084 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22087 DEFVAR_BOOL ("truncate-partial-width-windows",
22088 &truncate_partial_width_windows
,
22089 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22090 truncate_partial_width_windows
= 1;
22092 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22093 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22094 Any other value means to use the appropriate face, `mode-line',
22095 `header-line', or `menu' respectively. */);
22096 mode_line_inverse_video
= 1;
22098 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22099 doc
: /* *Maximum buffer size for which line number should be displayed.
22100 If the buffer is bigger than this, the line number does not appear
22101 in the mode line. A value of nil means no limit. */);
22102 Vline_number_display_limit
= Qnil
;
22104 DEFVAR_INT ("line-number-display-limit-width",
22105 &line_number_display_limit_width
,
22106 doc
: /* *Maximum line width (in characters) for line number display.
22107 If the average length of the lines near point is bigger than this, then the
22108 line number may be omitted from the mode line. */);
22109 line_number_display_limit_width
= 200;
22111 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22112 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22113 highlight_nonselected_windows
= 0;
22115 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22116 doc
: /* Non-nil if more than one frame is visible on this display.
22117 Minibuffer-only frames don't count, but iconified frames do.
22118 This variable is not guaranteed to be accurate except while processing
22119 `frame-title-format' and `icon-title-format'. */);
22121 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22122 doc
: /* Template for displaying the title bar of visible frames.
22123 \(Assuming the window manager supports this feature.)
22124 This variable has the same structure as `mode-line-format' (which see),
22125 and is used only on frames for which no explicit name has been set
22126 \(see `modify-frame-parameters'). */);
22128 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22129 doc
: /* Template for displaying the title bar of an iconified frame.
22130 \(Assuming the window manager supports this feature.)
22131 This variable has the same structure as `mode-line-format' (which see),
22132 and is used only on frames for which no explicit name has been set
22133 \(see `modify-frame-parameters'). */);
22135 = Vframe_title_format
22136 = Fcons (intern ("multiple-frames"),
22137 Fcons (build_string ("%b"),
22138 Fcons (Fcons (empty_string
,
22139 Fcons (intern ("invocation-name"),
22140 Fcons (build_string ("@"),
22141 Fcons (intern ("system-name"),
22145 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22146 doc
: /* Maximum number of lines to keep in the message log buffer.
22147 If nil, disable message logging. If t, log messages but don't truncate
22148 the buffer when it becomes large. */);
22149 Vmessage_log_max
= make_number (50);
22151 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22152 doc
: /* Functions called before redisplay, if window sizes have changed.
22153 The value should be a list of functions that take one argument.
22154 Just before redisplay, for each frame, if any of its windows have changed
22155 size since the last redisplay, or have been split or deleted,
22156 all the functions in the list are called, with the frame as argument. */);
22157 Vwindow_size_change_functions
= Qnil
;
22159 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22160 doc
: /* List of Functions to call before redisplaying a window with scrolling.
22161 Each function is called with two arguments, the window
22162 and its new display-start position. Note that the value of `window-end'
22163 is not valid when these functions are called. */);
22164 Vwindow_scroll_functions
= Qnil
;
22166 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22167 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22168 mouse_autoselect_window
= 0;
22170 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22171 doc
: /* *Non-nil means automatically resize tool-bars.
22172 This increases a tool-bar's height if not all tool-bar items are visible.
22173 It decreases a tool-bar's height when it would display blank lines
22175 auto_resize_tool_bars_p
= 1;
22177 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22178 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22179 auto_raise_tool_bar_buttons_p
= 1;
22181 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22182 doc
: /* *Margin around tool-bar buttons in pixels.
22183 If an integer, use that for both horizontal and vertical margins.
22184 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22185 HORZ specifying the horizontal margin, and VERT specifying the
22186 vertical margin. */);
22187 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22189 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22190 doc
: /* *Relief thickness of tool-bar buttons. */);
22191 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22193 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22194 doc
: /* List of functions to call to fontify regions of text.
22195 Each function is called with one argument POS. Functions must
22196 fontify a region starting at POS in the current buffer, and give
22197 fontified regions the property `fontified'. */);
22198 Vfontification_functions
= Qnil
;
22199 Fmake_variable_buffer_local (Qfontification_functions
);
22201 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22202 &unibyte_display_via_language_environment
,
22203 doc
: /* *Non-nil means display unibyte text according to language environment.
22204 Specifically this means that unibyte non-ASCII characters
22205 are displayed by converting them to the equivalent multibyte characters
22206 according to the current language environment. As a result, they are
22207 displayed according to the current fontset. */);
22208 unibyte_display_via_language_environment
= 0;
22210 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22211 doc
: /* *Maximum height for resizing mini-windows.
22212 If a float, it specifies a fraction of the mini-window frame's height.
22213 If an integer, it specifies a number of lines. */);
22214 Vmax_mini_window_height
= make_float (0.25);
22216 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22217 doc
: /* *How to resize mini-windows.
22218 A value of nil means don't automatically resize mini-windows.
22219 A value of t means resize them to fit the text displayed in them.
22220 A value of `grow-only', the default, means let mini-windows grow
22221 only, until their display becomes empty, at which point the windows
22222 go back to their normal size. */);
22223 Vresize_mini_windows
= Qgrow_only
;
22225 DEFVAR_LISP ("cursor-in-non-selected-windows",
22226 &Vcursor_in_non_selected_windows
,
22227 doc
: /* *Cursor type to display in non-selected windows.
22228 t means to use hollow box cursor. See `cursor-type' for other values. */);
22229 Vcursor_in_non_selected_windows
= Qt
;
22231 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22232 doc
: /* Alist specifying how to blink the cursor off.
22233 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22234 `cursor-type' frame-parameter or variable equals ON-STATE,
22235 comparing using `equal', Emacs uses OFF-STATE to specify
22236 how to blink it off. */);
22237 Vblink_cursor_alist
= Qnil
;
22239 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22240 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22241 automatic_hscrolling_p
= 1;
22243 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22244 doc
: /* *How many columns away from the window edge point is allowed to get
22245 before automatic hscrolling will horizontally scroll the window. */);
22246 hscroll_margin
= 5;
22248 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22249 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22250 When point is less than `automatic-hscroll-margin' columns from the window
22251 edge, automatic hscrolling will scroll the window by the amount of columns
22252 determined by this variable. If its value is a positive integer, scroll that
22253 many columns. If it's a positive floating-point number, it specifies the
22254 fraction of the window's width to scroll. If it's nil or zero, point will be
22255 centered horizontally after the scroll. Any other value, including negative
22256 numbers, are treated as if the value were zero.
22258 Automatic hscrolling always moves point outside the scroll margin, so if
22259 point was more than scroll step columns inside the margin, the window will
22260 scroll more than the value given by the scroll step.
22262 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22263 and `scroll-right' overrides this variable's effect. */);
22264 Vhscroll_step
= make_number (0);
22266 DEFVAR_LISP ("image-types", &Vimage_types
,
22267 doc
: /* List of supported image types.
22268 Each element of the list is a symbol for a supported image type. */);
22269 Vimage_types
= Qnil
;
22271 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22272 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22273 Bind this around calls to `message' to let it take effect. */);
22274 message_truncate_lines
= 0;
22276 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22277 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22278 Can be used to update submenus whose contents should vary. */);
22279 Vmenu_bar_update_hook
= Qnil
;
22281 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22282 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22283 inhibit_menubar_update
= 0;
22285 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22286 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22287 inhibit_eval_during_redisplay
= 0;
22289 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22290 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22291 inhibit_free_realized_faces
= 0;
22294 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22295 doc
: /* Inhibit try_window_id display optimization. */);
22296 inhibit_try_window_id
= 0;
22298 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22299 doc
: /* Inhibit try_window_reusing display optimization. */);
22300 inhibit_try_window_reusing
= 0;
22302 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22303 doc
: /* Inhibit try_cursor_movement display optimization. */);
22304 inhibit_try_cursor_movement
= 0;
22305 #endif /* GLYPH_DEBUG */
22309 /* Initialize this module when Emacs starts. */
22314 Lisp_Object root_window
;
22315 struct window
*mini_w
;
22317 current_header_line_height
= current_mode_line_height
= -1;
22319 CHARPOS (this_line_start_pos
) = 0;
22321 mini_w
= XWINDOW (minibuf_window
);
22322 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22324 if (!noninteractive
)
22326 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22329 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22330 set_window_height (root_window
,
22331 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22333 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22334 set_window_height (minibuf_window
, 1, 0);
22336 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22337 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22339 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22340 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22341 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22343 /* The default ellipsis glyphs `...'. */
22344 for (i
= 0; i
< 3; ++i
)
22345 default_invis_vector
[i
] = make_number ('.');
22349 /* Allocate the buffer for frame titles.
22350 Also used for `format-mode-line'. */
22352 frame_title_buf
= (char *) xmalloc (size
);
22353 frame_title_buf_end
= frame_title_buf
+ size
;
22354 frame_title_ptr
= NULL
;
22357 help_echo_showing_p
= 0;
22361 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22362 (do not change this comment) */