1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03,04
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
203 #ifndef FRAME_X_OUTPUT
204 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
207 #define INFINITY 10000000
209 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
211 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
212 extern int pending_menu_activation
;
215 extern int interrupt_input
;
216 extern int command_loop_level
;
218 extern Lisp_Object do_mouse_tracking
;
220 extern int minibuffer_auto_raise
;
221 extern Lisp_Object Vminibuffer_list
;
223 extern Lisp_Object Qface
;
224 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
226 extern Lisp_Object Voverriding_local_map
;
227 extern Lisp_Object Voverriding_local_map_menu_flag
;
228 extern Lisp_Object Qmenu_item
;
229 extern Lisp_Object Qwhen
;
230 extern Lisp_Object Qhelp_echo
;
232 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
233 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
234 Lisp_Object Qredisplay_end_trigger_functions
;
235 Lisp_Object Qinhibit_point_motion_hooks
;
236 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
237 Lisp_Object Qfontified
;
238 Lisp_Object Qgrow_only
;
239 Lisp_Object Qinhibit_eval_during_redisplay
;
240 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
243 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Non-zero means to reposition window if cursor line is only partially visible. */
269 int make_cursor_line_fully_visible_p
;
271 /* Margin around tool bar buttons in pixels. */
273 Lisp_Object Vtool_bar_button_margin
;
275 /* Thickness of shadow to draw around tool bar buttons. */
277 EMACS_INT tool_bar_button_relief
;
279 /* Non-zero means automatically resize tool-bars so that all tool-bar
280 items are visible, and no blank lines remain. */
282 int auto_resize_tool_bars_p
;
284 /* Non-zero means draw block and hollow cursor as wide as the glyph
285 under it. For example, if a block cursor is over a tab, it will be
286 drawn as wide as that tab on the display. */
288 int x_stretch_cursor_p
;
290 /* Non-nil means don't actually do any redisplay. */
292 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
294 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
296 int inhibit_eval_during_redisplay
;
298 /* Names of text properties relevant for redisplay. */
300 Lisp_Object Qdisplay
;
301 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
303 /* Symbols used in text property values. */
305 Lisp_Object Vdisplay_pixels_per_inch
;
306 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
307 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
310 Lisp_Object Qmargin
, Qpointer
;
311 Lisp_Object Qline_height
, Qtotal
;
312 extern Lisp_Object Qheight
;
313 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
314 extern Lisp_Object Qscroll_bar
;
315 extern Lisp_Object Qcursor
;
317 /* Non-nil means highlight trailing whitespace. */
319 Lisp_Object Vshow_trailing_whitespace
;
321 #ifdef HAVE_WINDOW_SYSTEM
322 extern Lisp_Object Voverflow_newline_into_fringe
;
324 /* Test if overflow newline into fringe. Called with iterator IT
325 at or past right window margin, and with IT->current_x set. */
327 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
328 (!NILP (Voverflow_newline_into_fringe) \
329 && FRAME_WINDOW_P (it->f) \
330 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
331 && it->current_x == it->last_visible_x)
333 #endif /* HAVE_WINDOW_SYSTEM */
335 /* Non-nil means show the text cursor in void text areas
336 i.e. in blank areas after eol and eob. This used to be
337 the default in 21.3. */
339 Lisp_Object Vvoid_text_area_pointer
;
341 /* Name of the face used to highlight trailing whitespace. */
343 Lisp_Object Qtrailing_whitespace
;
345 /* Name and number of the face used to highlight escape glyphs. */
347 Lisp_Object Qescape_glyph
;
348 int escape_glyph_face
;
350 /* The symbol `image' which is the car of the lists used to represent
355 /* The image map types. */
356 Lisp_Object QCmap
, QCpointer
;
357 Lisp_Object Qrect
, Qcircle
, Qpoly
;
359 /* Non-zero means print newline to stdout before next mini-buffer
362 int noninteractive_need_newline
;
364 /* Non-zero means print newline to message log before next message. */
366 static int message_log_need_newline
;
368 /* Three markers that message_dolog uses.
369 It could allocate them itself, but that causes trouble
370 in handling memory-full errors. */
371 static Lisp_Object message_dolog_marker1
;
372 static Lisp_Object message_dolog_marker2
;
373 static Lisp_Object message_dolog_marker3
;
375 /* The buffer position of the first character appearing entirely or
376 partially on the line of the selected window which contains the
377 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
378 redisplay optimization in redisplay_internal. */
380 static struct text_pos this_line_start_pos
;
382 /* Number of characters past the end of the line above, including the
383 terminating newline. */
385 static struct text_pos this_line_end_pos
;
387 /* The vertical positions and the height of this line. */
389 static int this_line_vpos
;
390 static int this_line_y
;
391 static int this_line_pixel_height
;
393 /* X position at which this display line starts. Usually zero;
394 negative if first character is partially visible. */
396 static int this_line_start_x
;
398 /* Buffer that this_line_.* variables are referring to. */
400 static struct buffer
*this_line_buffer
;
402 /* Nonzero means truncate lines in all windows less wide than the
405 int truncate_partial_width_windows
;
407 /* A flag to control how to display unibyte 8-bit character. */
409 int unibyte_display_via_language_environment
;
411 /* Nonzero means we have more than one non-mini-buffer-only frame.
412 Not guaranteed to be accurate except while parsing
413 frame-title-format. */
417 Lisp_Object Vglobal_mode_string
;
420 /* List of variables (symbols) which hold markers for overlay arrows.
421 The symbols on this list are examined during redisplay to determine
422 where to display overlay arrows. */
424 Lisp_Object Voverlay_arrow_variable_list
;
426 /* Marker for where to display an arrow on top of the buffer text. */
428 Lisp_Object Voverlay_arrow_position
;
430 /* String to display for the arrow. Only used on terminal frames. */
432 Lisp_Object Voverlay_arrow_string
;
434 /* Values of those variables at last redisplay are stored as
435 properties on `overlay-arrow-position' symbol. However, if
436 Voverlay_arrow_position is a marker, last-arrow-position is its
437 numerical position. */
439 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
441 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
442 properties on a symbol in overlay-arrow-variable-list. */
444 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
446 /* Like mode-line-format, but for the title bar on a visible frame. */
448 Lisp_Object Vframe_title_format
;
450 /* Like mode-line-format, but for the title bar on an iconified frame. */
452 Lisp_Object Vicon_title_format
;
454 /* List of functions to call when a window's size changes. These
455 functions get one arg, a frame on which one or more windows' sizes
458 static Lisp_Object Vwindow_size_change_functions
;
460 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
462 /* Nonzero if overlay arrow has been displayed once in this window. */
464 static int overlay_arrow_seen
;
466 /* Nonzero means highlight the region even in nonselected windows. */
468 int highlight_nonselected_windows
;
470 /* If cursor motion alone moves point off frame, try scrolling this
471 many lines up or down if that will bring it back. */
473 static EMACS_INT scroll_step
;
475 /* Nonzero means scroll just far enough to bring point back on the
476 screen, when appropriate. */
478 static EMACS_INT scroll_conservatively
;
480 /* Recenter the window whenever point gets within this many lines of
481 the top or bottom of the window. This value is translated into a
482 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
483 that there is really a fixed pixel height scroll margin. */
485 EMACS_INT scroll_margin
;
487 /* Number of windows showing the buffer of the selected window (or
488 another buffer with the same base buffer). keyboard.c refers to
493 /* Vector containing glyphs for an ellipsis `...'. */
495 static Lisp_Object default_invis_vector
[3];
497 /* Zero means display the mode-line/header-line/menu-bar in the default face
498 (this slightly odd definition is for compatibility with previous versions
499 of emacs), non-zero means display them using their respective faces.
501 This variable is deprecated. */
503 int mode_line_inverse_video
;
505 /* Prompt to display in front of the mini-buffer contents. */
507 Lisp_Object minibuf_prompt
;
509 /* Width of current mini-buffer prompt. Only set after display_line
510 of the line that contains the prompt. */
512 int minibuf_prompt_width
;
514 /* This is the window where the echo area message was displayed. It
515 is always a mini-buffer window, but it may not be the same window
516 currently active as a mini-buffer. */
518 Lisp_Object echo_area_window
;
520 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
521 pushes the current message and the value of
522 message_enable_multibyte on the stack, the function restore_message
523 pops the stack and displays MESSAGE again. */
525 Lisp_Object Vmessage_stack
;
527 /* Nonzero means multibyte characters were enabled when the echo area
528 message was specified. */
530 int message_enable_multibyte
;
532 /* Nonzero if we should redraw the mode lines on the next redisplay. */
534 int update_mode_lines
;
536 /* Nonzero if window sizes or contents have changed since last
537 redisplay that finished. */
539 int windows_or_buffers_changed
;
541 /* Nonzero means a frame's cursor type has been changed. */
543 int cursor_type_changed
;
545 /* Nonzero after display_mode_line if %l was used and it displayed a
548 int line_number_displayed
;
550 /* Maximum buffer size for which to display line numbers. */
552 Lisp_Object Vline_number_display_limit
;
554 /* Line width to consider when repositioning for line number display. */
556 static EMACS_INT line_number_display_limit_width
;
558 /* Number of lines to keep in the message log buffer. t means
559 infinite. nil means don't log at all. */
561 Lisp_Object Vmessage_log_max
;
563 /* The name of the *Messages* buffer, a string. */
565 static Lisp_Object Vmessages_buffer_name
;
567 /* Current, index 0, and last displayed echo area message. Either
568 buffers from echo_buffers, or nil to indicate no message. */
570 Lisp_Object echo_area_buffer
[2];
572 /* The buffers referenced from echo_area_buffer. */
574 static Lisp_Object echo_buffer
[2];
576 /* A vector saved used in with_area_buffer to reduce consing. */
578 static Lisp_Object Vwith_echo_area_save_vector
;
580 /* Non-zero means display_echo_area should display the last echo area
581 message again. Set by redisplay_preserve_echo_area. */
583 static int display_last_displayed_message_p
;
585 /* Nonzero if echo area is being used by print; zero if being used by
588 int message_buf_print
;
590 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
592 Lisp_Object Qinhibit_menubar_update
;
593 int inhibit_menubar_update
;
595 /* Maximum height for resizing mini-windows. Either a float
596 specifying a fraction of the available height, or an integer
597 specifying a number of lines. */
599 Lisp_Object Vmax_mini_window_height
;
601 /* Non-zero means messages should be displayed with truncated
602 lines instead of being continued. */
604 int message_truncate_lines
;
605 Lisp_Object Qmessage_truncate_lines
;
607 /* Set to 1 in clear_message to make redisplay_internal aware
608 of an emptied echo area. */
610 static int message_cleared_p
;
612 /* Non-zero means we want a hollow cursor in windows that are not
613 selected. Zero means there's no cursor in such windows. */
615 Lisp_Object Vcursor_in_non_selected_windows
;
616 Lisp_Object Qcursor_in_non_selected_windows
;
618 /* How to blink the default frame cursor off. */
619 Lisp_Object Vblink_cursor_alist
;
621 /* A scratch glyph row with contents used for generating truncation
622 glyphs. Also used in direct_output_for_insert. */
624 #define MAX_SCRATCH_GLYPHS 100
625 struct glyph_row scratch_glyph_row
;
626 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
628 /* Ascent and height of the last line processed by move_it_to. */
630 static int last_max_ascent
, last_height
;
632 /* Non-zero if there's a help-echo in the echo area. */
634 int help_echo_showing_p
;
636 /* If >= 0, computed, exact values of mode-line and header-line height
637 to use in the macros CURRENT_MODE_LINE_HEIGHT and
638 CURRENT_HEADER_LINE_HEIGHT. */
640 int current_mode_line_height
, current_header_line_height
;
642 /* The maximum distance to look ahead for text properties. Values
643 that are too small let us call compute_char_face and similar
644 functions too often which is expensive. Values that are too large
645 let us call compute_char_face and alike too often because we
646 might not be interested in text properties that far away. */
648 #define TEXT_PROP_DISTANCE_LIMIT 100
652 /* Variables to turn off display optimizations from Lisp. */
654 int inhibit_try_window_id
, inhibit_try_window_reusing
;
655 int inhibit_try_cursor_movement
;
657 /* Non-zero means print traces of redisplay if compiled with
660 int trace_redisplay_p
;
662 #endif /* GLYPH_DEBUG */
664 #ifdef DEBUG_TRACE_MOVE
665 /* Non-zero means trace with TRACE_MOVE to stderr. */
668 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
670 #define TRACE_MOVE(x) (void) 0
673 /* Non-zero means automatically scroll windows horizontally to make
676 int automatic_hscrolling_p
;
678 /* How close to the margin can point get before the window is scrolled
680 EMACS_INT hscroll_margin
;
682 /* How much to scroll horizontally when point is inside the above margin. */
683 Lisp_Object Vhscroll_step
;
685 /* The variable `resize-mini-windows'. If nil, don't resize
686 mini-windows. If t, always resize them to fit the text they
687 display. If `grow-only', let mini-windows grow only until they
690 Lisp_Object Vresize_mini_windows
;
692 /* Buffer being redisplayed -- for redisplay_window_error. */
694 struct buffer
*displayed_buffer
;
696 /* Value returned from text property handlers (see below). */
701 HANDLED_RECOMPUTE_PROPS
,
702 HANDLED_OVERLAY_STRING_CONSUMED
,
706 /* A description of text properties that redisplay is interested
711 /* The name of the property. */
714 /* A unique index for the property. */
717 /* A handler function called to set up iterator IT from the property
718 at IT's current position. Value is used to steer handle_stop. */
719 enum prop_handled (*handler
) P_ ((struct it
*it
));
722 static enum prop_handled handle_face_prop
P_ ((struct it
*));
723 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
724 static enum prop_handled handle_display_prop
P_ ((struct it
*));
725 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
726 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
727 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
729 /* Properties handled by iterators. */
731 static struct props it_props
[] =
733 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
734 /* Handle `face' before `display' because some sub-properties of
735 `display' need to know the face. */
736 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
737 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
738 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
739 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
743 /* Value is the position described by X. If X is a marker, value is
744 the marker_position of X. Otherwise, value is X. */
746 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
748 /* Enumeration returned by some move_it_.* functions internally. */
752 /* Not used. Undefined value. */
755 /* Move ended at the requested buffer position or ZV. */
756 MOVE_POS_MATCH_OR_ZV
,
758 /* Move ended at the requested X pixel position. */
761 /* Move within a line ended at the end of a line that must be
765 /* Move within a line ended at the end of a line that would
766 be displayed truncated. */
769 /* Move within a line ended at a line end. */
773 /* This counter is used to clear the face cache every once in a while
774 in redisplay_internal. It is incremented for each redisplay.
775 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
778 #define CLEAR_FACE_CACHE_COUNT 500
779 static int clear_face_cache_count
;
781 /* Non-zero while redisplay_internal is in progress. */
785 /* Non-zero means don't free realized faces. Bound while freeing
786 realized faces is dangerous because glyph matrices might still
789 int inhibit_free_realized_faces
;
790 Lisp_Object Qinhibit_free_realized_faces
;
792 /* If a string, XTread_socket generates an event to display that string.
793 (The display is done in read_char.) */
795 Lisp_Object help_echo_string
;
796 Lisp_Object help_echo_window
;
797 Lisp_Object help_echo_object
;
800 /* Temporary variable for XTread_socket. */
802 Lisp_Object previous_help_echo_string
;
804 /* Null glyph slice */
806 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
809 /* Function prototypes. */
811 static void setup_for_ellipsis
P_ ((struct it
*, int));
812 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
813 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
814 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
815 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
816 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
817 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
820 static int invisible_text_between_p
P_ ((struct it
*, int, int));
823 static int next_element_from_ellipsis
P_ ((struct it
*));
824 static void pint2str
P_ ((char *, int, int));
825 static void pint2hrstr
P_ ((char *, int, int));
826 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
828 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
829 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
830 static void store_frame_title_char
P_ ((char));
831 static int store_frame_title
P_ ((const unsigned char *, int, int));
832 static void x_consider_frame_title
P_ ((Lisp_Object
));
833 static void handle_stop
P_ ((struct it
*));
834 static int tool_bar_lines_needed
P_ ((struct frame
*));
835 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
836 static void ensure_echo_area_buffers
P_ ((void));
837 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
838 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
839 static int with_echo_area_buffer
P_ ((struct window
*, int,
840 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
841 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
842 static void clear_garbaged_frames
P_ ((void));
843 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
844 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
845 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
846 static int display_echo_area
P_ ((struct window
*));
847 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
848 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
849 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
850 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
851 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
853 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
854 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
855 static void insert_left_trunc_glyphs
P_ ((struct it
*));
856 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
858 static void extend_face_to_end_of_line
P_ ((struct it
*));
859 static int append_space_for_newline
P_ ((struct it
*, int));
860 static int make_cursor_line_fully_visible
P_ ((struct window
*, int));
861 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
862 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
863 static int trailing_whitespace_p
P_ ((int));
864 static int message_log_check_duplicate
P_ ((int, int, int, int));
865 static void push_it
P_ ((struct it
*));
866 static void pop_it
P_ ((struct it
*));
867 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
868 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
869 static void redisplay_internal
P_ ((int));
870 static int echo_area_display
P_ ((int));
871 static void redisplay_windows
P_ ((Lisp_Object
));
872 static void redisplay_window
P_ ((Lisp_Object
, int));
873 static Lisp_Object
redisplay_window_error ();
874 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
875 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
876 static void update_menu_bar
P_ ((struct frame
*, int));
877 static int try_window_reusing_current_matrix
P_ ((struct window
*));
878 static int try_window_id
P_ ((struct window
*));
879 static int display_line
P_ ((struct it
*));
880 static int display_mode_lines
P_ ((struct window
*));
881 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
882 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
883 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
884 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
885 static void display_menu_bar
P_ ((struct window
*));
886 static int display_count_lines
P_ ((int, int, int, int, int *));
887 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
888 int, int, struct it
*, int, int, int, int));
889 static void compute_line_metrics
P_ ((struct it
*));
890 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
891 static int get_overlay_strings
P_ ((struct it
*, int));
892 static void next_overlay_string
P_ ((struct it
*));
893 static void reseat
P_ ((struct it
*, struct text_pos
, int));
894 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
895 static void back_to_previous_visible_line_start
P_ ((struct it
*));
896 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
897 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
898 static int next_element_from_display_vector
P_ ((struct it
*));
899 static int next_element_from_string
P_ ((struct it
*));
900 static int next_element_from_c_string
P_ ((struct it
*));
901 static int next_element_from_buffer
P_ ((struct it
*));
902 static int next_element_from_composition
P_ ((struct it
*));
903 static int next_element_from_image
P_ ((struct it
*));
904 static int next_element_from_stretch
P_ ((struct it
*));
905 static void load_overlay_strings
P_ ((struct it
*, int));
906 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
907 struct display_pos
*));
908 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
909 Lisp_Object
, int, int, int, int));
910 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
912 void move_it_vertically_backward
P_ ((struct it
*, int));
913 static void init_to_row_start
P_ ((struct it
*, struct window
*,
914 struct glyph_row
*));
915 static int init_to_row_end
P_ ((struct it
*, struct window
*,
916 struct glyph_row
*));
917 static void back_to_previous_line_start
P_ ((struct it
*));
918 static int forward_to_next_line_start
P_ ((struct it
*, int *));
919 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
921 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
922 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
923 static int number_of_chars
P_ ((unsigned char *, int));
924 static void compute_stop_pos
P_ ((struct it
*));
925 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
927 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
928 static int next_overlay_change
P_ ((int));
929 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
930 Lisp_Object
, struct text_pos
*,
932 static int underlying_face_id
P_ ((struct it
*));
933 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
936 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
937 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
939 #ifdef HAVE_WINDOW_SYSTEM
941 static void update_tool_bar
P_ ((struct frame
*, int));
942 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
943 static int redisplay_tool_bar
P_ ((struct frame
*));
944 static void display_tool_bar_line
P_ ((struct it
*));
945 static void notice_overwritten_cursor
P_ ((struct window
*,
947 int, int, int, int));
951 #endif /* HAVE_WINDOW_SYSTEM */
954 /***********************************************************************
955 Window display dimensions
956 ***********************************************************************/
958 /* Return the bottom boundary y-position for text lines in window W.
959 This is the first y position at which a line cannot start.
960 It is relative to the top of the window.
962 This is the height of W minus the height of a mode line, if any. */
965 window_text_bottom_y (w
)
968 int height
= WINDOW_TOTAL_HEIGHT (w
);
970 if (WINDOW_WANTS_MODELINE_P (w
))
971 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
975 /* Return the pixel width of display area AREA of window W. AREA < 0
976 means return the total width of W, not including fringes to
977 the left and right of the window. */
980 window_box_width (w
, area
)
984 int cols
= XFASTINT (w
->total_cols
);
987 if (!w
->pseudo_window_p
)
989 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
991 if (area
== TEXT_AREA
)
993 if (INTEGERP (w
->left_margin_cols
))
994 cols
-= XFASTINT (w
->left_margin_cols
);
995 if (INTEGERP (w
->right_margin_cols
))
996 cols
-= XFASTINT (w
->right_margin_cols
);
997 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
999 else if (area
== LEFT_MARGIN_AREA
)
1001 cols
= (INTEGERP (w
->left_margin_cols
)
1002 ? XFASTINT (w
->left_margin_cols
) : 0);
1005 else if (area
== RIGHT_MARGIN_AREA
)
1007 cols
= (INTEGERP (w
->right_margin_cols
)
1008 ? XFASTINT (w
->right_margin_cols
) : 0);
1013 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1017 /* Return the pixel height of the display area of window W, not
1018 including mode lines of W, if any. */
1021 window_box_height (w
)
1024 struct frame
*f
= XFRAME (w
->frame
);
1025 int height
= WINDOW_TOTAL_HEIGHT (w
);
1027 xassert (height
>= 0);
1029 /* Note: the code below that determines the mode-line/header-line
1030 height is essentially the same as that contained in the macro
1031 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1032 the appropriate glyph row has its `mode_line_p' flag set,
1033 and if it doesn't, uses estimate_mode_line_height instead. */
1035 if (WINDOW_WANTS_MODELINE_P (w
))
1037 struct glyph_row
*ml_row
1038 = (w
->current_matrix
&& w
->current_matrix
->rows
1039 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1041 if (ml_row
&& ml_row
->mode_line_p
)
1042 height
-= ml_row
->height
;
1044 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1047 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1049 struct glyph_row
*hl_row
1050 = (w
->current_matrix
&& w
->current_matrix
->rows
1051 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1053 if (hl_row
&& hl_row
->mode_line_p
)
1054 height
-= hl_row
->height
;
1056 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1059 /* With a very small font and a mode-line that's taller than
1060 default, we might end up with a negative height. */
1061 return max (0, height
);
1064 /* Return the window-relative coordinate of the left edge of display
1065 area AREA of window W. AREA < 0 means return the left edge of the
1066 whole window, to the right of the left fringe of W. */
1069 window_box_left_offset (w
, area
)
1075 if (w
->pseudo_window_p
)
1078 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1080 if (area
== TEXT_AREA
)
1081 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1082 + window_box_width (w
, LEFT_MARGIN_AREA
));
1083 else if (area
== RIGHT_MARGIN_AREA
)
1084 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1085 + window_box_width (w
, LEFT_MARGIN_AREA
)
1086 + window_box_width (w
, TEXT_AREA
)
1087 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1089 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1090 else if (area
== LEFT_MARGIN_AREA
1091 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1092 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1098 /* Return the window-relative coordinate of the right edge of display
1099 area AREA of window W. AREA < 0 means return the left edge of the
1100 whole window, to the left of the right fringe of W. */
1103 window_box_right_offset (w
, area
)
1107 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1110 /* Return the frame-relative coordinate of the left edge of display
1111 area AREA of window W. AREA < 0 means return the left edge of the
1112 whole window, to the right of the left fringe of W. */
1115 window_box_left (w
, area
)
1119 struct frame
*f
= XFRAME (w
->frame
);
1122 if (w
->pseudo_window_p
)
1123 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1125 x
= (WINDOW_LEFT_EDGE_X (w
)
1126 + window_box_left_offset (w
, area
));
1132 /* Return the frame-relative coordinate of the right edge of display
1133 area AREA of window W. AREA < 0 means return the left edge of the
1134 whole window, to the left of the right fringe of W. */
1137 window_box_right (w
, area
)
1141 return window_box_left (w
, area
) + window_box_width (w
, area
);
1144 /* Get the bounding box of the display area AREA of window W, without
1145 mode lines, in frame-relative coordinates. AREA < 0 means the
1146 whole window, not including the left and right fringes of
1147 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1148 coordinates of the upper-left corner of the box. Return in
1149 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1152 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1155 int *box_x
, *box_y
, *box_width
, *box_height
;
1158 *box_width
= window_box_width (w
, area
);
1160 *box_height
= window_box_height (w
);
1162 *box_x
= window_box_left (w
, area
);
1165 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1166 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1167 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1172 /* Get the bounding box of the display area AREA of window W, without
1173 mode lines. AREA < 0 means the whole window, not including the
1174 left and right fringe of the window. Return in *TOP_LEFT_X
1175 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1176 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1177 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1181 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1182 bottom_right_x
, bottom_right_y
)
1185 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1187 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1189 *bottom_right_x
+= *top_left_x
;
1190 *bottom_right_y
+= *top_left_y
;
1195 /***********************************************************************
1197 ***********************************************************************/
1199 /* Return the bottom y-position of the line the iterator IT is in.
1200 This can modify IT's settings. */
1206 int line_height
= it
->max_ascent
+ it
->max_descent
;
1207 int line_top_y
= it
->current_y
;
1209 if (line_height
== 0)
1212 line_height
= last_height
;
1213 else if (IT_CHARPOS (*it
) < ZV
)
1215 move_it_by_lines (it
, 1, 1);
1216 line_height
= (it
->max_ascent
|| it
->max_descent
1217 ? it
->max_ascent
+ it
->max_descent
1222 struct glyph_row
*row
= it
->glyph_row
;
1224 /* Use the default character height. */
1225 it
->glyph_row
= NULL
;
1226 it
->what
= IT_CHARACTER
;
1229 PRODUCE_GLYPHS (it
);
1230 line_height
= it
->ascent
+ it
->descent
;
1231 it
->glyph_row
= row
;
1235 return line_top_y
+ line_height
;
1239 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1240 1 if POS is visible and the line containing POS is fully visible.
1241 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1242 and header-lines heights. */
1245 pos_visible_p (w
, charpos
, fully
, x
, y
, exact_mode_line_heights_p
)
1247 int charpos
, *fully
, *x
, *y
, exact_mode_line_heights_p
;
1250 struct text_pos top
;
1252 struct buffer
*old_buffer
= NULL
;
1254 if (XBUFFER (w
->buffer
) != current_buffer
)
1256 old_buffer
= current_buffer
;
1257 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1260 *fully
= visible_p
= 0;
1261 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1263 /* Compute exact mode line heights, if requested. */
1264 if (exact_mode_line_heights_p
)
1266 if (WINDOW_WANTS_MODELINE_P (w
))
1267 current_mode_line_height
1268 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1269 current_buffer
->mode_line_format
);
1271 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1272 current_header_line_height
1273 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1274 current_buffer
->header_line_format
);
1277 start_display (&it
, w
, top
);
1278 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1279 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1281 /* Note that we may overshoot because of invisible text. */
1282 if (IT_CHARPOS (it
) >= charpos
)
1284 int top_y
= it
.current_y
;
1285 int bottom_y
= line_bottom_y (&it
);
1286 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1288 if (top_y
< window_top_y
)
1289 visible_p
= bottom_y
> window_top_y
;
1290 else if (top_y
< it
.last_visible_y
)
1293 *fully
= bottom_y
<= it
.last_visible_y
;
1298 *y
= max (top_y
+ it
.max_ascent
- it
.ascent
, window_top_y
);
1301 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1306 move_it_by_lines (&it
, 1, 0);
1307 if (charpos
< IT_CHARPOS (it
))
1312 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1314 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1320 set_buffer_internal_1 (old_buffer
);
1322 current_header_line_height
= current_mode_line_height
= -1;
1328 /* Return the next character from STR which is MAXLEN bytes long.
1329 Return in *LEN the length of the character. This is like
1330 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1331 we find one, we return a `?', but with the length of the invalid
1335 string_char_and_length (str
, maxlen
, len
)
1336 const unsigned char *str
;
1341 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1342 if (!CHAR_VALID_P (c
, 1))
1343 /* We may not change the length here because other places in Emacs
1344 don't use this function, i.e. they silently accept invalid
1353 /* Given a position POS containing a valid character and byte position
1354 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1356 static struct text_pos
1357 string_pos_nchars_ahead (pos
, string
, nchars
)
1358 struct text_pos pos
;
1362 xassert (STRINGP (string
) && nchars
>= 0);
1364 if (STRING_MULTIBYTE (string
))
1366 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1367 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1372 string_char_and_length (p
, rest
, &len
);
1373 p
+= len
, rest
-= len
;
1374 xassert (rest
>= 0);
1376 BYTEPOS (pos
) += len
;
1380 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1386 /* Value is the text position, i.e. character and byte position,
1387 for character position CHARPOS in STRING. */
1389 static INLINE
struct text_pos
1390 string_pos (charpos
, string
)
1394 struct text_pos pos
;
1395 xassert (STRINGP (string
));
1396 xassert (charpos
>= 0);
1397 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1402 /* Value is a text position, i.e. character and byte position, for
1403 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1404 means recognize multibyte characters. */
1406 static struct text_pos
1407 c_string_pos (charpos
, s
, multibyte_p
)
1412 struct text_pos pos
;
1414 xassert (s
!= NULL
);
1415 xassert (charpos
>= 0);
1419 int rest
= strlen (s
), len
;
1421 SET_TEXT_POS (pos
, 0, 0);
1424 string_char_and_length (s
, rest
, &len
);
1425 s
+= len
, rest
-= len
;
1426 xassert (rest
>= 0);
1428 BYTEPOS (pos
) += len
;
1432 SET_TEXT_POS (pos
, charpos
, charpos
);
1438 /* Value is the number of characters in C string S. MULTIBYTE_P
1439 non-zero means recognize multibyte characters. */
1442 number_of_chars (s
, multibyte_p
)
1450 int rest
= strlen (s
), len
;
1451 unsigned char *p
= (unsigned char *) s
;
1453 for (nchars
= 0; rest
> 0; ++nchars
)
1455 string_char_and_length (p
, rest
, &len
);
1456 rest
-= len
, p
+= len
;
1460 nchars
= strlen (s
);
1466 /* Compute byte position NEWPOS->bytepos corresponding to
1467 NEWPOS->charpos. POS is a known position in string STRING.
1468 NEWPOS->charpos must be >= POS.charpos. */
1471 compute_string_pos (newpos
, pos
, string
)
1472 struct text_pos
*newpos
, pos
;
1475 xassert (STRINGP (string
));
1476 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1478 if (STRING_MULTIBYTE (string
))
1479 *newpos
= string_pos_nchars_ahead (pos
, string
,
1480 CHARPOS (*newpos
) - CHARPOS (pos
));
1482 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1486 Return an estimation of the pixel height of mode or top lines on
1487 frame F. FACE_ID specifies what line's height to estimate. */
1490 estimate_mode_line_height (f
, face_id
)
1492 enum face_id face_id
;
1494 #ifdef HAVE_WINDOW_SYSTEM
1495 if (FRAME_WINDOW_P (f
))
1497 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1499 /* This function is called so early when Emacs starts that the face
1500 cache and mode line face are not yet initialized. */
1501 if (FRAME_FACE_CACHE (f
))
1503 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1507 height
= FONT_HEIGHT (face
->font
);
1508 if (face
->box_line_width
> 0)
1509 height
+= 2 * face
->box_line_width
;
1520 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1521 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1522 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1523 not force the value into range. */
1526 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1528 register int pix_x
, pix_y
;
1530 NativeRectangle
*bounds
;
1534 #ifdef HAVE_WINDOW_SYSTEM
1535 if (FRAME_WINDOW_P (f
))
1537 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1538 even for negative values. */
1540 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1542 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1544 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1545 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1548 STORE_NATIVE_RECT (*bounds
,
1549 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1550 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1551 FRAME_COLUMN_WIDTH (f
) - 1,
1552 FRAME_LINE_HEIGHT (f
) - 1);
1558 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1559 pix_x
= FRAME_TOTAL_COLS (f
);
1563 else if (pix_y
> FRAME_LINES (f
))
1564 pix_y
= FRAME_LINES (f
);
1574 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1575 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1576 can't tell the positions because W's display is not up to date,
1580 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1583 int *frame_x
, *frame_y
;
1585 #ifdef HAVE_WINDOW_SYSTEM
1586 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1590 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1591 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1593 if (display_completed
)
1595 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1596 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1597 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1603 hpos
+= glyph
->pixel_width
;
1607 /* If first glyph is partially visible, its first visible position is still 0. */
1619 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1620 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1631 #ifdef HAVE_WINDOW_SYSTEM
1633 /* Find the glyph under window-relative coordinates X/Y in window W.
1634 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1635 strings. Return in *HPOS and *VPOS the row and column number of
1636 the glyph found. Return in *AREA the glyph area containing X.
1637 Value is a pointer to the glyph found or null if X/Y is not on
1638 text, or we can't tell because W's current matrix is not up to
1641 static struct glyph
*
1642 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1645 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1647 struct glyph
*glyph
, *end
;
1648 struct glyph_row
*row
= NULL
;
1651 /* Find row containing Y. Give up if some row is not enabled. */
1652 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1654 row
= MATRIX_ROW (w
->current_matrix
, i
);
1655 if (!row
->enabled_p
)
1657 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1664 /* Give up if Y is not in the window. */
1665 if (i
== w
->current_matrix
->nrows
)
1668 /* Get the glyph area containing X. */
1669 if (w
->pseudo_window_p
)
1676 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1678 *area
= LEFT_MARGIN_AREA
;
1679 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1681 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1684 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1688 *area
= RIGHT_MARGIN_AREA
;
1689 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1693 /* Find glyph containing X. */
1694 glyph
= row
->glyphs
[*area
];
1695 end
= glyph
+ row
->used
[*area
];
1697 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1699 x
-= glyph
->pixel_width
;
1709 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1712 *hpos
= glyph
- row
->glyphs
[*area
];
1718 Convert frame-relative x/y to coordinates relative to window W.
1719 Takes pseudo-windows into account. */
1722 frame_to_window_pixel_xy (w
, x
, y
)
1726 if (w
->pseudo_window_p
)
1728 /* A pseudo-window is always full-width, and starts at the
1729 left edge of the frame, plus a frame border. */
1730 struct frame
*f
= XFRAME (w
->frame
);
1731 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1732 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1736 *x
-= WINDOW_LEFT_EDGE_X (w
);
1737 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1742 Return in *R the clipping rectangle for glyph string S. */
1745 get_glyph_string_clip_rect (s
, nr
)
1746 struct glyph_string
*s
;
1747 NativeRectangle
*nr
;
1751 if (s
->row
->full_width_p
)
1753 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1754 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1755 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1757 /* Unless displaying a mode or menu bar line, which are always
1758 fully visible, clip to the visible part of the row. */
1759 if (s
->w
->pseudo_window_p
)
1760 r
.height
= s
->row
->visible_height
;
1762 r
.height
= s
->height
;
1766 /* This is a text line that may be partially visible. */
1767 r
.x
= window_box_left (s
->w
, s
->area
);
1768 r
.width
= window_box_width (s
->w
, s
->area
);
1769 r
.height
= s
->row
->visible_height
;
1772 /* If S draws overlapping rows, it's sufficient to use the top and
1773 bottom of the window for clipping because this glyph string
1774 intentionally draws over other lines. */
1775 if (s
->for_overlaps_p
)
1777 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1778 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1782 /* Don't use S->y for clipping because it doesn't take partially
1783 visible lines into account. For example, it can be negative for
1784 partially visible lines at the top of a window. */
1785 if (!s
->row
->full_width_p
1786 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1787 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1789 r
.y
= max (0, s
->row
->y
);
1791 /* If drawing a tool-bar window, draw it over the internal border
1792 at the top of the window. */
1793 if (WINDOWP (s
->f
->tool_bar_window
)
1794 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1795 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1798 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1800 /* If drawing the cursor, don't let glyph draw outside its
1801 advertised boundaries. Cleartype does this under some circumstances. */
1802 if (s
->hl
== DRAW_CURSOR
)
1804 struct glyph
*glyph
= s
->first_glyph
;
1809 r
.width
-= s
->x
- r
.x
;
1812 r
.width
= min (r
.width
, glyph
->pixel_width
);
1814 /* Don't draw cursor glyph taller than our actual glyph. */
1815 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1816 if (height
< r
.height
)
1818 int max_y
= r
.y
+ r
.height
;
1819 r
.y
= min (max_y
, s
->ybase
+ glyph
->descent
- height
);
1820 r
.height
= min (max_y
- r
.y
, height
);
1824 #ifdef CONVERT_FROM_XRECT
1825 CONVERT_FROM_XRECT (r
, *nr
);
1831 #endif /* HAVE_WINDOW_SYSTEM */
1834 /***********************************************************************
1835 Lisp form evaluation
1836 ***********************************************************************/
1838 /* Error handler for safe_eval and safe_call. */
1841 safe_eval_handler (arg
)
1844 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1849 /* Evaluate SEXPR and return the result, or nil if something went
1850 wrong. Prevent redisplay during the evaluation. */
1858 if (inhibit_eval_during_redisplay
)
1862 int count
= SPECPDL_INDEX ();
1863 struct gcpro gcpro1
;
1866 specbind (Qinhibit_redisplay
, Qt
);
1867 /* Use Qt to ensure debugger does not run,
1868 so there is no possibility of wanting to redisplay. */
1869 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1872 val
= unbind_to (count
, val
);
1879 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1880 Return the result, or nil if something went wrong. Prevent
1881 redisplay during the evaluation. */
1884 safe_call (nargs
, args
)
1890 if (inhibit_eval_during_redisplay
)
1894 int count
= SPECPDL_INDEX ();
1895 struct gcpro gcpro1
;
1898 gcpro1
.nvars
= nargs
;
1899 specbind (Qinhibit_redisplay
, Qt
);
1900 /* Use Qt to ensure debugger does not run,
1901 so there is no possibility of wanting to redisplay. */
1902 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1905 val
= unbind_to (count
, val
);
1912 /* Call function FN with one argument ARG.
1913 Return the result, or nil if something went wrong. */
1916 safe_call1 (fn
, arg
)
1917 Lisp_Object fn
, arg
;
1919 Lisp_Object args
[2];
1922 return safe_call (2, args
);
1927 /***********************************************************************
1929 ***********************************************************************/
1933 /* Define CHECK_IT to perform sanity checks on iterators.
1934 This is for debugging. It is too slow to do unconditionally. */
1940 if (it
->method
== next_element_from_string
)
1942 xassert (STRINGP (it
->string
));
1943 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1947 xassert (IT_STRING_CHARPOS (*it
) < 0);
1948 if (it
->method
== next_element_from_buffer
)
1950 /* Check that character and byte positions agree. */
1951 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1956 xassert (it
->current
.dpvec_index
>= 0);
1958 xassert (it
->current
.dpvec_index
< 0);
1961 #define CHECK_IT(IT) check_it ((IT))
1965 #define CHECK_IT(IT) (void) 0
1972 /* Check that the window end of window W is what we expect it
1973 to be---the last row in the current matrix displaying text. */
1976 check_window_end (w
)
1979 if (!MINI_WINDOW_P (w
)
1980 && !NILP (w
->window_end_valid
))
1982 struct glyph_row
*row
;
1983 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1984 XFASTINT (w
->window_end_vpos
)),
1986 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1987 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1991 #define CHECK_WINDOW_END(W) check_window_end ((W))
1993 #else /* not GLYPH_DEBUG */
1995 #define CHECK_WINDOW_END(W) (void) 0
1997 #endif /* not GLYPH_DEBUG */
2001 /***********************************************************************
2002 Iterator initialization
2003 ***********************************************************************/
2005 /* Initialize IT for displaying current_buffer in window W, starting
2006 at character position CHARPOS. CHARPOS < 0 means that no buffer
2007 position is specified which is useful when the iterator is assigned
2008 a position later. BYTEPOS is the byte position corresponding to
2009 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2011 If ROW is not null, calls to produce_glyphs with IT as parameter
2012 will produce glyphs in that row.
2014 BASE_FACE_ID is the id of a base face to use. It must be one of
2015 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2016 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2017 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2019 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2020 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2021 will be initialized to use the corresponding mode line glyph row of
2022 the desired matrix of W. */
2025 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2028 int charpos
, bytepos
;
2029 struct glyph_row
*row
;
2030 enum face_id base_face_id
;
2032 int highlight_region_p
;
2034 /* Some precondition checks. */
2035 xassert (w
!= NULL
&& it
!= NULL
);
2036 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2039 /* If face attributes have been changed since the last redisplay,
2040 free realized faces now because they depend on face definitions
2041 that might have changed. Don't free faces while there might be
2042 desired matrices pending which reference these faces. */
2043 if (face_change_count
&& !inhibit_free_realized_faces
)
2045 face_change_count
= 0;
2046 free_all_realized_faces (Qnil
);
2049 /* Use one of the mode line rows of W's desired matrix if
2053 if (base_face_id
== MODE_LINE_FACE_ID
2054 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2055 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2056 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2057 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2061 bzero (it
, sizeof *it
);
2062 it
->current
.overlay_string_index
= -1;
2063 it
->current
.dpvec_index
= -1;
2064 it
->base_face_id
= base_face_id
;
2066 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2068 /* The window in which we iterate over current_buffer: */
2069 XSETWINDOW (it
->window
, w
);
2071 it
->f
= XFRAME (w
->frame
);
2073 /* Extra space between lines (on window systems only). */
2074 if (base_face_id
== DEFAULT_FACE_ID
2075 && FRAME_WINDOW_P (it
->f
))
2077 if (NATNUMP (current_buffer
->extra_line_spacing
))
2078 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2079 else if (FLOATP (current_buffer
->extra_line_spacing
))
2080 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2081 * FRAME_LINE_HEIGHT (it
->f
));
2082 else if (it
->f
->extra_line_spacing
> 0)
2083 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2084 it
->max_extra_line_spacing
= 0;
2087 /* If realized faces have been removed, e.g. because of face
2088 attribute changes of named faces, recompute them. When running
2089 in batch mode, the face cache of the initial frame is null. If
2090 we happen to get called, make a dummy face cache. */
2091 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2092 init_frame_faces (it
->f
);
2093 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2094 recompute_basic_faces (it
->f
);
2096 /* Current value of the `slice', `space-width', and 'height' properties. */
2097 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2098 it
->space_width
= Qnil
;
2099 it
->font_height
= Qnil
;
2100 it
->override_ascent
= -1;
2102 /* Are control characters displayed as `^C'? */
2103 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2105 /* -1 means everything between a CR and the following line end
2106 is invisible. >0 means lines indented more than this value are
2108 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2109 ? XFASTINT (current_buffer
->selective_display
)
2110 : (!NILP (current_buffer
->selective_display
)
2112 it
->selective_display_ellipsis_p
2113 = !NILP (current_buffer
->selective_display_ellipses
);
2115 /* Display table to use. */
2116 it
->dp
= window_display_table (w
);
2118 /* Are multibyte characters enabled in current_buffer? */
2119 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2121 /* Non-zero if we should highlight the region. */
2123 = (!NILP (Vtransient_mark_mode
)
2124 && !NILP (current_buffer
->mark_active
)
2125 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2127 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2128 start and end of a visible region in window IT->w. Set both to
2129 -1 to indicate no region. */
2130 if (highlight_region_p
2131 /* Maybe highlight only in selected window. */
2132 && (/* Either show region everywhere. */
2133 highlight_nonselected_windows
2134 /* Or show region in the selected window. */
2135 || w
== XWINDOW (selected_window
)
2136 /* Or show the region if we are in the mini-buffer and W is
2137 the window the mini-buffer refers to. */
2138 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2139 && WINDOWP (minibuf_selected_window
)
2140 && w
== XWINDOW (minibuf_selected_window
))))
2142 int charpos
= marker_position (current_buffer
->mark
);
2143 it
->region_beg_charpos
= min (PT
, charpos
);
2144 it
->region_end_charpos
= max (PT
, charpos
);
2147 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2149 /* Get the position at which the redisplay_end_trigger hook should
2150 be run, if it is to be run at all. */
2151 if (MARKERP (w
->redisplay_end_trigger
)
2152 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2153 it
->redisplay_end_trigger_charpos
2154 = marker_position (w
->redisplay_end_trigger
);
2155 else if (INTEGERP (w
->redisplay_end_trigger
))
2156 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2158 /* Correct bogus values of tab_width. */
2159 it
->tab_width
= XINT (current_buffer
->tab_width
);
2160 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2163 /* Are lines in the display truncated? */
2164 it
->truncate_lines_p
2165 = (base_face_id
!= DEFAULT_FACE_ID
2166 || XINT (it
->w
->hscroll
)
2167 || (truncate_partial_width_windows
2168 && !WINDOW_FULL_WIDTH_P (it
->w
))
2169 || !NILP (current_buffer
->truncate_lines
));
2171 /* Get dimensions of truncation and continuation glyphs. These are
2172 displayed as fringe bitmaps under X, so we don't need them for such
2174 if (!FRAME_WINDOW_P (it
->f
))
2176 if (it
->truncate_lines_p
)
2178 /* We will need the truncation glyph. */
2179 xassert (it
->glyph_row
== NULL
);
2180 produce_special_glyphs (it
, IT_TRUNCATION
);
2181 it
->truncation_pixel_width
= it
->pixel_width
;
2185 /* We will need the continuation glyph. */
2186 xassert (it
->glyph_row
== NULL
);
2187 produce_special_glyphs (it
, IT_CONTINUATION
);
2188 it
->continuation_pixel_width
= it
->pixel_width
;
2191 /* Reset these values to zero because the produce_special_glyphs
2192 above has changed them. */
2193 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2194 it
->phys_ascent
= it
->phys_descent
= 0;
2197 /* Set this after getting the dimensions of truncation and
2198 continuation glyphs, so that we don't produce glyphs when calling
2199 produce_special_glyphs, above. */
2200 it
->glyph_row
= row
;
2201 it
->area
= TEXT_AREA
;
2203 /* Get the dimensions of the display area. The display area
2204 consists of the visible window area plus a horizontally scrolled
2205 part to the left of the window. All x-values are relative to the
2206 start of this total display area. */
2207 if (base_face_id
!= DEFAULT_FACE_ID
)
2209 /* Mode lines, menu bar in terminal frames. */
2210 it
->first_visible_x
= 0;
2211 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2216 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2217 it
->last_visible_x
= (it
->first_visible_x
2218 + window_box_width (w
, TEXT_AREA
));
2220 /* If we truncate lines, leave room for the truncator glyph(s) at
2221 the right margin. Otherwise, leave room for the continuation
2222 glyph(s). Truncation and continuation glyphs are not inserted
2223 for window-based redisplay. */
2224 if (!FRAME_WINDOW_P (it
->f
))
2226 if (it
->truncate_lines_p
)
2227 it
->last_visible_x
-= it
->truncation_pixel_width
;
2229 it
->last_visible_x
-= it
->continuation_pixel_width
;
2232 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2233 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2236 /* Leave room for a border glyph. */
2237 if (!FRAME_WINDOW_P (it
->f
)
2238 && !WINDOW_RIGHTMOST_P (it
->w
))
2239 it
->last_visible_x
-= 1;
2241 it
->last_visible_y
= window_text_bottom_y (w
);
2243 /* For mode lines and alike, arrange for the first glyph having a
2244 left box line if the face specifies a box. */
2245 if (base_face_id
!= DEFAULT_FACE_ID
)
2249 it
->face_id
= base_face_id
;
2251 /* If we have a boxed mode line, make the first character appear
2252 with a left box line. */
2253 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2254 if (face
->box
!= FACE_NO_BOX
)
2255 it
->start_of_box_run_p
= 1;
2258 /* If a buffer position was specified, set the iterator there,
2259 getting overlays and face properties from that position. */
2260 if (charpos
>= BUF_BEG (current_buffer
))
2262 it
->end_charpos
= ZV
;
2264 IT_CHARPOS (*it
) = charpos
;
2266 /* Compute byte position if not specified. */
2267 if (bytepos
< charpos
)
2268 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2270 IT_BYTEPOS (*it
) = bytepos
;
2272 it
->start
= it
->current
;
2274 /* Compute faces etc. */
2275 reseat (it
, it
->current
.pos
, 1);
2282 /* Initialize IT for the display of window W with window start POS. */
2285 start_display (it
, w
, pos
)
2288 struct text_pos pos
;
2290 struct glyph_row
*row
;
2291 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2293 row
= w
->desired_matrix
->rows
+ first_vpos
;
2294 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2295 it
->first_vpos
= first_vpos
;
2297 if (!it
->truncate_lines_p
)
2299 int start_at_line_beg_p
;
2300 int first_y
= it
->current_y
;
2302 /* If window start is not at a line start, skip forward to POS to
2303 get the correct continuation lines width. */
2304 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2305 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2306 if (!start_at_line_beg_p
)
2310 reseat_at_previous_visible_line_start (it
);
2311 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2313 new_x
= it
->current_x
+ it
->pixel_width
;
2315 /* If lines are continued, this line may end in the middle
2316 of a multi-glyph character (e.g. a control character
2317 displayed as \003, or in the middle of an overlay
2318 string). In this case move_it_to above will not have
2319 taken us to the start of the continuation line but to the
2320 end of the continued line. */
2321 if (it
->current_x
> 0
2322 && !it
->truncate_lines_p
/* Lines are continued. */
2323 && (/* And glyph doesn't fit on the line. */
2324 new_x
> it
->last_visible_x
2325 /* Or it fits exactly and we're on a window
2327 || (new_x
== it
->last_visible_x
2328 && FRAME_WINDOW_P (it
->f
))))
2330 if (it
->current
.dpvec_index
>= 0
2331 || it
->current
.overlay_string_index
>= 0)
2333 set_iterator_to_next (it
, 1);
2334 move_it_in_display_line_to (it
, -1, -1, 0);
2337 it
->continuation_lines_width
+= it
->current_x
;
2340 /* We're starting a new display line, not affected by the
2341 height of the continued line, so clear the appropriate
2342 fields in the iterator structure. */
2343 it
->max_ascent
= it
->max_descent
= 0;
2344 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2346 it
->current_y
= first_y
;
2348 it
->current_x
= it
->hpos
= 0;
2352 #if 0 /* Don't assert the following because start_display is sometimes
2353 called intentionally with a window start that is not at a
2354 line start. Please leave this code in as a comment. */
2356 /* Window start should be on a line start, now. */
2357 xassert (it
->continuation_lines_width
2358 || IT_CHARPOS (it
) == BEGV
2359 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2364 /* Return 1 if POS is a position in ellipses displayed for invisible
2365 text. W is the window we display, for text property lookup. */
2368 in_ellipses_for_invisible_text_p (pos
, w
)
2369 struct display_pos
*pos
;
2372 Lisp_Object prop
, window
;
2374 int charpos
= CHARPOS (pos
->pos
);
2376 /* If POS specifies a position in a display vector, this might
2377 be for an ellipsis displayed for invisible text. We won't
2378 get the iterator set up for delivering that ellipsis unless
2379 we make sure that it gets aware of the invisible text. */
2380 if (pos
->dpvec_index
>= 0
2381 && pos
->overlay_string_index
< 0
2382 && CHARPOS (pos
->string_pos
) < 0
2384 && (XSETWINDOW (window
, w
),
2385 prop
= Fget_char_property (make_number (charpos
),
2386 Qinvisible
, window
),
2387 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2389 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2391 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2398 /* Initialize IT for stepping through current_buffer in window W,
2399 starting at position POS that includes overlay string and display
2400 vector/ control character translation position information. Value
2401 is zero if there are overlay strings with newlines at POS. */
2404 init_from_display_pos (it
, w
, pos
)
2407 struct display_pos
*pos
;
2409 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2410 int i
, overlay_strings_with_newlines
= 0;
2412 /* If POS specifies a position in a display vector, this might
2413 be for an ellipsis displayed for invisible text. We won't
2414 get the iterator set up for delivering that ellipsis unless
2415 we make sure that it gets aware of the invisible text. */
2416 if (in_ellipses_for_invisible_text_p (pos
, w
))
2422 /* Keep in mind: the call to reseat in init_iterator skips invisible
2423 text, so we might end up at a position different from POS. This
2424 is only a problem when POS is a row start after a newline and an
2425 overlay starts there with an after-string, and the overlay has an
2426 invisible property. Since we don't skip invisible text in
2427 display_line and elsewhere immediately after consuming the
2428 newline before the row start, such a POS will not be in a string,
2429 but the call to init_iterator below will move us to the
2431 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2433 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2435 const char *s
= SDATA (it
->overlay_strings
[i
]);
2436 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2438 while (s
< e
&& *s
!= '\n')
2443 overlay_strings_with_newlines
= 1;
2448 /* If position is within an overlay string, set up IT to the right
2450 if (pos
->overlay_string_index
>= 0)
2454 /* If the first overlay string happens to have a `display'
2455 property for an image, the iterator will be set up for that
2456 image, and we have to undo that setup first before we can
2457 correct the overlay string index. */
2458 if (it
->method
== next_element_from_image
)
2461 /* We already have the first chunk of overlay strings in
2462 IT->overlay_strings. Load more until the one for
2463 pos->overlay_string_index is in IT->overlay_strings. */
2464 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2466 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2467 it
->current
.overlay_string_index
= 0;
2470 load_overlay_strings (it
, 0);
2471 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2475 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2476 relative_index
= (it
->current
.overlay_string_index
2477 % OVERLAY_STRING_CHUNK_SIZE
);
2478 it
->string
= it
->overlay_strings
[relative_index
];
2479 xassert (STRINGP (it
->string
));
2480 it
->current
.string_pos
= pos
->string_pos
;
2481 it
->method
= next_element_from_string
;
2484 #if 0 /* This is bogus because POS not having an overlay string
2485 position does not mean it's after the string. Example: A
2486 line starting with a before-string and initialization of IT
2487 to the previous row's end position. */
2488 else if (it
->current
.overlay_string_index
>= 0)
2490 /* If POS says we're already after an overlay string ending at
2491 POS, make sure to pop the iterator because it will be in
2492 front of that overlay string. When POS is ZV, we've thereby
2493 also ``processed'' overlay strings at ZV. */
2496 it
->current
.overlay_string_index
= -1;
2497 it
->method
= next_element_from_buffer
;
2498 if (CHARPOS (pos
->pos
) == ZV
)
2499 it
->overlay_strings_at_end_processed_p
= 1;
2503 if (CHARPOS (pos
->string_pos
) >= 0)
2505 /* Recorded position is not in an overlay string, but in another
2506 string. This can only be a string from a `display' property.
2507 IT should already be filled with that string. */
2508 it
->current
.string_pos
= pos
->string_pos
;
2509 xassert (STRINGP (it
->string
));
2512 /* Restore position in display vector translations, control
2513 character translations or ellipses. */
2514 if (pos
->dpvec_index
>= 0)
2516 if (it
->dpvec
== NULL
)
2517 get_next_display_element (it
);
2518 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2519 it
->current
.dpvec_index
= pos
->dpvec_index
;
2523 return !overlay_strings_with_newlines
;
2527 /* Initialize IT for stepping through current_buffer in window W
2528 starting at ROW->start. */
2531 init_to_row_start (it
, w
, row
)
2534 struct glyph_row
*row
;
2536 init_from_display_pos (it
, w
, &row
->start
);
2537 it
->start
= row
->start
;
2538 it
->continuation_lines_width
= row
->continuation_lines_width
;
2543 /* Initialize IT for stepping through current_buffer in window W
2544 starting in the line following ROW, i.e. starting at ROW->end.
2545 Value is zero if there are overlay strings with newlines at ROW's
2549 init_to_row_end (it
, w
, row
)
2552 struct glyph_row
*row
;
2556 if (init_from_display_pos (it
, w
, &row
->end
))
2558 if (row
->continued_p
)
2559 it
->continuation_lines_width
2560 = row
->continuation_lines_width
+ row
->pixel_width
;
2571 /***********************************************************************
2573 ***********************************************************************/
2575 /* Called when IT reaches IT->stop_charpos. Handle text property and
2576 overlay changes. Set IT->stop_charpos to the next position where
2583 enum prop_handled handled
;
2584 int handle_overlay_change_p
= 1;
2588 it
->current
.dpvec_index
= -1;
2592 handled
= HANDLED_NORMALLY
;
2594 /* Call text property handlers. */
2595 for (p
= it_props
; p
->handler
; ++p
)
2597 handled
= p
->handler (it
);
2599 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2601 else if (handled
== HANDLED_RETURN
)
2603 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2604 handle_overlay_change_p
= 0;
2607 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2609 /* Don't check for overlay strings below when set to deliver
2610 characters from a display vector. */
2611 if (it
->method
== next_element_from_display_vector
)
2612 handle_overlay_change_p
= 0;
2614 /* Handle overlay changes. */
2615 if (handle_overlay_change_p
)
2616 handled
= handle_overlay_change (it
);
2618 /* Determine where to stop next. */
2619 if (handled
== HANDLED_NORMALLY
)
2620 compute_stop_pos (it
);
2623 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2627 /* Compute IT->stop_charpos from text property and overlay change
2628 information for IT's current position. */
2631 compute_stop_pos (it
)
2634 register INTERVAL iv
, next_iv
;
2635 Lisp_Object object
, limit
, position
;
2637 /* If nowhere else, stop at the end. */
2638 it
->stop_charpos
= it
->end_charpos
;
2640 if (STRINGP (it
->string
))
2642 /* Strings are usually short, so don't limit the search for
2644 object
= it
->string
;
2646 position
= make_number (IT_STRING_CHARPOS (*it
));
2652 /* If next overlay change is in front of the current stop pos
2653 (which is IT->end_charpos), stop there. Note: value of
2654 next_overlay_change is point-max if no overlay change
2656 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2657 if (charpos
< it
->stop_charpos
)
2658 it
->stop_charpos
= charpos
;
2660 /* If showing the region, we have to stop at the region
2661 start or end because the face might change there. */
2662 if (it
->region_beg_charpos
> 0)
2664 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2665 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2666 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2667 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2670 /* Set up variables for computing the stop position from text
2671 property changes. */
2672 XSETBUFFER (object
, current_buffer
);
2673 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2674 position
= make_number (IT_CHARPOS (*it
));
2678 /* Get the interval containing IT's position. Value is a null
2679 interval if there isn't such an interval. */
2680 iv
= validate_interval_range (object
, &position
, &position
, 0);
2681 if (!NULL_INTERVAL_P (iv
))
2683 Lisp_Object values_here
[LAST_PROP_IDX
];
2686 /* Get properties here. */
2687 for (p
= it_props
; p
->handler
; ++p
)
2688 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2690 /* Look for an interval following iv that has different
2692 for (next_iv
= next_interval (iv
);
2693 (!NULL_INTERVAL_P (next_iv
)
2695 || XFASTINT (limit
) > next_iv
->position
));
2696 next_iv
= next_interval (next_iv
))
2698 for (p
= it_props
; p
->handler
; ++p
)
2700 Lisp_Object new_value
;
2702 new_value
= textget (next_iv
->plist
, *p
->name
);
2703 if (!EQ (values_here
[p
->idx
], new_value
))
2711 if (!NULL_INTERVAL_P (next_iv
))
2713 if (INTEGERP (limit
)
2714 && next_iv
->position
>= XFASTINT (limit
))
2715 /* No text property change up to limit. */
2716 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2718 /* Text properties change in next_iv. */
2719 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2723 xassert (STRINGP (it
->string
)
2724 || (it
->stop_charpos
>= BEGV
2725 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2729 /* Return the position of the next overlay change after POS in
2730 current_buffer. Value is point-max if no overlay change
2731 follows. This is like `next-overlay-change' but doesn't use
2735 next_overlay_change (pos
)
2740 Lisp_Object
*overlays
;
2743 /* Get all overlays at the given position. */
2744 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2746 /* If any of these overlays ends before endpos,
2747 use its ending point instead. */
2748 for (i
= 0; i
< noverlays
; ++i
)
2753 oend
= OVERLAY_END (overlays
[i
]);
2754 oendpos
= OVERLAY_POSITION (oend
);
2755 endpos
= min (endpos
, oendpos
);
2763 /***********************************************************************
2765 ***********************************************************************/
2767 /* Handle changes in the `fontified' property of the current buffer by
2768 calling hook functions from Qfontification_functions to fontify
2771 static enum prop_handled
2772 handle_fontified_prop (it
)
2775 Lisp_Object prop
, pos
;
2776 enum prop_handled handled
= HANDLED_NORMALLY
;
2778 /* Get the value of the `fontified' property at IT's current buffer
2779 position. (The `fontified' property doesn't have a special
2780 meaning in strings.) If the value is nil, call functions from
2781 Qfontification_functions. */
2782 if (!STRINGP (it
->string
)
2784 && !NILP (Vfontification_functions
)
2785 && !NILP (Vrun_hooks
)
2786 && (pos
= make_number (IT_CHARPOS (*it
)),
2787 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2790 int count
= SPECPDL_INDEX ();
2793 val
= Vfontification_functions
;
2794 specbind (Qfontification_functions
, Qnil
);
2796 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2797 safe_call1 (val
, pos
);
2800 Lisp_Object globals
, fn
;
2801 struct gcpro gcpro1
, gcpro2
;
2804 GCPRO2 (val
, globals
);
2806 for (; CONSP (val
); val
= XCDR (val
))
2812 /* A value of t indicates this hook has a local
2813 binding; it means to run the global binding too.
2814 In a global value, t should not occur. If it
2815 does, we must ignore it to avoid an endless
2817 for (globals
= Fdefault_value (Qfontification_functions
);
2819 globals
= XCDR (globals
))
2821 fn
= XCAR (globals
);
2823 safe_call1 (fn
, pos
);
2827 safe_call1 (fn
, pos
);
2833 unbind_to (count
, Qnil
);
2835 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2836 something. This avoids an endless loop if they failed to
2837 fontify the text for which reason ever. */
2838 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2839 handled
= HANDLED_RECOMPUTE_PROPS
;
2847 /***********************************************************************
2849 ***********************************************************************/
2851 /* Set up iterator IT from face properties at its current position.
2852 Called from handle_stop. */
2854 static enum prop_handled
2855 handle_face_prop (it
)
2858 int new_face_id
, next_stop
;
2860 if (!STRINGP (it
->string
))
2863 = face_at_buffer_position (it
->w
,
2865 it
->region_beg_charpos
,
2866 it
->region_end_charpos
,
2869 + TEXT_PROP_DISTANCE_LIMIT
),
2872 /* Is this a start of a run of characters with box face?
2873 Caveat: this can be called for a freshly initialized
2874 iterator; face_id is -1 in this case. We know that the new
2875 face will not change until limit, i.e. if the new face has a
2876 box, all characters up to limit will have one. But, as
2877 usual, we don't know whether limit is really the end. */
2878 if (new_face_id
!= it
->face_id
)
2880 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2882 /* If new face has a box but old face has not, this is
2883 the start of a run of characters with box, i.e. it has
2884 a shadow on the left side. The value of face_id of the
2885 iterator will be -1 if this is the initial call that gets
2886 the face. In this case, we have to look in front of IT's
2887 position and see whether there is a face != new_face_id. */
2888 it
->start_of_box_run_p
2889 = (new_face
->box
!= FACE_NO_BOX
2890 && (it
->face_id
>= 0
2891 || IT_CHARPOS (*it
) == BEG
2892 || new_face_id
!= face_before_it_pos (it
)));
2893 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2898 int base_face_id
, bufpos
;
2900 if (it
->current
.overlay_string_index
>= 0)
2901 bufpos
= IT_CHARPOS (*it
);
2905 /* For strings from a buffer, i.e. overlay strings or strings
2906 from a `display' property, use the face at IT's current
2907 buffer position as the base face to merge with, so that
2908 overlay strings appear in the same face as surrounding
2909 text, unless they specify their own faces. */
2910 base_face_id
= underlying_face_id (it
);
2912 new_face_id
= face_at_string_position (it
->w
,
2914 IT_STRING_CHARPOS (*it
),
2916 it
->region_beg_charpos
,
2917 it
->region_end_charpos
,
2921 #if 0 /* This shouldn't be neccessary. Let's check it. */
2922 /* If IT is used to display a mode line we would really like to
2923 use the mode line face instead of the frame's default face. */
2924 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2925 && new_face_id
== DEFAULT_FACE_ID
)
2926 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2929 /* Is this a start of a run of characters with box? Caveat:
2930 this can be called for a freshly allocated iterator; face_id
2931 is -1 is this case. We know that the new face will not
2932 change until the next check pos, i.e. if the new face has a
2933 box, all characters up to that position will have a
2934 box. But, as usual, we don't know whether that position
2935 is really the end. */
2936 if (new_face_id
!= it
->face_id
)
2938 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2939 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2941 /* If new face has a box but old face hasn't, this is the
2942 start of a run of characters with box, i.e. it has a
2943 shadow on the left side. */
2944 it
->start_of_box_run_p
2945 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2946 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2950 it
->face_id
= new_face_id
;
2951 return HANDLED_NORMALLY
;
2955 /* Return the ID of the face ``underlying'' IT's current position,
2956 which is in a string. If the iterator is associated with a
2957 buffer, return the face at IT's current buffer position.
2958 Otherwise, use the iterator's base_face_id. */
2961 underlying_face_id (it
)
2964 int face_id
= it
->base_face_id
, i
;
2966 xassert (STRINGP (it
->string
));
2968 for (i
= it
->sp
- 1; i
>= 0; --i
)
2969 if (NILP (it
->stack
[i
].string
))
2970 face_id
= it
->stack
[i
].face_id
;
2976 /* Compute the face one character before or after the current position
2977 of IT. BEFORE_P non-zero means get the face in front of IT's
2978 position. Value is the id of the face. */
2981 face_before_or_after_it_pos (it
, before_p
)
2986 int next_check_charpos
;
2987 struct text_pos pos
;
2989 xassert (it
->s
== NULL
);
2991 if (STRINGP (it
->string
))
2993 int bufpos
, base_face_id
;
2995 /* No face change past the end of the string (for the case
2996 we are padding with spaces). No face change before the
2998 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2999 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3002 /* Set pos to the position before or after IT's current position. */
3004 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3006 /* For composition, we must check the character after the
3008 pos
= (it
->what
== IT_COMPOSITION
3009 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3010 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3012 if (it
->current
.overlay_string_index
>= 0)
3013 bufpos
= IT_CHARPOS (*it
);
3017 base_face_id
= underlying_face_id (it
);
3019 /* Get the face for ASCII, or unibyte. */
3020 face_id
= face_at_string_position (it
->w
,
3024 it
->region_beg_charpos
,
3025 it
->region_end_charpos
,
3026 &next_check_charpos
,
3029 /* Correct the face for charsets different from ASCII. Do it
3030 for the multibyte case only. The face returned above is
3031 suitable for unibyte text if IT->string is unibyte. */
3032 if (STRING_MULTIBYTE (it
->string
))
3034 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3035 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3037 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3039 c
= string_char_and_length (p
, rest
, &len
);
3040 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3045 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3046 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3049 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3050 pos
= it
->current
.pos
;
3053 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3056 if (it
->what
== IT_COMPOSITION
)
3057 /* For composition, we must check the position after the
3059 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3061 INC_TEXT_POS (pos
, it
->multibyte_p
);
3064 /* Determine face for CHARSET_ASCII, or unibyte. */
3065 face_id
= face_at_buffer_position (it
->w
,
3067 it
->region_beg_charpos
,
3068 it
->region_end_charpos
,
3069 &next_check_charpos
,
3072 /* Correct the face for charsets different from ASCII. Do it
3073 for the multibyte case only. The face returned above is
3074 suitable for unibyte text if current_buffer is unibyte. */
3075 if (it
->multibyte_p
)
3077 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3078 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3079 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3088 /***********************************************************************
3090 ***********************************************************************/
3092 /* Set up iterator IT from invisible properties at its current
3093 position. Called from handle_stop. */
3095 static enum prop_handled
3096 handle_invisible_prop (it
)
3099 enum prop_handled handled
= HANDLED_NORMALLY
;
3101 if (STRINGP (it
->string
))
3103 extern Lisp_Object Qinvisible
;
3104 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3106 /* Get the value of the invisible text property at the
3107 current position. Value will be nil if there is no such
3109 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3110 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3113 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3115 handled
= HANDLED_RECOMPUTE_PROPS
;
3117 /* Get the position at which the next change of the
3118 invisible text property can be found in IT->string.
3119 Value will be nil if the property value is the same for
3120 all the rest of IT->string. */
3121 XSETINT (limit
, SCHARS (it
->string
));
3122 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3125 /* Text at current position is invisible. The next
3126 change in the property is at position end_charpos.
3127 Move IT's current position to that position. */
3128 if (INTEGERP (end_charpos
)
3129 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3131 struct text_pos old
;
3132 old
= it
->current
.string_pos
;
3133 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3134 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3138 /* The rest of the string is invisible. If this is an
3139 overlay string, proceed with the next overlay string
3140 or whatever comes and return a character from there. */
3141 if (it
->current
.overlay_string_index
>= 0)
3143 next_overlay_string (it
);
3144 /* Don't check for overlay strings when we just
3145 finished processing them. */
3146 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3150 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3151 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3158 int invis_p
, newpos
, next_stop
, start_charpos
;
3159 Lisp_Object pos
, prop
, overlay
;
3161 /* First of all, is there invisible text at this position? */
3162 start_charpos
= IT_CHARPOS (*it
);
3163 pos
= make_number (IT_CHARPOS (*it
));
3164 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3166 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3168 /* If we are on invisible text, skip over it. */
3169 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3171 /* Record whether we have to display an ellipsis for the
3173 int display_ellipsis_p
= invis_p
== 2;
3175 handled
= HANDLED_RECOMPUTE_PROPS
;
3177 /* Loop skipping over invisible text. The loop is left at
3178 ZV or with IT on the first char being visible again. */
3181 /* Try to skip some invisible text. Return value is the
3182 position reached which can be equal to IT's position
3183 if there is nothing invisible here. This skips both
3184 over invisible text properties and overlays with
3185 invisible property. */
3186 newpos
= skip_invisible (IT_CHARPOS (*it
),
3187 &next_stop
, ZV
, it
->window
);
3189 /* If we skipped nothing at all we weren't at invisible
3190 text in the first place. If everything to the end of
3191 the buffer was skipped, end the loop. */
3192 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3196 /* We skipped some characters but not necessarily
3197 all there are. Check if we ended up on visible
3198 text. Fget_char_property returns the property of
3199 the char before the given position, i.e. if we
3200 get invis_p = 0, this means that the char at
3201 newpos is visible. */
3202 pos
= make_number (newpos
);
3203 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3204 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3207 /* If we ended up on invisible text, proceed to
3208 skip starting with next_stop. */
3210 IT_CHARPOS (*it
) = next_stop
;
3214 /* The position newpos is now either ZV or on visible text. */
3215 IT_CHARPOS (*it
) = newpos
;
3216 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3218 /* If there are before-strings at the start of invisible
3219 text, and the text is invisible because of a text
3220 property, arrange to show before-strings because 20.x did
3221 it that way. (If the text is invisible because of an
3222 overlay property instead of a text property, this is
3223 already handled in the overlay code.) */
3225 && get_overlay_strings (it
, start_charpos
))
3227 handled
= HANDLED_RECOMPUTE_PROPS
;
3228 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3230 else if (display_ellipsis_p
)
3231 setup_for_ellipsis (it
, 0);
3239 /* Make iterator IT return `...' next.
3240 Replaces LEN characters from buffer. */
3243 setup_for_ellipsis (it
, len
)
3247 /* Use the display table definition for `...'. Invalid glyphs
3248 will be handled by the method returning elements from dpvec. */
3249 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3251 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3252 it
->dpvec
= v
->contents
;
3253 it
->dpend
= v
->contents
+ v
->size
;
3257 /* Default `...'. */
3258 it
->dpvec
= default_invis_vector
;
3259 it
->dpend
= default_invis_vector
+ 3;
3262 it
->dpvec_char_len
= len
;
3263 it
->current
.dpvec_index
= 0;
3265 /* Remember the current face id in case glyphs specify faces.
3266 IT's face is restored in set_iterator_to_next. */
3267 it
->saved_face_id
= it
->face_id
;
3268 it
->method
= next_element_from_display_vector
;
3273 /***********************************************************************
3275 ***********************************************************************/
3277 /* Set up iterator IT from `display' property at its current position.
3278 Called from handle_stop. */
3280 static enum prop_handled
3281 handle_display_prop (it
)
3284 Lisp_Object prop
, object
;
3285 struct text_pos
*position
;
3286 int display_replaced_p
= 0;
3288 if (STRINGP (it
->string
))
3290 object
= it
->string
;
3291 position
= &it
->current
.string_pos
;
3295 object
= it
->w
->buffer
;
3296 position
= &it
->current
.pos
;
3299 /* Reset those iterator values set from display property values. */
3300 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3301 it
->space_width
= Qnil
;
3302 it
->font_height
= Qnil
;
3305 /* We don't support recursive `display' properties, i.e. string
3306 values that have a string `display' property, that have a string
3307 `display' property etc. */
3308 if (!it
->string_from_display_prop_p
)
3309 it
->area
= TEXT_AREA
;
3311 prop
= Fget_char_property (make_number (position
->charpos
),
3314 return HANDLED_NORMALLY
;
3317 /* Simple properties. */
3318 && !EQ (XCAR (prop
), Qimage
)
3319 && !EQ (XCAR (prop
), Qspace
)
3320 && !EQ (XCAR (prop
), Qwhen
)
3321 && !EQ (XCAR (prop
), Qslice
)
3322 && !EQ (XCAR (prop
), Qspace_width
)
3323 && !EQ (XCAR (prop
), Qheight
)
3324 && !EQ (XCAR (prop
), Qraise
)
3325 /* Marginal area specifications. */
3326 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3327 && !EQ (XCAR (prop
), Qleft_fringe
)
3328 && !EQ (XCAR (prop
), Qright_fringe
)
3329 && !NILP (XCAR (prop
)))
3331 for (; CONSP (prop
); prop
= XCDR (prop
))
3333 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3334 position
, display_replaced_p
))
3335 display_replaced_p
= 1;
3338 else if (VECTORP (prop
))
3341 for (i
= 0; i
< ASIZE (prop
); ++i
)
3342 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3343 position
, display_replaced_p
))
3344 display_replaced_p
= 1;
3348 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3349 display_replaced_p
= 1;
3352 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3356 /* Value is the position of the end of the `display' property starting
3357 at START_POS in OBJECT. */
3359 static struct text_pos
3360 display_prop_end (it
, object
, start_pos
)
3363 struct text_pos start_pos
;
3366 struct text_pos end_pos
;
3368 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3369 Qdisplay
, object
, Qnil
);
3370 CHARPOS (end_pos
) = XFASTINT (end
);
3371 if (STRINGP (object
))
3372 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3374 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3380 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3381 is the object in which the `display' property was found. *POSITION
3382 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3383 means that we previously saw a display sub-property which already
3384 replaced text display with something else, for example an image;
3385 ignore such properties after the first one has been processed.
3387 If PROP is a `space' or `image' sub-property, set *POSITION to the
3388 end position of the `display' property.
3390 Value is non-zero if something was found which replaces the display
3391 of buffer or string text. */
3394 handle_single_display_prop (it
, prop
, object
, position
,
3395 display_replaced_before_p
)
3399 struct text_pos
*position
;
3400 int display_replaced_before_p
;
3403 int replaces_text_display_p
= 0;
3406 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3407 evaluated. If the result is nil, VALUE is ignored. */
3409 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3418 if (!NILP (form
) && !EQ (form
, Qt
))
3420 int count
= SPECPDL_INDEX ();
3421 struct gcpro gcpro1
;
3423 /* Bind `object' to the object having the `display' property, a
3424 buffer or string. Bind `position' to the position in the
3425 object where the property was found, and `buffer-position'
3426 to the current position in the buffer. */
3427 specbind (Qobject
, object
);
3428 specbind (Qposition
, make_number (CHARPOS (*position
)));
3429 specbind (Qbuffer_position
,
3430 make_number (STRINGP (object
)
3431 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3433 form
= safe_eval (form
);
3435 unbind_to (count
, Qnil
);
3442 && EQ (XCAR (prop
), Qheight
)
3443 && CONSP (XCDR (prop
)))
3445 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3448 /* `(height HEIGHT)'. */
3449 it
->font_height
= XCAR (XCDR (prop
));
3450 if (!NILP (it
->font_height
))
3452 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3453 int new_height
= -1;
3455 if (CONSP (it
->font_height
)
3456 && (EQ (XCAR (it
->font_height
), Qplus
)
3457 || EQ (XCAR (it
->font_height
), Qminus
))
3458 && CONSP (XCDR (it
->font_height
))
3459 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3461 /* `(+ N)' or `(- N)' where N is an integer. */
3462 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3463 if (EQ (XCAR (it
->font_height
), Qplus
))
3465 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3467 else if (FUNCTIONP (it
->font_height
))
3469 /* Call function with current height as argument.
3470 Value is the new height. */
3472 height
= safe_call1 (it
->font_height
,
3473 face
->lface
[LFACE_HEIGHT_INDEX
]);
3474 if (NUMBERP (height
))
3475 new_height
= XFLOATINT (height
);
3477 else if (NUMBERP (it
->font_height
))
3479 /* Value is a multiple of the canonical char height. */
3482 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3483 new_height
= (XFLOATINT (it
->font_height
)
3484 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3488 /* Evaluate IT->font_height with `height' bound to the
3489 current specified height to get the new height. */
3491 int count
= SPECPDL_INDEX ();
3493 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3494 value
= safe_eval (it
->font_height
);
3495 unbind_to (count
, Qnil
);
3497 if (NUMBERP (value
))
3498 new_height
= XFLOATINT (value
);
3502 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3505 else if (CONSP (prop
)
3506 && EQ (XCAR (prop
), Qspace_width
)
3507 && CONSP (XCDR (prop
)))
3509 /* `(space_width WIDTH)'. */
3510 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3513 value
= XCAR (XCDR (prop
));
3514 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3515 it
->space_width
= value
;
3517 else if (CONSP (prop
)
3518 && EQ (XCAR (prop
), Qslice
))
3520 /* `(slice X Y WIDTH HEIGHT)'. */
3523 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3526 if (tem
= XCDR (prop
), CONSP (tem
))
3528 it
->slice
.x
= XCAR (tem
);
3529 if (tem
= XCDR (tem
), CONSP (tem
))
3531 it
->slice
.y
= XCAR (tem
);
3532 if (tem
= XCDR (tem
), CONSP (tem
))
3534 it
->slice
.width
= XCAR (tem
);
3535 if (tem
= XCDR (tem
), CONSP (tem
))
3536 it
->slice
.height
= XCAR (tem
);
3541 else if (CONSP (prop
)
3542 && EQ (XCAR (prop
), Qraise
)
3543 && CONSP (XCDR (prop
)))
3545 /* `(raise FACTOR)'. */
3546 if (!FRAME_WINDOW_P (it
->f
))
3549 #ifdef HAVE_WINDOW_SYSTEM
3550 value
= XCAR (XCDR (prop
));
3551 if (NUMBERP (value
))
3553 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3554 it
->voffset
= - (XFLOATINT (value
)
3555 * (FONT_HEIGHT (face
->font
)));
3557 #endif /* HAVE_WINDOW_SYSTEM */
3559 else if (!it
->string_from_display_prop_p
)
3561 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3562 VALUE) or `((margin nil) VALUE)' or VALUE. */
3563 Lisp_Object location
, value
;
3564 struct text_pos start_pos
;
3567 /* Characters having this form of property are not displayed, so
3568 we have to find the end of the property. */
3569 start_pos
= *position
;
3570 *position
= display_prop_end (it
, object
, start_pos
);
3573 /* Let's stop at the new position and assume that all
3574 text properties change there. */
3575 it
->stop_charpos
= position
->charpos
;
3578 && (EQ (XCAR (prop
), Qleft_fringe
)
3579 || EQ (XCAR (prop
), Qright_fringe
))
3580 && CONSP (XCDR (prop
)))
3582 int face_id
= DEFAULT_FACE_ID
;
3585 /* Save current settings of IT so that we can restore them
3586 when we are finished with the glyph property value. */
3588 /* `(left-fringe BITMAP FACE)'. */
3589 if (!FRAME_WINDOW_P (it
->f
))
3592 #ifdef HAVE_WINDOW_SYSTEM
3593 value
= XCAR (XCDR (prop
));
3594 if (!SYMBOLP (value
)
3595 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3598 if (CONSP (XCDR (XCDR (prop
))))
3600 Lisp_Object face_name
= XCAR (XCDR (XCDR (prop
)));
3601 int face_id2
= lookup_named_face (it
->f
, face_name
, 'A', 0);
3608 it
->area
= TEXT_AREA
;
3609 it
->what
= IT_IMAGE
;
3610 it
->image_id
= -1; /* no image */
3611 it
->position
= start_pos
;
3612 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3613 it
->method
= next_element_from_image
;
3614 it
->face_id
= face_id
;
3616 /* Say that we haven't consumed the characters with
3617 `display' property yet. The call to pop_it in
3618 set_iterator_to_next will clean this up. */
3619 *position
= start_pos
;
3621 if (EQ (XCAR (prop
), Qleft_fringe
))
3623 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3624 it
->left_user_fringe_face_id
= face_id
;
3628 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3629 it
->right_user_fringe_face_id
= face_id
;
3631 #endif /* HAVE_WINDOW_SYSTEM */
3635 location
= Qunbound
;
3636 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3640 value
= XCDR (prop
);
3642 value
= XCAR (value
);
3645 if (EQ (XCAR (tem
), Qmargin
)
3646 && (tem
= XCDR (tem
),
3647 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3649 || EQ (tem
, Qleft_margin
)
3650 || EQ (tem
, Qright_margin
))))
3654 if (EQ (location
, Qunbound
))
3660 valid_p
= (STRINGP (value
)
3661 #ifdef HAVE_WINDOW_SYSTEM
3662 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
3663 #endif /* not HAVE_WINDOW_SYSTEM */
3664 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3666 if ((EQ (location
, Qleft_margin
)
3667 || EQ (location
, Qright_margin
)
3670 && !display_replaced_before_p
)
3672 replaces_text_display_p
= 1;
3674 /* Save current settings of IT so that we can restore them
3675 when we are finished with the glyph property value. */
3678 if (NILP (location
))
3679 it
->area
= TEXT_AREA
;
3680 else if (EQ (location
, Qleft_margin
))
3681 it
->area
= LEFT_MARGIN_AREA
;
3683 it
->area
= RIGHT_MARGIN_AREA
;
3685 if (STRINGP (value
))
3688 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3689 it
->current
.overlay_string_index
= -1;
3690 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3691 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3692 it
->method
= next_element_from_string
;
3693 it
->stop_charpos
= 0;
3694 it
->string_from_display_prop_p
= 1;
3695 /* Say that we haven't consumed the characters with
3696 `display' property yet. The call to pop_it in
3697 set_iterator_to_next will clean this up. */
3698 *position
= start_pos
;
3700 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3702 it
->method
= next_element_from_stretch
;
3704 it
->current
.pos
= it
->position
= start_pos
;
3706 #ifdef HAVE_WINDOW_SYSTEM
3709 if (FRAME_WINDOW_P (it
->f
))
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
;
3718 /* Say that we haven't consumed the characters with
3719 `display' property yet. The call to pop_it in
3720 set_iterator_to_next will clean this up. */
3721 *position
= start_pos
;
3723 #endif /* HAVE_WINDOW_SYSTEM */
3726 /* Invalid property or property not supported. Restore
3727 the position to what it was before. */
3728 *position
= start_pos
;
3731 return replaces_text_display_p
;
3735 /* Check if PROP is a display sub-property value whose text should be
3736 treated as intangible. */
3739 single_display_prop_intangible_p (prop
)
3742 /* Skip over `when FORM'. */
3743 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3757 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3758 we don't need to treat text as intangible. */
3759 if (EQ (XCAR (prop
), Qmargin
))
3767 || EQ (XCAR (prop
), Qleft_margin
)
3768 || EQ (XCAR (prop
), Qright_margin
))
3772 return (CONSP (prop
)
3773 && (EQ (XCAR (prop
), Qimage
)
3774 || EQ (XCAR (prop
), Qspace
)));
3778 /* Check if PROP is a display property value whose text should be
3779 treated as intangible. */
3782 display_prop_intangible_p (prop
)
3786 && CONSP (XCAR (prop
))
3787 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3789 /* A list of sub-properties. */
3790 while (CONSP (prop
))
3792 if (single_display_prop_intangible_p (XCAR (prop
)))
3797 else if (VECTORP (prop
))
3799 /* A vector of sub-properties. */
3801 for (i
= 0; i
< ASIZE (prop
); ++i
)
3802 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3806 return single_display_prop_intangible_p (prop
);
3812 /* Return 1 if PROP is a display sub-property value containing STRING. */
3815 single_display_prop_string_p (prop
, string
)
3816 Lisp_Object prop
, string
;
3818 if (EQ (string
, prop
))
3821 /* Skip over `when FORM'. */
3822 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3831 /* Skip over `margin LOCATION'. */
3832 if (EQ (XCAR (prop
), Qmargin
))
3843 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3847 /* Return 1 if STRING appears in the `display' property PROP. */
3850 display_prop_string_p (prop
, string
)
3851 Lisp_Object prop
, string
;
3854 && CONSP (XCAR (prop
))
3855 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3857 /* A list of sub-properties. */
3858 while (CONSP (prop
))
3860 if (single_display_prop_string_p (XCAR (prop
), string
))
3865 else if (VECTORP (prop
))
3867 /* A vector of sub-properties. */
3869 for (i
= 0; i
< ASIZE (prop
); ++i
)
3870 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3874 return single_display_prop_string_p (prop
, string
);
3880 /* Determine from which buffer position in W's buffer STRING comes
3881 from. AROUND_CHARPOS is an approximate position where it could
3882 be from. Value is the buffer position or 0 if it couldn't be
3885 W's buffer must be current.
3887 This function is necessary because we don't record buffer positions
3888 in glyphs generated from strings (to keep struct glyph small).
3889 This function may only use code that doesn't eval because it is
3890 called asynchronously from note_mouse_highlight. */
3893 string_buffer_position (w
, string
, around_charpos
)
3898 Lisp_Object limit
, prop
, pos
;
3899 const int MAX_DISTANCE
= 1000;
3902 pos
= make_number (around_charpos
);
3903 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3904 while (!found
&& !EQ (pos
, limit
))
3906 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3907 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3910 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3915 pos
= make_number (around_charpos
);
3916 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3917 while (!found
&& !EQ (pos
, limit
))
3919 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3920 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3923 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3928 return found
? XINT (pos
) : 0;
3933 /***********************************************************************
3934 `composition' property
3935 ***********************************************************************/
3937 /* Set up iterator IT from `composition' property at its current
3938 position. Called from handle_stop. */
3940 static enum prop_handled
3941 handle_composition_prop (it
)
3944 Lisp_Object prop
, string
;
3945 int pos
, pos_byte
, end
;
3946 enum prop_handled handled
= HANDLED_NORMALLY
;
3948 if (STRINGP (it
->string
))
3950 pos
= IT_STRING_CHARPOS (*it
);
3951 pos_byte
= IT_STRING_BYTEPOS (*it
);
3952 string
= it
->string
;
3956 pos
= IT_CHARPOS (*it
);
3957 pos_byte
= IT_BYTEPOS (*it
);
3961 /* If there's a valid composition and point is not inside of the
3962 composition (in the case that the composition is from the current
3963 buffer), draw a glyph composed from the composition components. */
3964 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3965 && COMPOSITION_VALID_P (pos
, end
, prop
)
3966 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3968 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3972 it
->method
= next_element_from_composition
;
3974 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3975 /* For a terminal, draw only the first character of the
3977 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3978 it
->len
= (STRINGP (it
->string
)
3979 ? string_char_to_byte (it
->string
, end
)
3980 : CHAR_TO_BYTE (end
)) - pos_byte
;
3981 it
->stop_charpos
= end
;
3982 handled
= HANDLED_RETURN
;
3991 /***********************************************************************
3993 ***********************************************************************/
3995 /* The following structure is used to record overlay strings for
3996 later sorting in load_overlay_strings. */
3998 struct overlay_entry
4000 Lisp_Object overlay
;
4007 /* Set up iterator IT from overlay strings at its current position.
4008 Called from handle_stop. */
4010 static enum prop_handled
4011 handle_overlay_change (it
)
4014 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4015 return HANDLED_RECOMPUTE_PROPS
;
4017 return HANDLED_NORMALLY
;
4021 /* Set up the next overlay string for delivery by IT, if there is an
4022 overlay string to deliver. Called by set_iterator_to_next when the
4023 end of the current overlay string is reached. If there are more
4024 overlay strings to display, IT->string and
4025 IT->current.overlay_string_index are set appropriately here.
4026 Otherwise IT->string is set to nil. */
4029 next_overlay_string (it
)
4032 ++it
->current
.overlay_string_index
;
4033 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4035 /* No more overlay strings. Restore IT's settings to what
4036 they were before overlay strings were processed, and
4037 continue to deliver from current_buffer. */
4038 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4041 xassert (it
->stop_charpos
>= BEGV
4042 && it
->stop_charpos
<= it
->end_charpos
);
4044 it
->current
.overlay_string_index
= -1;
4045 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4046 it
->n_overlay_strings
= 0;
4047 it
->method
= next_element_from_buffer
;
4049 /* If we're at the end of the buffer, record that we have
4050 processed the overlay strings there already, so that
4051 next_element_from_buffer doesn't try it again. */
4052 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4053 it
->overlay_strings_at_end_processed_p
= 1;
4055 /* If we have to display `...' for invisible text, set
4056 the iterator up for that. */
4057 if (display_ellipsis_p
)
4058 setup_for_ellipsis (it
, 0);
4062 /* There are more overlay strings to process. If
4063 IT->current.overlay_string_index has advanced to a position
4064 where we must load IT->overlay_strings with more strings, do
4066 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4068 if (it
->current
.overlay_string_index
&& i
== 0)
4069 load_overlay_strings (it
, 0);
4071 /* Initialize IT to deliver display elements from the overlay
4073 it
->string
= it
->overlay_strings
[i
];
4074 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4075 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4076 it
->method
= next_element_from_string
;
4077 it
->stop_charpos
= 0;
4084 /* Compare two overlay_entry structures E1 and E2. Used as a
4085 comparison function for qsort in load_overlay_strings. Overlay
4086 strings for the same position are sorted so that
4088 1. All after-strings come in front of before-strings, except
4089 when they come from the same overlay.
4091 2. Within after-strings, strings are sorted so that overlay strings
4092 from overlays with higher priorities come first.
4094 2. Within before-strings, strings are sorted so that overlay
4095 strings from overlays with higher priorities come last.
4097 Value is analogous to strcmp. */
4101 compare_overlay_entries (e1
, e2
)
4104 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4105 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4108 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4110 /* Let after-strings appear in front of before-strings if
4111 they come from different overlays. */
4112 if (EQ (entry1
->overlay
, entry2
->overlay
))
4113 result
= entry1
->after_string_p
? 1 : -1;
4115 result
= entry1
->after_string_p
? -1 : 1;
4117 else if (entry1
->after_string_p
)
4118 /* After-strings sorted in order of decreasing priority. */
4119 result
= entry2
->priority
- entry1
->priority
;
4121 /* Before-strings sorted in order of increasing priority. */
4122 result
= entry1
->priority
- entry2
->priority
;
4128 /* Load the vector IT->overlay_strings with overlay strings from IT's
4129 current buffer position, or from CHARPOS if that is > 0. Set
4130 IT->n_overlays to the total number of overlay strings found.
4132 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4133 a time. On entry into load_overlay_strings,
4134 IT->current.overlay_string_index gives the number of overlay
4135 strings that have already been loaded by previous calls to this
4138 IT->add_overlay_start contains an additional overlay start
4139 position to consider for taking overlay strings from, if non-zero.
4140 This position comes into play when the overlay has an `invisible'
4141 property, and both before and after-strings. When we've skipped to
4142 the end of the overlay, because of its `invisible' property, we
4143 nevertheless want its before-string to appear.
4144 IT->add_overlay_start will contain the overlay start position
4147 Overlay strings are sorted so that after-string strings come in
4148 front of before-string strings. Within before and after-strings,
4149 strings are sorted by overlay priority. See also function
4150 compare_overlay_entries. */
4153 load_overlay_strings (it
, charpos
)
4157 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4158 Lisp_Object overlay
, window
, str
, invisible
;
4159 struct Lisp_Overlay
*ov
;
4162 int n
= 0, i
, j
, invis_p
;
4163 struct overlay_entry
*entries
4164 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4167 charpos
= IT_CHARPOS (*it
);
4169 /* Append the overlay string STRING of overlay OVERLAY to vector
4170 `entries' which has size `size' and currently contains `n'
4171 elements. AFTER_P non-zero means STRING is an after-string of
4173 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4176 Lisp_Object priority; \
4180 int new_size = 2 * size; \
4181 struct overlay_entry *old = entries; \
4183 (struct overlay_entry *) alloca (new_size \
4184 * sizeof *entries); \
4185 bcopy (old, entries, size * sizeof *entries); \
4189 entries[n].string = (STRING); \
4190 entries[n].overlay = (OVERLAY); \
4191 priority = Foverlay_get ((OVERLAY), Qpriority); \
4192 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4193 entries[n].after_string_p = (AFTER_P); \
4198 /* Process overlay before the overlay center. */
4199 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4201 XSETMISC (overlay
, ov
);
4202 xassert (OVERLAYP (overlay
));
4203 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4204 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4209 /* Skip this overlay if it doesn't start or end at IT's current
4211 if (end
!= charpos
&& start
!= charpos
)
4214 /* Skip this overlay if it doesn't apply to IT->w. */
4215 window
= Foverlay_get (overlay
, Qwindow
);
4216 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4219 /* If the text ``under'' the overlay is invisible, both before-
4220 and after-strings from this overlay are visible; start and
4221 end position are indistinguishable. */
4222 invisible
= Foverlay_get (overlay
, Qinvisible
);
4223 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4225 /* If overlay has a non-empty before-string, record it. */
4226 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4227 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4229 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4231 /* If overlay has a non-empty after-string, record it. */
4232 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4233 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4235 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4238 /* Process overlays after the overlay center. */
4239 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4241 XSETMISC (overlay
, ov
);
4242 xassert (OVERLAYP (overlay
));
4243 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4244 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4246 if (start
> charpos
)
4249 /* Skip this overlay if it doesn't start or end at IT's current
4251 if (end
!= charpos
&& start
!= charpos
)
4254 /* Skip this overlay if it doesn't apply to IT->w. */
4255 window
= Foverlay_get (overlay
, Qwindow
);
4256 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4259 /* If the text ``under'' the overlay is invisible, it has a zero
4260 dimension, and both before- and after-strings apply. */
4261 invisible
= Foverlay_get (overlay
, Qinvisible
);
4262 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4264 /* If overlay has a non-empty before-string, record it. */
4265 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4266 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4268 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4270 /* If overlay has a non-empty after-string, record it. */
4271 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4272 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4274 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4277 #undef RECORD_OVERLAY_STRING
4281 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4283 /* Record the total number of strings to process. */
4284 it
->n_overlay_strings
= n
;
4286 /* IT->current.overlay_string_index is the number of overlay strings
4287 that have already been consumed by IT. Copy some of the
4288 remaining overlay strings to IT->overlay_strings. */
4290 j
= it
->current
.overlay_string_index
;
4291 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4292 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4298 /* Get the first chunk of overlay strings at IT's current buffer
4299 position, or at CHARPOS if that is > 0. Value is non-zero if at
4300 least one overlay string was found. */
4303 get_overlay_strings (it
, charpos
)
4307 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4308 process. This fills IT->overlay_strings with strings, and sets
4309 IT->n_overlay_strings to the total number of strings to process.
4310 IT->pos.overlay_string_index has to be set temporarily to zero
4311 because load_overlay_strings needs this; it must be set to -1
4312 when no overlay strings are found because a zero value would
4313 indicate a position in the first overlay string. */
4314 it
->current
.overlay_string_index
= 0;
4315 load_overlay_strings (it
, charpos
);
4317 /* If we found overlay strings, set up IT to deliver display
4318 elements from the first one. Otherwise set up IT to deliver
4319 from current_buffer. */
4320 if (it
->n_overlay_strings
)
4322 /* Make sure we know settings in current_buffer, so that we can
4323 restore meaningful values when we're done with the overlay
4325 compute_stop_pos (it
);
4326 xassert (it
->face_id
>= 0);
4328 /* Save IT's settings. They are restored after all overlay
4329 strings have been processed. */
4330 xassert (it
->sp
== 0);
4333 /* Set up IT to deliver display elements from the first overlay
4335 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4336 it
->string
= it
->overlay_strings
[0];
4337 it
->stop_charpos
= 0;
4338 xassert (STRINGP (it
->string
));
4339 it
->end_charpos
= SCHARS (it
->string
);
4340 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4341 it
->method
= next_element_from_string
;
4346 it
->current
.overlay_string_index
= -1;
4347 it
->method
= next_element_from_buffer
;
4352 /* Value is non-zero if we found at least one overlay string. */
4353 return STRINGP (it
->string
);
4358 /***********************************************************************
4359 Saving and restoring state
4360 ***********************************************************************/
4362 /* Save current settings of IT on IT->stack. Called, for example,
4363 before setting up IT for an overlay string, to be able to restore
4364 IT's settings to what they were after the overlay string has been
4371 struct iterator_stack_entry
*p
;
4373 xassert (it
->sp
< 2);
4374 p
= it
->stack
+ it
->sp
;
4376 p
->stop_charpos
= it
->stop_charpos
;
4377 xassert (it
->face_id
>= 0);
4378 p
->face_id
= it
->face_id
;
4379 p
->string
= it
->string
;
4380 p
->pos
= it
->current
;
4381 p
->end_charpos
= it
->end_charpos
;
4382 p
->string_nchars
= it
->string_nchars
;
4384 p
->multibyte_p
= it
->multibyte_p
;
4385 p
->slice
= it
->slice
;
4386 p
->space_width
= it
->space_width
;
4387 p
->font_height
= it
->font_height
;
4388 p
->voffset
= it
->voffset
;
4389 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4390 p
->display_ellipsis_p
= 0;
4395 /* Restore IT's settings from IT->stack. Called, for example, when no
4396 more overlay strings must be processed, and we return to delivering
4397 display elements from a buffer, or when the end of a string from a
4398 `display' property is reached and we return to delivering display
4399 elements from an overlay string, or from a buffer. */
4405 struct iterator_stack_entry
*p
;
4407 xassert (it
->sp
> 0);
4409 p
= it
->stack
+ it
->sp
;
4410 it
->stop_charpos
= p
->stop_charpos
;
4411 it
->face_id
= p
->face_id
;
4412 it
->string
= p
->string
;
4413 it
->current
= p
->pos
;
4414 it
->end_charpos
= p
->end_charpos
;
4415 it
->string_nchars
= p
->string_nchars
;
4417 it
->multibyte_p
= p
->multibyte_p
;
4418 it
->slice
= p
->slice
;
4419 it
->space_width
= p
->space_width
;
4420 it
->font_height
= p
->font_height
;
4421 it
->voffset
= p
->voffset
;
4422 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4427 /***********************************************************************
4429 ***********************************************************************/
4431 /* Set IT's current position to the previous line start. */
4434 back_to_previous_line_start (it
)
4437 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4438 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4442 /* Move IT to the next line start.
4444 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4445 we skipped over part of the text (as opposed to moving the iterator
4446 continuously over the text). Otherwise, don't change the value
4449 Newlines may come from buffer text, overlay strings, or strings
4450 displayed via the `display' property. That's the reason we can't
4451 simply use find_next_newline_no_quit.
4453 Note that this function may not skip over invisible text that is so
4454 because of text properties and immediately follows a newline. If
4455 it would, function reseat_at_next_visible_line_start, when called
4456 from set_iterator_to_next, would effectively make invisible
4457 characters following a newline part of the wrong glyph row, which
4458 leads to wrong cursor motion. */
4461 forward_to_next_line_start (it
, skipped_p
)
4465 int old_selective
, newline_found_p
, n
;
4466 const int MAX_NEWLINE_DISTANCE
= 500;
4468 /* If already on a newline, just consume it to avoid unintended
4469 skipping over invisible text below. */
4470 if (it
->what
== IT_CHARACTER
4472 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4474 set_iterator_to_next (it
, 0);
4479 /* Don't handle selective display in the following. It's (a)
4480 unnecessary because it's done by the caller, and (b) leads to an
4481 infinite recursion because next_element_from_ellipsis indirectly
4482 calls this function. */
4483 old_selective
= it
->selective
;
4486 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4487 from buffer text. */
4488 for (n
= newline_found_p
= 0;
4489 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4490 n
+= STRINGP (it
->string
) ? 0 : 1)
4492 if (!get_next_display_element (it
))
4494 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4495 set_iterator_to_next (it
, 0);
4498 /* If we didn't find a newline near enough, see if we can use a
4500 if (!newline_found_p
)
4502 int start
= IT_CHARPOS (*it
);
4503 int limit
= find_next_newline_no_quit (start
, 1);
4506 xassert (!STRINGP (it
->string
));
4508 /* If there isn't any `display' property in sight, and no
4509 overlays, we can just use the position of the newline in
4511 if (it
->stop_charpos
>= limit
4512 || ((pos
= Fnext_single_property_change (make_number (start
),
4514 Qnil
, make_number (limit
)),
4516 && next_overlay_change (start
) == ZV
))
4518 IT_CHARPOS (*it
) = limit
;
4519 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4520 *skipped_p
= newline_found_p
= 1;
4524 while (get_next_display_element (it
)
4525 && !newline_found_p
)
4527 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4528 set_iterator_to_next (it
, 0);
4533 it
->selective
= old_selective
;
4534 return newline_found_p
;
4538 /* Set IT's current position to the previous visible line start. Skip
4539 invisible text that is so either due to text properties or due to
4540 selective display. Caution: this does not change IT->current_x and
4544 back_to_previous_visible_line_start (it
)
4549 /* Go back one newline if not on BEGV already. */
4550 if (IT_CHARPOS (*it
) > BEGV
)
4551 back_to_previous_line_start (it
);
4553 /* Move over lines that are invisible because of selective display
4554 or text properties. */
4555 while (IT_CHARPOS (*it
) > BEGV
4560 /* If selective > 0, then lines indented more than that values
4562 if (it
->selective
> 0
4563 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4564 (double) it
->selective
)) /* iftc */
4570 /* Check the newline before point for invisibility. */
4571 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4572 Qinvisible
, it
->window
);
4573 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4579 struct it it2
= *it
;
4581 if (handle_display_prop (&it2
) == HANDLED_RETURN
)
4585 /* Back one more newline if the current one is invisible. */
4587 back_to_previous_line_start (it
);
4590 xassert (IT_CHARPOS (*it
) >= BEGV
);
4591 xassert (IT_CHARPOS (*it
) == BEGV
4592 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4597 /* Reseat iterator IT at the previous visible line start. Skip
4598 invisible text that is so either due to text properties or due to
4599 selective display. At the end, update IT's overlay information,
4600 face information etc. */
4603 reseat_at_previous_visible_line_start (it
)
4606 back_to_previous_visible_line_start (it
);
4607 reseat (it
, it
->current
.pos
, 1);
4612 /* Reseat iterator IT on the next visible line start in the current
4613 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4614 preceding the line start. Skip over invisible text that is so
4615 because of selective display. Compute faces, overlays etc at the
4616 new position. Note that this function does not skip over text that
4617 is invisible because of text properties. */
4620 reseat_at_next_visible_line_start (it
, on_newline_p
)
4624 int newline_found_p
, skipped_p
= 0;
4626 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4628 /* Skip over lines that are invisible because they are indented
4629 more than the value of IT->selective. */
4630 if (it
->selective
> 0)
4631 while (IT_CHARPOS (*it
) < ZV
4632 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4633 (double) it
->selective
)) /* iftc */
4635 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4636 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4639 /* Position on the newline if that's what's requested. */
4640 if (on_newline_p
&& newline_found_p
)
4642 if (STRINGP (it
->string
))
4644 if (IT_STRING_CHARPOS (*it
) > 0)
4646 --IT_STRING_CHARPOS (*it
);
4647 --IT_STRING_BYTEPOS (*it
);
4650 else if (IT_CHARPOS (*it
) > BEGV
)
4654 reseat (it
, it
->current
.pos
, 0);
4658 reseat (it
, it
->current
.pos
, 0);
4665 /***********************************************************************
4666 Changing an iterator's position
4667 ***********************************************************************/
4669 /* Change IT's current position to POS in current_buffer. If FORCE_P
4670 is non-zero, always check for text properties at the new position.
4671 Otherwise, text properties are only looked up if POS >=
4672 IT->check_charpos of a property. */
4675 reseat (it
, pos
, force_p
)
4677 struct text_pos pos
;
4680 int original_pos
= IT_CHARPOS (*it
);
4682 reseat_1 (it
, pos
, 0);
4684 /* Determine where to check text properties. Avoid doing it
4685 where possible because text property lookup is very expensive. */
4687 || CHARPOS (pos
) > it
->stop_charpos
4688 || CHARPOS (pos
) < original_pos
)
4695 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4696 IT->stop_pos to POS, also. */
4699 reseat_1 (it
, pos
, set_stop_p
)
4701 struct text_pos pos
;
4704 /* Don't call this function when scanning a C string. */
4705 xassert (it
->s
== NULL
);
4707 /* POS must be a reasonable value. */
4708 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4710 it
->current
.pos
= it
->position
= pos
;
4711 XSETBUFFER (it
->object
, current_buffer
);
4712 it
->end_charpos
= ZV
;
4714 it
->current
.dpvec_index
= -1;
4715 it
->current
.overlay_string_index
= -1;
4716 IT_STRING_CHARPOS (*it
) = -1;
4717 IT_STRING_BYTEPOS (*it
) = -1;
4719 it
->method
= next_element_from_buffer
;
4720 /* RMS: I added this to fix a bug in move_it_vertically_backward
4721 where it->area continued to relate to the starting point
4722 for the backward motion. Bug report from
4723 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4724 However, I am not sure whether reseat still does the right thing
4725 in general after this change. */
4726 it
->area
= TEXT_AREA
;
4727 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4729 it
->face_before_selective_p
= 0;
4732 it
->stop_charpos
= CHARPOS (pos
);
4736 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4737 If S is non-null, it is a C string to iterate over. Otherwise,
4738 STRING gives a Lisp string to iterate over.
4740 If PRECISION > 0, don't return more then PRECISION number of
4741 characters from the string.
4743 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4744 characters have been returned. FIELD_WIDTH < 0 means an infinite
4747 MULTIBYTE = 0 means disable processing of multibyte characters,
4748 MULTIBYTE > 0 means enable it,
4749 MULTIBYTE < 0 means use IT->multibyte_p.
4751 IT must be initialized via a prior call to init_iterator before
4752 calling this function. */
4755 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4760 int precision
, field_width
, multibyte
;
4762 /* No region in strings. */
4763 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4765 /* No text property checks performed by default, but see below. */
4766 it
->stop_charpos
= -1;
4768 /* Set iterator position and end position. */
4769 bzero (&it
->current
, sizeof it
->current
);
4770 it
->current
.overlay_string_index
= -1;
4771 it
->current
.dpvec_index
= -1;
4772 xassert (charpos
>= 0);
4774 /* If STRING is specified, use its multibyteness, otherwise use the
4775 setting of MULTIBYTE, if specified. */
4777 it
->multibyte_p
= multibyte
> 0;
4781 xassert (STRINGP (string
));
4782 it
->string
= string
;
4784 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4785 it
->method
= next_element_from_string
;
4786 it
->current
.string_pos
= string_pos (charpos
, string
);
4793 /* Note that we use IT->current.pos, not it->current.string_pos,
4794 for displaying C strings. */
4795 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4796 if (it
->multibyte_p
)
4798 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4799 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4803 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4804 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4807 it
->method
= next_element_from_c_string
;
4810 /* PRECISION > 0 means don't return more than PRECISION characters
4812 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4813 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4815 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4816 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4817 FIELD_WIDTH < 0 means infinite field width. This is useful for
4818 padding with `-' at the end of a mode line. */
4819 if (field_width
< 0)
4820 field_width
= INFINITY
;
4821 if (field_width
> it
->end_charpos
- charpos
)
4822 it
->end_charpos
= charpos
+ field_width
;
4824 /* Use the standard display table for displaying strings. */
4825 if (DISP_TABLE_P (Vstandard_display_table
))
4826 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4828 it
->stop_charpos
= charpos
;
4834 /***********************************************************************
4836 ***********************************************************************/
4838 /* Load IT's display element fields with information about the next
4839 display element from the current position of IT. Value is zero if
4840 end of buffer (or C string) is reached. */
4843 get_next_display_element (it
)
4846 /* Non-zero means that we found a display element. Zero means that
4847 we hit the end of what we iterate over. Performance note: the
4848 function pointer `method' used here turns out to be faster than
4849 using a sequence of if-statements. */
4853 success_p
= (*it
->method
) (it
);
4855 if (it
->what
== IT_CHARACTER
)
4857 /* Map via display table or translate control characters.
4858 IT->c, IT->len etc. have been set to the next character by
4859 the function call above. If we have a display table, and it
4860 contains an entry for IT->c, translate it. Don't do this if
4861 IT->c itself comes from a display table, otherwise we could
4862 end up in an infinite recursion. (An alternative could be to
4863 count the recursion depth of this function and signal an
4864 error when a certain maximum depth is reached.) Is it worth
4866 if (success_p
&& it
->dpvec
== NULL
)
4871 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4874 struct Lisp_Vector
*v
= XVECTOR (dv
);
4876 /* Return the first character from the display table
4877 entry, if not empty. If empty, don't display the
4878 current character. */
4881 it
->dpvec_char_len
= it
->len
;
4882 it
->dpvec
= v
->contents
;
4883 it
->dpend
= v
->contents
+ v
->size
;
4884 it
->current
.dpvec_index
= 0;
4885 it
->saved_face_id
= it
->face_id
;
4886 it
->method
= next_element_from_display_vector
;
4890 set_iterator_to_next (it
, 0);
4895 /* Translate control characters into `\003' or `^C' form.
4896 Control characters coming from a display table entry are
4897 currently not translated because we use IT->dpvec to hold
4898 the translation. This could easily be changed but I
4899 don't believe that it is worth doing.
4901 If it->multibyte_p is nonzero, eight-bit characters and
4902 non-printable multibyte characters are also translated to
4905 If it->multibyte_p is zero, eight-bit characters that
4906 don't have corresponding multibyte char code are also
4907 translated to octal form. */
4908 else if ((it
->c
< ' '
4909 && (it
->area
!= TEXT_AREA
4910 /* In mode line, treat \n like other crl chars. */
4912 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
4913 || (it
->c
!= '\n' && it
->c
!= '\t')))
4917 || !CHAR_PRINTABLE_P (it
->c
)
4921 && (!unibyte_display_via_language_environment
4922 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
4924 /* IT->c is a control character which must be displayed
4925 either as '\003' or as `^C' where the '\\' and '^'
4926 can be defined in the display table. Fill
4927 IT->ctl_chars with glyphs for what we have to
4928 display. Then, set IT->dpvec to these glyphs. */
4931 int face_id
= escape_glyph_face
;
4933 /* Find the face id if `escape-glyph' unless we recently did. */
4936 Lisp_Object tem
= Fget (Qescape_glyph
, Qface
);
4938 face_id
= XINT (tem
);
4941 /* If there's overflow, use 0 instead. */
4942 if (FAST_GLYPH_FACE (FAST_MAKE_GLYPH (0, face_id
)) != face_id
)
4944 escape_glyph_face
= face_id
;
4947 if (it
->c
< 128 && it
->ctl_arrow_p
)
4949 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4951 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4952 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4953 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4955 g
= FAST_MAKE_GLYPH ('^', face_id
);
4956 XSETINT (it
->ctl_chars
[0], g
);
4958 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, face_id
);
4959 XSETINT (it
->ctl_chars
[1], g
);
4962 else if (it
->c
== 0x8a0 || it
->c
== 0x8ad)
4964 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4966 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4967 && GLYPH_CHAR_VALID_P (XINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4968 g
= XINT (DISP_ESCAPE_GLYPH (it
->dp
));
4970 g
= FAST_MAKE_GLYPH ('\\', face_id
);
4971 XSETINT (it
->ctl_chars
[0], g
);
4973 g
= FAST_MAKE_GLYPH (it
->c
== 0x8ad ? '-' : ' ', face_id
);
4974 XSETINT (it
->ctl_chars
[1], g
);
4979 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4984 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4986 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4987 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4988 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4990 escape_glyph
= FAST_MAKE_GLYPH ('\\', face_id
);
4992 if (SINGLE_BYTE_CHAR_P (it
->c
))
4993 str
[0] = it
->c
, len
= 1;
4996 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4999 /* It's an invalid character, which
5000 shouldn't happen actually, but due to
5001 bugs it may happen. Let's print the char
5002 as is, there's not much meaningful we can
5005 str
[1] = it
->c
>> 8;
5006 str
[2] = it
->c
>> 16;
5007 str
[3] = it
->c
>> 24;
5012 for (i
= 0; i
< len
; i
++)
5014 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5015 /* Insert three more glyphs into IT->ctl_chars for
5016 the octal display of the character. */
5017 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0',
5019 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5020 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0',
5022 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5023 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0',
5025 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5030 /* Set up IT->dpvec and return first character from it. */
5031 it
->dpvec_char_len
= it
->len
;
5032 it
->dpvec
= it
->ctl_chars
;
5033 it
->dpend
= it
->dpvec
+ ctl_len
;
5034 it
->current
.dpvec_index
= 0;
5035 it
->saved_face_id
= it
->face_id
;
5036 it
->method
= next_element_from_display_vector
;
5041 /* Adjust face id for a multibyte character. There are no
5042 multibyte character in unibyte text. */
5045 && FRAME_WINDOW_P (it
->f
))
5047 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5048 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5052 /* Is this character the last one of a run of characters with
5053 box? If yes, set IT->end_of_box_run_p to 1. */
5060 it
->end_of_box_run_p
5061 = ((face_id
= face_after_it_pos (it
),
5062 face_id
!= it
->face_id
)
5063 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5064 face
->box
== FACE_NO_BOX
));
5067 /* Value is 0 if end of buffer or string reached. */
5072 /* Move IT to the next display element.
5074 RESEAT_P non-zero means if called on a newline in buffer text,
5075 skip to the next visible line start.
5077 Functions get_next_display_element and set_iterator_to_next are
5078 separate because I find this arrangement easier to handle than a
5079 get_next_display_element function that also increments IT's
5080 position. The way it is we can first look at an iterator's current
5081 display element, decide whether it fits on a line, and if it does,
5082 increment the iterator position. The other way around we probably
5083 would either need a flag indicating whether the iterator has to be
5084 incremented the next time, or we would have to implement a
5085 decrement position function which would not be easy to write. */
5088 set_iterator_to_next (it
, reseat_p
)
5092 /* Reset flags indicating start and end of a sequence of characters
5093 with box. Reset them at the start of this function because
5094 moving the iterator to a new position might set them. */
5095 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5097 if (it
->method
== next_element_from_buffer
)
5099 /* The current display element of IT is a character from
5100 current_buffer. Advance in the buffer, and maybe skip over
5101 invisible lines that are so because of selective display. */
5102 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5103 reseat_at_next_visible_line_start (it
, 0);
5106 xassert (it
->len
!= 0);
5107 IT_BYTEPOS (*it
) += it
->len
;
5108 IT_CHARPOS (*it
) += 1;
5109 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5112 else if (it
->method
== next_element_from_composition
)
5114 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5115 if (STRINGP (it
->string
))
5117 IT_STRING_BYTEPOS (*it
) += it
->len
;
5118 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5119 it
->method
= next_element_from_string
;
5120 goto consider_string_end
;
5124 IT_BYTEPOS (*it
) += it
->len
;
5125 IT_CHARPOS (*it
) += it
->cmp_len
;
5126 it
->method
= next_element_from_buffer
;
5129 else if (it
->method
== next_element_from_c_string
)
5131 /* Current display element of IT is from a C string. */
5132 IT_BYTEPOS (*it
) += it
->len
;
5133 IT_CHARPOS (*it
) += 1;
5135 else if (it
->method
== next_element_from_display_vector
)
5137 /* Current display element of IT is from a display table entry.
5138 Advance in the display table definition. Reset it to null if
5139 end reached, and continue with characters from buffers/
5141 ++it
->current
.dpvec_index
;
5143 /* Restore face of the iterator to what they were before the
5144 display vector entry (these entries may contain faces). */
5145 it
->face_id
= it
->saved_face_id
;
5147 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5150 it
->method
= next_element_from_c_string
;
5151 else if (STRINGP (it
->string
))
5152 it
->method
= next_element_from_string
;
5154 it
->method
= next_element_from_buffer
;
5157 it
->current
.dpvec_index
= -1;
5159 /* Recheck faces after display vector */
5160 it
->stop_charpos
= 0;
5162 /* Skip over characters which were displayed via IT->dpvec. */
5163 if (it
->dpvec_char_len
< 0)
5164 reseat_at_next_visible_line_start (it
, 1);
5165 else if (it
->dpvec_char_len
> 0)
5167 it
->len
= it
->dpvec_char_len
;
5168 set_iterator_to_next (it
, reseat_p
);
5172 else if (it
->method
== next_element_from_string
)
5174 /* Current display element is a character from a Lisp string. */
5175 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5176 IT_STRING_BYTEPOS (*it
) += it
->len
;
5177 IT_STRING_CHARPOS (*it
) += 1;
5179 consider_string_end
:
5181 if (it
->current
.overlay_string_index
>= 0)
5183 /* IT->string is an overlay string. Advance to the
5184 next, if there is one. */
5185 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5186 next_overlay_string (it
);
5190 /* IT->string is not an overlay string. If we reached
5191 its end, and there is something on IT->stack, proceed
5192 with what is on the stack. This can be either another
5193 string, this time an overlay string, or a buffer. */
5194 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5198 if (!STRINGP (it
->string
))
5199 it
->method
= next_element_from_buffer
;
5201 goto consider_string_end
;
5205 else if (it
->method
== next_element_from_image
5206 || it
->method
== next_element_from_stretch
)
5208 /* The position etc with which we have to proceed are on
5209 the stack. The position may be at the end of a string,
5210 if the `display' property takes up the whole string. */
5213 if (STRINGP (it
->string
))
5215 it
->method
= next_element_from_string
;
5216 goto consider_string_end
;
5219 it
->method
= next_element_from_buffer
;
5222 /* There are no other methods defined, so this should be a bug. */
5225 xassert (it
->method
!= next_element_from_string
5226 || (STRINGP (it
->string
)
5227 && IT_STRING_CHARPOS (*it
) >= 0));
5230 /* Load IT's display element fields with information about the next
5231 display element which comes from a display table entry or from the
5232 result of translating a control character to one of the forms `^C'
5235 IT->dpvec holds the glyphs to return as characters.
5236 IT->saved_face_id holds the face id before the display vector--
5237 it is restored into IT->face_idin set_iterator_to_next. */
5240 next_element_from_display_vector (it
)
5244 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5246 if (INTEGERP (*it
->dpvec
)
5247 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5252 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5253 it
->c
= FAST_GLYPH_CHAR (g
);
5254 it
->len
= CHAR_BYTES (it
->c
);
5256 /* The entry may contain a face id to use. Such a face id is
5257 the id of a Lisp face, not a realized face. A face id of
5258 zero means no face is specified. */
5259 lface_id
= FAST_GLYPH_FACE (g
);
5262 /* The function returns -1 if lface_id is invalid. */
5263 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5265 it
->face_id
= face_id
;
5269 /* Display table entry is invalid. Return a space. */
5270 it
->c
= ' ', it
->len
= 1;
5272 /* Don't change position and object of the iterator here. They are
5273 still the values of the character that had this display table
5274 entry or was translated, and that's what we want. */
5275 it
->what
= IT_CHARACTER
;
5280 /* Load IT with the next display element from Lisp string IT->string.
5281 IT->current.string_pos is the current position within the string.
5282 If IT->current.overlay_string_index >= 0, the Lisp string is an
5286 next_element_from_string (it
)
5289 struct text_pos position
;
5291 xassert (STRINGP (it
->string
));
5292 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5293 position
= it
->current
.string_pos
;
5295 /* Time to check for invisible text? */
5296 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5297 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5301 /* Since a handler may have changed IT->method, we must
5303 return get_next_display_element (it
);
5306 if (it
->current
.overlay_string_index
>= 0)
5308 /* Get the next character from an overlay string. In overlay
5309 strings, There is no field width or padding with spaces to
5311 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5316 else if (STRING_MULTIBYTE (it
->string
))
5318 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5319 const unsigned char *s
= (SDATA (it
->string
)
5320 + IT_STRING_BYTEPOS (*it
));
5321 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5325 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5331 /* Get the next character from a Lisp string that is not an
5332 overlay string. Such strings come from the mode line, for
5333 example. We may have to pad with spaces, or truncate the
5334 string. See also next_element_from_c_string. */
5335 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5340 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5342 /* Pad with spaces. */
5343 it
->c
= ' ', it
->len
= 1;
5344 CHARPOS (position
) = BYTEPOS (position
) = -1;
5346 else if (STRING_MULTIBYTE (it
->string
))
5348 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5349 const unsigned char *s
= (SDATA (it
->string
)
5350 + IT_STRING_BYTEPOS (*it
));
5351 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5355 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5360 /* Record what we have and where it came from. Note that we store a
5361 buffer position in IT->position although it could arguably be a
5363 it
->what
= IT_CHARACTER
;
5364 it
->object
= it
->string
;
5365 it
->position
= position
;
5370 /* Load IT with next display element from C string IT->s.
5371 IT->string_nchars is the maximum number of characters to return
5372 from the string. IT->end_charpos may be greater than
5373 IT->string_nchars when this function is called, in which case we
5374 may have to return padding spaces. Value is zero if end of string
5375 reached, including padding spaces. */
5378 next_element_from_c_string (it
)
5384 it
->what
= IT_CHARACTER
;
5385 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5388 /* IT's position can be greater IT->string_nchars in case a field
5389 width or precision has been specified when the iterator was
5391 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5393 /* End of the game. */
5397 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5399 /* Pad with spaces. */
5400 it
->c
= ' ', it
->len
= 1;
5401 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5403 else if (it
->multibyte_p
)
5405 /* Implementation note: The calls to strlen apparently aren't a
5406 performance problem because there is no noticeable performance
5407 difference between Emacs running in unibyte or multibyte mode. */
5408 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5409 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5413 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5419 /* Set up IT to return characters from an ellipsis, if appropriate.
5420 The definition of the ellipsis glyphs may come from a display table
5421 entry. This function Fills IT with the first glyph from the
5422 ellipsis if an ellipsis is to be displayed. */
5425 next_element_from_ellipsis (it
)
5428 if (it
->selective_display_ellipsis_p
)
5429 setup_for_ellipsis (it
, it
->len
);
5432 /* The face at the current position may be different from the
5433 face we find after the invisible text. Remember what it
5434 was in IT->saved_face_id, and signal that it's there by
5435 setting face_before_selective_p. */
5436 it
->saved_face_id
= it
->face_id
;
5437 it
->method
= next_element_from_buffer
;
5438 reseat_at_next_visible_line_start (it
, 1);
5439 it
->face_before_selective_p
= 1;
5442 return get_next_display_element (it
);
5446 /* Deliver an image display element. The iterator IT is already
5447 filled with image information (done in handle_display_prop). Value
5452 next_element_from_image (it
)
5455 it
->what
= IT_IMAGE
;
5460 /* Fill iterator IT with next display element from a stretch glyph
5461 property. IT->object is the value of the text property. Value is
5465 next_element_from_stretch (it
)
5468 it
->what
= IT_STRETCH
;
5473 /* Load IT with the next display element from current_buffer. Value
5474 is zero if end of buffer reached. IT->stop_charpos is the next
5475 position at which to stop and check for text properties or buffer
5479 next_element_from_buffer (it
)
5484 /* Check this assumption, otherwise, we would never enter the
5485 if-statement, below. */
5486 xassert (IT_CHARPOS (*it
) >= BEGV
5487 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5489 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5491 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5493 int overlay_strings_follow_p
;
5495 /* End of the game, except when overlay strings follow that
5496 haven't been returned yet. */
5497 if (it
->overlay_strings_at_end_processed_p
)
5498 overlay_strings_follow_p
= 0;
5501 it
->overlay_strings_at_end_processed_p
= 1;
5502 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5505 if (overlay_strings_follow_p
)
5506 success_p
= get_next_display_element (it
);
5510 it
->position
= it
->current
.pos
;
5517 return get_next_display_element (it
);
5522 /* No face changes, overlays etc. in sight, so just return a
5523 character from current_buffer. */
5526 /* Maybe run the redisplay end trigger hook. Performance note:
5527 This doesn't seem to cost measurable time. */
5528 if (it
->redisplay_end_trigger_charpos
5530 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5531 run_redisplay_end_trigger_hook (it
);
5533 /* Get the next character, maybe multibyte. */
5534 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5535 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5537 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5538 - IT_BYTEPOS (*it
));
5539 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5542 it
->c
= *p
, it
->len
= 1;
5544 /* Record what we have and where it came from. */
5545 it
->what
= IT_CHARACTER
;;
5546 it
->object
= it
->w
->buffer
;
5547 it
->position
= it
->current
.pos
;
5549 /* Normally we return the character found above, except when we
5550 really want to return an ellipsis for selective display. */
5555 /* A value of selective > 0 means hide lines indented more
5556 than that number of columns. */
5557 if (it
->selective
> 0
5558 && IT_CHARPOS (*it
) + 1 < ZV
5559 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5560 IT_BYTEPOS (*it
) + 1,
5561 (double) it
->selective
)) /* iftc */
5563 success_p
= next_element_from_ellipsis (it
);
5564 it
->dpvec_char_len
= -1;
5567 else if (it
->c
== '\r' && it
->selective
== -1)
5569 /* A value of selective == -1 means that everything from the
5570 CR to the end of the line is invisible, with maybe an
5571 ellipsis displayed for it. */
5572 success_p
= next_element_from_ellipsis (it
);
5573 it
->dpvec_char_len
= -1;
5578 /* Value is zero if end of buffer reached. */
5579 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5584 /* Run the redisplay end trigger hook for IT. */
5587 run_redisplay_end_trigger_hook (it
)
5590 Lisp_Object args
[3];
5592 /* IT->glyph_row should be non-null, i.e. we should be actually
5593 displaying something, or otherwise we should not run the hook. */
5594 xassert (it
->glyph_row
);
5596 /* Set up hook arguments. */
5597 args
[0] = Qredisplay_end_trigger_functions
;
5598 args
[1] = it
->window
;
5599 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5600 it
->redisplay_end_trigger_charpos
= 0;
5602 /* Since we are *trying* to run these functions, don't try to run
5603 them again, even if they get an error. */
5604 it
->w
->redisplay_end_trigger
= Qnil
;
5605 Frun_hook_with_args (3, args
);
5607 /* Notice if it changed the face of the character we are on. */
5608 handle_face_prop (it
);
5612 /* Deliver a composition display element. The iterator IT is already
5613 filled with composition information (done in
5614 handle_composition_prop). Value is always 1. */
5617 next_element_from_composition (it
)
5620 it
->what
= IT_COMPOSITION
;
5621 it
->position
= (STRINGP (it
->string
)
5622 ? it
->current
.string_pos
5629 /***********************************************************************
5630 Moving an iterator without producing glyphs
5631 ***********************************************************************/
5633 /* Move iterator IT to a specified buffer or X position within one
5634 line on the display without producing glyphs.
5636 OP should be a bit mask including some or all of these bits:
5637 MOVE_TO_X: Stop on reaching x-position TO_X.
5638 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5639 Regardless of OP's value, stop in reaching the end of the display line.
5641 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5642 This means, in particular, that TO_X includes window's horizontal
5645 The return value has several possible values that
5646 say what condition caused the scan to stop:
5648 MOVE_POS_MATCH_OR_ZV
5649 - when TO_POS or ZV was reached.
5652 -when TO_X was reached before TO_POS or ZV were reached.
5655 - when we reached the end of the display area and the line must
5659 - when we reached the end of the display area and the line is
5663 - when we stopped at a line end, i.e. a newline or a CR and selective
5666 static enum move_it_result
5667 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5669 int to_charpos
, to_x
, op
;
5671 enum move_it_result result
= MOVE_UNDEFINED
;
5672 struct glyph_row
*saved_glyph_row
;
5674 /* Don't produce glyphs in produce_glyphs. */
5675 saved_glyph_row
= it
->glyph_row
;
5676 it
->glyph_row
= NULL
;
5678 #define BUFFER_POS_REACHED_P() \
5679 ((op & MOVE_TO_POS) != 0 \
5680 && BUFFERP (it->object) \
5681 && IT_CHARPOS (*it) >= to_charpos)
5685 int x
, i
, ascent
= 0, descent
= 0;
5687 /* Stop when ZV reached.
5688 We used to stop here when TO_CHARPOS reached as well, but that is
5689 too soon if this glyph does not fit on this line. So we handle it
5690 explicitly below. */
5691 if (!get_next_display_element (it
)
5692 || (it
->truncate_lines_p
5693 && BUFFER_POS_REACHED_P ()))
5695 result
= MOVE_POS_MATCH_OR_ZV
;
5699 /* The call to produce_glyphs will get the metrics of the
5700 display element IT is loaded with. We record in x the
5701 x-position before this display element in case it does not
5705 /* Remember the line height so far in case the next element doesn't
5707 if (!it
->truncate_lines_p
)
5709 ascent
= it
->max_ascent
;
5710 descent
= it
->max_descent
;
5713 PRODUCE_GLYPHS (it
);
5715 if (it
->area
!= TEXT_AREA
)
5717 set_iterator_to_next (it
, 1);
5721 /* The number of glyphs we get back in IT->nglyphs will normally
5722 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5723 character on a terminal frame, or (iii) a line end. For the
5724 second case, IT->nglyphs - 1 padding glyphs will be present
5725 (on X frames, there is only one glyph produced for a
5726 composite character.
5728 The behavior implemented below means, for continuation lines,
5729 that as many spaces of a TAB as fit on the current line are
5730 displayed there. For terminal frames, as many glyphs of a
5731 multi-glyph character are displayed in the current line, too.
5732 This is what the old redisplay code did, and we keep it that
5733 way. Under X, the whole shape of a complex character must
5734 fit on the line or it will be completely displayed in the
5737 Note that both for tabs and padding glyphs, all glyphs have
5741 /* More than one glyph or glyph doesn't fit on line. All
5742 glyphs have the same width. */
5743 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5746 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5748 new_x
= x
+ single_glyph_width
;
5750 /* We want to leave anything reaching TO_X to the caller. */
5751 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5753 if (BUFFER_POS_REACHED_P ())
5754 goto buffer_pos_reached
;
5756 result
= MOVE_X_REACHED
;
5759 else if (/* Lines are continued. */
5760 !it
->truncate_lines_p
5761 && (/* And glyph doesn't fit on the line. */
5762 new_x
> it
->last_visible_x
5763 /* Or it fits exactly and we're on a window
5765 || (new_x
== it
->last_visible_x
5766 && FRAME_WINDOW_P (it
->f
))))
5768 if (/* IT->hpos == 0 means the very first glyph
5769 doesn't fit on the line, e.g. a wide image. */
5771 || (new_x
== it
->last_visible_x
5772 && FRAME_WINDOW_P (it
->f
)))
5775 it
->current_x
= new_x
;
5776 if (i
== it
->nglyphs
- 1)
5778 set_iterator_to_next (it
, 1);
5779 #ifdef HAVE_WINDOW_SYSTEM
5780 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5782 if (!get_next_display_element (it
))
5784 result
= MOVE_POS_MATCH_OR_ZV
;
5787 if (BUFFER_POS_REACHED_P ())
5789 if (ITERATOR_AT_END_OF_LINE_P (it
))
5790 result
= MOVE_POS_MATCH_OR_ZV
;
5792 result
= MOVE_LINE_CONTINUED
;
5795 if (ITERATOR_AT_END_OF_LINE_P (it
))
5797 result
= MOVE_NEWLINE_OR_CR
;
5801 #endif /* HAVE_WINDOW_SYSTEM */
5807 it
->max_ascent
= ascent
;
5808 it
->max_descent
= descent
;
5811 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5813 result
= MOVE_LINE_CONTINUED
;
5816 else if (BUFFER_POS_REACHED_P ())
5817 goto buffer_pos_reached
;
5818 else if (new_x
> it
->first_visible_x
)
5820 /* Glyph is visible. Increment number of glyphs that
5821 would be displayed. */
5826 /* Glyph is completely off the left margin of the display
5827 area. Nothing to do. */
5831 if (result
!= MOVE_UNDEFINED
)
5834 else if (BUFFER_POS_REACHED_P ())
5838 it
->max_ascent
= ascent
;
5839 it
->max_descent
= descent
;
5840 result
= MOVE_POS_MATCH_OR_ZV
;
5843 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5845 /* Stop when TO_X specified and reached. This check is
5846 necessary here because of lines consisting of a line end,
5847 only. The line end will not produce any glyphs and we
5848 would never get MOVE_X_REACHED. */
5849 xassert (it
->nglyphs
== 0);
5850 result
= MOVE_X_REACHED
;
5854 /* Is this a line end? If yes, we're done. */
5855 if (ITERATOR_AT_END_OF_LINE_P (it
))
5857 result
= MOVE_NEWLINE_OR_CR
;
5861 /* The current display element has been consumed. Advance
5863 set_iterator_to_next (it
, 1);
5865 /* Stop if lines are truncated and IT's current x-position is
5866 past the right edge of the window now. */
5867 if (it
->truncate_lines_p
5868 && it
->current_x
>= it
->last_visible_x
)
5870 #ifdef HAVE_WINDOW_SYSTEM
5871 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5873 if (!get_next_display_element (it
)
5874 || BUFFER_POS_REACHED_P ())
5876 result
= MOVE_POS_MATCH_OR_ZV
;
5879 if (ITERATOR_AT_END_OF_LINE_P (it
))
5881 result
= MOVE_NEWLINE_OR_CR
;
5885 #endif /* HAVE_WINDOW_SYSTEM */
5886 result
= MOVE_LINE_TRUNCATED
;
5891 #undef BUFFER_POS_REACHED_P
5893 /* Restore the iterator settings altered at the beginning of this
5895 it
->glyph_row
= saved_glyph_row
;
5900 /* Move IT forward until it satisfies one or more of the criteria in
5901 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5903 OP is a bit-mask that specifies where to stop, and in particular,
5904 which of those four position arguments makes a difference. See the
5905 description of enum move_operation_enum.
5907 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5908 screen line, this function will set IT to the next position >
5912 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5914 int to_charpos
, to_x
, to_y
, to_vpos
;
5917 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5923 if (op
& MOVE_TO_VPOS
)
5925 /* If no TO_CHARPOS and no TO_X specified, stop at the
5926 start of the line TO_VPOS. */
5927 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5929 if (it
->vpos
== to_vpos
)
5935 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5939 /* TO_VPOS >= 0 means stop at TO_X in the line at
5940 TO_VPOS, or at TO_POS, whichever comes first. */
5941 if (it
->vpos
== to_vpos
)
5947 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5949 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5954 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5956 /* We have reached TO_X but not in the line we want. */
5957 skip
= move_it_in_display_line_to (it
, to_charpos
,
5959 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5967 else if (op
& MOVE_TO_Y
)
5969 struct it it_backup
;
5971 /* TO_Y specified means stop at TO_X in the line containing
5972 TO_Y---or at TO_CHARPOS if this is reached first. The
5973 problem is that we can't really tell whether the line
5974 contains TO_Y before we have completely scanned it, and
5975 this may skip past TO_X. What we do is to first scan to
5978 If TO_X is not specified, use a TO_X of zero. The reason
5979 is to make the outcome of this function more predictable.
5980 If we didn't use TO_X == 0, we would stop at the end of
5981 the line which is probably not what a caller would expect
5983 skip
= move_it_in_display_line_to (it
, to_charpos
,
5987 | (op
& MOVE_TO_POS
)));
5989 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5990 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5996 /* If TO_X was reached, we would like to know whether TO_Y
5997 is in the line. This can only be said if we know the
5998 total line height which requires us to scan the rest of
6000 if (skip
== MOVE_X_REACHED
)
6003 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6004 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6006 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6009 /* Now, decide whether TO_Y is in this line. */
6010 line_height
= it
->max_ascent
+ it
->max_descent
;
6011 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6013 if (to_y
>= it
->current_y
6014 && to_y
< it
->current_y
+ line_height
)
6016 if (skip
== MOVE_X_REACHED
)
6017 /* If TO_Y is in this line and TO_X was reached above,
6018 we scanned too far. We have to restore IT's settings
6019 to the ones before skipping. */
6023 else if (skip
== MOVE_X_REACHED
)
6026 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6034 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6038 case MOVE_POS_MATCH_OR_ZV
:
6042 case MOVE_NEWLINE_OR_CR
:
6043 set_iterator_to_next (it
, 1);
6044 it
->continuation_lines_width
= 0;
6047 case MOVE_LINE_TRUNCATED
:
6048 it
->continuation_lines_width
= 0;
6049 reseat_at_next_visible_line_start (it
, 0);
6050 if ((op
& MOVE_TO_POS
) != 0
6051 && IT_CHARPOS (*it
) > to_charpos
)
6058 case MOVE_LINE_CONTINUED
:
6059 it
->continuation_lines_width
+= it
->current_x
;
6066 /* Reset/increment for the next run. */
6067 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6068 it
->current_x
= it
->hpos
= 0;
6069 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6071 last_height
= it
->max_ascent
+ it
->max_descent
;
6072 last_max_ascent
= it
->max_ascent
;
6073 it
->max_ascent
= it
->max_descent
= 0;
6078 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6082 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6084 If DY > 0, move IT backward at least that many pixels. DY = 0
6085 means move IT backward to the preceding line start or BEGV. This
6086 function may move over more than DY pixels if IT->current_y - DY
6087 ends up in the middle of a line; in this case IT->current_y will be
6088 set to the top of the line moved to. */
6091 move_it_vertically_backward (it
, dy
)
6102 start_pos
= IT_CHARPOS (*it
);
6104 /* Estimate how many newlines we must move back. */
6105 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6107 /* Set the iterator's position that many lines back. */
6108 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6109 back_to_previous_visible_line_start (it
);
6111 /* Reseat the iterator here. When moving backward, we don't want
6112 reseat to skip forward over invisible text, set up the iterator
6113 to deliver from overlay strings at the new position etc. So,
6114 use reseat_1 here. */
6115 reseat_1 (it
, it
->current
.pos
, 1);
6117 /* We are now surely at a line start. */
6118 it
->current_x
= it
->hpos
= 0;
6119 it
->continuation_lines_width
= 0;
6121 /* Move forward and see what y-distance we moved. First move to the
6122 start of the next line so that we get its height. We need this
6123 height to be able to tell whether we reached the specified
6126 it2
.max_ascent
= it2
.max_descent
= 0;
6127 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6128 MOVE_TO_POS
| MOVE_TO_VPOS
);
6129 xassert (IT_CHARPOS (*it
) >= BEGV
);
6132 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6133 xassert (IT_CHARPOS (*it
) >= BEGV
);
6134 /* H is the actual vertical distance from the position in *IT
6135 and the starting position. */
6136 h
= it2
.current_y
- it
->current_y
;
6137 /* NLINES is the distance in number of lines. */
6138 nlines
= it2
.vpos
- it
->vpos
;
6140 /* Correct IT's y and vpos position
6141 so that they are relative to the starting point. */
6147 /* DY == 0 means move to the start of the screen line. The
6148 value of nlines is > 0 if continuation lines were involved. */
6150 move_it_by_lines (it
, nlines
, 1);
6151 xassert (IT_CHARPOS (*it
) <= start_pos
);
6155 /* The y-position we try to reach, relative to *IT.
6156 Note that H has been subtracted in front of the if-statement. */
6157 int target_y
= it
->current_y
+ h
- dy
;
6158 int y0
= it3
.current_y
;
6159 int y1
= line_bottom_y (&it3
);
6160 int line_height
= y1
- y0
;
6162 /* If we did not reach target_y, try to move further backward if
6163 we can. If we moved too far backward, try to move forward. */
6164 if (target_y
< it
->current_y
6165 /* This is heuristic. In a window that's 3 lines high, with
6166 a line height of 13 pixels each, recentering with point
6167 on the bottom line will try to move -39/2 = 19 pixels
6168 backward. Try to avoid moving into the first line. */
6169 && it
->current_y
- target_y
> line_height
* 2 / 3
6170 && IT_CHARPOS (*it
) > BEGV
)
6172 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6173 target_y
- it
->current_y
));
6174 dy
= it
->current_y
- target_y
;
6175 goto move_further_back
;
6177 else if (target_y
>= it
->current_y
+ line_height
6178 && IT_CHARPOS (*it
) < ZV
)
6180 /* Should move forward by at least one line, maybe more.
6182 Note: Calling move_it_by_lines can be expensive on
6183 terminal frames, where compute_motion is used (via
6184 vmotion) to do the job, when there are very long lines
6185 and truncate-lines is nil. That's the reason for
6186 treating terminal frames specially here. */
6188 if (!FRAME_WINDOW_P (it
->f
))
6189 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6194 move_it_by_lines (it
, 1, 1);
6196 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6199 xassert (IT_CHARPOS (*it
) >= BEGV
);
6205 /* Move IT by a specified amount of pixel lines DY. DY negative means
6206 move backwards. DY = 0 means move to start of screen line. At the
6207 end, IT will be on the start of a screen line. */
6210 move_it_vertically (it
, dy
)
6215 move_it_vertically_backward (it
, -dy
);
6218 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6219 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6220 MOVE_TO_POS
| MOVE_TO_Y
);
6221 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6223 /* If buffer ends in ZV without a newline, move to the start of
6224 the line to satisfy the post-condition. */
6225 if (IT_CHARPOS (*it
) == ZV
6226 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6227 move_it_by_lines (it
, 0, 0);
6232 /* Move iterator IT past the end of the text line it is in. */
6235 move_it_past_eol (it
)
6238 enum move_it_result rc
;
6240 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6241 if (rc
== MOVE_NEWLINE_OR_CR
)
6242 set_iterator_to_next (it
, 0);
6246 #if 0 /* Currently not used. */
6248 /* Return non-zero if some text between buffer positions START_CHARPOS
6249 and END_CHARPOS is invisible. IT->window is the window for text
6253 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6255 int start_charpos
, end_charpos
;
6257 Lisp_Object prop
, limit
;
6258 int invisible_found_p
;
6260 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6262 /* Is text at START invisible? */
6263 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6265 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6266 invisible_found_p
= 1;
6269 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6271 make_number (end_charpos
));
6272 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6275 return invisible_found_p
;
6281 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6282 negative means move up. DVPOS == 0 means move to the start of the
6283 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6284 NEED_Y_P is zero, IT->current_y will be left unchanged.
6286 Further optimization ideas: If we would know that IT->f doesn't use
6287 a face with proportional font, we could be faster for
6288 truncate-lines nil. */
6291 move_it_by_lines (it
, dvpos
, need_y_p
)
6293 int dvpos
, need_y_p
;
6295 struct position pos
;
6297 if (!FRAME_WINDOW_P (it
->f
))
6299 struct text_pos textpos
;
6301 /* We can use vmotion on frames without proportional fonts. */
6302 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6303 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6304 reseat (it
, textpos
, 1);
6305 it
->vpos
+= pos
.vpos
;
6306 it
->current_y
+= pos
.vpos
;
6308 else if (dvpos
== 0)
6310 /* DVPOS == 0 means move to the start of the screen line. */
6311 move_it_vertically_backward (it
, 0);
6312 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6313 /* Let next call to line_bottom_y calculate real line height */
6317 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6321 int start_charpos
, i
;
6323 /* Start at the beginning of the screen line containing IT's
6325 move_it_vertically_backward (it
, 0);
6327 /* Go back -DVPOS visible lines and reseat the iterator there. */
6328 start_charpos
= IT_CHARPOS (*it
);
6329 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6330 back_to_previous_visible_line_start (it
);
6331 reseat (it
, it
->current
.pos
, 1);
6332 it
->current_x
= it
->hpos
= 0;
6334 /* Above call may have moved too far if continuation lines
6335 are involved. Scan forward and see if it did. */
6337 it2
.vpos
= it2
.current_y
= 0;
6338 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6339 it
->vpos
-= it2
.vpos
;
6340 it
->current_y
-= it2
.current_y
;
6341 it
->current_x
= it
->hpos
= 0;
6343 /* If we moved too far, move IT some lines forward. */
6344 if (it2
.vpos
> -dvpos
)
6346 int delta
= it2
.vpos
+ dvpos
;
6347 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6352 /* Return 1 if IT points into the middle of a display vector. */
6355 in_display_vector_p (it
)
6358 return (it
->method
== next_element_from_display_vector
6359 && it
->current
.dpvec_index
> 0
6360 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6364 /***********************************************************************
6366 ***********************************************************************/
6369 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6373 add_to_log (format
, arg1
, arg2
)
6375 Lisp_Object arg1
, arg2
;
6377 Lisp_Object args
[3];
6378 Lisp_Object msg
, fmt
;
6381 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6384 /* Do nothing if called asynchronously. Inserting text into
6385 a buffer may call after-change-functions and alike and
6386 that would means running Lisp asynchronously. */
6387 if (handling_signal
)
6391 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6393 args
[0] = fmt
= build_string (format
);
6396 msg
= Fformat (3, args
);
6398 len
= SBYTES (msg
) + 1;
6399 SAFE_ALLOCA (buffer
, char *, len
);
6400 bcopy (SDATA (msg
), buffer
, len
);
6402 message_dolog (buffer
, len
- 1, 1, 0);
6409 /* Output a newline in the *Messages* buffer if "needs" one. */
6412 message_log_maybe_newline ()
6414 if (message_log_need_newline
)
6415 message_dolog ("", 0, 1, 0);
6419 /* Add a string M of length NBYTES to the message log, optionally
6420 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6421 nonzero, means interpret the contents of M as multibyte. This
6422 function calls low-level routines in order to bypass text property
6423 hooks, etc. which might not be safe to run. */
6426 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6428 int nbytes
, nlflag
, multibyte
;
6430 if (!NILP (Vmemory_full
))
6433 if (!NILP (Vmessage_log_max
))
6435 struct buffer
*oldbuf
;
6436 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6437 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6438 int point_at_end
= 0;
6440 Lisp_Object old_deactivate_mark
, tem
;
6441 struct gcpro gcpro1
;
6443 old_deactivate_mark
= Vdeactivate_mark
;
6444 oldbuf
= current_buffer
;
6445 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6446 current_buffer
->undo_list
= Qt
;
6448 oldpoint
= message_dolog_marker1
;
6449 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6450 oldbegv
= message_dolog_marker2
;
6451 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6452 oldzv
= message_dolog_marker3
;
6453 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6454 GCPRO1 (old_deactivate_mark
);
6462 BEGV_BYTE
= BEG_BYTE
;
6465 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6467 /* Insert the string--maybe converting multibyte to single byte
6468 or vice versa, so that all the text fits the buffer. */
6470 && NILP (current_buffer
->enable_multibyte_characters
))
6472 int i
, c
, char_bytes
;
6473 unsigned char work
[1];
6475 /* Convert a multibyte string to single-byte
6476 for the *Message* buffer. */
6477 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6479 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6480 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6482 : multibyte_char_to_unibyte (c
, Qnil
));
6483 insert_1_both (work
, 1, 1, 1, 0, 0);
6486 else if (! multibyte
6487 && ! NILP (current_buffer
->enable_multibyte_characters
))
6489 int i
, c
, char_bytes
;
6490 unsigned char *msg
= (unsigned char *) m
;
6491 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6492 /* Convert a single-byte string to multibyte
6493 for the *Message* buffer. */
6494 for (i
= 0; i
< nbytes
; i
++)
6496 c
= unibyte_char_to_multibyte (msg
[i
]);
6497 char_bytes
= CHAR_STRING (c
, str
);
6498 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6502 insert_1 (m
, nbytes
, 1, 0, 0);
6506 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6507 insert_1 ("\n", 1, 1, 0, 0);
6509 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6511 this_bol_byte
= PT_BYTE
;
6513 /* See if this line duplicates the previous one.
6514 If so, combine duplicates. */
6517 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6519 prev_bol_byte
= PT_BYTE
;
6521 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6522 this_bol
, this_bol_byte
);
6525 del_range_both (prev_bol
, prev_bol_byte
,
6526 this_bol
, this_bol_byte
, 0);
6532 /* If you change this format, don't forget to also
6533 change message_log_check_duplicate. */
6534 sprintf (dupstr
, " [%d times]", dup
);
6535 duplen
= strlen (dupstr
);
6536 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6537 insert_1 (dupstr
, duplen
, 1, 0, 1);
6542 /* If we have more than the desired maximum number of lines
6543 in the *Messages* buffer now, delete the oldest ones.
6544 This is safe because we don't have undo in this buffer. */
6546 if (NATNUMP (Vmessage_log_max
))
6548 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6549 -XFASTINT (Vmessage_log_max
) - 1, 0);
6550 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6553 BEGV
= XMARKER (oldbegv
)->charpos
;
6554 BEGV_BYTE
= marker_byte_position (oldbegv
);
6563 ZV
= XMARKER (oldzv
)->charpos
;
6564 ZV_BYTE
= marker_byte_position (oldzv
);
6568 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6570 /* We can't do Fgoto_char (oldpoint) because it will run some
6572 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6573 XMARKER (oldpoint
)->bytepos
);
6576 unchain_marker (XMARKER (oldpoint
));
6577 unchain_marker (XMARKER (oldbegv
));
6578 unchain_marker (XMARKER (oldzv
));
6580 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6581 set_buffer_internal (oldbuf
);
6583 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6584 message_log_need_newline
= !nlflag
;
6585 Vdeactivate_mark
= old_deactivate_mark
;
6590 /* We are at the end of the buffer after just having inserted a newline.
6591 (Note: We depend on the fact we won't be crossing the gap.)
6592 Check to see if the most recent message looks a lot like the previous one.
6593 Return 0 if different, 1 if the new one should just replace it, or a
6594 value N > 1 if we should also append " [N times]". */
6597 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6598 int prev_bol
, this_bol
;
6599 int prev_bol_byte
, this_bol_byte
;
6602 int len
= Z_BYTE
- 1 - this_bol_byte
;
6604 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6605 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6607 for (i
= 0; i
< len
; i
++)
6609 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6617 if (*p1
++ == ' ' && *p1
++ == '[')
6620 while (*p1
>= '0' && *p1
<= '9')
6621 n
= n
* 10 + *p1
++ - '0';
6622 if (strncmp (p1
, " times]\n", 8) == 0)
6629 /* Display an echo area message M with a specified length of NBYTES
6630 bytes. The string may include null characters. If M is 0, clear
6631 out any existing message, and let the mini-buffer text show
6634 The buffer M must continue to exist until after the echo area gets
6635 cleared or some other message gets displayed there. This means do
6636 not pass text that is stored in a Lisp string; do not pass text in
6637 a buffer that was alloca'd. */
6640 message2 (m
, nbytes
, multibyte
)
6645 /* First flush out any partial line written with print. */
6646 message_log_maybe_newline ();
6648 message_dolog (m
, nbytes
, 1, multibyte
);
6649 message2_nolog (m
, nbytes
, multibyte
);
6653 /* The non-logging counterpart of message2. */
6656 message2_nolog (m
, nbytes
, multibyte
)
6658 int nbytes
, multibyte
;
6660 struct frame
*sf
= SELECTED_FRAME ();
6661 message_enable_multibyte
= multibyte
;
6665 if (noninteractive_need_newline
)
6666 putc ('\n', stderr
);
6667 noninteractive_need_newline
= 0;
6669 fwrite (m
, nbytes
, 1, stderr
);
6670 if (cursor_in_echo_area
== 0)
6671 fprintf (stderr
, "\n");
6674 /* A null message buffer means that the frame hasn't really been
6675 initialized yet. Error messages get reported properly by
6676 cmd_error, so this must be just an informative message; toss it. */
6677 else if (INTERACTIVE
6678 && sf
->glyphs_initialized_p
6679 && FRAME_MESSAGE_BUF (sf
))
6681 Lisp_Object mini_window
;
6684 /* Get the frame containing the mini-buffer
6685 that the selected frame is using. */
6686 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6687 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6689 FRAME_SAMPLE_VISIBILITY (f
);
6690 if (FRAME_VISIBLE_P (sf
)
6691 && ! FRAME_VISIBLE_P (f
))
6692 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6696 set_message (m
, Qnil
, nbytes
, multibyte
);
6697 if (minibuffer_auto_raise
)
6698 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6701 clear_message (1, 1);
6703 do_pending_window_change (0);
6704 echo_area_display (1);
6705 do_pending_window_change (0);
6706 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6707 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6712 /* Display an echo area message M with a specified length of NBYTES
6713 bytes. The string may include null characters. If M is not a
6714 string, clear out any existing message, and let the mini-buffer
6715 text show through. */
6718 message3 (m
, nbytes
, multibyte
)
6723 struct gcpro gcpro1
;
6726 clear_message (1,1);
6728 /* First flush out any partial line written with print. */
6729 message_log_maybe_newline ();
6731 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6732 message3_nolog (m
, nbytes
, multibyte
);
6738 /* The non-logging version of message3. */
6741 message3_nolog (m
, nbytes
, multibyte
)
6743 int nbytes
, multibyte
;
6745 struct frame
*sf
= SELECTED_FRAME ();
6746 message_enable_multibyte
= multibyte
;
6750 if (noninteractive_need_newline
)
6751 putc ('\n', stderr
);
6752 noninteractive_need_newline
= 0;
6754 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6755 if (cursor_in_echo_area
== 0)
6756 fprintf (stderr
, "\n");
6759 /* A null message buffer means that the frame hasn't really been
6760 initialized yet. Error messages get reported properly by
6761 cmd_error, so this must be just an informative message; toss it. */
6762 else if (INTERACTIVE
6763 && sf
->glyphs_initialized_p
6764 && FRAME_MESSAGE_BUF (sf
))
6766 Lisp_Object mini_window
;
6770 /* Get the frame containing the mini-buffer
6771 that the selected frame is using. */
6772 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6773 frame
= XWINDOW (mini_window
)->frame
;
6776 FRAME_SAMPLE_VISIBILITY (f
);
6777 if (FRAME_VISIBLE_P (sf
)
6778 && !FRAME_VISIBLE_P (f
))
6779 Fmake_frame_visible (frame
);
6781 if (STRINGP (m
) && SCHARS (m
) > 0)
6783 set_message (NULL
, m
, nbytes
, multibyte
);
6784 if (minibuffer_auto_raise
)
6785 Fraise_frame (frame
);
6788 clear_message (1, 1);
6790 do_pending_window_change (0);
6791 echo_area_display (1);
6792 do_pending_window_change (0);
6793 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6794 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6799 /* Display a null-terminated echo area message M. If M is 0, clear
6800 out any existing message, and let the mini-buffer text show through.
6802 The buffer M must continue to exist until after the echo area gets
6803 cleared or some other message gets displayed there. Do not pass
6804 text that is stored in a Lisp string. Do not pass text in a buffer
6805 that was alloca'd. */
6811 message2 (m
, (m
? strlen (m
) : 0), 0);
6815 /* The non-logging counterpart of message1. */
6821 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6824 /* Display a message M which contains a single %s
6825 which gets replaced with STRING. */
6828 message_with_string (m
, string
, log
)
6833 CHECK_STRING (string
);
6839 if (noninteractive_need_newline
)
6840 putc ('\n', stderr
);
6841 noninteractive_need_newline
= 0;
6842 fprintf (stderr
, m
, SDATA (string
));
6843 if (cursor_in_echo_area
== 0)
6844 fprintf (stderr
, "\n");
6848 else if (INTERACTIVE
)
6850 /* The frame whose minibuffer we're going to display the message on.
6851 It may be larger than the selected frame, so we need
6852 to use its buffer, not the selected frame's buffer. */
6853 Lisp_Object mini_window
;
6854 struct frame
*f
, *sf
= SELECTED_FRAME ();
6856 /* Get the frame containing the minibuffer
6857 that the selected frame is using. */
6858 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6859 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6861 /* A null message buffer means that the frame hasn't really been
6862 initialized yet. Error messages get reported properly by
6863 cmd_error, so this must be just an informative message; toss it. */
6864 if (FRAME_MESSAGE_BUF (f
))
6866 Lisp_Object args
[2], message
;
6867 struct gcpro gcpro1
, gcpro2
;
6869 args
[0] = build_string (m
);
6870 args
[1] = message
= string
;
6871 GCPRO2 (args
[0], message
);
6874 message
= Fformat (2, args
);
6877 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6879 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6883 /* Print should start at the beginning of the message
6884 buffer next time. */
6885 message_buf_print
= 0;
6891 /* Dump an informative message to the minibuf. If M is 0, clear out
6892 any existing message, and let the mini-buffer text show through. */
6896 message (m
, a1
, a2
, a3
)
6898 EMACS_INT a1
, a2
, a3
;
6904 if (noninteractive_need_newline
)
6905 putc ('\n', stderr
);
6906 noninteractive_need_newline
= 0;
6907 fprintf (stderr
, m
, a1
, a2
, a3
);
6908 if (cursor_in_echo_area
== 0)
6909 fprintf (stderr
, "\n");
6913 else if (INTERACTIVE
)
6915 /* The frame whose mini-buffer we're going to display the message
6916 on. It may be larger than the selected frame, so we need to
6917 use its buffer, not the selected frame's buffer. */
6918 Lisp_Object mini_window
;
6919 struct frame
*f
, *sf
= SELECTED_FRAME ();
6921 /* Get the frame containing the mini-buffer
6922 that the selected frame is using. */
6923 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6924 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6926 /* A null message buffer means that the frame hasn't really been
6927 initialized yet. Error messages get reported properly by
6928 cmd_error, so this must be just an informative message; toss
6930 if (FRAME_MESSAGE_BUF (f
))
6941 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6942 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6944 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6945 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6947 #endif /* NO_ARG_ARRAY */
6949 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6954 /* Print should start at the beginning of the message
6955 buffer next time. */
6956 message_buf_print
= 0;
6962 /* The non-logging version of message. */
6965 message_nolog (m
, a1
, a2
, a3
)
6967 EMACS_INT a1
, a2
, a3
;
6969 Lisp_Object old_log_max
;
6970 old_log_max
= Vmessage_log_max
;
6971 Vmessage_log_max
= Qnil
;
6972 message (m
, a1
, a2
, a3
);
6973 Vmessage_log_max
= old_log_max
;
6977 /* Display the current message in the current mini-buffer. This is
6978 only called from error handlers in process.c, and is not time
6984 if (!NILP (echo_area_buffer
[0]))
6987 string
= Fcurrent_message ();
6988 message3 (string
, SBYTES (string
),
6989 !NILP (current_buffer
->enable_multibyte_characters
));
6994 /* Make sure echo area buffers in `echo_buffers' are live.
6995 If they aren't, make new ones. */
6998 ensure_echo_area_buffers ()
7002 for (i
= 0; i
< 2; ++i
)
7003 if (!BUFFERP (echo_buffer
[i
])
7004 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7007 Lisp_Object old_buffer
;
7010 old_buffer
= echo_buffer
[i
];
7011 sprintf (name
, " *Echo Area %d*", i
);
7012 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7013 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7015 for (j
= 0; j
< 2; ++j
)
7016 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7017 echo_area_buffer
[j
] = echo_buffer
[i
];
7022 /* Call FN with args A1..A4 with either the current or last displayed
7023 echo_area_buffer as current buffer.
7025 WHICH zero means use the current message buffer
7026 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7027 from echo_buffer[] and clear it.
7029 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7030 suitable buffer from echo_buffer[] and clear it.
7032 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7033 that the current message becomes the last displayed one, make
7034 choose a suitable buffer for echo_area_buffer[0], and clear it.
7036 Value is what FN returns. */
7039 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7042 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7048 int this_one
, the_other
, clear_buffer_p
, rc
;
7049 int count
= SPECPDL_INDEX ();
7051 /* If buffers aren't live, make new ones. */
7052 ensure_echo_area_buffers ();
7057 this_one
= 0, the_other
= 1;
7059 this_one
= 1, the_other
= 0;
7062 this_one
= 0, the_other
= 1;
7065 /* We need a fresh one in case the current echo buffer equals
7066 the one containing the last displayed echo area message. */
7067 if (!NILP (echo_area_buffer
[this_one
])
7068 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7069 echo_area_buffer
[this_one
] = Qnil
;
7072 /* Choose a suitable buffer from echo_buffer[] is we don't
7074 if (NILP (echo_area_buffer
[this_one
]))
7076 echo_area_buffer
[this_one
]
7077 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7078 ? echo_buffer
[the_other
]
7079 : echo_buffer
[this_one
]);
7083 buffer
= echo_area_buffer
[this_one
];
7085 /* Don't get confused by reusing the buffer used for echoing
7086 for a different purpose. */
7087 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7090 record_unwind_protect (unwind_with_echo_area_buffer
,
7091 with_echo_area_buffer_unwind_data (w
));
7093 /* Make the echo area buffer current. Note that for display
7094 purposes, it is not necessary that the displayed window's buffer
7095 == current_buffer, except for text property lookup. So, let's
7096 only set that buffer temporarily here without doing a full
7097 Fset_window_buffer. We must also change w->pointm, though,
7098 because otherwise an assertions in unshow_buffer fails, and Emacs
7100 set_buffer_internal_1 (XBUFFER (buffer
));
7104 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7107 current_buffer
->undo_list
= Qt
;
7108 current_buffer
->read_only
= Qnil
;
7109 specbind (Qinhibit_read_only
, Qt
);
7110 specbind (Qinhibit_modification_hooks
, Qt
);
7112 if (clear_buffer_p
&& Z
> BEG
)
7115 xassert (BEGV
>= BEG
);
7116 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7118 rc
= fn (a1
, a2
, a3
, a4
);
7120 xassert (BEGV
>= BEG
);
7121 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7123 unbind_to (count
, Qnil
);
7128 /* Save state that should be preserved around the call to the function
7129 FN called in with_echo_area_buffer. */
7132 with_echo_area_buffer_unwind_data (w
)
7138 /* Reduce consing by keeping one vector in
7139 Vwith_echo_area_save_vector. */
7140 vector
= Vwith_echo_area_save_vector
;
7141 Vwith_echo_area_save_vector
= Qnil
;
7144 vector
= Fmake_vector (make_number (7), Qnil
);
7146 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7147 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7148 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7152 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7153 AREF (vector
, i
) = w
->buffer
; ++i
;
7154 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7155 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7160 for (; i
< end
; ++i
)
7161 AREF (vector
, i
) = Qnil
;
7164 xassert (i
== ASIZE (vector
));
7169 /* Restore global state from VECTOR which was created by
7170 with_echo_area_buffer_unwind_data. */
7173 unwind_with_echo_area_buffer (vector
)
7176 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7177 Vdeactivate_mark
= AREF (vector
, 1);
7178 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7180 if (WINDOWP (AREF (vector
, 3)))
7183 Lisp_Object buffer
, charpos
, bytepos
;
7185 w
= XWINDOW (AREF (vector
, 3));
7186 buffer
= AREF (vector
, 4);
7187 charpos
= AREF (vector
, 5);
7188 bytepos
= AREF (vector
, 6);
7191 set_marker_both (w
->pointm
, buffer
,
7192 XFASTINT (charpos
), XFASTINT (bytepos
));
7195 Vwith_echo_area_save_vector
= vector
;
7200 /* Set up the echo area for use by print functions. MULTIBYTE_P
7201 non-zero means we will print multibyte. */
7204 setup_echo_area_for_printing (multibyte_p
)
7207 /* If we can't find an echo area any more, exit. */
7208 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7211 ensure_echo_area_buffers ();
7213 if (!message_buf_print
)
7215 /* A message has been output since the last time we printed.
7216 Choose a fresh echo area buffer. */
7217 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7218 echo_area_buffer
[0] = echo_buffer
[1];
7220 echo_area_buffer
[0] = echo_buffer
[0];
7222 /* Switch to that buffer and clear it. */
7223 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7224 current_buffer
->truncate_lines
= Qnil
;
7228 int count
= SPECPDL_INDEX ();
7229 specbind (Qinhibit_read_only
, Qt
);
7230 /* Note that undo recording is always disabled. */
7232 unbind_to (count
, Qnil
);
7234 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7236 /* Set up the buffer for the multibyteness we need. */
7238 != !NILP (current_buffer
->enable_multibyte_characters
))
7239 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7241 /* Raise the frame containing the echo area. */
7242 if (minibuffer_auto_raise
)
7244 struct frame
*sf
= SELECTED_FRAME ();
7245 Lisp_Object mini_window
;
7246 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7247 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7250 message_log_maybe_newline ();
7251 message_buf_print
= 1;
7255 if (NILP (echo_area_buffer
[0]))
7257 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7258 echo_area_buffer
[0] = echo_buffer
[1];
7260 echo_area_buffer
[0] = echo_buffer
[0];
7263 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7265 /* Someone switched buffers between print requests. */
7266 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7267 current_buffer
->truncate_lines
= Qnil
;
7273 /* Display an echo area message in window W. Value is non-zero if W's
7274 height is changed. If display_last_displayed_message_p is
7275 non-zero, display the message that was last displayed, otherwise
7276 display the current message. */
7279 display_echo_area (w
)
7282 int i
, no_message_p
, window_height_changed_p
, count
;
7284 /* Temporarily disable garbage collections while displaying the echo
7285 area. This is done because a GC can print a message itself.
7286 That message would modify the echo area buffer's contents while a
7287 redisplay of the buffer is going on, and seriously confuse
7289 count
= inhibit_garbage_collection ();
7291 /* If there is no message, we must call display_echo_area_1
7292 nevertheless because it resizes the window. But we will have to
7293 reset the echo_area_buffer in question to nil at the end because
7294 with_echo_area_buffer will sets it to an empty buffer. */
7295 i
= display_last_displayed_message_p
? 1 : 0;
7296 no_message_p
= NILP (echo_area_buffer
[i
]);
7298 window_height_changed_p
7299 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7300 display_echo_area_1
,
7301 (EMACS_INT
) w
, Qnil
, 0, 0);
7304 echo_area_buffer
[i
] = Qnil
;
7306 unbind_to (count
, Qnil
);
7307 return window_height_changed_p
;
7311 /* Helper for display_echo_area. Display the current buffer which
7312 contains the current echo area message in window W, a mini-window,
7313 a pointer to which is passed in A1. A2..A4 are currently not used.
7314 Change the height of W so that all of the message is displayed.
7315 Value is non-zero if height of W was changed. */
7318 display_echo_area_1 (a1
, a2
, a3
, a4
)
7323 struct window
*w
= (struct window
*) a1
;
7325 struct text_pos start
;
7326 int window_height_changed_p
= 0;
7328 /* Do this before displaying, so that we have a large enough glyph
7329 matrix for the display. */
7330 window_height_changed_p
= resize_mini_window (w
, 0);
7333 clear_glyph_matrix (w
->desired_matrix
);
7334 XSETWINDOW (window
, w
);
7335 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7336 try_window (window
, start
);
7338 return window_height_changed_p
;
7342 /* Resize the echo area window to exactly the size needed for the
7343 currently displayed message, if there is one. If a mini-buffer
7344 is active, don't shrink it. */
7347 resize_echo_area_exactly ()
7349 if (BUFFERP (echo_area_buffer
[0])
7350 && WINDOWP (echo_area_window
))
7352 struct window
*w
= XWINDOW (echo_area_window
);
7354 Lisp_Object resize_exactly
;
7356 if (minibuf_level
== 0)
7357 resize_exactly
= Qt
;
7359 resize_exactly
= Qnil
;
7361 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7362 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7365 ++windows_or_buffers_changed
;
7366 ++update_mode_lines
;
7367 redisplay_internal (0);
7373 /* Callback function for with_echo_area_buffer, when used from
7374 resize_echo_area_exactly. A1 contains a pointer to the window to
7375 resize, EXACTLY non-nil means resize the mini-window exactly to the
7376 size of the text displayed. A3 and A4 are not used. Value is what
7377 resize_mini_window returns. */
7380 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7382 Lisp_Object exactly
;
7385 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7389 /* Resize mini-window W to fit the size of its contents. EXACT:P
7390 means size the window exactly to the size needed. Otherwise, it's
7391 only enlarged until W's buffer is empty. Value is non-zero if
7392 the window height has been changed. */
7395 resize_mini_window (w
, exact_p
)
7399 struct frame
*f
= XFRAME (w
->frame
);
7400 int window_height_changed_p
= 0;
7402 xassert (MINI_WINDOW_P (w
));
7404 /* Don't resize windows while redisplaying a window; it would
7405 confuse redisplay functions when the size of the window they are
7406 displaying changes from under them. Such a resizing can happen,
7407 for instance, when which-func prints a long message while
7408 we are running fontification-functions. We're running these
7409 functions with safe_call which binds inhibit-redisplay to t. */
7410 if (!NILP (Vinhibit_redisplay
))
7413 /* Nil means don't try to resize. */
7414 if (NILP (Vresize_mini_windows
)
7415 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7418 if (!FRAME_MINIBUF_ONLY_P (f
))
7421 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7422 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7423 int height
, max_height
;
7424 int unit
= FRAME_LINE_HEIGHT (f
);
7425 struct text_pos start
;
7426 struct buffer
*old_current_buffer
= NULL
;
7428 if (current_buffer
!= XBUFFER (w
->buffer
))
7430 old_current_buffer
= current_buffer
;
7431 set_buffer_internal (XBUFFER (w
->buffer
));
7434 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7436 /* Compute the max. number of lines specified by the user. */
7437 if (FLOATP (Vmax_mini_window_height
))
7438 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7439 else if (INTEGERP (Vmax_mini_window_height
))
7440 max_height
= XINT (Vmax_mini_window_height
);
7442 max_height
= total_height
/ 4;
7444 /* Correct that max. height if it's bogus. */
7445 max_height
= max (1, max_height
);
7446 max_height
= min (total_height
, max_height
);
7448 /* Find out the height of the text in the window. */
7449 if (it
.truncate_lines_p
)
7454 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7455 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7456 height
= it
.current_y
+ last_height
;
7458 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7459 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7460 height
= (height
+ unit
- 1) / unit
;
7463 /* Compute a suitable window start. */
7464 if (height
> max_height
)
7466 height
= max_height
;
7467 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7468 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7469 start
= it
.current
.pos
;
7472 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7473 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7475 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7477 /* Let it grow only, until we display an empty message, in which
7478 case the window shrinks again. */
7479 if (height
> WINDOW_TOTAL_LINES (w
))
7481 int old_height
= WINDOW_TOTAL_LINES (w
);
7482 freeze_window_starts (f
, 1);
7483 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7484 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7486 else if (height
< WINDOW_TOTAL_LINES (w
)
7487 && (exact_p
|| BEGV
== ZV
))
7489 int old_height
= WINDOW_TOTAL_LINES (w
);
7490 freeze_window_starts (f
, 0);
7491 shrink_mini_window (w
);
7492 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7497 /* Always resize to exact size needed. */
7498 if (height
> WINDOW_TOTAL_LINES (w
))
7500 int old_height
= WINDOW_TOTAL_LINES (w
);
7501 freeze_window_starts (f
, 1);
7502 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7503 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7505 else if (height
< WINDOW_TOTAL_LINES (w
))
7507 int old_height
= WINDOW_TOTAL_LINES (w
);
7508 freeze_window_starts (f
, 0);
7509 shrink_mini_window (w
);
7513 freeze_window_starts (f
, 1);
7514 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7517 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7521 if (old_current_buffer
)
7522 set_buffer_internal (old_current_buffer
);
7525 return window_height_changed_p
;
7529 /* Value is the current message, a string, or nil if there is no
7537 if (NILP (echo_area_buffer
[0]))
7541 with_echo_area_buffer (0, 0, current_message_1
,
7542 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7544 echo_area_buffer
[0] = Qnil
;
7552 current_message_1 (a1
, a2
, a3
, a4
)
7557 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7560 *msg
= make_buffer_string (BEG
, Z
, 1);
7567 /* Push the current message on Vmessage_stack for later restauration
7568 by restore_message. Value is non-zero if the current message isn't
7569 empty. This is a relatively infrequent operation, so it's not
7570 worth optimizing. */
7576 msg
= current_message ();
7577 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7578 return STRINGP (msg
);
7582 /* Restore message display from the top of Vmessage_stack. */
7589 xassert (CONSP (Vmessage_stack
));
7590 msg
= XCAR (Vmessage_stack
);
7592 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7594 message3_nolog (msg
, 0, 0);
7598 /* Handler for record_unwind_protect calling pop_message. */
7601 pop_message_unwind (dummy
)
7608 /* Pop the top-most entry off Vmessage_stack. */
7613 xassert (CONSP (Vmessage_stack
));
7614 Vmessage_stack
= XCDR (Vmessage_stack
);
7618 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7619 exits. If the stack is not empty, we have a missing pop_message
7623 check_message_stack ()
7625 if (!NILP (Vmessage_stack
))
7630 /* Truncate to NCHARS what will be displayed in the echo area the next
7631 time we display it---but don't redisplay it now. */
7634 truncate_echo_area (nchars
)
7638 echo_area_buffer
[0] = Qnil
;
7639 /* A null message buffer means that the frame hasn't really been
7640 initialized yet. Error messages get reported properly by
7641 cmd_error, so this must be just an informative message; toss it. */
7642 else if (!noninteractive
7644 && !NILP (echo_area_buffer
[0]))
7646 struct frame
*sf
= SELECTED_FRAME ();
7647 if (FRAME_MESSAGE_BUF (sf
))
7648 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7653 /* Helper function for truncate_echo_area. Truncate the current
7654 message to at most NCHARS characters. */
7657 truncate_message_1 (nchars
, a2
, a3
, a4
)
7662 if (BEG
+ nchars
< Z
)
7663 del_range (BEG
+ nchars
, Z
);
7665 echo_area_buffer
[0] = Qnil
;
7670 /* Set the current message to a substring of S or STRING.
7672 If STRING is a Lisp string, set the message to the first NBYTES
7673 bytes from STRING. NBYTES zero means use the whole string. If
7674 STRING is multibyte, the message will be displayed multibyte.
7676 If S is not null, set the message to the first LEN bytes of S. LEN
7677 zero means use the whole string. MULTIBYTE_P non-zero means S is
7678 multibyte. Display the message multibyte in that case. */
7681 set_message (s
, string
, nbytes
, multibyte_p
)
7684 int nbytes
, multibyte_p
;
7686 message_enable_multibyte
7687 = ((s
&& multibyte_p
)
7688 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7690 with_echo_area_buffer (0, -1, set_message_1
,
7691 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7692 message_buf_print
= 0;
7693 help_echo_showing_p
= 0;
7697 /* Helper function for set_message. Arguments have the same meaning
7698 as there, with A1 corresponding to S and A2 corresponding to STRING
7699 This function is called with the echo area buffer being
7703 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7706 EMACS_INT nbytes
, multibyte_p
;
7708 const char *s
= (const char *) a1
;
7709 Lisp_Object string
= a2
;
7713 /* Change multibyteness of the echo buffer appropriately. */
7714 if (message_enable_multibyte
7715 != !NILP (current_buffer
->enable_multibyte_characters
))
7716 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7718 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7720 /* Insert new message at BEG. */
7721 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7723 if (STRINGP (string
))
7728 nbytes
= SBYTES (string
);
7729 nchars
= string_byte_to_char (string
, nbytes
);
7731 /* This function takes care of single/multibyte conversion. We
7732 just have to ensure that the echo area buffer has the right
7733 setting of enable_multibyte_characters. */
7734 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7739 nbytes
= strlen (s
);
7741 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7743 /* Convert from multi-byte to single-byte. */
7745 unsigned char work
[1];
7747 /* Convert a multibyte string to single-byte. */
7748 for (i
= 0; i
< nbytes
; i
+= n
)
7750 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7751 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7753 : multibyte_char_to_unibyte (c
, Qnil
));
7754 insert_1_both (work
, 1, 1, 1, 0, 0);
7757 else if (!multibyte_p
7758 && !NILP (current_buffer
->enable_multibyte_characters
))
7760 /* Convert from single-byte to multi-byte. */
7762 const unsigned char *msg
= (const unsigned char *) s
;
7763 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7765 /* Convert a single-byte string to multibyte. */
7766 for (i
= 0; i
< nbytes
; i
++)
7768 c
= unibyte_char_to_multibyte (msg
[i
]);
7769 n
= CHAR_STRING (c
, str
);
7770 insert_1_both (str
, 1, n
, 1, 0, 0);
7774 insert_1 (s
, nbytes
, 1, 0, 0);
7781 /* Clear messages. CURRENT_P non-zero means clear the current
7782 message. LAST_DISPLAYED_P non-zero means clear the message
7786 clear_message (current_p
, last_displayed_p
)
7787 int current_p
, last_displayed_p
;
7791 echo_area_buffer
[0] = Qnil
;
7792 message_cleared_p
= 1;
7795 if (last_displayed_p
)
7796 echo_area_buffer
[1] = Qnil
;
7798 message_buf_print
= 0;
7801 /* Clear garbaged frames.
7803 This function is used where the old redisplay called
7804 redraw_garbaged_frames which in turn called redraw_frame which in
7805 turn called clear_frame. The call to clear_frame was a source of
7806 flickering. I believe a clear_frame is not necessary. It should
7807 suffice in the new redisplay to invalidate all current matrices,
7808 and ensure a complete redisplay of all windows. */
7811 clear_garbaged_frames ()
7815 Lisp_Object tail
, frame
;
7816 int changed_count
= 0;
7818 FOR_EACH_FRAME (tail
, frame
)
7820 struct frame
*f
= XFRAME (frame
);
7822 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7826 Fredraw_frame (frame
);
7827 f
->force_flush_display_p
= 1;
7829 clear_current_matrices (f
);
7838 ++windows_or_buffers_changed
;
7843 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7844 is non-zero update selected_frame. Value is non-zero if the
7845 mini-windows height has been changed. */
7848 echo_area_display (update_frame_p
)
7851 Lisp_Object mini_window
;
7854 int window_height_changed_p
= 0;
7855 struct frame
*sf
= SELECTED_FRAME ();
7857 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7858 w
= XWINDOW (mini_window
);
7859 f
= XFRAME (WINDOW_FRAME (w
));
7861 /* Don't display if frame is invisible or not yet initialized. */
7862 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7865 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7867 #ifdef HAVE_WINDOW_SYSTEM
7868 /* When Emacs starts, selected_frame may be the initial terminal
7869 frame. If we let this through, a message would be displayed on
7871 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
7873 #endif /* HAVE_WINDOW_SYSTEM */
7876 /* Redraw garbaged frames. */
7878 clear_garbaged_frames ();
7880 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7882 echo_area_window
= mini_window
;
7883 window_height_changed_p
= display_echo_area (w
);
7884 w
->must_be_updated_p
= 1;
7886 /* Update the display, unless called from redisplay_internal.
7887 Also don't update the screen during redisplay itself. The
7888 update will happen at the end of redisplay, and an update
7889 here could cause confusion. */
7890 if (update_frame_p
&& !redisplaying_p
)
7894 /* If the display update has been interrupted by pending
7895 input, update mode lines in the frame. Due to the
7896 pending input, it might have been that redisplay hasn't
7897 been called, so that mode lines above the echo area are
7898 garbaged. This looks odd, so we prevent it here. */
7899 if (!display_completed
)
7900 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7902 if (window_height_changed_p
7903 /* Don't do this if Emacs is shutting down. Redisplay
7904 needs to run hooks. */
7905 && !NILP (Vrun_hooks
))
7907 /* Must update other windows. Likewise as in other
7908 cases, don't let this update be interrupted by
7910 int count
= SPECPDL_INDEX ();
7911 specbind (Qredisplay_dont_pause
, Qt
);
7912 windows_or_buffers_changed
= 1;
7913 redisplay_internal (0);
7914 unbind_to (count
, Qnil
);
7916 else if (FRAME_WINDOW_P (f
) && n
== 0)
7918 /* Window configuration is the same as before.
7919 Can do with a display update of the echo area,
7920 unless we displayed some mode lines. */
7921 update_single_window (w
, 1);
7922 FRAME_RIF (f
)->flush_display (f
);
7925 update_frame (f
, 1, 1);
7927 /* If cursor is in the echo area, make sure that the next
7928 redisplay displays the minibuffer, so that the cursor will
7929 be replaced with what the minibuffer wants. */
7930 if (cursor_in_echo_area
)
7931 ++windows_or_buffers_changed
;
7934 else if (!EQ (mini_window
, selected_window
))
7935 windows_or_buffers_changed
++;
7937 /* Last displayed message is now the current message. */
7938 echo_area_buffer
[1] = echo_area_buffer
[0];
7940 /* Prevent redisplay optimization in redisplay_internal by resetting
7941 this_line_start_pos. This is done because the mini-buffer now
7942 displays the message instead of its buffer text. */
7943 if (EQ (mini_window
, selected_window
))
7944 CHARPOS (this_line_start_pos
) = 0;
7946 return window_height_changed_p
;
7951 /***********************************************************************
7953 ***********************************************************************/
7956 /* The frame title buffering code is also used by Fformat_mode_line.
7957 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7959 /* A buffer for constructing frame titles in it; allocated from the
7960 heap in init_xdisp and resized as needed in store_frame_title_char. */
7962 static char *frame_title_buf
;
7964 /* The buffer's end, and a current output position in it. */
7966 static char *frame_title_buf_end
;
7967 static char *frame_title_ptr
;
7970 /* Store a single character C for the frame title in frame_title_buf.
7971 Re-allocate frame_title_buf if necessary. */
7975 store_frame_title_char (char c
)
7977 store_frame_title_char (c
)
7981 /* If output position has reached the end of the allocated buffer,
7982 double the buffer's size. */
7983 if (frame_title_ptr
== frame_title_buf_end
)
7985 int len
= frame_title_ptr
- frame_title_buf
;
7986 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7987 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7988 frame_title_buf_end
= frame_title_buf
+ new_size
;
7989 frame_title_ptr
= frame_title_buf
+ len
;
7992 *frame_title_ptr
++ = c
;
7996 /* Store part of a frame title in frame_title_buf, beginning at
7997 frame_title_ptr. STR is the string to store. Do not copy
7998 characters that yield more columns than PRECISION; PRECISION <= 0
7999 means copy the whole string. Pad with spaces until FIELD_WIDTH
8000 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8001 pad. Called from display_mode_element when it is used to build a
8005 store_frame_title (str
, field_width
, precision
)
8006 const unsigned char *str
;
8007 int field_width
, precision
;
8012 /* Copy at most PRECISION chars from STR. */
8013 nbytes
= strlen (str
);
8014 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8016 store_frame_title_char (*str
++);
8018 /* Fill up with spaces until FIELD_WIDTH reached. */
8019 while (field_width
> 0
8022 store_frame_title_char (' ');
8029 #ifdef HAVE_WINDOW_SYSTEM
8031 /* Set the title of FRAME, if it has changed. The title format is
8032 Vicon_title_format if FRAME is iconified, otherwise it is
8033 frame_title_format. */
8036 x_consider_frame_title (frame
)
8039 struct frame
*f
= XFRAME (frame
);
8041 if (FRAME_WINDOW_P (f
)
8042 || FRAME_MINIBUF_ONLY_P (f
)
8043 || f
->explicit_name
)
8045 /* Do we have more than one visible frame on this X display? */
8048 struct buffer
*obuf
;
8052 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8054 Lisp_Object other_frame
= XCAR (tail
);
8055 struct frame
*tf
= XFRAME (other_frame
);
8058 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8059 && !FRAME_MINIBUF_ONLY_P (tf
)
8060 && !EQ (other_frame
, tip_frame
)
8061 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8065 /* Set global variable indicating that multiple frames exist. */
8066 multiple_frames
= CONSP (tail
);
8068 /* Switch to the buffer of selected window of the frame. Set up
8069 frame_title_ptr so that display_mode_element will output into it;
8070 then display the title. */
8071 obuf
= current_buffer
;
8072 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8073 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8074 frame_title_ptr
= frame_title_buf
;
8075 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8076 NULL
, DEFAULT_FACE_ID
);
8077 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8078 len
= frame_title_ptr
- frame_title_buf
;
8079 frame_title_ptr
= NULL
;
8080 set_buffer_internal_1 (obuf
);
8082 /* Set the title only if it's changed. This avoids consing in
8083 the common case where it hasn't. (If it turns out that we've
8084 already wasted too much time by walking through the list with
8085 display_mode_element, then we might need to optimize at a
8086 higher level than this.) */
8087 if (! STRINGP (f
->name
)
8088 || SBYTES (f
->name
) != len
8089 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8090 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8094 #endif /* not HAVE_WINDOW_SYSTEM */
8099 /***********************************************************************
8101 ***********************************************************************/
8104 /* Prepare for redisplay by updating menu-bar item lists when
8105 appropriate. This can call eval. */
8108 prepare_menu_bars ()
8111 struct gcpro gcpro1
, gcpro2
;
8113 Lisp_Object tooltip_frame
;
8115 #ifdef HAVE_WINDOW_SYSTEM
8116 tooltip_frame
= tip_frame
;
8118 tooltip_frame
= Qnil
;
8121 /* Update all frame titles based on their buffer names, etc. We do
8122 this before the menu bars so that the buffer-menu will show the
8123 up-to-date frame titles. */
8124 #ifdef HAVE_WINDOW_SYSTEM
8125 if (windows_or_buffers_changed
|| update_mode_lines
)
8127 Lisp_Object tail
, frame
;
8129 FOR_EACH_FRAME (tail
, frame
)
8132 if (!EQ (frame
, tooltip_frame
)
8133 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8134 x_consider_frame_title (frame
);
8137 #endif /* HAVE_WINDOW_SYSTEM */
8139 /* Update the menu bar item lists, if appropriate. This has to be
8140 done before any actual redisplay or generation of display lines. */
8141 all_windows
= (update_mode_lines
8142 || buffer_shared
> 1
8143 || windows_or_buffers_changed
);
8146 Lisp_Object tail
, frame
;
8147 int count
= SPECPDL_INDEX ();
8149 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8151 FOR_EACH_FRAME (tail
, frame
)
8155 /* Ignore tooltip frame. */
8156 if (EQ (frame
, tooltip_frame
))
8159 /* If a window on this frame changed size, report that to
8160 the user and clear the size-change flag. */
8161 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8163 Lisp_Object functions
;
8165 /* Clear flag first in case we get an error below. */
8166 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8167 functions
= Vwindow_size_change_functions
;
8168 GCPRO2 (tail
, functions
);
8170 while (CONSP (functions
))
8172 call1 (XCAR (functions
), frame
);
8173 functions
= XCDR (functions
);
8179 update_menu_bar (f
, 0);
8180 #ifdef HAVE_WINDOW_SYSTEM
8181 update_tool_bar (f
, 0);
8186 unbind_to (count
, Qnil
);
8190 struct frame
*sf
= SELECTED_FRAME ();
8191 update_menu_bar (sf
, 1);
8192 #ifdef HAVE_WINDOW_SYSTEM
8193 update_tool_bar (sf
, 1);
8197 /* Motif needs this. See comment in xmenu.c. Turn it off when
8198 pending_menu_activation is not defined. */
8199 #ifdef USE_X_TOOLKIT
8200 pending_menu_activation
= 0;
8205 /* Update the menu bar item list for frame F. This has to be done
8206 before we start to fill in any display lines, because it can call
8209 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8212 update_menu_bar (f
, save_match_data
)
8214 int save_match_data
;
8217 register struct window
*w
;
8219 /* If called recursively during a menu update, do nothing. This can
8220 happen when, for instance, an activate-menubar-hook causes a
8222 if (inhibit_menubar_update
)
8225 window
= FRAME_SELECTED_WINDOW (f
);
8226 w
= XWINDOW (window
);
8228 #if 0 /* The if statement below this if statement used to include the
8229 condition !NILP (w->update_mode_line), rather than using
8230 update_mode_lines directly, and this if statement may have
8231 been added to make that condition work. Now the if
8232 statement below matches its comment, this isn't needed. */
8233 if (update_mode_lines
)
8234 w
->update_mode_line
= Qt
;
8237 if (FRAME_WINDOW_P (f
)
8239 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8240 || defined (USE_GTK)
8241 FRAME_EXTERNAL_MENU_BAR (f
)
8243 FRAME_MENU_BAR_LINES (f
) > 0
8245 : FRAME_MENU_BAR_LINES (f
) > 0)
8247 /* If the user has switched buffers or windows, we need to
8248 recompute to reflect the new bindings. But we'll
8249 recompute when update_mode_lines is set too; that means
8250 that people can use force-mode-line-update to request
8251 that the menu bar be recomputed. The adverse effect on
8252 the rest of the redisplay algorithm is about the same as
8253 windows_or_buffers_changed anyway. */
8254 if (windows_or_buffers_changed
8255 /* This used to test w->update_mode_line, but we believe
8256 there is no need to recompute the menu in that case. */
8257 || update_mode_lines
8258 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8259 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8260 != !NILP (w
->last_had_star
))
8261 || ((!NILP (Vtransient_mark_mode
)
8262 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8263 != !NILP (w
->region_showing
)))
8265 struct buffer
*prev
= current_buffer
;
8266 int count
= SPECPDL_INDEX ();
8268 specbind (Qinhibit_menubar_update
, Qt
);
8270 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8271 if (save_match_data
)
8272 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8273 if (NILP (Voverriding_local_map_menu_flag
))
8275 specbind (Qoverriding_terminal_local_map
, Qnil
);
8276 specbind (Qoverriding_local_map
, Qnil
);
8279 /* Run the Lucid hook. */
8280 safe_run_hooks (Qactivate_menubar_hook
);
8282 /* If it has changed current-menubar from previous value,
8283 really recompute the menu-bar from the value. */
8284 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8285 call0 (Qrecompute_lucid_menubar
);
8287 safe_run_hooks (Qmenu_bar_update_hook
);
8288 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8290 /* Redisplay the menu bar in case we changed it. */
8291 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8292 || defined (USE_GTK)
8293 if (FRAME_WINDOW_P (f
)
8294 #if defined (MAC_OS)
8295 /* All frames on Mac OS share the same menubar. So only the
8296 selected frame should be allowed to set it. */
8297 && f
== SELECTED_FRAME ()
8300 set_frame_menubar (f
, 0, 0);
8302 /* On a terminal screen, the menu bar is an ordinary screen
8303 line, and this makes it get updated. */
8304 w
->update_mode_line
= Qt
;
8305 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8306 /* In the non-toolkit version, the menu bar is an ordinary screen
8307 line, and this makes it get updated. */
8308 w
->update_mode_line
= Qt
;
8309 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8311 unbind_to (count
, Qnil
);
8312 set_buffer_internal_1 (prev
);
8319 /***********************************************************************
8321 ***********************************************************************/
8323 #ifdef HAVE_WINDOW_SYSTEM
8326 Nominal cursor position -- where to draw output.
8327 HPOS and VPOS are window relative glyph matrix coordinates.
8328 X and Y are window relative pixel coordinates. */
8330 struct cursor_pos output_cursor
;
8334 Set the global variable output_cursor to CURSOR. All cursor
8335 positions are relative to updated_window. */
8338 set_output_cursor (cursor
)
8339 struct cursor_pos
*cursor
;
8341 output_cursor
.hpos
= cursor
->hpos
;
8342 output_cursor
.vpos
= cursor
->vpos
;
8343 output_cursor
.x
= cursor
->x
;
8344 output_cursor
.y
= cursor
->y
;
8349 Set a nominal cursor position.
8351 HPOS and VPOS are column/row positions in a window glyph matrix. X
8352 and Y are window text area relative pixel positions.
8354 If this is done during an update, updated_window will contain the
8355 window that is being updated and the position is the future output
8356 cursor position for that window. If updated_window is null, use
8357 selected_window and display the cursor at the given position. */
8360 x_cursor_to (vpos
, hpos
, y
, x
)
8361 int vpos
, hpos
, y
, x
;
8365 /* If updated_window is not set, work on selected_window. */
8369 w
= XWINDOW (selected_window
);
8371 /* Set the output cursor. */
8372 output_cursor
.hpos
= hpos
;
8373 output_cursor
.vpos
= vpos
;
8374 output_cursor
.x
= x
;
8375 output_cursor
.y
= y
;
8377 /* If not called as part of an update, really display the cursor.
8378 This will also set the cursor position of W. */
8379 if (updated_window
== NULL
)
8382 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8383 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
8384 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
8389 #endif /* HAVE_WINDOW_SYSTEM */
8392 /***********************************************************************
8394 ***********************************************************************/
8396 #ifdef HAVE_WINDOW_SYSTEM
8398 /* Where the mouse was last time we reported a mouse event. */
8400 FRAME_PTR last_mouse_frame
;
8402 /* Tool-bar item index of the item on which a mouse button was pressed
8405 int last_tool_bar_item
;
8408 /* Update the tool-bar item list for frame F. This has to be done
8409 before we start to fill in any display lines. Called from
8410 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8411 and restore it here. */
8414 update_tool_bar (f
, save_match_data
)
8416 int save_match_data
;
8419 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8421 int do_update
= WINDOWP (f
->tool_bar_window
)
8422 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8430 window
= FRAME_SELECTED_WINDOW (f
);
8431 w
= XWINDOW (window
);
8433 /* If the user has switched buffers or windows, we need to
8434 recompute to reflect the new bindings. But we'll
8435 recompute when update_mode_lines is set too; that means
8436 that people can use force-mode-line-update to request
8437 that the menu bar be recomputed. The adverse effect on
8438 the rest of the redisplay algorithm is about the same as
8439 windows_or_buffers_changed anyway. */
8440 if (windows_or_buffers_changed
8441 || !NILP (w
->update_mode_line
)
8442 || update_mode_lines
8443 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8444 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8445 != !NILP (w
->last_had_star
))
8446 || ((!NILP (Vtransient_mark_mode
)
8447 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8448 != !NILP (w
->region_showing
)))
8450 struct buffer
*prev
= current_buffer
;
8451 int count
= SPECPDL_INDEX ();
8452 Lisp_Object new_tool_bar
;
8454 struct gcpro gcpro1
;
8456 /* Set current_buffer to the buffer of the selected
8457 window of the frame, so that we get the right local
8459 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8461 /* Save match data, if we must. */
8462 if (save_match_data
)
8463 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8465 /* Make sure that we don't accidentally use bogus keymaps. */
8466 if (NILP (Voverriding_local_map_menu_flag
))
8468 specbind (Qoverriding_terminal_local_map
, Qnil
);
8469 specbind (Qoverriding_local_map
, Qnil
);
8472 GCPRO1 (new_tool_bar
);
8474 /* Build desired tool-bar items from keymaps. */
8475 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8478 /* Redisplay the tool-bar if we changed it. */
8479 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8481 /* Redisplay that happens asynchronously due to an expose event
8482 may access f->tool_bar_items. Make sure we update both
8483 variables within BLOCK_INPUT so no such event interrupts. */
8485 f
->tool_bar_items
= new_tool_bar
;
8486 f
->n_tool_bar_items
= new_n_tool_bar
;
8487 w
->update_mode_line
= Qt
;
8493 unbind_to (count
, Qnil
);
8494 set_buffer_internal_1 (prev
);
8500 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8501 F's desired tool-bar contents. F->tool_bar_items must have
8502 been set up previously by calling prepare_menu_bars. */
8505 build_desired_tool_bar_string (f
)
8508 int i
, size
, size_needed
;
8509 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8510 Lisp_Object image
, plist
, props
;
8512 image
= plist
= props
= Qnil
;
8513 GCPRO3 (image
, plist
, props
);
8515 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8516 Otherwise, make a new string. */
8518 /* The size of the string we might be able to reuse. */
8519 size
= (STRINGP (f
->desired_tool_bar_string
)
8520 ? SCHARS (f
->desired_tool_bar_string
)
8523 /* We need one space in the string for each image. */
8524 size_needed
= f
->n_tool_bar_items
;
8526 /* Reuse f->desired_tool_bar_string, if possible. */
8527 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8528 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8532 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8533 Fremove_text_properties (make_number (0), make_number (size
),
8534 props
, f
->desired_tool_bar_string
);
8537 /* Put a `display' property on the string for the images to display,
8538 put a `menu_item' property on tool-bar items with a value that
8539 is the index of the item in F's tool-bar item vector. */
8540 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8542 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8544 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8545 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8546 int hmargin
, vmargin
, relief
, idx
, end
;
8547 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8549 /* If image is a vector, choose the image according to the
8551 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8552 if (VECTORP (image
))
8556 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8557 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8560 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8561 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8563 xassert (ASIZE (image
) >= idx
);
8564 image
= AREF (image
, idx
);
8569 /* Ignore invalid image specifications. */
8570 if (!valid_image_p (image
))
8573 /* Display the tool-bar button pressed, or depressed. */
8574 plist
= Fcopy_sequence (XCDR (image
));
8576 /* Compute margin and relief to draw. */
8577 relief
= (tool_bar_button_relief
>= 0
8578 ? tool_bar_button_relief
8579 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8580 hmargin
= vmargin
= relief
;
8582 if (INTEGERP (Vtool_bar_button_margin
)
8583 && XINT (Vtool_bar_button_margin
) > 0)
8585 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8586 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8588 else if (CONSP (Vtool_bar_button_margin
))
8590 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8591 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8592 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8594 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8595 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8596 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8599 if (auto_raise_tool_bar_buttons_p
)
8601 /* Add a `:relief' property to the image spec if the item is
8605 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8612 /* If image is selected, display it pressed, i.e. with a
8613 negative relief. If it's not selected, display it with a
8615 plist
= Fplist_put (plist
, QCrelief
,
8617 ? make_number (-relief
)
8618 : make_number (relief
)));
8623 /* Put a margin around the image. */
8624 if (hmargin
|| vmargin
)
8626 if (hmargin
== vmargin
)
8627 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8629 plist
= Fplist_put (plist
, QCmargin
,
8630 Fcons (make_number (hmargin
),
8631 make_number (vmargin
)));
8634 /* If button is not enabled, and we don't have special images
8635 for the disabled state, make the image appear disabled by
8636 applying an appropriate algorithm to it. */
8637 if (!enabled_p
&& idx
< 0)
8638 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8640 /* Put a `display' text property on the string for the image to
8641 display. Put a `menu-item' property on the string that gives
8642 the start of this item's properties in the tool-bar items
8644 image
= Fcons (Qimage
, plist
);
8645 props
= list4 (Qdisplay
, image
,
8646 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8648 /* Let the last image hide all remaining spaces in the tool bar
8649 string. The string can be longer than needed when we reuse a
8651 if (i
+ 1 == f
->n_tool_bar_items
)
8652 end
= SCHARS (f
->desired_tool_bar_string
);
8655 Fadd_text_properties (make_number (i
), make_number (end
),
8656 props
, f
->desired_tool_bar_string
);
8664 /* Display one line of the tool-bar of frame IT->f. */
8667 display_tool_bar_line (it
)
8670 struct glyph_row
*row
= it
->glyph_row
;
8671 int max_x
= it
->last_visible_x
;
8674 prepare_desired_row (row
);
8675 row
->y
= it
->current_y
;
8677 /* Note that this isn't made use of if the face hasn't a box,
8678 so there's no need to check the face here. */
8679 it
->start_of_box_run_p
= 1;
8681 while (it
->current_x
< max_x
)
8683 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8685 /* Get the next display element. */
8686 if (!get_next_display_element (it
))
8689 /* Produce glyphs. */
8690 x_before
= it
->current_x
;
8691 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8692 PRODUCE_GLYPHS (it
);
8694 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8699 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8701 if (x
+ glyph
->pixel_width
> max_x
)
8703 /* Glyph doesn't fit on line. */
8704 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8710 x
+= glyph
->pixel_width
;
8714 /* Stop at line ends. */
8715 if (ITERATOR_AT_END_OF_LINE_P (it
))
8718 set_iterator_to_next (it
, 1);
8723 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8724 extend_face_to_end_of_line (it
);
8725 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8726 last
->right_box_line_p
= 1;
8727 if (last
== row
->glyphs
[TEXT_AREA
])
8728 last
->left_box_line_p
= 1;
8729 compute_line_metrics (it
);
8731 /* If line is empty, make it occupy the rest of the tool-bar. */
8732 if (!row
->displays_text_p
)
8734 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8735 row
->ascent
= row
->phys_ascent
= 0;
8736 row
->extra_line_spacing
= 0;
8739 row
->full_width_p
= 1;
8740 row
->continued_p
= 0;
8741 row
->truncated_on_left_p
= 0;
8742 row
->truncated_on_right_p
= 0;
8744 it
->current_x
= it
->hpos
= 0;
8745 it
->current_y
+= row
->height
;
8751 /* Value is the number of screen lines needed to make all tool-bar
8752 items of frame F visible. */
8755 tool_bar_lines_needed (f
)
8758 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8761 /* Initialize an iterator for iteration over
8762 F->desired_tool_bar_string in the tool-bar window of frame F. */
8763 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8764 it
.first_visible_x
= 0;
8765 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8766 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8768 while (!ITERATOR_AT_END_P (&it
))
8770 it
.glyph_row
= w
->desired_matrix
->rows
;
8771 clear_glyph_row (it
.glyph_row
);
8772 display_tool_bar_line (&it
);
8775 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8779 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8781 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8790 frame
= selected_frame
;
8792 CHECK_FRAME (frame
);
8795 if (WINDOWP (f
->tool_bar_window
)
8796 || (w
= XWINDOW (f
->tool_bar_window
),
8797 WINDOW_TOTAL_LINES (w
) > 0))
8799 update_tool_bar (f
, 1);
8800 if (f
->n_tool_bar_items
)
8802 build_desired_tool_bar_string (f
);
8803 nlines
= tool_bar_lines_needed (f
);
8807 return make_number (nlines
);
8811 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8812 height should be changed. */
8815 redisplay_tool_bar (f
)
8820 struct glyph_row
*row
;
8821 int change_height_p
= 0;
8824 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8825 update_frame_tool_bar (f
);
8829 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8830 do anything. This means you must start with tool-bar-lines
8831 non-zero to get the auto-sizing effect. Or in other words, you
8832 can turn off tool-bars by specifying tool-bar-lines zero. */
8833 if (!WINDOWP (f
->tool_bar_window
)
8834 || (w
= XWINDOW (f
->tool_bar_window
),
8835 WINDOW_TOTAL_LINES (w
) == 0))
8838 /* Set up an iterator for the tool-bar window. */
8839 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8840 it
.first_visible_x
= 0;
8841 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8844 /* Build a string that represents the contents of the tool-bar. */
8845 build_desired_tool_bar_string (f
);
8846 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8848 /* Display as many lines as needed to display all tool-bar items. */
8849 while (it
.current_y
< it
.last_visible_y
)
8850 display_tool_bar_line (&it
);
8852 /* It doesn't make much sense to try scrolling in the tool-bar
8853 window, so don't do it. */
8854 w
->desired_matrix
->no_scrolling_p
= 1;
8855 w
->must_be_updated_p
= 1;
8857 if (auto_resize_tool_bars_p
)
8861 /* If we couldn't display everything, change the tool-bar's
8863 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8864 change_height_p
= 1;
8866 /* If there are blank lines at the end, except for a partially
8867 visible blank line at the end that is smaller than
8868 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8869 row
= it
.glyph_row
- 1;
8870 if (!row
->displays_text_p
8871 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8872 change_height_p
= 1;
8874 /* If row displays tool-bar items, but is partially visible,
8875 change the tool-bar's height. */
8876 if (row
->displays_text_p
8877 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8878 change_height_p
= 1;
8880 /* Resize windows as needed by changing the `tool-bar-lines'
8883 && (nlines
= tool_bar_lines_needed (f
),
8884 nlines
!= WINDOW_TOTAL_LINES (w
)))
8886 extern Lisp_Object Qtool_bar_lines
;
8888 int old_height
= WINDOW_TOTAL_LINES (w
);
8890 XSETFRAME (frame
, f
);
8891 clear_glyph_matrix (w
->desired_matrix
);
8892 Fmodify_frame_parameters (frame
,
8893 Fcons (Fcons (Qtool_bar_lines
,
8894 make_number (nlines
)),
8896 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8897 fonts_changed_p
= 1;
8901 return change_height_p
;
8905 /* Get information about the tool-bar item which is displayed in GLYPH
8906 on frame F. Return in *PROP_IDX the index where tool-bar item
8907 properties start in F->tool_bar_items. Value is zero if
8908 GLYPH doesn't display a tool-bar item. */
8911 tool_bar_item_info (f
, glyph
, prop_idx
)
8913 struct glyph
*glyph
;
8920 /* This function can be called asynchronously, which means we must
8921 exclude any possibility that Fget_text_property signals an
8923 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8924 charpos
= max (0, charpos
);
8926 /* Get the text property `menu-item' at pos. The value of that
8927 property is the start index of this item's properties in
8928 F->tool_bar_items. */
8929 prop
= Fget_text_property (make_number (charpos
),
8930 Qmenu_item
, f
->current_tool_bar_string
);
8931 if (INTEGERP (prop
))
8933 *prop_idx
= XINT (prop
);
8943 /* Get information about the tool-bar item at position X/Y on frame F.
8944 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8945 the current matrix of the tool-bar window of F, or NULL if not
8946 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8947 item in F->tool_bar_items. Value is
8949 -1 if X/Y is not on a tool-bar item
8950 0 if X/Y is on the same item that was highlighted before.
8954 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8957 struct glyph
**glyph
;
8958 int *hpos
, *vpos
, *prop_idx
;
8960 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8961 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8964 /* Find the glyph under X/Y. */
8965 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8969 /* Get the start of this tool-bar item's properties in
8970 f->tool_bar_items. */
8971 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8974 /* Is mouse on the highlighted item? */
8975 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8976 && *vpos
>= dpyinfo
->mouse_face_beg_row
8977 && *vpos
<= dpyinfo
->mouse_face_end_row
8978 && (*vpos
> dpyinfo
->mouse_face_beg_row
8979 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8980 && (*vpos
< dpyinfo
->mouse_face_end_row
8981 || *hpos
< dpyinfo
->mouse_face_end_col
8982 || dpyinfo
->mouse_face_past_end
))
8990 Handle mouse button event on the tool-bar of frame F, at
8991 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8992 0 for button release. MODIFIERS is event modifiers for button
8996 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8999 unsigned int modifiers
;
9001 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9002 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9003 int hpos
, vpos
, prop_idx
;
9004 struct glyph
*glyph
;
9005 Lisp_Object enabled_p
;
9007 /* If not on the highlighted tool-bar item, return. */
9008 frame_to_window_pixel_xy (w
, &x
, &y
);
9009 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9012 /* If item is disabled, do nothing. */
9013 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9014 if (NILP (enabled_p
))
9019 /* Show item in pressed state. */
9020 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9021 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9022 last_tool_bar_item
= prop_idx
;
9026 Lisp_Object key
, frame
;
9027 struct input_event event
;
9030 /* Show item in released state. */
9031 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9032 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9034 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9036 XSETFRAME (frame
, f
);
9037 event
.kind
= TOOL_BAR_EVENT
;
9038 event
.frame_or_window
= frame
;
9040 kbd_buffer_store_event (&event
);
9042 event
.kind
= TOOL_BAR_EVENT
;
9043 event
.frame_or_window
= frame
;
9045 event
.modifiers
= modifiers
;
9046 kbd_buffer_store_event (&event
);
9047 last_tool_bar_item
= -1;
9052 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9053 tool-bar window-relative coordinates X/Y. Called from
9054 note_mouse_highlight. */
9057 note_tool_bar_highlight (f
, x
, y
)
9061 Lisp_Object window
= f
->tool_bar_window
;
9062 struct window
*w
= XWINDOW (window
);
9063 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9065 struct glyph
*glyph
;
9066 struct glyph_row
*row
;
9068 Lisp_Object enabled_p
;
9070 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9071 int mouse_down_p
, rc
;
9073 /* Function note_mouse_highlight is called with negative x(y
9074 values when mouse moves outside of the frame. */
9075 if (x
<= 0 || y
<= 0)
9077 clear_mouse_face (dpyinfo
);
9081 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9084 /* Not on tool-bar item. */
9085 clear_mouse_face (dpyinfo
);
9089 /* On same tool-bar item as before. */
9092 clear_mouse_face (dpyinfo
);
9094 /* Mouse is down, but on different tool-bar item? */
9095 mouse_down_p
= (dpyinfo
->grabbed
9096 && f
== last_mouse_frame
9097 && FRAME_LIVE_P (f
));
9099 && last_tool_bar_item
!= prop_idx
)
9102 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9103 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9105 /* If tool-bar item is not enabled, don't highlight it. */
9106 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9107 if (!NILP (enabled_p
))
9109 /* Compute the x-position of the glyph. In front and past the
9110 image is a space. We include this in the highlighted area. */
9111 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9112 for (i
= x
= 0; i
< hpos
; ++i
)
9113 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9115 /* Record this as the current active region. */
9116 dpyinfo
->mouse_face_beg_col
= hpos
;
9117 dpyinfo
->mouse_face_beg_row
= vpos
;
9118 dpyinfo
->mouse_face_beg_x
= x
;
9119 dpyinfo
->mouse_face_beg_y
= row
->y
;
9120 dpyinfo
->mouse_face_past_end
= 0;
9122 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9123 dpyinfo
->mouse_face_end_row
= vpos
;
9124 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9125 dpyinfo
->mouse_face_end_y
= row
->y
;
9126 dpyinfo
->mouse_face_window
= window
;
9127 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9129 /* Display it as active. */
9130 show_mouse_face (dpyinfo
, draw
);
9131 dpyinfo
->mouse_face_image_state
= draw
;
9136 /* Set help_echo_string to a help string to display for this tool-bar item.
9137 XTread_socket does the rest. */
9138 help_echo_object
= help_echo_window
= Qnil
;
9140 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9141 if (NILP (help_echo_string
))
9142 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9145 #endif /* HAVE_WINDOW_SYSTEM */
9149 /************************************************************************
9150 Horizontal scrolling
9151 ************************************************************************/
9153 static int hscroll_window_tree
P_ ((Lisp_Object
));
9154 static int hscroll_windows
P_ ((Lisp_Object
));
9156 /* For all leaf windows in the window tree rooted at WINDOW, set their
9157 hscroll value so that PT is (i) visible in the window, and (ii) so
9158 that it is not within a certain margin at the window's left and
9159 right border. Value is non-zero if any window's hscroll has been
9163 hscroll_window_tree (window
)
9166 int hscrolled_p
= 0;
9167 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9168 int hscroll_step_abs
= 0;
9169 double hscroll_step_rel
= 0;
9171 if (hscroll_relative_p
)
9173 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9174 if (hscroll_step_rel
< 0)
9176 hscroll_relative_p
= 0;
9177 hscroll_step_abs
= 0;
9180 else if (INTEGERP (Vhscroll_step
))
9182 hscroll_step_abs
= XINT (Vhscroll_step
);
9183 if (hscroll_step_abs
< 0)
9184 hscroll_step_abs
= 0;
9187 hscroll_step_abs
= 0;
9189 while (WINDOWP (window
))
9191 struct window
*w
= XWINDOW (window
);
9193 if (WINDOWP (w
->hchild
))
9194 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9195 else if (WINDOWP (w
->vchild
))
9196 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9197 else if (w
->cursor
.vpos
>= 0)
9200 int text_area_width
;
9201 struct glyph_row
*current_cursor_row
9202 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9203 struct glyph_row
*desired_cursor_row
9204 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9205 struct glyph_row
*cursor_row
9206 = (desired_cursor_row
->enabled_p
9207 ? desired_cursor_row
9208 : current_cursor_row
);
9210 text_area_width
= window_box_width (w
, TEXT_AREA
);
9212 /* Scroll when cursor is inside this scroll margin. */
9213 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9215 if ((XFASTINT (w
->hscroll
)
9216 && w
->cursor
.x
<= h_margin
)
9217 || (cursor_row
->enabled_p
9218 && cursor_row
->truncated_on_right_p
9219 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9223 struct buffer
*saved_current_buffer
;
9227 /* Find point in a display of infinite width. */
9228 saved_current_buffer
= current_buffer
;
9229 current_buffer
= XBUFFER (w
->buffer
);
9231 if (w
== XWINDOW (selected_window
))
9232 pt
= BUF_PT (current_buffer
);
9235 pt
= marker_position (w
->pointm
);
9236 pt
= max (BEGV
, pt
);
9240 /* Move iterator to pt starting at cursor_row->start in
9241 a line with infinite width. */
9242 init_to_row_start (&it
, w
, cursor_row
);
9243 it
.last_visible_x
= INFINITY
;
9244 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9245 current_buffer
= saved_current_buffer
;
9247 /* Position cursor in window. */
9248 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9249 hscroll
= max (0, (it
.current_x
9250 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9251 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9252 : (text_area_width
/ 2))))
9253 / FRAME_COLUMN_WIDTH (it
.f
);
9254 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9256 if (hscroll_relative_p
)
9257 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9260 wanted_x
= text_area_width
9261 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9264 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9268 if (hscroll_relative_p
)
9269 wanted_x
= text_area_width
* hscroll_step_rel
9272 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9275 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9277 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9279 /* Don't call Fset_window_hscroll if value hasn't
9280 changed because it will prevent redisplay
9282 if (XFASTINT (w
->hscroll
) != hscroll
)
9284 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9285 w
->hscroll
= make_number (hscroll
);
9294 /* Value is non-zero if hscroll of any leaf window has been changed. */
9299 /* Set hscroll so that cursor is visible and not inside horizontal
9300 scroll margins for all windows in the tree rooted at WINDOW. See
9301 also hscroll_window_tree above. Value is non-zero if any window's
9302 hscroll has been changed. If it has, desired matrices on the frame
9303 of WINDOW are cleared. */
9306 hscroll_windows (window
)
9311 if (automatic_hscrolling_p
)
9313 hscrolled_p
= hscroll_window_tree (window
);
9315 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9324 /************************************************************************
9326 ************************************************************************/
9328 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9329 to a non-zero value. This is sometimes handy to have in a debugger
9334 /* First and last unchanged row for try_window_id. */
9336 int debug_first_unchanged_at_end_vpos
;
9337 int debug_last_unchanged_at_beg_vpos
;
9339 /* Delta vpos and y. */
9341 int debug_dvpos
, debug_dy
;
9343 /* Delta in characters and bytes for try_window_id. */
9345 int debug_delta
, debug_delta_bytes
;
9347 /* Values of window_end_pos and window_end_vpos at the end of
9350 EMACS_INT debug_end_pos
, debug_end_vpos
;
9352 /* Append a string to W->desired_matrix->method. FMT is a printf
9353 format string. A1...A9 are a supplement for a variable-length
9354 argument list. If trace_redisplay_p is non-zero also printf the
9355 resulting string to stderr. */
9358 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9361 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9364 char *method
= w
->desired_matrix
->method
;
9365 int len
= strlen (method
);
9366 int size
= sizeof w
->desired_matrix
->method
;
9367 int remaining
= size
- len
- 1;
9369 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9370 if (len
&& remaining
)
9376 strncpy (method
+ len
, buffer
, remaining
);
9378 if (trace_redisplay_p
)
9379 fprintf (stderr
, "%p (%s): %s\n",
9381 ((BUFFERP (w
->buffer
)
9382 && STRINGP (XBUFFER (w
->buffer
)->name
))
9383 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9388 #endif /* GLYPH_DEBUG */
9391 /* Value is non-zero if all changes in window W, which displays
9392 current_buffer, are in the text between START and END. START is a
9393 buffer position, END is given as a distance from Z. Used in
9394 redisplay_internal for display optimization. */
9397 text_outside_line_unchanged_p (w
, start
, end
)
9401 int unchanged_p
= 1;
9403 /* If text or overlays have changed, see where. */
9404 if (XFASTINT (w
->last_modified
) < MODIFF
9405 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9407 /* Gap in the line? */
9408 if (GPT
< start
|| Z
- GPT
< end
)
9411 /* Changes start in front of the line, or end after it? */
9413 && (BEG_UNCHANGED
< start
- 1
9414 || END_UNCHANGED
< end
))
9417 /* If selective display, can't optimize if changes start at the
9418 beginning of the line. */
9420 && INTEGERP (current_buffer
->selective_display
)
9421 && XINT (current_buffer
->selective_display
) > 0
9422 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9425 /* If there are overlays at the start or end of the line, these
9426 may have overlay strings with newlines in them. A change at
9427 START, for instance, may actually concern the display of such
9428 overlay strings as well, and they are displayed on different
9429 lines. So, quickly rule out this case. (For the future, it
9430 might be desirable to implement something more telling than
9431 just BEG/END_UNCHANGED.) */
9434 if (BEG
+ BEG_UNCHANGED
== start
9435 && overlay_touches_p (start
))
9437 if (END_UNCHANGED
== end
9438 && overlay_touches_p (Z
- end
))
9447 /* Do a frame update, taking possible shortcuts into account. This is
9448 the main external entry point for redisplay.
9450 If the last redisplay displayed an echo area message and that message
9451 is no longer requested, we clear the echo area or bring back the
9452 mini-buffer if that is in use. */
9457 redisplay_internal (0);
9462 overlay_arrow_string_or_property (var
, pbitmap
)
9466 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9472 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9473 *pbitmap
= XINT (bitmap
);
9478 return Voverlay_arrow_string
;
9481 /* Return 1 if there are any overlay-arrows in current_buffer. */
9483 overlay_arrow_in_current_buffer_p ()
9487 for (vlist
= Voverlay_arrow_variable_list
;
9489 vlist
= XCDR (vlist
))
9491 Lisp_Object var
= XCAR (vlist
);
9496 val
= find_symbol_value (var
);
9498 && current_buffer
== XMARKER (val
)->buffer
)
9505 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9509 overlay_arrows_changed_p ()
9513 for (vlist
= Voverlay_arrow_variable_list
;
9515 vlist
= XCDR (vlist
))
9517 Lisp_Object var
= XCAR (vlist
);
9518 Lisp_Object val
, pstr
;
9522 val
= find_symbol_value (var
);
9525 if (! EQ (COERCE_MARKER (val
),
9526 Fget (var
, Qlast_arrow_position
))
9527 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9528 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9534 /* Mark overlay arrows to be updated on next redisplay. */
9537 update_overlay_arrows (up_to_date
)
9542 for (vlist
= Voverlay_arrow_variable_list
;
9544 vlist
= XCDR (vlist
))
9546 Lisp_Object var
= XCAR (vlist
);
9553 Lisp_Object val
= find_symbol_value (var
);
9554 Fput (var
, Qlast_arrow_position
,
9555 COERCE_MARKER (val
));
9556 Fput (var
, Qlast_arrow_string
,
9557 overlay_arrow_string_or_property (var
, 0));
9559 else if (up_to_date
< 0
9560 || !NILP (Fget (var
, Qlast_arrow_position
)))
9562 Fput (var
, Qlast_arrow_position
, Qt
);
9563 Fput (var
, Qlast_arrow_string
, Qt
);
9569 /* Return overlay arrow string to display at row.
9570 Return t if display as bitmap in left fringe.
9571 Return nil if no overlay arrow. */
9574 overlay_arrow_at_row (it
, row
, pbitmap
)
9576 struct glyph_row
*row
;
9581 for (vlist
= Voverlay_arrow_variable_list
;
9583 vlist
= XCDR (vlist
))
9585 Lisp_Object var
= XCAR (vlist
);
9591 val
= find_symbol_value (var
);
9594 && current_buffer
== XMARKER (val
)->buffer
9595 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9597 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9598 if (FRAME_WINDOW_P (it
->f
)
9599 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9611 /* Return 1 if point moved out of or into a composition. Otherwise
9612 return 0. PREV_BUF and PREV_PT are the last point buffer and
9613 position. BUF and PT are the current point buffer and position. */
9616 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9617 struct buffer
*prev_buf
, *buf
;
9624 XSETBUFFER (buffer
, buf
);
9625 /* Check a composition at the last point if point moved within the
9627 if (prev_buf
== buf
)
9630 /* Point didn't move. */
9633 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9634 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9635 && COMPOSITION_VALID_P (start
, end
, prop
)
9636 && start
< prev_pt
&& end
> prev_pt
)
9637 /* The last point was within the composition. Return 1 iff
9638 point moved out of the composition. */
9639 return (pt
<= start
|| pt
>= end
);
9642 /* Check a composition at the current point. */
9643 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9644 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9645 && COMPOSITION_VALID_P (start
, end
, prop
)
9646 && start
< pt
&& end
> pt
);
9650 /* Reconsider the setting of B->clip_changed which is displayed
9654 reconsider_clip_changes (w
, b
)
9659 && !NILP (w
->window_end_valid
)
9660 && w
->current_matrix
->buffer
== b
9661 && w
->current_matrix
->zv
== BUF_ZV (b
)
9662 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9663 b
->clip_changed
= 0;
9665 /* If display wasn't paused, and W is not a tool bar window, see if
9666 point has been moved into or out of a composition. In that case,
9667 we set b->clip_changed to 1 to force updating the screen. If
9668 b->clip_changed has already been set to 1, we can skip this
9670 if (!b
->clip_changed
9671 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9675 if (w
== XWINDOW (selected_window
))
9676 pt
= BUF_PT (current_buffer
);
9678 pt
= marker_position (w
->pointm
);
9680 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9681 || pt
!= XINT (w
->last_point
))
9682 && check_point_in_composition (w
->current_matrix
->buffer
,
9683 XINT (w
->last_point
),
9684 XBUFFER (w
->buffer
), pt
))
9685 b
->clip_changed
= 1;
9690 /* Select FRAME to forward the values of frame-local variables into C
9691 variables so that the redisplay routines can access those values
9695 select_frame_for_redisplay (frame
)
9698 Lisp_Object tail
, sym
, val
;
9699 Lisp_Object old
= selected_frame
;
9701 selected_frame
= frame
;
9703 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9704 if (CONSP (XCAR (tail
))
9705 && (sym
= XCAR (XCAR (tail
)),
9707 && (sym
= indirect_variable (sym
),
9708 val
= SYMBOL_VALUE (sym
),
9709 (BUFFER_LOCAL_VALUEP (val
)
9710 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9711 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9712 Fsymbol_value (sym
);
9714 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9715 if (CONSP (XCAR (tail
))
9716 && (sym
= XCAR (XCAR (tail
)),
9718 && (sym
= indirect_variable (sym
),
9719 val
= SYMBOL_VALUE (sym
),
9720 (BUFFER_LOCAL_VALUEP (val
)
9721 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9722 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9723 Fsymbol_value (sym
);
9727 #define STOP_POLLING \
9728 do { if (! polling_stopped_here) stop_polling (); \
9729 polling_stopped_here = 1; } while (0)
9731 #define RESUME_POLLING \
9732 do { if (polling_stopped_here) start_polling (); \
9733 polling_stopped_here = 0; } while (0)
9736 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9737 response to any user action; therefore, we should preserve the echo
9738 area. (Actually, our caller does that job.) Perhaps in the future
9739 avoid recentering windows if it is not necessary; currently that
9740 causes some problems. */
9743 redisplay_internal (preserve_echo_area
)
9744 int preserve_echo_area
;
9746 struct window
*w
= XWINDOW (selected_window
);
9747 struct frame
*f
= XFRAME (w
->frame
);
9749 int must_finish
= 0;
9750 struct text_pos tlbufpos
, tlendpos
;
9751 int number_of_visible_frames
;
9753 struct frame
*sf
= SELECTED_FRAME ();
9754 int polling_stopped_here
= 0;
9756 /* Non-zero means redisplay has to consider all windows on all
9757 frames. Zero means, only selected_window is considered. */
9758 int consider_all_windows_p
;
9760 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9762 /* No redisplay if running in batch mode or frame is not yet fully
9763 initialized, or redisplay is explicitly turned off by setting
9764 Vinhibit_redisplay. */
9766 || !NILP (Vinhibit_redisplay
)
9767 || !f
->glyphs_initialized_p
)
9770 /* The flag redisplay_performed_directly_p is set by
9771 direct_output_for_insert when it already did the whole screen
9772 update necessary. */
9773 if (redisplay_performed_directly_p
)
9775 redisplay_performed_directly_p
= 0;
9776 if (!hscroll_windows (selected_window
))
9780 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9781 if (popup_activated ())
9785 /* I don't think this happens but let's be paranoid. */
9789 /* Record a function that resets redisplaying_p to its old value
9790 when we leave this function. */
9791 count
= SPECPDL_INDEX ();
9792 record_unwind_protect (unwind_redisplay
,
9793 Fcons (make_number (redisplaying_p
), selected_frame
));
9795 specbind (Qinhibit_free_realized_faces
, Qnil
);
9799 reconsider_clip_changes (w
, current_buffer
);
9801 /* If new fonts have been loaded that make a glyph matrix adjustment
9802 necessary, do it. */
9803 if (fonts_changed_p
)
9805 adjust_glyphs (NULL
);
9806 ++windows_or_buffers_changed
;
9807 fonts_changed_p
= 0;
9810 /* If face_change_count is non-zero, init_iterator will free all
9811 realized faces, which includes the faces referenced from current
9812 matrices. So, we can't reuse current matrices in this case. */
9813 if (face_change_count
)
9814 ++windows_or_buffers_changed
;
9816 if (FRAME_TERMCAP_P (sf
)
9817 && FRAME_TTY (sf
)->previous_terminal_frame
!= sf
)
9819 /* Since frames on a single ASCII terminal share the same
9820 display area, displaying a different frame means redisplay
9822 windows_or_buffers_changed
++;
9823 SET_FRAME_GARBAGED (sf
);
9824 FRAME_TTY (sf
)->previous_terminal_frame
= sf
;
9827 /* Set the visible flags for all frames. Do this before checking
9828 for resized or garbaged frames; they want to know if their frames
9829 are visible. See the comment in frame.h for
9830 FRAME_SAMPLE_VISIBILITY. */
9832 Lisp_Object tail
, frame
;
9834 number_of_visible_frames
= 0;
9836 FOR_EACH_FRAME (tail
, frame
)
9838 struct frame
*f
= XFRAME (frame
);
9840 FRAME_SAMPLE_VISIBILITY (f
);
9841 if (FRAME_VISIBLE_P (f
))
9842 ++number_of_visible_frames
;
9843 clear_desired_matrices (f
);
9848 /* Notice any pending interrupt request to change frame size. */
9849 do_pending_window_change (1);
9851 /* Clear frames marked as garbaged. */
9853 clear_garbaged_frames ();
9855 /* Build menubar and tool-bar items. */
9856 prepare_menu_bars ();
9858 if (windows_or_buffers_changed
)
9859 update_mode_lines
++;
9861 /* Detect case that we need to write or remove a star in the mode line. */
9862 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9864 w
->update_mode_line
= Qt
;
9865 if (buffer_shared
> 1)
9866 update_mode_lines
++;
9869 /* If %c is in the mode line, update it if needed. */
9870 if (!NILP (w
->column_number_displayed
)
9871 /* This alternative quickly identifies a common case
9872 where no change is needed. */
9873 && !(PT
== XFASTINT (w
->last_point
)
9874 && XFASTINT (w
->last_modified
) >= MODIFF
9875 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9876 && (XFASTINT (w
->column_number_displayed
)
9877 != (int) current_column ())) /* iftc */
9878 w
->update_mode_line
= Qt
;
9880 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9882 /* The variable buffer_shared is set in redisplay_window and
9883 indicates that we redisplay a buffer in different windows. See
9885 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9886 || cursor_type_changed
);
9888 /* If specs for an arrow have changed, do thorough redisplay
9889 to ensure we remove any arrow that should no longer exist. */
9890 if (overlay_arrows_changed_p ())
9891 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9893 /* Normally the message* functions will have already displayed and
9894 updated the echo area, but the frame may have been trashed, or
9895 the update may have been preempted, so display the echo area
9896 again here. Checking message_cleared_p captures the case that
9897 the echo area should be cleared. */
9898 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9899 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9900 || (message_cleared_p
9901 && minibuf_level
== 0
9902 /* If the mini-window is currently selected, this means the
9903 echo-area doesn't show through. */
9904 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9906 int window_height_changed_p
= echo_area_display (0);
9909 /* If we don't display the current message, don't clear the
9910 message_cleared_p flag, because, if we did, we wouldn't clear
9911 the echo area in the next redisplay which doesn't preserve
9913 if (!display_last_displayed_message_p
)
9914 message_cleared_p
= 0;
9916 if (fonts_changed_p
)
9918 else if (window_height_changed_p
)
9920 consider_all_windows_p
= 1;
9921 ++update_mode_lines
;
9922 ++windows_or_buffers_changed
;
9924 /* If window configuration was changed, frames may have been
9925 marked garbaged. Clear them or we will experience
9926 surprises wrt scrolling. */
9928 clear_garbaged_frames ();
9931 else if (EQ (selected_window
, minibuf_window
)
9932 && (current_buffer
->clip_changed
9933 || XFASTINT (w
->last_modified
) < MODIFF
9934 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9935 && resize_mini_window (w
, 0))
9937 /* Resized active mini-window to fit the size of what it is
9938 showing if its contents might have changed. */
9940 consider_all_windows_p
= 1;
9941 ++windows_or_buffers_changed
;
9942 ++update_mode_lines
;
9944 /* If window configuration was changed, frames may have been
9945 marked garbaged. Clear them or we will experience
9946 surprises wrt scrolling. */
9948 clear_garbaged_frames ();
9952 /* If showing the region, and mark has changed, we must redisplay
9953 the whole window. The assignment to this_line_start_pos prevents
9954 the optimization directly below this if-statement. */
9955 if (((!NILP (Vtransient_mark_mode
)
9956 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9957 != !NILP (w
->region_showing
))
9958 || (!NILP (w
->region_showing
)
9959 && !EQ (w
->region_showing
,
9960 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9961 CHARPOS (this_line_start_pos
) = 0;
9963 /* Optimize the case that only the line containing the cursor in the
9964 selected window has changed. Variables starting with this_ are
9965 set in display_line and record information about the line
9966 containing the cursor. */
9967 tlbufpos
= this_line_start_pos
;
9968 tlendpos
= this_line_end_pos
;
9969 if (!consider_all_windows_p
9970 && CHARPOS (tlbufpos
) > 0
9971 && NILP (w
->update_mode_line
)
9972 && !current_buffer
->clip_changed
9973 && !current_buffer
->prevent_redisplay_optimizations_p
9974 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9975 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9976 /* Make sure recorded data applies to current buffer, etc. */
9977 && this_line_buffer
== current_buffer
9978 && current_buffer
== XBUFFER (w
->buffer
)
9979 && NILP (w
->force_start
)
9980 && NILP (w
->optional_new_start
)
9981 /* Point must be on the line that we have info recorded about. */
9982 && PT
>= CHARPOS (tlbufpos
)
9983 && PT
<= Z
- CHARPOS (tlendpos
)
9984 /* All text outside that line, including its final newline,
9985 must be unchanged */
9986 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9987 CHARPOS (tlendpos
)))
9989 if (CHARPOS (tlbufpos
) > BEGV
9990 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9991 && (CHARPOS (tlbufpos
) == ZV
9992 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9993 /* Former continuation line has disappeared by becoming empty */
9995 else if (XFASTINT (w
->last_modified
) < MODIFF
9996 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9997 || MINI_WINDOW_P (w
))
9999 /* We have to handle the case of continuation around a
10000 wide-column character (See the comment in indent.c around
10003 For instance, in the following case:
10005 -------- Insert --------
10006 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10007 J_I_ ==> J_I_ `^^' are cursors.
10011 As we have to redraw the line above, we should goto cancel. */
10014 int line_height_before
= this_line_pixel_height
;
10016 /* Note that start_display will handle the case that the
10017 line starting at tlbufpos is a continuation lines. */
10018 start_display (&it
, w
, tlbufpos
);
10020 /* Implementation note: It this still necessary? */
10021 if (it
.current_x
!= this_line_start_x
)
10024 TRACE ((stderr
, "trying display optimization 1\n"));
10025 w
->cursor
.vpos
= -1;
10026 overlay_arrow_seen
= 0;
10027 it
.vpos
= this_line_vpos
;
10028 it
.current_y
= this_line_y
;
10029 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10030 display_line (&it
);
10032 /* If line contains point, is not continued,
10033 and ends at same distance from eob as before, we win */
10034 if (w
->cursor
.vpos
>= 0
10035 /* Line is not continued, otherwise this_line_start_pos
10036 would have been set to 0 in display_line. */
10037 && CHARPOS (this_line_start_pos
)
10038 /* Line ends as before. */
10039 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10040 /* Line has same height as before. Otherwise other lines
10041 would have to be shifted up or down. */
10042 && this_line_pixel_height
== line_height_before
)
10044 /* If this is not the window's last line, we must adjust
10045 the charstarts of the lines below. */
10046 if (it
.current_y
< it
.last_visible_y
)
10048 struct glyph_row
*row
10049 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10050 int delta
, delta_bytes
;
10052 if (Z
- CHARPOS (tlendpos
) == ZV
)
10054 /* This line ends at end of (accessible part of)
10055 buffer. There is no newline to count. */
10057 - CHARPOS (tlendpos
)
10058 - MATRIX_ROW_START_CHARPOS (row
));
10059 delta_bytes
= (Z_BYTE
10060 - BYTEPOS (tlendpos
)
10061 - MATRIX_ROW_START_BYTEPOS (row
));
10065 /* This line ends in a newline. Must take
10066 account of the newline and the rest of the
10067 text that follows. */
10069 - CHARPOS (tlendpos
)
10070 - MATRIX_ROW_START_CHARPOS (row
));
10071 delta_bytes
= (Z_BYTE
10072 - BYTEPOS (tlendpos
)
10073 - MATRIX_ROW_START_BYTEPOS (row
));
10076 increment_matrix_positions (w
->current_matrix
,
10077 this_line_vpos
+ 1,
10078 w
->current_matrix
->nrows
,
10079 delta
, delta_bytes
);
10082 /* If this row displays text now but previously didn't,
10083 or vice versa, w->window_end_vpos may have to be
10085 if ((it
.glyph_row
- 1)->displays_text_p
)
10087 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10088 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10090 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10091 && this_line_vpos
> 0)
10092 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10093 w
->window_end_valid
= Qnil
;
10095 /* Update hint: No need to try to scroll in update_window. */
10096 w
->desired_matrix
->no_scrolling_p
= 1;
10099 *w
->desired_matrix
->method
= 0;
10100 debug_method_add (w
, "optimization 1");
10102 #ifdef HAVE_WINDOW_SYSTEM
10103 update_window_fringes (w
, 0);
10110 else if (/* Cursor position hasn't changed. */
10111 PT
== XFASTINT (w
->last_point
)
10112 /* Make sure the cursor was last displayed
10113 in this window. Otherwise we have to reposition it. */
10114 && 0 <= w
->cursor
.vpos
10115 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10119 do_pending_window_change (1);
10121 /* We used to always goto end_of_redisplay here, but this
10122 isn't enough if we have a blinking cursor. */
10123 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10124 goto end_of_redisplay
;
10128 /* If highlighting the region, or if the cursor is in the echo area,
10129 then we can't just move the cursor. */
10130 else if (! (!NILP (Vtransient_mark_mode
)
10131 && !NILP (current_buffer
->mark_active
))
10132 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10133 || highlight_nonselected_windows
)
10134 && NILP (w
->region_showing
)
10135 && NILP (Vshow_trailing_whitespace
)
10136 && !cursor_in_echo_area
)
10139 struct glyph_row
*row
;
10141 /* Skip from tlbufpos to PT and see where it is. Note that
10142 PT may be in invisible text. If so, we will end at the
10143 next visible position. */
10144 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10145 NULL
, DEFAULT_FACE_ID
);
10146 it
.current_x
= this_line_start_x
;
10147 it
.current_y
= this_line_y
;
10148 it
.vpos
= this_line_vpos
;
10150 /* The call to move_it_to stops in front of PT, but
10151 moves over before-strings. */
10152 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10154 if (it
.vpos
== this_line_vpos
10155 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10158 xassert (this_line_vpos
== it
.vpos
);
10159 xassert (this_line_y
== it
.current_y
);
10160 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10162 *w
->desired_matrix
->method
= 0;
10163 debug_method_add (w
, "optimization 3");
10172 /* Text changed drastically or point moved off of line. */
10173 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10176 CHARPOS (this_line_start_pos
) = 0;
10177 consider_all_windows_p
|= buffer_shared
> 1;
10178 ++clear_face_cache_count
;
10181 /* Build desired matrices, and update the display. If
10182 consider_all_windows_p is non-zero, do it for all windows on all
10183 frames. Otherwise do it for selected_window, only. */
10185 if (consider_all_windows_p
)
10187 Lisp_Object tail
, frame
;
10188 int i
, n
= 0, size
= 50;
10189 struct frame
**updated
10190 = (struct frame
**) alloca (size
* sizeof *updated
);
10192 /* Clear the face cache eventually. */
10193 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10195 clear_face_cache (0);
10196 clear_face_cache_count
= 0;
10199 /* Recompute # windows showing selected buffer. This will be
10200 incremented each time such a window is displayed. */
10203 FOR_EACH_FRAME (tail
, frame
)
10205 struct frame
*f
= XFRAME (frame
);
10207 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10209 if (! EQ (frame
, selected_frame
))
10210 /* Select the frame, for the sake of frame-local
10212 select_frame_for_redisplay (frame
);
10214 #ifdef HAVE_WINDOW_SYSTEM
10215 if (clear_face_cache_count
% 50 == 0
10216 && FRAME_WINDOW_P (f
))
10217 clear_image_cache (f
, 0);
10218 #endif /* HAVE_WINDOW_SYSTEM */
10220 /* Mark all the scroll bars to be removed; we'll redeem
10221 the ones we want when we redisplay their windows. */
10222 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
10223 FRAME_DISPLAY (f
)->condemn_scroll_bars_hook (f
);
10225 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10226 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10228 /* Any scroll bars which redisplay_windows should have
10229 nuked should now go away. */
10230 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
10231 FRAME_DISPLAY (f
)->judge_scroll_bars_hook (f
);
10233 /* If fonts changed, display again. */
10234 /* ??? rms: I suspect it is a mistake to jump all the way
10235 back to retry here. It should just retry this frame. */
10236 if (fonts_changed_p
)
10239 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10241 /* See if we have to hscroll. */
10242 if (hscroll_windows (f
->root_window
))
10245 /* Prevent various kinds of signals during display
10246 update. stdio is not robust about handling
10247 signals, which can cause an apparent I/O
10249 if (interrupt_input
)
10250 unrequest_sigio ();
10253 /* Update the display. */
10254 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10255 pause
|= update_frame (f
, 0, 0);
10256 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10263 int nbytes
= size
* sizeof *updated
;
10264 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10265 bcopy (updated
, p
, nbytes
);
10276 /* Do the mark_window_display_accurate after all windows have
10277 been redisplayed because this call resets flags in buffers
10278 which are needed for proper redisplay. */
10279 for (i
= 0; i
< n
; ++i
)
10281 struct frame
*f
= updated
[i
];
10282 mark_window_display_accurate (f
->root_window
, 1);
10283 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
)
10284 FRAME_DISPLAY (f
)->frame_up_to_date_hook (f
);
10288 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10290 Lisp_Object mini_window
;
10291 struct frame
*mini_frame
;
10293 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10294 /* Use list_of_error, not Qerror, so that
10295 we catch only errors and don't run the debugger. */
10296 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10298 redisplay_window_error
);
10300 /* Compare desired and current matrices, perform output. */
10303 /* If fonts changed, display again. */
10304 if (fonts_changed_p
)
10307 /* Prevent various kinds of signals during display update.
10308 stdio is not robust about handling signals,
10309 which can cause an apparent I/O error. */
10310 if (interrupt_input
)
10311 unrequest_sigio ();
10314 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10316 if (hscroll_windows (selected_window
))
10319 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10320 pause
= update_frame (sf
, 0, 0);
10323 /* We may have called echo_area_display at the top of this
10324 function. If the echo area is on another frame, that may
10325 have put text on a frame other than the selected one, so the
10326 above call to update_frame would not have caught it. Catch
10328 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10329 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10331 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10333 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10334 pause
|= update_frame (mini_frame
, 0, 0);
10335 if (!pause
&& hscroll_windows (mini_window
))
10340 /* If display was paused because of pending input, make sure we do a
10341 thorough update the next time. */
10344 /* Prevent the optimization at the beginning of
10345 redisplay_internal that tries a single-line update of the
10346 line containing the cursor in the selected window. */
10347 CHARPOS (this_line_start_pos
) = 0;
10349 /* Let the overlay arrow be updated the next time. */
10350 update_overlay_arrows (0);
10352 /* If we pause after scrolling, some rows in the current
10353 matrices of some windows are not valid. */
10354 if (!WINDOW_FULL_WIDTH_P (w
)
10355 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10356 update_mode_lines
= 1;
10360 if (!consider_all_windows_p
)
10362 /* This has already been done above if
10363 consider_all_windows_p is set. */
10364 mark_window_display_accurate_1 (w
, 1);
10366 /* Say overlay arrows are up to date. */
10367 update_overlay_arrows (1);
10369 if (FRAME_DISPLAY (sf
)->frame_up_to_date_hook
!= 0)
10370 FRAME_DISPLAY (sf
)->frame_up_to_date_hook (sf
);
10373 update_mode_lines
= 0;
10374 windows_or_buffers_changed
= 0;
10375 cursor_type_changed
= 0;
10378 /* Start SIGIO interrupts coming again. Having them off during the
10379 code above makes it less likely one will discard output, but not
10380 impossible, since there might be stuff in the system buffer here.
10381 But it is much hairier to try to do anything about that. */
10382 if (interrupt_input
)
10386 /* If a frame has become visible which was not before, redisplay
10387 again, so that we display it. Expose events for such a frame
10388 (which it gets when becoming visible) don't call the parts of
10389 redisplay constructing glyphs, so simply exposing a frame won't
10390 display anything in this case. So, we have to display these
10391 frames here explicitly. */
10394 Lisp_Object tail
, frame
;
10397 FOR_EACH_FRAME (tail
, frame
)
10399 int this_is_visible
= 0;
10401 if (XFRAME (frame
)->visible
)
10402 this_is_visible
= 1;
10403 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10404 if (XFRAME (frame
)->visible
)
10405 this_is_visible
= 1;
10407 if (this_is_visible
)
10411 if (new_count
!= number_of_visible_frames
)
10412 windows_or_buffers_changed
++;
10415 /* Change frame size now if a change is pending. */
10416 do_pending_window_change (1);
10418 /* If we just did a pending size change, or have additional
10419 visible frames, redisplay again. */
10420 if (windows_or_buffers_changed
&& !pause
)
10424 unbind_to (count
, Qnil
);
10429 /* Redisplay, but leave alone any recent echo area message unless
10430 another message has been requested in its place.
10432 This is useful in situations where you need to redisplay but no
10433 user action has occurred, making it inappropriate for the message
10434 area to be cleared. See tracking_off and
10435 wait_reading_process_output for examples of these situations.
10437 FROM_WHERE is an integer saying from where this function was
10438 called. This is useful for debugging. */
10441 redisplay_preserve_echo_area (from_where
)
10444 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10446 if (!NILP (echo_area_buffer
[1]))
10448 /* We have a previously displayed message, but no current
10449 message. Redisplay the previous message. */
10450 display_last_displayed_message_p
= 1;
10451 redisplay_internal (1);
10452 display_last_displayed_message_p
= 0;
10455 redisplay_internal (1);
10457 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
10458 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10459 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
10463 /* Function registered with record_unwind_protect in
10464 redisplay_internal. Reset redisplaying_p to the value it had
10465 before redisplay_internal was called, and clear
10466 prevent_freeing_realized_faces_p. It also selects the previously
10470 unwind_redisplay (val
)
10473 Lisp_Object old_redisplaying_p
, old_frame
;
10475 old_redisplaying_p
= XCAR (val
);
10476 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10477 old_frame
= XCDR (val
);
10478 if (! EQ (old_frame
, selected_frame
))
10479 select_frame_for_redisplay (old_frame
);
10484 /* Mark the display of window W as accurate or inaccurate. If
10485 ACCURATE_P is non-zero mark display of W as accurate. If
10486 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10487 redisplay_internal is called. */
10490 mark_window_display_accurate_1 (w
, accurate_p
)
10494 if (BUFFERP (w
->buffer
))
10496 struct buffer
*b
= XBUFFER (w
->buffer
);
10499 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10500 w
->last_overlay_modified
10501 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10503 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10507 b
->clip_changed
= 0;
10508 b
->prevent_redisplay_optimizations_p
= 0;
10510 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10511 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10512 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10513 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10515 w
->current_matrix
->buffer
= b
;
10516 w
->current_matrix
->begv
= BUF_BEGV (b
);
10517 w
->current_matrix
->zv
= BUF_ZV (b
);
10519 w
->last_cursor
= w
->cursor
;
10520 w
->last_cursor_off_p
= w
->cursor_off_p
;
10522 if (w
== XWINDOW (selected_window
))
10523 w
->last_point
= make_number (BUF_PT (b
));
10525 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10531 w
->window_end_valid
= w
->buffer
;
10532 #if 0 /* This is incorrect with variable-height lines. */
10533 xassert (XINT (w
->window_end_vpos
)
10534 < (WINDOW_TOTAL_LINES (w
)
10535 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10537 w
->update_mode_line
= Qnil
;
10542 /* Mark the display of windows in the window tree rooted at WINDOW as
10543 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10544 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10545 be redisplayed the next time redisplay_internal is called. */
10548 mark_window_display_accurate (window
, accurate_p
)
10549 Lisp_Object window
;
10554 for (; !NILP (window
); window
= w
->next
)
10556 w
= XWINDOW (window
);
10557 mark_window_display_accurate_1 (w
, accurate_p
);
10559 if (!NILP (w
->vchild
))
10560 mark_window_display_accurate (w
->vchild
, accurate_p
);
10561 if (!NILP (w
->hchild
))
10562 mark_window_display_accurate (w
->hchild
, accurate_p
);
10567 update_overlay_arrows (1);
10571 /* Force a thorough redisplay the next time by setting
10572 last_arrow_position and last_arrow_string to t, which is
10573 unequal to any useful value of Voverlay_arrow_... */
10574 update_overlay_arrows (-1);
10579 /* Return value in display table DP (Lisp_Char_Table *) for character
10580 C. Since a display table doesn't have any parent, we don't have to
10581 follow parent. Do not call this function directly but use the
10582 macro DISP_CHAR_VECTOR. */
10585 disp_char_vector (dp
, c
)
10586 struct Lisp_Char_Table
*dp
;
10592 if (SINGLE_BYTE_CHAR_P (c
))
10593 return (dp
->contents
[c
]);
10595 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10598 else if (code
[2] < 32)
10601 /* Here, the possible range of code[0] (== charset ID) is
10602 128..max_charset. Since the top level char table contains data
10603 for multibyte characters after 256th element, we must increment
10604 code[0] by 128 to get a correct index. */
10606 code
[3] = -1; /* anchor */
10608 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10610 val
= dp
->contents
[code
[i
]];
10611 if (!SUB_CHAR_TABLE_P (val
))
10612 return (NILP (val
) ? dp
->defalt
: val
);
10615 /* Here, val is a sub char table. We return the default value of
10617 return (dp
->defalt
);
10622 /***********************************************************************
10624 ***********************************************************************/
10626 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10629 redisplay_windows (window
)
10630 Lisp_Object window
;
10632 while (!NILP (window
))
10634 struct window
*w
= XWINDOW (window
);
10636 if (!NILP (w
->hchild
))
10637 redisplay_windows (w
->hchild
);
10638 else if (!NILP (w
->vchild
))
10639 redisplay_windows (w
->vchild
);
10642 displayed_buffer
= XBUFFER (w
->buffer
);
10643 /* Use list_of_error, not Qerror, so that
10644 we catch only errors and don't run the debugger. */
10645 internal_condition_case_1 (redisplay_window_0
, window
,
10647 redisplay_window_error
);
10655 redisplay_window_error ()
10657 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10662 redisplay_window_0 (window
)
10663 Lisp_Object window
;
10665 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10666 redisplay_window (window
, 0);
10671 redisplay_window_1 (window
)
10672 Lisp_Object window
;
10674 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10675 redisplay_window (window
, 1);
10680 /* Increment GLYPH until it reaches END or CONDITION fails while
10681 adding (GLYPH)->pixel_width to X. */
10683 #define SKIP_GLYPHS(glyph, end, x, condition) \
10686 (x) += (glyph)->pixel_width; \
10689 while ((glyph) < (end) && (condition))
10692 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10693 DELTA is the number of bytes by which positions recorded in ROW
10694 differ from current buffer positions. */
10697 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10699 struct glyph_row
*row
;
10700 struct glyph_matrix
*matrix
;
10701 int delta
, delta_bytes
, dy
, dvpos
;
10703 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10704 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10705 struct glyph
*cursor
= NULL
;
10706 /* The first glyph that starts a sequence of glyphs from string. */
10707 struct glyph
*string_start
;
10708 /* The X coordinate of string_start. */
10709 int string_start_x
;
10710 /* The last known character position. */
10711 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10712 /* The last known character position before string_start. */
10713 int string_before_pos
;
10716 int cursor_from_overlay_pos
= 0;
10717 int pt_old
= PT
- delta
;
10719 /* Skip over glyphs not having an object at the start of the row.
10720 These are special glyphs like truncation marks on terminal
10722 if (row
->displays_text_p
)
10724 && INTEGERP (glyph
->object
)
10725 && glyph
->charpos
< 0)
10727 x
+= glyph
->pixel_width
;
10731 string_start
= NULL
;
10733 && !INTEGERP (glyph
->object
)
10734 && (!BUFFERP (glyph
->object
)
10735 || (last_pos
= glyph
->charpos
) < pt_old
))
10737 if (! STRINGP (glyph
->object
))
10739 string_start
= NULL
;
10740 x
+= glyph
->pixel_width
;
10742 if (cursor_from_overlay_pos
10743 && last_pos
> cursor_from_overlay_pos
)
10745 cursor_from_overlay_pos
= 0;
10751 string_before_pos
= last_pos
;
10752 string_start
= glyph
;
10753 string_start_x
= x
;
10754 /* Skip all glyphs from string. */
10758 if ((cursor
== NULL
|| glyph
> cursor
)
10759 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
10760 Qcursor
, (glyph
)->object
))
10761 && (pos
= string_buffer_position (w
, glyph
->object
,
10762 string_before_pos
),
10763 (pos
== 0 /* From overlay */
10764 || pos
== pt_old
)))
10766 /* Estimate overlay buffer position from the buffer
10767 positions of the glyphs before and after the overlay.
10768 Add 1 to last_pos so that if point corresponds to the
10769 glyph right after the overlay, we still use a 'cursor'
10770 property found in that overlay. */
10771 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
10775 x
+= glyph
->pixel_width
;
10778 while (glyph
< end
&& STRINGP (glyph
->object
));
10782 if (cursor
!= NULL
)
10787 else if (string_start
10788 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10790 /* We may have skipped over point because the previous glyphs
10791 are from string. As there's no easy way to know the
10792 character position of the current glyph, find the correct
10793 glyph on point by scanning from string_start again. */
10795 Lisp_Object string
;
10798 limit
= make_number (pt_old
+ 1);
10800 glyph
= string_start
;
10801 x
= string_start_x
;
10802 string
= glyph
->object
;
10803 pos
= string_buffer_position (w
, string
, string_before_pos
);
10804 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10805 because we always put cursor after overlay strings. */
10806 while (pos
== 0 && glyph
< end
)
10808 string
= glyph
->object
;
10809 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10811 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10814 while (glyph
< end
)
10816 pos
= XINT (Fnext_single_char_property_change
10817 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10820 /* Skip glyphs from the same string. */
10821 string
= glyph
->object
;
10822 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10823 /* Skip glyphs from an overlay. */
10825 && ! string_buffer_position (w
, glyph
->object
, pos
))
10827 string
= glyph
->object
;
10828 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10833 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10835 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10836 w
->cursor
.y
= row
->y
+ dy
;
10838 if (w
== XWINDOW (selected_window
))
10840 if (!row
->continued_p
10841 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10844 this_line_buffer
= XBUFFER (w
->buffer
);
10846 CHARPOS (this_line_start_pos
)
10847 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10848 BYTEPOS (this_line_start_pos
)
10849 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10851 CHARPOS (this_line_end_pos
)
10852 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10853 BYTEPOS (this_line_end_pos
)
10854 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10856 this_line_y
= w
->cursor
.y
;
10857 this_line_pixel_height
= row
->height
;
10858 this_line_vpos
= w
->cursor
.vpos
;
10859 this_line_start_x
= row
->x
;
10862 CHARPOS (this_line_start_pos
) = 0;
10867 /* Run window scroll functions, if any, for WINDOW with new window
10868 start STARTP. Sets the window start of WINDOW to that position.
10870 We assume that the window's buffer is really current. */
10872 static INLINE
struct text_pos
10873 run_window_scroll_functions (window
, startp
)
10874 Lisp_Object window
;
10875 struct text_pos startp
;
10877 struct window
*w
= XWINDOW (window
);
10878 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10880 if (current_buffer
!= XBUFFER (w
->buffer
))
10883 if (!NILP (Vwindow_scroll_functions
))
10885 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10886 make_number (CHARPOS (startp
)));
10887 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10888 /* In case the hook functions switch buffers. */
10889 if (current_buffer
!= XBUFFER (w
->buffer
))
10890 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10897 /* Make sure the line containing the cursor is fully visible.
10898 A value of 1 means there is nothing to be done.
10899 (Either the line is fully visible, or it cannot be made so,
10900 or we cannot tell.)
10902 If FORCE_P is non-zero, return 0 even if partial visible cursor row
10903 is higher than window.
10905 A value of 0 means the caller should do scrolling
10906 as if point had gone off the screen. */
10909 make_cursor_line_fully_visible (w
, force_p
)
10913 struct glyph_matrix
*matrix
;
10914 struct glyph_row
*row
;
10917 if (!make_cursor_line_fully_visible_p
)
10920 /* It's not always possible to find the cursor, e.g, when a window
10921 is full of overlay strings. Don't do anything in that case. */
10922 if (w
->cursor
.vpos
< 0)
10925 matrix
= w
->desired_matrix
;
10926 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10928 /* If the cursor row is not partially visible, there's nothing to do. */
10929 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
10932 /* If the row the cursor is in is taller than the window's height,
10933 it's not clear what to do, so do nothing. */
10934 window_height
= window_box_height (w
);
10935 if (row
->height
>= window_height
)
10937 if (!force_p
|| w
->vscroll
)
10943 /* This code used to try to scroll the window just enough to make
10944 the line visible. It returned 0 to say that the caller should
10945 allocate larger glyph matrices. */
10947 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10949 int dy
= row
->height
- row
->visible_height
;
10952 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10954 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10956 int dy
= - (row
->height
- row
->visible_height
);
10959 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10962 /* When we change the cursor y-position of the selected window,
10963 change this_line_y as well so that the display optimization for
10964 the cursor line of the selected window in redisplay_internal uses
10965 the correct y-position. */
10966 if (w
== XWINDOW (selected_window
))
10967 this_line_y
= w
->cursor
.y
;
10969 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10970 redisplay with larger matrices. */
10971 if (matrix
->nrows
< required_matrix_height (w
))
10973 fonts_changed_p
= 1;
10982 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10983 non-zero means only WINDOW is redisplayed in redisplay_internal.
10984 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10985 in redisplay_window to bring a partially visible line into view in
10986 the case that only the cursor has moved.
10988 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10989 last screen line's vertical height extends past the end of the screen.
10993 1 if scrolling succeeded
10995 0 if scrolling didn't find point.
10997 -1 if new fonts have been loaded so that we must interrupt
10998 redisplay, adjust glyph matrices, and try again. */
11004 SCROLLING_NEED_LARGER_MATRICES
11008 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11009 scroll_step
, temp_scroll_step
, last_line_misfit
)
11010 Lisp_Object window
;
11011 int just_this_one_p
;
11012 EMACS_INT scroll_conservatively
, scroll_step
;
11013 int temp_scroll_step
;
11014 int last_line_misfit
;
11016 struct window
*w
= XWINDOW (window
);
11017 struct frame
*f
= XFRAME (w
->frame
);
11018 struct text_pos scroll_margin_pos
;
11019 struct text_pos pos
;
11020 struct text_pos startp
;
11022 Lisp_Object window_end
;
11023 int this_scroll_margin
;
11027 int amount_to_scroll
= 0;
11028 Lisp_Object aggressive
;
11030 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11033 debug_method_add (w
, "try_scrolling");
11036 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11038 /* Compute scroll margin height in pixels. We scroll when point is
11039 within this distance from the top or bottom of the window. */
11040 if (scroll_margin
> 0)
11042 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11043 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11046 this_scroll_margin
= 0;
11048 /* Force scroll_conservatively to have a reasonable value so it doesn't
11049 cause an overflow while computing how much to scroll. */
11050 if (scroll_conservatively
)
11051 scroll_conservatively
= min (scroll_conservatively
,
11052 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11054 /* Compute how much we should try to scroll maximally to bring point
11056 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11057 scroll_max
= max (scroll_step
,
11058 max (scroll_conservatively
, temp_scroll_step
));
11059 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11060 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11061 /* We're trying to scroll because of aggressive scrolling
11062 but no scroll_step is set. Choose an arbitrary one. Maybe
11063 there should be a variable for this. */
11067 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11069 /* Decide whether we have to scroll down. Start at the window end
11070 and move this_scroll_margin up to find the position of the scroll
11072 window_end
= Fwindow_end (window
, Qt
);
11076 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11077 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11079 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11081 start_display (&it
, w
, scroll_margin_pos
);
11082 if (this_scroll_margin
)
11083 move_it_vertically_backward (&it
, this_scroll_margin
);
11084 if (extra_scroll_margin_lines
)
11085 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11086 scroll_margin_pos
= it
.current
.pos
;
11089 if (PT
>= CHARPOS (scroll_margin_pos
))
11093 /* Point is in the scroll margin at the bottom of the window, or
11094 below. Compute a new window start that makes point visible. */
11096 /* Compute the distance from the scroll margin to PT.
11097 Give up if the distance is greater than scroll_max. */
11098 start_display (&it
, w
, scroll_margin_pos
);
11100 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11101 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11103 /* To make point visible, we have to move the window start
11104 down so that the line the cursor is in is visible, which
11105 means we have to add in the height of the cursor line. */
11106 dy
= line_bottom_y (&it
) - y0
;
11108 if (dy
> scroll_max
)
11109 return SCROLLING_FAILED
;
11111 /* Move the window start down. If scrolling conservatively,
11112 move it just enough down to make point visible. If
11113 scroll_step is set, move it down by scroll_step. */
11114 start_display (&it
, w
, startp
);
11116 if (scroll_conservatively
)
11117 /* Set AMOUNT_TO_SCROLL to at least one line,
11118 and at most scroll_conservatively lines. */
11120 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11121 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11122 else if (scroll_step
|| temp_scroll_step
)
11123 amount_to_scroll
= scroll_max
;
11126 aggressive
= current_buffer
->scroll_up_aggressively
;
11127 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11128 if (NUMBERP (aggressive
))
11130 double float_amount
= XFLOATINT (aggressive
) * height
;
11131 amount_to_scroll
= float_amount
;
11132 if (amount_to_scroll
== 0 && float_amount
> 0)
11133 amount_to_scroll
= 1;
11137 if (amount_to_scroll
<= 0)
11138 return SCROLLING_FAILED
;
11140 /* If moving by amount_to_scroll leaves STARTP unchanged,
11141 move it down one screen line. */
11143 move_it_vertically (&it
, amount_to_scroll
);
11144 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11145 move_it_by_lines (&it
, 1, 1);
11146 startp
= it
.current
.pos
;
11150 /* See if point is inside the scroll margin at the top of the
11152 scroll_margin_pos
= startp
;
11153 if (this_scroll_margin
)
11155 start_display (&it
, w
, startp
);
11156 move_it_vertically (&it
, this_scroll_margin
);
11157 scroll_margin_pos
= it
.current
.pos
;
11160 if (PT
< CHARPOS (scroll_margin_pos
))
11162 /* Point is in the scroll margin at the top of the window or
11163 above what is displayed in the window. */
11166 /* Compute the vertical distance from PT to the scroll
11167 margin position. Give up if distance is greater than
11169 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11170 start_display (&it
, w
, pos
);
11172 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11173 it
.last_visible_y
, -1,
11174 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11175 dy
= it
.current_y
- y0
;
11176 if (dy
> scroll_max
)
11177 return SCROLLING_FAILED
;
11179 /* Compute new window start. */
11180 start_display (&it
, w
, startp
);
11182 if (scroll_conservatively
)
11184 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11185 else if (scroll_step
|| temp_scroll_step
)
11186 amount_to_scroll
= scroll_max
;
11189 aggressive
= current_buffer
->scroll_down_aggressively
;
11190 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11191 if (NUMBERP (aggressive
))
11193 double float_amount
= XFLOATINT (aggressive
) * height
;
11194 amount_to_scroll
= float_amount
;
11195 if (amount_to_scroll
== 0 && float_amount
> 0)
11196 amount_to_scroll
= 1;
11200 if (amount_to_scroll
<= 0)
11201 return SCROLLING_FAILED
;
11203 move_it_vertically_backward (&it
, amount_to_scroll
);
11204 startp
= it
.current
.pos
;
11208 /* Run window scroll functions. */
11209 startp
= run_window_scroll_functions (window
, startp
);
11211 /* Display the window. Give up if new fonts are loaded, or if point
11213 if (!try_window (window
, startp
))
11214 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11215 else if (w
->cursor
.vpos
< 0)
11217 clear_glyph_matrix (w
->desired_matrix
);
11218 rc
= SCROLLING_FAILED
;
11222 /* Maybe forget recorded base line for line number display. */
11223 if (!just_this_one_p
11224 || current_buffer
->clip_changed
11225 || BEG_UNCHANGED
< CHARPOS (startp
))
11226 w
->base_line_number
= Qnil
;
11228 /* If cursor ends up on a partially visible line,
11229 treat that as being off the bottom of the screen. */
11230 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11232 clear_glyph_matrix (w
->desired_matrix
);
11233 ++extra_scroll_margin_lines
;
11236 rc
= SCROLLING_SUCCESS
;
11243 /* Compute a suitable window start for window W if display of W starts
11244 on a continuation line. Value is non-zero if a new window start
11247 The new window start will be computed, based on W's width, starting
11248 from the start of the continued line. It is the start of the
11249 screen line with the minimum distance from the old start W->start. */
11252 compute_window_start_on_continuation_line (w
)
11255 struct text_pos pos
, start_pos
;
11256 int window_start_changed_p
= 0;
11258 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11260 /* If window start is on a continuation line... Window start may be
11261 < BEGV in case there's invisible text at the start of the
11262 buffer (M-x rmail, for example). */
11263 if (CHARPOS (start_pos
) > BEGV
11264 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11267 struct glyph_row
*row
;
11269 /* Handle the case that the window start is out of range. */
11270 if (CHARPOS (start_pos
) < BEGV
)
11271 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11272 else if (CHARPOS (start_pos
) > ZV
)
11273 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11275 /* Find the start of the continued line. This should be fast
11276 because scan_buffer is fast (newline cache). */
11277 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11278 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11279 row
, DEFAULT_FACE_ID
);
11280 reseat_at_previous_visible_line_start (&it
);
11282 /* If the line start is "too far" away from the window start,
11283 say it takes too much time to compute a new window start. */
11284 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11285 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11287 int min_distance
, distance
;
11289 /* Move forward by display lines to find the new window
11290 start. If window width was enlarged, the new start can
11291 be expected to be > the old start. If window width was
11292 decreased, the new window start will be < the old start.
11293 So, we're looking for the display line start with the
11294 minimum distance from the old window start. */
11295 pos
= it
.current
.pos
;
11296 min_distance
= INFINITY
;
11297 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11298 distance
< min_distance
)
11300 min_distance
= distance
;
11301 pos
= it
.current
.pos
;
11302 move_it_by_lines (&it
, 1, 0);
11305 /* Set the window start there. */
11306 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11307 window_start_changed_p
= 1;
11311 return window_start_changed_p
;
11315 /* Try cursor movement in case text has not changed in window WINDOW,
11316 with window start STARTP. Value is
11318 CURSOR_MOVEMENT_SUCCESS if successful
11320 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11322 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11323 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11324 we want to scroll as if scroll-step were set to 1. See the code.
11326 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11327 which case we have to abort this redisplay, and adjust matrices
11332 CURSOR_MOVEMENT_SUCCESS
,
11333 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11334 CURSOR_MOVEMENT_MUST_SCROLL
,
11335 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11339 try_cursor_movement (window
, startp
, scroll_step
)
11340 Lisp_Object window
;
11341 struct text_pos startp
;
11344 struct window
*w
= XWINDOW (window
);
11345 struct frame
*f
= XFRAME (w
->frame
);
11346 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11349 if (inhibit_try_cursor_movement
)
11353 /* Handle case where text has not changed, only point, and it has
11354 not moved off the frame. */
11355 if (/* Point may be in this window. */
11356 PT
>= CHARPOS (startp
)
11357 /* Selective display hasn't changed. */
11358 && !current_buffer
->clip_changed
11359 /* Function force-mode-line-update is used to force a thorough
11360 redisplay. It sets either windows_or_buffers_changed or
11361 update_mode_lines. So don't take a shortcut here for these
11363 && !update_mode_lines
11364 && !windows_or_buffers_changed
11365 && !cursor_type_changed
11366 /* Can't use this case if highlighting a region. When a
11367 region exists, cursor movement has to do more than just
11369 && !(!NILP (Vtransient_mark_mode
)
11370 && !NILP (current_buffer
->mark_active
))
11371 && NILP (w
->region_showing
)
11372 && NILP (Vshow_trailing_whitespace
)
11373 /* Right after splitting windows, last_point may be nil. */
11374 && INTEGERP (w
->last_point
)
11375 /* This code is not used for mini-buffer for the sake of the case
11376 of redisplaying to replace an echo area message; since in
11377 that case the mini-buffer contents per se are usually
11378 unchanged. This code is of no real use in the mini-buffer
11379 since the handling of this_line_start_pos, etc., in redisplay
11380 handles the same cases. */
11381 && !EQ (window
, minibuf_window
)
11382 /* When splitting windows or for new windows, it happens that
11383 redisplay is called with a nil window_end_vpos or one being
11384 larger than the window. This should really be fixed in
11385 window.c. I don't have this on my list, now, so we do
11386 approximately the same as the old redisplay code. --gerd. */
11387 && INTEGERP (w
->window_end_vpos
)
11388 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11389 && (FRAME_WINDOW_P (f
)
11390 || !overlay_arrow_in_current_buffer_p ()))
11392 int this_scroll_margin
, top_scroll_margin
;
11393 struct glyph_row
*row
= NULL
;
11396 debug_method_add (w
, "cursor movement");
11399 /* Scroll if point within this distance from the top or bottom
11400 of the window. This is a pixel value. */
11401 this_scroll_margin
= max (0, scroll_margin
);
11402 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11403 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11405 top_scroll_margin
= this_scroll_margin
;
11406 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11407 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11409 /* Start with the row the cursor was displayed during the last
11410 not paused redisplay. Give up if that row is not valid. */
11411 if (w
->last_cursor
.vpos
< 0
11412 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11413 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11416 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11417 if (row
->mode_line_p
)
11419 if (!row
->enabled_p
)
11420 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11423 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11426 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11428 if (PT
> XFASTINT (w
->last_point
))
11430 /* Point has moved forward. */
11431 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11432 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11434 xassert (row
->enabled_p
);
11438 /* The end position of a row equals the start position
11439 of the next row. If PT is there, we would rather
11440 display it in the next line. */
11441 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11442 && MATRIX_ROW_END_CHARPOS (row
) == PT
11443 && !cursor_row_p (w
, row
))
11446 /* If within the scroll margin, scroll. Note that
11447 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11448 the next line would be drawn, and that
11449 this_scroll_margin can be zero. */
11450 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11451 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11452 /* Line is completely visible last line in window
11453 and PT is to be set in the next line. */
11454 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11455 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11456 && !row
->ends_at_zv_p
11457 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11460 else if (PT
< XFASTINT (w
->last_point
))
11462 /* Cursor has to be moved backward. Note that PT >=
11463 CHARPOS (startp) because of the outer if-statement. */
11464 while (!row
->mode_line_p
11465 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11466 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11467 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11468 && (row
->y
> top_scroll_margin
11469 || CHARPOS (startp
) == BEGV
))
11471 xassert (row
->enabled_p
);
11475 /* Consider the following case: Window starts at BEGV,
11476 there is invisible, intangible text at BEGV, so that
11477 display starts at some point START > BEGV. It can
11478 happen that we are called with PT somewhere between
11479 BEGV and START. Try to handle that case. */
11480 if (row
< w
->current_matrix
->rows
11481 || row
->mode_line_p
)
11483 row
= w
->current_matrix
->rows
;
11484 if (row
->mode_line_p
)
11488 /* Due to newlines in overlay strings, we may have to
11489 skip forward over overlay strings. */
11490 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11491 && MATRIX_ROW_END_CHARPOS (row
) == PT
11492 && !cursor_row_p (w
, row
))
11495 /* If within the scroll margin, scroll. */
11496 if (row
->y
< top_scroll_margin
11497 && CHARPOS (startp
) != BEGV
)
11501 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11502 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11504 /* if PT is not in the glyph row, give up. */
11505 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11507 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11508 && make_cursor_line_fully_visible_p
)
11510 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11511 && !row
->ends_at_zv_p
11512 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11513 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11514 else if (row
->height
> window_box_height (w
))
11516 /* If we end up in a partially visible line, let's
11517 make it fully visible, except when it's taller
11518 than the window, in which case we can't do much
11521 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11525 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11526 if (!make_cursor_line_fully_visible (w
, 0))
11527 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11529 rc
= CURSOR_MOVEMENT_SUCCESS
;
11533 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11536 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11537 rc
= CURSOR_MOVEMENT_SUCCESS
;
11546 set_vertical_scroll_bar (w
)
11549 int start
, end
, whole
;
11551 /* Calculate the start and end positions for the current window.
11552 At some point, it would be nice to choose between scrollbars
11553 which reflect the whole buffer size, with special markers
11554 indicating narrowing, and scrollbars which reflect only the
11557 Note that mini-buffers sometimes aren't displaying any text. */
11558 if (!MINI_WINDOW_P (w
)
11559 || (w
== XWINDOW (minibuf_window
)
11560 && NILP (echo_area_buffer
[0])))
11562 struct buffer
*buf
= XBUFFER (w
->buffer
);
11563 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11564 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11565 /* I don't think this is guaranteed to be right. For the
11566 moment, we'll pretend it is. */
11567 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11571 if (whole
< (end
- start
))
11572 whole
= end
- start
;
11575 start
= end
= whole
= 0;
11577 /* Indicate what this scroll bar ought to be displaying now. */
11578 if (FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11579 (*FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11580 (w
, end
- start
, whole
, start
);
11584 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11585 selected_window is redisplayed.
11587 We can return without actually redisplaying the window if
11588 fonts_changed_p is nonzero. In that case, redisplay_internal will
11592 redisplay_window (window
, just_this_one_p
)
11593 Lisp_Object window
;
11594 int just_this_one_p
;
11596 struct window
*w
= XWINDOW (window
);
11597 struct frame
*f
= XFRAME (w
->frame
);
11598 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11599 struct buffer
*old
= current_buffer
;
11600 struct text_pos lpoint
, opoint
, startp
;
11601 int update_mode_line
;
11604 /* Record it now because it's overwritten. */
11605 int current_matrix_up_to_date_p
= 0;
11606 int used_current_matrix_p
= 0;
11607 /* This is less strict than current_matrix_up_to_date_p.
11608 It indictes that the buffer contents and narrowing are unchanged. */
11609 int buffer_unchanged_p
= 0;
11610 int temp_scroll_step
= 0;
11611 int count
= SPECPDL_INDEX ();
11613 int centering_position
;
11614 int last_line_misfit
= 0;
11616 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11619 /* W must be a leaf window here. */
11620 xassert (!NILP (w
->buffer
));
11622 *w
->desired_matrix
->method
= 0;
11625 /* Force this to be looked up again for each redisp of each window. */
11626 escape_glyph_face
= -1;
11628 specbind (Qinhibit_point_motion_hooks
, Qt
);
11630 reconsider_clip_changes (w
, buffer
);
11632 /* Has the mode line to be updated? */
11633 update_mode_line
= (!NILP (w
->update_mode_line
)
11634 || update_mode_lines
11635 || buffer
->clip_changed
11636 || buffer
->prevent_redisplay_optimizations_p
);
11638 if (MINI_WINDOW_P (w
))
11640 if (w
== XWINDOW (echo_area_window
)
11641 && !NILP (echo_area_buffer
[0]))
11643 if (update_mode_line
)
11644 /* We may have to update a tty frame's menu bar or a
11645 tool-bar. Example `M-x C-h C-h C-g'. */
11646 goto finish_menu_bars
;
11648 /* We've already displayed the echo area glyphs in this window. */
11649 goto finish_scroll_bars
;
11651 else if ((w
!= XWINDOW (minibuf_window
)
11652 || minibuf_level
== 0)
11653 /* When buffer is nonempty, redisplay window normally. */
11654 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11655 /* Quail displays non-mini buffers in minibuffer window.
11656 In that case, redisplay the window normally. */
11657 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11659 /* W is a mini-buffer window, but it's not active, so clear
11661 int yb
= window_text_bottom_y (w
);
11662 struct glyph_row
*row
;
11665 for (y
= 0, row
= w
->desired_matrix
->rows
;
11667 y
+= row
->height
, ++row
)
11668 blank_row (w
, row
, y
);
11669 goto finish_scroll_bars
;
11672 clear_glyph_matrix (w
->desired_matrix
);
11675 /* Otherwise set up data on this window; select its buffer and point
11677 /* Really select the buffer, for the sake of buffer-local
11679 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11680 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11682 current_matrix_up_to_date_p
11683 = (!NILP (w
->window_end_valid
)
11684 && !current_buffer
->clip_changed
11685 && !current_buffer
->prevent_redisplay_optimizations_p
11686 && XFASTINT (w
->last_modified
) >= MODIFF
11687 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11690 = (!NILP (w
->window_end_valid
)
11691 && !current_buffer
->clip_changed
11692 && XFASTINT (w
->last_modified
) >= MODIFF
11693 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11695 /* When windows_or_buffers_changed is non-zero, we can't rely on
11696 the window end being valid, so set it to nil there. */
11697 if (windows_or_buffers_changed
)
11699 /* If window starts on a continuation line, maybe adjust the
11700 window start in case the window's width changed. */
11701 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11702 compute_window_start_on_continuation_line (w
);
11704 w
->window_end_valid
= Qnil
;
11707 /* Some sanity checks. */
11708 CHECK_WINDOW_END (w
);
11709 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11711 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11714 /* If %c is in mode line, update it if needed. */
11715 if (!NILP (w
->column_number_displayed
)
11716 /* This alternative quickly identifies a common case
11717 where no change is needed. */
11718 && !(PT
== XFASTINT (w
->last_point
)
11719 && XFASTINT (w
->last_modified
) >= MODIFF
11720 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11721 && (XFASTINT (w
->column_number_displayed
)
11722 != (int) current_column ())) /* iftc */
11723 update_mode_line
= 1;
11725 /* Count number of windows showing the selected buffer. An indirect
11726 buffer counts as its base buffer. */
11727 if (!just_this_one_p
)
11729 struct buffer
*current_base
, *window_base
;
11730 current_base
= current_buffer
;
11731 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11732 if (current_base
->base_buffer
)
11733 current_base
= current_base
->base_buffer
;
11734 if (window_base
->base_buffer
)
11735 window_base
= window_base
->base_buffer
;
11736 if (current_base
== window_base
)
11740 /* Point refers normally to the selected window. For any other
11741 window, set up appropriate value. */
11742 if (!EQ (window
, selected_window
))
11744 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11745 int new_pt_byte
= marker_byte_position (w
->pointm
);
11749 new_pt_byte
= BEGV_BYTE
;
11750 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11752 else if (new_pt
> (ZV
- 1))
11755 new_pt_byte
= ZV_BYTE
;
11756 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11759 /* We don't use SET_PT so that the point-motion hooks don't run. */
11760 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11763 /* If any of the character widths specified in the display table
11764 have changed, invalidate the width run cache. It's true that
11765 this may be a bit late to catch such changes, but the rest of
11766 redisplay goes (non-fatally) haywire when the display table is
11767 changed, so why should we worry about doing any better? */
11768 if (current_buffer
->width_run_cache
)
11770 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11772 if (! disptab_matches_widthtab (disptab
,
11773 XVECTOR (current_buffer
->width_table
)))
11775 invalidate_region_cache (current_buffer
,
11776 current_buffer
->width_run_cache
,
11778 recompute_width_table (current_buffer
, disptab
);
11782 /* If window-start is screwed up, choose a new one. */
11783 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11786 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11788 /* If someone specified a new starting point but did not insist,
11789 check whether it can be used. */
11790 if (!NILP (w
->optional_new_start
)
11791 && CHARPOS (startp
) >= BEGV
11792 && CHARPOS (startp
) <= ZV
)
11794 w
->optional_new_start
= Qnil
;
11795 start_display (&it
, w
, startp
);
11796 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11797 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11798 if (IT_CHARPOS (it
) == PT
)
11799 w
->force_start
= Qt
;
11800 /* IT may overshoot PT if text at PT is invisible. */
11801 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11802 w
->force_start
= Qt
;
11807 /* Handle case where place to start displaying has been specified,
11808 unless the specified location is outside the accessible range. */
11809 if (!NILP (w
->force_start
)
11810 || w
->frozen_window_start_p
)
11812 /* We set this later on if we have to adjust point. */
11815 w
->force_start
= Qnil
;
11817 w
->window_end_valid
= Qnil
;
11819 /* Forget any recorded base line for line number display. */
11820 if (!buffer_unchanged_p
)
11821 w
->base_line_number
= Qnil
;
11823 /* Redisplay the mode line. Select the buffer properly for that.
11824 Also, run the hook window-scroll-functions
11825 because we have scrolled. */
11826 /* Note, we do this after clearing force_start because
11827 if there's an error, it is better to forget about force_start
11828 than to get into an infinite loop calling the hook functions
11829 and having them get more errors. */
11830 if (!update_mode_line
11831 || ! NILP (Vwindow_scroll_functions
))
11833 update_mode_line
= 1;
11834 w
->update_mode_line
= Qt
;
11835 startp
= run_window_scroll_functions (window
, startp
);
11838 w
->last_modified
= make_number (0);
11839 w
->last_overlay_modified
= make_number (0);
11840 if (CHARPOS (startp
) < BEGV
)
11841 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11842 else if (CHARPOS (startp
) > ZV
)
11843 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11845 /* Redisplay, then check if cursor has been set during the
11846 redisplay. Give up if new fonts were loaded. */
11847 if (!try_window (window
, startp
))
11849 w
->force_start
= Qt
;
11850 clear_glyph_matrix (w
->desired_matrix
);
11851 goto need_larger_matrices
;
11854 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11856 /* If point does not appear, try to move point so it does
11857 appear. The desired matrix has been built above, so we
11858 can use it here. */
11859 new_vpos
= window_box_height (w
) / 2;
11862 if (!make_cursor_line_fully_visible (w
, 0))
11864 /* Point does appear, but on a line partly visible at end of window.
11865 Move it back to a fully-visible line. */
11866 new_vpos
= window_box_height (w
);
11869 /* If we need to move point for either of the above reasons,
11870 now actually do it. */
11873 struct glyph_row
*row
;
11875 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11876 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11879 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11880 MATRIX_ROW_START_BYTEPOS (row
));
11882 if (w
!= XWINDOW (selected_window
))
11883 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11884 else if (current_buffer
== old
)
11885 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11887 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11889 /* If we are highlighting the region, then we just changed
11890 the region, so redisplay to show it. */
11891 if (!NILP (Vtransient_mark_mode
)
11892 && !NILP (current_buffer
->mark_active
))
11894 clear_glyph_matrix (w
->desired_matrix
);
11895 if (!try_window (window
, startp
))
11896 goto need_larger_matrices
;
11901 debug_method_add (w
, "forced window start");
11906 /* Handle case where text has not changed, only point, and it has
11907 not moved off the frame, and we are not retrying after hscroll.
11908 (current_matrix_up_to_date_p is nonzero when retrying.) */
11909 if (current_matrix_up_to_date_p
11910 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11911 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11915 case CURSOR_MOVEMENT_SUCCESS
:
11916 used_current_matrix_p
= 1;
11919 #if 0 /* try_cursor_movement never returns this value. */
11920 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11921 goto need_larger_matrices
;
11924 case CURSOR_MOVEMENT_MUST_SCROLL
:
11925 goto try_to_scroll
;
11931 /* If current starting point was originally the beginning of a line
11932 but no longer is, find a new starting point. */
11933 else if (!NILP (w
->start_at_line_beg
)
11934 && !(CHARPOS (startp
) <= BEGV
11935 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11938 debug_method_add (w
, "recenter 1");
11943 /* Try scrolling with try_window_id. Value is > 0 if update has
11944 been done, it is -1 if we know that the same window start will
11945 not work. It is 0 if unsuccessful for some other reason. */
11946 else if ((tem
= try_window_id (w
)) != 0)
11949 debug_method_add (w
, "try_window_id %d", tem
);
11952 if (fonts_changed_p
)
11953 goto need_larger_matrices
;
11957 /* Otherwise try_window_id has returned -1 which means that we
11958 don't want the alternative below this comment to execute. */
11960 else if (CHARPOS (startp
) >= BEGV
11961 && CHARPOS (startp
) <= ZV
11962 && PT
>= CHARPOS (startp
)
11963 && (CHARPOS (startp
) < ZV
11964 /* Avoid starting at end of buffer. */
11965 || CHARPOS (startp
) == BEGV
11966 || (XFASTINT (w
->last_modified
) >= MODIFF
11967 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11970 debug_method_add (w
, "same window start");
11973 /* Try to redisplay starting at same place as before.
11974 If point has not moved off frame, accept the results. */
11975 if (!current_matrix_up_to_date_p
11976 /* Don't use try_window_reusing_current_matrix in this case
11977 because a window scroll function can have changed the
11979 || !NILP (Vwindow_scroll_functions
)
11980 || MINI_WINDOW_P (w
)
11981 || !(used_current_matrix_p
11982 = try_window_reusing_current_matrix (w
)))
11984 IF_DEBUG (debug_method_add (w
, "1"));
11985 try_window (window
, startp
);
11988 if (fonts_changed_p
)
11989 goto need_larger_matrices
;
11991 if (w
->cursor
.vpos
>= 0)
11993 if (!just_this_one_p
11994 || current_buffer
->clip_changed
11995 || BEG_UNCHANGED
< CHARPOS (startp
))
11996 /* Forget any recorded base line for line number display. */
11997 w
->base_line_number
= Qnil
;
11999 if (!make_cursor_line_fully_visible (w
, 1))
12001 clear_glyph_matrix (w
->desired_matrix
);
12002 last_line_misfit
= 1;
12004 /* Drop through and scroll. */
12009 clear_glyph_matrix (w
->desired_matrix
);
12014 w
->last_modified
= make_number (0);
12015 w
->last_overlay_modified
= make_number (0);
12017 /* Redisplay the mode line. Select the buffer properly for that. */
12018 if (!update_mode_line
)
12020 update_mode_line
= 1;
12021 w
->update_mode_line
= Qt
;
12024 /* Try to scroll by specified few lines. */
12025 if ((scroll_conservatively
12027 || temp_scroll_step
12028 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12029 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12030 && !current_buffer
->clip_changed
12031 && CHARPOS (startp
) >= BEGV
12032 && CHARPOS (startp
) <= ZV
)
12034 /* The function returns -1 if new fonts were loaded, 1 if
12035 successful, 0 if not successful. */
12036 int rc
= try_scrolling (window
, just_this_one_p
,
12037 scroll_conservatively
,
12039 temp_scroll_step
, last_line_misfit
);
12042 case SCROLLING_SUCCESS
:
12045 case SCROLLING_NEED_LARGER_MATRICES
:
12046 goto need_larger_matrices
;
12048 case SCROLLING_FAILED
:
12056 /* Finally, just choose place to start which centers point */
12059 centering_position
= window_box_height (w
) / 2;
12062 /* Jump here with centering_position already set to 0. */
12065 debug_method_add (w
, "recenter");
12068 /* w->vscroll = 0; */
12070 /* Forget any previously recorded base line for line number display. */
12071 if (!buffer_unchanged_p
)
12072 w
->base_line_number
= Qnil
;
12074 /* Move backward half the height of the window. */
12075 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12076 it
.current_y
= it
.last_visible_y
;
12077 move_it_vertically_backward (&it
, centering_position
);
12078 xassert (IT_CHARPOS (it
) >= BEGV
);
12080 /* The function move_it_vertically_backward may move over more
12081 than the specified y-distance. If it->w is small, e.g. a
12082 mini-buffer window, we may end up in front of the window's
12083 display area. Start displaying at the start of the line
12084 containing PT in this case. */
12085 if (it
.current_y
<= 0)
12087 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12088 move_it_vertically_backward (&it
, 0);
12089 xassert (IT_CHARPOS (it
) <= PT
);
12093 it
.current_x
= it
.hpos
= 0;
12095 /* Set startp here explicitly in case that helps avoid an infinite loop
12096 in case the window-scroll-functions functions get errors. */
12097 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12099 /* Run scroll hooks. */
12100 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12102 /* Redisplay the window. */
12103 if (!current_matrix_up_to_date_p
12104 || windows_or_buffers_changed
12105 || cursor_type_changed
12106 /* Don't use try_window_reusing_current_matrix in this case
12107 because it can have changed the buffer. */
12108 || !NILP (Vwindow_scroll_functions
)
12109 || !just_this_one_p
12110 || MINI_WINDOW_P (w
)
12111 || !(used_current_matrix_p
12112 = try_window_reusing_current_matrix (w
)))
12113 try_window (window
, startp
);
12115 /* If new fonts have been loaded (due to fontsets), give up. We
12116 have to start a new redisplay since we need to re-adjust glyph
12118 if (fonts_changed_p
)
12119 goto need_larger_matrices
;
12121 /* If cursor did not appear assume that the middle of the window is
12122 in the first line of the window. Do it again with the next line.
12123 (Imagine a window of height 100, displaying two lines of height
12124 60. Moving back 50 from it->last_visible_y will end in the first
12126 if (w
->cursor
.vpos
< 0)
12128 if (!NILP (w
->window_end_valid
)
12129 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12131 clear_glyph_matrix (w
->desired_matrix
);
12132 move_it_by_lines (&it
, 1, 0);
12133 try_window (window
, it
.current
.pos
);
12135 else if (PT
< IT_CHARPOS (it
))
12137 clear_glyph_matrix (w
->desired_matrix
);
12138 move_it_by_lines (&it
, -1, 0);
12139 try_window (window
, it
.current
.pos
);
12143 /* Not much we can do about it. */
12147 /* Consider the following case: Window starts at BEGV, there is
12148 invisible, intangible text at BEGV, so that display starts at
12149 some point START > BEGV. It can happen that we are called with
12150 PT somewhere between BEGV and START. Try to handle that case. */
12151 if (w
->cursor
.vpos
< 0)
12153 struct glyph_row
*row
= w
->current_matrix
->rows
;
12154 if (row
->mode_line_p
)
12156 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12159 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12161 /* If vscroll is enabled, disable it and try again. */
12165 clear_glyph_matrix (w
->desired_matrix
);
12169 /* If centering point failed to make the whole line visible,
12170 put point at the top instead. That has to make the whole line
12171 visible, if it can be done. */
12172 clear_glyph_matrix (w
->desired_matrix
);
12173 centering_position
= 0;
12179 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12180 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12181 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12184 /* Display the mode line, if we must. */
12185 if ((update_mode_line
12186 /* If window not full width, must redo its mode line
12187 if (a) the window to its side is being redone and
12188 (b) we do a frame-based redisplay. This is a consequence
12189 of how inverted lines are drawn in frame-based redisplay. */
12190 || (!just_this_one_p
12191 && !FRAME_WINDOW_P (f
)
12192 && !WINDOW_FULL_WIDTH_P (w
))
12193 /* Line number to display. */
12194 || INTEGERP (w
->base_line_pos
)
12195 /* Column number is displayed and different from the one displayed. */
12196 || (!NILP (w
->column_number_displayed
)
12197 && (XFASTINT (w
->column_number_displayed
)
12198 != (int) current_column ()))) /* iftc */
12199 /* This means that the window has a mode line. */
12200 && (WINDOW_WANTS_MODELINE_P (w
)
12201 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12203 display_mode_lines (w
);
12205 /* If mode line height has changed, arrange for a thorough
12206 immediate redisplay using the correct mode line height. */
12207 if (WINDOW_WANTS_MODELINE_P (w
)
12208 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12210 fonts_changed_p
= 1;
12211 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12212 = DESIRED_MODE_LINE_HEIGHT (w
);
12215 /* If top line height has changed, arrange for a thorough
12216 immediate redisplay using the correct mode line height. */
12217 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12218 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12220 fonts_changed_p
= 1;
12221 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12222 = DESIRED_HEADER_LINE_HEIGHT (w
);
12225 if (fonts_changed_p
)
12226 goto need_larger_matrices
;
12229 if (!line_number_displayed
12230 && !BUFFERP (w
->base_line_pos
))
12232 w
->base_line_pos
= Qnil
;
12233 w
->base_line_number
= Qnil
;
12238 /* When we reach a frame's selected window, redo the frame's menu bar. */
12239 if (update_mode_line
12240 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12242 int redisplay_menu_p
= 0;
12243 int redisplay_tool_bar_p
= 0;
12245 if (FRAME_WINDOW_P (f
))
12247 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12248 || defined (USE_GTK)
12249 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12251 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12255 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12257 if (redisplay_menu_p
)
12258 display_menu_bar (w
);
12260 #ifdef HAVE_WINDOW_SYSTEM
12261 if (FRAME_WINDOW_P (f
))
12264 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12266 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12267 && (FRAME_TOOL_BAR_LINES (f
) > 0
12268 || auto_resize_tool_bars_p
);
12271 if (redisplay_tool_bar_p
)
12272 redisplay_tool_bar (f
);
12277 #ifdef HAVE_WINDOW_SYSTEM
12278 if (FRAME_WINDOW_P (f
)
12279 && update_window_fringes (w
, 0)
12280 && !just_this_one_p
12281 && (used_current_matrix_p
|| overlay_arrow_seen
)
12282 && !w
->pseudo_window_p
)
12286 if (draw_window_fringes (w
, 1))
12287 x_draw_vertical_border (w
);
12291 #endif /* HAVE_WINDOW_SYSTEM */
12293 /* We go to this label, with fonts_changed_p nonzero,
12294 if it is necessary to try again using larger glyph matrices.
12295 We have to redeem the scroll bar even in this case,
12296 because the loop in redisplay_internal expects that. */
12297 need_larger_matrices
:
12299 finish_scroll_bars
:
12301 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12303 /* Set the thumb's position and size. */
12304 set_vertical_scroll_bar (w
);
12306 /* Note that we actually used the scroll bar attached to this
12307 window, so it shouldn't be deleted at the end of redisplay. */
12308 if (FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
)
12309 (*FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
) (w
);
12312 /* Restore current_buffer and value of point in it. */
12313 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12314 set_buffer_internal_1 (old
);
12315 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12317 unbind_to (count
, Qnil
);
12321 /* Build the complete desired matrix of WINDOW with a window start
12322 buffer position POS. Value is non-zero if successful. It is zero
12323 if fonts were loaded during redisplay which makes re-adjusting
12324 glyph matrices necessary. */
12327 try_window (window
, pos
)
12328 Lisp_Object window
;
12329 struct text_pos pos
;
12331 struct window
*w
= XWINDOW (window
);
12333 struct glyph_row
*last_text_row
= NULL
;
12335 /* Make POS the new window start. */
12336 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12338 /* Mark cursor position as unknown. No overlay arrow seen. */
12339 w
->cursor
.vpos
= -1;
12340 overlay_arrow_seen
= 0;
12342 /* Initialize iterator and info to start at POS. */
12343 start_display (&it
, w
, pos
);
12345 /* Display all lines of W. */
12346 while (it
.current_y
< it
.last_visible_y
)
12348 if (display_line (&it
))
12349 last_text_row
= it
.glyph_row
- 1;
12350 if (fonts_changed_p
)
12354 /* If bottom moved off end of frame, change mode line percentage. */
12355 if (XFASTINT (w
->window_end_pos
) <= 0
12356 && Z
!= IT_CHARPOS (it
))
12357 w
->update_mode_line
= Qt
;
12359 /* Set window_end_pos to the offset of the last character displayed
12360 on the window from the end of current_buffer. Set
12361 window_end_vpos to its row number. */
12364 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12365 w
->window_end_bytepos
12366 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12368 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12370 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12371 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12372 ->displays_text_p
);
12376 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12377 w
->window_end_pos
= make_number (Z
- ZV
);
12378 w
->window_end_vpos
= make_number (0);
12381 /* But that is not valid info until redisplay finishes. */
12382 w
->window_end_valid
= Qnil
;
12388 /************************************************************************
12389 Window redisplay reusing current matrix when buffer has not changed
12390 ************************************************************************/
12392 /* Try redisplay of window W showing an unchanged buffer with a
12393 different window start than the last time it was displayed by
12394 reusing its current matrix. Value is non-zero if successful.
12395 W->start is the new window start. */
12398 try_window_reusing_current_matrix (w
)
12401 struct frame
*f
= XFRAME (w
->frame
);
12402 struct glyph_row
*row
, *bottom_row
;
12405 struct text_pos start
, new_start
;
12406 int nrows_scrolled
, i
;
12407 struct glyph_row
*last_text_row
;
12408 struct glyph_row
*last_reused_text_row
;
12409 struct glyph_row
*start_row
;
12410 int start_vpos
, min_y
, max_y
;
12413 if (inhibit_try_window_reusing
)
12417 if (/* This function doesn't handle terminal frames. */
12418 !FRAME_WINDOW_P (f
)
12419 /* Don't try to reuse the display if windows have been split
12421 || windows_or_buffers_changed
12422 || cursor_type_changed
)
12425 /* Can't do this if region may have changed. */
12426 if ((!NILP (Vtransient_mark_mode
)
12427 && !NILP (current_buffer
->mark_active
))
12428 || !NILP (w
->region_showing
)
12429 || !NILP (Vshow_trailing_whitespace
))
12432 /* If top-line visibility has changed, give up. */
12433 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12434 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12437 /* Give up if old or new display is scrolled vertically. We could
12438 make this function handle this, but right now it doesn't. */
12439 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12440 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12443 /* The variable new_start now holds the new window start. The old
12444 start `start' can be determined from the current matrix. */
12445 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12446 start
= start_row
->start
.pos
;
12447 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12449 /* Clear the desired matrix for the display below. */
12450 clear_glyph_matrix (w
->desired_matrix
);
12452 if (CHARPOS (new_start
) <= CHARPOS (start
))
12456 /* Don't use this method if the display starts with an ellipsis
12457 displayed for invisible text. It's not easy to handle that case
12458 below, and it's certainly not worth the effort since this is
12459 not a frequent case. */
12460 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12463 IF_DEBUG (debug_method_add (w
, "twu1"));
12465 /* Display up to a row that can be reused. The variable
12466 last_text_row is set to the last row displayed that displays
12467 text. Note that it.vpos == 0 if or if not there is a
12468 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12469 start_display (&it
, w
, new_start
);
12470 first_row_y
= it
.current_y
;
12471 w
->cursor
.vpos
= -1;
12472 last_text_row
= last_reused_text_row
= NULL
;
12474 while (it
.current_y
< it
.last_visible_y
12475 && !fonts_changed_p
)
12477 /* If we have reached into the characters in the START row,
12478 that means the line boundaries have changed. So we
12479 can't start copying with the row START. Maybe it will
12480 work to start copying with the following row. */
12481 while (IT_CHARPOS (it
) > CHARPOS (start
))
12483 /* Advance to the next row as the "start". */
12485 start
= start_row
->start
.pos
;
12486 /* If there are no more rows to try, or just one, give up. */
12487 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12488 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12489 || CHARPOS (start
) == ZV
)
12491 clear_glyph_matrix (w
->desired_matrix
);
12495 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12497 /* If we have reached alignment,
12498 we can copy the rest of the rows. */
12499 if (IT_CHARPOS (it
) == CHARPOS (start
))
12502 if (display_line (&it
))
12503 last_text_row
= it
.glyph_row
- 1;
12506 /* A value of current_y < last_visible_y means that we stopped
12507 at the previous window start, which in turn means that we
12508 have at least one reusable row. */
12509 if (it
.current_y
< it
.last_visible_y
)
12511 /* IT.vpos always starts from 0; it counts text lines. */
12512 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12514 /* Find PT if not already found in the lines displayed. */
12515 if (w
->cursor
.vpos
< 0)
12517 int dy
= it
.current_y
- start_row
->y
;
12519 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12520 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12522 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12523 dy
, nrows_scrolled
);
12526 clear_glyph_matrix (w
->desired_matrix
);
12531 /* Scroll the display. Do it before the current matrix is
12532 changed. The problem here is that update has not yet
12533 run, i.e. part of the current matrix is not up to date.
12534 scroll_run_hook will clear the cursor, and use the
12535 current matrix to get the height of the row the cursor is
12537 run
.current_y
= start_row
->y
;
12538 run
.desired_y
= it
.current_y
;
12539 run
.height
= it
.last_visible_y
- it
.current_y
;
12541 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12544 FRAME_RIF (f
)->update_window_begin_hook (w
);
12545 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12546 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12547 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12551 /* Shift current matrix down by nrows_scrolled lines. */
12552 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12553 rotate_matrix (w
->current_matrix
,
12555 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12558 /* Disable lines that must be updated. */
12559 for (i
= 0; i
< it
.vpos
; ++i
)
12560 (start_row
+ i
)->enabled_p
= 0;
12562 /* Re-compute Y positions. */
12563 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12564 max_y
= it
.last_visible_y
;
12565 for (row
= start_row
+ nrows_scrolled
;
12569 row
->y
= it
.current_y
;
12570 row
->visible_height
= row
->height
;
12572 if (row
->y
< min_y
)
12573 row
->visible_height
-= min_y
- row
->y
;
12574 if (row
->y
+ row
->height
> max_y
)
12575 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12576 row
->redraw_fringe_bitmaps_p
= 1;
12578 it
.current_y
+= row
->height
;
12580 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12581 last_reused_text_row
= row
;
12582 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12586 /* Disable lines in the current matrix which are now
12587 below the window. */
12588 for (++row
; row
< bottom_row
; ++row
)
12589 row
->enabled_p
= 0;
12592 /* Update window_end_pos etc.; last_reused_text_row is the last
12593 reused row from the current matrix containing text, if any.
12594 The value of last_text_row is the last displayed line
12595 containing text. */
12596 if (last_reused_text_row
)
12598 w
->window_end_bytepos
12599 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12601 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12603 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12604 w
->current_matrix
));
12606 else if (last_text_row
)
12608 w
->window_end_bytepos
12609 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12611 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12613 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12617 /* This window must be completely empty. */
12618 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12619 w
->window_end_pos
= make_number (Z
- ZV
);
12620 w
->window_end_vpos
= make_number (0);
12622 w
->window_end_valid
= Qnil
;
12624 /* Update hint: don't try scrolling again in update_window. */
12625 w
->desired_matrix
->no_scrolling_p
= 1;
12628 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12632 else if (CHARPOS (new_start
) > CHARPOS (start
))
12634 struct glyph_row
*pt_row
, *row
;
12635 struct glyph_row
*first_reusable_row
;
12636 struct glyph_row
*first_row_to_display
;
12638 int yb
= window_text_bottom_y (w
);
12640 /* Find the row starting at new_start, if there is one. Don't
12641 reuse a partially visible line at the end. */
12642 first_reusable_row
= start_row
;
12643 while (first_reusable_row
->enabled_p
12644 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12645 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12646 < CHARPOS (new_start
)))
12647 ++first_reusable_row
;
12649 /* Give up if there is no row to reuse. */
12650 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12651 || !first_reusable_row
->enabled_p
12652 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12653 != CHARPOS (new_start
)))
12656 /* We can reuse fully visible rows beginning with
12657 first_reusable_row to the end of the window. Set
12658 first_row_to_display to the first row that cannot be reused.
12659 Set pt_row to the row containing point, if there is any. */
12661 for (first_row_to_display
= first_reusable_row
;
12662 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12663 ++first_row_to_display
)
12665 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12666 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12667 pt_row
= first_row_to_display
;
12670 /* Start displaying at the start of first_row_to_display. */
12671 xassert (first_row_to_display
->y
< yb
);
12672 init_to_row_start (&it
, w
, first_row_to_display
);
12674 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12676 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12678 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12679 + WINDOW_HEADER_LINE_HEIGHT (w
));
12681 /* Display lines beginning with first_row_to_display in the
12682 desired matrix. Set last_text_row to the last row displayed
12683 that displays text. */
12684 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12685 if (pt_row
== NULL
)
12686 w
->cursor
.vpos
= -1;
12687 last_text_row
= NULL
;
12688 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12689 if (display_line (&it
))
12690 last_text_row
= it
.glyph_row
- 1;
12692 /* Give up If point isn't in a row displayed or reused. */
12693 if (w
->cursor
.vpos
< 0)
12695 clear_glyph_matrix (w
->desired_matrix
);
12699 /* If point is in a reused row, adjust y and vpos of the cursor
12703 w
->cursor
.vpos
-= nrows_scrolled
;
12704 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
12707 /* Scroll the display. */
12708 run
.current_y
= first_reusable_row
->y
;
12709 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12710 run
.height
= it
.last_visible_y
- run
.current_y
;
12711 dy
= run
.current_y
- run
.desired_y
;
12716 FRAME_RIF (f
)->update_window_begin_hook (w
);
12717 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12718 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12719 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12723 /* Adjust Y positions of reused rows. */
12724 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12725 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12726 max_y
= it
.last_visible_y
;
12727 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12730 row
->visible_height
= row
->height
;
12731 if (row
->y
< min_y
)
12732 row
->visible_height
-= min_y
- row
->y
;
12733 if (row
->y
+ row
->height
> max_y
)
12734 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12735 row
->redraw_fringe_bitmaps_p
= 1;
12738 /* Scroll the current matrix. */
12739 xassert (nrows_scrolled
> 0);
12740 rotate_matrix (w
->current_matrix
,
12742 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12745 /* Disable rows not reused. */
12746 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12747 row
->enabled_p
= 0;
12749 /* Point may have moved to a different line, so we cannot assume that
12750 the previous cursor position is valid; locate the correct row. */
12753 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12754 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
12758 w
->cursor
.y
= row
->y
;
12760 if (row
< bottom_row
)
12762 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
12763 while (glyph
->charpos
< PT
)
12766 w
->cursor
.x
+= glyph
->pixel_width
;
12772 /* Adjust window end. A null value of last_text_row means that
12773 the window end is in reused rows which in turn means that
12774 only its vpos can have changed. */
12777 w
->window_end_bytepos
12778 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12780 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12782 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12787 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12790 w
->window_end_valid
= Qnil
;
12791 w
->desired_matrix
->no_scrolling_p
= 1;
12794 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12804 /************************************************************************
12805 Window redisplay reusing current matrix when buffer has changed
12806 ************************************************************************/
12808 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12809 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12811 static struct glyph_row
*
12812 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12813 struct glyph_row
*));
12816 /* Return the last row in MATRIX displaying text. If row START is
12817 non-null, start searching with that row. IT gives the dimensions
12818 of the display. Value is null if matrix is empty; otherwise it is
12819 a pointer to the row found. */
12821 static struct glyph_row
*
12822 find_last_row_displaying_text (matrix
, it
, start
)
12823 struct glyph_matrix
*matrix
;
12825 struct glyph_row
*start
;
12827 struct glyph_row
*row
, *row_found
;
12829 /* Set row_found to the last row in IT->w's current matrix
12830 displaying text. The loop looks funny but think of partially
12833 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12834 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12836 xassert (row
->enabled_p
);
12838 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12847 /* Return the last row in the current matrix of W that is not affected
12848 by changes at the start of current_buffer that occurred since W's
12849 current matrix was built. Value is null if no such row exists.
12851 BEG_UNCHANGED us the number of characters unchanged at the start of
12852 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12853 first changed character in current_buffer. Characters at positions <
12854 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12855 when the current matrix was built. */
12857 static struct glyph_row
*
12858 find_last_unchanged_at_beg_row (w
)
12861 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12862 struct glyph_row
*row
;
12863 struct glyph_row
*row_found
= NULL
;
12864 int yb
= window_text_bottom_y (w
);
12866 /* Find the last row displaying unchanged text. */
12867 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12868 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12869 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12871 if (/* If row ends before first_changed_pos, it is unchanged,
12872 except in some case. */
12873 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12874 /* When row ends in ZV and we write at ZV it is not
12876 && !row
->ends_at_zv_p
12877 /* When first_changed_pos is the end of a continued line,
12878 row is not unchanged because it may be no longer
12880 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12881 && (row
->continued_p
12882 || row
->exact_window_width_line_p
)))
12885 /* Stop if last visible row. */
12886 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12896 /* Find the first glyph row in the current matrix of W that is not
12897 affected by changes at the end of current_buffer since the
12898 time W's current matrix was built.
12900 Return in *DELTA the number of chars by which buffer positions in
12901 unchanged text at the end of current_buffer must be adjusted.
12903 Return in *DELTA_BYTES the corresponding number of bytes.
12905 Value is null if no such row exists, i.e. all rows are affected by
12908 static struct glyph_row
*
12909 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12911 int *delta
, *delta_bytes
;
12913 struct glyph_row
*row
;
12914 struct glyph_row
*row_found
= NULL
;
12916 *delta
= *delta_bytes
= 0;
12918 /* Display must not have been paused, otherwise the current matrix
12919 is not up to date. */
12920 if (NILP (w
->window_end_valid
))
12923 /* A value of window_end_pos >= END_UNCHANGED means that the window
12924 end is in the range of changed text. If so, there is no
12925 unchanged row at the end of W's current matrix. */
12926 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12929 /* Set row to the last row in W's current matrix displaying text. */
12930 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12932 /* If matrix is entirely empty, no unchanged row exists. */
12933 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12935 /* The value of row is the last glyph row in the matrix having a
12936 meaningful buffer position in it. The end position of row
12937 corresponds to window_end_pos. This allows us to translate
12938 buffer positions in the current matrix to current buffer
12939 positions for characters not in changed text. */
12940 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12941 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12942 int last_unchanged_pos
, last_unchanged_pos_old
;
12943 struct glyph_row
*first_text_row
12944 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12946 *delta
= Z
- Z_old
;
12947 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12949 /* Set last_unchanged_pos to the buffer position of the last
12950 character in the buffer that has not been changed. Z is the
12951 index + 1 of the last character in current_buffer, i.e. by
12952 subtracting END_UNCHANGED we get the index of the last
12953 unchanged character, and we have to add BEG to get its buffer
12955 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12956 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12958 /* Search backward from ROW for a row displaying a line that
12959 starts at a minimum position >= last_unchanged_pos_old. */
12960 for (; row
> first_text_row
; --row
)
12962 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12965 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12970 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12977 /* Make sure that glyph rows in the current matrix of window W
12978 reference the same glyph memory as corresponding rows in the
12979 frame's frame matrix. This function is called after scrolling W's
12980 current matrix on a terminal frame in try_window_id and
12981 try_window_reusing_current_matrix. */
12984 sync_frame_with_window_matrix_rows (w
)
12987 struct frame
*f
= XFRAME (w
->frame
);
12988 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12990 /* Preconditions: W must be a leaf window and full-width. Its frame
12991 must have a frame matrix. */
12992 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12993 xassert (WINDOW_FULL_WIDTH_P (w
));
12994 xassert (!FRAME_WINDOW_P (f
));
12996 /* If W is a full-width window, glyph pointers in W's current matrix
12997 have, by definition, to be the same as glyph pointers in the
12998 corresponding frame matrix. Note that frame matrices have no
12999 marginal areas (see build_frame_matrix). */
13000 window_row
= w
->current_matrix
->rows
;
13001 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13002 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13003 while (window_row
< window_row_end
)
13005 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13006 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13008 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13009 frame_row
->glyphs
[TEXT_AREA
] = start
;
13010 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13011 frame_row
->glyphs
[LAST_AREA
] = end
;
13013 /* Disable frame rows whose corresponding window rows have
13014 been disabled in try_window_id. */
13015 if (!window_row
->enabled_p
)
13016 frame_row
->enabled_p
= 0;
13018 ++window_row
, ++frame_row
;
13023 /* Find the glyph row in window W containing CHARPOS. Consider all
13024 rows between START and END (not inclusive). END null means search
13025 all rows to the end of the display area of W. Value is the row
13026 containing CHARPOS or null. */
13029 row_containing_pos (w
, charpos
, start
, end
, dy
)
13032 struct glyph_row
*start
, *end
;
13035 struct glyph_row
*row
= start
;
13038 /* If we happen to start on a header-line, skip that. */
13039 if (row
->mode_line_p
)
13042 if ((end
&& row
>= end
) || !row
->enabled_p
)
13045 last_y
= window_text_bottom_y (w
) - dy
;
13049 /* Give up if we have gone too far. */
13050 if (end
&& row
>= end
)
13052 /* This formerly returned if they were equal.
13053 I think that both quantities are of a "last plus one" type;
13054 if so, when they are equal, the row is within the screen. -- rms. */
13055 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13058 /* If it is in this row, return this row. */
13059 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13060 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13061 /* The end position of a row equals the start
13062 position of the next row. If CHARPOS is there, we
13063 would rather display it in the next line, except
13064 when this line ends in ZV. */
13065 && !row
->ends_at_zv_p
13066 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13067 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13074 /* Try to redisplay window W by reusing its existing display. W's
13075 current matrix must be up to date when this function is called,
13076 i.e. window_end_valid must not be nil.
13080 1 if display has been updated
13081 0 if otherwise unsuccessful
13082 -1 if redisplay with same window start is known not to succeed
13084 The following steps are performed:
13086 1. Find the last row in the current matrix of W that is not
13087 affected by changes at the start of current_buffer. If no such row
13090 2. Find the first row in W's current matrix that is not affected by
13091 changes at the end of current_buffer. Maybe there is no such row.
13093 3. Display lines beginning with the row + 1 found in step 1 to the
13094 row found in step 2 or, if step 2 didn't find a row, to the end of
13097 4. If cursor is not known to appear on the window, give up.
13099 5. If display stopped at the row found in step 2, scroll the
13100 display and current matrix as needed.
13102 6. Maybe display some lines at the end of W, if we must. This can
13103 happen under various circumstances, like a partially visible line
13104 becoming fully visible, or because newly displayed lines are displayed
13105 in smaller font sizes.
13107 7. Update W's window end information. */
13113 struct frame
*f
= XFRAME (w
->frame
);
13114 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13115 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13116 struct glyph_row
*last_unchanged_at_beg_row
;
13117 struct glyph_row
*first_unchanged_at_end_row
;
13118 struct glyph_row
*row
;
13119 struct glyph_row
*bottom_row
;
13122 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13123 struct text_pos start_pos
;
13125 int first_unchanged_at_end_vpos
= 0;
13126 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13127 struct text_pos start
;
13128 int first_changed_charpos
, last_changed_charpos
;
13131 if (inhibit_try_window_id
)
13135 /* This is handy for debugging. */
13137 #define GIVE_UP(X) \
13139 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13143 #define GIVE_UP(X) return 0
13146 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13148 /* Don't use this for mini-windows because these can show
13149 messages and mini-buffers, and we don't handle that here. */
13150 if (MINI_WINDOW_P (w
))
13153 /* This flag is used to prevent redisplay optimizations. */
13154 if (windows_or_buffers_changed
|| cursor_type_changed
)
13157 /* Verify that narrowing has not changed.
13158 Also verify that we were not told to prevent redisplay optimizations.
13159 It would be nice to further
13160 reduce the number of cases where this prevents try_window_id. */
13161 if (current_buffer
->clip_changed
13162 || current_buffer
->prevent_redisplay_optimizations_p
)
13165 /* Window must either use window-based redisplay or be full width. */
13166 if (!FRAME_WINDOW_P (f
)
13167 && (!FRAME_LINE_INS_DEL_OK (f
)
13168 || !WINDOW_FULL_WIDTH_P (w
)))
13171 /* Give up if point is not known NOT to appear in W. */
13172 if (PT
< CHARPOS (start
))
13175 /* Another way to prevent redisplay optimizations. */
13176 if (XFASTINT (w
->last_modified
) == 0)
13179 /* Verify that window is not hscrolled. */
13180 if (XFASTINT (w
->hscroll
) != 0)
13183 /* Verify that display wasn't paused. */
13184 if (NILP (w
->window_end_valid
))
13187 /* Can't use this if highlighting a region because a cursor movement
13188 will do more than just set the cursor. */
13189 if (!NILP (Vtransient_mark_mode
)
13190 && !NILP (current_buffer
->mark_active
))
13193 /* Likewise if highlighting trailing whitespace. */
13194 if (!NILP (Vshow_trailing_whitespace
))
13197 /* Likewise if showing a region. */
13198 if (!NILP (w
->region_showing
))
13201 /* Can use this if overlay arrow position and or string have changed. */
13202 if (overlay_arrows_changed_p ())
13206 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13207 only if buffer has really changed. The reason is that the gap is
13208 initially at Z for freshly visited files. The code below would
13209 set end_unchanged to 0 in that case. */
13210 if (MODIFF
> SAVE_MODIFF
13211 /* This seems to happen sometimes after saving a buffer. */
13212 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13214 if (GPT
- BEG
< BEG_UNCHANGED
)
13215 BEG_UNCHANGED
= GPT
- BEG
;
13216 if (Z
- GPT
< END_UNCHANGED
)
13217 END_UNCHANGED
= Z
- GPT
;
13220 /* The position of the first and last character that has been changed. */
13221 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13222 last_changed_charpos
= Z
- END_UNCHANGED
;
13224 /* If window starts after a line end, and the last change is in
13225 front of that newline, then changes don't affect the display.
13226 This case happens with stealth-fontification. Note that although
13227 the display is unchanged, glyph positions in the matrix have to
13228 be adjusted, of course. */
13229 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13230 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13231 && ((last_changed_charpos
< CHARPOS (start
)
13232 && CHARPOS (start
) == BEGV
)
13233 || (last_changed_charpos
< CHARPOS (start
) - 1
13234 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13236 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13237 struct glyph_row
*r0
;
13239 /* Compute how many chars/bytes have been added to or removed
13240 from the buffer. */
13241 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13242 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13244 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13246 /* Give up if PT is not in the window. Note that it already has
13247 been checked at the start of try_window_id that PT is not in
13248 front of the window start. */
13249 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13252 /* If window start is unchanged, we can reuse the whole matrix
13253 as is, after adjusting glyph positions. No need to compute
13254 the window end again, since its offset from Z hasn't changed. */
13255 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13256 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13257 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13258 /* PT must not be in a partially visible line. */
13259 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13260 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13262 /* Adjust positions in the glyph matrix. */
13263 if (delta
|| delta_bytes
)
13265 struct glyph_row
*r1
13266 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13267 increment_matrix_positions (w
->current_matrix
,
13268 MATRIX_ROW_VPOS (r0
, current_matrix
),
13269 MATRIX_ROW_VPOS (r1
, current_matrix
),
13270 delta
, delta_bytes
);
13273 /* Set the cursor. */
13274 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13276 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13283 /* Handle the case that changes are all below what is displayed in
13284 the window, and that PT is in the window. This shortcut cannot
13285 be taken if ZV is visible in the window, and text has been added
13286 there that is visible in the window. */
13287 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13288 /* ZV is not visible in the window, or there are no
13289 changes at ZV, actually. */
13290 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13291 || first_changed_charpos
== last_changed_charpos
))
13293 struct glyph_row
*r0
;
13295 /* Give up if PT is not in the window. Note that it already has
13296 been checked at the start of try_window_id that PT is not in
13297 front of the window start. */
13298 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13301 /* If window start is unchanged, we can reuse the whole matrix
13302 as is, without changing glyph positions since no text has
13303 been added/removed in front of the window end. */
13304 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13305 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13306 /* PT must not be in a partially visible line. */
13307 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13308 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13310 /* We have to compute the window end anew since text
13311 can have been added/removed after it. */
13313 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13314 w
->window_end_bytepos
13315 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13317 /* Set the cursor. */
13318 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13320 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13327 /* Give up if window start is in the changed area.
13329 The condition used to read
13331 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13333 but why that was tested escapes me at the moment. */
13334 if (CHARPOS (start
) >= first_changed_charpos
13335 && CHARPOS (start
) <= last_changed_charpos
)
13338 /* Check that window start agrees with the start of the first glyph
13339 row in its current matrix. Check this after we know the window
13340 start is not in changed text, otherwise positions would not be
13342 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13343 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13346 /* Give up if the window ends in strings. Overlay strings
13347 at the end are difficult to handle, so don't try. */
13348 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13349 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13352 /* Compute the position at which we have to start displaying new
13353 lines. Some of the lines at the top of the window might be
13354 reusable because they are not displaying changed text. Find the
13355 last row in W's current matrix not affected by changes at the
13356 start of current_buffer. Value is null if changes start in the
13357 first line of window. */
13358 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13359 if (last_unchanged_at_beg_row
)
13361 /* Avoid starting to display in the moddle of a character, a TAB
13362 for instance. This is easier than to set up the iterator
13363 exactly, and it's not a frequent case, so the additional
13364 effort wouldn't really pay off. */
13365 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13366 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13367 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13368 --last_unchanged_at_beg_row
;
13370 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13373 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13375 start_pos
= it
.current
.pos
;
13377 /* Start displaying new lines in the desired matrix at the same
13378 vpos we would use in the current matrix, i.e. below
13379 last_unchanged_at_beg_row. */
13380 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13382 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13383 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13385 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13389 /* There are no reusable lines at the start of the window.
13390 Start displaying in the first text line. */
13391 start_display (&it
, w
, start
);
13392 it
.vpos
= it
.first_vpos
;
13393 start_pos
= it
.current
.pos
;
13396 /* Find the first row that is not affected by changes at the end of
13397 the buffer. Value will be null if there is no unchanged row, in
13398 which case we must redisplay to the end of the window. delta
13399 will be set to the value by which buffer positions beginning with
13400 first_unchanged_at_end_row have to be adjusted due to text
13402 first_unchanged_at_end_row
13403 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13404 IF_DEBUG (debug_delta
= delta
);
13405 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13407 /* Set stop_pos to the buffer position up to which we will have to
13408 display new lines. If first_unchanged_at_end_row != NULL, this
13409 is the buffer position of the start of the line displayed in that
13410 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13411 that we don't stop at a buffer position. */
13413 if (first_unchanged_at_end_row
)
13415 xassert (last_unchanged_at_beg_row
== NULL
13416 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13418 /* If this is a continuation line, move forward to the next one
13419 that isn't. Changes in lines above affect this line.
13420 Caution: this may move first_unchanged_at_end_row to a row
13421 not displaying text. */
13422 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13423 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13424 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13425 < it
.last_visible_y
))
13426 ++first_unchanged_at_end_row
;
13428 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13429 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13430 >= it
.last_visible_y
))
13431 first_unchanged_at_end_row
= NULL
;
13434 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13436 first_unchanged_at_end_vpos
13437 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13438 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13441 else if (last_unchanged_at_beg_row
== NULL
)
13447 /* Either there is no unchanged row at the end, or the one we have
13448 now displays text. This is a necessary condition for the window
13449 end pos calculation at the end of this function. */
13450 xassert (first_unchanged_at_end_row
== NULL
13451 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13453 debug_last_unchanged_at_beg_vpos
13454 = (last_unchanged_at_beg_row
13455 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13457 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13459 #endif /* GLYPH_DEBUG != 0 */
13462 /* Display new lines. Set last_text_row to the last new line
13463 displayed which has text on it, i.e. might end up as being the
13464 line where the window_end_vpos is. */
13465 w
->cursor
.vpos
= -1;
13466 last_text_row
= NULL
;
13467 overlay_arrow_seen
= 0;
13468 while (it
.current_y
< it
.last_visible_y
13469 && !fonts_changed_p
13470 && (first_unchanged_at_end_row
== NULL
13471 || IT_CHARPOS (it
) < stop_pos
))
13473 if (display_line (&it
))
13474 last_text_row
= it
.glyph_row
- 1;
13477 if (fonts_changed_p
)
13481 /* Compute differences in buffer positions, y-positions etc. for
13482 lines reused at the bottom of the window. Compute what we can
13484 if (first_unchanged_at_end_row
13485 /* No lines reused because we displayed everything up to the
13486 bottom of the window. */
13487 && it
.current_y
< it
.last_visible_y
)
13490 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13492 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13493 run
.current_y
= first_unchanged_at_end_row
->y
;
13494 run
.desired_y
= run
.current_y
+ dy
;
13495 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13499 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13500 first_unchanged_at_end_row
= NULL
;
13502 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13505 /* Find the cursor if not already found. We have to decide whether
13506 PT will appear on this window (it sometimes doesn't, but this is
13507 not a very frequent case.) This decision has to be made before
13508 the current matrix is altered. A value of cursor.vpos < 0 means
13509 that PT is either in one of the lines beginning at
13510 first_unchanged_at_end_row or below the window. Don't care for
13511 lines that might be displayed later at the window end; as
13512 mentioned, this is not a frequent case. */
13513 if (w
->cursor
.vpos
< 0)
13515 /* Cursor in unchanged rows at the top? */
13516 if (PT
< CHARPOS (start_pos
)
13517 && last_unchanged_at_beg_row
)
13519 row
= row_containing_pos (w
, PT
,
13520 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13521 last_unchanged_at_beg_row
+ 1, 0);
13523 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13526 /* Start from first_unchanged_at_end_row looking for PT. */
13527 else if (first_unchanged_at_end_row
)
13529 row
= row_containing_pos (w
, PT
- delta
,
13530 first_unchanged_at_end_row
, NULL
, 0);
13532 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13533 delta_bytes
, dy
, dvpos
);
13536 /* Give up if cursor was not found. */
13537 if (w
->cursor
.vpos
< 0)
13539 clear_glyph_matrix (w
->desired_matrix
);
13544 /* Don't let the cursor end in the scroll margins. */
13546 int this_scroll_margin
, cursor_height
;
13548 this_scroll_margin
= max (0, scroll_margin
);
13549 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13550 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13551 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13553 if ((w
->cursor
.y
< this_scroll_margin
13554 && CHARPOS (start
) > BEGV
)
13555 /* Old redisplay didn't take scroll margin into account at the bottom,
13556 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13557 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13558 ? cursor_height
+ this_scroll_margin
13559 : 1)) > it
.last_visible_y
)
13561 w
->cursor
.vpos
= -1;
13562 clear_glyph_matrix (w
->desired_matrix
);
13567 /* Scroll the display. Do it before changing the current matrix so
13568 that xterm.c doesn't get confused about where the cursor glyph is
13570 if (dy
&& run
.height
)
13574 if (FRAME_WINDOW_P (f
))
13576 FRAME_RIF (f
)->update_window_begin_hook (w
);
13577 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13578 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13579 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13583 /* Terminal frame. In this case, dvpos gives the number of
13584 lines to scroll by; dvpos < 0 means scroll up. */
13585 int first_unchanged_at_end_vpos
13586 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13587 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13588 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13589 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13590 + window_internal_height (w
));
13592 /* Perform the operation on the screen. */
13595 /* Scroll last_unchanged_at_beg_row to the end of the
13596 window down dvpos lines. */
13597 set_terminal_window (f
, end
);
13599 /* On dumb terminals delete dvpos lines at the end
13600 before inserting dvpos empty lines. */
13601 if (!FRAME_SCROLL_REGION_OK (f
))
13602 ins_del_lines (f
, end
- dvpos
, -dvpos
);
13604 /* Insert dvpos empty lines in front of
13605 last_unchanged_at_beg_row. */
13606 ins_del_lines (f
, from
, dvpos
);
13608 else if (dvpos
< 0)
13610 /* Scroll up last_unchanged_at_beg_vpos to the end of
13611 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13612 set_terminal_window (f
, end
);
13614 /* Delete dvpos lines in front of
13615 last_unchanged_at_beg_vpos. ins_del_lines will set
13616 the cursor to the given vpos and emit |dvpos| delete
13618 ins_del_lines (f
, from
+ dvpos
, dvpos
);
13620 /* On a dumb terminal insert dvpos empty lines at the
13622 if (!FRAME_SCROLL_REGION_OK (f
))
13623 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
13626 set_terminal_window (f
, 0);
13632 /* Shift reused rows of the current matrix to the right position.
13633 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13635 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13636 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13639 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13640 bottom_vpos
, dvpos
);
13641 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13644 else if (dvpos
> 0)
13646 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13647 bottom_vpos
, dvpos
);
13648 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13649 first_unchanged_at_end_vpos
+ dvpos
, 0);
13652 /* For frame-based redisplay, make sure that current frame and window
13653 matrix are in sync with respect to glyph memory. */
13654 if (!FRAME_WINDOW_P (f
))
13655 sync_frame_with_window_matrix_rows (w
);
13657 /* Adjust buffer positions in reused rows. */
13659 increment_matrix_positions (current_matrix
,
13660 first_unchanged_at_end_vpos
+ dvpos
,
13661 bottom_vpos
, delta
, delta_bytes
);
13663 /* Adjust Y positions. */
13665 shift_glyph_matrix (w
, current_matrix
,
13666 first_unchanged_at_end_vpos
+ dvpos
,
13669 if (first_unchanged_at_end_row
)
13670 first_unchanged_at_end_row
+= dvpos
;
13672 /* If scrolling up, there may be some lines to display at the end of
13674 last_text_row_at_end
= NULL
;
13677 /* Scrolling up can leave for example a partially visible line
13678 at the end of the window to be redisplayed. */
13679 /* Set last_row to the glyph row in the current matrix where the
13680 window end line is found. It has been moved up or down in
13681 the matrix by dvpos. */
13682 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13683 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13685 /* If last_row is the window end line, it should display text. */
13686 xassert (last_row
->displays_text_p
);
13688 /* If window end line was partially visible before, begin
13689 displaying at that line. Otherwise begin displaying with the
13690 line following it. */
13691 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13693 init_to_row_start (&it
, w
, last_row
);
13694 it
.vpos
= last_vpos
;
13695 it
.current_y
= last_row
->y
;
13699 init_to_row_end (&it
, w
, last_row
);
13700 it
.vpos
= 1 + last_vpos
;
13701 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13705 /* We may start in a continuation line. If so, we have to
13706 get the right continuation_lines_width and current_x. */
13707 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13708 it
.hpos
= it
.current_x
= 0;
13710 /* Display the rest of the lines at the window end. */
13711 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13712 while (it
.current_y
< it
.last_visible_y
13713 && !fonts_changed_p
)
13715 /* Is it always sure that the display agrees with lines in
13716 the current matrix? I don't think so, so we mark rows
13717 displayed invalid in the current matrix by setting their
13718 enabled_p flag to zero. */
13719 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13720 if (display_line (&it
))
13721 last_text_row_at_end
= it
.glyph_row
- 1;
13725 /* Update window_end_pos and window_end_vpos. */
13726 if (first_unchanged_at_end_row
13727 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13728 && !last_text_row_at_end
)
13730 /* Window end line if one of the preserved rows from the current
13731 matrix. Set row to the last row displaying text in current
13732 matrix starting at first_unchanged_at_end_row, after
13734 xassert (first_unchanged_at_end_row
->displays_text_p
);
13735 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13736 first_unchanged_at_end_row
);
13737 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13739 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13740 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13742 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13743 xassert (w
->window_end_bytepos
>= 0);
13744 IF_DEBUG (debug_method_add (w
, "A"));
13746 else if (last_text_row_at_end
)
13749 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13750 w
->window_end_bytepos
13751 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13753 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13754 xassert (w
->window_end_bytepos
>= 0);
13755 IF_DEBUG (debug_method_add (w
, "B"));
13757 else if (last_text_row
)
13759 /* We have displayed either to the end of the window or at the
13760 end of the window, i.e. the last row with text is to be found
13761 in the desired matrix. */
13763 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13764 w
->window_end_bytepos
13765 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13767 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13768 xassert (w
->window_end_bytepos
>= 0);
13770 else if (first_unchanged_at_end_row
== NULL
13771 && last_text_row
== NULL
13772 && last_text_row_at_end
== NULL
)
13774 /* Displayed to end of window, but no line containing text was
13775 displayed. Lines were deleted at the end of the window. */
13776 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13777 int vpos
= XFASTINT (w
->window_end_vpos
);
13778 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13779 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13782 row
== NULL
&& vpos
>= first_vpos
;
13783 --vpos
, --current_row
, --desired_row
)
13785 if (desired_row
->enabled_p
)
13787 if (desired_row
->displays_text_p
)
13790 else if (current_row
->displays_text_p
)
13794 xassert (row
!= NULL
);
13795 w
->window_end_vpos
= make_number (vpos
+ 1);
13796 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13797 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13798 xassert (w
->window_end_bytepos
>= 0);
13799 IF_DEBUG (debug_method_add (w
, "C"));
13804 #if 0 /* This leads to problems, for instance when the cursor is
13805 at ZV, and the cursor line displays no text. */
13806 /* Disable rows below what's displayed in the window. This makes
13807 debugging easier. */
13808 enable_glyph_matrix_rows (current_matrix
,
13809 XFASTINT (w
->window_end_vpos
) + 1,
13813 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13814 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13816 /* Record that display has not been completed. */
13817 w
->window_end_valid
= Qnil
;
13818 w
->desired_matrix
->no_scrolling_p
= 1;
13826 /***********************************************************************
13827 More debugging support
13828 ***********************************************************************/
13832 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13833 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13834 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13837 /* Dump the contents of glyph matrix MATRIX on stderr.
13839 GLYPHS 0 means don't show glyph contents.
13840 GLYPHS 1 means show glyphs in short form
13841 GLYPHS > 1 means show glyphs in long form. */
13844 dump_glyph_matrix (matrix
, glyphs
)
13845 struct glyph_matrix
*matrix
;
13849 for (i
= 0; i
< matrix
->nrows
; ++i
)
13850 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13854 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13855 the glyph row and area where the glyph comes from. */
13858 dump_glyph (row
, glyph
, area
)
13859 struct glyph_row
*row
;
13860 struct glyph
*glyph
;
13863 if (glyph
->type
== CHAR_GLYPH
)
13866 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13867 glyph
- row
->glyphs
[TEXT_AREA
],
13870 (BUFFERP (glyph
->object
)
13872 : (STRINGP (glyph
->object
)
13875 glyph
->pixel_width
,
13877 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13881 glyph
->left_box_line_p
,
13882 glyph
->right_box_line_p
);
13884 else if (glyph
->type
== STRETCH_GLYPH
)
13887 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13888 glyph
- row
->glyphs
[TEXT_AREA
],
13891 (BUFFERP (glyph
->object
)
13893 : (STRINGP (glyph
->object
)
13896 glyph
->pixel_width
,
13900 glyph
->left_box_line_p
,
13901 glyph
->right_box_line_p
);
13903 else if (glyph
->type
== IMAGE_GLYPH
)
13906 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13907 glyph
- row
->glyphs
[TEXT_AREA
],
13910 (BUFFERP (glyph
->object
)
13912 : (STRINGP (glyph
->object
)
13915 glyph
->pixel_width
,
13919 glyph
->left_box_line_p
,
13920 glyph
->right_box_line_p
);
13925 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13926 GLYPHS 0 means don't show glyph contents.
13927 GLYPHS 1 means show glyphs in short form
13928 GLYPHS > 1 means show glyphs in long form. */
13931 dump_glyph_row (row
, vpos
, glyphs
)
13932 struct glyph_row
*row
;
13937 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13938 fprintf (stderr
, "=======================================================================\n");
13940 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13941 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13943 MATRIX_ROW_START_CHARPOS (row
),
13944 MATRIX_ROW_END_CHARPOS (row
),
13945 row
->used
[TEXT_AREA
],
13946 row
->contains_overlapping_glyphs_p
,
13948 row
->truncated_on_left_p
,
13949 row
->truncated_on_right_p
,
13950 row
->overlay_arrow_p
,
13952 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13953 row
->displays_text_p
,
13956 row
->ends_in_middle_of_char_p
,
13957 row
->starts_in_middle_of_char_p
,
13963 row
->visible_height
,
13966 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13967 row
->end
.overlay_string_index
,
13968 row
->continuation_lines_width
);
13969 fprintf (stderr
, "%9d %5d\n",
13970 CHARPOS (row
->start
.string_pos
),
13971 CHARPOS (row
->end
.string_pos
));
13972 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13973 row
->end
.dpvec_index
);
13980 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13982 struct glyph
*glyph
= row
->glyphs
[area
];
13983 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13985 /* Glyph for a line end in text. */
13986 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13989 if (glyph
< glyph_end
)
13990 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13992 for (; glyph
< glyph_end
; ++glyph
)
13993 dump_glyph (row
, glyph
, area
);
13996 else if (glyphs
== 1)
14000 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14002 char *s
= (char *) alloca (row
->used
[area
] + 1);
14005 for (i
= 0; i
< row
->used
[area
]; ++i
)
14007 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14008 if (glyph
->type
== CHAR_GLYPH
14009 && glyph
->u
.ch
< 0x80
14010 && glyph
->u
.ch
>= ' ')
14011 s
[i
] = glyph
->u
.ch
;
14017 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14023 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14024 Sdump_glyph_matrix
, 0, 1, "p",
14025 doc
: /* Dump the current matrix of the selected window to stderr.
14026 Shows contents of glyph row structures. With non-nil
14027 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14028 glyphs in short form, otherwise show glyphs in long form. */)
14030 Lisp_Object glyphs
;
14032 struct window
*w
= XWINDOW (selected_window
);
14033 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14035 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14036 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14037 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14038 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14039 fprintf (stderr
, "=============================================\n");
14040 dump_glyph_matrix (w
->current_matrix
,
14041 NILP (glyphs
) ? 0 : XINT (glyphs
));
14046 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14047 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14050 struct frame
*f
= XFRAME (selected_frame
);
14051 dump_glyph_matrix (f
->current_matrix
, 1);
14056 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14057 doc
: /* Dump glyph row ROW to stderr.
14058 GLYPH 0 means don't dump glyphs.
14059 GLYPH 1 means dump glyphs in short form.
14060 GLYPH > 1 or omitted means dump glyphs in long form. */)
14062 Lisp_Object row
, glyphs
;
14064 struct glyph_matrix
*matrix
;
14067 CHECK_NUMBER (row
);
14068 matrix
= XWINDOW (selected_window
)->current_matrix
;
14070 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14071 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14073 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14078 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14079 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14080 GLYPH 0 means don't dump glyphs.
14081 GLYPH 1 means dump glyphs in short form.
14082 GLYPH > 1 or omitted means dump glyphs in long form. */)
14084 Lisp_Object row
, glyphs
;
14086 struct frame
*sf
= SELECTED_FRAME ();
14087 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14090 CHECK_NUMBER (row
);
14092 if (vpos
>= 0 && vpos
< m
->nrows
)
14093 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14094 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14099 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14100 doc
: /* Toggle tracing of redisplay.
14101 With ARG, turn tracing on if and only if ARG is positive. */)
14106 trace_redisplay_p
= !trace_redisplay_p
;
14109 arg
= Fprefix_numeric_value (arg
);
14110 trace_redisplay_p
= XINT (arg
) > 0;
14117 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14118 doc
: /* Like `format', but print result to stderr.
14119 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14124 Lisp_Object s
= Fformat (nargs
, args
);
14125 fprintf (stderr
, "%s", SDATA (s
));
14129 #endif /* GLYPH_DEBUG */
14133 /***********************************************************************
14134 Building Desired Matrix Rows
14135 ***********************************************************************/
14137 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14138 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14140 static struct glyph_row
*
14141 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14143 Lisp_Object overlay_arrow_string
;
14145 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14146 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14147 struct buffer
*old
= current_buffer
;
14148 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14149 int arrow_len
= SCHARS (overlay_arrow_string
);
14150 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14151 const unsigned char *p
;
14154 int n_glyphs_before
;
14156 set_buffer_temp (buffer
);
14157 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14158 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14159 SET_TEXT_POS (it
.position
, 0, 0);
14161 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14163 while (p
< arrow_end
)
14165 Lisp_Object face
, ilisp
;
14167 /* Get the next character. */
14169 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14171 it
.c
= *p
, it
.len
= 1;
14174 /* Get its face. */
14175 ilisp
= make_number (p
- arrow_string
);
14176 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14177 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14179 /* Compute its width, get its glyphs. */
14180 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14181 SET_TEXT_POS (it
.position
, -1, -1);
14182 PRODUCE_GLYPHS (&it
);
14184 /* If this character doesn't fit any more in the line, we have
14185 to remove some glyphs. */
14186 if (it
.current_x
> it
.last_visible_x
)
14188 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14193 set_buffer_temp (old
);
14194 return it
.glyph_row
;
14198 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14199 glyphs are only inserted for terminal frames since we can't really
14200 win with truncation glyphs when partially visible glyphs are
14201 involved. Which glyphs to insert is determined by
14202 produce_special_glyphs. */
14205 insert_left_trunc_glyphs (it
)
14208 struct it truncate_it
;
14209 struct glyph
*from
, *end
, *to
, *toend
;
14211 xassert (!FRAME_WINDOW_P (it
->f
));
14213 /* Get the truncation glyphs. */
14215 truncate_it
.current_x
= 0;
14216 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14217 truncate_it
.glyph_row
= &scratch_glyph_row
;
14218 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14219 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14220 truncate_it
.object
= make_number (0);
14221 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14223 /* Overwrite glyphs from IT with truncation glyphs. */
14224 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14225 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14226 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14227 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14232 /* There may be padding glyphs left over. Overwrite them too. */
14233 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14235 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14241 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14245 /* Compute the pixel height and width of IT->glyph_row.
14247 Most of the time, ascent and height of a display line will be equal
14248 to the max_ascent and max_height values of the display iterator
14249 structure. This is not the case if
14251 1. We hit ZV without displaying anything. In this case, max_ascent
14252 and max_height will be zero.
14254 2. We have some glyphs that don't contribute to the line height.
14255 (The glyph row flag contributes_to_line_height_p is for future
14256 pixmap extensions).
14258 The first case is easily covered by using default values because in
14259 these cases, the line height does not really matter, except that it
14260 must not be zero. */
14263 compute_line_metrics (it
)
14266 struct glyph_row
*row
= it
->glyph_row
;
14269 if (FRAME_WINDOW_P (it
->f
))
14271 int i
, min_y
, max_y
;
14273 /* The line may consist of one space only, that was added to
14274 place the cursor on it. If so, the row's height hasn't been
14276 if (row
->height
== 0)
14278 if (it
->max_ascent
+ it
->max_descent
== 0)
14279 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14280 row
->ascent
= it
->max_ascent
;
14281 row
->height
= it
->max_ascent
+ it
->max_descent
;
14282 row
->phys_ascent
= it
->max_phys_ascent
;
14283 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14284 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14287 /* Compute the width of this line. */
14288 row
->pixel_width
= row
->x
;
14289 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14290 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14292 xassert (row
->pixel_width
>= 0);
14293 xassert (row
->ascent
>= 0 && row
->height
> 0);
14295 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14296 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14298 /* If first line's physical ascent is larger than its logical
14299 ascent, use the physical ascent, and make the row taller.
14300 This makes accented characters fully visible. */
14301 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14302 && row
->phys_ascent
> row
->ascent
)
14304 row
->height
+= row
->phys_ascent
- row
->ascent
;
14305 row
->ascent
= row
->phys_ascent
;
14308 /* Compute how much of the line is visible. */
14309 row
->visible_height
= row
->height
;
14311 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14312 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14314 if (row
->y
< min_y
)
14315 row
->visible_height
-= min_y
- row
->y
;
14316 if (row
->y
+ row
->height
> max_y
)
14317 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14321 row
->pixel_width
= row
->used
[TEXT_AREA
];
14322 if (row
->continued_p
)
14323 row
->pixel_width
-= it
->continuation_pixel_width
;
14324 else if (row
->truncated_on_right_p
)
14325 row
->pixel_width
-= it
->truncation_pixel_width
;
14326 row
->ascent
= row
->phys_ascent
= 0;
14327 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14328 row
->extra_line_spacing
= 0;
14331 /* Compute a hash code for this row. */
14333 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14334 for (i
= 0; i
< row
->used
[area
]; ++i
)
14335 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14336 + row
->glyphs
[area
][i
].u
.val
14337 + row
->glyphs
[area
][i
].face_id
14338 + row
->glyphs
[area
][i
].padding_p
14339 + (row
->glyphs
[area
][i
].type
<< 2));
14341 it
->max_ascent
= it
->max_descent
= 0;
14342 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14346 /* Append one space to the glyph row of iterator IT if doing a
14347 window-based redisplay. The space has the same face as
14348 IT->face_id. Value is non-zero if a space was added.
14350 This function is called to make sure that there is always one glyph
14351 at the end of a glyph row that the cursor can be set on under
14352 window-systems. (If there weren't such a glyph we would not know
14353 how wide and tall a box cursor should be displayed).
14355 At the same time this space let's a nicely handle clearing to the
14356 end of the line if the row ends in italic text. */
14359 append_space_for_newline (it
, default_face_p
)
14361 int default_face_p
;
14363 if (FRAME_WINDOW_P (it
->f
))
14365 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14367 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14368 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14370 /* Save some values that must not be changed.
14371 Must save IT->c and IT->len because otherwise
14372 ITERATOR_AT_END_P wouldn't work anymore after
14373 append_space_for_newline has been called. */
14374 enum display_element_type saved_what
= it
->what
;
14375 int saved_c
= it
->c
, saved_len
= it
->len
;
14376 int saved_x
= it
->current_x
;
14377 int saved_face_id
= it
->face_id
;
14378 struct text_pos saved_pos
;
14379 Lisp_Object saved_object
;
14382 saved_object
= it
->object
;
14383 saved_pos
= it
->position
;
14385 it
->what
= IT_CHARACTER
;
14386 bzero (&it
->position
, sizeof it
->position
);
14387 it
->object
= make_number (0);
14391 if (default_face_p
)
14392 it
->face_id
= DEFAULT_FACE_ID
;
14393 else if (it
->face_before_selective_p
)
14394 it
->face_id
= it
->saved_face_id
;
14395 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14396 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14398 PRODUCE_GLYPHS (it
);
14400 it
->override_ascent
= -1;
14401 it
->constrain_row_ascent_descent_p
= 0;
14402 it
->current_x
= saved_x
;
14403 it
->object
= saved_object
;
14404 it
->position
= saved_pos
;
14405 it
->what
= saved_what
;
14406 it
->face_id
= saved_face_id
;
14407 it
->len
= saved_len
;
14417 /* Extend the face of the last glyph in the text area of IT->glyph_row
14418 to the end of the display line. Called from display_line.
14419 If the glyph row is empty, add a space glyph to it so that we
14420 know the face to draw. Set the glyph row flag fill_line_p. */
14423 extend_face_to_end_of_line (it
)
14427 struct frame
*f
= it
->f
;
14429 /* If line is already filled, do nothing. */
14430 if (it
->current_x
>= it
->last_visible_x
)
14433 /* Face extension extends the background and box of IT->face_id
14434 to the end of the line. If the background equals the background
14435 of the frame, we don't have to do anything. */
14436 if (it
->face_before_selective_p
)
14437 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14439 face
= FACE_FROM_ID (f
, it
->face_id
);
14441 if (FRAME_WINDOW_P (f
)
14442 && face
->box
== FACE_NO_BOX
14443 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14447 /* Set the glyph row flag indicating that the face of the last glyph
14448 in the text area has to be drawn to the end of the text area. */
14449 it
->glyph_row
->fill_line_p
= 1;
14451 /* If current character of IT is not ASCII, make sure we have the
14452 ASCII face. This will be automatically undone the next time
14453 get_next_display_element returns a multibyte character. Note
14454 that the character will always be single byte in unibyte text. */
14455 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14457 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14460 if (FRAME_WINDOW_P (f
))
14462 /* If the row is empty, add a space with the current face of IT,
14463 so that we know which face to draw. */
14464 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14466 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14467 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14468 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14473 /* Save some values that must not be changed. */
14474 int saved_x
= it
->current_x
;
14475 struct text_pos saved_pos
;
14476 Lisp_Object saved_object
;
14477 enum display_element_type saved_what
= it
->what
;
14478 int saved_face_id
= it
->face_id
;
14480 saved_object
= it
->object
;
14481 saved_pos
= it
->position
;
14483 it
->what
= IT_CHARACTER
;
14484 bzero (&it
->position
, sizeof it
->position
);
14485 it
->object
= make_number (0);
14488 it
->face_id
= face
->id
;
14490 PRODUCE_GLYPHS (it
);
14492 while (it
->current_x
<= it
->last_visible_x
)
14493 PRODUCE_GLYPHS (it
);
14495 /* Don't count these blanks really. It would let us insert a left
14496 truncation glyph below and make us set the cursor on them, maybe. */
14497 it
->current_x
= saved_x
;
14498 it
->object
= saved_object
;
14499 it
->position
= saved_pos
;
14500 it
->what
= saved_what
;
14501 it
->face_id
= saved_face_id
;
14506 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14507 trailing whitespace. */
14510 trailing_whitespace_p (charpos
)
14513 int bytepos
= CHAR_TO_BYTE (charpos
);
14516 while (bytepos
< ZV_BYTE
14517 && (c
= FETCH_CHAR (bytepos
),
14518 c
== ' ' || c
== '\t'))
14521 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14523 if (bytepos
!= PT_BYTE
)
14530 /* Highlight trailing whitespace, if any, in ROW. */
14533 highlight_trailing_whitespace (f
, row
)
14535 struct glyph_row
*row
;
14537 int used
= row
->used
[TEXT_AREA
];
14541 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14542 struct glyph
*glyph
= start
+ used
- 1;
14544 /* Skip over glyphs inserted to display the cursor at the
14545 end of a line, for extending the face of the last glyph
14546 to the end of the line on terminals, and for truncation
14547 and continuation glyphs. */
14548 while (glyph
>= start
14549 && glyph
->type
== CHAR_GLYPH
14550 && INTEGERP (glyph
->object
))
14553 /* If last glyph is a space or stretch, and it's trailing
14554 whitespace, set the face of all trailing whitespace glyphs in
14555 IT->glyph_row to `trailing-whitespace'. */
14557 && BUFFERP (glyph
->object
)
14558 && (glyph
->type
== STRETCH_GLYPH
14559 || (glyph
->type
== CHAR_GLYPH
14560 && glyph
->u
.ch
== ' '))
14561 && trailing_whitespace_p (glyph
->charpos
))
14563 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14567 while (glyph
>= start
14568 && BUFFERP (glyph
->object
)
14569 && (glyph
->type
== STRETCH_GLYPH
14570 || (glyph
->type
== CHAR_GLYPH
14571 && glyph
->u
.ch
== ' ')))
14572 (glyph
--)->face_id
= face_id
;
14578 /* Value is non-zero if glyph row ROW in window W should be
14579 used to hold the cursor. */
14582 cursor_row_p (w
, row
)
14584 struct glyph_row
*row
;
14586 int cursor_row_p
= 1;
14588 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14590 /* If the row ends with a newline from a string, we don't want
14591 the cursor there (if the row is continued it doesn't end in a
14593 if (CHARPOS (row
->end
.string_pos
) >= 0
14594 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14595 cursor_row_p
= row
->continued_p
;
14597 /* If the row ends at ZV, display the cursor at the end of that
14598 row instead of at the start of the row below. */
14599 else if (row
->ends_at_zv_p
)
14605 return cursor_row_p
;
14609 /* Construct the glyph row IT->glyph_row in the desired matrix of
14610 IT->w from text at the current position of IT. See dispextern.h
14611 for an overview of struct it. Value is non-zero if
14612 IT->glyph_row displays text, as opposed to a line displaying ZV
14619 struct glyph_row
*row
= it
->glyph_row
;
14620 int overlay_arrow_bitmap
;
14621 Lisp_Object overlay_arrow_string
;
14623 /* We always start displaying at hpos zero even if hscrolled. */
14624 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14626 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14627 >= it
->w
->desired_matrix
->nrows
)
14629 it
->w
->nrows_scale_factor
++;
14630 fonts_changed_p
= 1;
14634 /* Is IT->w showing the region? */
14635 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14637 /* Clear the result glyph row and enable it. */
14638 prepare_desired_row (row
);
14640 row
->y
= it
->current_y
;
14641 row
->start
= it
->start
;
14642 row
->continuation_lines_width
= it
->continuation_lines_width
;
14643 row
->displays_text_p
= 1;
14644 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14645 it
->starts_in_middle_of_char_p
= 0;
14647 /* Arrange the overlays nicely for our purposes. Usually, we call
14648 display_line on only one line at a time, in which case this
14649 can't really hurt too much, or we call it on lines which appear
14650 one after another in the buffer, in which case all calls to
14651 recenter_overlay_lists but the first will be pretty cheap. */
14652 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14654 /* Move over display elements that are not visible because we are
14655 hscrolled. This may stop at an x-position < IT->first_visible_x
14656 if the first glyph is partially visible or if we hit a line end. */
14657 if (it
->current_x
< it
->first_visible_x
)
14659 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14660 MOVE_TO_POS
| MOVE_TO_X
);
14663 /* Get the initial row height. This is either the height of the
14664 text hscrolled, if there is any, or zero. */
14665 row
->ascent
= it
->max_ascent
;
14666 row
->height
= it
->max_ascent
+ it
->max_descent
;
14667 row
->phys_ascent
= it
->max_phys_ascent
;
14668 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14669 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14671 /* Loop generating characters. The loop is left with IT on the next
14672 character to display. */
14675 int n_glyphs_before
, hpos_before
, x_before
;
14677 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14679 /* Retrieve the next thing to display. Value is zero if end of
14681 if (!get_next_display_element (it
))
14683 /* Maybe add a space at the end of this line that is used to
14684 display the cursor there under X. Set the charpos of the
14685 first glyph of blank lines not corresponding to any text
14687 #ifdef HAVE_WINDOW_SYSTEM
14688 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14689 row
->exact_window_width_line_p
= 1;
14691 #endif /* HAVE_WINDOW_SYSTEM */
14692 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14693 || row
->used
[TEXT_AREA
] == 0)
14695 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14696 row
->displays_text_p
= 0;
14698 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14699 && (!MINI_WINDOW_P (it
->w
)
14700 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14701 row
->indicate_empty_line_p
= 1;
14704 it
->continuation_lines_width
= 0;
14705 row
->ends_at_zv_p
= 1;
14709 /* Now, get the metrics of what we want to display. This also
14710 generates glyphs in `row' (which is IT->glyph_row). */
14711 n_glyphs_before
= row
->used
[TEXT_AREA
];
14714 /* Remember the line height so far in case the next element doesn't
14715 fit on the line. */
14716 if (!it
->truncate_lines_p
)
14718 ascent
= it
->max_ascent
;
14719 descent
= it
->max_descent
;
14720 phys_ascent
= it
->max_phys_ascent
;
14721 phys_descent
= it
->max_phys_descent
;
14724 PRODUCE_GLYPHS (it
);
14726 /* If this display element was in marginal areas, continue with
14728 if (it
->area
!= TEXT_AREA
)
14730 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14731 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14732 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14733 row
->phys_height
= max (row
->phys_height
,
14734 it
->max_phys_ascent
+ it
->max_phys_descent
);
14735 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14736 it
->max_extra_line_spacing
);
14737 set_iterator_to_next (it
, 1);
14741 /* Does the display element fit on the line? If we truncate
14742 lines, we should draw past the right edge of the window. If
14743 we don't truncate, we want to stop so that we can display the
14744 continuation glyph before the right margin. If lines are
14745 continued, there are two possible strategies for characters
14746 resulting in more than 1 glyph (e.g. tabs): Display as many
14747 glyphs as possible in this line and leave the rest for the
14748 continuation line, or display the whole element in the next
14749 line. Original redisplay did the former, so we do it also. */
14750 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14751 hpos_before
= it
->hpos
;
14754 if (/* Not a newline. */
14756 /* Glyphs produced fit entirely in the line. */
14757 && it
->current_x
< it
->last_visible_x
)
14759 it
->hpos
+= nglyphs
;
14760 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14761 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14762 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14763 row
->phys_height
= max (row
->phys_height
,
14764 it
->max_phys_ascent
+ it
->max_phys_descent
);
14765 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14766 it
->max_extra_line_spacing
);
14767 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14768 row
->x
= x
- it
->first_visible_x
;
14773 struct glyph
*glyph
;
14775 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14777 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14778 new_x
= x
+ glyph
->pixel_width
;
14780 if (/* Lines are continued. */
14781 !it
->truncate_lines_p
14782 && (/* Glyph doesn't fit on the line. */
14783 new_x
> it
->last_visible_x
14784 /* Or it fits exactly on a window system frame. */
14785 || (new_x
== it
->last_visible_x
14786 && FRAME_WINDOW_P (it
->f
))))
14788 /* End of a continued line. */
14791 || (new_x
== it
->last_visible_x
14792 && FRAME_WINDOW_P (it
->f
)))
14794 /* Current glyph is the only one on the line or
14795 fits exactly on the line. We must continue
14796 the line because we can't draw the cursor
14797 after the glyph. */
14798 row
->continued_p
= 1;
14799 it
->current_x
= new_x
;
14800 it
->continuation_lines_width
+= new_x
;
14802 if (i
== nglyphs
- 1)
14804 set_iterator_to_next (it
, 1);
14805 #ifdef HAVE_WINDOW_SYSTEM
14806 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14808 if (!get_next_display_element (it
))
14810 row
->exact_window_width_line_p
= 1;
14811 it
->continuation_lines_width
= 0;
14812 row
->continued_p
= 0;
14813 row
->ends_at_zv_p
= 1;
14815 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14817 row
->continued_p
= 0;
14818 row
->exact_window_width_line_p
= 1;
14821 #endif /* HAVE_WINDOW_SYSTEM */
14824 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14825 && !FRAME_WINDOW_P (it
->f
))
14827 /* A padding glyph that doesn't fit on this line.
14828 This means the whole character doesn't fit
14830 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14832 /* Fill the rest of the row with continuation
14833 glyphs like in 20.x. */
14834 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14835 < row
->glyphs
[1 + TEXT_AREA
])
14836 produce_special_glyphs (it
, IT_CONTINUATION
);
14838 row
->continued_p
= 1;
14839 it
->current_x
= x_before
;
14840 it
->continuation_lines_width
+= x_before
;
14842 /* Restore the height to what it was before the
14843 element not fitting on the line. */
14844 it
->max_ascent
= ascent
;
14845 it
->max_descent
= descent
;
14846 it
->max_phys_ascent
= phys_ascent
;
14847 it
->max_phys_descent
= phys_descent
;
14849 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14851 /* A TAB that extends past the right edge of the
14852 window. This produces a single glyph on
14853 window system frames. We leave the glyph in
14854 this row and let it fill the row, but don't
14855 consume the TAB. */
14856 it
->continuation_lines_width
+= it
->last_visible_x
;
14857 row
->ends_in_middle_of_char_p
= 1;
14858 row
->continued_p
= 1;
14859 glyph
->pixel_width
= it
->last_visible_x
- x
;
14860 it
->starts_in_middle_of_char_p
= 1;
14864 /* Something other than a TAB that draws past
14865 the right edge of the window. Restore
14866 positions to values before the element. */
14867 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14869 /* Display continuation glyphs. */
14870 if (!FRAME_WINDOW_P (it
->f
))
14871 produce_special_glyphs (it
, IT_CONTINUATION
);
14872 row
->continued_p
= 1;
14874 it
->continuation_lines_width
+= x
;
14876 if (nglyphs
> 1 && i
> 0)
14878 row
->ends_in_middle_of_char_p
= 1;
14879 it
->starts_in_middle_of_char_p
= 1;
14882 /* Restore the height to what it was before the
14883 element not fitting on the line. */
14884 it
->max_ascent
= ascent
;
14885 it
->max_descent
= descent
;
14886 it
->max_phys_ascent
= phys_ascent
;
14887 it
->max_phys_descent
= phys_descent
;
14892 else if (new_x
> it
->first_visible_x
)
14894 /* Increment number of glyphs actually displayed. */
14897 if (x
< it
->first_visible_x
)
14898 /* Glyph is partially visible, i.e. row starts at
14899 negative X position. */
14900 row
->x
= x
- it
->first_visible_x
;
14904 /* Glyph is completely off the left margin of the
14905 window. This should not happen because of the
14906 move_it_in_display_line at the start of this
14907 function, unless the text display area of the
14908 window is empty. */
14909 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14913 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14914 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14915 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14916 row
->phys_height
= max (row
->phys_height
,
14917 it
->max_phys_ascent
+ it
->max_phys_descent
);
14918 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14919 it
->max_extra_line_spacing
);
14921 /* End of this display line if row is continued. */
14922 if (row
->continued_p
|| row
->ends_at_zv_p
)
14927 /* Is this a line end? If yes, we're also done, after making
14928 sure that a non-default face is extended up to the right
14929 margin of the window. */
14930 if (ITERATOR_AT_END_OF_LINE_P (it
))
14932 int used_before
= row
->used
[TEXT_AREA
];
14934 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14936 #ifdef HAVE_WINDOW_SYSTEM
14937 /* Add a space at the end of the line that is used to
14938 display the cursor there. */
14939 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14940 append_space_for_newline (it
, 0);
14941 #endif /* HAVE_WINDOW_SYSTEM */
14943 /* Extend the face to the end of the line. */
14944 extend_face_to_end_of_line (it
);
14946 /* Make sure we have the position. */
14947 if (used_before
== 0)
14948 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14950 /* Consume the line end. This skips over invisible lines. */
14951 set_iterator_to_next (it
, 1);
14952 it
->continuation_lines_width
= 0;
14956 /* Proceed with next display element. Note that this skips
14957 over lines invisible because of selective display. */
14958 set_iterator_to_next (it
, 1);
14960 /* If we truncate lines, we are done when the last displayed
14961 glyphs reach past the right margin of the window. */
14962 if (it
->truncate_lines_p
14963 && (FRAME_WINDOW_P (it
->f
)
14964 ? (it
->current_x
>= it
->last_visible_x
)
14965 : (it
->current_x
> it
->last_visible_x
)))
14967 /* Maybe add truncation glyphs. */
14968 if (!FRAME_WINDOW_P (it
->f
))
14972 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14973 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14976 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14978 row
->used
[TEXT_AREA
] = i
;
14979 produce_special_glyphs (it
, IT_TRUNCATION
);
14982 #ifdef HAVE_WINDOW_SYSTEM
14985 /* Don't truncate if we can overflow newline into fringe. */
14986 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14988 if (!get_next_display_element (it
))
14990 it
->continuation_lines_width
= 0;
14991 row
->ends_at_zv_p
= 1;
14992 row
->exact_window_width_line_p
= 1;
14995 if (ITERATOR_AT_END_OF_LINE_P (it
))
14997 row
->exact_window_width_line_p
= 1;
14998 goto at_end_of_line
;
15002 #endif /* HAVE_WINDOW_SYSTEM */
15004 row
->truncated_on_right_p
= 1;
15005 it
->continuation_lines_width
= 0;
15006 reseat_at_next_visible_line_start (it
, 0);
15007 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15008 it
->hpos
= hpos_before
;
15009 it
->current_x
= x_before
;
15014 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15015 at the left window margin. */
15016 if (it
->first_visible_x
15017 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15019 if (!FRAME_WINDOW_P (it
->f
))
15020 insert_left_trunc_glyphs (it
);
15021 row
->truncated_on_left_p
= 1;
15024 /* If the start of this line is the overlay arrow-position, then
15025 mark this glyph row as the one containing the overlay arrow.
15026 This is clearly a mess with variable size fonts. It would be
15027 better to let it be displayed like cursors under X. */
15028 if (! overlay_arrow_seen
15029 && (overlay_arrow_string
15030 = overlay_arrow_at_row (it
, row
, &overlay_arrow_bitmap
),
15031 !NILP (overlay_arrow_string
)))
15033 /* Overlay arrow in window redisplay is a fringe bitmap. */
15034 if (STRINGP (overlay_arrow_string
))
15036 struct glyph_row
*arrow_row
15037 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15038 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15039 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15040 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15041 struct glyph
*p2
, *end
;
15043 /* Copy the arrow glyphs. */
15044 while (glyph
< arrow_end
)
15047 /* Throw away padding glyphs. */
15049 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15050 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15056 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15061 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
15062 row
->overlay_arrow_p
= 1;
15064 overlay_arrow_seen
= 1;
15067 /* Compute pixel dimensions of this line. */
15068 compute_line_metrics (it
);
15070 /* Remember the position at which this line ends. */
15071 row
->end
= it
->current
;
15073 /* Save fringe bitmaps in this row. */
15074 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15075 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15076 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15077 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15079 it
->left_user_fringe_bitmap
= 0;
15080 it
->left_user_fringe_face_id
= 0;
15081 it
->right_user_fringe_bitmap
= 0;
15082 it
->right_user_fringe_face_id
= 0;
15084 /* Maybe set the cursor. */
15085 if (it
->w
->cursor
.vpos
< 0
15086 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15087 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15088 && cursor_row_p (it
->w
, row
))
15089 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15091 /* Highlight trailing whitespace. */
15092 if (!NILP (Vshow_trailing_whitespace
))
15093 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15095 /* Prepare for the next line. This line starts horizontally at (X
15096 HPOS) = (0 0). Vertical positions are incremented. As a
15097 convenience for the caller, IT->glyph_row is set to the next
15099 it
->current_x
= it
->hpos
= 0;
15100 it
->current_y
+= row
->height
;
15103 it
->start
= it
->current
;
15104 return row
->displays_text_p
;
15109 /***********************************************************************
15111 ***********************************************************************/
15113 /* Redisplay the menu bar in the frame for window W.
15115 The menu bar of X frames that don't have X toolkit support is
15116 displayed in a special window W->frame->menu_bar_window.
15118 The menu bar of terminal frames is treated specially as far as
15119 glyph matrices are concerned. Menu bar lines are not part of
15120 windows, so the update is done directly on the frame matrix rows
15121 for the menu bar. */
15124 display_menu_bar (w
)
15127 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15132 /* Don't do all this for graphical frames. */
15134 if (!NILP (Vwindow_system
))
15137 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15142 if (FRAME_MAC_P (f
))
15146 #ifdef USE_X_TOOLKIT
15147 xassert (!FRAME_WINDOW_P (f
));
15148 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15149 it
.first_visible_x
= 0;
15150 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15151 #else /* not USE_X_TOOLKIT */
15152 if (FRAME_WINDOW_P (f
))
15154 /* Menu bar lines are displayed in the desired matrix of the
15155 dummy window menu_bar_window. */
15156 struct window
*menu_w
;
15157 xassert (WINDOWP (f
->menu_bar_window
));
15158 menu_w
= XWINDOW (f
->menu_bar_window
);
15159 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15161 it
.first_visible_x
= 0;
15162 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15166 /* This is a TTY frame, i.e. character hpos/vpos are used as
15168 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15170 it
.first_visible_x
= 0;
15171 it
.last_visible_x
= FRAME_COLS (f
);
15173 #endif /* not USE_X_TOOLKIT */
15175 if (! mode_line_inverse_video
)
15176 /* Force the menu-bar to be displayed in the default face. */
15177 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15179 /* Clear all rows of the menu bar. */
15180 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15182 struct glyph_row
*row
= it
.glyph_row
+ i
;
15183 clear_glyph_row (row
);
15184 row
->enabled_p
= 1;
15185 row
->full_width_p
= 1;
15188 /* Display all items of the menu bar. */
15189 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15190 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15192 Lisp_Object string
;
15194 /* Stop at nil string. */
15195 string
= AREF (items
, i
+ 1);
15199 /* Remember where item was displayed. */
15200 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15202 /* Display the item, pad with one space. */
15203 if (it
.current_x
< it
.last_visible_x
)
15204 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15205 SCHARS (string
) + 1, 0, 0, -1);
15208 /* Fill out the line with spaces. */
15209 if (it
.current_x
< it
.last_visible_x
)
15210 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15212 /* Compute the total height of the lines. */
15213 compute_line_metrics (&it
);
15218 /***********************************************************************
15220 ***********************************************************************/
15222 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15223 FORCE is non-zero, redisplay mode lines unconditionally.
15224 Otherwise, redisplay only mode lines that are garbaged. Value is
15225 the number of windows whose mode lines were redisplayed. */
15228 redisplay_mode_lines (window
, force
)
15229 Lisp_Object window
;
15234 while (!NILP (window
))
15236 struct window
*w
= XWINDOW (window
);
15238 if (WINDOWP (w
->hchild
))
15239 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15240 else if (WINDOWP (w
->vchild
))
15241 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15243 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15244 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15246 struct text_pos lpoint
;
15247 struct buffer
*old
= current_buffer
;
15249 /* Set the window's buffer for the mode line display. */
15250 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15251 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15253 /* Point refers normally to the selected window. For any
15254 other window, set up appropriate value. */
15255 if (!EQ (window
, selected_window
))
15257 struct text_pos pt
;
15259 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15260 if (CHARPOS (pt
) < BEGV
)
15261 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15262 else if (CHARPOS (pt
) > (ZV
- 1))
15263 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15265 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15268 /* Display mode lines. */
15269 clear_glyph_matrix (w
->desired_matrix
);
15270 if (display_mode_lines (w
))
15273 w
->must_be_updated_p
= 1;
15276 /* Restore old settings. */
15277 set_buffer_internal_1 (old
);
15278 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15288 /* Display the mode and/or top line of window W. Value is the number
15289 of mode lines displayed. */
15292 display_mode_lines (w
)
15295 Lisp_Object old_selected_window
, old_selected_frame
;
15298 old_selected_frame
= selected_frame
;
15299 selected_frame
= w
->frame
;
15300 old_selected_window
= selected_window
;
15301 XSETWINDOW (selected_window
, w
);
15303 /* These will be set while the mode line specs are processed. */
15304 line_number_displayed
= 0;
15305 w
->column_number_displayed
= Qnil
;
15307 if (WINDOW_WANTS_MODELINE_P (w
))
15309 struct window
*sel_w
= XWINDOW (old_selected_window
);
15311 /* Select mode line face based on the real selected window. */
15312 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15313 current_buffer
->mode_line_format
);
15317 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15319 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15320 current_buffer
->header_line_format
);
15324 selected_frame
= old_selected_frame
;
15325 selected_window
= old_selected_window
;
15330 /* Display mode or top line of window W. FACE_ID specifies which line
15331 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15332 FORMAT is the mode line format to display. Value is the pixel
15333 height of the mode line displayed. */
15336 display_mode_line (w
, face_id
, format
)
15338 enum face_id face_id
;
15339 Lisp_Object format
;
15344 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15345 prepare_desired_row (it
.glyph_row
);
15347 it
.glyph_row
->mode_line_p
= 1;
15349 if (! mode_line_inverse_video
)
15350 /* Force the mode-line to be displayed in the default face. */
15351 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15353 /* Temporarily make frame's keyboard the current kboard so that
15354 kboard-local variables in the mode_line_format will get the right
15356 push_frame_kboard (it
.f
);
15357 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15358 pop_frame_kboard ();
15360 /* Fill up with spaces. */
15361 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15363 compute_line_metrics (&it
);
15364 it
.glyph_row
->full_width_p
= 1;
15365 it
.glyph_row
->continued_p
= 0;
15366 it
.glyph_row
->truncated_on_left_p
= 0;
15367 it
.glyph_row
->truncated_on_right_p
= 0;
15369 /* Make a 3D mode-line have a shadow at its right end. */
15370 face
= FACE_FROM_ID (it
.f
, face_id
);
15371 extend_face_to_end_of_line (&it
);
15372 if (face
->box
!= FACE_NO_BOX
)
15374 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15375 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15376 last
->right_box_line_p
= 1;
15379 return it
.glyph_row
->height
;
15382 /* Alist that caches the results of :propertize.
15383 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15384 Lisp_Object mode_line_proptrans_alist
;
15386 /* List of strings making up the mode-line. */
15387 Lisp_Object mode_line_string_list
;
15389 /* Base face property when building propertized mode line string. */
15390 static Lisp_Object mode_line_string_face
;
15391 static Lisp_Object mode_line_string_face_prop
;
15394 /* Contribute ELT to the mode line for window IT->w. How it
15395 translates into text depends on its data type.
15397 IT describes the display environment in which we display, as usual.
15399 DEPTH is the depth in recursion. It is used to prevent
15400 infinite recursion here.
15402 FIELD_WIDTH is the number of characters the display of ELT should
15403 occupy in the mode line, and PRECISION is the maximum number of
15404 characters to display from ELT's representation. See
15405 display_string for details.
15407 Returns the hpos of the end of the text generated by ELT.
15409 PROPS is a property list to add to any string we encounter.
15411 If RISKY is nonzero, remove (disregard) any properties in any string
15412 we encounter, and ignore :eval and :propertize.
15414 If the global variable `frame_title_ptr' is non-NULL, then the output
15415 is passed to `store_frame_title' instead of `display_string'. */
15418 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15421 int field_width
, precision
;
15422 Lisp_Object elt
, props
;
15425 int n
= 0, field
, prec
;
15430 elt
= build_string ("*too-deep*");
15434 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15438 /* A string: output it and check for %-constructs within it. */
15440 const unsigned char *this, *lisp_string
;
15442 if (!NILP (props
) || risky
)
15444 Lisp_Object oprops
, aelt
;
15445 oprops
= Ftext_properties_at (make_number (0), elt
);
15447 /* If the starting string's properties are not what
15448 we want, translate the string. Also, if the string
15449 is risky, do that anyway. */
15451 if (NILP (Fequal (props
, oprops
)) || risky
)
15453 /* If the starting string has properties,
15454 merge the specified ones onto the existing ones. */
15455 if (! NILP (oprops
) && !risky
)
15459 oprops
= Fcopy_sequence (oprops
);
15461 while (CONSP (tem
))
15463 oprops
= Fplist_put (oprops
, XCAR (tem
),
15464 XCAR (XCDR (tem
)));
15465 tem
= XCDR (XCDR (tem
));
15470 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15471 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15473 mode_line_proptrans_alist
15474 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15481 elt
= Fcopy_sequence (elt
);
15482 Fset_text_properties (make_number (0), Flength (elt
),
15484 /* Add this item to mode_line_proptrans_alist. */
15485 mode_line_proptrans_alist
15486 = Fcons (Fcons (elt
, props
),
15487 mode_line_proptrans_alist
);
15488 /* Truncate mode_line_proptrans_alist
15489 to at most 50 elements. */
15490 tem
= Fnthcdr (make_number (50),
15491 mode_line_proptrans_alist
);
15493 XSETCDR (tem
, Qnil
);
15498 this = SDATA (elt
);
15499 lisp_string
= this;
15503 prec
= precision
- n
;
15504 if (frame_title_ptr
)
15505 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15506 else if (!NILP (mode_line_string_list
))
15507 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15509 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15510 0, prec
, 0, STRING_MULTIBYTE (elt
));
15515 while ((precision
<= 0 || n
< precision
)
15517 && (frame_title_ptr
15518 || !NILP (mode_line_string_list
)
15519 || it
->current_x
< it
->last_visible_x
))
15521 const unsigned char *last
= this;
15523 /* Advance to end of string or next format specifier. */
15524 while ((c
= *this++) != '\0' && c
!= '%')
15527 if (this - 1 != last
)
15529 int nchars
, nbytes
;
15531 /* Output to end of string or up to '%'. Field width
15532 is length of string. Don't output more than
15533 PRECISION allows us. */
15536 prec
= c_string_width (last
, this - last
, precision
- n
,
15539 if (frame_title_ptr
)
15540 n
+= store_frame_title (last
, 0, prec
);
15541 else if (!NILP (mode_line_string_list
))
15543 int bytepos
= last
- lisp_string
;
15544 int charpos
= string_byte_to_char (elt
, bytepos
);
15545 int endpos
= (precision
<= 0
15546 ? string_byte_to_char (elt
,
15547 this - lisp_string
)
15548 : charpos
+ nchars
);
15550 n
+= store_mode_line_string (NULL
,
15551 Fsubstring (elt
, make_number (charpos
),
15552 make_number (endpos
)),
15557 int bytepos
= last
- lisp_string
;
15558 int charpos
= string_byte_to_char (elt
, bytepos
);
15559 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15561 STRING_MULTIBYTE (elt
));
15564 else /* c == '%' */
15566 const unsigned char *percent_position
= this;
15568 /* Get the specified minimum width. Zero means
15571 while ((c
= *this++) >= '0' && c
<= '9')
15572 field
= field
* 10 + c
- '0';
15574 /* Don't pad beyond the total padding allowed. */
15575 if (field_width
- n
> 0 && field
> field_width
- n
)
15576 field
= field_width
- n
;
15578 /* Note that either PRECISION <= 0 or N < PRECISION. */
15579 prec
= precision
- n
;
15582 n
+= display_mode_element (it
, depth
, field
, prec
,
15583 Vglobal_mode_string
, props
,
15588 int bytepos
, charpos
;
15589 unsigned char *spec
;
15591 bytepos
= percent_position
- lisp_string
;
15592 charpos
= (STRING_MULTIBYTE (elt
)
15593 ? string_byte_to_char (elt
, bytepos
)
15597 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15599 if (frame_title_ptr
)
15600 n
+= store_frame_title (spec
, field
, prec
);
15601 else if (!NILP (mode_line_string_list
))
15603 int len
= strlen (spec
);
15604 Lisp_Object tem
= make_string (spec
, len
);
15605 props
= Ftext_properties_at (make_number (charpos
), elt
);
15606 /* Should only keep face property in props */
15607 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15611 int nglyphs_before
, nwritten
;
15613 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15614 nwritten
= display_string (spec
, Qnil
, elt
,
15619 /* Assign to the glyphs written above the
15620 string where the `%x' came from, position
15624 struct glyph
*glyph
15625 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15629 for (i
= 0; i
< nwritten
; ++i
)
15631 glyph
[i
].object
= elt
;
15632 glyph
[i
].charpos
= charpos
;
15647 /* A symbol: process the value of the symbol recursively
15648 as if it appeared here directly. Avoid error if symbol void.
15649 Special case: if value of symbol is a string, output the string
15652 register Lisp_Object tem
;
15654 /* If the variable is not marked as risky to set
15655 then its contents are risky to use. */
15656 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15659 tem
= Fboundp (elt
);
15662 tem
= Fsymbol_value (elt
);
15663 /* If value is a string, output that string literally:
15664 don't check for % within it. */
15668 if (!EQ (tem
, elt
))
15670 /* Give up right away for nil or t. */
15680 register Lisp_Object car
, tem
;
15682 /* A cons cell: five distinct cases.
15683 If first element is :eval or :propertize, do something special.
15684 If first element is a string or a cons, process all the elements
15685 and effectively concatenate them.
15686 If first element is a negative number, truncate displaying cdr to
15687 at most that many characters. If positive, pad (with spaces)
15688 to at least that many characters.
15689 If first element is a symbol, process the cadr or caddr recursively
15690 according to whether the symbol's value is non-nil or nil. */
15692 if (EQ (car
, QCeval
))
15694 /* An element of the form (:eval FORM) means evaluate FORM
15695 and use the result as mode line elements. */
15700 if (CONSP (XCDR (elt
)))
15703 spec
= safe_eval (XCAR (XCDR (elt
)));
15704 n
+= display_mode_element (it
, depth
, field_width
- n
,
15705 precision
- n
, spec
, props
,
15709 else if (EQ (car
, QCpropertize
))
15711 /* An element of the form (:propertize ELT PROPS...)
15712 means display ELT but applying properties PROPS. */
15717 if (CONSP (XCDR (elt
)))
15718 n
+= display_mode_element (it
, depth
, field_width
- n
,
15719 precision
- n
, XCAR (XCDR (elt
)),
15720 XCDR (XCDR (elt
)), risky
);
15722 else if (SYMBOLP (car
))
15724 tem
= Fboundp (car
);
15728 /* elt is now the cdr, and we know it is a cons cell.
15729 Use its car if CAR has a non-nil value. */
15732 tem
= Fsymbol_value (car
);
15739 /* Symbol's value is nil (or symbol is unbound)
15740 Get the cddr of the original list
15741 and if possible find the caddr and use that. */
15745 else if (!CONSP (elt
))
15750 else if (INTEGERP (car
))
15752 register int lim
= XINT (car
);
15756 /* Negative int means reduce maximum width. */
15757 if (precision
<= 0)
15760 precision
= min (precision
, -lim
);
15764 /* Padding specified. Don't let it be more than
15765 current maximum. */
15767 lim
= min (precision
, lim
);
15769 /* If that's more padding than already wanted, queue it.
15770 But don't reduce padding already specified even if
15771 that is beyond the current truncation point. */
15772 field_width
= max (lim
, field_width
);
15776 else if (STRINGP (car
) || CONSP (car
))
15778 register int limit
= 50;
15779 /* Limit is to protect against circular lists. */
15782 && (precision
<= 0 || n
< precision
))
15784 n
+= display_mode_element (it
, depth
, field_width
- n
,
15785 precision
- n
, XCAR (elt
),
15795 elt
= build_string ("*invalid*");
15799 /* Pad to FIELD_WIDTH. */
15800 if (field_width
> 0 && n
< field_width
)
15802 if (frame_title_ptr
)
15803 n
+= store_frame_title ("", field_width
- n
, 0);
15804 else if (!NILP (mode_line_string_list
))
15805 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15807 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15814 /* Store a mode-line string element in mode_line_string_list.
15816 If STRING is non-null, display that C string. Otherwise, the Lisp
15817 string LISP_STRING is displayed.
15819 FIELD_WIDTH is the minimum number of output glyphs to produce.
15820 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15821 with spaces. FIELD_WIDTH <= 0 means don't pad.
15823 PRECISION is the maximum number of characters to output from
15824 STRING. PRECISION <= 0 means don't truncate the string.
15826 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15827 properties to the string.
15829 PROPS are the properties to add to the string.
15830 The mode_line_string_face face property is always added to the string.
15834 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15836 Lisp_Object lisp_string
;
15845 if (string
!= NULL
)
15847 len
= strlen (string
);
15848 if (precision
> 0 && len
> precision
)
15850 lisp_string
= make_string (string
, len
);
15852 props
= mode_line_string_face_prop
;
15853 else if (!NILP (mode_line_string_face
))
15855 Lisp_Object face
= Fsafe_plist_get (props
, Qface
);
15856 props
= Fcopy_sequence (props
);
15858 face
= mode_line_string_face
;
15860 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15861 props
= Fplist_put (props
, Qface
, face
);
15863 Fadd_text_properties (make_number (0), make_number (len
),
15864 props
, lisp_string
);
15868 len
= XFASTINT (Flength (lisp_string
));
15869 if (precision
> 0 && len
> precision
)
15872 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15875 if (!NILP (mode_line_string_face
))
15879 props
= Ftext_properties_at (make_number (0), lisp_string
);
15880 face
= Fsafe_plist_get (props
, Qface
);
15882 face
= mode_line_string_face
;
15884 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15885 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15887 lisp_string
= Fcopy_sequence (lisp_string
);
15890 Fadd_text_properties (make_number (0), make_number (len
),
15891 props
, lisp_string
);
15896 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15900 if (field_width
> len
)
15902 field_width
-= len
;
15903 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15905 Fadd_text_properties (make_number (0), make_number (field_width
),
15906 props
, lisp_string
);
15907 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15915 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15917 doc
: /* Return the mode-line of selected window as a string.
15918 First optional arg FORMAT specifies a different format string (see
15919 `mode-line-format' for details) to use. If FORMAT is t, return
15920 the buffer's header-line. Second optional arg WINDOW specifies a
15921 different window to use as the context for the formatting.
15922 If third optional arg NO-PROPS is non-nil, string is not propertized.
15923 Fourth optional arg BUFFER specifies which buffer to use. */)
15924 (format
, window
, no_props
, buffer
)
15925 Lisp_Object format
, window
, no_props
, buffer
;
15930 struct buffer
*old_buffer
= NULL
;
15931 enum face_id face_id
= DEFAULT_FACE_ID
;
15934 window
= selected_window
;
15935 CHECK_WINDOW (window
);
15936 w
= XWINDOW (window
);
15939 buffer
= w
->buffer
;
15941 CHECK_BUFFER (buffer
);
15943 if (XBUFFER (buffer
) != current_buffer
)
15945 old_buffer
= current_buffer
;
15946 set_buffer_internal_1 (XBUFFER (buffer
));
15949 if (NILP (format
) || EQ (format
, Qt
))
15951 face_id
= (NILP (format
)
15952 ? CURRENT_MODE_LINE_FACE_ID (w
)
15953 : HEADER_LINE_FACE_ID
);
15954 format
= (NILP (format
)
15955 ? current_buffer
->mode_line_format
15956 : current_buffer
->header_line_format
);
15959 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15961 if (NILP (no_props
))
15963 mode_line_string_face
15964 = (face_id
== MODE_LINE_FACE_ID
? Qmode_line
15965 : face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
15966 : face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15968 mode_line_string_face_prop
15969 = (NILP (mode_line_string_face
) ? Qnil
15970 : Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
)));
15972 /* We need a dummy last element in mode_line_string_list to
15973 indicate we are building the propertized mode-line string.
15974 Using mode_line_string_face_prop here GC protects it. */
15975 mode_line_string_list
15976 = Fcons (mode_line_string_face_prop
, Qnil
);
15977 frame_title_ptr
= NULL
;
15981 mode_line_string_face_prop
= Qnil
;
15982 mode_line_string_list
= Qnil
;
15983 frame_title_ptr
= frame_title_buf
;
15986 push_frame_kboard (it
.f
);
15987 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15988 pop_frame_kboard ();
15991 set_buffer_internal_1 (old_buffer
);
15993 if (NILP (no_props
))
15996 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15997 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15998 make_string ("", 0));
15999 mode_line_string_face_prop
= Qnil
;
16000 mode_line_string_list
= Qnil
;
16004 len
= frame_title_ptr
- frame_title_buf
;
16005 if (len
> 0 && frame_title_ptr
[-1] == '-')
16007 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
16008 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
16010 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
16011 if (len
> frame_title_ptr
- frame_title_buf
)
16012 len
= frame_title_ptr
- frame_title_buf
;
16015 frame_title_ptr
= NULL
;
16016 return make_string (frame_title_buf
, len
);
16019 /* Write a null-terminated, right justified decimal representation of
16020 the positive integer D to BUF using a minimal field width WIDTH. */
16023 pint2str (buf
, width
, d
)
16024 register char *buf
;
16025 register int width
;
16028 register char *p
= buf
;
16036 *p
++ = d
% 10 + '0';
16041 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16052 /* Write a null-terminated, right justified decimal and "human
16053 readable" representation of the nonnegative integer D to BUF using
16054 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16056 static const char power_letter
[] =
16070 pint2hrstr (buf
, width
, d
)
16075 /* We aim to represent the nonnegative integer D as
16076 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16079 /* -1 means: do not use TENTHS. */
16083 /* Length of QUOTIENT.TENTHS as a string. */
16089 if (1000 <= quotient
)
16091 /* Scale to the appropriate EXPONENT. */
16094 remainder
= quotient
% 1000;
16098 while (1000 <= quotient
);
16100 /* Round to nearest and decide whether to use TENTHS or not. */
16103 tenths
= remainder
/ 100;
16104 if (50 <= remainder
% 100)
16111 if (quotient
== 10)
16119 if (500 <= remainder
)
16121 if (quotient
< 999)
16132 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16133 if (tenths
== -1 && quotient
<= 99)
16140 p
= psuffix
= buf
+ max (width
, length
);
16142 /* Print EXPONENT. */
16144 *psuffix
++ = power_letter
[exponent
];
16147 /* Print TENTHS. */
16150 *--p
= '0' + tenths
;
16154 /* Print QUOTIENT. */
16157 int digit
= quotient
% 10;
16158 *--p
= '0' + digit
;
16160 while ((quotient
/= 10) != 0);
16162 /* Print leading spaces. */
16167 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16168 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16169 type of CODING_SYSTEM. Return updated pointer into BUF. */
16171 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16174 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16175 Lisp_Object coding_system
;
16176 register char *buf
;
16180 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16181 const unsigned char *eol_str
;
16183 /* The EOL conversion we are using. */
16184 Lisp_Object eoltype
;
16186 val
= Fget (coding_system
, Qcoding_system
);
16189 if (!VECTORP (val
)) /* Not yet decided. */
16194 eoltype
= eol_mnemonic_undecided
;
16195 /* Don't mention EOL conversion if it isn't decided. */
16199 Lisp_Object eolvalue
;
16201 eolvalue
= Fget (coding_system
, Qeol_type
);
16204 *buf
++ = XFASTINT (AREF (val
, 1));
16208 /* The EOL conversion that is normal on this system. */
16210 if (NILP (eolvalue
)) /* Not yet decided. */
16211 eoltype
= eol_mnemonic_undecided
;
16212 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16213 eoltype
= eol_mnemonic_undecided
;
16214 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16215 eoltype
= (XFASTINT (eolvalue
) == 0
16216 ? eol_mnemonic_unix
16217 : (XFASTINT (eolvalue
) == 1
16218 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16224 /* Mention the EOL conversion if it is not the usual one. */
16225 if (STRINGP (eoltype
))
16227 eol_str
= SDATA (eoltype
);
16228 eol_str_len
= SBYTES (eoltype
);
16230 else if (INTEGERP (eoltype
)
16231 && CHAR_VALID_P (XINT (eoltype
), 0))
16233 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16234 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16239 eol_str
= invalid_eol_type
;
16240 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16242 bcopy (eol_str
, buf
, eol_str_len
);
16243 buf
+= eol_str_len
;
16249 /* Return a string for the output of a mode line %-spec for window W,
16250 generated by character C. PRECISION >= 0 means don't return a
16251 string longer than that value. FIELD_WIDTH > 0 means pad the
16252 string returned with spaces to that value. Return 1 in *MULTIBYTE
16253 if the result is multibyte text.
16255 Note we operate on the current buffer for most purposes,
16256 the exception being w->base_line_pos. */
16258 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16261 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16264 int field_width
, precision
;
16268 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16269 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16270 struct buffer
*b
= current_buffer
;
16278 if (!NILP (b
->read_only
))
16280 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16285 /* This differs from %* only for a modified read-only buffer. */
16286 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16288 if (!NILP (b
->read_only
))
16293 /* This differs from %* in ignoring read-only-ness. */
16294 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16306 if (command_loop_level
> 5)
16308 p
= decode_mode_spec_buf
;
16309 for (i
= 0; i
< command_loop_level
; i
++)
16312 return decode_mode_spec_buf
;
16320 if (command_loop_level
> 5)
16322 p
= decode_mode_spec_buf
;
16323 for (i
= 0; i
< command_loop_level
; i
++)
16326 return decode_mode_spec_buf
;
16333 /* Let lots_of_dashes be a string of infinite length. */
16334 if (!NILP (mode_line_string_list
))
16336 if (field_width
<= 0
16337 || field_width
> sizeof (lots_of_dashes
))
16339 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16340 decode_mode_spec_buf
[i
] = '-';
16341 decode_mode_spec_buf
[i
] = '\0';
16342 return decode_mode_spec_buf
;
16345 return lots_of_dashes
;
16354 int col
= (int) current_column (); /* iftc */
16355 w
->column_number_displayed
= make_number (col
);
16356 pint2str (decode_mode_spec_buf
, field_width
, col
);
16357 return decode_mode_spec_buf
;
16361 /* %F displays the frame name. */
16362 if (!NILP (f
->title
))
16363 return (char *) SDATA (f
->title
);
16364 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16365 return (char *) SDATA (f
->name
);
16374 int size
= ZV
- BEGV
;
16375 pint2str (decode_mode_spec_buf
, field_width
, size
);
16376 return decode_mode_spec_buf
;
16381 int size
= ZV
- BEGV
;
16382 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16383 return decode_mode_spec_buf
;
16388 int startpos
= XMARKER (w
->start
)->charpos
;
16389 int startpos_byte
= marker_byte_position (w
->start
);
16390 int line
, linepos
, linepos_byte
, topline
;
16392 int height
= WINDOW_TOTAL_LINES (w
);
16394 /* If we decided that this buffer isn't suitable for line numbers,
16395 don't forget that too fast. */
16396 if (EQ (w
->base_line_pos
, w
->buffer
))
16398 /* But do forget it, if the window shows a different buffer now. */
16399 else if (BUFFERP (w
->base_line_pos
))
16400 w
->base_line_pos
= Qnil
;
16402 /* If the buffer is very big, don't waste time. */
16403 if (INTEGERP (Vline_number_display_limit
)
16404 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16406 w
->base_line_pos
= Qnil
;
16407 w
->base_line_number
= Qnil
;
16411 if (!NILP (w
->base_line_number
)
16412 && !NILP (w
->base_line_pos
)
16413 && XFASTINT (w
->base_line_pos
) <= startpos
)
16415 line
= XFASTINT (w
->base_line_number
);
16416 linepos
= XFASTINT (w
->base_line_pos
);
16417 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16422 linepos
= BUF_BEGV (b
);
16423 linepos_byte
= BUF_BEGV_BYTE (b
);
16426 /* Count lines from base line to window start position. */
16427 nlines
= display_count_lines (linepos
, linepos_byte
,
16431 topline
= nlines
+ line
;
16433 /* Determine a new base line, if the old one is too close
16434 or too far away, or if we did not have one.
16435 "Too close" means it's plausible a scroll-down would
16436 go back past it. */
16437 if (startpos
== BUF_BEGV (b
))
16439 w
->base_line_number
= make_number (topline
);
16440 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16442 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16443 || linepos
== BUF_BEGV (b
))
16445 int limit
= BUF_BEGV (b
);
16446 int limit_byte
= BUF_BEGV_BYTE (b
);
16448 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16450 if (startpos
- distance
> limit
)
16452 limit
= startpos
- distance
;
16453 limit_byte
= CHAR_TO_BYTE (limit
);
16456 nlines
= display_count_lines (startpos
, startpos_byte
,
16458 - (height
* 2 + 30),
16460 /* If we couldn't find the lines we wanted within
16461 line_number_display_limit_width chars per line,
16462 give up on line numbers for this window. */
16463 if (position
== limit_byte
&& limit
== startpos
- distance
)
16465 w
->base_line_pos
= w
->buffer
;
16466 w
->base_line_number
= Qnil
;
16470 w
->base_line_number
= make_number (topline
- nlines
);
16471 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16474 /* Now count lines from the start pos to point. */
16475 nlines
= display_count_lines (startpos
, startpos_byte
,
16476 PT_BYTE
, PT
, &junk
);
16478 /* Record that we did display the line number. */
16479 line_number_displayed
= 1;
16481 /* Make the string to show. */
16482 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16483 return decode_mode_spec_buf
;
16486 char* p
= decode_mode_spec_buf
;
16487 int pad
= field_width
- 2;
16493 return decode_mode_spec_buf
;
16499 obj
= b
->mode_name
;
16503 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16509 int pos
= marker_position (w
->start
);
16510 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16512 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16514 if (pos
<= BUF_BEGV (b
))
16519 else if (pos
<= BUF_BEGV (b
))
16523 if (total
> 1000000)
16524 /* Do it differently for a large value, to avoid overflow. */
16525 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16527 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16528 /* We can't normally display a 3-digit number,
16529 so get us a 2-digit number that is close. */
16532 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16533 return decode_mode_spec_buf
;
16537 /* Display percentage of size above the bottom of the screen. */
16540 int toppos
= marker_position (w
->start
);
16541 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16542 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16544 if (botpos
>= BUF_ZV (b
))
16546 if (toppos
<= BUF_BEGV (b
))
16553 if (total
> 1000000)
16554 /* Do it differently for a large value, to avoid overflow. */
16555 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16557 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16558 /* We can't normally display a 3-digit number,
16559 so get us a 2-digit number that is close. */
16562 if (toppos
<= BUF_BEGV (b
))
16563 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16565 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16566 return decode_mode_spec_buf
;
16571 /* status of process */
16572 obj
= Fget_buffer_process (Fcurrent_buffer ());
16574 return "no process";
16575 #ifdef subprocesses
16576 obj
= Fsymbol_name (Fprocess_status (obj
));
16580 case 't': /* indicate TEXT or BINARY */
16581 #ifdef MODE_LINE_BINARY_TEXT
16582 return MODE_LINE_BINARY_TEXT (b
);
16588 /* coding-system (not including end-of-line format) */
16590 /* coding-system (including end-of-line type) */
16592 int eol_flag
= (c
== 'Z');
16593 char *p
= decode_mode_spec_buf
;
16595 if (! FRAME_WINDOW_P (f
))
16597 /* No need to mention EOL here--the terminal never needs
16598 to do EOL conversion. */
16599 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
16600 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
16602 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16605 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16606 #ifdef subprocesses
16607 obj
= Fget_buffer_process (Fcurrent_buffer ());
16608 if (PROCESSP (obj
))
16610 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16612 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16615 #endif /* subprocesses */
16618 return decode_mode_spec_buf
;
16624 *multibyte
= STRING_MULTIBYTE (obj
);
16625 return (char *) SDATA (obj
);
16632 /* Count up to COUNT lines starting from START / START_BYTE.
16633 But don't go beyond LIMIT_BYTE.
16634 Return the number of lines thus found (always nonnegative).
16636 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16639 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16640 int start
, start_byte
, limit_byte
, count
;
16643 register unsigned char *cursor
;
16644 unsigned char *base
;
16646 register int ceiling
;
16647 register unsigned char *ceiling_addr
;
16648 int orig_count
= count
;
16650 /* If we are not in selective display mode,
16651 check only for newlines. */
16652 int selective_display
= (!NILP (current_buffer
->selective_display
)
16653 && !INTEGERP (current_buffer
->selective_display
));
16657 while (start_byte
< limit_byte
)
16659 ceiling
= BUFFER_CEILING_OF (start_byte
);
16660 ceiling
= min (limit_byte
- 1, ceiling
);
16661 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16662 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16665 if (selective_display
)
16666 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16669 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16672 if (cursor
!= ceiling_addr
)
16676 start_byte
+= cursor
- base
+ 1;
16677 *byte_pos_ptr
= start_byte
;
16681 if (++cursor
== ceiling_addr
)
16687 start_byte
+= cursor
- base
;
16692 while (start_byte
> limit_byte
)
16694 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16695 ceiling
= max (limit_byte
, ceiling
);
16696 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16697 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16700 if (selective_display
)
16701 while (--cursor
!= ceiling_addr
16702 && *cursor
!= '\n' && *cursor
!= 015)
16705 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16708 if (cursor
!= ceiling_addr
)
16712 start_byte
+= cursor
- base
+ 1;
16713 *byte_pos_ptr
= start_byte
;
16714 /* When scanning backwards, we should
16715 not count the newline posterior to which we stop. */
16716 return - orig_count
- 1;
16722 /* Here we add 1 to compensate for the last decrement
16723 of CURSOR, which took it past the valid range. */
16724 start_byte
+= cursor
- base
+ 1;
16728 *byte_pos_ptr
= limit_byte
;
16731 return - orig_count
+ count
;
16732 return orig_count
- count
;
16738 /***********************************************************************
16740 ***********************************************************************/
16742 /* Display a NUL-terminated string, starting with index START.
16744 If STRING is non-null, display that C string. Otherwise, the Lisp
16745 string LISP_STRING is displayed.
16747 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16748 FACE_STRING. Display STRING or LISP_STRING with the face at
16749 FACE_STRING_POS in FACE_STRING:
16751 Display the string in the environment given by IT, but use the
16752 standard display table, temporarily.
16754 FIELD_WIDTH is the minimum number of output glyphs to produce.
16755 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16756 with spaces. If STRING has more characters, more than FIELD_WIDTH
16757 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16759 PRECISION is the maximum number of characters to output from
16760 STRING. PRECISION < 0 means don't truncate the string.
16762 This is roughly equivalent to printf format specifiers:
16764 FIELD_WIDTH PRECISION PRINTF
16765 ----------------------------------------
16771 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16772 display them, and < 0 means obey the current buffer's value of
16773 enable_multibyte_characters.
16775 Value is the number of glyphs produced. */
16778 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16779 start
, it
, field_width
, precision
, max_x
, multibyte
)
16780 unsigned char *string
;
16781 Lisp_Object lisp_string
;
16782 Lisp_Object face_string
;
16783 int face_string_pos
;
16786 int field_width
, precision
, max_x
;
16789 int hpos_at_start
= it
->hpos
;
16790 int saved_face_id
= it
->face_id
;
16791 struct glyph_row
*row
= it
->glyph_row
;
16793 /* Initialize the iterator IT for iteration over STRING beginning
16794 with index START. */
16795 reseat_to_string (it
, string
, lisp_string
, start
,
16796 precision
, field_width
, multibyte
);
16798 /* If displaying STRING, set up the face of the iterator
16799 from LISP_STRING, if that's given. */
16800 if (STRINGP (face_string
))
16806 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16807 0, it
->region_beg_charpos
,
16808 it
->region_end_charpos
,
16809 &endptr
, it
->base_face_id
, 0);
16810 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16811 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16814 /* Set max_x to the maximum allowed X position. Don't let it go
16815 beyond the right edge of the window. */
16817 max_x
= it
->last_visible_x
;
16819 max_x
= min (max_x
, it
->last_visible_x
);
16821 /* Skip over display elements that are not visible. because IT->w is
16823 if (it
->current_x
< it
->first_visible_x
)
16824 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16825 MOVE_TO_POS
| MOVE_TO_X
);
16827 row
->ascent
= it
->max_ascent
;
16828 row
->height
= it
->max_ascent
+ it
->max_descent
;
16829 row
->phys_ascent
= it
->max_phys_ascent
;
16830 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16831 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16833 /* This condition is for the case that we are called with current_x
16834 past last_visible_x. */
16835 while (it
->current_x
< max_x
)
16837 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16839 /* Get the next display element. */
16840 if (!get_next_display_element (it
))
16843 /* Produce glyphs. */
16844 x_before
= it
->current_x
;
16845 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16846 PRODUCE_GLYPHS (it
);
16848 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16851 while (i
< nglyphs
)
16853 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16855 if (!it
->truncate_lines_p
16856 && x
+ glyph
->pixel_width
> max_x
)
16858 /* End of continued line or max_x reached. */
16859 if (CHAR_GLYPH_PADDING_P (*glyph
))
16861 /* A wide character is unbreakable. */
16862 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16863 it
->current_x
= x_before
;
16867 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16872 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16874 /* Glyph is at least partially visible. */
16876 if (x
< it
->first_visible_x
)
16877 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16881 /* Glyph is off the left margin of the display area.
16882 Should not happen. */
16886 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16887 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16888 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16889 row
->phys_height
= max (row
->phys_height
,
16890 it
->max_phys_ascent
+ it
->max_phys_descent
);
16891 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16892 it
->max_extra_line_spacing
);
16893 x
+= glyph
->pixel_width
;
16897 /* Stop if max_x reached. */
16901 /* Stop at line ends. */
16902 if (ITERATOR_AT_END_OF_LINE_P (it
))
16904 it
->continuation_lines_width
= 0;
16908 set_iterator_to_next (it
, 1);
16910 /* Stop if truncating at the right edge. */
16911 if (it
->truncate_lines_p
16912 && it
->current_x
>= it
->last_visible_x
)
16914 /* Add truncation mark, but don't do it if the line is
16915 truncated at a padding space. */
16916 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16918 if (!FRAME_WINDOW_P (it
->f
))
16922 if (it
->current_x
> it
->last_visible_x
)
16924 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16925 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16927 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16929 row
->used
[TEXT_AREA
] = i
;
16930 produce_special_glyphs (it
, IT_TRUNCATION
);
16933 produce_special_glyphs (it
, IT_TRUNCATION
);
16935 it
->glyph_row
->truncated_on_right_p
= 1;
16941 /* Maybe insert a truncation at the left. */
16942 if (it
->first_visible_x
16943 && IT_CHARPOS (*it
) > 0)
16945 if (!FRAME_WINDOW_P (it
->f
))
16946 insert_left_trunc_glyphs (it
);
16947 it
->glyph_row
->truncated_on_left_p
= 1;
16950 it
->face_id
= saved_face_id
;
16952 /* Value is number of columns displayed. */
16953 return it
->hpos
- hpos_at_start
;
16958 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16959 appears as an element of LIST or as the car of an element of LIST.
16960 If PROPVAL is a list, compare each element against LIST in that
16961 way, and return 1/2 if any element of PROPVAL is found in LIST.
16962 Otherwise return 0. This function cannot quit.
16963 The return value is 2 if the text is invisible but with an ellipsis
16964 and 1 if it's invisible and without an ellipsis. */
16967 invisible_p (propval
, list
)
16968 register Lisp_Object propval
;
16971 register Lisp_Object tail
, proptail
;
16973 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16975 register Lisp_Object tem
;
16977 if (EQ (propval
, tem
))
16979 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16980 return NILP (XCDR (tem
)) ? 1 : 2;
16983 if (CONSP (propval
))
16985 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16987 Lisp_Object propelt
;
16988 propelt
= XCAR (proptail
);
16989 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16991 register Lisp_Object tem
;
16993 if (EQ (propelt
, tem
))
16995 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16996 return NILP (XCDR (tem
)) ? 1 : 2;
17004 /* Calculate a width or height in pixels from a specification using
17005 the following elements:
17008 NUM - a (fractional) multiple of the default font width/height
17009 (NUM) - specifies exactly NUM pixels
17010 UNIT - a fixed number of pixels, see below.
17011 ELEMENT - size of a display element in pixels, see below.
17012 (NUM . SPEC) - equals NUM * SPEC
17013 (+ SPEC SPEC ...) - add pixel values
17014 (- SPEC SPEC ...) - subtract pixel values
17015 (- SPEC) - negate pixel value
17018 INT or FLOAT - a number constant
17019 SYMBOL - use symbol's (buffer local) variable binding.
17022 in - pixels per inch *)
17023 mm - pixels per 1/1000 meter *)
17024 cm - pixels per 1/100 meter *)
17025 width - width of current font in pixels.
17026 height - height of current font in pixels.
17028 *) using the ratio(s) defined in display-pixels-per-inch.
17032 left-fringe - left fringe width in pixels
17033 right-fringe - right fringe width in pixels
17035 left-margin - left margin width in pixels
17036 right-margin - right margin width in pixels
17038 scroll-bar - scroll-bar area width in pixels
17042 Pixels corresponding to 5 inches:
17045 Total width of non-text areas on left side of window (if scroll-bar is on left):
17046 '(space :width (+ left-fringe left-margin scroll-bar))
17048 Align to first text column (in header line):
17049 '(space :align-to 0)
17051 Align to middle of text area minus half the width of variable `my-image'
17052 containing a loaded image:
17053 '(space :align-to (0.5 . (- text my-image)))
17055 Width of left margin minus width of 1 character in the default font:
17056 '(space :width (- left-margin 1))
17058 Width of left margin minus width of 2 characters in the current font:
17059 '(space :width (- left-margin (2 . width)))
17061 Center 1 character over left-margin (in header line):
17062 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17064 Different ways to express width of left fringe plus left margin minus one pixel:
17065 '(space :width (- (+ left-fringe left-margin) (1)))
17066 '(space :width (+ left-fringe left-margin (- (1))))
17067 '(space :width (+ left-fringe left-margin (-1)))
17071 #define NUMVAL(X) \
17072 ((INTEGERP (X) || FLOATP (X)) \
17077 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17082 int width_p
, *align_to
;
17086 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17087 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17090 return OK_PIXELS (0);
17092 if (SYMBOLP (prop
))
17094 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17096 char *unit
= SDATA (SYMBOL_NAME (prop
));
17098 if (unit
[0] == 'i' && unit
[1] == 'n')
17100 else if (unit
[0] == 'm' && unit
[1] == 'm')
17102 else if (unit
[0] == 'c' && unit
[1] == 'm')
17109 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17110 || (CONSP (Vdisplay_pixels_per_inch
)
17112 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17113 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17115 return OK_PIXELS (ppi
/ pixels
);
17121 #ifdef HAVE_WINDOW_SYSTEM
17122 if (EQ (prop
, Qheight
))
17123 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17124 if (EQ (prop
, Qwidth
))
17125 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17127 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17128 return OK_PIXELS (1);
17131 if (EQ (prop
, Qtext
))
17132 return OK_PIXELS (width_p
17133 ? window_box_width (it
->w
, TEXT_AREA
)
17134 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17136 if (align_to
&& *align_to
< 0)
17139 if (EQ (prop
, Qleft
))
17140 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17141 if (EQ (prop
, Qright
))
17142 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17143 if (EQ (prop
, Qcenter
))
17144 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17145 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17146 if (EQ (prop
, Qleft_fringe
))
17147 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17148 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17149 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17150 if (EQ (prop
, Qright_fringe
))
17151 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17152 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17153 : window_box_right_offset (it
->w
, TEXT_AREA
));
17154 if (EQ (prop
, Qleft_margin
))
17155 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17156 if (EQ (prop
, Qright_margin
))
17157 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17158 if (EQ (prop
, Qscroll_bar
))
17159 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17161 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17162 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17163 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17168 if (EQ (prop
, Qleft_fringe
))
17169 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17170 if (EQ (prop
, Qright_fringe
))
17171 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17172 if (EQ (prop
, Qleft_margin
))
17173 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17174 if (EQ (prop
, Qright_margin
))
17175 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17176 if (EQ (prop
, Qscroll_bar
))
17177 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17180 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17183 if (INTEGERP (prop
) || FLOATP (prop
))
17185 int base_unit
= (width_p
17186 ? FRAME_COLUMN_WIDTH (it
->f
)
17187 : FRAME_LINE_HEIGHT (it
->f
));
17188 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17193 Lisp_Object car
= XCAR (prop
);
17194 Lisp_Object cdr
= XCDR (prop
);
17198 #ifdef HAVE_WINDOW_SYSTEM
17199 if (valid_image_p (prop
))
17201 int id
= lookup_image (it
->f
, prop
);
17202 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17204 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17207 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17213 while (CONSP (cdr
))
17215 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17216 font
, width_p
, align_to
))
17219 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17224 if (EQ (car
, Qminus
))
17226 return OK_PIXELS (pixels
);
17229 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17232 if (INTEGERP (car
) || FLOATP (car
))
17235 pixels
= XFLOATINT (car
);
17237 return OK_PIXELS (pixels
);
17238 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17239 font
, width_p
, align_to
))
17240 return OK_PIXELS (pixels
* fact
);
17251 /***********************************************************************
17253 ***********************************************************************/
17255 #ifdef HAVE_WINDOW_SYSTEM
17260 dump_glyph_string (s
)
17261 struct glyph_string
*s
;
17263 fprintf (stderr
, "glyph string\n");
17264 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17265 s
->x
, s
->y
, s
->width
, s
->height
);
17266 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17267 fprintf (stderr
, " hl = %d\n", s
->hl
);
17268 fprintf (stderr
, " left overhang = %d, right = %d\n",
17269 s
->left_overhang
, s
->right_overhang
);
17270 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17271 fprintf (stderr
, " extends to end of line = %d\n",
17272 s
->extends_to_end_of_line_p
);
17273 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17274 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17277 #endif /* GLYPH_DEBUG */
17279 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17280 of XChar2b structures for S; it can't be allocated in
17281 init_glyph_string because it must be allocated via `alloca'. W
17282 is the window on which S is drawn. ROW and AREA are the glyph row
17283 and area within the row from which S is constructed. START is the
17284 index of the first glyph structure covered by S. HL is a
17285 face-override for drawing S. */
17288 #define OPTIONAL_HDC(hdc) hdc,
17289 #define DECLARE_HDC(hdc) HDC hdc;
17290 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17291 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17294 #ifndef OPTIONAL_HDC
17295 #define OPTIONAL_HDC(hdc)
17296 #define DECLARE_HDC(hdc)
17297 #define ALLOCATE_HDC(hdc, f)
17298 #define RELEASE_HDC(hdc, f)
17302 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17303 struct glyph_string
*s
;
17307 struct glyph_row
*row
;
17308 enum glyph_row_area area
;
17310 enum draw_glyphs_face hl
;
17312 bzero (s
, sizeof *s
);
17314 s
->f
= XFRAME (w
->frame
);
17318 s
->display
= FRAME_X_DISPLAY (s
->f
);
17319 s
->window
= FRAME_X_WINDOW (s
->f
);
17320 s
->char2b
= char2b
;
17324 s
->first_glyph
= row
->glyphs
[area
] + start
;
17325 s
->height
= row
->height
;
17326 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17328 /* Display the internal border below the tool-bar window. */
17329 if (WINDOWP (s
->f
->tool_bar_window
)
17330 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17331 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17333 s
->ybase
= s
->y
+ row
->ascent
;
17337 /* Append the list of glyph strings with head H and tail T to the list
17338 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17341 append_glyph_string_lists (head
, tail
, h
, t
)
17342 struct glyph_string
**head
, **tail
;
17343 struct glyph_string
*h
, *t
;
17357 /* Prepend the list of glyph strings with head H and tail T to the
17358 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17362 prepend_glyph_string_lists (head
, tail
, h
, t
)
17363 struct glyph_string
**head
, **tail
;
17364 struct glyph_string
*h
, *t
;
17378 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17379 Set *HEAD and *TAIL to the resulting list. */
17382 append_glyph_string (head
, tail
, s
)
17383 struct glyph_string
**head
, **tail
;
17384 struct glyph_string
*s
;
17386 s
->next
= s
->prev
= NULL
;
17387 append_glyph_string_lists (head
, tail
, s
, s
);
17391 /* Get face and two-byte form of character glyph GLYPH on frame F.
17392 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17393 a pointer to a realized face that is ready for display. */
17395 static INLINE
struct face
*
17396 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17398 struct glyph
*glyph
;
17404 xassert (glyph
->type
== CHAR_GLYPH
);
17405 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17410 if (!glyph
->multibyte_p
)
17412 /* Unibyte case. We don't have to encode, but we have to make
17413 sure to use a face suitable for unibyte. */
17414 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17416 else if (glyph
->u
.ch
< 128
17417 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17419 /* Case of ASCII in a face known to fit ASCII. */
17420 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17424 int c1
, c2
, charset
;
17426 /* Split characters into bytes. If c2 is -1 afterwards, C is
17427 really a one-byte character so that byte1 is zero. */
17428 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17430 STORE_XCHAR2B (char2b
, c1
, c2
);
17432 STORE_XCHAR2B (char2b
, 0, c1
);
17434 /* Maybe encode the character in *CHAR2B. */
17435 if (charset
!= CHARSET_ASCII
)
17437 struct font_info
*font_info
17438 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17441 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17445 /* Make sure X resources of the face are allocated. */
17446 xassert (face
!= NULL
);
17447 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17452 /* Fill glyph string S with composition components specified by S->cmp.
17454 FACES is an array of faces for all components of this composition.
17455 S->gidx is the index of the first component for S.
17456 OVERLAPS_P non-zero means S should draw the foreground only, and
17457 use its physical height for clipping.
17459 Value is the index of a component not in S. */
17462 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17463 struct glyph_string
*s
;
17464 struct face
**faces
;
17471 s
->for_overlaps_p
= overlaps_p
;
17473 s
->face
= faces
[s
->gidx
];
17474 s
->font
= s
->face
->font
;
17475 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17477 /* For all glyphs of this composition, starting at the offset
17478 S->gidx, until we reach the end of the definition or encounter a
17479 glyph that requires the different face, add it to S. */
17481 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17484 /* All glyph strings for the same composition has the same width,
17485 i.e. the width set for the first component of the composition. */
17487 s
->width
= s
->first_glyph
->pixel_width
;
17489 /* If the specified font could not be loaded, use the frame's
17490 default font, but record the fact that we couldn't load it in
17491 the glyph string so that we can draw rectangles for the
17492 characters of the glyph string. */
17493 if (s
->font
== NULL
)
17495 s
->font_not_found_p
= 1;
17496 s
->font
= FRAME_FONT (s
->f
);
17499 /* Adjust base line for subscript/superscript text. */
17500 s
->ybase
+= s
->first_glyph
->voffset
;
17502 xassert (s
->face
&& s
->face
->gc
);
17504 /* This glyph string must always be drawn with 16-bit functions. */
17507 return s
->gidx
+ s
->nchars
;
17511 /* Fill glyph string S from a sequence of character glyphs.
17513 FACE_ID is the face id of the string. START is the index of the
17514 first glyph to consider, END is the index of the last + 1.
17515 OVERLAPS_P non-zero means S should draw the foreground only, and
17516 use its physical height for clipping.
17518 Value is the index of the first glyph not in S. */
17521 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17522 struct glyph_string
*s
;
17524 int start
, end
, overlaps_p
;
17526 struct glyph
*glyph
, *last
;
17528 int glyph_not_available_p
;
17530 xassert (s
->f
== XFRAME (s
->w
->frame
));
17531 xassert (s
->nchars
== 0);
17532 xassert (start
>= 0 && end
> start
);
17534 s
->for_overlaps_p
= overlaps_p
,
17535 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17536 last
= s
->row
->glyphs
[s
->area
] + end
;
17537 voffset
= glyph
->voffset
;
17539 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17541 while (glyph
< last
17542 && glyph
->type
== CHAR_GLYPH
17543 && glyph
->voffset
== voffset
17544 /* Same face id implies same font, nowadays. */
17545 && glyph
->face_id
== face_id
17546 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17550 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17551 s
->char2b
+ s
->nchars
,
17553 s
->two_byte_p
= two_byte_p
;
17555 xassert (s
->nchars
<= end
- start
);
17556 s
->width
+= glyph
->pixel_width
;
17560 s
->font
= s
->face
->font
;
17561 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17563 /* If the specified font could not be loaded, use the frame's font,
17564 but record the fact that we couldn't load it in
17565 S->font_not_found_p so that we can draw rectangles for the
17566 characters of the glyph string. */
17567 if (s
->font
== NULL
|| glyph_not_available_p
)
17569 s
->font_not_found_p
= 1;
17570 s
->font
= FRAME_FONT (s
->f
);
17573 /* Adjust base line for subscript/superscript text. */
17574 s
->ybase
+= voffset
;
17576 xassert (s
->face
&& s
->face
->gc
);
17577 return glyph
- s
->row
->glyphs
[s
->area
];
17581 /* Fill glyph string S from image glyph S->first_glyph. */
17584 fill_image_glyph_string (s
)
17585 struct glyph_string
*s
;
17587 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17588 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17590 s
->slice
= s
->first_glyph
->slice
;
17591 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17592 s
->font
= s
->face
->font
;
17593 s
->width
= s
->first_glyph
->pixel_width
;
17595 /* Adjust base line for subscript/superscript text. */
17596 s
->ybase
+= s
->first_glyph
->voffset
;
17600 /* Fill glyph string S from a sequence of stretch glyphs.
17602 ROW is the glyph row in which the glyphs are found, AREA is the
17603 area within the row. START is the index of the first glyph to
17604 consider, END is the index of the last + 1.
17606 Value is the index of the first glyph not in S. */
17609 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17610 struct glyph_string
*s
;
17611 struct glyph_row
*row
;
17612 enum glyph_row_area area
;
17615 struct glyph
*glyph
, *last
;
17616 int voffset
, face_id
;
17618 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17620 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17621 last
= s
->row
->glyphs
[s
->area
] + end
;
17622 face_id
= glyph
->face_id
;
17623 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17624 s
->font
= s
->face
->font
;
17625 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17626 s
->width
= glyph
->pixel_width
;
17627 voffset
= glyph
->voffset
;
17631 && glyph
->type
== STRETCH_GLYPH
17632 && glyph
->voffset
== voffset
17633 && glyph
->face_id
== face_id
);
17635 s
->width
+= glyph
->pixel_width
;
17637 /* Adjust base line for subscript/superscript text. */
17638 s
->ybase
+= voffset
;
17640 /* The case that face->gc == 0 is handled when drawing the glyph
17641 string by calling PREPARE_FACE_FOR_DISPLAY. */
17643 return glyph
- s
->row
->glyphs
[s
->area
];
17648 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17649 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17650 assumed to be zero. */
17653 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17654 struct glyph
*glyph
;
17658 *left
= *right
= 0;
17660 if (glyph
->type
== CHAR_GLYPH
)
17664 struct font_info
*font_info
;
17668 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17670 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17671 if (font
/* ++KFS: Should this be font_info ? */
17672 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17674 if (pcm
->rbearing
> pcm
->width
)
17675 *right
= pcm
->rbearing
- pcm
->width
;
17676 if (pcm
->lbearing
< 0)
17677 *left
= -pcm
->lbearing
;
17683 /* Return the index of the first glyph preceding glyph string S that
17684 is overwritten by S because of S's left overhang. Value is -1
17685 if no glyphs are overwritten. */
17688 left_overwritten (s
)
17689 struct glyph_string
*s
;
17693 if (s
->left_overhang
)
17696 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17697 int first
= s
->first_glyph
- glyphs
;
17699 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17700 x
-= glyphs
[i
].pixel_width
;
17711 /* Return the index of the first glyph preceding glyph string S that
17712 is overwriting S because of its right overhang. Value is -1 if no
17713 glyph in front of S overwrites S. */
17716 left_overwriting (s
)
17717 struct glyph_string
*s
;
17720 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17721 int first
= s
->first_glyph
- glyphs
;
17725 for (i
= first
- 1; i
>= 0; --i
)
17728 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17731 x
-= glyphs
[i
].pixel_width
;
17738 /* Return the index of the last glyph following glyph string S that is
17739 not overwritten by S because of S's right overhang. Value is -1 if
17740 no such glyph is found. */
17743 right_overwritten (s
)
17744 struct glyph_string
*s
;
17748 if (s
->right_overhang
)
17751 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17752 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17753 int end
= s
->row
->used
[s
->area
];
17755 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17756 x
+= glyphs
[i
].pixel_width
;
17765 /* Return the index of the last glyph following glyph string S that
17766 overwrites S because of its left overhang. Value is negative
17767 if no such glyph is found. */
17770 right_overwriting (s
)
17771 struct glyph_string
*s
;
17774 int end
= s
->row
->used
[s
->area
];
17775 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17776 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17780 for (i
= first
; i
< end
; ++i
)
17783 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17786 x
+= glyphs
[i
].pixel_width
;
17793 /* Get face and two-byte form of character C in face FACE_ID on frame
17794 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17795 means we want to display multibyte text. DISPLAY_P non-zero means
17796 make sure that X resources for the face returned are allocated.
17797 Value is a pointer to a realized face that is ready for display if
17798 DISPLAY_P is non-zero. */
17800 static INLINE
struct face
*
17801 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17805 int multibyte_p
, display_p
;
17807 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17811 /* Unibyte case. We don't have to encode, but we have to make
17812 sure to use a face suitable for unibyte. */
17813 STORE_XCHAR2B (char2b
, 0, c
);
17814 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17815 face
= FACE_FROM_ID (f
, face_id
);
17817 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17819 /* Case of ASCII in a face known to fit ASCII. */
17820 STORE_XCHAR2B (char2b
, 0, c
);
17824 int c1
, c2
, charset
;
17826 /* Split characters into bytes. If c2 is -1 afterwards, C is
17827 really a one-byte character so that byte1 is zero. */
17828 SPLIT_CHAR (c
, charset
, c1
, c2
);
17830 STORE_XCHAR2B (char2b
, c1
, c2
);
17832 STORE_XCHAR2B (char2b
, 0, c1
);
17834 /* Maybe encode the character in *CHAR2B. */
17835 if (face
->font
!= NULL
)
17837 struct font_info
*font_info
17838 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17840 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
17844 /* Make sure X resources of the face are allocated. */
17845 #ifdef HAVE_X_WINDOWS
17849 xassert (face
!= NULL
);
17850 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17857 /* Set background width of glyph string S. START is the index of the
17858 first glyph following S. LAST_X is the right-most x-position + 1
17859 in the drawing area. */
17862 set_glyph_string_background_width (s
, start
, last_x
)
17863 struct glyph_string
*s
;
17867 /* If the face of this glyph string has to be drawn to the end of
17868 the drawing area, set S->extends_to_end_of_line_p. */
17869 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17871 if (start
== s
->row
->used
[s
->area
]
17872 && s
->area
== TEXT_AREA
17873 && ((s
->hl
== DRAW_NORMAL_TEXT
17874 && (s
->row
->fill_line_p
17875 || s
->face
->background
!= default_face
->background
17876 || s
->face
->stipple
!= default_face
->stipple
17877 || s
->row
->mouse_face_p
))
17878 || s
->hl
== DRAW_MOUSE_FACE
17879 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17880 && s
->row
->fill_line_p
)))
17881 s
->extends_to_end_of_line_p
= 1;
17883 /* If S extends its face to the end of the line, set its
17884 background_width to the distance to the right edge of the drawing
17886 if (s
->extends_to_end_of_line_p
)
17887 s
->background_width
= last_x
- s
->x
+ 1;
17889 s
->background_width
= s
->width
;
17893 /* Compute overhangs and x-positions for glyph string S and its
17894 predecessors, or successors. X is the starting x-position for S.
17895 BACKWARD_P non-zero means process predecessors. */
17898 compute_overhangs_and_x (s
, x
, backward_p
)
17899 struct glyph_string
*s
;
17907 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17908 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17918 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17919 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17929 /* The following macros are only called from draw_glyphs below.
17930 They reference the following parameters of that function directly:
17931 `w', `row', `area', and `overlap_p'
17932 as well as the following local variables:
17933 `s', `f', and `hdc' (in W32) */
17936 /* On W32, silently add local `hdc' variable to argument list of
17937 init_glyph_string. */
17938 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17939 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17941 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17942 init_glyph_string (s, char2b, w, row, area, start, hl)
17945 /* Add a glyph string for a stretch glyph to the list of strings
17946 between HEAD and TAIL. START is the index of the stretch glyph in
17947 row area AREA of glyph row ROW. END is the index of the last glyph
17948 in that glyph row area. X is the current output position assigned
17949 to the new glyph string constructed. HL overrides that face of the
17950 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17951 is the right-most x-position of the drawing area. */
17953 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17954 and below -- keep them on one line. */
17955 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17958 s = (struct glyph_string *) alloca (sizeof *s); \
17959 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17960 START = fill_stretch_glyph_string (s, row, area, START, END); \
17961 append_glyph_string (&HEAD, &TAIL, s); \
17967 /* Add a glyph string for an image glyph to the list of strings
17968 between HEAD and TAIL. START is the index of the image glyph in
17969 row area AREA of glyph row ROW. END is the index of the last glyph
17970 in that glyph row area. X is the current output position assigned
17971 to the new glyph string constructed. HL overrides that face of the
17972 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17973 is the right-most x-position of the drawing area. */
17975 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17978 s = (struct glyph_string *) alloca (sizeof *s); \
17979 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17980 fill_image_glyph_string (s); \
17981 append_glyph_string (&HEAD, &TAIL, s); \
17988 /* Add a glyph string for a sequence of character glyphs to the list
17989 of strings between HEAD and TAIL. START is the index of the first
17990 glyph in row area AREA of glyph row ROW that is part of the new
17991 glyph string. END is the index of the last glyph in that glyph row
17992 area. X is the current output position assigned to the new glyph
17993 string constructed. HL overrides that face of the glyph; e.g. it
17994 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17995 right-most x-position of the drawing area. */
17997 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18003 c = (row)->glyphs[area][START].u.ch; \
18004 face_id = (row)->glyphs[area][START].face_id; \
18006 s = (struct glyph_string *) alloca (sizeof *s); \
18007 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18008 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18009 append_glyph_string (&HEAD, &TAIL, s); \
18011 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18016 /* Add a glyph string for a composite sequence to the list of strings
18017 between HEAD and TAIL. START is the index of the first glyph in
18018 row area AREA of glyph row ROW that is part of the new glyph
18019 string. END is the index of the last glyph in that glyph row area.
18020 X is the current output position assigned to the new glyph string
18021 constructed. HL overrides that face of the glyph; e.g. it is
18022 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18023 x-position of the drawing area. */
18025 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18027 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18028 int face_id = (row)->glyphs[area][START].face_id; \
18029 struct face *base_face = FACE_FROM_ID (f, face_id); \
18030 struct composition *cmp = composition_table[cmp_id]; \
18031 int glyph_len = cmp->glyph_len; \
18033 struct face **faces; \
18034 struct glyph_string *first_s = NULL; \
18037 base_face = base_face->ascii_face; \
18038 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18039 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18040 /* At first, fill in `char2b' and `faces'. */ \
18041 for (n = 0; n < glyph_len; n++) \
18043 int c = COMPOSITION_GLYPH (cmp, n); \
18044 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18045 faces[n] = FACE_FROM_ID (f, this_face_id); \
18046 get_char_face_and_encoding (f, c, this_face_id, \
18047 char2b + n, 1, 1); \
18050 /* Make glyph_strings for each glyph sequence that is drawable by \
18051 the same face, and append them to HEAD/TAIL. */ \
18052 for (n = 0; n < cmp->glyph_len;) \
18054 s = (struct glyph_string *) alloca (sizeof *s); \
18055 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18056 append_glyph_string (&(HEAD), &(TAIL), s); \
18064 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18072 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18073 of AREA of glyph row ROW on window W between indices START and END.
18074 HL overrides the face for drawing glyph strings, e.g. it is
18075 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18076 x-positions of the drawing area.
18078 This is an ugly monster macro construct because we must use alloca
18079 to allocate glyph strings (because draw_glyphs can be called
18080 asynchronously). */
18082 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18085 HEAD = TAIL = NULL; \
18086 while (START < END) \
18088 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18089 switch (first_glyph->type) \
18092 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18096 case COMPOSITE_GLYPH: \
18097 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18101 case STRETCH_GLYPH: \
18102 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18106 case IMAGE_GLYPH: \
18107 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18115 set_glyph_string_background_width (s, START, LAST_X); \
18122 /* Draw glyphs between START and END in AREA of ROW on window W,
18123 starting at x-position X. X is relative to AREA in W. HL is a
18124 face-override with the following meaning:
18126 DRAW_NORMAL_TEXT draw normally
18127 DRAW_CURSOR draw in cursor face
18128 DRAW_MOUSE_FACE draw in mouse face.
18129 DRAW_INVERSE_VIDEO draw in mode line face
18130 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18131 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18133 If OVERLAPS_P is non-zero, draw only the foreground of characters
18134 and clip to the physical height of ROW.
18136 Value is the x-position reached, relative to AREA of W. */
18139 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18142 struct glyph_row
*row
;
18143 enum glyph_row_area area
;
18145 enum draw_glyphs_face hl
;
18148 struct glyph_string
*head
, *tail
;
18149 struct glyph_string
*s
;
18150 int last_x
, area_width
;
18153 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18156 ALLOCATE_HDC (hdc
, f
);
18158 /* Let's rather be paranoid than getting a SEGV. */
18159 end
= min (end
, row
->used
[area
]);
18160 start
= max (0, start
);
18161 start
= min (end
, start
);
18163 /* Translate X to frame coordinates. Set last_x to the right
18164 end of the drawing area. */
18165 if (row
->full_width_p
)
18167 /* X is relative to the left edge of W, without scroll bars
18169 x
+= WINDOW_LEFT_EDGE_X (w
);
18170 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18174 int area_left
= window_box_left (w
, area
);
18176 area_width
= window_box_width (w
, area
);
18177 last_x
= area_left
+ area_width
;
18180 /* Build a doubly-linked list of glyph_string structures between
18181 head and tail from what we have to draw. Note that the macro
18182 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18183 the reason we use a separate variable `i'. */
18185 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18187 x_reached
= tail
->x
+ tail
->background_width
;
18191 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18192 the row, redraw some glyphs in front or following the glyph
18193 strings built above. */
18194 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18197 struct glyph_string
*h
, *t
;
18199 /* Compute overhangs for all glyph strings. */
18200 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
18201 for (s
= head
; s
; s
= s
->next
)
18202 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
18204 /* Prepend glyph strings for glyphs in front of the first glyph
18205 string that are overwritten because of the first glyph
18206 string's left overhang. The background of all strings
18207 prepended must be drawn because the first glyph string
18209 i
= left_overwritten (head
);
18213 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18214 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18216 compute_overhangs_and_x (t
, head
->x
, 1);
18217 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18220 /* Prepend glyph strings for glyphs in front of the first glyph
18221 string that overwrite that glyph string because of their
18222 right overhang. For these strings, only the foreground must
18223 be drawn, because it draws over the glyph string at `head'.
18224 The background must not be drawn because this would overwrite
18225 right overhangs of preceding glyphs for which no glyph
18227 i
= left_overwriting (head
);
18230 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18231 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18232 for (s
= h
; s
; s
= s
->next
)
18233 s
->background_filled_p
= 1;
18234 compute_overhangs_and_x (t
, head
->x
, 1);
18235 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18238 /* Append glyphs strings for glyphs following the last glyph
18239 string tail that are overwritten by tail. The background of
18240 these strings has to be drawn because tail's foreground draws
18242 i
= right_overwritten (tail
);
18245 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18246 DRAW_NORMAL_TEXT
, x
, last_x
);
18247 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18248 append_glyph_string_lists (&head
, &tail
, h
, t
);
18251 /* Append glyph strings for glyphs following the last glyph
18252 string tail that overwrite tail. The foreground of such
18253 glyphs has to be drawn because it writes into the background
18254 of tail. The background must not be drawn because it could
18255 paint over the foreground of following glyphs. */
18256 i
= right_overwriting (tail
);
18259 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18260 DRAW_NORMAL_TEXT
, x
, last_x
);
18261 for (s
= h
; s
; s
= s
->next
)
18262 s
->background_filled_p
= 1;
18263 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18264 append_glyph_string_lists (&head
, &tail
, h
, t
);
18268 /* Draw all strings. */
18269 for (s
= head
; s
; s
= s
->next
)
18270 FRAME_RIF (f
)->draw_glyph_string (s
);
18272 if (area
== TEXT_AREA
18273 && !row
->full_width_p
18274 /* When drawing overlapping rows, only the glyph strings'
18275 foreground is drawn, which doesn't erase a cursor
18279 int x0
= head
? head
->x
: x
;
18280 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18282 int text_left
= window_box_left (w
, TEXT_AREA
);
18286 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18287 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18290 /* Value is the x-position up to which drawn, relative to AREA of W.
18291 This doesn't include parts drawn because of overhangs. */
18292 if (row
->full_width_p
)
18293 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18295 x_reached
-= window_box_left (w
, area
);
18297 RELEASE_HDC (hdc
, f
);
18302 /* Expand row matrix if too narrow. Don't expand if area
18305 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18307 if (!fonts_changed_p \
18308 && (it->glyph_row->glyphs[area] \
18309 < it->glyph_row->glyphs[area + 1])) \
18311 it->w->ncols_scale_factor++; \
18312 fonts_changed_p = 1; \
18316 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18317 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18323 struct glyph
*glyph
;
18324 enum glyph_row_area area
= it
->area
;
18326 xassert (it
->glyph_row
);
18327 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18329 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18330 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18332 glyph
->charpos
= CHARPOS (it
->position
);
18333 glyph
->object
= it
->object
;
18334 glyph
->pixel_width
= it
->pixel_width
;
18335 glyph
->ascent
= it
->ascent
;
18336 glyph
->descent
= it
->descent
;
18337 glyph
->voffset
= it
->voffset
;
18338 glyph
->type
= CHAR_GLYPH
;
18339 glyph
->multibyte_p
= it
->multibyte_p
;
18340 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18341 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18342 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18343 || it
->phys_descent
> it
->descent
);
18344 glyph
->padding_p
= 0;
18345 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18346 glyph
->face_id
= it
->face_id
;
18347 glyph
->u
.ch
= it
->char_to_display
;
18348 glyph
->slice
= null_glyph_slice
;
18349 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18350 ++it
->glyph_row
->used
[area
];
18353 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18356 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18357 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18360 append_composite_glyph (it
)
18363 struct glyph
*glyph
;
18364 enum glyph_row_area area
= it
->area
;
18366 xassert (it
->glyph_row
);
18368 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18369 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18371 glyph
->charpos
= CHARPOS (it
->position
);
18372 glyph
->object
= it
->object
;
18373 glyph
->pixel_width
= it
->pixel_width
;
18374 glyph
->ascent
= it
->ascent
;
18375 glyph
->descent
= it
->descent
;
18376 glyph
->voffset
= it
->voffset
;
18377 glyph
->type
= COMPOSITE_GLYPH
;
18378 glyph
->multibyte_p
= it
->multibyte_p
;
18379 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18380 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18381 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18382 || it
->phys_descent
> it
->descent
);
18383 glyph
->padding_p
= 0;
18384 glyph
->glyph_not_available_p
= 0;
18385 glyph
->face_id
= it
->face_id
;
18386 glyph
->u
.cmp_id
= it
->cmp_id
;
18387 glyph
->slice
= null_glyph_slice
;
18388 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18389 ++it
->glyph_row
->used
[area
];
18392 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18396 /* Change IT->ascent and IT->height according to the setting of
18400 take_vertical_position_into_account (it
)
18405 if (it
->voffset
< 0)
18406 /* Increase the ascent so that we can display the text higher
18408 it
->ascent
-= it
->voffset
;
18410 /* Increase the descent so that we can display the text lower
18412 it
->descent
+= it
->voffset
;
18417 /* Produce glyphs/get display metrics for the image IT is loaded with.
18418 See the description of struct display_iterator in dispextern.h for
18419 an overview of struct display_iterator. */
18422 produce_image_glyph (it
)
18428 struct glyph_slice slice
;
18430 xassert (it
->what
== IT_IMAGE
);
18432 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18434 /* Make sure X resources of the face is loaded. */
18435 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18437 if (it
->image_id
< 0)
18439 /* Fringe bitmap. */
18440 it
->ascent
= it
->phys_ascent
= 0;
18441 it
->descent
= it
->phys_descent
= 0;
18442 it
->pixel_width
= 0;
18447 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18449 /* Make sure X resources of the image is loaded. */
18450 prepare_image_for_display (it
->f
, img
);
18452 slice
.x
= slice
.y
= 0;
18453 slice
.width
= img
->width
;
18454 slice
.height
= img
->height
;
18456 if (INTEGERP (it
->slice
.x
))
18457 slice
.x
= XINT (it
->slice
.x
);
18458 else if (FLOATP (it
->slice
.x
))
18459 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18461 if (INTEGERP (it
->slice
.y
))
18462 slice
.y
= XINT (it
->slice
.y
);
18463 else if (FLOATP (it
->slice
.y
))
18464 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18466 if (INTEGERP (it
->slice
.width
))
18467 slice
.width
= XINT (it
->slice
.width
);
18468 else if (FLOATP (it
->slice
.width
))
18469 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18471 if (INTEGERP (it
->slice
.height
))
18472 slice
.height
= XINT (it
->slice
.height
);
18473 else if (FLOATP (it
->slice
.height
))
18474 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18476 if (slice
.x
>= img
->width
)
18477 slice
.x
= img
->width
;
18478 if (slice
.y
>= img
->height
)
18479 slice
.y
= img
->height
;
18480 if (slice
.x
+ slice
.width
>= img
->width
)
18481 slice
.width
= img
->width
- slice
.x
;
18482 if (slice
.y
+ slice
.height
> img
->height
)
18483 slice
.height
= img
->height
- slice
.y
;
18485 if (slice
.width
== 0 || slice
.height
== 0)
18488 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18490 it
->descent
= slice
.height
- glyph_ascent
;
18492 it
->descent
+= img
->vmargin
;
18493 if (slice
.y
+ slice
.height
== img
->height
)
18494 it
->descent
+= img
->vmargin
;
18495 it
->phys_descent
= it
->descent
;
18497 it
->pixel_width
= slice
.width
;
18499 it
->pixel_width
+= img
->hmargin
;
18500 if (slice
.x
+ slice
.width
== img
->width
)
18501 it
->pixel_width
+= img
->hmargin
;
18503 /* It's quite possible for images to have an ascent greater than
18504 their height, so don't get confused in that case. */
18505 if (it
->descent
< 0)
18508 #if 0 /* this breaks image tiling */
18509 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18510 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18511 if (face_ascent
> it
->ascent
)
18512 it
->ascent
= it
->phys_ascent
= face_ascent
;
18517 if (face
->box
!= FACE_NO_BOX
)
18519 if (face
->box_line_width
> 0)
18522 it
->ascent
+= face
->box_line_width
;
18523 if (slice
.y
+ slice
.height
== img
->height
)
18524 it
->descent
+= face
->box_line_width
;
18527 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18528 it
->pixel_width
+= abs (face
->box_line_width
);
18529 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18530 it
->pixel_width
+= abs (face
->box_line_width
);
18533 take_vertical_position_into_account (it
);
18537 struct glyph
*glyph
;
18538 enum glyph_row_area area
= it
->area
;
18540 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18541 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18543 glyph
->charpos
= CHARPOS (it
->position
);
18544 glyph
->object
= it
->object
;
18545 glyph
->pixel_width
= it
->pixel_width
;
18546 glyph
->ascent
= glyph_ascent
;
18547 glyph
->descent
= it
->descent
;
18548 glyph
->voffset
= it
->voffset
;
18549 glyph
->type
= IMAGE_GLYPH
;
18550 glyph
->multibyte_p
= it
->multibyte_p
;
18551 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18552 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18553 glyph
->overlaps_vertically_p
= 0;
18554 glyph
->padding_p
= 0;
18555 glyph
->glyph_not_available_p
= 0;
18556 glyph
->face_id
= it
->face_id
;
18557 glyph
->u
.img_id
= img
->id
;
18558 glyph
->slice
= slice
;
18559 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18560 ++it
->glyph_row
->used
[area
];
18563 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18568 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18569 of the glyph, WIDTH and HEIGHT are the width and height of the
18570 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18573 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18575 Lisp_Object object
;
18579 struct glyph
*glyph
;
18580 enum glyph_row_area area
= it
->area
;
18582 xassert (ascent
>= 0 && ascent
<= height
);
18584 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18585 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18587 glyph
->charpos
= CHARPOS (it
->position
);
18588 glyph
->object
= object
;
18589 glyph
->pixel_width
= width
;
18590 glyph
->ascent
= ascent
;
18591 glyph
->descent
= height
- ascent
;
18592 glyph
->voffset
= it
->voffset
;
18593 glyph
->type
= STRETCH_GLYPH
;
18594 glyph
->multibyte_p
= it
->multibyte_p
;
18595 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18596 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18597 glyph
->overlaps_vertically_p
= 0;
18598 glyph
->padding_p
= 0;
18599 glyph
->glyph_not_available_p
= 0;
18600 glyph
->face_id
= it
->face_id
;
18601 glyph
->u
.stretch
.ascent
= ascent
;
18602 glyph
->u
.stretch
.height
= height
;
18603 glyph
->slice
= null_glyph_slice
;
18604 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18605 ++it
->glyph_row
->used
[area
];
18608 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18612 /* Produce a stretch glyph for iterator IT. IT->object is the value
18613 of the glyph property displayed. The value must be a list
18614 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18617 1. `:width WIDTH' specifies that the space should be WIDTH *
18618 canonical char width wide. WIDTH may be an integer or floating
18621 2. `:relative-width FACTOR' specifies that the width of the stretch
18622 should be computed from the width of the first character having the
18623 `glyph' property, and should be FACTOR times that width.
18625 3. `:align-to HPOS' specifies that the space should be wide enough
18626 to reach HPOS, a value in canonical character units.
18628 Exactly one of the above pairs must be present.
18630 4. `:height HEIGHT' specifies that the height of the stretch produced
18631 should be HEIGHT, measured in canonical character units.
18633 5. `:relative-height FACTOR' specifies that the height of the
18634 stretch should be FACTOR times the height of the characters having
18635 the glyph property.
18637 Either none or exactly one of 4 or 5 must be present.
18639 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18640 of the stretch should be used for the ascent of the stretch.
18641 ASCENT must be in the range 0 <= ASCENT <= 100. */
18644 produce_stretch_glyph (it
)
18647 /* (space :width WIDTH :height HEIGHT ...) */
18648 Lisp_Object prop
, plist
;
18649 int width
= 0, height
= 0, align_to
= -1;
18650 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18653 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18654 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18656 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18658 /* List should start with `space'. */
18659 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18660 plist
= XCDR (it
->object
);
18662 /* Compute the width of the stretch. */
18663 if ((prop
= Fsafe_plist_get (plist
, QCwidth
), !NILP (prop
))
18664 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18666 /* Absolute width `:width WIDTH' specified and valid. */
18667 zero_width_ok_p
= 1;
18670 else if (prop
= Fsafe_plist_get (plist
, QCrelative_width
),
18673 /* Relative width `:relative-width FACTOR' specified and valid.
18674 Compute the width of the characters having the `glyph'
18677 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18680 if (it
->multibyte_p
)
18682 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18683 - IT_BYTEPOS (*it
));
18684 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18687 it2
.c
= *p
, it2
.len
= 1;
18689 it2
.glyph_row
= NULL
;
18690 it2
.what
= IT_CHARACTER
;
18691 x_produce_glyphs (&it2
);
18692 width
= NUMVAL (prop
) * it2
.pixel_width
;
18694 else if ((prop
= Fsafe_plist_get (plist
, QCalign_to
), !NILP (prop
))
18695 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18697 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18698 align_to
= (align_to
< 0
18700 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18701 else if (align_to
< 0)
18702 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18703 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18704 zero_width_ok_p
= 1;
18707 /* Nothing specified -> width defaults to canonical char width. */
18708 width
= FRAME_COLUMN_WIDTH (it
->f
);
18710 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18713 /* Compute height. */
18714 if ((prop
= Fsafe_plist_get (plist
, QCheight
), !NILP (prop
))
18715 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18718 zero_height_ok_p
= 1;
18720 else if (prop
= Fsafe_plist_get (plist
, QCrelative_height
),
18722 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18724 height
= FONT_HEIGHT (font
);
18726 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18729 /* Compute percentage of height used for ascent. If
18730 `:ascent ASCENT' is present and valid, use that. Otherwise,
18731 derive the ascent from the font in use. */
18732 if (prop
= Fsafe_plist_get (plist
, QCascent
),
18733 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18734 ascent
= height
* NUMVAL (prop
) / 100.0;
18735 else if (!NILP (prop
)
18736 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18737 ascent
= min (max (0, (int)tem
), height
);
18739 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18741 if (width
> 0 && height
> 0 && it
->glyph_row
)
18743 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18744 if (!STRINGP (object
))
18745 object
= it
->w
->buffer
;
18746 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18749 it
->pixel_width
= width
;
18750 it
->ascent
= it
->phys_ascent
= ascent
;
18751 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18752 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18754 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18756 if (face
->box_line_width
> 0)
18758 it
->ascent
+= face
->box_line_width
;
18759 it
->descent
+= face
->box_line_width
;
18762 if (it
->start_of_box_run_p
)
18763 it
->pixel_width
+= abs (face
->box_line_width
);
18764 if (it
->end_of_box_run_p
)
18765 it
->pixel_width
+= abs (face
->box_line_width
);
18768 take_vertical_position_into_account (it
);
18771 /* Calculate line-height and line-spacing properties.
18772 An integer value specifies explicit pixel value.
18773 A float value specifies relative value to current face height.
18774 A cons (float . face-name) specifies relative value to
18775 height of specified face font.
18777 Returns height in pixels, or nil. */
18780 calc_line_height_property (it
, prop
, font
, boff
, total
)
18786 Lisp_Object position
, val
;
18787 Lisp_Object face_name
= Qnil
;
18788 int ascent
, descent
, height
, override
;
18790 if (STRINGP (it
->object
))
18791 position
= make_number (IT_STRING_CHARPOS (*it
));
18792 else if (BUFFERP (it
->object
))
18793 position
= make_number (IT_CHARPOS (*it
));
18797 val
= Fget_char_property (position
, prop
, it
->object
);
18802 if (total
&& CONSP (val
) && EQ (XCAR (val
), Qtotal
))
18808 if (INTEGERP (val
))
18813 face_name
= XCDR (val
);
18816 else if (SYMBOLP (val
))
18822 override
= EQ (prop
, Qline_height
);
18824 if (NILP (face_name
))
18826 font
= FRAME_FONT (it
->f
);
18827 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18829 else if (EQ (face_name
, Qt
))
18837 struct font_info
*font_info
;
18839 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
18841 return make_number (-1);
18843 face
= FACE_FROM_ID (it
->f
, face_id
);
18846 return make_number (-1);
18848 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18849 boff
= font_info
->baseline_offset
;
18850 if (font_info
->vertical_centering
)
18851 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18854 ascent
= FONT_BASE (font
) + boff
;
18855 descent
= FONT_DESCENT (font
) - boff
;
18859 it
->override_ascent
= ascent
;
18860 it
->override_descent
= descent
;
18861 it
->override_boff
= boff
;
18864 height
= ascent
+ descent
;
18866 height
= (int)(XFLOAT_DATA (val
) * height
);
18867 else if (INTEGERP (val
))
18868 height
*= XINT (val
);
18870 return make_number (height
);
18875 Produce glyphs/get display metrics for the display element IT is
18876 loaded with. See the description of struct display_iterator in
18877 dispextern.h for an overview of struct display_iterator. */
18880 x_produce_glyphs (it
)
18883 int extra_line_spacing
= it
->extra_line_spacing
;
18885 it
->glyph_not_available_p
= 0;
18887 if (it
->what
== IT_CHARACTER
)
18891 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18893 int font_not_found_p
;
18894 struct font_info
*font_info
;
18895 int boff
; /* baseline offset */
18896 /* We may change it->multibyte_p upon unibyte<->multibyte
18897 conversion. So, save the current value now and restore it
18900 Note: It seems that we don't have to record multibyte_p in
18901 struct glyph because the character code itself tells if or
18902 not the character is multibyte. Thus, in the future, we must
18903 consider eliminating the field `multibyte_p' in the struct
18905 int saved_multibyte_p
= it
->multibyte_p
;
18907 /* Maybe translate single-byte characters to multibyte, or the
18909 it
->char_to_display
= it
->c
;
18910 if (!ASCII_BYTE_P (it
->c
))
18912 if (unibyte_display_via_language_environment
18913 && SINGLE_BYTE_CHAR_P (it
->c
)
18915 || !NILP (Vnonascii_translation_table
)))
18917 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18918 it
->multibyte_p
= 1;
18919 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18920 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18922 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18923 && !it
->multibyte_p
)
18925 it
->multibyte_p
= 1;
18926 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18927 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18931 /* Get font to use. Encode IT->char_to_display. */
18932 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18933 &char2b
, it
->multibyte_p
, 0);
18936 /* When no suitable font found, use the default font. */
18937 font_not_found_p
= font
== NULL
;
18938 if (font_not_found_p
)
18940 font
= FRAME_FONT (it
->f
);
18941 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18946 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18947 boff
= font_info
->baseline_offset
;
18948 if (font_info
->vertical_centering
)
18949 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18952 if (it
->char_to_display
>= ' '
18953 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18955 /* Either unibyte or ASCII. */
18960 pcm
= FRAME_RIF (it
->f
)->per_char_metric
18961 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18963 if (it
->override_ascent
>= 0)
18965 it
->ascent
= it
->override_ascent
;
18966 it
->descent
= it
->override_descent
;
18967 boff
= it
->override_boff
;
18971 it
->ascent
= FONT_BASE (font
) + boff
;
18972 it
->descent
= FONT_DESCENT (font
) - boff
;
18977 it
->phys_ascent
= pcm
->ascent
+ boff
;
18978 it
->phys_descent
= pcm
->descent
- boff
;
18979 it
->pixel_width
= pcm
->width
;
18983 it
->glyph_not_available_p
= 1;
18984 it
->phys_ascent
= it
->ascent
;
18985 it
->phys_descent
= it
->descent
;
18986 it
->pixel_width
= FONT_WIDTH (font
);
18989 if (it
->constrain_row_ascent_descent_p
)
18991 if (it
->descent
> it
->max_descent
)
18993 it
->ascent
+= it
->descent
- it
->max_descent
;
18994 it
->descent
= it
->max_descent
;
18996 if (it
->ascent
> it
->max_ascent
)
18998 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
18999 it
->ascent
= it
->max_ascent
;
19001 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19002 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19003 extra_line_spacing
= 0;
19006 /* If this is a space inside a region of text with
19007 `space-width' property, change its width. */
19008 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19010 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19012 /* If face has a box, add the box thickness to the character
19013 height. If character has a box line to the left and/or
19014 right, add the box line width to the character's width. */
19015 if (face
->box
!= FACE_NO_BOX
)
19017 int thick
= face
->box_line_width
;
19021 it
->ascent
+= thick
;
19022 it
->descent
+= thick
;
19027 if (it
->start_of_box_run_p
)
19028 it
->pixel_width
+= thick
;
19029 if (it
->end_of_box_run_p
)
19030 it
->pixel_width
+= thick
;
19033 /* If face has an overline, add the height of the overline
19034 (1 pixel) and a 1 pixel margin to the character height. */
19035 if (face
->overline_p
)
19038 if (it
->constrain_row_ascent_descent_p
)
19040 if (it
->ascent
> it
->max_ascent
)
19041 it
->ascent
= it
->max_ascent
;
19042 if (it
->descent
> it
->max_descent
)
19043 it
->descent
= it
->max_descent
;
19046 take_vertical_position_into_account (it
);
19048 /* If we have to actually produce glyphs, do it. */
19053 /* Translate a space with a `space-width' property
19054 into a stretch glyph. */
19055 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19056 / FONT_HEIGHT (font
));
19057 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19058 it
->ascent
+ it
->descent
, ascent
);
19063 /* If characters with lbearing or rbearing are displayed
19064 in this line, record that fact in a flag of the
19065 glyph row. This is used to optimize X output code. */
19066 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19067 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19070 else if (it
->char_to_display
== '\n')
19072 /* A newline has no width but we need the height of the line.
19073 But if previous part of the line set a height, don't
19074 increase that height */
19076 Lisp_Object height
;
19078 it
->override_ascent
= -1;
19079 it
->pixel_width
= 0;
19082 height
= calc_line_height_property(it
, Qline_height
, font
, boff
, 0);
19084 if (it
->override_ascent
>= 0)
19086 it
->ascent
= it
->override_ascent
;
19087 it
->descent
= it
->override_descent
;
19088 boff
= it
->override_boff
;
19092 it
->ascent
= FONT_BASE (font
) + boff
;
19093 it
->descent
= FONT_DESCENT (font
) - boff
;
19096 if (EQ (height
, make_number(0)))
19098 if (it
->descent
> it
->max_descent
)
19100 it
->ascent
+= it
->descent
- it
->max_descent
;
19101 it
->descent
= it
->max_descent
;
19103 if (it
->ascent
> it
->max_ascent
)
19105 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19106 it
->ascent
= it
->max_ascent
;
19108 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19109 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19110 it
->constrain_row_ascent_descent_p
= 1;
19111 extra_line_spacing
= 0;
19115 Lisp_Object spacing
;
19118 it
->phys_ascent
= it
->ascent
;
19119 it
->phys_descent
= it
->descent
;
19121 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19122 && face
->box
!= FACE_NO_BOX
19123 && face
->box_line_width
> 0)
19125 it
->ascent
+= face
->box_line_width
;
19126 it
->descent
+= face
->box_line_width
;
19129 && XINT (height
) > it
->ascent
+ it
->descent
)
19130 it
->ascent
= XINT (height
) - it
->descent
;
19132 spacing
= calc_line_height_property(it
, Qline_spacing
, font
, boff
, &total
);
19133 if (INTEGERP (spacing
))
19135 extra_line_spacing
= XINT (spacing
);
19137 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19141 else if (it
->char_to_display
== '\t')
19143 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
19144 int x
= it
->current_x
+ it
->continuation_lines_width
;
19145 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19147 /* If the distance from the current position to the next tab
19148 stop is less than a canonical character width, use the
19149 tab stop after that. */
19150 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
19151 next_tab_x
+= tab_width
;
19153 it
->pixel_width
= next_tab_x
- x
;
19155 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19156 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19160 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19161 it
->ascent
+ it
->descent
, it
->ascent
);
19166 /* A multi-byte character. Assume that the display width of the
19167 character is the width of the character multiplied by the
19168 width of the font. */
19170 /* If we found a font, this font should give us the right
19171 metrics. If we didn't find a font, use the frame's
19172 default font and calculate the width of the character
19173 from the charset width; this is what old redisplay code
19176 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19177 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19179 if (font_not_found_p
|| !pcm
)
19181 int charset
= CHAR_CHARSET (it
->char_to_display
);
19183 it
->glyph_not_available_p
= 1;
19184 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19185 * CHARSET_WIDTH (charset
));
19186 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19187 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19191 it
->pixel_width
= pcm
->width
;
19192 it
->phys_ascent
= pcm
->ascent
+ boff
;
19193 it
->phys_descent
= pcm
->descent
- boff
;
19195 && (pcm
->lbearing
< 0
19196 || pcm
->rbearing
> pcm
->width
))
19197 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19200 it
->ascent
= FONT_BASE (font
) + boff
;
19201 it
->descent
= FONT_DESCENT (font
) - boff
;
19202 if (face
->box
!= FACE_NO_BOX
)
19204 int thick
= face
->box_line_width
;
19208 it
->ascent
+= thick
;
19209 it
->descent
+= thick
;
19214 if (it
->start_of_box_run_p
)
19215 it
->pixel_width
+= thick
;
19216 if (it
->end_of_box_run_p
)
19217 it
->pixel_width
+= thick
;
19220 /* If face has an overline, add the height of the overline
19221 (1 pixel) and a 1 pixel margin to the character height. */
19222 if (face
->overline_p
)
19225 take_vertical_position_into_account (it
);
19230 it
->multibyte_p
= saved_multibyte_p
;
19232 else if (it
->what
== IT_COMPOSITION
)
19234 /* Note: A composition is represented as one glyph in the
19235 glyph matrix. There are no padding glyphs. */
19238 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19240 int font_not_found_p
;
19241 struct font_info
*font_info
;
19242 int boff
; /* baseline offset */
19243 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19245 /* Maybe translate single-byte characters to multibyte. */
19246 it
->char_to_display
= it
->c
;
19247 if (unibyte_display_via_language_environment
19248 && SINGLE_BYTE_CHAR_P (it
->c
)
19251 && !NILP (Vnonascii_translation_table
))))
19253 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19256 /* Get face and font to use. Encode IT->char_to_display. */
19257 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19258 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19259 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19260 &char2b
, it
->multibyte_p
, 0);
19263 /* When no suitable font found, use the default font. */
19264 font_not_found_p
= font
== NULL
;
19265 if (font_not_found_p
)
19267 font
= FRAME_FONT (it
->f
);
19268 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19273 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19274 boff
= font_info
->baseline_offset
;
19275 if (font_info
->vertical_centering
)
19276 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19279 /* There are no padding glyphs, so there is only one glyph to
19280 produce for the composition. Important is that pixel_width,
19281 ascent and descent are the values of what is drawn by
19282 draw_glyphs (i.e. the values of the overall glyphs composed). */
19285 /* If we have not yet calculated pixel size data of glyphs of
19286 the composition for the current face font, calculate them
19287 now. Theoretically, we have to check all fonts for the
19288 glyphs, but that requires much time and memory space. So,
19289 here we check only the font of the first glyph. This leads
19290 to incorrect display very rarely, and C-l (recenter) can
19291 correct the display anyway. */
19292 if (cmp
->font
!= (void *) font
)
19294 /* Ascent and descent of the font of the first character of
19295 this composition (adjusted by baseline offset). Ascent
19296 and descent of overall glyphs should not be less than
19297 them respectively. */
19298 int font_ascent
= FONT_BASE (font
) + boff
;
19299 int font_descent
= FONT_DESCENT (font
) - boff
;
19300 /* Bounding box of the overall glyphs. */
19301 int leftmost
, rightmost
, lowest
, highest
;
19302 int i
, width
, ascent
, descent
;
19304 cmp
->font
= (void *) font
;
19306 /* Initialize the bounding box. */
19308 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19309 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19311 width
= pcm
->width
;
19312 ascent
= pcm
->ascent
;
19313 descent
= pcm
->descent
;
19317 width
= FONT_WIDTH (font
);
19318 ascent
= FONT_BASE (font
);
19319 descent
= FONT_DESCENT (font
);
19323 lowest
= - descent
+ boff
;
19324 highest
= ascent
+ boff
;
19328 && font_info
->default_ascent
19329 && CHAR_TABLE_P (Vuse_default_ascent
)
19330 && !NILP (Faref (Vuse_default_ascent
,
19331 make_number (it
->char_to_display
))))
19332 highest
= font_info
->default_ascent
+ boff
;
19334 /* Draw the first glyph at the normal position. It may be
19335 shifted to right later if some other glyphs are drawn at
19337 cmp
->offsets
[0] = 0;
19338 cmp
->offsets
[1] = boff
;
19340 /* Set cmp->offsets for the remaining glyphs. */
19341 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19343 int left
, right
, btm
, top
;
19344 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19345 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19347 face
= FACE_FROM_ID (it
->f
, face_id
);
19348 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19349 &char2b
, it
->multibyte_p
, 0);
19353 font
= FRAME_FONT (it
->f
);
19354 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19360 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19361 boff
= font_info
->baseline_offset
;
19362 if (font_info
->vertical_centering
)
19363 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19367 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19368 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19370 width
= pcm
->width
;
19371 ascent
= pcm
->ascent
;
19372 descent
= pcm
->descent
;
19376 width
= FONT_WIDTH (font
);
19381 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19383 /* Relative composition with or without
19384 alternate chars. */
19385 left
= (leftmost
+ rightmost
- width
) / 2;
19386 btm
= - descent
+ boff
;
19387 if (font_info
&& font_info
->relative_compose
19388 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19389 || NILP (Faref (Vignore_relative_composition
,
19390 make_number (ch
)))))
19393 if (- descent
>= font_info
->relative_compose
)
19394 /* One extra pixel between two glyphs. */
19396 else if (ascent
<= 0)
19397 /* One extra pixel between two glyphs. */
19398 btm
= lowest
- 1 - ascent
- descent
;
19403 /* A composition rule is specified by an integer
19404 value that encodes global and new reference
19405 points (GREF and NREF). GREF and NREF are
19406 specified by numbers as below:
19408 0---1---2 -- ascent
19412 9--10--11 -- center
19414 ---3---4---5--- baseline
19416 6---7---8 -- descent
19418 int rule
= COMPOSITION_RULE (cmp
, i
);
19419 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19421 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19422 grefx
= gref
% 3, nrefx
= nref
% 3;
19423 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19426 + grefx
* (rightmost
- leftmost
) / 2
19427 - nrefx
* width
/ 2);
19428 btm
= ((grefy
== 0 ? highest
19430 : grefy
== 2 ? lowest
19431 : (highest
+ lowest
) / 2)
19432 - (nrefy
== 0 ? ascent
+ descent
19433 : nrefy
== 1 ? descent
- boff
19435 : (ascent
+ descent
) / 2));
19438 cmp
->offsets
[i
* 2] = left
;
19439 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19441 /* Update the bounding box of the overall glyphs. */
19442 right
= left
+ width
;
19443 top
= btm
+ descent
+ ascent
;
19444 if (left
< leftmost
)
19446 if (right
> rightmost
)
19454 /* If there are glyphs whose x-offsets are negative,
19455 shift all glyphs to the right and make all x-offsets
19459 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19460 cmp
->offsets
[i
* 2] -= leftmost
;
19461 rightmost
-= leftmost
;
19464 cmp
->pixel_width
= rightmost
;
19465 cmp
->ascent
= highest
;
19466 cmp
->descent
= - lowest
;
19467 if (cmp
->ascent
< font_ascent
)
19468 cmp
->ascent
= font_ascent
;
19469 if (cmp
->descent
< font_descent
)
19470 cmp
->descent
= font_descent
;
19473 it
->pixel_width
= cmp
->pixel_width
;
19474 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19475 it
->descent
= it
->phys_descent
= cmp
->descent
;
19477 if (face
->box
!= FACE_NO_BOX
)
19479 int thick
= face
->box_line_width
;
19483 it
->ascent
+= thick
;
19484 it
->descent
+= thick
;
19489 if (it
->start_of_box_run_p
)
19490 it
->pixel_width
+= thick
;
19491 if (it
->end_of_box_run_p
)
19492 it
->pixel_width
+= thick
;
19495 /* If face has an overline, add the height of the overline
19496 (1 pixel) and a 1 pixel margin to the character height. */
19497 if (face
->overline_p
)
19500 take_vertical_position_into_account (it
);
19503 append_composite_glyph (it
);
19505 else if (it
->what
== IT_IMAGE
)
19506 produce_image_glyph (it
);
19507 else if (it
->what
== IT_STRETCH
)
19508 produce_stretch_glyph (it
);
19510 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19511 because this isn't true for images with `:ascent 100'. */
19512 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19513 if (it
->area
== TEXT_AREA
)
19514 it
->current_x
+= it
->pixel_width
;
19516 if (extra_line_spacing
> 0)
19518 it
->descent
+= extra_line_spacing
;
19519 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19520 it
->max_extra_line_spacing
= extra_line_spacing
;
19523 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19524 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19525 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19526 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19530 Output LEN glyphs starting at START at the nominal cursor position.
19531 Advance the nominal cursor over the text. The global variable
19532 updated_window contains the window being updated, updated_row is
19533 the glyph row being updated, and updated_area is the area of that
19534 row being updated. */
19537 x_write_glyphs (start
, len
)
19538 struct glyph
*start
;
19543 xassert (updated_window
&& updated_row
);
19546 /* Write glyphs. */
19548 hpos
= start
- updated_row
->glyphs
[updated_area
];
19549 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19550 updated_row
, updated_area
,
19552 DRAW_NORMAL_TEXT
, 0);
19554 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19555 if (updated_area
== TEXT_AREA
19556 && updated_window
->phys_cursor_on_p
19557 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19558 && updated_window
->phys_cursor
.hpos
>= hpos
19559 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19560 updated_window
->phys_cursor_on_p
= 0;
19564 /* Advance the output cursor. */
19565 output_cursor
.hpos
+= len
;
19566 output_cursor
.x
= x
;
19571 Insert LEN glyphs from START at the nominal cursor position. */
19574 x_insert_glyphs (start
, len
)
19575 struct glyph
*start
;
19580 int line_height
, shift_by_width
, shifted_region_width
;
19581 struct glyph_row
*row
;
19582 struct glyph
*glyph
;
19583 int frame_x
, frame_y
, hpos
;
19585 xassert (updated_window
&& updated_row
);
19587 w
= updated_window
;
19588 f
= XFRAME (WINDOW_FRAME (w
));
19590 /* Get the height of the line we are in. */
19592 line_height
= row
->height
;
19594 /* Get the width of the glyphs to insert. */
19595 shift_by_width
= 0;
19596 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19597 shift_by_width
+= glyph
->pixel_width
;
19599 /* Get the width of the region to shift right. */
19600 shifted_region_width
= (window_box_width (w
, updated_area
)
19605 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19606 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19608 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19609 line_height
, shift_by_width
);
19611 /* Write the glyphs. */
19612 hpos
= start
- row
->glyphs
[updated_area
];
19613 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19615 DRAW_NORMAL_TEXT
, 0);
19617 /* Advance the output cursor. */
19618 output_cursor
.hpos
+= len
;
19619 output_cursor
.x
+= shift_by_width
;
19625 Erase the current text line from the nominal cursor position
19626 (inclusive) to pixel column TO_X (exclusive). The idea is that
19627 everything from TO_X onward is already erased.
19629 TO_X is a pixel position relative to updated_area of
19630 updated_window. TO_X == -1 means clear to the end of this area. */
19633 x_clear_end_of_line (to_x
)
19637 struct window
*w
= updated_window
;
19638 int max_x
, min_y
, max_y
;
19639 int from_x
, from_y
, to_y
;
19641 xassert (updated_window
&& updated_row
);
19642 f
= XFRAME (w
->frame
);
19644 if (updated_row
->full_width_p
)
19645 max_x
= WINDOW_TOTAL_WIDTH (w
);
19647 max_x
= window_box_width (w
, updated_area
);
19648 max_y
= window_text_bottom_y (w
);
19650 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19651 of window. For TO_X > 0, truncate to end of drawing area. */
19657 to_x
= min (to_x
, max_x
);
19659 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19661 /* Notice if the cursor will be cleared by this operation. */
19662 if (!updated_row
->full_width_p
)
19663 notice_overwritten_cursor (w
, updated_area
,
19664 output_cursor
.x
, -1,
19666 MATRIX_ROW_BOTTOM_Y (updated_row
));
19668 from_x
= output_cursor
.x
;
19670 /* Translate to frame coordinates. */
19671 if (updated_row
->full_width_p
)
19673 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19674 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19678 int area_left
= window_box_left (w
, updated_area
);
19679 from_x
+= area_left
;
19683 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19684 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19685 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19687 /* Prevent inadvertently clearing to end of the X window. */
19688 if (to_x
> from_x
&& to_y
> from_y
)
19691 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
19692 to_x
- from_x
, to_y
- from_y
);
19697 #endif /* HAVE_WINDOW_SYSTEM */
19701 /***********************************************************************
19703 ***********************************************************************/
19705 /* Value is the internal representation of the specified cursor type
19706 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19707 of the bar cursor. */
19709 static enum text_cursor_kinds
19710 get_specified_cursor_type (arg
, width
)
19714 enum text_cursor_kinds type
;
19719 if (EQ (arg
, Qbox
))
19720 return FILLED_BOX_CURSOR
;
19722 if (EQ (arg
, Qhollow
))
19723 return HOLLOW_BOX_CURSOR
;
19725 if (EQ (arg
, Qbar
))
19732 && EQ (XCAR (arg
), Qbar
)
19733 && INTEGERP (XCDR (arg
))
19734 && XINT (XCDR (arg
)) >= 0)
19736 *width
= XINT (XCDR (arg
));
19740 if (EQ (arg
, Qhbar
))
19743 return HBAR_CURSOR
;
19747 && EQ (XCAR (arg
), Qhbar
)
19748 && INTEGERP (XCDR (arg
))
19749 && XINT (XCDR (arg
)) >= 0)
19751 *width
= XINT (XCDR (arg
));
19752 return HBAR_CURSOR
;
19755 /* Treat anything unknown as "hollow box cursor".
19756 It was bad to signal an error; people have trouble fixing
19757 .Xdefaults with Emacs, when it has something bad in it. */
19758 type
= HOLLOW_BOX_CURSOR
;
19763 /* Set the default cursor types for specified frame. */
19765 set_frame_cursor_types (f
, arg
)
19772 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19773 FRAME_CURSOR_WIDTH (f
) = width
;
19775 /* By default, set up the blink-off state depending on the on-state. */
19777 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19780 FRAME_BLINK_OFF_CURSOR (f
)
19781 = get_specified_cursor_type (XCDR (tem
), &width
);
19782 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19785 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19789 /* Return the cursor we want to be displayed in window W. Return
19790 width of bar/hbar cursor through WIDTH arg. Return with
19791 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19792 (i.e. if the `system caret' should track this cursor).
19794 In a mini-buffer window, we want the cursor only to appear if we
19795 are reading input from this window. For the selected window, we
19796 want the cursor type given by the frame parameter or buffer local
19797 setting of cursor-type. If explicitly marked off, draw no cursor.
19798 In all other cases, we want a hollow box cursor. */
19800 static enum text_cursor_kinds
19801 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19803 struct glyph
*glyph
;
19805 int *active_cursor
;
19807 struct frame
*f
= XFRAME (w
->frame
);
19808 struct buffer
*b
= XBUFFER (w
->buffer
);
19809 int cursor_type
= DEFAULT_CURSOR
;
19810 Lisp_Object alt_cursor
;
19811 int non_selected
= 0;
19813 *active_cursor
= 1;
19816 if (cursor_in_echo_area
19817 && FRAME_HAS_MINIBUF_P (f
)
19818 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19820 if (w
== XWINDOW (echo_area_window
))
19822 *width
= FRAME_CURSOR_WIDTH (f
);
19823 return FRAME_DESIRED_CURSOR (f
);
19826 *active_cursor
= 0;
19830 /* Nonselected window or nonselected frame. */
19831 else if (w
!= XWINDOW (f
->selected_window
)
19832 #ifdef HAVE_WINDOW_SYSTEM
19833 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19837 *active_cursor
= 0;
19839 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19845 /* Never display a cursor in a window in which cursor-type is nil. */
19846 if (NILP (b
->cursor_type
))
19849 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19852 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19853 return get_specified_cursor_type (alt_cursor
, width
);
19856 /* Get the normal cursor type for this window. */
19857 if (EQ (b
->cursor_type
, Qt
))
19859 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19860 *width
= FRAME_CURSOR_WIDTH (f
);
19863 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19865 /* Use normal cursor if not blinked off. */
19866 if (!w
->cursor_off_p
)
19868 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19869 if (cursor_type
== FILLED_BOX_CURSOR
)
19870 cursor_type
= HOLLOW_BOX_CURSOR
;
19872 return cursor_type
;
19875 /* Cursor is blinked off, so determine how to "toggle" it. */
19877 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19878 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19879 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19881 /* Then see if frame has specified a specific blink off cursor type. */
19882 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19884 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19885 return FRAME_BLINK_OFF_CURSOR (f
);
19889 /* Some people liked having a permanently visible blinking cursor,
19890 while others had very strong opinions against it. So it was
19891 decided to remove it. KFS 2003-09-03 */
19893 /* Finally perform built-in cursor blinking:
19894 filled box <-> hollow box
19895 wide [h]bar <-> narrow [h]bar
19896 narrow [h]bar <-> no cursor
19897 other type <-> no cursor */
19899 if (cursor_type
== FILLED_BOX_CURSOR
)
19900 return HOLLOW_BOX_CURSOR
;
19902 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19905 return cursor_type
;
19913 #ifdef HAVE_WINDOW_SYSTEM
19915 /* Notice when the text cursor of window W has been completely
19916 overwritten by a drawing operation that outputs glyphs in AREA
19917 starting at X0 and ending at X1 in the line starting at Y0 and
19918 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19919 the rest of the line after X0 has been written. Y coordinates
19920 are window-relative. */
19923 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19925 enum glyph_row_area area
;
19926 int x0
, y0
, x1
, y1
;
19928 int cx0
, cx1
, cy0
, cy1
;
19929 struct glyph_row
*row
;
19931 if (!w
->phys_cursor_on_p
)
19933 if (area
!= TEXT_AREA
)
19936 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19937 if (!row
->displays_text_p
)
19940 if (row
->cursor_in_fringe_p
)
19942 row
->cursor_in_fringe_p
= 0;
19943 draw_fringe_bitmap (w
, row
, 0);
19944 w
->phys_cursor_on_p
= 0;
19948 cx0
= w
->phys_cursor
.x
;
19949 cx1
= cx0
+ w
->phys_cursor_width
;
19950 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19953 /* The cursor image will be completely removed from the
19954 screen if the output area intersects the cursor area in
19955 y-direction. When we draw in [y0 y1[, and some part of
19956 the cursor is at y < y0, that part must have been drawn
19957 before. When scrolling, the cursor is erased before
19958 actually scrolling, so we don't come here. When not
19959 scrolling, the rows above the old cursor row must have
19960 changed, and in this case these rows must have written
19961 over the cursor image.
19963 Likewise if part of the cursor is below y1, with the
19964 exception of the cursor being in the first blank row at
19965 the buffer and window end because update_text_area
19966 doesn't draw that row. (Except when it does, but
19967 that's handled in update_text_area.) */
19969 cy0
= w
->phys_cursor
.y
;
19970 cy1
= cy0
+ w
->phys_cursor_height
;
19971 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19974 w
->phys_cursor_on_p
= 0;
19977 #endif /* HAVE_WINDOW_SYSTEM */
19980 /************************************************************************
19982 ************************************************************************/
19984 #ifdef HAVE_WINDOW_SYSTEM
19987 Fix the display of area AREA of overlapping row ROW in window W. */
19990 x_fix_overlapping_area (w
, row
, area
)
19992 struct glyph_row
*row
;
19993 enum glyph_row_area area
;
20000 for (i
= 0; i
< row
->used
[area
];)
20002 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20004 int start
= i
, start_x
= x
;
20008 x
+= row
->glyphs
[area
][i
].pixel_width
;
20011 while (i
< row
->used
[area
]
20012 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20014 draw_glyphs (w
, start_x
, row
, area
,
20016 DRAW_NORMAL_TEXT
, 1);
20020 x
+= row
->glyphs
[area
][i
].pixel_width
;
20030 Draw the cursor glyph of window W in glyph row ROW. See the
20031 comment of draw_glyphs for the meaning of HL. */
20034 draw_phys_cursor_glyph (w
, row
, hl
)
20036 struct glyph_row
*row
;
20037 enum draw_glyphs_face hl
;
20039 /* If cursor hpos is out of bounds, don't draw garbage. This can
20040 happen in mini-buffer windows when switching between echo area
20041 glyphs and mini-buffer. */
20042 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20044 int on_p
= w
->phys_cursor_on_p
;
20046 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20047 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20049 w
->phys_cursor_on_p
= on_p
;
20051 if (hl
== DRAW_CURSOR
)
20052 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20053 /* When we erase the cursor, and ROW is overlapped by other
20054 rows, make sure that these overlapping parts of other rows
20056 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20058 if (row
> w
->current_matrix
->rows
20059 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20060 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20062 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20063 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20064 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20071 Erase the image of a cursor of window W from the screen. */
20074 erase_phys_cursor (w
)
20077 struct frame
*f
= XFRAME (w
->frame
);
20078 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20079 int hpos
= w
->phys_cursor
.hpos
;
20080 int vpos
= w
->phys_cursor
.vpos
;
20081 int mouse_face_here_p
= 0;
20082 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20083 struct glyph_row
*cursor_row
;
20084 struct glyph
*cursor_glyph
;
20085 enum draw_glyphs_face hl
;
20087 /* No cursor displayed or row invalidated => nothing to do on the
20089 if (w
->phys_cursor_type
== NO_CURSOR
)
20090 goto mark_cursor_off
;
20092 /* VPOS >= active_glyphs->nrows means that window has been resized.
20093 Don't bother to erase the cursor. */
20094 if (vpos
>= active_glyphs
->nrows
)
20095 goto mark_cursor_off
;
20097 /* If row containing cursor is marked invalid, there is nothing we
20099 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20100 if (!cursor_row
->enabled_p
)
20101 goto mark_cursor_off
;
20103 /* If line spacing is > 0, old cursor may only be partially visible in
20104 window after split-window. So adjust visible height. */
20105 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20106 window_text_bottom_y (w
) - cursor_row
->y
);
20108 /* If row is completely invisible, don't attempt to delete a cursor which
20109 isn't there. This can happen if cursor is at top of a window, and
20110 we switch to a buffer with a header line in that window. */
20111 if (cursor_row
->visible_height
<= 0)
20112 goto mark_cursor_off
;
20114 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20115 if (cursor_row
->cursor_in_fringe_p
)
20117 cursor_row
->cursor_in_fringe_p
= 0;
20118 draw_fringe_bitmap (w
, cursor_row
, 0);
20119 goto mark_cursor_off
;
20122 /* This can happen when the new row is shorter than the old one.
20123 In this case, either draw_glyphs or clear_end_of_line
20124 should have cleared the cursor. Note that we wouldn't be
20125 able to erase the cursor in this case because we don't have a
20126 cursor glyph at hand. */
20127 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20128 goto mark_cursor_off
;
20130 /* If the cursor is in the mouse face area, redisplay that when
20131 we clear the cursor. */
20132 if (! NILP (dpyinfo
->mouse_face_window
)
20133 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20134 && (vpos
> dpyinfo
->mouse_face_beg_row
20135 || (vpos
== dpyinfo
->mouse_face_beg_row
20136 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20137 && (vpos
< dpyinfo
->mouse_face_end_row
20138 || (vpos
== dpyinfo
->mouse_face_end_row
20139 && hpos
< dpyinfo
->mouse_face_end_col
))
20140 /* Don't redraw the cursor's spot in mouse face if it is at the
20141 end of a line (on a newline). The cursor appears there, but
20142 mouse highlighting does not. */
20143 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20144 mouse_face_here_p
= 1;
20146 /* Maybe clear the display under the cursor. */
20147 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20150 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20153 cursor_glyph
= get_phys_cursor_glyph (w
);
20154 if (cursor_glyph
== NULL
)
20155 goto mark_cursor_off
;
20157 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20158 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20159 width
= min (cursor_glyph
->pixel_width
,
20160 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20162 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20165 /* Erase the cursor by redrawing the character underneath it. */
20166 if (mouse_face_here_p
)
20167 hl
= DRAW_MOUSE_FACE
;
20169 hl
= DRAW_NORMAL_TEXT
;
20170 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20173 w
->phys_cursor_on_p
= 0;
20174 w
->phys_cursor_type
= NO_CURSOR
;
20179 Display or clear cursor of window W. If ON is zero, clear the
20180 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20181 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20184 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20186 int on
, hpos
, vpos
, x
, y
;
20188 struct frame
*f
= XFRAME (w
->frame
);
20189 int new_cursor_type
;
20190 int new_cursor_width
;
20192 struct glyph_row
*glyph_row
;
20193 struct glyph
*glyph
;
20195 /* This is pointless on invisible frames, and dangerous on garbaged
20196 windows and frames; in the latter case, the frame or window may
20197 be in the midst of changing its size, and x and y may be off the
20199 if (! FRAME_VISIBLE_P (f
)
20200 || FRAME_GARBAGED_P (f
)
20201 || vpos
>= w
->current_matrix
->nrows
20202 || hpos
>= w
->current_matrix
->matrix_w
)
20205 /* If cursor is off and we want it off, return quickly. */
20206 if (!on
&& !w
->phys_cursor_on_p
)
20209 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20210 /* If cursor row is not enabled, we don't really know where to
20211 display the cursor. */
20212 if (!glyph_row
->enabled_p
)
20214 w
->phys_cursor_on_p
= 0;
20219 if (!glyph_row
->exact_window_width_line_p
20220 || hpos
< glyph_row
->used
[TEXT_AREA
])
20221 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20223 xassert (interrupt_input_blocked
);
20225 /* Set new_cursor_type to the cursor we want to be displayed. */
20226 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20227 &new_cursor_width
, &active_cursor
);
20229 /* If cursor is currently being shown and we don't want it to be or
20230 it is in the wrong place, or the cursor type is not what we want,
20232 if (w
->phys_cursor_on_p
20234 || w
->phys_cursor
.x
!= x
20235 || w
->phys_cursor
.y
!= y
20236 || new_cursor_type
!= w
->phys_cursor_type
20237 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20238 && new_cursor_width
!= w
->phys_cursor_width
)))
20239 erase_phys_cursor (w
);
20241 /* Don't check phys_cursor_on_p here because that flag is only set
20242 to zero in some cases where we know that the cursor has been
20243 completely erased, to avoid the extra work of erasing the cursor
20244 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20245 still not be visible, or it has only been partly erased. */
20248 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20249 w
->phys_cursor_height
= glyph_row
->height
;
20251 /* Set phys_cursor_.* before x_draw_.* is called because some
20252 of them may need the information. */
20253 w
->phys_cursor
.x
= x
;
20254 w
->phys_cursor
.y
= glyph_row
->y
;
20255 w
->phys_cursor
.hpos
= hpos
;
20256 w
->phys_cursor
.vpos
= vpos
;
20259 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
20260 new_cursor_type
, new_cursor_width
,
20261 on
, active_cursor
);
20265 /* Switch the display of W's cursor on or off, according to the value
20269 update_window_cursor (w
, on
)
20273 /* Don't update cursor in windows whose frame is in the process
20274 of being deleted. */
20275 if (w
->current_matrix
)
20278 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20279 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20285 /* Call update_window_cursor with parameter ON_P on all leaf windows
20286 in the window tree rooted at W. */
20289 update_cursor_in_window_tree (w
, on_p
)
20295 if (!NILP (w
->hchild
))
20296 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20297 else if (!NILP (w
->vchild
))
20298 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20300 update_window_cursor (w
, on_p
);
20302 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20308 Display the cursor on window W, or clear it, according to ON_P.
20309 Don't change the cursor's position. */
20312 x_update_cursor (f
, on_p
)
20316 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20321 Clear the cursor of window W to background color, and mark the
20322 cursor as not shown. This is used when the text where the cursor
20323 is is about to be rewritten. */
20329 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20330 update_window_cursor (w
, 0);
20335 Display the active region described by mouse_face_* according to DRAW. */
20338 show_mouse_face (dpyinfo
, draw
)
20339 Display_Info
*dpyinfo
;
20340 enum draw_glyphs_face draw
;
20342 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20343 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20345 if (/* If window is in the process of being destroyed, don't bother
20347 w
->current_matrix
!= NULL
20348 /* Don't update mouse highlight if hidden */
20349 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20350 /* Recognize when we are called to operate on rows that don't exist
20351 anymore. This can happen when a window is split. */
20352 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20354 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20355 struct glyph_row
*row
, *first
, *last
;
20357 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20358 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20360 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20362 int start_hpos
, end_hpos
, start_x
;
20364 /* For all but the first row, the highlight starts at column 0. */
20367 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20368 start_x
= dpyinfo
->mouse_face_beg_x
;
20377 end_hpos
= dpyinfo
->mouse_face_end_col
;
20379 end_hpos
= row
->used
[TEXT_AREA
];
20381 if (end_hpos
> start_hpos
)
20383 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20384 start_hpos
, end_hpos
,
20388 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20392 /* When we've written over the cursor, arrange for it to
20393 be displayed again. */
20394 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20397 display_and_set_cursor (w
, 1,
20398 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20399 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20404 /* Change the mouse cursor. */
20405 if (draw
== DRAW_NORMAL_TEXT
)
20406 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20407 else if (draw
== DRAW_MOUSE_FACE
)
20408 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20410 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20414 Clear out the mouse-highlighted active region.
20415 Redraw it un-highlighted first. Value is non-zero if mouse
20416 face was actually drawn unhighlighted. */
20419 clear_mouse_face (dpyinfo
)
20420 Display_Info
*dpyinfo
;
20424 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20426 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20430 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20431 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20432 dpyinfo
->mouse_face_window
= Qnil
;
20433 dpyinfo
->mouse_face_overlay
= Qnil
;
20439 Non-zero if physical cursor of window W is within mouse face. */
20442 cursor_in_mouse_face_p (w
)
20445 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20446 int in_mouse_face
= 0;
20448 if (WINDOWP (dpyinfo
->mouse_face_window
)
20449 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20451 int hpos
= w
->phys_cursor
.hpos
;
20452 int vpos
= w
->phys_cursor
.vpos
;
20454 if (vpos
>= dpyinfo
->mouse_face_beg_row
20455 && vpos
<= dpyinfo
->mouse_face_end_row
20456 && (vpos
> dpyinfo
->mouse_face_beg_row
20457 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20458 && (vpos
< dpyinfo
->mouse_face_end_row
20459 || hpos
< dpyinfo
->mouse_face_end_col
20460 || dpyinfo
->mouse_face_past_end
))
20464 return in_mouse_face
;
20470 /* Find the glyph matrix position of buffer position CHARPOS in window
20471 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20472 current glyphs must be up to date. If CHARPOS is above window
20473 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20474 of last line in W. In the row containing CHARPOS, stop before glyphs
20475 having STOP as object. */
20477 #if 1 /* This is a version of fast_find_position that's more correct
20478 in the presence of hscrolling, for example. I didn't install
20479 it right away because the problem fixed is minor, it failed
20480 in 20.x as well, and I think it's too risky to install
20481 so near the release of 21.1. 2001-09-25 gerd. */
20484 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20487 int *hpos
, *vpos
, *x
, *y
;
20490 struct glyph_row
*row
, *first
;
20491 struct glyph
*glyph
, *end
;
20494 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20495 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20500 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20504 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20507 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20513 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20515 glyph
= row
->glyphs
[TEXT_AREA
];
20516 end
= glyph
+ row
->used
[TEXT_AREA
];
20518 /* Skip over glyphs not having an object at the start of the row.
20519 These are special glyphs like truncation marks on terminal
20521 if (row
->displays_text_p
)
20523 && INTEGERP (glyph
->object
)
20524 && !EQ (stop
, glyph
->object
)
20525 && glyph
->charpos
< 0)
20527 *x
+= glyph
->pixel_width
;
20532 && !INTEGERP (glyph
->object
)
20533 && !EQ (stop
, glyph
->object
)
20534 && (!BUFFERP (glyph
->object
)
20535 || glyph
->charpos
< charpos
))
20537 *x
+= glyph
->pixel_width
;
20541 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20548 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20551 int *hpos
, *vpos
, *x
, *y
;
20556 int maybe_next_line_p
= 0;
20557 int line_start_position
;
20558 int yb
= window_text_bottom_y (w
);
20559 struct glyph_row
*row
, *best_row
;
20560 int row_vpos
, best_row_vpos
;
20563 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20564 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20566 while (row
->y
< yb
)
20568 if (row
->used
[TEXT_AREA
])
20569 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20571 line_start_position
= 0;
20573 if (line_start_position
> pos
)
20575 /* If the position sought is the end of the buffer,
20576 don't include the blank lines at the bottom of the window. */
20577 else if (line_start_position
== pos
20578 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20580 maybe_next_line_p
= 1;
20583 else if (line_start_position
> 0)
20586 best_row_vpos
= row_vpos
;
20589 if (row
->y
+ row
->height
>= yb
)
20596 /* Find the right column within BEST_ROW. */
20598 current_x
= best_row
->x
;
20599 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20601 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20602 int charpos
= glyph
->charpos
;
20604 if (BUFFERP (glyph
->object
))
20606 if (charpos
== pos
)
20609 *vpos
= best_row_vpos
;
20614 else if (charpos
> pos
)
20617 else if (EQ (glyph
->object
, stop
))
20622 current_x
+= glyph
->pixel_width
;
20625 /* If we're looking for the end of the buffer,
20626 and we didn't find it in the line we scanned,
20627 use the start of the following line. */
20628 if (maybe_next_line_p
)
20633 current_x
= best_row
->x
;
20636 *vpos
= best_row_vpos
;
20637 *hpos
= lastcol
+ 1;
20646 /* Find the position of the glyph for position POS in OBJECT in
20647 window W's current matrix, and return in *X, *Y the pixel
20648 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20650 RIGHT_P non-zero means return the position of the right edge of the
20651 glyph, RIGHT_P zero means return the left edge position.
20653 If no glyph for POS exists in the matrix, return the position of
20654 the glyph with the next smaller position that is in the matrix, if
20655 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20656 exists in the matrix, return the position of the glyph with the
20657 next larger position in OBJECT.
20659 Value is non-zero if a glyph was found. */
20662 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20665 Lisp_Object object
;
20666 int *hpos
, *vpos
, *x
, *y
;
20669 int yb
= window_text_bottom_y (w
);
20670 struct glyph_row
*r
;
20671 struct glyph
*best_glyph
= NULL
;
20672 struct glyph_row
*best_row
= NULL
;
20675 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20676 r
->enabled_p
&& r
->y
< yb
;
20679 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20680 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20683 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20684 if (EQ (g
->object
, object
))
20686 if (g
->charpos
== pos
)
20693 else if (best_glyph
== NULL
20694 || ((abs (g
->charpos
- pos
)
20695 < abs (best_glyph
->charpos
- pos
))
20698 : g
->charpos
> pos
)))
20712 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20716 *x
+= best_glyph
->pixel_width
;
20721 *vpos
= best_row
- w
->current_matrix
->rows
;
20724 return best_glyph
!= NULL
;
20728 /* See if position X, Y is within a hot-spot of an image. */
20731 on_hot_spot_p (hot_spot
, x
, y
)
20732 Lisp_Object hot_spot
;
20735 if (!CONSP (hot_spot
))
20738 if (EQ (XCAR (hot_spot
), Qrect
))
20740 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20741 Lisp_Object rect
= XCDR (hot_spot
);
20745 if (!CONSP (XCAR (rect
)))
20747 if (!CONSP (XCDR (rect
)))
20749 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20751 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20753 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20755 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20759 else if (EQ (XCAR (hot_spot
), Qcircle
))
20761 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20762 Lisp_Object circ
= XCDR (hot_spot
);
20763 Lisp_Object lr
, lx0
, ly0
;
20765 && CONSP (XCAR (circ
))
20766 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20767 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20768 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20770 double r
= XFLOATINT (lr
);
20771 double dx
= XINT (lx0
) - x
;
20772 double dy
= XINT (ly0
) - y
;
20773 return (dx
* dx
+ dy
* dy
<= r
* r
);
20776 else if (EQ (XCAR (hot_spot
), Qpoly
))
20778 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20779 if (VECTORP (XCDR (hot_spot
)))
20781 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20782 Lisp_Object
*poly
= v
->contents
;
20786 Lisp_Object lx
, ly
;
20789 /* Need an even number of coordinates, and at least 3 edges. */
20790 if (n
< 6 || n
& 1)
20793 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20794 If count is odd, we are inside polygon. Pixels on edges
20795 may or may not be included depending on actual geometry of the
20797 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20798 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20800 x0
= XINT (lx
), y0
= XINT (ly
);
20801 for (i
= 0; i
< n
; i
+= 2)
20803 int x1
= x0
, y1
= y0
;
20804 if ((lx
= poly
[i
], !INTEGERP (lx
))
20805 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20807 x0
= XINT (lx
), y0
= XINT (ly
);
20809 /* Does this segment cross the X line? */
20817 if (y
> y0
&& y
> y1
)
20819 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20829 find_hot_spot (map
, x
, y
)
20833 while (CONSP (map
))
20835 if (CONSP (XCAR (map
))
20836 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20844 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20846 doc
: /* Lookup in image map MAP coordinates X and Y.
20847 An image map is an alist where each element has the format (AREA ID PLIST).
20848 An AREA is specified as either a rectangle, a circle, or a polygon:
20849 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20850 pixel coordinates of the upper left and bottom right corners.
20851 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20852 and the radius of the circle; r may be a float or integer.
20853 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20854 vector describes one corner in the polygon.
20855 Returns the alist element for the first matching AREA in MAP. */)
20866 return find_hot_spot (map
, XINT (x
), XINT (y
));
20870 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20872 define_frame_cursor1 (f
, cursor
, pointer
)
20875 Lisp_Object pointer
;
20877 /* Do not change cursor shape while dragging mouse. */
20878 if (!NILP (do_mouse_tracking
))
20881 if (!NILP (pointer
))
20883 if (EQ (pointer
, Qarrow
))
20884 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20885 else if (EQ (pointer
, Qhand
))
20886 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20887 else if (EQ (pointer
, Qtext
))
20888 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20889 else if (EQ (pointer
, intern ("hdrag")))
20890 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20891 #ifdef HAVE_X_WINDOWS
20892 else if (EQ (pointer
, intern ("vdrag")))
20893 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20895 else if (EQ (pointer
, intern ("hourglass")))
20896 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20897 else if (EQ (pointer
, Qmodeline
))
20898 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20900 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20903 if (cursor
!= No_Cursor
)
20904 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
20907 /* Take proper action when mouse has moved to the mode or header line
20908 or marginal area AREA of window W, x-position X and y-position Y.
20909 X is relative to the start of the text display area of W, so the
20910 width of bitmap areas and scroll bars must be subtracted to get a
20911 position relative to the start of the mode line. */
20914 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20917 enum window_part area
;
20919 struct frame
*f
= XFRAME (w
->frame
);
20920 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20921 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20922 Lisp_Object pointer
= Qnil
;
20923 int charpos
, dx
, dy
, width
, height
;
20924 Lisp_Object string
, object
= Qnil
;
20925 Lisp_Object pos
, help
;
20927 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20928 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20929 &object
, &dx
, &dy
, &width
, &height
);
20932 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20933 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20934 &object
, &dx
, &dy
, &width
, &height
);
20939 if (IMAGEP (object
))
20941 Lisp_Object image_map
, hotspot
;
20942 if ((image_map
= Fsafe_plist_get (XCDR (object
), QCmap
),
20944 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20946 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20948 Lisp_Object area_id
, plist
;
20950 area_id
= XCAR (hotspot
);
20951 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20952 If so, we could look for mouse-enter, mouse-leave
20953 properties in PLIST (and do something...). */
20954 hotspot
= XCDR (hotspot
);
20955 if (CONSP (hotspot
)
20956 && (plist
= XCAR (hotspot
), CONSP (plist
)))
20958 pointer
= Fsafe_plist_get (plist
, Qpointer
);
20959 if (NILP (pointer
))
20961 help
= Fsafe_plist_get (plist
, Qhelp_echo
);
20964 help_echo_string
= help
;
20965 /* Is this correct? ++kfs */
20966 XSETWINDOW (help_echo_window
, w
);
20967 help_echo_object
= w
->buffer
;
20968 help_echo_pos
= charpos
;
20971 if (NILP (pointer
))
20972 pointer
= Fsafe_plist_get (XCDR (object
), QCpointer
);
20976 if (STRINGP (string
))
20978 pos
= make_number (charpos
);
20979 /* If we're on a string with `help-echo' text property, arrange
20980 for the help to be displayed. This is done by setting the
20981 global variable help_echo_string to the help string. */
20984 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20987 help_echo_string
= help
;
20988 XSETWINDOW (help_echo_window
, w
);
20989 help_echo_object
= string
;
20990 help_echo_pos
= charpos
;
20994 if (NILP (pointer
))
20995 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20997 /* Change the mouse pointer according to what is under X/Y. */
20998 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21001 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21002 if (!KEYMAPP (map
))
21003 map
= Fget_text_property (pos
, Qkeymap
, string
);
21004 if (!KEYMAPP (map
))
21005 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21009 define_frame_cursor1 (f
, cursor
, pointer
);
21014 Take proper action when the mouse has moved to position X, Y on
21015 frame F as regards highlighting characters that have mouse-face
21016 properties. Also de-highlighting chars where the mouse was before.
21017 X and Y can be negative or out of range. */
21020 note_mouse_highlight (f
, x
, y
)
21024 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21025 enum window_part part
;
21026 Lisp_Object window
;
21028 Cursor cursor
= No_Cursor
;
21029 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21032 /* When a menu is active, don't highlight because this looks odd. */
21033 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21034 if (popup_activated ())
21038 if (NILP (Vmouse_highlight
)
21039 || !f
->glyphs_initialized_p
)
21042 dpyinfo
->mouse_face_mouse_x
= x
;
21043 dpyinfo
->mouse_face_mouse_y
= y
;
21044 dpyinfo
->mouse_face_mouse_frame
= f
;
21046 if (dpyinfo
->mouse_face_defer
)
21049 if (gc_in_progress
)
21051 dpyinfo
->mouse_face_deferred_gc
= 1;
21055 /* Which window is that in? */
21056 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21058 /* If we were displaying active text in another window, clear that.
21059 Also clear if we move out of text area in same window. */
21060 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21061 || (part
!= ON_TEXT
&& !NILP (dpyinfo
->mouse_face_window
)))
21062 clear_mouse_face (dpyinfo
);
21064 /* Not on a window -> return. */
21065 if (!WINDOWP (window
))
21068 /* Reset help_echo_string. It will get recomputed below. */
21069 help_echo_string
= Qnil
;
21071 /* Convert to window-relative pixel coordinates. */
21072 w
= XWINDOW (window
);
21073 frame_to_window_pixel_xy (w
, &x
, &y
);
21075 /* Handle tool-bar window differently since it doesn't display a
21077 if (EQ (window
, f
->tool_bar_window
))
21079 note_tool_bar_highlight (f
, x
, y
);
21083 /* Mouse is on the mode, header line or margin? */
21084 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21085 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21087 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
21091 if (part
== ON_VERTICAL_BORDER
)
21092 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21093 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21094 || part
== ON_SCROLL_BAR
)
21095 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21097 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21099 /* Are we in a window whose display is up to date?
21100 And verify the buffer's text has not changed. */
21101 b
= XBUFFER (w
->buffer
);
21102 if (part
== ON_TEXT
21103 && EQ (w
->window_end_valid
, w
->buffer
)
21104 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21105 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21107 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21108 struct glyph
*glyph
;
21109 Lisp_Object object
;
21110 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21111 Lisp_Object
*overlay_vec
= NULL
;
21113 struct buffer
*obuf
;
21114 int obegv
, ozv
, same_region
;
21116 /* Find the glyph under X/Y. */
21117 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21119 /* Look for :pointer property on image. */
21120 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21122 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21123 if (img
!= NULL
&& IMAGEP (img
->spec
))
21125 Lisp_Object image_map
, hotspot
;
21126 if ((image_map
= Fsafe_plist_get (XCDR (img
->spec
), QCmap
),
21128 && (hotspot
= find_hot_spot (image_map
,
21129 glyph
->slice
.x
+ dx
,
21130 glyph
->slice
.y
+ dy
),
21132 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21134 Lisp_Object area_id
, plist
;
21136 area_id
= XCAR (hotspot
);
21137 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21138 If so, we could look for mouse-enter, mouse-leave
21139 properties in PLIST (and do something...). */
21140 hotspot
= XCDR (hotspot
);
21141 if (CONSP (hotspot
)
21142 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21144 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21145 if (NILP (pointer
))
21147 help_echo_string
= Fsafe_plist_get (plist
, Qhelp_echo
);
21148 if (!NILP (help_echo_string
))
21150 help_echo_window
= window
;
21151 help_echo_object
= glyph
->object
;
21152 help_echo_pos
= glyph
->charpos
;
21156 if (NILP (pointer
))
21157 pointer
= Fsafe_plist_get (XCDR (img
->spec
), QCpointer
);
21161 /* Clear mouse face if X/Y not over text. */
21163 || area
!= TEXT_AREA
21164 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21166 if (clear_mouse_face (dpyinfo
))
21167 cursor
= No_Cursor
;
21168 if (NILP (pointer
))
21170 if (area
!= TEXT_AREA
)
21171 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21173 pointer
= Vvoid_text_area_pointer
;
21178 pos
= glyph
->charpos
;
21179 object
= glyph
->object
;
21180 if (!STRINGP (object
) && !BUFFERP (object
))
21183 /* If we get an out-of-range value, return now; avoid an error. */
21184 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21187 /* Make the window's buffer temporarily current for
21188 overlays_at and compute_char_face. */
21189 obuf
= current_buffer
;
21190 current_buffer
= b
;
21196 /* Is this char mouse-active or does it have help-echo? */
21197 position
= make_number (pos
);
21199 if (BUFFERP (object
))
21201 /* Put all the overlays we want in a vector in overlay_vec. */
21202 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21203 /* Sort overlays into increasing priority order. */
21204 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21209 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21210 && vpos
>= dpyinfo
->mouse_face_beg_row
21211 && vpos
<= dpyinfo
->mouse_face_end_row
21212 && (vpos
> dpyinfo
->mouse_face_beg_row
21213 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21214 && (vpos
< dpyinfo
->mouse_face_end_row
21215 || hpos
< dpyinfo
->mouse_face_end_col
21216 || dpyinfo
->mouse_face_past_end
));
21219 cursor
= No_Cursor
;
21221 /* Check mouse-face highlighting. */
21223 /* If there exists an overlay with mouse-face overlapping
21224 the one we are currently highlighting, we have to
21225 check if we enter the overlapping overlay, and then
21226 highlight only that. */
21227 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21228 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21230 /* Find the highest priority overlay that has a mouse-face
21233 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21235 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21236 if (!NILP (mouse_face
))
21237 overlay
= overlay_vec
[i
];
21240 /* If we're actually highlighting the same overlay as
21241 before, there's no need to do that again. */
21242 if (!NILP (overlay
)
21243 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21244 goto check_help_echo
;
21246 dpyinfo
->mouse_face_overlay
= overlay
;
21248 /* Clear the display of the old active region, if any. */
21249 if (clear_mouse_face (dpyinfo
))
21250 cursor
= No_Cursor
;
21252 /* If no overlay applies, get a text property. */
21253 if (NILP (overlay
))
21254 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21256 /* Handle the overlay case. */
21257 if (!NILP (overlay
))
21259 /* Find the range of text around this char that
21260 should be active. */
21261 Lisp_Object before
, after
;
21264 before
= Foverlay_start (overlay
);
21265 after
= Foverlay_end (overlay
);
21266 /* Record this as the current active region. */
21267 fast_find_position (w
, XFASTINT (before
),
21268 &dpyinfo
->mouse_face_beg_col
,
21269 &dpyinfo
->mouse_face_beg_row
,
21270 &dpyinfo
->mouse_face_beg_x
,
21271 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21273 dpyinfo
->mouse_face_past_end
21274 = !fast_find_position (w
, XFASTINT (after
),
21275 &dpyinfo
->mouse_face_end_col
,
21276 &dpyinfo
->mouse_face_end_row
,
21277 &dpyinfo
->mouse_face_end_x
,
21278 &dpyinfo
->mouse_face_end_y
, Qnil
);
21279 dpyinfo
->mouse_face_window
= window
;
21281 dpyinfo
->mouse_face_face_id
21282 = face_at_buffer_position (w
, pos
, 0, 0,
21284 !dpyinfo
->mouse_face_hidden
);
21286 /* Display it as active. */
21287 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21288 cursor
= No_Cursor
;
21290 /* Handle the text property case. */
21291 else if (!NILP (mouse_face
) && BUFFERP (object
))
21293 /* Find the range of text around this char that
21294 should be active. */
21295 Lisp_Object before
, after
, beginning
, end
;
21298 beginning
= Fmarker_position (w
->start
);
21299 end
= make_number (BUF_Z (XBUFFER (object
))
21300 - XFASTINT (w
->window_end_pos
));
21302 = Fprevious_single_property_change (make_number (pos
+ 1),
21304 object
, beginning
);
21306 = Fnext_single_property_change (position
, Qmouse_face
,
21309 /* Record this as the current active region. */
21310 fast_find_position (w
, XFASTINT (before
),
21311 &dpyinfo
->mouse_face_beg_col
,
21312 &dpyinfo
->mouse_face_beg_row
,
21313 &dpyinfo
->mouse_face_beg_x
,
21314 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21315 dpyinfo
->mouse_face_past_end
21316 = !fast_find_position (w
, XFASTINT (after
),
21317 &dpyinfo
->mouse_face_end_col
,
21318 &dpyinfo
->mouse_face_end_row
,
21319 &dpyinfo
->mouse_face_end_x
,
21320 &dpyinfo
->mouse_face_end_y
, Qnil
);
21321 dpyinfo
->mouse_face_window
= window
;
21323 if (BUFFERP (object
))
21324 dpyinfo
->mouse_face_face_id
21325 = face_at_buffer_position (w
, pos
, 0, 0,
21327 !dpyinfo
->mouse_face_hidden
);
21329 /* Display it as active. */
21330 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21331 cursor
= No_Cursor
;
21333 else if (!NILP (mouse_face
) && STRINGP (object
))
21338 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21341 e
= Fnext_single_property_change (position
, Qmouse_face
,
21344 b
= make_number (0);
21346 e
= make_number (SCHARS (object
) - 1);
21347 fast_find_string_pos (w
, XINT (b
), object
,
21348 &dpyinfo
->mouse_face_beg_col
,
21349 &dpyinfo
->mouse_face_beg_row
,
21350 &dpyinfo
->mouse_face_beg_x
,
21351 &dpyinfo
->mouse_face_beg_y
, 0);
21352 fast_find_string_pos (w
, XINT (e
), object
,
21353 &dpyinfo
->mouse_face_end_col
,
21354 &dpyinfo
->mouse_face_end_row
,
21355 &dpyinfo
->mouse_face_end_x
,
21356 &dpyinfo
->mouse_face_end_y
, 1);
21357 dpyinfo
->mouse_face_past_end
= 0;
21358 dpyinfo
->mouse_face_window
= window
;
21359 dpyinfo
->mouse_face_face_id
21360 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21361 glyph
->face_id
, 1);
21362 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21363 cursor
= No_Cursor
;
21365 else if (STRINGP (object
) && NILP (mouse_face
))
21367 /* A string which doesn't have mouse-face, but
21368 the text ``under'' it might have. */
21369 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21370 int start
= MATRIX_ROW_START_CHARPOS (r
);
21372 pos
= string_buffer_position (w
, object
, start
);
21374 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21378 if (!NILP (mouse_face
) && !NILP (overlay
))
21380 Lisp_Object before
= Foverlay_start (overlay
);
21381 Lisp_Object after
= Foverlay_end (overlay
);
21384 /* Note that we might not be able to find position
21385 BEFORE in the glyph matrix if the overlay is
21386 entirely covered by a `display' property. In
21387 this case, we overshoot. So let's stop in
21388 the glyph matrix before glyphs for OBJECT. */
21389 fast_find_position (w
, XFASTINT (before
),
21390 &dpyinfo
->mouse_face_beg_col
,
21391 &dpyinfo
->mouse_face_beg_row
,
21392 &dpyinfo
->mouse_face_beg_x
,
21393 &dpyinfo
->mouse_face_beg_y
,
21396 dpyinfo
->mouse_face_past_end
21397 = !fast_find_position (w
, XFASTINT (after
),
21398 &dpyinfo
->mouse_face_end_col
,
21399 &dpyinfo
->mouse_face_end_row
,
21400 &dpyinfo
->mouse_face_end_x
,
21401 &dpyinfo
->mouse_face_end_y
,
21403 dpyinfo
->mouse_face_window
= window
;
21404 dpyinfo
->mouse_face_face_id
21405 = face_at_buffer_position (w
, pos
, 0, 0,
21407 !dpyinfo
->mouse_face_hidden
);
21409 /* Display it as active. */
21410 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21411 cursor
= No_Cursor
;
21418 /* Look for a `help-echo' property. */
21419 if (NILP (help_echo_string
)) {
21420 Lisp_Object help
, overlay
;
21422 /* Check overlays first. */
21423 help
= overlay
= Qnil
;
21424 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21426 overlay
= overlay_vec
[i
];
21427 help
= Foverlay_get (overlay
, Qhelp_echo
);
21432 help_echo_string
= help
;
21433 help_echo_window
= window
;
21434 help_echo_object
= overlay
;
21435 help_echo_pos
= pos
;
21439 Lisp_Object object
= glyph
->object
;
21440 int charpos
= glyph
->charpos
;
21442 /* Try text properties. */
21443 if (STRINGP (object
)
21445 && charpos
< SCHARS (object
))
21447 help
= Fget_text_property (make_number (charpos
),
21448 Qhelp_echo
, object
);
21451 /* If the string itself doesn't specify a help-echo,
21452 see if the buffer text ``under'' it does. */
21453 struct glyph_row
*r
21454 = MATRIX_ROW (w
->current_matrix
, vpos
);
21455 int start
= MATRIX_ROW_START_CHARPOS (r
);
21456 int pos
= string_buffer_position (w
, object
, start
);
21459 help
= Fget_char_property (make_number (pos
),
21460 Qhelp_echo
, w
->buffer
);
21464 object
= w
->buffer
;
21469 else if (BUFFERP (object
)
21472 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21477 help_echo_string
= help
;
21478 help_echo_window
= window
;
21479 help_echo_object
= object
;
21480 help_echo_pos
= charpos
;
21485 /* Look for a `pointer' property. */
21486 if (NILP (pointer
))
21488 /* Check overlays first. */
21489 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21490 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21492 if (NILP (pointer
))
21494 Lisp_Object object
= glyph
->object
;
21495 int charpos
= glyph
->charpos
;
21497 /* Try text properties. */
21498 if (STRINGP (object
)
21500 && charpos
< SCHARS (object
))
21502 pointer
= Fget_text_property (make_number (charpos
),
21504 if (NILP (pointer
))
21506 /* If the string itself doesn't specify a pointer,
21507 see if the buffer text ``under'' it does. */
21508 struct glyph_row
*r
21509 = MATRIX_ROW (w
->current_matrix
, vpos
);
21510 int start
= MATRIX_ROW_START_CHARPOS (r
);
21511 int pos
= string_buffer_position (w
, object
, start
);
21513 pointer
= Fget_char_property (make_number (pos
),
21514 Qpointer
, w
->buffer
);
21517 else if (BUFFERP (object
)
21520 pointer
= Fget_text_property (make_number (charpos
),
21527 current_buffer
= obuf
;
21532 define_frame_cursor1 (f
, cursor
, pointer
);
21537 Clear any mouse-face on window W. This function is part of the
21538 redisplay interface, and is called from try_window_id and similar
21539 functions to ensure the mouse-highlight is off. */
21542 x_clear_window_mouse_face (w
)
21545 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21546 Lisp_Object window
;
21549 XSETWINDOW (window
, w
);
21550 if (EQ (window
, dpyinfo
->mouse_face_window
))
21551 clear_mouse_face (dpyinfo
);
21557 Just discard the mouse face information for frame F, if any.
21558 This is used when the size of F is changed. */
21561 cancel_mouse_face (f
)
21564 Lisp_Object window
;
21565 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21567 window
= dpyinfo
->mouse_face_window
;
21568 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21570 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21571 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21572 dpyinfo
->mouse_face_window
= Qnil
;
21577 #endif /* HAVE_WINDOW_SYSTEM */
21580 /***********************************************************************
21582 ***********************************************************************/
21584 #ifdef HAVE_WINDOW_SYSTEM
21586 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21587 which intersects rectangle R. R is in window-relative coordinates. */
21590 expose_area (w
, row
, r
, area
)
21592 struct glyph_row
*row
;
21594 enum glyph_row_area area
;
21596 struct glyph
*first
= row
->glyphs
[area
];
21597 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21598 struct glyph
*last
;
21599 int first_x
, start_x
, x
;
21601 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21602 /* If row extends face to end of line write the whole line. */
21603 draw_glyphs (w
, 0, row
, area
,
21604 0, row
->used
[area
],
21605 DRAW_NORMAL_TEXT
, 0);
21608 /* Set START_X to the window-relative start position for drawing glyphs of
21609 AREA. The first glyph of the text area can be partially visible.
21610 The first glyphs of other areas cannot. */
21611 start_x
= window_box_left_offset (w
, area
);
21613 if (area
== TEXT_AREA
)
21616 /* Find the first glyph that must be redrawn. */
21618 && x
+ first
->pixel_width
< r
->x
)
21620 x
+= first
->pixel_width
;
21624 /* Find the last one. */
21628 && x
< r
->x
+ r
->width
)
21630 x
+= last
->pixel_width
;
21636 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21637 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21638 DRAW_NORMAL_TEXT
, 0);
21643 /* Redraw the parts of the glyph row ROW on window W intersecting
21644 rectangle R. R is in window-relative coordinates. Value is
21645 non-zero if mouse-face was overwritten. */
21648 expose_line (w
, row
, r
)
21650 struct glyph_row
*row
;
21653 xassert (row
->enabled_p
);
21655 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21656 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21657 0, row
->used
[TEXT_AREA
],
21658 DRAW_NORMAL_TEXT
, 0);
21661 if (row
->used
[LEFT_MARGIN_AREA
])
21662 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21663 if (row
->used
[TEXT_AREA
])
21664 expose_area (w
, row
, r
, TEXT_AREA
);
21665 if (row
->used
[RIGHT_MARGIN_AREA
])
21666 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21667 draw_row_fringe_bitmaps (w
, row
);
21670 return row
->mouse_face_p
;
21674 /* Redraw those parts of glyphs rows during expose event handling that
21675 overlap other rows. Redrawing of an exposed line writes over parts
21676 of lines overlapping that exposed line; this function fixes that.
21678 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21679 row in W's current matrix that is exposed and overlaps other rows.
21680 LAST_OVERLAPPING_ROW is the last such row. */
21683 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21685 struct glyph_row
*first_overlapping_row
;
21686 struct glyph_row
*last_overlapping_row
;
21688 struct glyph_row
*row
;
21690 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21691 if (row
->overlapping_p
)
21693 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21695 if (row
->used
[LEFT_MARGIN_AREA
])
21696 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21698 if (row
->used
[TEXT_AREA
])
21699 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21701 if (row
->used
[RIGHT_MARGIN_AREA
])
21702 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21707 /* Return non-zero if W's cursor intersects rectangle R. */
21710 phys_cursor_in_rect_p (w
, r
)
21714 XRectangle cr
, result
;
21715 struct glyph
*cursor_glyph
;
21717 cursor_glyph
= get_phys_cursor_glyph (w
);
21720 /* r is relative to W's box, but w->phys_cursor.x is relative
21721 to left edge of W's TEXT area. Adjust it. */
21722 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21723 cr
.y
= w
->phys_cursor
.y
;
21724 cr
.width
= cursor_glyph
->pixel_width
;
21725 cr
.height
= w
->phys_cursor_height
;
21726 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21727 I assume the effect is the same -- and this is portable. */
21728 return x_intersect_rectangles (&cr
, r
, &result
);
21730 /* If we don't understand the format, pretend we're not in the hot-spot. */
21736 Draw a vertical window border to the right of window W if W doesn't
21737 have vertical scroll bars. */
21740 x_draw_vertical_border (w
)
21743 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21745 /* We could do better, if we knew what type of scroll-bar the adjacent
21746 windows (on either side) have... But we don't :-(
21747 However, I think this works ok. ++KFS 2003-04-25 */
21749 /* Redraw borders between horizontally adjacent windows. Don't
21750 do it for frames with vertical scroll bars because either the
21751 right scroll bar of a window, or the left scroll bar of its
21752 neighbor will suffice as a border. */
21753 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
21756 if (!WINDOW_RIGHTMOST_P (w
)
21757 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21759 int x0
, x1
, y0
, y1
;
21761 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21764 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
21766 else if (!WINDOW_LEFTMOST_P (w
)
21767 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21769 int x0
, x1
, y0
, y1
;
21771 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21774 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
21779 /* Redraw the part of window W intersection rectangle FR. Pixel
21780 coordinates in FR are frame-relative. Call this function with
21781 input blocked. Value is non-zero if the exposure overwrites
21785 expose_window (w
, fr
)
21789 struct frame
*f
= XFRAME (w
->frame
);
21791 int mouse_face_overwritten_p
= 0;
21793 /* If window is not yet fully initialized, do nothing. This can
21794 happen when toolkit scroll bars are used and a window is split.
21795 Reconfiguring the scroll bar will generate an expose for a newly
21797 if (w
->current_matrix
== NULL
)
21800 /* When we're currently updating the window, display and current
21801 matrix usually don't agree. Arrange for a thorough display
21803 if (w
== updated_window
)
21805 SET_FRAME_GARBAGED (f
);
21809 /* Frame-relative pixel rectangle of W. */
21810 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21811 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21812 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21813 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21815 if (x_intersect_rectangles (fr
, &wr
, &r
))
21817 int yb
= window_text_bottom_y (w
);
21818 struct glyph_row
*row
;
21819 int cursor_cleared_p
;
21820 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21822 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21823 r
.x
, r
.y
, r
.width
, r
.height
));
21825 /* Convert to window coordinates. */
21826 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21827 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21829 /* Turn off the cursor. */
21830 if (!w
->pseudo_window_p
21831 && phys_cursor_in_rect_p (w
, &r
))
21833 x_clear_cursor (w
);
21834 cursor_cleared_p
= 1;
21837 cursor_cleared_p
= 0;
21839 /* Update lines intersecting rectangle R. */
21840 first_overlapping_row
= last_overlapping_row
= NULL
;
21841 for (row
= w
->current_matrix
->rows
;
21846 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21848 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21849 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21850 || (r
.y
>= y0
&& r
.y
< y1
)
21851 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21853 if (row
->overlapping_p
)
21855 if (first_overlapping_row
== NULL
)
21856 first_overlapping_row
= row
;
21857 last_overlapping_row
= row
;
21860 if (expose_line (w
, row
, &r
))
21861 mouse_face_overwritten_p
= 1;
21868 /* Display the mode line if there is one. */
21869 if (WINDOW_WANTS_MODELINE_P (w
)
21870 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21872 && row
->y
< r
.y
+ r
.height
)
21874 if (expose_line (w
, row
, &r
))
21875 mouse_face_overwritten_p
= 1;
21878 if (!w
->pseudo_window_p
)
21880 /* Fix the display of overlapping rows. */
21881 if (first_overlapping_row
)
21882 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21884 /* Draw border between windows. */
21885 x_draw_vertical_border (w
);
21887 /* Turn the cursor on again. */
21888 if (cursor_cleared_p
)
21889 update_window_cursor (w
, 1);
21894 /* Display scroll bar for this window. */
21895 if (!NILP (w
->vertical_scroll_bar
))
21898 If this doesn't work here (maybe some header files are missing),
21899 make a function in macterm.c and call it to do the job! */
21901 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21907 return mouse_face_overwritten_p
;
21912 /* Redraw (parts) of all windows in the window tree rooted at W that
21913 intersect R. R contains frame pixel coordinates. Value is
21914 non-zero if the exposure overwrites mouse-face. */
21917 expose_window_tree (w
, r
)
21921 struct frame
*f
= XFRAME (w
->frame
);
21922 int mouse_face_overwritten_p
= 0;
21924 while (w
&& !FRAME_GARBAGED_P (f
))
21926 if (!NILP (w
->hchild
))
21927 mouse_face_overwritten_p
21928 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21929 else if (!NILP (w
->vchild
))
21930 mouse_face_overwritten_p
21931 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21933 mouse_face_overwritten_p
|= expose_window (w
, r
);
21935 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21938 return mouse_face_overwritten_p
;
21943 Redisplay an exposed area of frame F. X and Y are the upper-left
21944 corner of the exposed rectangle. W and H are width and height of
21945 the exposed area. All are pixel values. W or H zero means redraw
21946 the entire frame. */
21949 expose_frame (f
, x
, y
, w
, h
)
21954 int mouse_face_overwritten_p
= 0;
21956 TRACE ((stderr
, "expose_frame "));
21958 /* No need to redraw if frame will be redrawn soon. */
21959 if (FRAME_GARBAGED_P (f
))
21961 TRACE ((stderr
, " garbaged\n"));
21966 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21967 or deactivated here, for unknown reasons, activated scroll bars
21968 are shown in deactivated frames in some instances. */
21969 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21970 activate_scroll_bars (f
);
21972 deactivate_scroll_bars (f
);
21975 /* If basic faces haven't been realized yet, there is no point in
21976 trying to redraw anything. This can happen when we get an expose
21977 event while Emacs is starting, e.g. by moving another window. */
21978 if (FRAME_FACE_CACHE (f
) == NULL
21979 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21981 TRACE ((stderr
, " no faces\n"));
21985 if (w
== 0 || h
== 0)
21988 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21989 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21999 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22000 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22002 if (WINDOWP (f
->tool_bar_window
))
22003 mouse_face_overwritten_p
22004 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22006 #ifdef HAVE_X_WINDOWS
22008 #ifndef USE_X_TOOLKIT
22009 if (WINDOWP (f
->menu_bar_window
))
22010 mouse_face_overwritten_p
22011 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22012 #endif /* not USE_X_TOOLKIT */
22016 /* Some window managers support a focus-follows-mouse style with
22017 delayed raising of frames. Imagine a partially obscured frame,
22018 and moving the mouse into partially obscured mouse-face on that
22019 frame. The visible part of the mouse-face will be highlighted,
22020 then the WM raises the obscured frame. With at least one WM, KDE
22021 2.1, Emacs is not getting any event for the raising of the frame
22022 (even tried with SubstructureRedirectMask), only Expose events.
22023 These expose events will draw text normally, i.e. not
22024 highlighted. Which means we must redo the highlight here.
22025 Subsume it under ``we love X''. --gerd 2001-08-15 */
22026 /* Included in Windows version because Windows most likely does not
22027 do the right thing if any third party tool offers
22028 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22029 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22031 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22032 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22034 int x
= dpyinfo
->mouse_face_mouse_x
;
22035 int y
= dpyinfo
->mouse_face_mouse_y
;
22036 clear_mouse_face (dpyinfo
);
22037 note_mouse_highlight (f
, x
, y
);
22044 Determine the intersection of two rectangles R1 and R2. Return
22045 the intersection in *RESULT. Value is non-zero if RESULT is not
22049 x_intersect_rectangles (r1
, r2
, result
)
22050 XRectangle
*r1
, *r2
, *result
;
22052 XRectangle
*left
, *right
;
22053 XRectangle
*upper
, *lower
;
22054 int intersection_p
= 0;
22056 /* Rearrange so that R1 is the left-most rectangle. */
22058 left
= r1
, right
= r2
;
22060 left
= r2
, right
= r1
;
22062 /* X0 of the intersection is right.x0, if this is inside R1,
22063 otherwise there is no intersection. */
22064 if (right
->x
<= left
->x
+ left
->width
)
22066 result
->x
= right
->x
;
22068 /* The right end of the intersection is the minimum of the
22069 the right ends of left and right. */
22070 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22073 /* Same game for Y. */
22075 upper
= r1
, lower
= r2
;
22077 upper
= r2
, lower
= r1
;
22079 /* The upper end of the intersection is lower.y0, if this is inside
22080 of upper. Otherwise, there is no intersection. */
22081 if (lower
->y
<= upper
->y
+ upper
->height
)
22083 result
->y
= lower
->y
;
22085 /* The lower end of the intersection is the minimum of the lower
22086 ends of upper and lower. */
22087 result
->height
= (min (lower
->y
+ lower
->height
,
22088 upper
->y
+ upper
->height
)
22090 intersection_p
= 1;
22094 return intersection_p
;
22097 #endif /* HAVE_WINDOW_SYSTEM */
22100 /***********************************************************************
22102 ***********************************************************************/
22107 Vwith_echo_area_save_vector
= Qnil
;
22108 staticpro (&Vwith_echo_area_save_vector
);
22110 Vmessage_stack
= Qnil
;
22111 staticpro (&Vmessage_stack
);
22113 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22114 staticpro (&Qinhibit_redisplay
);
22116 message_dolog_marker1
= Fmake_marker ();
22117 staticpro (&message_dolog_marker1
);
22118 message_dolog_marker2
= Fmake_marker ();
22119 staticpro (&message_dolog_marker2
);
22120 message_dolog_marker3
= Fmake_marker ();
22121 staticpro (&message_dolog_marker3
);
22124 defsubr (&Sdump_frame_glyph_matrix
);
22125 defsubr (&Sdump_glyph_matrix
);
22126 defsubr (&Sdump_glyph_row
);
22127 defsubr (&Sdump_tool_bar_row
);
22128 defsubr (&Strace_redisplay
);
22129 defsubr (&Strace_to_stderr
);
22131 #ifdef HAVE_WINDOW_SYSTEM
22132 defsubr (&Stool_bar_lines_needed
);
22133 defsubr (&Slookup_image_map
);
22135 defsubr (&Sformat_mode_line
);
22137 staticpro (&Qmenu_bar_update_hook
);
22138 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22140 staticpro (&Qoverriding_terminal_local_map
);
22141 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22143 staticpro (&Qoverriding_local_map
);
22144 Qoverriding_local_map
= intern ("overriding-local-map");
22146 staticpro (&Qwindow_scroll_functions
);
22147 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22149 staticpro (&Qredisplay_end_trigger_functions
);
22150 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22152 staticpro (&Qinhibit_point_motion_hooks
);
22153 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22155 QCdata
= intern (":data");
22156 staticpro (&QCdata
);
22157 Qdisplay
= intern ("display");
22158 staticpro (&Qdisplay
);
22159 Qspace_width
= intern ("space-width");
22160 staticpro (&Qspace_width
);
22161 Qraise
= intern ("raise");
22162 staticpro (&Qraise
);
22163 Qslice
= intern ("slice");
22164 staticpro (&Qslice
);
22165 Qspace
= intern ("space");
22166 staticpro (&Qspace
);
22167 Qmargin
= intern ("margin");
22168 staticpro (&Qmargin
);
22169 Qpointer
= intern ("pointer");
22170 staticpro (&Qpointer
);
22171 Qleft_margin
= intern ("left-margin");
22172 staticpro (&Qleft_margin
);
22173 Qright_margin
= intern ("right-margin");
22174 staticpro (&Qright_margin
);
22175 Qcenter
= intern ("center");
22176 staticpro (&Qcenter
);
22177 Qline_height
= intern ("line-height");
22178 staticpro (&Qline_height
);
22179 Qtotal
= intern ("total");
22180 staticpro (&Qtotal
);
22181 QCalign_to
= intern (":align-to");
22182 staticpro (&QCalign_to
);
22183 QCrelative_width
= intern (":relative-width");
22184 staticpro (&QCrelative_width
);
22185 QCrelative_height
= intern (":relative-height");
22186 staticpro (&QCrelative_height
);
22187 QCeval
= intern (":eval");
22188 staticpro (&QCeval
);
22189 QCpropertize
= intern (":propertize");
22190 staticpro (&QCpropertize
);
22191 QCfile
= intern (":file");
22192 staticpro (&QCfile
);
22193 Qfontified
= intern ("fontified");
22194 staticpro (&Qfontified
);
22195 Qfontification_functions
= intern ("fontification-functions");
22196 staticpro (&Qfontification_functions
);
22197 Qtrailing_whitespace
= intern ("trailing-whitespace");
22198 staticpro (&Qtrailing_whitespace
);
22199 Qescape_glyph
= intern ("escape-glyph");
22200 staticpro (&Qescape_glyph
);
22201 Qimage
= intern ("image");
22202 staticpro (&Qimage
);
22203 QCmap
= intern (":map");
22204 staticpro (&QCmap
);
22205 QCpointer
= intern (":pointer");
22206 staticpro (&QCpointer
);
22207 Qrect
= intern ("rect");
22208 staticpro (&Qrect
);
22209 Qcircle
= intern ("circle");
22210 staticpro (&Qcircle
);
22211 Qpoly
= intern ("poly");
22212 staticpro (&Qpoly
);
22213 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22214 staticpro (&Qmessage_truncate_lines
);
22215 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
22216 staticpro (&Qcursor_in_non_selected_windows
);
22217 Qgrow_only
= intern ("grow-only");
22218 staticpro (&Qgrow_only
);
22219 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22220 staticpro (&Qinhibit_menubar_update
);
22221 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22222 staticpro (&Qinhibit_eval_during_redisplay
);
22223 Qposition
= intern ("position");
22224 staticpro (&Qposition
);
22225 Qbuffer_position
= intern ("buffer-position");
22226 staticpro (&Qbuffer_position
);
22227 Qobject
= intern ("object");
22228 staticpro (&Qobject
);
22229 Qbar
= intern ("bar");
22231 Qhbar
= intern ("hbar");
22232 staticpro (&Qhbar
);
22233 Qbox
= intern ("box");
22235 Qhollow
= intern ("hollow");
22236 staticpro (&Qhollow
);
22237 Qhand
= intern ("hand");
22238 staticpro (&Qhand
);
22239 Qarrow
= intern ("arrow");
22240 staticpro (&Qarrow
);
22241 Qtext
= intern ("text");
22242 staticpro (&Qtext
);
22243 Qrisky_local_variable
= intern ("risky-local-variable");
22244 staticpro (&Qrisky_local_variable
);
22245 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22246 staticpro (&Qinhibit_free_realized_faces
);
22248 list_of_error
= Fcons (Fcons (intern ("error"),
22249 Fcons (intern ("void-variable"), Qnil
)),
22251 staticpro (&list_of_error
);
22253 Qlast_arrow_position
= intern ("last-arrow-position");
22254 staticpro (&Qlast_arrow_position
);
22255 Qlast_arrow_string
= intern ("last-arrow-string");
22256 staticpro (&Qlast_arrow_string
);
22258 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22259 staticpro (&Qoverlay_arrow_string
);
22260 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22261 staticpro (&Qoverlay_arrow_bitmap
);
22263 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22264 staticpro (&echo_buffer
[0]);
22265 staticpro (&echo_buffer
[1]);
22267 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22268 staticpro (&echo_area_buffer
[0]);
22269 staticpro (&echo_area_buffer
[1]);
22271 Vmessages_buffer_name
= build_string ("*Messages*");
22272 staticpro (&Vmessages_buffer_name
);
22274 mode_line_proptrans_alist
= Qnil
;
22275 staticpro (&mode_line_proptrans_alist
);
22277 mode_line_string_list
= Qnil
;
22278 staticpro (&mode_line_string_list
);
22280 help_echo_string
= Qnil
;
22281 staticpro (&help_echo_string
);
22282 help_echo_object
= Qnil
;
22283 staticpro (&help_echo_object
);
22284 help_echo_window
= Qnil
;
22285 staticpro (&help_echo_window
);
22286 previous_help_echo_string
= Qnil
;
22287 staticpro (&previous_help_echo_string
);
22288 help_echo_pos
= -1;
22290 #ifdef HAVE_WINDOW_SYSTEM
22291 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22292 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22293 For example, if a block cursor is over a tab, it will be drawn as
22294 wide as that tab on the display. */);
22295 x_stretch_cursor_p
= 0;
22298 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22299 doc
: /* *Non-nil means highlight trailing whitespace.
22300 The face used for trailing whitespace is `trailing-whitespace'. */);
22301 Vshow_trailing_whitespace
= Qnil
;
22303 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22304 doc
: /* *The pointer shape to show in void text areas.
22305 Nil means to show the text pointer. Other options are `arrow', `text',
22306 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22307 Vvoid_text_area_pointer
= Qarrow
;
22309 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22310 doc
: /* Non-nil means don't actually do any redisplay.
22311 This is used for internal purposes. */);
22312 Vinhibit_redisplay
= Qnil
;
22314 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22315 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22316 Vglobal_mode_string
= Qnil
;
22318 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22319 doc
: /* Marker for where to display an arrow on top of the buffer text.
22320 This must be the beginning of a line in order to work.
22321 See also `overlay-arrow-string'. */);
22322 Voverlay_arrow_position
= Qnil
;
22324 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22325 doc
: /* String to display as an arrow in non-window frames.
22326 See also `overlay-arrow-position'. */);
22327 Voverlay_arrow_string
= Qnil
;
22329 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22330 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22331 The symbols on this list are examined during redisplay to determine
22332 where to display overlay arrows. */);
22333 Voverlay_arrow_variable_list
22334 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22336 DEFVAR_INT ("scroll-step", &scroll_step
,
22337 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22338 If that fails to bring point back on frame, point is centered instead.
22339 If this is zero, point is always centered after it moves off frame.
22340 If you want scrolling to always be a line at a time, you should set
22341 `scroll-conservatively' to a large value rather than set this to 1. */);
22343 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22344 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22345 A value of zero means to scroll the text to center point vertically
22346 in the window. */);
22347 scroll_conservatively
= 0;
22349 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22350 doc
: /* *Number of lines of margin at the top and bottom of a window.
22351 Recenter the window whenever point gets within this many lines
22352 of the top or bottom of the window. */);
22355 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22356 doc
: /* Pixels per inch on current display.
22357 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22358 Vdisplay_pixels_per_inch
= make_float (72.0);
22361 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22364 DEFVAR_BOOL ("truncate-partial-width-windows",
22365 &truncate_partial_width_windows
,
22366 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22367 truncate_partial_width_windows
= 1;
22369 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22370 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22371 Any other value means to use the appropriate face, `mode-line',
22372 `header-line', or `menu' respectively. */);
22373 mode_line_inverse_video
= 1;
22375 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22376 doc
: /* *Maximum buffer size for which line number should be displayed.
22377 If the buffer is bigger than this, the line number does not appear
22378 in the mode line. A value of nil means no limit. */);
22379 Vline_number_display_limit
= Qnil
;
22381 DEFVAR_INT ("line-number-display-limit-width",
22382 &line_number_display_limit_width
,
22383 doc
: /* *Maximum line width (in characters) for line number display.
22384 If the average length of the lines near point is bigger than this, then the
22385 line number may be omitted from the mode line. */);
22386 line_number_display_limit_width
= 200;
22388 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22389 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22390 highlight_nonselected_windows
= 0;
22392 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22393 doc
: /* Non-nil if more than one frame is visible on this display.
22394 Minibuffer-only frames don't count, but iconified frames do.
22395 This variable is not guaranteed to be accurate except while processing
22396 `frame-title-format' and `icon-title-format'. */);
22398 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22399 doc
: /* Template for displaying the title bar of visible frames.
22400 \(Assuming the window manager supports this feature.)
22401 This variable has the same structure as `mode-line-format' (which see),
22402 and is used only on frames for which no explicit name has been set
22403 \(see `modify-frame-parameters'). */);
22405 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22406 doc
: /* Template for displaying the title bar of an iconified frame.
22407 \(Assuming the window manager supports this feature.)
22408 This variable has the same structure as `mode-line-format' (which see),
22409 and is used only on frames for which no explicit name has been set
22410 \(see `modify-frame-parameters'). */);
22412 = Vframe_title_format
22413 = Fcons (intern ("multiple-frames"),
22414 Fcons (build_string ("%b"),
22415 Fcons (Fcons (empty_string
,
22416 Fcons (intern ("invocation-name"),
22417 Fcons (build_string ("@"),
22418 Fcons (intern ("system-name"),
22422 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22423 doc
: /* Maximum number of lines to keep in the message log buffer.
22424 If nil, disable message logging. If t, log messages but don't truncate
22425 the buffer when it becomes large. */);
22426 Vmessage_log_max
= make_number (50);
22428 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22429 doc
: /* Functions called before redisplay, if window sizes have changed.
22430 The value should be a list of functions that take one argument.
22431 Just before redisplay, for each frame, if any of its windows have changed
22432 size since the last redisplay, or have been split or deleted,
22433 all the functions in the list are called, with the frame as argument. */);
22434 Vwindow_size_change_functions
= Qnil
;
22436 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22437 doc
: /* List of functions to call before redisplaying a window with scrolling.
22438 Each function is called with two arguments, the window
22439 and its new display-start position. Note that the value of `window-end'
22440 is not valid when these functions are called. */);
22441 Vwindow_scroll_functions
= Qnil
;
22443 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22444 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22445 mouse_autoselect_window
= 0;
22447 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22448 doc
: /* *Non-nil means automatically resize tool-bars.
22449 This increases a tool-bar's height if not all tool-bar items are visible.
22450 It decreases a tool-bar's height when it would display blank lines
22452 auto_resize_tool_bars_p
= 1;
22454 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22455 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22456 auto_raise_tool_bar_buttons_p
= 1;
22458 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
22459 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
22460 make_cursor_line_fully_visible_p
= 1;
22462 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22463 doc
: /* *Margin around tool-bar buttons in pixels.
22464 If an integer, use that for both horizontal and vertical margins.
22465 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22466 HORZ specifying the horizontal margin, and VERT specifying the
22467 vertical margin. */);
22468 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22470 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22471 doc
: /* *Relief thickness of tool-bar buttons. */);
22472 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22474 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22475 doc
: /* List of functions to call to fontify regions of text.
22476 Each function is called with one argument POS. Functions must
22477 fontify a region starting at POS in the current buffer, and give
22478 fontified regions the property `fontified'. */);
22479 Vfontification_functions
= Qnil
;
22480 Fmake_variable_buffer_local (Qfontification_functions
);
22482 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22483 &unibyte_display_via_language_environment
,
22484 doc
: /* *Non-nil means display unibyte text according to language environment.
22485 Specifically this means that unibyte non-ASCII characters
22486 are displayed by converting them to the equivalent multibyte characters
22487 according to the current language environment. As a result, they are
22488 displayed according to the current fontset. */);
22489 unibyte_display_via_language_environment
= 0;
22491 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22492 doc
: /* *Maximum height for resizing mini-windows.
22493 If a float, it specifies a fraction of the mini-window frame's height.
22494 If an integer, it specifies a number of lines. */);
22495 Vmax_mini_window_height
= make_float (0.25);
22497 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22498 doc
: /* *How to resize mini-windows.
22499 A value of nil means don't automatically resize mini-windows.
22500 A value of t means resize them to fit the text displayed in them.
22501 A value of `grow-only', the default, means let mini-windows grow
22502 only, until their display becomes empty, at which point the windows
22503 go back to their normal size. */);
22504 Vresize_mini_windows
= Qgrow_only
;
22506 DEFVAR_LISP ("cursor-in-non-selected-windows",
22507 &Vcursor_in_non_selected_windows
,
22508 doc
: /* *Cursor type to display in non-selected windows.
22509 t means to use hollow box cursor. See `cursor-type' for other values. */);
22510 Vcursor_in_non_selected_windows
= Qt
;
22512 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22513 doc
: /* Alist specifying how to blink the cursor off.
22514 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22515 `cursor-type' frame-parameter or variable equals ON-STATE,
22516 comparing using `equal', Emacs uses OFF-STATE to specify
22517 how to blink it off. */);
22518 Vblink_cursor_alist
= Qnil
;
22520 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22521 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22522 automatic_hscrolling_p
= 1;
22524 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22525 doc
: /* *How many columns away from the window edge point is allowed to get
22526 before automatic hscrolling will horizontally scroll the window. */);
22527 hscroll_margin
= 5;
22529 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22530 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22531 When point is less than `automatic-hscroll-margin' columns from the window
22532 edge, automatic hscrolling will scroll the window by the amount of columns
22533 determined by this variable. If its value is a positive integer, scroll that
22534 many columns. If it's a positive floating-point number, it specifies the
22535 fraction of the window's width to scroll. If it's nil or zero, point will be
22536 centered horizontally after the scroll. Any other value, including negative
22537 numbers, are treated as if the value were zero.
22539 Automatic hscrolling always moves point outside the scroll margin, so if
22540 point was more than scroll step columns inside the margin, the window will
22541 scroll more than the value given by the scroll step.
22543 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22544 and `scroll-right' overrides this variable's effect. */);
22545 Vhscroll_step
= make_number (0);
22547 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22548 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22549 Bind this around calls to `message' to let it take effect. */);
22550 message_truncate_lines
= 0;
22552 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22553 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22554 Can be used to update submenus whose contents should vary. */);
22555 Vmenu_bar_update_hook
= Qnil
;
22557 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22558 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22559 inhibit_menubar_update
= 0;
22561 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22562 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22563 inhibit_eval_during_redisplay
= 0;
22565 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22566 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22567 inhibit_free_realized_faces
= 0;
22570 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22571 doc
: /* Inhibit try_window_id display optimization. */);
22572 inhibit_try_window_id
= 0;
22574 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22575 doc
: /* Inhibit try_window_reusing display optimization. */);
22576 inhibit_try_window_reusing
= 0;
22578 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22579 doc
: /* Inhibit try_cursor_movement display optimization. */);
22580 inhibit_try_cursor_movement
= 0;
22581 #endif /* GLYPH_DEBUG */
22585 /* Initialize this module when Emacs starts. */
22590 Lisp_Object root_window
;
22591 struct window
*mini_w
;
22593 current_header_line_height
= current_mode_line_height
= -1;
22595 CHARPOS (this_line_start_pos
) = 0;
22597 mini_w
= XWINDOW (minibuf_window
);
22598 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22600 if (!noninteractive
)
22602 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22605 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22606 set_window_height (root_window
,
22607 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22609 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22610 set_window_height (minibuf_window
, 1, 0);
22612 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22613 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22615 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22616 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22617 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22619 /* The default ellipsis glyphs `...'. */
22620 for (i
= 0; i
< 3; ++i
)
22621 default_invis_vector
[i
] = make_number ('.');
22625 /* Allocate the buffer for frame titles.
22626 Also used for `format-mode-line'. */
22628 frame_title_buf
= (char *) xmalloc (size
);
22629 frame_title_buf_end
= frame_title_buf
+ size
;
22630 frame_title_ptr
= NULL
;
22633 help_echo_showing_p
= 0;
22637 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22638 (do not change this comment) */