1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 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
;
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 /* Non-nil means escape non-break space and hyphens. */
323 Lisp_Object Vshow_nonbreak_escape
;
325 #ifdef HAVE_WINDOW_SYSTEM
326 extern Lisp_Object Voverflow_newline_into_fringe
;
328 /* Test if overflow newline into fringe. Called with iterator IT
329 at or past right window margin, and with IT->current_x set. */
331 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
332 (!NILP (Voverflow_newline_into_fringe) \
333 && FRAME_WINDOW_P (it->f) \
334 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
335 && it->current_x == it->last_visible_x)
337 #endif /* HAVE_WINDOW_SYSTEM */
339 /* Non-nil means show the text cursor in void text areas
340 i.e. in blank areas after eol and eob. This used to be
341 the default in 21.3. */
343 Lisp_Object Vvoid_text_area_pointer
;
345 /* Name of the face used to highlight trailing whitespace. */
347 Lisp_Object Qtrailing_whitespace
;
349 /* Name and number of the face used to highlight escape glyphs. */
351 Lisp_Object Qescape_glyph
;
353 /* The symbol `image' which is the car of the lists used to represent
358 /* The image map types. */
359 Lisp_Object QCmap
, QCpointer
;
360 Lisp_Object Qrect
, Qcircle
, Qpoly
;
362 /* Non-zero means print newline to stdout before next mini-buffer
365 int noninteractive_need_newline
;
367 /* Non-zero means print newline to message log before next message. */
369 static int message_log_need_newline
;
371 /* Three markers that message_dolog uses.
372 It could allocate them itself, but that causes trouble
373 in handling memory-full errors. */
374 static Lisp_Object message_dolog_marker1
;
375 static Lisp_Object message_dolog_marker2
;
376 static Lisp_Object message_dolog_marker3
;
378 /* The buffer position of the first character appearing entirely or
379 partially on the line of the selected window which contains the
380 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
381 redisplay optimization in redisplay_internal. */
383 static struct text_pos this_line_start_pos
;
385 /* Number of characters past the end of the line above, including the
386 terminating newline. */
388 static struct text_pos this_line_end_pos
;
390 /* The vertical positions and the height of this line. */
392 static int this_line_vpos
;
393 static int this_line_y
;
394 static int this_line_pixel_height
;
396 /* X position at which this display line starts. Usually zero;
397 negative if first character is partially visible. */
399 static int this_line_start_x
;
401 /* Buffer that this_line_.* variables are referring to. */
403 static struct buffer
*this_line_buffer
;
405 /* Nonzero means truncate lines in all windows less wide than the
408 int truncate_partial_width_windows
;
410 /* A flag to control how to display unibyte 8-bit character. */
412 int unibyte_display_via_language_environment
;
414 /* Nonzero means we have more than one non-mini-buffer-only frame.
415 Not guaranteed to be accurate except while parsing
416 frame-title-format. */
420 Lisp_Object Vglobal_mode_string
;
423 /* List of variables (symbols) which hold markers for overlay arrows.
424 The symbols on this list are examined during redisplay to determine
425 where to display overlay arrows. */
427 Lisp_Object Voverlay_arrow_variable_list
;
429 /* Marker for where to display an arrow on top of the buffer text. */
431 Lisp_Object Voverlay_arrow_position
;
433 /* String to display for the arrow. Only used on terminal frames. */
435 Lisp_Object Voverlay_arrow_string
;
437 /* Values of those variables at last redisplay are stored as
438 properties on `overlay-arrow-position' symbol. However, if
439 Voverlay_arrow_position is a marker, last-arrow-position is its
440 numerical position. */
442 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
444 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
445 properties on a symbol in overlay-arrow-variable-list. */
447 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
449 /* Like mode-line-format, but for the title bar on a visible frame. */
451 Lisp_Object Vframe_title_format
;
453 /* Like mode-line-format, but for the title bar on an iconified frame. */
455 Lisp_Object Vicon_title_format
;
457 /* List of functions to call when a window's size changes. These
458 functions get one arg, a frame on which one or more windows' sizes
461 static Lisp_Object Vwindow_size_change_functions
;
463 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
465 /* Nonzero if an overlay arrow has been displayed in this window. */
467 static int overlay_arrow_seen
;
469 /* Nonzero means highlight the region even in nonselected windows. */
471 int highlight_nonselected_windows
;
473 /* If cursor motion alone moves point off frame, try scrolling this
474 many lines up or down if that will bring it back. */
476 static EMACS_INT scroll_step
;
478 /* Nonzero means scroll just far enough to bring point back on the
479 screen, when appropriate. */
481 static EMACS_INT scroll_conservatively
;
483 /* Recenter the window whenever point gets within this many lines of
484 the top or bottom of the window. This value is translated into a
485 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
486 that there is really a fixed pixel height scroll margin. */
488 EMACS_INT scroll_margin
;
490 /* Number of windows showing the buffer of the selected window (or
491 another buffer with the same base buffer). keyboard.c refers to
496 /* Vector containing glyphs for an ellipsis `...'. */
498 static Lisp_Object default_invis_vector
[3];
500 /* Zero means display the mode-line/header-line/menu-bar in the default face
501 (this slightly odd definition is for compatibility with previous versions
502 of emacs), non-zero means display them using their respective faces.
504 This variable is deprecated. */
506 int mode_line_inverse_video
;
508 /* Prompt to display in front of the mini-buffer contents. */
510 Lisp_Object minibuf_prompt
;
512 /* Width of current mini-buffer prompt. Only set after display_line
513 of the line that contains the prompt. */
515 int minibuf_prompt_width
;
517 /* This is the window where the echo area message was displayed. It
518 is always a mini-buffer window, but it may not be the same window
519 currently active as a mini-buffer. */
521 Lisp_Object echo_area_window
;
523 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
524 pushes the current message and the value of
525 message_enable_multibyte on the stack, the function restore_message
526 pops the stack and displays MESSAGE again. */
528 Lisp_Object Vmessage_stack
;
530 /* Nonzero means multibyte characters were enabled when the echo area
531 message was specified. */
533 int message_enable_multibyte
;
535 /* Nonzero if we should redraw the mode lines on the next redisplay. */
537 int update_mode_lines
;
539 /* Nonzero if window sizes or contents have changed since last
540 redisplay that finished. */
542 int windows_or_buffers_changed
;
544 /* Nonzero means a frame's cursor type has been changed. */
546 int cursor_type_changed
;
548 /* Nonzero after display_mode_line if %l was used and it displayed a
551 int line_number_displayed
;
553 /* Maximum buffer size for which to display line numbers. */
555 Lisp_Object Vline_number_display_limit
;
557 /* Line width to consider when repositioning for line number display. */
559 static EMACS_INT line_number_display_limit_width
;
561 /* Number of lines to keep in the message log buffer. t means
562 infinite. nil means don't log at all. */
564 Lisp_Object Vmessage_log_max
;
566 /* The name of the *Messages* buffer, a string. */
568 static Lisp_Object Vmessages_buffer_name
;
570 /* Current, index 0, and last displayed echo area message. Either
571 buffers from echo_buffers, or nil to indicate no message. */
573 Lisp_Object echo_area_buffer
[2];
575 /* The buffers referenced from echo_area_buffer. */
577 static Lisp_Object echo_buffer
[2];
579 /* A vector saved used in with_area_buffer to reduce consing. */
581 static Lisp_Object Vwith_echo_area_save_vector
;
583 /* Non-zero means display_echo_area should display the last echo area
584 message again. Set by redisplay_preserve_echo_area. */
586 static int display_last_displayed_message_p
;
588 /* Nonzero if echo area is being used by print; zero if being used by
591 int message_buf_print
;
593 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
595 Lisp_Object Qinhibit_menubar_update
;
596 int inhibit_menubar_update
;
598 /* Maximum height for resizing mini-windows. Either a float
599 specifying a fraction of the available height, or an integer
600 specifying a number of lines. */
602 Lisp_Object Vmax_mini_window_height
;
604 /* Non-zero means messages should be displayed with truncated
605 lines instead of being continued. */
607 int message_truncate_lines
;
608 Lisp_Object Qmessage_truncate_lines
;
610 /* Set to 1 in clear_message to make redisplay_internal aware
611 of an emptied echo area. */
613 static int message_cleared_p
;
615 /* Non-zero means we want a hollow cursor in windows that are not
616 selected. Zero means there's no cursor in such windows. */
618 Lisp_Object Vcursor_in_non_selected_windows
;
619 Lisp_Object Qcursor_in_non_selected_windows
;
621 /* How to blink the default frame cursor off. */
622 Lisp_Object Vblink_cursor_alist
;
624 /* A scratch glyph row with contents used for generating truncation
625 glyphs. Also used in direct_output_for_insert. */
627 #define MAX_SCRATCH_GLYPHS 100
628 struct glyph_row scratch_glyph_row
;
629 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
631 /* Ascent and height of the last line processed by move_it_to. */
633 static int last_max_ascent
, last_height
;
635 /* Non-zero if there's a help-echo in the echo area. */
637 int help_echo_showing_p
;
639 /* If >= 0, computed, exact values of mode-line and header-line height
640 to use in the macros CURRENT_MODE_LINE_HEIGHT and
641 CURRENT_HEADER_LINE_HEIGHT. */
643 int current_mode_line_height
, current_header_line_height
;
645 /* The maximum distance to look ahead for text properties. Values
646 that are too small let us call compute_char_face and similar
647 functions too often which is expensive. Values that are too large
648 let us call compute_char_face and alike too often because we
649 might not be interested in text properties that far away. */
651 #define TEXT_PROP_DISTANCE_LIMIT 100
655 /* Variables to turn off display optimizations from Lisp. */
657 int inhibit_try_window_id
, inhibit_try_window_reusing
;
658 int inhibit_try_cursor_movement
;
660 /* Non-zero means print traces of redisplay if compiled with
663 int trace_redisplay_p
;
665 #endif /* GLYPH_DEBUG */
667 #ifdef DEBUG_TRACE_MOVE
668 /* Non-zero means trace with TRACE_MOVE to stderr. */
671 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
673 #define TRACE_MOVE(x) (void) 0
676 /* Non-zero means automatically scroll windows horizontally to make
679 int automatic_hscrolling_p
;
681 /* How close to the margin can point get before the window is scrolled
683 EMACS_INT hscroll_margin
;
685 /* How much to scroll horizontally when point is inside the above margin. */
686 Lisp_Object Vhscroll_step
;
688 /* The variable `resize-mini-windows'. If nil, don't resize
689 mini-windows. If t, always resize them to fit the text they
690 display. If `grow-only', let mini-windows grow only until they
693 Lisp_Object Vresize_mini_windows
;
695 /* Buffer being redisplayed -- for redisplay_window_error. */
697 struct buffer
*displayed_buffer
;
699 /* Value returned from text property handlers (see below). */
704 HANDLED_RECOMPUTE_PROPS
,
705 HANDLED_OVERLAY_STRING_CONSUMED
,
709 /* A description of text properties that redisplay is interested
714 /* The name of the property. */
717 /* A unique index for the property. */
720 /* A handler function called to set up iterator IT from the property
721 at IT's current position. Value is used to steer handle_stop. */
722 enum prop_handled (*handler
) P_ ((struct it
*it
));
725 static enum prop_handled handle_face_prop
P_ ((struct it
*));
726 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
727 static enum prop_handled handle_display_prop
P_ ((struct it
*));
728 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
729 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
730 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
732 /* Properties handled by iterators. */
734 static struct props it_props
[] =
736 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
737 /* Handle `face' before `display' because some sub-properties of
738 `display' need to know the face. */
739 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
740 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
741 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
742 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
746 /* Value is the position described by X. If X is a marker, value is
747 the marker_position of X. Otherwise, value is X. */
749 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
751 /* Enumeration returned by some move_it_.* functions internally. */
755 /* Not used. Undefined value. */
758 /* Move ended at the requested buffer position or ZV. */
759 MOVE_POS_MATCH_OR_ZV
,
761 /* Move ended at the requested X pixel position. */
764 /* Move within a line ended at the end of a line that must be
768 /* Move within a line ended at the end of a line that would
769 be displayed truncated. */
772 /* Move within a line ended at a line end. */
776 /* This counter is used to clear the face cache every once in a while
777 in redisplay_internal. It is incremented for each redisplay.
778 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
781 #define CLEAR_FACE_CACHE_COUNT 500
782 static int clear_face_cache_count
;
784 /* Similarly for the image cache. */
786 #ifdef HAVE_WINDOW_SYSTEM
787 #define CLEAR_IMAGE_CACHE_COUNT 101
788 static int clear_image_cache_count
;
791 /* Record the previous terminal frame we displayed. */
793 static struct frame
*previous_terminal_frame
;
795 /* Non-zero while redisplay_internal is in progress. */
799 /* Non-zero means don't free realized faces. Bound while freeing
800 realized faces is dangerous because glyph matrices might still
803 int inhibit_free_realized_faces
;
804 Lisp_Object Qinhibit_free_realized_faces
;
806 /* If a string, XTread_socket generates an event to display that string.
807 (The display is done in read_char.) */
809 Lisp_Object help_echo_string
;
810 Lisp_Object help_echo_window
;
811 Lisp_Object help_echo_object
;
814 /* Temporary variable for XTread_socket. */
816 Lisp_Object previous_help_echo_string
;
818 /* Null glyph slice */
820 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
823 /* Function prototypes. */
825 static void setup_for_ellipsis
P_ ((struct it
*, int));
826 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
827 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
828 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
829 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
830 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
831 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
834 static int invisible_text_between_p
P_ ((struct it
*, int, int));
837 static void pint2str
P_ ((char *, int, int));
838 static void pint2hrstr
P_ ((char *, int, int));
839 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
841 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
842 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
843 static void store_frame_title_char
P_ ((char));
844 static int store_frame_title
P_ ((const unsigned char *, int, int));
845 static void x_consider_frame_title
P_ ((Lisp_Object
));
846 static void handle_stop
P_ ((struct it
*));
847 static int tool_bar_lines_needed
P_ ((struct frame
*));
848 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
849 static void ensure_echo_area_buffers
P_ ((void));
850 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
851 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
852 static int with_echo_area_buffer
P_ ((struct window
*, int,
853 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
854 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
855 static void clear_garbaged_frames
P_ ((void));
856 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
857 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
858 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
859 static int display_echo_area
P_ ((struct window
*));
860 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
861 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
862 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
863 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
864 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
866 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
867 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
868 static void insert_left_trunc_glyphs
P_ ((struct it
*));
869 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
871 static void extend_face_to_end_of_line
P_ ((struct it
*));
872 static int append_space_for_newline
P_ ((struct it
*, int));
873 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
874 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
875 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
876 static int trailing_whitespace_p
P_ ((int));
877 static int message_log_check_duplicate
P_ ((int, int, int, int));
878 static void push_it
P_ ((struct it
*));
879 static void pop_it
P_ ((struct it
*));
880 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
881 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
882 static void redisplay_internal
P_ ((int));
883 static int echo_area_display
P_ ((int));
884 static void redisplay_windows
P_ ((Lisp_Object
));
885 static void redisplay_window
P_ ((Lisp_Object
, int));
886 static Lisp_Object
redisplay_window_error ();
887 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
888 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
889 static void update_menu_bar
P_ ((struct frame
*, int));
890 static int try_window_reusing_current_matrix
P_ ((struct window
*));
891 static int try_window_id
P_ ((struct window
*));
892 static int display_line
P_ ((struct it
*));
893 static int display_mode_lines
P_ ((struct window
*));
894 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
895 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
896 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
897 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
898 static void display_menu_bar
P_ ((struct window
*));
899 static int display_count_lines
P_ ((int, int, int, int, int *));
900 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
901 int, int, struct it
*, int, int, int, int));
902 static void compute_line_metrics
P_ ((struct it
*));
903 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
904 static int get_overlay_strings
P_ ((struct it
*, int));
905 static void next_overlay_string
P_ ((struct it
*));
906 static void reseat
P_ ((struct it
*, struct text_pos
, int));
907 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
908 static void back_to_previous_visible_line_start
P_ ((struct it
*));
909 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
910 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
911 static int next_element_from_ellipsis
P_ ((struct it
*));
912 static int next_element_from_display_vector
P_ ((struct it
*));
913 static int next_element_from_string
P_ ((struct it
*));
914 static int next_element_from_c_string
P_ ((struct it
*));
915 static int next_element_from_buffer
P_ ((struct it
*));
916 static int next_element_from_composition
P_ ((struct it
*));
917 static int next_element_from_image
P_ ((struct it
*));
918 static int next_element_from_stretch
P_ ((struct it
*));
919 static void load_overlay_strings
P_ ((struct it
*, int));
920 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
921 struct display_pos
*));
922 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
923 Lisp_Object
, int, int, int, int));
924 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
926 void move_it_vertically_backward
P_ ((struct it
*, int));
927 static void init_to_row_start
P_ ((struct it
*, struct window
*,
928 struct glyph_row
*));
929 static int init_to_row_end
P_ ((struct it
*, struct window
*,
930 struct glyph_row
*));
931 static void back_to_previous_line_start
P_ ((struct it
*));
932 static int forward_to_next_line_start
P_ ((struct it
*, int *));
933 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
935 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
936 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
937 static int number_of_chars
P_ ((unsigned char *, int));
938 static void compute_stop_pos
P_ ((struct it
*));
939 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
941 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
942 static int next_overlay_change
P_ ((int));
943 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
944 Lisp_Object
, struct text_pos
*,
946 static int underlying_face_id
P_ ((struct it
*));
947 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
950 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
951 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
953 #ifdef HAVE_WINDOW_SYSTEM
955 static void update_tool_bar
P_ ((struct frame
*, int));
956 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
957 static int redisplay_tool_bar
P_ ((struct frame
*));
958 static void display_tool_bar_line
P_ ((struct it
*));
959 static void notice_overwritten_cursor
P_ ((struct window
*,
961 int, int, int, int));
965 #endif /* HAVE_WINDOW_SYSTEM */
968 /***********************************************************************
969 Window display dimensions
970 ***********************************************************************/
972 /* Return the bottom boundary y-position for text lines in window W.
973 This is the first y position at which a line cannot start.
974 It is relative to the top of the window.
976 This is the height of W minus the height of a mode line, if any. */
979 window_text_bottom_y (w
)
982 int height
= WINDOW_TOTAL_HEIGHT (w
);
984 if (WINDOW_WANTS_MODELINE_P (w
))
985 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
989 /* Return the pixel width of display area AREA of window W. AREA < 0
990 means return the total width of W, not including fringes to
991 the left and right of the window. */
994 window_box_width (w
, area
)
998 int cols
= XFASTINT (w
->total_cols
);
1001 if (!w
->pseudo_window_p
)
1003 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1005 if (area
== TEXT_AREA
)
1007 if (INTEGERP (w
->left_margin_cols
))
1008 cols
-= XFASTINT (w
->left_margin_cols
);
1009 if (INTEGERP (w
->right_margin_cols
))
1010 cols
-= XFASTINT (w
->right_margin_cols
);
1011 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1013 else if (area
== LEFT_MARGIN_AREA
)
1015 cols
= (INTEGERP (w
->left_margin_cols
)
1016 ? XFASTINT (w
->left_margin_cols
) : 0);
1019 else if (area
== RIGHT_MARGIN_AREA
)
1021 cols
= (INTEGERP (w
->right_margin_cols
)
1022 ? XFASTINT (w
->right_margin_cols
) : 0);
1027 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1031 /* Return the pixel height of the display area of window W, not
1032 including mode lines of W, if any. */
1035 window_box_height (w
)
1038 struct frame
*f
= XFRAME (w
->frame
);
1039 int height
= WINDOW_TOTAL_HEIGHT (w
);
1041 xassert (height
>= 0);
1043 /* Note: the code below that determines the mode-line/header-line
1044 height is essentially the same as that contained in the macro
1045 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1046 the appropriate glyph row has its `mode_line_p' flag set,
1047 and if it doesn't, uses estimate_mode_line_height instead. */
1049 if (WINDOW_WANTS_MODELINE_P (w
))
1051 struct glyph_row
*ml_row
1052 = (w
->current_matrix
&& w
->current_matrix
->rows
1053 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1055 if (ml_row
&& ml_row
->mode_line_p
)
1056 height
-= ml_row
->height
;
1058 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1061 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1063 struct glyph_row
*hl_row
1064 = (w
->current_matrix
&& w
->current_matrix
->rows
1065 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1067 if (hl_row
&& hl_row
->mode_line_p
)
1068 height
-= hl_row
->height
;
1070 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1073 /* With a very small font and a mode-line that's taller than
1074 default, we might end up with a negative height. */
1075 return max (0, height
);
1078 /* Return the window-relative coordinate of the left edge of display
1079 area AREA of window W. AREA < 0 means return the left edge of the
1080 whole window, to the right of the left fringe of W. */
1083 window_box_left_offset (w
, area
)
1089 if (w
->pseudo_window_p
)
1092 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1094 if (area
== TEXT_AREA
)
1095 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1096 + window_box_width (w
, LEFT_MARGIN_AREA
));
1097 else if (area
== RIGHT_MARGIN_AREA
)
1098 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1099 + window_box_width (w
, LEFT_MARGIN_AREA
)
1100 + window_box_width (w
, TEXT_AREA
)
1101 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1103 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1104 else if (area
== LEFT_MARGIN_AREA
1105 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1106 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1112 /* Return the window-relative coordinate of the right edge of display
1113 area AREA of window W. AREA < 0 means return the left edge of the
1114 whole window, to the left of the right fringe of W. */
1117 window_box_right_offset (w
, area
)
1121 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1124 /* Return the frame-relative coordinate of the left edge of display
1125 area AREA of window W. AREA < 0 means return the left edge of the
1126 whole window, to the right of the left fringe of W. */
1129 window_box_left (w
, area
)
1133 struct frame
*f
= XFRAME (w
->frame
);
1136 if (w
->pseudo_window_p
)
1137 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1139 x
= (WINDOW_LEFT_EDGE_X (w
)
1140 + window_box_left_offset (w
, area
));
1146 /* Return the frame-relative coordinate of the right edge of display
1147 area AREA of window W. AREA < 0 means return the left edge of the
1148 whole window, to the left of the right fringe of W. */
1151 window_box_right (w
, area
)
1155 return window_box_left (w
, area
) + window_box_width (w
, area
);
1158 /* Get the bounding box of the display area AREA of window W, without
1159 mode lines, in frame-relative coordinates. AREA < 0 means the
1160 whole window, not including the left and right fringes of
1161 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1162 coordinates of the upper-left corner of the box. Return in
1163 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1166 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1169 int *box_x
, *box_y
, *box_width
, *box_height
;
1172 *box_width
= window_box_width (w
, area
);
1174 *box_height
= window_box_height (w
);
1176 *box_x
= window_box_left (w
, area
);
1179 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1180 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1181 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1186 /* Get the bounding box of the display area AREA of window W, without
1187 mode lines. AREA < 0 means the whole window, not including the
1188 left and right fringe of the window. Return in *TOP_LEFT_X
1189 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1190 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1191 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1195 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1196 bottom_right_x
, bottom_right_y
)
1199 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1201 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1203 *bottom_right_x
+= *top_left_x
;
1204 *bottom_right_y
+= *top_left_y
;
1209 /***********************************************************************
1211 ***********************************************************************/
1213 /* Return the bottom y-position of the line the iterator IT is in.
1214 This can modify IT's settings. */
1220 int line_height
= it
->max_ascent
+ it
->max_descent
;
1221 int line_top_y
= it
->current_y
;
1223 if (line_height
== 0)
1226 line_height
= last_height
;
1227 else if (IT_CHARPOS (*it
) < ZV
)
1229 move_it_by_lines (it
, 1, 1);
1230 line_height
= (it
->max_ascent
|| it
->max_descent
1231 ? it
->max_ascent
+ it
->max_descent
1236 struct glyph_row
*row
= it
->glyph_row
;
1238 /* Use the default character height. */
1239 it
->glyph_row
= NULL
;
1240 it
->what
= IT_CHARACTER
;
1243 PRODUCE_GLYPHS (it
);
1244 line_height
= it
->ascent
+ it
->descent
;
1245 it
->glyph_row
= row
;
1249 return line_top_y
+ line_height
;
1253 /* Return 1 if position CHARPOS is visible in window W.
1254 If visible, set *X and *Y to pixel coordinates of top left corner.
1255 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1256 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1257 and header-lines heights. */
1260 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1262 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1265 struct text_pos top
;
1267 struct buffer
*old_buffer
= NULL
;
1272 if (XBUFFER (w
->buffer
) != current_buffer
)
1274 old_buffer
= current_buffer
;
1275 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1278 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1280 /* Compute exact mode line heights, if requested. */
1281 if (exact_mode_line_heights_p
)
1283 if (WINDOW_WANTS_MODELINE_P (w
))
1284 current_mode_line_height
1285 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1286 current_buffer
->mode_line_format
);
1288 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1289 current_header_line_height
1290 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1291 current_buffer
->header_line_format
);
1294 start_display (&it
, w
, top
);
1295 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1296 MOVE_TO_POS
| MOVE_TO_Y
);
1298 /* Note that we may overshoot because of invisible text. */
1299 if (IT_CHARPOS (it
) >= charpos
)
1301 int top_x
= it
.current_x
;
1302 int top_y
= it
.current_y
;
1303 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1304 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1306 if (top_y
< window_top_y
)
1307 visible_p
= bottom_y
> window_top_y
;
1308 else if (top_y
< it
.last_visible_y
)
1313 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1314 *rtop
= max (0, window_top_y
- top_y
);
1315 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1323 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1324 move_it_by_lines (&it
, 1, 0);
1325 if (charpos
< IT_CHARPOS (it
))
1328 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1330 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1331 *rtop
= max (0, -it2
.current_y
);
1332 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1333 - it
.last_visible_y
));
1338 set_buffer_internal_1 (old_buffer
);
1340 current_header_line_height
= current_mode_line_height
= -1;
1346 /* Return the next character from STR which is MAXLEN bytes long.
1347 Return in *LEN the length of the character. This is like
1348 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1349 we find one, we return a `?', but with the length of the invalid
1353 string_char_and_length (str
, maxlen
, len
)
1354 const unsigned char *str
;
1359 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1360 if (!CHAR_VALID_P (c
, 1))
1361 /* We may not change the length here because other places in Emacs
1362 don't use this function, i.e. they silently accept invalid
1371 /* Given a position POS containing a valid character and byte position
1372 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1374 static struct text_pos
1375 string_pos_nchars_ahead (pos
, string
, nchars
)
1376 struct text_pos pos
;
1380 xassert (STRINGP (string
) && nchars
>= 0);
1382 if (STRING_MULTIBYTE (string
))
1384 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1385 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1390 string_char_and_length (p
, rest
, &len
);
1391 p
+= len
, rest
-= len
;
1392 xassert (rest
>= 0);
1394 BYTEPOS (pos
) += len
;
1398 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1404 /* Value is the text position, i.e. character and byte position,
1405 for character position CHARPOS in STRING. */
1407 static INLINE
struct text_pos
1408 string_pos (charpos
, string
)
1412 struct text_pos pos
;
1413 xassert (STRINGP (string
));
1414 xassert (charpos
>= 0);
1415 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1420 /* Value is a text position, i.e. character and byte position, for
1421 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1422 means recognize multibyte characters. */
1424 static struct text_pos
1425 c_string_pos (charpos
, s
, multibyte_p
)
1430 struct text_pos pos
;
1432 xassert (s
!= NULL
);
1433 xassert (charpos
>= 0);
1437 int rest
= strlen (s
), len
;
1439 SET_TEXT_POS (pos
, 0, 0);
1442 string_char_and_length (s
, rest
, &len
);
1443 s
+= len
, rest
-= len
;
1444 xassert (rest
>= 0);
1446 BYTEPOS (pos
) += len
;
1450 SET_TEXT_POS (pos
, charpos
, charpos
);
1456 /* Value is the number of characters in C string S. MULTIBYTE_P
1457 non-zero means recognize multibyte characters. */
1460 number_of_chars (s
, multibyte_p
)
1468 int rest
= strlen (s
), len
;
1469 unsigned char *p
= (unsigned char *) s
;
1471 for (nchars
= 0; rest
> 0; ++nchars
)
1473 string_char_and_length (p
, rest
, &len
);
1474 rest
-= len
, p
+= len
;
1478 nchars
= strlen (s
);
1484 /* Compute byte position NEWPOS->bytepos corresponding to
1485 NEWPOS->charpos. POS is a known position in string STRING.
1486 NEWPOS->charpos must be >= POS.charpos. */
1489 compute_string_pos (newpos
, pos
, string
)
1490 struct text_pos
*newpos
, pos
;
1493 xassert (STRINGP (string
));
1494 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1496 if (STRING_MULTIBYTE (string
))
1497 *newpos
= string_pos_nchars_ahead (pos
, string
,
1498 CHARPOS (*newpos
) - CHARPOS (pos
));
1500 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1504 Return an estimation of the pixel height of mode or top lines on
1505 frame F. FACE_ID specifies what line's height to estimate. */
1508 estimate_mode_line_height (f
, face_id
)
1510 enum face_id face_id
;
1512 #ifdef HAVE_WINDOW_SYSTEM
1513 if (FRAME_WINDOW_P (f
))
1515 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1517 /* This function is called so early when Emacs starts that the face
1518 cache and mode line face are not yet initialized. */
1519 if (FRAME_FACE_CACHE (f
))
1521 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1525 height
= FONT_HEIGHT (face
->font
);
1526 if (face
->box_line_width
> 0)
1527 height
+= 2 * face
->box_line_width
;
1538 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1539 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1540 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1541 not force the value into range. */
1544 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1546 register int pix_x
, pix_y
;
1548 NativeRectangle
*bounds
;
1552 #ifdef HAVE_WINDOW_SYSTEM
1553 if (FRAME_WINDOW_P (f
))
1555 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1556 even for negative values. */
1558 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1560 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1562 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1563 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1566 STORE_NATIVE_RECT (*bounds
,
1567 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1568 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1569 FRAME_COLUMN_WIDTH (f
) - 1,
1570 FRAME_LINE_HEIGHT (f
) - 1);
1576 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1577 pix_x
= FRAME_TOTAL_COLS (f
);
1581 else if (pix_y
> FRAME_LINES (f
))
1582 pix_y
= FRAME_LINES (f
);
1592 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1593 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1594 can't tell the positions because W's display is not up to date,
1598 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1601 int *frame_x
, *frame_y
;
1603 #ifdef HAVE_WINDOW_SYSTEM
1604 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1608 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1609 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1611 if (display_completed
)
1613 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1614 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1615 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1621 hpos
+= glyph
->pixel_width
;
1625 /* If first glyph is partially visible, its first visible position is still 0. */
1637 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1638 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1649 #ifdef HAVE_WINDOW_SYSTEM
1651 /* Find the glyph under window-relative coordinates X/Y in window W.
1652 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1653 strings. Return in *HPOS and *VPOS the row and column number of
1654 the glyph found. Return in *AREA the glyph area containing X.
1655 Value is a pointer to the glyph found or null if X/Y is not on
1656 text, or we can't tell because W's current matrix is not up to
1659 static struct glyph
*
1660 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1663 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1665 struct glyph
*glyph
, *end
;
1666 struct glyph_row
*row
= NULL
;
1669 /* Find row containing Y. Give up if some row is not enabled. */
1670 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1672 row
= MATRIX_ROW (w
->current_matrix
, i
);
1673 if (!row
->enabled_p
)
1675 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1682 /* Give up if Y is not in the window. */
1683 if (i
== w
->current_matrix
->nrows
)
1686 /* Get the glyph area containing X. */
1687 if (w
->pseudo_window_p
)
1694 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1696 *area
= LEFT_MARGIN_AREA
;
1697 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1699 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1702 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1706 *area
= RIGHT_MARGIN_AREA
;
1707 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1711 /* Find glyph containing X. */
1712 glyph
= row
->glyphs
[*area
];
1713 end
= glyph
+ row
->used
[*area
];
1715 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1717 x
-= glyph
->pixel_width
;
1727 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1730 *hpos
= glyph
- row
->glyphs
[*area
];
1736 Convert frame-relative x/y to coordinates relative to window W.
1737 Takes pseudo-windows into account. */
1740 frame_to_window_pixel_xy (w
, x
, y
)
1744 if (w
->pseudo_window_p
)
1746 /* A pseudo-window is always full-width, and starts at the
1747 left edge of the frame, plus a frame border. */
1748 struct frame
*f
= XFRAME (w
->frame
);
1749 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1750 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1754 *x
-= WINDOW_LEFT_EDGE_X (w
);
1755 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1760 Return in *R the clipping rectangle for glyph string S. */
1763 get_glyph_string_clip_rect (s
, nr
)
1764 struct glyph_string
*s
;
1765 NativeRectangle
*nr
;
1769 if (s
->row
->full_width_p
)
1771 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1772 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1773 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1775 /* Unless displaying a mode or menu bar line, which are always
1776 fully visible, clip to the visible part of the row. */
1777 if (s
->w
->pseudo_window_p
)
1778 r
.height
= s
->row
->visible_height
;
1780 r
.height
= s
->height
;
1784 /* This is a text line that may be partially visible. */
1785 r
.x
= window_box_left (s
->w
, s
->area
);
1786 r
.width
= window_box_width (s
->w
, s
->area
);
1787 r
.height
= s
->row
->visible_height
;
1791 if (r
.x
< s
->clip_head
->x
)
1793 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1794 r
.width
-= s
->clip_head
->x
- r
.x
;
1797 r
.x
= s
->clip_head
->x
;
1800 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1802 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1803 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1808 /* If S draws overlapping rows, it's sufficient to use the top and
1809 bottom of the window for clipping because this glyph string
1810 intentionally draws over other lines. */
1811 if (s
->for_overlaps_p
)
1813 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1814 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1818 /* Don't use S->y for clipping because it doesn't take partially
1819 visible lines into account. For example, it can be negative for
1820 partially visible lines at the top of a window. */
1821 if (!s
->row
->full_width_p
1822 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1823 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1825 r
.y
= max (0, s
->row
->y
);
1827 /* If drawing a tool-bar window, draw it over the internal border
1828 at the top of the window. */
1829 if (WINDOWP (s
->f
->tool_bar_window
)
1830 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1831 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1834 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1836 /* If drawing the cursor, don't let glyph draw outside its
1837 advertised boundaries. Cleartype does this under some circumstances. */
1838 if (s
->hl
== DRAW_CURSOR
)
1840 struct glyph
*glyph
= s
->first_glyph
;
1845 r
.width
-= s
->x
- r
.x
;
1848 r
.width
= min (r
.width
, glyph
->pixel_width
);
1850 /* If r.y is below window bottom, ensure that we still see a cursor. */
1851 height
= min (glyph
->ascent
+ glyph
->descent
,
1852 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1853 max_y
= window_text_bottom_y (s
->w
) - height
;
1854 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1855 if (s
->ybase
- glyph
->ascent
> max_y
)
1862 /* Don't draw cursor glyph taller than our actual glyph. */
1863 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1864 if (height
< r
.height
)
1866 max_y
= r
.y
+ r
.height
;
1867 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1868 r
.height
= min (max_y
- r
.y
, height
);
1873 #ifdef CONVERT_FROM_XRECT
1874 CONVERT_FROM_XRECT (r
, *nr
);
1882 Return the position and height of the phys cursor in window W.
1883 Set w->phys_cursor_width to width of phys cursor.
1887 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1889 struct glyph_row
*row
;
1890 struct glyph
*glyph
;
1893 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1894 int x
, y
, wd
, h
, h0
, y0
;
1896 /* Compute the width of the rectangle to draw. If on a stretch
1897 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1898 rectangle as wide as the glyph, but use a canonical character
1900 wd
= glyph
->pixel_width
- 1;
1904 if (glyph
->type
== STRETCH_GLYPH
1905 && !x_stretch_cursor_p
)
1906 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1907 w
->phys_cursor_width
= wd
;
1909 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1911 /* If y is below window bottom, ensure that we still see a cursor. */
1912 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1914 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1915 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1917 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1920 h
= max (h
- (y0
- y
) + 1, h0
);
1925 y0
= window_text_bottom_y (w
) - h0
;
1934 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1938 #endif /* HAVE_WINDOW_SYSTEM */
1941 /***********************************************************************
1942 Lisp form evaluation
1943 ***********************************************************************/
1945 /* Error handler for safe_eval and safe_call. */
1948 safe_eval_handler (arg
)
1951 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1956 /* Evaluate SEXPR and return the result, or nil if something went
1957 wrong. Prevent redisplay during the evaluation. */
1965 if (inhibit_eval_during_redisplay
)
1969 int count
= SPECPDL_INDEX ();
1970 struct gcpro gcpro1
;
1973 specbind (Qinhibit_redisplay
, Qt
);
1974 /* Use Qt to ensure debugger does not run,
1975 so there is no possibility of wanting to redisplay. */
1976 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1979 val
= unbind_to (count
, val
);
1986 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1987 Return the result, or nil if something went wrong. Prevent
1988 redisplay during the evaluation. */
1991 safe_call (nargs
, args
)
1997 if (inhibit_eval_during_redisplay
)
2001 int count
= SPECPDL_INDEX ();
2002 struct gcpro gcpro1
;
2005 gcpro1
.nvars
= nargs
;
2006 specbind (Qinhibit_redisplay
, Qt
);
2007 /* Use Qt to ensure debugger does not run,
2008 so there is no possibility of wanting to redisplay. */
2009 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2012 val
= unbind_to (count
, val
);
2019 /* Call function FN with one argument ARG.
2020 Return the result, or nil if something went wrong. */
2023 safe_call1 (fn
, arg
)
2024 Lisp_Object fn
, arg
;
2026 Lisp_Object args
[2];
2029 return safe_call (2, args
);
2034 /***********************************************************************
2036 ***********************************************************************/
2040 /* Define CHECK_IT to perform sanity checks on iterators.
2041 This is for debugging. It is too slow to do unconditionally. */
2047 if (it
->method
== GET_FROM_STRING
)
2049 xassert (STRINGP (it
->string
));
2050 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2054 xassert (IT_STRING_CHARPOS (*it
) < 0);
2055 if (it
->method
== GET_FROM_BUFFER
)
2057 /* Check that character and byte positions agree. */
2058 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2063 xassert (it
->current
.dpvec_index
>= 0);
2065 xassert (it
->current
.dpvec_index
< 0);
2068 #define CHECK_IT(IT) check_it ((IT))
2072 #define CHECK_IT(IT) (void) 0
2079 /* Check that the window end of window W is what we expect it
2080 to be---the last row in the current matrix displaying text. */
2083 check_window_end (w
)
2086 if (!MINI_WINDOW_P (w
)
2087 && !NILP (w
->window_end_valid
))
2089 struct glyph_row
*row
;
2090 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2091 XFASTINT (w
->window_end_vpos
)),
2093 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2094 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2098 #define CHECK_WINDOW_END(W) check_window_end ((W))
2100 #else /* not GLYPH_DEBUG */
2102 #define CHECK_WINDOW_END(W) (void) 0
2104 #endif /* not GLYPH_DEBUG */
2108 /***********************************************************************
2109 Iterator initialization
2110 ***********************************************************************/
2112 /* Initialize IT for displaying current_buffer in window W, starting
2113 at character position CHARPOS. CHARPOS < 0 means that no buffer
2114 position is specified which is useful when the iterator is assigned
2115 a position later. BYTEPOS is the byte position corresponding to
2116 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2118 If ROW is not null, calls to produce_glyphs with IT as parameter
2119 will produce glyphs in that row.
2121 BASE_FACE_ID is the id of a base face to use. It must be one of
2122 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2123 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2124 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2126 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2127 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2128 will be initialized to use the corresponding mode line glyph row of
2129 the desired matrix of W. */
2132 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2135 int charpos
, bytepos
;
2136 struct glyph_row
*row
;
2137 enum face_id base_face_id
;
2139 int highlight_region_p
;
2141 /* Some precondition checks. */
2142 xassert (w
!= NULL
&& it
!= NULL
);
2143 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2146 /* If face attributes have been changed since the last redisplay,
2147 free realized faces now because they depend on face definitions
2148 that might have changed. Don't free faces while there might be
2149 desired matrices pending which reference these faces. */
2150 if (face_change_count
&& !inhibit_free_realized_faces
)
2152 face_change_count
= 0;
2153 free_all_realized_faces (Qnil
);
2156 /* Use one of the mode line rows of W's desired matrix if
2160 if (base_face_id
== MODE_LINE_FACE_ID
2161 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2162 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2163 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2164 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2168 bzero (it
, sizeof *it
);
2169 it
->current
.overlay_string_index
= -1;
2170 it
->current
.dpvec_index
= -1;
2171 it
->base_face_id
= base_face_id
;
2173 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2175 /* The window in which we iterate over current_buffer: */
2176 XSETWINDOW (it
->window
, w
);
2178 it
->f
= XFRAME (w
->frame
);
2180 /* Extra space between lines (on window systems only). */
2181 if (base_face_id
== DEFAULT_FACE_ID
2182 && FRAME_WINDOW_P (it
->f
))
2184 if (NATNUMP (current_buffer
->extra_line_spacing
))
2185 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2186 else if (FLOATP (current_buffer
->extra_line_spacing
))
2187 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2188 * FRAME_LINE_HEIGHT (it
->f
));
2189 else if (it
->f
->extra_line_spacing
> 0)
2190 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2191 it
->max_extra_line_spacing
= 0;
2194 /* If realized faces have been removed, e.g. because of face
2195 attribute changes of named faces, recompute them. When running
2196 in batch mode, the face cache of Vterminal_frame is null. If
2197 we happen to get called, make a dummy face cache. */
2198 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2199 init_frame_faces (it
->f
);
2200 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2201 recompute_basic_faces (it
->f
);
2203 /* Current value of the `slice', `space-width', and 'height' properties. */
2204 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2205 it
->space_width
= Qnil
;
2206 it
->font_height
= Qnil
;
2207 it
->override_ascent
= -1;
2209 /* Are control characters displayed as `^C'? */
2210 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2212 /* -1 means everything between a CR and the following line end
2213 is invisible. >0 means lines indented more than this value are
2215 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2216 ? XFASTINT (current_buffer
->selective_display
)
2217 : (!NILP (current_buffer
->selective_display
)
2219 it
->selective_display_ellipsis_p
2220 = !NILP (current_buffer
->selective_display_ellipses
);
2222 /* Display table to use. */
2223 it
->dp
= window_display_table (w
);
2225 /* Are multibyte characters enabled in current_buffer? */
2226 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2228 /* Non-zero if we should highlight the region. */
2230 = (!NILP (Vtransient_mark_mode
)
2231 && !NILP (current_buffer
->mark_active
)
2232 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2234 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2235 start and end of a visible region in window IT->w. Set both to
2236 -1 to indicate no region. */
2237 if (highlight_region_p
2238 /* Maybe highlight only in selected window. */
2239 && (/* Either show region everywhere. */
2240 highlight_nonselected_windows
2241 /* Or show region in the selected window. */
2242 || w
== XWINDOW (selected_window
)
2243 /* Or show the region if we are in the mini-buffer and W is
2244 the window the mini-buffer refers to. */
2245 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2246 && WINDOWP (minibuf_selected_window
)
2247 && w
== XWINDOW (minibuf_selected_window
))))
2249 int charpos
= marker_position (current_buffer
->mark
);
2250 it
->region_beg_charpos
= min (PT
, charpos
);
2251 it
->region_end_charpos
= max (PT
, charpos
);
2254 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2256 /* Get the position at which the redisplay_end_trigger hook should
2257 be run, if it is to be run at all. */
2258 if (MARKERP (w
->redisplay_end_trigger
)
2259 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2260 it
->redisplay_end_trigger_charpos
2261 = marker_position (w
->redisplay_end_trigger
);
2262 else if (INTEGERP (w
->redisplay_end_trigger
))
2263 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2265 /* Correct bogus values of tab_width. */
2266 it
->tab_width
= XINT (current_buffer
->tab_width
);
2267 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2270 /* Are lines in the display truncated? */
2271 it
->truncate_lines_p
2272 = (base_face_id
!= DEFAULT_FACE_ID
2273 || XINT (it
->w
->hscroll
)
2274 || (truncate_partial_width_windows
2275 && !WINDOW_FULL_WIDTH_P (it
->w
))
2276 || !NILP (current_buffer
->truncate_lines
));
2278 /* Get dimensions of truncation and continuation glyphs. These are
2279 displayed as fringe bitmaps under X, so we don't need them for such
2281 if (!FRAME_WINDOW_P (it
->f
))
2283 if (it
->truncate_lines_p
)
2285 /* We will need the truncation glyph. */
2286 xassert (it
->glyph_row
== NULL
);
2287 produce_special_glyphs (it
, IT_TRUNCATION
);
2288 it
->truncation_pixel_width
= it
->pixel_width
;
2292 /* We will need the continuation glyph. */
2293 xassert (it
->glyph_row
== NULL
);
2294 produce_special_glyphs (it
, IT_CONTINUATION
);
2295 it
->continuation_pixel_width
= it
->pixel_width
;
2298 /* Reset these values to zero because the produce_special_glyphs
2299 above has changed them. */
2300 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2301 it
->phys_ascent
= it
->phys_descent
= 0;
2304 /* Set this after getting the dimensions of truncation and
2305 continuation glyphs, so that we don't produce glyphs when calling
2306 produce_special_glyphs, above. */
2307 it
->glyph_row
= row
;
2308 it
->area
= TEXT_AREA
;
2310 /* Get the dimensions of the display area. The display area
2311 consists of the visible window area plus a horizontally scrolled
2312 part to the left of the window. All x-values are relative to the
2313 start of this total display area. */
2314 if (base_face_id
!= DEFAULT_FACE_ID
)
2316 /* Mode lines, menu bar in terminal frames. */
2317 it
->first_visible_x
= 0;
2318 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2323 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2324 it
->last_visible_x
= (it
->first_visible_x
2325 + window_box_width (w
, TEXT_AREA
));
2327 /* If we truncate lines, leave room for the truncator glyph(s) at
2328 the right margin. Otherwise, leave room for the continuation
2329 glyph(s). Truncation and continuation glyphs are not inserted
2330 for window-based redisplay. */
2331 if (!FRAME_WINDOW_P (it
->f
))
2333 if (it
->truncate_lines_p
)
2334 it
->last_visible_x
-= it
->truncation_pixel_width
;
2336 it
->last_visible_x
-= it
->continuation_pixel_width
;
2339 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2340 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2343 /* Leave room for a border glyph. */
2344 if (!FRAME_WINDOW_P (it
->f
)
2345 && !WINDOW_RIGHTMOST_P (it
->w
))
2346 it
->last_visible_x
-= 1;
2348 it
->last_visible_y
= window_text_bottom_y (w
);
2350 /* For mode lines and alike, arrange for the first glyph having a
2351 left box line if the face specifies a box. */
2352 if (base_face_id
!= DEFAULT_FACE_ID
)
2356 it
->face_id
= base_face_id
;
2358 /* If we have a boxed mode line, make the first character appear
2359 with a left box line. */
2360 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2361 if (face
->box
!= FACE_NO_BOX
)
2362 it
->start_of_box_run_p
= 1;
2365 /* If a buffer position was specified, set the iterator there,
2366 getting overlays and face properties from that position. */
2367 if (charpos
>= BUF_BEG (current_buffer
))
2369 it
->end_charpos
= ZV
;
2371 IT_CHARPOS (*it
) = charpos
;
2373 /* Compute byte position if not specified. */
2374 if (bytepos
< charpos
)
2375 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2377 IT_BYTEPOS (*it
) = bytepos
;
2379 it
->start
= it
->current
;
2381 /* Compute faces etc. */
2382 reseat (it
, it
->current
.pos
, 1);
2389 /* Initialize IT for the display of window W with window start POS. */
2392 start_display (it
, w
, pos
)
2395 struct text_pos pos
;
2397 struct glyph_row
*row
;
2398 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2400 row
= w
->desired_matrix
->rows
+ first_vpos
;
2401 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2402 it
->first_vpos
= first_vpos
;
2404 if (!it
->truncate_lines_p
)
2406 int start_at_line_beg_p
;
2407 int first_y
= it
->current_y
;
2409 /* If window start is not at a line start, skip forward to POS to
2410 get the correct continuation lines width. */
2411 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2412 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2413 if (!start_at_line_beg_p
)
2417 reseat_at_previous_visible_line_start (it
);
2418 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2420 new_x
= it
->current_x
+ it
->pixel_width
;
2422 /* If lines are continued, this line may end in the middle
2423 of a multi-glyph character (e.g. a control character
2424 displayed as \003, or in the middle of an overlay
2425 string). In this case move_it_to above will not have
2426 taken us to the start of the continuation line but to the
2427 end of the continued line. */
2428 if (it
->current_x
> 0
2429 && !it
->truncate_lines_p
/* Lines are continued. */
2430 && (/* And glyph doesn't fit on the line. */
2431 new_x
> it
->last_visible_x
2432 /* Or it fits exactly and we're on a window
2434 || (new_x
== it
->last_visible_x
2435 && FRAME_WINDOW_P (it
->f
))))
2437 if (it
->current
.dpvec_index
>= 0
2438 || it
->current
.overlay_string_index
>= 0)
2440 set_iterator_to_next (it
, 1);
2441 move_it_in_display_line_to (it
, -1, -1, 0);
2444 it
->continuation_lines_width
+= it
->current_x
;
2447 /* We're starting a new display line, not affected by the
2448 height of the continued line, so clear the appropriate
2449 fields in the iterator structure. */
2450 it
->max_ascent
= it
->max_descent
= 0;
2451 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2453 it
->current_y
= first_y
;
2455 it
->current_x
= it
->hpos
= 0;
2459 #if 0 /* Don't assert the following because start_display is sometimes
2460 called intentionally with a window start that is not at a
2461 line start. Please leave this code in as a comment. */
2463 /* Window start should be on a line start, now. */
2464 xassert (it
->continuation_lines_width
2465 || IT_CHARPOS (it
) == BEGV
2466 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2471 /* Return 1 if POS is a position in ellipses displayed for invisible
2472 text. W is the window we display, for text property lookup. */
2475 in_ellipses_for_invisible_text_p (pos
, w
)
2476 struct display_pos
*pos
;
2479 Lisp_Object prop
, window
;
2481 int charpos
= CHARPOS (pos
->pos
);
2483 /* If POS specifies a position in a display vector, this might
2484 be for an ellipsis displayed for invisible text. We won't
2485 get the iterator set up for delivering that ellipsis unless
2486 we make sure that it gets aware of the invisible text. */
2487 if (pos
->dpvec_index
>= 0
2488 && pos
->overlay_string_index
< 0
2489 && CHARPOS (pos
->string_pos
) < 0
2491 && (XSETWINDOW (window
, w
),
2492 prop
= Fget_char_property (make_number (charpos
),
2493 Qinvisible
, window
),
2494 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2496 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2498 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2505 /* Initialize IT for stepping through current_buffer in window W,
2506 starting at position POS that includes overlay string and display
2507 vector/ control character translation position information. Value
2508 is zero if there are overlay strings with newlines at POS. */
2511 init_from_display_pos (it
, w
, pos
)
2514 struct display_pos
*pos
;
2516 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2517 int i
, overlay_strings_with_newlines
= 0;
2519 /* If POS specifies a position in a display vector, this might
2520 be for an ellipsis displayed for invisible text. We won't
2521 get the iterator set up for delivering that ellipsis unless
2522 we make sure that it gets aware of the invisible text. */
2523 if (in_ellipses_for_invisible_text_p (pos
, w
))
2529 /* Keep in mind: the call to reseat in init_iterator skips invisible
2530 text, so we might end up at a position different from POS. This
2531 is only a problem when POS is a row start after a newline and an
2532 overlay starts there with an after-string, and the overlay has an
2533 invisible property. Since we don't skip invisible text in
2534 display_line and elsewhere immediately after consuming the
2535 newline before the row start, such a POS will not be in a string,
2536 but the call to init_iterator below will move us to the
2538 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2540 /* This only scans the current chunk -- it should scan all chunks.
2541 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2542 to 16 in 22.1 to make this a lesser problem. */
2543 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2545 const char *s
= SDATA (it
->overlay_strings
[i
]);
2546 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2548 while (s
< e
&& *s
!= '\n')
2553 overlay_strings_with_newlines
= 1;
2558 /* If position is within an overlay string, set up IT to the right
2560 if (pos
->overlay_string_index
>= 0)
2564 /* If the first overlay string happens to have a `display'
2565 property for an image, the iterator will be set up for that
2566 image, and we have to undo that setup first before we can
2567 correct the overlay string index. */
2568 if (it
->method
== GET_FROM_IMAGE
)
2571 /* We already have the first chunk of overlay strings in
2572 IT->overlay_strings. Load more until the one for
2573 pos->overlay_string_index is in IT->overlay_strings. */
2574 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2576 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2577 it
->current
.overlay_string_index
= 0;
2580 load_overlay_strings (it
, 0);
2581 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2585 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2586 relative_index
= (it
->current
.overlay_string_index
2587 % OVERLAY_STRING_CHUNK_SIZE
);
2588 it
->string
= it
->overlay_strings
[relative_index
];
2589 xassert (STRINGP (it
->string
));
2590 it
->current
.string_pos
= pos
->string_pos
;
2591 it
->method
= GET_FROM_STRING
;
2594 #if 0 /* This is bogus because POS not having an overlay string
2595 position does not mean it's after the string. Example: A
2596 line starting with a before-string and initialization of IT
2597 to the previous row's end position. */
2598 else if (it
->current
.overlay_string_index
>= 0)
2600 /* If POS says we're already after an overlay string ending at
2601 POS, make sure to pop the iterator because it will be in
2602 front of that overlay string. When POS is ZV, we've thereby
2603 also ``processed'' overlay strings at ZV. */
2606 it
->current
.overlay_string_index
= -1;
2607 it
->method
= GET_FROM_BUFFER
;
2608 if (CHARPOS (pos
->pos
) == ZV
)
2609 it
->overlay_strings_at_end_processed_p
= 1;
2613 if (CHARPOS (pos
->string_pos
) >= 0)
2615 /* Recorded position is not in an overlay string, but in another
2616 string. This can only be a string from a `display' property.
2617 IT should already be filled with that string. */
2618 it
->current
.string_pos
= pos
->string_pos
;
2619 xassert (STRINGP (it
->string
));
2622 /* Restore position in display vector translations, control
2623 character translations or ellipses. */
2624 if (pos
->dpvec_index
>= 0)
2626 if (it
->dpvec
== NULL
)
2627 get_next_display_element (it
);
2628 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2629 it
->current
.dpvec_index
= pos
->dpvec_index
;
2633 return !overlay_strings_with_newlines
;
2637 /* Initialize IT for stepping through current_buffer in window W
2638 starting at ROW->start. */
2641 init_to_row_start (it
, w
, row
)
2644 struct glyph_row
*row
;
2646 init_from_display_pos (it
, w
, &row
->start
);
2647 it
->start
= row
->start
;
2648 it
->continuation_lines_width
= row
->continuation_lines_width
;
2653 /* Initialize IT for stepping through current_buffer in window W
2654 starting in the line following ROW, i.e. starting at ROW->end.
2655 Value is zero if there are overlay strings with newlines at ROW's
2659 init_to_row_end (it
, w
, row
)
2662 struct glyph_row
*row
;
2666 if (init_from_display_pos (it
, w
, &row
->end
))
2668 if (row
->continued_p
)
2669 it
->continuation_lines_width
2670 = row
->continuation_lines_width
+ row
->pixel_width
;
2681 /***********************************************************************
2683 ***********************************************************************/
2685 /* Called when IT reaches IT->stop_charpos. Handle text property and
2686 overlay changes. Set IT->stop_charpos to the next position where
2693 enum prop_handled handled
;
2694 int handle_overlay_change_p
= 1;
2698 it
->current
.dpvec_index
= -1;
2702 handled
= HANDLED_NORMALLY
;
2704 /* Call text property handlers. */
2705 for (p
= it_props
; p
->handler
; ++p
)
2707 handled
= p
->handler (it
);
2709 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2711 else if (handled
== HANDLED_RETURN
)
2713 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2714 handle_overlay_change_p
= 0;
2717 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2719 /* Don't check for overlay strings below when set to deliver
2720 characters from a display vector. */
2721 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2722 handle_overlay_change_p
= 0;
2724 /* Handle overlay changes. */
2725 if (handle_overlay_change_p
)
2726 handled
= handle_overlay_change (it
);
2728 /* Determine where to stop next. */
2729 if (handled
== HANDLED_NORMALLY
)
2730 compute_stop_pos (it
);
2733 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2737 /* Compute IT->stop_charpos from text property and overlay change
2738 information for IT's current position. */
2741 compute_stop_pos (it
)
2744 register INTERVAL iv
, next_iv
;
2745 Lisp_Object object
, limit
, position
;
2747 /* If nowhere else, stop at the end. */
2748 it
->stop_charpos
= it
->end_charpos
;
2750 if (STRINGP (it
->string
))
2752 /* Strings are usually short, so don't limit the search for
2754 object
= it
->string
;
2756 position
= make_number (IT_STRING_CHARPOS (*it
));
2762 /* If next overlay change is in front of the current stop pos
2763 (which is IT->end_charpos), stop there. Note: value of
2764 next_overlay_change is point-max if no overlay change
2766 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2767 if (charpos
< it
->stop_charpos
)
2768 it
->stop_charpos
= charpos
;
2770 /* If showing the region, we have to stop at the region
2771 start or end because the face might change there. */
2772 if (it
->region_beg_charpos
> 0)
2774 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2775 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2776 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2777 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2780 /* Set up variables for computing the stop position from text
2781 property changes. */
2782 XSETBUFFER (object
, current_buffer
);
2783 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2784 position
= make_number (IT_CHARPOS (*it
));
2788 /* Get the interval containing IT's position. Value is a null
2789 interval if there isn't such an interval. */
2790 iv
= validate_interval_range (object
, &position
, &position
, 0);
2791 if (!NULL_INTERVAL_P (iv
))
2793 Lisp_Object values_here
[LAST_PROP_IDX
];
2796 /* Get properties here. */
2797 for (p
= it_props
; p
->handler
; ++p
)
2798 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2800 /* Look for an interval following iv that has different
2802 for (next_iv
= next_interval (iv
);
2803 (!NULL_INTERVAL_P (next_iv
)
2805 || XFASTINT (limit
) > next_iv
->position
));
2806 next_iv
= next_interval (next_iv
))
2808 for (p
= it_props
; p
->handler
; ++p
)
2810 Lisp_Object new_value
;
2812 new_value
= textget (next_iv
->plist
, *p
->name
);
2813 if (!EQ (values_here
[p
->idx
], new_value
))
2821 if (!NULL_INTERVAL_P (next_iv
))
2823 if (INTEGERP (limit
)
2824 && next_iv
->position
>= XFASTINT (limit
))
2825 /* No text property change up to limit. */
2826 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2828 /* Text properties change in next_iv. */
2829 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2833 xassert (STRINGP (it
->string
)
2834 || (it
->stop_charpos
>= BEGV
2835 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2839 /* Return the position of the next overlay change after POS in
2840 current_buffer. Value is point-max if no overlay change
2841 follows. This is like `next-overlay-change' but doesn't use
2845 next_overlay_change (pos
)
2850 Lisp_Object
*overlays
;
2853 /* Get all overlays at the given position. */
2854 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2856 /* If any of these overlays ends before endpos,
2857 use its ending point instead. */
2858 for (i
= 0; i
< noverlays
; ++i
)
2863 oend
= OVERLAY_END (overlays
[i
]);
2864 oendpos
= OVERLAY_POSITION (oend
);
2865 endpos
= min (endpos
, oendpos
);
2873 /***********************************************************************
2875 ***********************************************************************/
2877 /* Handle changes in the `fontified' property of the current buffer by
2878 calling hook functions from Qfontification_functions to fontify
2881 static enum prop_handled
2882 handle_fontified_prop (it
)
2885 Lisp_Object prop
, pos
;
2886 enum prop_handled handled
= HANDLED_NORMALLY
;
2888 /* Get the value of the `fontified' property at IT's current buffer
2889 position. (The `fontified' property doesn't have a special
2890 meaning in strings.) If the value is nil, call functions from
2891 Qfontification_functions. */
2892 if (!STRINGP (it
->string
)
2894 && !NILP (Vfontification_functions
)
2895 && !NILP (Vrun_hooks
)
2896 && (pos
= make_number (IT_CHARPOS (*it
)),
2897 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2900 int count
= SPECPDL_INDEX ();
2903 val
= Vfontification_functions
;
2904 specbind (Qfontification_functions
, Qnil
);
2906 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2907 safe_call1 (val
, pos
);
2910 Lisp_Object globals
, fn
;
2911 struct gcpro gcpro1
, gcpro2
;
2914 GCPRO2 (val
, globals
);
2916 for (; CONSP (val
); val
= XCDR (val
))
2922 /* A value of t indicates this hook has a local
2923 binding; it means to run the global binding too.
2924 In a global value, t should not occur. If it
2925 does, we must ignore it to avoid an endless
2927 for (globals
= Fdefault_value (Qfontification_functions
);
2929 globals
= XCDR (globals
))
2931 fn
= XCAR (globals
);
2933 safe_call1 (fn
, pos
);
2937 safe_call1 (fn
, pos
);
2943 unbind_to (count
, Qnil
);
2945 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2946 something. This avoids an endless loop if they failed to
2947 fontify the text for which reason ever. */
2948 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2949 handled
= HANDLED_RECOMPUTE_PROPS
;
2957 /***********************************************************************
2959 ***********************************************************************/
2961 /* Set up iterator IT from face properties at its current position.
2962 Called from handle_stop. */
2964 static enum prop_handled
2965 handle_face_prop (it
)
2968 int new_face_id
, next_stop
;
2970 if (!STRINGP (it
->string
))
2973 = face_at_buffer_position (it
->w
,
2975 it
->region_beg_charpos
,
2976 it
->region_end_charpos
,
2979 + TEXT_PROP_DISTANCE_LIMIT
),
2982 /* Is this a start of a run of characters with box face?
2983 Caveat: this can be called for a freshly initialized
2984 iterator; face_id is -1 in this case. We know that the new
2985 face will not change until limit, i.e. if the new face has a
2986 box, all characters up to limit will have one. But, as
2987 usual, we don't know whether limit is really the end. */
2988 if (new_face_id
!= it
->face_id
)
2990 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2992 /* If new face has a box but old face has not, this is
2993 the start of a run of characters with box, i.e. it has
2994 a shadow on the left side. The value of face_id of the
2995 iterator will be -1 if this is the initial call that gets
2996 the face. In this case, we have to look in front of IT's
2997 position and see whether there is a face != new_face_id. */
2998 it
->start_of_box_run_p
2999 = (new_face
->box
!= FACE_NO_BOX
3000 && (it
->face_id
>= 0
3001 || IT_CHARPOS (*it
) == BEG
3002 || new_face_id
!= face_before_it_pos (it
)));
3003 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3008 int base_face_id
, bufpos
;
3010 if (it
->current
.overlay_string_index
>= 0)
3011 bufpos
= IT_CHARPOS (*it
);
3015 /* For strings from a buffer, i.e. overlay strings or strings
3016 from a `display' property, use the face at IT's current
3017 buffer position as the base face to merge with, so that
3018 overlay strings appear in the same face as surrounding
3019 text, unless they specify their own faces. */
3020 base_face_id
= underlying_face_id (it
);
3022 new_face_id
= face_at_string_position (it
->w
,
3024 IT_STRING_CHARPOS (*it
),
3026 it
->region_beg_charpos
,
3027 it
->region_end_charpos
,
3031 #if 0 /* This shouldn't be neccessary. Let's check it. */
3032 /* If IT is used to display a mode line we would really like to
3033 use the mode line face instead of the frame's default face. */
3034 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3035 && new_face_id
== DEFAULT_FACE_ID
)
3036 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3039 /* Is this a start of a run of characters with box? Caveat:
3040 this can be called for a freshly allocated iterator; face_id
3041 is -1 is this case. We know that the new face will not
3042 change until the next check pos, i.e. if the new face has a
3043 box, all characters up to that position will have a
3044 box. But, as usual, we don't know whether that position
3045 is really the end. */
3046 if (new_face_id
!= it
->face_id
)
3048 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3049 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3051 /* If new face has a box but old face hasn't, this is the
3052 start of a run of characters with box, i.e. it has a
3053 shadow on the left side. */
3054 it
->start_of_box_run_p
3055 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3056 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3060 it
->face_id
= new_face_id
;
3061 return HANDLED_NORMALLY
;
3065 /* Return the ID of the face ``underlying'' IT's current position,
3066 which is in a string. If the iterator is associated with a
3067 buffer, return the face at IT's current buffer position.
3068 Otherwise, use the iterator's base_face_id. */
3071 underlying_face_id (it
)
3074 int face_id
= it
->base_face_id
, i
;
3076 xassert (STRINGP (it
->string
));
3078 for (i
= it
->sp
- 1; i
>= 0; --i
)
3079 if (NILP (it
->stack
[i
].string
))
3080 face_id
= it
->stack
[i
].face_id
;
3086 /* Compute the face one character before or after the current position
3087 of IT. BEFORE_P non-zero means get the face in front of IT's
3088 position. Value is the id of the face. */
3091 face_before_or_after_it_pos (it
, before_p
)
3096 int next_check_charpos
;
3097 struct text_pos pos
;
3099 xassert (it
->s
== NULL
);
3101 if (STRINGP (it
->string
))
3103 int bufpos
, base_face_id
;
3105 /* No face change past the end of the string (for the case
3106 we are padding with spaces). No face change before the
3108 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3109 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3112 /* Set pos to the position before or after IT's current position. */
3114 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3116 /* For composition, we must check the character after the
3118 pos
= (it
->what
== IT_COMPOSITION
3119 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3120 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3122 if (it
->current
.overlay_string_index
>= 0)
3123 bufpos
= IT_CHARPOS (*it
);
3127 base_face_id
= underlying_face_id (it
);
3129 /* Get the face for ASCII, or unibyte. */
3130 face_id
= face_at_string_position (it
->w
,
3134 it
->region_beg_charpos
,
3135 it
->region_end_charpos
,
3136 &next_check_charpos
,
3139 /* Correct the face for charsets different from ASCII. Do it
3140 for the multibyte case only. The face returned above is
3141 suitable for unibyte text if IT->string is unibyte. */
3142 if (STRING_MULTIBYTE (it
->string
))
3144 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3145 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3147 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3149 c
= string_char_and_length (p
, rest
, &len
);
3150 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3155 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3156 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3159 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3160 pos
= it
->current
.pos
;
3163 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3166 if (it
->what
== IT_COMPOSITION
)
3167 /* For composition, we must check the position after the
3169 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3171 INC_TEXT_POS (pos
, it
->multibyte_p
);
3174 /* Determine face for CHARSET_ASCII, or unibyte. */
3175 face_id
= face_at_buffer_position (it
->w
,
3177 it
->region_beg_charpos
,
3178 it
->region_end_charpos
,
3179 &next_check_charpos
,
3182 /* Correct the face for charsets different from ASCII. Do it
3183 for the multibyte case only. The face returned above is
3184 suitable for unibyte text if current_buffer is unibyte. */
3185 if (it
->multibyte_p
)
3187 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3188 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3189 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3198 /***********************************************************************
3200 ***********************************************************************/
3202 /* Set up iterator IT from invisible properties at its current
3203 position. Called from handle_stop. */
3205 static enum prop_handled
3206 handle_invisible_prop (it
)
3209 enum prop_handled handled
= HANDLED_NORMALLY
;
3211 if (STRINGP (it
->string
))
3213 extern Lisp_Object Qinvisible
;
3214 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3216 /* Get the value of the invisible text property at the
3217 current position. Value will be nil if there is no such
3219 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3220 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3223 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3225 handled
= HANDLED_RECOMPUTE_PROPS
;
3227 /* Get the position at which the next change of the
3228 invisible text property can be found in IT->string.
3229 Value will be nil if the property value is the same for
3230 all the rest of IT->string. */
3231 XSETINT (limit
, SCHARS (it
->string
));
3232 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3235 /* Text at current position is invisible. The next
3236 change in the property is at position end_charpos.
3237 Move IT's current position to that position. */
3238 if (INTEGERP (end_charpos
)
3239 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3241 struct text_pos old
;
3242 old
= it
->current
.string_pos
;
3243 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3244 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3248 /* The rest of the string is invisible. If this is an
3249 overlay string, proceed with the next overlay string
3250 or whatever comes and return a character from there. */
3251 if (it
->current
.overlay_string_index
>= 0)
3253 next_overlay_string (it
);
3254 /* Don't check for overlay strings when we just
3255 finished processing them. */
3256 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3260 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3261 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3268 int invis_p
, newpos
, next_stop
, start_charpos
;
3269 Lisp_Object pos
, prop
, overlay
;
3271 /* First of all, is there invisible text at this position? */
3272 start_charpos
= IT_CHARPOS (*it
);
3273 pos
= make_number (IT_CHARPOS (*it
));
3274 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3276 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3278 /* If we are on invisible text, skip over it. */
3279 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3281 /* Record whether we have to display an ellipsis for the
3283 int display_ellipsis_p
= invis_p
== 2;
3285 handled
= HANDLED_RECOMPUTE_PROPS
;
3287 /* Loop skipping over invisible text. The loop is left at
3288 ZV or with IT on the first char being visible again. */
3291 /* Try to skip some invisible text. Return value is the
3292 position reached which can be equal to IT's position
3293 if there is nothing invisible here. This skips both
3294 over invisible text properties and overlays with
3295 invisible property. */
3296 newpos
= skip_invisible (IT_CHARPOS (*it
),
3297 &next_stop
, ZV
, it
->window
);
3299 /* If we skipped nothing at all we weren't at invisible
3300 text in the first place. If everything to the end of
3301 the buffer was skipped, end the loop. */
3302 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3306 /* We skipped some characters but not necessarily
3307 all there are. Check if we ended up on visible
3308 text. Fget_char_property returns the property of
3309 the char before the given position, i.e. if we
3310 get invis_p = 0, this means that the char at
3311 newpos is visible. */
3312 pos
= make_number (newpos
);
3313 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3314 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3317 /* If we ended up on invisible text, proceed to
3318 skip starting with next_stop. */
3320 IT_CHARPOS (*it
) = next_stop
;
3324 /* The position newpos is now either ZV or on visible text. */
3325 IT_CHARPOS (*it
) = newpos
;
3326 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3328 /* If there are before-strings at the start of invisible
3329 text, and the text is invisible because of a text
3330 property, arrange to show before-strings because 20.x did
3331 it that way. (If the text is invisible because of an
3332 overlay property instead of a text property, this is
3333 already handled in the overlay code.) */
3335 && get_overlay_strings (it
, start_charpos
))
3337 handled
= HANDLED_RECOMPUTE_PROPS
;
3338 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3340 else if (display_ellipsis_p
)
3341 setup_for_ellipsis (it
, 0);
3349 /* Make iterator IT return `...' next.
3350 Replaces LEN characters from buffer. */
3353 setup_for_ellipsis (it
, len
)
3357 /* Use the display table definition for `...'. Invalid glyphs
3358 will be handled by the method returning elements from dpvec. */
3359 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3361 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3362 it
->dpvec
= v
->contents
;
3363 it
->dpend
= v
->contents
+ v
->size
;
3367 /* Default `...'. */
3368 it
->dpvec
= default_invis_vector
;
3369 it
->dpend
= default_invis_vector
+ 3;
3372 it
->dpvec_char_len
= len
;
3373 it
->current
.dpvec_index
= 0;
3374 it
->dpvec_face_id
= -1;
3376 /* Remember the current face id in case glyphs specify faces.
3377 IT's face is restored in set_iterator_to_next. */
3378 it
->saved_face_id
= it
->face_id
;
3379 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3385 /***********************************************************************
3387 ***********************************************************************/
3389 /* Set up iterator IT from `display' property at its current position.
3390 Called from handle_stop.
3391 We return HANDLED_RETURN if some part of the display property
3392 overrides the display of the buffer text itself.
3393 Otherwise we return HANDLED_NORMALLY. */
3395 static enum prop_handled
3396 handle_display_prop (it
)
3399 Lisp_Object prop
, object
;
3400 struct text_pos
*position
;
3401 /* Nonzero if some property replaces the display of the text itself. */
3402 int display_replaced_p
= 0;
3404 if (STRINGP (it
->string
))
3406 object
= it
->string
;
3407 position
= &it
->current
.string_pos
;
3411 object
= it
->w
->buffer
;
3412 position
= &it
->current
.pos
;
3415 /* Reset those iterator values set from display property values. */
3416 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3417 it
->space_width
= Qnil
;
3418 it
->font_height
= Qnil
;
3421 /* We don't support recursive `display' properties, i.e. string
3422 values that have a string `display' property, that have a string
3423 `display' property etc. */
3424 if (!it
->string_from_display_prop_p
)
3425 it
->area
= TEXT_AREA
;
3427 prop
= Fget_char_property (make_number (position
->charpos
),
3430 return HANDLED_NORMALLY
;
3433 /* Simple properties. */
3434 && !EQ (XCAR (prop
), Qimage
)
3435 && !EQ (XCAR (prop
), Qspace
)
3436 && !EQ (XCAR (prop
), Qwhen
)
3437 && !EQ (XCAR (prop
), Qslice
)
3438 && !EQ (XCAR (prop
), Qspace_width
)
3439 && !EQ (XCAR (prop
), Qheight
)
3440 && !EQ (XCAR (prop
), Qraise
)
3441 /* Marginal area specifications. */
3442 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3443 && !EQ (XCAR (prop
), Qleft_fringe
)
3444 && !EQ (XCAR (prop
), Qright_fringe
)
3445 && !NILP (XCAR (prop
)))
3447 for (; CONSP (prop
); prop
= XCDR (prop
))
3449 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3450 position
, display_replaced_p
))
3451 display_replaced_p
= 1;
3454 else if (VECTORP (prop
))
3457 for (i
= 0; i
< ASIZE (prop
); ++i
)
3458 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3459 position
, display_replaced_p
))
3460 display_replaced_p
= 1;
3464 if (handle_single_display_spec (it
, prop
, object
, position
, 0))
3465 display_replaced_p
= 1;
3468 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3472 /* Value is the position of the end of the `display' property starting
3473 at START_POS in OBJECT. */
3475 static struct text_pos
3476 display_prop_end (it
, object
, start_pos
)
3479 struct text_pos start_pos
;
3482 struct text_pos end_pos
;
3484 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3485 Qdisplay
, object
, Qnil
);
3486 CHARPOS (end_pos
) = XFASTINT (end
);
3487 if (STRINGP (object
))
3488 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3490 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3496 /* Set up IT from a single `display' specification PROP. OBJECT
3497 is the object in which the `display' property was found. *POSITION
3498 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3499 means that we previously saw a display specification which already
3500 replaced text display with something else, for example an image;
3501 we ignore such properties after the first one has been processed.
3503 If PROP is a `space' or `image' specification, and in some other
3504 cases too, set *POSITION to the position where the `display'
3507 Value is non-zero if something was found which replaces the display
3508 of buffer or string text. */
3511 handle_single_display_spec (it
, spec
, object
, position
,
3512 display_replaced_before_p
)
3516 struct text_pos
*position
;
3517 int display_replaced_before_p
;
3520 Lisp_Object location
, value
;
3521 struct text_pos start_pos
;
3524 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3525 If the result is non-nil, use VALUE instead of SPEC. */
3527 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3536 if (!NILP (form
) && !EQ (form
, Qt
))
3538 int count
= SPECPDL_INDEX ();
3539 struct gcpro gcpro1
;
3541 /* Bind `object' to the object having the `display' property, a
3542 buffer or string. Bind `position' to the position in the
3543 object where the property was found, and `buffer-position'
3544 to the current position in the buffer. */
3545 specbind (Qobject
, object
);
3546 specbind (Qposition
, make_number (CHARPOS (*position
)));
3547 specbind (Qbuffer_position
,
3548 make_number (STRINGP (object
)
3549 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3551 form
= safe_eval (form
);
3553 unbind_to (count
, Qnil
);
3559 /* Handle `(height HEIGHT)' specifications. */
3561 && EQ (XCAR (spec
), Qheight
)
3562 && CONSP (XCDR (spec
)))
3564 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3567 it
->font_height
= XCAR (XCDR (spec
));
3568 if (!NILP (it
->font_height
))
3570 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3571 int new_height
= -1;
3573 if (CONSP (it
->font_height
)
3574 && (EQ (XCAR (it
->font_height
), Qplus
)
3575 || EQ (XCAR (it
->font_height
), Qminus
))
3576 && CONSP (XCDR (it
->font_height
))
3577 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3579 /* `(+ N)' or `(- N)' where N is an integer. */
3580 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3581 if (EQ (XCAR (it
->font_height
), Qplus
))
3583 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3585 else if (FUNCTIONP (it
->font_height
))
3587 /* Call function with current height as argument.
3588 Value is the new height. */
3590 height
= safe_call1 (it
->font_height
,
3591 face
->lface
[LFACE_HEIGHT_INDEX
]);
3592 if (NUMBERP (height
))
3593 new_height
= XFLOATINT (height
);
3595 else if (NUMBERP (it
->font_height
))
3597 /* Value is a multiple of the canonical char height. */
3600 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3601 new_height
= (XFLOATINT (it
->font_height
)
3602 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3606 /* Evaluate IT->font_height with `height' bound to the
3607 current specified height to get the new height. */
3608 int count
= SPECPDL_INDEX ();
3610 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3611 value
= safe_eval (it
->font_height
);
3612 unbind_to (count
, Qnil
);
3614 if (NUMBERP (value
))
3615 new_height
= XFLOATINT (value
);
3619 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3625 /* Handle `(space_width WIDTH)'. */
3627 && EQ (XCAR (spec
), Qspace_width
)
3628 && CONSP (XCDR (spec
)))
3630 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3633 value
= XCAR (XCDR (spec
));
3634 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3635 it
->space_width
= value
;
3640 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3642 && EQ (XCAR (spec
), Qslice
))
3646 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3649 if (tem
= XCDR (spec
), CONSP (tem
))
3651 it
->slice
.x
= XCAR (tem
);
3652 if (tem
= XCDR (tem
), CONSP (tem
))
3654 it
->slice
.y
= XCAR (tem
);
3655 if (tem
= XCDR (tem
), CONSP (tem
))
3657 it
->slice
.width
= XCAR (tem
);
3658 if (tem
= XCDR (tem
), CONSP (tem
))
3659 it
->slice
.height
= XCAR (tem
);
3667 /* Handle `(raise FACTOR)'. */
3669 && EQ (XCAR (spec
), Qraise
)
3670 && CONSP (XCDR (spec
)))
3672 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3675 #ifdef HAVE_WINDOW_SYSTEM
3676 value
= XCAR (XCDR (spec
));
3677 if (NUMBERP (value
))
3679 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3680 it
->voffset
= - (XFLOATINT (value
)
3681 * (FONT_HEIGHT (face
->font
)));
3683 #endif /* HAVE_WINDOW_SYSTEM */
3688 /* Don't handle the other kinds of display specifications
3689 inside a string that we got from a `display' property. */
3690 if (it
->string_from_display_prop_p
)
3693 /* Characters having this form of property are not displayed, so
3694 we have to find the end of the property. */
3695 start_pos
= *position
;
3696 *position
= display_prop_end (it
, object
, start_pos
);
3699 /* Stop the scan at that end position--we assume that all
3700 text properties change there. */
3701 it
->stop_charpos
= position
->charpos
;
3703 /* Handle `(left-fringe BITMAP [FACE])'
3704 and `(right-fringe BITMAP [FACE])'. */
3706 && (EQ (XCAR (spec
), Qleft_fringe
)
3707 || EQ (XCAR (spec
), Qright_fringe
))
3708 && CONSP (XCDR (spec
)))
3710 int face_id
= DEFAULT_FACE_ID
;
3713 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3714 /* If we return here, POSITION has been advanced
3715 across the text with this property. */
3718 #ifdef HAVE_WINDOW_SYSTEM
3719 value
= XCAR (XCDR (spec
));
3720 if (!SYMBOLP (value
)
3721 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3722 /* If we return here, POSITION has been advanced
3723 across the text with this property. */
3726 if (CONSP (XCDR (XCDR (spec
))))
3728 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3729 int face_id2
= lookup_derived_face (it
->f
, face_name
,
3730 'A', FRINGE_FACE_ID
, 0);
3735 /* Save current settings of IT so that we can restore them
3736 when we are finished with the glyph property value. */
3740 it
->area
= TEXT_AREA
;
3741 it
->what
= IT_IMAGE
;
3742 it
->image_id
= -1; /* no image */
3743 it
->position
= start_pos
;
3744 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3745 it
->method
= GET_FROM_IMAGE
;
3746 it
->face_id
= face_id
;
3748 /* Say that we haven't consumed the characters with
3749 `display' property yet. The call to pop_it in
3750 set_iterator_to_next will clean this up. */
3751 *position
= start_pos
;
3753 if (EQ (XCAR (spec
), Qleft_fringe
))
3755 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3756 it
->left_user_fringe_face_id
= face_id
;
3760 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3761 it
->right_user_fringe_face_id
= face_id
;
3763 #endif /* HAVE_WINDOW_SYSTEM */
3767 /* Prepare to handle `((margin left-margin) ...)',
3768 `((margin right-margin) ...)' and `((margin nil) ...)'
3769 prefixes for display specifications. */
3770 location
= Qunbound
;
3771 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3775 value
= XCDR (spec
);
3777 value
= XCAR (value
);
3780 if (EQ (XCAR (tem
), Qmargin
)
3781 && (tem
= XCDR (tem
),
3782 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3784 || EQ (tem
, Qleft_margin
)
3785 || EQ (tem
, Qright_margin
))))
3789 if (EQ (location
, Qunbound
))
3795 /* After this point, VALUE is the property after any
3796 margin prefix has been stripped. It must be a string,
3797 an image specification, or `(space ...)'.
3799 LOCATION specifies where to display: `left-margin',
3800 `right-margin' or nil. */
3802 valid_p
= (STRINGP (value
)
3803 #ifdef HAVE_WINDOW_SYSTEM
3804 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3805 #endif /* not HAVE_WINDOW_SYSTEM */
3806 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3808 if (valid_p
&& !display_replaced_before_p
)
3810 /* Save current settings of IT so that we can restore them
3811 when we are finished with the glyph property value. */
3814 if (NILP (location
))
3815 it
->area
= TEXT_AREA
;
3816 else if (EQ (location
, Qleft_margin
))
3817 it
->area
= LEFT_MARGIN_AREA
;
3819 it
->area
= RIGHT_MARGIN_AREA
;
3821 if (STRINGP (value
))
3824 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3825 it
->current
.overlay_string_index
= -1;
3826 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3827 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3828 it
->method
= GET_FROM_STRING
;
3829 it
->stop_charpos
= 0;
3830 it
->string_from_display_prop_p
= 1;
3831 /* Say that we haven't consumed the characters with
3832 `display' property yet. The call to pop_it in
3833 set_iterator_to_next will clean this up. */
3834 *position
= start_pos
;
3836 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3838 it
->method
= GET_FROM_STRETCH
;
3840 it
->current
.pos
= it
->position
= start_pos
;
3842 #ifdef HAVE_WINDOW_SYSTEM
3845 it
->what
= IT_IMAGE
;
3846 it
->image_id
= lookup_image (it
->f
, value
);
3847 it
->position
= start_pos
;
3848 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3849 it
->method
= GET_FROM_IMAGE
;
3851 /* Say that we haven't consumed the characters with
3852 `display' property yet. The call to pop_it in
3853 set_iterator_to_next will clean this up. */
3854 *position
= start_pos
;
3856 #endif /* HAVE_WINDOW_SYSTEM */
3861 /* Invalid property or property not supported. Restore
3862 POSITION to what it was before. */
3863 *position
= start_pos
;
3868 /* Check if SPEC is a display specification value whose text should be
3869 treated as intangible. */
3872 single_display_spec_intangible_p (prop
)
3875 /* Skip over `when FORM'. */
3876 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3890 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3891 we don't need to treat text as intangible. */
3892 if (EQ (XCAR (prop
), Qmargin
))
3900 || EQ (XCAR (prop
), Qleft_margin
)
3901 || EQ (XCAR (prop
), Qright_margin
))
3905 return (CONSP (prop
)
3906 && (EQ (XCAR (prop
), Qimage
)
3907 || EQ (XCAR (prop
), Qspace
)));
3911 /* Check if PROP is a display property value whose text should be
3912 treated as intangible. */
3915 display_prop_intangible_p (prop
)
3919 && CONSP (XCAR (prop
))
3920 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3922 /* A list of sub-properties. */
3923 while (CONSP (prop
))
3925 if (single_display_spec_intangible_p (XCAR (prop
)))
3930 else if (VECTORP (prop
))
3932 /* A vector of sub-properties. */
3934 for (i
= 0; i
< ASIZE (prop
); ++i
)
3935 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3939 return single_display_spec_intangible_p (prop
);
3945 /* Return 1 if PROP is a display sub-property value containing STRING. */
3948 single_display_spec_string_p (prop
, string
)
3949 Lisp_Object prop
, string
;
3951 if (EQ (string
, prop
))
3954 /* Skip over `when FORM'. */
3955 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3964 /* Skip over `margin LOCATION'. */
3965 if (EQ (XCAR (prop
), Qmargin
))
3976 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3980 /* Return 1 if STRING appears in the `display' property PROP. */
3983 display_prop_string_p (prop
, string
)
3984 Lisp_Object prop
, string
;
3987 && CONSP (XCAR (prop
))
3988 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3990 /* A list of sub-properties. */
3991 while (CONSP (prop
))
3993 if (single_display_spec_string_p (XCAR (prop
), string
))
3998 else if (VECTORP (prop
))
4000 /* A vector of sub-properties. */
4002 for (i
= 0; i
< ASIZE (prop
); ++i
)
4003 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4007 return single_display_spec_string_p (prop
, string
);
4013 /* Determine from which buffer position in W's buffer STRING comes
4014 from. AROUND_CHARPOS is an approximate position where it could
4015 be from. Value is the buffer position or 0 if it couldn't be
4018 W's buffer must be current.
4020 This function is necessary because we don't record buffer positions
4021 in glyphs generated from strings (to keep struct glyph small).
4022 This function may only use code that doesn't eval because it is
4023 called asynchronously from note_mouse_highlight. */
4026 string_buffer_position (w
, string
, around_charpos
)
4031 Lisp_Object limit
, prop
, pos
;
4032 const int MAX_DISTANCE
= 1000;
4035 pos
= make_number (around_charpos
);
4036 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4037 while (!found
&& !EQ (pos
, limit
))
4039 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4040 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4043 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4048 pos
= make_number (around_charpos
);
4049 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4050 while (!found
&& !EQ (pos
, limit
))
4052 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4053 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4056 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4061 return found
? XINT (pos
) : 0;
4066 /***********************************************************************
4067 `composition' property
4068 ***********************************************************************/
4070 /* Set up iterator IT from `composition' property at its current
4071 position. Called from handle_stop. */
4073 static enum prop_handled
4074 handle_composition_prop (it
)
4077 Lisp_Object prop
, string
;
4078 int pos
, pos_byte
, end
;
4079 enum prop_handled handled
= HANDLED_NORMALLY
;
4081 if (STRINGP (it
->string
))
4083 pos
= IT_STRING_CHARPOS (*it
);
4084 pos_byte
= IT_STRING_BYTEPOS (*it
);
4085 string
= it
->string
;
4089 pos
= IT_CHARPOS (*it
);
4090 pos_byte
= IT_BYTEPOS (*it
);
4094 /* If there's a valid composition and point is not inside of the
4095 composition (in the case that the composition is from the current
4096 buffer), draw a glyph composed from the composition components. */
4097 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4098 && COMPOSITION_VALID_P (pos
, end
, prop
)
4099 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4101 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4105 it
->method
= GET_FROM_COMPOSITION
;
4107 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4108 /* For a terminal, draw only the first character of the
4110 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4111 it
->len
= (STRINGP (it
->string
)
4112 ? string_char_to_byte (it
->string
, end
)
4113 : CHAR_TO_BYTE (end
)) - pos_byte
;
4114 it
->stop_charpos
= end
;
4115 handled
= HANDLED_RETURN
;
4124 /***********************************************************************
4126 ***********************************************************************/
4128 /* The following structure is used to record overlay strings for
4129 later sorting in load_overlay_strings. */
4131 struct overlay_entry
4133 Lisp_Object overlay
;
4140 /* Set up iterator IT from overlay strings at its current position.
4141 Called from handle_stop. */
4143 static enum prop_handled
4144 handle_overlay_change (it
)
4147 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4148 return HANDLED_RECOMPUTE_PROPS
;
4150 return HANDLED_NORMALLY
;
4154 /* Set up the next overlay string for delivery by IT, if there is an
4155 overlay string to deliver. Called by set_iterator_to_next when the
4156 end of the current overlay string is reached. If there are more
4157 overlay strings to display, IT->string and
4158 IT->current.overlay_string_index are set appropriately here.
4159 Otherwise IT->string is set to nil. */
4162 next_overlay_string (it
)
4165 ++it
->current
.overlay_string_index
;
4166 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4168 /* No more overlay strings. Restore IT's settings to what
4169 they were before overlay strings were processed, and
4170 continue to deliver from current_buffer. */
4171 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4174 xassert (it
->stop_charpos
>= BEGV
4175 && it
->stop_charpos
<= it
->end_charpos
);
4177 it
->current
.overlay_string_index
= -1;
4178 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4179 it
->n_overlay_strings
= 0;
4180 it
->method
= GET_FROM_BUFFER
;
4182 /* If we're at the end of the buffer, record that we have
4183 processed the overlay strings there already, so that
4184 next_element_from_buffer doesn't try it again. */
4185 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4186 it
->overlay_strings_at_end_processed_p
= 1;
4188 /* If we have to display `...' for invisible text, set
4189 the iterator up for that. */
4190 if (display_ellipsis_p
)
4191 setup_for_ellipsis (it
, 0);
4195 /* There are more overlay strings to process. If
4196 IT->current.overlay_string_index has advanced to a position
4197 where we must load IT->overlay_strings with more strings, do
4199 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4201 if (it
->current
.overlay_string_index
&& i
== 0)
4202 load_overlay_strings (it
, 0);
4204 /* Initialize IT to deliver display elements from the overlay
4206 it
->string
= it
->overlay_strings
[i
];
4207 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4208 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4209 it
->method
= GET_FROM_STRING
;
4210 it
->stop_charpos
= 0;
4217 /* Compare two overlay_entry structures E1 and E2. Used as a
4218 comparison function for qsort in load_overlay_strings. Overlay
4219 strings for the same position are sorted so that
4221 1. All after-strings come in front of before-strings, except
4222 when they come from the same overlay.
4224 2. Within after-strings, strings are sorted so that overlay strings
4225 from overlays with higher priorities come first.
4227 2. Within before-strings, strings are sorted so that overlay
4228 strings from overlays with higher priorities come last.
4230 Value is analogous to strcmp. */
4234 compare_overlay_entries (e1
, e2
)
4237 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4238 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4241 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4243 /* Let after-strings appear in front of before-strings if
4244 they come from different overlays. */
4245 if (EQ (entry1
->overlay
, entry2
->overlay
))
4246 result
= entry1
->after_string_p
? 1 : -1;
4248 result
= entry1
->after_string_p
? -1 : 1;
4250 else if (entry1
->after_string_p
)
4251 /* After-strings sorted in order of decreasing priority. */
4252 result
= entry2
->priority
- entry1
->priority
;
4254 /* Before-strings sorted in order of increasing priority. */
4255 result
= entry1
->priority
- entry2
->priority
;
4261 /* Load the vector IT->overlay_strings with overlay strings from IT's
4262 current buffer position, or from CHARPOS if that is > 0. Set
4263 IT->n_overlays to the total number of overlay strings found.
4265 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4266 a time. On entry into load_overlay_strings,
4267 IT->current.overlay_string_index gives the number of overlay
4268 strings that have already been loaded by previous calls to this
4271 IT->add_overlay_start contains an additional overlay start
4272 position to consider for taking overlay strings from, if non-zero.
4273 This position comes into play when the overlay has an `invisible'
4274 property, and both before and after-strings. When we've skipped to
4275 the end of the overlay, because of its `invisible' property, we
4276 nevertheless want its before-string to appear.
4277 IT->add_overlay_start will contain the overlay start position
4280 Overlay strings are sorted so that after-string strings come in
4281 front of before-string strings. Within before and after-strings,
4282 strings are sorted by overlay priority. See also function
4283 compare_overlay_entries. */
4286 load_overlay_strings (it
, charpos
)
4290 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4291 Lisp_Object overlay
, window
, str
, invisible
;
4292 struct Lisp_Overlay
*ov
;
4295 int n
= 0, i
, j
, invis_p
;
4296 struct overlay_entry
*entries
4297 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4300 charpos
= IT_CHARPOS (*it
);
4302 /* Append the overlay string STRING of overlay OVERLAY to vector
4303 `entries' which has size `size' and currently contains `n'
4304 elements. AFTER_P non-zero means STRING is an after-string of
4306 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4309 Lisp_Object priority; \
4313 int new_size = 2 * size; \
4314 struct overlay_entry *old = entries; \
4316 (struct overlay_entry *) alloca (new_size \
4317 * sizeof *entries); \
4318 bcopy (old, entries, size * sizeof *entries); \
4322 entries[n].string = (STRING); \
4323 entries[n].overlay = (OVERLAY); \
4324 priority = Foverlay_get ((OVERLAY), Qpriority); \
4325 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4326 entries[n].after_string_p = (AFTER_P); \
4331 /* Process overlay before the overlay center. */
4332 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4334 XSETMISC (overlay
, ov
);
4335 xassert (OVERLAYP (overlay
));
4336 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4337 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4342 /* Skip this overlay if it doesn't start or end at IT's current
4344 if (end
!= charpos
&& start
!= charpos
)
4347 /* Skip this overlay if it doesn't apply to IT->w. */
4348 window
= Foverlay_get (overlay
, Qwindow
);
4349 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4352 /* If the text ``under'' the overlay is invisible, both before-
4353 and after-strings from this overlay are visible; start and
4354 end position are indistinguishable. */
4355 invisible
= Foverlay_get (overlay
, Qinvisible
);
4356 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4358 /* If overlay has a non-empty before-string, record it. */
4359 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4360 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4362 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4364 /* If overlay has a non-empty after-string, record it. */
4365 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4366 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4368 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4371 /* Process overlays after the overlay center. */
4372 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4374 XSETMISC (overlay
, ov
);
4375 xassert (OVERLAYP (overlay
));
4376 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4377 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4379 if (start
> charpos
)
4382 /* Skip this overlay if it doesn't start or end at IT's current
4384 if (end
!= charpos
&& start
!= charpos
)
4387 /* Skip this overlay if it doesn't apply to IT->w. */
4388 window
= Foverlay_get (overlay
, Qwindow
);
4389 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4392 /* If the text ``under'' the overlay is invisible, it has a zero
4393 dimension, and both before- and after-strings apply. */
4394 invisible
= Foverlay_get (overlay
, Qinvisible
);
4395 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4397 /* If overlay has a non-empty before-string, record it. */
4398 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4399 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4401 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4403 /* If overlay has a non-empty after-string, record it. */
4404 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4405 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4407 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4410 #undef RECORD_OVERLAY_STRING
4414 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4416 /* Record the total number of strings to process. */
4417 it
->n_overlay_strings
= n
;
4419 /* IT->current.overlay_string_index is the number of overlay strings
4420 that have already been consumed by IT. Copy some of the
4421 remaining overlay strings to IT->overlay_strings. */
4423 j
= it
->current
.overlay_string_index
;
4424 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4425 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4431 /* Get the first chunk of overlay strings at IT's current buffer
4432 position, or at CHARPOS if that is > 0. Value is non-zero if at
4433 least one overlay string was found. */
4436 get_overlay_strings (it
, charpos
)
4440 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4441 process. This fills IT->overlay_strings with strings, and sets
4442 IT->n_overlay_strings to the total number of strings to process.
4443 IT->pos.overlay_string_index has to be set temporarily to zero
4444 because load_overlay_strings needs this; it must be set to -1
4445 when no overlay strings are found because a zero value would
4446 indicate a position in the first overlay string. */
4447 it
->current
.overlay_string_index
= 0;
4448 load_overlay_strings (it
, charpos
);
4450 /* If we found overlay strings, set up IT to deliver display
4451 elements from the first one. Otherwise set up IT to deliver
4452 from current_buffer. */
4453 if (it
->n_overlay_strings
)
4455 /* Make sure we know settings in current_buffer, so that we can
4456 restore meaningful values when we're done with the overlay
4458 compute_stop_pos (it
);
4459 xassert (it
->face_id
>= 0);
4461 /* Save IT's settings. They are restored after all overlay
4462 strings have been processed. */
4463 xassert (it
->sp
== 0);
4466 /* Set up IT to deliver display elements from the first overlay
4468 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4469 it
->string
= it
->overlay_strings
[0];
4470 it
->stop_charpos
= 0;
4471 xassert (STRINGP (it
->string
));
4472 it
->end_charpos
= SCHARS (it
->string
);
4473 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4474 it
->method
= GET_FROM_STRING
;
4479 it
->current
.overlay_string_index
= -1;
4480 it
->method
= GET_FROM_BUFFER
;
4485 /* Value is non-zero if we found at least one overlay string. */
4486 return STRINGP (it
->string
);
4491 /***********************************************************************
4492 Saving and restoring state
4493 ***********************************************************************/
4495 /* Save current settings of IT on IT->stack. Called, for example,
4496 before setting up IT for an overlay string, to be able to restore
4497 IT's settings to what they were after the overlay string has been
4504 struct iterator_stack_entry
*p
;
4506 xassert (it
->sp
< 2);
4507 p
= it
->stack
+ it
->sp
;
4509 p
->stop_charpos
= it
->stop_charpos
;
4510 xassert (it
->face_id
>= 0);
4511 p
->face_id
= it
->face_id
;
4512 p
->string
= it
->string
;
4513 p
->pos
= it
->current
;
4514 p
->end_charpos
= it
->end_charpos
;
4515 p
->string_nchars
= it
->string_nchars
;
4517 p
->multibyte_p
= it
->multibyte_p
;
4518 p
->slice
= it
->slice
;
4519 p
->space_width
= it
->space_width
;
4520 p
->font_height
= it
->font_height
;
4521 p
->voffset
= it
->voffset
;
4522 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4523 p
->display_ellipsis_p
= 0;
4528 /* Restore IT's settings from IT->stack. Called, for example, when no
4529 more overlay strings must be processed, and we return to delivering
4530 display elements from a buffer, or when the end of a string from a
4531 `display' property is reached and we return to delivering display
4532 elements from an overlay string, or from a buffer. */
4538 struct iterator_stack_entry
*p
;
4540 xassert (it
->sp
> 0);
4542 p
= it
->stack
+ it
->sp
;
4543 it
->stop_charpos
= p
->stop_charpos
;
4544 it
->face_id
= p
->face_id
;
4545 it
->string
= p
->string
;
4546 it
->current
= p
->pos
;
4547 it
->end_charpos
= p
->end_charpos
;
4548 it
->string_nchars
= p
->string_nchars
;
4550 it
->multibyte_p
= p
->multibyte_p
;
4551 it
->slice
= p
->slice
;
4552 it
->space_width
= p
->space_width
;
4553 it
->font_height
= p
->font_height
;
4554 it
->voffset
= p
->voffset
;
4555 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4560 /***********************************************************************
4562 ***********************************************************************/
4564 /* Set IT's current position to the previous line start. */
4567 back_to_previous_line_start (it
)
4570 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4571 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4575 /* Move IT to the next line start.
4577 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4578 we skipped over part of the text (as opposed to moving the iterator
4579 continuously over the text). Otherwise, don't change the value
4582 Newlines may come from buffer text, overlay strings, or strings
4583 displayed via the `display' property. That's the reason we can't
4584 simply use find_next_newline_no_quit.
4586 Note that this function may not skip over invisible text that is so
4587 because of text properties and immediately follows a newline. If
4588 it would, function reseat_at_next_visible_line_start, when called
4589 from set_iterator_to_next, would effectively make invisible
4590 characters following a newline part of the wrong glyph row, which
4591 leads to wrong cursor motion. */
4594 forward_to_next_line_start (it
, skipped_p
)
4598 int old_selective
, newline_found_p
, n
;
4599 const int MAX_NEWLINE_DISTANCE
= 500;
4601 /* If already on a newline, just consume it to avoid unintended
4602 skipping over invisible text below. */
4603 if (it
->what
== IT_CHARACTER
4605 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4607 set_iterator_to_next (it
, 0);
4612 /* Don't handle selective display in the following. It's (a)
4613 unnecessary because it's done by the caller, and (b) leads to an
4614 infinite recursion because next_element_from_ellipsis indirectly
4615 calls this function. */
4616 old_selective
= it
->selective
;
4619 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4620 from buffer text. */
4621 for (n
= newline_found_p
= 0;
4622 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4623 n
+= STRINGP (it
->string
) ? 0 : 1)
4625 if (!get_next_display_element (it
))
4627 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4628 set_iterator_to_next (it
, 0);
4631 /* If we didn't find a newline near enough, see if we can use a
4633 if (!newline_found_p
)
4635 int start
= IT_CHARPOS (*it
);
4636 int limit
= find_next_newline_no_quit (start
, 1);
4639 xassert (!STRINGP (it
->string
));
4641 /* If there isn't any `display' property in sight, and no
4642 overlays, we can just use the position of the newline in
4644 if (it
->stop_charpos
>= limit
4645 || ((pos
= Fnext_single_property_change (make_number (start
),
4647 Qnil
, make_number (limit
)),
4649 && next_overlay_change (start
) == ZV
))
4651 IT_CHARPOS (*it
) = limit
;
4652 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4653 *skipped_p
= newline_found_p
= 1;
4657 while (get_next_display_element (it
)
4658 && !newline_found_p
)
4660 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4661 set_iterator_to_next (it
, 0);
4666 it
->selective
= old_selective
;
4667 return newline_found_p
;
4671 /* Set IT's current position to the previous visible line start. Skip
4672 invisible text that is so either due to text properties or due to
4673 selective display. Caution: this does not change IT->current_x and
4677 back_to_previous_visible_line_start (it
)
4680 while (IT_CHARPOS (*it
) > BEGV
)
4682 back_to_previous_line_start (it
);
4683 if (IT_CHARPOS (*it
) <= BEGV
)
4686 /* If selective > 0, then lines indented more than that values
4688 if (it
->selective
> 0
4689 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4690 (double) it
->selective
)) /* iftc */
4693 /* Check the newline before point for invisibility. */
4696 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4697 Qinvisible
, it
->window
);
4698 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4702 /* If newline has a display property that replaces the newline with something
4703 else (image or text), find start of overlay or interval and continue search
4705 if (IT_CHARPOS (*it
) > BEGV
)
4707 struct it it2
= *it
;
4710 Lisp_Object val
, overlay
;
4712 pos
= --IT_CHARPOS (it2
);
4715 if (handle_display_prop (&it2
) == HANDLED_RETURN
4716 && !NILP (val
= get_char_property_and_overlay
4717 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4718 && (OVERLAYP (overlay
)
4719 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4720 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4724 IT_CHARPOS (*it
) = beg
;
4725 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4733 xassert (IT_CHARPOS (*it
) >= BEGV
);
4734 xassert (IT_CHARPOS (*it
) == BEGV
4735 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4740 /* Reseat iterator IT at the previous visible line start. Skip
4741 invisible text that is so either due to text properties or due to
4742 selective display. At the end, update IT's overlay information,
4743 face information etc. */
4746 reseat_at_previous_visible_line_start (it
)
4749 back_to_previous_visible_line_start (it
);
4750 reseat (it
, it
->current
.pos
, 1);
4755 /* Reseat iterator IT on the next visible line start in the current
4756 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4757 preceding the line start. Skip over invisible text that is so
4758 because of selective display. Compute faces, overlays etc at the
4759 new position. Note that this function does not skip over text that
4760 is invisible because of text properties. */
4763 reseat_at_next_visible_line_start (it
, on_newline_p
)
4767 int newline_found_p
, skipped_p
= 0;
4769 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4771 /* Skip over lines that are invisible because they are indented
4772 more than the value of IT->selective. */
4773 if (it
->selective
> 0)
4774 while (IT_CHARPOS (*it
) < ZV
4775 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4776 (double) it
->selective
)) /* iftc */
4778 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4779 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4782 /* Position on the newline if that's what's requested. */
4783 if (on_newline_p
&& newline_found_p
)
4785 if (STRINGP (it
->string
))
4787 if (IT_STRING_CHARPOS (*it
) > 0)
4789 --IT_STRING_CHARPOS (*it
);
4790 --IT_STRING_BYTEPOS (*it
);
4793 else if (IT_CHARPOS (*it
) > BEGV
)
4797 reseat (it
, it
->current
.pos
, 0);
4801 reseat (it
, it
->current
.pos
, 0);
4808 /***********************************************************************
4809 Changing an iterator's position
4810 ***********************************************************************/
4812 /* Change IT's current position to POS in current_buffer. If FORCE_P
4813 is non-zero, always check for text properties at the new position.
4814 Otherwise, text properties are only looked up if POS >=
4815 IT->check_charpos of a property. */
4818 reseat (it
, pos
, force_p
)
4820 struct text_pos pos
;
4823 int original_pos
= IT_CHARPOS (*it
);
4825 reseat_1 (it
, pos
, 0);
4827 /* Determine where to check text properties. Avoid doing it
4828 where possible because text property lookup is very expensive. */
4830 || CHARPOS (pos
) > it
->stop_charpos
4831 || CHARPOS (pos
) < original_pos
)
4838 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4839 IT->stop_pos to POS, also. */
4842 reseat_1 (it
, pos
, set_stop_p
)
4844 struct text_pos pos
;
4847 /* Don't call this function when scanning a C string. */
4848 xassert (it
->s
== NULL
);
4850 /* POS must be a reasonable value. */
4851 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4853 it
->current
.pos
= it
->position
= pos
;
4854 XSETBUFFER (it
->object
, current_buffer
);
4855 it
->end_charpos
= ZV
;
4857 it
->current
.dpvec_index
= -1;
4858 it
->current
.overlay_string_index
= -1;
4859 IT_STRING_CHARPOS (*it
) = -1;
4860 IT_STRING_BYTEPOS (*it
) = -1;
4862 it
->method
= GET_FROM_BUFFER
;
4863 /* RMS: I added this to fix a bug in move_it_vertically_backward
4864 where it->area continued to relate to the starting point
4865 for the backward motion. Bug report from
4866 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4867 However, I am not sure whether reseat still does the right thing
4868 in general after this change. */
4869 it
->area
= TEXT_AREA
;
4870 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4872 it
->face_before_selective_p
= 0;
4875 it
->stop_charpos
= CHARPOS (pos
);
4879 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4880 If S is non-null, it is a C string to iterate over. Otherwise,
4881 STRING gives a Lisp string to iterate over.
4883 If PRECISION > 0, don't return more then PRECISION number of
4884 characters from the string.
4886 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4887 characters have been returned. FIELD_WIDTH < 0 means an infinite
4890 MULTIBYTE = 0 means disable processing of multibyte characters,
4891 MULTIBYTE > 0 means enable it,
4892 MULTIBYTE < 0 means use IT->multibyte_p.
4894 IT must be initialized via a prior call to init_iterator before
4895 calling this function. */
4898 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4903 int precision
, field_width
, multibyte
;
4905 /* No region in strings. */
4906 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4908 /* No text property checks performed by default, but see below. */
4909 it
->stop_charpos
= -1;
4911 /* Set iterator position and end position. */
4912 bzero (&it
->current
, sizeof it
->current
);
4913 it
->current
.overlay_string_index
= -1;
4914 it
->current
.dpvec_index
= -1;
4915 xassert (charpos
>= 0);
4917 /* If STRING is specified, use its multibyteness, otherwise use the
4918 setting of MULTIBYTE, if specified. */
4920 it
->multibyte_p
= multibyte
> 0;
4924 xassert (STRINGP (string
));
4925 it
->string
= string
;
4927 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4928 it
->method
= GET_FROM_STRING
;
4929 it
->current
.string_pos
= string_pos (charpos
, string
);
4936 /* Note that we use IT->current.pos, not it->current.string_pos,
4937 for displaying C strings. */
4938 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4939 if (it
->multibyte_p
)
4941 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4942 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4946 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4947 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4950 it
->method
= GET_FROM_C_STRING
;
4953 /* PRECISION > 0 means don't return more than PRECISION characters
4955 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4956 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4958 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4959 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4960 FIELD_WIDTH < 0 means infinite field width. This is useful for
4961 padding with `-' at the end of a mode line. */
4962 if (field_width
< 0)
4963 field_width
= INFINITY
;
4964 if (field_width
> it
->end_charpos
- charpos
)
4965 it
->end_charpos
= charpos
+ field_width
;
4967 /* Use the standard display table for displaying strings. */
4968 if (DISP_TABLE_P (Vstandard_display_table
))
4969 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4971 it
->stop_charpos
= charpos
;
4977 /***********************************************************************
4979 ***********************************************************************/
4981 /* Map enum it_method value to corresponding next_element_from_* function. */
4983 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
4985 next_element_from_buffer
,
4986 next_element_from_display_vector
,
4987 next_element_from_composition
,
4988 next_element_from_string
,
4989 next_element_from_c_string
,
4990 next_element_from_image
,
4991 next_element_from_stretch
4995 /* Load IT's display element fields with information about the next
4996 display element from the current position of IT. Value is zero if
4997 end of buffer (or C string) is reached. */
5000 get_next_display_element (it
)
5003 /* Non-zero means that we found a display element. Zero means that
5004 we hit the end of what we iterate over. Performance note: the
5005 function pointer `method' used here turns out to be faster than
5006 using a sequence of if-statements. */
5010 success_p
= (*get_next_element
[it
->method
]) (it
);
5012 if (it
->what
== IT_CHARACTER
)
5014 /* Map via display table or translate control characters.
5015 IT->c, IT->len etc. have been set to the next character by
5016 the function call above. If we have a display table, and it
5017 contains an entry for IT->c, translate it. Don't do this if
5018 IT->c itself comes from a display table, otherwise we could
5019 end up in an infinite recursion. (An alternative could be to
5020 count the recursion depth of this function and signal an
5021 error when a certain maximum depth is reached.) Is it worth
5023 if (success_p
&& it
->dpvec
== NULL
)
5028 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5031 struct Lisp_Vector
*v
= XVECTOR (dv
);
5033 /* Return the first character from the display table
5034 entry, if not empty. If empty, don't display the
5035 current character. */
5038 it
->dpvec_char_len
= it
->len
;
5039 it
->dpvec
= v
->contents
;
5040 it
->dpend
= v
->contents
+ v
->size
;
5041 it
->current
.dpvec_index
= 0;
5042 it
->dpvec_face_id
= -1;
5043 it
->saved_face_id
= it
->face_id
;
5044 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5049 set_iterator_to_next (it
, 0);
5054 /* Translate control characters into `\003' or `^C' form.
5055 Control characters coming from a display table entry are
5056 currently not translated because we use IT->dpvec to hold
5057 the translation. This could easily be changed but I
5058 don't believe that it is worth doing.
5060 If it->multibyte_p is nonzero, eight-bit characters and
5061 non-printable multibyte characters are also translated to
5064 If it->multibyte_p is zero, eight-bit characters that
5065 don't have corresponding multibyte char code are also
5066 translated to octal form. */
5067 else if ((it
->c
< ' '
5068 && (it
->area
!= TEXT_AREA
5069 /* In mode line, treat \n like other crl chars. */
5071 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5072 || (it
->c
!= '\n' && it
->c
!= '\t')))
5076 || !CHAR_PRINTABLE_P (it
->c
)
5077 || (!NILP (Vshow_nonbreak_escape
)
5078 && (it
->c
== 0x8ad || it
->c
== 0x8a0
5079 || it
->c
== 0xf2d || it
->c
== 0xf20)))
5081 && (!unibyte_display_via_language_environment
5082 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5084 /* IT->c is a control character which must be displayed
5085 either as '\003' or as `^C' where the '\\' and '^'
5086 can be defined in the display table. Fill
5087 IT->ctl_chars with glyphs for what we have to
5088 display. Then, set IT->dpvec to these glyphs. */
5091 int face_id
, lface_id
= 0 ;
5094 if (it
->c
< 128 && it
->ctl_arrow_p
)
5096 g
= '^'; /* default glyph for Control */
5097 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5099 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5100 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5102 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5103 lface_id
= FAST_GLYPH_FACE (g
);
5107 g
= FAST_GLYPH_CHAR (g
);
5108 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5113 /* Merge the escape-glyph face into the current face. */
5114 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5118 XSETINT (it
->ctl_chars
[0], g
);
5120 XSETINT (it
->ctl_chars
[1], g
);
5122 goto display_control
;
5125 escape_glyph
= '\\'; /* default for Octal display */
5127 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5128 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5130 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5131 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5135 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5136 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5141 /* Merge the escape-glyph face into the current face. */
5142 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5146 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5147 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5149 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5151 XSETINT (it
->ctl_chars
[1], g
);
5153 goto display_control
;
5157 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5161 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5162 if (SINGLE_BYTE_CHAR_P (it
->c
))
5163 str
[0] = it
->c
, len
= 1;
5166 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5169 /* It's an invalid character, which shouldn't
5170 happen actually, but due to bugs it may
5171 happen. Let's print the char as is, there's
5172 not much meaningful we can do with it. */
5174 str
[1] = it
->c
>> 8;
5175 str
[2] = it
->c
>> 16;
5176 str
[3] = it
->c
>> 24;
5181 for (i
= 0; i
< len
; i
++)
5183 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5184 /* Insert three more glyphs into IT->ctl_chars for
5185 the octal display of the character. */
5186 g
= ((str
[i
] >> 6) & 7) + '0';
5187 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5188 g
= ((str
[i
] >> 3) & 7) + '0';
5189 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5190 g
= (str
[i
] & 7) + '0';
5191 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5197 /* Set up IT->dpvec and return first character from it. */
5198 it
->dpvec_char_len
= it
->len
;
5199 it
->dpvec
= it
->ctl_chars
;
5200 it
->dpend
= it
->dpvec
+ ctl_len
;
5201 it
->current
.dpvec_index
= 0;
5202 it
->dpvec_face_id
= face_id
;
5203 it
->saved_face_id
= it
->face_id
;
5204 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5210 /* Adjust face id for a multibyte character. There are no
5211 multibyte character in unibyte text. */
5214 && FRAME_WINDOW_P (it
->f
))
5216 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5217 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5221 /* Is this character the last one of a run of characters with
5222 box? If yes, set IT->end_of_box_run_p to 1. */
5229 it
->end_of_box_run_p
5230 = ((face_id
= face_after_it_pos (it
),
5231 face_id
!= it
->face_id
)
5232 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5233 face
->box
== FACE_NO_BOX
));
5236 /* Value is 0 if end of buffer or string reached. */
5241 /* Move IT to the next display element.
5243 RESEAT_P non-zero means if called on a newline in buffer text,
5244 skip to the next visible line start.
5246 Functions get_next_display_element and set_iterator_to_next are
5247 separate because I find this arrangement easier to handle than a
5248 get_next_display_element function that also increments IT's
5249 position. The way it is we can first look at an iterator's current
5250 display element, decide whether it fits on a line, and if it does,
5251 increment the iterator position. The other way around we probably
5252 would either need a flag indicating whether the iterator has to be
5253 incremented the next time, or we would have to implement a
5254 decrement position function which would not be easy to write. */
5257 set_iterator_to_next (it
, reseat_p
)
5261 /* Reset flags indicating start and end of a sequence of characters
5262 with box. Reset them at the start of this function because
5263 moving the iterator to a new position might set them. */
5264 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5268 case GET_FROM_BUFFER
:
5269 /* The current display element of IT is a character from
5270 current_buffer. Advance in the buffer, and maybe skip over
5271 invisible lines that are so because of selective display. */
5272 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5273 reseat_at_next_visible_line_start (it
, 0);
5276 xassert (it
->len
!= 0);
5277 IT_BYTEPOS (*it
) += it
->len
;
5278 IT_CHARPOS (*it
) += 1;
5279 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5283 case GET_FROM_COMPOSITION
:
5284 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5285 if (STRINGP (it
->string
))
5287 IT_STRING_BYTEPOS (*it
) += it
->len
;
5288 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5289 it
->method
= GET_FROM_STRING
;
5290 goto consider_string_end
;
5294 IT_BYTEPOS (*it
) += it
->len
;
5295 IT_CHARPOS (*it
) += it
->cmp_len
;
5296 it
->method
= GET_FROM_BUFFER
;
5300 case GET_FROM_C_STRING
:
5301 /* Current display element of IT is from a C string. */
5302 IT_BYTEPOS (*it
) += it
->len
;
5303 IT_CHARPOS (*it
) += 1;
5306 case GET_FROM_DISPLAY_VECTOR
:
5307 /* Current display element of IT is from a display table entry.
5308 Advance in the display table definition. Reset it to null if
5309 end reached, and continue with characters from buffers/
5311 ++it
->current
.dpvec_index
;
5313 /* Restore face of the iterator to what they were before the
5314 display vector entry (these entries may contain faces). */
5315 it
->face_id
= it
->saved_face_id
;
5317 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5320 it
->method
= GET_FROM_C_STRING
;
5321 else if (STRINGP (it
->string
))
5322 it
->method
= GET_FROM_STRING
;
5324 it
->method
= GET_FROM_BUFFER
;
5327 it
->current
.dpvec_index
= -1;
5329 /* Skip over characters which were displayed via IT->dpvec. */
5330 if (it
->dpvec_char_len
< 0)
5331 reseat_at_next_visible_line_start (it
, 1);
5332 else if (it
->dpvec_char_len
> 0)
5334 it
->len
= it
->dpvec_char_len
;
5335 set_iterator_to_next (it
, reseat_p
);
5338 /* Recheck faces after display vector */
5339 it
->stop_charpos
= IT_CHARPOS (*it
);
5343 case GET_FROM_STRING
:
5344 /* Current display element is a character from a Lisp string. */
5345 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5346 IT_STRING_BYTEPOS (*it
) += it
->len
;
5347 IT_STRING_CHARPOS (*it
) += 1;
5349 consider_string_end
:
5351 if (it
->current
.overlay_string_index
>= 0)
5353 /* IT->string is an overlay string. Advance to the
5354 next, if there is one. */
5355 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5356 next_overlay_string (it
);
5360 /* IT->string is not an overlay string. If we reached
5361 its end, and there is something on IT->stack, proceed
5362 with what is on the stack. This can be either another
5363 string, this time an overlay string, or a buffer. */
5364 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5368 if (STRINGP (it
->string
))
5369 goto consider_string_end
;
5370 it
->method
= GET_FROM_BUFFER
;
5375 case GET_FROM_IMAGE
:
5376 case GET_FROM_STRETCH
:
5377 /* The position etc with which we have to proceed are on
5378 the stack. The position may be at the end of a string,
5379 if the `display' property takes up the whole string. */
5380 xassert (it
->sp
> 0);
5383 if (STRINGP (it
->string
))
5385 it
->method
= GET_FROM_STRING
;
5386 goto consider_string_end
;
5388 it
->method
= GET_FROM_BUFFER
;
5392 /* There are no other methods defined, so this should be a bug. */
5396 xassert (it
->method
!= GET_FROM_STRING
5397 || (STRINGP (it
->string
)
5398 && IT_STRING_CHARPOS (*it
) >= 0));
5401 /* Load IT's display element fields with information about the next
5402 display element which comes from a display table entry or from the
5403 result of translating a control character to one of the forms `^C'
5406 IT->dpvec holds the glyphs to return as characters.
5407 IT->saved_face_id holds the face id before the display vector--
5408 it is restored into IT->face_idin set_iterator_to_next. */
5411 next_element_from_display_vector (it
)
5415 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5417 if (INTEGERP (*it
->dpvec
)
5418 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5422 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5423 it
->c
= FAST_GLYPH_CHAR (g
);
5424 it
->len
= CHAR_BYTES (it
->c
);
5426 /* The entry may contain a face id to use. Such a face id is
5427 the id of a Lisp face, not a realized face. A face id of
5428 zero means no face is specified. */
5429 if (it
->dpvec_face_id
>= 0)
5430 it
->face_id
= it
->dpvec_face_id
;
5433 int lface_id
= FAST_GLYPH_FACE (g
);
5435 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5440 /* Display table entry is invalid. Return a space. */
5441 it
->c
= ' ', it
->len
= 1;
5443 /* Don't change position and object of the iterator here. They are
5444 still the values of the character that had this display table
5445 entry or was translated, and that's what we want. */
5446 it
->what
= IT_CHARACTER
;
5451 /* Load IT with the next display element from Lisp string IT->string.
5452 IT->current.string_pos is the current position within the string.
5453 If IT->current.overlay_string_index >= 0, the Lisp string is an
5457 next_element_from_string (it
)
5460 struct text_pos position
;
5462 xassert (STRINGP (it
->string
));
5463 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5464 position
= it
->current
.string_pos
;
5466 /* Time to check for invisible text? */
5467 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5468 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5472 /* Since a handler may have changed IT->method, we must
5474 return get_next_display_element (it
);
5477 if (it
->current
.overlay_string_index
>= 0)
5479 /* Get the next character from an overlay string. In overlay
5480 strings, There is no field width or padding with spaces to
5482 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5487 else if (STRING_MULTIBYTE (it
->string
))
5489 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5490 const unsigned char *s
= (SDATA (it
->string
)
5491 + IT_STRING_BYTEPOS (*it
));
5492 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5496 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5502 /* Get the next character from a Lisp string that is not an
5503 overlay string. Such strings come from the mode line, for
5504 example. We may have to pad with spaces, or truncate the
5505 string. See also next_element_from_c_string. */
5506 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5511 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5513 /* Pad with spaces. */
5514 it
->c
= ' ', it
->len
= 1;
5515 CHARPOS (position
) = BYTEPOS (position
) = -1;
5517 else if (STRING_MULTIBYTE (it
->string
))
5519 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5520 const unsigned char *s
= (SDATA (it
->string
)
5521 + IT_STRING_BYTEPOS (*it
));
5522 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5526 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5531 /* Record what we have and where it came from. Note that we store a
5532 buffer position in IT->position although it could arguably be a
5534 it
->what
= IT_CHARACTER
;
5535 it
->object
= it
->string
;
5536 it
->position
= position
;
5541 /* Load IT with next display element from C string IT->s.
5542 IT->string_nchars is the maximum number of characters to return
5543 from the string. IT->end_charpos may be greater than
5544 IT->string_nchars when this function is called, in which case we
5545 may have to return padding spaces. Value is zero if end of string
5546 reached, including padding spaces. */
5549 next_element_from_c_string (it
)
5555 it
->what
= IT_CHARACTER
;
5556 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5559 /* IT's position can be greater IT->string_nchars in case a field
5560 width or precision has been specified when the iterator was
5562 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5564 /* End of the game. */
5568 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5570 /* Pad with spaces. */
5571 it
->c
= ' ', it
->len
= 1;
5572 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5574 else if (it
->multibyte_p
)
5576 /* Implementation note: The calls to strlen apparently aren't a
5577 performance problem because there is no noticeable performance
5578 difference between Emacs running in unibyte or multibyte mode. */
5579 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5580 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5584 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5590 /* Set up IT to return characters from an ellipsis, if appropriate.
5591 The definition of the ellipsis glyphs may come from a display table
5592 entry. This function Fills IT with the first glyph from the
5593 ellipsis if an ellipsis is to be displayed. */
5596 next_element_from_ellipsis (it
)
5599 if (it
->selective_display_ellipsis_p
)
5600 setup_for_ellipsis (it
, it
->len
);
5603 /* The face at the current position may be different from the
5604 face we find after the invisible text. Remember what it
5605 was in IT->saved_face_id, and signal that it's there by
5606 setting face_before_selective_p. */
5607 it
->saved_face_id
= it
->face_id
;
5608 it
->method
= GET_FROM_BUFFER
;
5609 reseat_at_next_visible_line_start (it
, 1);
5610 it
->face_before_selective_p
= 1;
5613 return get_next_display_element (it
);
5617 /* Deliver an image display element. The iterator IT is already
5618 filled with image information (done in handle_display_prop). Value
5623 next_element_from_image (it
)
5626 it
->what
= IT_IMAGE
;
5631 /* Fill iterator IT with next display element from a stretch glyph
5632 property. IT->object is the value of the text property. Value is
5636 next_element_from_stretch (it
)
5639 it
->what
= IT_STRETCH
;
5644 /* Load IT with the next display element from current_buffer. Value
5645 is zero if end of buffer reached. IT->stop_charpos is the next
5646 position at which to stop and check for text properties or buffer
5650 next_element_from_buffer (it
)
5655 /* Check this assumption, otherwise, we would never enter the
5656 if-statement, below. */
5657 xassert (IT_CHARPOS (*it
) >= BEGV
5658 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5660 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5662 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5664 int overlay_strings_follow_p
;
5666 /* End of the game, except when overlay strings follow that
5667 haven't been returned yet. */
5668 if (it
->overlay_strings_at_end_processed_p
)
5669 overlay_strings_follow_p
= 0;
5672 it
->overlay_strings_at_end_processed_p
= 1;
5673 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5676 if (overlay_strings_follow_p
)
5677 success_p
= get_next_display_element (it
);
5681 it
->position
= it
->current
.pos
;
5688 return get_next_display_element (it
);
5693 /* No face changes, overlays etc. in sight, so just return a
5694 character from current_buffer. */
5697 /* Maybe run the redisplay end trigger hook. Performance note:
5698 This doesn't seem to cost measurable time. */
5699 if (it
->redisplay_end_trigger_charpos
5701 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5702 run_redisplay_end_trigger_hook (it
);
5704 /* Get the next character, maybe multibyte. */
5705 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5706 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5708 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5709 - IT_BYTEPOS (*it
));
5710 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5713 it
->c
= *p
, it
->len
= 1;
5715 /* Record what we have and where it came from. */
5716 it
->what
= IT_CHARACTER
;;
5717 it
->object
= it
->w
->buffer
;
5718 it
->position
= it
->current
.pos
;
5720 /* Normally we return the character found above, except when we
5721 really want to return an ellipsis for selective display. */
5726 /* A value of selective > 0 means hide lines indented more
5727 than that number of columns. */
5728 if (it
->selective
> 0
5729 && IT_CHARPOS (*it
) + 1 < ZV
5730 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5731 IT_BYTEPOS (*it
) + 1,
5732 (double) it
->selective
)) /* iftc */
5734 success_p
= next_element_from_ellipsis (it
);
5735 it
->dpvec_char_len
= -1;
5738 else if (it
->c
== '\r' && it
->selective
== -1)
5740 /* A value of selective == -1 means that everything from the
5741 CR to the end of the line is invisible, with maybe an
5742 ellipsis displayed for it. */
5743 success_p
= next_element_from_ellipsis (it
);
5744 it
->dpvec_char_len
= -1;
5749 /* Value is zero if end of buffer reached. */
5750 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5755 /* Run the redisplay end trigger hook for IT. */
5758 run_redisplay_end_trigger_hook (it
)
5761 Lisp_Object args
[3];
5763 /* IT->glyph_row should be non-null, i.e. we should be actually
5764 displaying something, or otherwise we should not run the hook. */
5765 xassert (it
->glyph_row
);
5767 /* Set up hook arguments. */
5768 args
[0] = Qredisplay_end_trigger_functions
;
5769 args
[1] = it
->window
;
5770 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5771 it
->redisplay_end_trigger_charpos
= 0;
5773 /* Since we are *trying* to run these functions, don't try to run
5774 them again, even if they get an error. */
5775 it
->w
->redisplay_end_trigger
= Qnil
;
5776 Frun_hook_with_args (3, args
);
5778 /* Notice if it changed the face of the character we are on. */
5779 handle_face_prop (it
);
5783 /* Deliver a composition display element. The iterator IT is already
5784 filled with composition information (done in
5785 handle_composition_prop). Value is always 1. */
5788 next_element_from_composition (it
)
5791 it
->what
= IT_COMPOSITION
;
5792 it
->position
= (STRINGP (it
->string
)
5793 ? it
->current
.string_pos
5800 /***********************************************************************
5801 Moving an iterator without producing glyphs
5802 ***********************************************************************/
5804 /* Move iterator IT to a specified buffer or X position within one
5805 line on the display without producing glyphs.
5807 OP should be a bit mask including some or all of these bits:
5808 MOVE_TO_X: Stop on reaching x-position TO_X.
5809 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5810 Regardless of OP's value, stop in reaching the end of the display line.
5812 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5813 This means, in particular, that TO_X includes window's horizontal
5816 The return value has several possible values that
5817 say what condition caused the scan to stop:
5819 MOVE_POS_MATCH_OR_ZV
5820 - when TO_POS or ZV was reached.
5823 -when TO_X was reached before TO_POS or ZV were reached.
5826 - when we reached the end of the display area and the line must
5830 - when we reached the end of the display area and the line is
5834 - when we stopped at a line end, i.e. a newline or a CR and selective
5837 static enum move_it_result
5838 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5840 int to_charpos
, to_x
, op
;
5842 enum move_it_result result
= MOVE_UNDEFINED
;
5843 struct glyph_row
*saved_glyph_row
;
5845 /* Don't produce glyphs in produce_glyphs. */
5846 saved_glyph_row
= it
->glyph_row
;
5847 it
->glyph_row
= NULL
;
5849 #define BUFFER_POS_REACHED_P() \
5850 ((op & MOVE_TO_POS) != 0 \
5851 && BUFFERP (it->object) \
5852 && IT_CHARPOS (*it) >= to_charpos \
5853 && (it->method == GET_FROM_BUFFER \
5854 || (it->method == GET_FROM_DISPLAY_VECTOR \
5855 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
5860 int x
, i
, ascent
= 0, descent
= 0;
5862 /* Stop when ZV reached.
5863 We used to stop here when TO_CHARPOS reached as well, but that is
5864 too soon if this glyph does not fit on this line. So we handle it
5865 explicitly below. */
5866 if (!get_next_display_element (it
)
5867 || (it
->truncate_lines_p
5868 && BUFFER_POS_REACHED_P ()))
5870 result
= MOVE_POS_MATCH_OR_ZV
;
5874 /* The call to produce_glyphs will get the metrics of the
5875 display element IT is loaded with. We record in x the
5876 x-position before this display element in case it does not
5880 /* Remember the line height so far in case the next element doesn't
5882 if (!it
->truncate_lines_p
)
5884 ascent
= it
->max_ascent
;
5885 descent
= it
->max_descent
;
5888 PRODUCE_GLYPHS (it
);
5890 if (it
->area
!= TEXT_AREA
)
5892 set_iterator_to_next (it
, 1);
5896 /* The number of glyphs we get back in IT->nglyphs will normally
5897 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5898 character on a terminal frame, or (iii) a line end. For the
5899 second case, IT->nglyphs - 1 padding glyphs will be present
5900 (on X frames, there is only one glyph produced for a
5901 composite character.
5903 The behavior implemented below means, for continuation lines,
5904 that as many spaces of a TAB as fit on the current line are
5905 displayed there. For terminal frames, as many glyphs of a
5906 multi-glyph character are displayed in the current line, too.
5907 This is what the old redisplay code did, and we keep it that
5908 way. Under X, the whole shape of a complex character must
5909 fit on the line or it will be completely displayed in the
5912 Note that both for tabs and padding glyphs, all glyphs have
5916 /* More than one glyph or glyph doesn't fit on line. All
5917 glyphs have the same width. */
5918 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5921 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5923 new_x
= x
+ single_glyph_width
;
5925 /* We want to leave anything reaching TO_X to the caller. */
5926 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5928 if (BUFFER_POS_REACHED_P ())
5929 goto buffer_pos_reached
;
5931 result
= MOVE_X_REACHED
;
5934 else if (/* Lines are continued. */
5935 !it
->truncate_lines_p
5936 && (/* And glyph doesn't fit on the line. */
5937 new_x
> it
->last_visible_x
5938 /* Or it fits exactly and we're on a window
5940 || (new_x
== it
->last_visible_x
5941 && FRAME_WINDOW_P (it
->f
))))
5943 if (/* IT->hpos == 0 means the very first glyph
5944 doesn't fit on the line, e.g. a wide image. */
5946 || (new_x
== it
->last_visible_x
5947 && FRAME_WINDOW_P (it
->f
)))
5950 it
->current_x
= new_x
;
5951 if (i
== it
->nglyphs
- 1)
5953 set_iterator_to_next (it
, 1);
5954 #ifdef HAVE_WINDOW_SYSTEM
5955 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5957 if (!get_next_display_element (it
))
5959 result
= MOVE_POS_MATCH_OR_ZV
;
5962 if (BUFFER_POS_REACHED_P ())
5964 if (ITERATOR_AT_END_OF_LINE_P (it
))
5965 result
= MOVE_POS_MATCH_OR_ZV
;
5967 result
= MOVE_LINE_CONTINUED
;
5970 if (ITERATOR_AT_END_OF_LINE_P (it
))
5972 result
= MOVE_NEWLINE_OR_CR
;
5976 #endif /* HAVE_WINDOW_SYSTEM */
5982 it
->max_ascent
= ascent
;
5983 it
->max_descent
= descent
;
5986 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5988 result
= MOVE_LINE_CONTINUED
;
5991 else if (BUFFER_POS_REACHED_P ())
5992 goto buffer_pos_reached
;
5993 else if (new_x
> it
->first_visible_x
)
5995 /* Glyph is visible. Increment number of glyphs that
5996 would be displayed. */
6001 /* Glyph is completely off the left margin of the display
6002 area. Nothing to do. */
6006 if (result
!= MOVE_UNDEFINED
)
6009 else if (BUFFER_POS_REACHED_P ())
6013 it
->max_ascent
= ascent
;
6014 it
->max_descent
= descent
;
6015 result
= MOVE_POS_MATCH_OR_ZV
;
6018 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6020 /* Stop when TO_X specified and reached. This check is
6021 necessary here because of lines consisting of a line end,
6022 only. The line end will not produce any glyphs and we
6023 would never get MOVE_X_REACHED. */
6024 xassert (it
->nglyphs
== 0);
6025 result
= MOVE_X_REACHED
;
6029 /* Is this a line end? If yes, we're done. */
6030 if (ITERATOR_AT_END_OF_LINE_P (it
))
6032 result
= MOVE_NEWLINE_OR_CR
;
6036 /* The current display element has been consumed. Advance
6038 set_iterator_to_next (it
, 1);
6040 /* Stop if lines are truncated and IT's current x-position is
6041 past the right edge of the window now. */
6042 if (it
->truncate_lines_p
6043 && it
->current_x
>= it
->last_visible_x
)
6045 #ifdef HAVE_WINDOW_SYSTEM
6046 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6048 if (!get_next_display_element (it
)
6049 || BUFFER_POS_REACHED_P ())
6051 result
= MOVE_POS_MATCH_OR_ZV
;
6054 if (ITERATOR_AT_END_OF_LINE_P (it
))
6056 result
= MOVE_NEWLINE_OR_CR
;
6060 #endif /* HAVE_WINDOW_SYSTEM */
6061 result
= MOVE_LINE_TRUNCATED
;
6066 #undef BUFFER_POS_REACHED_P
6068 /* Restore the iterator settings altered at the beginning of this
6070 it
->glyph_row
= saved_glyph_row
;
6075 /* Move IT forward until it satisfies one or more of the criteria in
6076 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6078 OP is a bit-mask that specifies where to stop, and in particular,
6079 which of those four position arguments makes a difference. See the
6080 description of enum move_operation_enum.
6082 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6083 screen line, this function will set IT to the next position >
6087 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6089 int to_charpos
, to_x
, to_y
, to_vpos
;
6092 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6098 if (op
& MOVE_TO_VPOS
)
6100 /* If no TO_CHARPOS and no TO_X specified, stop at the
6101 start of the line TO_VPOS. */
6102 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6104 if (it
->vpos
== to_vpos
)
6110 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6114 /* TO_VPOS >= 0 means stop at TO_X in the line at
6115 TO_VPOS, or at TO_POS, whichever comes first. */
6116 if (it
->vpos
== to_vpos
)
6122 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6124 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6129 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6131 /* We have reached TO_X but not in the line we want. */
6132 skip
= move_it_in_display_line_to (it
, to_charpos
,
6134 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6142 else if (op
& MOVE_TO_Y
)
6144 struct it it_backup
;
6146 /* TO_Y specified means stop at TO_X in the line containing
6147 TO_Y---or at TO_CHARPOS if this is reached first. The
6148 problem is that we can't really tell whether the line
6149 contains TO_Y before we have completely scanned it, and
6150 this may skip past TO_X. What we do is to first scan to
6153 If TO_X is not specified, use a TO_X of zero. The reason
6154 is to make the outcome of this function more predictable.
6155 If we didn't use TO_X == 0, we would stop at the end of
6156 the line which is probably not what a caller would expect
6158 skip
= move_it_in_display_line_to (it
, to_charpos
,
6162 | (op
& MOVE_TO_POS
)));
6164 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6165 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6171 /* If TO_X was reached, we would like to know whether TO_Y
6172 is in the line. This can only be said if we know the
6173 total line height which requires us to scan the rest of
6175 if (skip
== MOVE_X_REACHED
)
6178 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6179 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6181 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6184 /* Now, decide whether TO_Y is in this line. */
6185 line_height
= it
->max_ascent
+ it
->max_descent
;
6186 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6188 if (to_y
>= it
->current_y
6189 && to_y
< it
->current_y
+ line_height
)
6191 if (skip
== MOVE_X_REACHED
)
6192 /* If TO_Y is in this line and TO_X was reached above,
6193 we scanned too far. We have to restore IT's settings
6194 to the ones before skipping. */
6198 else if (skip
== MOVE_X_REACHED
)
6201 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6209 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6213 case MOVE_POS_MATCH_OR_ZV
:
6217 case MOVE_NEWLINE_OR_CR
:
6218 set_iterator_to_next (it
, 1);
6219 it
->continuation_lines_width
= 0;
6222 case MOVE_LINE_TRUNCATED
:
6223 it
->continuation_lines_width
= 0;
6224 reseat_at_next_visible_line_start (it
, 0);
6225 if ((op
& MOVE_TO_POS
) != 0
6226 && IT_CHARPOS (*it
) > to_charpos
)
6233 case MOVE_LINE_CONTINUED
:
6234 it
->continuation_lines_width
+= it
->current_x
;
6241 /* Reset/increment for the next run. */
6242 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6243 it
->current_x
= it
->hpos
= 0;
6244 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6246 last_height
= it
->max_ascent
+ it
->max_descent
;
6247 last_max_ascent
= it
->max_ascent
;
6248 it
->max_ascent
= it
->max_descent
= 0;
6253 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6257 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6259 If DY > 0, move IT backward at least that many pixels. DY = 0
6260 means move IT backward to the preceding line start or BEGV. This
6261 function may move over more than DY pixels if IT->current_y - DY
6262 ends up in the middle of a line; in this case IT->current_y will be
6263 set to the top of the line moved to. */
6266 move_it_vertically_backward (it
, dy
)
6277 start_pos
= IT_CHARPOS (*it
);
6279 /* Estimate how many newlines we must move back. */
6280 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6282 /* Set the iterator's position that many lines back. */
6283 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6284 back_to_previous_visible_line_start (it
);
6286 /* Reseat the iterator here. When moving backward, we don't want
6287 reseat to skip forward over invisible text, set up the iterator
6288 to deliver from overlay strings at the new position etc. So,
6289 use reseat_1 here. */
6290 reseat_1 (it
, it
->current
.pos
, 1);
6292 /* We are now surely at a line start. */
6293 it
->current_x
= it
->hpos
= 0;
6294 it
->continuation_lines_width
= 0;
6296 /* Move forward and see what y-distance we moved. First move to the
6297 start of the next line so that we get its height. We need this
6298 height to be able to tell whether we reached the specified
6301 it2
.max_ascent
= it2
.max_descent
= 0;
6302 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6303 MOVE_TO_POS
| MOVE_TO_VPOS
);
6304 xassert (IT_CHARPOS (*it
) >= BEGV
);
6307 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6308 xassert (IT_CHARPOS (*it
) >= BEGV
);
6309 /* H is the actual vertical distance from the position in *IT
6310 and the starting position. */
6311 h
= it2
.current_y
- it
->current_y
;
6312 /* NLINES is the distance in number of lines. */
6313 nlines
= it2
.vpos
- it
->vpos
;
6315 /* Correct IT's y and vpos position
6316 so that they are relative to the starting point. */
6322 /* DY == 0 means move to the start of the screen line. The
6323 value of nlines is > 0 if continuation lines were involved. */
6325 move_it_by_lines (it
, nlines
, 1);
6327 /* I think this assert is bogus if buffer contains
6328 invisible text or images. KFS. */
6329 xassert (IT_CHARPOS (*it
) <= start_pos
);
6334 /* The y-position we try to reach, relative to *IT.
6335 Note that H has been subtracted in front of the if-statement. */
6336 int target_y
= it
->current_y
+ h
- dy
;
6337 int y0
= it3
.current_y
;
6338 int y1
= line_bottom_y (&it3
);
6339 int line_height
= y1
- y0
;
6341 /* If we did not reach target_y, try to move further backward if
6342 we can. If we moved too far backward, try to move forward. */
6343 if (target_y
< it
->current_y
6344 /* This is heuristic. In a window that's 3 lines high, with
6345 a line height of 13 pixels each, recentering with point
6346 on the bottom line will try to move -39/2 = 19 pixels
6347 backward. Try to avoid moving into the first line. */
6348 && (it
->current_y
- target_y
6349 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6350 && IT_CHARPOS (*it
) > BEGV
)
6352 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6353 target_y
- it
->current_y
));
6354 dy
= it
->current_y
- target_y
;
6355 goto move_further_back
;
6357 else if (target_y
>= it
->current_y
+ line_height
6358 && IT_CHARPOS (*it
) < ZV
)
6360 /* Should move forward by at least one line, maybe more.
6362 Note: Calling move_it_by_lines can be expensive on
6363 terminal frames, where compute_motion is used (via
6364 vmotion) to do the job, when there are very long lines
6365 and truncate-lines is nil. That's the reason for
6366 treating terminal frames specially here. */
6368 if (!FRAME_WINDOW_P (it
->f
))
6369 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6374 move_it_by_lines (it
, 1, 1);
6376 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6380 /* I think this assert is bogus if buffer contains
6381 invisible text or images. KFS. */
6382 xassert (IT_CHARPOS (*it
) >= BEGV
);
6389 /* Move IT by a specified amount of pixel lines DY. DY negative means
6390 move backwards. DY = 0 means move to start of screen line. At the
6391 end, IT will be on the start of a screen line. */
6394 move_it_vertically (it
, dy
)
6399 move_it_vertically_backward (it
, -dy
);
6402 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6403 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6404 MOVE_TO_POS
| MOVE_TO_Y
);
6405 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6407 /* If buffer ends in ZV without a newline, move to the start of
6408 the line to satisfy the post-condition. */
6409 if (IT_CHARPOS (*it
) == ZV
6410 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6411 move_it_by_lines (it
, 0, 0);
6416 /* Move iterator IT past the end of the text line it is in. */
6419 move_it_past_eol (it
)
6422 enum move_it_result rc
;
6424 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6425 if (rc
== MOVE_NEWLINE_OR_CR
)
6426 set_iterator_to_next (it
, 0);
6430 #if 0 /* Currently not used. */
6432 /* Return non-zero if some text between buffer positions START_CHARPOS
6433 and END_CHARPOS is invisible. IT->window is the window for text
6437 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6439 int start_charpos
, end_charpos
;
6441 Lisp_Object prop
, limit
;
6442 int invisible_found_p
;
6444 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6446 /* Is text at START invisible? */
6447 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6449 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6450 invisible_found_p
= 1;
6453 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6455 make_number (end_charpos
));
6456 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6459 return invisible_found_p
;
6465 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6466 negative means move up. DVPOS == 0 means move to the start of the
6467 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6468 NEED_Y_P is zero, IT->current_y will be left unchanged.
6470 Further optimization ideas: If we would know that IT->f doesn't use
6471 a face with proportional font, we could be faster for
6472 truncate-lines nil. */
6475 move_it_by_lines (it
, dvpos
, need_y_p
)
6477 int dvpos
, need_y_p
;
6479 struct position pos
;
6481 if (!FRAME_WINDOW_P (it
->f
))
6483 struct text_pos textpos
;
6485 /* We can use vmotion on frames without proportional fonts. */
6486 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6487 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6488 reseat (it
, textpos
, 1);
6489 it
->vpos
+= pos
.vpos
;
6490 it
->current_y
+= pos
.vpos
;
6492 else if (dvpos
== 0)
6494 /* DVPOS == 0 means move to the start of the screen line. */
6495 move_it_vertically_backward (it
, 0);
6496 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6497 /* Let next call to line_bottom_y calculate real line height */
6501 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6505 int start_charpos
, i
;
6507 /* Start at the beginning of the screen line containing IT's
6509 move_it_vertically_backward (it
, 0);
6511 /* Go back -DVPOS visible lines and reseat the iterator there. */
6512 start_charpos
= IT_CHARPOS (*it
);
6513 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6514 back_to_previous_visible_line_start (it
);
6515 reseat (it
, it
->current
.pos
, 1);
6516 it
->current_x
= it
->hpos
= 0;
6518 /* Above call may have moved too far if continuation lines
6519 are involved. Scan forward and see if it did. */
6521 it2
.vpos
= it2
.current_y
= 0;
6522 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6523 it
->vpos
-= it2
.vpos
;
6524 it
->current_y
-= it2
.current_y
;
6525 it
->current_x
= it
->hpos
= 0;
6527 /* If we moved too far back, move IT some lines forward. */
6528 if (it2
.vpos
> -dvpos
)
6530 int delta
= it2
.vpos
+ dvpos
;
6532 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6533 /* Move back again if we got too far ahead. */
6534 if (IT_CHARPOS (*it
) >= start_charpos
)
6540 /* Return 1 if IT points into the middle of a display vector. */
6543 in_display_vector_p (it
)
6546 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6547 && it
->current
.dpvec_index
> 0
6548 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6552 /***********************************************************************
6554 ***********************************************************************/
6557 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6561 add_to_log (format
, arg1
, arg2
)
6563 Lisp_Object arg1
, arg2
;
6565 Lisp_Object args
[3];
6566 Lisp_Object msg
, fmt
;
6569 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6572 /* Do nothing if called asynchronously. Inserting text into
6573 a buffer may call after-change-functions and alike and
6574 that would means running Lisp asynchronously. */
6575 if (handling_signal
)
6579 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6581 args
[0] = fmt
= build_string (format
);
6584 msg
= Fformat (3, args
);
6586 len
= SBYTES (msg
) + 1;
6587 SAFE_ALLOCA (buffer
, char *, len
);
6588 bcopy (SDATA (msg
), buffer
, len
);
6590 message_dolog (buffer
, len
- 1, 1, 0);
6597 /* Output a newline in the *Messages* buffer if "needs" one. */
6600 message_log_maybe_newline ()
6602 if (message_log_need_newline
)
6603 message_dolog ("", 0, 1, 0);
6607 /* Add a string M of length NBYTES to the message log, optionally
6608 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6609 nonzero, means interpret the contents of M as multibyte. This
6610 function calls low-level routines in order to bypass text property
6611 hooks, etc. which might not be safe to run. */
6614 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6616 int nbytes
, nlflag
, multibyte
;
6618 if (!NILP (Vmemory_full
))
6621 if (!NILP (Vmessage_log_max
))
6623 struct buffer
*oldbuf
;
6624 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6625 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6626 int point_at_end
= 0;
6628 Lisp_Object old_deactivate_mark
, tem
;
6629 struct gcpro gcpro1
;
6631 old_deactivate_mark
= Vdeactivate_mark
;
6632 oldbuf
= current_buffer
;
6633 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6634 current_buffer
->undo_list
= Qt
;
6636 oldpoint
= message_dolog_marker1
;
6637 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6638 oldbegv
= message_dolog_marker2
;
6639 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6640 oldzv
= message_dolog_marker3
;
6641 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6642 GCPRO1 (old_deactivate_mark
);
6650 BEGV_BYTE
= BEG_BYTE
;
6653 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6655 /* Insert the string--maybe converting multibyte to single byte
6656 or vice versa, so that all the text fits the buffer. */
6658 && NILP (current_buffer
->enable_multibyte_characters
))
6660 int i
, c
, char_bytes
;
6661 unsigned char work
[1];
6663 /* Convert a multibyte string to single-byte
6664 for the *Message* buffer. */
6665 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6667 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6668 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6670 : multibyte_char_to_unibyte (c
, Qnil
));
6671 insert_1_both (work
, 1, 1, 1, 0, 0);
6674 else if (! multibyte
6675 && ! NILP (current_buffer
->enable_multibyte_characters
))
6677 int i
, c
, char_bytes
;
6678 unsigned char *msg
= (unsigned char *) m
;
6679 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6680 /* Convert a single-byte string to multibyte
6681 for the *Message* buffer. */
6682 for (i
= 0; i
< nbytes
; i
++)
6684 c
= unibyte_char_to_multibyte (msg
[i
]);
6685 char_bytes
= CHAR_STRING (c
, str
);
6686 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6690 insert_1 (m
, nbytes
, 1, 0, 0);
6694 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6695 insert_1 ("\n", 1, 1, 0, 0);
6697 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6699 this_bol_byte
= PT_BYTE
;
6701 /* See if this line duplicates the previous one.
6702 If so, combine duplicates. */
6705 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6707 prev_bol_byte
= PT_BYTE
;
6709 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6710 this_bol
, this_bol_byte
);
6713 del_range_both (prev_bol
, prev_bol_byte
,
6714 this_bol
, this_bol_byte
, 0);
6720 /* If you change this format, don't forget to also
6721 change message_log_check_duplicate. */
6722 sprintf (dupstr
, " [%d times]", dup
);
6723 duplen
= strlen (dupstr
);
6724 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6725 insert_1 (dupstr
, duplen
, 1, 0, 1);
6730 /* If we have more than the desired maximum number of lines
6731 in the *Messages* buffer now, delete the oldest ones.
6732 This is safe because we don't have undo in this buffer. */
6734 if (NATNUMP (Vmessage_log_max
))
6736 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6737 -XFASTINT (Vmessage_log_max
) - 1, 0);
6738 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6741 BEGV
= XMARKER (oldbegv
)->charpos
;
6742 BEGV_BYTE
= marker_byte_position (oldbegv
);
6751 ZV
= XMARKER (oldzv
)->charpos
;
6752 ZV_BYTE
= marker_byte_position (oldzv
);
6756 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6758 /* We can't do Fgoto_char (oldpoint) because it will run some
6760 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6761 XMARKER (oldpoint
)->bytepos
);
6764 unchain_marker (XMARKER (oldpoint
));
6765 unchain_marker (XMARKER (oldbegv
));
6766 unchain_marker (XMARKER (oldzv
));
6768 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6769 set_buffer_internal (oldbuf
);
6771 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6772 message_log_need_newline
= !nlflag
;
6773 Vdeactivate_mark
= old_deactivate_mark
;
6778 /* We are at the end of the buffer after just having inserted a newline.
6779 (Note: We depend on the fact we won't be crossing the gap.)
6780 Check to see if the most recent message looks a lot like the previous one.
6781 Return 0 if different, 1 if the new one should just replace it, or a
6782 value N > 1 if we should also append " [N times]". */
6785 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6786 int prev_bol
, this_bol
;
6787 int prev_bol_byte
, this_bol_byte
;
6790 int len
= Z_BYTE
- 1 - this_bol_byte
;
6792 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6793 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6795 for (i
= 0; i
< len
; i
++)
6797 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6805 if (*p1
++ == ' ' && *p1
++ == '[')
6808 while (*p1
>= '0' && *p1
<= '9')
6809 n
= n
* 10 + *p1
++ - '0';
6810 if (strncmp (p1
, " times]\n", 8) == 0)
6817 /* Display an echo area message M with a specified length of NBYTES
6818 bytes. The string may include null characters. If M is 0, clear
6819 out any existing message, and let the mini-buffer text show
6822 The buffer M must continue to exist until after the echo area gets
6823 cleared or some other message gets displayed there. This means do
6824 not pass text that is stored in a Lisp string; do not pass text in
6825 a buffer that was alloca'd. */
6828 message2 (m
, nbytes
, multibyte
)
6833 /* First flush out any partial line written with print. */
6834 message_log_maybe_newline ();
6836 message_dolog (m
, nbytes
, 1, multibyte
);
6837 message2_nolog (m
, nbytes
, multibyte
);
6841 /* The non-logging counterpart of message2. */
6844 message2_nolog (m
, nbytes
, multibyte
)
6846 int nbytes
, multibyte
;
6848 struct frame
*sf
= SELECTED_FRAME ();
6849 message_enable_multibyte
= multibyte
;
6853 if (noninteractive_need_newline
)
6854 putc ('\n', stderr
);
6855 noninteractive_need_newline
= 0;
6857 fwrite (m
, nbytes
, 1, stderr
);
6858 if (cursor_in_echo_area
== 0)
6859 fprintf (stderr
, "\n");
6862 /* A null message buffer means that the frame hasn't really been
6863 initialized yet. Error messages get reported properly by
6864 cmd_error, so this must be just an informative message; toss it. */
6865 else if (INTERACTIVE
6866 && sf
->glyphs_initialized_p
6867 && FRAME_MESSAGE_BUF (sf
))
6869 Lisp_Object mini_window
;
6872 /* Get the frame containing the mini-buffer
6873 that the selected frame is using. */
6874 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6875 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6877 FRAME_SAMPLE_VISIBILITY (f
);
6878 if (FRAME_VISIBLE_P (sf
)
6879 && ! FRAME_VISIBLE_P (f
))
6880 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6884 set_message (m
, Qnil
, nbytes
, multibyte
);
6885 if (minibuffer_auto_raise
)
6886 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6889 clear_message (1, 1);
6891 do_pending_window_change (0);
6892 echo_area_display (1);
6893 do_pending_window_change (0);
6894 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6895 (*frame_up_to_date_hook
) (f
);
6900 /* Display an echo area message M with a specified length of NBYTES
6901 bytes. The string may include null characters. If M is not a
6902 string, clear out any existing message, and let the mini-buffer
6903 text show through. */
6906 message3 (m
, nbytes
, multibyte
)
6911 struct gcpro gcpro1
;
6914 clear_message (1,1);
6916 /* First flush out any partial line written with print. */
6917 message_log_maybe_newline ();
6919 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6920 message3_nolog (m
, nbytes
, multibyte
);
6926 /* The non-logging version of message3. */
6929 message3_nolog (m
, nbytes
, multibyte
)
6931 int nbytes
, multibyte
;
6933 struct frame
*sf
= SELECTED_FRAME ();
6934 message_enable_multibyte
= multibyte
;
6938 if (noninteractive_need_newline
)
6939 putc ('\n', stderr
);
6940 noninteractive_need_newline
= 0;
6942 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6943 if (cursor_in_echo_area
== 0)
6944 fprintf (stderr
, "\n");
6947 /* A null message buffer means that the frame hasn't really been
6948 initialized yet. Error messages get reported properly by
6949 cmd_error, so this must be just an informative message; toss it. */
6950 else if (INTERACTIVE
6951 && sf
->glyphs_initialized_p
6952 && FRAME_MESSAGE_BUF (sf
))
6954 Lisp_Object mini_window
;
6958 /* Get the frame containing the mini-buffer
6959 that the selected frame is using. */
6960 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6961 frame
= XWINDOW (mini_window
)->frame
;
6964 FRAME_SAMPLE_VISIBILITY (f
);
6965 if (FRAME_VISIBLE_P (sf
)
6966 && !FRAME_VISIBLE_P (f
))
6967 Fmake_frame_visible (frame
);
6969 if (STRINGP (m
) && SCHARS (m
) > 0)
6971 set_message (NULL
, m
, nbytes
, multibyte
);
6972 if (minibuffer_auto_raise
)
6973 Fraise_frame (frame
);
6976 clear_message (1, 1);
6978 do_pending_window_change (0);
6979 echo_area_display (1);
6980 do_pending_window_change (0);
6981 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6982 (*frame_up_to_date_hook
) (f
);
6987 /* Display a null-terminated echo area message M. If M is 0, clear
6988 out any existing message, and let the mini-buffer text show through.
6990 The buffer M must continue to exist until after the echo area gets
6991 cleared or some other message gets displayed there. Do not pass
6992 text that is stored in a Lisp string. Do not pass text in a buffer
6993 that was alloca'd. */
6999 message2 (m
, (m
? strlen (m
) : 0), 0);
7003 /* The non-logging counterpart of message1. */
7009 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7012 /* Display a message M which contains a single %s
7013 which gets replaced with STRING. */
7016 message_with_string (m
, string
, log
)
7021 CHECK_STRING (string
);
7027 if (noninteractive_need_newline
)
7028 putc ('\n', stderr
);
7029 noninteractive_need_newline
= 0;
7030 fprintf (stderr
, m
, SDATA (string
));
7031 if (cursor_in_echo_area
== 0)
7032 fprintf (stderr
, "\n");
7036 else if (INTERACTIVE
)
7038 /* The frame whose minibuffer we're going to display the message on.
7039 It may be larger than the selected frame, so we need
7040 to use its buffer, not the selected frame's buffer. */
7041 Lisp_Object mini_window
;
7042 struct frame
*f
, *sf
= SELECTED_FRAME ();
7044 /* Get the frame containing the minibuffer
7045 that the selected frame is using. */
7046 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7047 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7049 /* A null message buffer means that the frame hasn't really been
7050 initialized yet. Error messages get reported properly by
7051 cmd_error, so this must be just an informative message; toss it. */
7052 if (FRAME_MESSAGE_BUF (f
))
7054 Lisp_Object args
[2], message
;
7055 struct gcpro gcpro1
, gcpro2
;
7057 args
[0] = build_string (m
);
7058 args
[1] = message
= string
;
7059 GCPRO2 (args
[0], message
);
7062 message
= Fformat (2, args
);
7065 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7067 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7071 /* Print should start at the beginning of the message
7072 buffer next time. */
7073 message_buf_print
= 0;
7079 /* Dump an informative message to the minibuf. If M is 0, clear out
7080 any existing message, and let the mini-buffer text show through. */
7084 message (m
, a1
, a2
, a3
)
7086 EMACS_INT a1
, a2
, a3
;
7092 if (noninteractive_need_newline
)
7093 putc ('\n', stderr
);
7094 noninteractive_need_newline
= 0;
7095 fprintf (stderr
, m
, a1
, a2
, a3
);
7096 if (cursor_in_echo_area
== 0)
7097 fprintf (stderr
, "\n");
7101 else if (INTERACTIVE
)
7103 /* The frame whose mini-buffer we're going to display the message
7104 on. It may be larger than the selected frame, so we need to
7105 use its buffer, not the selected frame's buffer. */
7106 Lisp_Object mini_window
;
7107 struct frame
*f
, *sf
= SELECTED_FRAME ();
7109 /* Get the frame containing the mini-buffer
7110 that the selected frame is using. */
7111 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7112 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7114 /* A null message buffer means that the frame hasn't really been
7115 initialized yet. Error messages get reported properly by
7116 cmd_error, so this must be just an informative message; toss
7118 if (FRAME_MESSAGE_BUF (f
))
7129 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7130 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7132 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7133 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7135 #endif /* NO_ARG_ARRAY */
7137 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7142 /* Print should start at the beginning of the message
7143 buffer next time. */
7144 message_buf_print
= 0;
7150 /* The non-logging version of message. */
7153 message_nolog (m
, a1
, a2
, a3
)
7155 EMACS_INT a1
, a2
, a3
;
7157 Lisp_Object old_log_max
;
7158 old_log_max
= Vmessage_log_max
;
7159 Vmessage_log_max
= Qnil
;
7160 message (m
, a1
, a2
, a3
);
7161 Vmessage_log_max
= old_log_max
;
7165 /* Display the current message in the current mini-buffer. This is
7166 only called from error handlers in process.c, and is not time
7172 if (!NILP (echo_area_buffer
[0]))
7175 string
= Fcurrent_message ();
7176 message3 (string
, SBYTES (string
),
7177 !NILP (current_buffer
->enable_multibyte_characters
));
7182 /* Make sure echo area buffers in `echo_buffers' are live.
7183 If they aren't, make new ones. */
7186 ensure_echo_area_buffers ()
7190 for (i
= 0; i
< 2; ++i
)
7191 if (!BUFFERP (echo_buffer
[i
])
7192 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7195 Lisp_Object old_buffer
;
7198 old_buffer
= echo_buffer
[i
];
7199 sprintf (name
, " *Echo Area %d*", i
);
7200 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7201 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7203 for (j
= 0; j
< 2; ++j
)
7204 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7205 echo_area_buffer
[j
] = echo_buffer
[i
];
7210 /* Call FN with args A1..A4 with either the current or last displayed
7211 echo_area_buffer as current buffer.
7213 WHICH zero means use the current message buffer
7214 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7215 from echo_buffer[] and clear it.
7217 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7218 suitable buffer from echo_buffer[] and clear it.
7220 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7221 that the current message becomes the last displayed one, make
7222 choose a suitable buffer for echo_area_buffer[0], and clear it.
7224 Value is what FN returns. */
7227 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7230 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7236 int this_one
, the_other
, clear_buffer_p
, rc
;
7237 int count
= SPECPDL_INDEX ();
7239 /* If buffers aren't live, make new ones. */
7240 ensure_echo_area_buffers ();
7245 this_one
= 0, the_other
= 1;
7247 this_one
= 1, the_other
= 0;
7250 this_one
= 0, the_other
= 1;
7253 /* We need a fresh one in case the current echo buffer equals
7254 the one containing the last displayed echo area message. */
7255 if (!NILP (echo_area_buffer
[this_one
])
7256 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7257 echo_area_buffer
[this_one
] = Qnil
;
7260 /* Choose a suitable buffer from echo_buffer[] is we don't
7262 if (NILP (echo_area_buffer
[this_one
]))
7264 echo_area_buffer
[this_one
]
7265 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7266 ? echo_buffer
[the_other
]
7267 : echo_buffer
[this_one
]);
7271 buffer
= echo_area_buffer
[this_one
];
7273 /* Don't get confused by reusing the buffer used for echoing
7274 for a different purpose. */
7275 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7278 record_unwind_protect (unwind_with_echo_area_buffer
,
7279 with_echo_area_buffer_unwind_data (w
));
7281 /* Make the echo area buffer current. Note that for display
7282 purposes, it is not necessary that the displayed window's buffer
7283 == current_buffer, except for text property lookup. So, let's
7284 only set that buffer temporarily here without doing a full
7285 Fset_window_buffer. We must also change w->pointm, though,
7286 because otherwise an assertions in unshow_buffer fails, and Emacs
7288 set_buffer_internal_1 (XBUFFER (buffer
));
7292 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7295 current_buffer
->undo_list
= Qt
;
7296 current_buffer
->read_only
= Qnil
;
7297 specbind (Qinhibit_read_only
, Qt
);
7298 specbind (Qinhibit_modification_hooks
, Qt
);
7300 if (clear_buffer_p
&& Z
> BEG
)
7303 xassert (BEGV
>= BEG
);
7304 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7306 rc
= fn (a1
, a2
, a3
, a4
);
7308 xassert (BEGV
>= BEG
);
7309 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7311 unbind_to (count
, Qnil
);
7316 /* Save state that should be preserved around the call to the function
7317 FN called in with_echo_area_buffer. */
7320 with_echo_area_buffer_unwind_data (w
)
7326 /* Reduce consing by keeping one vector in
7327 Vwith_echo_area_save_vector. */
7328 vector
= Vwith_echo_area_save_vector
;
7329 Vwith_echo_area_save_vector
= Qnil
;
7332 vector
= Fmake_vector (make_number (7), Qnil
);
7334 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7335 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7336 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7340 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7341 AREF (vector
, i
) = w
->buffer
; ++i
;
7342 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7343 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7348 for (; i
< end
; ++i
)
7349 AREF (vector
, i
) = Qnil
;
7352 xassert (i
== ASIZE (vector
));
7357 /* Restore global state from VECTOR which was created by
7358 with_echo_area_buffer_unwind_data. */
7361 unwind_with_echo_area_buffer (vector
)
7364 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7365 Vdeactivate_mark
= AREF (vector
, 1);
7366 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7368 if (WINDOWP (AREF (vector
, 3)))
7371 Lisp_Object buffer
, charpos
, bytepos
;
7373 w
= XWINDOW (AREF (vector
, 3));
7374 buffer
= AREF (vector
, 4);
7375 charpos
= AREF (vector
, 5);
7376 bytepos
= AREF (vector
, 6);
7379 set_marker_both (w
->pointm
, buffer
,
7380 XFASTINT (charpos
), XFASTINT (bytepos
));
7383 Vwith_echo_area_save_vector
= vector
;
7388 /* Set up the echo area for use by print functions. MULTIBYTE_P
7389 non-zero means we will print multibyte. */
7392 setup_echo_area_for_printing (multibyte_p
)
7395 /* If we can't find an echo area any more, exit. */
7396 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7399 ensure_echo_area_buffers ();
7401 if (!message_buf_print
)
7403 /* A message has been output since the last time we printed.
7404 Choose a fresh echo area buffer. */
7405 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7406 echo_area_buffer
[0] = echo_buffer
[1];
7408 echo_area_buffer
[0] = echo_buffer
[0];
7410 /* Switch to that buffer and clear it. */
7411 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7412 current_buffer
->truncate_lines
= Qnil
;
7416 int count
= SPECPDL_INDEX ();
7417 specbind (Qinhibit_read_only
, Qt
);
7418 /* Note that undo recording is always disabled. */
7420 unbind_to (count
, Qnil
);
7422 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7424 /* Set up the buffer for the multibyteness we need. */
7426 != !NILP (current_buffer
->enable_multibyte_characters
))
7427 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7429 /* Raise the frame containing the echo area. */
7430 if (minibuffer_auto_raise
)
7432 struct frame
*sf
= SELECTED_FRAME ();
7433 Lisp_Object mini_window
;
7434 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7435 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7438 message_log_maybe_newline ();
7439 message_buf_print
= 1;
7443 if (NILP (echo_area_buffer
[0]))
7445 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7446 echo_area_buffer
[0] = echo_buffer
[1];
7448 echo_area_buffer
[0] = echo_buffer
[0];
7451 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7453 /* Someone switched buffers between print requests. */
7454 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7455 current_buffer
->truncate_lines
= Qnil
;
7461 /* Display an echo area message in window W. Value is non-zero if W's
7462 height is changed. If display_last_displayed_message_p is
7463 non-zero, display the message that was last displayed, otherwise
7464 display the current message. */
7467 display_echo_area (w
)
7470 int i
, no_message_p
, window_height_changed_p
, count
;
7472 /* Temporarily disable garbage collections while displaying the echo
7473 area. This is done because a GC can print a message itself.
7474 That message would modify the echo area buffer's contents while a
7475 redisplay of the buffer is going on, and seriously confuse
7477 count
= inhibit_garbage_collection ();
7479 /* If there is no message, we must call display_echo_area_1
7480 nevertheless because it resizes the window. But we will have to
7481 reset the echo_area_buffer in question to nil at the end because
7482 with_echo_area_buffer will sets it to an empty buffer. */
7483 i
= display_last_displayed_message_p
? 1 : 0;
7484 no_message_p
= NILP (echo_area_buffer
[i
]);
7486 window_height_changed_p
7487 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7488 display_echo_area_1
,
7489 (EMACS_INT
) w
, Qnil
, 0, 0);
7492 echo_area_buffer
[i
] = Qnil
;
7494 unbind_to (count
, Qnil
);
7495 return window_height_changed_p
;
7499 /* Helper for display_echo_area. Display the current buffer which
7500 contains the current echo area message in window W, a mini-window,
7501 a pointer to which is passed in A1. A2..A4 are currently not used.
7502 Change the height of W so that all of the message is displayed.
7503 Value is non-zero if height of W was changed. */
7506 display_echo_area_1 (a1
, a2
, a3
, a4
)
7511 struct window
*w
= (struct window
*) a1
;
7513 struct text_pos start
;
7514 int window_height_changed_p
= 0;
7516 /* Do this before displaying, so that we have a large enough glyph
7517 matrix for the display. */
7518 window_height_changed_p
= resize_mini_window (w
, 0);
7521 clear_glyph_matrix (w
->desired_matrix
);
7522 XSETWINDOW (window
, w
);
7523 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7524 try_window (window
, start
);
7526 return window_height_changed_p
;
7530 /* Resize the echo area window to exactly the size needed for the
7531 currently displayed message, if there is one. If a mini-buffer
7532 is active, don't shrink it. */
7535 resize_echo_area_exactly ()
7537 if (BUFFERP (echo_area_buffer
[0])
7538 && WINDOWP (echo_area_window
))
7540 struct window
*w
= XWINDOW (echo_area_window
);
7542 Lisp_Object resize_exactly
;
7544 if (minibuf_level
== 0)
7545 resize_exactly
= Qt
;
7547 resize_exactly
= Qnil
;
7549 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7550 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7553 ++windows_or_buffers_changed
;
7554 ++update_mode_lines
;
7555 redisplay_internal (0);
7561 /* Callback function for with_echo_area_buffer, when used from
7562 resize_echo_area_exactly. A1 contains a pointer to the window to
7563 resize, EXACTLY non-nil means resize the mini-window exactly to the
7564 size of the text displayed. A3 and A4 are not used. Value is what
7565 resize_mini_window returns. */
7568 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7570 Lisp_Object exactly
;
7573 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7577 /* Resize mini-window W to fit the size of its contents. EXACT:P
7578 means size the window exactly to the size needed. Otherwise, it's
7579 only enlarged until W's buffer is empty. Value is non-zero if
7580 the window height has been changed. */
7583 resize_mini_window (w
, exact_p
)
7587 struct frame
*f
= XFRAME (w
->frame
);
7588 int window_height_changed_p
= 0;
7590 xassert (MINI_WINDOW_P (w
));
7592 /* Don't resize windows while redisplaying a window; it would
7593 confuse redisplay functions when the size of the window they are
7594 displaying changes from under them. Such a resizing can happen,
7595 for instance, when which-func prints a long message while
7596 we are running fontification-functions. We're running these
7597 functions with safe_call which binds inhibit-redisplay to t. */
7598 if (!NILP (Vinhibit_redisplay
))
7601 /* Nil means don't try to resize. */
7602 if (NILP (Vresize_mini_windows
)
7603 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7606 if (!FRAME_MINIBUF_ONLY_P (f
))
7609 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7610 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7611 int height
, max_height
;
7612 int unit
= FRAME_LINE_HEIGHT (f
);
7613 struct text_pos start
;
7614 struct buffer
*old_current_buffer
= NULL
;
7616 if (current_buffer
!= XBUFFER (w
->buffer
))
7618 old_current_buffer
= current_buffer
;
7619 set_buffer_internal (XBUFFER (w
->buffer
));
7622 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7624 /* Compute the max. number of lines specified by the user. */
7625 if (FLOATP (Vmax_mini_window_height
))
7626 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7627 else if (INTEGERP (Vmax_mini_window_height
))
7628 max_height
= XINT (Vmax_mini_window_height
);
7630 max_height
= total_height
/ 4;
7632 /* Correct that max. height if it's bogus. */
7633 max_height
= max (1, max_height
);
7634 max_height
= min (total_height
, max_height
);
7636 /* Find out the height of the text in the window. */
7637 if (it
.truncate_lines_p
)
7642 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7643 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7644 height
= it
.current_y
+ last_height
;
7646 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7647 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7648 height
= (height
+ unit
- 1) / unit
;
7651 /* Compute a suitable window start. */
7652 if (height
> max_height
)
7654 height
= max_height
;
7655 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7656 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7657 start
= it
.current
.pos
;
7660 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7661 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7663 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7665 /* Let it grow only, until we display an empty message, in which
7666 case the window shrinks again. */
7667 if (height
> WINDOW_TOTAL_LINES (w
))
7669 int old_height
= WINDOW_TOTAL_LINES (w
);
7670 freeze_window_starts (f
, 1);
7671 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7672 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7674 else if (height
< WINDOW_TOTAL_LINES (w
)
7675 && (exact_p
|| BEGV
== ZV
))
7677 int old_height
= WINDOW_TOTAL_LINES (w
);
7678 freeze_window_starts (f
, 0);
7679 shrink_mini_window (w
);
7680 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7685 /* Always resize to exact size needed. */
7686 if (height
> WINDOW_TOTAL_LINES (w
))
7688 int old_height
= WINDOW_TOTAL_LINES (w
);
7689 freeze_window_starts (f
, 1);
7690 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7691 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7693 else if (height
< WINDOW_TOTAL_LINES (w
))
7695 int old_height
= WINDOW_TOTAL_LINES (w
);
7696 freeze_window_starts (f
, 0);
7697 shrink_mini_window (w
);
7701 freeze_window_starts (f
, 1);
7702 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7705 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7709 if (old_current_buffer
)
7710 set_buffer_internal (old_current_buffer
);
7713 return window_height_changed_p
;
7717 /* Value is the current message, a string, or nil if there is no
7725 if (NILP (echo_area_buffer
[0]))
7729 with_echo_area_buffer (0, 0, current_message_1
,
7730 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7732 echo_area_buffer
[0] = Qnil
;
7740 current_message_1 (a1
, a2
, a3
, a4
)
7745 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7748 *msg
= make_buffer_string (BEG
, Z
, 1);
7755 /* Push the current message on Vmessage_stack for later restauration
7756 by restore_message. Value is non-zero if the current message isn't
7757 empty. This is a relatively infrequent operation, so it's not
7758 worth optimizing. */
7764 msg
= current_message ();
7765 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7766 return STRINGP (msg
);
7770 /* Restore message display from the top of Vmessage_stack. */
7777 xassert (CONSP (Vmessage_stack
));
7778 msg
= XCAR (Vmessage_stack
);
7780 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7782 message3_nolog (msg
, 0, 0);
7786 /* Handler for record_unwind_protect calling pop_message. */
7789 pop_message_unwind (dummy
)
7796 /* Pop the top-most entry off Vmessage_stack. */
7801 xassert (CONSP (Vmessage_stack
));
7802 Vmessage_stack
= XCDR (Vmessage_stack
);
7806 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7807 exits. If the stack is not empty, we have a missing pop_message
7811 check_message_stack ()
7813 if (!NILP (Vmessage_stack
))
7818 /* Truncate to NCHARS what will be displayed in the echo area the next
7819 time we display it---but don't redisplay it now. */
7822 truncate_echo_area (nchars
)
7826 echo_area_buffer
[0] = Qnil
;
7827 /* A null message buffer means that the frame hasn't really been
7828 initialized yet. Error messages get reported properly by
7829 cmd_error, so this must be just an informative message; toss it. */
7830 else if (!noninteractive
7832 && !NILP (echo_area_buffer
[0]))
7834 struct frame
*sf
= SELECTED_FRAME ();
7835 if (FRAME_MESSAGE_BUF (sf
))
7836 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7841 /* Helper function for truncate_echo_area. Truncate the current
7842 message to at most NCHARS characters. */
7845 truncate_message_1 (nchars
, a2
, a3
, a4
)
7850 if (BEG
+ nchars
< Z
)
7851 del_range (BEG
+ nchars
, Z
);
7853 echo_area_buffer
[0] = Qnil
;
7858 /* Set the current message to a substring of S or STRING.
7860 If STRING is a Lisp string, set the message to the first NBYTES
7861 bytes from STRING. NBYTES zero means use the whole string. If
7862 STRING is multibyte, the message will be displayed multibyte.
7864 If S is not null, set the message to the first LEN bytes of S. LEN
7865 zero means use the whole string. MULTIBYTE_P non-zero means S is
7866 multibyte. Display the message multibyte in that case. */
7869 set_message (s
, string
, nbytes
, multibyte_p
)
7872 int nbytes
, multibyte_p
;
7874 message_enable_multibyte
7875 = ((s
&& multibyte_p
)
7876 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7878 with_echo_area_buffer (0, -1, set_message_1
,
7879 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7880 message_buf_print
= 0;
7881 help_echo_showing_p
= 0;
7885 /* Helper function for set_message. Arguments have the same meaning
7886 as there, with A1 corresponding to S and A2 corresponding to STRING
7887 This function is called with the echo area buffer being
7891 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7894 EMACS_INT nbytes
, multibyte_p
;
7896 const char *s
= (const char *) a1
;
7897 Lisp_Object string
= a2
;
7901 /* Change multibyteness of the echo buffer appropriately. */
7902 if (message_enable_multibyte
7903 != !NILP (current_buffer
->enable_multibyte_characters
))
7904 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7906 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7908 /* Insert new message at BEG. */
7909 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7911 if (STRINGP (string
))
7916 nbytes
= SBYTES (string
);
7917 nchars
= string_byte_to_char (string
, nbytes
);
7919 /* This function takes care of single/multibyte conversion. We
7920 just have to ensure that the echo area buffer has the right
7921 setting of enable_multibyte_characters. */
7922 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7927 nbytes
= strlen (s
);
7929 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7931 /* Convert from multi-byte to single-byte. */
7933 unsigned char work
[1];
7935 /* Convert a multibyte string to single-byte. */
7936 for (i
= 0; i
< nbytes
; i
+= n
)
7938 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7939 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7941 : multibyte_char_to_unibyte (c
, Qnil
));
7942 insert_1_both (work
, 1, 1, 1, 0, 0);
7945 else if (!multibyte_p
7946 && !NILP (current_buffer
->enable_multibyte_characters
))
7948 /* Convert from single-byte to multi-byte. */
7950 const unsigned char *msg
= (const unsigned char *) s
;
7951 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7953 /* Convert a single-byte string to multibyte. */
7954 for (i
= 0; i
< nbytes
; i
++)
7956 c
= unibyte_char_to_multibyte (msg
[i
]);
7957 n
= CHAR_STRING (c
, str
);
7958 insert_1_both (str
, 1, n
, 1, 0, 0);
7962 insert_1 (s
, nbytes
, 1, 0, 0);
7969 /* Clear messages. CURRENT_P non-zero means clear the current
7970 message. LAST_DISPLAYED_P non-zero means clear the message
7974 clear_message (current_p
, last_displayed_p
)
7975 int current_p
, last_displayed_p
;
7979 echo_area_buffer
[0] = Qnil
;
7980 message_cleared_p
= 1;
7983 if (last_displayed_p
)
7984 echo_area_buffer
[1] = Qnil
;
7986 message_buf_print
= 0;
7989 /* Clear garbaged frames.
7991 This function is used where the old redisplay called
7992 redraw_garbaged_frames which in turn called redraw_frame which in
7993 turn called clear_frame. The call to clear_frame was a source of
7994 flickering. I believe a clear_frame is not necessary. It should
7995 suffice in the new redisplay to invalidate all current matrices,
7996 and ensure a complete redisplay of all windows. */
7999 clear_garbaged_frames ()
8003 Lisp_Object tail
, frame
;
8004 int changed_count
= 0;
8006 FOR_EACH_FRAME (tail
, frame
)
8008 struct frame
*f
= XFRAME (frame
);
8010 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8014 Fredraw_frame (frame
);
8015 f
->force_flush_display_p
= 1;
8017 clear_current_matrices (f
);
8026 ++windows_or_buffers_changed
;
8031 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8032 is non-zero update selected_frame. Value is non-zero if the
8033 mini-windows height has been changed. */
8036 echo_area_display (update_frame_p
)
8039 Lisp_Object mini_window
;
8042 int window_height_changed_p
= 0;
8043 struct frame
*sf
= SELECTED_FRAME ();
8045 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8046 w
= XWINDOW (mini_window
);
8047 f
= XFRAME (WINDOW_FRAME (w
));
8049 /* Don't display if frame is invisible or not yet initialized. */
8050 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8053 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8055 #ifdef HAVE_WINDOW_SYSTEM
8056 /* When Emacs starts, selected_frame may be a visible terminal
8057 frame, even if we run under a window system. If we let this
8058 through, a message would be displayed on the terminal. */
8059 if (EQ (selected_frame
, Vterminal_frame
)
8060 && !NILP (Vwindow_system
))
8062 #endif /* HAVE_WINDOW_SYSTEM */
8065 /* Redraw garbaged frames. */
8067 clear_garbaged_frames ();
8069 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8071 echo_area_window
= mini_window
;
8072 window_height_changed_p
= display_echo_area (w
);
8073 w
->must_be_updated_p
= 1;
8075 /* Update the display, unless called from redisplay_internal.
8076 Also don't update the screen during redisplay itself. The
8077 update will happen at the end of redisplay, and an update
8078 here could cause confusion. */
8079 if (update_frame_p
&& !redisplaying_p
)
8083 /* If the display update has been interrupted by pending
8084 input, update mode lines in the frame. Due to the
8085 pending input, it might have been that redisplay hasn't
8086 been called, so that mode lines above the echo area are
8087 garbaged. This looks odd, so we prevent it here. */
8088 if (!display_completed
)
8089 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8091 if (window_height_changed_p
8092 /* Don't do this if Emacs is shutting down. Redisplay
8093 needs to run hooks. */
8094 && !NILP (Vrun_hooks
))
8096 /* Must update other windows. Likewise as in other
8097 cases, don't let this update be interrupted by
8099 int count
= SPECPDL_INDEX ();
8100 specbind (Qredisplay_dont_pause
, Qt
);
8101 windows_or_buffers_changed
= 1;
8102 redisplay_internal (0);
8103 unbind_to (count
, Qnil
);
8105 else if (FRAME_WINDOW_P (f
) && n
== 0)
8107 /* Window configuration is the same as before.
8108 Can do with a display update of the echo area,
8109 unless we displayed some mode lines. */
8110 update_single_window (w
, 1);
8111 rif
->flush_display (f
);
8114 update_frame (f
, 1, 1);
8116 /* If cursor is in the echo area, make sure that the next
8117 redisplay displays the minibuffer, so that the cursor will
8118 be replaced with what the minibuffer wants. */
8119 if (cursor_in_echo_area
)
8120 ++windows_or_buffers_changed
;
8123 else if (!EQ (mini_window
, selected_window
))
8124 windows_or_buffers_changed
++;
8126 /* Last displayed message is now the current message. */
8127 echo_area_buffer
[1] = echo_area_buffer
[0];
8128 /* Inform read_char that we're not echoing. */
8129 echo_message_buffer
= Qnil
;
8131 /* Prevent redisplay optimization in redisplay_internal by resetting
8132 this_line_start_pos. This is done because the mini-buffer now
8133 displays the message instead of its buffer text. */
8134 if (EQ (mini_window
, selected_window
))
8135 CHARPOS (this_line_start_pos
) = 0;
8137 return window_height_changed_p
;
8142 /***********************************************************************
8144 ***********************************************************************/
8147 /* The frame title buffering code is also used by Fformat_mode_line.
8148 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
8150 /* A buffer for constructing frame titles in it; allocated from the
8151 heap in init_xdisp and resized as needed in store_frame_title_char. */
8153 static char *frame_title_buf
;
8155 /* The buffer's end, and a current output position in it. */
8157 static char *frame_title_buf_end
;
8158 static char *frame_title_ptr
;
8161 /* Store a single character C for the frame title in frame_title_buf.
8162 Re-allocate frame_title_buf if necessary. */
8166 store_frame_title_char (char c
)
8168 store_frame_title_char (c
)
8172 /* If output position has reached the end of the allocated buffer,
8173 double the buffer's size. */
8174 if (frame_title_ptr
== frame_title_buf_end
)
8176 int len
= frame_title_ptr
- frame_title_buf
;
8177 int new_size
= 2 * len
* sizeof *frame_title_buf
;
8178 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
8179 frame_title_buf_end
= frame_title_buf
+ new_size
;
8180 frame_title_ptr
= frame_title_buf
+ len
;
8183 *frame_title_ptr
++ = c
;
8187 /* Store part of a frame title in frame_title_buf, beginning at
8188 frame_title_ptr. STR is the string to store. Do not copy
8189 characters that yield more columns than PRECISION; PRECISION <= 0
8190 means copy the whole string. Pad with spaces until FIELD_WIDTH
8191 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8192 pad. Called from display_mode_element when it is used to build a
8196 store_frame_title (str
, field_width
, precision
)
8197 const unsigned char *str
;
8198 int field_width
, precision
;
8203 /* Copy at most PRECISION chars from STR. */
8204 nbytes
= strlen (str
);
8205 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8207 store_frame_title_char (*str
++);
8209 /* Fill up with spaces until FIELD_WIDTH reached. */
8210 while (field_width
> 0
8213 store_frame_title_char (' ');
8220 #ifdef HAVE_WINDOW_SYSTEM
8222 /* Set the title of FRAME, if it has changed. The title format is
8223 Vicon_title_format if FRAME is iconified, otherwise it is
8224 frame_title_format. */
8227 x_consider_frame_title (frame
)
8230 struct frame
*f
= XFRAME (frame
);
8232 if (FRAME_WINDOW_P (f
)
8233 || FRAME_MINIBUF_ONLY_P (f
)
8234 || f
->explicit_name
)
8236 /* Do we have more than one visible frame on this X display? */
8239 struct buffer
*obuf
;
8243 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8245 Lisp_Object other_frame
= XCAR (tail
);
8246 struct frame
*tf
= XFRAME (other_frame
);
8249 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8250 && !FRAME_MINIBUF_ONLY_P (tf
)
8251 && !EQ (other_frame
, tip_frame
)
8252 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8256 /* Set global variable indicating that multiple frames exist. */
8257 multiple_frames
= CONSP (tail
);
8259 /* Switch to the buffer of selected window of the frame. Set up
8260 frame_title_ptr so that display_mode_element will output into it;
8261 then display the title. */
8262 obuf
= current_buffer
;
8263 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8264 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8265 frame_title_ptr
= frame_title_buf
;
8266 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8267 NULL
, DEFAULT_FACE_ID
);
8268 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8269 len
= frame_title_ptr
- frame_title_buf
;
8270 frame_title_ptr
= NULL
;
8271 set_buffer_internal_1 (obuf
);
8273 /* Set the title only if it's changed. This avoids consing in
8274 the common case where it hasn't. (If it turns out that we've
8275 already wasted too much time by walking through the list with
8276 display_mode_element, then we might need to optimize at a
8277 higher level than this.) */
8278 if (! STRINGP (f
->name
)
8279 || SBYTES (f
->name
) != len
8280 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8281 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8285 #endif /* not HAVE_WINDOW_SYSTEM */
8290 /***********************************************************************
8292 ***********************************************************************/
8295 /* Prepare for redisplay by updating menu-bar item lists when
8296 appropriate. This can call eval. */
8299 prepare_menu_bars ()
8302 struct gcpro gcpro1
, gcpro2
;
8304 Lisp_Object tooltip_frame
;
8306 #ifdef HAVE_WINDOW_SYSTEM
8307 tooltip_frame
= tip_frame
;
8309 tooltip_frame
= Qnil
;
8312 /* Update all frame titles based on their buffer names, etc. We do
8313 this before the menu bars so that the buffer-menu will show the
8314 up-to-date frame titles. */
8315 #ifdef HAVE_WINDOW_SYSTEM
8316 if (windows_or_buffers_changed
|| update_mode_lines
)
8318 Lisp_Object tail
, frame
;
8320 FOR_EACH_FRAME (tail
, frame
)
8323 if (!EQ (frame
, tooltip_frame
)
8324 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8325 x_consider_frame_title (frame
);
8328 #endif /* HAVE_WINDOW_SYSTEM */
8330 /* Update the menu bar item lists, if appropriate. This has to be
8331 done before any actual redisplay or generation of display lines. */
8332 all_windows
= (update_mode_lines
8333 || buffer_shared
> 1
8334 || windows_or_buffers_changed
);
8337 Lisp_Object tail
, frame
;
8338 int count
= SPECPDL_INDEX ();
8340 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8342 FOR_EACH_FRAME (tail
, frame
)
8346 /* Ignore tooltip frame. */
8347 if (EQ (frame
, tooltip_frame
))
8350 /* If a window on this frame changed size, report that to
8351 the user and clear the size-change flag. */
8352 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8354 Lisp_Object functions
;
8356 /* Clear flag first in case we get an error below. */
8357 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8358 functions
= Vwindow_size_change_functions
;
8359 GCPRO2 (tail
, functions
);
8361 while (CONSP (functions
))
8363 call1 (XCAR (functions
), frame
);
8364 functions
= XCDR (functions
);
8370 update_menu_bar (f
, 0);
8371 #ifdef HAVE_WINDOW_SYSTEM
8372 update_tool_bar (f
, 0);
8377 unbind_to (count
, Qnil
);
8381 struct frame
*sf
= SELECTED_FRAME ();
8382 update_menu_bar (sf
, 1);
8383 #ifdef HAVE_WINDOW_SYSTEM
8384 update_tool_bar (sf
, 1);
8388 /* Motif needs this. See comment in xmenu.c. Turn it off when
8389 pending_menu_activation is not defined. */
8390 #ifdef USE_X_TOOLKIT
8391 pending_menu_activation
= 0;
8396 /* Update the menu bar item list for frame F. This has to be done
8397 before we start to fill in any display lines, because it can call
8400 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8403 update_menu_bar (f
, save_match_data
)
8405 int save_match_data
;
8408 register struct window
*w
;
8410 /* If called recursively during a menu update, do nothing. This can
8411 happen when, for instance, an activate-menubar-hook causes a
8413 if (inhibit_menubar_update
)
8416 window
= FRAME_SELECTED_WINDOW (f
);
8417 w
= XWINDOW (window
);
8419 #if 0 /* The if statement below this if statement used to include the
8420 condition !NILP (w->update_mode_line), rather than using
8421 update_mode_lines directly, and this if statement may have
8422 been added to make that condition work. Now the if
8423 statement below matches its comment, this isn't needed. */
8424 if (update_mode_lines
)
8425 w
->update_mode_line
= Qt
;
8428 if (FRAME_WINDOW_P (f
)
8430 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8431 || defined (USE_GTK)
8432 FRAME_EXTERNAL_MENU_BAR (f
)
8434 FRAME_MENU_BAR_LINES (f
) > 0
8436 : FRAME_MENU_BAR_LINES (f
) > 0)
8438 /* If the user has switched buffers or windows, we need to
8439 recompute to reflect the new bindings. But we'll
8440 recompute when update_mode_lines is set too; that means
8441 that people can use force-mode-line-update to request
8442 that the menu bar be recomputed. The adverse effect on
8443 the rest of the redisplay algorithm is about the same as
8444 windows_or_buffers_changed anyway. */
8445 if (windows_or_buffers_changed
8446 /* This used to test w->update_mode_line, but we believe
8447 there is no need to recompute the menu in that case. */
8448 || update_mode_lines
8449 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8450 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8451 != !NILP (w
->last_had_star
))
8452 || ((!NILP (Vtransient_mark_mode
)
8453 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8454 != !NILP (w
->region_showing
)))
8456 struct buffer
*prev
= current_buffer
;
8457 int count
= SPECPDL_INDEX ();
8459 specbind (Qinhibit_menubar_update
, Qt
);
8461 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8462 if (save_match_data
)
8463 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8464 if (NILP (Voverriding_local_map_menu_flag
))
8466 specbind (Qoverriding_terminal_local_map
, Qnil
);
8467 specbind (Qoverriding_local_map
, Qnil
);
8470 /* Run the Lucid hook. */
8471 safe_run_hooks (Qactivate_menubar_hook
);
8473 /* If it has changed current-menubar from previous value,
8474 really recompute the menu-bar from the value. */
8475 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8476 call0 (Qrecompute_lucid_menubar
);
8478 safe_run_hooks (Qmenu_bar_update_hook
);
8479 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8481 /* Redisplay the menu bar in case we changed it. */
8482 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8483 || defined (USE_GTK)
8484 if (FRAME_WINDOW_P (f
)
8485 #if defined (MAC_OS)
8486 /* All frames on Mac OS share the same menubar. So only the
8487 selected frame should be allowed to set it. */
8488 && f
== SELECTED_FRAME ()
8491 set_frame_menubar (f
, 0, 0);
8493 /* On a terminal screen, the menu bar is an ordinary screen
8494 line, and this makes it get updated. */
8495 w
->update_mode_line
= Qt
;
8496 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8497 /* In the non-toolkit version, the menu bar is an ordinary screen
8498 line, and this makes it get updated. */
8499 w
->update_mode_line
= Qt
;
8500 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8502 unbind_to (count
, Qnil
);
8503 set_buffer_internal_1 (prev
);
8510 /***********************************************************************
8512 ***********************************************************************/
8514 #ifdef HAVE_WINDOW_SYSTEM
8517 Nominal cursor position -- where to draw output.
8518 HPOS and VPOS are window relative glyph matrix coordinates.
8519 X and Y are window relative pixel coordinates. */
8521 struct cursor_pos output_cursor
;
8525 Set the global variable output_cursor to CURSOR. All cursor
8526 positions are relative to updated_window. */
8529 set_output_cursor (cursor
)
8530 struct cursor_pos
*cursor
;
8532 output_cursor
.hpos
= cursor
->hpos
;
8533 output_cursor
.vpos
= cursor
->vpos
;
8534 output_cursor
.x
= cursor
->x
;
8535 output_cursor
.y
= cursor
->y
;
8540 Set a nominal cursor position.
8542 HPOS and VPOS are column/row positions in a window glyph matrix. X
8543 and Y are window text area relative pixel positions.
8545 If this is done during an update, updated_window will contain the
8546 window that is being updated and the position is the future output
8547 cursor position for that window. If updated_window is null, use
8548 selected_window and display the cursor at the given position. */
8551 x_cursor_to (vpos
, hpos
, y
, x
)
8552 int vpos
, hpos
, y
, x
;
8556 /* If updated_window is not set, work on selected_window. */
8560 w
= XWINDOW (selected_window
);
8562 /* Set the output cursor. */
8563 output_cursor
.hpos
= hpos
;
8564 output_cursor
.vpos
= vpos
;
8565 output_cursor
.x
= x
;
8566 output_cursor
.y
= y
;
8568 /* If not called as part of an update, really display the cursor.
8569 This will also set the cursor position of W. */
8570 if (updated_window
== NULL
)
8573 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8574 if (rif
->flush_display_optional
)
8575 rif
->flush_display_optional (SELECTED_FRAME ());
8580 #endif /* HAVE_WINDOW_SYSTEM */
8583 /***********************************************************************
8585 ***********************************************************************/
8587 #ifdef HAVE_WINDOW_SYSTEM
8589 /* Where the mouse was last time we reported a mouse event. */
8591 FRAME_PTR last_mouse_frame
;
8593 /* Tool-bar item index of the item on which a mouse button was pressed
8596 int last_tool_bar_item
;
8599 /* Update the tool-bar item list for frame F. This has to be done
8600 before we start to fill in any display lines. Called from
8601 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8602 and restore it here. */
8605 update_tool_bar (f
, save_match_data
)
8607 int save_match_data
;
8610 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8612 int do_update
= WINDOWP (f
->tool_bar_window
)
8613 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8621 window
= FRAME_SELECTED_WINDOW (f
);
8622 w
= XWINDOW (window
);
8624 /* If the user has switched buffers or windows, we need to
8625 recompute to reflect the new bindings. But we'll
8626 recompute when update_mode_lines is set too; that means
8627 that people can use force-mode-line-update to request
8628 that the menu bar be recomputed. The adverse effect on
8629 the rest of the redisplay algorithm is about the same as
8630 windows_or_buffers_changed anyway. */
8631 if (windows_or_buffers_changed
8632 || !NILP (w
->update_mode_line
)
8633 || update_mode_lines
8634 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8635 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8636 != !NILP (w
->last_had_star
))
8637 || ((!NILP (Vtransient_mark_mode
)
8638 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8639 != !NILP (w
->region_showing
)))
8641 struct buffer
*prev
= current_buffer
;
8642 int count
= SPECPDL_INDEX ();
8643 Lisp_Object new_tool_bar
;
8645 struct gcpro gcpro1
;
8647 /* Set current_buffer to the buffer of the selected
8648 window of the frame, so that we get the right local
8650 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8652 /* Save match data, if we must. */
8653 if (save_match_data
)
8654 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8656 /* Make sure that we don't accidentally use bogus keymaps. */
8657 if (NILP (Voverriding_local_map_menu_flag
))
8659 specbind (Qoverriding_terminal_local_map
, Qnil
);
8660 specbind (Qoverriding_local_map
, Qnil
);
8663 GCPRO1 (new_tool_bar
);
8665 /* Build desired tool-bar items from keymaps. */
8666 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8669 /* Redisplay the tool-bar if we changed it. */
8670 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8672 /* Redisplay that happens asynchronously due to an expose event
8673 may access f->tool_bar_items. Make sure we update both
8674 variables within BLOCK_INPUT so no such event interrupts. */
8676 f
->tool_bar_items
= new_tool_bar
;
8677 f
->n_tool_bar_items
= new_n_tool_bar
;
8678 w
->update_mode_line
= Qt
;
8684 unbind_to (count
, Qnil
);
8685 set_buffer_internal_1 (prev
);
8691 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8692 F's desired tool-bar contents. F->tool_bar_items must have
8693 been set up previously by calling prepare_menu_bars. */
8696 build_desired_tool_bar_string (f
)
8699 int i
, size
, size_needed
;
8700 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8701 Lisp_Object image
, plist
, props
;
8703 image
= plist
= props
= Qnil
;
8704 GCPRO3 (image
, plist
, props
);
8706 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8707 Otherwise, make a new string. */
8709 /* The size of the string we might be able to reuse. */
8710 size
= (STRINGP (f
->desired_tool_bar_string
)
8711 ? SCHARS (f
->desired_tool_bar_string
)
8714 /* We need one space in the string for each image. */
8715 size_needed
= f
->n_tool_bar_items
;
8717 /* Reuse f->desired_tool_bar_string, if possible. */
8718 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8719 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8723 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8724 Fremove_text_properties (make_number (0), make_number (size
),
8725 props
, f
->desired_tool_bar_string
);
8728 /* Put a `display' property on the string for the images to display,
8729 put a `menu_item' property on tool-bar items with a value that
8730 is the index of the item in F's tool-bar item vector. */
8731 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8733 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8735 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8736 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8737 int hmargin
, vmargin
, relief
, idx
, end
;
8738 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8740 /* If image is a vector, choose the image according to the
8742 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8743 if (VECTORP (image
))
8747 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8748 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8751 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8752 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8754 xassert (ASIZE (image
) >= idx
);
8755 image
= AREF (image
, idx
);
8760 /* Ignore invalid image specifications. */
8761 if (!valid_image_p (image
))
8764 /* Display the tool-bar button pressed, or depressed. */
8765 plist
= Fcopy_sequence (XCDR (image
));
8767 /* Compute margin and relief to draw. */
8768 relief
= (tool_bar_button_relief
>= 0
8769 ? tool_bar_button_relief
8770 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8771 hmargin
= vmargin
= relief
;
8773 if (INTEGERP (Vtool_bar_button_margin
)
8774 && XINT (Vtool_bar_button_margin
) > 0)
8776 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8777 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8779 else if (CONSP (Vtool_bar_button_margin
))
8781 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8782 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8783 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8785 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8786 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8787 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8790 if (auto_raise_tool_bar_buttons_p
)
8792 /* Add a `:relief' property to the image spec if the item is
8796 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8803 /* If image is selected, display it pressed, i.e. with a
8804 negative relief. If it's not selected, display it with a
8806 plist
= Fplist_put (plist
, QCrelief
,
8808 ? make_number (-relief
)
8809 : make_number (relief
)));
8814 /* Put a margin around the image. */
8815 if (hmargin
|| vmargin
)
8817 if (hmargin
== vmargin
)
8818 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8820 plist
= Fplist_put (plist
, QCmargin
,
8821 Fcons (make_number (hmargin
),
8822 make_number (vmargin
)));
8825 /* If button is not enabled, and we don't have special images
8826 for the disabled state, make the image appear disabled by
8827 applying an appropriate algorithm to it. */
8828 if (!enabled_p
&& idx
< 0)
8829 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8831 /* Put a `display' text property on the string for the image to
8832 display. Put a `menu-item' property on the string that gives
8833 the start of this item's properties in the tool-bar items
8835 image
= Fcons (Qimage
, plist
);
8836 props
= list4 (Qdisplay
, image
,
8837 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8839 /* Let the last image hide all remaining spaces in the tool bar
8840 string. The string can be longer than needed when we reuse a
8842 if (i
+ 1 == f
->n_tool_bar_items
)
8843 end
= SCHARS (f
->desired_tool_bar_string
);
8846 Fadd_text_properties (make_number (i
), make_number (end
),
8847 props
, f
->desired_tool_bar_string
);
8855 /* Display one line of the tool-bar of frame IT->f. */
8858 display_tool_bar_line (it
)
8861 struct glyph_row
*row
= it
->glyph_row
;
8862 int max_x
= it
->last_visible_x
;
8865 prepare_desired_row (row
);
8866 row
->y
= it
->current_y
;
8868 /* Note that this isn't made use of if the face hasn't a box,
8869 so there's no need to check the face here. */
8870 it
->start_of_box_run_p
= 1;
8872 while (it
->current_x
< max_x
)
8874 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8876 /* Get the next display element. */
8877 if (!get_next_display_element (it
))
8880 /* Produce glyphs. */
8881 x_before
= it
->current_x
;
8882 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8883 PRODUCE_GLYPHS (it
);
8885 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8890 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8892 if (x
+ glyph
->pixel_width
> max_x
)
8894 /* Glyph doesn't fit on line. */
8895 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8901 x
+= glyph
->pixel_width
;
8905 /* Stop at line ends. */
8906 if (ITERATOR_AT_END_OF_LINE_P (it
))
8909 set_iterator_to_next (it
, 1);
8914 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8915 extend_face_to_end_of_line (it
);
8916 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8917 last
->right_box_line_p
= 1;
8918 if (last
== row
->glyphs
[TEXT_AREA
])
8919 last
->left_box_line_p
= 1;
8920 compute_line_metrics (it
);
8922 /* If line is empty, make it occupy the rest of the tool-bar. */
8923 if (!row
->displays_text_p
)
8925 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8926 row
->ascent
= row
->phys_ascent
= 0;
8927 row
->extra_line_spacing
= 0;
8930 row
->full_width_p
= 1;
8931 row
->continued_p
= 0;
8932 row
->truncated_on_left_p
= 0;
8933 row
->truncated_on_right_p
= 0;
8935 it
->current_x
= it
->hpos
= 0;
8936 it
->current_y
+= row
->height
;
8942 /* Value is the number of screen lines needed to make all tool-bar
8943 items of frame F visible. */
8946 tool_bar_lines_needed (f
)
8949 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8952 /* Initialize an iterator for iteration over
8953 F->desired_tool_bar_string in the tool-bar window of frame F. */
8954 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8955 it
.first_visible_x
= 0;
8956 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8957 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8959 while (!ITERATOR_AT_END_P (&it
))
8961 it
.glyph_row
= w
->desired_matrix
->rows
;
8962 clear_glyph_row (it
.glyph_row
);
8963 display_tool_bar_line (&it
);
8966 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8970 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8972 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8981 frame
= selected_frame
;
8983 CHECK_FRAME (frame
);
8986 if (WINDOWP (f
->tool_bar_window
)
8987 || (w
= XWINDOW (f
->tool_bar_window
),
8988 WINDOW_TOTAL_LINES (w
) > 0))
8990 update_tool_bar (f
, 1);
8991 if (f
->n_tool_bar_items
)
8993 build_desired_tool_bar_string (f
);
8994 nlines
= tool_bar_lines_needed (f
);
8998 return make_number (nlines
);
9002 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9003 height should be changed. */
9006 redisplay_tool_bar (f
)
9011 struct glyph_row
*row
;
9012 int change_height_p
= 0;
9015 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9016 update_frame_tool_bar (f
);
9020 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9021 do anything. This means you must start with tool-bar-lines
9022 non-zero to get the auto-sizing effect. Or in other words, you
9023 can turn off tool-bars by specifying tool-bar-lines zero. */
9024 if (!WINDOWP (f
->tool_bar_window
)
9025 || (w
= XWINDOW (f
->tool_bar_window
),
9026 WINDOW_TOTAL_LINES (w
) == 0))
9029 /* Set up an iterator for the tool-bar window. */
9030 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9031 it
.first_visible_x
= 0;
9032 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9035 /* Build a string that represents the contents of the tool-bar. */
9036 build_desired_tool_bar_string (f
);
9037 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9039 /* Display as many lines as needed to display all tool-bar items. */
9040 while (it
.current_y
< it
.last_visible_y
)
9041 display_tool_bar_line (&it
);
9043 /* It doesn't make much sense to try scrolling in the tool-bar
9044 window, so don't do it. */
9045 w
->desired_matrix
->no_scrolling_p
= 1;
9046 w
->must_be_updated_p
= 1;
9048 if (auto_resize_tool_bars_p
)
9052 /* If we couldn't display everything, change the tool-bar's
9054 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9055 change_height_p
= 1;
9057 /* If there are blank lines at the end, except for a partially
9058 visible blank line at the end that is smaller than
9059 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9060 row
= it
.glyph_row
- 1;
9061 if (!row
->displays_text_p
9062 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9063 change_height_p
= 1;
9065 /* If row displays tool-bar items, but is partially visible,
9066 change the tool-bar's height. */
9067 if (row
->displays_text_p
9068 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9069 change_height_p
= 1;
9071 /* Resize windows as needed by changing the `tool-bar-lines'
9074 && (nlines
= tool_bar_lines_needed (f
),
9075 nlines
!= WINDOW_TOTAL_LINES (w
)))
9077 extern Lisp_Object Qtool_bar_lines
;
9079 int old_height
= WINDOW_TOTAL_LINES (w
);
9081 XSETFRAME (frame
, f
);
9082 clear_glyph_matrix (w
->desired_matrix
);
9083 Fmodify_frame_parameters (frame
,
9084 Fcons (Fcons (Qtool_bar_lines
,
9085 make_number (nlines
)),
9087 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9088 fonts_changed_p
= 1;
9092 return change_height_p
;
9096 /* Get information about the tool-bar item which is displayed in GLYPH
9097 on frame F. Return in *PROP_IDX the index where tool-bar item
9098 properties start in F->tool_bar_items. Value is zero if
9099 GLYPH doesn't display a tool-bar item. */
9102 tool_bar_item_info (f
, glyph
, prop_idx
)
9104 struct glyph
*glyph
;
9111 /* This function can be called asynchronously, which means we must
9112 exclude any possibility that Fget_text_property signals an
9114 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9115 charpos
= max (0, charpos
);
9117 /* Get the text property `menu-item' at pos. The value of that
9118 property is the start index of this item's properties in
9119 F->tool_bar_items. */
9120 prop
= Fget_text_property (make_number (charpos
),
9121 Qmenu_item
, f
->current_tool_bar_string
);
9122 if (INTEGERP (prop
))
9124 *prop_idx
= XINT (prop
);
9134 /* Get information about the tool-bar item at position X/Y on frame F.
9135 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9136 the current matrix of the tool-bar window of F, or NULL if not
9137 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9138 item in F->tool_bar_items. Value is
9140 -1 if X/Y is not on a tool-bar item
9141 0 if X/Y is on the same item that was highlighted before.
9145 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9148 struct glyph
**glyph
;
9149 int *hpos
, *vpos
, *prop_idx
;
9151 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9152 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9155 /* Find the glyph under X/Y. */
9156 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9160 /* Get the start of this tool-bar item's properties in
9161 f->tool_bar_items. */
9162 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9165 /* Is mouse on the highlighted item? */
9166 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9167 && *vpos
>= dpyinfo
->mouse_face_beg_row
9168 && *vpos
<= dpyinfo
->mouse_face_end_row
9169 && (*vpos
> dpyinfo
->mouse_face_beg_row
9170 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9171 && (*vpos
< dpyinfo
->mouse_face_end_row
9172 || *hpos
< dpyinfo
->mouse_face_end_col
9173 || dpyinfo
->mouse_face_past_end
))
9181 Handle mouse button event on the tool-bar of frame F, at
9182 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9183 0 for button release. MODIFIERS is event modifiers for button
9187 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9190 unsigned int modifiers
;
9192 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9193 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9194 int hpos
, vpos
, prop_idx
;
9195 struct glyph
*glyph
;
9196 Lisp_Object enabled_p
;
9198 /* If not on the highlighted tool-bar item, return. */
9199 frame_to_window_pixel_xy (w
, &x
, &y
);
9200 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9203 /* If item is disabled, do nothing. */
9204 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9205 if (NILP (enabled_p
))
9210 /* Show item in pressed state. */
9211 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9212 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9213 last_tool_bar_item
= prop_idx
;
9217 Lisp_Object key
, frame
;
9218 struct input_event event
;
9221 /* Show item in released state. */
9222 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9223 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9225 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9227 XSETFRAME (frame
, f
);
9228 event
.kind
= TOOL_BAR_EVENT
;
9229 event
.frame_or_window
= frame
;
9231 kbd_buffer_store_event (&event
);
9233 event
.kind
= TOOL_BAR_EVENT
;
9234 event
.frame_or_window
= frame
;
9236 event
.modifiers
= modifiers
;
9237 kbd_buffer_store_event (&event
);
9238 last_tool_bar_item
= -1;
9243 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9244 tool-bar window-relative coordinates X/Y. Called from
9245 note_mouse_highlight. */
9248 note_tool_bar_highlight (f
, x
, y
)
9252 Lisp_Object window
= f
->tool_bar_window
;
9253 struct window
*w
= XWINDOW (window
);
9254 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9256 struct glyph
*glyph
;
9257 struct glyph_row
*row
;
9259 Lisp_Object enabled_p
;
9261 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9262 int mouse_down_p
, rc
;
9264 /* Function note_mouse_highlight is called with negative x(y
9265 values when mouse moves outside of the frame. */
9266 if (x
<= 0 || y
<= 0)
9268 clear_mouse_face (dpyinfo
);
9272 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9275 /* Not on tool-bar item. */
9276 clear_mouse_face (dpyinfo
);
9280 /* On same tool-bar item as before. */
9283 clear_mouse_face (dpyinfo
);
9285 /* Mouse is down, but on different tool-bar item? */
9286 mouse_down_p
= (dpyinfo
->grabbed
9287 && f
== last_mouse_frame
9288 && FRAME_LIVE_P (f
));
9290 && last_tool_bar_item
!= prop_idx
)
9293 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9294 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9296 /* If tool-bar item is not enabled, don't highlight it. */
9297 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9298 if (!NILP (enabled_p
))
9300 /* Compute the x-position of the glyph. In front and past the
9301 image is a space. We include this in the highlighted area. */
9302 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9303 for (i
= x
= 0; i
< hpos
; ++i
)
9304 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9306 /* Record this as the current active region. */
9307 dpyinfo
->mouse_face_beg_col
= hpos
;
9308 dpyinfo
->mouse_face_beg_row
= vpos
;
9309 dpyinfo
->mouse_face_beg_x
= x
;
9310 dpyinfo
->mouse_face_beg_y
= row
->y
;
9311 dpyinfo
->mouse_face_past_end
= 0;
9313 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9314 dpyinfo
->mouse_face_end_row
= vpos
;
9315 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9316 dpyinfo
->mouse_face_end_y
= row
->y
;
9317 dpyinfo
->mouse_face_window
= window
;
9318 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9320 /* Display it as active. */
9321 show_mouse_face (dpyinfo
, draw
);
9322 dpyinfo
->mouse_face_image_state
= draw
;
9327 /* Set help_echo_string to a help string to display for this tool-bar item.
9328 XTread_socket does the rest. */
9329 help_echo_object
= help_echo_window
= Qnil
;
9331 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9332 if (NILP (help_echo_string
))
9333 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9336 #endif /* HAVE_WINDOW_SYSTEM */
9340 /************************************************************************
9341 Horizontal scrolling
9342 ************************************************************************/
9344 static int hscroll_window_tree
P_ ((Lisp_Object
));
9345 static int hscroll_windows
P_ ((Lisp_Object
));
9347 /* For all leaf windows in the window tree rooted at WINDOW, set their
9348 hscroll value so that PT is (i) visible in the window, and (ii) so
9349 that it is not within a certain margin at the window's left and
9350 right border. Value is non-zero if any window's hscroll has been
9354 hscroll_window_tree (window
)
9357 int hscrolled_p
= 0;
9358 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9359 int hscroll_step_abs
= 0;
9360 double hscroll_step_rel
= 0;
9362 if (hscroll_relative_p
)
9364 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9365 if (hscroll_step_rel
< 0)
9367 hscroll_relative_p
= 0;
9368 hscroll_step_abs
= 0;
9371 else if (INTEGERP (Vhscroll_step
))
9373 hscroll_step_abs
= XINT (Vhscroll_step
);
9374 if (hscroll_step_abs
< 0)
9375 hscroll_step_abs
= 0;
9378 hscroll_step_abs
= 0;
9380 while (WINDOWP (window
))
9382 struct window
*w
= XWINDOW (window
);
9384 if (WINDOWP (w
->hchild
))
9385 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9386 else if (WINDOWP (w
->vchild
))
9387 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9388 else if (w
->cursor
.vpos
>= 0)
9391 int text_area_width
;
9392 struct glyph_row
*current_cursor_row
9393 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9394 struct glyph_row
*desired_cursor_row
9395 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9396 struct glyph_row
*cursor_row
9397 = (desired_cursor_row
->enabled_p
9398 ? desired_cursor_row
9399 : current_cursor_row
);
9401 text_area_width
= window_box_width (w
, TEXT_AREA
);
9403 /* Scroll when cursor is inside this scroll margin. */
9404 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9406 if ((XFASTINT (w
->hscroll
)
9407 && w
->cursor
.x
<= h_margin
)
9408 || (cursor_row
->enabled_p
9409 && cursor_row
->truncated_on_right_p
9410 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9414 struct buffer
*saved_current_buffer
;
9418 /* Find point in a display of infinite width. */
9419 saved_current_buffer
= current_buffer
;
9420 current_buffer
= XBUFFER (w
->buffer
);
9422 if (w
== XWINDOW (selected_window
))
9423 pt
= BUF_PT (current_buffer
);
9426 pt
= marker_position (w
->pointm
);
9427 pt
= max (BEGV
, pt
);
9431 /* Move iterator to pt starting at cursor_row->start in
9432 a line with infinite width. */
9433 init_to_row_start (&it
, w
, cursor_row
);
9434 it
.last_visible_x
= INFINITY
;
9435 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9436 current_buffer
= saved_current_buffer
;
9438 /* Position cursor in window. */
9439 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9440 hscroll
= max (0, (it
.current_x
9441 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9442 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9443 : (text_area_width
/ 2))))
9444 / FRAME_COLUMN_WIDTH (it
.f
);
9445 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9447 if (hscroll_relative_p
)
9448 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9451 wanted_x
= text_area_width
9452 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9455 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9459 if (hscroll_relative_p
)
9460 wanted_x
= text_area_width
* hscroll_step_rel
9463 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9466 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9468 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9470 /* Don't call Fset_window_hscroll if value hasn't
9471 changed because it will prevent redisplay
9473 if (XFASTINT (w
->hscroll
) != hscroll
)
9475 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9476 w
->hscroll
= make_number (hscroll
);
9485 /* Value is non-zero if hscroll of any leaf window has been changed. */
9490 /* Set hscroll so that cursor is visible and not inside horizontal
9491 scroll margins for all windows in the tree rooted at WINDOW. See
9492 also hscroll_window_tree above. Value is non-zero if any window's
9493 hscroll has been changed. If it has, desired matrices on the frame
9494 of WINDOW are cleared. */
9497 hscroll_windows (window
)
9502 if (automatic_hscrolling_p
)
9504 hscrolled_p
= hscroll_window_tree (window
);
9506 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9515 /************************************************************************
9517 ************************************************************************/
9519 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9520 to a non-zero value. This is sometimes handy to have in a debugger
9525 /* First and last unchanged row for try_window_id. */
9527 int debug_first_unchanged_at_end_vpos
;
9528 int debug_last_unchanged_at_beg_vpos
;
9530 /* Delta vpos and y. */
9532 int debug_dvpos
, debug_dy
;
9534 /* Delta in characters and bytes for try_window_id. */
9536 int debug_delta
, debug_delta_bytes
;
9538 /* Values of window_end_pos and window_end_vpos at the end of
9541 EMACS_INT debug_end_pos
, debug_end_vpos
;
9543 /* Append a string to W->desired_matrix->method. FMT is a printf
9544 format string. A1...A9 are a supplement for a variable-length
9545 argument list. If trace_redisplay_p is non-zero also printf the
9546 resulting string to stderr. */
9549 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9552 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9555 char *method
= w
->desired_matrix
->method
;
9556 int len
= strlen (method
);
9557 int size
= sizeof w
->desired_matrix
->method
;
9558 int remaining
= size
- len
- 1;
9560 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9561 if (len
&& remaining
)
9567 strncpy (method
+ len
, buffer
, remaining
);
9569 if (trace_redisplay_p
)
9570 fprintf (stderr
, "%p (%s): %s\n",
9572 ((BUFFERP (w
->buffer
)
9573 && STRINGP (XBUFFER (w
->buffer
)->name
))
9574 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9579 #endif /* GLYPH_DEBUG */
9582 /* Value is non-zero if all changes in window W, which displays
9583 current_buffer, are in the text between START and END. START is a
9584 buffer position, END is given as a distance from Z. Used in
9585 redisplay_internal for display optimization. */
9588 text_outside_line_unchanged_p (w
, start
, end
)
9592 int unchanged_p
= 1;
9594 /* If text or overlays have changed, see where. */
9595 if (XFASTINT (w
->last_modified
) < MODIFF
9596 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9598 /* Gap in the line? */
9599 if (GPT
< start
|| Z
- GPT
< end
)
9602 /* Changes start in front of the line, or end after it? */
9604 && (BEG_UNCHANGED
< start
- 1
9605 || END_UNCHANGED
< end
))
9608 /* If selective display, can't optimize if changes start at the
9609 beginning of the line. */
9611 && INTEGERP (current_buffer
->selective_display
)
9612 && XINT (current_buffer
->selective_display
) > 0
9613 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9616 /* If there are overlays at the start or end of the line, these
9617 may have overlay strings with newlines in them. A change at
9618 START, for instance, may actually concern the display of such
9619 overlay strings as well, and they are displayed on different
9620 lines. So, quickly rule out this case. (For the future, it
9621 might be desirable to implement something more telling than
9622 just BEG/END_UNCHANGED.) */
9625 if (BEG
+ BEG_UNCHANGED
== start
9626 && overlay_touches_p (start
))
9628 if (END_UNCHANGED
== end
9629 && overlay_touches_p (Z
- end
))
9638 /* Do a frame update, taking possible shortcuts into account. This is
9639 the main external entry point for redisplay.
9641 If the last redisplay displayed an echo area message and that message
9642 is no longer requested, we clear the echo area or bring back the
9643 mini-buffer if that is in use. */
9648 redisplay_internal (0);
9653 overlay_arrow_string_or_property (var
, pbitmap
)
9657 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9663 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9664 *pbitmap
= XINT (bitmap
);
9669 return Voverlay_arrow_string
;
9672 /* Return 1 if there are any overlay-arrows in current_buffer. */
9674 overlay_arrow_in_current_buffer_p ()
9678 for (vlist
= Voverlay_arrow_variable_list
;
9680 vlist
= XCDR (vlist
))
9682 Lisp_Object var
= XCAR (vlist
);
9687 val
= find_symbol_value (var
);
9689 && current_buffer
== XMARKER (val
)->buffer
)
9696 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9700 overlay_arrows_changed_p ()
9704 for (vlist
= Voverlay_arrow_variable_list
;
9706 vlist
= XCDR (vlist
))
9708 Lisp_Object var
= XCAR (vlist
);
9709 Lisp_Object val
, pstr
;
9713 val
= find_symbol_value (var
);
9716 if (! EQ (COERCE_MARKER (val
),
9717 Fget (var
, Qlast_arrow_position
))
9718 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9719 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9725 /* Mark overlay arrows to be updated on next redisplay. */
9728 update_overlay_arrows (up_to_date
)
9733 for (vlist
= Voverlay_arrow_variable_list
;
9735 vlist
= XCDR (vlist
))
9737 Lisp_Object var
= XCAR (vlist
);
9744 Lisp_Object val
= find_symbol_value (var
);
9745 Fput (var
, Qlast_arrow_position
,
9746 COERCE_MARKER (val
));
9747 Fput (var
, Qlast_arrow_string
,
9748 overlay_arrow_string_or_property (var
, 0));
9750 else if (up_to_date
< 0
9751 || !NILP (Fget (var
, Qlast_arrow_position
)))
9753 Fput (var
, Qlast_arrow_position
, Qt
);
9754 Fput (var
, Qlast_arrow_string
, Qt
);
9760 /* Return overlay arrow string to display at row.
9761 Return t if display as bitmap in left fringe.
9762 Return nil if no overlay arrow. */
9765 overlay_arrow_at_row (it
, row
, pbitmap
)
9767 struct glyph_row
*row
;
9772 for (vlist
= Voverlay_arrow_variable_list
;
9774 vlist
= XCDR (vlist
))
9776 Lisp_Object var
= XCAR (vlist
);
9782 val
= find_symbol_value (var
);
9785 && current_buffer
== XMARKER (val
)->buffer
9786 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9788 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9789 if (FRAME_WINDOW_P (it
->f
)
9790 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9802 /* Return 1 if point moved out of or into a composition. Otherwise
9803 return 0. PREV_BUF and PREV_PT are the last point buffer and
9804 position. BUF and PT are the current point buffer and position. */
9807 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9808 struct buffer
*prev_buf
, *buf
;
9815 XSETBUFFER (buffer
, buf
);
9816 /* Check a composition at the last point if point moved within the
9818 if (prev_buf
== buf
)
9821 /* Point didn't move. */
9824 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9825 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9826 && COMPOSITION_VALID_P (start
, end
, prop
)
9827 && start
< prev_pt
&& end
> prev_pt
)
9828 /* The last point was within the composition. Return 1 iff
9829 point moved out of the composition. */
9830 return (pt
<= start
|| pt
>= end
);
9833 /* Check a composition at the current point. */
9834 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9835 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9836 && COMPOSITION_VALID_P (start
, end
, prop
)
9837 && start
< pt
&& end
> pt
);
9841 /* Reconsider the setting of B->clip_changed which is displayed
9845 reconsider_clip_changes (w
, b
)
9850 && !NILP (w
->window_end_valid
)
9851 && w
->current_matrix
->buffer
== b
9852 && w
->current_matrix
->zv
== BUF_ZV (b
)
9853 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9854 b
->clip_changed
= 0;
9856 /* If display wasn't paused, and W is not a tool bar window, see if
9857 point has been moved into or out of a composition. In that case,
9858 we set b->clip_changed to 1 to force updating the screen. If
9859 b->clip_changed has already been set to 1, we can skip this
9861 if (!b
->clip_changed
9862 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9866 if (w
== XWINDOW (selected_window
))
9867 pt
= BUF_PT (current_buffer
);
9869 pt
= marker_position (w
->pointm
);
9871 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9872 || pt
!= XINT (w
->last_point
))
9873 && check_point_in_composition (w
->current_matrix
->buffer
,
9874 XINT (w
->last_point
),
9875 XBUFFER (w
->buffer
), pt
))
9876 b
->clip_changed
= 1;
9881 /* Select FRAME to forward the values of frame-local variables into C
9882 variables so that the redisplay routines can access those values
9886 select_frame_for_redisplay (frame
)
9889 Lisp_Object tail
, sym
, val
;
9890 Lisp_Object old
= selected_frame
;
9892 selected_frame
= frame
;
9894 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9895 if (CONSP (XCAR (tail
))
9896 && (sym
= XCAR (XCAR (tail
)),
9898 && (sym
= indirect_variable (sym
),
9899 val
= SYMBOL_VALUE (sym
),
9900 (BUFFER_LOCAL_VALUEP (val
)
9901 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9902 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9903 Fsymbol_value (sym
);
9905 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9906 if (CONSP (XCAR (tail
))
9907 && (sym
= XCAR (XCAR (tail
)),
9909 && (sym
= indirect_variable (sym
),
9910 val
= SYMBOL_VALUE (sym
),
9911 (BUFFER_LOCAL_VALUEP (val
)
9912 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9913 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9914 Fsymbol_value (sym
);
9918 #define STOP_POLLING \
9919 do { if (! polling_stopped_here) stop_polling (); \
9920 polling_stopped_here = 1; } while (0)
9922 #define RESUME_POLLING \
9923 do { if (polling_stopped_here) start_polling (); \
9924 polling_stopped_here = 0; } while (0)
9927 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9928 response to any user action; therefore, we should preserve the echo
9929 area. (Actually, our caller does that job.) Perhaps in the future
9930 avoid recentering windows if it is not necessary; currently that
9931 causes some problems. */
9934 redisplay_internal (preserve_echo_area
)
9935 int preserve_echo_area
;
9937 struct window
*w
= XWINDOW (selected_window
);
9938 struct frame
*f
= XFRAME (w
->frame
);
9940 int must_finish
= 0;
9941 struct text_pos tlbufpos
, tlendpos
;
9942 int number_of_visible_frames
;
9944 struct frame
*sf
= SELECTED_FRAME ();
9945 int polling_stopped_here
= 0;
9947 /* Non-zero means redisplay has to consider all windows on all
9948 frames. Zero means, only selected_window is considered. */
9949 int consider_all_windows_p
;
9951 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9953 /* No redisplay if running in batch mode or frame is not yet fully
9954 initialized, or redisplay is explicitly turned off by setting
9955 Vinhibit_redisplay. */
9957 || !NILP (Vinhibit_redisplay
)
9958 || !f
->glyphs_initialized_p
)
9961 /* The flag redisplay_performed_directly_p is set by
9962 direct_output_for_insert when it already did the whole screen
9963 update necessary. */
9964 if (redisplay_performed_directly_p
)
9966 redisplay_performed_directly_p
= 0;
9967 if (!hscroll_windows (selected_window
))
9971 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9972 if (popup_activated ())
9976 /* I don't think this happens but let's be paranoid. */
9980 /* Record a function that resets redisplaying_p to its old value
9981 when we leave this function. */
9982 count
= SPECPDL_INDEX ();
9983 record_unwind_protect (unwind_redisplay
,
9984 Fcons (make_number (redisplaying_p
), selected_frame
));
9986 specbind (Qinhibit_free_realized_faces
, Qnil
);
9990 reconsider_clip_changes (w
, current_buffer
);
9992 /* If new fonts have been loaded that make a glyph matrix adjustment
9993 necessary, do it. */
9994 if (fonts_changed_p
)
9996 adjust_glyphs (NULL
);
9997 ++windows_or_buffers_changed
;
9998 fonts_changed_p
= 0;
10001 /* If face_change_count is non-zero, init_iterator will free all
10002 realized faces, which includes the faces referenced from current
10003 matrices. So, we can't reuse current matrices in this case. */
10004 if (face_change_count
)
10005 ++windows_or_buffers_changed
;
10007 if (! FRAME_WINDOW_P (sf
)
10008 && previous_terminal_frame
!= sf
)
10010 /* Since frames on an ASCII terminal share the same display
10011 area, displaying a different frame means redisplay the whole
10013 windows_or_buffers_changed
++;
10014 SET_FRAME_GARBAGED (sf
);
10015 XSETFRAME (Vterminal_frame
, sf
);
10017 previous_terminal_frame
= sf
;
10019 /* Set the visible flags for all frames. Do this before checking
10020 for resized or garbaged frames; they want to know if their frames
10021 are visible. See the comment in frame.h for
10022 FRAME_SAMPLE_VISIBILITY. */
10024 Lisp_Object tail
, frame
;
10026 number_of_visible_frames
= 0;
10028 FOR_EACH_FRAME (tail
, frame
)
10030 struct frame
*f
= XFRAME (frame
);
10032 FRAME_SAMPLE_VISIBILITY (f
);
10033 if (FRAME_VISIBLE_P (f
))
10034 ++number_of_visible_frames
;
10035 clear_desired_matrices (f
);
10039 /* Notice any pending interrupt request to change frame size. */
10040 do_pending_window_change (1);
10042 /* Clear frames marked as garbaged. */
10043 if (frame_garbaged
)
10044 clear_garbaged_frames ();
10046 /* Build menubar and tool-bar items. */
10047 prepare_menu_bars ();
10049 if (windows_or_buffers_changed
)
10050 update_mode_lines
++;
10052 /* Detect case that we need to write or remove a star in the mode line. */
10053 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10055 w
->update_mode_line
= Qt
;
10056 if (buffer_shared
> 1)
10057 update_mode_lines
++;
10060 /* If %c is in the mode line, update it if needed. */
10061 if (!NILP (w
->column_number_displayed
)
10062 /* This alternative quickly identifies a common case
10063 where no change is needed. */
10064 && !(PT
== XFASTINT (w
->last_point
)
10065 && XFASTINT (w
->last_modified
) >= MODIFF
10066 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10067 && (XFASTINT (w
->column_number_displayed
)
10068 != (int) current_column ())) /* iftc */
10069 w
->update_mode_line
= Qt
;
10071 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10073 /* The variable buffer_shared is set in redisplay_window and
10074 indicates that we redisplay a buffer in different windows. See
10076 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10077 || cursor_type_changed
);
10079 /* If specs for an arrow have changed, do thorough redisplay
10080 to ensure we remove any arrow that should no longer exist. */
10081 if (overlay_arrows_changed_p ())
10082 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10084 /* Normally the message* functions will have already displayed and
10085 updated the echo area, but the frame may have been trashed, or
10086 the update may have been preempted, so display the echo area
10087 again here. Checking message_cleared_p captures the case that
10088 the echo area should be cleared. */
10089 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10090 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10091 || (message_cleared_p
10092 && minibuf_level
== 0
10093 /* If the mini-window is currently selected, this means the
10094 echo-area doesn't show through. */
10095 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10097 int window_height_changed_p
= echo_area_display (0);
10100 /* If we don't display the current message, don't clear the
10101 message_cleared_p flag, because, if we did, we wouldn't clear
10102 the echo area in the next redisplay which doesn't preserve
10104 if (!display_last_displayed_message_p
)
10105 message_cleared_p
= 0;
10107 if (fonts_changed_p
)
10109 else if (window_height_changed_p
)
10111 consider_all_windows_p
= 1;
10112 ++update_mode_lines
;
10113 ++windows_or_buffers_changed
;
10115 /* If window configuration was changed, frames may have been
10116 marked garbaged. Clear them or we will experience
10117 surprises wrt scrolling. */
10118 if (frame_garbaged
)
10119 clear_garbaged_frames ();
10122 else if (EQ (selected_window
, minibuf_window
)
10123 && (current_buffer
->clip_changed
10124 || XFASTINT (w
->last_modified
) < MODIFF
10125 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10126 && resize_mini_window (w
, 0))
10128 /* Resized active mini-window to fit the size of what it is
10129 showing if its contents might have changed. */
10131 consider_all_windows_p
= 1;
10132 ++windows_or_buffers_changed
;
10133 ++update_mode_lines
;
10135 /* If window configuration was changed, frames may have been
10136 marked garbaged. Clear them or we will experience
10137 surprises wrt scrolling. */
10138 if (frame_garbaged
)
10139 clear_garbaged_frames ();
10143 /* If showing the region, and mark has changed, we must redisplay
10144 the whole window. The assignment to this_line_start_pos prevents
10145 the optimization directly below this if-statement. */
10146 if (((!NILP (Vtransient_mark_mode
)
10147 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10148 != !NILP (w
->region_showing
))
10149 || (!NILP (w
->region_showing
)
10150 && !EQ (w
->region_showing
,
10151 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10152 CHARPOS (this_line_start_pos
) = 0;
10154 /* Optimize the case that only the line containing the cursor in the
10155 selected window has changed. Variables starting with this_ are
10156 set in display_line and record information about the line
10157 containing the cursor. */
10158 tlbufpos
= this_line_start_pos
;
10159 tlendpos
= this_line_end_pos
;
10160 if (!consider_all_windows_p
10161 && CHARPOS (tlbufpos
) > 0
10162 && NILP (w
->update_mode_line
)
10163 && !current_buffer
->clip_changed
10164 && !current_buffer
->prevent_redisplay_optimizations_p
10165 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10166 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10167 /* Make sure recorded data applies to current buffer, etc. */
10168 && this_line_buffer
== current_buffer
10169 && current_buffer
== XBUFFER (w
->buffer
)
10170 && NILP (w
->force_start
)
10171 && NILP (w
->optional_new_start
)
10172 /* Point must be on the line that we have info recorded about. */
10173 && PT
>= CHARPOS (tlbufpos
)
10174 && PT
<= Z
- CHARPOS (tlendpos
)
10175 /* All text outside that line, including its final newline,
10176 must be unchanged */
10177 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10178 CHARPOS (tlendpos
)))
10180 if (CHARPOS (tlbufpos
) > BEGV
10181 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10182 && (CHARPOS (tlbufpos
) == ZV
10183 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10184 /* Former continuation line has disappeared by becoming empty */
10186 else if (XFASTINT (w
->last_modified
) < MODIFF
10187 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10188 || MINI_WINDOW_P (w
))
10190 /* We have to handle the case of continuation around a
10191 wide-column character (See the comment in indent.c around
10194 For instance, in the following case:
10196 -------- Insert --------
10197 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10198 J_I_ ==> J_I_ `^^' are cursors.
10202 As we have to redraw the line above, we should goto cancel. */
10205 int line_height_before
= this_line_pixel_height
;
10207 /* Note that start_display will handle the case that the
10208 line starting at tlbufpos is a continuation lines. */
10209 start_display (&it
, w
, tlbufpos
);
10211 /* Implementation note: It this still necessary? */
10212 if (it
.current_x
!= this_line_start_x
)
10215 TRACE ((stderr
, "trying display optimization 1\n"));
10216 w
->cursor
.vpos
= -1;
10217 overlay_arrow_seen
= 0;
10218 it
.vpos
= this_line_vpos
;
10219 it
.current_y
= this_line_y
;
10220 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10221 display_line (&it
);
10223 /* If line contains point, is not continued,
10224 and ends at same distance from eob as before, we win */
10225 if (w
->cursor
.vpos
>= 0
10226 /* Line is not continued, otherwise this_line_start_pos
10227 would have been set to 0 in display_line. */
10228 && CHARPOS (this_line_start_pos
)
10229 /* Line ends as before. */
10230 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10231 /* Line has same height as before. Otherwise other lines
10232 would have to be shifted up or down. */
10233 && this_line_pixel_height
== line_height_before
)
10235 /* If this is not the window's last line, we must adjust
10236 the charstarts of the lines below. */
10237 if (it
.current_y
< it
.last_visible_y
)
10239 struct glyph_row
*row
10240 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10241 int delta
, delta_bytes
;
10243 if (Z
- CHARPOS (tlendpos
) == ZV
)
10245 /* This line ends at end of (accessible part of)
10246 buffer. There is no newline to count. */
10248 - CHARPOS (tlendpos
)
10249 - MATRIX_ROW_START_CHARPOS (row
));
10250 delta_bytes
= (Z_BYTE
10251 - BYTEPOS (tlendpos
)
10252 - MATRIX_ROW_START_BYTEPOS (row
));
10256 /* This line ends in a newline. Must take
10257 account of the newline and the rest of the
10258 text that follows. */
10260 - CHARPOS (tlendpos
)
10261 - MATRIX_ROW_START_CHARPOS (row
));
10262 delta_bytes
= (Z_BYTE
10263 - BYTEPOS (tlendpos
)
10264 - MATRIX_ROW_START_BYTEPOS (row
));
10267 increment_matrix_positions (w
->current_matrix
,
10268 this_line_vpos
+ 1,
10269 w
->current_matrix
->nrows
,
10270 delta
, delta_bytes
);
10273 /* If this row displays text now but previously didn't,
10274 or vice versa, w->window_end_vpos may have to be
10276 if ((it
.glyph_row
- 1)->displays_text_p
)
10278 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10279 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10281 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10282 && this_line_vpos
> 0)
10283 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10284 w
->window_end_valid
= Qnil
;
10286 /* Update hint: No need to try to scroll in update_window. */
10287 w
->desired_matrix
->no_scrolling_p
= 1;
10290 *w
->desired_matrix
->method
= 0;
10291 debug_method_add (w
, "optimization 1");
10293 #ifdef HAVE_WINDOW_SYSTEM
10294 update_window_fringes (w
, 0);
10301 else if (/* Cursor position hasn't changed. */
10302 PT
== XFASTINT (w
->last_point
)
10303 /* Make sure the cursor was last displayed
10304 in this window. Otherwise we have to reposition it. */
10305 && 0 <= w
->cursor
.vpos
10306 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10310 do_pending_window_change (1);
10312 /* We used to always goto end_of_redisplay here, but this
10313 isn't enough if we have a blinking cursor. */
10314 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10315 goto end_of_redisplay
;
10319 /* If highlighting the region, or if the cursor is in the echo area,
10320 then we can't just move the cursor. */
10321 else if (! (!NILP (Vtransient_mark_mode
)
10322 && !NILP (current_buffer
->mark_active
))
10323 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10324 || highlight_nonselected_windows
)
10325 && NILP (w
->region_showing
)
10326 && NILP (Vshow_trailing_whitespace
)
10327 && !cursor_in_echo_area
)
10330 struct glyph_row
*row
;
10332 /* Skip from tlbufpos to PT and see where it is. Note that
10333 PT may be in invisible text. If so, we will end at the
10334 next visible position. */
10335 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10336 NULL
, DEFAULT_FACE_ID
);
10337 it
.current_x
= this_line_start_x
;
10338 it
.current_y
= this_line_y
;
10339 it
.vpos
= this_line_vpos
;
10341 /* The call to move_it_to stops in front of PT, but
10342 moves over before-strings. */
10343 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10345 if (it
.vpos
== this_line_vpos
10346 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10349 xassert (this_line_vpos
== it
.vpos
);
10350 xassert (this_line_y
== it
.current_y
);
10351 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10353 *w
->desired_matrix
->method
= 0;
10354 debug_method_add (w
, "optimization 3");
10363 /* Text changed drastically or point moved off of line. */
10364 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10367 CHARPOS (this_line_start_pos
) = 0;
10368 consider_all_windows_p
|= buffer_shared
> 1;
10369 ++clear_face_cache_count
;
10370 #ifdef HAVE_WINDOW_SYSTEM
10371 ++clear_image_cache_count
;
10374 /* Build desired matrices, and update the display. If
10375 consider_all_windows_p is non-zero, do it for all windows on all
10376 frames. Otherwise do it for selected_window, only. */
10378 if (consider_all_windows_p
)
10380 Lisp_Object tail
, frame
;
10381 int i
, n
= 0, size
= 50;
10382 struct frame
**updated
10383 = (struct frame
**) alloca (size
* sizeof *updated
);
10385 /* Recompute # windows showing selected buffer. This will be
10386 incremented each time such a window is displayed. */
10389 FOR_EACH_FRAME (tail
, frame
)
10391 struct frame
*f
= XFRAME (frame
);
10393 if (FRAME_WINDOW_P (f
) || f
== sf
)
10395 if (! EQ (frame
, selected_frame
))
10396 /* Select the frame, for the sake of frame-local
10398 select_frame_for_redisplay (frame
);
10400 /* Mark all the scroll bars to be removed; we'll redeem
10401 the ones we want when we redisplay their windows. */
10402 if (condemn_scroll_bars_hook
)
10403 condemn_scroll_bars_hook (f
);
10405 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10406 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10408 /* Any scroll bars which redisplay_windows should have
10409 nuked should now go away. */
10410 if (judge_scroll_bars_hook
)
10411 judge_scroll_bars_hook (f
);
10413 /* If fonts changed, display again. */
10414 /* ??? rms: I suspect it is a mistake to jump all the way
10415 back to retry here. It should just retry this frame. */
10416 if (fonts_changed_p
)
10419 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10421 /* See if we have to hscroll. */
10422 if (hscroll_windows (f
->root_window
))
10425 /* Prevent various kinds of signals during display
10426 update. stdio is not robust about handling
10427 signals, which can cause an apparent I/O
10429 if (interrupt_input
)
10430 unrequest_sigio ();
10433 /* Update the display. */
10434 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10435 pause
|= update_frame (f
, 0, 0);
10436 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10443 int nbytes
= size
* sizeof *updated
;
10444 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10445 bcopy (updated
, p
, nbytes
);
10456 /* Do the mark_window_display_accurate after all windows have
10457 been redisplayed because this call resets flags in buffers
10458 which are needed for proper redisplay. */
10459 for (i
= 0; i
< n
; ++i
)
10461 struct frame
*f
= updated
[i
];
10462 mark_window_display_accurate (f
->root_window
, 1);
10463 if (frame_up_to_date_hook
)
10464 frame_up_to_date_hook (f
);
10468 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10470 Lisp_Object mini_window
;
10471 struct frame
*mini_frame
;
10473 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10474 /* Use list_of_error, not Qerror, so that
10475 we catch only errors and don't run the debugger. */
10476 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10478 redisplay_window_error
);
10480 /* Compare desired and current matrices, perform output. */
10483 /* If fonts changed, display again. */
10484 if (fonts_changed_p
)
10487 /* Prevent various kinds of signals during display update.
10488 stdio is not robust about handling signals,
10489 which can cause an apparent I/O error. */
10490 if (interrupt_input
)
10491 unrequest_sigio ();
10494 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10496 if (hscroll_windows (selected_window
))
10499 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10500 pause
= update_frame (sf
, 0, 0);
10503 /* We may have called echo_area_display at the top of this
10504 function. If the echo area is on another frame, that may
10505 have put text on a frame other than the selected one, so the
10506 above call to update_frame would not have caught it. Catch
10508 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10509 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10511 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10513 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10514 pause
|= update_frame (mini_frame
, 0, 0);
10515 if (!pause
&& hscroll_windows (mini_window
))
10520 /* If display was paused because of pending input, make sure we do a
10521 thorough update the next time. */
10524 /* Prevent the optimization at the beginning of
10525 redisplay_internal that tries a single-line update of the
10526 line containing the cursor in the selected window. */
10527 CHARPOS (this_line_start_pos
) = 0;
10529 /* Let the overlay arrow be updated the next time. */
10530 update_overlay_arrows (0);
10532 /* If we pause after scrolling, some rows in the current
10533 matrices of some windows are not valid. */
10534 if (!WINDOW_FULL_WIDTH_P (w
)
10535 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10536 update_mode_lines
= 1;
10540 if (!consider_all_windows_p
)
10542 /* This has already been done above if
10543 consider_all_windows_p is set. */
10544 mark_window_display_accurate_1 (w
, 1);
10546 /* Say overlay arrows are up to date. */
10547 update_overlay_arrows (1);
10549 if (frame_up_to_date_hook
!= 0)
10550 frame_up_to_date_hook (sf
);
10553 update_mode_lines
= 0;
10554 windows_or_buffers_changed
= 0;
10555 cursor_type_changed
= 0;
10558 /* Start SIGIO interrupts coming again. Having them off during the
10559 code above makes it less likely one will discard output, but not
10560 impossible, since there might be stuff in the system buffer here.
10561 But it is much hairier to try to do anything about that. */
10562 if (interrupt_input
)
10566 /* If a frame has become visible which was not before, redisplay
10567 again, so that we display it. Expose events for such a frame
10568 (which it gets when becoming visible) don't call the parts of
10569 redisplay constructing glyphs, so simply exposing a frame won't
10570 display anything in this case. So, we have to display these
10571 frames here explicitly. */
10574 Lisp_Object tail
, frame
;
10577 FOR_EACH_FRAME (tail
, frame
)
10579 int this_is_visible
= 0;
10581 if (XFRAME (frame
)->visible
)
10582 this_is_visible
= 1;
10583 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10584 if (XFRAME (frame
)->visible
)
10585 this_is_visible
= 1;
10587 if (this_is_visible
)
10591 if (new_count
!= number_of_visible_frames
)
10592 windows_or_buffers_changed
++;
10595 /* Change frame size now if a change is pending. */
10596 do_pending_window_change (1);
10598 /* If we just did a pending size change, or have additional
10599 visible frames, redisplay again. */
10600 if (windows_or_buffers_changed
&& !pause
)
10603 /* Clear the face cache eventually. */
10604 if (consider_all_windows_p
)
10606 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10608 clear_face_cache (0);
10609 clear_face_cache_count
= 0;
10611 #ifdef HAVE_WINDOW_SYSTEM
10612 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10614 Lisp_Object tail
, frame
;
10615 FOR_EACH_FRAME (tail
, frame
)
10617 struct frame
*f
= XFRAME (frame
);
10618 if (FRAME_WINDOW_P (f
))
10619 clear_image_cache (f
, 0);
10621 clear_image_cache_count
= 0;
10623 #endif /* HAVE_WINDOW_SYSTEM */
10627 unbind_to (count
, Qnil
);
10632 /* Redisplay, but leave alone any recent echo area message unless
10633 another message has been requested in its place.
10635 This is useful in situations where you need to redisplay but no
10636 user action has occurred, making it inappropriate for the message
10637 area to be cleared. See tracking_off and
10638 wait_reading_process_output for examples of these situations.
10640 FROM_WHERE is an integer saying from where this function was
10641 called. This is useful for debugging. */
10644 redisplay_preserve_echo_area (from_where
)
10647 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10649 if (!NILP (echo_area_buffer
[1]))
10651 /* We have a previously displayed message, but no current
10652 message. Redisplay the previous message. */
10653 display_last_displayed_message_p
= 1;
10654 redisplay_internal (1);
10655 display_last_displayed_message_p
= 0;
10658 redisplay_internal (1);
10660 if (rif
!= NULL
&& rif
->flush_display_optional
)
10661 rif
->flush_display_optional (NULL
);
10665 /* Function registered with record_unwind_protect in
10666 redisplay_internal. Reset redisplaying_p to the value it had
10667 before redisplay_internal was called, and clear
10668 prevent_freeing_realized_faces_p. It also selects the previously
10672 unwind_redisplay (val
)
10675 Lisp_Object old_redisplaying_p
, old_frame
;
10677 old_redisplaying_p
= XCAR (val
);
10678 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10679 old_frame
= XCDR (val
);
10680 if (! EQ (old_frame
, selected_frame
))
10681 select_frame_for_redisplay (old_frame
);
10686 /* Mark the display of window W as accurate or inaccurate. If
10687 ACCURATE_P is non-zero mark display of W as accurate. If
10688 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10689 redisplay_internal is called. */
10692 mark_window_display_accurate_1 (w
, accurate_p
)
10696 if (BUFFERP (w
->buffer
))
10698 struct buffer
*b
= XBUFFER (w
->buffer
);
10701 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10702 w
->last_overlay_modified
10703 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10705 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10709 b
->clip_changed
= 0;
10710 b
->prevent_redisplay_optimizations_p
= 0;
10712 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10713 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10714 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10715 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10717 w
->current_matrix
->buffer
= b
;
10718 w
->current_matrix
->begv
= BUF_BEGV (b
);
10719 w
->current_matrix
->zv
= BUF_ZV (b
);
10721 w
->last_cursor
= w
->cursor
;
10722 w
->last_cursor_off_p
= w
->cursor_off_p
;
10724 if (w
== XWINDOW (selected_window
))
10725 w
->last_point
= make_number (BUF_PT (b
));
10727 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10733 w
->window_end_valid
= w
->buffer
;
10734 #if 0 /* This is incorrect with variable-height lines. */
10735 xassert (XINT (w
->window_end_vpos
)
10736 < (WINDOW_TOTAL_LINES (w
)
10737 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10739 w
->update_mode_line
= Qnil
;
10744 /* Mark the display of windows in the window tree rooted at WINDOW as
10745 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10746 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10747 be redisplayed the next time redisplay_internal is called. */
10750 mark_window_display_accurate (window
, accurate_p
)
10751 Lisp_Object window
;
10756 for (; !NILP (window
); window
= w
->next
)
10758 w
= XWINDOW (window
);
10759 mark_window_display_accurate_1 (w
, accurate_p
);
10761 if (!NILP (w
->vchild
))
10762 mark_window_display_accurate (w
->vchild
, accurate_p
);
10763 if (!NILP (w
->hchild
))
10764 mark_window_display_accurate (w
->hchild
, accurate_p
);
10769 update_overlay_arrows (1);
10773 /* Force a thorough redisplay the next time by setting
10774 last_arrow_position and last_arrow_string to t, which is
10775 unequal to any useful value of Voverlay_arrow_... */
10776 update_overlay_arrows (-1);
10781 /* Return value in display table DP (Lisp_Char_Table *) for character
10782 C. Since a display table doesn't have any parent, we don't have to
10783 follow parent. Do not call this function directly but use the
10784 macro DISP_CHAR_VECTOR. */
10787 disp_char_vector (dp
, c
)
10788 struct Lisp_Char_Table
*dp
;
10794 if (SINGLE_BYTE_CHAR_P (c
))
10795 return (dp
->contents
[c
]);
10797 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10800 else if (code
[2] < 32)
10803 /* Here, the possible range of code[0] (== charset ID) is
10804 128..max_charset. Since the top level char table contains data
10805 for multibyte characters after 256th element, we must increment
10806 code[0] by 128 to get a correct index. */
10808 code
[3] = -1; /* anchor */
10810 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10812 val
= dp
->contents
[code
[i
]];
10813 if (!SUB_CHAR_TABLE_P (val
))
10814 return (NILP (val
) ? dp
->defalt
: val
);
10817 /* Here, val is a sub char table. We return the default value of
10819 return (dp
->defalt
);
10824 /***********************************************************************
10826 ***********************************************************************/
10828 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10831 redisplay_windows (window
)
10832 Lisp_Object window
;
10834 while (!NILP (window
))
10836 struct window
*w
= XWINDOW (window
);
10838 if (!NILP (w
->hchild
))
10839 redisplay_windows (w
->hchild
);
10840 else if (!NILP (w
->vchild
))
10841 redisplay_windows (w
->vchild
);
10844 displayed_buffer
= XBUFFER (w
->buffer
);
10845 /* Use list_of_error, not Qerror, so that
10846 we catch only errors and don't run the debugger. */
10847 internal_condition_case_1 (redisplay_window_0
, window
,
10849 redisplay_window_error
);
10857 redisplay_window_error ()
10859 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10864 redisplay_window_0 (window
)
10865 Lisp_Object window
;
10867 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10868 redisplay_window (window
, 0);
10873 redisplay_window_1 (window
)
10874 Lisp_Object window
;
10876 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10877 redisplay_window (window
, 1);
10882 /* Increment GLYPH until it reaches END or CONDITION fails while
10883 adding (GLYPH)->pixel_width to X. */
10885 #define SKIP_GLYPHS(glyph, end, x, condition) \
10888 (x) += (glyph)->pixel_width; \
10891 while ((glyph) < (end) && (condition))
10894 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10895 DELTA is the number of bytes by which positions recorded in ROW
10896 differ from current buffer positions. */
10899 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10901 struct glyph_row
*row
;
10902 struct glyph_matrix
*matrix
;
10903 int delta
, delta_bytes
, dy
, dvpos
;
10905 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10906 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10907 struct glyph
*cursor
= NULL
;
10908 /* The first glyph that starts a sequence of glyphs from string. */
10909 struct glyph
*string_start
;
10910 /* The X coordinate of string_start. */
10911 int string_start_x
;
10912 /* The last known character position. */
10913 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10914 /* The last known character position before string_start. */
10915 int string_before_pos
;
10918 int cursor_from_overlay_pos
= 0;
10919 int pt_old
= PT
- delta
;
10921 /* Skip over glyphs not having an object at the start of the row.
10922 These are special glyphs like truncation marks on terminal
10924 if (row
->displays_text_p
)
10926 && INTEGERP (glyph
->object
)
10927 && glyph
->charpos
< 0)
10929 x
+= glyph
->pixel_width
;
10933 string_start
= NULL
;
10935 && !INTEGERP (glyph
->object
)
10936 && (!BUFFERP (glyph
->object
)
10937 || (last_pos
= glyph
->charpos
) < pt_old
))
10939 if (! STRINGP (glyph
->object
))
10941 string_start
= NULL
;
10942 x
+= glyph
->pixel_width
;
10944 if (cursor_from_overlay_pos
10945 && last_pos
> cursor_from_overlay_pos
)
10947 cursor_from_overlay_pos
= 0;
10953 string_before_pos
= last_pos
;
10954 string_start
= glyph
;
10955 string_start_x
= x
;
10956 /* Skip all glyphs from string. */
10960 if ((cursor
== NULL
|| glyph
> cursor
)
10961 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
10962 Qcursor
, (glyph
)->object
))
10963 && (pos
= string_buffer_position (w
, glyph
->object
,
10964 string_before_pos
),
10965 (pos
== 0 /* From overlay */
10966 || pos
== pt_old
)))
10968 /* Estimate overlay buffer position from the buffer
10969 positions of the glyphs before and after the overlay.
10970 Add 1 to last_pos so that if point corresponds to the
10971 glyph right after the overlay, we still use a 'cursor'
10972 property found in that overlay. */
10973 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
10977 x
+= glyph
->pixel_width
;
10980 while (glyph
< end
&& STRINGP (glyph
->object
));
10984 if (cursor
!= NULL
)
10989 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
10991 /* Scan back over the ellipsis glyphs, decrementing positions. */
10992 while (glyph
> row
->glyphs
[TEXT_AREA
]
10993 && (glyph
- 1)->charpos
== last_pos
)
10994 glyph
--, x
-= glyph
->pixel_width
;
10995 /* That loop always goes one position too far,
10996 including the glyph before the ellipsis.
10997 So scan forward over that one. */
10998 x
+= glyph
->pixel_width
;
11001 else if (string_start
11002 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11004 /* We may have skipped over point because the previous glyphs
11005 are from string. As there's no easy way to know the
11006 character position of the current glyph, find the correct
11007 glyph on point by scanning from string_start again. */
11009 Lisp_Object string
;
11012 limit
= make_number (pt_old
+ 1);
11014 glyph
= string_start
;
11015 x
= string_start_x
;
11016 string
= glyph
->object
;
11017 pos
= string_buffer_position (w
, string
, string_before_pos
);
11018 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11019 because we always put cursor after overlay strings. */
11020 while (pos
== 0 && glyph
< end
)
11022 string
= glyph
->object
;
11023 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11025 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11028 while (glyph
< end
)
11030 pos
= XINT (Fnext_single_char_property_change
11031 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11034 /* Skip glyphs from the same string. */
11035 string
= glyph
->object
;
11036 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11037 /* Skip glyphs from an overlay. */
11039 && ! string_buffer_position (w
, glyph
->object
, pos
))
11041 string
= glyph
->object
;
11042 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11047 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11049 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11050 w
->cursor
.y
= row
->y
+ dy
;
11052 if (w
== XWINDOW (selected_window
))
11054 if (!row
->continued_p
11055 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11058 this_line_buffer
= XBUFFER (w
->buffer
);
11060 CHARPOS (this_line_start_pos
)
11061 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11062 BYTEPOS (this_line_start_pos
)
11063 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11065 CHARPOS (this_line_end_pos
)
11066 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11067 BYTEPOS (this_line_end_pos
)
11068 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11070 this_line_y
= w
->cursor
.y
;
11071 this_line_pixel_height
= row
->height
;
11072 this_line_vpos
= w
->cursor
.vpos
;
11073 this_line_start_x
= row
->x
;
11076 CHARPOS (this_line_start_pos
) = 0;
11081 /* Run window scroll functions, if any, for WINDOW with new window
11082 start STARTP. Sets the window start of WINDOW to that position.
11084 We assume that the window's buffer is really current. */
11086 static INLINE
struct text_pos
11087 run_window_scroll_functions (window
, startp
)
11088 Lisp_Object window
;
11089 struct text_pos startp
;
11091 struct window
*w
= XWINDOW (window
);
11092 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11094 if (current_buffer
!= XBUFFER (w
->buffer
))
11097 if (!NILP (Vwindow_scroll_functions
))
11099 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11100 make_number (CHARPOS (startp
)));
11101 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11102 /* In case the hook functions switch buffers. */
11103 if (current_buffer
!= XBUFFER (w
->buffer
))
11104 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11111 /* Make sure the line containing the cursor is fully visible.
11112 A value of 1 means there is nothing to be done.
11113 (Either the line is fully visible, or it cannot be made so,
11114 or we cannot tell.)
11116 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11117 is higher than window.
11119 A value of 0 means the caller should do scrolling
11120 as if point had gone off the screen. */
11123 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11127 struct glyph_matrix
*matrix
;
11128 struct glyph_row
*row
;
11131 if (!make_cursor_line_fully_visible_p
)
11134 /* It's not always possible to find the cursor, e.g, when a window
11135 is full of overlay strings. Don't do anything in that case. */
11136 if (w
->cursor
.vpos
< 0)
11139 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11140 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11142 /* If the cursor row is not partially visible, there's nothing to do. */
11143 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11146 /* If the row the cursor is in is taller than the window's height,
11147 it's not clear what to do, so do nothing. */
11148 window_height
= window_box_height (w
);
11149 if (row
->height
>= window_height
)
11151 if (!force_p
|| w
->vscroll
)
11157 /* This code used to try to scroll the window just enough to make
11158 the line visible. It returned 0 to say that the caller should
11159 allocate larger glyph matrices. */
11161 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11163 int dy
= row
->height
- row
->visible_height
;
11166 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11168 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11170 int dy
= - (row
->height
- row
->visible_height
);
11173 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11176 /* When we change the cursor y-position of the selected window,
11177 change this_line_y as well so that the display optimization for
11178 the cursor line of the selected window in redisplay_internal uses
11179 the correct y-position. */
11180 if (w
== XWINDOW (selected_window
))
11181 this_line_y
= w
->cursor
.y
;
11183 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11184 redisplay with larger matrices. */
11185 if (matrix
->nrows
< required_matrix_height (w
))
11187 fonts_changed_p
= 1;
11196 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11197 non-zero means only WINDOW is redisplayed in redisplay_internal.
11198 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11199 in redisplay_window to bring a partially visible line into view in
11200 the case that only the cursor has moved.
11202 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11203 last screen line's vertical height extends past the end of the screen.
11207 1 if scrolling succeeded
11209 0 if scrolling didn't find point.
11211 -1 if new fonts have been loaded so that we must interrupt
11212 redisplay, adjust glyph matrices, and try again. */
11218 SCROLLING_NEED_LARGER_MATRICES
11222 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11223 scroll_step
, temp_scroll_step
, last_line_misfit
)
11224 Lisp_Object window
;
11225 int just_this_one_p
;
11226 EMACS_INT scroll_conservatively
, scroll_step
;
11227 int temp_scroll_step
;
11228 int last_line_misfit
;
11230 struct window
*w
= XWINDOW (window
);
11231 struct frame
*f
= XFRAME (w
->frame
);
11232 struct text_pos scroll_margin_pos
;
11233 struct text_pos pos
;
11234 struct text_pos startp
;
11236 Lisp_Object window_end
;
11237 int this_scroll_margin
;
11241 int amount_to_scroll
= 0;
11242 Lisp_Object aggressive
;
11244 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11247 debug_method_add (w
, "try_scrolling");
11250 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11252 /* Compute scroll margin height in pixels. We scroll when point is
11253 within this distance from the top or bottom of the window. */
11254 if (scroll_margin
> 0)
11256 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11257 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11260 this_scroll_margin
= 0;
11262 /* Force scroll_conservatively to have a reasonable value so it doesn't
11263 cause an overflow while computing how much to scroll. */
11264 if (scroll_conservatively
)
11265 scroll_conservatively
= min (scroll_conservatively
,
11266 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11268 /* Compute how much we should try to scroll maximally to bring point
11270 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11271 scroll_max
= max (scroll_step
,
11272 max (scroll_conservatively
, temp_scroll_step
));
11273 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11274 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11275 /* We're trying to scroll because of aggressive scrolling
11276 but no scroll_step is set. Choose an arbitrary one. Maybe
11277 there should be a variable for this. */
11281 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11283 /* Decide whether we have to scroll down. Start at the window end
11284 and move this_scroll_margin up to find the position of the scroll
11286 window_end
= Fwindow_end (window
, Qt
);
11290 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11291 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11293 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11295 start_display (&it
, w
, scroll_margin_pos
);
11296 if (this_scroll_margin
)
11297 move_it_vertically_backward (&it
, this_scroll_margin
);
11298 if (extra_scroll_margin_lines
)
11299 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11300 scroll_margin_pos
= it
.current
.pos
;
11303 if (PT
>= CHARPOS (scroll_margin_pos
))
11307 /* Point is in the scroll margin at the bottom of the window, or
11308 below. Compute a new window start that makes point visible. */
11310 /* Compute the distance from the scroll margin to PT.
11311 Give up if the distance is greater than scroll_max. */
11312 start_display (&it
, w
, scroll_margin_pos
);
11314 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11315 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11317 /* To make point visible, we have to move the window start
11318 down so that the line the cursor is in is visible, which
11319 means we have to add in the height of the cursor line. */
11320 dy
= line_bottom_y (&it
) - y0
;
11322 if (dy
> scroll_max
)
11323 return SCROLLING_FAILED
;
11325 /* Move the window start down. If scrolling conservatively,
11326 move it just enough down to make point visible. If
11327 scroll_step is set, move it down by scroll_step. */
11328 start_display (&it
, w
, startp
);
11330 if (scroll_conservatively
)
11331 /* Set AMOUNT_TO_SCROLL to at least one line,
11332 and at most scroll_conservatively lines. */
11334 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11335 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11336 else if (scroll_step
|| temp_scroll_step
)
11337 amount_to_scroll
= scroll_max
;
11340 aggressive
= current_buffer
->scroll_up_aggressively
;
11341 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11342 if (NUMBERP (aggressive
))
11344 double float_amount
= XFLOATINT (aggressive
) * height
;
11345 amount_to_scroll
= float_amount
;
11346 if (amount_to_scroll
== 0 && float_amount
> 0)
11347 amount_to_scroll
= 1;
11351 if (amount_to_scroll
<= 0)
11352 return SCROLLING_FAILED
;
11354 /* If moving by amount_to_scroll leaves STARTP unchanged,
11355 move it down one screen line. */
11357 move_it_vertically (&it
, amount_to_scroll
);
11358 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11359 move_it_by_lines (&it
, 1, 1);
11360 startp
= it
.current
.pos
;
11364 /* See if point is inside the scroll margin at the top of the
11366 scroll_margin_pos
= startp
;
11367 if (this_scroll_margin
)
11369 start_display (&it
, w
, startp
);
11370 move_it_vertically (&it
, this_scroll_margin
);
11371 scroll_margin_pos
= it
.current
.pos
;
11374 if (PT
< CHARPOS (scroll_margin_pos
))
11376 /* Point is in the scroll margin at the top of the window or
11377 above what is displayed in the window. */
11380 /* Compute the vertical distance from PT to the scroll
11381 margin position. Give up if distance is greater than
11383 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11384 start_display (&it
, w
, pos
);
11386 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11387 it
.last_visible_y
, -1,
11388 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11389 dy
= it
.current_y
- y0
;
11390 if (dy
> scroll_max
)
11391 return SCROLLING_FAILED
;
11393 /* Compute new window start. */
11394 start_display (&it
, w
, startp
);
11396 if (scroll_conservatively
)
11398 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11399 else if (scroll_step
|| temp_scroll_step
)
11400 amount_to_scroll
= scroll_max
;
11403 aggressive
= current_buffer
->scroll_down_aggressively
;
11404 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11405 if (NUMBERP (aggressive
))
11407 double float_amount
= XFLOATINT (aggressive
) * height
;
11408 amount_to_scroll
= float_amount
;
11409 if (amount_to_scroll
== 0 && float_amount
> 0)
11410 amount_to_scroll
= 1;
11414 if (amount_to_scroll
<= 0)
11415 return SCROLLING_FAILED
;
11417 move_it_vertically_backward (&it
, amount_to_scroll
);
11418 startp
= it
.current
.pos
;
11422 /* Run window scroll functions. */
11423 startp
= run_window_scroll_functions (window
, startp
);
11425 /* Display the window. Give up if new fonts are loaded, or if point
11427 if (!try_window (window
, startp
))
11428 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11429 else if (w
->cursor
.vpos
< 0)
11431 clear_glyph_matrix (w
->desired_matrix
);
11432 rc
= SCROLLING_FAILED
;
11436 /* Maybe forget recorded base line for line number display. */
11437 if (!just_this_one_p
11438 || current_buffer
->clip_changed
11439 || BEG_UNCHANGED
< CHARPOS (startp
))
11440 w
->base_line_number
= Qnil
;
11442 /* If cursor ends up on a partially visible line,
11443 treat that as being off the bottom of the screen. */
11444 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11446 clear_glyph_matrix (w
->desired_matrix
);
11447 ++extra_scroll_margin_lines
;
11450 rc
= SCROLLING_SUCCESS
;
11457 /* Compute a suitable window start for window W if display of W starts
11458 on a continuation line. Value is non-zero if a new window start
11461 The new window start will be computed, based on W's width, starting
11462 from the start of the continued line. It is the start of the
11463 screen line with the minimum distance from the old start W->start. */
11466 compute_window_start_on_continuation_line (w
)
11469 struct text_pos pos
, start_pos
;
11470 int window_start_changed_p
= 0;
11472 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11474 /* If window start is on a continuation line... Window start may be
11475 < BEGV in case there's invisible text at the start of the
11476 buffer (M-x rmail, for example). */
11477 if (CHARPOS (start_pos
) > BEGV
11478 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11481 struct glyph_row
*row
;
11483 /* Handle the case that the window start is out of range. */
11484 if (CHARPOS (start_pos
) < BEGV
)
11485 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11486 else if (CHARPOS (start_pos
) > ZV
)
11487 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11489 /* Find the start of the continued line. This should be fast
11490 because scan_buffer is fast (newline cache). */
11491 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11492 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11493 row
, DEFAULT_FACE_ID
);
11494 reseat_at_previous_visible_line_start (&it
);
11496 /* If the line start is "too far" away from the window start,
11497 say it takes too much time to compute a new window start. */
11498 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11499 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11501 int min_distance
, distance
;
11503 /* Move forward by display lines to find the new window
11504 start. If window width was enlarged, the new start can
11505 be expected to be > the old start. If window width was
11506 decreased, the new window start will be < the old start.
11507 So, we're looking for the display line start with the
11508 minimum distance from the old window start. */
11509 pos
= it
.current
.pos
;
11510 min_distance
= INFINITY
;
11511 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11512 distance
< min_distance
)
11514 min_distance
= distance
;
11515 pos
= it
.current
.pos
;
11516 move_it_by_lines (&it
, 1, 0);
11519 /* Set the window start there. */
11520 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11521 window_start_changed_p
= 1;
11525 return window_start_changed_p
;
11529 /* Try cursor movement in case text has not changed in window WINDOW,
11530 with window start STARTP. Value is
11532 CURSOR_MOVEMENT_SUCCESS if successful
11534 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11536 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11537 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11538 we want to scroll as if scroll-step were set to 1. See the code.
11540 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11541 which case we have to abort this redisplay, and adjust matrices
11546 CURSOR_MOVEMENT_SUCCESS
,
11547 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11548 CURSOR_MOVEMENT_MUST_SCROLL
,
11549 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11553 try_cursor_movement (window
, startp
, scroll_step
)
11554 Lisp_Object window
;
11555 struct text_pos startp
;
11558 struct window
*w
= XWINDOW (window
);
11559 struct frame
*f
= XFRAME (w
->frame
);
11560 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11563 if (inhibit_try_cursor_movement
)
11567 /* Handle case where text has not changed, only point, and it has
11568 not moved off the frame. */
11569 if (/* Point may be in this window. */
11570 PT
>= CHARPOS (startp
)
11571 /* Selective display hasn't changed. */
11572 && !current_buffer
->clip_changed
11573 /* Function force-mode-line-update is used to force a thorough
11574 redisplay. It sets either windows_or_buffers_changed or
11575 update_mode_lines. So don't take a shortcut here for these
11577 && !update_mode_lines
11578 && !windows_or_buffers_changed
11579 && !cursor_type_changed
11580 /* Can't use this case if highlighting a region. When a
11581 region exists, cursor movement has to do more than just
11583 && !(!NILP (Vtransient_mark_mode
)
11584 && !NILP (current_buffer
->mark_active
))
11585 && NILP (w
->region_showing
)
11586 && NILP (Vshow_trailing_whitespace
)
11587 /* Right after splitting windows, last_point may be nil. */
11588 && INTEGERP (w
->last_point
)
11589 /* This code is not used for mini-buffer for the sake of the case
11590 of redisplaying to replace an echo area message; since in
11591 that case the mini-buffer contents per se are usually
11592 unchanged. This code is of no real use in the mini-buffer
11593 since the handling of this_line_start_pos, etc., in redisplay
11594 handles the same cases. */
11595 && !EQ (window
, minibuf_window
)
11596 /* When splitting windows or for new windows, it happens that
11597 redisplay is called with a nil window_end_vpos or one being
11598 larger than the window. This should really be fixed in
11599 window.c. I don't have this on my list, now, so we do
11600 approximately the same as the old redisplay code. --gerd. */
11601 && INTEGERP (w
->window_end_vpos
)
11602 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11603 && (FRAME_WINDOW_P (f
)
11604 || !overlay_arrow_in_current_buffer_p ()))
11606 int this_scroll_margin
, top_scroll_margin
;
11607 struct glyph_row
*row
= NULL
;
11610 debug_method_add (w
, "cursor movement");
11613 /* Scroll if point within this distance from the top or bottom
11614 of the window. This is a pixel value. */
11615 this_scroll_margin
= max (0, scroll_margin
);
11616 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11617 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11619 top_scroll_margin
= this_scroll_margin
;
11620 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11621 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11623 /* Start with the row the cursor was displayed during the last
11624 not paused redisplay. Give up if that row is not valid. */
11625 if (w
->last_cursor
.vpos
< 0
11626 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11627 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11630 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11631 if (row
->mode_line_p
)
11633 if (!row
->enabled_p
)
11634 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11637 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11640 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11642 if (PT
> XFASTINT (w
->last_point
))
11644 /* Point has moved forward. */
11645 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11646 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11648 xassert (row
->enabled_p
);
11652 /* The end position of a row equals the start position
11653 of the next row. If PT is there, we would rather
11654 display it in the next line. */
11655 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11656 && MATRIX_ROW_END_CHARPOS (row
) == PT
11657 && !cursor_row_p (w
, row
))
11660 /* If within the scroll margin, scroll. Note that
11661 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11662 the next line would be drawn, and that
11663 this_scroll_margin can be zero. */
11664 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11665 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11666 /* Line is completely visible last line in window
11667 and PT is to be set in the next line. */
11668 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11669 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11670 && !row
->ends_at_zv_p
11671 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11674 else if (PT
< XFASTINT (w
->last_point
))
11676 /* Cursor has to be moved backward. Note that PT >=
11677 CHARPOS (startp) because of the outer if-statement. */
11678 while (!row
->mode_line_p
11679 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11680 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11681 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11682 && (row
->y
> top_scroll_margin
11683 || CHARPOS (startp
) == BEGV
))
11685 xassert (row
->enabled_p
);
11689 /* Consider the following case: Window starts at BEGV,
11690 there is invisible, intangible text at BEGV, so that
11691 display starts at some point START > BEGV. It can
11692 happen that we are called with PT somewhere between
11693 BEGV and START. Try to handle that case. */
11694 if (row
< w
->current_matrix
->rows
11695 || row
->mode_line_p
)
11697 row
= w
->current_matrix
->rows
;
11698 if (row
->mode_line_p
)
11702 /* Due to newlines in overlay strings, we may have to
11703 skip forward over overlay strings. */
11704 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11705 && MATRIX_ROW_END_CHARPOS (row
) == PT
11706 && !cursor_row_p (w
, row
))
11709 /* If within the scroll margin, scroll. */
11710 if (row
->y
< top_scroll_margin
11711 && CHARPOS (startp
) != BEGV
)
11716 /* Cursor did not move. So don't scroll even if cursor line
11717 is partially visible, as it was so before. */
11718 rc
= CURSOR_MOVEMENT_SUCCESS
;
11721 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11722 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11724 /* if PT is not in the glyph row, give up. */
11725 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11727 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
11728 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11729 && make_cursor_line_fully_visible_p
)
11731 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11732 && !row
->ends_at_zv_p
11733 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11734 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11735 else if (row
->height
> window_box_height (w
))
11737 /* If we end up in a partially visible line, let's
11738 make it fully visible, except when it's taller
11739 than the window, in which case we can't do much
11742 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11746 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11747 if (!cursor_row_fully_visible_p (w
, 0, 1))
11748 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11750 rc
= CURSOR_MOVEMENT_SUCCESS
;
11754 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11757 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11758 rc
= CURSOR_MOVEMENT_SUCCESS
;
11767 set_vertical_scroll_bar (w
)
11770 int start
, end
, whole
;
11772 /* Calculate the start and end positions for the current window.
11773 At some point, it would be nice to choose between scrollbars
11774 which reflect the whole buffer size, with special markers
11775 indicating narrowing, and scrollbars which reflect only the
11778 Note that mini-buffers sometimes aren't displaying any text. */
11779 if (!MINI_WINDOW_P (w
)
11780 || (w
== XWINDOW (minibuf_window
)
11781 && NILP (echo_area_buffer
[0])))
11783 struct buffer
*buf
= XBUFFER (w
->buffer
);
11784 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11785 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11786 /* I don't think this is guaranteed to be right. For the
11787 moment, we'll pretend it is. */
11788 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11792 if (whole
< (end
- start
))
11793 whole
= end
- start
;
11796 start
= end
= whole
= 0;
11798 /* Indicate what this scroll bar ought to be displaying now. */
11799 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11803 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11804 selected_window is redisplayed.
11806 We can return without actually redisplaying the window if
11807 fonts_changed_p is nonzero. In that case, redisplay_internal will
11811 redisplay_window (window
, just_this_one_p
)
11812 Lisp_Object window
;
11813 int just_this_one_p
;
11815 struct window
*w
= XWINDOW (window
);
11816 struct frame
*f
= XFRAME (w
->frame
);
11817 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11818 struct buffer
*old
= current_buffer
;
11819 struct text_pos lpoint
, opoint
, startp
;
11820 int update_mode_line
;
11823 /* Record it now because it's overwritten. */
11824 int current_matrix_up_to_date_p
= 0;
11825 int used_current_matrix_p
= 0;
11826 /* This is less strict than current_matrix_up_to_date_p.
11827 It indictes that the buffer contents and narrowing are unchanged. */
11828 int buffer_unchanged_p
= 0;
11829 int temp_scroll_step
= 0;
11830 int count
= SPECPDL_INDEX ();
11832 int centering_position
= -1;
11833 int last_line_misfit
= 0;
11835 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11838 /* W must be a leaf window here. */
11839 xassert (!NILP (w
->buffer
));
11841 *w
->desired_matrix
->method
= 0;
11844 specbind (Qinhibit_point_motion_hooks
, Qt
);
11846 reconsider_clip_changes (w
, buffer
);
11848 /* Has the mode line to be updated? */
11849 update_mode_line
= (!NILP (w
->update_mode_line
)
11850 || update_mode_lines
11851 || buffer
->clip_changed
11852 || buffer
->prevent_redisplay_optimizations_p
);
11854 if (MINI_WINDOW_P (w
))
11856 if (w
== XWINDOW (echo_area_window
)
11857 && !NILP (echo_area_buffer
[0]))
11859 if (update_mode_line
)
11860 /* We may have to update a tty frame's menu bar or a
11861 tool-bar. Example `M-x C-h C-h C-g'. */
11862 goto finish_menu_bars
;
11864 /* We've already displayed the echo area glyphs in this window. */
11865 goto finish_scroll_bars
;
11867 else if ((w
!= XWINDOW (minibuf_window
)
11868 || minibuf_level
== 0)
11869 /* When buffer is nonempty, redisplay window normally. */
11870 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11871 /* Quail displays non-mini buffers in minibuffer window.
11872 In that case, redisplay the window normally. */
11873 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11875 /* W is a mini-buffer window, but it's not active, so clear
11877 int yb
= window_text_bottom_y (w
);
11878 struct glyph_row
*row
;
11881 for (y
= 0, row
= w
->desired_matrix
->rows
;
11883 y
+= row
->height
, ++row
)
11884 blank_row (w
, row
, y
);
11885 goto finish_scroll_bars
;
11888 clear_glyph_matrix (w
->desired_matrix
);
11891 /* Otherwise set up data on this window; select its buffer and point
11893 /* Really select the buffer, for the sake of buffer-local
11895 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11896 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11898 current_matrix_up_to_date_p
11899 = (!NILP (w
->window_end_valid
)
11900 && !current_buffer
->clip_changed
11901 && !current_buffer
->prevent_redisplay_optimizations_p
11902 && XFASTINT (w
->last_modified
) >= MODIFF
11903 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11906 = (!NILP (w
->window_end_valid
)
11907 && !current_buffer
->clip_changed
11908 && XFASTINT (w
->last_modified
) >= MODIFF
11909 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11911 /* When windows_or_buffers_changed is non-zero, we can't rely on
11912 the window end being valid, so set it to nil there. */
11913 if (windows_or_buffers_changed
)
11915 /* If window starts on a continuation line, maybe adjust the
11916 window start in case the window's width changed. */
11917 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11918 compute_window_start_on_continuation_line (w
);
11920 w
->window_end_valid
= Qnil
;
11923 /* Some sanity checks. */
11924 CHECK_WINDOW_END (w
);
11925 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11927 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11930 /* If %c is in mode line, update it if needed. */
11931 if (!NILP (w
->column_number_displayed
)
11932 /* This alternative quickly identifies a common case
11933 where no change is needed. */
11934 && !(PT
== XFASTINT (w
->last_point
)
11935 && XFASTINT (w
->last_modified
) >= MODIFF
11936 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11937 && (XFASTINT (w
->column_number_displayed
)
11938 != (int) current_column ())) /* iftc */
11939 update_mode_line
= 1;
11941 /* Count number of windows showing the selected buffer. An indirect
11942 buffer counts as its base buffer. */
11943 if (!just_this_one_p
)
11945 struct buffer
*current_base
, *window_base
;
11946 current_base
= current_buffer
;
11947 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11948 if (current_base
->base_buffer
)
11949 current_base
= current_base
->base_buffer
;
11950 if (window_base
->base_buffer
)
11951 window_base
= window_base
->base_buffer
;
11952 if (current_base
== window_base
)
11956 /* Point refers normally to the selected window. For any other
11957 window, set up appropriate value. */
11958 if (!EQ (window
, selected_window
))
11960 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11961 int new_pt_byte
= marker_byte_position (w
->pointm
);
11965 new_pt_byte
= BEGV_BYTE
;
11966 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11968 else if (new_pt
> (ZV
- 1))
11971 new_pt_byte
= ZV_BYTE
;
11972 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11975 /* We don't use SET_PT so that the point-motion hooks don't run. */
11976 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11979 /* If any of the character widths specified in the display table
11980 have changed, invalidate the width run cache. It's true that
11981 this may be a bit late to catch such changes, but the rest of
11982 redisplay goes (non-fatally) haywire when the display table is
11983 changed, so why should we worry about doing any better? */
11984 if (current_buffer
->width_run_cache
)
11986 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11988 if (! disptab_matches_widthtab (disptab
,
11989 XVECTOR (current_buffer
->width_table
)))
11991 invalidate_region_cache (current_buffer
,
11992 current_buffer
->width_run_cache
,
11994 recompute_width_table (current_buffer
, disptab
);
11998 /* If window-start is screwed up, choose a new one. */
11999 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12002 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12004 /* If someone specified a new starting point but did not insist,
12005 check whether it can be used. */
12006 if (!NILP (w
->optional_new_start
)
12007 && CHARPOS (startp
) >= BEGV
12008 && CHARPOS (startp
) <= ZV
)
12010 w
->optional_new_start
= Qnil
;
12011 start_display (&it
, w
, startp
);
12012 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12013 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12014 if (IT_CHARPOS (it
) == PT
)
12015 w
->force_start
= Qt
;
12016 /* IT may overshoot PT if text at PT is invisible. */
12017 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12018 w
->force_start
= Qt
;
12023 /* Handle case where place to start displaying has been specified,
12024 unless the specified location is outside the accessible range. */
12025 if (!NILP (w
->force_start
)
12026 || w
->frozen_window_start_p
)
12028 /* We set this later on if we have to adjust point. */
12031 w
->force_start
= Qnil
;
12033 w
->window_end_valid
= Qnil
;
12035 /* Forget any recorded base line for line number display. */
12036 if (!buffer_unchanged_p
)
12037 w
->base_line_number
= Qnil
;
12039 /* Redisplay the mode line. Select the buffer properly for that.
12040 Also, run the hook window-scroll-functions
12041 because we have scrolled. */
12042 /* Note, we do this after clearing force_start because
12043 if there's an error, it is better to forget about force_start
12044 than to get into an infinite loop calling the hook functions
12045 and having them get more errors. */
12046 if (!update_mode_line
12047 || ! NILP (Vwindow_scroll_functions
))
12049 update_mode_line
= 1;
12050 w
->update_mode_line
= Qt
;
12051 startp
= run_window_scroll_functions (window
, startp
);
12054 w
->last_modified
= make_number (0);
12055 w
->last_overlay_modified
= make_number (0);
12056 if (CHARPOS (startp
) < BEGV
)
12057 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12058 else if (CHARPOS (startp
) > ZV
)
12059 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12061 /* Redisplay, then check if cursor has been set during the
12062 redisplay. Give up if new fonts were loaded. */
12063 if (!try_window (window
, startp
))
12065 w
->force_start
= Qt
;
12066 clear_glyph_matrix (w
->desired_matrix
);
12067 goto need_larger_matrices
;
12070 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12072 /* If point does not appear, try to move point so it does
12073 appear. The desired matrix has been built above, so we
12074 can use it here. */
12075 new_vpos
= window_box_height (w
) / 2;
12078 if (!cursor_row_fully_visible_p (w
, 0, 0))
12080 /* Point does appear, but on a line partly visible at end of window.
12081 Move it back to a fully-visible line. */
12082 new_vpos
= window_box_height (w
);
12085 /* If we need to move point for either of the above reasons,
12086 now actually do it. */
12089 struct glyph_row
*row
;
12091 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12092 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12095 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12096 MATRIX_ROW_START_BYTEPOS (row
));
12098 if (w
!= XWINDOW (selected_window
))
12099 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12100 else if (current_buffer
== old
)
12101 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12103 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12105 /* If we are highlighting the region, then we just changed
12106 the region, so redisplay to show it. */
12107 if (!NILP (Vtransient_mark_mode
)
12108 && !NILP (current_buffer
->mark_active
))
12110 clear_glyph_matrix (w
->desired_matrix
);
12111 if (!try_window (window
, startp
))
12112 goto need_larger_matrices
;
12117 debug_method_add (w
, "forced window start");
12122 /* Handle case where text has not changed, only point, and it has
12123 not moved off the frame, and we are not retrying after hscroll.
12124 (current_matrix_up_to_date_p is nonzero when retrying.) */
12125 if (current_matrix_up_to_date_p
12126 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12127 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12131 case CURSOR_MOVEMENT_SUCCESS
:
12132 used_current_matrix_p
= 1;
12135 #if 0 /* try_cursor_movement never returns this value. */
12136 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12137 goto need_larger_matrices
;
12140 case CURSOR_MOVEMENT_MUST_SCROLL
:
12141 goto try_to_scroll
;
12147 /* If current starting point was originally the beginning of a line
12148 but no longer is, find a new starting point. */
12149 else if (!NILP (w
->start_at_line_beg
)
12150 && !(CHARPOS (startp
) <= BEGV
12151 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12154 debug_method_add (w
, "recenter 1");
12159 /* Try scrolling with try_window_id. Value is > 0 if update has
12160 been done, it is -1 if we know that the same window start will
12161 not work. It is 0 if unsuccessful for some other reason. */
12162 else if ((tem
= try_window_id (w
)) != 0)
12165 debug_method_add (w
, "try_window_id %d", tem
);
12168 if (fonts_changed_p
)
12169 goto need_larger_matrices
;
12173 /* Otherwise try_window_id has returned -1 which means that we
12174 don't want the alternative below this comment to execute. */
12176 else if (CHARPOS (startp
) >= BEGV
12177 && CHARPOS (startp
) <= ZV
12178 && PT
>= CHARPOS (startp
)
12179 && (CHARPOS (startp
) < ZV
12180 /* Avoid starting at end of buffer. */
12181 || CHARPOS (startp
) == BEGV
12182 || (XFASTINT (w
->last_modified
) >= MODIFF
12183 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12186 debug_method_add (w
, "same window start");
12189 /* Try to redisplay starting at same place as before.
12190 If point has not moved off frame, accept the results. */
12191 if (!current_matrix_up_to_date_p
12192 /* Don't use try_window_reusing_current_matrix in this case
12193 because a window scroll function can have changed the
12195 || !NILP (Vwindow_scroll_functions
)
12196 || MINI_WINDOW_P (w
)
12197 || !(used_current_matrix_p
12198 = try_window_reusing_current_matrix (w
)))
12200 IF_DEBUG (debug_method_add (w
, "1"));
12201 try_window (window
, startp
);
12204 if (fonts_changed_p
)
12205 goto need_larger_matrices
;
12207 if (w
->cursor
.vpos
>= 0)
12209 if (!just_this_one_p
12210 || current_buffer
->clip_changed
12211 || BEG_UNCHANGED
< CHARPOS (startp
))
12212 /* Forget any recorded base line for line number display. */
12213 w
->base_line_number
= Qnil
;
12215 if (!cursor_row_fully_visible_p (w
, 1, 0))
12217 clear_glyph_matrix (w
->desired_matrix
);
12218 last_line_misfit
= 1;
12220 /* Drop through and scroll. */
12225 clear_glyph_matrix (w
->desired_matrix
);
12230 w
->last_modified
= make_number (0);
12231 w
->last_overlay_modified
= make_number (0);
12233 /* Redisplay the mode line. Select the buffer properly for that. */
12234 if (!update_mode_line
)
12236 update_mode_line
= 1;
12237 w
->update_mode_line
= Qt
;
12240 /* Try to scroll by specified few lines. */
12241 if ((scroll_conservatively
12243 || temp_scroll_step
12244 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12245 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12246 && !current_buffer
->clip_changed
12247 && CHARPOS (startp
) >= BEGV
12248 && CHARPOS (startp
) <= ZV
)
12250 /* The function returns -1 if new fonts were loaded, 1 if
12251 successful, 0 if not successful. */
12252 int rc
= try_scrolling (window
, just_this_one_p
,
12253 scroll_conservatively
,
12255 temp_scroll_step
, last_line_misfit
);
12258 case SCROLLING_SUCCESS
:
12261 case SCROLLING_NEED_LARGER_MATRICES
:
12262 goto need_larger_matrices
;
12264 case SCROLLING_FAILED
:
12272 /* Finally, just choose place to start which centers point */
12275 if (centering_position
< 0)
12276 centering_position
= window_box_height (w
) / 2;
12279 debug_method_add (w
, "recenter");
12282 /* w->vscroll = 0; */
12284 /* Forget any previously recorded base line for line number display. */
12285 if (!buffer_unchanged_p
)
12286 w
->base_line_number
= Qnil
;
12288 /* Move backward half the height of the window. */
12289 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12290 it
.current_y
= it
.last_visible_y
;
12291 move_it_vertically_backward (&it
, centering_position
);
12292 xassert (IT_CHARPOS (it
) >= BEGV
);
12294 /* The function move_it_vertically_backward may move over more
12295 than the specified y-distance. If it->w is small, e.g. a
12296 mini-buffer window, we may end up in front of the window's
12297 display area. Start displaying at the start of the line
12298 containing PT in this case. */
12299 if (it
.current_y
<= 0)
12301 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12302 move_it_vertically_backward (&it
, 0);
12304 /* I think this assert is bogus if buffer contains
12305 invisible text or images. KFS. */
12306 xassert (IT_CHARPOS (it
) <= PT
);
12311 it
.current_x
= it
.hpos
= 0;
12313 /* Set startp here explicitly in case that helps avoid an infinite loop
12314 in case the window-scroll-functions functions get errors. */
12315 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12317 /* Run scroll hooks. */
12318 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12320 /* Redisplay the window. */
12321 if (!current_matrix_up_to_date_p
12322 || windows_or_buffers_changed
12323 || cursor_type_changed
12324 /* Don't use try_window_reusing_current_matrix in this case
12325 because it can have changed the buffer. */
12326 || !NILP (Vwindow_scroll_functions
)
12327 || !just_this_one_p
12328 || MINI_WINDOW_P (w
)
12329 || !(used_current_matrix_p
12330 = try_window_reusing_current_matrix (w
)))
12331 try_window (window
, startp
);
12333 /* If new fonts have been loaded (due to fontsets), give up. We
12334 have to start a new redisplay since we need to re-adjust glyph
12336 if (fonts_changed_p
)
12337 goto need_larger_matrices
;
12339 /* If cursor did not appear assume that the middle of the window is
12340 in the first line of the window. Do it again with the next line.
12341 (Imagine a window of height 100, displaying two lines of height
12342 60. Moving back 50 from it->last_visible_y will end in the first
12344 if (w
->cursor
.vpos
< 0)
12346 if (!NILP (w
->window_end_valid
)
12347 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12349 clear_glyph_matrix (w
->desired_matrix
);
12350 move_it_by_lines (&it
, 1, 0);
12351 try_window (window
, it
.current
.pos
);
12353 else if (PT
< IT_CHARPOS (it
))
12355 clear_glyph_matrix (w
->desired_matrix
);
12356 move_it_by_lines (&it
, -1, 0);
12357 try_window (window
, it
.current
.pos
);
12361 /* Not much we can do about it. */
12365 /* Consider the following case: Window starts at BEGV, there is
12366 invisible, intangible text at BEGV, so that display starts at
12367 some point START > BEGV. It can happen that we are called with
12368 PT somewhere between BEGV and START. Try to handle that case. */
12369 if (w
->cursor
.vpos
< 0)
12371 struct glyph_row
*row
= w
->current_matrix
->rows
;
12372 if (row
->mode_line_p
)
12374 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12377 if (!cursor_row_fully_visible_p (w
, 0, 0))
12379 /* If vscroll is enabled, disable it and try again. */
12383 clear_glyph_matrix (w
->desired_matrix
);
12387 /* If centering point failed to make the whole line visible,
12388 put point at the top instead. That has to make the whole line
12389 visible, if it can be done. */
12390 if (centering_position
== 0)
12393 clear_glyph_matrix (w
->desired_matrix
);
12394 centering_position
= 0;
12400 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12401 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12402 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12405 /* Display the mode line, if we must. */
12406 if ((update_mode_line
12407 /* If window not full width, must redo its mode line
12408 if (a) the window to its side is being redone and
12409 (b) we do a frame-based redisplay. This is a consequence
12410 of how inverted lines are drawn in frame-based redisplay. */
12411 || (!just_this_one_p
12412 && !FRAME_WINDOW_P (f
)
12413 && !WINDOW_FULL_WIDTH_P (w
))
12414 /* Line number to display. */
12415 || INTEGERP (w
->base_line_pos
)
12416 /* Column number is displayed and different from the one displayed. */
12417 || (!NILP (w
->column_number_displayed
)
12418 && (XFASTINT (w
->column_number_displayed
)
12419 != (int) current_column ()))) /* iftc */
12420 /* This means that the window has a mode line. */
12421 && (WINDOW_WANTS_MODELINE_P (w
)
12422 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12424 display_mode_lines (w
);
12426 /* If mode line height has changed, arrange for a thorough
12427 immediate redisplay using the correct mode line height. */
12428 if (WINDOW_WANTS_MODELINE_P (w
)
12429 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12431 fonts_changed_p
= 1;
12432 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12433 = DESIRED_MODE_LINE_HEIGHT (w
);
12436 /* If top line height has changed, arrange for a thorough
12437 immediate redisplay using the correct mode line height. */
12438 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12439 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12441 fonts_changed_p
= 1;
12442 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12443 = DESIRED_HEADER_LINE_HEIGHT (w
);
12446 if (fonts_changed_p
)
12447 goto need_larger_matrices
;
12450 if (!line_number_displayed
12451 && !BUFFERP (w
->base_line_pos
))
12453 w
->base_line_pos
= Qnil
;
12454 w
->base_line_number
= Qnil
;
12459 /* When we reach a frame's selected window, redo the frame's menu bar. */
12460 if (update_mode_line
12461 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12463 int redisplay_menu_p
= 0;
12464 int redisplay_tool_bar_p
= 0;
12466 if (FRAME_WINDOW_P (f
))
12468 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12469 || defined (USE_GTK)
12470 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12472 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12476 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12478 if (redisplay_menu_p
)
12479 display_menu_bar (w
);
12481 #ifdef HAVE_WINDOW_SYSTEM
12483 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12485 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12486 && (FRAME_TOOL_BAR_LINES (f
) > 0
12487 || auto_resize_tool_bars_p
);
12491 if (redisplay_tool_bar_p
)
12492 redisplay_tool_bar (f
);
12496 #ifdef HAVE_WINDOW_SYSTEM
12497 if (FRAME_WINDOW_P (f
)
12498 && update_window_fringes (w
, 0)
12499 && !just_this_one_p
12500 && (used_current_matrix_p
|| overlay_arrow_seen
)
12501 && !w
->pseudo_window_p
)
12505 if (draw_window_fringes (w
, 1))
12506 x_draw_vertical_border (w
);
12510 #endif /* HAVE_WINDOW_SYSTEM */
12512 /* We go to this label, with fonts_changed_p nonzero,
12513 if it is necessary to try again using larger glyph matrices.
12514 We have to redeem the scroll bar even in this case,
12515 because the loop in redisplay_internal expects that. */
12516 need_larger_matrices
:
12518 finish_scroll_bars
:
12520 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12522 /* Set the thumb's position and size. */
12523 set_vertical_scroll_bar (w
);
12525 /* Note that we actually used the scroll bar attached to this
12526 window, so it shouldn't be deleted at the end of redisplay. */
12527 redeem_scroll_bar_hook (w
);
12530 /* Restore current_buffer and value of point in it. */
12531 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12532 set_buffer_internal_1 (old
);
12533 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12535 unbind_to (count
, Qnil
);
12539 /* Build the complete desired matrix of WINDOW with a window start
12540 buffer position POS. Value is non-zero if successful. It is zero
12541 if fonts were loaded during redisplay which makes re-adjusting
12542 glyph matrices necessary. */
12545 try_window (window
, pos
)
12546 Lisp_Object window
;
12547 struct text_pos pos
;
12549 struct window
*w
= XWINDOW (window
);
12551 struct glyph_row
*last_text_row
= NULL
;
12553 /* Make POS the new window start. */
12554 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12556 /* Mark cursor position as unknown. No overlay arrow seen. */
12557 w
->cursor
.vpos
= -1;
12558 overlay_arrow_seen
= 0;
12560 /* Initialize iterator and info to start at POS. */
12561 start_display (&it
, w
, pos
);
12563 /* Display all lines of W. */
12564 while (it
.current_y
< it
.last_visible_y
)
12566 if (display_line (&it
))
12567 last_text_row
= it
.glyph_row
- 1;
12568 if (fonts_changed_p
)
12572 /* If bottom moved off end of frame, change mode line percentage. */
12573 if (XFASTINT (w
->window_end_pos
) <= 0
12574 && Z
!= IT_CHARPOS (it
))
12575 w
->update_mode_line
= Qt
;
12577 /* Set window_end_pos to the offset of the last character displayed
12578 on the window from the end of current_buffer. Set
12579 window_end_vpos to its row number. */
12582 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12583 w
->window_end_bytepos
12584 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12586 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12588 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12589 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12590 ->displays_text_p
);
12594 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12595 w
->window_end_pos
= make_number (Z
- ZV
);
12596 w
->window_end_vpos
= make_number (0);
12599 /* But that is not valid info until redisplay finishes. */
12600 w
->window_end_valid
= Qnil
;
12606 /************************************************************************
12607 Window redisplay reusing current matrix when buffer has not changed
12608 ************************************************************************/
12610 /* Try redisplay of window W showing an unchanged buffer with a
12611 different window start than the last time it was displayed by
12612 reusing its current matrix. Value is non-zero if successful.
12613 W->start is the new window start. */
12616 try_window_reusing_current_matrix (w
)
12619 struct frame
*f
= XFRAME (w
->frame
);
12620 struct glyph_row
*row
, *bottom_row
;
12623 struct text_pos start
, new_start
;
12624 int nrows_scrolled
, i
;
12625 struct glyph_row
*last_text_row
;
12626 struct glyph_row
*last_reused_text_row
;
12627 struct glyph_row
*start_row
;
12628 int start_vpos
, min_y
, max_y
;
12631 if (inhibit_try_window_reusing
)
12635 if (/* This function doesn't handle terminal frames. */
12636 !FRAME_WINDOW_P (f
)
12637 /* Don't try to reuse the display if windows have been split
12639 || windows_or_buffers_changed
12640 || cursor_type_changed
)
12643 /* Can't do this if region may have changed. */
12644 if ((!NILP (Vtransient_mark_mode
)
12645 && !NILP (current_buffer
->mark_active
))
12646 || !NILP (w
->region_showing
)
12647 || !NILP (Vshow_trailing_whitespace
))
12650 /* If top-line visibility has changed, give up. */
12651 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12652 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12655 /* Give up if old or new display is scrolled vertically. We could
12656 make this function handle this, but right now it doesn't. */
12657 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12658 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12661 /* The variable new_start now holds the new window start. The old
12662 start `start' can be determined from the current matrix. */
12663 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12664 start
= start_row
->start
.pos
;
12665 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12667 /* Clear the desired matrix for the display below. */
12668 clear_glyph_matrix (w
->desired_matrix
);
12670 if (CHARPOS (new_start
) <= CHARPOS (start
))
12674 /* Don't use this method if the display starts with an ellipsis
12675 displayed for invisible text. It's not easy to handle that case
12676 below, and it's certainly not worth the effort since this is
12677 not a frequent case. */
12678 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12681 IF_DEBUG (debug_method_add (w
, "twu1"));
12683 /* Display up to a row that can be reused. The variable
12684 last_text_row is set to the last row displayed that displays
12685 text. Note that it.vpos == 0 if or if not there is a
12686 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12687 start_display (&it
, w
, new_start
);
12688 first_row_y
= it
.current_y
;
12689 w
->cursor
.vpos
= -1;
12690 last_text_row
= last_reused_text_row
= NULL
;
12692 while (it
.current_y
< it
.last_visible_y
12693 && !fonts_changed_p
)
12695 /* If we have reached into the characters in the START row,
12696 that means the line boundaries have changed. So we
12697 can't start copying with the row START. Maybe it will
12698 work to start copying with the following row. */
12699 while (IT_CHARPOS (it
) > CHARPOS (start
))
12701 /* Advance to the next row as the "start". */
12703 start
= start_row
->start
.pos
;
12704 /* If there are no more rows to try, or just one, give up. */
12705 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12706 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12707 || CHARPOS (start
) == ZV
)
12709 clear_glyph_matrix (w
->desired_matrix
);
12713 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12715 /* If we have reached alignment,
12716 we can copy the rest of the rows. */
12717 if (IT_CHARPOS (it
) == CHARPOS (start
))
12720 if (display_line (&it
))
12721 last_text_row
= it
.glyph_row
- 1;
12724 /* A value of current_y < last_visible_y means that we stopped
12725 at the previous window start, which in turn means that we
12726 have at least one reusable row. */
12727 if (it
.current_y
< it
.last_visible_y
)
12729 /* IT.vpos always starts from 0; it counts text lines. */
12730 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12732 /* Find PT if not already found in the lines displayed. */
12733 if (w
->cursor
.vpos
< 0)
12735 int dy
= it
.current_y
- start_row
->y
;
12737 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12738 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12740 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12741 dy
, nrows_scrolled
);
12744 clear_glyph_matrix (w
->desired_matrix
);
12749 /* Scroll the display. Do it before the current matrix is
12750 changed. The problem here is that update has not yet
12751 run, i.e. part of the current matrix is not up to date.
12752 scroll_run_hook will clear the cursor, and use the
12753 current matrix to get the height of the row the cursor is
12755 run
.current_y
= start_row
->y
;
12756 run
.desired_y
= it
.current_y
;
12757 run
.height
= it
.last_visible_y
- it
.current_y
;
12759 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12762 rif
->update_window_begin_hook (w
);
12763 rif
->clear_window_mouse_face (w
);
12764 rif
->scroll_run_hook (w
, &run
);
12765 rif
->update_window_end_hook (w
, 0, 0);
12769 /* Shift current matrix down by nrows_scrolled lines. */
12770 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12771 rotate_matrix (w
->current_matrix
,
12773 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12776 /* Disable lines that must be updated. */
12777 for (i
= 0; i
< it
.vpos
; ++i
)
12778 (start_row
+ i
)->enabled_p
= 0;
12780 /* Re-compute Y positions. */
12781 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12782 max_y
= it
.last_visible_y
;
12783 for (row
= start_row
+ nrows_scrolled
;
12787 row
->y
= it
.current_y
;
12788 row
->visible_height
= row
->height
;
12790 if (row
->y
< min_y
)
12791 row
->visible_height
-= min_y
- row
->y
;
12792 if (row
->y
+ row
->height
> max_y
)
12793 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12794 row
->redraw_fringe_bitmaps_p
= 1;
12796 it
.current_y
+= row
->height
;
12798 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12799 last_reused_text_row
= row
;
12800 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12804 /* Disable lines in the current matrix which are now
12805 below the window. */
12806 for (++row
; row
< bottom_row
; ++row
)
12807 row
->enabled_p
= 0;
12810 /* Update window_end_pos etc.; last_reused_text_row is the last
12811 reused row from the current matrix containing text, if any.
12812 The value of last_text_row is the last displayed line
12813 containing text. */
12814 if (last_reused_text_row
)
12816 w
->window_end_bytepos
12817 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12819 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12821 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12822 w
->current_matrix
));
12824 else if (last_text_row
)
12826 w
->window_end_bytepos
12827 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12829 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12831 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12835 /* This window must be completely empty. */
12836 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12837 w
->window_end_pos
= make_number (Z
- ZV
);
12838 w
->window_end_vpos
= make_number (0);
12840 w
->window_end_valid
= Qnil
;
12842 /* Update hint: don't try scrolling again in update_window. */
12843 w
->desired_matrix
->no_scrolling_p
= 1;
12846 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12850 else if (CHARPOS (new_start
) > CHARPOS (start
))
12852 struct glyph_row
*pt_row
, *row
;
12853 struct glyph_row
*first_reusable_row
;
12854 struct glyph_row
*first_row_to_display
;
12856 int yb
= window_text_bottom_y (w
);
12858 /* Find the row starting at new_start, if there is one. Don't
12859 reuse a partially visible line at the end. */
12860 first_reusable_row
= start_row
;
12861 while (first_reusable_row
->enabled_p
12862 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12863 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12864 < CHARPOS (new_start
)))
12865 ++first_reusable_row
;
12867 /* Give up if there is no row to reuse. */
12868 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12869 || !first_reusable_row
->enabled_p
12870 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12871 != CHARPOS (new_start
)))
12874 /* We can reuse fully visible rows beginning with
12875 first_reusable_row to the end of the window. Set
12876 first_row_to_display to the first row that cannot be reused.
12877 Set pt_row to the row containing point, if there is any. */
12879 for (first_row_to_display
= first_reusable_row
;
12880 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12881 ++first_row_to_display
)
12883 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12884 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12885 pt_row
= first_row_to_display
;
12888 /* Start displaying at the start of first_row_to_display. */
12889 xassert (first_row_to_display
->y
< yb
);
12890 init_to_row_start (&it
, w
, first_row_to_display
);
12892 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12894 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12896 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12897 + WINDOW_HEADER_LINE_HEIGHT (w
));
12899 /* Display lines beginning with first_row_to_display in the
12900 desired matrix. Set last_text_row to the last row displayed
12901 that displays text. */
12902 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12903 if (pt_row
== NULL
)
12904 w
->cursor
.vpos
= -1;
12905 last_text_row
= NULL
;
12906 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12907 if (display_line (&it
))
12908 last_text_row
= it
.glyph_row
- 1;
12910 /* Give up If point isn't in a row displayed or reused. */
12911 if (w
->cursor
.vpos
< 0)
12913 clear_glyph_matrix (w
->desired_matrix
);
12917 /* If point is in a reused row, adjust y and vpos of the cursor
12921 w
->cursor
.vpos
-= nrows_scrolled
;
12922 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
12925 /* Scroll the display. */
12926 run
.current_y
= first_reusable_row
->y
;
12927 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12928 run
.height
= it
.last_visible_y
- run
.current_y
;
12929 dy
= run
.current_y
- run
.desired_y
;
12934 rif
->update_window_begin_hook (w
);
12935 rif
->clear_window_mouse_face (w
);
12936 rif
->scroll_run_hook (w
, &run
);
12937 rif
->update_window_end_hook (w
, 0, 0);
12941 /* Adjust Y positions of reused rows. */
12942 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12943 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12944 max_y
= it
.last_visible_y
;
12945 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12948 row
->visible_height
= row
->height
;
12949 if (row
->y
< min_y
)
12950 row
->visible_height
-= min_y
- row
->y
;
12951 if (row
->y
+ row
->height
> max_y
)
12952 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12953 row
->redraw_fringe_bitmaps_p
= 1;
12956 /* Scroll the current matrix. */
12957 xassert (nrows_scrolled
> 0);
12958 rotate_matrix (w
->current_matrix
,
12960 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12963 /* Disable rows not reused. */
12964 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12965 row
->enabled_p
= 0;
12967 /* Point may have moved to a different line, so we cannot assume that
12968 the previous cursor position is valid; locate the correct row. */
12971 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12972 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
12976 w
->cursor
.y
= row
->y
;
12978 if (row
< bottom_row
)
12980 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
12981 while (glyph
->charpos
< PT
)
12984 w
->cursor
.x
+= glyph
->pixel_width
;
12990 /* Adjust window end. A null value of last_text_row means that
12991 the window end is in reused rows which in turn means that
12992 only its vpos can have changed. */
12995 w
->window_end_bytepos
12996 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12998 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13000 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13005 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13008 w
->window_end_valid
= Qnil
;
13009 w
->desired_matrix
->no_scrolling_p
= 1;
13012 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13022 /************************************************************************
13023 Window redisplay reusing current matrix when buffer has changed
13024 ************************************************************************/
13026 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13027 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13029 static struct glyph_row
*
13030 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13031 struct glyph_row
*));
13034 /* Return the last row in MATRIX displaying text. If row START is
13035 non-null, start searching with that row. IT gives the dimensions
13036 of the display. Value is null if matrix is empty; otherwise it is
13037 a pointer to the row found. */
13039 static struct glyph_row
*
13040 find_last_row_displaying_text (matrix
, it
, start
)
13041 struct glyph_matrix
*matrix
;
13043 struct glyph_row
*start
;
13045 struct glyph_row
*row
, *row_found
;
13047 /* Set row_found to the last row in IT->w's current matrix
13048 displaying text. The loop looks funny but think of partially
13051 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13052 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13054 xassert (row
->enabled_p
);
13056 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13065 /* Return the last row in the current matrix of W that is not affected
13066 by changes at the start of current_buffer that occurred since W's
13067 current matrix was built. Value is null if no such row exists.
13069 BEG_UNCHANGED us the number of characters unchanged at the start of
13070 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13071 first changed character in current_buffer. Characters at positions <
13072 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13073 when the current matrix was built. */
13075 static struct glyph_row
*
13076 find_last_unchanged_at_beg_row (w
)
13079 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13080 struct glyph_row
*row
;
13081 struct glyph_row
*row_found
= NULL
;
13082 int yb
= window_text_bottom_y (w
);
13084 /* Find the last row displaying unchanged text. */
13085 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13086 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13087 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13089 if (/* If row ends before first_changed_pos, it is unchanged,
13090 except in some case. */
13091 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13092 /* When row ends in ZV and we write at ZV it is not
13094 && !row
->ends_at_zv_p
13095 /* When first_changed_pos is the end of a continued line,
13096 row is not unchanged because it may be no longer
13098 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13099 && (row
->continued_p
13100 || row
->exact_window_width_line_p
)))
13103 /* Stop if last visible row. */
13104 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13114 /* Find the first glyph row in the current matrix of W that is not
13115 affected by changes at the end of current_buffer since the
13116 time W's current matrix was built.
13118 Return in *DELTA the number of chars by which buffer positions in
13119 unchanged text at the end of current_buffer must be adjusted.
13121 Return in *DELTA_BYTES the corresponding number of bytes.
13123 Value is null if no such row exists, i.e. all rows are affected by
13126 static struct glyph_row
*
13127 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13129 int *delta
, *delta_bytes
;
13131 struct glyph_row
*row
;
13132 struct glyph_row
*row_found
= NULL
;
13134 *delta
= *delta_bytes
= 0;
13136 /* Display must not have been paused, otherwise the current matrix
13137 is not up to date. */
13138 if (NILP (w
->window_end_valid
))
13141 /* A value of window_end_pos >= END_UNCHANGED means that the window
13142 end is in the range of changed text. If so, there is no
13143 unchanged row at the end of W's current matrix. */
13144 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13147 /* Set row to the last row in W's current matrix displaying text. */
13148 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13150 /* If matrix is entirely empty, no unchanged row exists. */
13151 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13153 /* The value of row is the last glyph row in the matrix having a
13154 meaningful buffer position in it. The end position of row
13155 corresponds to window_end_pos. This allows us to translate
13156 buffer positions in the current matrix to current buffer
13157 positions for characters not in changed text. */
13158 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13159 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13160 int last_unchanged_pos
, last_unchanged_pos_old
;
13161 struct glyph_row
*first_text_row
13162 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13164 *delta
= Z
- Z_old
;
13165 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13167 /* Set last_unchanged_pos to the buffer position of the last
13168 character in the buffer that has not been changed. Z is the
13169 index + 1 of the last character in current_buffer, i.e. by
13170 subtracting END_UNCHANGED we get the index of the last
13171 unchanged character, and we have to add BEG to get its buffer
13173 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13174 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13176 /* Search backward from ROW for a row displaying a line that
13177 starts at a minimum position >= last_unchanged_pos_old. */
13178 for (; row
> first_text_row
; --row
)
13180 /* This used to abort, but it can happen.
13181 It is ok to just stop the search instead here. KFS. */
13182 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13185 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13190 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13197 /* Make sure that glyph rows in the current matrix of window W
13198 reference the same glyph memory as corresponding rows in the
13199 frame's frame matrix. This function is called after scrolling W's
13200 current matrix on a terminal frame in try_window_id and
13201 try_window_reusing_current_matrix. */
13204 sync_frame_with_window_matrix_rows (w
)
13207 struct frame
*f
= XFRAME (w
->frame
);
13208 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13210 /* Preconditions: W must be a leaf window and full-width. Its frame
13211 must have a frame matrix. */
13212 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13213 xassert (WINDOW_FULL_WIDTH_P (w
));
13214 xassert (!FRAME_WINDOW_P (f
));
13216 /* If W is a full-width window, glyph pointers in W's current matrix
13217 have, by definition, to be the same as glyph pointers in the
13218 corresponding frame matrix. Note that frame matrices have no
13219 marginal areas (see build_frame_matrix). */
13220 window_row
= w
->current_matrix
->rows
;
13221 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13222 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13223 while (window_row
< window_row_end
)
13225 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13226 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13228 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13229 frame_row
->glyphs
[TEXT_AREA
] = start
;
13230 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13231 frame_row
->glyphs
[LAST_AREA
] = end
;
13233 /* Disable frame rows whose corresponding window rows have
13234 been disabled in try_window_id. */
13235 if (!window_row
->enabled_p
)
13236 frame_row
->enabled_p
= 0;
13238 ++window_row
, ++frame_row
;
13243 /* Find the glyph row in window W containing CHARPOS. Consider all
13244 rows between START and END (not inclusive). END null means search
13245 all rows to the end of the display area of W. Value is the row
13246 containing CHARPOS or null. */
13249 row_containing_pos (w
, charpos
, start
, end
, dy
)
13252 struct glyph_row
*start
, *end
;
13255 struct glyph_row
*row
= start
;
13258 /* If we happen to start on a header-line, skip that. */
13259 if (row
->mode_line_p
)
13262 if ((end
&& row
>= end
) || !row
->enabled_p
)
13265 last_y
= window_text_bottom_y (w
) - dy
;
13269 /* Give up if we have gone too far. */
13270 if (end
&& row
>= end
)
13272 /* This formerly returned if they were equal.
13273 I think that both quantities are of a "last plus one" type;
13274 if so, when they are equal, the row is within the screen. -- rms. */
13275 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13278 /* If it is in this row, return this row. */
13279 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13280 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13281 /* The end position of a row equals the start
13282 position of the next row. If CHARPOS is there, we
13283 would rather display it in the next line, except
13284 when this line ends in ZV. */
13285 && !row
->ends_at_zv_p
13286 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13287 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13294 /* Try to redisplay window W by reusing its existing display. W's
13295 current matrix must be up to date when this function is called,
13296 i.e. window_end_valid must not be nil.
13300 1 if display has been updated
13301 0 if otherwise unsuccessful
13302 -1 if redisplay with same window start is known not to succeed
13304 The following steps are performed:
13306 1. Find the last row in the current matrix of W that is not
13307 affected by changes at the start of current_buffer. If no such row
13310 2. Find the first row in W's current matrix that is not affected by
13311 changes at the end of current_buffer. Maybe there is no such row.
13313 3. Display lines beginning with the row + 1 found in step 1 to the
13314 row found in step 2 or, if step 2 didn't find a row, to the end of
13317 4. If cursor is not known to appear on the window, give up.
13319 5. If display stopped at the row found in step 2, scroll the
13320 display and current matrix as needed.
13322 6. Maybe display some lines at the end of W, if we must. This can
13323 happen under various circumstances, like a partially visible line
13324 becoming fully visible, or because newly displayed lines are displayed
13325 in smaller font sizes.
13327 7. Update W's window end information. */
13333 struct frame
*f
= XFRAME (w
->frame
);
13334 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13335 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13336 struct glyph_row
*last_unchanged_at_beg_row
;
13337 struct glyph_row
*first_unchanged_at_end_row
;
13338 struct glyph_row
*row
;
13339 struct glyph_row
*bottom_row
;
13342 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13343 struct text_pos start_pos
;
13345 int first_unchanged_at_end_vpos
= 0;
13346 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13347 struct text_pos start
;
13348 int first_changed_charpos
, last_changed_charpos
;
13351 if (inhibit_try_window_id
)
13355 /* This is handy for debugging. */
13357 #define GIVE_UP(X) \
13359 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13363 #define GIVE_UP(X) return 0
13366 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13368 /* Don't use this for mini-windows because these can show
13369 messages and mini-buffers, and we don't handle that here. */
13370 if (MINI_WINDOW_P (w
))
13373 /* This flag is used to prevent redisplay optimizations. */
13374 if (windows_or_buffers_changed
|| cursor_type_changed
)
13377 /* Verify that narrowing has not changed.
13378 Also verify that we were not told to prevent redisplay optimizations.
13379 It would be nice to further
13380 reduce the number of cases where this prevents try_window_id. */
13381 if (current_buffer
->clip_changed
13382 || current_buffer
->prevent_redisplay_optimizations_p
)
13385 /* Window must either use window-based redisplay or be full width. */
13386 if (!FRAME_WINDOW_P (f
)
13387 && (!line_ins_del_ok
13388 || !WINDOW_FULL_WIDTH_P (w
)))
13391 /* Give up if point is not known NOT to appear in W. */
13392 if (PT
< CHARPOS (start
))
13395 /* Another way to prevent redisplay optimizations. */
13396 if (XFASTINT (w
->last_modified
) == 0)
13399 /* Verify that window is not hscrolled. */
13400 if (XFASTINT (w
->hscroll
) != 0)
13403 /* Verify that display wasn't paused. */
13404 if (NILP (w
->window_end_valid
))
13407 /* Can't use this if highlighting a region because a cursor movement
13408 will do more than just set the cursor. */
13409 if (!NILP (Vtransient_mark_mode
)
13410 && !NILP (current_buffer
->mark_active
))
13413 /* Likewise if highlighting trailing whitespace. */
13414 if (!NILP (Vshow_trailing_whitespace
))
13417 /* Likewise if showing a region. */
13418 if (!NILP (w
->region_showing
))
13421 /* Can use this if overlay arrow position and or string have changed. */
13422 if (overlay_arrows_changed_p ())
13426 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13427 only if buffer has really changed. The reason is that the gap is
13428 initially at Z for freshly visited files. The code below would
13429 set end_unchanged to 0 in that case. */
13430 if (MODIFF
> SAVE_MODIFF
13431 /* This seems to happen sometimes after saving a buffer. */
13432 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13434 if (GPT
- BEG
< BEG_UNCHANGED
)
13435 BEG_UNCHANGED
= GPT
- BEG
;
13436 if (Z
- GPT
< END_UNCHANGED
)
13437 END_UNCHANGED
= Z
- GPT
;
13440 /* The position of the first and last character that has been changed. */
13441 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13442 last_changed_charpos
= Z
- END_UNCHANGED
;
13444 /* If window starts after a line end, and the last change is in
13445 front of that newline, then changes don't affect the display.
13446 This case happens with stealth-fontification. Note that although
13447 the display is unchanged, glyph positions in the matrix have to
13448 be adjusted, of course. */
13449 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13450 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13451 && ((last_changed_charpos
< CHARPOS (start
)
13452 && CHARPOS (start
) == BEGV
)
13453 || (last_changed_charpos
< CHARPOS (start
) - 1
13454 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13456 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13457 struct glyph_row
*r0
;
13459 /* Compute how many chars/bytes have been added to or removed
13460 from the buffer. */
13461 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13462 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13464 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13466 /* Give up if PT is not in the window. Note that it already has
13467 been checked at the start of try_window_id that PT is not in
13468 front of the window start. */
13469 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13472 /* If window start is unchanged, we can reuse the whole matrix
13473 as is, after adjusting glyph positions. No need to compute
13474 the window end again, since its offset from Z hasn't changed. */
13475 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13476 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13477 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13478 /* PT must not be in a partially visible line. */
13479 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13480 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13482 /* Adjust positions in the glyph matrix. */
13483 if (delta
|| delta_bytes
)
13485 struct glyph_row
*r1
13486 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13487 increment_matrix_positions (w
->current_matrix
,
13488 MATRIX_ROW_VPOS (r0
, current_matrix
),
13489 MATRIX_ROW_VPOS (r1
, current_matrix
),
13490 delta
, delta_bytes
);
13493 /* Set the cursor. */
13494 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13496 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13503 /* Handle the case that changes are all below what is displayed in
13504 the window, and that PT is in the window. This shortcut cannot
13505 be taken if ZV is visible in the window, and text has been added
13506 there that is visible in the window. */
13507 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13508 /* ZV is not visible in the window, or there are no
13509 changes at ZV, actually. */
13510 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13511 || first_changed_charpos
== last_changed_charpos
))
13513 struct glyph_row
*r0
;
13515 /* Give up if PT is not in the window. Note that it already has
13516 been checked at the start of try_window_id that PT is not in
13517 front of the window start. */
13518 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13521 /* If window start is unchanged, we can reuse the whole matrix
13522 as is, without changing glyph positions since no text has
13523 been added/removed in front of the window end. */
13524 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13525 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13526 /* PT must not be in a partially visible line. */
13527 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13528 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13530 /* We have to compute the window end anew since text
13531 can have been added/removed after it. */
13533 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13534 w
->window_end_bytepos
13535 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13537 /* Set the cursor. */
13538 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13540 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13547 /* Give up if window start is in the changed area.
13549 The condition used to read
13551 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13553 but why that was tested escapes me at the moment. */
13554 if (CHARPOS (start
) >= first_changed_charpos
13555 && CHARPOS (start
) <= last_changed_charpos
)
13558 /* Check that window start agrees with the start of the first glyph
13559 row in its current matrix. Check this after we know the window
13560 start is not in changed text, otherwise positions would not be
13562 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13563 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13566 /* Give up if the window ends in strings. Overlay strings
13567 at the end are difficult to handle, so don't try. */
13568 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13569 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13572 /* Compute the position at which we have to start displaying new
13573 lines. Some of the lines at the top of the window might be
13574 reusable because they are not displaying changed text. Find the
13575 last row in W's current matrix not affected by changes at the
13576 start of current_buffer. Value is null if changes start in the
13577 first line of window. */
13578 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13579 if (last_unchanged_at_beg_row
)
13581 /* Avoid starting to display in the moddle of a character, a TAB
13582 for instance. This is easier than to set up the iterator
13583 exactly, and it's not a frequent case, so the additional
13584 effort wouldn't really pay off. */
13585 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13586 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13587 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13588 --last_unchanged_at_beg_row
;
13590 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13593 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13595 start_pos
= it
.current
.pos
;
13597 /* Start displaying new lines in the desired matrix at the same
13598 vpos we would use in the current matrix, i.e. below
13599 last_unchanged_at_beg_row. */
13600 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13602 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13603 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13605 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13609 /* There are no reusable lines at the start of the window.
13610 Start displaying in the first text line. */
13611 start_display (&it
, w
, start
);
13612 it
.vpos
= it
.first_vpos
;
13613 start_pos
= it
.current
.pos
;
13616 /* Find the first row that is not affected by changes at the end of
13617 the buffer. Value will be null if there is no unchanged row, in
13618 which case we must redisplay to the end of the window. delta
13619 will be set to the value by which buffer positions beginning with
13620 first_unchanged_at_end_row have to be adjusted due to text
13622 first_unchanged_at_end_row
13623 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13624 IF_DEBUG (debug_delta
= delta
);
13625 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13627 /* Set stop_pos to the buffer position up to which we will have to
13628 display new lines. If first_unchanged_at_end_row != NULL, this
13629 is the buffer position of the start of the line displayed in that
13630 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13631 that we don't stop at a buffer position. */
13633 if (first_unchanged_at_end_row
)
13635 xassert (last_unchanged_at_beg_row
== NULL
13636 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13638 /* If this is a continuation line, move forward to the next one
13639 that isn't. Changes in lines above affect this line.
13640 Caution: this may move first_unchanged_at_end_row to a row
13641 not displaying text. */
13642 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13643 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13644 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13645 < it
.last_visible_y
))
13646 ++first_unchanged_at_end_row
;
13648 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13649 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13650 >= it
.last_visible_y
))
13651 first_unchanged_at_end_row
= NULL
;
13654 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13656 first_unchanged_at_end_vpos
13657 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13658 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13661 else if (last_unchanged_at_beg_row
== NULL
)
13667 /* Either there is no unchanged row at the end, or the one we have
13668 now displays text. This is a necessary condition for the window
13669 end pos calculation at the end of this function. */
13670 xassert (first_unchanged_at_end_row
== NULL
13671 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13673 debug_last_unchanged_at_beg_vpos
13674 = (last_unchanged_at_beg_row
13675 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13677 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13679 #endif /* GLYPH_DEBUG != 0 */
13682 /* Display new lines. Set last_text_row to the last new line
13683 displayed which has text on it, i.e. might end up as being the
13684 line where the window_end_vpos is. */
13685 w
->cursor
.vpos
= -1;
13686 last_text_row
= NULL
;
13687 overlay_arrow_seen
= 0;
13688 while (it
.current_y
< it
.last_visible_y
13689 && !fonts_changed_p
13690 && (first_unchanged_at_end_row
== NULL
13691 || IT_CHARPOS (it
) < stop_pos
))
13693 if (display_line (&it
))
13694 last_text_row
= it
.glyph_row
- 1;
13697 if (fonts_changed_p
)
13701 /* Compute differences in buffer positions, y-positions etc. for
13702 lines reused at the bottom of the window. Compute what we can
13704 if (first_unchanged_at_end_row
13705 /* No lines reused because we displayed everything up to the
13706 bottom of the window. */
13707 && it
.current_y
< it
.last_visible_y
)
13710 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13712 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13713 run
.current_y
= first_unchanged_at_end_row
->y
;
13714 run
.desired_y
= run
.current_y
+ dy
;
13715 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13719 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13720 first_unchanged_at_end_row
= NULL
;
13722 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13725 /* Find the cursor if not already found. We have to decide whether
13726 PT will appear on this window (it sometimes doesn't, but this is
13727 not a very frequent case.) This decision has to be made before
13728 the current matrix is altered. A value of cursor.vpos < 0 means
13729 that PT is either in one of the lines beginning at
13730 first_unchanged_at_end_row or below the window. Don't care for
13731 lines that might be displayed later at the window end; as
13732 mentioned, this is not a frequent case. */
13733 if (w
->cursor
.vpos
< 0)
13735 /* Cursor in unchanged rows at the top? */
13736 if (PT
< CHARPOS (start_pos
)
13737 && last_unchanged_at_beg_row
)
13739 row
= row_containing_pos (w
, PT
,
13740 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13741 last_unchanged_at_beg_row
+ 1, 0);
13743 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13746 /* Start from first_unchanged_at_end_row looking for PT. */
13747 else if (first_unchanged_at_end_row
)
13749 row
= row_containing_pos (w
, PT
- delta
,
13750 first_unchanged_at_end_row
, NULL
, 0);
13752 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13753 delta_bytes
, dy
, dvpos
);
13756 /* Give up if cursor was not found. */
13757 if (w
->cursor
.vpos
< 0)
13759 clear_glyph_matrix (w
->desired_matrix
);
13764 /* Don't let the cursor end in the scroll margins. */
13766 int this_scroll_margin
, cursor_height
;
13768 this_scroll_margin
= max (0, scroll_margin
);
13769 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13770 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13771 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13773 if ((w
->cursor
.y
< this_scroll_margin
13774 && CHARPOS (start
) > BEGV
)
13775 /* Old redisplay didn't take scroll margin into account at the bottom,
13776 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13777 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13778 ? cursor_height
+ this_scroll_margin
13779 : 1)) > it
.last_visible_y
)
13781 w
->cursor
.vpos
= -1;
13782 clear_glyph_matrix (w
->desired_matrix
);
13787 /* Scroll the display. Do it before changing the current matrix so
13788 that xterm.c doesn't get confused about where the cursor glyph is
13790 if (dy
&& run
.height
)
13794 if (FRAME_WINDOW_P (f
))
13796 rif
->update_window_begin_hook (w
);
13797 rif
->clear_window_mouse_face (w
);
13798 rif
->scroll_run_hook (w
, &run
);
13799 rif
->update_window_end_hook (w
, 0, 0);
13803 /* Terminal frame. In this case, dvpos gives the number of
13804 lines to scroll by; dvpos < 0 means scroll up. */
13805 int first_unchanged_at_end_vpos
13806 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13807 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13808 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13809 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13810 + window_internal_height (w
));
13812 /* Perform the operation on the screen. */
13815 /* Scroll last_unchanged_at_beg_row to the end of the
13816 window down dvpos lines. */
13817 set_terminal_window (end
);
13819 /* On dumb terminals delete dvpos lines at the end
13820 before inserting dvpos empty lines. */
13821 if (!scroll_region_ok
)
13822 ins_del_lines (end
- dvpos
, -dvpos
);
13824 /* Insert dvpos empty lines in front of
13825 last_unchanged_at_beg_row. */
13826 ins_del_lines (from
, dvpos
);
13828 else if (dvpos
< 0)
13830 /* Scroll up last_unchanged_at_beg_vpos to the end of
13831 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13832 set_terminal_window (end
);
13834 /* Delete dvpos lines in front of
13835 last_unchanged_at_beg_vpos. ins_del_lines will set
13836 the cursor to the given vpos and emit |dvpos| delete
13838 ins_del_lines (from
+ dvpos
, dvpos
);
13840 /* On a dumb terminal insert dvpos empty lines at the
13842 if (!scroll_region_ok
)
13843 ins_del_lines (end
+ dvpos
, -dvpos
);
13846 set_terminal_window (0);
13852 /* Shift reused rows of the current matrix to the right position.
13853 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13855 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13856 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13859 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13860 bottom_vpos
, dvpos
);
13861 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13864 else if (dvpos
> 0)
13866 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13867 bottom_vpos
, dvpos
);
13868 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13869 first_unchanged_at_end_vpos
+ dvpos
, 0);
13872 /* For frame-based redisplay, make sure that current frame and window
13873 matrix are in sync with respect to glyph memory. */
13874 if (!FRAME_WINDOW_P (f
))
13875 sync_frame_with_window_matrix_rows (w
);
13877 /* Adjust buffer positions in reused rows. */
13879 increment_matrix_positions (current_matrix
,
13880 first_unchanged_at_end_vpos
+ dvpos
,
13881 bottom_vpos
, delta
, delta_bytes
);
13883 /* Adjust Y positions. */
13885 shift_glyph_matrix (w
, current_matrix
,
13886 first_unchanged_at_end_vpos
+ dvpos
,
13889 if (first_unchanged_at_end_row
)
13891 first_unchanged_at_end_row
+= dvpos
;
13892 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
13893 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
13894 first_unchanged_at_end_row
= NULL
;
13897 /* If scrolling up, there may be some lines to display at the end of
13899 last_text_row_at_end
= NULL
;
13902 /* Scrolling up can leave for example a partially visible line
13903 at the end of the window to be redisplayed. */
13904 /* Set last_row to the glyph row in the current matrix where the
13905 window end line is found. It has been moved up or down in
13906 the matrix by dvpos. */
13907 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13908 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13910 /* If last_row is the window end line, it should display text. */
13911 xassert (last_row
->displays_text_p
);
13913 /* If window end line was partially visible before, begin
13914 displaying at that line. Otherwise begin displaying with the
13915 line following it. */
13916 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13918 init_to_row_start (&it
, w
, last_row
);
13919 it
.vpos
= last_vpos
;
13920 it
.current_y
= last_row
->y
;
13924 init_to_row_end (&it
, w
, last_row
);
13925 it
.vpos
= 1 + last_vpos
;
13926 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13930 /* We may start in a continuation line. If so, we have to
13931 get the right continuation_lines_width and current_x. */
13932 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13933 it
.hpos
= it
.current_x
= 0;
13935 /* Display the rest of the lines at the window end. */
13936 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13937 while (it
.current_y
< it
.last_visible_y
13938 && !fonts_changed_p
)
13940 /* Is it always sure that the display agrees with lines in
13941 the current matrix? I don't think so, so we mark rows
13942 displayed invalid in the current matrix by setting their
13943 enabled_p flag to zero. */
13944 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13945 if (display_line (&it
))
13946 last_text_row_at_end
= it
.glyph_row
- 1;
13950 /* Update window_end_pos and window_end_vpos. */
13951 if (first_unchanged_at_end_row
13952 && !last_text_row_at_end
)
13954 /* Window end line if one of the preserved rows from the current
13955 matrix. Set row to the last row displaying text in current
13956 matrix starting at first_unchanged_at_end_row, after
13958 xassert (first_unchanged_at_end_row
->displays_text_p
);
13959 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13960 first_unchanged_at_end_row
);
13961 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13963 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13964 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13966 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13967 xassert (w
->window_end_bytepos
>= 0);
13968 IF_DEBUG (debug_method_add (w
, "A"));
13970 else if (last_text_row_at_end
)
13973 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13974 w
->window_end_bytepos
13975 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13977 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13978 xassert (w
->window_end_bytepos
>= 0);
13979 IF_DEBUG (debug_method_add (w
, "B"));
13981 else if (last_text_row
)
13983 /* We have displayed either to the end of the window or at the
13984 end of the window, i.e. the last row with text is to be found
13985 in the desired matrix. */
13987 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13988 w
->window_end_bytepos
13989 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13991 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13992 xassert (w
->window_end_bytepos
>= 0);
13994 else if (first_unchanged_at_end_row
== NULL
13995 && last_text_row
== NULL
13996 && last_text_row_at_end
== NULL
)
13998 /* Displayed to end of window, but no line containing text was
13999 displayed. Lines were deleted at the end of the window. */
14000 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14001 int vpos
= XFASTINT (w
->window_end_vpos
);
14002 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14003 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14006 row
== NULL
&& vpos
>= first_vpos
;
14007 --vpos
, --current_row
, --desired_row
)
14009 if (desired_row
->enabled_p
)
14011 if (desired_row
->displays_text_p
)
14014 else if (current_row
->displays_text_p
)
14018 xassert (row
!= NULL
);
14019 w
->window_end_vpos
= make_number (vpos
+ 1);
14020 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14021 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14022 xassert (w
->window_end_bytepos
>= 0);
14023 IF_DEBUG (debug_method_add (w
, "C"));
14028 #if 0 /* This leads to problems, for instance when the cursor is
14029 at ZV, and the cursor line displays no text. */
14030 /* Disable rows below what's displayed in the window. This makes
14031 debugging easier. */
14032 enable_glyph_matrix_rows (current_matrix
,
14033 XFASTINT (w
->window_end_vpos
) + 1,
14037 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14038 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14040 /* Record that display has not been completed. */
14041 w
->window_end_valid
= Qnil
;
14042 w
->desired_matrix
->no_scrolling_p
= 1;
14050 /***********************************************************************
14051 More debugging support
14052 ***********************************************************************/
14056 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14057 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14058 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14061 /* Dump the contents of glyph matrix MATRIX on stderr.
14063 GLYPHS 0 means don't show glyph contents.
14064 GLYPHS 1 means show glyphs in short form
14065 GLYPHS > 1 means show glyphs in long form. */
14068 dump_glyph_matrix (matrix
, glyphs
)
14069 struct glyph_matrix
*matrix
;
14073 for (i
= 0; i
< matrix
->nrows
; ++i
)
14074 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14078 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14079 the glyph row and area where the glyph comes from. */
14082 dump_glyph (row
, glyph
, area
)
14083 struct glyph_row
*row
;
14084 struct glyph
*glyph
;
14087 if (glyph
->type
== CHAR_GLYPH
)
14090 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14091 glyph
- row
->glyphs
[TEXT_AREA
],
14094 (BUFFERP (glyph
->object
)
14096 : (STRINGP (glyph
->object
)
14099 glyph
->pixel_width
,
14101 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14105 glyph
->left_box_line_p
,
14106 glyph
->right_box_line_p
);
14108 else if (glyph
->type
== STRETCH_GLYPH
)
14111 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14112 glyph
- row
->glyphs
[TEXT_AREA
],
14115 (BUFFERP (glyph
->object
)
14117 : (STRINGP (glyph
->object
)
14120 glyph
->pixel_width
,
14124 glyph
->left_box_line_p
,
14125 glyph
->right_box_line_p
);
14127 else if (glyph
->type
== IMAGE_GLYPH
)
14130 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14131 glyph
- row
->glyphs
[TEXT_AREA
],
14134 (BUFFERP (glyph
->object
)
14136 : (STRINGP (glyph
->object
)
14139 glyph
->pixel_width
,
14143 glyph
->left_box_line_p
,
14144 glyph
->right_box_line_p
);
14149 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14150 GLYPHS 0 means don't show glyph contents.
14151 GLYPHS 1 means show glyphs in short form
14152 GLYPHS > 1 means show glyphs in long form. */
14155 dump_glyph_row (row
, vpos
, glyphs
)
14156 struct glyph_row
*row
;
14161 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
14162 fprintf (stderr
, "=======================================================================\n");
14164 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
14165 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14167 MATRIX_ROW_START_CHARPOS (row
),
14168 MATRIX_ROW_END_CHARPOS (row
),
14169 row
->used
[TEXT_AREA
],
14170 row
->contains_overlapping_glyphs_p
,
14172 row
->truncated_on_left_p
,
14173 row
->truncated_on_right_p
,
14174 row
->overlay_arrow_p
,
14176 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14177 row
->displays_text_p
,
14180 row
->ends_in_middle_of_char_p
,
14181 row
->starts_in_middle_of_char_p
,
14187 row
->visible_height
,
14190 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14191 row
->end
.overlay_string_index
,
14192 row
->continuation_lines_width
);
14193 fprintf (stderr
, "%9d %5d\n",
14194 CHARPOS (row
->start
.string_pos
),
14195 CHARPOS (row
->end
.string_pos
));
14196 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14197 row
->end
.dpvec_index
);
14204 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14206 struct glyph
*glyph
= row
->glyphs
[area
];
14207 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14209 /* Glyph for a line end in text. */
14210 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14213 if (glyph
< glyph_end
)
14214 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14216 for (; glyph
< glyph_end
; ++glyph
)
14217 dump_glyph (row
, glyph
, area
);
14220 else if (glyphs
== 1)
14224 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14226 char *s
= (char *) alloca (row
->used
[area
] + 1);
14229 for (i
= 0; i
< row
->used
[area
]; ++i
)
14231 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14232 if (glyph
->type
== CHAR_GLYPH
14233 && glyph
->u
.ch
< 0x80
14234 && glyph
->u
.ch
>= ' ')
14235 s
[i
] = glyph
->u
.ch
;
14241 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14247 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14248 Sdump_glyph_matrix
, 0, 1, "p",
14249 doc
: /* Dump the current matrix of the selected window to stderr.
14250 Shows contents of glyph row structures. With non-nil
14251 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14252 glyphs in short form, otherwise show glyphs in long form. */)
14254 Lisp_Object glyphs
;
14256 struct window
*w
= XWINDOW (selected_window
);
14257 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14259 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14260 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14261 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14262 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14263 fprintf (stderr
, "=============================================\n");
14264 dump_glyph_matrix (w
->current_matrix
,
14265 NILP (glyphs
) ? 0 : XINT (glyphs
));
14270 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14271 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14274 struct frame
*f
= XFRAME (selected_frame
);
14275 dump_glyph_matrix (f
->current_matrix
, 1);
14280 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14281 doc
: /* Dump glyph row ROW to stderr.
14282 GLYPH 0 means don't dump glyphs.
14283 GLYPH 1 means dump glyphs in short form.
14284 GLYPH > 1 or omitted means dump glyphs in long form. */)
14286 Lisp_Object row
, glyphs
;
14288 struct glyph_matrix
*matrix
;
14291 CHECK_NUMBER (row
);
14292 matrix
= XWINDOW (selected_window
)->current_matrix
;
14294 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14295 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14297 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14302 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14303 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14304 GLYPH 0 means don't dump glyphs.
14305 GLYPH 1 means dump glyphs in short form.
14306 GLYPH > 1 or omitted means dump glyphs in long form. */)
14308 Lisp_Object row
, glyphs
;
14310 struct frame
*sf
= SELECTED_FRAME ();
14311 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14314 CHECK_NUMBER (row
);
14316 if (vpos
>= 0 && vpos
< m
->nrows
)
14317 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14318 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14323 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14324 doc
: /* Toggle tracing of redisplay.
14325 With ARG, turn tracing on if and only if ARG is positive. */)
14330 trace_redisplay_p
= !trace_redisplay_p
;
14333 arg
= Fprefix_numeric_value (arg
);
14334 trace_redisplay_p
= XINT (arg
) > 0;
14341 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14342 doc
: /* Like `format', but print result to stderr.
14343 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14348 Lisp_Object s
= Fformat (nargs
, args
);
14349 fprintf (stderr
, "%s", SDATA (s
));
14353 #endif /* GLYPH_DEBUG */
14357 /***********************************************************************
14358 Building Desired Matrix Rows
14359 ***********************************************************************/
14361 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14362 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14364 static struct glyph_row
*
14365 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14367 Lisp_Object overlay_arrow_string
;
14369 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14370 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14371 struct buffer
*old
= current_buffer
;
14372 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14373 int arrow_len
= SCHARS (overlay_arrow_string
);
14374 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14375 const unsigned char *p
;
14378 int n_glyphs_before
;
14380 set_buffer_temp (buffer
);
14381 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14382 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14383 SET_TEXT_POS (it
.position
, 0, 0);
14385 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14387 while (p
< arrow_end
)
14389 Lisp_Object face
, ilisp
;
14391 /* Get the next character. */
14393 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14395 it
.c
= *p
, it
.len
= 1;
14398 /* Get its face. */
14399 ilisp
= make_number (p
- arrow_string
);
14400 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14401 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14403 /* Compute its width, get its glyphs. */
14404 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14405 SET_TEXT_POS (it
.position
, -1, -1);
14406 PRODUCE_GLYPHS (&it
);
14408 /* If this character doesn't fit any more in the line, we have
14409 to remove some glyphs. */
14410 if (it
.current_x
> it
.last_visible_x
)
14412 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14417 set_buffer_temp (old
);
14418 return it
.glyph_row
;
14422 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14423 glyphs are only inserted for terminal frames since we can't really
14424 win with truncation glyphs when partially visible glyphs are
14425 involved. Which glyphs to insert is determined by
14426 produce_special_glyphs. */
14429 insert_left_trunc_glyphs (it
)
14432 struct it truncate_it
;
14433 struct glyph
*from
, *end
, *to
, *toend
;
14435 xassert (!FRAME_WINDOW_P (it
->f
));
14437 /* Get the truncation glyphs. */
14439 truncate_it
.current_x
= 0;
14440 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14441 truncate_it
.glyph_row
= &scratch_glyph_row
;
14442 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14443 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14444 truncate_it
.object
= make_number (0);
14445 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14447 /* Overwrite glyphs from IT with truncation glyphs. */
14448 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14449 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14450 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14451 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14456 /* There may be padding glyphs left over. Overwrite them too. */
14457 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14459 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14465 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14469 /* Compute the pixel height and width of IT->glyph_row.
14471 Most of the time, ascent and height of a display line will be equal
14472 to the max_ascent and max_height values of the display iterator
14473 structure. This is not the case if
14475 1. We hit ZV without displaying anything. In this case, max_ascent
14476 and max_height will be zero.
14478 2. We have some glyphs that don't contribute to the line height.
14479 (The glyph row flag contributes_to_line_height_p is for future
14480 pixmap extensions).
14482 The first case is easily covered by using default values because in
14483 these cases, the line height does not really matter, except that it
14484 must not be zero. */
14487 compute_line_metrics (it
)
14490 struct glyph_row
*row
= it
->glyph_row
;
14493 if (FRAME_WINDOW_P (it
->f
))
14495 int i
, min_y
, max_y
;
14497 /* The line may consist of one space only, that was added to
14498 place the cursor on it. If so, the row's height hasn't been
14500 if (row
->height
== 0)
14502 if (it
->max_ascent
+ it
->max_descent
== 0)
14503 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14504 row
->ascent
= it
->max_ascent
;
14505 row
->height
= it
->max_ascent
+ it
->max_descent
;
14506 row
->phys_ascent
= it
->max_phys_ascent
;
14507 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14508 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14511 /* Compute the width of this line. */
14512 row
->pixel_width
= row
->x
;
14513 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14514 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14516 xassert (row
->pixel_width
>= 0);
14517 xassert (row
->ascent
>= 0 && row
->height
> 0);
14519 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14520 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14522 /* If first line's physical ascent is larger than its logical
14523 ascent, use the physical ascent, and make the row taller.
14524 This makes accented characters fully visible. */
14525 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14526 && row
->phys_ascent
> row
->ascent
)
14528 row
->height
+= row
->phys_ascent
- row
->ascent
;
14529 row
->ascent
= row
->phys_ascent
;
14532 /* Compute how much of the line is visible. */
14533 row
->visible_height
= row
->height
;
14535 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14536 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14538 if (row
->y
< min_y
)
14539 row
->visible_height
-= min_y
- row
->y
;
14540 if (row
->y
+ row
->height
> max_y
)
14541 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14545 row
->pixel_width
= row
->used
[TEXT_AREA
];
14546 if (row
->continued_p
)
14547 row
->pixel_width
-= it
->continuation_pixel_width
;
14548 else if (row
->truncated_on_right_p
)
14549 row
->pixel_width
-= it
->truncation_pixel_width
;
14550 row
->ascent
= row
->phys_ascent
= 0;
14551 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14552 row
->extra_line_spacing
= 0;
14555 /* Compute a hash code for this row. */
14557 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14558 for (i
= 0; i
< row
->used
[area
]; ++i
)
14559 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14560 + row
->glyphs
[area
][i
].u
.val
14561 + row
->glyphs
[area
][i
].face_id
14562 + row
->glyphs
[area
][i
].padding_p
14563 + (row
->glyphs
[area
][i
].type
<< 2));
14565 it
->max_ascent
= it
->max_descent
= 0;
14566 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14570 /* Append one space to the glyph row of iterator IT if doing a
14571 window-based redisplay. The space has the same face as
14572 IT->face_id. Value is non-zero if a space was added.
14574 This function is called to make sure that there is always one glyph
14575 at the end of a glyph row that the cursor can be set on under
14576 window-systems. (If there weren't such a glyph we would not know
14577 how wide and tall a box cursor should be displayed).
14579 At the same time this space let's a nicely handle clearing to the
14580 end of the line if the row ends in italic text. */
14583 append_space_for_newline (it
, default_face_p
)
14585 int default_face_p
;
14587 if (FRAME_WINDOW_P (it
->f
))
14589 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14591 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14592 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14594 /* Save some values that must not be changed.
14595 Must save IT->c and IT->len because otherwise
14596 ITERATOR_AT_END_P wouldn't work anymore after
14597 append_space_for_newline has been called. */
14598 enum display_element_type saved_what
= it
->what
;
14599 int saved_c
= it
->c
, saved_len
= it
->len
;
14600 int saved_x
= it
->current_x
;
14601 int saved_face_id
= it
->face_id
;
14602 struct text_pos saved_pos
;
14603 Lisp_Object saved_object
;
14606 saved_object
= it
->object
;
14607 saved_pos
= it
->position
;
14609 it
->what
= IT_CHARACTER
;
14610 bzero (&it
->position
, sizeof it
->position
);
14611 it
->object
= make_number (0);
14615 if (default_face_p
)
14616 it
->face_id
= DEFAULT_FACE_ID
;
14617 else if (it
->face_before_selective_p
)
14618 it
->face_id
= it
->saved_face_id
;
14619 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14620 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14622 PRODUCE_GLYPHS (it
);
14624 it
->override_ascent
= -1;
14625 it
->constrain_row_ascent_descent_p
= 0;
14626 it
->current_x
= saved_x
;
14627 it
->object
= saved_object
;
14628 it
->position
= saved_pos
;
14629 it
->what
= saved_what
;
14630 it
->face_id
= saved_face_id
;
14631 it
->len
= saved_len
;
14641 /* Extend the face of the last glyph in the text area of IT->glyph_row
14642 to the end of the display line. Called from display_line.
14643 If the glyph row is empty, add a space glyph to it so that we
14644 know the face to draw. Set the glyph row flag fill_line_p. */
14647 extend_face_to_end_of_line (it
)
14651 struct frame
*f
= it
->f
;
14653 /* If line is already filled, do nothing. */
14654 if (it
->current_x
>= it
->last_visible_x
)
14657 /* Face extension extends the background and box of IT->face_id
14658 to the end of the line. If the background equals the background
14659 of the frame, we don't have to do anything. */
14660 if (it
->face_before_selective_p
)
14661 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14663 face
= FACE_FROM_ID (f
, it
->face_id
);
14665 if (FRAME_WINDOW_P (f
)
14666 && face
->box
== FACE_NO_BOX
14667 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14671 /* Set the glyph row flag indicating that the face of the last glyph
14672 in the text area has to be drawn to the end of the text area. */
14673 it
->glyph_row
->fill_line_p
= 1;
14675 /* If current character of IT is not ASCII, make sure we have the
14676 ASCII face. This will be automatically undone the next time
14677 get_next_display_element returns a multibyte character. Note
14678 that the character will always be single byte in unibyte text. */
14679 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14681 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14684 if (FRAME_WINDOW_P (f
))
14686 /* If the row is empty, add a space with the current face of IT,
14687 so that we know which face to draw. */
14688 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14690 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14691 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14692 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14697 /* Save some values that must not be changed. */
14698 int saved_x
= it
->current_x
;
14699 struct text_pos saved_pos
;
14700 Lisp_Object saved_object
;
14701 enum display_element_type saved_what
= it
->what
;
14702 int saved_face_id
= it
->face_id
;
14704 saved_object
= it
->object
;
14705 saved_pos
= it
->position
;
14707 it
->what
= IT_CHARACTER
;
14708 bzero (&it
->position
, sizeof it
->position
);
14709 it
->object
= make_number (0);
14712 it
->face_id
= face
->id
;
14714 PRODUCE_GLYPHS (it
);
14716 while (it
->current_x
<= it
->last_visible_x
)
14717 PRODUCE_GLYPHS (it
);
14719 /* Don't count these blanks really. It would let us insert a left
14720 truncation glyph below and make us set the cursor on them, maybe. */
14721 it
->current_x
= saved_x
;
14722 it
->object
= saved_object
;
14723 it
->position
= saved_pos
;
14724 it
->what
= saved_what
;
14725 it
->face_id
= saved_face_id
;
14730 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14731 trailing whitespace. */
14734 trailing_whitespace_p (charpos
)
14737 int bytepos
= CHAR_TO_BYTE (charpos
);
14740 while (bytepos
< ZV_BYTE
14741 && (c
= FETCH_CHAR (bytepos
),
14742 c
== ' ' || c
== '\t'))
14745 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14747 if (bytepos
!= PT_BYTE
)
14754 /* Highlight trailing whitespace, if any, in ROW. */
14757 highlight_trailing_whitespace (f
, row
)
14759 struct glyph_row
*row
;
14761 int used
= row
->used
[TEXT_AREA
];
14765 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14766 struct glyph
*glyph
= start
+ used
- 1;
14768 /* Skip over glyphs inserted to display the cursor at the
14769 end of a line, for extending the face of the last glyph
14770 to the end of the line on terminals, and for truncation
14771 and continuation glyphs. */
14772 while (glyph
>= start
14773 && glyph
->type
== CHAR_GLYPH
14774 && INTEGERP (glyph
->object
))
14777 /* If last glyph is a space or stretch, and it's trailing
14778 whitespace, set the face of all trailing whitespace glyphs in
14779 IT->glyph_row to `trailing-whitespace'. */
14781 && BUFFERP (glyph
->object
)
14782 && (glyph
->type
== STRETCH_GLYPH
14783 || (glyph
->type
== CHAR_GLYPH
14784 && glyph
->u
.ch
== ' '))
14785 && trailing_whitespace_p (glyph
->charpos
))
14787 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14791 while (glyph
>= start
14792 && BUFFERP (glyph
->object
)
14793 && (glyph
->type
== STRETCH_GLYPH
14794 || (glyph
->type
== CHAR_GLYPH
14795 && glyph
->u
.ch
== ' ')))
14796 (glyph
--)->face_id
= face_id
;
14802 /* Value is non-zero if glyph row ROW in window W should be
14803 used to hold the cursor. */
14806 cursor_row_p (w
, row
)
14808 struct glyph_row
*row
;
14810 int cursor_row_p
= 1;
14812 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14814 /* If the row ends with a newline from a string, we don't want
14815 the cursor there (if the row is continued it doesn't end in a
14817 if (CHARPOS (row
->end
.string_pos
) >= 0)
14818 cursor_row_p
= row
->continued_p
;
14819 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14821 /* If the row ends in middle of a real character,
14822 and the line is continued, we want the cursor here.
14823 That's because MATRIX_ROW_END_CHARPOS would equal
14824 PT if PT is before the character. */
14825 if (!row
->ends_in_ellipsis_p
)
14826 cursor_row_p
= row
->continued_p
;
14828 /* If the row ends in an ellipsis, then
14829 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
14830 We want that position to be displayed after the ellipsis. */
14833 /* If the row ends at ZV, display the cursor at the end of that
14834 row instead of at the start of the row below. */
14835 else if (row
->ends_at_zv_p
)
14841 return cursor_row_p
;
14845 /* Construct the glyph row IT->glyph_row in the desired matrix of
14846 IT->w from text at the current position of IT. See dispextern.h
14847 for an overview of struct it. Value is non-zero if
14848 IT->glyph_row displays text, as opposed to a line displaying ZV
14855 struct glyph_row
*row
= it
->glyph_row
;
14856 int overlay_arrow_bitmap
;
14857 Lisp_Object overlay_arrow_string
;
14859 /* We always start displaying at hpos zero even if hscrolled. */
14860 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14862 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14863 >= it
->w
->desired_matrix
->nrows
)
14865 it
->w
->nrows_scale_factor
++;
14866 fonts_changed_p
= 1;
14870 /* Is IT->w showing the region? */
14871 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14873 /* Clear the result glyph row and enable it. */
14874 prepare_desired_row (row
);
14876 row
->y
= it
->current_y
;
14877 row
->start
= it
->start
;
14878 row
->continuation_lines_width
= it
->continuation_lines_width
;
14879 row
->displays_text_p
= 1;
14880 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14881 it
->starts_in_middle_of_char_p
= 0;
14883 /* Arrange the overlays nicely for our purposes. Usually, we call
14884 display_line on only one line at a time, in which case this
14885 can't really hurt too much, or we call it on lines which appear
14886 one after another in the buffer, in which case all calls to
14887 recenter_overlay_lists but the first will be pretty cheap. */
14888 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14890 /* Move over display elements that are not visible because we are
14891 hscrolled. This may stop at an x-position < IT->first_visible_x
14892 if the first glyph is partially visible or if we hit a line end. */
14893 if (it
->current_x
< it
->first_visible_x
)
14895 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14896 MOVE_TO_POS
| MOVE_TO_X
);
14899 /* Get the initial row height. This is either the height of the
14900 text hscrolled, if there is any, or zero. */
14901 row
->ascent
= it
->max_ascent
;
14902 row
->height
= it
->max_ascent
+ it
->max_descent
;
14903 row
->phys_ascent
= it
->max_phys_ascent
;
14904 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14905 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14907 /* Loop generating characters. The loop is left with IT on the next
14908 character to display. */
14911 int n_glyphs_before
, hpos_before
, x_before
;
14913 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14915 /* Retrieve the next thing to display. Value is zero if end of
14917 if (!get_next_display_element (it
))
14919 /* Maybe add a space at the end of this line that is used to
14920 display the cursor there under X. Set the charpos of the
14921 first glyph of blank lines not corresponding to any text
14923 #ifdef HAVE_WINDOW_SYSTEM
14924 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14925 row
->exact_window_width_line_p
= 1;
14927 #endif /* HAVE_WINDOW_SYSTEM */
14928 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14929 || row
->used
[TEXT_AREA
] == 0)
14931 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14932 row
->displays_text_p
= 0;
14934 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14935 && (!MINI_WINDOW_P (it
->w
)
14936 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14937 row
->indicate_empty_line_p
= 1;
14940 it
->continuation_lines_width
= 0;
14941 row
->ends_at_zv_p
= 1;
14945 /* Now, get the metrics of what we want to display. This also
14946 generates glyphs in `row' (which is IT->glyph_row). */
14947 n_glyphs_before
= row
->used
[TEXT_AREA
];
14950 /* Remember the line height so far in case the next element doesn't
14951 fit on the line. */
14952 if (!it
->truncate_lines_p
)
14954 ascent
= it
->max_ascent
;
14955 descent
= it
->max_descent
;
14956 phys_ascent
= it
->max_phys_ascent
;
14957 phys_descent
= it
->max_phys_descent
;
14960 PRODUCE_GLYPHS (it
);
14962 /* If this display element was in marginal areas, continue with
14964 if (it
->area
!= TEXT_AREA
)
14966 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14967 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14968 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14969 row
->phys_height
= max (row
->phys_height
,
14970 it
->max_phys_ascent
+ it
->max_phys_descent
);
14971 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14972 it
->max_extra_line_spacing
);
14973 set_iterator_to_next (it
, 1);
14977 /* Does the display element fit on the line? If we truncate
14978 lines, we should draw past the right edge of the window. If
14979 we don't truncate, we want to stop so that we can display the
14980 continuation glyph before the right margin. If lines are
14981 continued, there are two possible strategies for characters
14982 resulting in more than 1 glyph (e.g. tabs): Display as many
14983 glyphs as possible in this line and leave the rest for the
14984 continuation line, or display the whole element in the next
14985 line. Original redisplay did the former, so we do it also. */
14986 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14987 hpos_before
= it
->hpos
;
14990 if (/* Not a newline. */
14992 /* Glyphs produced fit entirely in the line. */
14993 && it
->current_x
< it
->last_visible_x
)
14995 it
->hpos
+= nglyphs
;
14996 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14997 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14998 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14999 row
->phys_height
= max (row
->phys_height
,
15000 it
->max_phys_ascent
+ it
->max_phys_descent
);
15001 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15002 it
->max_extra_line_spacing
);
15003 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15004 row
->x
= x
- it
->first_visible_x
;
15009 struct glyph
*glyph
;
15011 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15013 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15014 new_x
= x
+ glyph
->pixel_width
;
15016 if (/* Lines are continued. */
15017 !it
->truncate_lines_p
15018 && (/* Glyph doesn't fit on the line. */
15019 new_x
> it
->last_visible_x
15020 /* Or it fits exactly on a window system frame. */
15021 || (new_x
== it
->last_visible_x
15022 && FRAME_WINDOW_P (it
->f
))))
15024 /* End of a continued line. */
15027 || (new_x
== it
->last_visible_x
15028 && FRAME_WINDOW_P (it
->f
)))
15030 /* Current glyph is the only one on the line or
15031 fits exactly on the line. We must continue
15032 the line because we can't draw the cursor
15033 after the glyph. */
15034 row
->continued_p
= 1;
15035 it
->current_x
= new_x
;
15036 it
->continuation_lines_width
+= new_x
;
15038 if (i
== nglyphs
- 1)
15040 set_iterator_to_next (it
, 1);
15041 #ifdef HAVE_WINDOW_SYSTEM
15042 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15044 if (!get_next_display_element (it
))
15046 row
->exact_window_width_line_p
= 1;
15047 it
->continuation_lines_width
= 0;
15048 row
->continued_p
= 0;
15049 row
->ends_at_zv_p
= 1;
15051 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15053 row
->continued_p
= 0;
15054 row
->exact_window_width_line_p
= 1;
15057 #endif /* HAVE_WINDOW_SYSTEM */
15060 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15061 && !FRAME_WINDOW_P (it
->f
))
15063 /* A padding glyph that doesn't fit on this line.
15064 This means the whole character doesn't fit
15066 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15068 /* Fill the rest of the row with continuation
15069 glyphs like in 20.x. */
15070 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15071 < row
->glyphs
[1 + TEXT_AREA
])
15072 produce_special_glyphs (it
, IT_CONTINUATION
);
15074 row
->continued_p
= 1;
15075 it
->current_x
= x_before
;
15076 it
->continuation_lines_width
+= x_before
;
15078 /* Restore the height to what it was before the
15079 element not fitting on the line. */
15080 it
->max_ascent
= ascent
;
15081 it
->max_descent
= descent
;
15082 it
->max_phys_ascent
= phys_ascent
;
15083 it
->max_phys_descent
= phys_descent
;
15085 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15087 /* A TAB that extends past the right edge of the
15088 window. This produces a single glyph on
15089 window system frames. We leave the glyph in
15090 this row and let it fill the row, but don't
15091 consume the TAB. */
15092 it
->continuation_lines_width
+= it
->last_visible_x
;
15093 row
->ends_in_middle_of_char_p
= 1;
15094 row
->continued_p
= 1;
15095 glyph
->pixel_width
= it
->last_visible_x
- x
;
15096 it
->starts_in_middle_of_char_p
= 1;
15100 /* Something other than a TAB that draws past
15101 the right edge of the window. Restore
15102 positions to values before the element. */
15103 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15105 /* Display continuation glyphs. */
15106 if (!FRAME_WINDOW_P (it
->f
))
15107 produce_special_glyphs (it
, IT_CONTINUATION
);
15108 row
->continued_p
= 1;
15110 it
->continuation_lines_width
+= x
;
15112 if (nglyphs
> 1 && i
> 0)
15114 row
->ends_in_middle_of_char_p
= 1;
15115 it
->starts_in_middle_of_char_p
= 1;
15118 /* Restore the height to what it was before the
15119 element not fitting on the line. */
15120 it
->max_ascent
= ascent
;
15121 it
->max_descent
= descent
;
15122 it
->max_phys_ascent
= phys_ascent
;
15123 it
->max_phys_descent
= phys_descent
;
15128 else if (new_x
> it
->first_visible_x
)
15130 /* Increment number of glyphs actually displayed. */
15133 if (x
< it
->first_visible_x
)
15134 /* Glyph is partially visible, i.e. row starts at
15135 negative X position. */
15136 row
->x
= x
- it
->first_visible_x
;
15140 /* Glyph is completely off the left margin of the
15141 window. This should not happen because of the
15142 move_it_in_display_line at the start of this
15143 function, unless the text display area of the
15144 window is empty. */
15145 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15149 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15150 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15151 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15152 row
->phys_height
= max (row
->phys_height
,
15153 it
->max_phys_ascent
+ it
->max_phys_descent
);
15154 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15155 it
->max_extra_line_spacing
);
15157 /* End of this display line if row is continued. */
15158 if (row
->continued_p
|| row
->ends_at_zv_p
)
15163 /* Is this a line end? If yes, we're also done, after making
15164 sure that a non-default face is extended up to the right
15165 margin of the window. */
15166 if (ITERATOR_AT_END_OF_LINE_P (it
))
15168 int used_before
= row
->used
[TEXT_AREA
];
15170 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15172 #ifdef HAVE_WINDOW_SYSTEM
15173 /* Add a space at the end of the line that is used to
15174 display the cursor there. */
15175 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15176 append_space_for_newline (it
, 0);
15177 #endif /* HAVE_WINDOW_SYSTEM */
15179 /* Extend the face to the end of the line. */
15180 extend_face_to_end_of_line (it
);
15182 /* Make sure we have the position. */
15183 if (used_before
== 0)
15184 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15186 /* Consume the line end. This skips over invisible lines. */
15187 set_iterator_to_next (it
, 1);
15188 it
->continuation_lines_width
= 0;
15192 /* Proceed with next display element. Note that this skips
15193 over lines invisible because of selective display. */
15194 set_iterator_to_next (it
, 1);
15196 /* If we truncate lines, we are done when the last displayed
15197 glyphs reach past the right margin of the window. */
15198 if (it
->truncate_lines_p
15199 && (FRAME_WINDOW_P (it
->f
)
15200 ? (it
->current_x
>= it
->last_visible_x
)
15201 : (it
->current_x
> it
->last_visible_x
)))
15203 /* Maybe add truncation glyphs. */
15204 if (!FRAME_WINDOW_P (it
->f
))
15208 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15209 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15212 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15214 row
->used
[TEXT_AREA
] = i
;
15215 produce_special_glyphs (it
, IT_TRUNCATION
);
15218 #ifdef HAVE_WINDOW_SYSTEM
15221 /* Don't truncate if we can overflow newline into fringe. */
15222 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15224 if (!get_next_display_element (it
))
15226 it
->continuation_lines_width
= 0;
15227 row
->ends_at_zv_p
= 1;
15228 row
->exact_window_width_line_p
= 1;
15231 if (ITERATOR_AT_END_OF_LINE_P (it
))
15233 row
->exact_window_width_line_p
= 1;
15234 goto at_end_of_line
;
15238 #endif /* HAVE_WINDOW_SYSTEM */
15240 row
->truncated_on_right_p
= 1;
15241 it
->continuation_lines_width
= 0;
15242 reseat_at_next_visible_line_start (it
, 0);
15243 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15244 it
->hpos
= hpos_before
;
15245 it
->current_x
= x_before
;
15250 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15251 at the left window margin. */
15252 if (it
->first_visible_x
15253 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15255 if (!FRAME_WINDOW_P (it
->f
))
15256 insert_left_trunc_glyphs (it
);
15257 row
->truncated_on_left_p
= 1;
15260 /* If the start of this line is the overlay arrow-position, then
15261 mark this glyph row as the one containing the overlay arrow.
15262 This is clearly a mess with variable size fonts. It would be
15263 better to let it be displayed like cursors under X. */
15264 if ((overlay_arrow_string
15265 = overlay_arrow_at_row (it
, row
, &overlay_arrow_bitmap
),
15266 !NILP (overlay_arrow_string
)))
15268 /* Overlay arrow in window redisplay is a fringe bitmap. */
15269 if (STRINGP (overlay_arrow_string
))
15271 struct glyph_row
*arrow_row
15272 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15273 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15274 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15275 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15276 struct glyph
*p2
, *end
;
15278 /* Copy the arrow glyphs. */
15279 while (glyph
< arrow_end
)
15282 /* Throw away padding glyphs. */
15284 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15285 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15291 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15296 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
15297 row
->overlay_arrow_p
= 1;
15299 overlay_arrow_seen
= 1;
15302 /* Compute pixel dimensions of this line. */
15303 compute_line_metrics (it
);
15305 /* Remember the position at which this line ends. */
15306 row
->end
= it
->current
;
15308 /* Record whether this row ends inside an ellipsis. */
15309 row
->ends_in_ellipsis_p
15310 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15311 && it
->ellipsis_p
);
15313 /* Save fringe bitmaps in this row. */
15314 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15315 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15316 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15317 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15319 it
->left_user_fringe_bitmap
= 0;
15320 it
->left_user_fringe_face_id
= 0;
15321 it
->right_user_fringe_bitmap
= 0;
15322 it
->right_user_fringe_face_id
= 0;
15324 /* Maybe set the cursor. */
15325 if (it
->w
->cursor
.vpos
< 0
15326 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15327 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15328 && cursor_row_p (it
->w
, row
))
15329 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15331 /* Highlight trailing whitespace. */
15332 if (!NILP (Vshow_trailing_whitespace
))
15333 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15335 /* Prepare for the next line. This line starts horizontally at (X
15336 HPOS) = (0 0). Vertical positions are incremented. As a
15337 convenience for the caller, IT->glyph_row is set to the next
15339 it
->current_x
= it
->hpos
= 0;
15340 it
->current_y
+= row
->height
;
15343 it
->start
= it
->current
;
15344 return row
->displays_text_p
;
15349 /***********************************************************************
15351 ***********************************************************************/
15353 /* Redisplay the menu bar in the frame for window W.
15355 The menu bar of X frames that don't have X toolkit support is
15356 displayed in a special window W->frame->menu_bar_window.
15358 The menu bar of terminal frames is treated specially as far as
15359 glyph matrices are concerned. Menu bar lines are not part of
15360 windows, so the update is done directly on the frame matrix rows
15361 for the menu bar. */
15364 display_menu_bar (w
)
15367 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15372 /* Don't do all this for graphical frames. */
15374 if (!NILP (Vwindow_system
))
15377 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15382 if (FRAME_MAC_P (f
))
15386 #ifdef USE_X_TOOLKIT
15387 xassert (!FRAME_WINDOW_P (f
));
15388 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15389 it
.first_visible_x
= 0;
15390 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15391 #else /* not USE_X_TOOLKIT */
15392 if (FRAME_WINDOW_P (f
))
15394 /* Menu bar lines are displayed in the desired matrix of the
15395 dummy window menu_bar_window. */
15396 struct window
*menu_w
;
15397 xassert (WINDOWP (f
->menu_bar_window
));
15398 menu_w
= XWINDOW (f
->menu_bar_window
);
15399 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15401 it
.first_visible_x
= 0;
15402 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15406 /* This is a TTY frame, i.e. character hpos/vpos are used as
15408 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15410 it
.first_visible_x
= 0;
15411 it
.last_visible_x
= FRAME_COLS (f
);
15413 #endif /* not USE_X_TOOLKIT */
15415 if (! mode_line_inverse_video
)
15416 /* Force the menu-bar to be displayed in the default face. */
15417 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15419 /* Clear all rows of the menu bar. */
15420 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15422 struct glyph_row
*row
= it
.glyph_row
+ i
;
15423 clear_glyph_row (row
);
15424 row
->enabled_p
= 1;
15425 row
->full_width_p
= 1;
15428 /* Display all items of the menu bar. */
15429 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15430 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15432 Lisp_Object string
;
15434 /* Stop at nil string. */
15435 string
= AREF (items
, i
+ 1);
15439 /* Remember where item was displayed. */
15440 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15442 /* Display the item, pad with one space. */
15443 if (it
.current_x
< it
.last_visible_x
)
15444 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15445 SCHARS (string
) + 1, 0, 0, -1);
15448 /* Fill out the line with spaces. */
15449 if (it
.current_x
< it
.last_visible_x
)
15450 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15452 /* Compute the total height of the lines. */
15453 compute_line_metrics (&it
);
15458 /***********************************************************************
15460 ***********************************************************************/
15462 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15463 FORCE is non-zero, redisplay mode lines unconditionally.
15464 Otherwise, redisplay only mode lines that are garbaged. Value is
15465 the number of windows whose mode lines were redisplayed. */
15468 redisplay_mode_lines (window
, force
)
15469 Lisp_Object window
;
15474 while (!NILP (window
))
15476 struct window
*w
= XWINDOW (window
);
15478 if (WINDOWP (w
->hchild
))
15479 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15480 else if (WINDOWP (w
->vchild
))
15481 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15483 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15484 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15486 struct text_pos lpoint
;
15487 struct buffer
*old
= current_buffer
;
15489 /* Set the window's buffer for the mode line display. */
15490 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15491 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15493 /* Point refers normally to the selected window. For any
15494 other window, set up appropriate value. */
15495 if (!EQ (window
, selected_window
))
15497 struct text_pos pt
;
15499 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15500 if (CHARPOS (pt
) < BEGV
)
15501 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15502 else if (CHARPOS (pt
) > (ZV
- 1))
15503 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15505 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15508 /* Display mode lines. */
15509 clear_glyph_matrix (w
->desired_matrix
);
15510 if (display_mode_lines (w
))
15513 w
->must_be_updated_p
= 1;
15516 /* Restore old settings. */
15517 set_buffer_internal_1 (old
);
15518 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15528 /* Display the mode and/or top line of window W. Value is the number
15529 of mode lines displayed. */
15532 display_mode_lines (w
)
15535 Lisp_Object old_selected_window
, old_selected_frame
;
15538 old_selected_frame
= selected_frame
;
15539 selected_frame
= w
->frame
;
15540 old_selected_window
= selected_window
;
15541 XSETWINDOW (selected_window
, w
);
15543 /* These will be set while the mode line specs are processed. */
15544 line_number_displayed
= 0;
15545 w
->column_number_displayed
= Qnil
;
15547 if (WINDOW_WANTS_MODELINE_P (w
))
15549 struct window
*sel_w
= XWINDOW (old_selected_window
);
15551 /* Select mode line face based on the real selected window. */
15552 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15553 current_buffer
->mode_line_format
);
15557 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15559 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15560 current_buffer
->header_line_format
);
15564 selected_frame
= old_selected_frame
;
15565 selected_window
= old_selected_window
;
15570 /* Display mode or top line of window W. FACE_ID specifies which line
15571 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15572 FORMAT is the mode line format to display. Value is the pixel
15573 height of the mode line displayed. */
15576 display_mode_line (w
, face_id
, format
)
15578 enum face_id face_id
;
15579 Lisp_Object format
;
15584 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15585 prepare_desired_row (it
.glyph_row
);
15587 it
.glyph_row
->mode_line_p
= 1;
15589 if (! mode_line_inverse_video
)
15590 /* Force the mode-line to be displayed in the default face. */
15591 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15593 /* Temporarily make frame's keyboard the current kboard so that
15594 kboard-local variables in the mode_line_format will get the right
15596 push_frame_kboard (it
.f
);
15597 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15598 pop_frame_kboard ();
15600 /* Fill up with spaces. */
15601 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15603 compute_line_metrics (&it
);
15604 it
.glyph_row
->full_width_p
= 1;
15605 it
.glyph_row
->continued_p
= 0;
15606 it
.glyph_row
->truncated_on_left_p
= 0;
15607 it
.glyph_row
->truncated_on_right_p
= 0;
15609 /* Make a 3D mode-line have a shadow at its right end. */
15610 face
= FACE_FROM_ID (it
.f
, face_id
);
15611 extend_face_to_end_of_line (&it
);
15612 if (face
->box
!= FACE_NO_BOX
)
15614 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15615 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15616 last
->right_box_line_p
= 1;
15619 return it
.glyph_row
->height
;
15622 /* Alist that caches the results of :propertize.
15623 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15624 Lisp_Object mode_line_proptrans_alist
;
15626 /* List of strings making up the mode-line. */
15627 Lisp_Object mode_line_string_list
;
15629 /* Base face property when building propertized mode line string. */
15630 static Lisp_Object mode_line_string_face
;
15631 static Lisp_Object mode_line_string_face_prop
;
15634 /* Contribute ELT to the mode line for window IT->w. How it
15635 translates into text depends on its data type.
15637 IT describes the display environment in which we display, as usual.
15639 DEPTH is the depth in recursion. It is used to prevent
15640 infinite recursion here.
15642 FIELD_WIDTH is the number of characters the display of ELT should
15643 occupy in the mode line, and PRECISION is the maximum number of
15644 characters to display from ELT's representation. See
15645 display_string for details.
15647 Returns the hpos of the end of the text generated by ELT.
15649 PROPS is a property list to add to any string we encounter.
15651 If RISKY is nonzero, remove (disregard) any properties in any string
15652 we encounter, and ignore :eval and :propertize.
15654 If the global variable `frame_title_ptr' is non-NULL, then the output
15655 is passed to `store_frame_title' instead of `display_string'. */
15658 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15661 int field_width
, precision
;
15662 Lisp_Object elt
, props
;
15665 int n
= 0, field
, prec
;
15670 elt
= build_string ("*too-deep*");
15674 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15678 /* A string: output it and check for %-constructs within it. */
15680 const unsigned char *this, *lisp_string
;
15682 if (!NILP (props
) || risky
)
15684 Lisp_Object oprops
, aelt
;
15685 oprops
= Ftext_properties_at (make_number (0), elt
);
15687 /* If the starting string's properties are not what
15688 we want, translate the string. Also, if the string
15689 is risky, do that anyway. */
15691 if (NILP (Fequal (props
, oprops
)) || risky
)
15693 /* If the starting string has properties,
15694 merge the specified ones onto the existing ones. */
15695 if (! NILP (oprops
) && !risky
)
15699 oprops
= Fcopy_sequence (oprops
);
15701 while (CONSP (tem
))
15703 oprops
= Fplist_put (oprops
, XCAR (tem
),
15704 XCAR (XCDR (tem
)));
15705 tem
= XCDR (XCDR (tem
));
15710 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15711 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15713 mode_line_proptrans_alist
15714 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15721 elt
= Fcopy_sequence (elt
);
15722 Fset_text_properties (make_number (0), Flength (elt
),
15724 /* Add this item to mode_line_proptrans_alist. */
15725 mode_line_proptrans_alist
15726 = Fcons (Fcons (elt
, props
),
15727 mode_line_proptrans_alist
);
15728 /* Truncate mode_line_proptrans_alist
15729 to at most 50 elements. */
15730 tem
= Fnthcdr (make_number (50),
15731 mode_line_proptrans_alist
);
15733 XSETCDR (tem
, Qnil
);
15738 this = SDATA (elt
);
15739 lisp_string
= this;
15743 prec
= precision
- n
;
15744 if (frame_title_ptr
)
15745 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15746 else if (!NILP (mode_line_string_list
))
15747 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15749 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15750 0, prec
, 0, STRING_MULTIBYTE (elt
));
15755 while ((precision
<= 0 || n
< precision
)
15757 && (frame_title_ptr
15758 || !NILP (mode_line_string_list
)
15759 || it
->current_x
< it
->last_visible_x
))
15761 const unsigned char *last
= this;
15763 /* Advance to end of string or next format specifier. */
15764 while ((c
= *this++) != '\0' && c
!= '%')
15767 if (this - 1 != last
)
15769 int nchars
, nbytes
;
15771 /* Output to end of string or up to '%'. Field width
15772 is length of string. Don't output more than
15773 PRECISION allows us. */
15776 prec
= c_string_width (last
, this - last
, precision
- n
,
15779 if (frame_title_ptr
)
15780 n
+= store_frame_title (last
, 0, prec
);
15781 else if (!NILP (mode_line_string_list
))
15783 int bytepos
= last
- lisp_string
;
15784 int charpos
= string_byte_to_char (elt
, bytepos
);
15785 int endpos
= (precision
<= 0
15786 ? string_byte_to_char (elt
,
15787 this - lisp_string
)
15788 : charpos
+ nchars
);
15790 n
+= store_mode_line_string (NULL
,
15791 Fsubstring (elt
, make_number (charpos
),
15792 make_number (endpos
)),
15797 int bytepos
= last
- lisp_string
;
15798 int charpos
= string_byte_to_char (elt
, bytepos
);
15799 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15801 STRING_MULTIBYTE (elt
));
15804 else /* c == '%' */
15806 const unsigned char *percent_position
= this;
15808 /* Get the specified minimum width. Zero means
15811 while ((c
= *this++) >= '0' && c
<= '9')
15812 field
= field
* 10 + c
- '0';
15814 /* Don't pad beyond the total padding allowed. */
15815 if (field_width
- n
> 0 && field
> field_width
- n
)
15816 field
= field_width
- n
;
15818 /* Note that either PRECISION <= 0 or N < PRECISION. */
15819 prec
= precision
- n
;
15822 n
+= display_mode_element (it
, depth
, field
, prec
,
15823 Vglobal_mode_string
, props
,
15828 int bytepos
, charpos
;
15829 unsigned char *spec
;
15831 bytepos
= percent_position
- lisp_string
;
15832 charpos
= (STRING_MULTIBYTE (elt
)
15833 ? string_byte_to_char (elt
, bytepos
)
15837 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15839 if (frame_title_ptr
)
15840 n
+= store_frame_title (spec
, field
, prec
);
15841 else if (!NILP (mode_line_string_list
))
15843 int len
= strlen (spec
);
15844 Lisp_Object tem
= make_string (spec
, len
);
15845 props
= Ftext_properties_at (make_number (charpos
), elt
);
15846 /* Should only keep face property in props */
15847 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15851 int nglyphs_before
, nwritten
;
15853 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15854 nwritten
= display_string (spec
, Qnil
, elt
,
15859 /* Assign to the glyphs written above the
15860 string where the `%x' came from, position
15864 struct glyph
*glyph
15865 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15869 for (i
= 0; i
< nwritten
; ++i
)
15871 glyph
[i
].object
= elt
;
15872 glyph
[i
].charpos
= charpos
;
15887 /* A symbol: process the value of the symbol recursively
15888 as if it appeared here directly. Avoid error if symbol void.
15889 Special case: if value of symbol is a string, output the string
15892 register Lisp_Object tem
;
15894 /* If the variable is not marked as risky to set
15895 then its contents are risky to use. */
15896 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15899 tem
= Fboundp (elt
);
15902 tem
= Fsymbol_value (elt
);
15903 /* If value is a string, output that string literally:
15904 don't check for % within it. */
15908 if (!EQ (tem
, elt
))
15910 /* Give up right away for nil or t. */
15920 register Lisp_Object car
, tem
;
15922 /* A cons cell: five distinct cases.
15923 If first element is :eval or :propertize, do something special.
15924 If first element is a string or a cons, process all the elements
15925 and effectively concatenate them.
15926 If first element is a negative number, truncate displaying cdr to
15927 at most that many characters. If positive, pad (with spaces)
15928 to at least that many characters.
15929 If first element is a symbol, process the cadr or caddr recursively
15930 according to whether the symbol's value is non-nil or nil. */
15932 if (EQ (car
, QCeval
))
15934 /* An element of the form (:eval FORM) means evaluate FORM
15935 and use the result as mode line elements. */
15940 if (CONSP (XCDR (elt
)))
15943 spec
= safe_eval (XCAR (XCDR (elt
)));
15944 n
+= display_mode_element (it
, depth
, field_width
- n
,
15945 precision
- n
, spec
, props
,
15949 else if (EQ (car
, QCpropertize
))
15951 /* An element of the form (:propertize ELT PROPS...)
15952 means display ELT but applying properties PROPS. */
15957 if (CONSP (XCDR (elt
)))
15958 n
+= display_mode_element (it
, depth
, field_width
- n
,
15959 precision
- n
, XCAR (XCDR (elt
)),
15960 XCDR (XCDR (elt
)), risky
);
15962 else if (SYMBOLP (car
))
15964 tem
= Fboundp (car
);
15968 /* elt is now the cdr, and we know it is a cons cell.
15969 Use its car if CAR has a non-nil value. */
15972 tem
= Fsymbol_value (car
);
15979 /* Symbol's value is nil (or symbol is unbound)
15980 Get the cddr of the original list
15981 and if possible find the caddr and use that. */
15985 else if (!CONSP (elt
))
15990 else if (INTEGERP (car
))
15992 register int lim
= XINT (car
);
15996 /* Negative int means reduce maximum width. */
15997 if (precision
<= 0)
16000 precision
= min (precision
, -lim
);
16004 /* Padding specified. Don't let it be more than
16005 current maximum. */
16007 lim
= min (precision
, lim
);
16009 /* If that's more padding than already wanted, queue it.
16010 But don't reduce padding already specified even if
16011 that is beyond the current truncation point. */
16012 field_width
= max (lim
, field_width
);
16016 else if (STRINGP (car
) || CONSP (car
))
16018 register int limit
= 50;
16019 /* Limit is to protect against circular lists. */
16022 && (precision
<= 0 || n
< precision
))
16024 n
+= display_mode_element (it
, depth
, field_width
- n
,
16025 precision
- n
, XCAR (elt
),
16035 elt
= build_string ("*invalid*");
16039 /* Pad to FIELD_WIDTH. */
16040 if (field_width
> 0 && n
< field_width
)
16042 if (frame_title_ptr
)
16043 n
+= store_frame_title ("", field_width
- n
, 0);
16044 else if (!NILP (mode_line_string_list
))
16045 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16047 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16054 /* Store a mode-line string element in mode_line_string_list.
16056 If STRING is non-null, display that C string. Otherwise, the Lisp
16057 string LISP_STRING is displayed.
16059 FIELD_WIDTH is the minimum number of output glyphs to produce.
16060 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16061 with spaces. FIELD_WIDTH <= 0 means don't pad.
16063 PRECISION is the maximum number of characters to output from
16064 STRING. PRECISION <= 0 means don't truncate the string.
16066 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16067 properties to the string.
16069 PROPS are the properties to add to the string.
16070 The mode_line_string_face face property is always added to the string.
16074 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16076 Lisp_Object lisp_string
;
16085 if (string
!= NULL
)
16087 len
= strlen (string
);
16088 if (precision
> 0 && len
> precision
)
16090 lisp_string
= make_string (string
, len
);
16092 props
= mode_line_string_face_prop
;
16093 else if (!NILP (mode_line_string_face
))
16095 Lisp_Object face
= Fsafe_plist_get (props
, Qface
);
16096 props
= Fcopy_sequence (props
);
16098 face
= mode_line_string_face
;
16100 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16101 props
= Fplist_put (props
, Qface
, face
);
16103 Fadd_text_properties (make_number (0), make_number (len
),
16104 props
, lisp_string
);
16108 len
= XFASTINT (Flength (lisp_string
));
16109 if (precision
> 0 && len
> precision
)
16112 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16115 if (!NILP (mode_line_string_face
))
16119 props
= Ftext_properties_at (make_number (0), lisp_string
);
16120 face
= Fsafe_plist_get (props
, Qface
);
16122 face
= mode_line_string_face
;
16124 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16125 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16127 lisp_string
= Fcopy_sequence (lisp_string
);
16130 Fadd_text_properties (make_number (0), make_number (len
),
16131 props
, lisp_string
);
16136 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16140 if (field_width
> len
)
16142 field_width
-= len
;
16143 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16145 Fadd_text_properties (make_number (0), make_number (field_width
),
16146 props
, lisp_string
);
16147 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16155 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16157 doc
: /* Format a string out of a mode line format specification.
16158 First arg FORMAT specifies the mode line format (see `mode-line-format'
16159 for details) to use.
16161 Optional second arg FACE specifies the face property to put
16162 on all characters for which no face is specified.
16163 t means whatever face the window's mode line currently uses
16164 \(either `mode-line' or `mode-line-inactive', depending).
16165 nil means the default is no face property.
16166 If FACE is an integer, the value string has no text properties.
16168 Optional third and fourth args WINDOW and BUFFER specify the window
16169 and buffer to use as the context for the formatting (defaults
16170 are the selected window and the window's buffer). */)
16171 (format
, face
, window
, buffer
)
16172 Lisp_Object format
, face
, window
, buffer
;
16177 struct buffer
*old_buffer
= NULL
;
16179 int no_props
= INTEGERP (face
);
16182 window
= selected_window
;
16183 CHECK_WINDOW (window
);
16184 w
= XWINDOW (window
);
16187 buffer
= w
->buffer
;
16188 CHECK_BUFFER (buffer
);
16191 return build_string ("");
16199 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16200 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16204 face_id
= DEFAULT_FACE_ID
;
16206 if (XBUFFER (buffer
) != current_buffer
)
16208 old_buffer
= current_buffer
;
16209 set_buffer_internal_1 (XBUFFER (buffer
));
16212 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16216 mode_line_string_face
= face
;
16217 mode_line_string_face_prop
16218 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16220 /* We need a dummy last element in mode_line_string_list to
16221 indicate we are building the propertized mode-line string.
16222 Using mode_line_string_face_prop here GC protects it. */
16223 mode_line_string_list
16224 = Fcons (mode_line_string_face_prop
, Qnil
);
16225 frame_title_ptr
= NULL
;
16229 mode_line_string_face_prop
= Qnil
;
16230 mode_line_string_list
= Qnil
;
16231 frame_title_ptr
= frame_title_buf
;
16234 push_frame_kboard (it
.f
);
16235 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16236 pop_frame_kboard ();
16239 set_buffer_internal_1 (old_buffer
);
16244 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16245 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
16246 make_string ("", 0));
16247 mode_line_string_face_prop
= Qnil
;
16248 mode_line_string_list
= Qnil
;
16252 len
= frame_title_ptr
- frame_title_buf
;
16253 if (len
> 0 && frame_title_ptr
[-1] == '-')
16255 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
16256 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
16258 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
16259 if (len
> frame_title_ptr
- frame_title_buf
)
16260 len
= frame_title_ptr
- frame_title_buf
;
16263 frame_title_ptr
= NULL
;
16264 return make_string (frame_title_buf
, len
);
16267 /* Write a null-terminated, right justified decimal representation of
16268 the positive integer D to BUF using a minimal field width WIDTH. */
16271 pint2str (buf
, width
, d
)
16272 register char *buf
;
16273 register int width
;
16276 register char *p
= buf
;
16284 *p
++ = d
% 10 + '0';
16289 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16300 /* Write a null-terminated, right justified decimal and "human
16301 readable" representation of the nonnegative integer D to BUF using
16302 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16304 static const char power_letter
[] =
16318 pint2hrstr (buf
, width
, d
)
16323 /* We aim to represent the nonnegative integer D as
16324 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16327 /* -1 means: do not use TENTHS. */
16331 /* Length of QUOTIENT.TENTHS as a string. */
16337 if (1000 <= quotient
)
16339 /* Scale to the appropriate EXPONENT. */
16342 remainder
= quotient
% 1000;
16346 while (1000 <= quotient
);
16348 /* Round to nearest and decide whether to use TENTHS or not. */
16351 tenths
= remainder
/ 100;
16352 if (50 <= remainder
% 100)
16359 if (quotient
== 10)
16367 if (500 <= remainder
)
16369 if (quotient
< 999)
16380 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16381 if (tenths
== -1 && quotient
<= 99)
16388 p
= psuffix
= buf
+ max (width
, length
);
16390 /* Print EXPONENT. */
16392 *psuffix
++ = power_letter
[exponent
];
16395 /* Print TENTHS. */
16398 *--p
= '0' + tenths
;
16402 /* Print QUOTIENT. */
16405 int digit
= quotient
% 10;
16406 *--p
= '0' + digit
;
16408 while ((quotient
/= 10) != 0);
16410 /* Print leading spaces. */
16415 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16416 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16417 type of CODING_SYSTEM. Return updated pointer into BUF. */
16419 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16422 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16423 Lisp_Object coding_system
;
16424 register char *buf
;
16428 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16429 const unsigned char *eol_str
;
16431 /* The EOL conversion we are using. */
16432 Lisp_Object eoltype
;
16434 val
= Fget (coding_system
, Qcoding_system
);
16437 if (!VECTORP (val
)) /* Not yet decided. */
16442 eoltype
= eol_mnemonic_undecided
;
16443 /* Don't mention EOL conversion if it isn't decided. */
16447 Lisp_Object eolvalue
;
16449 eolvalue
= Fget (coding_system
, Qeol_type
);
16452 *buf
++ = XFASTINT (AREF (val
, 1));
16456 /* The EOL conversion that is normal on this system. */
16458 if (NILP (eolvalue
)) /* Not yet decided. */
16459 eoltype
= eol_mnemonic_undecided
;
16460 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16461 eoltype
= eol_mnemonic_undecided
;
16462 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16463 eoltype
= (XFASTINT (eolvalue
) == 0
16464 ? eol_mnemonic_unix
16465 : (XFASTINT (eolvalue
) == 1
16466 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16472 /* Mention the EOL conversion if it is not the usual one. */
16473 if (STRINGP (eoltype
))
16475 eol_str
= SDATA (eoltype
);
16476 eol_str_len
= SBYTES (eoltype
);
16478 else if (INTEGERP (eoltype
)
16479 && CHAR_VALID_P (XINT (eoltype
), 0))
16481 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16482 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16487 eol_str
= invalid_eol_type
;
16488 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16490 bcopy (eol_str
, buf
, eol_str_len
);
16491 buf
+= eol_str_len
;
16497 /* Return a string for the output of a mode line %-spec for window W,
16498 generated by character C. PRECISION >= 0 means don't return a
16499 string longer than that value. FIELD_WIDTH > 0 means pad the
16500 string returned with spaces to that value. Return 1 in *MULTIBYTE
16501 if the result is multibyte text.
16503 Note we operate on the current buffer for most purposes,
16504 the exception being w->base_line_pos. */
16506 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16509 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16512 int field_width
, precision
;
16516 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16517 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16518 struct buffer
*b
= current_buffer
;
16526 if (!NILP (b
->read_only
))
16528 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16533 /* This differs from %* only for a modified read-only buffer. */
16534 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16536 if (!NILP (b
->read_only
))
16541 /* This differs from %* in ignoring read-only-ness. */
16542 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16554 if (command_loop_level
> 5)
16556 p
= decode_mode_spec_buf
;
16557 for (i
= 0; i
< command_loop_level
; i
++)
16560 return decode_mode_spec_buf
;
16568 if (command_loop_level
> 5)
16570 p
= decode_mode_spec_buf
;
16571 for (i
= 0; i
< command_loop_level
; i
++)
16574 return decode_mode_spec_buf
;
16581 /* Let lots_of_dashes be a string of infinite length. */
16582 if (!NILP (mode_line_string_list
))
16584 if (field_width
<= 0
16585 || field_width
> sizeof (lots_of_dashes
))
16587 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16588 decode_mode_spec_buf
[i
] = '-';
16589 decode_mode_spec_buf
[i
] = '\0';
16590 return decode_mode_spec_buf
;
16593 return lots_of_dashes
;
16602 int col
= (int) current_column (); /* iftc */
16603 w
->column_number_displayed
= make_number (col
);
16604 pint2str (decode_mode_spec_buf
, field_width
, col
);
16605 return decode_mode_spec_buf
;
16609 /* %F displays the frame name. */
16610 if (!NILP (f
->title
))
16611 return (char *) SDATA (f
->title
);
16612 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16613 return (char *) SDATA (f
->name
);
16622 int size
= ZV
- BEGV
;
16623 pint2str (decode_mode_spec_buf
, field_width
, size
);
16624 return decode_mode_spec_buf
;
16629 int size
= ZV
- BEGV
;
16630 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16631 return decode_mode_spec_buf
;
16636 int startpos
= XMARKER (w
->start
)->charpos
;
16637 int startpos_byte
= marker_byte_position (w
->start
);
16638 int line
, linepos
, linepos_byte
, topline
;
16640 int height
= WINDOW_TOTAL_LINES (w
);
16642 /* If we decided that this buffer isn't suitable for line numbers,
16643 don't forget that too fast. */
16644 if (EQ (w
->base_line_pos
, w
->buffer
))
16646 /* But do forget it, if the window shows a different buffer now. */
16647 else if (BUFFERP (w
->base_line_pos
))
16648 w
->base_line_pos
= Qnil
;
16650 /* If the buffer is very big, don't waste time. */
16651 if (INTEGERP (Vline_number_display_limit
)
16652 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16654 w
->base_line_pos
= Qnil
;
16655 w
->base_line_number
= Qnil
;
16659 if (!NILP (w
->base_line_number
)
16660 && !NILP (w
->base_line_pos
)
16661 && XFASTINT (w
->base_line_pos
) <= startpos
)
16663 line
= XFASTINT (w
->base_line_number
);
16664 linepos
= XFASTINT (w
->base_line_pos
);
16665 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16670 linepos
= BUF_BEGV (b
);
16671 linepos_byte
= BUF_BEGV_BYTE (b
);
16674 /* Count lines from base line to window start position. */
16675 nlines
= display_count_lines (linepos
, linepos_byte
,
16679 topline
= nlines
+ line
;
16681 /* Determine a new base line, if the old one is too close
16682 or too far away, or if we did not have one.
16683 "Too close" means it's plausible a scroll-down would
16684 go back past it. */
16685 if (startpos
== BUF_BEGV (b
))
16687 w
->base_line_number
= make_number (topline
);
16688 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16690 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16691 || linepos
== BUF_BEGV (b
))
16693 int limit
= BUF_BEGV (b
);
16694 int limit_byte
= BUF_BEGV_BYTE (b
);
16696 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16698 if (startpos
- distance
> limit
)
16700 limit
= startpos
- distance
;
16701 limit_byte
= CHAR_TO_BYTE (limit
);
16704 nlines
= display_count_lines (startpos
, startpos_byte
,
16706 - (height
* 2 + 30),
16708 /* If we couldn't find the lines we wanted within
16709 line_number_display_limit_width chars per line,
16710 give up on line numbers for this window. */
16711 if (position
== limit_byte
&& limit
== startpos
- distance
)
16713 w
->base_line_pos
= w
->buffer
;
16714 w
->base_line_number
= Qnil
;
16718 w
->base_line_number
= make_number (topline
- nlines
);
16719 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16722 /* Now count lines from the start pos to point. */
16723 nlines
= display_count_lines (startpos
, startpos_byte
,
16724 PT_BYTE
, PT
, &junk
);
16726 /* Record that we did display the line number. */
16727 line_number_displayed
= 1;
16729 /* Make the string to show. */
16730 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16731 return decode_mode_spec_buf
;
16734 char* p
= decode_mode_spec_buf
;
16735 int pad
= field_width
- 2;
16741 return decode_mode_spec_buf
;
16747 obj
= b
->mode_name
;
16751 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16757 int pos
= marker_position (w
->start
);
16758 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16760 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16762 if (pos
<= BUF_BEGV (b
))
16767 else if (pos
<= BUF_BEGV (b
))
16771 if (total
> 1000000)
16772 /* Do it differently for a large value, to avoid overflow. */
16773 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16775 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16776 /* We can't normally display a 3-digit number,
16777 so get us a 2-digit number that is close. */
16780 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16781 return decode_mode_spec_buf
;
16785 /* Display percentage of size above the bottom of the screen. */
16788 int toppos
= marker_position (w
->start
);
16789 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16790 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16792 if (botpos
>= BUF_ZV (b
))
16794 if (toppos
<= BUF_BEGV (b
))
16801 if (total
> 1000000)
16802 /* Do it differently for a large value, to avoid overflow. */
16803 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16805 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16806 /* We can't normally display a 3-digit number,
16807 so get us a 2-digit number that is close. */
16810 if (toppos
<= BUF_BEGV (b
))
16811 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16813 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16814 return decode_mode_spec_buf
;
16819 /* status of process */
16820 obj
= Fget_buffer_process (Fcurrent_buffer ());
16822 return "no process";
16823 #ifdef subprocesses
16824 obj
= Fsymbol_name (Fprocess_status (obj
));
16828 case 't': /* indicate TEXT or BINARY */
16829 #ifdef MODE_LINE_BINARY_TEXT
16830 return MODE_LINE_BINARY_TEXT (b
);
16836 /* coding-system (not including end-of-line format) */
16838 /* coding-system (including end-of-line type) */
16840 int eol_flag
= (c
== 'Z');
16841 char *p
= decode_mode_spec_buf
;
16843 if (! FRAME_WINDOW_P (f
))
16845 /* No need to mention EOL here--the terminal never needs
16846 to do EOL conversion. */
16847 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16848 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16850 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16853 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16854 #ifdef subprocesses
16855 obj
= Fget_buffer_process (Fcurrent_buffer ());
16856 if (PROCESSP (obj
))
16858 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16860 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16863 #endif /* subprocesses */
16866 return decode_mode_spec_buf
;
16872 *multibyte
= STRING_MULTIBYTE (obj
);
16873 return (char *) SDATA (obj
);
16880 /* Count up to COUNT lines starting from START / START_BYTE.
16881 But don't go beyond LIMIT_BYTE.
16882 Return the number of lines thus found (always nonnegative).
16884 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16887 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16888 int start
, start_byte
, limit_byte
, count
;
16891 register unsigned char *cursor
;
16892 unsigned char *base
;
16894 register int ceiling
;
16895 register unsigned char *ceiling_addr
;
16896 int orig_count
= count
;
16898 /* If we are not in selective display mode,
16899 check only for newlines. */
16900 int selective_display
= (!NILP (current_buffer
->selective_display
)
16901 && !INTEGERP (current_buffer
->selective_display
));
16905 while (start_byte
< limit_byte
)
16907 ceiling
= BUFFER_CEILING_OF (start_byte
);
16908 ceiling
= min (limit_byte
- 1, ceiling
);
16909 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16910 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16913 if (selective_display
)
16914 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16917 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16920 if (cursor
!= ceiling_addr
)
16924 start_byte
+= cursor
- base
+ 1;
16925 *byte_pos_ptr
= start_byte
;
16929 if (++cursor
== ceiling_addr
)
16935 start_byte
+= cursor
- base
;
16940 while (start_byte
> limit_byte
)
16942 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16943 ceiling
= max (limit_byte
, ceiling
);
16944 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16945 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16948 if (selective_display
)
16949 while (--cursor
!= ceiling_addr
16950 && *cursor
!= '\n' && *cursor
!= 015)
16953 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16956 if (cursor
!= ceiling_addr
)
16960 start_byte
+= cursor
- base
+ 1;
16961 *byte_pos_ptr
= start_byte
;
16962 /* When scanning backwards, we should
16963 not count the newline posterior to which we stop. */
16964 return - orig_count
- 1;
16970 /* Here we add 1 to compensate for the last decrement
16971 of CURSOR, which took it past the valid range. */
16972 start_byte
+= cursor
- base
+ 1;
16976 *byte_pos_ptr
= limit_byte
;
16979 return - orig_count
+ count
;
16980 return orig_count
- count
;
16986 /***********************************************************************
16988 ***********************************************************************/
16990 /* Display a NUL-terminated string, starting with index START.
16992 If STRING is non-null, display that C string. Otherwise, the Lisp
16993 string LISP_STRING is displayed.
16995 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16996 FACE_STRING. Display STRING or LISP_STRING with the face at
16997 FACE_STRING_POS in FACE_STRING:
16999 Display the string in the environment given by IT, but use the
17000 standard display table, temporarily.
17002 FIELD_WIDTH is the minimum number of output glyphs to produce.
17003 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17004 with spaces. If STRING has more characters, more than FIELD_WIDTH
17005 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17007 PRECISION is the maximum number of characters to output from
17008 STRING. PRECISION < 0 means don't truncate the string.
17010 This is roughly equivalent to printf format specifiers:
17012 FIELD_WIDTH PRECISION PRINTF
17013 ----------------------------------------
17019 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17020 display them, and < 0 means obey the current buffer's value of
17021 enable_multibyte_characters.
17023 Value is the number of glyphs produced. */
17026 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17027 start
, it
, field_width
, precision
, max_x
, multibyte
)
17028 unsigned char *string
;
17029 Lisp_Object lisp_string
;
17030 Lisp_Object face_string
;
17031 int face_string_pos
;
17034 int field_width
, precision
, max_x
;
17037 int hpos_at_start
= it
->hpos
;
17038 int saved_face_id
= it
->face_id
;
17039 struct glyph_row
*row
= it
->glyph_row
;
17041 /* Initialize the iterator IT for iteration over STRING beginning
17042 with index START. */
17043 reseat_to_string (it
, string
, lisp_string
, start
,
17044 precision
, field_width
, multibyte
);
17046 /* If displaying STRING, set up the face of the iterator
17047 from LISP_STRING, if that's given. */
17048 if (STRINGP (face_string
))
17054 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17055 0, it
->region_beg_charpos
,
17056 it
->region_end_charpos
,
17057 &endptr
, it
->base_face_id
, 0);
17058 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17059 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17062 /* Set max_x to the maximum allowed X position. Don't let it go
17063 beyond the right edge of the window. */
17065 max_x
= it
->last_visible_x
;
17067 max_x
= min (max_x
, it
->last_visible_x
);
17069 /* Skip over display elements that are not visible. because IT->w is
17071 if (it
->current_x
< it
->first_visible_x
)
17072 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17073 MOVE_TO_POS
| MOVE_TO_X
);
17075 row
->ascent
= it
->max_ascent
;
17076 row
->height
= it
->max_ascent
+ it
->max_descent
;
17077 row
->phys_ascent
= it
->max_phys_ascent
;
17078 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17079 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17081 /* This condition is for the case that we are called with current_x
17082 past last_visible_x. */
17083 while (it
->current_x
< max_x
)
17085 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17087 /* Get the next display element. */
17088 if (!get_next_display_element (it
))
17091 /* Produce glyphs. */
17092 x_before
= it
->current_x
;
17093 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17094 PRODUCE_GLYPHS (it
);
17096 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17099 while (i
< nglyphs
)
17101 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17103 if (!it
->truncate_lines_p
17104 && x
+ glyph
->pixel_width
> max_x
)
17106 /* End of continued line or max_x reached. */
17107 if (CHAR_GLYPH_PADDING_P (*glyph
))
17109 /* A wide character is unbreakable. */
17110 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17111 it
->current_x
= x_before
;
17115 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17120 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17122 /* Glyph is at least partially visible. */
17124 if (x
< it
->first_visible_x
)
17125 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17129 /* Glyph is off the left margin of the display area.
17130 Should not happen. */
17134 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17135 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17136 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17137 row
->phys_height
= max (row
->phys_height
,
17138 it
->max_phys_ascent
+ it
->max_phys_descent
);
17139 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17140 it
->max_extra_line_spacing
);
17141 x
+= glyph
->pixel_width
;
17145 /* Stop if max_x reached. */
17149 /* Stop at line ends. */
17150 if (ITERATOR_AT_END_OF_LINE_P (it
))
17152 it
->continuation_lines_width
= 0;
17156 set_iterator_to_next (it
, 1);
17158 /* Stop if truncating at the right edge. */
17159 if (it
->truncate_lines_p
17160 && it
->current_x
>= it
->last_visible_x
)
17162 /* Add truncation mark, but don't do it if the line is
17163 truncated at a padding space. */
17164 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17166 if (!FRAME_WINDOW_P (it
->f
))
17170 if (it
->current_x
> it
->last_visible_x
)
17172 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17173 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17175 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17177 row
->used
[TEXT_AREA
] = i
;
17178 produce_special_glyphs (it
, IT_TRUNCATION
);
17181 produce_special_glyphs (it
, IT_TRUNCATION
);
17183 it
->glyph_row
->truncated_on_right_p
= 1;
17189 /* Maybe insert a truncation at the left. */
17190 if (it
->first_visible_x
17191 && IT_CHARPOS (*it
) > 0)
17193 if (!FRAME_WINDOW_P (it
->f
))
17194 insert_left_trunc_glyphs (it
);
17195 it
->glyph_row
->truncated_on_left_p
= 1;
17198 it
->face_id
= saved_face_id
;
17200 /* Value is number of columns displayed. */
17201 return it
->hpos
- hpos_at_start
;
17206 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17207 appears as an element of LIST or as the car of an element of LIST.
17208 If PROPVAL is a list, compare each element against LIST in that
17209 way, and return 1/2 if any element of PROPVAL is found in LIST.
17210 Otherwise return 0. This function cannot quit.
17211 The return value is 2 if the text is invisible but with an ellipsis
17212 and 1 if it's invisible and without an ellipsis. */
17215 invisible_p (propval
, list
)
17216 register Lisp_Object propval
;
17219 register Lisp_Object tail
, proptail
;
17221 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17223 register Lisp_Object tem
;
17225 if (EQ (propval
, tem
))
17227 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17228 return NILP (XCDR (tem
)) ? 1 : 2;
17231 if (CONSP (propval
))
17233 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17235 Lisp_Object propelt
;
17236 propelt
= XCAR (proptail
);
17237 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17239 register Lisp_Object tem
;
17241 if (EQ (propelt
, tem
))
17243 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17244 return NILP (XCDR (tem
)) ? 1 : 2;
17252 /* Calculate a width or height in pixels from a specification using
17253 the following elements:
17256 NUM - a (fractional) multiple of the default font width/height
17257 (NUM) - specifies exactly NUM pixels
17258 UNIT - a fixed number of pixels, see below.
17259 ELEMENT - size of a display element in pixels, see below.
17260 (NUM . SPEC) - equals NUM * SPEC
17261 (+ SPEC SPEC ...) - add pixel values
17262 (- SPEC SPEC ...) - subtract pixel values
17263 (- SPEC) - negate pixel value
17266 INT or FLOAT - a number constant
17267 SYMBOL - use symbol's (buffer local) variable binding.
17270 in - pixels per inch *)
17271 mm - pixels per 1/1000 meter *)
17272 cm - pixels per 1/100 meter *)
17273 width - width of current font in pixels.
17274 height - height of current font in pixels.
17276 *) using the ratio(s) defined in display-pixels-per-inch.
17280 left-fringe - left fringe width in pixels
17281 right-fringe - right fringe width in pixels
17283 left-margin - left margin width in pixels
17284 right-margin - right margin width in pixels
17286 scroll-bar - scroll-bar area width in pixels
17290 Pixels corresponding to 5 inches:
17293 Total width of non-text areas on left side of window (if scroll-bar is on left):
17294 '(space :width (+ left-fringe left-margin scroll-bar))
17296 Align to first text column (in header line):
17297 '(space :align-to 0)
17299 Align to middle of text area minus half the width of variable `my-image'
17300 containing a loaded image:
17301 '(space :align-to (0.5 . (- text my-image)))
17303 Width of left margin minus width of 1 character in the default font:
17304 '(space :width (- left-margin 1))
17306 Width of left margin minus width of 2 characters in the current font:
17307 '(space :width (- left-margin (2 . width)))
17309 Center 1 character over left-margin (in header line):
17310 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17312 Different ways to express width of left fringe plus left margin minus one pixel:
17313 '(space :width (- (+ left-fringe left-margin) (1)))
17314 '(space :width (+ left-fringe left-margin (- (1))))
17315 '(space :width (+ left-fringe left-margin (-1)))
17319 #define NUMVAL(X) \
17320 ((INTEGERP (X) || FLOATP (X)) \
17325 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17330 int width_p
, *align_to
;
17334 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17335 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17338 return OK_PIXELS (0);
17340 if (SYMBOLP (prop
))
17342 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17344 char *unit
= SDATA (SYMBOL_NAME (prop
));
17346 if (unit
[0] == 'i' && unit
[1] == 'n')
17348 else if (unit
[0] == 'm' && unit
[1] == 'm')
17350 else if (unit
[0] == 'c' && unit
[1] == 'm')
17357 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17358 || (CONSP (Vdisplay_pixels_per_inch
)
17360 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17361 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17363 return OK_PIXELS (ppi
/ pixels
);
17369 #ifdef HAVE_WINDOW_SYSTEM
17370 if (EQ (prop
, Qheight
))
17371 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17372 if (EQ (prop
, Qwidth
))
17373 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17375 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17376 return OK_PIXELS (1);
17379 if (EQ (prop
, Qtext
))
17380 return OK_PIXELS (width_p
17381 ? window_box_width (it
->w
, TEXT_AREA
)
17382 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17384 if (align_to
&& *align_to
< 0)
17387 if (EQ (prop
, Qleft
))
17388 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17389 if (EQ (prop
, Qright
))
17390 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17391 if (EQ (prop
, Qcenter
))
17392 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17393 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17394 if (EQ (prop
, Qleft_fringe
))
17395 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17396 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17397 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17398 if (EQ (prop
, Qright_fringe
))
17399 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17400 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17401 : window_box_right_offset (it
->w
, TEXT_AREA
));
17402 if (EQ (prop
, Qleft_margin
))
17403 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17404 if (EQ (prop
, Qright_margin
))
17405 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17406 if (EQ (prop
, Qscroll_bar
))
17407 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17409 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17410 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17411 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17416 if (EQ (prop
, Qleft_fringe
))
17417 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17418 if (EQ (prop
, Qright_fringe
))
17419 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17420 if (EQ (prop
, Qleft_margin
))
17421 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17422 if (EQ (prop
, Qright_margin
))
17423 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17424 if (EQ (prop
, Qscroll_bar
))
17425 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17428 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17431 if (INTEGERP (prop
) || FLOATP (prop
))
17433 int base_unit
= (width_p
17434 ? FRAME_COLUMN_WIDTH (it
->f
)
17435 : FRAME_LINE_HEIGHT (it
->f
));
17436 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17441 Lisp_Object car
= XCAR (prop
);
17442 Lisp_Object cdr
= XCDR (prop
);
17446 #ifdef HAVE_WINDOW_SYSTEM
17447 if (valid_image_p (prop
))
17449 int id
= lookup_image (it
->f
, prop
);
17450 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17452 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17455 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17461 while (CONSP (cdr
))
17463 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17464 font
, width_p
, align_to
))
17467 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17472 if (EQ (car
, Qminus
))
17474 return OK_PIXELS (pixels
);
17477 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17480 if (INTEGERP (car
) || FLOATP (car
))
17483 pixels
= XFLOATINT (car
);
17485 return OK_PIXELS (pixels
);
17486 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17487 font
, width_p
, align_to
))
17488 return OK_PIXELS (pixels
* fact
);
17499 /***********************************************************************
17501 ***********************************************************************/
17503 #ifdef HAVE_WINDOW_SYSTEM
17508 dump_glyph_string (s
)
17509 struct glyph_string
*s
;
17511 fprintf (stderr
, "glyph string\n");
17512 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17513 s
->x
, s
->y
, s
->width
, s
->height
);
17514 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17515 fprintf (stderr
, " hl = %d\n", s
->hl
);
17516 fprintf (stderr
, " left overhang = %d, right = %d\n",
17517 s
->left_overhang
, s
->right_overhang
);
17518 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17519 fprintf (stderr
, " extends to end of line = %d\n",
17520 s
->extends_to_end_of_line_p
);
17521 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17522 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17525 #endif /* GLYPH_DEBUG */
17527 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17528 of XChar2b structures for S; it can't be allocated in
17529 init_glyph_string because it must be allocated via `alloca'. W
17530 is the window on which S is drawn. ROW and AREA are the glyph row
17531 and area within the row from which S is constructed. START is the
17532 index of the first glyph structure covered by S. HL is a
17533 face-override for drawing S. */
17536 #define OPTIONAL_HDC(hdc) hdc,
17537 #define DECLARE_HDC(hdc) HDC hdc;
17538 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17539 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17542 #ifndef OPTIONAL_HDC
17543 #define OPTIONAL_HDC(hdc)
17544 #define DECLARE_HDC(hdc)
17545 #define ALLOCATE_HDC(hdc, f)
17546 #define RELEASE_HDC(hdc, f)
17550 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17551 struct glyph_string
*s
;
17555 struct glyph_row
*row
;
17556 enum glyph_row_area area
;
17558 enum draw_glyphs_face hl
;
17560 bzero (s
, sizeof *s
);
17562 s
->f
= XFRAME (w
->frame
);
17566 s
->display
= FRAME_X_DISPLAY (s
->f
);
17567 s
->window
= FRAME_X_WINDOW (s
->f
);
17568 s
->char2b
= char2b
;
17572 s
->first_glyph
= row
->glyphs
[area
] + start
;
17573 s
->height
= row
->height
;
17574 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17576 /* Display the internal border below the tool-bar window. */
17577 if (WINDOWP (s
->f
->tool_bar_window
)
17578 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17579 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17581 s
->ybase
= s
->y
+ row
->ascent
;
17585 /* Append the list of glyph strings with head H and tail T to the list
17586 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17589 append_glyph_string_lists (head
, tail
, h
, t
)
17590 struct glyph_string
**head
, **tail
;
17591 struct glyph_string
*h
, *t
;
17605 /* Prepend the list of glyph strings with head H and tail T to the
17606 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17610 prepend_glyph_string_lists (head
, tail
, h
, t
)
17611 struct glyph_string
**head
, **tail
;
17612 struct glyph_string
*h
, *t
;
17626 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17627 Set *HEAD and *TAIL to the resulting list. */
17630 append_glyph_string (head
, tail
, s
)
17631 struct glyph_string
**head
, **tail
;
17632 struct glyph_string
*s
;
17634 s
->next
= s
->prev
= NULL
;
17635 append_glyph_string_lists (head
, tail
, s
, s
);
17639 /* Get face and two-byte form of character glyph GLYPH on frame F.
17640 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17641 a pointer to a realized face that is ready for display. */
17643 static INLINE
struct face
*
17644 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17646 struct glyph
*glyph
;
17652 xassert (glyph
->type
== CHAR_GLYPH
);
17653 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17658 if (!glyph
->multibyte_p
)
17660 /* Unibyte case. We don't have to encode, but we have to make
17661 sure to use a face suitable for unibyte. */
17662 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17664 else if (glyph
->u
.ch
< 128
17665 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17667 /* Case of ASCII in a face known to fit ASCII. */
17668 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17672 int c1
, c2
, charset
;
17674 /* Split characters into bytes. If c2 is -1 afterwards, C is
17675 really a one-byte character so that byte1 is zero. */
17676 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17678 STORE_XCHAR2B (char2b
, c1
, c2
);
17680 STORE_XCHAR2B (char2b
, 0, c1
);
17682 /* Maybe encode the character in *CHAR2B. */
17683 if (charset
!= CHARSET_ASCII
)
17685 struct font_info
*font_info
17686 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17689 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17693 /* Make sure X resources of the face are allocated. */
17694 xassert (face
!= NULL
);
17695 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17700 /* Fill glyph string S with composition components specified by S->cmp.
17702 FACES is an array of faces for all components of this composition.
17703 S->gidx is the index of the first component for S.
17704 OVERLAPS_P non-zero means S should draw the foreground only, and
17705 use its physical height for clipping.
17707 Value is the index of a component not in S. */
17710 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17711 struct glyph_string
*s
;
17712 struct face
**faces
;
17719 s
->for_overlaps_p
= overlaps_p
;
17721 s
->face
= faces
[s
->gidx
];
17722 s
->font
= s
->face
->font
;
17723 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17725 /* For all glyphs of this composition, starting at the offset
17726 S->gidx, until we reach the end of the definition or encounter a
17727 glyph that requires the different face, add it to S. */
17729 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17732 /* All glyph strings for the same composition has the same width,
17733 i.e. the width set for the first component of the composition. */
17735 s
->width
= s
->first_glyph
->pixel_width
;
17737 /* If the specified font could not be loaded, use the frame's
17738 default font, but record the fact that we couldn't load it in
17739 the glyph string so that we can draw rectangles for the
17740 characters of the glyph string. */
17741 if (s
->font
== NULL
)
17743 s
->font_not_found_p
= 1;
17744 s
->font
= FRAME_FONT (s
->f
);
17747 /* Adjust base line for subscript/superscript text. */
17748 s
->ybase
+= s
->first_glyph
->voffset
;
17750 xassert (s
->face
&& s
->face
->gc
);
17752 /* This glyph string must always be drawn with 16-bit functions. */
17755 return s
->gidx
+ s
->nchars
;
17759 /* Fill glyph string S from a sequence of character glyphs.
17761 FACE_ID is the face id of the string. START is the index of the
17762 first glyph to consider, END is the index of the last + 1.
17763 OVERLAPS_P non-zero means S should draw the foreground only, and
17764 use its physical height for clipping.
17766 Value is the index of the first glyph not in S. */
17769 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17770 struct glyph_string
*s
;
17772 int start
, end
, overlaps_p
;
17774 struct glyph
*glyph
, *last
;
17776 int glyph_not_available_p
;
17778 xassert (s
->f
== XFRAME (s
->w
->frame
));
17779 xassert (s
->nchars
== 0);
17780 xassert (start
>= 0 && end
> start
);
17782 s
->for_overlaps_p
= overlaps_p
,
17783 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17784 last
= s
->row
->glyphs
[s
->area
] + end
;
17785 voffset
= glyph
->voffset
;
17787 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17789 while (glyph
< last
17790 && glyph
->type
== CHAR_GLYPH
17791 && glyph
->voffset
== voffset
17792 /* Same face id implies same font, nowadays. */
17793 && glyph
->face_id
== face_id
17794 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17798 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17799 s
->char2b
+ s
->nchars
,
17801 s
->two_byte_p
= two_byte_p
;
17803 xassert (s
->nchars
<= end
- start
);
17804 s
->width
+= glyph
->pixel_width
;
17808 s
->font
= s
->face
->font
;
17809 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17811 /* If the specified font could not be loaded, use the frame's font,
17812 but record the fact that we couldn't load it in
17813 S->font_not_found_p so that we can draw rectangles for the
17814 characters of the glyph string. */
17815 if (s
->font
== NULL
|| glyph_not_available_p
)
17817 s
->font_not_found_p
= 1;
17818 s
->font
= FRAME_FONT (s
->f
);
17821 /* Adjust base line for subscript/superscript text. */
17822 s
->ybase
+= voffset
;
17824 xassert (s
->face
&& s
->face
->gc
);
17825 return glyph
- s
->row
->glyphs
[s
->area
];
17829 /* Fill glyph string S from image glyph S->first_glyph. */
17832 fill_image_glyph_string (s
)
17833 struct glyph_string
*s
;
17835 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17836 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17838 s
->slice
= s
->first_glyph
->slice
;
17839 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17840 s
->font
= s
->face
->font
;
17841 s
->width
= s
->first_glyph
->pixel_width
;
17843 /* Adjust base line for subscript/superscript text. */
17844 s
->ybase
+= s
->first_glyph
->voffset
;
17848 /* Fill glyph string S from a sequence of stretch glyphs.
17850 ROW is the glyph row in which the glyphs are found, AREA is the
17851 area within the row. START is the index of the first glyph to
17852 consider, END is the index of the last + 1.
17854 Value is the index of the first glyph not in S. */
17857 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17858 struct glyph_string
*s
;
17859 struct glyph_row
*row
;
17860 enum glyph_row_area area
;
17863 struct glyph
*glyph
, *last
;
17864 int voffset
, face_id
;
17866 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17868 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17869 last
= s
->row
->glyphs
[s
->area
] + end
;
17870 face_id
= glyph
->face_id
;
17871 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17872 s
->font
= s
->face
->font
;
17873 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17874 s
->width
= glyph
->pixel_width
;
17875 voffset
= glyph
->voffset
;
17879 && glyph
->type
== STRETCH_GLYPH
17880 && glyph
->voffset
== voffset
17881 && glyph
->face_id
== face_id
);
17883 s
->width
+= glyph
->pixel_width
;
17885 /* Adjust base line for subscript/superscript text. */
17886 s
->ybase
+= voffset
;
17888 /* The case that face->gc == 0 is handled when drawing the glyph
17889 string by calling PREPARE_FACE_FOR_DISPLAY. */
17891 return glyph
- s
->row
->glyphs
[s
->area
];
17896 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17897 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17898 assumed to be zero. */
17901 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17902 struct glyph
*glyph
;
17906 *left
= *right
= 0;
17908 if (glyph
->type
== CHAR_GLYPH
)
17912 struct font_info
*font_info
;
17916 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17918 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17919 if (font
/* ++KFS: Should this be font_info ? */
17920 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17922 if (pcm
->rbearing
> pcm
->width
)
17923 *right
= pcm
->rbearing
- pcm
->width
;
17924 if (pcm
->lbearing
< 0)
17925 *left
= -pcm
->lbearing
;
17931 /* Return the index of the first glyph preceding glyph string S that
17932 is overwritten by S because of S's left overhang. Value is -1
17933 if no glyphs are overwritten. */
17936 left_overwritten (s
)
17937 struct glyph_string
*s
;
17941 if (s
->left_overhang
)
17944 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17945 int first
= s
->first_glyph
- glyphs
;
17947 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17948 x
-= glyphs
[i
].pixel_width
;
17959 /* Return the index of the first glyph preceding glyph string S that
17960 is overwriting S because of its right overhang. Value is -1 if no
17961 glyph in front of S overwrites S. */
17964 left_overwriting (s
)
17965 struct glyph_string
*s
;
17968 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17969 int first
= s
->first_glyph
- glyphs
;
17973 for (i
= first
- 1; i
>= 0; --i
)
17976 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17979 x
-= glyphs
[i
].pixel_width
;
17986 /* Return the index of the last glyph following glyph string S that is
17987 not overwritten by S because of S's right overhang. Value is -1 if
17988 no such glyph is found. */
17991 right_overwritten (s
)
17992 struct glyph_string
*s
;
17996 if (s
->right_overhang
)
17999 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18000 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18001 int end
= s
->row
->used
[s
->area
];
18003 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18004 x
+= glyphs
[i
].pixel_width
;
18013 /* Return the index of the last glyph following glyph string S that
18014 overwrites S because of its left overhang. Value is negative
18015 if no such glyph is found. */
18018 right_overwriting (s
)
18019 struct glyph_string
*s
;
18022 int end
= s
->row
->used
[s
->area
];
18023 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18024 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18028 for (i
= first
; i
< end
; ++i
)
18031 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18034 x
+= glyphs
[i
].pixel_width
;
18041 /* Get face and two-byte form of character C in face FACE_ID on frame
18042 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18043 means we want to display multibyte text. DISPLAY_P non-zero means
18044 make sure that X resources for the face returned are allocated.
18045 Value is a pointer to a realized face that is ready for display if
18046 DISPLAY_P is non-zero. */
18048 static INLINE
struct face
*
18049 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18053 int multibyte_p
, display_p
;
18055 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18059 /* Unibyte case. We don't have to encode, but we have to make
18060 sure to use a face suitable for unibyte. */
18061 STORE_XCHAR2B (char2b
, 0, c
);
18062 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18063 face
= FACE_FROM_ID (f
, face_id
);
18065 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18067 /* Case of ASCII in a face known to fit ASCII. */
18068 STORE_XCHAR2B (char2b
, 0, c
);
18072 int c1
, c2
, charset
;
18074 /* Split characters into bytes. If c2 is -1 afterwards, C is
18075 really a one-byte character so that byte1 is zero. */
18076 SPLIT_CHAR (c
, charset
, c1
, c2
);
18078 STORE_XCHAR2B (char2b
, c1
, c2
);
18080 STORE_XCHAR2B (char2b
, 0, c1
);
18082 /* Maybe encode the character in *CHAR2B. */
18083 if (face
->font
!= NULL
)
18085 struct font_info
*font_info
18086 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18088 rif
->encode_char (c
, char2b
, font_info
, 0);
18092 /* Make sure X resources of the face are allocated. */
18093 #ifdef HAVE_X_WINDOWS
18097 xassert (face
!= NULL
);
18098 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18105 /* Set background width of glyph string S. START is the index of the
18106 first glyph following S. LAST_X is the right-most x-position + 1
18107 in the drawing area. */
18110 set_glyph_string_background_width (s
, start
, last_x
)
18111 struct glyph_string
*s
;
18115 /* If the face of this glyph string has to be drawn to the end of
18116 the drawing area, set S->extends_to_end_of_line_p. */
18117 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18119 if (start
== s
->row
->used
[s
->area
]
18120 && s
->area
== TEXT_AREA
18121 && ((s
->hl
== DRAW_NORMAL_TEXT
18122 && (s
->row
->fill_line_p
18123 || s
->face
->background
!= default_face
->background
18124 || s
->face
->stipple
!= default_face
->stipple
18125 || s
->row
->mouse_face_p
))
18126 || s
->hl
== DRAW_MOUSE_FACE
18127 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18128 && s
->row
->fill_line_p
)))
18129 s
->extends_to_end_of_line_p
= 1;
18131 /* If S extends its face to the end of the line, set its
18132 background_width to the distance to the right edge of the drawing
18134 if (s
->extends_to_end_of_line_p
)
18135 s
->background_width
= last_x
- s
->x
+ 1;
18137 s
->background_width
= s
->width
;
18141 /* Compute overhangs and x-positions for glyph string S and its
18142 predecessors, or successors. X is the starting x-position for S.
18143 BACKWARD_P non-zero means process predecessors. */
18146 compute_overhangs_and_x (s
, x
, backward_p
)
18147 struct glyph_string
*s
;
18155 if (rif
->compute_glyph_string_overhangs
)
18156 rif
->compute_glyph_string_overhangs (s
);
18166 if (rif
->compute_glyph_string_overhangs
)
18167 rif
->compute_glyph_string_overhangs (s
);
18177 /* The following macros are only called from draw_glyphs below.
18178 They reference the following parameters of that function directly:
18179 `w', `row', `area', and `overlap_p'
18180 as well as the following local variables:
18181 `s', `f', and `hdc' (in W32) */
18184 /* On W32, silently add local `hdc' variable to argument list of
18185 init_glyph_string. */
18186 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18187 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18189 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18190 init_glyph_string (s, char2b, w, row, area, start, hl)
18193 /* Add a glyph string for a stretch glyph to the list of strings
18194 between HEAD and TAIL. START is the index of the stretch glyph in
18195 row area AREA of glyph row ROW. END is the index of the last glyph
18196 in that glyph row area. X is the current output position assigned
18197 to the new glyph string constructed. HL overrides that face of the
18198 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18199 is the right-most x-position of the drawing area. */
18201 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18202 and below -- keep them on one line. */
18203 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18206 s = (struct glyph_string *) alloca (sizeof *s); \
18207 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18208 START = fill_stretch_glyph_string (s, row, area, START, END); \
18209 append_glyph_string (&HEAD, &TAIL, s); \
18215 /* Add a glyph string for an image glyph to the list of strings
18216 between HEAD and TAIL. START is the index of the image glyph in
18217 row area AREA of glyph row ROW. END is the index of the last glyph
18218 in that glyph row area. X is the current output position assigned
18219 to the new glyph string constructed. HL overrides that face of the
18220 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18221 is the right-most x-position of the drawing area. */
18223 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18226 s = (struct glyph_string *) alloca (sizeof *s); \
18227 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18228 fill_image_glyph_string (s); \
18229 append_glyph_string (&HEAD, &TAIL, s); \
18236 /* Add a glyph string for a sequence of character glyphs to the list
18237 of strings between HEAD and TAIL. START is the index of the first
18238 glyph in row area AREA of glyph row ROW that is part of the new
18239 glyph string. END is the index of the last glyph in that glyph row
18240 area. X is the current output position assigned to the new glyph
18241 string constructed. HL overrides that face of the glyph; e.g. it
18242 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18243 right-most x-position of the drawing area. */
18245 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18251 c = (row)->glyphs[area][START].u.ch; \
18252 face_id = (row)->glyphs[area][START].face_id; \
18254 s = (struct glyph_string *) alloca (sizeof *s); \
18255 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18256 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18257 append_glyph_string (&HEAD, &TAIL, s); \
18259 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18264 /* Add a glyph string for a composite sequence to the list of strings
18265 between HEAD and TAIL. START is the index of the first glyph in
18266 row area AREA of glyph row ROW that is part of the new glyph
18267 string. END is the index of the last glyph in that glyph row area.
18268 X is the current output position assigned to the new glyph string
18269 constructed. HL overrides that face of the glyph; e.g. it is
18270 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18271 x-position of the drawing area. */
18273 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18275 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18276 int face_id = (row)->glyphs[area][START].face_id; \
18277 struct face *base_face = FACE_FROM_ID (f, face_id); \
18278 struct composition *cmp = composition_table[cmp_id]; \
18279 int glyph_len = cmp->glyph_len; \
18281 struct face **faces; \
18282 struct glyph_string *first_s = NULL; \
18285 base_face = base_face->ascii_face; \
18286 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18287 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18288 /* At first, fill in `char2b' and `faces'. */ \
18289 for (n = 0; n < glyph_len; n++) \
18291 int c = COMPOSITION_GLYPH (cmp, n); \
18292 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18293 faces[n] = FACE_FROM_ID (f, this_face_id); \
18294 get_char_face_and_encoding (f, c, this_face_id, \
18295 char2b + n, 1, 1); \
18298 /* Make glyph_strings for each glyph sequence that is drawable by \
18299 the same face, and append them to HEAD/TAIL. */ \
18300 for (n = 0; n < cmp->glyph_len;) \
18302 s = (struct glyph_string *) alloca (sizeof *s); \
18303 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18304 append_glyph_string (&(HEAD), &(TAIL), s); \
18312 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18320 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18321 of AREA of glyph row ROW on window W between indices START and END.
18322 HL overrides the face for drawing glyph strings, e.g. it is
18323 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18324 x-positions of the drawing area.
18326 This is an ugly monster macro construct because we must use alloca
18327 to allocate glyph strings (because draw_glyphs can be called
18328 asynchronously). */
18330 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18333 HEAD = TAIL = NULL; \
18334 while (START < END) \
18336 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18337 switch (first_glyph->type) \
18340 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18344 case COMPOSITE_GLYPH: \
18345 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18349 case STRETCH_GLYPH: \
18350 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18354 case IMAGE_GLYPH: \
18355 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18363 set_glyph_string_background_width (s, START, LAST_X); \
18370 /* Draw glyphs between START and END in AREA of ROW on window W,
18371 starting at x-position X. X is relative to AREA in W. HL is a
18372 face-override with the following meaning:
18374 DRAW_NORMAL_TEXT draw normally
18375 DRAW_CURSOR draw in cursor face
18376 DRAW_MOUSE_FACE draw in mouse face.
18377 DRAW_INVERSE_VIDEO draw in mode line face
18378 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18379 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18381 If OVERLAPS_P is non-zero, draw only the foreground of characters
18382 and clip to the physical height of ROW.
18384 Value is the x-position reached, relative to AREA of W. */
18387 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18390 struct glyph_row
*row
;
18391 enum glyph_row_area area
;
18393 enum draw_glyphs_face hl
;
18396 struct glyph_string
*head
, *tail
;
18397 struct glyph_string
*s
;
18398 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18399 int last_x
, area_width
;
18402 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18405 ALLOCATE_HDC (hdc
, f
);
18407 /* Let's rather be paranoid than getting a SEGV. */
18408 end
= min (end
, row
->used
[area
]);
18409 start
= max (0, start
);
18410 start
= min (end
, start
);
18412 /* Translate X to frame coordinates. Set last_x to the right
18413 end of the drawing area. */
18414 if (row
->full_width_p
)
18416 /* X is relative to the left edge of W, without scroll bars
18418 x
+= WINDOW_LEFT_EDGE_X (w
);
18419 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18423 int area_left
= window_box_left (w
, area
);
18425 area_width
= window_box_width (w
, area
);
18426 last_x
= area_left
+ area_width
;
18429 /* Build a doubly-linked list of glyph_string structures between
18430 head and tail from what we have to draw. Note that the macro
18431 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18432 the reason we use a separate variable `i'. */
18434 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18436 x_reached
= tail
->x
+ tail
->background_width
;
18440 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18441 the row, redraw some glyphs in front or following the glyph
18442 strings built above. */
18443 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18446 struct glyph_string
*h
, *t
;
18448 /* Compute overhangs for all glyph strings. */
18449 if (rif
->compute_glyph_string_overhangs
)
18450 for (s
= head
; s
; s
= s
->next
)
18451 rif
->compute_glyph_string_overhangs (s
);
18453 /* Prepend glyph strings for glyphs in front of the first glyph
18454 string that are overwritten because of the first glyph
18455 string's left overhang. The background of all strings
18456 prepended must be drawn because the first glyph string
18458 i
= left_overwritten (head
);
18462 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18463 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18465 compute_overhangs_and_x (t
, head
->x
, 1);
18466 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18470 /* Prepend glyph strings for glyphs in front of the first glyph
18471 string that overwrite that glyph string because of their
18472 right overhang. For these strings, only the foreground must
18473 be drawn, because it draws over the glyph string at `head'.
18474 The background must not be drawn because this would overwrite
18475 right overhangs of preceding glyphs for which no glyph
18477 i
= left_overwriting (head
);
18481 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18482 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18483 for (s
= h
; s
; s
= s
->next
)
18484 s
->background_filled_p
= 1;
18485 compute_overhangs_and_x (t
, head
->x
, 1);
18486 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18489 /* Append glyphs strings for glyphs following the last glyph
18490 string tail that are overwritten by tail. The background of
18491 these strings has to be drawn because tail's foreground draws
18493 i
= right_overwritten (tail
);
18496 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18497 DRAW_NORMAL_TEXT
, x
, last_x
);
18498 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18499 append_glyph_string_lists (&head
, &tail
, h
, t
);
18503 /* Append glyph strings for glyphs following the last glyph
18504 string tail that overwrite tail. The foreground of such
18505 glyphs has to be drawn because it writes into the background
18506 of tail. The background must not be drawn because it could
18507 paint over the foreground of following glyphs. */
18508 i
= right_overwriting (tail
);
18512 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18513 DRAW_NORMAL_TEXT
, x
, last_x
);
18514 for (s
= h
; s
; s
= s
->next
)
18515 s
->background_filled_p
= 1;
18516 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18517 append_glyph_string_lists (&head
, &tail
, h
, t
);
18519 if (clip_head
|| clip_tail
)
18520 for (s
= head
; s
; s
= s
->next
)
18522 s
->clip_head
= clip_head
;
18523 s
->clip_tail
= clip_tail
;
18527 /* Draw all strings. */
18528 for (s
= head
; s
; s
= s
->next
)
18529 rif
->draw_glyph_string (s
);
18531 if (area
== TEXT_AREA
18532 && !row
->full_width_p
18533 /* When drawing overlapping rows, only the glyph strings'
18534 foreground is drawn, which doesn't erase a cursor
18538 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18539 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18540 : (tail
? tail
->x
+ tail
->background_width
: x
));
18542 int text_left
= window_box_left (w
, TEXT_AREA
);
18546 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18547 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18550 /* Value is the x-position up to which drawn, relative to AREA of W.
18551 This doesn't include parts drawn because of overhangs. */
18552 if (row
->full_width_p
)
18553 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18555 x_reached
-= window_box_left (w
, area
);
18557 RELEASE_HDC (hdc
, f
);
18562 /* Expand row matrix if too narrow. Don't expand if area
18565 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18567 if (!fonts_changed_p \
18568 && (it->glyph_row->glyphs[area] \
18569 < it->glyph_row->glyphs[area + 1])) \
18571 it->w->ncols_scale_factor++; \
18572 fonts_changed_p = 1; \
18576 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18577 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18583 struct glyph
*glyph
;
18584 enum glyph_row_area area
= it
->area
;
18586 xassert (it
->glyph_row
);
18587 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18589 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18590 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18592 glyph
->charpos
= CHARPOS (it
->position
);
18593 glyph
->object
= it
->object
;
18594 glyph
->pixel_width
= it
->pixel_width
;
18595 glyph
->ascent
= it
->ascent
;
18596 glyph
->descent
= it
->descent
;
18597 glyph
->voffset
= it
->voffset
;
18598 glyph
->type
= CHAR_GLYPH
;
18599 glyph
->multibyte_p
= it
->multibyte_p
;
18600 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18601 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18602 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18603 || it
->phys_descent
> it
->descent
);
18604 glyph
->padding_p
= 0;
18605 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18606 glyph
->face_id
= it
->face_id
;
18607 glyph
->u
.ch
= it
->char_to_display
;
18608 glyph
->slice
= null_glyph_slice
;
18609 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18610 ++it
->glyph_row
->used
[area
];
18613 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18616 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18617 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18620 append_composite_glyph (it
)
18623 struct glyph
*glyph
;
18624 enum glyph_row_area area
= it
->area
;
18626 xassert (it
->glyph_row
);
18628 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18629 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18631 glyph
->charpos
= CHARPOS (it
->position
);
18632 glyph
->object
= it
->object
;
18633 glyph
->pixel_width
= it
->pixel_width
;
18634 glyph
->ascent
= it
->ascent
;
18635 glyph
->descent
= it
->descent
;
18636 glyph
->voffset
= it
->voffset
;
18637 glyph
->type
= COMPOSITE_GLYPH
;
18638 glyph
->multibyte_p
= it
->multibyte_p
;
18639 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18640 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18641 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18642 || it
->phys_descent
> it
->descent
);
18643 glyph
->padding_p
= 0;
18644 glyph
->glyph_not_available_p
= 0;
18645 glyph
->face_id
= it
->face_id
;
18646 glyph
->u
.cmp_id
= it
->cmp_id
;
18647 glyph
->slice
= null_glyph_slice
;
18648 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18649 ++it
->glyph_row
->used
[area
];
18652 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18656 /* Change IT->ascent and IT->height according to the setting of
18660 take_vertical_position_into_account (it
)
18665 if (it
->voffset
< 0)
18666 /* Increase the ascent so that we can display the text higher
18668 it
->ascent
-= it
->voffset
;
18670 /* Increase the descent so that we can display the text lower
18672 it
->descent
+= it
->voffset
;
18677 /* Produce glyphs/get display metrics for the image IT is loaded with.
18678 See the description of struct display_iterator in dispextern.h for
18679 an overview of struct display_iterator. */
18682 produce_image_glyph (it
)
18688 struct glyph_slice slice
;
18690 xassert (it
->what
== IT_IMAGE
);
18692 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18694 /* Make sure X resources of the face is loaded. */
18695 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18697 if (it
->image_id
< 0)
18699 /* Fringe bitmap. */
18700 it
->ascent
= it
->phys_ascent
= 0;
18701 it
->descent
= it
->phys_descent
= 0;
18702 it
->pixel_width
= 0;
18707 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18709 /* Make sure X resources of the image is loaded. */
18710 prepare_image_for_display (it
->f
, img
);
18712 slice
.x
= slice
.y
= 0;
18713 slice
.width
= img
->width
;
18714 slice
.height
= img
->height
;
18716 if (INTEGERP (it
->slice
.x
))
18717 slice
.x
= XINT (it
->slice
.x
);
18718 else if (FLOATP (it
->slice
.x
))
18719 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18721 if (INTEGERP (it
->slice
.y
))
18722 slice
.y
= XINT (it
->slice
.y
);
18723 else if (FLOATP (it
->slice
.y
))
18724 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18726 if (INTEGERP (it
->slice
.width
))
18727 slice
.width
= XINT (it
->slice
.width
);
18728 else if (FLOATP (it
->slice
.width
))
18729 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18731 if (INTEGERP (it
->slice
.height
))
18732 slice
.height
= XINT (it
->slice
.height
);
18733 else if (FLOATP (it
->slice
.height
))
18734 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18736 if (slice
.x
>= img
->width
)
18737 slice
.x
= img
->width
;
18738 if (slice
.y
>= img
->height
)
18739 slice
.y
= img
->height
;
18740 if (slice
.x
+ slice
.width
>= img
->width
)
18741 slice
.width
= img
->width
- slice
.x
;
18742 if (slice
.y
+ slice
.height
> img
->height
)
18743 slice
.height
= img
->height
- slice
.y
;
18745 if (slice
.width
== 0 || slice
.height
== 0)
18748 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18750 it
->descent
= slice
.height
- glyph_ascent
;
18752 it
->descent
+= img
->vmargin
;
18753 if (slice
.y
+ slice
.height
== img
->height
)
18754 it
->descent
+= img
->vmargin
;
18755 it
->phys_descent
= it
->descent
;
18757 it
->pixel_width
= slice
.width
;
18759 it
->pixel_width
+= img
->hmargin
;
18760 if (slice
.x
+ slice
.width
== img
->width
)
18761 it
->pixel_width
+= img
->hmargin
;
18763 /* It's quite possible for images to have an ascent greater than
18764 their height, so don't get confused in that case. */
18765 if (it
->descent
< 0)
18768 #if 0 /* this breaks image tiling */
18769 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18770 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18771 if (face_ascent
> it
->ascent
)
18772 it
->ascent
= it
->phys_ascent
= face_ascent
;
18777 if (face
->box
!= FACE_NO_BOX
)
18779 if (face
->box_line_width
> 0)
18782 it
->ascent
+= face
->box_line_width
;
18783 if (slice
.y
+ slice
.height
== img
->height
)
18784 it
->descent
+= face
->box_line_width
;
18787 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18788 it
->pixel_width
+= abs (face
->box_line_width
);
18789 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18790 it
->pixel_width
+= abs (face
->box_line_width
);
18793 take_vertical_position_into_account (it
);
18797 struct glyph
*glyph
;
18798 enum glyph_row_area area
= it
->area
;
18800 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18801 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18803 glyph
->charpos
= CHARPOS (it
->position
);
18804 glyph
->object
= it
->object
;
18805 glyph
->pixel_width
= it
->pixel_width
;
18806 glyph
->ascent
= glyph_ascent
;
18807 glyph
->descent
= it
->descent
;
18808 glyph
->voffset
= it
->voffset
;
18809 glyph
->type
= IMAGE_GLYPH
;
18810 glyph
->multibyte_p
= it
->multibyte_p
;
18811 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18812 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18813 glyph
->overlaps_vertically_p
= 0;
18814 glyph
->padding_p
= 0;
18815 glyph
->glyph_not_available_p
= 0;
18816 glyph
->face_id
= it
->face_id
;
18817 glyph
->u
.img_id
= img
->id
;
18818 glyph
->slice
= slice
;
18819 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18820 ++it
->glyph_row
->used
[area
];
18823 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18828 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18829 of the glyph, WIDTH and HEIGHT are the width and height of the
18830 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18833 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18835 Lisp_Object object
;
18839 struct glyph
*glyph
;
18840 enum glyph_row_area area
= it
->area
;
18842 xassert (ascent
>= 0 && ascent
<= height
);
18844 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18845 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18847 glyph
->charpos
= CHARPOS (it
->position
);
18848 glyph
->object
= object
;
18849 glyph
->pixel_width
= width
;
18850 glyph
->ascent
= ascent
;
18851 glyph
->descent
= height
- ascent
;
18852 glyph
->voffset
= it
->voffset
;
18853 glyph
->type
= STRETCH_GLYPH
;
18854 glyph
->multibyte_p
= it
->multibyte_p
;
18855 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18856 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18857 glyph
->overlaps_vertically_p
= 0;
18858 glyph
->padding_p
= 0;
18859 glyph
->glyph_not_available_p
= 0;
18860 glyph
->face_id
= it
->face_id
;
18861 glyph
->u
.stretch
.ascent
= ascent
;
18862 glyph
->u
.stretch
.height
= height
;
18863 glyph
->slice
= null_glyph_slice
;
18864 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18865 ++it
->glyph_row
->used
[area
];
18868 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18872 /* Produce a stretch glyph for iterator IT. IT->object is the value
18873 of the glyph property displayed. The value must be a list
18874 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18877 1. `:width WIDTH' specifies that the space should be WIDTH *
18878 canonical char width wide. WIDTH may be an integer or floating
18881 2. `:relative-width FACTOR' specifies that the width of the stretch
18882 should be computed from the width of the first character having the
18883 `glyph' property, and should be FACTOR times that width.
18885 3. `:align-to HPOS' specifies that the space should be wide enough
18886 to reach HPOS, a value in canonical character units.
18888 Exactly one of the above pairs must be present.
18890 4. `:height HEIGHT' specifies that the height of the stretch produced
18891 should be HEIGHT, measured in canonical character units.
18893 5. `:relative-height FACTOR' specifies that the height of the
18894 stretch should be FACTOR times the height of the characters having
18895 the glyph property.
18897 Either none or exactly one of 4 or 5 must be present.
18899 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18900 of the stretch should be used for the ascent of the stretch.
18901 ASCENT must be in the range 0 <= ASCENT <= 100. */
18904 produce_stretch_glyph (it
)
18907 /* (space :width WIDTH :height HEIGHT ...) */
18908 Lisp_Object prop
, plist
;
18909 int width
= 0, height
= 0, align_to
= -1;
18910 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18913 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18914 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18916 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18918 /* List should start with `space'. */
18919 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18920 plist
= XCDR (it
->object
);
18922 /* Compute the width of the stretch. */
18923 if ((prop
= Fsafe_plist_get (plist
, QCwidth
), !NILP (prop
))
18924 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18926 /* Absolute width `:width WIDTH' specified and valid. */
18927 zero_width_ok_p
= 1;
18930 else if (prop
= Fsafe_plist_get (plist
, QCrelative_width
),
18933 /* Relative width `:relative-width FACTOR' specified and valid.
18934 Compute the width of the characters having the `glyph'
18937 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18940 if (it
->multibyte_p
)
18942 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18943 - IT_BYTEPOS (*it
));
18944 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18947 it2
.c
= *p
, it2
.len
= 1;
18949 it2
.glyph_row
= NULL
;
18950 it2
.what
= IT_CHARACTER
;
18951 x_produce_glyphs (&it2
);
18952 width
= NUMVAL (prop
) * it2
.pixel_width
;
18954 else if ((prop
= Fsafe_plist_get (plist
, QCalign_to
), !NILP (prop
))
18955 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18957 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18958 align_to
= (align_to
< 0
18960 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18961 else if (align_to
< 0)
18962 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18963 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18964 zero_width_ok_p
= 1;
18967 /* Nothing specified -> width defaults to canonical char width. */
18968 width
= FRAME_COLUMN_WIDTH (it
->f
);
18970 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18973 /* Compute height. */
18974 if ((prop
= Fsafe_plist_get (plist
, QCheight
), !NILP (prop
))
18975 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18978 zero_height_ok_p
= 1;
18980 else if (prop
= Fsafe_plist_get (plist
, QCrelative_height
),
18982 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18984 height
= FONT_HEIGHT (font
);
18986 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18989 /* Compute percentage of height used for ascent. If
18990 `:ascent ASCENT' is present and valid, use that. Otherwise,
18991 derive the ascent from the font in use. */
18992 if (prop
= Fsafe_plist_get (plist
, QCascent
),
18993 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18994 ascent
= height
* NUMVAL (prop
) / 100.0;
18995 else if (!NILP (prop
)
18996 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18997 ascent
= min (max (0, (int)tem
), height
);
18999 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19001 if (width
> 0 && height
> 0 && it
->glyph_row
)
19003 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19004 if (!STRINGP (object
))
19005 object
= it
->w
->buffer
;
19006 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19009 it
->pixel_width
= width
;
19010 it
->ascent
= it
->phys_ascent
= ascent
;
19011 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19012 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19014 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19016 if (face
->box_line_width
> 0)
19018 it
->ascent
+= face
->box_line_width
;
19019 it
->descent
+= face
->box_line_width
;
19022 if (it
->start_of_box_run_p
)
19023 it
->pixel_width
+= abs (face
->box_line_width
);
19024 if (it
->end_of_box_run_p
)
19025 it
->pixel_width
+= abs (face
->box_line_width
);
19028 take_vertical_position_into_account (it
);
19031 /* Get line-height and line-spacing property at point.
19032 If line-height has format (HEIGHT TOTAL), return TOTAL
19033 in TOTAL_HEIGHT. */
19036 get_line_height_property (it
, prop
)
19040 Lisp_Object position
, val
;
19042 if (STRINGP (it
->object
))
19043 position
= make_number (IT_STRING_CHARPOS (*it
));
19044 else if (BUFFERP (it
->object
))
19045 position
= make_number (IT_CHARPOS (*it
));
19049 return Fget_char_property (position
, prop
, it
->object
);
19052 /* Calculate line-height and line-spacing properties.
19053 An integer value specifies explicit pixel value.
19054 A float value specifies relative value to current face height.
19055 A cons (float . face-name) specifies relative value to
19056 height of specified face font.
19058 Returns height in pixels, or nil. */
19062 calc_line_height_property (it
, val
, font
, boff
, override
)
19066 int boff
, override
;
19068 Lisp_Object face_name
= Qnil
;
19069 int ascent
, descent
, height
;
19071 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19076 face_name
= XCAR (val
);
19078 if (!NUMBERP (val
))
19079 val
= make_number (1);
19080 if (NILP (face_name
))
19082 height
= it
->ascent
+ it
->descent
;
19087 if (NILP (face_name
))
19089 font
= FRAME_FONT (it
->f
);
19090 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19092 else if (EQ (face_name
, Qt
))
19100 struct font_info
*font_info
;
19102 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19104 return make_number (-1);
19106 face
= FACE_FROM_ID (it
->f
, face_id
);
19109 return make_number (-1);
19111 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19112 boff
= font_info
->baseline_offset
;
19113 if (font_info
->vertical_centering
)
19114 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19117 ascent
= FONT_BASE (font
) + boff
;
19118 descent
= FONT_DESCENT (font
) - boff
;
19122 it
->override_ascent
= ascent
;
19123 it
->override_descent
= descent
;
19124 it
->override_boff
= boff
;
19127 height
= ascent
+ descent
;
19131 height
= (int)(XFLOAT_DATA (val
) * height
);
19132 else if (INTEGERP (val
))
19133 height
*= XINT (val
);
19135 return make_number (height
);
19140 Produce glyphs/get display metrics for the display element IT is
19141 loaded with. See the description of struct display_iterator in
19142 dispextern.h for an overview of struct display_iterator. */
19145 x_produce_glyphs (it
)
19148 int extra_line_spacing
= it
->extra_line_spacing
;
19150 it
->glyph_not_available_p
= 0;
19152 if (it
->what
== IT_CHARACTER
)
19156 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19158 int font_not_found_p
;
19159 struct font_info
*font_info
;
19160 int boff
; /* baseline offset */
19161 /* We may change it->multibyte_p upon unibyte<->multibyte
19162 conversion. So, save the current value now and restore it
19165 Note: It seems that we don't have to record multibyte_p in
19166 struct glyph because the character code itself tells if or
19167 not the character is multibyte. Thus, in the future, we must
19168 consider eliminating the field `multibyte_p' in the struct
19170 int saved_multibyte_p
= it
->multibyte_p
;
19172 /* Maybe translate single-byte characters to multibyte, or the
19174 it
->char_to_display
= it
->c
;
19175 if (!ASCII_BYTE_P (it
->c
))
19177 if (unibyte_display_via_language_environment
19178 && SINGLE_BYTE_CHAR_P (it
->c
)
19180 || !NILP (Vnonascii_translation_table
)))
19182 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19183 it
->multibyte_p
= 1;
19184 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19185 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19187 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19188 && !it
->multibyte_p
)
19190 it
->multibyte_p
= 1;
19191 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19192 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19196 /* Get font to use. Encode IT->char_to_display. */
19197 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19198 &char2b
, it
->multibyte_p
, 0);
19201 /* When no suitable font found, use the default font. */
19202 font_not_found_p
= font
== NULL
;
19203 if (font_not_found_p
)
19205 font
= FRAME_FONT (it
->f
);
19206 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19211 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19212 boff
= font_info
->baseline_offset
;
19213 if (font_info
->vertical_centering
)
19214 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19217 if (it
->char_to_display
>= ' '
19218 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19220 /* Either unibyte or ASCII. */
19225 pcm
= rif
->per_char_metric (font
, &char2b
,
19226 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19228 if (it
->override_ascent
>= 0)
19230 it
->ascent
= it
->override_ascent
;
19231 it
->descent
= it
->override_descent
;
19232 boff
= it
->override_boff
;
19236 it
->ascent
= FONT_BASE (font
) + boff
;
19237 it
->descent
= FONT_DESCENT (font
) - boff
;
19242 it
->phys_ascent
= pcm
->ascent
+ boff
;
19243 it
->phys_descent
= pcm
->descent
- boff
;
19244 it
->pixel_width
= pcm
->width
;
19248 it
->glyph_not_available_p
= 1;
19249 it
->phys_ascent
= it
->ascent
;
19250 it
->phys_descent
= it
->descent
;
19251 it
->pixel_width
= FONT_WIDTH (font
);
19254 if (it
->constrain_row_ascent_descent_p
)
19256 if (it
->descent
> it
->max_descent
)
19258 it
->ascent
+= it
->descent
- it
->max_descent
;
19259 it
->descent
= it
->max_descent
;
19261 if (it
->ascent
> it
->max_ascent
)
19263 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19264 it
->ascent
= it
->max_ascent
;
19266 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19267 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19268 extra_line_spacing
= 0;
19271 /* If this is a space inside a region of text with
19272 `space-width' property, change its width. */
19273 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19275 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19277 /* If face has a box, add the box thickness to the character
19278 height. If character has a box line to the left and/or
19279 right, add the box line width to the character's width. */
19280 if (face
->box
!= FACE_NO_BOX
)
19282 int thick
= face
->box_line_width
;
19286 it
->ascent
+= thick
;
19287 it
->descent
+= thick
;
19292 if (it
->start_of_box_run_p
)
19293 it
->pixel_width
+= thick
;
19294 if (it
->end_of_box_run_p
)
19295 it
->pixel_width
+= thick
;
19298 /* If face has an overline, add the height of the overline
19299 (1 pixel) and a 1 pixel margin to the character height. */
19300 if (face
->overline_p
)
19303 if (it
->constrain_row_ascent_descent_p
)
19305 if (it
->ascent
> it
->max_ascent
)
19306 it
->ascent
= it
->max_ascent
;
19307 if (it
->descent
> it
->max_descent
)
19308 it
->descent
= it
->max_descent
;
19311 take_vertical_position_into_account (it
);
19313 /* If we have to actually produce glyphs, do it. */
19318 /* Translate a space with a `space-width' property
19319 into a stretch glyph. */
19320 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19321 / FONT_HEIGHT (font
));
19322 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19323 it
->ascent
+ it
->descent
, ascent
);
19328 /* If characters with lbearing or rbearing are displayed
19329 in this line, record that fact in a flag of the
19330 glyph row. This is used to optimize X output code. */
19331 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19332 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19335 else if (it
->char_to_display
== '\n')
19337 /* A newline has no width but we need the height of the line.
19338 But if previous part of the line set a height, don't
19339 increase that height */
19341 Lisp_Object height
;
19342 Lisp_Object total_height
= Qnil
;
19344 it
->override_ascent
= -1;
19345 it
->pixel_width
= 0;
19348 height
= get_line_height_property(it
, Qline_height
);
19349 /* Split (line-height total-height) list */
19351 && CONSP (XCDR (height
))
19352 && NILP (XCDR (XCDR (height
))))
19354 total_height
= XCAR (XCDR (height
));
19355 height
= XCAR (height
);
19357 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19359 if (it
->override_ascent
>= 0)
19361 it
->ascent
= it
->override_ascent
;
19362 it
->descent
= it
->override_descent
;
19363 boff
= it
->override_boff
;
19367 it
->ascent
= FONT_BASE (font
) + boff
;
19368 it
->descent
= FONT_DESCENT (font
) - boff
;
19371 if (EQ (height
, Qt
))
19373 if (it
->descent
> it
->max_descent
)
19375 it
->ascent
+= it
->descent
- it
->max_descent
;
19376 it
->descent
= it
->max_descent
;
19378 if (it
->ascent
> it
->max_ascent
)
19380 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19381 it
->ascent
= it
->max_ascent
;
19383 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19384 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19385 it
->constrain_row_ascent_descent_p
= 1;
19386 extra_line_spacing
= 0;
19390 Lisp_Object spacing
;
19393 it
->phys_ascent
= it
->ascent
;
19394 it
->phys_descent
= it
->descent
;
19396 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19397 && face
->box
!= FACE_NO_BOX
19398 && face
->box_line_width
> 0)
19400 it
->ascent
+= face
->box_line_width
;
19401 it
->descent
+= face
->box_line_width
;
19404 && XINT (height
) > it
->ascent
+ it
->descent
)
19405 it
->ascent
= XINT (height
) - it
->descent
;
19407 if (!NILP (total_height
))
19408 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19411 spacing
= get_line_height_property(it
, Qline_spacing
);
19412 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19414 if (INTEGERP (spacing
))
19416 extra_line_spacing
= XINT (spacing
);
19417 if (!NILP (total_height
))
19418 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19422 else if (it
->char_to_display
== '\t')
19424 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19425 int x
= it
->current_x
+ it
->continuation_lines_width
;
19426 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19428 /* If the distance from the current position to the next tab
19429 stop is less than a space character width, use the
19430 tab stop after that. */
19431 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19432 next_tab_x
+= tab_width
;
19434 it
->pixel_width
= next_tab_x
- x
;
19436 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19437 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19441 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19442 it
->ascent
+ it
->descent
, it
->ascent
);
19447 /* A multi-byte character. Assume that the display width of the
19448 character is the width of the character multiplied by the
19449 width of the font. */
19451 /* If we found a font, this font should give us the right
19452 metrics. If we didn't find a font, use the frame's
19453 default font and calculate the width of the character
19454 from the charset width; this is what old redisplay code
19457 pcm
= rif
->per_char_metric (font
, &char2b
,
19458 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19460 if (font_not_found_p
|| !pcm
)
19462 int charset
= CHAR_CHARSET (it
->char_to_display
);
19464 it
->glyph_not_available_p
= 1;
19465 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19466 * CHARSET_WIDTH (charset
));
19467 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19468 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19472 it
->pixel_width
= pcm
->width
;
19473 it
->phys_ascent
= pcm
->ascent
+ boff
;
19474 it
->phys_descent
= pcm
->descent
- boff
;
19476 && (pcm
->lbearing
< 0
19477 || pcm
->rbearing
> pcm
->width
))
19478 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19481 it
->ascent
= FONT_BASE (font
) + boff
;
19482 it
->descent
= FONT_DESCENT (font
) - boff
;
19483 if (face
->box
!= FACE_NO_BOX
)
19485 int thick
= face
->box_line_width
;
19489 it
->ascent
+= thick
;
19490 it
->descent
+= thick
;
19495 if (it
->start_of_box_run_p
)
19496 it
->pixel_width
+= thick
;
19497 if (it
->end_of_box_run_p
)
19498 it
->pixel_width
+= thick
;
19501 /* If face has an overline, add the height of the overline
19502 (1 pixel) and a 1 pixel margin to the character height. */
19503 if (face
->overline_p
)
19506 take_vertical_position_into_account (it
);
19511 it
->multibyte_p
= saved_multibyte_p
;
19513 else if (it
->what
== IT_COMPOSITION
)
19515 /* Note: A composition is represented as one glyph in the
19516 glyph matrix. There are no padding glyphs. */
19519 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19521 int font_not_found_p
;
19522 struct font_info
*font_info
;
19523 int boff
; /* baseline offset */
19524 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19526 /* Maybe translate single-byte characters to multibyte. */
19527 it
->char_to_display
= it
->c
;
19528 if (unibyte_display_via_language_environment
19529 && SINGLE_BYTE_CHAR_P (it
->c
)
19532 && !NILP (Vnonascii_translation_table
))))
19534 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19537 /* Get face and font to use. Encode IT->char_to_display. */
19538 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19539 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19540 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19541 &char2b
, it
->multibyte_p
, 0);
19544 /* When no suitable font found, use the default font. */
19545 font_not_found_p
= font
== NULL
;
19546 if (font_not_found_p
)
19548 font
= FRAME_FONT (it
->f
);
19549 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19554 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19555 boff
= font_info
->baseline_offset
;
19556 if (font_info
->vertical_centering
)
19557 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19560 /* There are no padding glyphs, so there is only one glyph to
19561 produce for the composition. Important is that pixel_width,
19562 ascent and descent are the values of what is drawn by
19563 draw_glyphs (i.e. the values of the overall glyphs composed). */
19566 /* If we have not yet calculated pixel size data of glyphs of
19567 the composition for the current face font, calculate them
19568 now. Theoretically, we have to check all fonts for the
19569 glyphs, but that requires much time and memory space. So,
19570 here we check only the font of the first glyph. This leads
19571 to incorrect display very rarely, and C-l (recenter) can
19572 correct the display anyway. */
19573 if (cmp
->font
!= (void *) font
)
19575 /* Ascent and descent of the font of the first character of
19576 this composition (adjusted by baseline offset). Ascent
19577 and descent of overall glyphs should not be less than
19578 them respectively. */
19579 int font_ascent
= FONT_BASE (font
) + boff
;
19580 int font_descent
= FONT_DESCENT (font
) - boff
;
19581 /* Bounding box of the overall glyphs. */
19582 int leftmost
, rightmost
, lowest
, highest
;
19583 int i
, width
, ascent
, descent
;
19585 cmp
->font
= (void *) font
;
19587 /* Initialize the bounding box. */
19589 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19590 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19592 width
= pcm
->width
;
19593 ascent
= pcm
->ascent
;
19594 descent
= pcm
->descent
;
19598 width
= FONT_WIDTH (font
);
19599 ascent
= FONT_BASE (font
);
19600 descent
= FONT_DESCENT (font
);
19604 lowest
= - descent
+ boff
;
19605 highest
= ascent
+ boff
;
19609 && font_info
->default_ascent
19610 && CHAR_TABLE_P (Vuse_default_ascent
)
19611 && !NILP (Faref (Vuse_default_ascent
,
19612 make_number (it
->char_to_display
))))
19613 highest
= font_info
->default_ascent
+ boff
;
19615 /* Draw the first glyph at the normal position. It may be
19616 shifted to right later if some other glyphs are drawn at
19618 cmp
->offsets
[0] = 0;
19619 cmp
->offsets
[1] = boff
;
19621 /* Set cmp->offsets for the remaining glyphs. */
19622 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19624 int left
, right
, btm
, top
;
19625 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19626 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19628 face
= FACE_FROM_ID (it
->f
, face_id
);
19629 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19630 &char2b
, it
->multibyte_p
, 0);
19634 font
= FRAME_FONT (it
->f
);
19635 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19641 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19642 boff
= font_info
->baseline_offset
;
19643 if (font_info
->vertical_centering
)
19644 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19648 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19649 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19651 width
= pcm
->width
;
19652 ascent
= pcm
->ascent
;
19653 descent
= pcm
->descent
;
19657 width
= FONT_WIDTH (font
);
19662 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19664 /* Relative composition with or without
19665 alternate chars. */
19666 left
= (leftmost
+ rightmost
- width
) / 2;
19667 btm
= - descent
+ boff
;
19668 if (font_info
&& font_info
->relative_compose
19669 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19670 || NILP (Faref (Vignore_relative_composition
,
19671 make_number (ch
)))))
19674 if (- descent
>= font_info
->relative_compose
)
19675 /* One extra pixel between two glyphs. */
19677 else if (ascent
<= 0)
19678 /* One extra pixel between two glyphs. */
19679 btm
= lowest
- 1 - ascent
- descent
;
19684 /* A composition rule is specified by an integer
19685 value that encodes global and new reference
19686 points (GREF and NREF). GREF and NREF are
19687 specified by numbers as below:
19689 0---1---2 -- ascent
19693 9--10--11 -- center
19695 ---3---4---5--- baseline
19697 6---7---8 -- descent
19699 int rule
= COMPOSITION_RULE (cmp
, i
);
19700 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19702 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19703 grefx
= gref
% 3, nrefx
= nref
% 3;
19704 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19707 + grefx
* (rightmost
- leftmost
) / 2
19708 - nrefx
* width
/ 2);
19709 btm
= ((grefy
== 0 ? highest
19711 : grefy
== 2 ? lowest
19712 : (highest
+ lowest
) / 2)
19713 - (nrefy
== 0 ? ascent
+ descent
19714 : nrefy
== 1 ? descent
- boff
19716 : (ascent
+ descent
) / 2));
19719 cmp
->offsets
[i
* 2] = left
;
19720 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19722 /* Update the bounding box of the overall glyphs. */
19723 right
= left
+ width
;
19724 top
= btm
+ descent
+ ascent
;
19725 if (left
< leftmost
)
19727 if (right
> rightmost
)
19735 /* If there are glyphs whose x-offsets are negative,
19736 shift all glyphs to the right and make all x-offsets
19740 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19741 cmp
->offsets
[i
* 2] -= leftmost
;
19742 rightmost
-= leftmost
;
19745 cmp
->pixel_width
= rightmost
;
19746 cmp
->ascent
= highest
;
19747 cmp
->descent
= - lowest
;
19748 if (cmp
->ascent
< font_ascent
)
19749 cmp
->ascent
= font_ascent
;
19750 if (cmp
->descent
< font_descent
)
19751 cmp
->descent
= font_descent
;
19754 it
->pixel_width
= cmp
->pixel_width
;
19755 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19756 it
->descent
= it
->phys_descent
= cmp
->descent
;
19758 if (face
->box
!= FACE_NO_BOX
)
19760 int thick
= face
->box_line_width
;
19764 it
->ascent
+= thick
;
19765 it
->descent
+= thick
;
19770 if (it
->start_of_box_run_p
)
19771 it
->pixel_width
+= thick
;
19772 if (it
->end_of_box_run_p
)
19773 it
->pixel_width
+= thick
;
19776 /* If face has an overline, add the height of the overline
19777 (1 pixel) and a 1 pixel margin to the character height. */
19778 if (face
->overline_p
)
19781 take_vertical_position_into_account (it
);
19784 append_composite_glyph (it
);
19786 else if (it
->what
== IT_IMAGE
)
19787 produce_image_glyph (it
);
19788 else if (it
->what
== IT_STRETCH
)
19789 produce_stretch_glyph (it
);
19791 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19792 because this isn't true for images with `:ascent 100'. */
19793 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19794 if (it
->area
== TEXT_AREA
)
19795 it
->current_x
+= it
->pixel_width
;
19797 if (extra_line_spacing
> 0)
19799 it
->descent
+= extra_line_spacing
;
19800 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19801 it
->max_extra_line_spacing
= extra_line_spacing
;
19804 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19805 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19806 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19807 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19811 Output LEN glyphs starting at START at the nominal cursor position.
19812 Advance the nominal cursor over the text. The global variable
19813 updated_window contains the window being updated, updated_row is
19814 the glyph row being updated, and updated_area is the area of that
19815 row being updated. */
19818 x_write_glyphs (start
, len
)
19819 struct glyph
*start
;
19824 xassert (updated_window
&& updated_row
);
19827 /* Write glyphs. */
19829 hpos
= start
- updated_row
->glyphs
[updated_area
];
19830 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19831 updated_row
, updated_area
,
19833 DRAW_NORMAL_TEXT
, 0);
19835 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19836 if (updated_area
== TEXT_AREA
19837 && updated_window
->phys_cursor_on_p
19838 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19839 && updated_window
->phys_cursor
.hpos
>= hpos
19840 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19841 updated_window
->phys_cursor_on_p
= 0;
19845 /* Advance the output cursor. */
19846 output_cursor
.hpos
+= len
;
19847 output_cursor
.x
= x
;
19852 Insert LEN glyphs from START at the nominal cursor position. */
19855 x_insert_glyphs (start
, len
)
19856 struct glyph
*start
;
19861 int line_height
, shift_by_width
, shifted_region_width
;
19862 struct glyph_row
*row
;
19863 struct glyph
*glyph
;
19864 int frame_x
, frame_y
, hpos
;
19866 xassert (updated_window
&& updated_row
);
19868 w
= updated_window
;
19869 f
= XFRAME (WINDOW_FRAME (w
));
19871 /* Get the height of the line we are in. */
19873 line_height
= row
->height
;
19875 /* Get the width of the glyphs to insert. */
19876 shift_by_width
= 0;
19877 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19878 shift_by_width
+= glyph
->pixel_width
;
19880 /* Get the width of the region to shift right. */
19881 shifted_region_width
= (window_box_width (w
, updated_area
)
19886 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19887 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19889 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19890 line_height
, shift_by_width
);
19892 /* Write the glyphs. */
19893 hpos
= start
- row
->glyphs
[updated_area
];
19894 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19896 DRAW_NORMAL_TEXT
, 0);
19898 /* Advance the output cursor. */
19899 output_cursor
.hpos
+= len
;
19900 output_cursor
.x
+= shift_by_width
;
19906 Erase the current text line from the nominal cursor position
19907 (inclusive) to pixel column TO_X (exclusive). The idea is that
19908 everything from TO_X onward is already erased.
19910 TO_X is a pixel position relative to updated_area of
19911 updated_window. TO_X == -1 means clear to the end of this area. */
19914 x_clear_end_of_line (to_x
)
19918 struct window
*w
= updated_window
;
19919 int max_x
, min_y
, max_y
;
19920 int from_x
, from_y
, to_y
;
19922 xassert (updated_window
&& updated_row
);
19923 f
= XFRAME (w
->frame
);
19925 if (updated_row
->full_width_p
)
19926 max_x
= WINDOW_TOTAL_WIDTH (w
);
19928 max_x
= window_box_width (w
, updated_area
);
19929 max_y
= window_text_bottom_y (w
);
19931 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19932 of window. For TO_X > 0, truncate to end of drawing area. */
19938 to_x
= min (to_x
, max_x
);
19940 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19942 /* Notice if the cursor will be cleared by this operation. */
19943 if (!updated_row
->full_width_p
)
19944 notice_overwritten_cursor (w
, updated_area
,
19945 output_cursor
.x
, -1,
19947 MATRIX_ROW_BOTTOM_Y (updated_row
));
19949 from_x
= output_cursor
.x
;
19951 /* Translate to frame coordinates. */
19952 if (updated_row
->full_width_p
)
19954 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19955 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19959 int area_left
= window_box_left (w
, updated_area
);
19960 from_x
+= area_left
;
19964 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19965 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19966 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19968 /* Prevent inadvertently clearing to end of the X window. */
19969 if (to_x
> from_x
&& to_y
> from_y
)
19972 rif
->clear_frame_area (f
, from_x
, from_y
,
19973 to_x
- from_x
, to_y
- from_y
);
19978 #endif /* HAVE_WINDOW_SYSTEM */
19982 /***********************************************************************
19984 ***********************************************************************/
19986 /* Value is the internal representation of the specified cursor type
19987 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19988 of the bar cursor. */
19990 static enum text_cursor_kinds
19991 get_specified_cursor_type (arg
, width
)
19995 enum text_cursor_kinds type
;
20000 if (EQ (arg
, Qbox
))
20001 return FILLED_BOX_CURSOR
;
20003 if (EQ (arg
, Qhollow
))
20004 return HOLLOW_BOX_CURSOR
;
20006 if (EQ (arg
, Qbar
))
20013 && EQ (XCAR (arg
), Qbar
)
20014 && INTEGERP (XCDR (arg
))
20015 && XINT (XCDR (arg
)) >= 0)
20017 *width
= XINT (XCDR (arg
));
20021 if (EQ (arg
, Qhbar
))
20024 return HBAR_CURSOR
;
20028 && EQ (XCAR (arg
), Qhbar
)
20029 && INTEGERP (XCDR (arg
))
20030 && XINT (XCDR (arg
)) >= 0)
20032 *width
= XINT (XCDR (arg
));
20033 return HBAR_CURSOR
;
20036 /* Treat anything unknown as "hollow box cursor".
20037 It was bad to signal an error; people have trouble fixing
20038 .Xdefaults with Emacs, when it has something bad in it. */
20039 type
= HOLLOW_BOX_CURSOR
;
20044 /* Set the default cursor types for specified frame. */
20046 set_frame_cursor_types (f
, arg
)
20053 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20054 FRAME_CURSOR_WIDTH (f
) = width
;
20056 /* By default, set up the blink-off state depending on the on-state. */
20058 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20061 FRAME_BLINK_OFF_CURSOR (f
)
20062 = get_specified_cursor_type (XCDR (tem
), &width
);
20063 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20066 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20070 /* Return the cursor we want to be displayed in window W. Return
20071 width of bar/hbar cursor through WIDTH arg. Return with
20072 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20073 (i.e. if the `system caret' should track this cursor).
20075 In a mini-buffer window, we want the cursor only to appear if we
20076 are reading input from this window. For the selected window, we
20077 want the cursor type given by the frame parameter or buffer local
20078 setting of cursor-type. If explicitly marked off, draw no cursor.
20079 In all other cases, we want a hollow box cursor. */
20081 static enum text_cursor_kinds
20082 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20084 struct glyph
*glyph
;
20086 int *active_cursor
;
20088 struct frame
*f
= XFRAME (w
->frame
);
20089 struct buffer
*b
= XBUFFER (w
->buffer
);
20090 int cursor_type
= DEFAULT_CURSOR
;
20091 Lisp_Object alt_cursor
;
20092 int non_selected
= 0;
20094 *active_cursor
= 1;
20097 if (cursor_in_echo_area
20098 && FRAME_HAS_MINIBUF_P (f
)
20099 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20101 if (w
== XWINDOW (echo_area_window
))
20103 *width
= FRAME_CURSOR_WIDTH (f
);
20104 return FRAME_DESIRED_CURSOR (f
);
20107 *active_cursor
= 0;
20111 /* Nonselected window or nonselected frame. */
20112 else if (w
!= XWINDOW (f
->selected_window
)
20113 #ifdef HAVE_WINDOW_SYSTEM
20114 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20118 *active_cursor
= 0;
20120 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20126 /* Never display a cursor in a window in which cursor-type is nil. */
20127 if (NILP (b
->cursor_type
))
20130 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20133 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
20134 return get_specified_cursor_type (alt_cursor
, width
);
20137 /* Get the normal cursor type for this window. */
20138 if (EQ (b
->cursor_type
, Qt
))
20140 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20141 *width
= FRAME_CURSOR_WIDTH (f
);
20144 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20146 /* Use normal cursor if not blinked off. */
20147 if (!w
->cursor_off_p
)
20149 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20150 if (cursor_type
== FILLED_BOX_CURSOR
)
20151 cursor_type
= HOLLOW_BOX_CURSOR
;
20153 return cursor_type
;
20156 /* Cursor is blinked off, so determine how to "toggle" it. */
20158 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20159 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20160 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20162 /* Then see if frame has specified a specific blink off cursor type. */
20163 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20165 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20166 return FRAME_BLINK_OFF_CURSOR (f
);
20170 /* Some people liked having a permanently visible blinking cursor,
20171 while others had very strong opinions against it. So it was
20172 decided to remove it. KFS 2003-09-03 */
20174 /* Finally perform built-in cursor blinking:
20175 filled box <-> hollow box
20176 wide [h]bar <-> narrow [h]bar
20177 narrow [h]bar <-> no cursor
20178 other type <-> no cursor */
20180 if (cursor_type
== FILLED_BOX_CURSOR
)
20181 return HOLLOW_BOX_CURSOR
;
20183 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20186 return cursor_type
;
20194 #ifdef HAVE_WINDOW_SYSTEM
20196 /* Notice when the text cursor of window W has been completely
20197 overwritten by a drawing operation that outputs glyphs in AREA
20198 starting at X0 and ending at X1 in the line starting at Y0 and
20199 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20200 the rest of the line after X0 has been written. Y coordinates
20201 are window-relative. */
20204 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20206 enum glyph_row_area area
;
20207 int x0
, y0
, x1
, y1
;
20209 int cx0
, cx1
, cy0
, cy1
;
20210 struct glyph_row
*row
;
20212 if (!w
->phys_cursor_on_p
)
20214 if (area
!= TEXT_AREA
)
20217 if (w
->phys_cursor
.vpos
< 0
20218 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20219 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20220 !(row
->enabled_p
&& row
->displays_text_p
)))
20223 if (row
->cursor_in_fringe_p
)
20225 row
->cursor_in_fringe_p
= 0;
20226 draw_fringe_bitmap (w
, row
, 0);
20227 w
->phys_cursor_on_p
= 0;
20231 cx0
= w
->phys_cursor
.x
;
20232 cx1
= cx0
+ w
->phys_cursor_width
;
20233 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20236 /* The cursor image will be completely removed from the
20237 screen if the output area intersects the cursor area in
20238 y-direction. When we draw in [y0 y1[, and some part of
20239 the cursor is at y < y0, that part must have been drawn
20240 before. When scrolling, the cursor is erased before
20241 actually scrolling, so we don't come here. When not
20242 scrolling, the rows above the old cursor row must have
20243 changed, and in this case these rows must have written
20244 over the cursor image.
20246 Likewise if part of the cursor is below y1, with the
20247 exception of the cursor being in the first blank row at
20248 the buffer and window end because update_text_area
20249 doesn't draw that row. (Except when it does, but
20250 that's handled in update_text_area.) */
20252 cy0
= w
->phys_cursor
.y
;
20253 cy1
= cy0
+ w
->phys_cursor_height
;
20254 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20257 w
->phys_cursor_on_p
= 0;
20260 #endif /* HAVE_WINDOW_SYSTEM */
20263 /************************************************************************
20265 ************************************************************************/
20267 #ifdef HAVE_WINDOW_SYSTEM
20270 Fix the display of area AREA of overlapping row ROW in window W. */
20273 x_fix_overlapping_area (w
, row
, area
)
20275 struct glyph_row
*row
;
20276 enum glyph_row_area area
;
20283 for (i
= 0; i
< row
->used
[area
];)
20285 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20287 int start
= i
, start_x
= x
;
20291 x
+= row
->glyphs
[area
][i
].pixel_width
;
20294 while (i
< row
->used
[area
]
20295 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20297 draw_glyphs (w
, start_x
, row
, area
,
20299 DRAW_NORMAL_TEXT
, 1);
20303 x
+= row
->glyphs
[area
][i
].pixel_width
;
20313 Draw the cursor glyph of window W in glyph row ROW. See the
20314 comment of draw_glyphs for the meaning of HL. */
20317 draw_phys_cursor_glyph (w
, row
, hl
)
20319 struct glyph_row
*row
;
20320 enum draw_glyphs_face hl
;
20322 /* If cursor hpos is out of bounds, don't draw garbage. This can
20323 happen in mini-buffer windows when switching between echo area
20324 glyphs and mini-buffer. */
20325 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20327 int on_p
= w
->phys_cursor_on_p
;
20329 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20330 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20332 w
->phys_cursor_on_p
= on_p
;
20334 if (hl
== DRAW_CURSOR
)
20335 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20336 /* When we erase the cursor, and ROW is overlapped by other
20337 rows, make sure that these overlapping parts of other rows
20339 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20341 if (row
> w
->current_matrix
->rows
20342 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20343 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20345 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20346 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20347 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20354 Erase the image of a cursor of window W from the screen. */
20357 erase_phys_cursor (w
)
20360 struct frame
*f
= XFRAME (w
->frame
);
20361 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20362 int hpos
= w
->phys_cursor
.hpos
;
20363 int vpos
= w
->phys_cursor
.vpos
;
20364 int mouse_face_here_p
= 0;
20365 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20366 struct glyph_row
*cursor_row
;
20367 struct glyph
*cursor_glyph
;
20368 enum draw_glyphs_face hl
;
20370 /* No cursor displayed or row invalidated => nothing to do on the
20372 if (w
->phys_cursor_type
== NO_CURSOR
)
20373 goto mark_cursor_off
;
20375 /* VPOS >= active_glyphs->nrows means that window has been resized.
20376 Don't bother to erase the cursor. */
20377 if (vpos
>= active_glyphs
->nrows
)
20378 goto mark_cursor_off
;
20380 /* If row containing cursor is marked invalid, there is nothing we
20382 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20383 if (!cursor_row
->enabled_p
)
20384 goto mark_cursor_off
;
20386 /* If line spacing is > 0, old cursor may only be partially visible in
20387 window after split-window. So adjust visible height. */
20388 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20389 window_text_bottom_y (w
) - cursor_row
->y
);
20391 /* If row is completely invisible, don't attempt to delete a cursor which
20392 isn't there. This can happen if cursor is at top of a window, and
20393 we switch to a buffer with a header line in that window. */
20394 if (cursor_row
->visible_height
<= 0)
20395 goto mark_cursor_off
;
20397 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20398 if (cursor_row
->cursor_in_fringe_p
)
20400 cursor_row
->cursor_in_fringe_p
= 0;
20401 draw_fringe_bitmap (w
, cursor_row
, 0);
20402 goto mark_cursor_off
;
20405 /* This can happen when the new row is shorter than the old one.
20406 In this case, either draw_glyphs or clear_end_of_line
20407 should have cleared the cursor. Note that we wouldn't be
20408 able to erase the cursor in this case because we don't have a
20409 cursor glyph at hand. */
20410 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20411 goto mark_cursor_off
;
20413 /* If the cursor is in the mouse face area, redisplay that when
20414 we clear the cursor. */
20415 if (! NILP (dpyinfo
->mouse_face_window
)
20416 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20417 && (vpos
> dpyinfo
->mouse_face_beg_row
20418 || (vpos
== dpyinfo
->mouse_face_beg_row
20419 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20420 && (vpos
< dpyinfo
->mouse_face_end_row
20421 || (vpos
== dpyinfo
->mouse_face_end_row
20422 && hpos
< dpyinfo
->mouse_face_end_col
))
20423 /* Don't redraw the cursor's spot in mouse face if it is at the
20424 end of a line (on a newline). The cursor appears there, but
20425 mouse highlighting does not. */
20426 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20427 mouse_face_here_p
= 1;
20429 /* Maybe clear the display under the cursor. */
20430 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20433 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20436 cursor_glyph
= get_phys_cursor_glyph (w
);
20437 if (cursor_glyph
== NULL
)
20438 goto mark_cursor_off
;
20440 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20441 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20442 width
= min (cursor_glyph
->pixel_width
,
20443 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20445 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20448 /* Erase the cursor by redrawing the character underneath it. */
20449 if (mouse_face_here_p
)
20450 hl
= DRAW_MOUSE_FACE
;
20452 hl
= DRAW_NORMAL_TEXT
;
20453 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20456 w
->phys_cursor_on_p
= 0;
20457 w
->phys_cursor_type
= NO_CURSOR
;
20462 Display or clear cursor of window W. If ON is zero, clear the
20463 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20464 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20467 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20469 int on
, hpos
, vpos
, x
, y
;
20471 struct frame
*f
= XFRAME (w
->frame
);
20472 int new_cursor_type
;
20473 int new_cursor_width
;
20475 struct glyph_row
*glyph_row
;
20476 struct glyph
*glyph
;
20478 /* This is pointless on invisible frames, and dangerous on garbaged
20479 windows and frames; in the latter case, the frame or window may
20480 be in the midst of changing its size, and x and y may be off the
20482 if (! FRAME_VISIBLE_P (f
)
20483 || FRAME_GARBAGED_P (f
)
20484 || vpos
>= w
->current_matrix
->nrows
20485 || hpos
>= w
->current_matrix
->matrix_w
)
20488 /* If cursor is off and we want it off, return quickly. */
20489 if (!on
&& !w
->phys_cursor_on_p
)
20492 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20493 /* If cursor row is not enabled, we don't really know where to
20494 display the cursor. */
20495 if (!glyph_row
->enabled_p
)
20497 w
->phys_cursor_on_p
= 0;
20502 if (!glyph_row
->exact_window_width_line_p
20503 || hpos
< glyph_row
->used
[TEXT_AREA
])
20504 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20506 xassert (interrupt_input_blocked
);
20508 /* Set new_cursor_type to the cursor we want to be displayed. */
20509 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20510 &new_cursor_width
, &active_cursor
);
20512 /* If cursor is currently being shown and we don't want it to be or
20513 it is in the wrong place, or the cursor type is not what we want,
20515 if (w
->phys_cursor_on_p
20517 || w
->phys_cursor
.x
!= x
20518 || w
->phys_cursor
.y
!= y
20519 || new_cursor_type
!= w
->phys_cursor_type
20520 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20521 && new_cursor_width
!= w
->phys_cursor_width
)))
20522 erase_phys_cursor (w
);
20524 /* Don't check phys_cursor_on_p here because that flag is only set
20525 to zero in some cases where we know that the cursor has been
20526 completely erased, to avoid the extra work of erasing the cursor
20527 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20528 still not be visible, or it has only been partly erased. */
20531 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20532 w
->phys_cursor_height
= glyph_row
->height
;
20534 /* Set phys_cursor_.* before x_draw_.* is called because some
20535 of them may need the information. */
20536 w
->phys_cursor
.x
= x
;
20537 w
->phys_cursor
.y
= glyph_row
->y
;
20538 w
->phys_cursor
.hpos
= hpos
;
20539 w
->phys_cursor
.vpos
= vpos
;
20542 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20543 new_cursor_type
, new_cursor_width
,
20544 on
, active_cursor
);
20548 /* Switch the display of W's cursor on or off, according to the value
20552 update_window_cursor (w
, on
)
20556 /* Don't update cursor in windows whose frame is in the process
20557 of being deleted. */
20558 if (w
->current_matrix
)
20561 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20562 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20568 /* Call update_window_cursor with parameter ON_P on all leaf windows
20569 in the window tree rooted at W. */
20572 update_cursor_in_window_tree (w
, on_p
)
20578 if (!NILP (w
->hchild
))
20579 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20580 else if (!NILP (w
->vchild
))
20581 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20583 update_window_cursor (w
, on_p
);
20585 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20591 Display the cursor on window W, or clear it, according to ON_P.
20592 Don't change the cursor's position. */
20595 x_update_cursor (f
, on_p
)
20599 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20604 Clear the cursor of window W to background color, and mark the
20605 cursor as not shown. This is used when the text where the cursor
20606 is is about to be rewritten. */
20612 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20613 update_window_cursor (w
, 0);
20618 Display the active region described by mouse_face_* according to DRAW. */
20621 show_mouse_face (dpyinfo
, draw
)
20622 Display_Info
*dpyinfo
;
20623 enum draw_glyphs_face draw
;
20625 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20626 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20628 if (/* If window is in the process of being destroyed, don't bother
20630 w
->current_matrix
!= NULL
20631 /* Don't update mouse highlight if hidden */
20632 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20633 /* Recognize when we are called to operate on rows that don't exist
20634 anymore. This can happen when a window is split. */
20635 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20637 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20638 struct glyph_row
*row
, *first
, *last
;
20640 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20641 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20643 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20645 int start_hpos
, end_hpos
, start_x
;
20647 /* For all but the first row, the highlight starts at column 0. */
20650 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20651 start_x
= dpyinfo
->mouse_face_beg_x
;
20660 end_hpos
= dpyinfo
->mouse_face_end_col
;
20662 end_hpos
= row
->used
[TEXT_AREA
];
20664 if (end_hpos
> start_hpos
)
20666 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20667 start_hpos
, end_hpos
,
20671 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20675 /* When we've written over the cursor, arrange for it to
20676 be displayed again. */
20677 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20680 display_and_set_cursor (w
, 1,
20681 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20682 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20687 /* Change the mouse cursor. */
20688 if (draw
== DRAW_NORMAL_TEXT
)
20689 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20690 else if (draw
== DRAW_MOUSE_FACE
)
20691 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20693 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20697 Clear out the mouse-highlighted active region.
20698 Redraw it un-highlighted first. Value is non-zero if mouse
20699 face was actually drawn unhighlighted. */
20702 clear_mouse_face (dpyinfo
)
20703 Display_Info
*dpyinfo
;
20707 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20709 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20713 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20714 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20715 dpyinfo
->mouse_face_window
= Qnil
;
20716 dpyinfo
->mouse_face_overlay
= Qnil
;
20722 Non-zero if physical cursor of window W is within mouse face. */
20725 cursor_in_mouse_face_p (w
)
20728 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20729 int in_mouse_face
= 0;
20731 if (WINDOWP (dpyinfo
->mouse_face_window
)
20732 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20734 int hpos
= w
->phys_cursor
.hpos
;
20735 int vpos
= w
->phys_cursor
.vpos
;
20737 if (vpos
>= dpyinfo
->mouse_face_beg_row
20738 && vpos
<= dpyinfo
->mouse_face_end_row
20739 && (vpos
> dpyinfo
->mouse_face_beg_row
20740 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20741 && (vpos
< dpyinfo
->mouse_face_end_row
20742 || hpos
< dpyinfo
->mouse_face_end_col
20743 || dpyinfo
->mouse_face_past_end
))
20747 return in_mouse_face
;
20753 /* Find the glyph matrix position of buffer position CHARPOS in window
20754 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20755 current glyphs must be up to date. If CHARPOS is above window
20756 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20757 of last line in W. In the row containing CHARPOS, stop before glyphs
20758 having STOP as object. */
20760 #if 1 /* This is a version of fast_find_position that's more correct
20761 in the presence of hscrolling, for example. I didn't install
20762 it right away because the problem fixed is minor, it failed
20763 in 20.x as well, and I think it's too risky to install
20764 so near the release of 21.1. 2001-09-25 gerd. */
20767 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20770 int *hpos
, *vpos
, *x
, *y
;
20773 struct glyph_row
*row
, *first
;
20774 struct glyph
*glyph
, *end
;
20777 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20778 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20783 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20787 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20790 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20794 /* If whole rows or last part of a row came from a display overlay,
20795 row_containing_pos will skip over such rows because their end pos
20796 equals the start pos of the overlay or interval.
20798 Move back if we have a STOP object and previous row's
20799 end glyph came from STOP. */
20802 struct glyph_row
*prev
;
20803 while ((prev
= row
- 1, prev
>= first
)
20804 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
20805 && prev
->used
[TEXT_AREA
] > 0)
20807 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
20808 glyph
= beg
+ prev
->used
[TEXT_AREA
];
20809 while (--glyph
>= beg
20810 && INTEGERP (glyph
->object
));
20812 || !EQ (stop
, glyph
->object
))
20820 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20822 glyph
= row
->glyphs
[TEXT_AREA
];
20823 end
= glyph
+ row
->used
[TEXT_AREA
];
20825 /* Skip over glyphs not having an object at the start of the row.
20826 These are special glyphs like truncation marks on terminal
20828 if (row
->displays_text_p
)
20830 && INTEGERP (glyph
->object
)
20831 && !EQ (stop
, glyph
->object
)
20832 && glyph
->charpos
< 0)
20834 *x
+= glyph
->pixel_width
;
20839 && !INTEGERP (glyph
->object
)
20840 && !EQ (stop
, glyph
->object
)
20841 && (!BUFFERP (glyph
->object
)
20842 || glyph
->charpos
< charpos
))
20844 *x
+= glyph
->pixel_width
;
20848 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20855 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20858 int *hpos
, *vpos
, *x
, *y
;
20863 int maybe_next_line_p
= 0;
20864 int line_start_position
;
20865 int yb
= window_text_bottom_y (w
);
20866 struct glyph_row
*row
, *best_row
;
20867 int row_vpos
, best_row_vpos
;
20870 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20871 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20873 while (row
->y
< yb
)
20875 if (row
->used
[TEXT_AREA
])
20876 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20878 line_start_position
= 0;
20880 if (line_start_position
> pos
)
20882 /* If the position sought is the end of the buffer,
20883 don't include the blank lines at the bottom of the window. */
20884 else if (line_start_position
== pos
20885 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20887 maybe_next_line_p
= 1;
20890 else if (line_start_position
> 0)
20893 best_row_vpos
= row_vpos
;
20896 if (row
->y
+ row
->height
>= yb
)
20903 /* Find the right column within BEST_ROW. */
20905 current_x
= best_row
->x
;
20906 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20908 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20909 int charpos
= glyph
->charpos
;
20911 if (BUFFERP (glyph
->object
))
20913 if (charpos
== pos
)
20916 *vpos
= best_row_vpos
;
20921 else if (charpos
> pos
)
20924 else if (EQ (glyph
->object
, stop
))
20929 current_x
+= glyph
->pixel_width
;
20932 /* If we're looking for the end of the buffer,
20933 and we didn't find it in the line we scanned,
20934 use the start of the following line. */
20935 if (maybe_next_line_p
)
20940 current_x
= best_row
->x
;
20943 *vpos
= best_row_vpos
;
20944 *hpos
= lastcol
+ 1;
20953 /* Find the position of the glyph for position POS in OBJECT in
20954 window W's current matrix, and return in *X, *Y the pixel
20955 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20957 RIGHT_P non-zero means return the position of the right edge of the
20958 glyph, RIGHT_P zero means return the left edge position.
20960 If no glyph for POS exists in the matrix, return the position of
20961 the glyph with the next smaller position that is in the matrix, if
20962 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20963 exists in the matrix, return the position of the glyph with the
20964 next larger position in OBJECT.
20966 Value is non-zero if a glyph was found. */
20969 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20972 Lisp_Object object
;
20973 int *hpos
, *vpos
, *x
, *y
;
20976 int yb
= window_text_bottom_y (w
);
20977 struct glyph_row
*r
;
20978 struct glyph
*best_glyph
= NULL
;
20979 struct glyph_row
*best_row
= NULL
;
20982 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20983 r
->enabled_p
&& r
->y
< yb
;
20986 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20987 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20990 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20991 if (EQ (g
->object
, object
))
20993 if (g
->charpos
== pos
)
21000 else if (best_glyph
== NULL
21001 || ((abs (g
->charpos
- pos
)
21002 < abs (best_glyph
->charpos
- pos
))
21005 : g
->charpos
> pos
)))
21019 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21023 *x
+= best_glyph
->pixel_width
;
21028 *vpos
= best_row
- w
->current_matrix
->rows
;
21031 return best_glyph
!= NULL
;
21035 /* See if position X, Y is within a hot-spot of an image. */
21038 on_hot_spot_p (hot_spot
, x
, y
)
21039 Lisp_Object hot_spot
;
21042 if (!CONSP (hot_spot
))
21045 if (EQ (XCAR (hot_spot
), Qrect
))
21047 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21048 Lisp_Object rect
= XCDR (hot_spot
);
21052 if (!CONSP (XCAR (rect
)))
21054 if (!CONSP (XCDR (rect
)))
21056 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21058 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21060 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21062 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21066 else if (EQ (XCAR (hot_spot
), Qcircle
))
21068 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21069 Lisp_Object circ
= XCDR (hot_spot
);
21070 Lisp_Object lr
, lx0
, ly0
;
21072 && CONSP (XCAR (circ
))
21073 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21074 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21075 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21077 double r
= XFLOATINT (lr
);
21078 double dx
= XINT (lx0
) - x
;
21079 double dy
= XINT (ly0
) - y
;
21080 return (dx
* dx
+ dy
* dy
<= r
* r
);
21083 else if (EQ (XCAR (hot_spot
), Qpoly
))
21085 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21086 if (VECTORP (XCDR (hot_spot
)))
21088 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21089 Lisp_Object
*poly
= v
->contents
;
21093 Lisp_Object lx
, ly
;
21096 /* Need an even number of coordinates, and at least 3 edges. */
21097 if (n
< 6 || n
& 1)
21100 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21101 If count is odd, we are inside polygon. Pixels on edges
21102 may or may not be included depending on actual geometry of the
21104 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21105 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21107 x0
= XINT (lx
), y0
= XINT (ly
);
21108 for (i
= 0; i
< n
; i
+= 2)
21110 int x1
= x0
, y1
= y0
;
21111 if ((lx
= poly
[i
], !INTEGERP (lx
))
21112 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21114 x0
= XINT (lx
), y0
= XINT (ly
);
21116 /* Does this segment cross the X line? */
21124 if (y
> y0
&& y
> y1
)
21126 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21132 /* If we don't understand the format, pretend we're not in the hot-spot. */
21137 find_hot_spot (map
, x
, y
)
21141 while (CONSP (map
))
21143 if (CONSP (XCAR (map
))
21144 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21152 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21154 doc
: /* Lookup in image map MAP coordinates X and Y.
21155 An image map is an alist where each element has the format (AREA ID PLIST).
21156 An AREA is specified as either a rectangle, a circle, or a polygon:
21157 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21158 pixel coordinates of the upper left and bottom right corners.
21159 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21160 and the radius of the circle; r may be a float or integer.
21161 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21162 vector describes one corner in the polygon.
21163 Returns the alist element for the first matching AREA in MAP. */)
21174 return find_hot_spot (map
, XINT (x
), XINT (y
));
21178 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21180 define_frame_cursor1 (f
, cursor
, pointer
)
21183 Lisp_Object pointer
;
21185 /* Do not change cursor shape while dragging mouse. */
21186 if (!NILP (do_mouse_tracking
))
21189 if (!NILP (pointer
))
21191 if (EQ (pointer
, Qarrow
))
21192 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21193 else if (EQ (pointer
, Qhand
))
21194 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21195 else if (EQ (pointer
, Qtext
))
21196 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21197 else if (EQ (pointer
, intern ("hdrag")))
21198 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21199 #ifdef HAVE_X_WINDOWS
21200 else if (EQ (pointer
, intern ("vdrag")))
21201 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21203 else if (EQ (pointer
, intern ("hourglass")))
21204 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21205 else if (EQ (pointer
, Qmodeline
))
21206 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21208 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21211 if (cursor
!= No_Cursor
)
21212 rif
->define_frame_cursor (f
, cursor
);
21215 /* Take proper action when mouse has moved to the mode or header line
21216 or marginal area AREA of window W, x-position X and y-position Y.
21217 X is relative to the start of the text display area of W, so the
21218 width of bitmap areas and scroll bars must be subtracted to get a
21219 position relative to the start of the mode line. */
21222 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
21225 enum window_part area
;
21227 struct frame
*f
= XFRAME (w
->frame
);
21228 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21229 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21230 Lisp_Object pointer
= Qnil
;
21231 int charpos
, dx
, dy
, width
, height
;
21232 Lisp_Object string
, object
= Qnil
;
21233 Lisp_Object pos
, help
;
21235 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21236 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21237 &object
, &dx
, &dy
, &width
, &height
);
21240 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21241 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21242 &object
, &dx
, &dy
, &width
, &height
);
21247 if (IMAGEP (object
))
21249 Lisp_Object image_map
, hotspot
;
21250 if ((image_map
= Fsafe_plist_get (XCDR (object
), QCmap
),
21252 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21254 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21256 Lisp_Object area_id
, plist
;
21258 area_id
= XCAR (hotspot
);
21259 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21260 If so, we could look for mouse-enter, mouse-leave
21261 properties in PLIST (and do something...). */
21262 hotspot
= XCDR (hotspot
);
21263 if (CONSP (hotspot
)
21264 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21266 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21267 if (NILP (pointer
))
21269 help
= Fsafe_plist_get (plist
, Qhelp_echo
);
21272 help_echo_string
= help
;
21273 /* Is this correct? ++kfs */
21274 XSETWINDOW (help_echo_window
, w
);
21275 help_echo_object
= w
->buffer
;
21276 help_echo_pos
= charpos
;
21280 if (NILP (pointer
))
21281 pointer
= Fsafe_plist_get (XCDR (object
), QCpointer
);
21284 if (STRINGP (string
))
21286 pos
= make_number (charpos
);
21287 /* If we're on a string with `help-echo' text property, arrange
21288 for the help to be displayed. This is done by setting the
21289 global variable help_echo_string to the help string. */
21292 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21295 help_echo_string
= help
;
21296 XSETWINDOW (help_echo_window
, w
);
21297 help_echo_object
= string
;
21298 help_echo_pos
= charpos
;
21302 if (NILP (pointer
))
21303 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21305 /* Change the mouse pointer according to what is under X/Y. */
21306 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21309 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21310 if (!KEYMAPP (map
))
21311 map
= Fget_text_property (pos
, Qkeymap
, string
);
21312 if (!KEYMAPP (map
))
21313 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21317 define_frame_cursor1 (f
, cursor
, pointer
);
21322 Take proper action when the mouse has moved to position X, Y on
21323 frame F as regards highlighting characters that have mouse-face
21324 properties. Also de-highlighting chars where the mouse was before.
21325 X and Y can be negative or out of range. */
21328 note_mouse_highlight (f
, x
, y
)
21332 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21333 enum window_part part
;
21334 Lisp_Object window
;
21336 Cursor cursor
= No_Cursor
;
21337 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21340 /* When a menu is active, don't highlight because this looks odd. */
21341 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21342 if (popup_activated ())
21346 if (NILP (Vmouse_highlight
)
21347 || !f
->glyphs_initialized_p
)
21350 dpyinfo
->mouse_face_mouse_x
= x
;
21351 dpyinfo
->mouse_face_mouse_y
= y
;
21352 dpyinfo
->mouse_face_mouse_frame
= f
;
21354 if (dpyinfo
->mouse_face_defer
)
21357 if (gc_in_progress
)
21359 dpyinfo
->mouse_face_deferred_gc
= 1;
21363 /* Which window is that in? */
21364 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21366 /* If we were displaying active text in another window, clear that.
21367 Also clear if we move out of text area in same window. */
21368 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21369 || (part
!= ON_TEXT
&& !NILP (dpyinfo
->mouse_face_window
)))
21370 clear_mouse_face (dpyinfo
);
21372 /* Not on a window -> return. */
21373 if (!WINDOWP (window
))
21376 /* Reset help_echo_string. It will get recomputed below. */
21377 help_echo_string
= Qnil
;
21379 /* Convert to window-relative pixel coordinates. */
21380 w
= XWINDOW (window
);
21381 frame_to_window_pixel_xy (w
, &x
, &y
);
21383 /* Handle tool-bar window differently since it doesn't display a
21385 if (EQ (window
, f
->tool_bar_window
))
21387 note_tool_bar_highlight (f
, x
, y
);
21391 /* Mouse is on the mode, header line or margin? */
21392 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21393 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21395 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
21399 if (part
== ON_VERTICAL_BORDER
)
21400 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21401 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21402 || part
== ON_SCROLL_BAR
)
21403 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21405 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21407 /* Are we in a window whose display is up to date?
21408 And verify the buffer's text has not changed. */
21409 b
= XBUFFER (w
->buffer
);
21410 if (part
== ON_TEXT
21411 && EQ (w
->window_end_valid
, w
->buffer
)
21412 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21413 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21415 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21416 struct glyph
*glyph
;
21417 Lisp_Object object
;
21418 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21419 Lisp_Object
*overlay_vec
= NULL
;
21421 struct buffer
*obuf
;
21422 int obegv
, ozv
, same_region
;
21424 /* Find the glyph under X/Y. */
21425 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21427 /* Look for :pointer property on image. */
21428 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21430 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21431 if (img
!= NULL
&& IMAGEP (img
->spec
))
21433 Lisp_Object image_map
, hotspot
;
21434 if ((image_map
= Fsafe_plist_get (XCDR (img
->spec
), QCmap
),
21436 && (hotspot
= find_hot_spot (image_map
,
21437 glyph
->slice
.x
+ dx
,
21438 glyph
->slice
.y
+ dy
),
21440 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21442 Lisp_Object area_id
, plist
;
21444 area_id
= XCAR (hotspot
);
21445 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21446 If so, we could look for mouse-enter, mouse-leave
21447 properties in PLIST (and do something...). */
21448 hotspot
= XCDR (hotspot
);
21449 if (CONSP (hotspot
)
21450 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21452 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21453 if (NILP (pointer
))
21455 help_echo_string
= Fsafe_plist_get (plist
, Qhelp_echo
);
21456 if (!NILP (help_echo_string
))
21458 help_echo_window
= window
;
21459 help_echo_object
= glyph
->object
;
21460 help_echo_pos
= glyph
->charpos
;
21464 if (NILP (pointer
))
21465 pointer
= Fsafe_plist_get (XCDR (img
->spec
), QCpointer
);
21469 /* Clear mouse face if X/Y not over text. */
21471 || area
!= TEXT_AREA
21472 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21474 if (clear_mouse_face (dpyinfo
))
21475 cursor
= No_Cursor
;
21476 if (NILP (pointer
))
21478 if (area
!= TEXT_AREA
)
21479 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21481 pointer
= Vvoid_text_area_pointer
;
21486 pos
= glyph
->charpos
;
21487 object
= glyph
->object
;
21488 if (!STRINGP (object
) && !BUFFERP (object
))
21491 /* If we get an out-of-range value, return now; avoid an error. */
21492 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21495 /* Make the window's buffer temporarily current for
21496 overlays_at and compute_char_face. */
21497 obuf
= current_buffer
;
21498 current_buffer
= b
;
21504 /* Is this char mouse-active or does it have help-echo? */
21505 position
= make_number (pos
);
21507 if (BUFFERP (object
))
21509 /* Put all the overlays we want in a vector in overlay_vec. */
21510 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21511 /* Sort overlays into increasing priority order. */
21512 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21517 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21518 && vpos
>= dpyinfo
->mouse_face_beg_row
21519 && vpos
<= dpyinfo
->mouse_face_end_row
21520 && (vpos
> dpyinfo
->mouse_face_beg_row
21521 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21522 && (vpos
< dpyinfo
->mouse_face_end_row
21523 || hpos
< dpyinfo
->mouse_face_end_col
21524 || dpyinfo
->mouse_face_past_end
));
21527 cursor
= No_Cursor
;
21529 /* Check mouse-face highlighting. */
21531 /* If there exists an overlay with mouse-face overlapping
21532 the one we are currently highlighting, we have to
21533 check if we enter the overlapping overlay, and then
21534 highlight only that. */
21535 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21536 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21538 /* Find the highest priority overlay that has a mouse-face
21541 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21543 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21544 if (!NILP (mouse_face
))
21545 overlay
= overlay_vec
[i
];
21548 /* If we're actually highlighting the same overlay as
21549 before, there's no need to do that again. */
21550 if (!NILP (overlay
)
21551 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21552 goto check_help_echo
;
21554 dpyinfo
->mouse_face_overlay
= overlay
;
21556 /* Clear the display of the old active region, if any. */
21557 if (clear_mouse_face (dpyinfo
))
21558 cursor
= No_Cursor
;
21560 /* If no overlay applies, get a text property. */
21561 if (NILP (overlay
))
21562 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21564 /* Handle the overlay case. */
21565 if (!NILP (overlay
))
21567 /* Find the range of text around this char that
21568 should be active. */
21569 Lisp_Object before
, after
;
21572 before
= Foverlay_start (overlay
);
21573 after
= Foverlay_end (overlay
);
21574 /* Record this as the current active region. */
21575 fast_find_position (w
, XFASTINT (before
),
21576 &dpyinfo
->mouse_face_beg_col
,
21577 &dpyinfo
->mouse_face_beg_row
,
21578 &dpyinfo
->mouse_face_beg_x
,
21579 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21581 dpyinfo
->mouse_face_past_end
21582 = !fast_find_position (w
, XFASTINT (after
),
21583 &dpyinfo
->mouse_face_end_col
,
21584 &dpyinfo
->mouse_face_end_row
,
21585 &dpyinfo
->mouse_face_end_x
,
21586 &dpyinfo
->mouse_face_end_y
, Qnil
);
21587 dpyinfo
->mouse_face_window
= window
;
21589 dpyinfo
->mouse_face_face_id
21590 = face_at_buffer_position (w
, pos
, 0, 0,
21592 !dpyinfo
->mouse_face_hidden
);
21594 /* Display it as active. */
21595 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21596 cursor
= No_Cursor
;
21598 /* Handle the text property case. */
21599 else if (!NILP (mouse_face
) && BUFFERP (object
))
21601 /* Find the range of text around this char that
21602 should be active. */
21603 Lisp_Object before
, after
, beginning
, end
;
21606 beginning
= Fmarker_position (w
->start
);
21607 end
= make_number (BUF_Z (XBUFFER (object
))
21608 - XFASTINT (w
->window_end_pos
));
21610 = Fprevious_single_property_change (make_number (pos
+ 1),
21612 object
, beginning
);
21614 = Fnext_single_property_change (position
, Qmouse_face
,
21617 /* Record this as the current active region. */
21618 fast_find_position (w
, XFASTINT (before
),
21619 &dpyinfo
->mouse_face_beg_col
,
21620 &dpyinfo
->mouse_face_beg_row
,
21621 &dpyinfo
->mouse_face_beg_x
,
21622 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21623 dpyinfo
->mouse_face_past_end
21624 = !fast_find_position (w
, XFASTINT (after
),
21625 &dpyinfo
->mouse_face_end_col
,
21626 &dpyinfo
->mouse_face_end_row
,
21627 &dpyinfo
->mouse_face_end_x
,
21628 &dpyinfo
->mouse_face_end_y
, Qnil
);
21629 dpyinfo
->mouse_face_window
= window
;
21631 if (BUFFERP (object
))
21632 dpyinfo
->mouse_face_face_id
21633 = face_at_buffer_position (w
, pos
, 0, 0,
21635 !dpyinfo
->mouse_face_hidden
);
21637 /* Display it as active. */
21638 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21639 cursor
= No_Cursor
;
21641 else if (!NILP (mouse_face
) && STRINGP (object
))
21646 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21649 e
= Fnext_single_property_change (position
, Qmouse_face
,
21652 b
= make_number (0);
21654 e
= make_number (SCHARS (object
) - 1);
21655 fast_find_string_pos (w
, XINT (b
), object
,
21656 &dpyinfo
->mouse_face_beg_col
,
21657 &dpyinfo
->mouse_face_beg_row
,
21658 &dpyinfo
->mouse_face_beg_x
,
21659 &dpyinfo
->mouse_face_beg_y
, 0);
21660 fast_find_string_pos (w
, XINT (e
), object
,
21661 &dpyinfo
->mouse_face_end_col
,
21662 &dpyinfo
->mouse_face_end_row
,
21663 &dpyinfo
->mouse_face_end_x
,
21664 &dpyinfo
->mouse_face_end_y
, 1);
21665 dpyinfo
->mouse_face_past_end
= 0;
21666 dpyinfo
->mouse_face_window
= window
;
21667 dpyinfo
->mouse_face_face_id
21668 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21669 glyph
->face_id
, 1);
21670 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21671 cursor
= No_Cursor
;
21673 else if (STRINGP (object
) && NILP (mouse_face
))
21675 /* A string which doesn't have mouse-face, but
21676 the text ``under'' it might have. */
21677 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21678 int start
= MATRIX_ROW_START_CHARPOS (r
);
21680 pos
= string_buffer_position (w
, object
, start
);
21682 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21686 if (!NILP (mouse_face
) && !NILP (overlay
))
21688 Lisp_Object before
= Foverlay_start (overlay
);
21689 Lisp_Object after
= Foverlay_end (overlay
);
21692 /* Note that we might not be able to find position
21693 BEFORE in the glyph matrix if the overlay is
21694 entirely covered by a `display' property. In
21695 this case, we overshoot. So let's stop in
21696 the glyph matrix before glyphs for OBJECT. */
21697 fast_find_position (w
, XFASTINT (before
),
21698 &dpyinfo
->mouse_face_beg_col
,
21699 &dpyinfo
->mouse_face_beg_row
,
21700 &dpyinfo
->mouse_face_beg_x
,
21701 &dpyinfo
->mouse_face_beg_y
,
21704 dpyinfo
->mouse_face_past_end
21705 = !fast_find_position (w
, XFASTINT (after
),
21706 &dpyinfo
->mouse_face_end_col
,
21707 &dpyinfo
->mouse_face_end_row
,
21708 &dpyinfo
->mouse_face_end_x
,
21709 &dpyinfo
->mouse_face_end_y
,
21711 dpyinfo
->mouse_face_window
= window
;
21712 dpyinfo
->mouse_face_face_id
21713 = face_at_buffer_position (w
, pos
, 0, 0,
21715 !dpyinfo
->mouse_face_hidden
);
21717 /* Display it as active. */
21718 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21719 cursor
= No_Cursor
;
21726 /* Look for a `help-echo' property. */
21727 if (NILP (help_echo_string
)) {
21728 Lisp_Object help
, overlay
;
21730 /* Check overlays first. */
21731 help
= overlay
= Qnil
;
21732 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21734 overlay
= overlay_vec
[i
];
21735 help
= Foverlay_get (overlay
, Qhelp_echo
);
21740 help_echo_string
= help
;
21741 help_echo_window
= window
;
21742 help_echo_object
= overlay
;
21743 help_echo_pos
= pos
;
21747 Lisp_Object object
= glyph
->object
;
21748 int charpos
= glyph
->charpos
;
21750 /* Try text properties. */
21751 if (STRINGP (object
)
21753 && charpos
< SCHARS (object
))
21755 help
= Fget_text_property (make_number (charpos
),
21756 Qhelp_echo
, object
);
21759 /* If the string itself doesn't specify a help-echo,
21760 see if the buffer text ``under'' it does. */
21761 struct glyph_row
*r
21762 = MATRIX_ROW (w
->current_matrix
, vpos
);
21763 int start
= MATRIX_ROW_START_CHARPOS (r
);
21764 int pos
= string_buffer_position (w
, object
, start
);
21767 help
= Fget_char_property (make_number (pos
),
21768 Qhelp_echo
, w
->buffer
);
21772 object
= w
->buffer
;
21777 else if (BUFFERP (object
)
21780 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21785 help_echo_string
= help
;
21786 help_echo_window
= window
;
21787 help_echo_object
= object
;
21788 help_echo_pos
= charpos
;
21793 /* Look for a `pointer' property. */
21794 if (NILP (pointer
))
21796 /* Check overlays first. */
21797 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21798 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21800 if (NILP (pointer
))
21802 Lisp_Object object
= glyph
->object
;
21803 int charpos
= glyph
->charpos
;
21805 /* Try text properties. */
21806 if (STRINGP (object
)
21808 && charpos
< SCHARS (object
))
21810 pointer
= Fget_text_property (make_number (charpos
),
21812 if (NILP (pointer
))
21814 /* If the string itself doesn't specify a pointer,
21815 see if the buffer text ``under'' it does. */
21816 struct glyph_row
*r
21817 = MATRIX_ROW (w
->current_matrix
, vpos
);
21818 int start
= MATRIX_ROW_START_CHARPOS (r
);
21819 int pos
= string_buffer_position (w
, object
, start
);
21821 pointer
= Fget_char_property (make_number (pos
),
21822 Qpointer
, w
->buffer
);
21825 else if (BUFFERP (object
)
21828 pointer
= Fget_text_property (make_number (charpos
),
21835 current_buffer
= obuf
;
21840 define_frame_cursor1 (f
, cursor
, pointer
);
21845 Clear any mouse-face on window W. This function is part of the
21846 redisplay interface, and is called from try_window_id and similar
21847 functions to ensure the mouse-highlight is off. */
21850 x_clear_window_mouse_face (w
)
21853 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21854 Lisp_Object window
;
21857 XSETWINDOW (window
, w
);
21858 if (EQ (window
, dpyinfo
->mouse_face_window
))
21859 clear_mouse_face (dpyinfo
);
21865 Just discard the mouse face information for frame F, if any.
21866 This is used when the size of F is changed. */
21869 cancel_mouse_face (f
)
21872 Lisp_Object window
;
21873 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21875 window
= dpyinfo
->mouse_face_window
;
21876 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21878 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21879 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21880 dpyinfo
->mouse_face_window
= Qnil
;
21885 #endif /* HAVE_WINDOW_SYSTEM */
21888 /***********************************************************************
21890 ***********************************************************************/
21892 #ifdef HAVE_WINDOW_SYSTEM
21894 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21895 which intersects rectangle R. R is in window-relative coordinates. */
21898 expose_area (w
, row
, r
, area
)
21900 struct glyph_row
*row
;
21902 enum glyph_row_area area
;
21904 struct glyph
*first
= row
->glyphs
[area
];
21905 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21906 struct glyph
*last
;
21907 int first_x
, start_x
, x
;
21909 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21910 /* If row extends face to end of line write the whole line. */
21911 draw_glyphs (w
, 0, row
, area
,
21912 0, row
->used
[area
],
21913 DRAW_NORMAL_TEXT
, 0);
21916 /* Set START_X to the window-relative start position for drawing glyphs of
21917 AREA. The first glyph of the text area can be partially visible.
21918 The first glyphs of other areas cannot. */
21919 start_x
= window_box_left_offset (w
, area
);
21921 if (area
== TEXT_AREA
)
21924 /* Find the first glyph that must be redrawn. */
21926 && x
+ first
->pixel_width
< r
->x
)
21928 x
+= first
->pixel_width
;
21932 /* Find the last one. */
21936 && x
< r
->x
+ r
->width
)
21938 x
+= last
->pixel_width
;
21944 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21945 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21946 DRAW_NORMAL_TEXT
, 0);
21951 /* Redraw the parts of the glyph row ROW on window W intersecting
21952 rectangle R. R is in window-relative coordinates. Value is
21953 non-zero if mouse-face was overwritten. */
21956 expose_line (w
, row
, r
)
21958 struct glyph_row
*row
;
21961 xassert (row
->enabled_p
);
21963 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21964 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21965 0, row
->used
[TEXT_AREA
],
21966 DRAW_NORMAL_TEXT
, 0);
21969 if (row
->used
[LEFT_MARGIN_AREA
])
21970 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21971 if (row
->used
[TEXT_AREA
])
21972 expose_area (w
, row
, r
, TEXT_AREA
);
21973 if (row
->used
[RIGHT_MARGIN_AREA
])
21974 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21975 draw_row_fringe_bitmaps (w
, row
);
21978 return row
->mouse_face_p
;
21982 /* Redraw those parts of glyphs rows during expose event handling that
21983 overlap other rows. Redrawing of an exposed line writes over parts
21984 of lines overlapping that exposed line; this function fixes that.
21986 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21987 row in W's current matrix that is exposed and overlaps other rows.
21988 LAST_OVERLAPPING_ROW is the last such row. */
21991 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21993 struct glyph_row
*first_overlapping_row
;
21994 struct glyph_row
*last_overlapping_row
;
21996 struct glyph_row
*row
;
21998 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21999 if (row
->overlapping_p
)
22001 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22003 if (row
->used
[LEFT_MARGIN_AREA
])
22004 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22006 if (row
->used
[TEXT_AREA
])
22007 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22009 if (row
->used
[RIGHT_MARGIN_AREA
])
22010 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22015 /* Return non-zero if W's cursor intersects rectangle R. */
22018 phys_cursor_in_rect_p (w
, r
)
22022 XRectangle cr
, result
;
22023 struct glyph
*cursor_glyph
;
22025 cursor_glyph
= get_phys_cursor_glyph (w
);
22028 /* r is relative to W's box, but w->phys_cursor.x is relative
22029 to left edge of W's TEXT area. Adjust it. */
22030 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22031 cr
.y
= w
->phys_cursor
.y
;
22032 cr
.width
= cursor_glyph
->pixel_width
;
22033 cr
.height
= w
->phys_cursor_height
;
22034 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22035 I assume the effect is the same -- and this is portable. */
22036 return x_intersect_rectangles (&cr
, r
, &result
);
22044 Draw a vertical window border to the right of window W if W doesn't
22045 have vertical scroll bars. */
22048 x_draw_vertical_border (w
)
22051 /* We could do better, if we knew what type of scroll-bar the adjacent
22052 windows (on either side) have... But we don't :-(
22053 However, I think this works ok. ++KFS 2003-04-25 */
22055 /* Redraw borders between horizontally adjacent windows. Don't
22056 do it for frames with vertical scroll bars because either the
22057 right scroll bar of a window, or the left scroll bar of its
22058 neighbor will suffice as a border. */
22059 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22062 if (!WINDOW_RIGHTMOST_P (w
)
22063 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22065 int x0
, x1
, y0
, y1
;
22067 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22070 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22072 else if (!WINDOW_LEFTMOST_P (w
)
22073 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22075 int x0
, x1
, y0
, y1
;
22077 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22080 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22085 /* Redraw the part of window W intersection rectangle FR. Pixel
22086 coordinates in FR are frame-relative. Call this function with
22087 input blocked. Value is non-zero if the exposure overwrites
22091 expose_window (w
, fr
)
22095 struct frame
*f
= XFRAME (w
->frame
);
22097 int mouse_face_overwritten_p
= 0;
22099 /* If window is not yet fully initialized, do nothing. This can
22100 happen when toolkit scroll bars are used and a window is split.
22101 Reconfiguring the scroll bar will generate an expose for a newly
22103 if (w
->current_matrix
== NULL
)
22106 /* When we're currently updating the window, display and current
22107 matrix usually don't agree. Arrange for a thorough display
22109 if (w
== updated_window
)
22111 SET_FRAME_GARBAGED (f
);
22115 /* Frame-relative pixel rectangle of W. */
22116 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22117 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22118 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22119 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22121 if (x_intersect_rectangles (fr
, &wr
, &r
))
22123 int yb
= window_text_bottom_y (w
);
22124 struct glyph_row
*row
;
22125 int cursor_cleared_p
;
22126 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22128 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22129 r
.x
, r
.y
, r
.width
, r
.height
));
22131 /* Convert to window coordinates. */
22132 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22133 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22135 /* Turn off the cursor. */
22136 if (!w
->pseudo_window_p
22137 && phys_cursor_in_rect_p (w
, &r
))
22139 x_clear_cursor (w
);
22140 cursor_cleared_p
= 1;
22143 cursor_cleared_p
= 0;
22145 /* Update lines intersecting rectangle R. */
22146 first_overlapping_row
= last_overlapping_row
= NULL
;
22147 for (row
= w
->current_matrix
->rows
;
22152 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22154 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22155 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22156 || (r
.y
>= y0
&& r
.y
< y1
)
22157 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22159 /* A header line may be overlapping, but there is no need
22160 to fix overlapping areas for them. KFS 2005-02-12 */
22161 if (row
->overlapping_p
&& !row
->mode_line_p
)
22163 if (first_overlapping_row
== NULL
)
22164 first_overlapping_row
= row
;
22165 last_overlapping_row
= row
;
22168 if (expose_line (w
, row
, &r
))
22169 mouse_face_overwritten_p
= 1;
22176 /* Display the mode line if there is one. */
22177 if (WINDOW_WANTS_MODELINE_P (w
)
22178 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22180 && row
->y
< r
.y
+ r
.height
)
22182 if (expose_line (w
, row
, &r
))
22183 mouse_face_overwritten_p
= 1;
22186 if (!w
->pseudo_window_p
)
22188 /* Fix the display of overlapping rows. */
22189 if (first_overlapping_row
)
22190 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22192 /* Draw border between windows. */
22193 x_draw_vertical_border (w
);
22195 /* Turn the cursor on again. */
22196 if (cursor_cleared_p
)
22197 update_window_cursor (w
, 1);
22201 return mouse_face_overwritten_p
;
22206 /* Redraw (parts) of all windows in the window tree rooted at W that
22207 intersect R. R contains frame pixel coordinates. Value is
22208 non-zero if the exposure overwrites mouse-face. */
22211 expose_window_tree (w
, r
)
22215 struct frame
*f
= XFRAME (w
->frame
);
22216 int mouse_face_overwritten_p
= 0;
22218 while (w
&& !FRAME_GARBAGED_P (f
))
22220 if (!NILP (w
->hchild
))
22221 mouse_face_overwritten_p
22222 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22223 else if (!NILP (w
->vchild
))
22224 mouse_face_overwritten_p
22225 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22227 mouse_face_overwritten_p
|= expose_window (w
, r
);
22229 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22232 return mouse_face_overwritten_p
;
22237 Redisplay an exposed area of frame F. X and Y are the upper-left
22238 corner of the exposed rectangle. W and H are width and height of
22239 the exposed area. All are pixel values. W or H zero means redraw
22240 the entire frame. */
22243 expose_frame (f
, x
, y
, w
, h
)
22248 int mouse_face_overwritten_p
= 0;
22250 TRACE ((stderr
, "expose_frame "));
22252 /* No need to redraw if frame will be redrawn soon. */
22253 if (FRAME_GARBAGED_P (f
))
22255 TRACE ((stderr
, " garbaged\n"));
22259 /* If basic faces haven't been realized yet, there is no point in
22260 trying to redraw anything. This can happen when we get an expose
22261 event while Emacs is starting, e.g. by moving another window. */
22262 if (FRAME_FACE_CACHE (f
) == NULL
22263 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22265 TRACE ((stderr
, " no faces\n"));
22269 if (w
== 0 || h
== 0)
22272 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22273 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22283 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22284 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22286 if (WINDOWP (f
->tool_bar_window
))
22287 mouse_face_overwritten_p
22288 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22290 #ifdef HAVE_X_WINDOWS
22292 #ifndef USE_X_TOOLKIT
22293 if (WINDOWP (f
->menu_bar_window
))
22294 mouse_face_overwritten_p
22295 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22296 #endif /* not USE_X_TOOLKIT */
22300 /* Some window managers support a focus-follows-mouse style with
22301 delayed raising of frames. Imagine a partially obscured frame,
22302 and moving the mouse into partially obscured mouse-face on that
22303 frame. The visible part of the mouse-face will be highlighted,
22304 then the WM raises the obscured frame. With at least one WM, KDE
22305 2.1, Emacs is not getting any event for the raising of the frame
22306 (even tried with SubstructureRedirectMask), only Expose events.
22307 These expose events will draw text normally, i.e. not
22308 highlighted. Which means we must redo the highlight here.
22309 Subsume it under ``we love X''. --gerd 2001-08-15 */
22310 /* Included in Windows version because Windows most likely does not
22311 do the right thing if any third party tool offers
22312 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22313 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22315 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22316 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22318 int x
= dpyinfo
->mouse_face_mouse_x
;
22319 int y
= dpyinfo
->mouse_face_mouse_y
;
22320 clear_mouse_face (dpyinfo
);
22321 note_mouse_highlight (f
, x
, y
);
22328 Determine the intersection of two rectangles R1 and R2. Return
22329 the intersection in *RESULT. Value is non-zero if RESULT is not
22333 x_intersect_rectangles (r1
, r2
, result
)
22334 XRectangle
*r1
, *r2
, *result
;
22336 XRectangle
*left
, *right
;
22337 XRectangle
*upper
, *lower
;
22338 int intersection_p
= 0;
22340 /* Rearrange so that R1 is the left-most rectangle. */
22342 left
= r1
, right
= r2
;
22344 left
= r2
, right
= r1
;
22346 /* X0 of the intersection is right.x0, if this is inside R1,
22347 otherwise there is no intersection. */
22348 if (right
->x
<= left
->x
+ left
->width
)
22350 result
->x
= right
->x
;
22352 /* The right end of the intersection is the minimum of the
22353 the right ends of left and right. */
22354 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22357 /* Same game for Y. */
22359 upper
= r1
, lower
= r2
;
22361 upper
= r2
, lower
= r1
;
22363 /* The upper end of the intersection is lower.y0, if this is inside
22364 of upper. Otherwise, there is no intersection. */
22365 if (lower
->y
<= upper
->y
+ upper
->height
)
22367 result
->y
= lower
->y
;
22369 /* The lower end of the intersection is the minimum of the lower
22370 ends of upper and lower. */
22371 result
->height
= (min (lower
->y
+ lower
->height
,
22372 upper
->y
+ upper
->height
)
22374 intersection_p
= 1;
22378 return intersection_p
;
22381 #endif /* HAVE_WINDOW_SYSTEM */
22384 /***********************************************************************
22386 ***********************************************************************/
22391 Vwith_echo_area_save_vector
= Qnil
;
22392 staticpro (&Vwith_echo_area_save_vector
);
22394 Vmessage_stack
= Qnil
;
22395 staticpro (&Vmessage_stack
);
22397 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22398 staticpro (&Qinhibit_redisplay
);
22400 message_dolog_marker1
= Fmake_marker ();
22401 staticpro (&message_dolog_marker1
);
22402 message_dolog_marker2
= Fmake_marker ();
22403 staticpro (&message_dolog_marker2
);
22404 message_dolog_marker3
= Fmake_marker ();
22405 staticpro (&message_dolog_marker3
);
22408 defsubr (&Sdump_frame_glyph_matrix
);
22409 defsubr (&Sdump_glyph_matrix
);
22410 defsubr (&Sdump_glyph_row
);
22411 defsubr (&Sdump_tool_bar_row
);
22412 defsubr (&Strace_redisplay
);
22413 defsubr (&Strace_to_stderr
);
22415 #ifdef HAVE_WINDOW_SYSTEM
22416 defsubr (&Stool_bar_lines_needed
);
22417 defsubr (&Slookup_image_map
);
22419 defsubr (&Sformat_mode_line
);
22421 staticpro (&Qmenu_bar_update_hook
);
22422 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22424 staticpro (&Qoverriding_terminal_local_map
);
22425 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22427 staticpro (&Qoverriding_local_map
);
22428 Qoverriding_local_map
= intern ("overriding-local-map");
22430 staticpro (&Qwindow_scroll_functions
);
22431 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22433 staticpro (&Qredisplay_end_trigger_functions
);
22434 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22436 staticpro (&Qinhibit_point_motion_hooks
);
22437 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22439 QCdata
= intern (":data");
22440 staticpro (&QCdata
);
22441 Qdisplay
= intern ("display");
22442 staticpro (&Qdisplay
);
22443 Qspace_width
= intern ("space-width");
22444 staticpro (&Qspace_width
);
22445 Qraise
= intern ("raise");
22446 staticpro (&Qraise
);
22447 Qslice
= intern ("slice");
22448 staticpro (&Qslice
);
22449 Qspace
= intern ("space");
22450 staticpro (&Qspace
);
22451 Qmargin
= intern ("margin");
22452 staticpro (&Qmargin
);
22453 Qpointer
= intern ("pointer");
22454 staticpro (&Qpointer
);
22455 Qleft_margin
= intern ("left-margin");
22456 staticpro (&Qleft_margin
);
22457 Qright_margin
= intern ("right-margin");
22458 staticpro (&Qright_margin
);
22459 Qcenter
= intern ("center");
22460 staticpro (&Qcenter
);
22461 Qline_height
= intern ("line-height");
22462 staticpro (&Qline_height
);
22463 QCalign_to
= intern (":align-to");
22464 staticpro (&QCalign_to
);
22465 QCrelative_width
= intern (":relative-width");
22466 staticpro (&QCrelative_width
);
22467 QCrelative_height
= intern (":relative-height");
22468 staticpro (&QCrelative_height
);
22469 QCeval
= intern (":eval");
22470 staticpro (&QCeval
);
22471 QCpropertize
= intern (":propertize");
22472 staticpro (&QCpropertize
);
22473 QCfile
= intern (":file");
22474 staticpro (&QCfile
);
22475 Qfontified
= intern ("fontified");
22476 staticpro (&Qfontified
);
22477 Qfontification_functions
= intern ("fontification-functions");
22478 staticpro (&Qfontification_functions
);
22479 Qtrailing_whitespace
= intern ("trailing-whitespace");
22480 staticpro (&Qtrailing_whitespace
);
22481 Qescape_glyph
= intern ("escape-glyph");
22482 staticpro (&Qescape_glyph
);
22483 Qimage
= intern ("image");
22484 staticpro (&Qimage
);
22485 QCmap
= intern (":map");
22486 staticpro (&QCmap
);
22487 QCpointer
= intern (":pointer");
22488 staticpro (&QCpointer
);
22489 Qrect
= intern ("rect");
22490 staticpro (&Qrect
);
22491 Qcircle
= intern ("circle");
22492 staticpro (&Qcircle
);
22493 Qpoly
= intern ("poly");
22494 staticpro (&Qpoly
);
22495 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22496 staticpro (&Qmessage_truncate_lines
);
22497 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
22498 staticpro (&Qcursor_in_non_selected_windows
);
22499 Qgrow_only
= intern ("grow-only");
22500 staticpro (&Qgrow_only
);
22501 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22502 staticpro (&Qinhibit_menubar_update
);
22503 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22504 staticpro (&Qinhibit_eval_during_redisplay
);
22505 Qposition
= intern ("position");
22506 staticpro (&Qposition
);
22507 Qbuffer_position
= intern ("buffer-position");
22508 staticpro (&Qbuffer_position
);
22509 Qobject
= intern ("object");
22510 staticpro (&Qobject
);
22511 Qbar
= intern ("bar");
22513 Qhbar
= intern ("hbar");
22514 staticpro (&Qhbar
);
22515 Qbox
= intern ("box");
22517 Qhollow
= intern ("hollow");
22518 staticpro (&Qhollow
);
22519 Qhand
= intern ("hand");
22520 staticpro (&Qhand
);
22521 Qarrow
= intern ("arrow");
22522 staticpro (&Qarrow
);
22523 Qtext
= intern ("text");
22524 staticpro (&Qtext
);
22525 Qrisky_local_variable
= intern ("risky-local-variable");
22526 staticpro (&Qrisky_local_variable
);
22527 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22528 staticpro (&Qinhibit_free_realized_faces
);
22530 list_of_error
= Fcons (Fcons (intern ("error"),
22531 Fcons (intern ("void-variable"), Qnil
)),
22533 staticpro (&list_of_error
);
22535 Qlast_arrow_position
= intern ("last-arrow-position");
22536 staticpro (&Qlast_arrow_position
);
22537 Qlast_arrow_string
= intern ("last-arrow-string");
22538 staticpro (&Qlast_arrow_string
);
22540 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22541 staticpro (&Qoverlay_arrow_string
);
22542 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22543 staticpro (&Qoverlay_arrow_bitmap
);
22545 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22546 staticpro (&echo_buffer
[0]);
22547 staticpro (&echo_buffer
[1]);
22549 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22550 staticpro (&echo_area_buffer
[0]);
22551 staticpro (&echo_area_buffer
[1]);
22553 Vmessages_buffer_name
= build_string ("*Messages*");
22554 staticpro (&Vmessages_buffer_name
);
22556 mode_line_proptrans_alist
= Qnil
;
22557 staticpro (&mode_line_proptrans_alist
);
22559 mode_line_string_list
= Qnil
;
22560 staticpro (&mode_line_string_list
);
22562 help_echo_string
= Qnil
;
22563 staticpro (&help_echo_string
);
22564 help_echo_object
= Qnil
;
22565 staticpro (&help_echo_object
);
22566 help_echo_window
= Qnil
;
22567 staticpro (&help_echo_window
);
22568 previous_help_echo_string
= Qnil
;
22569 staticpro (&previous_help_echo_string
);
22570 help_echo_pos
= -1;
22572 #ifdef HAVE_WINDOW_SYSTEM
22573 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22574 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22575 For example, if a block cursor is over a tab, it will be drawn as
22576 wide as that tab on the display. */);
22577 x_stretch_cursor_p
= 0;
22580 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22581 doc
: /* *Non-nil means highlight trailing whitespace.
22582 The face used for trailing whitespace is `trailing-whitespace'. */);
22583 Vshow_trailing_whitespace
= Qnil
;
22585 DEFVAR_LISP ("show-nonbreak-escape", &Vshow_nonbreak_escape
,
22586 doc
: /* *Non-nil means display escape character before non-break space and hyphen. */);
22587 Vshow_nonbreak_escape
= Qt
;
22589 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22590 doc
: /* *The pointer shape to show in void text areas.
22591 Nil means to show the text pointer. Other options are `arrow', `text',
22592 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22593 Vvoid_text_area_pointer
= Qarrow
;
22595 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22596 doc
: /* Non-nil means don't actually do any redisplay.
22597 This is used for internal purposes. */);
22598 Vinhibit_redisplay
= Qnil
;
22600 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22601 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22602 Vglobal_mode_string
= Qnil
;
22604 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22605 doc
: /* Marker for where to display an arrow on top of the buffer text.
22606 This must be the beginning of a line in order to work.
22607 See also `overlay-arrow-string'. */);
22608 Voverlay_arrow_position
= Qnil
;
22610 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22611 doc
: /* String to display as an arrow in non-window frames.
22612 See also `overlay-arrow-position'. */);
22613 Voverlay_arrow_string
= Qnil
;
22615 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22616 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22617 The symbols on this list are examined during redisplay to determine
22618 where to display overlay arrows. */);
22619 Voverlay_arrow_variable_list
22620 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22622 DEFVAR_INT ("scroll-step", &scroll_step
,
22623 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22624 If that fails to bring point back on frame, point is centered instead.
22625 If this is zero, point is always centered after it moves off frame.
22626 If you want scrolling to always be a line at a time, you should set
22627 `scroll-conservatively' to a large value rather than set this to 1. */);
22629 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22630 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22631 A value of zero means to scroll the text to center point vertically
22632 in the window. */);
22633 scroll_conservatively
= 0;
22635 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22636 doc
: /* *Number of lines of margin at the top and bottom of a window.
22637 Recenter the window whenever point gets within this many lines
22638 of the top or bottom of the window. */);
22641 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22642 doc
: /* Pixels per inch on current display.
22643 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22644 Vdisplay_pixels_per_inch
= make_float (72.0);
22647 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22650 DEFVAR_BOOL ("truncate-partial-width-windows",
22651 &truncate_partial_width_windows
,
22652 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22653 truncate_partial_width_windows
= 1;
22655 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22656 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22657 Any other value means to use the appropriate face, `mode-line',
22658 `header-line', or `menu' respectively. */);
22659 mode_line_inverse_video
= 1;
22661 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22662 doc
: /* *Maximum buffer size for which line number should be displayed.
22663 If the buffer is bigger than this, the line number does not appear
22664 in the mode line. A value of nil means no limit. */);
22665 Vline_number_display_limit
= Qnil
;
22667 DEFVAR_INT ("line-number-display-limit-width",
22668 &line_number_display_limit_width
,
22669 doc
: /* *Maximum line width (in characters) for line number display.
22670 If the average length of the lines near point is bigger than this, then the
22671 line number may be omitted from the mode line. */);
22672 line_number_display_limit_width
= 200;
22674 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22675 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22676 highlight_nonselected_windows
= 0;
22678 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22679 doc
: /* Non-nil if more than one frame is visible on this display.
22680 Minibuffer-only frames don't count, but iconified frames do.
22681 This variable is not guaranteed to be accurate except while processing
22682 `frame-title-format' and `icon-title-format'. */);
22684 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22685 doc
: /* Template for displaying the title bar of visible frames.
22686 \(Assuming the window manager supports this feature.)
22687 This variable has the same structure as `mode-line-format' (which see),
22688 and is used only on frames for which no explicit name has been set
22689 \(see `modify-frame-parameters'). */);
22691 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22692 doc
: /* Template for displaying the title bar of an iconified frame.
22693 \(Assuming the window manager supports this feature.)
22694 This variable has the same structure as `mode-line-format' (which see),
22695 and is used only on frames for which no explicit name has been set
22696 \(see `modify-frame-parameters'). */);
22698 = Vframe_title_format
22699 = Fcons (intern ("multiple-frames"),
22700 Fcons (build_string ("%b"),
22701 Fcons (Fcons (empty_string
,
22702 Fcons (intern ("invocation-name"),
22703 Fcons (build_string ("@"),
22704 Fcons (intern ("system-name"),
22708 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22709 doc
: /* Maximum number of lines to keep in the message log buffer.
22710 If nil, disable message logging. If t, log messages but don't truncate
22711 the buffer when it becomes large. */);
22712 Vmessage_log_max
= make_number (50);
22714 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22715 doc
: /* Functions called before redisplay, if window sizes have changed.
22716 The value should be a list of functions that take one argument.
22717 Just before redisplay, for each frame, if any of its windows have changed
22718 size since the last redisplay, or have been split or deleted,
22719 all the functions in the list are called, with the frame as argument. */);
22720 Vwindow_size_change_functions
= Qnil
;
22722 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22723 doc
: /* List of functions to call before redisplaying a window with scrolling.
22724 Each function is called with two arguments, the window
22725 and its new display-start position. Note that the value of `window-end'
22726 is not valid when these functions are called. */);
22727 Vwindow_scroll_functions
= Qnil
;
22729 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22730 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22731 mouse_autoselect_window
= 0;
22733 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22734 doc
: /* *Non-nil means automatically resize tool-bars.
22735 This increases a tool-bar's height if not all tool-bar items are visible.
22736 It decreases a tool-bar's height when it would display blank lines
22738 auto_resize_tool_bars_p
= 1;
22740 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22741 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22742 auto_raise_tool_bar_buttons_p
= 1;
22744 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
22745 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
22746 make_cursor_line_fully_visible_p
= 1;
22748 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22749 doc
: /* *Margin around tool-bar buttons in pixels.
22750 If an integer, use that for both horizontal and vertical margins.
22751 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22752 HORZ specifying the horizontal margin, and VERT specifying the
22753 vertical margin. */);
22754 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22756 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22757 doc
: /* *Relief thickness of tool-bar buttons. */);
22758 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22760 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22761 doc
: /* List of functions to call to fontify regions of text.
22762 Each function is called with one argument POS. Functions must
22763 fontify a region starting at POS in the current buffer, and give
22764 fontified regions the property `fontified'. */);
22765 Vfontification_functions
= Qnil
;
22766 Fmake_variable_buffer_local (Qfontification_functions
);
22768 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22769 &unibyte_display_via_language_environment
,
22770 doc
: /* *Non-nil means display unibyte text according to language environment.
22771 Specifically this means that unibyte non-ASCII characters
22772 are displayed by converting them to the equivalent multibyte characters
22773 according to the current language environment. As a result, they are
22774 displayed according to the current fontset. */);
22775 unibyte_display_via_language_environment
= 0;
22777 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22778 doc
: /* *Maximum height for resizing mini-windows.
22779 If a float, it specifies a fraction of the mini-window frame's height.
22780 If an integer, it specifies a number of lines. */);
22781 Vmax_mini_window_height
= make_float (0.25);
22783 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22784 doc
: /* *How to resize mini-windows.
22785 A value of nil means don't automatically resize mini-windows.
22786 A value of t means resize them to fit the text displayed in them.
22787 A value of `grow-only', the default, means let mini-windows grow
22788 only, until their display becomes empty, at which point the windows
22789 go back to their normal size. */);
22790 Vresize_mini_windows
= Qgrow_only
;
22792 DEFVAR_LISP ("cursor-in-non-selected-windows",
22793 &Vcursor_in_non_selected_windows
,
22794 doc
: /* *Cursor type to display in non-selected windows.
22795 t means to use hollow box cursor. See `cursor-type' for other values. */);
22796 Vcursor_in_non_selected_windows
= Qt
;
22798 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22799 doc
: /* Alist specifying how to blink the cursor off.
22800 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22801 `cursor-type' frame-parameter or variable equals ON-STATE,
22802 comparing using `equal', Emacs uses OFF-STATE to specify
22803 how to blink it off. */);
22804 Vblink_cursor_alist
= Qnil
;
22806 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22807 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22808 automatic_hscrolling_p
= 1;
22810 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22811 doc
: /* *How many columns away from the window edge point is allowed to get
22812 before automatic hscrolling will horizontally scroll the window. */);
22813 hscroll_margin
= 5;
22815 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22816 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22817 When point is less than `automatic-hscroll-margin' columns from the window
22818 edge, automatic hscrolling will scroll the window by the amount of columns
22819 determined by this variable. If its value is a positive integer, scroll that
22820 many columns. If it's a positive floating-point number, it specifies the
22821 fraction of the window's width to scroll. If it's nil or zero, point will be
22822 centered horizontally after the scroll. Any other value, including negative
22823 numbers, are treated as if the value were zero.
22825 Automatic hscrolling always moves point outside the scroll margin, so if
22826 point was more than scroll step columns inside the margin, the window will
22827 scroll more than the value given by the scroll step.
22829 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22830 and `scroll-right' overrides this variable's effect. */);
22831 Vhscroll_step
= make_number (0);
22833 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22834 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22835 Bind this around calls to `message' to let it take effect. */);
22836 message_truncate_lines
= 0;
22838 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22839 doc
: /* Normal hook run to update the menu bar definitions.
22840 Redisplay runs this hook before it redisplays the menu bar.
22841 This is used to update submenus such as Buffers,
22842 whose contents depend on various data. */);
22843 Vmenu_bar_update_hook
= Qnil
;
22845 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22846 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22847 inhibit_menubar_update
= 0;
22849 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22850 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22851 inhibit_eval_during_redisplay
= 0;
22853 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22854 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22855 inhibit_free_realized_faces
= 0;
22858 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22859 doc
: /* Inhibit try_window_id display optimization. */);
22860 inhibit_try_window_id
= 0;
22862 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22863 doc
: /* Inhibit try_window_reusing display optimization. */);
22864 inhibit_try_window_reusing
= 0;
22866 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22867 doc
: /* Inhibit try_cursor_movement display optimization. */);
22868 inhibit_try_cursor_movement
= 0;
22869 #endif /* GLYPH_DEBUG */
22873 /* Initialize this module when Emacs starts. */
22878 Lisp_Object root_window
;
22879 struct window
*mini_w
;
22881 current_header_line_height
= current_mode_line_height
= -1;
22883 CHARPOS (this_line_start_pos
) = 0;
22885 mini_w
= XWINDOW (minibuf_window
);
22886 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22888 if (!noninteractive
)
22890 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22893 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22894 set_window_height (root_window
,
22895 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22897 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22898 set_window_height (minibuf_window
, 1, 0);
22900 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22901 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22903 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22904 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22905 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22907 /* The default ellipsis glyphs `...'. */
22908 for (i
= 0; i
< 3; ++i
)
22909 default_invis_vector
[i
] = make_number ('.');
22913 /* Allocate the buffer for frame titles.
22914 Also used for `format-mode-line'. */
22916 frame_title_buf
= (char *) xmalloc (size
);
22917 frame_title_buf_end
= frame_title_buf
+ size
;
22918 frame_title_ptr
= NULL
;
22921 help_echo_showing_p
= 0;
22925 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22926 (do not change this comment) */