1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03,04
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
203 #ifndef FRAME_X_OUTPUT
204 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
207 #define INFINITY 10000000
209 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
211 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
212 extern int pending_menu_activation
;
215 extern int interrupt_input
;
216 extern int command_loop_level
;
218 extern Lisp_Object do_mouse_tracking
;
220 extern int minibuffer_auto_raise
;
221 extern Lisp_Object Vminibuffer_list
;
223 extern Lisp_Object Qface
;
224 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
226 extern Lisp_Object Voverriding_local_map
;
227 extern Lisp_Object Voverriding_local_map_menu_flag
;
228 extern Lisp_Object Qmenu_item
;
229 extern Lisp_Object Qwhen
;
230 extern Lisp_Object Qhelp_echo
;
232 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
233 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
234 Lisp_Object Qredisplay_end_trigger_functions
;
235 Lisp_Object Qinhibit_point_motion_hooks
;
236 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
237 Lisp_Object Qfontified
;
238 Lisp_Object Qgrow_only
;
239 Lisp_Object Qinhibit_eval_during_redisplay
;
240 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
243 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Non-zero means to reposition window if cursor line is only partially visible. */
269 int make_cursor_line_fully_visible_p
;
271 /* Margin around tool bar buttons in pixels. */
273 Lisp_Object Vtool_bar_button_margin
;
275 /* Thickness of shadow to draw around tool bar buttons. */
277 EMACS_INT tool_bar_button_relief
;
279 /* Non-zero means automatically resize tool-bars so that all tool-bar
280 items are visible, and no blank lines remain. */
282 int auto_resize_tool_bars_p
;
284 /* Non-zero means draw block and hollow cursor as wide as the glyph
285 under it. For example, if a block cursor is over a tab, it will be
286 drawn as wide as that tab on the display. */
288 int x_stretch_cursor_p
;
290 /* Non-nil means don't actually do any redisplay. */
292 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
294 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
296 int inhibit_eval_during_redisplay
;
298 /* Names of text properties relevant for redisplay. */
300 Lisp_Object Qdisplay
;
301 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
303 /* Symbols used in text property values. */
305 Lisp_Object Vdisplay_pixels_per_inch
;
306 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
307 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
310 Lisp_Object Qmargin
, Qpointer
;
311 Lisp_Object Qline_height
, Qtotal
;
312 extern Lisp_Object Qheight
;
313 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
314 extern Lisp_Object Qscroll_bar
;
315 extern Lisp_Object Qcursor
;
317 /* Non-nil means highlight trailing whitespace. */
319 Lisp_Object Vshow_trailing_whitespace
;
321 #ifdef HAVE_WINDOW_SYSTEM
322 extern Lisp_Object Voverflow_newline_into_fringe
;
324 /* Test if overflow newline into fringe. Called with iterator IT
325 at or past right window margin, and with IT->current_x set. */
327 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
328 (!NILP (Voverflow_newline_into_fringe) \
329 && FRAME_WINDOW_P (it->f) \
330 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
331 && it->current_x == it->last_visible_x)
333 #endif /* HAVE_WINDOW_SYSTEM */
335 /* Non-nil means show the text cursor in void text areas
336 i.e. in blank areas after eol and eob. This used to be
337 the default in 21.3. */
339 Lisp_Object Vvoid_text_area_pointer
;
341 /* Name of the face used to highlight trailing whitespace. */
343 Lisp_Object Qtrailing_whitespace
;
345 /* The symbol `image' which is the car of the lists used to represent
350 /* The image map types. */
351 Lisp_Object QCmap
, QCpointer
;
352 Lisp_Object Qrect
, Qcircle
, Qpoly
;
354 /* Non-zero means print newline to stdout before next mini-buffer
357 int noninteractive_need_newline
;
359 /* Non-zero means print newline to message log before next message. */
361 static int message_log_need_newline
;
363 /* Three markers that message_dolog uses.
364 It could allocate them itself, but that causes trouble
365 in handling memory-full errors. */
366 static Lisp_Object message_dolog_marker1
;
367 static Lisp_Object message_dolog_marker2
;
368 static Lisp_Object message_dolog_marker3
;
370 /* The buffer position of the first character appearing entirely or
371 partially on the line of the selected window which contains the
372 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
373 redisplay optimization in redisplay_internal. */
375 static struct text_pos this_line_start_pos
;
377 /* Number of characters past the end of the line above, including the
378 terminating newline. */
380 static struct text_pos this_line_end_pos
;
382 /* The vertical positions and the height of this line. */
384 static int this_line_vpos
;
385 static int this_line_y
;
386 static int this_line_pixel_height
;
388 /* X position at which this display line starts. Usually zero;
389 negative if first character is partially visible. */
391 static int this_line_start_x
;
393 /* Buffer that this_line_.* variables are referring to. */
395 static struct buffer
*this_line_buffer
;
397 /* Nonzero means truncate lines in all windows less wide than the
400 int truncate_partial_width_windows
;
402 /* A flag to control how to display unibyte 8-bit character. */
404 int unibyte_display_via_language_environment
;
406 /* Nonzero means we have more than one non-mini-buffer-only frame.
407 Not guaranteed to be accurate except while parsing
408 frame-title-format. */
412 Lisp_Object Vglobal_mode_string
;
415 /* List of variables (symbols) which hold markers for overlay arrows.
416 The symbols on this list are examined during redisplay to determine
417 where to display overlay arrows. */
419 Lisp_Object Voverlay_arrow_variable_list
;
421 /* Marker for where to display an arrow on top of the buffer text. */
423 Lisp_Object Voverlay_arrow_position
;
425 /* String to display for the arrow. Only used on terminal frames. */
427 Lisp_Object Voverlay_arrow_string
;
429 /* Values of those variables at last redisplay are stored as
430 properties on `overlay-arrow-position' symbol. However, if
431 Voverlay_arrow_position is a marker, last-arrow-position is its
432 numerical position. */
434 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
436 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
437 properties on a symbol in overlay-arrow-variable-list. */
439 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
441 /* Like mode-line-format, but for the title bar on a visible frame. */
443 Lisp_Object Vframe_title_format
;
445 /* Like mode-line-format, but for the title bar on an iconified frame. */
447 Lisp_Object Vicon_title_format
;
449 /* List of functions to call when a window's size changes. These
450 functions get one arg, a frame on which one or more windows' sizes
453 static Lisp_Object Vwindow_size_change_functions
;
455 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
457 /* Nonzero if overlay arrow has been displayed once in this window. */
459 static int overlay_arrow_seen
;
461 /* Nonzero means highlight the region even in nonselected windows. */
463 int highlight_nonselected_windows
;
465 /* If cursor motion alone moves point off frame, try scrolling this
466 many lines up or down if that will bring it back. */
468 static EMACS_INT scroll_step
;
470 /* Nonzero means scroll just far enough to bring point back on the
471 screen, when appropriate. */
473 static EMACS_INT scroll_conservatively
;
475 /* Recenter the window whenever point gets within this many lines of
476 the top or bottom of the window. This value is translated into a
477 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
478 that there is really a fixed pixel height scroll margin. */
480 EMACS_INT scroll_margin
;
482 /* Number of windows showing the buffer of the selected window (or
483 another buffer with the same base buffer). keyboard.c refers to
488 /* Vector containing glyphs for an ellipsis `...'. */
490 static Lisp_Object default_invis_vector
[3];
492 /* Zero means display the mode-line/header-line/menu-bar in the default face
493 (this slightly odd definition is for compatibility with previous versions
494 of emacs), non-zero means display them using their respective faces.
496 This variable is deprecated. */
498 int mode_line_inverse_video
;
500 /* Prompt to display in front of the mini-buffer contents. */
502 Lisp_Object minibuf_prompt
;
504 /* Width of current mini-buffer prompt. Only set after display_line
505 of the line that contains the prompt. */
507 int minibuf_prompt_width
;
509 /* This is the window where the echo area message was displayed. It
510 is always a mini-buffer window, but it may not be the same window
511 currently active as a mini-buffer. */
513 Lisp_Object echo_area_window
;
515 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
516 pushes the current message and the value of
517 message_enable_multibyte on the stack, the function restore_message
518 pops the stack and displays MESSAGE again. */
520 Lisp_Object Vmessage_stack
;
522 /* Nonzero means multibyte characters were enabled when the echo area
523 message was specified. */
525 int message_enable_multibyte
;
527 /* Nonzero if we should redraw the mode lines on the next redisplay. */
529 int update_mode_lines
;
531 /* Nonzero if window sizes or contents have changed since last
532 redisplay that finished. */
534 int windows_or_buffers_changed
;
536 /* Nonzero means a frame's cursor type has been changed. */
538 int cursor_type_changed
;
540 /* Nonzero after display_mode_line if %l was used and it displayed a
543 int line_number_displayed
;
545 /* Maximum buffer size for which to display line numbers. */
547 Lisp_Object Vline_number_display_limit
;
549 /* Line width to consider when repositioning for line number display. */
551 static EMACS_INT line_number_display_limit_width
;
553 /* Number of lines to keep in the message log buffer. t means
554 infinite. nil means don't log at all. */
556 Lisp_Object Vmessage_log_max
;
558 /* The name of the *Messages* buffer, a string. */
560 static Lisp_Object Vmessages_buffer_name
;
562 /* Current, index 0, and last displayed echo area message. Either
563 buffers from echo_buffers, or nil to indicate no message. */
565 Lisp_Object echo_area_buffer
[2];
567 /* The buffers referenced from echo_area_buffer. */
569 static Lisp_Object echo_buffer
[2];
571 /* A vector saved used in with_area_buffer to reduce consing. */
573 static Lisp_Object Vwith_echo_area_save_vector
;
575 /* Non-zero means display_echo_area should display the last echo area
576 message again. Set by redisplay_preserve_echo_area. */
578 static int display_last_displayed_message_p
;
580 /* Nonzero if echo area is being used by print; zero if being used by
583 int message_buf_print
;
585 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
587 Lisp_Object Qinhibit_menubar_update
;
588 int inhibit_menubar_update
;
590 /* Maximum height for resizing mini-windows. Either a float
591 specifying a fraction of the available height, or an integer
592 specifying a number of lines. */
594 Lisp_Object Vmax_mini_window_height
;
596 /* Non-zero means messages should be displayed with truncated
597 lines instead of being continued. */
599 int message_truncate_lines
;
600 Lisp_Object Qmessage_truncate_lines
;
602 /* Set to 1 in clear_message to make redisplay_internal aware
603 of an emptied echo area. */
605 static int message_cleared_p
;
607 /* Non-zero means we want a hollow cursor in windows that are not
608 selected. Zero means there's no cursor in such windows. */
610 Lisp_Object Vcursor_in_non_selected_windows
;
611 Lisp_Object Qcursor_in_non_selected_windows
;
613 /* How to blink the default frame cursor off. */
614 Lisp_Object Vblink_cursor_alist
;
616 /* A scratch glyph row with contents used for generating truncation
617 glyphs. Also used in direct_output_for_insert. */
619 #define MAX_SCRATCH_GLYPHS 100
620 struct glyph_row scratch_glyph_row
;
621 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
623 /* Ascent and height of the last line processed by move_it_to. */
625 static int last_max_ascent
, last_height
;
627 /* Non-zero if there's a help-echo in the echo area. */
629 int help_echo_showing_p
;
631 /* If >= 0, computed, exact values of mode-line and header-line height
632 to use in the macros CURRENT_MODE_LINE_HEIGHT and
633 CURRENT_HEADER_LINE_HEIGHT. */
635 int current_mode_line_height
, current_header_line_height
;
637 /* The maximum distance to look ahead for text properties. Values
638 that are too small let us call compute_char_face and similar
639 functions too often which is expensive. Values that are too large
640 let us call compute_char_face and alike too often because we
641 might not be interested in text properties that far away. */
643 #define TEXT_PROP_DISTANCE_LIMIT 100
647 /* Variables to turn off display optimizations from Lisp. */
649 int inhibit_try_window_id
, inhibit_try_window_reusing
;
650 int inhibit_try_cursor_movement
;
652 /* Non-zero means print traces of redisplay if compiled with
655 int trace_redisplay_p
;
657 #endif /* GLYPH_DEBUG */
659 #ifdef DEBUG_TRACE_MOVE
660 /* Non-zero means trace with TRACE_MOVE to stderr. */
663 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
665 #define TRACE_MOVE(x) (void) 0
668 /* Non-zero means automatically scroll windows horizontally to make
671 int automatic_hscrolling_p
;
673 /* How close to the margin can point get before the window is scrolled
675 EMACS_INT hscroll_margin
;
677 /* How much to scroll horizontally when point is inside the above margin. */
678 Lisp_Object Vhscroll_step
;
680 /* The variable `resize-mini-windows'. If nil, don't resize
681 mini-windows. If t, always resize them to fit the text they
682 display. If `grow-only', let mini-windows grow only until they
685 Lisp_Object Vresize_mini_windows
;
687 /* Buffer being redisplayed -- for redisplay_window_error. */
689 struct buffer
*displayed_buffer
;
691 /* Value returned from text property handlers (see below). */
696 HANDLED_RECOMPUTE_PROPS
,
697 HANDLED_OVERLAY_STRING_CONSUMED
,
701 /* A description of text properties that redisplay is interested
706 /* The name of the property. */
709 /* A unique index for the property. */
712 /* A handler function called to set up iterator IT from the property
713 at IT's current position. Value is used to steer handle_stop. */
714 enum prop_handled (*handler
) P_ ((struct it
*it
));
717 static enum prop_handled handle_face_prop
P_ ((struct it
*));
718 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
719 static enum prop_handled handle_display_prop
P_ ((struct it
*));
720 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
721 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
722 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
724 /* Properties handled by iterators. */
726 static struct props it_props
[] =
728 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
729 /* Handle `face' before `display' because some sub-properties of
730 `display' need to know the face. */
731 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
732 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
733 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
734 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
738 /* Value is the position described by X. If X is a marker, value is
739 the marker_position of X. Otherwise, value is X. */
741 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
743 /* Enumeration returned by some move_it_.* functions internally. */
747 /* Not used. Undefined value. */
750 /* Move ended at the requested buffer position or ZV. */
751 MOVE_POS_MATCH_OR_ZV
,
753 /* Move ended at the requested X pixel position. */
756 /* Move within a line ended at the end of a line that must be
760 /* Move within a line ended at the end of a line that would
761 be displayed truncated. */
764 /* Move within a line ended at a line end. */
768 /* This counter is used to clear the face cache every once in a while
769 in redisplay_internal. It is incremented for each redisplay.
770 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
773 #define CLEAR_FACE_CACHE_COUNT 500
774 static int clear_face_cache_count
;
776 /* Non-zero while redisplay_internal is in progress. */
780 /* Non-zero means don't free realized faces. Bound while freeing
781 realized faces is dangerous because glyph matrices might still
784 int inhibit_free_realized_faces
;
785 Lisp_Object Qinhibit_free_realized_faces
;
787 /* If a string, XTread_socket generates an event to display that string.
788 (The display is done in read_char.) */
790 Lisp_Object help_echo_string
;
791 Lisp_Object help_echo_window
;
792 Lisp_Object help_echo_object
;
795 /* Temporary variable for XTread_socket. */
797 Lisp_Object previous_help_echo_string
;
799 /* Null glyph slice */
801 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
804 /* Function prototypes. */
806 static void setup_for_ellipsis
P_ ((struct it
*));
807 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
808 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
809 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
810 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
811 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
812 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
815 static int invisible_text_between_p
P_ ((struct it
*, int, int));
818 static int next_element_from_ellipsis
P_ ((struct it
*));
819 static void pint2str
P_ ((char *, int, int));
820 static void pint2hrstr
P_ ((char *, int, int));
821 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
823 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
824 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
825 static void store_frame_title_char
P_ ((char));
826 static int store_frame_title
P_ ((const unsigned char *, int, int));
827 static void x_consider_frame_title
P_ ((Lisp_Object
));
828 static void handle_stop
P_ ((struct it
*));
829 static int tool_bar_lines_needed
P_ ((struct frame
*));
830 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
831 static void ensure_echo_area_buffers
P_ ((void));
832 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
833 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
834 static int with_echo_area_buffer
P_ ((struct window
*, int,
835 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
836 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
837 static void clear_garbaged_frames
P_ ((void));
838 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
839 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
840 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
841 static int display_echo_area
P_ ((struct window
*));
842 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
843 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
844 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
845 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
846 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
848 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
849 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
850 static void insert_left_trunc_glyphs
P_ ((struct it
*));
851 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
853 static void extend_face_to_end_of_line
P_ ((struct it
*));
854 static int append_space_for_newline
P_ ((struct it
*, int));
855 static int make_cursor_line_fully_visible
P_ ((struct window
*, int));
856 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
857 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
858 static int trailing_whitespace_p
P_ ((int));
859 static int message_log_check_duplicate
P_ ((int, int, int, int));
860 static void push_it
P_ ((struct it
*));
861 static void pop_it
P_ ((struct it
*));
862 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
863 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
864 static void redisplay_internal
P_ ((int));
865 static int echo_area_display
P_ ((int));
866 static void redisplay_windows
P_ ((Lisp_Object
));
867 static void redisplay_window
P_ ((Lisp_Object
, int));
868 static Lisp_Object
redisplay_window_error ();
869 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
870 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
871 static void update_menu_bar
P_ ((struct frame
*, int));
872 static int try_window_reusing_current_matrix
P_ ((struct window
*));
873 static int try_window_id
P_ ((struct window
*));
874 static int display_line
P_ ((struct it
*));
875 static int display_mode_lines
P_ ((struct window
*));
876 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
877 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
878 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
879 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
880 static void display_menu_bar
P_ ((struct window
*));
881 static int display_count_lines
P_ ((int, int, int, int, int *));
882 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
883 int, int, struct it
*, int, int, int, int));
884 static void compute_line_metrics
P_ ((struct it
*));
885 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
886 static int get_overlay_strings
P_ ((struct it
*, int));
887 static void next_overlay_string
P_ ((struct it
*));
888 static void reseat
P_ ((struct it
*, struct text_pos
, int));
889 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
890 static void back_to_previous_visible_line_start
P_ ((struct it
*));
891 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
892 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
893 static int next_element_from_display_vector
P_ ((struct it
*));
894 static int next_element_from_string
P_ ((struct it
*));
895 static int next_element_from_c_string
P_ ((struct it
*));
896 static int next_element_from_buffer
P_ ((struct it
*));
897 static int next_element_from_composition
P_ ((struct it
*));
898 static int next_element_from_image
P_ ((struct it
*));
899 static int next_element_from_stretch
P_ ((struct it
*));
900 static void load_overlay_strings
P_ ((struct it
*, int));
901 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
902 struct display_pos
*));
903 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
904 Lisp_Object
, int, int, int, int));
905 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
907 void move_it_vertically_backward
P_ ((struct it
*, int));
908 static void init_to_row_start
P_ ((struct it
*, struct window
*,
909 struct glyph_row
*));
910 static int init_to_row_end
P_ ((struct it
*, struct window
*,
911 struct glyph_row
*));
912 static void back_to_previous_line_start
P_ ((struct it
*));
913 static int forward_to_next_line_start
P_ ((struct it
*, int *));
914 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
916 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
917 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
918 static int number_of_chars
P_ ((unsigned char *, int));
919 static void compute_stop_pos
P_ ((struct it
*));
920 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
922 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
923 static int next_overlay_change
P_ ((int));
924 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
925 Lisp_Object
, struct text_pos
*,
927 static int underlying_face_id
P_ ((struct it
*));
928 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
931 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
932 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
934 #ifdef HAVE_WINDOW_SYSTEM
936 static void update_tool_bar
P_ ((struct frame
*, int));
937 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
938 static int redisplay_tool_bar
P_ ((struct frame
*));
939 static void display_tool_bar_line
P_ ((struct it
*));
940 static void notice_overwritten_cursor
P_ ((struct window
*,
942 int, int, int, int));
946 #endif /* HAVE_WINDOW_SYSTEM */
949 /***********************************************************************
950 Window display dimensions
951 ***********************************************************************/
953 /* Return the bottom boundary y-position for text lines in window W.
954 This is the first y position at which a line cannot start.
955 It is relative to the top of the window.
957 This is the height of W minus the height of a mode line, if any. */
960 window_text_bottom_y (w
)
963 int height
= WINDOW_TOTAL_HEIGHT (w
);
965 if (WINDOW_WANTS_MODELINE_P (w
))
966 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
970 /* Return the pixel width of display area AREA of window W. AREA < 0
971 means return the total width of W, not including fringes to
972 the left and right of the window. */
975 window_box_width (w
, area
)
979 int cols
= XFASTINT (w
->total_cols
);
982 if (!w
->pseudo_window_p
)
984 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
986 if (area
== TEXT_AREA
)
988 if (INTEGERP (w
->left_margin_cols
))
989 cols
-= XFASTINT (w
->left_margin_cols
);
990 if (INTEGERP (w
->right_margin_cols
))
991 cols
-= XFASTINT (w
->right_margin_cols
);
992 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
994 else if (area
== LEFT_MARGIN_AREA
)
996 cols
= (INTEGERP (w
->left_margin_cols
)
997 ? XFASTINT (w
->left_margin_cols
) : 0);
1000 else if (area
== RIGHT_MARGIN_AREA
)
1002 cols
= (INTEGERP (w
->right_margin_cols
)
1003 ? XFASTINT (w
->right_margin_cols
) : 0);
1008 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1012 /* Return the pixel height of the display area of window W, not
1013 including mode lines of W, if any. */
1016 window_box_height (w
)
1019 struct frame
*f
= XFRAME (w
->frame
);
1020 int height
= WINDOW_TOTAL_HEIGHT (w
);
1022 xassert (height
>= 0);
1024 /* Note: the code below that determines the mode-line/header-line
1025 height is essentially the same as that contained in the macro
1026 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1027 the appropriate glyph row has its `mode_line_p' flag set,
1028 and if it doesn't, uses estimate_mode_line_height instead. */
1030 if (WINDOW_WANTS_MODELINE_P (w
))
1032 struct glyph_row
*ml_row
1033 = (w
->current_matrix
&& w
->current_matrix
->rows
1034 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1036 if (ml_row
&& ml_row
->mode_line_p
)
1037 height
-= ml_row
->height
;
1039 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1042 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1044 struct glyph_row
*hl_row
1045 = (w
->current_matrix
&& w
->current_matrix
->rows
1046 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1048 if (hl_row
&& hl_row
->mode_line_p
)
1049 height
-= hl_row
->height
;
1051 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1054 /* With a very small font and a mode-line that's taller than
1055 default, we might end up with a negative height. */
1056 return max (0, height
);
1059 /* Return the window-relative coordinate of the left edge of display
1060 area AREA of window W. AREA < 0 means return the left edge of the
1061 whole window, to the right of the left fringe of W. */
1064 window_box_left_offset (w
, area
)
1070 if (w
->pseudo_window_p
)
1073 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1075 if (area
== TEXT_AREA
)
1076 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1077 + window_box_width (w
, LEFT_MARGIN_AREA
));
1078 else if (area
== RIGHT_MARGIN_AREA
)
1079 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1080 + window_box_width (w
, LEFT_MARGIN_AREA
)
1081 + window_box_width (w
, TEXT_AREA
)
1082 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1084 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1085 else if (area
== LEFT_MARGIN_AREA
1086 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1087 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1093 /* Return the window-relative coordinate of the right edge of display
1094 area AREA of window W. AREA < 0 means return the left edge of the
1095 whole window, to the left of the right fringe of W. */
1098 window_box_right_offset (w
, area
)
1102 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1105 /* Return the frame-relative coordinate of the left edge of display
1106 area AREA of window W. AREA < 0 means return the left edge of the
1107 whole window, to the right of the left fringe of W. */
1110 window_box_left (w
, area
)
1114 struct frame
*f
= XFRAME (w
->frame
);
1117 if (w
->pseudo_window_p
)
1118 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1120 x
= (WINDOW_LEFT_EDGE_X (w
)
1121 + window_box_left_offset (w
, area
));
1127 /* Return the frame-relative coordinate of the right edge of display
1128 area AREA of window W. AREA < 0 means return the left edge of the
1129 whole window, to the left of the right fringe of W. */
1132 window_box_right (w
, area
)
1136 return window_box_left (w
, area
) + window_box_width (w
, area
);
1139 /* Get the bounding box of the display area AREA of window W, without
1140 mode lines, in frame-relative coordinates. AREA < 0 means the
1141 whole window, not including the left and right fringes of
1142 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1143 coordinates of the upper-left corner of the box. Return in
1144 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1147 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1150 int *box_x
, *box_y
, *box_width
, *box_height
;
1153 *box_width
= window_box_width (w
, area
);
1155 *box_height
= window_box_height (w
);
1157 *box_x
= window_box_left (w
, area
);
1160 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1161 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1162 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1167 /* Get the bounding box of the display area AREA of window W, without
1168 mode lines. AREA < 0 means the whole window, not including the
1169 left and right fringe of the window. Return in *TOP_LEFT_X
1170 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1171 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1172 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1176 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1177 bottom_right_x
, bottom_right_y
)
1180 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1182 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1184 *bottom_right_x
+= *top_left_x
;
1185 *bottom_right_y
+= *top_left_y
;
1190 /***********************************************************************
1192 ***********************************************************************/
1194 /* Return the bottom y-position of the line the iterator IT is in.
1195 This can modify IT's settings. */
1201 int line_height
= it
->max_ascent
+ it
->max_descent
;
1202 int line_top_y
= it
->current_y
;
1204 if (line_height
== 0)
1207 line_height
= last_height
;
1208 else if (IT_CHARPOS (*it
) < ZV
)
1210 move_it_by_lines (it
, 1, 1);
1211 line_height
= (it
->max_ascent
|| it
->max_descent
1212 ? it
->max_ascent
+ it
->max_descent
1217 struct glyph_row
*row
= it
->glyph_row
;
1219 /* Use the default character height. */
1220 it
->glyph_row
= NULL
;
1221 it
->what
= IT_CHARACTER
;
1224 PRODUCE_GLYPHS (it
);
1225 line_height
= it
->ascent
+ it
->descent
;
1226 it
->glyph_row
= row
;
1230 return line_top_y
+ line_height
;
1234 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1235 1 if POS is visible and the line containing POS is fully visible.
1236 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1237 and header-lines heights. */
1240 pos_visible_p (w
, charpos
, fully
, x
, y
, exact_mode_line_heights_p
)
1242 int charpos
, *fully
, *x
, *y
, exact_mode_line_heights_p
;
1245 struct text_pos top
;
1247 struct buffer
*old_buffer
= NULL
;
1249 if (XBUFFER (w
->buffer
) != current_buffer
)
1251 old_buffer
= current_buffer
;
1252 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1255 *fully
= visible_p
= 0;
1256 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1258 /* Compute exact mode line heights, if requested. */
1259 if (exact_mode_line_heights_p
)
1261 if (WINDOW_WANTS_MODELINE_P (w
))
1262 current_mode_line_height
1263 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1264 current_buffer
->mode_line_format
);
1266 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1267 current_header_line_height
1268 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1269 current_buffer
->header_line_format
);
1272 start_display (&it
, w
, top
);
1273 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1274 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1276 /* Note that we may overshoot because of invisible text. */
1277 if (IT_CHARPOS (it
) >= charpos
)
1279 int top_y
= it
.current_y
;
1280 int bottom_y
= line_bottom_y (&it
);
1281 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1283 if (top_y
< window_top_y
)
1284 visible_p
= bottom_y
> window_top_y
;
1285 else if (top_y
< it
.last_visible_y
)
1288 *fully
= bottom_y
<= it
.last_visible_y
;
1293 *y
= max (top_y
+ it
.max_ascent
- it
.ascent
, window_top_y
);
1296 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1301 move_it_by_lines (&it
, 1, 0);
1302 if (charpos
< IT_CHARPOS (it
))
1307 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1309 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1315 set_buffer_internal_1 (old_buffer
);
1317 current_header_line_height
= current_mode_line_height
= -1;
1323 /* Return the next character from STR which is MAXLEN bytes long.
1324 Return in *LEN the length of the character. This is like
1325 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1326 we find one, we return a `?', but with the length of the invalid
1330 string_char_and_length (str
, maxlen
, len
)
1331 const unsigned char *str
;
1336 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1337 if (!CHAR_VALID_P (c
, 1))
1338 /* We may not change the length here because other places in Emacs
1339 don't use this function, i.e. they silently accept invalid
1348 /* Given a position POS containing a valid character and byte position
1349 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1351 static struct text_pos
1352 string_pos_nchars_ahead (pos
, string
, nchars
)
1353 struct text_pos pos
;
1357 xassert (STRINGP (string
) && nchars
>= 0);
1359 if (STRING_MULTIBYTE (string
))
1361 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1362 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1367 string_char_and_length (p
, rest
, &len
);
1368 p
+= len
, rest
-= len
;
1369 xassert (rest
>= 0);
1371 BYTEPOS (pos
) += len
;
1375 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1381 /* Value is the text position, i.e. character and byte position,
1382 for character position CHARPOS in STRING. */
1384 static INLINE
struct text_pos
1385 string_pos (charpos
, string
)
1389 struct text_pos pos
;
1390 xassert (STRINGP (string
));
1391 xassert (charpos
>= 0);
1392 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1397 /* Value is a text position, i.e. character and byte position, for
1398 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1399 means recognize multibyte characters. */
1401 static struct text_pos
1402 c_string_pos (charpos
, s
, multibyte_p
)
1407 struct text_pos pos
;
1409 xassert (s
!= NULL
);
1410 xassert (charpos
>= 0);
1414 int rest
= strlen (s
), len
;
1416 SET_TEXT_POS (pos
, 0, 0);
1419 string_char_and_length (s
, rest
, &len
);
1420 s
+= len
, rest
-= len
;
1421 xassert (rest
>= 0);
1423 BYTEPOS (pos
) += len
;
1427 SET_TEXT_POS (pos
, charpos
, charpos
);
1433 /* Value is the number of characters in C string S. MULTIBYTE_P
1434 non-zero means recognize multibyte characters. */
1437 number_of_chars (s
, multibyte_p
)
1445 int rest
= strlen (s
), len
;
1446 unsigned char *p
= (unsigned char *) s
;
1448 for (nchars
= 0; rest
> 0; ++nchars
)
1450 string_char_and_length (p
, rest
, &len
);
1451 rest
-= len
, p
+= len
;
1455 nchars
= strlen (s
);
1461 /* Compute byte position NEWPOS->bytepos corresponding to
1462 NEWPOS->charpos. POS is a known position in string STRING.
1463 NEWPOS->charpos must be >= POS.charpos. */
1466 compute_string_pos (newpos
, pos
, string
)
1467 struct text_pos
*newpos
, pos
;
1470 xassert (STRINGP (string
));
1471 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1473 if (STRING_MULTIBYTE (string
))
1474 *newpos
= string_pos_nchars_ahead (pos
, string
,
1475 CHARPOS (*newpos
) - CHARPOS (pos
));
1477 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1481 Return an estimation of the pixel height of mode or top lines on
1482 frame F. FACE_ID specifies what line's height to estimate. */
1485 estimate_mode_line_height (f
, face_id
)
1487 enum face_id face_id
;
1489 #ifdef HAVE_WINDOW_SYSTEM
1490 if (FRAME_WINDOW_P (f
))
1492 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1494 /* This function is called so early when Emacs starts that the face
1495 cache and mode line face are not yet initialized. */
1496 if (FRAME_FACE_CACHE (f
))
1498 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1502 height
= FONT_HEIGHT (face
->font
);
1503 if (face
->box_line_width
> 0)
1504 height
+= 2 * face
->box_line_width
;
1515 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1516 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1517 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1518 not force the value into range. */
1521 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1523 register int pix_x
, pix_y
;
1525 NativeRectangle
*bounds
;
1529 #ifdef HAVE_WINDOW_SYSTEM
1530 if (FRAME_WINDOW_P (f
))
1532 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1533 even for negative values. */
1535 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1537 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1539 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1540 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1543 STORE_NATIVE_RECT (*bounds
,
1544 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1545 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1546 FRAME_COLUMN_WIDTH (f
) - 1,
1547 FRAME_LINE_HEIGHT (f
) - 1);
1553 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1554 pix_x
= FRAME_TOTAL_COLS (f
);
1558 else if (pix_y
> FRAME_LINES (f
))
1559 pix_y
= FRAME_LINES (f
);
1569 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1570 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1571 can't tell the positions because W's display is not up to date,
1575 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1578 int *frame_x
, *frame_y
;
1580 #ifdef HAVE_WINDOW_SYSTEM
1581 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1585 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1586 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1588 if (display_completed
)
1590 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1591 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1592 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1598 hpos
+= glyph
->pixel_width
;
1602 /* If first glyph is partially visible, its first visible position is still 0. */
1614 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1615 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1626 #ifdef HAVE_WINDOW_SYSTEM
1628 /* Find the glyph under window-relative coordinates X/Y in window W.
1629 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1630 strings. Return in *HPOS and *VPOS the row and column number of
1631 the glyph found. Return in *AREA the glyph area containing X.
1632 Value is a pointer to the glyph found or null if X/Y is not on
1633 text, or we can't tell because W's current matrix is not up to
1636 static struct glyph
*
1637 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1640 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1642 struct glyph
*glyph
, *end
;
1643 struct glyph_row
*row
= NULL
;
1646 /* Find row containing Y. Give up if some row is not enabled. */
1647 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1649 row
= MATRIX_ROW (w
->current_matrix
, i
);
1650 if (!row
->enabled_p
)
1652 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1659 /* Give up if Y is not in the window. */
1660 if (i
== w
->current_matrix
->nrows
)
1663 /* Get the glyph area containing X. */
1664 if (w
->pseudo_window_p
)
1671 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1673 *area
= LEFT_MARGIN_AREA
;
1674 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1676 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1679 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1683 *area
= RIGHT_MARGIN_AREA
;
1684 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1688 /* Find glyph containing X. */
1689 glyph
= row
->glyphs
[*area
];
1690 end
= glyph
+ row
->used
[*area
];
1692 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1694 x
-= glyph
->pixel_width
;
1704 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1707 *hpos
= glyph
- row
->glyphs
[*area
];
1713 Convert frame-relative x/y to coordinates relative to window W.
1714 Takes pseudo-windows into account. */
1717 frame_to_window_pixel_xy (w
, x
, y
)
1721 if (w
->pseudo_window_p
)
1723 /* A pseudo-window is always full-width, and starts at the
1724 left edge of the frame, plus a frame border. */
1725 struct frame
*f
= XFRAME (w
->frame
);
1726 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1727 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1731 *x
-= WINDOW_LEFT_EDGE_X (w
);
1732 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1737 Return in *R the clipping rectangle for glyph string S. */
1740 get_glyph_string_clip_rect (s
, nr
)
1741 struct glyph_string
*s
;
1742 NativeRectangle
*nr
;
1746 if (s
->row
->full_width_p
)
1748 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1749 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1750 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1752 /* Unless displaying a mode or menu bar line, which are always
1753 fully visible, clip to the visible part of the row. */
1754 if (s
->w
->pseudo_window_p
)
1755 r
.height
= s
->row
->visible_height
;
1757 r
.height
= s
->height
;
1761 /* This is a text line that may be partially visible. */
1762 r
.x
= window_box_left (s
->w
, s
->area
);
1763 r
.width
= window_box_width (s
->w
, s
->area
);
1764 r
.height
= s
->row
->visible_height
;
1767 /* If S draws overlapping rows, it's sufficient to use the top and
1768 bottom of the window for clipping because this glyph string
1769 intentionally draws over other lines. */
1770 if (s
->for_overlaps_p
)
1772 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1773 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1777 /* Don't use S->y for clipping because it doesn't take partially
1778 visible lines into account. For example, it can be negative for
1779 partially visible lines at the top of a window. */
1780 if (!s
->row
->full_width_p
1781 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1782 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1784 r
.y
= max (0, s
->row
->y
);
1786 /* If drawing a tool-bar window, draw it over the internal border
1787 at the top of the window. */
1788 if (WINDOWP (s
->f
->tool_bar_window
)
1789 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1790 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1793 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1795 /* If drawing the cursor, don't let glyph draw outside its
1796 advertised boundaries. Cleartype does this under some circumstances. */
1797 if (s
->hl
== DRAW_CURSOR
)
1799 struct glyph
*glyph
= s
->first_glyph
;
1804 r
.width
-= s
->x
- r
.x
;
1807 r
.width
= min (r
.width
, glyph
->pixel_width
);
1809 /* Don't draw cursor glyph taller than our actual glyph. */
1810 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1811 if (height
< r
.height
)
1813 int max_y
= r
.y
+ r
.height
;
1814 r
.y
= min (max_y
, s
->ybase
+ glyph
->descent
- height
);
1815 r
.height
= min (max_y
- r
.y
, height
);
1819 #ifdef CONVERT_FROM_XRECT
1820 CONVERT_FROM_XRECT (r
, *nr
);
1826 #endif /* HAVE_WINDOW_SYSTEM */
1829 /***********************************************************************
1830 Lisp form evaluation
1831 ***********************************************************************/
1833 /* Error handler for safe_eval and safe_call. */
1836 safe_eval_handler (arg
)
1839 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1844 /* Evaluate SEXPR and return the result, or nil if something went
1845 wrong. Prevent redisplay during the evaluation. */
1853 if (inhibit_eval_during_redisplay
)
1857 int count
= SPECPDL_INDEX ();
1858 struct gcpro gcpro1
;
1861 specbind (Qinhibit_redisplay
, Qt
);
1862 /* Use Qt to ensure debugger does not run,
1863 so there is no possibility of wanting to redisplay. */
1864 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1867 val
= unbind_to (count
, val
);
1874 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1875 Return the result, or nil if something went wrong. Prevent
1876 redisplay during the evaluation. */
1879 safe_call (nargs
, args
)
1885 if (inhibit_eval_during_redisplay
)
1889 int count
= SPECPDL_INDEX ();
1890 struct gcpro gcpro1
;
1893 gcpro1
.nvars
= nargs
;
1894 specbind (Qinhibit_redisplay
, Qt
);
1895 /* Use Qt to ensure debugger does not run,
1896 so there is no possibility of wanting to redisplay. */
1897 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1900 val
= unbind_to (count
, val
);
1907 /* Call function FN with one argument ARG.
1908 Return the result, or nil if something went wrong. */
1911 safe_call1 (fn
, arg
)
1912 Lisp_Object fn
, arg
;
1914 Lisp_Object args
[2];
1917 return safe_call (2, args
);
1922 /***********************************************************************
1924 ***********************************************************************/
1928 /* Define CHECK_IT to perform sanity checks on iterators.
1929 This is for debugging. It is too slow to do unconditionally. */
1935 if (it
->method
== next_element_from_string
)
1937 xassert (STRINGP (it
->string
));
1938 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1942 xassert (IT_STRING_CHARPOS (*it
) < 0);
1943 if (it
->method
== next_element_from_buffer
)
1945 /* Check that character and byte positions agree. */
1946 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1951 xassert (it
->current
.dpvec_index
>= 0);
1953 xassert (it
->current
.dpvec_index
< 0);
1956 #define CHECK_IT(IT) check_it ((IT))
1960 #define CHECK_IT(IT) (void) 0
1967 /* Check that the window end of window W is what we expect it
1968 to be---the last row in the current matrix displaying text. */
1971 check_window_end (w
)
1974 if (!MINI_WINDOW_P (w
)
1975 && !NILP (w
->window_end_valid
))
1977 struct glyph_row
*row
;
1978 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1979 XFASTINT (w
->window_end_vpos
)),
1981 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1982 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1986 #define CHECK_WINDOW_END(W) check_window_end ((W))
1988 #else /* not GLYPH_DEBUG */
1990 #define CHECK_WINDOW_END(W) (void) 0
1992 #endif /* not GLYPH_DEBUG */
1996 /***********************************************************************
1997 Iterator initialization
1998 ***********************************************************************/
2000 /* Initialize IT for displaying current_buffer in window W, starting
2001 at character position CHARPOS. CHARPOS < 0 means that no buffer
2002 position is specified which is useful when the iterator is assigned
2003 a position later. BYTEPOS is the byte position corresponding to
2004 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2006 If ROW is not null, calls to produce_glyphs with IT as parameter
2007 will produce glyphs in that row.
2009 BASE_FACE_ID is the id of a base face to use. It must be one of
2010 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2011 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2012 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2014 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2015 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2016 will be initialized to use the corresponding mode line glyph row of
2017 the desired matrix of W. */
2020 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2023 int charpos
, bytepos
;
2024 struct glyph_row
*row
;
2025 enum face_id base_face_id
;
2027 int highlight_region_p
;
2029 /* Some precondition checks. */
2030 xassert (w
!= NULL
&& it
!= NULL
);
2031 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2034 /* If face attributes have been changed since the last redisplay,
2035 free realized faces now because they depend on face definitions
2036 that might have changed. Don't free faces while there might be
2037 desired matrices pending which reference these faces. */
2038 if (face_change_count
&& !inhibit_free_realized_faces
)
2040 face_change_count
= 0;
2041 free_all_realized_faces (Qnil
);
2044 /* Use one of the mode line rows of W's desired matrix if
2048 if (base_face_id
== MODE_LINE_FACE_ID
2049 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2050 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2051 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2052 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2056 bzero (it
, sizeof *it
);
2057 it
->current
.overlay_string_index
= -1;
2058 it
->current
.dpvec_index
= -1;
2059 it
->base_face_id
= base_face_id
;
2061 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2063 /* The window in which we iterate over current_buffer: */
2064 XSETWINDOW (it
->window
, w
);
2066 it
->f
= XFRAME (w
->frame
);
2068 /* Extra space between lines (on window systems only). */
2069 if (base_face_id
== DEFAULT_FACE_ID
2070 && FRAME_WINDOW_P (it
->f
))
2072 if (NATNUMP (current_buffer
->extra_line_spacing
))
2073 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2074 else if (FLOATP (current_buffer
->extra_line_spacing
))
2075 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2076 * FRAME_LINE_HEIGHT (it
->f
));
2077 else if (it
->f
->extra_line_spacing
> 0)
2078 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2079 it
->max_extra_line_spacing
= 0;
2082 /* If realized faces have been removed, e.g. because of face
2083 attribute changes of named faces, recompute them. When running
2084 in batch mode, the face cache of the initial frame is null. If
2085 we happen to get called, make a dummy face cache. */
2086 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2087 init_frame_faces (it
->f
);
2088 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2089 recompute_basic_faces (it
->f
);
2091 /* Current value of the `slice', `space-width', and 'height' properties. */
2092 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2093 it
->space_width
= Qnil
;
2094 it
->font_height
= Qnil
;
2095 it
->override_ascent
= -1;
2097 /* Are control characters displayed as `^C'? */
2098 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2100 /* -1 means everything between a CR and the following line end
2101 is invisible. >0 means lines indented more than this value are
2103 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2104 ? XFASTINT (current_buffer
->selective_display
)
2105 : (!NILP (current_buffer
->selective_display
)
2107 it
->selective_display_ellipsis_p
2108 = !NILP (current_buffer
->selective_display_ellipses
);
2110 /* Display table to use. */
2111 it
->dp
= window_display_table (w
);
2113 /* Are multibyte characters enabled in current_buffer? */
2114 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2116 /* Non-zero if we should highlight the region. */
2118 = (!NILP (Vtransient_mark_mode
)
2119 && !NILP (current_buffer
->mark_active
)
2120 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2122 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2123 start and end of a visible region in window IT->w. Set both to
2124 -1 to indicate no region. */
2125 if (highlight_region_p
2126 /* Maybe highlight only in selected window. */
2127 && (/* Either show region everywhere. */
2128 highlight_nonselected_windows
2129 /* Or show region in the selected window. */
2130 || w
== XWINDOW (selected_window
)
2131 /* Or show the region if we are in the mini-buffer and W is
2132 the window the mini-buffer refers to. */
2133 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2134 && WINDOWP (minibuf_selected_window
)
2135 && w
== XWINDOW (minibuf_selected_window
))))
2137 int charpos
= marker_position (current_buffer
->mark
);
2138 it
->region_beg_charpos
= min (PT
, charpos
);
2139 it
->region_end_charpos
= max (PT
, charpos
);
2142 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2144 /* Get the position at which the redisplay_end_trigger hook should
2145 be run, if it is to be run at all. */
2146 if (MARKERP (w
->redisplay_end_trigger
)
2147 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2148 it
->redisplay_end_trigger_charpos
2149 = marker_position (w
->redisplay_end_trigger
);
2150 else if (INTEGERP (w
->redisplay_end_trigger
))
2151 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2153 /* Correct bogus values of tab_width. */
2154 it
->tab_width
= XINT (current_buffer
->tab_width
);
2155 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2158 /* Are lines in the display truncated? */
2159 it
->truncate_lines_p
2160 = (base_face_id
!= DEFAULT_FACE_ID
2161 || XINT (it
->w
->hscroll
)
2162 || (truncate_partial_width_windows
2163 && !WINDOW_FULL_WIDTH_P (it
->w
))
2164 || !NILP (current_buffer
->truncate_lines
));
2166 /* Get dimensions of truncation and continuation glyphs. These are
2167 displayed as fringe bitmaps under X, so we don't need them for such
2169 if (!FRAME_WINDOW_P (it
->f
))
2171 if (it
->truncate_lines_p
)
2173 /* We will need the truncation glyph. */
2174 xassert (it
->glyph_row
== NULL
);
2175 produce_special_glyphs (it
, IT_TRUNCATION
);
2176 it
->truncation_pixel_width
= it
->pixel_width
;
2180 /* We will need the continuation glyph. */
2181 xassert (it
->glyph_row
== NULL
);
2182 produce_special_glyphs (it
, IT_CONTINUATION
);
2183 it
->continuation_pixel_width
= it
->pixel_width
;
2186 /* Reset these values to zero because the produce_special_glyphs
2187 above has changed them. */
2188 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2189 it
->phys_ascent
= it
->phys_descent
= 0;
2192 /* Set this after getting the dimensions of truncation and
2193 continuation glyphs, so that we don't produce glyphs when calling
2194 produce_special_glyphs, above. */
2195 it
->glyph_row
= row
;
2196 it
->area
= TEXT_AREA
;
2198 /* Get the dimensions of the display area. The display area
2199 consists of the visible window area plus a horizontally scrolled
2200 part to the left of the window. All x-values are relative to the
2201 start of this total display area. */
2202 if (base_face_id
!= DEFAULT_FACE_ID
)
2204 /* Mode lines, menu bar in terminal frames. */
2205 it
->first_visible_x
= 0;
2206 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2211 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2212 it
->last_visible_x
= (it
->first_visible_x
2213 + window_box_width (w
, TEXT_AREA
));
2215 /* If we truncate lines, leave room for the truncator glyph(s) at
2216 the right margin. Otherwise, leave room for the continuation
2217 glyph(s). Truncation and continuation glyphs are not inserted
2218 for window-based redisplay. */
2219 if (!FRAME_WINDOW_P (it
->f
))
2221 if (it
->truncate_lines_p
)
2222 it
->last_visible_x
-= it
->truncation_pixel_width
;
2224 it
->last_visible_x
-= it
->continuation_pixel_width
;
2227 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2228 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2231 /* Leave room for a border glyph. */
2232 if (!FRAME_WINDOW_P (it
->f
)
2233 && !WINDOW_RIGHTMOST_P (it
->w
))
2234 it
->last_visible_x
-= 1;
2236 it
->last_visible_y
= window_text_bottom_y (w
);
2238 /* For mode lines and alike, arrange for the first glyph having a
2239 left box line if the face specifies a box. */
2240 if (base_face_id
!= DEFAULT_FACE_ID
)
2244 it
->face_id
= base_face_id
;
2246 /* If we have a boxed mode line, make the first character appear
2247 with a left box line. */
2248 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2249 if (face
->box
!= FACE_NO_BOX
)
2250 it
->start_of_box_run_p
= 1;
2253 /* If a buffer position was specified, set the iterator there,
2254 getting overlays and face properties from that position. */
2255 if (charpos
>= BUF_BEG (current_buffer
))
2257 it
->end_charpos
= ZV
;
2259 IT_CHARPOS (*it
) = charpos
;
2261 /* Compute byte position if not specified. */
2262 if (bytepos
< charpos
)
2263 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2265 IT_BYTEPOS (*it
) = bytepos
;
2267 it
->start
= it
->current
;
2269 /* Compute faces etc. */
2270 reseat (it
, it
->current
.pos
, 1);
2277 /* Initialize IT for the display of window W with window start POS. */
2280 start_display (it
, w
, pos
)
2283 struct text_pos pos
;
2285 struct glyph_row
*row
;
2286 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2288 row
= w
->desired_matrix
->rows
+ first_vpos
;
2289 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2290 it
->first_vpos
= first_vpos
;
2292 if (!it
->truncate_lines_p
)
2294 int start_at_line_beg_p
;
2295 int first_y
= it
->current_y
;
2297 /* If window start is not at a line start, skip forward to POS to
2298 get the correct continuation lines width. */
2299 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2300 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2301 if (!start_at_line_beg_p
)
2305 reseat_at_previous_visible_line_start (it
);
2306 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2308 new_x
= it
->current_x
+ it
->pixel_width
;
2310 /* If lines are continued, this line may end in the middle
2311 of a multi-glyph character (e.g. a control character
2312 displayed as \003, or in the middle of an overlay
2313 string). In this case move_it_to above will not have
2314 taken us to the start of the continuation line but to the
2315 end of the continued line. */
2316 if (it
->current_x
> 0
2317 && !it
->truncate_lines_p
/* Lines are continued. */
2318 && (/* And glyph doesn't fit on the line. */
2319 new_x
> it
->last_visible_x
2320 /* Or it fits exactly and we're on a window
2322 || (new_x
== it
->last_visible_x
2323 && FRAME_WINDOW_P (it
->f
))))
2325 if (it
->current
.dpvec_index
>= 0
2326 || it
->current
.overlay_string_index
>= 0)
2328 set_iterator_to_next (it
, 1);
2329 move_it_in_display_line_to (it
, -1, -1, 0);
2332 it
->continuation_lines_width
+= it
->current_x
;
2335 /* We're starting a new display line, not affected by the
2336 height of the continued line, so clear the appropriate
2337 fields in the iterator structure. */
2338 it
->max_ascent
= it
->max_descent
= 0;
2339 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2341 it
->current_y
= first_y
;
2343 it
->current_x
= it
->hpos
= 0;
2347 #if 0 /* Don't assert the following because start_display is sometimes
2348 called intentionally with a window start that is not at a
2349 line start. Please leave this code in as a comment. */
2351 /* Window start should be on a line start, now. */
2352 xassert (it
->continuation_lines_width
2353 || IT_CHARPOS (it
) == BEGV
2354 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2359 /* Return 1 if POS is a position in ellipses displayed for invisible
2360 text. W is the window we display, for text property lookup. */
2363 in_ellipses_for_invisible_text_p (pos
, w
)
2364 struct display_pos
*pos
;
2367 Lisp_Object prop
, window
;
2369 int charpos
= CHARPOS (pos
->pos
);
2371 /* If POS specifies a position in a display vector, this might
2372 be for an ellipsis displayed for invisible text. We won't
2373 get the iterator set up for delivering that ellipsis unless
2374 we make sure that it gets aware of the invisible text. */
2375 if (pos
->dpvec_index
>= 0
2376 && pos
->overlay_string_index
< 0
2377 && CHARPOS (pos
->string_pos
) < 0
2379 && (XSETWINDOW (window
, w
),
2380 prop
= Fget_char_property (make_number (charpos
),
2381 Qinvisible
, window
),
2382 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2384 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2386 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2393 /* Initialize IT for stepping through current_buffer in window W,
2394 starting at position POS that includes overlay string and display
2395 vector/ control character translation position information. Value
2396 is zero if there are overlay strings with newlines at POS. */
2399 init_from_display_pos (it
, w
, pos
)
2402 struct display_pos
*pos
;
2404 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2405 int i
, overlay_strings_with_newlines
= 0;
2407 /* If POS specifies a position in a display vector, this might
2408 be for an ellipsis displayed for invisible text. We won't
2409 get the iterator set up for delivering that ellipsis unless
2410 we make sure that it gets aware of the invisible text. */
2411 if (in_ellipses_for_invisible_text_p (pos
, w
))
2417 /* Keep in mind: the call to reseat in init_iterator skips invisible
2418 text, so we might end up at a position different from POS. This
2419 is only a problem when POS is a row start after a newline and an
2420 overlay starts there with an after-string, and the overlay has an
2421 invisible property. Since we don't skip invisible text in
2422 display_line and elsewhere immediately after consuming the
2423 newline before the row start, such a POS will not be in a string,
2424 but the call to init_iterator below will move us to the
2426 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2428 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2430 const char *s
= SDATA (it
->overlay_strings
[i
]);
2431 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2433 while (s
< e
&& *s
!= '\n')
2438 overlay_strings_with_newlines
= 1;
2443 /* If position is within an overlay string, set up IT to the right
2445 if (pos
->overlay_string_index
>= 0)
2449 /* If the first overlay string happens to have a `display'
2450 property for an image, the iterator will be set up for that
2451 image, and we have to undo that setup first before we can
2452 correct the overlay string index. */
2453 if (it
->method
== next_element_from_image
)
2456 /* We already have the first chunk of overlay strings in
2457 IT->overlay_strings. Load more until the one for
2458 pos->overlay_string_index is in IT->overlay_strings. */
2459 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2461 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2462 it
->current
.overlay_string_index
= 0;
2465 load_overlay_strings (it
, 0);
2466 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2470 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2471 relative_index
= (it
->current
.overlay_string_index
2472 % OVERLAY_STRING_CHUNK_SIZE
);
2473 it
->string
= it
->overlay_strings
[relative_index
];
2474 xassert (STRINGP (it
->string
));
2475 it
->current
.string_pos
= pos
->string_pos
;
2476 it
->method
= next_element_from_string
;
2479 #if 0 /* This is bogus because POS not having an overlay string
2480 position does not mean it's after the string. Example: A
2481 line starting with a before-string and initialization of IT
2482 to the previous row's end position. */
2483 else if (it
->current
.overlay_string_index
>= 0)
2485 /* If POS says we're already after an overlay string ending at
2486 POS, make sure to pop the iterator because it will be in
2487 front of that overlay string. When POS is ZV, we've thereby
2488 also ``processed'' overlay strings at ZV. */
2491 it
->current
.overlay_string_index
= -1;
2492 it
->method
= next_element_from_buffer
;
2493 if (CHARPOS (pos
->pos
) == ZV
)
2494 it
->overlay_strings_at_end_processed_p
= 1;
2498 if (CHARPOS (pos
->string_pos
) >= 0)
2500 /* Recorded position is not in an overlay string, but in another
2501 string. This can only be a string from a `display' property.
2502 IT should already be filled with that string. */
2503 it
->current
.string_pos
= pos
->string_pos
;
2504 xassert (STRINGP (it
->string
));
2507 /* Restore position in display vector translations, control
2508 character translations or ellipses. */
2509 if (pos
->dpvec_index
>= 0)
2511 if (it
->dpvec
== NULL
)
2512 get_next_display_element (it
);
2513 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2514 it
->current
.dpvec_index
= pos
->dpvec_index
;
2518 return !overlay_strings_with_newlines
;
2522 /* Initialize IT for stepping through current_buffer in window W
2523 starting at ROW->start. */
2526 init_to_row_start (it
, w
, row
)
2529 struct glyph_row
*row
;
2531 init_from_display_pos (it
, w
, &row
->start
);
2532 it
->start
= row
->start
;
2533 it
->continuation_lines_width
= row
->continuation_lines_width
;
2538 /* Initialize IT for stepping through current_buffer in window W
2539 starting in the line following ROW, i.e. starting at ROW->end.
2540 Value is zero if there are overlay strings with newlines at ROW's
2544 init_to_row_end (it
, w
, row
)
2547 struct glyph_row
*row
;
2551 if (init_from_display_pos (it
, w
, &row
->end
))
2553 if (row
->continued_p
)
2554 it
->continuation_lines_width
2555 = row
->continuation_lines_width
+ row
->pixel_width
;
2566 /***********************************************************************
2568 ***********************************************************************/
2570 /* Called when IT reaches IT->stop_charpos. Handle text property and
2571 overlay changes. Set IT->stop_charpos to the next position where
2578 enum prop_handled handled
;
2579 int handle_overlay_change_p
= 1;
2583 it
->current
.dpvec_index
= -1;
2587 handled
= HANDLED_NORMALLY
;
2589 /* Call text property handlers. */
2590 for (p
= it_props
; p
->handler
; ++p
)
2592 handled
= p
->handler (it
);
2594 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2596 else if (handled
== HANDLED_RETURN
)
2598 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2599 handle_overlay_change_p
= 0;
2602 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2604 /* Don't check for overlay strings below when set to deliver
2605 characters from a display vector. */
2606 if (it
->method
== next_element_from_display_vector
)
2607 handle_overlay_change_p
= 0;
2609 /* Handle overlay changes. */
2610 if (handle_overlay_change_p
)
2611 handled
= handle_overlay_change (it
);
2613 /* Determine where to stop next. */
2614 if (handled
== HANDLED_NORMALLY
)
2615 compute_stop_pos (it
);
2618 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2622 /* Compute IT->stop_charpos from text property and overlay change
2623 information for IT's current position. */
2626 compute_stop_pos (it
)
2629 register INTERVAL iv
, next_iv
;
2630 Lisp_Object object
, limit
, position
;
2632 /* If nowhere else, stop at the end. */
2633 it
->stop_charpos
= it
->end_charpos
;
2635 if (STRINGP (it
->string
))
2637 /* Strings are usually short, so don't limit the search for
2639 object
= it
->string
;
2641 position
= make_number (IT_STRING_CHARPOS (*it
));
2647 /* If next overlay change is in front of the current stop pos
2648 (which is IT->end_charpos), stop there. Note: value of
2649 next_overlay_change is point-max if no overlay change
2651 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2652 if (charpos
< it
->stop_charpos
)
2653 it
->stop_charpos
= charpos
;
2655 /* If showing the region, we have to stop at the region
2656 start or end because the face might change there. */
2657 if (it
->region_beg_charpos
> 0)
2659 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2660 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2661 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2662 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2665 /* Set up variables for computing the stop position from text
2666 property changes. */
2667 XSETBUFFER (object
, current_buffer
);
2668 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2669 position
= make_number (IT_CHARPOS (*it
));
2673 /* Get the interval containing IT's position. Value is a null
2674 interval if there isn't such an interval. */
2675 iv
= validate_interval_range (object
, &position
, &position
, 0);
2676 if (!NULL_INTERVAL_P (iv
))
2678 Lisp_Object values_here
[LAST_PROP_IDX
];
2681 /* Get properties here. */
2682 for (p
= it_props
; p
->handler
; ++p
)
2683 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2685 /* Look for an interval following iv that has different
2687 for (next_iv
= next_interval (iv
);
2688 (!NULL_INTERVAL_P (next_iv
)
2690 || XFASTINT (limit
) > next_iv
->position
));
2691 next_iv
= next_interval (next_iv
))
2693 for (p
= it_props
; p
->handler
; ++p
)
2695 Lisp_Object new_value
;
2697 new_value
= textget (next_iv
->plist
, *p
->name
);
2698 if (!EQ (values_here
[p
->idx
], new_value
))
2706 if (!NULL_INTERVAL_P (next_iv
))
2708 if (INTEGERP (limit
)
2709 && next_iv
->position
>= XFASTINT (limit
))
2710 /* No text property change up to limit. */
2711 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2713 /* Text properties change in next_iv. */
2714 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2718 xassert (STRINGP (it
->string
)
2719 || (it
->stop_charpos
>= BEGV
2720 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2724 /* Return the position of the next overlay change after POS in
2725 current_buffer. Value is point-max if no overlay change
2726 follows. This is like `next-overlay-change' but doesn't use
2730 next_overlay_change (pos
)
2735 Lisp_Object
*overlays
;
2738 /* Get all overlays at the given position. */
2739 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2741 /* If any of these overlays ends before endpos,
2742 use its ending point instead. */
2743 for (i
= 0; i
< noverlays
; ++i
)
2748 oend
= OVERLAY_END (overlays
[i
]);
2749 oendpos
= OVERLAY_POSITION (oend
);
2750 endpos
= min (endpos
, oendpos
);
2758 /***********************************************************************
2760 ***********************************************************************/
2762 /* Handle changes in the `fontified' property of the current buffer by
2763 calling hook functions from Qfontification_functions to fontify
2766 static enum prop_handled
2767 handle_fontified_prop (it
)
2770 Lisp_Object prop
, pos
;
2771 enum prop_handled handled
= HANDLED_NORMALLY
;
2773 /* Get the value of the `fontified' property at IT's current buffer
2774 position. (The `fontified' property doesn't have a special
2775 meaning in strings.) If the value is nil, call functions from
2776 Qfontification_functions. */
2777 if (!STRINGP (it
->string
)
2779 && !NILP (Vfontification_functions
)
2780 && !NILP (Vrun_hooks
)
2781 && (pos
= make_number (IT_CHARPOS (*it
)),
2782 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2785 int count
= SPECPDL_INDEX ();
2788 val
= Vfontification_functions
;
2789 specbind (Qfontification_functions
, Qnil
);
2791 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2792 safe_call1 (val
, pos
);
2795 Lisp_Object globals
, fn
;
2796 struct gcpro gcpro1
, gcpro2
;
2799 GCPRO2 (val
, globals
);
2801 for (; CONSP (val
); val
= XCDR (val
))
2807 /* A value of t indicates this hook has a local
2808 binding; it means to run the global binding too.
2809 In a global value, t should not occur. If it
2810 does, we must ignore it to avoid an endless
2812 for (globals
= Fdefault_value (Qfontification_functions
);
2814 globals
= XCDR (globals
))
2816 fn
= XCAR (globals
);
2818 safe_call1 (fn
, pos
);
2822 safe_call1 (fn
, pos
);
2828 unbind_to (count
, Qnil
);
2830 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2831 something. This avoids an endless loop if they failed to
2832 fontify the text for which reason ever. */
2833 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2834 handled
= HANDLED_RECOMPUTE_PROPS
;
2842 /***********************************************************************
2844 ***********************************************************************/
2846 /* Set up iterator IT from face properties at its current position.
2847 Called from handle_stop. */
2849 static enum prop_handled
2850 handle_face_prop (it
)
2853 int new_face_id
, next_stop
;
2855 if (!STRINGP (it
->string
))
2858 = face_at_buffer_position (it
->w
,
2860 it
->region_beg_charpos
,
2861 it
->region_end_charpos
,
2864 + TEXT_PROP_DISTANCE_LIMIT
),
2867 /* Is this a start of a run of characters with box face?
2868 Caveat: this can be called for a freshly initialized
2869 iterator; face_id is -1 in this case. We know that the new
2870 face will not change until limit, i.e. if the new face has a
2871 box, all characters up to limit will have one. But, as
2872 usual, we don't know whether limit is really the end. */
2873 if (new_face_id
!= it
->face_id
)
2875 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2877 /* If new face has a box but old face has not, this is
2878 the start of a run of characters with box, i.e. it has
2879 a shadow on the left side. The value of face_id of the
2880 iterator will be -1 if this is the initial call that gets
2881 the face. In this case, we have to look in front of IT's
2882 position and see whether there is a face != new_face_id. */
2883 it
->start_of_box_run_p
2884 = (new_face
->box
!= FACE_NO_BOX
2885 && (it
->face_id
>= 0
2886 || IT_CHARPOS (*it
) == BEG
2887 || new_face_id
!= face_before_it_pos (it
)));
2888 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2893 int base_face_id
, bufpos
;
2895 if (it
->current
.overlay_string_index
>= 0)
2896 bufpos
= IT_CHARPOS (*it
);
2900 /* For strings from a buffer, i.e. overlay strings or strings
2901 from a `display' property, use the face at IT's current
2902 buffer position as the base face to merge with, so that
2903 overlay strings appear in the same face as surrounding
2904 text, unless they specify their own faces. */
2905 base_face_id
= underlying_face_id (it
);
2907 new_face_id
= face_at_string_position (it
->w
,
2909 IT_STRING_CHARPOS (*it
),
2911 it
->region_beg_charpos
,
2912 it
->region_end_charpos
,
2916 #if 0 /* This shouldn't be neccessary. Let's check it. */
2917 /* If IT is used to display a mode line we would really like to
2918 use the mode line face instead of the frame's default face. */
2919 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2920 && new_face_id
== DEFAULT_FACE_ID
)
2921 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2924 /* Is this a start of a run of characters with box? Caveat:
2925 this can be called for a freshly allocated iterator; face_id
2926 is -1 is this case. We know that the new face will not
2927 change until the next check pos, i.e. if the new face has a
2928 box, all characters up to that position will have a
2929 box. But, as usual, we don't know whether that position
2930 is really the end. */
2931 if (new_face_id
!= it
->face_id
)
2933 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2934 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2936 /* If new face has a box but old face hasn't, this is the
2937 start of a run of characters with box, i.e. it has a
2938 shadow on the left side. */
2939 it
->start_of_box_run_p
2940 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2941 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2945 it
->face_id
= new_face_id
;
2946 return HANDLED_NORMALLY
;
2950 /* Return the ID of the face ``underlying'' IT's current position,
2951 which is in a string. If the iterator is associated with a
2952 buffer, return the face at IT's current buffer position.
2953 Otherwise, use the iterator's base_face_id. */
2956 underlying_face_id (it
)
2959 int face_id
= it
->base_face_id
, i
;
2961 xassert (STRINGP (it
->string
));
2963 for (i
= it
->sp
- 1; i
>= 0; --i
)
2964 if (NILP (it
->stack
[i
].string
))
2965 face_id
= it
->stack
[i
].face_id
;
2971 /* Compute the face one character before or after the current position
2972 of IT. BEFORE_P non-zero means get the face in front of IT's
2973 position. Value is the id of the face. */
2976 face_before_or_after_it_pos (it
, before_p
)
2981 int next_check_charpos
;
2982 struct text_pos pos
;
2984 xassert (it
->s
== NULL
);
2986 if (STRINGP (it
->string
))
2988 int bufpos
, base_face_id
;
2990 /* No face change past the end of the string (for the case
2991 we are padding with spaces). No face change before the
2993 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2994 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2997 /* Set pos to the position before or after IT's current position. */
2999 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3001 /* For composition, we must check the character after the
3003 pos
= (it
->what
== IT_COMPOSITION
3004 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3005 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3007 if (it
->current
.overlay_string_index
>= 0)
3008 bufpos
= IT_CHARPOS (*it
);
3012 base_face_id
= underlying_face_id (it
);
3014 /* Get the face for ASCII, or unibyte. */
3015 face_id
= face_at_string_position (it
->w
,
3019 it
->region_beg_charpos
,
3020 it
->region_end_charpos
,
3021 &next_check_charpos
,
3024 /* Correct the face for charsets different from ASCII. Do it
3025 for the multibyte case only. The face returned above is
3026 suitable for unibyte text if IT->string is unibyte. */
3027 if (STRING_MULTIBYTE (it
->string
))
3029 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3030 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3032 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3034 c
= string_char_and_length (p
, rest
, &len
);
3035 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3040 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3041 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3044 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3045 pos
= it
->current
.pos
;
3048 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3051 if (it
->what
== IT_COMPOSITION
)
3052 /* For composition, we must check the position after the
3054 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3056 INC_TEXT_POS (pos
, it
->multibyte_p
);
3059 /* Determine face for CHARSET_ASCII, or unibyte. */
3060 face_id
= face_at_buffer_position (it
->w
,
3062 it
->region_beg_charpos
,
3063 it
->region_end_charpos
,
3064 &next_check_charpos
,
3067 /* Correct the face for charsets different from ASCII. Do it
3068 for the multibyte case only. The face returned above is
3069 suitable for unibyte text if current_buffer is unibyte. */
3070 if (it
->multibyte_p
)
3072 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3073 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3074 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3083 /***********************************************************************
3085 ***********************************************************************/
3087 /* Set up iterator IT from invisible properties at its current
3088 position. Called from handle_stop. */
3090 static enum prop_handled
3091 handle_invisible_prop (it
)
3094 enum prop_handled handled
= HANDLED_NORMALLY
;
3096 if (STRINGP (it
->string
))
3098 extern Lisp_Object Qinvisible
;
3099 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3101 /* Get the value of the invisible text property at the
3102 current position. Value will be nil if there is no such
3104 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3105 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3108 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3110 handled
= HANDLED_RECOMPUTE_PROPS
;
3112 /* Get the position at which the next change of the
3113 invisible text property can be found in IT->string.
3114 Value will be nil if the property value is the same for
3115 all the rest of IT->string. */
3116 XSETINT (limit
, SCHARS (it
->string
));
3117 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3120 /* Text at current position is invisible. The next
3121 change in the property is at position end_charpos.
3122 Move IT's current position to that position. */
3123 if (INTEGERP (end_charpos
)
3124 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3126 struct text_pos old
;
3127 old
= it
->current
.string_pos
;
3128 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3129 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3133 /* The rest of the string is invisible. If this is an
3134 overlay string, proceed with the next overlay string
3135 or whatever comes and return a character from there. */
3136 if (it
->current
.overlay_string_index
>= 0)
3138 next_overlay_string (it
);
3139 /* Don't check for overlay strings when we just
3140 finished processing them. */
3141 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3145 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3146 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3153 int invis_p
, newpos
, next_stop
, start_charpos
;
3154 Lisp_Object pos
, prop
, overlay
;
3156 /* First of all, is there invisible text at this position? */
3157 start_charpos
= IT_CHARPOS (*it
);
3158 pos
= make_number (IT_CHARPOS (*it
));
3159 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3161 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3163 /* If we are on invisible text, skip over it. */
3164 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3166 /* Record whether we have to display an ellipsis for the
3168 int display_ellipsis_p
= invis_p
== 2;
3170 handled
= HANDLED_RECOMPUTE_PROPS
;
3172 /* Loop skipping over invisible text. The loop is left at
3173 ZV or with IT on the first char being visible again. */
3176 /* Try to skip some invisible text. Return value is the
3177 position reached which can be equal to IT's position
3178 if there is nothing invisible here. This skips both
3179 over invisible text properties and overlays with
3180 invisible property. */
3181 newpos
= skip_invisible (IT_CHARPOS (*it
),
3182 &next_stop
, ZV
, it
->window
);
3184 /* If we skipped nothing at all we weren't at invisible
3185 text in the first place. If everything to the end of
3186 the buffer was skipped, end the loop. */
3187 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3191 /* We skipped some characters but not necessarily
3192 all there are. Check if we ended up on visible
3193 text. Fget_char_property returns the property of
3194 the char before the given position, i.e. if we
3195 get invis_p = 0, this means that the char at
3196 newpos is visible. */
3197 pos
= make_number (newpos
);
3198 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3199 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3202 /* If we ended up on invisible text, proceed to
3203 skip starting with next_stop. */
3205 IT_CHARPOS (*it
) = next_stop
;
3209 /* The position newpos is now either ZV or on visible text. */
3210 IT_CHARPOS (*it
) = newpos
;
3211 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3213 /* If there are before-strings at the start of invisible
3214 text, and the text is invisible because of a text
3215 property, arrange to show before-strings because 20.x did
3216 it that way. (If the text is invisible because of an
3217 overlay property instead of a text property, this is
3218 already handled in the overlay code.) */
3220 && get_overlay_strings (it
, start_charpos
))
3222 handled
= HANDLED_RECOMPUTE_PROPS
;
3223 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3225 else if (display_ellipsis_p
)
3226 setup_for_ellipsis (it
);
3234 /* Make iterator IT return `...' next. */
3237 setup_for_ellipsis (it
)
3241 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3243 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3244 it
->dpvec
= v
->contents
;
3245 it
->dpend
= v
->contents
+ v
->size
;
3249 /* Default `...'. */
3250 it
->dpvec
= default_invis_vector
;
3251 it
->dpend
= default_invis_vector
+ 3;
3254 /* The ellipsis display does not replace the display of the
3255 character at the new position. Indicate this by setting
3256 IT->dpvec_char_len to zero. */
3257 it
->dpvec_char_len
= 0;
3259 it
->current
.dpvec_index
= 0;
3260 it
->method
= next_element_from_display_vector
;
3265 /***********************************************************************
3267 ***********************************************************************/
3269 /* Set up iterator IT from `display' property at its current position.
3270 Called from handle_stop. */
3272 static enum prop_handled
3273 handle_display_prop (it
)
3276 Lisp_Object prop
, object
;
3277 struct text_pos
*position
;
3278 int display_replaced_p
= 0;
3280 if (STRINGP (it
->string
))
3282 object
= it
->string
;
3283 position
= &it
->current
.string_pos
;
3287 object
= it
->w
->buffer
;
3288 position
= &it
->current
.pos
;
3291 /* Reset those iterator values set from display property values. */
3292 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3293 it
->space_width
= Qnil
;
3294 it
->font_height
= Qnil
;
3297 /* We don't support recursive `display' properties, i.e. string
3298 values that have a string `display' property, that have a string
3299 `display' property etc. */
3300 if (!it
->string_from_display_prop_p
)
3301 it
->area
= TEXT_AREA
;
3303 prop
= Fget_char_property (make_number (position
->charpos
),
3306 return HANDLED_NORMALLY
;
3309 /* Simple properties. */
3310 && !EQ (XCAR (prop
), Qimage
)
3311 && !EQ (XCAR (prop
), Qspace
)
3312 && !EQ (XCAR (prop
), Qwhen
)
3313 && !EQ (XCAR (prop
), Qslice
)
3314 && !EQ (XCAR (prop
), Qspace_width
)
3315 && !EQ (XCAR (prop
), Qheight
)
3316 && !EQ (XCAR (prop
), Qraise
)
3317 /* Marginal area specifications. */
3318 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3319 && !EQ (XCAR (prop
), Qleft_fringe
)
3320 && !EQ (XCAR (prop
), Qright_fringe
)
3321 && !NILP (XCAR (prop
)))
3323 for (; CONSP (prop
); prop
= XCDR (prop
))
3325 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3326 position
, display_replaced_p
))
3327 display_replaced_p
= 1;
3330 else if (VECTORP (prop
))
3333 for (i
= 0; i
< ASIZE (prop
); ++i
)
3334 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3335 position
, display_replaced_p
))
3336 display_replaced_p
= 1;
3340 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3341 display_replaced_p
= 1;
3344 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3348 /* Value is the position of the end of the `display' property starting
3349 at START_POS in OBJECT. */
3351 static struct text_pos
3352 display_prop_end (it
, object
, start_pos
)
3355 struct text_pos start_pos
;
3358 struct text_pos end_pos
;
3360 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3361 Qdisplay
, object
, Qnil
);
3362 CHARPOS (end_pos
) = XFASTINT (end
);
3363 if (STRINGP (object
))
3364 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3366 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3372 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3373 is the object in which the `display' property was found. *POSITION
3374 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3375 means that we previously saw a display sub-property which already
3376 replaced text display with something else, for example an image;
3377 ignore such properties after the first one has been processed.
3379 If PROP is a `space' or `image' sub-property, set *POSITION to the
3380 end position of the `display' property.
3382 Value is non-zero if something was found which replaces the display
3383 of buffer or string text. */
3386 handle_single_display_prop (it
, prop
, object
, position
,
3387 display_replaced_before_p
)
3391 struct text_pos
*position
;
3392 int display_replaced_before_p
;
3395 int replaces_text_display_p
= 0;
3398 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3399 evaluated. If the result is nil, VALUE is ignored. */
3401 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3410 if (!NILP (form
) && !EQ (form
, Qt
))
3412 int count
= SPECPDL_INDEX ();
3413 struct gcpro gcpro1
;
3415 /* Bind `object' to the object having the `display' property, a
3416 buffer or string. Bind `position' to the position in the
3417 object where the property was found, and `buffer-position'
3418 to the current position in the buffer. */
3419 specbind (Qobject
, object
);
3420 specbind (Qposition
, make_number (CHARPOS (*position
)));
3421 specbind (Qbuffer_position
,
3422 make_number (STRINGP (object
)
3423 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3425 form
= safe_eval (form
);
3427 unbind_to (count
, Qnil
);
3434 && EQ (XCAR (prop
), Qheight
)
3435 && CONSP (XCDR (prop
)))
3437 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3440 /* `(height HEIGHT)'. */
3441 it
->font_height
= XCAR (XCDR (prop
));
3442 if (!NILP (it
->font_height
))
3444 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3445 int new_height
= -1;
3447 if (CONSP (it
->font_height
)
3448 && (EQ (XCAR (it
->font_height
), Qplus
)
3449 || EQ (XCAR (it
->font_height
), Qminus
))
3450 && CONSP (XCDR (it
->font_height
))
3451 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3453 /* `(+ N)' or `(- N)' where N is an integer. */
3454 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3455 if (EQ (XCAR (it
->font_height
), Qplus
))
3457 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3459 else if (FUNCTIONP (it
->font_height
))
3461 /* Call function with current height as argument.
3462 Value is the new height. */
3464 height
= safe_call1 (it
->font_height
,
3465 face
->lface
[LFACE_HEIGHT_INDEX
]);
3466 if (NUMBERP (height
))
3467 new_height
= XFLOATINT (height
);
3469 else if (NUMBERP (it
->font_height
))
3471 /* Value is a multiple of the canonical char height. */
3474 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3475 new_height
= (XFLOATINT (it
->font_height
)
3476 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3480 /* Evaluate IT->font_height with `height' bound to the
3481 current specified height to get the new height. */
3483 int count
= SPECPDL_INDEX ();
3485 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3486 value
= safe_eval (it
->font_height
);
3487 unbind_to (count
, Qnil
);
3489 if (NUMBERP (value
))
3490 new_height
= XFLOATINT (value
);
3494 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3497 else if (CONSP (prop
)
3498 && EQ (XCAR (prop
), Qspace_width
)
3499 && CONSP (XCDR (prop
)))
3501 /* `(space_width WIDTH)'. */
3502 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3505 value
= XCAR (XCDR (prop
));
3506 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3507 it
->space_width
= value
;
3509 else if (CONSP (prop
)
3510 && EQ (XCAR (prop
), Qslice
))
3512 /* `(slice X Y WIDTH HEIGHT)'. */
3515 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3518 if (tem
= XCDR (prop
), CONSP (tem
))
3520 it
->slice
.x
= XCAR (tem
);
3521 if (tem
= XCDR (tem
), CONSP (tem
))
3523 it
->slice
.y
= XCAR (tem
);
3524 if (tem
= XCDR (tem
), CONSP (tem
))
3526 it
->slice
.width
= XCAR (tem
);
3527 if (tem
= XCDR (tem
), CONSP (tem
))
3528 it
->slice
.height
= XCAR (tem
);
3533 else if (CONSP (prop
)
3534 && EQ (XCAR (prop
), Qraise
)
3535 && CONSP (XCDR (prop
)))
3537 /* `(raise FACTOR)'. */
3538 if (!FRAME_WINDOW_P (it
->f
))
3541 #ifdef HAVE_WINDOW_SYSTEM
3542 value
= XCAR (XCDR (prop
));
3543 if (NUMBERP (value
))
3545 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3546 it
->voffset
= - (XFLOATINT (value
)
3547 * (FONT_HEIGHT (face
->font
)));
3549 #endif /* HAVE_WINDOW_SYSTEM */
3551 else if (!it
->string_from_display_prop_p
)
3553 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3554 VALUE) or `((margin nil) VALUE)' or VALUE. */
3555 Lisp_Object location
, value
;
3556 struct text_pos start_pos
;
3559 /* Characters having this form of property are not displayed, so
3560 we have to find the end of the property. */
3561 start_pos
= *position
;
3562 *position
= display_prop_end (it
, object
, start_pos
);
3565 /* Let's stop at the new position and assume that all
3566 text properties change there. */
3567 it
->stop_charpos
= position
->charpos
;
3570 && (EQ (XCAR (prop
), Qleft_fringe
)
3571 || EQ (XCAR (prop
), Qright_fringe
))
3572 && CONSP (XCDR (prop
)))
3574 unsigned face_id
= DEFAULT_FACE_ID
;
3577 /* Save current settings of IT so that we can restore them
3578 when we are finished with the glyph property value. */
3580 /* `(left-fringe BITMAP FACE)'. */
3581 if (!FRAME_WINDOW_P (it
->f
))
3584 #ifdef HAVE_WINDOW_SYSTEM
3585 value
= XCAR (XCDR (prop
));
3586 if (!SYMBOLP (value
)
3587 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3590 if (CONSP (XCDR (XCDR (prop
))))
3592 Lisp_Object face_name
= XCAR (XCDR (XCDR (prop
)));
3594 face_id
= lookup_named_face (it
->f
, face_name
, 'A');
3601 it
->area
= TEXT_AREA
;
3602 it
->what
= IT_IMAGE
;
3603 it
->image_id
= -1; /* no image */
3604 it
->position
= start_pos
;
3605 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3606 it
->method
= next_element_from_image
;
3607 it
->face_id
= face_id
;
3609 /* Say that we haven't consumed the characters with
3610 `display' property yet. The call to pop_it in
3611 set_iterator_to_next will clean this up. */
3612 *position
= start_pos
;
3614 if (EQ (XCAR (prop
), Qleft_fringe
))
3616 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3617 it
->left_user_fringe_face_id
= face_id
;
3621 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3622 it
->right_user_fringe_face_id
= face_id
;
3624 #endif /* HAVE_WINDOW_SYSTEM */
3628 location
= Qunbound
;
3629 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3633 value
= XCDR (prop
);
3635 value
= XCAR (value
);
3638 if (EQ (XCAR (tem
), Qmargin
)
3639 && (tem
= XCDR (tem
),
3640 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3642 || EQ (tem
, Qleft_margin
)
3643 || EQ (tem
, Qright_margin
))))
3647 if (EQ (location
, Qunbound
))
3653 valid_p
= (STRINGP (value
)
3654 #ifdef HAVE_WINDOW_SYSTEM
3655 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
3656 #endif /* not HAVE_WINDOW_SYSTEM */
3657 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3659 if ((EQ (location
, Qleft_margin
)
3660 || EQ (location
, Qright_margin
)
3663 && !display_replaced_before_p
)
3665 replaces_text_display_p
= 1;
3667 /* Save current settings of IT so that we can restore them
3668 when we are finished with the glyph property value. */
3671 if (NILP (location
))
3672 it
->area
= TEXT_AREA
;
3673 else if (EQ (location
, Qleft_margin
))
3674 it
->area
= LEFT_MARGIN_AREA
;
3676 it
->area
= RIGHT_MARGIN_AREA
;
3678 if (STRINGP (value
))
3681 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3682 it
->current
.overlay_string_index
= -1;
3683 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3684 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3685 it
->method
= next_element_from_string
;
3686 it
->stop_charpos
= 0;
3687 it
->string_from_display_prop_p
= 1;
3688 /* Say that we haven't consumed the characters with
3689 `display' property yet. The call to pop_it in
3690 set_iterator_to_next will clean this up. */
3691 *position
= start_pos
;
3693 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3695 it
->method
= next_element_from_stretch
;
3697 it
->current
.pos
= it
->position
= start_pos
;
3699 #ifdef HAVE_WINDOW_SYSTEM
3702 if (FRAME_WINDOW_P (it
->f
))
3704 it
->what
= IT_IMAGE
;
3705 it
->image_id
= lookup_image (it
->f
, value
);
3706 it
->position
= start_pos
;
3707 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3708 it
->method
= next_element_from_image
;
3711 /* Say that we haven't consumed the characters with
3712 `display' property yet. The call to pop_it in
3713 set_iterator_to_next will clean this up. */
3714 *position
= start_pos
;
3716 #endif /* HAVE_WINDOW_SYSTEM */
3719 /* Invalid property or property not supported. Restore
3720 the position to what it was before. */
3721 *position
= start_pos
;
3724 return replaces_text_display_p
;
3728 /* Check if PROP is a display sub-property value whose text should be
3729 treated as intangible. */
3732 single_display_prop_intangible_p (prop
)
3735 /* Skip over `when FORM'. */
3736 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3750 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3751 we don't need to treat text as intangible. */
3752 if (EQ (XCAR (prop
), Qmargin
))
3760 || EQ (XCAR (prop
), Qleft_margin
)
3761 || EQ (XCAR (prop
), Qright_margin
))
3765 return (CONSP (prop
)
3766 && (EQ (XCAR (prop
), Qimage
)
3767 || EQ (XCAR (prop
), Qspace
)));
3771 /* Check if PROP is a display property value whose text should be
3772 treated as intangible. */
3775 display_prop_intangible_p (prop
)
3779 && CONSP (XCAR (prop
))
3780 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3782 /* A list of sub-properties. */
3783 while (CONSP (prop
))
3785 if (single_display_prop_intangible_p (XCAR (prop
)))
3790 else if (VECTORP (prop
))
3792 /* A vector of sub-properties. */
3794 for (i
= 0; i
< ASIZE (prop
); ++i
)
3795 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3799 return single_display_prop_intangible_p (prop
);
3805 /* Return 1 if PROP is a display sub-property value containing STRING. */
3808 single_display_prop_string_p (prop
, string
)
3809 Lisp_Object prop
, string
;
3811 if (EQ (string
, prop
))
3814 /* Skip over `when FORM'. */
3815 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3824 /* Skip over `margin LOCATION'. */
3825 if (EQ (XCAR (prop
), Qmargin
))
3836 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3840 /* Return 1 if STRING appears in the `display' property PROP. */
3843 display_prop_string_p (prop
, string
)
3844 Lisp_Object prop
, string
;
3847 && CONSP (XCAR (prop
))
3848 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3850 /* A list of sub-properties. */
3851 while (CONSP (prop
))
3853 if (single_display_prop_string_p (XCAR (prop
), string
))
3858 else if (VECTORP (prop
))
3860 /* A vector of sub-properties. */
3862 for (i
= 0; i
< ASIZE (prop
); ++i
)
3863 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3867 return single_display_prop_string_p (prop
, string
);
3873 /* Determine from which buffer position in W's buffer STRING comes
3874 from. AROUND_CHARPOS is an approximate position where it could
3875 be from. Value is the buffer position or 0 if it couldn't be
3878 W's buffer must be current.
3880 This function is necessary because we don't record buffer positions
3881 in glyphs generated from strings (to keep struct glyph small).
3882 This function may only use code that doesn't eval because it is
3883 called asynchronously from note_mouse_highlight. */
3886 string_buffer_position (w
, string
, around_charpos
)
3891 Lisp_Object limit
, prop
, pos
;
3892 const int MAX_DISTANCE
= 1000;
3895 pos
= make_number (around_charpos
);
3896 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3897 while (!found
&& !EQ (pos
, limit
))
3899 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3900 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3903 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3908 pos
= make_number (around_charpos
);
3909 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3910 while (!found
&& !EQ (pos
, limit
))
3912 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3913 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3916 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3921 return found
? XINT (pos
) : 0;
3926 /***********************************************************************
3927 `composition' property
3928 ***********************************************************************/
3930 /* Set up iterator IT from `composition' property at its current
3931 position. Called from handle_stop. */
3933 static enum prop_handled
3934 handle_composition_prop (it
)
3937 Lisp_Object prop
, string
;
3938 int pos
, pos_byte
, end
;
3939 enum prop_handled handled
= HANDLED_NORMALLY
;
3941 if (STRINGP (it
->string
))
3943 pos
= IT_STRING_CHARPOS (*it
);
3944 pos_byte
= IT_STRING_BYTEPOS (*it
);
3945 string
= it
->string
;
3949 pos
= IT_CHARPOS (*it
);
3950 pos_byte
= IT_BYTEPOS (*it
);
3954 /* If there's a valid composition and point is not inside of the
3955 composition (in the case that the composition is from the current
3956 buffer), draw a glyph composed from the composition components. */
3957 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3958 && COMPOSITION_VALID_P (pos
, end
, prop
)
3959 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3961 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3965 it
->method
= next_element_from_composition
;
3967 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3968 /* For a terminal, draw only the first character of the
3970 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3971 it
->len
= (STRINGP (it
->string
)
3972 ? string_char_to_byte (it
->string
, end
)
3973 : CHAR_TO_BYTE (end
)) - pos_byte
;
3974 it
->stop_charpos
= end
;
3975 handled
= HANDLED_RETURN
;
3984 /***********************************************************************
3986 ***********************************************************************/
3988 /* The following structure is used to record overlay strings for
3989 later sorting in load_overlay_strings. */
3991 struct overlay_entry
3993 Lisp_Object overlay
;
4000 /* Set up iterator IT from overlay strings at its current position.
4001 Called from handle_stop. */
4003 static enum prop_handled
4004 handle_overlay_change (it
)
4007 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4008 return HANDLED_RECOMPUTE_PROPS
;
4010 return HANDLED_NORMALLY
;
4014 /* Set up the next overlay string for delivery by IT, if there is an
4015 overlay string to deliver. Called by set_iterator_to_next when the
4016 end of the current overlay string is reached. If there are more
4017 overlay strings to display, IT->string and
4018 IT->current.overlay_string_index are set appropriately here.
4019 Otherwise IT->string is set to nil. */
4022 next_overlay_string (it
)
4025 ++it
->current
.overlay_string_index
;
4026 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4028 /* No more overlay strings. Restore IT's settings to what
4029 they were before overlay strings were processed, and
4030 continue to deliver from current_buffer. */
4031 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4034 xassert (it
->stop_charpos
>= BEGV
4035 && it
->stop_charpos
<= it
->end_charpos
);
4037 it
->current
.overlay_string_index
= -1;
4038 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4039 it
->n_overlay_strings
= 0;
4040 it
->method
= next_element_from_buffer
;
4042 /* If we're at the end of the buffer, record that we have
4043 processed the overlay strings there already, so that
4044 next_element_from_buffer doesn't try it again. */
4045 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4046 it
->overlay_strings_at_end_processed_p
= 1;
4048 /* If we have to display `...' for invisible text, set
4049 the iterator up for that. */
4050 if (display_ellipsis_p
)
4051 setup_for_ellipsis (it
);
4055 /* There are more overlay strings to process. If
4056 IT->current.overlay_string_index has advanced to a position
4057 where we must load IT->overlay_strings with more strings, do
4059 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4061 if (it
->current
.overlay_string_index
&& i
== 0)
4062 load_overlay_strings (it
, 0);
4064 /* Initialize IT to deliver display elements from the overlay
4066 it
->string
= it
->overlay_strings
[i
];
4067 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4068 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4069 it
->method
= next_element_from_string
;
4070 it
->stop_charpos
= 0;
4077 /* Compare two overlay_entry structures E1 and E2. Used as a
4078 comparison function for qsort in load_overlay_strings. Overlay
4079 strings for the same position are sorted so that
4081 1. All after-strings come in front of before-strings, except
4082 when they come from the same overlay.
4084 2. Within after-strings, strings are sorted so that overlay strings
4085 from overlays with higher priorities come first.
4087 2. Within before-strings, strings are sorted so that overlay
4088 strings from overlays with higher priorities come last.
4090 Value is analogous to strcmp. */
4094 compare_overlay_entries (e1
, e2
)
4097 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4098 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4101 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4103 /* Let after-strings appear in front of before-strings if
4104 they come from different overlays. */
4105 if (EQ (entry1
->overlay
, entry2
->overlay
))
4106 result
= entry1
->after_string_p
? 1 : -1;
4108 result
= entry1
->after_string_p
? -1 : 1;
4110 else if (entry1
->after_string_p
)
4111 /* After-strings sorted in order of decreasing priority. */
4112 result
= entry2
->priority
- entry1
->priority
;
4114 /* Before-strings sorted in order of increasing priority. */
4115 result
= entry1
->priority
- entry2
->priority
;
4121 /* Load the vector IT->overlay_strings with overlay strings from IT's
4122 current buffer position, or from CHARPOS if that is > 0. Set
4123 IT->n_overlays to the total number of overlay strings found.
4125 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4126 a time. On entry into load_overlay_strings,
4127 IT->current.overlay_string_index gives the number of overlay
4128 strings that have already been loaded by previous calls to this
4131 IT->add_overlay_start contains an additional overlay start
4132 position to consider for taking overlay strings from, if non-zero.
4133 This position comes into play when the overlay has an `invisible'
4134 property, and both before and after-strings. When we've skipped to
4135 the end of the overlay, because of its `invisible' property, we
4136 nevertheless want its before-string to appear.
4137 IT->add_overlay_start will contain the overlay start position
4140 Overlay strings are sorted so that after-string strings come in
4141 front of before-string strings. Within before and after-strings,
4142 strings are sorted by overlay priority. See also function
4143 compare_overlay_entries. */
4146 load_overlay_strings (it
, charpos
)
4150 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4151 Lisp_Object overlay
, window
, str
, invisible
;
4152 struct Lisp_Overlay
*ov
;
4155 int n
= 0, i
, j
, invis_p
;
4156 struct overlay_entry
*entries
4157 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4160 charpos
= IT_CHARPOS (*it
);
4162 /* Append the overlay string STRING of overlay OVERLAY to vector
4163 `entries' which has size `size' and currently contains `n'
4164 elements. AFTER_P non-zero means STRING is an after-string of
4166 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4169 Lisp_Object priority; \
4173 int new_size = 2 * size; \
4174 struct overlay_entry *old = entries; \
4176 (struct overlay_entry *) alloca (new_size \
4177 * sizeof *entries); \
4178 bcopy (old, entries, size * sizeof *entries); \
4182 entries[n].string = (STRING); \
4183 entries[n].overlay = (OVERLAY); \
4184 priority = Foverlay_get ((OVERLAY), Qpriority); \
4185 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4186 entries[n].after_string_p = (AFTER_P); \
4191 /* Process overlay before the overlay center. */
4192 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4194 XSETMISC (overlay
, ov
);
4195 xassert (OVERLAYP (overlay
));
4196 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4197 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4202 /* Skip this overlay if it doesn't start or end at IT's current
4204 if (end
!= charpos
&& start
!= charpos
)
4207 /* Skip this overlay if it doesn't apply to IT->w. */
4208 window
= Foverlay_get (overlay
, Qwindow
);
4209 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4212 /* If the text ``under'' the overlay is invisible, both before-
4213 and after-strings from this overlay are visible; start and
4214 end position are indistinguishable. */
4215 invisible
= Foverlay_get (overlay
, Qinvisible
);
4216 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4218 /* If overlay has a non-empty before-string, record it. */
4219 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4220 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4222 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4224 /* If overlay has a non-empty after-string, record it. */
4225 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4226 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4228 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4231 /* Process overlays after the overlay center. */
4232 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4234 XSETMISC (overlay
, ov
);
4235 xassert (OVERLAYP (overlay
));
4236 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4237 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4239 if (start
> charpos
)
4242 /* Skip this overlay if it doesn't start or end at IT's current
4244 if (end
!= charpos
&& start
!= charpos
)
4247 /* Skip this overlay if it doesn't apply to IT->w. */
4248 window
= Foverlay_get (overlay
, Qwindow
);
4249 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4252 /* If the text ``under'' the overlay is invisible, it has a zero
4253 dimension, and both before- and after-strings apply. */
4254 invisible
= Foverlay_get (overlay
, Qinvisible
);
4255 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4257 /* If overlay has a non-empty before-string, record it. */
4258 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4259 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4261 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4263 /* If overlay has a non-empty after-string, record it. */
4264 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4265 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4267 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4270 #undef RECORD_OVERLAY_STRING
4274 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4276 /* Record the total number of strings to process. */
4277 it
->n_overlay_strings
= n
;
4279 /* IT->current.overlay_string_index is the number of overlay strings
4280 that have already been consumed by IT. Copy some of the
4281 remaining overlay strings to IT->overlay_strings. */
4283 j
= it
->current
.overlay_string_index
;
4284 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4285 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4291 /* Get the first chunk of overlay strings at IT's current buffer
4292 position, or at CHARPOS if that is > 0. Value is non-zero if at
4293 least one overlay string was found. */
4296 get_overlay_strings (it
, charpos
)
4300 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4301 process. This fills IT->overlay_strings with strings, and sets
4302 IT->n_overlay_strings to the total number of strings to process.
4303 IT->pos.overlay_string_index has to be set temporarily to zero
4304 because load_overlay_strings needs this; it must be set to -1
4305 when no overlay strings are found because a zero value would
4306 indicate a position in the first overlay string. */
4307 it
->current
.overlay_string_index
= 0;
4308 load_overlay_strings (it
, charpos
);
4310 /* If we found overlay strings, set up IT to deliver display
4311 elements from the first one. Otherwise set up IT to deliver
4312 from current_buffer. */
4313 if (it
->n_overlay_strings
)
4315 /* Make sure we know settings in current_buffer, so that we can
4316 restore meaningful values when we're done with the overlay
4318 compute_stop_pos (it
);
4319 xassert (it
->face_id
>= 0);
4321 /* Save IT's settings. They are restored after all overlay
4322 strings have been processed. */
4323 xassert (it
->sp
== 0);
4326 /* Set up IT to deliver display elements from the first overlay
4328 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4329 it
->string
= it
->overlay_strings
[0];
4330 it
->stop_charpos
= 0;
4331 xassert (STRINGP (it
->string
));
4332 it
->end_charpos
= SCHARS (it
->string
);
4333 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4334 it
->method
= next_element_from_string
;
4339 it
->current
.overlay_string_index
= -1;
4340 it
->method
= next_element_from_buffer
;
4345 /* Value is non-zero if we found at least one overlay string. */
4346 return STRINGP (it
->string
);
4351 /***********************************************************************
4352 Saving and restoring state
4353 ***********************************************************************/
4355 /* Save current settings of IT on IT->stack. Called, for example,
4356 before setting up IT for an overlay string, to be able to restore
4357 IT's settings to what they were after the overlay string has been
4364 struct iterator_stack_entry
*p
;
4366 xassert (it
->sp
< 2);
4367 p
= it
->stack
+ it
->sp
;
4369 p
->stop_charpos
= it
->stop_charpos
;
4370 xassert (it
->face_id
>= 0);
4371 p
->face_id
= it
->face_id
;
4372 p
->string
= it
->string
;
4373 p
->pos
= it
->current
;
4374 p
->end_charpos
= it
->end_charpos
;
4375 p
->string_nchars
= it
->string_nchars
;
4377 p
->multibyte_p
= it
->multibyte_p
;
4378 p
->slice
= it
->slice
;
4379 p
->space_width
= it
->space_width
;
4380 p
->font_height
= it
->font_height
;
4381 p
->voffset
= it
->voffset
;
4382 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4383 p
->display_ellipsis_p
= 0;
4388 /* Restore IT's settings from IT->stack. Called, for example, when no
4389 more overlay strings must be processed, and we return to delivering
4390 display elements from a buffer, or when the end of a string from a
4391 `display' property is reached and we return to delivering display
4392 elements from an overlay string, or from a buffer. */
4398 struct iterator_stack_entry
*p
;
4400 xassert (it
->sp
> 0);
4402 p
= it
->stack
+ it
->sp
;
4403 it
->stop_charpos
= p
->stop_charpos
;
4404 it
->face_id
= p
->face_id
;
4405 it
->string
= p
->string
;
4406 it
->current
= p
->pos
;
4407 it
->end_charpos
= p
->end_charpos
;
4408 it
->string_nchars
= p
->string_nchars
;
4410 it
->multibyte_p
= p
->multibyte_p
;
4411 it
->slice
= p
->slice
;
4412 it
->space_width
= p
->space_width
;
4413 it
->font_height
= p
->font_height
;
4414 it
->voffset
= p
->voffset
;
4415 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4420 /***********************************************************************
4422 ***********************************************************************/
4424 /* Set IT's current position to the previous line start. */
4427 back_to_previous_line_start (it
)
4430 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4431 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4435 /* Move IT to the next line start.
4437 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4438 we skipped over part of the text (as opposed to moving the iterator
4439 continuously over the text). Otherwise, don't change the value
4442 Newlines may come from buffer text, overlay strings, or strings
4443 displayed via the `display' property. That's the reason we can't
4444 simply use find_next_newline_no_quit.
4446 Note that this function may not skip over invisible text that is so
4447 because of text properties and immediately follows a newline. If
4448 it would, function reseat_at_next_visible_line_start, when called
4449 from set_iterator_to_next, would effectively make invisible
4450 characters following a newline part of the wrong glyph row, which
4451 leads to wrong cursor motion. */
4454 forward_to_next_line_start (it
, skipped_p
)
4458 int old_selective
, newline_found_p
, n
;
4459 const int MAX_NEWLINE_DISTANCE
= 500;
4461 /* If already on a newline, just consume it to avoid unintended
4462 skipping over invisible text below. */
4463 if (it
->what
== IT_CHARACTER
4465 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4467 set_iterator_to_next (it
, 0);
4472 /* Don't handle selective display in the following. It's (a)
4473 unnecessary because it's done by the caller, and (b) leads to an
4474 infinite recursion because next_element_from_ellipsis indirectly
4475 calls this function. */
4476 old_selective
= it
->selective
;
4479 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4480 from buffer text. */
4481 for (n
= newline_found_p
= 0;
4482 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4483 n
+= STRINGP (it
->string
) ? 0 : 1)
4485 if (!get_next_display_element (it
))
4487 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4488 set_iterator_to_next (it
, 0);
4491 /* If we didn't find a newline near enough, see if we can use a
4493 if (!newline_found_p
)
4495 int start
= IT_CHARPOS (*it
);
4496 int limit
= find_next_newline_no_quit (start
, 1);
4499 xassert (!STRINGP (it
->string
));
4501 /* If there isn't any `display' property in sight, and no
4502 overlays, we can just use the position of the newline in
4504 if (it
->stop_charpos
>= limit
4505 || ((pos
= Fnext_single_property_change (make_number (start
),
4507 Qnil
, make_number (limit
)),
4509 && next_overlay_change (start
) == ZV
))
4511 IT_CHARPOS (*it
) = limit
;
4512 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4513 *skipped_p
= newline_found_p
= 1;
4517 while (get_next_display_element (it
)
4518 && !newline_found_p
)
4520 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4521 set_iterator_to_next (it
, 0);
4526 it
->selective
= old_selective
;
4527 return newline_found_p
;
4531 /* Set IT's current position to the previous visible line start. Skip
4532 invisible text that is so either due to text properties or due to
4533 selective display. Caution: this does not change IT->current_x and
4537 back_to_previous_visible_line_start (it
)
4542 /* Go back one newline if not on BEGV already. */
4543 if (IT_CHARPOS (*it
) > BEGV
)
4544 back_to_previous_line_start (it
);
4546 /* Move over lines that are invisible because of selective display
4547 or text properties. */
4548 while (IT_CHARPOS (*it
) > BEGV
4553 /* If selective > 0, then lines indented more than that values
4555 if (it
->selective
> 0
4556 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4557 (double) it
->selective
)) /* iftc */
4563 /* Check the newline before point for invisibility. */
4564 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4565 Qinvisible
, it
->window
);
4566 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4572 struct it it2
= *it
;
4574 if (handle_display_prop (&it2
) == HANDLED_RETURN
)
4578 /* Back one more newline if the current one is invisible. */
4580 back_to_previous_line_start (it
);
4583 xassert (IT_CHARPOS (*it
) >= BEGV
);
4584 xassert (IT_CHARPOS (*it
) == BEGV
4585 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4590 /* Reseat iterator IT at the previous visible line start. Skip
4591 invisible text that is so either due to text properties or due to
4592 selective display. At the end, update IT's overlay information,
4593 face information etc. */
4596 reseat_at_previous_visible_line_start (it
)
4599 back_to_previous_visible_line_start (it
);
4600 reseat (it
, it
->current
.pos
, 1);
4605 /* Reseat iterator IT on the next visible line start in the current
4606 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4607 preceding the line start. Skip over invisible text that is so
4608 because of selective display. Compute faces, overlays etc at the
4609 new position. Note that this function does not skip over text that
4610 is invisible because of text properties. */
4613 reseat_at_next_visible_line_start (it
, on_newline_p
)
4617 int newline_found_p
, skipped_p
= 0;
4619 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4621 /* Skip over lines that are invisible because they are indented
4622 more than the value of IT->selective. */
4623 if (it
->selective
> 0)
4624 while (IT_CHARPOS (*it
) < ZV
4625 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4626 (double) it
->selective
)) /* iftc */
4628 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4629 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4632 /* Position on the newline if that's what's requested. */
4633 if (on_newline_p
&& newline_found_p
)
4635 if (STRINGP (it
->string
))
4637 if (IT_STRING_CHARPOS (*it
) > 0)
4639 --IT_STRING_CHARPOS (*it
);
4640 --IT_STRING_BYTEPOS (*it
);
4643 else if (IT_CHARPOS (*it
) > BEGV
)
4647 reseat (it
, it
->current
.pos
, 0);
4651 reseat (it
, it
->current
.pos
, 0);
4658 /***********************************************************************
4659 Changing an iterator's position
4660 ***********************************************************************/
4662 /* Change IT's current position to POS in current_buffer. If FORCE_P
4663 is non-zero, always check for text properties at the new position.
4664 Otherwise, text properties are only looked up if POS >=
4665 IT->check_charpos of a property. */
4668 reseat (it
, pos
, force_p
)
4670 struct text_pos pos
;
4673 int original_pos
= IT_CHARPOS (*it
);
4675 reseat_1 (it
, pos
, 0);
4677 /* Determine where to check text properties. Avoid doing it
4678 where possible because text property lookup is very expensive. */
4680 || CHARPOS (pos
) > it
->stop_charpos
4681 || CHARPOS (pos
) < original_pos
)
4688 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4689 IT->stop_pos to POS, also. */
4692 reseat_1 (it
, pos
, set_stop_p
)
4694 struct text_pos pos
;
4697 /* Don't call this function when scanning a C string. */
4698 xassert (it
->s
== NULL
);
4700 /* POS must be a reasonable value. */
4701 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4703 it
->current
.pos
= it
->position
= pos
;
4704 XSETBUFFER (it
->object
, current_buffer
);
4705 it
->end_charpos
= ZV
;
4707 it
->current
.dpvec_index
= -1;
4708 it
->current
.overlay_string_index
= -1;
4709 IT_STRING_CHARPOS (*it
) = -1;
4710 IT_STRING_BYTEPOS (*it
) = -1;
4712 it
->method
= next_element_from_buffer
;
4713 /* RMS: I added this to fix a bug in move_it_vertically_backward
4714 where it->area continued to relate to the starting point
4715 for the backward motion. Bug report from
4716 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4717 However, I am not sure whether reseat still does the right thing
4718 in general after this change. */
4719 it
->area
= TEXT_AREA
;
4720 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4722 it
->face_before_selective_p
= 0;
4725 it
->stop_charpos
= CHARPOS (pos
);
4729 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4730 If S is non-null, it is a C string to iterate over. Otherwise,
4731 STRING gives a Lisp string to iterate over.
4733 If PRECISION > 0, don't return more then PRECISION number of
4734 characters from the string.
4736 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4737 characters have been returned. FIELD_WIDTH < 0 means an infinite
4740 MULTIBYTE = 0 means disable processing of multibyte characters,
4741 MULTIBYTE > 0 means enable it,
4742 MULTIBYTE < 0 means use IT->multibyte_p.
4744 IT must be initialized via a prior call to init_iterator before
4745 calling this function. */
4748 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4753 int precision
, field_width
, multibyte
;
4755 /* No region in strings. */
4756 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4758 /* No text property checks performed by default, but see below. */
4759 it
->stop_charpos
= -1;
4761 /* Set iterator position and end position. */
4762 bzero (&it
->current
, sizeof it
->current
);
4763 it
->current
.overlay_string_index
= -1;
4764 it
->current
.dpvec_index
= -1;
4765 xassert (charpos
>= 0);
4767 /* If STRING is specified, use its multibyteness, otherwise use the
4768 setting of MULTIBYTE, if specified. */
4770 it
->multibyte_p
= multibyte
> 0;
4774 xassert (STRINGP (string
));
4775 it
->string
= string
;
4777 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4778 it
->method
= next_element_from_string
;
4779 it
->current
.string_pos
= string_pos (charpos
, string
);
4786 /* Note that we use IT->current.pos, not it->current.string_pos,
4787 for displaying C strings. */
4788 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4789 if (it
->multibyte_p
)
4791 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4792 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4796 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4797 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4800 it
->method
= next_element_from_c_string
;
4803 /* PRECISION > 0 means don't return more than PRECISION characters
4805 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4806 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4808 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4809 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4810 FIELD_WIDTH < 0 means infinite field width. This is useful for
4811 padding with `-' at the end of a mode line. */
4812 if (field_width
< 0)
4813 field_width
= INFINITY
;
4814 if (field_width
> it
->end_charpos
- charpos
)
4815 it
->end_charpos
= charpos
+ field_width
;
4817 /* Use the standard display table for displaying strings. */
4818 if (DISP_TABLE_P (Vstandard_display_table
))
4819 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4821 it
->stop_charpos
= charpos
;
4827 /***********************************************************************
4829 ***********************************************************************/
4831 /* Load IT's display element fields with information about the next
4832 display element from the current position of IT. Value is zero if
4833 end of buffer (or C string) is reached. */
4836 get_next_display_element (it
)
4839 /* Non-zero means that we found a display element. Zero means that
4840 we hit the end of what we iterate over. Performance note: the
4841 function pointer `method' used here turns out to be faster than
4842 using a sequence of if-statements. */
4843 int success_p
= (*it
->method
) (it
);
4845 if (it
->what
== IT_CHARACTER
)
4847 /* Map via display table or translate control characters.
4848 IT->c, IT->len etc. have been set to the next character by
4849 the function call above. If we have a display table, and it
4850 contains an entry for IT->c, translate it. Don't do this if
4851 IT->c itself comes from a display table, otherwise we could
4852 end up in an infinite recursion. (An alternative could be to
4853 count the recursion depth of this function and signal an
4854 error when a certain maximum depth is reached.) Is it worth
4856 if (success_p
&& it
->dpvec
== NULL
)
4861 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4864 struct Lisp_Vector
*v
= XVECTOR (dv
);
4866 /* Return the first character from the display table
4867 entry, if not empty. If empty, don't display the
4868 current character. */
4871 it
->dpvec_char_len
= it
->len
;
4872 it
->dpvec
= v
->contents
;
4873 it
->dpend
= v
->contents
+ v
->size
;
4874 it
->current
.dpvec_index
= 0;
4875 it
->method
= next_element_from_display_vector
;
4876 success_p
= get_next_display_element (it
);
4880 set_iterator_to_next (it
, 0);
4881 success_p
= get_next_display_element (it
);
4885 /* Translate control characters into `\003' or `^C' form.
4886 Control characters coming from a display table entry are
4887 currently not translated because we use IT->dpvec to hold
4888 the translation. This could easily be changed but I
4889 don't believe that it is worth doing.
4891 If it->multibyte_p is nonzero, eight-bit characters and
4892 non-printable multibyte characters are also translated to
4895 If it->multibyte_p is zero, eight-bit characters that
4896 don't have corresponding multibyte char code are also
4897 translated to octal form. */
4898 else if ((it
->c
< ' '
4899 && (it
->area
!= TEXT_AREA
4900 /* In mode line, treat \n like other crl chars. */
4902 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
4903 || (it
->c
!= '\n' && it
->c
!= '\t')))
4907 || !CHAR_PRINTABLE_P (it
->c
))
4909 && (!unibyte_display_via_language_environment
4910 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
4912 /* IT->c is a control character which must be displayed
4913 either as '\003' or as `^C' where the '\\' and '^'
4914 can be defined in the display table. Fill
4915 IT->ctl_chars with glyphs for what we have to
4916 display. Then, set IT->dpvec to these glyphs. */
4919 if (it
->c
< 128 && it
->ctl_arrow_p
)
4921 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4923 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4924 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4925 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4927 g
= FAST_MAKE_GLYPH ('^', 0);
4928 XSETINT (it
->ctl_chars
[0], g
);
4930 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4931 XSETINT (it
->ctl_chars
[1], g
);
4933 /* Set up IT->dpvec and return first character from it. */
4934 it
->dpvec_char_len
= it
->len
;
4935 it
->dpvec
= it
->ctl_chars
;
4936 it
->dpend
= it
->dpvec
+ 2;
4937 it
->current
.dpvec_index
= 0;
4938 it
->method
= next_element_from_display_vector
;
4939 get_next_display_element (it
);
4943 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4948 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4950 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4951 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4952 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4954 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4956 if (SINGLE_BYTE_CHAR_P (it
->c
))
4957 str
[0] = it
->c
, len
= 1;
4960 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4963 /* It's an invalid character, which
4964 shouldn't happen actually, but due to
4965 bugs it may happen. Let's print the char
4966 as is, there's not much meaningful we can
4969 str
[1] = it
->c
>> 8;
4970 str
[2] = it
->c
>> 16;
4971 str
[3] = it
->c
>> 24;
4976 for (i
= 0; i
< len
; i
++)
4978 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4979 /* Insert three more glyphs into IT->ctl_chars for
4980 the octal display of the character. */
4981 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4982 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4983 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4984 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4985 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4986 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4989 /* Set up IT->dpvec and return the first character
4991 it
->dpvec_char_len
= it
->len
;
4992 it
->dpvec
= it
->ctl_chars
;
4993 it
->dpend
= it
->dpvec
+ len
* 4;
4994 it
->current
.dpvec_index
= 0;
4995 it
->method
= next_element_from_display_vector
;
4996 get_next_display_element (it
);
5001 /* Adjust face id for a multibyte character. There are no
5002 multibyte character in unibyte text. */
5005 && FRAME_WINDOW_P (it
->f
))
5007 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5008 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5012 /* Is this character the last one of a run of characters with
5013 box? If yes, set IT->end_of_box_run_p to 1. */
5020 it
->end_of_box_run_p
5021 = ((face_id
= face_after_it_pos (it
),
5022 face_id
!= it
->face_id
)
5023 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5024 face
->box
== FACE_NO_BOX
));
5027 /* Value is 0 if end of buffer or string reached. */
5032 /* Move IT to the next display element.
5034 RESEAT_P non-zero means if called on a newline in buffer text,
5035 skip to the next visible line start.
5037 Functions get_next_display_element and set_iterator_to_next are
5038 separate because I find this arrangement easier to handle than a
5039 get_next_display_element function that also increments IT's
5040 position. The way it is we can first look at an iterator's current
5041 display element, decide whether it fits on a line, and if it does,
5042 increment the iterator position. The other way around we probably
5043 would either need a flag indicating whether the iterator has to be
5044 incremented the next time, or we would have to implement a
5045 decrement position function which would not be easy to write. */
5048 set_iterator_to_next (it
, reseat_p
)
5052 /* Reset flags indicating start and end of a sequence of characters
5053 with box. Reset them at the start of this function because
5054 moving the iterator to a new position might set them. */
5055 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5057 if (it
->method
== next_element_from_buffer
)
5059 /* The current display element of IT is a character from
5060 current_buffer. Advance in the buffer, and maybe skip over
5061 invisible lines that are so because of selective display. */
5062 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5063 reseat_at_next_visible_line_start (it
, 0);
5066 xassert (it
->len
!= 0);
5067 IT_BYTEPOS (*it
) += it
->len
;
5068 IT_CHARPOS (*it
) += 1;
5069 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5072 else if (it
->method
== next_element_from_composition
)
5074 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5075 if (STRINGP (it
->string
))
5077 IT_STRING_BYTEPOS (*it
) += it
->len
;
5078 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5079 it
->method
= next_element_from_string
;
5080 goto consider_string_end
;
5084 IT_BYTEPOS (*it
) += it
->len
;
5085 IT_CHARPOS (*it
) += it
->cmp_len
;
5086 it
->method
= next_element_from_buffer
;
5089 else if (it
->method
== next_element_from_c_string
)
5091 /* Current display element of IT is from a C string. */
5092 IT_BYTEPOS (*it
) += it
->len
;
5093 IT_CHARPOS (*it
) += 1;
5095 else if (it
->method
== next_element_from_display_vector
)
5097 /* Current display element of IT is from a display table entry.
5098 Advance in the display table definition. Reset it to null if
5099 end reached, and continue with characters from buffers/
5101 ++it
->current
.dpvec_index
;
5103 /* Restore face of the iterator to what they were before the
5104 display vector entry (these entries may contain faces). */
5105 it
->face_id
= it
->saved_face_id
;
5107 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5110 it
->method
= next_element_from_c_string
;
5111 else if (STRINGP (it
->string
))
5112 it
->method
= next_element_from_string
;
5114 it
->method
= next_element_from_buffer
;
5117 it
->current
.dpvec_index
= -1;
5119 /* Skip over characters which were displayed via IT->dpvec. */
5120 if (it
->dpvec_char_len
< 0)
5121 reseat_at_next_visible_line_start (it
, 1);
5122 else if (it
->dpvec_char_len
> 0)
5124 it
->len
= it
->dpvec_char_len
;
5125 set_iterator_to_next (it
, reseat_p
);
5129 else if (it
->method
== next_element_from_string
)
5131 /* Current display element is a character from a Lisp string. */
5132 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5133 IT_STRING_BYTEPOS (*it
) += it
->len
;
5134 IT_STRING_CHARPOS (*it
) += 1;
5136 consider_string_end
:
5138 if (it
->current
.overlay_string_index
>= 0)
5140 /* IT->string is an overlay string. Advance to the
5141 next, if there is one. */
5142 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5143 next_overlay_string (it
);
5147 /* IT->string is not an overlay string. If we reached
5148 its end, and there is something on IT->stack, proceed
5149 with what is on the stack. This can be either another
5150 string, this time an overlay string, or a buffer. */
5151 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5155 if (!STRINGP (it
->string
))
5156 it
->method
= next_element_from_buffer
;
5158 goto consider_string_end
;
5162 else if (it
->method
== next_element_from_image
5163 || it
->method
== next_element_from_stretch
)
5165 /* The position etc with which we have to proceed are on
5166 the stack. The position may be at the end of a string,
5167 if the `display' property takes up the whole string. */
5170 if (STRINGP (it
->string
))
5172 it
->method
= next_element_from_string
;
5173 goto consider_string_end
;
5176 it
->method
= next_element_from_buffer
;
5179 /* There are no other methods defined, so this should be a bug. */
5182 xassert (it
->method
!= next_element_from_string
5183 || (STRINGP (it
->string
)
5184 && IT_STRING_CHARPOS (*it
) >= 0));
5188 /* Load IT's display element fields with information about the next
5189 display element which comes from a display table entry or from the
5190 result of translating a control character to one of the forms `^C'
5191 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5194 next_element_from_display_vector (it
)
5198 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5200 /* Remember the current face id in case glyphs specify faces.
5201 IT's face is restored in set_iterator_to_next. */
5202 it
->saved_face_id
= it
->face_id
;
5204 if (INTEGERP (*it
->dpvec
)
5205 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5210 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5211 it
->c
= FAST_GLYPH_CHAR (g
);
5212 it
->len
= CHAR_BYTES (it
->c
);
5214 /* The entry may contain a face id to use. Such a face id is
5215 the id of a Lisp face, not a realized face. A face id of
5216 zero means no face is specified. */
5217 lface_id
= FAST_GLYPH_FACE (g
);
5220 /* The function returns -1 if lface_id is invalid. */
5221 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5223 it
->face_id
= face_id
;
5227 /* Display table entry is invalid. Return a space. */
5228 it
->c
= ' ', it
->len
= 1;
5230 /* Don't change position and object of the iterator here. They are
5231 still the values of the character that had this display table
5232 entry or was translated, and that's what we want. */
5233 it
->what
= IT_CHARACTER
;
5238 /* Load IT with the next display element from Lisp string IT->string.
5239 IT->current.string_pos is the current position within the string.
5240 If IT->current.overlay_string_index >= 0, the Lisp string is an
5244 next_element_from_string (it
)
5247 struct text_pos position
;
5249 xassert (STRINGP (it
->string
));
5250 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5251 position
= it
->current
.string_pos
;
5253 /* Time to check for invisible text? */
5254 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5255 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5259 /* Since a handler may have changed IT->method, we must
5261 return get_next_display_element (it
);
5264 if (it
->current
.overlay_string_index
>= 0)
5266 /* Get the next character from an overlay string. In overlay
5267 strings, There is no field width or padding with spaces to
5269 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5274 else if (STRING_MULTIBYTE (it
->string
))
5276 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5277 const unsigned char *s
= (SDATA (it
->string
)
5278 + IT_STRING_BYTEPOS (*it
));
5279 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5283 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5289 /* Get the next character from a Lisp string that is not an
5290 overlay string. Such strings come from the mode line, for
5291 example. We may have to pad with spaces, or truncate the
5292 string. See also next_element_from_c_string. */
5293 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5298 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5300 /* Pad with spaces. */
5301 it
->c
= ' ', it
->len
= 1;
5302 CHARPOS (position
) = BYTEPOS (position
) = -1;
5304 else if (STRING_MULTIBYTE (it
->string
))
5306 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5307 const unsigned char *s
= (SDATA (it
->string
)
5308 + IT_STRING_BYTEPOS (*it
));
5309 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5313 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5318 /* Record what we have and where it came from. Note that we store a
5319 buffer position in IT->position although it could arguably be a
5321 it
->what
= IT_CHARACTER
;
5322 it
->object
= it
->string
;
5323 it
->position
= position
;
5328 /* Load IT with next display element from C string IT->s.
5329 IT->string_nchars is the maximum number of characters to return
5330 from the string. IT->end_charpos may be greater than
5331 IT->string_nchars when this function is called, in which case we
5332 may have to return padding spaces. Value is zero if end of string
5333 reached, including padding spaces. */
5336 next_element_from_c_string (it
)
5342 it
->what
= IT_CHARACTER
;
5343 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5346 /* IT's position can be greater IT->string_nchars in case a field
5347 width or precision has been specified when the iterator was
5349 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5351 /* End of the game. */
5355 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5357 /* Pad with spaces. */
5358 it
->c
= ' ', it
->len
= 1;
5359 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5361 else if (it
->multibyte_p
)
5363 /* Implementation note: The calls to strlen apparently aren't a
5364 performance problem because there is no noticeable performance
5365 difference between Emacs running in unibyte or multibyte mode. */
5366 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5367 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5371 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5377 /* Set up IT to return characters from an ellipsis, if appropriate.
5378 The definition of the ellipsis glyphs may come from a display table
5379 entry. This function Fills IT with the first glyph from the
5380 ellipsis if an ellipsis is to be displayed. */
5383 next_element_from_ellipsis (it
)
5386 if (it
->selective_display_ellipsis_p
)
5388 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5390 /* Use the display table definition for `...'. Invalid glyphs
5391 will be handled by the method returning elements from dpvec. */
5392 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5393 it
->dpvec_char_len
= it
->len
;
5394 it
->dpvec
= v
->contents
;
5395 it
->dpend
= v
->contents
+ v
->size
;
5396 it
->current
.dpvec_index
= 0;
5397 it
->method
= next_element_from_display_vector
;
5401 /* Use default `...' which is stored in default_invis_vector. */
5402 it
->dpvec_char_len
= it
->len
;
5403 it
->dpvec
= default_invis_vector
;
5404 it
->dpend
= default_invis_vector
+ 3;
5405 it
->current
.dpvec_index
= 0;
5406 it
->method
= next_element_from_display_vector
;
5411 /* The face at the current position may be different from the
5412 face we find after the invisible text. Remember what it
5413 was in IT->saved_face_id, and signal that it's there by
5414 setting face_before_selective_p. */
5415 it
->saved_face_id
= it
->face_id
;
5416 it
->method
= next_element_from_buffer
;
5417 reseat_at_next_visible_line_start (it
, 1);
5418 it
->face_before_selective_p
= 1;
5421 return get_next_display_element (it
);
5425 /* Deliver an image display element. The iterator IT is already
5426 filled with image information (done in handle_display_prop). Value
5431 next_element_from_image (it
)
5434 it
->what
= IT_IMAGE
;
5439 /* Fill iterator IT with next display element from a stretch glyph
5440 property. IT->object is the value of the text property. Value is
5444 next_element_from_stretch (it
)
5447 it
->what
= IT_STRETCH
;
5452 /* Load IT with the next display element from current_buffer. Value
5453 is zero if end of buffer reached. IT->stop_charpos is the next
5454 position at which to stop and check for text properties or buffer
5458 next_element_from_buffer (it
)
5463 /* Check this assumption, otherwise, we would never enter the
5464 if-statement, below. */
5465 xassert (IT_CHARPOS (*it
) >= BEGV
5466 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5468 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5470 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5472 int overlay_strings_follow_p
;
5474 /* End of the game, except when overlay strings follow that
5475 haven't been returned yet. */
5476 if (it
->overlay_strings_at_end_processed_p
)
5477 overlay_strings_follow_p
= 0;
5480 it
->overlay_strings_at_end_processed_p
= 1;
5481 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5484 if (overlay_strings_follow_p
)
5485 success_p
= get_next_display_element (it
);
5489 it
->position
= it
->current
.pos
;
5496 return get_next_display_element (it
);
5501 /* No face changes, overlays etc. in sight, so just return a
5502 character from current_buffer. */
5505 /* Maybe run the redisplay end trigger hook. Performance note:
5506 This doesn't seem to cost measurable time. */
5507 if (it
->redisplay_end_trigger_charpos
5509 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5510 run_redisplay_end_trigger_hook (it
);
5512 /* Get the next character, maybe multibyte. */
5513 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5514 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5516 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5517 - IT_BYTEPOS (*it
));
5518 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5521 it
->c
= *p
, it
->len
= 1;
5523 /* Record what we have and where it came from. */
5524 it
->what
= IT_CHARACTER
;;
5525 it
->object
= it
->w
->buffer
;
5526 it
->position
= it
->current
.pos
;
5528 /* Normally we return the character found above, except when we
5529 really want to return an ellipsis for selective display. */
5534 /* A value of selective > 0 means hide lines indented more
5535 than that number of columns. */
5536 if (it
->selective
> 0
5537 && IT_CHARPOS (*it
) + 1 < ZV
5538 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5539 IT_BYTEPOS (*it
) + 1,
5540 (double) it
->selective
)) /* iftc */
5542 success_p
= next_element_from_ellipsis (it
);
5543 it
->dpvec_char_len
= -1;
5546 else if (it
->c
== '\r' && it
->selective
== -1)
5548 /* A value of selective == -1 means that everything from the
5549 CR to the end of the line is invisible, with maybe an
5550 ellipsis displayed for it. */
5551 success_p
= next_element_from_ellipsis (it
);
5552 it
->dpvec_char_len
= -1;
5557 /* Value is zero if end of buffer reached. */
5558 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5563 /* Run the redisplay end trigger hook for IT. */
5566 run_redisplay_end_trigger_hook (it
)
5569 Lisp_Object args
[3];
5571 /* IT->glyph_row should be non-null, i.e. we should be actually
5572 displaying something, or otherwise we should not run the hook. */
5573 xassert (it
->glyph_row
);
5575 /* Set up hook arguments. */
5576 args
[0] = Qredisplay_end_trigger_functions
;
5577 args
[1] = it
->window
;
5578 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5579 it
->redisplay_end_trigger_charpos
= 0;
5581 /* Since we are *trying* to run these functions, don't try to run
5582 them again, even if they get an error. */
5583 it
->w
->redisplay_end_trigger
= Qnil
;
5584 Frun_hook_with_args (3, args
);
5586 /* Notice if it changed the face of the character we are on. */
5587 handle_face_prop (it
);
5591 /* Deliver a composition display element. The iterator IT is already
5592 filled with composition information (done in
5593 handle_composition_prop). Value is always 1. */
5596 next_element_from_composition (it
)
5599 it
->what
= IT_COMPOSITION
;
5600 it
->position
= (STRINGP (it
->string
)
5601 ? it
->current
.string_pos
5608 /***********************************************************************
5609 Moving an iterator without producing glyphs
5610 ***********************************************************************/
5612 /* Move iterator IT to a specified buffer or X position within one
5613 line on the display without producing glyphs.
5615 OP should be a bit mask including some or all of these bits:
5616 MOVE_TO_X: Stop on reaching x-position TO_X.
5617 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5618 Regardless of OP's value, stop in reaching the end of the display line.
5620 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5621 This means, in particular, that TO_X includes window's horizontal
5624 The return value has several possible values that
5625 say what condition caused the scan to stop:
5627 MOVE_POS_MATCH_OR_ZV
5628 - when TO_POS or ZV was reached.
5631 -when TO_X was reached before TO_POS or ZV were reached.
5634 - when we reached the end of the display area and the line must
5638 - when we reached the end of the display area and the line is
5642 - when we stopped at a line end, i.e. a newline or a CR and selective
5645 static enum move_it_result
5646 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5648 int to_charpos
, to_x
, op
;
5650 enum move_it_result result
= MOVE_UNDEFINED
;
5651 struct glyph_row
*saved_glyph_row
;
5653 /* Don't produce glyphs in produce_glyphs. */
5654 saved_glyph_row
= it
->glyph_row
;
5655 it
->glyph_row
= NULL
;
5657 #define BUFFER_POS_REACHED_P() \
5658 ((op & MOVE_TO_POS) != 0 \
5659 && BUFFERP (it->object) \
5660 && IT_CHARPOS (*it) >= to_charpos)
5664 int x
, i
, ascent
= 0, descent
= 0;
5666 /* Stop when ZV reached.
5667 We used to stop here when TO_CHARPOS reached as well, but that is
5668 too soon if this glyph does not fit on this line. So we handle it
5669 explicitly below. */
5670 if (!get_next_display_element (it
)
5671 || (it
->truncate_lines_p
5672 && BUFFER_POS_REACHED_P ()))
5674 result
= MOVE_POS_MATCH_OR_ZV
;
5678 /* The call to produce_glyphs will get the metrics of the
5679 display element IT is loaded with. We record in x the
5680 x-position before this display element in case it does not
5684 /* Remember the line height so far in case the next element doesn't
5686 if (!it
->truncate_lines_p
)
5688 ascent
= it
->max_ascent
;
5689 descent
= it
->max_descent
;
5692 PRODUCE_GLYPHS (it
);
5694 if (it
->area
!= TEXT_AREA
)
5696 set_iterator_to_next (it
, 1);
5700 /* The number of glyphs we get back in IT->nglyphs will normally
5701 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5702 character on a terminal frame, or (iii) a line end. For the
5703 second case, IT->nglyphs - 1 padding glyphs will be present
5704 (on X frames, there is only one glyph produced for a
5705 composite character.
5707 The behavior implemented below means, for continuation lines,
5708 that as many spaces of a TAB as fit on the current line are
5709 displayed there. For terminal frames, as many glyphs of a
5710 multi-glyph character are displayed in the current line, too.
5711 This is what the old redisplay code did, and we keep it that
5712 way. Under X, the whole shape of a complex character must
5713 fit on the line or it will be completely displayed in the
5716 Note that both for tabs and padding glyphs, all glyphs have
5720 /* More than one glyph or glyph doesn't fit on line. All
5721 glyphs have the same width. */
5722 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5725 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5727 new_x
= x
+ single_glyph_width
;
5729 /* We want to leave anything reaching TO_X to the caller. */
5730 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5732 if (BUFFER_POS_REACHED_P ())
5733 goto buffer_pos_reached
;
5735 result
= MOVE_X_REACHED
;
5738 else if (/* Lines are continued. */
5739 !it
->truncate_lines_p
5740 && (/* And glyph doesn't fit on the line. */
5741 new_x
> it
->last_visible_x
5742 /* Or it fits exactly and we're on a window
5744 || (new_x
== it
->last_visible_x
5745 && FRAME_WINDOW_P (it
->f
))))
5747 if (/* IT->hpos == 0 means the very first glyph
5748 doesn't fit on the line, e.g. a wide image. */
5750 || (new_x
== it
->last_visible_x
5751 && FRAME_WINDOW_P (it
->f
)))
5754 it
->current_x
= new_x
;
5755 if (i
== it
->nglyphs
- 1)
5757 set_iterator_to_next (it
, 1);
5758 #ifdef HAVE_WINDOW_SYSTEM
5759 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5761 if (!get_next_display_element (it
))
5763 result
= MOVE_POS_MATCH_OR_ZV
;
5766 if (BUFFER_POS_REACHED_P ())
5768 if (ITERATOR_AT_END_OF_LINE_P (it
))
5769 result
= MOVE_POS_MATCH_OR_ZV
;
5771 result
= MOVE_LINE_CONTINUED
;
5774 if (ITERATOR_AT_END_OF_LINE_P (it
))
5776 result
= MOVE_NEWLINE_OR_CR
;
5779 if (it
->method
== next_element_from_display_vector
)
5780 it
->face_id
= it
->saved_face_id
;
5782 #endif /* HAVE_WINDOW_SYSTEM */
5788 it
->max_ascent
= ascent
;
5789 it
->max_descent
= descent
;
5792 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5794 result
= MOVE_LINE_CONTINUED
;
5797 else if (BUFFER_POS_REACHED_P ())
5798 goto buffer_pos_reached
;
5799 else if (new_x
> it
->first_visible_x
)
5801 /* Glyph is visible. Increment number of glyphs that
5802 would be displayed. */
5807 /* Glyph is completely off the left margin of the display
5808 area. Nothing to do. */
5812 if (result
!= MOVE_UNDEFINED
)
5815 else if (BUFFER_POS_REACHED_P ())
5819 it
->max_ascent
= ascent
;
5820 it
->max_descent
= descent
;
5821 result
= MOVE_POS_MATCH_OR_ZV
;
5824 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5826 /* Stop when TO_X specified and reached. This check is
5827 necessary here because of lines consisting of a line end,
5828 only. The line end will not produce any glyphs and we
5829 would never get MOVE_X_REACHED. */
5830 xassert (it
->nglyphs
== 0);
5831 result
= MOVE_X_REACHED
;
5835 /* Is this a line end? If yes, we're done. */
5836 if (ITERATOR_AT_END_OF_LINE_P (it
))
5838 result
= MOVE_NEWLINE_OR_CR
;
5842 /* The current display element has been consumed. Advance
5844 set_iterator_to_next (it
, 1);
5846 /* Stop if lines are truncated and IT's current x-position is
5847 past the right edge of the window now. */
5848 if (it
->truncate_lines_p
5849 && it
->current_x
>= it
->last_visible_x
)
5851 #ifdef HAVE_WINDOW_SYSTEM
5852 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5854 if (!get_next_display_element (it
)
5855 || BUFFER_POS_REACHED_P ())
5857 result
= MOVE_POS_MATCH_OR_ZV
;
5860 if (ITERATOR_AT_END_OF_LINE_P (it
))
5862 result
= MOVE_NEWLINE_OR_CR
;
5866 #endif /* HAVE_WINDOW_SYSTEM */
5867 result
= MOVE_LINE_TRUNCATED
;
5872 #undef BUFFER_POS_REACHED_P
5874 /* Restore the iterator settings altered at the beginning of this
5876 it
->glyph_row
= saved_glyph_row
;
5881 /* Move IT forward until it satisfies one or more of the criteria in
5882 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5884 OP is a bit-mask that specifies where to stop, and in particular,
5885 which of those four position arguments makes a difference. See the
5886 description of enum move_operation_enum.
5888 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5889 screen line, this function will set IT to the next position >
5893 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5895 int to_charpos
, to_x
, to_y
, to_vpos
;
5898 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5904 if (op
& MOVE_TO_VPOS
)
5906 /* If no TO_CHARPOS and no TO_X specified, stop at the
5907 start of the line TO_VPOS. */
5908 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5910 if (it
->vpos
== to_vpos
)
5916 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5920 /* TO_VPOS >= 0 means stop at TO_X in the line at
5921 TO_VPOS, or at TO_POS, whichever comes first. */
5922 if (it
->vpos
== to_vpos
)
5928 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5930 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5935 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5937 /* We have reached TO_X but not in the line we want. */
5938 skip
= move_it_in_display_line_to (it
, to_charpos
,
5940 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5948 else if (op
& MOVE_TO_Y
)
5950 struct it it_backup
;
5952 /* TO_Y specified means stop at TO_X in the line containing
5953 TO_Y---or at TO_CHARPOS if this is reached first. The
5954 problem is that we can't really tell whether the line
5955 contains TO_Y before we have completely scanned it, and
5956 this may skip past TO_X. What we do is to first scan to
5959 If TO_X is not specified, use a TO_X of zero. The reason
5960 is to make the outcome of this function more predictable.
5961 If we didn't use TO_X == 0, we would stop at the end of
5962 the line which is probably not what a caller would expect
5964 skip
= move_it_in_display_line_to (it
, to_charpos
,
5968 | (op
& MOVE_TO_POS
)));
5970 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5971 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5977 /* If TO_X was reached, we would like to know whether TO_Y
5978 is in the line. This can only be said if we know the
5979 total line height which requires us to scan the rest of
5981 if (skip
== MOVE_X_REACHED
)
5984 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5985 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5987 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5990 /* Now, decide whether TO_Y is in this line. */
5991 line_height
= it
->max_ascent
+ it
->max_descent
;
5992 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5994 if (to_y
>= it
->current_y
5995 && to_y
< it
->current_y
+ line_height
)
5997 if (skip
== MOVE_X_REACHED
)
5998 /* If TO_Y is in this line and TO_X was reached above,
5999 we scanned too far. We have to restore IT's settings
6000 to the ones before skipping. */
6004 else if (skip
== MOVE_X_REACHED
)
6007 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6015 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6019 case MOVE_POS_MATCH_OR_ZV
:
6023 case MOVE_NEWLINE_OR_CR
:
6024 set_iterator_to_next (it
, 1);
6025 it
->continuation_lines_width
= 0;
6028 case MOVE_LINE_TRUNCATED
:
6029 it
->continuation_lines_width
= 0;
6030 reseat_at_next_visible_line_start (it
, 0);
6031 if ((op
& MOVE_TO_POS
) != 0
6032 && IT_CHARPOS (*it
) > to_charpos
)
6039 case MOVE_LINE_CONTINUED
:
6040 it
->continuation_lines_width
+= it
->current_x
;
6047 /* Reset/increment for the next run. */
6048 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6049 it
->current_x
= it
->hpos
= 0;
6050 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6052 last_height
= it
->max_ascent
+ it
->max_descent
;
6053 last_max_ascent
= it
->max_ascent
;
6054 it
->max_ascent
= it
->max_descent
= 0;
6059 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6063 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6065 If DY > 0, move IT backward at least that many pixels. DY = 0
6066 means move IT backward to the preceding line start or BEGV. This
6067 function may move over more than DY pixels if IT->current_y - DY
6068 ends up in the middle of a line; in this case IT->current_y will be
6069 set to the top of the line moved to. */
6072 move_it_vertically_backward (it
, dy
)
6083 start_pos
= IT_CHARPOS (*it
);
6085 /* Estimate how many newlines we must move back. */
6086 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6088 /* Set the iterator's position that many lines back. */
6089 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6090 back_to_previous_visible_line_start (it
);
6092 /* Reseat the iterator here. When moving backward, we don't want
6093 reseat to skip forward over invisible text, set up the iterator
6094 to deliver from overlay strings at the new position etc. So,
6095 use reseat_1 here. */
6096 reseat_1 (it
, it
->current
.pos
, 1);
6098 /* We are now surely at a line start. */
6099 it
->current_x
= it
->hpos
= 0;
6100 it
->continuation_lines_width
= 0;
6102 /* Move forward and see what y-distance we moved. First move to the
6103 start of the next line so that we get its height. We need this
6104 height to be able to tell whether we reached the specified
6107 it2
.max_ascent
= it2
.max_descent
= 0;
6108 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6109 MOVE_TO_POS
| MOVE_TO_VPOS
);
6110 xassert (IT_CHARPOS (*it
) >= BEGV
);
6113 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6114 xassert (IT_CHARPOS (*it
) >= BEGV
);
6115 /* H is the actual vertical distance from the position in *IT
6116 and the starting position. */
6117 h
= it2
.current_y
- it
->current_y
;
6118 /* NLINES is the distance in number of lines. */
6119 nlines
= it2
.vpos
- it
->vpos
;
6121 /* Correct IT's y and vpos position
6122 so that they are relative to the starting point. */
6128 /* DY == 0 means move to the start of the screen line. The
6129 value of nlines is > 0 if continuation lines were involved. */
6131 move_it_by_lines (it
, nlines
, 1);
6132 xassert (IT_CHARPOS (*it
) <= start_pos
);
6136 /* The y-position we try to reach, relative to *IT.
6137 Note that H has been subtracted in front of the if-statement. */
6138 int target_y
= it
->current_y
+ h
- dy
;
6139 int y0
= it3
.current_y
;
6140 int y1
= line_bottom_y (&it3
);
6141 int line_height
= y1
- y0
;
6143 /* If we did not reach target_y, try to move further backward if
6144 we can. If we moved too far backward, try to move forward. */
6145 if (target_y
< it
->current_y
6146 /* This is heuristic. In a window that's 3 lines high, with
6147 a line height of 13 pixels each, recentering with point
6148 on the bottom line will try to move -39/2 = 19 pixels
6149 backward. Try to avoid moving into the first line. */
6150 && it
->current_y
- target_y
> line_height
* 2 / 3
6151 && IT_CHARPOS (*it
) > BEGV
)
6153 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6154 target_y
- it
->current_y
));
6155 dy
= it
->current_y
- target_y
;
6156 goto move_further_back
;
6158 else if (target_y
>= it
->current_y
+ line_height
6159 && IT_CHARPOS (*it
) < ZV
)
6161 /* Should move forward by at least one line, maybe more.
6163 Note: Calling move_it_by_lines can be expensive on
6164 terminal frames, where compute_motion is used (via
6165 vmotion) to do the job, when there are very long lines
6166 and truncate-lines is nil. That's the reason for
6167 treating terminal frames specially here. */
6169 if (!FRAME_WINDOW_P (it
->f
))
6170 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6175 move_it_by_lines (it
, 1, 1);
6177 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6180 xassert (IT_CHARPOS (*it
) >= BEGV
);
6186 /* Move IT by a specified amount of pixel lines DY. DY negative means
6187 move backwards. DY = 0 means move to start of screen line. At the
6188 end, IT will be on the start of a screen line. */
6191 move_it_vertically (it
, dy
)
6196 move_it_vertically_backward (it
, -dy
);
6199 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6200 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6201 MOVE_TO_POS
| MOVE_TO_Y
);
6202 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6204 /* If buffer ends in ZV without a newline, move to the start of
6205 the line to satisfy the post-condition. */
6206 if (IT_CHARPOS (*it
) == ZV
6207 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6208 move_it_by_lines (it
, 0, 0);
6213 /* Move iterator IT past the end of the text line it is in. */
6216 move_it_past_eol (it
)
6219 enum move_it_result rc
;
6221 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6222 if (rc
== MOVE_NEWLINE_OR_CR
)
6223 set_iterator_to_next (it
, 0);
6227 #if 0 /* Currently not used. */
6229 /* Return non-zero if some text between buffer positions START_CHARPOS
6230 and END_CHARPOS is invisible. IT->window is the window for text
6234 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6236 int start_charpos
, end_charpos
;
6238 Lisp_Object prop
, limit
;
6239 int invisible_found_p
;
6241 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6243 /* Is text at START invisible? */
6244 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6246 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6247 invisible_found_p
= 1;
6250 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6252 make_number (end_charpos
));
6253 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6256 return invisible_found_p
;
6262 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6263 negative means move up. DVPOS == 0 means move to the start of the
6264 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6265 NEED_Y_P is zero, IT->current_y will be left unchanged.
6267 Further optimization ideas: If we would know that IT->f doesn't use
6268 a face with proportional font, we could be faster for
6269 truncate-lines nil. */
6272 move_it_by_lines (it
, dvpos
, need_y_p
)
6274 int dvpos
, need_y_p
;
6276 struct position pos
;
6278 if (!FRAME_WINDOW_P (it
->f
))
6280 struct text_pos textpos
;
6282 /* We can use vmotion on frames without proportional fonts. */
6283 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6284 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6285 reseat (it
, textpos
, 1);
6286 it
->vpos
+= pos
.vpos
;
6287 it
->current_y
+= pos
.vpos
;
6289 else if (dvpos
== 0)
6291 /* DVPOS == 0 means move to the start of the screen line. */
6292 move_it_vertically_backward (it
, 0);
6293 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6294 /* Let next call to line_bottom_y calculate real line height */
6298 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6302 int start_charpos
, i
;
6304 /* Start at the beginning of the screen line containing IT's
6306 move_it_vertically_backward (it
, 0);
6308 /* Go back -DVPOS visible lines and reseat the iterator there. */
6309 start_charpos
= IT_CHARPOS (*it
);
6310 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6311 back_to_previous_visible_line_start (it
);
6312 reseat (it
, it
->current
.pos
, 1);
6313 it
->current_x
= it
->hpos
= 0;
6315 /* Above call may have moved too far if continuation lines
6316 are involved. Scan forward and see if it did. */
6318 it2
.vpos
= it2
.current_y
= 0;
6319 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6320 it
->vpos
-= it2
.vpos
;
6321 it
->current_y
-= it2
.current_y
;
6322 it
->current_x
= it
->hpos
= 0;
6324 /* If we moved too far, move IT some lines forward. */
6325 if (it2
.vpos
> -dvpos
)
6327 int delta
= it2
.vpos
+ dvpos
;
6328 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6333 /* Return 1 if IT points into the middle of a display vector. */
6336 in_display_vector_p (it
)
6339 return (it
->method
== next_element_from_display_vector
6340 && it
->current
.dpvec_index
> 0
6341 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6345 /***********************************************************************
6347 ***********************************************************************/
6350 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6354 add_to_log (format
, arg1
, arg2
)
6356 Lisp_Object arg1
, arg2
;
6358 Lisp_Object args
[3];
6359 Lisp_Object msg
, fmt
;
6362 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6365 /* Do nothing if called asynchronously. Inserting text into
6366 a buffer may call after-change-functions and alike and
6367 that would means running Lisp asynchronously. */
6368 if (handling_signal
)
6372 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6374 args
[0] = fmt
= build_string (format
);
6377 msg
= Fformat (3, args
);
6379 len
= SBYTES (msg
) + 1;
6380 SAFE_ALLOCA (buffer
, char *, len
);
6381 bcopy (SDATA (msg
), buffer
, len
);
6383 message_dolog (buffer
, len
- 1, 1, 0);
6390 /* Output a newline in the *Messages* buffer if "needs" one. */
6393 message_log_maybe_newline ()
6395 if (message_log_need_newline
)
6396 message_dolog ("", 0, 1, 0);
6400 /* Add a string M of length NBYTES to the message log, optionally
6401 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6402 nonzero, means interpret the contents of M as multibyte. This
6403 function calls low-level routines in order to bypass text property
6404 hooks, etc. which might not be safe to run. */
6407 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6409 int nbytes
, nlflag
, multibyte
;
6411 if (!NILP (Vmemory_full
))
6414 if (!NILP (Vmessage_log_max
))
6416 struct buffer
*oldbuf
;
6417 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6418 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6419 int point_at_end
= 0;
6421 Lisp_Object old_deactivate_mark
, tem
;
6422 struct gcpro gcpro1
;
6424 old_deactivate_mark
= Vdeactivate_mark
;
6425 oldbuf
= current_buffer
;
6426 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6427 current_buffer
->undo_list
= Qt
;
6429 oldpoint
= message_dolog_marker1
;
6430 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6431 oldbegv
= message_dolog_marker2
;
6432 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6433 oldzv
= message_dolog_marker3
;
6434 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6435 GCPRO1 (old_deactivate_mark
);
6443 BEGV_BYTE
= BEG_BYTE
;
6446 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6448 /* Insert the string--maybe converting multibyte to single byte
6449 or vice versa, so that all the text fits the buffer. */
6451 && NILP (current_buffer
->enable_multibyte_characters
))
6453 int i
, c
, char_bytes
;
6454 unsigned char work
[1];
6456 /* Convert a multibyte string to single-byte
6457 for the *Message* buffer. */
6458 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6460 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6461 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6463 : multibyte_char_to_unibyte (c
, Qnil
));
6464 insert_1_both (work
, 1, 1, 1, 0, 0);
6467 else if (! multibyte
6468 && ! NILP (current_buffer
->enable_multibyte_characters
))
6470 int i
, c
, char_bytes
;
6471 unsigned char *msg
= (unsigned char *) m
;
6472 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6473 /* Convert a single-byte string to multibyte
6474 for the *Message* buffer. */
6475 for (i
= 0; i
< nbytes
; i
++)
6477 c
= unibyte_char_to_multibyte (msg
[i
]);
6478 char_bytes
= CHAR_STRING (c
, str
);
6479 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6483 insert_1 (m
, nbytes
, 1, 0, 0);
6487 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6488 insert_1 ("\n", 1, 1, 0, 0);
6490 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6492 this_bol_byte
= PT_BYTE
;
6494 /* See if this line duplicates the previous one.
6495 If so, combine duplicates. */
6498 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6500 prev_bol_byte
= PT_BYTE
;
6502 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6503 this_bol
, this_bol_byte
);
6506 del_range_both (prev_bol
, prev_bol_byte
,
6507 this_bol
, this_bol_byte
, 0);
6513 /* If you change this format, don't forget to also
6514 change message_log_check_duplicate. */
6515 sprintf (dupstr
, " [%d times]", dup
);
6516 duplen
= strlen (dupstr
);
6517 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6518 insert_1 (dupstr
, duplen
, 1, 0, 1);
6523 /* If we have more than the desired maximum number of lines
6524 in the *Messages* buffer now, delete the oldest ones.
6525 This is safe because we don't have undo in this buffer. */
6527 if (NATNUMP (Vmessage_log_max
))
6529 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6530 -XFASTINT (Vmessage_log_max
) - 1, 0);
6531 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6534 BEGV
= XMARKER (oldbegv
)->charpos
;
6535 BEGV_BYTE
= marker_byte_position (oldbegv
);
6544 ZV
= XMARKER (oldzv
)->charpos
;
6545 ZV_BYTE
= marker_byte_position (oldzv
);
6549 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6551 /* We can't do Fgoto_char (oldpoint) because it will run some
6553 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6554 XMARKER (oldpoint
)->bytepos
);
6557 unchain_marker (XMARKER (oldpoint
));
6558 unchain_marker (XMARKER (oldbegv
));
6559 unchain_marker (XMARKER (oldzv
));
6561 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6562 set_buffer_internal (oldbuf
);
6564 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6565 message_log_need_newline
= !nlflag
;
6566 Vdeactivate_mark
= old_deactivate_mark
;
6571 /* We are at the end of the buffer after just having inserted a newline.
6572 (Note: We depend on the fact we won't be crossing the gap.)
6573 Check to see if the most recent message looks a lot like the previous one.
6574 Return 0 if different, 1 if the new one should just replace it, or a
6575 value N > 1 if we should also append " [N times]". */
6578 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6579 int prev_bol
, this_bol
;
6580 int prev_bol_byte
, this_bol_byte
;
6583 int len
= Z_BYTE
- 1 - this_bol_byte
;
6585 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6586 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6588 for (i
= 0; i
< len
; i
++)
6590 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6598 if (*p1
++ == ' ' && *p1
++ == '[')
6601 while (*p1
>= '0' && *p1
<= '9')
6602 n
= n
* 10 + *p1
++ - '0';
6603 if (strncmp (p1
, " times]\n", 8) == 0)
6610 /* Display an echo area message M with a specified length of NBYTES
6611 bytes. The string may include null characters. If M is 0, clear
6612 out any existing message, and let the mini-buffer text show
6615 The buffer M must continue to exist until after the echo area gets
6616 cleared or some other message gets displayed there. This means do
6617 not pass text that is stored in a Lisp string; do not pass text in
6618 a buffer that was alloca'd. */
6621 message2 (m
, nbytes
, multibyte
)
6626 /* First flush out any partial line written with print. */
6627 message_log_maybe_newline ();
6629 message_dolog (m
, nbytes
, 1, multibyte
);
6630 message2_nolog (m
, nbytes
, multibyte
);
6634 /* The non-logging counterpart of message2. */
6637 message2_nolog (m
, nbytes
, multibyte
)
6639 int nbytes
, multibyte
;
6641 struct frame
*sf
= SELECTED_FRAME ();
6642 message_enable_multibyte
= multibyte
;
6646 if (noninteractive_need_newline
)
6647 putc ('\n', stderr
);
6648 noninteractive_need_newline
= 0;
6650 fwrite (m
, nbytes
, 1, stderr
);
6651 if (cursor_in_echo_area
== 0)
6652 fprintf (stderr
, "\n");
6655 /* A null message buffer means that the frame hasn't really been
6656 initialized yet. Error messages get reported properly by
6657 cmd_error, so this must be just an informative message; toss it. */
6658 else if (INTERACTIVE
6659 && sf
->glyphs_initialized_p
6660 && FRAME_MESSAGE_BUF (sf
))
6662 Lisp_Object mini_window
;
6665 /* Get the frame containing the mini-buffer
6666 that the selected frame is using. */
6667 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6668 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6670 FRAME_SAMPLE_VISIBILITY (f
);
6671 if (FRAME_VISIBLE_P (sf
)
6672 && ! FRAME_VISIBLE_P (f
))
6673 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6677 set_message (m
, Qnil
, nbytes
, multibyte
);
6678 if (minibuffer_auto_raise
)
6679 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6682 clear_message (1, 1);
6684 do_pending_window_change (0);
6685 echo_area_display (1);
6686 do_pending_window_change (0);
6687 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6688 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6693 /* Display an echo area message M with a specified length of NBYTES
6694 bytes. The string may include null characters. If M is not a
6695 string, clear out any existing message, and let the mini-buffer
6696 text show through. */
6699 message3 (m
, nbytes
, multibyte
)
6704 struct gcpro gcpro1
;
6707 clear_message (1,1);
6709 /* First flush out any partial line written with print. */
6710 message_log_maybe_newline ();
6712 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6713 message3_nolog (m
, nbytes
, multibyte
);
6719 /* The non-logging version of message3. */
6722 message3_nolog (m
, nbytes
, multibyte
)
6724 int nbytes
, multibyte
;
6726 struct frame
*sf
= SELECTED_FRAME ();
6727 message_enable_multibyte
= multibyte
;
6731 if (noninteractive_need_newline
)
6732 putc ('\n', stderr
);
6733 noninteractive_need_newline
= 0;
6735 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6736 if (cursor_in_echo_area
== 0)
6737 fprintf (stderr
, "\n");
6740 /* A null message buffer means that the frame hasn't really been
6741 initialized yet. Error messages get reported properly by
6742 cmd_error, so this must be just an informative message; toss it. */
6743 else if (INTERACTIVE
6744 && sf
->glyphs_initialized_p
6745 && FRAME_MESSAGE_BUF (sf
))
6747 Lisp_Object mini_window
;
6751 /* Get the frame containing the mini-buffer
6752 that the selected frame is using. */
6753 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6754 frame
= XWINDOW (mini_window
)->frame
;
6757 FRAME_SAMPLE_VISIBILITY (f
);
6758 if (FRAME_VISIBLE_P (sf
)
6759 && !FRAME_VISIBLE_P (f
))
6760 Fmake_frame_visible (frame
);
6762 if (STRINGP (m
) && SCHARS (m
) > 0)
6764 set_message (NULL
, m
, nbytes
, multibyte
);
6765 if (minibuffer_auto_raise
)
6766 Fraise_frame (frame
);
6769 clear_message (1, 1);
6771 do_pending_window_change (0);
6772 echo_area_display (1);
6773 do_pending_window_change (0);
6774 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6775 (*FRAME_DISPLAY (f
)->frame_up_to_date_hook
) (f
);
6780 /* Display a null-terminated echo area message M. If M is 0, clear
6781 out any existing message, and let the mini-buffer text show through.
6783 The buffer M must continue to exist until after the echo area gets
6784 cleared or some other message gets displayed there. Do not pass
6785 text that is stored in a Lisp string. Do not pass text in a buffer
6786 that was alloca'd. */
6792 message2 (m
, (m
? strlen (m
) : 0), 0);
6796 /* The non-logging counterpart of message1. */
6802 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6805 /* Display a message M which contains a single %s
6806 which gets replaced with STRING. */
6809 message_with_string (m
, string
, log
)
6814 CHECK_STRING (string
);
6820 if (noninteractive_need_newline
)
6821 putc ('\n', stderr
);
6822 noninteractive_need_newline
= 0;
6823 fprintf (stderr
, m
, SDATA (string
));
6824 if (cursor_in_echo_area
== 0)
6825 fprintf (stderr
, "\n");
6829 else if (INTERACTIVE
)
6831 /* The frame whose minibuffer we're going to display the message on.
6832 It may be larger than the selected frame, so we need
6833 to use its buffer, not the selected frame's buffer. */
6834 Lisp_Object mini_window
;
6835 struct frame
*f
, *sf
= SELECTED_FRAME ();
6837 /* Get the frame containing the minibuffer
6838 that the selected frame is using. */
6839 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6840 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6842 /* A null message buffer means that the frame hasn't really been
6843 initialized yet. Error messages get reported properly by
6844 cmd_error, so this must be just an informative message; toss it. */
6845 if (FRAME_MESSAGE_BUF (f
))
6847 Lisp_Object args
[2], message
;
6848 struct gcpro gcpro1
, gcpro2
;
6850 args
[0] = build_string (m
);
6851 args
[1] = message
= string
;
6852 GCPRO2 (args
[0], message
);
6855 message
= Fformat (2, args
);
6858 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6860 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6864 /* Print should start at the beginning of the message
6865 buffer next time. */
6866 message_buf_print
= 0;
6872 /* Dump an informative message to the minibuf. If M is 0, clear out
6873 any existing message, and let the mini-buffer text show through. */
6877 message (m
, a1
, a2
, a3
)
6879 EMACS_INT a1
, a2
, a3
;
6885 if (noninteractive_need_newline
)
6886 putc ('\n', stderr
);
6887 noninteractive_need_newline
= 0;
6888 fprintf (stderr
, m
, a1
, a2
, a3
);
6889 if (cursor_in_echo_area
== 0)
6890 fprintf (stderr
, "\n");
6894 else if (INTERACTIVE
)
6896 /* The frame whose mini-buffer we're going to display the message
6897 on. It may be larger than the selected frame, so we need to
6898 use its buffer, not the selected frame's buffer. */
6899 Lisp_Object mini_window
;
6900 struct frame
*f
, *sf
= SELECTED_FRAME ();
6902 /* Get the frame containing the mini-buffer
6903 that the selected frame is using. */
6904 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6905 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6907 /* A null message buffer means that the frame hasn't really been
6908 initialized yet. Error messages get reported properly by
6909 cmd_error, so this must be just an informative message; toss
6911 if (FRAME_MESSAGE_BUF (f
))
6922 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6923 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6925 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6926 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6928 #endif /* NO_ARG_ARRAY */
6930 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6935 /* Print should start at the beginning of the message
6936 buffer next time. */
6937 message_buf_print
= 0;
6943 /* The non-logging version of message. */
6946 message_nolog (m
, a1
, a2
, a3
)
6948 EMACS_INT a1
, a2
, a3
;
6950 Lisp_Object old_log_max
;
6951 old_log_max
= Vmessage_log_max
;
6952 Vmessage_log_max
= Qnil
;
6953 message (m
, a1
, a2
, a3
);
6954 Vmessage_log_max
= old_log_max
;
6958 /* Display the current message in the current mini-buffer. This is
6959 only called from error handlers in process.c, and is not time
6965 if (!NILP (echo_area_buffer
[0]))
6968 string
= Fcurrent_message ();
6969 message3 (string
, SBYTES (string
),
6970 !NILP (current_buffer
->enable_multibyte_characters
));
6975 /* Make sure echo area buffers in `echo_buffers' are live.
6976 If they aren't, make new ones. */
6979 ensure_echo_area_buffers ()
6983 for (i
= 0; i
< 2; ++i
)
6984 if (!BUFFERP (echo_buffer
[i
])
6985 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6988 Lisp_Object old_buffer
;
6991 old_buffer
= echo_buffer
[i
];
6992 sprintf (name
, " *Echo Area %d*", i
);
6993 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6994 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6996 for (j
= 0; j
< 2; ++j
)
6997 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6998 echo_area_buffer
[j
] = echo_buffer
[i
];
7003 /* Call FN with args A1..A4 with either the current or last displayed
7004 echo_area_buffer as current buffer.
7006 WHICH zero means use the current message buffer
7007 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7008 from echo_buffer[] and clear it.
7010 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7011 suitable buffer from echo_buffer[] and clear it.
7013 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7014 that the current message becomes the last displayed one, make
7015 choose a suitable buffer for echo_area_buffer[0], and clear it.
7017 Value is what FN returns. */
7020 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7023 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7029 int this_one
, the_other
, clear_buffer_p
, rc
;
7030 int count
= SPECPDL_INDEX ();
7032 /* If buffers aren't live, make new ones. */
7033 ensure_echo_area_buffers ();
7038 this_one
= 0, the_other
= 1;
7040 this_one
= 1, the_other
= 0;
7043 this_one
= 0, the_other
= 1;
7046 /* We need a fresh one in case the current echo buffer equals
7047 the one containing the last displayed echo area message. */
7048 if (!NILP (echo_area_buffer
[this_one
])
7049 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7050 echo_area_buffer
[this_one
] = Qnil
;
7053 /* Choose a suitable buffer from echo_buffer[] is we don't
7055 if (NILP (echo_area_buffer
[this_one
]))
7057 echo_area_buffer
[this_one
]
7058 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7059 ? echo_buffer
[the_other
]
7060 : echo_buffer
[this_one
]);
7064 buffer
= echo_area_buffer
[this_one
];
7066 /* Don't get confused by reusing the buffer used for echoing
7067 for a different purpose. */
7068 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7071 record_unwind_protect (unwind_with_echo_area_buffer
,
7072 with_echo_area_buffer_unwind_data (w
));
7074 /* Make the echo area buffer current. Note that for display
7075 purposes, it is not necessary that the displayed window's buffer
7076 == current_buffer, except for text property lookup. So, let's
7077 only set that buffer temporarily here without doing a full
7078 Fset_window_buffer. We must also change w->pointm, though,
7079 because otherwise an assertions in unshow_buffer fails, and Emacs
7081 set_buffer_internal_1 (XBUFFER (buffer
));
7085 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7088 current_buffer
->undo_list
= Qt
;
7089 current_buffer
->read_only
= Qnil
;
7090 specbind (Qinhibit_read_only
, Qt
);
7091 specbind (Qinhibit_modification_hooks
, Qt
);
7093 if (clear_buffer_p
&& Z
> BEG
)
7096 xassert (BEGV
>= BEG
);
7097 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7099 rc
= fn (a1
, a2
, a3
, a4
);
7101 xassert (BEGV
>= BEG
);
7102 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7104 unbind_to (count
, Qnil
);
7109 /* Save state that should be preserved around the call to the function
7110 FN called in with_echo_area_buffer. */
7113 with_echo_area_buffer_unwind_data (w
)
7119 /* Reduce consing by keeping one vector in
7120 Vwith_echo_area_save_vector. */
7121 vector
= Vwith_echo_area_save_vector
;
7122 Vwith_echo_area_save_vector
= Qnil
;
7125 vector
= Fmake_vector (make_number (7), Qnil
);
7127 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7128 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7129 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7133 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7134 AREF (vector
, i
) = w
->buffer
; ++i
;
7135 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7136 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7141 for (; i
< end
; ++i
)
7142 AREF (vector
, i
) = Qnil
;
7145 xassert (i
== ASIZE (vector
));
7150 /* Restore global state from VECTOR which was created by
7151 with_echo_area_buffer_unwind_data. */
7154 unwind_with_echo_area_buffer (vector
)
7157 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7158 Vdeactivate_mark
= AREF (vector
, 1);
7159 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7161 if (WINDOWP (AREF (vector
, 3)))
7164 Lisp_Object buffer
, charpos
, bytepos
;
7166 w
= XWINDOW (AREF (vector
, 3));
7167 buffer
= AREF (vector
, 4);
7168 charpos
= AREF (vector
, 5);
7169 bytepos
= AREF (vector
, 6);
7172 set_marker_both (w
->pointm
, buffer
,
7173 XFASTINT (charpos
), XFASTINT (bytepos
));
7176 Vwith_echo_area_save_vector
= vector
;
7181 /* Set up the echo area for use by print functions. MULTIBYTE_P
7182 non-zero means we will print multibyte. */
7185 setup_echo_area_for_printing (multibyte_p
)
7188 /* If we can't find an echo area any more, exit. */
7189 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7192 ensure_echo_area_buffers ();
7194 if (!message_buf_print
)
7196 /* A message has been output since the last time we printed.
7197 Choose a fresh echo area buffer. */
7198 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7199 echo_area_buffer
[0] = echo_buffer
[1];
7201 echo_area_buffer
[0] = echo_buffer
[0];
7203 /* Switch to that buffer and clear it. */
7204 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7205 current_buffer
->truncate_lines
= Qnil
;
7209 int count
= SPECPDL_INDEX ();
7210 specbind (Qinhibit_read_only
, Qt
);
7211 /* Note that undo recording is always disabled. */
7213 unbind_to (count
, Qnil
);
7215 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7217 /* Set up the buffer for the multibyteness we need. */
7219 != !NILP (current_buffer
->enable_multibyte_characters
))
7220 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7222 /* Raise the frame containing the echo area. */
7223 if (minibuffer_auto_raise
)
7225 struct frame
*sf
= SELECTED_FRAME ();
7226 Lisp_Object mini_window
;
7227 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7228 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7231 message_log_maybe_newline ();
7232 message_buf_print
= 1;
7236 if (NILP (echo_area_buffer
[0]))
7238 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7239 echo_area_buffer
[0] = echo_buffer
[1];
7241 echo_area_buffer
[0] = echo_buffer
[0];
7244 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7246 /* Someone switched buffers between print requests. */
7247 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7248 current_buffer
->truncate_lines
= Qnil
;
7254 /* Display an echo area message in window W. Value is non-zero if W's
7255 height is changed. If display_last_displayed_message_p is
7256 non-zero, display the message that was last displayed, otherwise
7257 display the current message. */
7260 display_echo_area (w
)
7263 int i
, no_message_p
, window_height_changed_p
, count
;
7265 /* Temporarily disable garbage collections while displaying the echo
7266 area. This is done because a GC can print a message itself.
7267 That message would modify the echo area buffer's contents while a
7268 redisplay of the buffer is going on, and seriously confuse
7270 count
= inhibit_garbage_collection ();
7272 /* If there is no message, we must call display_echo_area_1
7273 nevertheless because it resizes the window. But we will have to
7274 reset the echo_area_buffer in question to nil at the end because
7275 with_echo_area_buffer will sets it to an empty buffer. */
7276 i
= display_last_displayed_message_p
? 1 : 0;
7277 no_message_p
= NILP (echo_area_buffer
[i
]);
7279 window_height_changed_p
7280 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7281 display_echo_area_1
,
7282 (EMACS_INT
) w
, Qnil
, 0, 0);
7285 echo_area_buffer
[i
] = Qnil
;
7287 unbind_to (count
, Qnil
);
7288 return window_height_changed_p
;
7292 /* Helper for display_echo_area. Display the current buffer which
7293 contains the current echo area message in window W, a mini-window,
7294 a pointer to which is passed in A1. A2..A4 are currently not used.
7295 Change the height of W so that all of the message is displayed.
7296 Value is non-zero if height of W was changed. */
7299 display_echo_area_1 (a1
, a2
, a3
, a4
)
7304 struct window
*w
= (struct window
*) a1
;
7306 struct text_pos start
;
7307 int window_height_changed_p
= 0;
7309 /* Do this before displaying, so that we have a large enough glyph
7310 matrix for the display. */
7311 window_height_changed_p
= resize_mini_window (w
, 0);
7314 clear_glyph_matrix (w
->desired_matrix
);
7315 XSETWINDOW (window
, w
);
7316 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7317 try_window (window
, start
);
7319 return window_height_changed_p
;
7323 /* Resize the echo area window to exactly the size needed for the
7324 currently displayed message, if there is one. If a mini-buffer
7325 is active, don't shrink it. */
7328 resize_echo_area_exactly ()
7330 if (BUFFERP (echo_area_buffer
[0])
7331 && WINDOWP (echo_area_window
))
7333 struct window
*w
= XWINDOW (echo_area_window
);
7335 Lisp_Object resize_exactly
;
7337 if (minibuf_level
== 0)
7338 resize_exactly
= Qt
;
7340 resize_exactly
= Qnil
;
7342 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7343 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7346 ++windows_or_buffers_changed
;
7347 ++update_mode_lines
;
7348 redisplay_internal (0);
7354 /* Callback function for with_echo_area_buffer, when used from
7355 resize_echo_area_exactly. A1 contains a pointer to the window to
7356 resize, EXACTLY non-nil means resize the mini-window exactly to the
7357 size of the text displayed. A3 and A4 are not used. Value is what
7358 resize_mini_window returns. */
7361 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7363 Lisp_Object exactly
;
7366 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7370 /* Resize mini-window W to fit the size of its contents. EXACT:P
7371 means size the window exactly to the size needed. Otherwise, it's
7372 only enlarged until W's buffer is empty. Value is non-zero if
7373 the window height has been changed. */
7376 resize_mini_window (w
, exact_p
)
7380 struct frame
*f
= XFRAME (w
->frame
);
7381 int window_height_changed_p
= 0;
7383 xassert (MINI_WINDOW_P (w
));
7385 /* Don't resize windows while redisplaying a window; it would
7386 confuse redisplay functions when the size of the window they are
7387 displaying changes from under them. Such a resizing can happen,
7388 for instance, when which-func prints a long message while
7389 we are running fontification-functions. We're running these
7390 functions with safe_call which binds inhibit-redisplay to t. */
7391 if (!NILP (Vinhibit_redisplay
))
7394 /* Nil means don't try to resize. */
7395 if (NILP (Vresize_mini_windows
)
7396 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7399 if (!FRAME_MINIBUF_ONLY_P (f
))
7402 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7403 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7404 int height
, max_height
;
7405 int unit
= FRAME_LINE_HEIGHT (f
);
7406 struct text_pos start
;
7407 struct buffer
*old_current_buffer
= NULL
;
7409 if (current_buffer
!= XBUFFER (w
->buffer
))
7411 old_current_buffer
= current_buffer
;
7412 set_buffer_internal (XBUFFER (w
->buffer
));
7415 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7417 /* Compute the max. number of lines specified by the user. */
7418 if (FLOATP (Vmax_mini_window_height
))
7419 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7420 else if (INTEGERP (Vmax_mini_window_height
))
7421 max_height
= XINT (Vmax_mini_window_height
);
7423 max_height
= total_height
/ 4;
7425 /* Correct that max. height if it's bogus. */
7426 max_height
= max (1, max_height
);
7427 max_height
= min (total_height
, max_height
);
7429 /* Find out the height of the text in the window. */
7430 if (it
.truncate_lines_p
)
7435 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7436 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7437 height
= it
.current_y
+ last_height
;
7439 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7440 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7441 height
= (height
+ unit
- 1) / unit
;
7444 /* Compute a suitable window start. */
7445 if (height
> max_height
)
7447 height
= max_height
;
7448 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7449 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7450 start
= it
.current
.pos
;
7453 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7454 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7456 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7458 /* Let it grow only, until we display an empty message, in which
7459 case the window shrinks again. */
7460 if (height
> WINDOW_TOTAL_LINES (w
))
7462 int old_height
= WINDOW_TOTAL_LINES (w
);
7463 freeze_window_starts (f
, 1);
7464 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7465 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7467 else if (height
< WINDOW_TOTAL_LINES (w
)
7468 && (exact_p
|| BEGV
== ZV
))
7470 int old_height
= WINDOW_TOTAL_LINES (w
);
7471 freeze_window_starts (f
, 0);
7472 shrink_mini_window (w
);
7473 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7478 /* Always resize to exact size needed. */
7479 if (height
> WINDOW_TOTAL_LINES (w
))
7481 int old_height
= WINDOW_TOTAL_LINES (w
);
7482 freeze_window_starts (f
, 1);
7483 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7484 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7486 else if (height
< WINDOW_TOTAL_LINES (w
))
7488 int old_height
= WINDOW_TOTAL_LINES (w
);
7489 freeze_window_starts (f
, 0);
7490 shrink_mini_window (w
);
7494 freeze_window_starts (f
, 1);
7495 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7498 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7502 if (old_current_buffer
)
7503 set_buffer_internal (old_current_buffer
);
7506 return window_height_changed_p
;
7510 /* Value is the current message, a string, or nil if there is no
7518 if (NILP (echo_area_buffer
[0]))
7522 with_echo_area_buffer (0, 0, current_message_1
,
7523 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7525 echo_area_buffer
[0] = Qnil
;
7533 current_message_1 (a1
, a2
, a3
, a4
)
7538 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7541 *msg
= make_buffer_string (BEG
, Z
, 1);
7548 /* Push the current message on Vmessage_stack for later restauration
7549 by restore_message. Value is non-zero if the current message isn't
7550 empty. This is a relatively infrequent operation, so it's not
7551 worth optimizing. */
7557 msg
= current_message ();
7558 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7559 return STRINGP (msg
);
7563 /* Restore message display from the top of Vmessage_stack. */
7570 xassert (CONSP (Vmessage_stack
));
7571 msg
= XCAR (Vmessage_stack
);
7573 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7575 message3_nolog (msg
, 0, 0);
7579 /* Handler for record_unwind_protect calling pop_message. */
7582 pop_message_unwind (dummy
)
7589 /* Pop the top-most entry off Vmessage_stack. */
7594 xassert (CONSP (Vmessage_stack
));
7595 Vmessage_stack
= XCDR (Vmessage_stack
);
7599 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7600 exits. If the stack is not empty, we have a missing pop_message
7604 check_message_stack ()
7606 if (!NILP (Vmessage_stack
))
7611 /* Truncate to NCHARS what will be displayed in the echo area the next
7612 time we display it---but don't redisplay it now. */
7615 truncate_echo_area (nchars
)
7619 echo_area_buffer
[0] = Qnil
;
7620 /* A null message buffer means that the frame hasn't really been
7621 initialized yet. Error messages get reported properly by
7622 cmd_error, so this must be just an informative message; toss it. */
7623 else if (!noninteractive
7625 && !NILP (echo_area_buffer
[0]))
7627 struct frame
*sf
= SELECTED_FRAME ();
7628 if (FRAME_MESSAGE_BUF (sf
))
7629 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7634 /* Helper function for truncate_echo_area. Truncate the current
7635 message to at most NCHARS characters. */
7638 truncate_message_1 (nchars
, a2
, a3
, a4
)
7643 if (BEG
+ nchars
< Z
)
7644 del_range (BEG
+ nchars
, Z
);
7646 echo_area_buffer
[0] = Qnil
;
7651 /* Set the current message to a substring of S or STRING.
7653 If STRING is a Lisp string, set the message to the first NBYTES
7654 bytes from STRING. NBYTES zero means use the whole string. If
7655 STRING is multibyte, the message will be displayed multibyte.
7657 If S is not null, set the message to the first LEN bytes of S. LEN
7658 zero means use the whole string. MULTIBYTE_P non-zero means S is
7659 multibyte. Display the message multibyte in that case. */
7662 set_message (s
, string
, nbytes
, multibyte_p
)
7665 int nbytes
, multibyte_p
;
7667 message_enable_multibyte
7668 = ((s
&& multibyte_p
)
7669 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7671 with_echo_area_buffer (0, -1, set_message_1
,
7672 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7673 message_buf_print
= 0;
7674 help_echo_showing_p
= 0;
7678 /* Helper function for set_message. Arguments have the same meaning
7679 as there, with A1 corresponding to S and A2 corresponding to STRING
7680 This function is called with the echo area buffer being
7684 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7687 EMACS_INT nbytes
, multibyte_p
;
7689 const char *s
= (const char *) a1
;
7690 Lisp_Object string
= a2
;
7694 /* Change multibyteness of the echo buffer appropriately. */
7695 if (message_enable_multibyte
7696 != !NILP (current_buffer
->enable_multibyte_characters
))
7697 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7699 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7701 /* Insert new message at BEG. */
7702 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7704 if (STRINGP (string
))
7709 nbytes
= SBYTES (string
);
7710 nchars
= string_byte_to_char (string
, nbytes
);
7712 /* This function takes care of single/multibyte conversion. We
7713 just have to ensure that the echo area buffer has the right
7714 setting of enable_multibyte_characters. */
7715 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7720 nbytes
= strlen (s
);
7722 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7724 /* Convert from multi-byte to single-byte. */
7726 unsigned char work
[1];
7728 /* Convert a multibyte string to single-byte. */
7729 for (i
= 0; i
< nbytes
; i
+= n
)
7731 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7732 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7734 : multibyte_char_to_unibyte (c
, Qnil
));
7735 insert_1_both (work
, 1, 1, 1, 0, 0);
7738 else if (!multibyte_p
7739 && !NILP (current_buffer
->enable_multibyte_characters
))
7741 /* Convert from single-byte to multi-byte. */
7743 const unsigned char *msg
= (const unsigned char *) s
;
7744 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7746 /* Convert a single-byte string to multibyte. */
7747 for (i
= 0; i
< nbytes
; i
++)
7749 c
= unibyte_char_to_multibyte (msg
[i
]);
7750 n
= CHAR_STRING (c
, str
);
7751 insert_1_both (str
, 1, n
, 1, 0, 0);
7755 insert_1 (s
, nbytes
, 1, 0, 0);
7762 /* Clear messages. CURRENT_P non-zero means clear the current
7763 message. LAST_DISPLAYED_P non-zero means clear the message
7767 clear_message (current_p
, last_displayed_p
)
7768 int current_p
, last_displayed_p
;
7772 echo_area_buffer
[0] = Qnil
;
7773 message_cleared_p
= 1;
7776 if (last_displayed_p
)
7777 echo_area_buffer
[1] = Qnil
;
7779 message_buf_print
= 0;
7782 /* Clear garbaged frames.
7784 This function is used where the old redisplay called
7785 redraw_garbaged_frames which in turn called redraw_frame which in
7786 turn called clear_frame. The call to clear_frame was a source of
7787 flickering. I believe a clear_frame is not necessary. It should
7788 suffice in the new redisplay to invalidate all current matrices,
7789 and ensure a complete redisplay of all windows. */
7792 clear_garbaged_frames ()
7796 Lisp_Object tail
, frame
;
7797 int changed_count
= 0;
7799 FOR_EACH_FRAME (tail
, frame
)
7801 struct frame
*f
= XFRAME (frame
);
7803 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7807 Fredraw_frame (frame
);
7808 f
->force_flush_display_p
= 1;
7810 clear_current_matrices (f
);
7819 ++windows_or_buffers_changed
;
7824 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7825 is non-zero update selected_frame. Value is non-zero if the
7826 mini-windows height has been changed. */
7829 echo_area_display (update_frame_p
)
7832 Lisp_Object mini_window
;
7835 int window_height_changed_p
= 0;
7836 struct frame
*sf
= SELECTED_FRAME ();
7838 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7839 w
= XWINDOW (mini_window
);
7840 f
= XFRAME (WINDOW_FRAME (w
));
7842 /* Don't display if frame is invisible or not yet initialized. */
7843 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7846 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7848 #ifdef HAVE_WINDOW_SYSTEM
7849 /* When Emacs starts, selected_frame may be the initial terminal
7850 frame. If we let this through, a message would be displayed on
7852 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
7854 #endif /* HAVE_WINDOW_SYSTEM */
7857 /* Redraw garbaged frames. */
7859 clear_garbaged_frames ();
7861 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7863 echo_area_window
= mini_window
;
7864 window_height_changed_p
= display_echo_area (w
);
7865 w
->must_be_updated_p
= 1;
7867 /* Update the display, unless called from redisplay_internal.
7868 Also don't update the screen during redisplay itself. The
7869 update will happen at the end of redisplay, and an update
7870 here could cause confusion. */
7871 if (update_frame_p
&& !redisplaying_p
)
7875 /* If the display update has been interrupted by pending
7876 input, update mode lines in the frame. Due to the
7877 pending input, it might have been that redisplay hasn't
7878 been called, so that mode lines above the echo area are
7879 garbaged. This looks odd, so we prevent it here. */
7880 if (!display_completed
)
7881 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7883 if (window_height_changed_p
7884 /* Don't do this if Emacs is shutting down. Redisplay
7885 needs to run hooks. */
7886 && !NILP (Vrun_hooks
))
7888 /* Must update other windows. Likewise as in other
7889 cases, don't let this update be interrupted by
7891 int count
= SPECPDL_INDEX ();
7892 specbind (Qredisplay_dont_pause
, Qt
);
7893 windows_or_buffers_changed
= 1;
7894 redisplay_internal (0);
7895 unbind_to (count
, Qnil
);
7897 else if (FRAME_WINDOW_P (f
) && n
== 0)
7899 /* Window configuration is the same as before.
7900 Can do with a display update of the echo area,
7901 unless we displayed some mode lines. */
7902 update_single_window (w
, 1);
7903 FRAME_RIF (f
)->flush_display (f
);
7906 update_frame (f
, 1, 1);
7908 /* If cursor is in the echo area, make sure that the next
7909 redisplay displays the minibuffer, so that the cursor will
7910 be replaced with what the minibuffer wants. */
7911 if (cursor_in_echo_area
)
7912 ++windows_or_buffers_changed
;
7915 else if (!EQ (mini_window
, selected_window
))
7916 windows_or_buffers_changed
++;
7918 /* Last displayed message is now the current message. */
7919 echo_area_buffer
[1] = echo_area_buffer
[0];
7921 /* Prevent redisplay optimization in redisplay_internal by resetting
7922 this_line_start_pos. This is done because the mini-buffer now
7923 displays the message instead of its buffer text. */
7924 if (EQ (mini_window
, selected_window
))
7925 CHARPOS (this_line_start_pos
) = 0;
7927 return window_height_changed_p
;
7932 /***********************************************************************
7934 ***********************************************************************/
7937 /* The frame title buffering code is also used by Fformat_mode_line.
7938 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7940 /* A buffer for constructing frame titles in it; allocated from the
7941 heap in init_xdisp and resized as needed in store_frame_title_char. */
7943 static char *frame_title_buf
;
7945 /* The buffer's end, and a current output position in it. */
7947 static char *frame_title_buf_end
;
7948 static char *frame_title_ptr
;
7951 /* Store a single character C for the frame title in frame_title_buf.
7952 Re-allocate frame_title_buf if necessary. */
7956 store_frame_title_char (char c
)
7958 store_frame_title_char (c
)
7962 /* If output position has reached the end of the allocated buffer,
7963 double the buffer's size. */
7964 if (frame_title_ptr
== frame_title_buf_end
)
7966 int len
= frame_title_ptr
- frame_title_buf
;
7967 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7968 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7969 frame_title_buf_end
= frame_title_buf
+ new_size
;
7970 frame_title_ptr
= frame_title_buf
+ len
;
7973 *frame_title_ptr
++ = c
;
7977 /* Store part of a frame title in frame_title_buf, beginning at
7978 frame_title_ptr. STR is the string to store. Do not copy
7979 characters that yield more columns than PRECISION; PRECISION <= 0
7980 means copy the whole string. Pad with spaces until FIELD_WIDTH
7981 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7982 pad. Called from display_mode_element when it is used to build a
7986 store_frame_title (str
, field_width
, precision
)
7987 const unsigned char *str
;
7988 int field_width
, precision
;
7993 /* Copy at most PRECISION chars from STR. */
7994 nbytes
= strlen (str
);
7995 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7997 store_frame_title_char (*str
++);
7999 /* Fill up with spaces until FIELD_WIDTH reached. */
8000 while (field_width
> 0
8003 store_frame_title_char (' ');
8010 #ifdef HAVE_WINDOW_SYSTEM
8012 /* Set the title of FRAME, if it has changed. The title format is
8013 Vicon_title_format if FRAME is iconified, otherwise it is
8014 frame_title_format. */
8017 x_consider_frame_title (frame
)
8020 struct frame
*f
= XFRAME (frame
);
8022 if (FRAME_WINDOW_P (f
)
8023 || FRAME_MINIBUF_ONLY_P (f
)
8024 || f
->explicit_name
)
8026 /* Do we have more than one visible frame on this X display? */
8029 struct buffer
*obuf
;
8033 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8035 Lisp_Object other_frame
= XCAR (tail
);
8036 struct frame
*tf
= XFRAME (other_frame
);
8039 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8040 && !FRAME_MINIBUF_ONLY_P (tf
)
8041 && !EQ (other_frame
, tip_frame
)
8042 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8046 /* Set global variable indicating that multiple frames exist. */
8047 multiple_frames
= CONSP (tail
);
8049 /* Switch to the buffer of selected window of the frame. Set up
8050 frame_title_ptr so that display_mode_element will output into it;
8051 then display the title. */
8052 obuf
= current_buffer
;
8053 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8054 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8055 frame_title_ptr
= frame_title_buf
;
8056 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8057 NULL
, DEFAULT_FACE_ID
);
8058 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8059 len
= frame_title_ptr
- frame_title_buf
;
8060 frame_title_ptr
= NULL
;
8061 set_buffer_internal_1 (obuf
);
8063 /* Set the title only if it's changed. This avoids consing in
8064 the common case where it hasn't. (If it turns out that we've
8065 already wasted too much time by walking through the list with
8066 display_mode_element, then we might need to optimize at a
8067 higher level than this.) */
8068 if (! STRINGP (f
->name
)
8069 || SBYTES (f
->name
) != len
8070 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8071 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8075 #endif /* not HAVE_WINDOW_SYSTEM */
8080 /***********************************************************************
8082 ***********************************************************************/
8085 /* Prepare for redisplay by updating menu-bar item lists when
8086 appropriate. This can call eval. */
8089 prepare_menu_bars ()
8092 struct gcpro gcpro1
, gcpro2
;
8094 Lisp_Object tooltip_frame
;
8096 #ifdef HAVE_WINDOW_SYSTEM
8097 tooltip_frame
= tip_frame
;
8099 tooltip_frame
= Qnil
;
8102 /* Update all frame titles based on their buffer names, etc. We do
8103 this before the menu bars so that the buffer-menu will show the
8104 up-to-date frame titles. */
8105 #ifdef HAVE_WINDOW_SYSTEM
8106 if (windows_or_buffers_changed
|| update_mode_lines
)
8108 Lisp_Object tail
, frame
;
8110 FOR_EACH_FRAME (tail
, frame
)
8113 if (!EQ (frame
, tooltip_frame
)
8114 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8115 x_consider_frame_title (frame
);
8118 #endif /* HAVE_WINDOW_SYSTEM */
8120 /* Update the menu bar item lists, if appropriate. This has to be
8121 done before any actual redisplay or generation of display lines. */
8122 all_windows
= (update_mode_lines
8123 || buffer_shared
> 1
8124 || windows_or_buffers_changed
);
8127 Lisp_Object tail
, frame
;
8128 int count
= SPECPDL_INDEX ();
8130 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8132 FOR_EACH_FRAME (tail
, frame
)
8136 /* Ignore tooltip frame. */
8137 if (EQ (frame
, tooltip_frame
))
8140 /* If a window on this frame changed size, report that to
8141 the user and clear the size-change flag. */
8142 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8144 Lisp_Object functions
;
8146 /* Clear flag first in case we get an error below. */
8147 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8148 functions
= Vwindow_size_change_functions
;
8149 GCPRO2 (tail
, functions
);
8151 while (CONSP (functions
))
8153 call1 (XCAR (functions
), frame
);
8154 functions
= XCDR (functions
);
8160 update_menu_bar (f
, 0);
8161 #ifdef HAVE_WINDOW_SYSTEM
8162 update_tool_bar (f
, 0);
8167 unbind_to (count
, Qnil
);
8171 struct frame
*sf
= SELECTED_FRAME ();
8172 update_menu_bar (sf
, 1);
8173 #ifdef HAVE_WINDOW_SYSTEM
8174 update_tool_bar (sf
, 1);
8178 /* Motif needs this. See comment in xmenu.c. Turn it off when
8179 pending_menu_activation is not defined. */
8180 #ifdef USE_X_TOOLKIT
8181 pending_menu_activation
= 0;
8186 /* Update the menu bar item list for frame F. This has to be done
8187 before we start to fill in any display lines, because it can call
8190 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8193 update_menu_bar (f
, save_match_data
)
8195 int save_match_data
;
8198 register struct window
*w
;
8200 /* If called recursively during a menu update, do nothing. This can
8201 happen when, for instance, an activate-menubar-hook causes a
8203 if (inhibit_menubar_update
)
8206 window
= FRAME_SELECTED_WINDOW (f
);
8207 w
= XWINDOW (window
);
8209 #if 0 /* The if statement below this if statement used to include the
8210 condition !NILP (w->update_mode_line), rather than using
8211 update_mode_lines directly, and this if statement may have
8212 been added to make that condition work. Now the if
8213 statement below matches its comment, this isn't needed. */
8214 if (update_mode_lines
)
8215 w
->update_mode_line
= Qt
;
8218 if (FRAME_WINDOW_P (f
)
8220 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8221 || defined (USE_GTK)
8222 FRAME_EXTERNAL_MENU_BAR (f
)
8224 FRAME_MENU_BAR_LINES (f
) > 0
8226 : FRAME_MENU_BAR_LINES (f
) > 0)
8228 /* If the user has switched buffers or windows, we need to
8229 recompute to reflect the new bindings. But we'll
8230 recompute when update_mode_lines is set too; that means
8231 that people can use force-mode-line-update to request
8232 that the menu bar be recomputed. The adverse effect on
8233 the rest of the redisplay algorithm is about the same as
8234 windows_or_buffers_changed anyway. */
8235 if (windows_or_buffers_changed
8236 /* This used to test w->update_mode_line, but we believe
8237 there is no need to recompute the menu in that case. */
8238 || update_mode_lines
8239 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8240 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8241 != !NILP (w
->last_had_star
))
8242 || ((!NILP (Vtransient_mark_mode
)
8243 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8244 != !NILP (w
->region_showing
)))
8246 struct buffer
*prev
= current_buffer
;
8247 int count
= SPECPDL_INDEX ();
8249 specbind (Qinhibit_menubar_update
, Qt
);
8251 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8252 if (save_match_data
)
8253 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8254 if (NILP (Voverriding_local_map_menu_flag
))
8256 specbind (Qoverriding_terminal_local_map
, Qnil
);
8257 specbind (Qoverriding_local_map
, Qnil
);
8260 /* Run the Lucid hook. */
8261 safe_run_hooks (Qactivate_menubar_hook
);
8263 /* If it has changed current-menubar from previous value,
8264 really recompute the menu-bar from the value. */
8265 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8266 call0 (Qrecompute_lucid_menubar
);
8268 safe_run_hooks (Qmenu_bar_update_hook
);
8269 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8271 /* Redisplay the menu bar in case we changed it. */
8272 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8273 || defined (USE_GTK)
8274 if (FRAME_WINDOW_P (f
)
8275 #if defined (MAC_OS)
8276 /* All frames on Mac OS share the same menubar. So only the
8277 selected frame should be allowed to set it. */
8278 && f
== SELECTED_FRAME ()
8281 set_frame_menubar (f
, 0, 0);
8283 /* On a terminal screen, the menu bar is an ordinary screen
8284 line, and this makes it get updated. */
8285 w
->update_mode_line
= Qt
;
8286 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8287 /* In the non-toolkit version, the menu bar is an ordinary screen
8288 line, and this makes it get updated. */
8289 w
->update_mode_line
= Qt
;
8290 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8292 unbind_to (count
, Qnil
);
8293 set_buffer_internal_1 (prev
);
8300 /***********************************************************************
8302 ***********************************************************************/
8304 #ifdef HAVE_WINDOW_SYSTEM
8307 Nominal cursor position -- where to draw output.
8308 HPOS and VPOS are window relative glyph matrix coordinates.
8309 X and Y are window relative pixel coordinates. */
8311 struct cursor_pos output_cursor
;
8315 Set the global variable output_cursor to CURSOR. All cursor
8316 positions are relative to updated_window. */
8319 set_output_cursor (cursor
)
8320 struct cursor_pos
*cursor
;
8322 output_cursor
.hpos
= cursor
->hpos
;
8323 output_cursor
.vpos
= cursor
->vpos
;
8324 output_cursor
.x
= cursor
->x
;
8325 output_cursor
.y
= cursor
->y
;
8330 Set a nominal cursor position.
8332 HPOS and VPOS are column/row positions in a window glyph matrix. X
8333 and Y are window text area relative pixel positions.
8335 If this is done during an update, updated_window will contain the
8336 window that is being updated and the position is the future output
8337 cursor position for that window. If updated_window is null, use
8338 selected_window and display the cursor at the given position. */
8341 x_cursor_to (vpos
, hpos
, y
, x
)
8342 int vpos
, hpos
, y
, x
;
8346 /* If updated_window is not set, work on selected_window. */
8350 w
= XWINDOW (selected_window
);
8352 /* Set the output cursor. */
8353 output_cursor
.hpos
= hpos
;
8354 output_cursor
.vpos
= vpos
;
8355 output_cursor
.x
= x
;
8356 output_cursor
.y
= y
;
8358 /* If not called as part of an update, really display the cursor.
8359 This will also set the cursor position of W. */
8360 if (updated_window
== NULL
)
8363 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8364 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
8365 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
8370 #endif /* HAVE_WINDOW_SYSTEM */
8373 /***********************************************************************
8375 ***********************************************************************/
8377 #ifdef HAVE_WINDOW_SYSTEM
8379 /* Where the mouse was last time we reported a mouse event. */
8381 FRAME_PTR last_mouse_frame
;
8383 /* Tool-bar item index of the item on which a mouse button was pressed
8386 int last_tool_bar_item
;
8389 /* Update the tool-bar item list for frame F. This has to be done
8390 before we start to fill in any display lines. Called from
8391 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8392 and restore it here. */
8395 update_tool_bar (f
, save_match_data
)
8397 int save_match_data
;
8400 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8402 int do_update
= WINDOWP (f
->tool_bar_window
)
8403 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8411 window
= FRAME_SELECTED_WINDOW (f
);
8412 w
= XWINDOW (window
);
8414 /* If the user has switched buffers or windows, we need to
8415 recompute to reflect the new bindings. But we'll
8416 recompute when update_mode_lines is set too; that means
8417 that people can use force-mode-line-update to request
8418 that the menu bar be recomputed. The adverse effect on
8419 the rest of the redisplay algorithm is about the same as
8420 windows_or_buffers_changed anyway. */
8421 if (windows_or_buffers_changed
8422 || !NILP (w
->update_mode_line
)
8423 || update_mode_lines
8424 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8425 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8426 != !NILP (w
->last_had_star
))
8427 || ((!NILP (Vtransient_mark_mode
)
8428 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8429 != !NILP (w
->region_showing
)))
8431 struct buffer
*prev
= current_buffer
;
8432 int count
= SPECPDL_INDEX ();
8433 Lisp_Object new_tool_bar
;
8435 struct gcpro gcpro1
;
8437 /* Set current_buffer to the buffer of the selected
8438 window of the frame, so that we get the right local
8440 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8442 /* Save match data, if we must. */
8443 if (save_match_data
)
8444 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8446 /* Make sure that we don't accidentally use bogus keymaps. */
8447 if (NILP (Voverriding_local_map_menu_flag
))
8449 specbind (Qoverriding_terminal_local_map
, Qnil
);
8450 specbind (Qoverriding_local_map
, Qnil
);
8453 GCPRO1 (new_tool_bar
);
8455 /* Build desired tool-bar items from keymaps. */
8456 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8459 /* Redisplay the tool-bar if we changed it. */
8460 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8462 /* Redisplay that happens asynchronously due to an expose event
8463 may access f->tool_bar_items. Make sure we update both
8464 variables within BLOCK_INPUT so no such event interrupts. */
8466 f
->tool_bar_items
= new_tool_bar
;
8467 f
->n_tool_bar_items
= new_n_tool_bar
;
8468 w
->update_mode_line
= Qt
;
8474 unbind_to (count
, Qnil
);
8475 set_buffer_internal_1 (prev
);
8481 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8482 F's desired tool-bar contents. F->tool_bar_items must have
8483 been set up previously by calling prepare_menu_bars. */
8486 build_desired_tool_bar_string (f
)
8489 int i
, size
, size_needed
;
8490 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8491 Lisp_Object image
, plist
, props
;
8493 image
= plist
= props
= Qnil
;
8494 GCPRO3 (image
, plist
, props
);
8496 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8497 Otherwise, make a new string. */
8499 /* The size of the string we might be able to reuse. */
8500 size
= (STRINGP (f
->desired_tool_bar_string
)
8501 ? SCHARS (f
->desired_tool_bar_string
)
8504 /* We need one space in the string for each image. */
8505 size_needed
= f
->n_tool_bar_items
;
8507 /* Reuse f->desired_tool_bar_string, if possible. */
8508 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8509 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8513 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8514 Fremove_text_properties (make_number (0), make_number (size
),
8515 props
, f
->desired_tool_bar_string
);
8518 /* Put a `display' property on the string for the images to display,
8519 put a `menu_item' property on tool-bar items with a value that
8520 is the index of the item in F's tool-bar item vector. */
8521 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8523 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8525 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8526 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8527 int hmargin
, vmargin
, relief
, idx
, end
;
8528 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8530 /* If image is a vector, choose the image according to the
8532 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8533 if (VECTORP (image
))
8537 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8538 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8541 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8542 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8544 xassert (ASIZE (image
) >= idx
);
8545 image
= AREF (image
, idx
);
8550 /* Ignore invalid image specifications. */
8551 if (!valid_image_p (image
))
8554 /* Display the tool-bar button pressed, or depressed. */
8555 plist
= Fcopy_sequence (XCDR (image
));
8557 /* Compute margin and relief to draw. */
8558 relief
= (tool_bar_button_relief
>= 0
8559 ? tool_bar_button_relief
8560 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8561 hmargin
= vmargin
= relief
;
8563 if (INTEGERP (Vtool_bar_button_margin
)
8564 && XINT (Vtool_bar_button_margin
) > 0)
8566 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8567 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8569 else if (CONSP (Vtool_bar_button_margin
))
8571 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8572 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8573 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8575 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8576 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8577 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8580 if (auto_raise_tool_bar_buttons_p
)
8582 /* Add a `:relief' property to the image spec if the item is
8586 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8593 /* If image is selected, display it pressed, i.e. with a
8594 negative relief. If it's not selected, display it with a
8596 plist
= Fplist_put (plist
, QCrelief
,
8598 ? make_number (-relief
)
8599 : make_number (relief
)));
8604 /* Put a margin around the image. */
8605 if (hmargin
|| vmargin
)
8607 if (hmargin
== vmargin
)
8608 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8610 plist
= Fplist_put (plist
, QCmargin
,
8611 Fcons (make_number (hmargin
),
8612 make_number (vmargin
)));
8615 /* If button is not enabled, and we don't have special images
8616 for the disabled state, make the image appear disabled by
8617 applying an appropriate algorithm to it. */
8618 if (!enabled_p
&& idx
< 0)
8619 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8621 /* Put a `display' text property on the string for the image to
8622 display. Put a `menu-item' property on the string that gives
8623 the start of this item's properties in the tool-bar items
8625 image
= Fcons (Qimage
, plist
);
8626 props
= list4 (Qdisplay
, image
,
8627 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8629 /* Let the last image hide all remaining spaces in the tool bar
8630 string. The string can be longer than needed when we reuse a
8632 if (i
+ 1 == f
->n_tool_bar_items
)
8633 end
= SCHARS (f
->desired_tool_bar_string
);
8636 Fadd_text_properties (make_number (i
), make_number (end
),
8637 props
, f
->desired_tool_bar_string
);
8645 /* Display one line of the tool-bar of frame IT->f. */
8648 display_tool_bar_line (it
)
8651 struct glyph_row
*row
= it
->glyph_row
;
8652 int max_x
= it
->last_visible_x
;
8655 prepare_desired_row (row
);
8656 row
->y
= it
->current_y
;
8658 /* Note that this isn't made use of if the face hasn't a box,
8659 so there's no need to check the face here. */
8660 it
->start_of_box_run_p
= 1;
8662 while (it
->current_x
< max_x
)
8664 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8666 /* Get the next display element. */
8667 if (!get_next_display_element (it
))
8670 /* Produce glyphs. */
8671 x_before
= it
->current_x
;
8672 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8673 PRODUCE_GLYPHS (it
);
8675 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8680 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8682 if (x
+ glyph
->pixel_width
> max_x
)
8684 /* Glyph doesn't fit on line. */
8685 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8691 x
+= glyph
->pixel_width
;
8695 /* Stop at line ends. */
8696 if (ITERATOR_AT_END_OF_LINE_P (it
))
8699 set_iterator_to_next (it
, 1);
8704 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8705 extend_face_to_end_of_line (it
);
8706 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8707 last
->right_box_line_p
= 1;
8708 if (last
== row
->glyphs
[TEXT_AREA
])
8709 last
->left_box_line_p
= 1;
8710 compute_line_metrics (it
);
8712 /* If line is empty, make it occupy the rest of the tool-bar. */
8713 if (!row
->displays_text_p
)
8715 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8716 row
->ascent
= row
->phys_ascent
= 0;
8717 row
->extra_line_spacing
= 0;
8720 row
->full_width_p
= 1;
8721 row
->continued_p
= 0;
8722 row
->truncated_on_left_p
= 0;
8723 row
->truncated_on_right_p
= 0;
8725 it
->current_x
= it
->hpos
= 0;
8726 it
->current_y
+= row
->height
;
8732 /* Value is the number of screen lines needed to make all tool-bar
8733 items of frame F visible. */
8736 tool_bar_lines_needed (f
)
8739 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8742 /* Initialize an iterator for iteration over
8743 F->desired_tool_bar_string in the tool-bar window of frame F. */
8744 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8745 it
.first_visible_x
= 0;
8746 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8747 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8749 while (!ITERATOR_AT_END_P (&it
))
8751 it
.glyph_row
= w
->desired_matrix
->rows
;
8752 clear_glyph_row (it
.glyph_row
);
8753 display_tool_bar_line (&it
);
8756 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8760 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8762 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8771 frame
= selected_frame
;
8773 CHECK_FRAME (frame
);
8776 if (WINDOWP (f
->tool_bar_window
)
8777 || (w
= XWINDOW (f
->tool_bar_window
),
8778 WINDOW_TOTAL_LINES (w
) > 0))
8780 update_tool_bar (f
, 1);
8781 if (f
->n_tool_bar_items
)
8783 build_desired_tool_bar_string (f
);
8784 nlines
= tool_bar_lines_needed (f
);
8788 return make_number (nlines
);
8792 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8793 height should be changed. */
8796 redisplay_tool_bar (f
)
8801 struct glyph_row
*row
;
8802 int change_height_p
= 0;
8805 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8806 update_frame_tool_bar (f
);
8810 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8811 do anything. This means you must start with tool-bar-lines
8812 non-zero to get the auto-sizing effect. Or in other words, you
8813 can turn off tool-bars by specifying tool-bar-lines zero. */
8814 if (!WINDOWP (f
->tool_bar_window
)
8815 || (w
= XWINDOW (f
->tool_bar_window
),
8816 WINDOW_TOTAL_LINES (w
) == 0))
8819 /* Set up an iterator for the tool-bar window. */
8820 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8821 it
.first_visible_x
= 0;
8822 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8825 /* Build a string that represents the contents of the tool-bar. */
8826 build_desired_tool_bar_string (f
);
8827 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8829 /* Display as many lines as needed to display all tool-bar items. */
8830 while (it
.current_y
< it
.last_visible_y
)
8831 display_tool_bar_line (&it
);
8833 /* It doesn't make much sense to try scrolling in the tool-bar
8834 window, so don't do it. */
8835 w
->desired_matrix
->no_scrolling_p
= 1;
8836 w
->must_be_updated_p
= 1;
8838 if (auto_resize_tool_bars_p
)
8842 /* If we couldn't display everything, change the tool-bar's
8844 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8845 change_height_p
= 1;
8847 /* If there are blank lines at the end, except for a partially
8848 visible blank line at the end that is smaller than
8849 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8850 row
= it
.glyph_row
- 1;
8851 if (!row
->displays_text_p
8852 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8853 change_height_p
= 1;
8855 /* If row displays tool-bar items, but is partially visible,
8856 change the tool-bar's height. */
8857 if (row
->displays_text_p
8858 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8859 change_height_p
= 1;
8861 /* Resize windows as needed by changing the `tool-bar-lines'
8864 && (nlines
= tool_bar_lines_needed (f
),
8865 nlines
!= WINDOW_TOTAL_LINES (w
)))
8867 extern Lisp_Object Qtool_bar_lines
;
8869 int old_height
= WINDOW_TOTAL_LINES (w
);
8871 XSETFRAME (frame
, f
);
8872 clear_glyph_matrix (w
->desired_matrix
);
8873 Fmodify_frame_parameters (frame
,
8874 Fcons (Fcons (Qtool_bar_lines
,
8875 make_number (nlines
)),
8877 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8878 fonts_changed_p
= 1;
8882 return change_height_p
;
8886 /* Get information about the tool-bar item which is displayed in GLYPH
8887 on frame F. Return in *PROP_IDX the index where tool-bar item
8888 properties start in F->tool_bar_items. Value is zero if
8889 GLYPH doesn't display a tool-bar item. */
8892 tool_bar_item_info (f
, glyph
, prop_idx
)
8894 struct glyph
*glyph
;
8901 /* This function can be called asynchronously, which means we must
8902 exclude any possibility that Fget_text_property signals an
8904 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8905 charpos
= max (0, charpos
);
8907 /* Get the text property `menu-item' at pos. The value of that
8908 property is the start index of this item's properties in
8909 F->tool_bar_items. */
8910 prop
= Fget_text_property (make_number (charpos
),
8911 Qmenu_item
, f
->current_tool_bar_string
);
8912 if (INTEGERP (prop
))
8914 *prop_idx
= XINT (prop
);
8924 /* Get information about the tool-bar item at position X/Y on frame F.
8925 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8926 the current matrix of the tool-bar window of F, or NULL if not
8927 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8928 item in F->tool_bar_items. Value is
8930 -1 if X/Y is not on a tool-bar item
8931 0 if X/Y is on the same item that was highlighted before.
8935 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8938 struct glyph
**glyph
;
8939 int *hpos
, *vpos
, *prop_idx
;
8941 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8942 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8945 /* Find the glyph under X/Y. */
8946 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
8950 /* Get the start of this tool-bar item's properties in
8951 f->tool_bar_items. */
8952 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8955 /* Is mouse on the highlighted item? */
8956 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8957 && *vpos
>= dpyinfo
->mouse_face_beg_row
8958 && *vpos
<= dpyinfo
->mouse_face_end_row
8959 && (*vpos
> dpyinfo
->mouse_face_beg_row
8960 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8961 && (*vpos
< dpyinfo
->mouse_face_end_row
8962 || *hpos
< dpyinfo
->mouse_face_end_col
8963 || dpyinfo
->mouse_face_past_end
))
8971 Handle mouse button event on the tool-bar of frame F, at
8972 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8973 0 for button release. MODIFIERS is event modifiers for button
8977 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8980 unsigned int modifiers
;
8982 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8983 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8984 int hpos
, vpos
, prop_idx
;
8985 struct glyph
*glyph
;
8986 Lisp_Object enabled_p
;
8988 /* If not on the highlighted tool-bar item, return. */
8989 frame_to_window_pixel_xy (w
, &x
, &y
);
8990 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8993 /* If item is disabled, do nothing. */
8994 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8995 if (NILP (enabled_p
))
9000 /* Show item in pressed state. */
9001 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9002 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9003 last_tool_bar_item
= prop_idx
;
9007 Lisp_Object key
, frame
;
9008 struct input_event event
;
9011 /* Show item in released state. */
9012 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9013 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9015 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9017 XSETFRAME (frame
, f
);
9018 event
.kind
= TOOL_BAR_EVENT
;
9019 event
.frame_or_window
= frame
;
9021 kbd_buffer_store_event (&event
);
9023 event
.kind
= TOOL_BAR_EVENT
;
9024 event
.frame_or_window
= frame
;
9026 event
.modifiers
= modifiers
;
9027 kbd_buffer_store_event (&event
);
9028 last_tool_bar_item
= -1;
9033 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9034 tool-bar window-relative coordinates X/Y. Called from
9035 note_mouse_highlight. */
9038 note_tool_bar_highlight (f
, x
, y
)
9042 Lisp_Object window
= f
->tool_bar_window
;
9043 struct window
*w
= XWINDOW (window
);
9044 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9046 struct glyph
*glyph
;
9047 struct glyph_row
*row
;
9049 Lisp_Object enabled_p
;
9051 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9052 int mouse_down_p
, rc
;
9054 /* Function note_mouse_highlight is called with negative x(y
9055 values when mouse moves outside of the frame. */
9056 if (x
<= 0 || y
<= 0)
9058 clear_mouse_face (dpyinfo
);
9062 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9065 /* Not on tool-bar item. */
9066 clear_mouse_face (dpyinfo
);
9070 /* On same tool-bar item as before. */
9073 clear_mouse_face (dpyinfo
);
9075 /* Mouse is down, but on different tool-bar item? */
9076 mouse_down_p
= (dpyinfo
->grabbed
9077 && f
== last_mouse_frame
9078 && FRAME_LIVE_P (f
));
9080 && last_tool_bar_item
!= prop_idx
)
9083 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9084 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9086 /* If tool-bar item is not enabled, don't highlight it. */
9087 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9088 if (!NILP (enabled_p
))
9090 /* Compute the x-position of the glyph. In front and past the
9091 image is a space. We include this in the highlighted area. */
9092 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9093 for (i
= x
= 0; i
< hpos
; ++i
)
9094 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9096 /* Record this as the current active region. */
9097 dpyinfo
->mouse_face_beg_col
= hpos
;
9098 dpyinfo
->mouse_face_beg_row
= vpos
;
9099 dpyinfo
->mouse_face_beg_x
= x
;
9100 dpyinfo
->mouse_face_beg_y
= row
->y
;
9101 dpyinfo
->mouse_face_past_end
= 0;
9103 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9104 dpyinfo
->mouse_face_end_row
= vpos
;
9105 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9106 dpyinfo
->mouse_face_end_y
= row
->y
;
9107 dpyinfo
->mouse_face_window
= window
;
9108 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9110 /* Display it as active. */
9111 show_mouse_face (dpyinfo
, draw
);
9112 dpyinfo
->mouse_face_image_state
= draw
;
9117 /* Set help_echo_string to a help string to display for this tool-bar item.
9118 XTread_socket does the rest. */
9119 help_echo_object
= help_echo_window
= Qnil
;
9121 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9122 if (NILP (help_echo_string
))
9123 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9126 #endif /* HAVE_WINDOW_SYSTEM */
9130 /************************************************************************
9131 Horizontal scrolling
9132 ************************************************************************/
9134 static int hscroll_window_tree
P_ ((Lisp_Object
));
9135 static int hscroll_windows
P_ ((Lisp_Object
));
9137 /* For all leaf windows in the window tree rooted at WINDOW, set their
9138 hscroll value so that PT is (i) visible in the window, and (ii) so
9139 that it is not within a certain margin at the window's left and
9140 right border. Value is non-zero if any window's hscroll has been
9144 hscroll_window_tree (window
)
9147 int hscrolled_p
= 0;
9148 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9149 int hscroll_step_abs
= 0;
9150 double hscroll_step_rel
= 0;
9152 if (hscroll_relative_p
)
9154 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9155 if (hscroll_step_rel
< 0)
9157 hscroll_relative_p
= 0;
9158 hscroll_step_abs
= 0;
9161 else if (INTEGERP (Vhscroll_step
))
9163 hscroll_step_abs
= XINT (Vhscroll_step
);
9164 if (hscroll_step_abs
< 0)
9165 hscroll_step_abs
= 0;
9168 hscroll_step_abs
= 0;
9170 while (WINDOWP (window
))
9172 struct window
*w
= XWINDOW (window
);
9174 if (WINDOWP (w
->hchild
))
9175 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9176 else if (WINDOWP (w
->vchild
))
9177 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9178 else if (w
->cursor
.vpos
>= 0)
9181 int text_area_width
;
9182 struct glyph_row
*current_cursor_row
9183 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9184 struct glyph_row
*desired_cursor_row
9185 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9186 struct glyph_row
*cursor_row
9187 = (desired_cursor_row
->enabled_p
9188 ? desired_cursor_row
9189 : current_cursor_row
);
9191 text_area_width
= window_box_width (w
, TEXT_AREA
);
9193 /* Scroll when cursor is inside this scroll margin. */
9194 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9196 if ((XFASTINT (w
->hscroll
)
9197 && w
->cursor
.x
<= h_margin
)
9198 || (cursor_row
->enabled_p
9199 && cursor_row
->truncated_on_right_p
9200 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9204 struct buffer
*saved_current_buffer
;
9208 /* Find point in a display of infinite width. */
9209 saved_current_buffer
= current_buffer
;
9210 current_buffer
= XBUFFER (w
->buffer
);
9212 if (w
== XWINDOW (selected_window
))
9213 pt
= BUF_PT (current_buffer
);
9216 pt
= marker_position (w
->pointm
);
9217 pt
= max (BEGV
, pt
);
9221 /* Move iterator to pt starting at cursor_row->start in
9222 a line with infinite width. */
9223 init_to_row_start (&it
, w
, cursor_row
);
9224 it
.last_visible_x
= INFINITY
;
9225 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9226 current_buffer
= saved_current_buffer
;
9228 /* Position cursor in window. */
9229 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9230 hscroll
= max (0, (it
.current_x
9231 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9232 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9233 : (text_area_width
/ 2))))
9234 / FRAME_COLUMN_WIDTH (it
.f
);
9235 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9237 if (hscroll_relative_p
)
9238 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9241 wanted_x
= text_area_width
9242 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9245 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9249 if (hscroll_relative_p
)
9250 wanted_x
= text_area_width
* hscroll_step_rel
9253 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9256 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9258 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9260 /* Don't call Fset_window_hscroll if value hasn't
9261 changed because it will prevent redisplay
9263 if (XFASTINT (w
->hscroll
) != hscroll
)
9265 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9266 w
->hscroll
= make_number (hscroll
);
9275 /* Value is non-zero if hscroll of any leaf window has been changed. */
9280 /* Set hscroll so that cursor is visible and not inside horizontal
9281 scroll margins for all windows in the tree rooted at WINDOW. See
9282 also hscroll_window_tree above. Value is non-zero if any window's
9283 hscroll has been changed. If it has, desired matrices on the frame
9284 of WINDOW are cleared. */
9287 hscroll_windows (window
)
9292 if (automatic_hscrolling_p
)
9294 hscrolled_p
= hscroll_window_tree (window
);
9296 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9305 /************************************************************************
9307 ************************************************************************/
9309 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9310 to a non-zero value. This is sometimes handy to have in a debugger
9315 /* First and last unchanged row for try_window_id. */
9317 int debug_first_unchanged_at_end_vpos
;
9318 int debug_last_unchanged_at_beg_vpos
;
9320 /* Delta vpos and y. */
9322 int debug_dvpos
, debug_dy
;
9324 /* Delta in characters and bytes for try_window_id. */
9326 int debug_delta
, debug_delta_bytes
;
9328 /* Values of window_end_pos and window_end_vpos at the end of
9331 EMACS_INT debug_end_pos
, debug_end_vpos
;
9333 /* Append a string to W->desired_matrix->method. FMT is a printf
9334 format string. A1...A9 are a supplement for a variable-length
9335 argument list. If trace_redisplay_p is non-zero also printf the
9336 resulting string to stderr. */
9339 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9342 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9345 char *method
= w
->desired_matrix
->method
;
9346 int len
= strlen (method
);
9347 int size
= sizeof w
->desired_matrix
->method
;
9348 int remaining
= size
- len
- 1;
9350 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9351 if (len
&& remaining
)
9357 strncpy (method
+ len
, buffer
, remaining
);
9359 if (trace_redisplay_p
)
9360 fprintf (stderr
, "%p (%s): %s\n",
9362 ((BUFFERP (w
->buffer
)
9363 && STRINGP (XBUFFER (w
->buffer
)->name
))
9364 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9369 #endif /* GLYPH_DEBUG */
9372 /* Value is non-zero if all changes in window W, which displays
9373 current_buffer, are in the text between START and END. START is a
9374 buffer position, END is given as a distance from Z. Used in
9375 redisplay_internal for display optimization. */
9378 text_outside_line_unchanged_p (w
, start
, end
)
9382 int unchanged_p
= 1;
9384 /* If text or overlays have changed, see where. */
9385 if (XFASTINT (w
->last_modified
) < MODIFF
9386 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9388 /* Gap in the line? */
9389 if (GPT
< start
|| Z
- GPT
< end
)
9392 /* Changes start in front of the line, or end after it? */
9394 && (BEG_UNCHANGED
< start
- 1
9395 || END_UNCHANGED
< end
))
9398 /* If selective display, can't optimize if changes start at the
9399 beginning of the line. */
9401 && INTEGERP (current_buffer
->selective_display
)
9402 && XINT (current_buffer
->selective_display
) > 0
9403 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9406 /* If there are overlays at the start or end of the line, these
9407 may have overlay strings with newlines in them. A change at
9408 START, for instance, may actually concern the display of such
9409 overlay strings as well, and they are displayed on different
9410 lines. So, quickly rule out this case. (For the future, it
9411 might be desirable to implement something more telling than
9412 just BEG/END_UNCHANGED.) */
9415 if (BEG
+ BEG_UNCHANGED
== start
9416 && overlay_touches_p (start
))
9418 if (END_UNCHANGED
== end
9419 && overlay_touches_p (Z
- end
))
9428 /* Do a frame update, taking possible shortcuts into account. This is
9429 the main external entry point for redisplay.
9431 If the last redisplay displayed an echo area message and that message
9432 is no longer requested, we clear the echo area or bring back the
9433 mini-buffer if that is in use. */
9438 redisplay_internal (0);
9443 overlay_arrow_string_or_property (var
, pbitmap
)
9447 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9453 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9454 *pbitmap
= XINT (bitmap
);
9459 return Voverlay_arrow_string
;
9462 /* Return 1 if there are any overlay-arrows in current_buffer. */
9464 overlay_arrow_in_current_buffer_p ()
9468 for (vlist
= Voverlay_arrow_variable_list
;
9470 vlist
= XCDR (vlist
))
9472 Lisp_Object var
= XCAR (vlist
);
9477 val
= find_symbol_value (var
);
9479 && current_buffer
== XMARKER (val
)->buffer
)
9486 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9490 overlay_arrows_changed_p ()
9494 for (vlist
= Voverlay_arrow_variable_list
;
9496 vlist
= XCDR (vlist
))
9498 Lisp_Object var
= XCAR (vlist
);
9499 Lisp_Object val
, pstr
;
9503 val
= find_symbol_value (var
);
9506 if (! EQ (COERCE_MARKER (val
),
9507 Fget (var
, Qlast_arrow_position
))
9508 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9509 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9515 /* Mark overlay arrows to be updated on next redisplay. */
9518 update_overlay_arrows (up_to_date
)
9523 for (vlist
= Voverlay_arrow_variable_list
;
9525 vlist
= XCDR (vlist
))
9527 Lisp_Object var
= XCAR (vlist
);
9534 Lisp_Object val
= find_symbol_value (var
);
9535 Fput (var
, Qlast_arrow_position
,
9536 COERCE_MARKER (val
));
9537 Fput (var
, Qlast_arrow_string
,
9538 overlay_arrow_string_or_property (var
, 0));
9540 else if (up_to_date
< 0
9541 || !NILP (Fget (var
, Qlast_arrow_position
)))
9543 Fput (var
, Qlast_arrow_position
, Qt
);
9544 Fput (var
, Qlast_arrow_string
, Qt
);
9550 /* Return overlay arrow string to display at row.
9551 Return t if display as bitmap in left fringe.
9552 Return nil if no overlay arrow. */
9555 overlay_arrow_at_row (it
, row
, pbitmap
)
9557 struct glyph_row
*row
;
9562 for (vlist
= Voverlay_arrow_variable_list
;
9564 vlist
= XCDR (vlist
))
9566 Lisp_Object var
= XCAR (vlist
);
9572 val
= find_symbol_value (var
);
9575 && current_buffer
== XMARKER (val
)->buffer
9576 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9578 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9579 if (FRAME_WINDOW_P (it
->f
)
9580 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9592 /* Return 1 if point moved out of or into a composition. Otherwise
9593 return 0. PREV_BUF and PREV_PT are the last point buffer and
9594 position. BUF and PT are the current point buffer and position. */
9597 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9598 struct buffer
*prev_buf
, *buf
;
9605 XSETBUFFER (buffer
, buf
);
9606 /* Check a composition at the last point if point moved within the
9608 if (prev_buf
== buf
)
9611 /* Point didn't move. */
9614 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9615 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9616 && COMPOSITION_VALID_P (start
, end
, prop
)
9617 && start
< prev_pt
&& end
> prev_pt
)
9618 /* The last point was within the composition. Return 1 iff
9619 point moved out of the composition. */
9620 return (pt
<= start
|| pt
>= end
);
9623 /* Check a composition at the current point. */
9624 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9625 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9626 && COMPOSITION_VALID_P (start
, end
, prop
)
9627 && start
< pt
&& end
> pt
);
9631 /* Reconsider the setting of B->clip_changed which is displayed
9635 reconsider_clip_changes (w
, b
)
9640 && !NILP (w
->window_end_valid
)
9641 && w
->current_matrix
->buffer
== b
9642 && w
->current_matrix
->zv
== BUF_ZV (b
)
9643 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9644 b
->clip_changed
= 0;
9646 /* If display wasn't paused, and W is not a tool bar window, see if
9647 point has been moved into or out of a composition. In that case,
9648 we set b->clip_changed to 1 to force updating the screen. If
9649 b->clip_changed has already been set to 1, we can skip this
9651 if (!b
->clip_changed
9652 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9656 if (w
== XWINDOW (selected_window
))
9657 pt
= BUF_PT (current_buffer
);
9659 pt
= marker_position (w
->pointm
);
9661 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9662 || pt
!= XINT (w
->last_point
))
9663 && check_point_in_composition (w
->current_matrix
->buffer
,
9664 XINT (w
->last_point
),
9665 XBUFFER (w
->buffer
), pt
))
9666 b
->clip_changed
= 1;
9671 /* Select FRAME to forward the values of frame-local variables into C
9672 variables so that the redisplay routines can access those values
9676 select_frame_for_redisplay (frame
)
9679 Lisp_Object tail
, sym
, val
;
9680 Lisp_Object old
= selected_frame
;
9682 selected_frame
= frame
;
9684 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9685 if (CONSP (XCAR (tail
))
9686 && (sym
= XCAR (XCAR (tail
)),
9688 && (sym
= indirect_variable (sym
),
9689 val
= SYMBOL_VALUE (sym
),
9690 (BUFFER_LOCAL_VALUEP (val
)
9691 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9692 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9693 Fsymbol_value (sym
);
9695 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9696 if (CONSP (XCAR (tail
))
9697 && (sym
= XCAR (XCAR (tail
)),
9699 && (sym
= indirect_variable (sym
),
9700 val
= SYMBOL_VALUE (sym
),
9701 (BUFFER_LOCAL_VALUEP (val
)
9702 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9703 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9704 Fsymbol_value (sym
);
9708 #define STOP_POLLING \
9709 do { if (! polling_stopped_here) stop_polling (); \
9710 polling_stopped_here = 1; } while (0)
9712 #define RESUME_POLLING \
9713 do { if (polling_stopped_here) start_polling (); \
9714 polling_stopped_here = 0; } while (0)
9717 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9718 response to any user action; therefore, we should preserve the echo
9719 area. (Actually, our caller does that job.) Perhaps in the future
9720 avoid recentering windows if it is not necessary; currently that
9721 causes some problems. */
9724 redisplay_internal (preserve_echo_area
)
9725 int preserve_echo_area
;
9727 struct window
*w
= XWINDOW (selected_window
);
9728 struct frame
*f
= XFRAME (w
->frame
);
9730 int must_finish
= 0;
9731 struct text_pos tlbufpos
, tlendpos
;
9732 int number_of_visible_frames
;
9734 struct frame
*sf
= SELECTED_FRAME ();
9735 int polling_stopped_here
= 0;
9737 /* Non-zero means redisplay has to consider all windows on all
9738 frames. Zero means, only selected_window is considered. */
9739 int consider_all_windows_p
;
9741 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9743 /* No redisplay if running in batch mode or frame is not yet fully
9744 initialized, or redisplay is explicitly turned off by setting
9745 Vinhibit_redisplay. */
9747 || !NILP (Vinhibit_redisplay
)
9748 || !f
->glyphs_initialized_p
)
9751 /* The flag redisplay_performed_directly_p is set by
9752 direct_output_for_insert when it already did the whole screen
9753 update necessary. */
9754 if (redisplay_performed_directly_p
)
9756 redisplay_performed_directly_p
= 0;
9757 if (!hscroll_windows (selected_window
))
9761 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9762 if (popup_activated ())
9766 /* I don't think this happens but let's be paranoid. */
9770 /* Record a function that resets redisplaying_p to its old value
9771 when we leave this function. */
9772 count
= SPECPDL_INDEX ();
9773 record_unwind_protect (unwind_redisplay
,
9774 Fcons (make_number (redisplaying_p
), selected_frame
));
9776 specbind (Qinhibit_free_realized_faces
, Qnil
);
9780 reconsider_clip_changes (w
, current_buffer
);
9782 /* If new fonts have been loaded that make a glyph matrix adjustment
9783 necessary, do it. */
9784 if (fonts_changed_p
)
9786 adjust_glyphs (NULL
);
9787 ++windows_or_buffers_changed
;
9788 fonts_changed_p
= 0;
9791 /* If face_change_count is non-zero, init_iterator will free all
9792 realized faces, which includes the faces referenced from current
9793 matrices. So, we can't reuse current matrices in this case. */
9794 if (face_change_count
)
9795 ++windows_or_buffers_changed
;
9797 if (FRAME_TERMCAP_P (sf
)
9798 && FRAME_TTY (sf
)->previous_terminal_frame
!= sf
)
9800 /* Since frames on a single ASCII terminal share the same
9801 display area, displaying a different frame means redisplay
9803 windows_or_buffers_changed
++;
9804 SET_FRAME_GARBAGED (sf
);
9805 FRAME_TTY (sf
)->previous_terminal_frame
= sf
;
9808 /* Set the visible flags for all frames. Do this before checking
9809 for resized or garbaged frames; they want to know if their frames
9810 are visible. See the comment in frame.h for
9811 FRAME_SAMPLE_VISIBILITY. */
9813 Lisp_Object tail
, frame
;
9815 number_of_visible_frames
= 0;
9817 FOR_EACH_FRAME (tail
, frame
)
9819 struct frame
*f
= XFRAME (frame
);
9821 FRAME_SAMPLE_VISIBILITY (f
);
9822 if (FRAME_VISIBLE_P (f
))
9823 ++number_of_visible_frames
;
9824 clear_desired_matrices (f
);
9829 /* Notice any pending interrupt request to change frame size. */
9830 do_pending_window_change (1);
9832 /* Clear frames marked as garbaged. */
9834 clear_garbaged_frames ();
9836 /* Build menubar and tool-bar items. */
9837 prepare_menu_bars ();
9839 if (windows_or_buffers_changed
)
9840 update_mode_lines
++;
9842 /* Detect case that we need to write or remove a star in the mode line. */
9843 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9845 w
->update_mode_line
= Qt
;
9846 if (buffer_shared
> 1)
9847 update_mode_lines
++;
9850 /* If %c is in the mode line, update it if needed. */
9851 if (!NILP (w
->column_number_displayed
)
9852 /* This alternative quickly identifies a common case
9853 where no change is needed. */
9854 && !(PT
== XFASTINT (w
->last_point
)
9855 && XFASTINT (w
->last_modified
) >= MODIFF
9856 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9857 && (XFASTINT (w
->column_number_displayed
)
9858 != (int) current_column ())) /* iftc */
9859 w
->update_mode_line
= Qt
;
9861 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9863 /* The variable buffer_shared is set in redisplay_window and
9864 indicates that we redisplay a buffer in different windows. See
9866 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9867 || cursor_type_changed
);
9869 /* If specs for an arrow have changed, do thorough redisplay
9870 to ensure we remove any arrow that should no longer exist. */
9871 if (overlay_arrows_changed_p ())
9872 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9874 /* Normally the message* functions will have already displayed and
9875 updated the echo area, but the frame may have been trashed, or
9876 the update may have been preempted, so display the echo area
9877 again here. Checking message_cleared_p captures the case that
9878 the echo area should be cleared. */
9879 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9880 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9881 || (message_cleared_p
9882 && minibuf_level
== 0
9883 /* If the mini-window is currently selected, this means the
9884 echo-area doesn't show through. */
9885 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9887 int window_height_changed_p
= echo_area_display (0);
9890 /* If we don't display the current message, don't clear the
9891 message_cleared_p flag, because, if we did, we wouldn't clear
9892 the echo area in the next redisplay which doesn't preserve
9894 if (!display_last_displayed_message_p
)
9895 message_cleared_p
= 0;
9897 if (fonts_changed_p
)
9899 else if (window_height_changed_p
)
9901 consider_all_windows_p
= 1;
9902 ++update_mode_lines
;
9903 ++windows_or_buffers_changed
;
9905 /* If window configuration was changed, frames may have been
9906 marked garbaged. Clear them or we will experience
9907 surprises wrt scrolling. */
9909 clear_garbaged_frames ();
9912 else if (EQ (selected_window
, minibuf_window
)
9913 && (current_buffer
->clip_changed
9914 || XFASTINT (w
->last_modified
) < MODIFF
9915 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9916 && resize_mini_window (w
, 0))
9918 /* Resized active mini-window to fit the size of what it is
9919 showing if its contents might have changed. */
9921 consider_all_windows_p
= 1;
9922 ++windows_or_buffers_changed
;
9923 ++update_mode_lines
;
9925 /* If window configuration was changed, frames may have been
9926 marked garbaged. Clear them or we will experience
9927 surprises wrt scrolling. */
9929 clear_garbaged_frames ();
9933 /* If showing the region, and mark has changed, we must redisplay
9934 the whole window. The assignment to this_line_start_pos prevents
9935 the optimization directly below this if-statement. */
9936 if (((!NILP (Vtransient_mark_mode
)
9937 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9938 != !NILP (w
->region_showing
))
9939 || (!NILP (w
->region_showing
)
9940 && !EQ (w
->region_showing
,
9941 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9942 CHARPOS (this_line_start_pos
) = 0;
9944 /* Optimize the case that only the line containing the cursor in the
9945 selected window has changed. Variables starting with this_ are
9946 set in display_line and record information about the line
9947 containing the cursor. */
9948 tlbufpos
= this_line_start_pos
;
9949 tlendpos
= this_line_end_pos
;
9950 if (!consider_all_windows_p
9951 && CHARPOS (tlbufpos
) > 0
9952 && NILP (w
->update_mode_line
)
9953 && !current_buffer
->clip_changed
9954 && !current_buffer
->prevent_redisplay_optimizations_p
9955 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9956 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9957 /* Make sure recorded data applies to current buffer, etc. */
9958 && this_line_buffer
== current_buffer
9959 && current_buffer
== XBUFFER (w
->buffer
)
9960 && NILP (w
->force_start
)
9961 && NILP (w
->optional_new_start
)
9962 /* Point must be on the line that we have info recorded about. */
9963 && PT
>= CHARPOS (tlbufpos
)
9964 && PT
<= Z
- CHARPOS (tlendpos
)
9965 /* All text outside that line, including its final newline,
9966 must be unchanged */
9967 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9968 CHARPOS (tlendpos
)))
9970 if (CHARPOS (tlbufpos
) > BEGV
9971 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9972 && (CHARPOS (tlbufpos
) == ZV
9973 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9974 /* Former continuation line has disappeared by becoming empty */
9976 else if (XFASTINT (w
->last_modified
) < MODIFF
9977 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9978 || MINI_WINDOW_P (w
))
9980 /* We have to handle the case of continuation around a
9981 wide-column character (See the comment in indent.c around
9984 For instance, in the following case:
9986 -------- Insert --------
9987 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9988 J_I_ ==> J_I_ `^^' are cursors.
9992 As we have to redraw the line above, we should goto cancel. */
9995 int line_height_before
= this_line_pixel_height
;
9997 /* Note that start_display will handle the case that the
9998 line starting at tlbufpos is a continuation lines. */
9999 start_display (&it
, w
, tlbufpos
);
10001 /* Implementation note: It this still necessary? */
10002 if (it
.current_x
!= this_line_start_x
)
10005 TRACE ((stderr
, "trying display optimization 1\n"));
10006 w
->cursor
.vpos
= -1;
10007 overlay_arrow_seen
= 0;
10008 it
.vpos
= this_line_vpos
;
10009 it
.current_y
= this_line_y
;
10010 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10011 display_line (&it
);
10013 /* If line contains point, is not continued,
10014 and ends at same distance from eob as before, we win */
10015 if (w
->cursor
.vpos
>= 0
10016 /* Line is not continued, otherwise this_line_start_pos
10017 would have been set to 0 in display_line. */
10018 && CHARPOS (this_line_start_pos
)
10019 /* Line ends as before. */
10020 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10021 /* Line has same height as before. Otherwise other lines
10022 would have to be shifted up or down. */
10023 && this_line_pixel_height
== line_height_before
)
10025 /* If this is not the window's last line, we must adjust
10026 the charstarts of the lines below. */
10027 if (it
.current_y
< it
.last_visible_y
)
10029 struct glyph_row
*row
10030 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10031 int delta
, delta_bytes
;
10033 if (Z
- CHARPOS (tlendpos
) == ZV
)
10035 /* This line ends at end of (accessible part of)
10036 buffer. There is no newline to count. */
10038 - CHARPOS (tlendpos
)
10039 - MATRIX_ROW_START_CHARPOS (row
));
10040 delta_bytes
= (Z_BYTE
10041 - BYTEPOS (tlendpos
)
10042 - MATRIX_ROW_START_BYTEPOS (row
));
10046 /* This line ends in a newline. Must take
10047 account of the newline and the rest of the
10048 text that follows. */
10050 - CHARPOS (tlendpos
)
10051 - MATRIX_ROW_START_CHARPOS (row
));
10052 delta_bytes
= (Z_BYTE
10053 - BYTEPOS (tlendpos
)
10054 - MATRIX_ROW_START_BYTEPOS (row
));
10057 increment_matrix_positions (w
->current_matrix
,
10058 this_line_vpos
+ 1,
10059 w
->current_matrix
->nrows
,
10060 delta
, delta_bytes
);
10063 /* If this row displays text now but previously didn't,
10064 or vice versa, w->window_end_vpos may have to be
10066 if ((it
.glyph_row
- 1)->displays_text_p
)
10068 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10069 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10071 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10072 && this_line_vpos
> 0)
10073 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10074 w
->window_end_valid
= Qnil
;
10076 /* Update hint: No need to try to scroll in update_window. */
10077 w
->desired_matrix
->no_scrolling_p
= 1;
10080 *w
->desired_matrix
->method
= 0;
10081 debug_method_add (w
, "optimization 1");
10083 #ifdef HAVE_WINDOW_SYSTEM
10084 update_window_fringes (w
, 0);
10091 else if (/* Cursor position hasn't changed. */
10092 PT
== XFASTINT (w
->last_point
)
10093 /* Make sure the cursor was last displayed
10094 in this window. Otherwise we have to reposition it. */
10095 && 0 <= w
->cursor
.vpos
10096 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10100 do_pending_window_change (1);
10102 /* We used to always goto end_of_redisplay here, but this
10103 isn't enough if we have a blinking cursor. */
10104 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10105 goto end_of_redisplay
;
10109 /* If highlighting the region, or if the cursor is in the echo area,
10110 then we can't just move the cursor. */
10111 else if (! (!NILP (Vtransient_mark_mode
)
10112 && !NILP (current_buffer
->mark_active
))
10113 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10114 || highlight_nonselected_windows
)
10115 && NILP (w
->region_showing
)
10116 && NILP (Vshow_trailing_whitespace
)
10117 && !cursor_in_echo_area
)
10120 struct glyph_row
*row
;
10122 /* Skip from tlbufpos to PT and see where it is. Note that
10123 PT may be in invisible text. If so, we will end at the
10124 next visible position. */
10125 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10126 NULL
, DEFAULT_FACE_ID
);
10127 it
.current_x
= this_line_start_x
;
10128 it
.current_y
= this_line_y
;
10129 it
.vpos
= this_line_vpos
;
10131 /* The call to move_it_to stops in front of PT, but
10132 moves over before-strings. */
10133 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10135 if (it
.vpos
== this_line_vpos
10136 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10139 xassert (this_line_vpos
== it
.vpos
);
10140 xassert (this_line_y
== it
.current_y
);
10141 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10143 *w
->desired_matrix
->method
= 0;
10144 debug_method_add (w
, "optimization 3");
10153 /* Text changed drastically or point moved off of line. */
10154 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10157 CHARPOS (this_line_start_pos
) = 0;
10158 consider_all_windows_p
|= buffer_shared
> 1;
10159 ++clear_face_cache_count
;
10162 /* Build desired matrices, and update the display. If
10163 consider_all_windows_p is non-zero, do it for all windows on all
10164 frames. Otherwise do it for selected_window, only. */
10166 if (consider_all_windows_p
)
10168 Lisp_Object tail
, frame
;
10169 int i
, n
= 0, size
= 50;
10170 struct frame
**updated
10171 = (struct frame
**) alloca (size
* sizeof *updated
);
10173 /* Clear the face cache eventually. */
10174 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10176 clear_face_cache (0);
10177 clear_face_cache_count
= 0;
10180 /* Recompute # windows showing selected buffer. This will be
10181 incremented each time such a window is displayed. */
10184 FOR_EACH_FRAME (tail
, frame
)
10186 struct frame
*f
= XFRAME (frame
);
10188 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10190 if (! EQ (frame
, selected_frame
))
10191 /* Select the frame, for the sake of frame-local
10193 select_frame_for_redisplay (frame
);
10195 #ifdef HAVE_WINDOW_SYSTEM
10196 if (clear_face_cache_count
% 50 == 0
10197 && FRAME_WINDOW_P (f
))
10198 clear_image_cache (f
, 0);
10199 #endif /* HAVE_WINDOW_SYSTEM */
10201 /* Mark all the scroll bars to be removed; we'll redeem
10202 the ones we want when we redisplay their windows. */
10203 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
10204 FRAME_DISPLAY (f
)->condemn_scroll_bars_hook (f
);
10206 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10207 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10209 /* Any scroll bars which redisplay_windows should have
10210 nuked should now go away. */
10211 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
10212 FRAME_DISPLAY (f
)->judge_scroll_bars_hook (f
);
10214 /* If fonts changed, display again. */
10215 /* ??? rms: I suspect it is a mistake to jump all the way
10216 back to retry here. It should just retry this frame. */
10217 if (fonts_changed_p
)
10220 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10222 /* See if we have to hscroll. */
10223 if (hscroll_windows (f
->root_window
))
10226 /* Prevent various kinds of signals during display
10227 update. stdio is not robust about handling
10228 signals, which can cause an apparent I/O
10230 if (interrupt_input
)
10231 unrequest_sigio ();
10234 /* Update the display. */
10235 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10236 pause
|= update_frame (f
, 0, 0);
10237 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10244 int nbytes
= size
* sizeof *updated
;
10245 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10246 bcopy (updated
, p
, nbytes
);
10257 /* Do the mark_window_display_accurate after all windows have
10258 been redisplayed because this call resets flags in buffers
10259 which are needed for proper redisplay. */
10260 for (i
= 0; i
< n
; ++i
)
10262 struct frame
*f
= updated
[i
];
10263 mark_window_display_accurate (f
->root_window
, 1);
10264 if (FRAME_DISPLAY (f
)->frame_up_to_date_hook
)
10265 FRAME_DISPLAY (f
)->frame_up_to_date_hook (f
);
10269 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10271 Lisp_Object mini_window
;
10272 struct frame
*mini_frame
;
10274 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10275 /* Use list_of_error, not Qerror, so that
10276 we catch only errors and don't run the debugger. */
10277 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10279 redisplay_window_error
);
10281 /* Compare desired and current matrices, perform output. */
10284 /* If fonts changed, display again. */
10285 if (fonts_changed_p
)
10288 /* Prevent various kinds of signals during display update.
10289 stdio is not robust about handling signals,
10290 which can cause an apparent I/O error. */
10291 if (interrupt_input
)
10292 unrequest_sigio ();
10295 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10297 if (hscroll_windows (selected_window
))
10300 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10301 pause
= update_frame (sf
, 0, 0);
10304 /* We may have called echo_area_display at the top of this
10305 function. If the echo area is on another frame, that may
10306 have put text on a frame other than the selected one, so the
10307 above call to update_frame would not have caught it. Catch
10309 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10310 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10312 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10314 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10315 pause
|= update_frame (mini_frame
, 0, 0);
10316 if (!pause
&& hscroll_windows (mini_window
))
10321 /* If display was paused because of pending input, make sure we do a
10322 thorough update the next time. */
10325 /* Prevent the optimization at the beginning of
10326 redisplay_internal that tries a single-line update of the
10327 line containing the cursor in the selected window. */
10328 CHARPOS (this_line_start_pos
) = 0;
10330 /* Let the overlay arrow be updated the next time. */
10331 update_overlay_arrows (0);
10333 /* If we pause after scrolling, some rows in the current
10334 matrices of some windows are not valid. */
10335 if (!WINDOW_FULL_WIDTH_P (w
)
10336 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10337 update_mode_lines
= 1;
10341 if (!consider_all_windows_p
)
10343 /* This has already been done above if
10344 consider_all_windows_p is set. */
10345 mark_window_display_accurate_1 (w
, 1);
10347 /* Say overlay arrows are up to date. */
10348 update_overlay_arrows (1);
10350 if (FRAME_DISPLAY (sf
)->frame_up_to_date_hook
!= 0)
10351 FRAME_DISPLAY (sf
)->frame_up_to_date_hook (sf
);
10354 update_mode_lines
= 0;
10355 windows_or_buffers_changed
= 0;
10356 cursor_type_changed
= 0;
10359 /* Start SIGIO interrupts coming again. Having them off during the
10360 code above makes it less likely one will discard output, but not
10361 impossible, since there might be stuff in the system buffer here.
10362 But it is much hairier to try to do anything about that. */
10363 if (interrupt_input
)
10367 /* If a frame has become visible which was not before, redisplay
10368 again, so that we display it. Expose events for such a frame
10369 (which it gets when becoming visible) don't call the parts of
10370 redisplay constructing glyphs, so simply exposing a frame won't
10371 display anything in this case. So, we have to display these
10372 frames here explicitly. */
10375 Lisp_Object tail
, frame
;
10378 FOR_EACH_FRAME (tail
, frame
)
10380 int this_is_visible
= 0;
10382 if (XFRAME (frame
)->visible
)
10383 this_is_visible
= 1;
10384 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10385 if (XFRAME (frame
)->visible
)
10386 this_is_visible
= 1;
10388 if (this_is_visible
)
10392 if (new_count
!= number_of_visible_frames
)
10393 windows_or_buffers_changed
++;
10396 /* Change frame size now if a change is pending. */
10397 do_pending_window_change (1);
10399 /* If we just did a pending size change, or have additional
10400 visible frames, redisplay again. */
10401 if (windows_or_buffers_changed
&& !pause
)
10405 unbind_to (count
, Qnil
);
10410 /* Redisplay, but leave alone any recent echo area message unless
10411 another message has been requested in its place.
10413 This is useful in situations where you need to redisplay but no
10414 user action has occurred, making it inappropriate for the message
10415 area to be cleared. See tracking_off and
10416 wait_reading_process_output for examples of these situations.
10418 FROM_WHERE is an integer saying from where this function was
10419 called. This is useful for debugging. */
10422 redisplay_preserve_echo_area (from_where
)
10425 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10427 if (!NILP (echo_area_buffer
[1]))
10429 /* We have a previously displayed message, but no current
10430 message. Redisplay the previous message. */
10431 display_last_displayed_message_p
= 1;
10432 redisplay_internal (1);
10433 display_last_displayed_message_p
= 0;
10436 redisplay_internal (1);
10438 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
10439 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10440 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
10444 /* Function registered with record_unwind_protect in
10445 redisplay_internal. Reset redisplaying_p to the value it had
10446 before redisplay_internal was called, and clear
10447 prevent_freeing_realized_faces_p. It also selects the previously
10451 unwind_redisplay (val
)
10454 Lisp_Object old_redisplaying_p
, old_frame
;
10456 old_redisplaying_p
= XCAR (val
);
10457 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10458 old_frame
= XCDR (val
);
10459 if (! EQ (old_frame
, selected_frame
))
10460 select_frame_for_redisplay (old_frame
);
10465 /* Mark the display of window W as accurate or inaccurate. If
10466 ACCURATE_P is non-zero mark display of W as accurate. If
10467 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10468 redisplay_internal is called. */
10471 mark_window_display_accurate_1 (w
, accurate_p
)
10475 if (BUFFERP (w
->buffer
))
10477 struct buffer
*b
= XBUFFER (w
->buffer
);
10480 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10481 w
->last_overlay_modified
10482 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10484 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10488 b
->clip_changed
= 0;
10489 b
->prevent_redisplay_optimizations_p
= 0;
10491 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10492 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10493 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10494 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10496 w
->current_matrix
->buffer
= b
;
10497 w
->current_matrix
->begv
= BUF_BEGV (b
);
10498 w
->current_matrix
->zv
= BUF_ZV (b
);
10500 w
->last_cursor
= w
->cursor
;
10501 w
->last_cursor_off_p
= w
->cursor_off_p
;
10503 if (w
== XWINDOW (selected_window
))
10504 w
->last_point
= make_number (BUF_PT (b
));
10506 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10512 w
->window_end_valid
= w
->buffer
;
10513 #if 0 /* This is incorrect with variable-height lines. */
10514 xassert (XINT (w
->window_end_vpos
)
10515 < (WINDOW_TOTAL_LINES (w
)
10516 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10518 w
->update_mode_line
= Qnil
;
10523 /* Mark the display of windows in the window tree rooted at WINDOW as
10524 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10525 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10526 be redisplayed the next time redisplay_internal is called. */
10529 mark_window_display_accurate (window
, accurate_p
)
10530 Lisp_Object window
;
10535 for (; !NILP (window
); window
= w
->next
)
10537 w
= XWINDOW (window
);
10538 mark_window_display_accurate_1 (w
, accurate_p
);
10540 if (!NILP (w
->vchild
))
10541 mark_window_display_accurate (w
->vchild
, accurate_p
);
10542 if (!NILP (w
->hchild
))
10543 mark_window_display_accurate (w
->hchild
, accurate_p
);
10548 update_overlay_arrows (1);
10552 /* Force a thorough redisplay the next time by setting
10553 last_arrow_position and last_arrow_string to t, which is
10554 unequal to any useful value of Voverlay_arrow_... */
10555 update_overlay_arrows (-1);
10560 /* Return value in display table DP (Lisp_Char_Table *) for character
10561 C. Since a display table doesn't have any parent, we don't have to
10562 follow parent. Do not call this function directly but use the
10563 macro DISP_CHAR_VECTOR. */
10566 disp_char_vector (dp
, c
)
10567 struct Lisp_Char_Table
*dp
;
10573 if (SINGLE_BYTE_CHAR_P (c
))
10574 return (dp
->contents
[c
]);
10576 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10579 else if (code
[2] < 32)
10582 /* Here, the possible range of code[0] (== charset ID) is
10583 128..max_charset. Since the top level char table contains data
10584 for multibyte characters after 256th element, we must increment
10585 code[0] by 128 to get a correct index. */
10587 code
[3] = -1; /* anchor */
10589 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10591 val
= dp
->contents
[code
[i
]];
10592 if (!SUB_CHAR_TABLE_P (val
))
10593 return (NILP (val
) ? dp
->defalt
: val
);
10596 /* Here, val is a sub char table. We return the default value of
10598 return (dp
->defalt
);
10603 /***********************************************************************
10605 ***********************************************************************/
10607 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10610 redisplay_windows (window
)
10611 Lisp_Object window
;
10613 while (!NILP (window
))
10615 struct window
*w
= XWINDOW (window
);
10617 if (!NILP (w
->hchild
))
10618 redisplay_windows (w
->hchild
);
10619 else if (!NILP (w
->vchild
))
10620 redisplay_windows (w
->vchild
);
10623 displayed_buffer
= XBUFFER (w
->buffer
);
10624 /* Use list_of_error, not Qerror, so that
10625 we catch only errors and don't run the debugger. */
10626 internal_condition_case_1 (redisplay_window_0
, window
,
10628 redisplay_window_error
);
10636 redisplay_window_error ()
10638 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10643 redisplay_window_0 (window
)
10644 Lisp_Object window
;
10646 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10647 redisplay_window (window
, 0);
10652 redisplay_window_1 (window
)
10653 Lisp_Object window
;
10655 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10656 redisplay_window (window
, 1);
10661 /* Increment GLYPH until it reaches END or CONDITION fails while
10662 adding (GLYPH)->pixel_width to X. */
10664 #define SKIP_GLYPHS(glyph, end, x, condition) \
10667 (x) += (glyph)->pixel_width; \
10670 while ((glyph) < (end) && (condition))
10673 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10674 DELTA is the number of bytes by which positions recorded in ROW
10675 differ from current buffer positions. */
10678 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10680 struct glyph_row
*row
;
10681 struct glyph_matrix
*matrix
;
10682 int delta
, delta_bytes
, dy
, dvpos
;
10684 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10685 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10686 struct glyph
*cursor
= NULL
;
10687 /* The first glyph that starts a sequence of glyphs from string. */
10688 struct glyph
*string_start
;
10689 /* The X coordinate of string_start. */
10690 int string_start_x
;
10691 /* The last known character position. */
10692 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10693 /* The last known character position before string_start. */
10694 int string_before_pos
;
10697 int cursor_from_overlay_pos
= 0;
10698 int pt_old
= PT
- delta
;
10700 /* Skip over glyphs not having an object at the start of the row.
10701 These are special glyphs like truncation marks on terminal
10703 if (row
->displays_text_p
)
10705 && INTEGERP (glyph
->object
)
10706 && glyph
->charpos
< 0)
10708 x
+= glyph
->pixel_width
;
10712 string_start
= NULL
;
10714 && !INTEGERP (glyph
->object
)
10715 && (!BUFFERP (glyph
->object
)
10716 || (last_pos
= glyph
->charpos
) < pt_old
))
10718 if (! STRINGP (glyph
->object
))
10720 string_start
= NULL
;
10721 x
+= glyph
->pixel_width
;
10723 if (cursor_from_overlay_pos
10724 && last_pos
> cursor_from_overlay_pos
)
10726 cursor_from_overlay_pos
= 0;
10732 string_before_pos
= last_pos
;
10733 string_start
= glyph
;
10734 string_start_x
= x
;
10735 /* Skip all glyphs from string. */
10739 if ((cursor
== NULL
|| glyph
> cursor
)
10740 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
10741 Qcursor
, (glyph
)->object
))
10742 && (pos
= string_buffer_position (w
, glyph
->object
,
10743 string_before_pos
),
10744 (pos
== 0 /* From overlay */
10745 || pos
== pt_old
)))
10747 /* Estimate overlay buffer position from the buffer
10748 positions of the glyphs before and after the overlay.
10749 Add 1 to last_pos so that if point corresponds to the
10750 glyph right after the overlay, we still use a 'cursor'
10751 property found in that overlay. */
10752 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
10756 x
+= glyph
->pixel_width
;
10759 while (glyph
< end
&& STRINGP (glyph
->object
));
10763 if (cursor
!= NULL
)
10768 else if (string_start
10769 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10771 /* We may have skipped over point because the previous glyphs
10772 are from string. As there's no easy way to know the
10773 character position of the current glyph, find the correct
10774 glyph on point by scanning from string_start again. */
10776 Lisp_Object string
;
10779 limit
= make_number (pt_old
+ 1);
10781 glyph
= string_start
;
10782 x
= string_start_x
;
10783 string
= glyph
->object
;
10784 pos
= string_buffer_position (w
, string
, string_before_pos
);
10785 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10786 because we always put cursor after overlay strings. */
10787 while (pos
== 0 && glyph
< end
)
10789 string
= glyph
->object
;
10790 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10792 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10795 while (glyph
< end
)
10797 pos
= XINT (Fnext_single_char_property_change
10798 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10801 /* Skip glyphs from the same string. */
10802 string
= glyph
->object
;
10803 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10804 /* Skip glyphs from an overlay. */
10806 && ! string_buffer_position (w
, glyph
->object
, pos
))
10808 string
= glyph
->object
;
10809 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10814 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10816 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10817 w
->cursor
.y
= row
->y
+ dy
;
10819 if (w
== XWINDOW (selected_window
))
10821 if (!row
->continued_p
10822 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10825 this_line_buffer
= XBUFFER (w
->buffer
);
10827 CHARPOS (this_line_start_pos
)
10828 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10829 BYTEPOS (this_line_start_pos
)
10830 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10832 CHARPOS (this_line_end_pos
)
10833 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10834 BYTEPOS (this_line_end_pos
)
10835 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10837 this_line_y
= w
->cursor
.y
;
10838 this_line_pixel_height
= row
->height
;
10839 this_line_vpos
= w
->cursor
.vpos
;
10840 this_line_start_x
= row
->x
;
10843 CHARPOS (this_line_start_pos
) = 0;
10848 /* Run window scroll functions, if any, for WINDOW with new window
10849 start STARTP. Sets the window start of WINDOW to that position.
10851 We assume that the window's buffer is really current. */
10853 static INLINE
struct text_pos
10854 run_window_scroll_functions (window
, startp
)
10855 Lisp_Object window
;
10856 struct text_pos startp
;
10858 struct window
*w
= XWINDOW (window
);
10859 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10861 if (current_buffer
!= XBUFFER (w
->buffer
))
10864 if (!NILP (Vwindow_scroll_functions
))
10866 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10867 make_number (CHARPOS (startp
)));
10868 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10869 /* In case the hook functions switch buffers. */
10870 if (current_buffer
!= XBUFFER (w
->buffer
))
10871 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10878 /* Make sure the line containing the cursor is fully visible.
10879 A value of 1 means there is nothing to be done.
10880 (Either the line is fully visible, or it cannot be made so,
10881 or we cannot tell.)
10883 If FORCE_P is non-zero, return 0 even if partial visible cursor row
10884 is higher than window.
10886 A value of 0 means the caller should do scrolling
10887 as if point had gone off the screen. */
10890 make_cursor_line_fully_visible (w
, force_p
)
10894 struct glyph_matrix
*matrix
;
10895 struct glyph_row
*row
;
10898 if (!make_cursor_line_fully_visible_p
)
10901 /* It's not always possible to find the cursor, e.g, when a window
10902 is full of overlay strings. Don't do anything in that case. */
10903 if (w
->cursor
.vpos
< 0)
10906 matrix
= w
->desired_matrix
;
10907 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10909 /* If the cursor row is not partially visible, there's nothing to do. */
10910 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
10913 /* If the row the cursor is in is taller than the window's height,
10914 it's not clear what to do, so do nothing. */
10915 window_height
= window_box_height (w
);
10916 if (row
->height
>= window_height
)
10918 if (!force_p
|| w
->vscroll
)
10924 /* This code used to try to scroll the window just enough to make
10925 the line visible. It returned 0 to say that the caller should
10926 allocate larger glyph matrices. */
10928 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10930 int dy
= row
->height
- row
->visible_height
;
10933 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10935 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10937 int dy
= - (row
->height
- row
->visible_height
);
10940 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10943 /* When we change the cursor y-position of the selected window,
10944 change this_line_y as well so that the display optimization for
10945 the cursor line of the selected window in redisplay_internal uses
10946 the correct y-position. */
10947 if (w
== XWINDOW (selected_window
))
10948 this_line_y
= w
->cursor
.y
;
10950 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10951 redisplay with larger matrices. */
10952 if (matrix
->nrows
< required_matrix_height (w
))
10954 fonts_changed_p
= 1;
10963 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10964 non-zero means only WINDOW is redisplayed in redisplay_internal.
10965 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10966 in redisplay_window to bring a partially visible line into view in
10967 the case that only the cursor has moved.
10969 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10970 last screen line's vertical height extends past the end of the screen.
10974 1 if scrolling succeeded
10976 0 if scrolling didn't find point.
10978 -1 if new fonts have been loaded so that we must interrupt
10979 redisplay, adjust glyph matrices, and try again. */
10985 SCROLLING_NEED_LARGER_MATRICES
10989 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10990 scroll_step
, temp_scroll_step
, last_line_misfit
)
10991 Lisp_Object window
;
10992 int just_this_one_p
;
10993 EMACS_INT scroll_conservatively
, scroll_step
;
10994 int temp_scroll_step
;
10995 int last_line_misfit
;
10997 struct window
*w
= XWINDOW (window
);
10998 struct frame
*f
= XFRAME (w
->frame
);
10999 struct text_pos scroll_margin_pos
;
11000 struct text_pos pos
;
11001 struct text_pos startp
;
11003 Lisp_Object window_end
;
11004 int this_scroll_margin
;
11008 int amount_to_scroll
= 0;
11009 Lisp_Object aggressive
;
11011 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11014 debug_method_add (w
, "try_scrolling");
11017 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11019 /* Compute scroll margin height in pixels. We scroll when point is
11020 within this distance from the top or bottom of the window. */
11021 if (scroll_margin
> 0)
11023 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11024 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11027 this_scroll_margin
= 0;
11029 /* Force scroll_conservatively to have a reasonable value so it doesn't
11030 cause an overflow while computing how much to scroll. */
11031 if (scroll_conservatively
)
11032 scroll_conservatively
= min (scroll_conservatively
,
11033 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11035 /* Compute how much we should try to scroll maximally to bring point
11037 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11038 scroll_max
= max (scroll_step
,
11039 max (scroll_conservatively
, temp_scroll_step
));
11040 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11041 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11042 /* We're trying to scroll because of aggressive scrolling
11043 but no scroll_step is set. Choose an arbitrary one. Maybe
11044 there should be a variable for this. */
11048 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11050 /* Decide whether we have to scroll down. Start at the window end
11051 and move this_scroll_margin up to find the position of the scroll
11053 window_end
= Fwindow_end (window
, Qt
);
11057 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11058 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11060 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11062 start_display (&it
, w
, scroll_margin_pos
);
11063 if (this_scroll_margin
)
11064 move_it_vertically_backward (&it
, this_scroll_margin
);
11065 if (extra_scroll_margin_lines
)
11066 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11067 scroll_margin_pos
= it
.current
.pos
;
11070 if (PT
>= CHARPOS (scroll_margin_pos
))
11074 /* Point is in the scroll margin at the bottom of the window, or
11075 below. Compute a new window start that makes point visible. */
11077 /* Compute the distance from the scroll margin to PT.
11078 Give up if the distance is greater than scroll_max. */
11079 start_display (&it
, w
, scroll_margin_pos
);
11081 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11082 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11084 /* To make point visible, we have to move the window start
11085 down so that the line the cursor is in is visible, which
11086 means we have to add in the height of the cursor line. */
11087 dy
= line_bottom_y (&it
) - y0
;
11089 if (dy
> scroll_max
)
11090 return SCROLLING_FAILED
;
11092 /* Move the window start down. If scrolling conservatively,
11093 move it just enough down to make point visible. If
11094 scroll_step is set, move it down by scroll_step. */
11095 start_display (&it
, w
, startp
);
11097 if (scroll_conservatively
)
11098 /* Set AMOUNT_TO_SCROLL to at least one line,
11099 and at most scroll_conservatively lines. */
11101 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11102 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11103 else if (scroll_step
|| temp_scroll_step
)
11104 amount_to_scroll
= scroll_max
;
11107 aggressive
= current_buffer
->scroll_up_aggressively
;
11108 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11109 if (NUMBERP (aggressive
))
11111 double float_amount
= XFLOATINT (aggressive
) * height
;
11112 amount_to_scroll
= float_amount
;
11113 if (amount_to_scroll
== 0 && float_amount
> 0)
11114 amount_to_scroll
= 1;
11118 if (amount_to_scroll
<= 0)
11119 return SCROLLING_FAILED
;
11121 /* If moving by amount_to_scroll leaves STARTP unchanged,
11122 move it down one screen line. */
11124 move_it_vertically (&it
, amount_to_scroll
);
11125 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11126 move_it_by_lines (&it
, 1, 1);
11127 startp
= it
.current
.pos
;
11131 /* See if point is inside the scroll margin at the top of the
11133 scroll_margin_pos
= startp
;
11134 if (this_scroll_margin
)
11136 start_display (&it
, w
, startp
);
11137 move_it_vertically (&it
, this_scroll_margin
);
11138 scroll_margin_pos
= it
.current
.pos
;
11141 if (PT
< CHARPOS (scroll_margin_pos
))
11143 /* Point is in the scroll margin at the top of the window or
11144 above what is displayed in the window. */
11147 /* Compute the vertical distance from PT to the scroll
11148 margin position. Give up if distance is greater than
11150 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11151 start_display (&it
, w
, pos
);
11153 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11154 it
.last_visible_y
, -1,
11155 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11156 dy
= it
.current_y
- y0
;
11157 if (dy
> scroll_max
)
11158 return SCROLLING_FAILED
;
11160 /* Compute new window start. */
11161 start_display (&it
, w
, startp
);
11163 if (scroll_conservatively
)
11165 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11166 else if (scroll_step
|| temp_scroll_step
)
11167 amount_to_scroll
= scroll_max
;
11170 aggressive
= current_buffer
->scroll_down_aggressively
;
11171 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11172 if (NUMBERP (aggressive
))
11174 double float_amount
= XFLOATINT (aggressive
) * height
;
11175 amount_to_scroll
= float_amount
;
11176 if (amount_to_scroll
== 0 && float_amount
> 0)
11177 amount_to_scroll
= 1;
11181 if (amount_to_scroll
<= 0)
11182 return SCROLLING_FAILED
;
11184 move_it_vertically_backward (&it
, amount_to_scroll
);
11185 startp
= it
.current
.pos
;
11189 /* Run window scroll functions. */
11190 startp
= run_window_scroll_functions (window
, startp
);
11192 /* Display the window. Give up if new fonts are loaded, or if point
11194 if (!try_window (window
, startp
))
11195 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11196 else if (w
->cursor
.vpos
< 0)
11198 clear_glyph_matrix (w
->desired_matrix
);
11199 rc
= SCROLLING_FAILED
;
11203 /* Maybe forget recorded base line for line number display. */
11204 if (!just_this_one_p
11205 || current_buffer
->clip_changed
11206 || BEG_UNCHANGED
< CHARPOS (startp
))
11207 w
->base_line_number
= Qnil
;
11209 /* If cursor ends up on a partially visible line,
11210 treat that as being off the bottom of the screen. */
11211 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11213 clear_glyph_matrix (w
->desired_matrix
);
11214 ++extra_scroll_margin_lines
;
11217 rc
= SCROLLING_SUCCESS
;
11224 /* Compute a suitable window start for window W if display of W starts
11225 on a continuation line. Value is non-zero if a new window start
11228 The new window start will be computed, based on W's width, starting
11229 from the start of the continued line. It is the start of the
11230 screen line with the minimum distance from the old start W->start. */
11233 compute_window_start_on_continuation_line (w
)
11236 struct text_pos pos
, start_pos
;
11237 int window_start_changed_p
= 0;
11239 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11241 /* If window start is on a continuation line... Window start may be
11242 < BEGV in case there's invisible text at the start of the
11243 buffer (M-x rmail, for example). */
11244 if (CHARPOS (start_pos
) > BEGV
11245 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11248 struct glyph_row
*row
;
11250 /* Handle the case that the window start is out of range. */
11251 if (CHARPOS (start_pos
) < BEGV
)
11252 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11253 else if (CHARPOS (start_pos
) > ZV
)
11254 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11256 /* Find the start of the continued line. This should be fast
11257 because scan_buffer is fast (newline cache). */
11258 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11259 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11260 row
, DEFAULT_FACE_ID
);
11261 reseat_at_previous_visible_line_start (&it
);
11263 /* If the line start is "too far" away from the window start,
11264 say it takes too much time to compute a new window start. */
11265 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11266 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11268 int min_distance
, distance
;
11270 /* Move forward by display lines to find the new window
11271 start. If window width was enlarged, the new start can
11272 be expected to be > the old start. If window width was
11273 decreased, the new window start will be < the old start.
11274 So, we're looking for the display line start with the
11275 minimum distance from the old window start. */
11276 pos
= it
.current
.pos
;
11277 min_distance
= INFINITY
;
11278 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11279 distance
< min_distance
)
11281 min_distance
= distance
;
11282 pos
= it
.current
.pos
;
11283 move_it_by_lines (&it
, 1, 0);
11286 /* Set the window start there. */
11287 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11288 window_start_changed_p
= 1;
11292 return window_start_changed_p
;
11296 /* Try cursor movement in case text has not changed in window WINDOW,
11297 with window start STARTP. Value is
11299 CURSOR_MOVEMENT_SUCCESS if successful
11301 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11303 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11304 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11305 we want to scroll as if scroll-step were set to 1. See the code.
11307 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11308 which case we have to abort this redisplay, and adjust matrices
11313 CURSOR_MOVEMENT_SUCCESS
,
11314 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11315 CURSOR_MOVEMENT_MUST_SCROLL
,
11316 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11320 try_cursor_movement (window
, startp
, scroll_step
)
11321 Lisp_Object window
;
11322 struct text_pos startp
;
11325 struct window
*w
= XWINDOW (window
);
11326 struct frame
*f
= XFRAME (w
->frame
);
11327 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11330 if (inhibit_try_cursor_movement
)
11334 /* Handle case where text has not changed, only point, and it has
11335 not moved off the frame. */
11336 if (/* Point may be in this window. */
11337 PT
>= CHARPOS (startp
)
11338 /* Selective display hasn't changed. */
11339 && !current_buffer
->clip_changed
11340 /* Function force-mode-line-update is used to force a thorough
11341 redisplay. It sets either windows_or_buffers_changed or
11342 update_mode_lines. So don't take a shortcut here for these
11344 && !update_mode_lines
11345 && !windows_or_buffers_changed
11346 && !cursor_type_changed
11347 /* Can't use this case if highlighting a region. When a
11348 region exists, cursor movement has to do more than just
11350 && !(!NILP (Vtransient_mark_mode
)
11351 && !NILP (current_buffer
->mark_active
))
11352 && NILP (w
->region_showing
)
11353 && NILP (Vshow_trailing_whitespace
)
11354 /* Right after splitting windows, last_point may be nil. */
11355 && INTEGERP (w
->last_point
)
11356 /* This code is not used for mini-buffer for the sake of the case
11357 of redisplaying to replace an echo area message; since in
11358 that case the mini-buffer contents per se are usually
11359 unchanged. This code is of no real use in the mini-buffer
11360 since the handling of this_line_start_pos, etc., in redisplay
11361 handles the same cases. */
11362 && !EQ (window
, minibuf_window
)
11363 /* When splitting windows or for new windows, it happens that
11364 redisplay is called with a nil window_end_vpos or one being
11365 larger than the window. This should really be fixed in
11366 window.c. I don't have this on my list, now, so we do
11367 approximately the same as the old redisplay code. --gerd. */
11368 && INTEGERP (w
->window_end_vpos
)
11369 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11370 && (FRAME_WINDOW_P (f
)
11371 || !overlay_arrow_in_current_buffer_p ()))
11373 int this_scroll_margin
, top_scroll_margin
;
11374 struct glyph_row
*row
= NULL
;
11377 debug_method_add (w
, "cursor movement");
11380 /* Scroll if point within this distance from the top or bottom
11381 of the window. This is a pixel value. */
11382 this_scroll_margin
= max (0, scroll_margin
);
11383 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11384 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11386 top_scroll_margin
= this_scroll_margin
;
11387 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11388 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11390 /* Start with the row the cursor was displayed during the last
11391 not paused redisplay. Give up if that row is not valid. */
11392 if (w
->last_cursor
.vpos
< 0
11393 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11394 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11397 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11398 if (row
->mode_line_p
)
11400 if (!row
->enabled_p
)
11401 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11404 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11407 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11409 if (PT
> XFASTINT (w
->last_point
))
11411 /* Point has moved forward. */
11412 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11413 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11415 xassert (row
->enabled_p
);
11419 /* The end position of a row equals the start position
11420 of the next row. If PT is there, we would rather
11421 display it in the next line. */
11422 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11423 && MATRIX_ROW_END_CHARPOS (row
) == PT
11424 && !cursor_row_p (w
, row
))
11427 /* If within the scroll margin, scroll. Note that
11428 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11429 the next line would be drawn, and that
11430 this_scroll_margin can be zero. */
11431 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11432 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11433 /* Line is completely visible last line in window
11434 and PT is to be set in the next line. */
11435 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11436 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11437 && !row
->ends_at_zv_p
11438 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11441 else if (PT
< XFASTINT (w
->last_point
))
11443 /* Cursor has to be moved backward. Note that PT >=
11444 CHARPOS (startp) because of the outer if-statement. */
11445 while (!row
->mode_line_p
11446 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11447 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11448 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11449 && (row
->y
> top_scroll_margin
11450 || CHARPOS (startp
) == BEGV
))
11452 xassert (row
->enabled_p
);
11456 /* Consider the following case: Window starts at BEGV,
11457 there is invisible, intangible text at BEGV, so that
11458 display starts at some point START > BEGV. It can
11459 happen that we are called with PT somewhere between
11460 BEGV and START. Try to handle that case. */
11461 if (row
< w
->current_matrix
->rows
11462 || row
->mode_line_p
)
11464 row
= w
->current_matrix
->rows
;
11465 if (row
->mode_line_p
)
11469 /* Due to newlines in overlay strings, we may have to
11470 skip forward over overlay strings. */
11471 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11472 && MATRIX_ROW_END_CHARPOS (row
) == PT
11473 && !cursor_row_p (w
, row
))
11476 /* If within the scroll margin, scroll. */
11477 if (row
->y
< top_scroll_margin
11478 && CHARPOS (startp
) != BEGV
)
11482 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11483 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11485 /* if PT is not in the glyph row, give up. */
11486 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11488 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11489 && make_cursor_line_fully_visible_p
)
11491 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11492 && !row
->ends_at_zv_p
11493 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11494 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11495 else if (row
->height
> window_box_height (w
))
11497 /* If we end up in a partially visible line, let's
11498 make it fully visible, except when it's taller
11499 than the window, in which case we can't do much
11502 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11506 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11507 if (!make_cursor_line_fully_visible (w
, 0))
11508 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11510 rc
= CURSOR_MOVEMENT_SUCCESS
;
11514 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11517 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11518 rc
= CURSOR_MOVEMENT_SUCCESS
;
11527 set_vertical_scroll_bar (w
)
11530 int start
, end
, whole
;
11532 /* Calculate the start and end positions for the current window.
11533 At some point, it would be nice to choose between scrollbars
11534 which reflect the whole buffer size, with special markers
11535 indicating narrowing, and scrollbars which reflect only the
11538 Note that mini-buffers sometimes aren't displaying any text. */
11539 if (!MINI_WINDOW_P (w
)
11540 || (w
== XWINDOW (minibuf_window
)
11541 && NILP (echo_area_buffer
[0])))
11543 struct buffer
*buf
= XBUFFER (w
->buffer
);
11544 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11545 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11546 /* I don't think this is guaranteed to be right. For the
11547 moment, we'll pretend it is. */
11548 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11552 if (whole
< (end
- start
))
11553 whole
= end
- start
;
11556 start
= end
= whole
= 0;
11558 /* Indicate what this scroll bar ought to be displaying now. */
11559 if (FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11560 (*FRAME_DISPLAY (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
11561 (w
, end
- start
, whole
, start
);
11565 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11566 selected_window is redisplayed.
11568 We can return without actually redisplaying the window if
11569 fonts_changed_p is nonzero. In that case, redisplay_internal will
11573 redisplay_window (window
, just_this_one_p
)
11574 Lisp_Object window
;
11575 int just_this_one_p
;
11577 struct window
*w
= XWINDOW (window
);
11578 struct frame
*f
= XFRAME (w
->frame
);
11579 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11580 struct buffer
*old
= current_buffer
;
11581 struct text_pos lpoint
, opoint
, startp
;
11582 int update_mode_line
;
11585 /* Record it now because it's overwritten. */
11586 int current_matrix_up_to_date_p
= 0;
11587 int used_current_matrix_p
= 0;
11588 /* This is less strict than current_matrix_up_to_date_p.
11589 It indictes that the buffer contents and narrowing are unchanged. */
11590 int buffer_unchanged_p
= 0;
11591 int temp_scroll_step
= 0;
11592 int count
= SPECPDL_INDEX ();
11594 int centering_position
;
11595 int last_line_misfit
= 0;
11597 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11600 /* W must be a leaf window here. */
11601 xassert (!NILP (w
->buffer
));
11603 *w
->desired_matrix
->method
= 0;
11606 specbind (Qinhibit_point_motion_hooks
, Qt
);
11608 reconsider_clip_changes (w
, buffer
);
11610 /* Has the mode line to be updated? */
11611 update_mode_line
= (!NILP (w
->update_mode_line
)
11612 || update_mode_lines
11613 || buffer
->clip_changed
11614 || buffer
->prevent_redisplay_optimizations_p
);
11616 if (MINI_WINDOW_P (w
))
11618 if (w
== XWINDOW (echo_area_window
)
11619 && !NILP (echo_area_buffer
[0]))
11621 if (update_mode_line
)
11622 /* We may have to update a tty frame's menu bar or a
11623 tool-bar. Example `M-x C-h C-h C-g'. */
11624 goto finish_menu_bars
;
11626 /* We've already displayed the echo area glyphs in this window. */
11627 goto finish_scroll_bars
;
11629 else if ((w
!= XWINDOW (minibuf_window
)
11630 || minibuf_level
== 0)
11631 /* When buffer is nonempty, redisplay window normally. */
11632 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11633 /* Quail displays non-mini buffers in minibuffer window.
11634 In that case, redisplay the window normally. */
11635 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11637 /* W is a mini-buffer window, but it's not active, so clear
11639 int yb
= window_text_bottom_y (w
);
11640 struct glyph_row
*row
;
11643 for (y
= 0, row
= w
->desired_matrix
->rows
;
11645 y
+= row
->height
, ++row
)
11646 blank_row (w
, row
, y
);
11647 goto finish_scroll_bars
;
11650 clear_glyph_matrix (w
->desired_matrix
);
11653 /* Otherwise set up data on this window; select its buffer and point
11655 /* Really select the buffer, for the sake of buffer-local
11657 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11658 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11660 current_matrix_up_to_date_p
11661 = (!NILP (w
->window_end_valid
)
11662 && !current_buffer
->clip_changed
11663 && !current_buffer
->prevent_redisplay_optimizations_p
11664 && XFASTINT (w
->last_modified
) >= MODIFF
11665 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11668 = (!NILP (w
->window_end_valid
)
11669 && !current_buffer
->clip_changed
11670 && XFASTINT (w
->last_modified
) >= MODIFF
11671 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11673 /* When windows_or_buffers_changed is non-zero, we can't rely on
11674 the window end being valid, so set it to nil there. */
11675 if (windows_or_buffers_changed
)
11677 /* If window starts on a continuation line, maybe adjust the
11678 window start in case the window's width changed. */
11679 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11680 compute_window_start_on_continuation_line (w
);
11682 w
->window_end_valid
= Qnil
;
11685 /* Some sanity checks. */
11686 CHECK_WINDOW_END (w
);
11687 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11689 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11692 /* If %c is in mode line, update it if needed. */
11693 if (!NILP (w
->column_number_displayed
)
11694 /* This alternative quickly identifies a common case
11695 where no change is needed. */
11696 && !(PT
== XFASTINT (w
->last_point
)
11697 && XFASTINT (w
->last_modified
) >= MODIFF
11698 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11699 && (XFASTINT (w
->column_number_displayed
)
11700 != (int) current_column ())) /* iftc */
11701 update_mode_line
= 1;
11703 /* Count number of windows showing the selected buffer. An indirect
11704 buffer counts as its base buffer. */
11705 if (!just_this_one_p
)
11707 struct buffer
*current_base
, *window_base
;
11708 current_base
= current_buffer
;
11709 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11710 if (current_base
->base_buffer
)
11711 current_base
= current_base
->base_buffer
;
11712 if (window_base
->base_buffer
)
11713 window_base
= window_base
->base_buffer
;
11714 if (current_base
== window_base
)
11718 /* Point refers normally to the selected window. For any other
11719 window, set up appropriate value. */
11720 if (!EQ (window
, selected_window
))
11722 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11723 int new_pt_byte
= marker_byte_position (w
->pointm
);
11727 new_pt_byte
= BEGV_BYTE
;
11728 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11730 else if (new_pt
> (ZV
- 1))
11733 new_pt_byte
= ZV_BYTE
;
11734 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11737 /* We don't use SET_PT so that the point-motion hooks don't run. */
11738 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11741 /* If any of the character widths specified in the display table
11742 have changed, invalidate the width run cache. It's true that
11743 this may be a bit late to catch such changes, but the rest of
11744 redisplay goes (non-fatally) haywire when the display table is
11745 changed, so why should we worry about doing any better? */
11746 if (current_buffer
->width_run_cache
)
11748 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11750 if (! disptab_matches_widthtab (disptab
,
11751 XVECTOR (current_buffer
->width_table
)))
11753 invalidate_region_cache (current_buffer
,
11754 current_buffer
->width_run_cache
,
11756 recompute_width_table (current_buffer
, disptab
);
11760 /* If window-start is screwed up, choose a new one. */
11761 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11764 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11766 /* If someone specified a new starting point but did not insist,
11767 check whether it can be used. */
11768 if (!NILP (w
->optional_new_start
)
11769 && CHARPOS (startp
) >= BEGV
11770 && CHARPOS (startp
) <= ZV
)
11772 w
->optional_new_start
= Qnil
;
11773 start_display (&it
, w
, startp
);
11774 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11775 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11776 if (IT_CHARPOS (it
) == PT
)
11777 w
->force_start
= Qt
;
11778 /* IT may overshoot PT if text at PT is invisible. */
11779 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11780 w
->force_start
= Qt
;
11785 /* Handle case where place to start displaying has been specified,
11786 unless the specified location is outside the accessible range. */
11787 if (!NILP (w
->force_start
)
11788 || w
->frozen_window_start_p
)
11790 /* We set this later on if we have to adjust point. */
11793 w
->force_start
= Qnil
;
11795 w
->window_end_valid
= Qnil
;
11797 /* Forget any recorded base line for line number display. */
11798 if (!buffer_unchanged_p
)
11799 w
->base_line_number
= Qnil
;
11801 /* Redisplay the mode line. Select the buffer properly for that.
11802 Also, run the hook window-scroll-functions
11803 because we have scrolled. */
11804 /* Note, we do this after clearing force_start because
11805 if there's an error, it is better to forget about force_start
11806 than to get into an infinite loop calling the hook functions
11807 and having them get more errors. */
11808 if (!update_mode_line
11809 || ! NILP (Vwindow_scroll_functions
))
11811 update_mode_line
= 1;
11812 w
->update_mode_line
= Qt
;
11813 startp
= run_window_scroll_functions (window
, startp
);
11816 w
->last_modified
= make_number (0);
11817 w
->last_overlay_modified
= make_number (0);
11818 if (CHARPOS (startp
) < BEGV
)
11819 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11820 else if (CHARPOS (startp
) > ZV
)
11821 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11823 /* Redisplay, then check if cursor has been set during the
11824 redisplay. Give up if new fonts were loaded. */
11825 if (!try_window (window
, startp
))
11827 w
->force_start
= Qt
;
11828 clear_glyph_matrix (w
->desired_matrix
);
11829 goto need_larger_matrices
;
11832 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11834 /* If point does not appear, try to move point so it does
11835 appear. The desired matrix has been built above, so we
11836 can use it here. */
11837 new_vpos
= window_box_height (w
) / 2;
11840 if (!make_cursor_line_fully_visible (w
, 0))
11842 /* Point does appear, but on a line partly visible at end of window.
11843 Move it back to a fully-visible line. */
11844 new_vpos
= window_box_height (w
);
11847 /* If we need to move point for either of the above reasons,
11848 now actually do it. */
11851 struct glyph_row
*row
;
11853 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11854 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11857 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11858 MATRIX_ROW_START_BYTEPOS (row
));
11860 if (w
!= XWINDOW (selected_window
))
11861 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11862 else if (current_buffer
== old
)
11863 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11865 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11867 /* If we are highlighting the region, then we just changed
11868 the region, so redisplay to show it. */
11869 if (!NILP (Vtransient_mark_mode
)
11870 && !NILP (current_buffer
->mark_active
))
11872 clear_glyph_matrix (w
->desired_matrix
);
11873 if (!try_window (window
, startp
))
11874 goto need_larger_matrices
;
11879 debug_method_add (w
, "forced window start");
11884 /* Handle case where text has not changed, only point, and it has
11885 not moved off the frame, and we are not retrying after hscroll.
11886 (current_matrix_up_to_date_p is nonzero when retrying.) */
11887 if (current_matrix_up_to_date_p
11888 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11889 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11893 case CURSOR_MOVEMENT_SUCCESS
:
11894 used_current_matrix_p
= 1;
11897 #if 0 /* try_cursor_movement never returns this value. */
11898 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11899 goto need_larger_matrices
;
11902 case CURSOR_MOVEMENT_MUST_SCROLL
:
11903 goto try_to_scroll
;
11909 /* If current starting point was originally the beginning of a line
11910 but no longer is, find a new starting point. */
11911 else if (!NILP (w
->start_at_line_beg
)
11912 && !(CHARPOS (startp
) <= BEGV
11913 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11916 debug_method_add (w
, "recenter 1");
11921 /* Try scrolling with try_window_id. Value is > 0 if update has
11922 been done, it is -1 if we know that the same window start will
11923 not work. It is 0 if unsuccessful for some other reason. */
11924 else if ((tem
= try_window_id (w
)) != 0)
11927 debug_method_add (w
, "try_window_id %d", tem
);
11930 if (fonts_changed_p
)
11931 goto need_larger_matrices
;
11935 /* Otherwise try_window_id has returned -1 which means that we
11936 don't want the alternative below this comment to execute. */
11938 else if (CHARPOS (startp
) >= BEGV
11939 && CHARPOS (startp
) <= ZV
11940 && PT
>= CHARPOS (startp
)
11941 && (CHARPOS (startp
) < ZV
11942 /* Avoid starting at end of buffer. */
11943 || CHARPOS (startp
) == BEGV
11944 || (XFASTINT (w
->last_modified
) >= MODIFF
11945 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11948 debug_method_add (w
, "same window start");
11951 /* Try to redisplay starting at same place as before.
11952 If point has not moved off frame, accept the results. */
11953 if (!current_matrix_up_to_date_p
11954 /* Don't use try_window_reusing_current_matrix in this case
11955 because a window scroll function can have changed the
11957 || !NILP (Vwindow_scroll_functions
)
11958 || MINI_WINDOW_P (w
)
11959 || !(used_current_matrix_p
11960 = try_window_reusing_current_matrix (w
)))
11962 IF_DEBUG (debug_method_add (w
, "1"));
11963 try_window (window
, startp
);
11966 if (fonts_changed_p
)
11967 goto need_larger_matrices
;
11969 if (w
->cursor
.vpos
>= 0)
11971 if (!just_this_one_p
11972 || current_buffer
->clip_changed
11973 || BEG_UNCHANGED
< CHARPOS (startp
))
11974 /* Forget any recorded base line for line number display. */
11975 w
->base_line_number
= Qnil
;
11977 if (!make_cursor_line_fully_visible (w
, 1))
11979 clear_glyph_matrix (w
->desired_matrix
);
11980 last_line_misfit
= 1;
11982 /* Drop through and scroll. */
11987 clear_glyph_matrix (w
->desired_matrix
);
11992 w
->last_modified
= make_number (0);
11993 w
->last_overlay_modified
= make_number (0);
11995 /* Redisplay the mode line. Select the buffer properly for that. */
11996 if (!update_mode_line
)
11998 update_mode_line
= 1;
11999 w
->update_mode_line
= Qt
;
12002 /* Try to scroll by specified few lines. */
12003 if ((scroll_conservatively
12005 || temp_scroll_step
12006 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12007 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12008 && !current_buffer
->clip_changed
12009 && CHARPOS (startp
) >= BEGV
12010 && CHARPOS (startp
) <= ZV
)
12012 /* The function returns -1 if new fonts were loaded, 1 if
12013 successful, 0 if not successful. */
12014 int rc
= try_scrolling (window
, just_this_one_p
,
12015 scroll_conservatively
,
12017 temp_scroll_step
, last_line_misfit
);
12020 case SCROLLING_SUCCESS
:
12023 case SCROLLING_NEED_LARGER_MATRICES
:
12024 goto need_larger_matrices
;
12026 case SCROLLING_FAILED
:
12034 /* Finally, just choose place to start which centers point */
12037 centering_position
= window_box_height (w
) / 2;
12040 /* Jump here with centering_position already set to 0. */
12043 debug_method_add (w
, "recenter");
12046 /* w->vscroll = 0; */
12048 /* Forget any previously recorded base line for line number display. */
12049 if (!buffer_unchanged_p
)
12050 w
->base_line_number
= Qnil
;
12052 /* Move backward half the height of the window. */
12053 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12054 it
.current_y
= it
.last_visible_y
;
12055 move_it_vertically_backward (&it
, centering_position
);
12056 xassert (IT_CHARPOS (it
) >= BEGV
);
12058 /* The function move_it_vertically_backward may move over more
12059 than the specified y-distance. If it->w is small, e.g. a
12060 mini-buffer window, we may end up in front of the window's
12061 display area. Start displaying at the start of the line
12062 containing PT in this case. */
12063 if (it
.current_y
<= 0)
12065 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12066 move_it_vertically_backward (&it
, 0);
12067 xassert (IT_CHARPOS (it
) <= PT
);
12071 it
.current_x
= it
.hpos
= 0;
12073 /* Set startp here explicitly in case that helps avoid an infinite loop
12074 in case the window-scroll-functions functions get errors. */
12075 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12077 /* Run scroll hooks. */
12078 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12080 /* Redisplay the window. */
12081 if (!current_matrix_up_to_date_p
12082 || windows_or_buffers_changed
12083 || cursor_type_changed
12084 /* Don't use try_window_reusing_current_matrix in this case
12085 because it can have changed the buffer. */
12086 || !NILP (Vwindow_scroll_functions
)
12087 || !just_this_one_p
12088 || MINI_WINDOW_P (w
)
12089 || !(used_current_matrix_p
12090 = try_window_reusing_current_matrix (w
)))
12091 try_window (window
, startp
);
12093 /* If new fonts have been loaded (due to fontsets), give up. We
12094 have to start a new redisplay since we need to re-adjust glyph
12096 if (fonts_changed_p
)
12097 goto need_larger_matrices
;
12099 /* If cursor did not appear assume that the middle of the window is
12100 in the first line of the window. Do it again with the next line.
12101 (Imagine a window of height 100, displaying two lines of height
12102 60. Moving back 50 from it->last_visible_y will end in the first
12104 if (w
->cursor
.vpos
< 0)
12106 if (!NILP (w
->window_end_valid
)
12107 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12109 clear_glyph_matrix (w
->desired_matrix
);
12110 move_it_by_lines (&it
, 1, 0);
12111 try_window (window
, it
.current
.pos
);
12113 else if (PT
< IT_CHARPOS (it
))
12115 clear_glyph_matrix (w
->desired_matrix
);
12116 move_it_by_lines (&it
, -1, 0);
12117 try_window (window
, it
.current
.pos
);
12121 /* Not much we can do about it. */
12125 /* Consider the following case: Window starts at BEGV, there is
12126 invisible, intangible text at BEGV, so that display starts at
12127 some point START > BEGV. It can happen that we are called with
12128 PT somewhere between BEGV and START. Try to handle that case. */
12129 if (w
->cursor
.vpos
< 0)
12131 struct glyph_row
*row
= w
->current_matrix
->rows
;
12132 if (row
->mode_line_p
)
12134 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12137 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12139 /* If vscroll is enabled, disable it and try again. */
12143 clear_glyph_matrix (w
->desired_matrix
);
12147 /* If centering point failed to make the whole line visible,
12148 put point at the top instead. That has to make the whole line
12149 visible, if it can be done. */
12150 clear_glyph_matrix (w
->desired_matrix
);
12151 centering_position
= 0;
12157 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12158 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12159 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12162 /* Display the mode line, if we must. */
12163 if ((update_mode_line
12164 /* If window not full width, must redo its mode line
12165 if (a) the window to its side is being redone and
12166 (b) we do a frame-based redisplay. This is a consequence
12167 of how inverted lines are drawn in frame-based redisplay. */
12168 || (!just_this_one_p
12169 && !FRAME_WINDOW_P (f
)
12170 && !WINDOW_FULL_WIDTH_P (w
))
12171 /* Line number to display. */
12172 || INTEGERP (w
->base_line_pos
)
12173 /* Column number is displayed and different from the one displayed. */
12174 || (!NILP (w
->column_number_displayed
)
12175 && (XFASTINT (w
->column_number_displayed
)
12176 != (int) current_column ()))) /* iftc */
12177 /* This means that the window has a mode line. */
12178 && (WINDOW_WANTS_MODELINE_P (w
)
12179 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12181 display_mode_lines (w
);
12183 /* If mode line height has changed, arrange for a thorough
12184 immediate redisplay using the correct mode line height. */
12185 if (WINDOW_WANTS_MODELINE_P (w
)
12186 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12188 fonts_changed_p
= 1;
12189 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12190 = DESIRED_MODE_LINE_HEIGHT (w
);
12193 /* If top line height has changed, arrange for a thorough
12194 immediate redisplay using the correct mode line height. */
12195 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12196 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12198 fonts_changed_p
= 1;
12199 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12200 = DESIRED_HEADER_LINE_HEIGHT (w
);
12203 if (fonts_changed_p
)
12204 goto need_larger_matrices
;
12207 if (!line_number_displayed
12208 && !BUFFERP (w
->base_line_pos
))
12210 w
->base_line_pos
= Qnil
;
12211 w
->base_line_number
= Qnil
;
12216 /* When we reach a frame's selected window, redo the frame's menu bar. */
12217 if (update_mode_line
12218 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12220 int redisplay_menu_p
= 0;
12221 int redisplay_tool_bar_p
= 0;
12223 if (FRAME_WINDOW_P (f
))
12225 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12226 || defined (USE_GTK)
12227 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12229 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12233 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12235 if (redisplay_menu_p
)
12236 display_menu_bar (w
);
12238 #ifdef HAVE_WINDOW_SYSTEM
12239 if (FRAME_WINDOW_P (f
))
12242 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12244 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12245 && (FRAME_TOOL_BAR_LINES (f
) > 0
12246 || auto_resize_tool_bars_p
);
12249 if (redisplay_tool_bar_p
)
12250 redisplay_tool_bar (f
);
12255 #ifdef HAVE_WINDOW_SYSTEM
12256 if (FRAME_WINDOW_P (f
)
12257 && update_window_fringes (w
, 0)
12258 && !just_this_one_p
12259 && (used_current_matrix_p
|| overlay_arrow_seen
)
12260 && !w
->pseudo_window_p
)
12264 if (draw_window_fringes (w
, 1))
12265 x_draw_vertical_border (w
);
12269 #endif /* HAVE_WINDOW_SYSTEM */
12271 /* We go to this label, with fonts_changed_p nonzero,
12272 if it is necessary to try again using larger glyph matrices.
12273 We have to redeem the scroll bar even in this case,
12274 because the loop in redisplay_internal expects that. */
12275 need_larger_matrices
:
12277 finish_scroll_bars
:
12279 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12281 /* Set the thumb's position and size. */
12282 set_vertical_scroll_bar (w
);
12284 /* Note that we actually used the scroll bar attached to this
12285 window, so it shouldn't be deleted at the end of redisplay. */
12286 if (FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
)
12287 (*FRAME_DISPLAY (f
)->redeem_scroll_bar_hook
) (w
);
12290 /* Restore current_buffer and value of point in it. */
12291 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12292 set_buffer_internal_1 (old
);
12293 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12295 unbind_to (count
, Qnil
);
12299 /* Build the complete desired matrix of WINDOW with a window start
12300 buffer position POS. Value is non-zero if successful. It is zero
12301 if fonts were loaded during redisplay which makes re-adjusting
12302 glyph matrices necessary. */
12305 try_window (window
, pos
)
12306 Lisp_Object window
;
12307 struct text_pos pos
;
12309 struct window
*w
= XWINDOW (window
);
12311 struct glyph_row
*last_text_row
= NULL
;
12313 /* Make POS the new window start. */
12314 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12316 /* Mark cursor position as unknown. No overlay arrow seen. */
12317 w
->cursor
.vpos
= -1;
12318 overlay_arrow_seen
= 0;
12320 /* Initialize iterator and info to start at POS. */
12321 start_display (&it
, w
, pos
);
12323 /* Display all lines of W. */
12324 while (it
.current_y
< it
.last_visible_y
)
12326 if (display_line (&it
))
12327 last_text_row
= it
.glyph_row
- 1;
12328 if (fonts_changed_p
)
12332 /* If bottom moved off end of frame, change mode line percentage. */
12333 if (XFASTINT (w
->window_end_pos
) <= 0
12334 && Z
!= IT_CHARPOS (it
))
12335 w
->update_mode_line
= Qt
;
12337 /* Set window_end_pos to the offset of the last character displayed
12338 on the window from the end of current_buffer. Set
12339 window_end_vpos to its row number. */
12342 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12343 w
->window_end_bytepos
12344 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12346 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12348 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12349 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12350 ->displays_text_p
);
12354 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12355 w
->window_end_pos
= make_number (Z
- ZV
);
12356 w
->window_end_vpos
= make_number (0);
12359 /* But that is not valid info until redisplay finishes. */
12360 w
->window_end_valid
= Qnil
;
12366 /************************************************************************
12367 Window redisplay reusing current matrix when buffer has not changed
12368 ************************************************************************/
12370 /* Try redisplay of window W showing an unchanged buffer with a
12371 different window start than the last time it was displayed by
12372 reusing its current matrix. Value is non-zero if successful.
12373 W->start is the new window start. */
12376 try_window_reusing_current_matrix (w
)
12379 struct frame
*f
= XFRAME (w
->frame
);
12380 struct glyph_row
*row
, *bottom_row
;
12383 struct text_pos start
, new_start
;
12384 int nrows_scrolled
, i
;
12385 struct glyph_row
*last_text_row
;
12386 struct glyph_row
*last_reused_text_row
;
12387 struct glyph_row
*start_row
;
12388 int start_vpos
, min_y
, max_y
;
12391 if (inhibit_try_window_reusing
)
12395 if (/* This function doesn't handle terminal frames. */
12396 !FRAME_WINDOW_P (f
)
12397 /* Don't try to reuse the display if windows have been split
12399 || windows_or_buffers_changed
12400 || cursor_type_changed
)
12403 /* Can't do this if region may have changed. */
12404 if ((!NILP (Vtransient_mark_mode
)
12405 && !NILP (current_buffer
->mark_active
))
12406 || !NILP (w
->region_showing
)
12407 || !NILP (Vshow_trailing_whitespace
))
12410 /* If top-line visibility has changed, give up. */
12411 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12412 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12415 /* Give up if old or new display is scrolled vertically. We could
12416 make this function handle this, but right now it doesn't. */
12417 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12418 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12421 /* The variable new_start now holds the new window start. The old
12422 start `start' can be determined from the current matrix. */
12423 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12424 start
= start_row
->start
.pos
;
12425 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12427 /* Clear the desired matrix for the display below. */
12428 clear_glyph_matrix (w
->desired_matrix
);
12430 if (CHARPOS (new_start
) <= CHARPOS (start
))
12434 /* Don't use this method if the display starts with an ellipsis
12435 displayed for invisible text. It's not easy to handle that case
12436 below, and it's certainly not worth the effort since this is
12437 not a frequent case. */
12438 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12441 IF_DEBUG (debug_method_add (w
, "twu1"));
12443 /* Display up to a row that can be reused. The variable
12444 last_text_row is set to the last row displayed that displays
12445 text. Note that it.vpos == 0 if or if not there is a
12446 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12447 start_display (&it
, w
, new_start
);
12448 first_row_y
= it
.current_y
;
12449 w
->cursor
.vpos
= -1;
12450 last_text_row
= last_reused_text_row
= NULL
;
12452 while (it
.current_y
< it
.last_visible_y
12453 && !fonts_changed_p
)
12455 /* If we have reached into the characters in the START row,
12456 that means the line boundaries have changed. So we
12457 can't start copying with the row START. Maybe it will
12458 work to start copying with the following row. */
12459 while (IT_CHARPOS (it
) > CHARPOS (start
))
12461 /* Advance to the next row as the "start". */
12463 start
= start_row
->start
.pos
;
12464 /* If there are no more rows to try, or just one, give up. */
12465 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12466 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12467 || CHARPOS (start
) == ZV
)
12469 clear_glyph_matrix (w
->desired_matrix
);
12473 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12475 /* If we have reached alignment,
12476 we can copy the rest of the rows. */
12477 if (IT_CHARPOS (it
) == CHARPOS (start
))
12480 if (display_line (&it
))
12481 last_text_row
= it
.glyph_row
- 1;
12484 /* A value of current_y < last_visible_y means that we stopped
12485 at the previous window start, which in turn means that we
12486 have at least one reusable row. */
12487 if (it
.current_y
< it
.last_visible_y
)
12489 /* IT.vpos always starts from 0; it counts text lines. */
12490 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12492 /* Find PT if not already found in the lines displayed. */
12493 if (w
->cursor
.vpos
< 0)
12495 int dy
= it
.current_y
- start_row
->y
;
12497 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12498 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12500 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12501 dy
, nrows_scrolled
);
12504 clear_glyph_matrix (w
->desired_matrix
);
12509 /* Scroll the display. Do it before the current matrix is
12510 changed. The problem here is that update has not yet
12511 run, i.e. part of the current matrix is not up to date.
12512 scroll_run_hook will clear the cursor, and use the
12513 current matrix to get the height of the row the cursor is
12515 run
.current_y
= start_row
->y
;
12516 run
.desired_y
= it
.current_y
;
12517 run
.height
= it
.last_visible_y
- it
.current_y
;
12519 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12522 FRAME_RIF (f
)->update_window_begin_hook (w
);
12523 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12524 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12525 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12529 /* Shift current matrix down by nrows_scrolled lines. */
12530 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12531 rotate_matrix (w
->current_matrix
,
12533 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12536 /* Disable lines that must be updated. */
12537 for (i
= 0; i
< it
.vpos
; ++i
)
12538 (start_row
+ i
)->enabled_p
= 0;
12540 /* Re-compute Y positions. */
12541 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12542 max_y
= it
.last_visible_y
;
12543 for (row
= start_row
+ nrows_scrolled
;
12547 row
->y
= it
.current_y
;
12548 row
->visible_height
= row
->height
;
12550 if (row
->y
< min_y
)
12551 row
->visible_height
-= min_y
- row
->y
;
12552 if (row
->y
+ row
->height
> max_y
)
12553 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12554 row
->redraw_fringe_bitmaps_p
= 1;
12556 it
.current_y
+= row
->height
;
12558 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12559 last_reused_text_row
= row
;
12560 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12564 /* Disable lines in the current matrix which are now
12565 below the window. */
12566 for (++row
; row
< bottom_row
; ++row
)
12567 row
->enabled_p
= 0;
12570 /* Update window_end_pos etc.; last_reused_text_row is the last
12571 reused row from the current matrix containing text, if any.
12572 The value of last_text_row is the last displayed line
12573 containing text. */
12574 if (last_reused_text_row
)
12576 w
->window_end_bytepos
12577 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12579 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12581 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12582 w
->current_matrix
));
12584 else if (last_text_row
)
12586 w
->window_end_bytepos
12587 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12589 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12591 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12595 /* This window must be completely empty. */
12596 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12597 w
->window_end_pos
= make_number (Z
- ZV
);
12598 w
->window_end_vpos
= make_number (0);
12600 w
->window_end_valid
= Qnil
;
12602 /* Update hint: don't try scrolling again in update_window. */
12603 w
->desired_matrix
->no_scrolling_p
= 1;
12606 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12610 else if (CHARPOS (new_start
) > CHARPOS (start
))
12612 struct glyph_row
*pt_row
, *row
;
12613 struct glyph_row
*first_reusable_row
;
12614 struct glyph_row
*first_row_to_display
;
12616 int yb
= window_text_bottom_y (w
);
12618 /* Find the row starting at new_start, if there is one. Don't
12619 reuse a partially visible line at the end. */
12620 first_reusable_row
= start_row
;
12621 while (first_reusable_row
->enabled_p
12622 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12623 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12624 < CHARPOS (new_start
)))
12625 ++first_reusable_row
;
12627 /* Give up if there is no row to reuse. */
12628 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12629 || !first_reusable_row
->enabled_p
12630 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12631 != CHARPOS (new_start
)))
12634 /* We can reuse fully visible rows beginning with
12635 first_reusable_row to the end of the window. Set
12636 first_row_to_display to the first row that cannot be reused.
12637 Set pt_row to the row containing point, if there is any. */
12639 for (first_row_to_display
= first_reusable_row
;
12640 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12641 ++first_row_to_display
)
12643 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12644 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12645 pt_row
= first_row_to_display
;
12648 /* Start displaying at the start of first_row_to_display. */
12649 xassert (first_row_to_display
->y
< yb
);
12650 init_to_row_start (&it
, w
, first_row_to_display
);
12652 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12654 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12656 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12657 + WINDOW_HEADER_LINE_HEIGHT (w
));
12659 /* Display lines beginning with first_row_to_display in the
12660 desired matrix. Set last_text_row to the last row displayed
12661 that displays text. */
12662 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12663 if (pt_row
== NULL
)
12664 w
->cursor
.vpos
= -1;
12665 last_text_row
= NULL
;
12666 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12667 if (display_line (&it
))
12668 last_text_row
= it
.glyph_row
- 1;
12670 /* Give up If point isn't in a row displayed or reused. */
12671 if (w
->cursor
.vpos
< 0)
12673 clear_glyph_matrix (w
->desired_matrix
);
12677 /* If point is in a reused row, adjust y and vpos of the cursor
12681 w
->cursor
.vpos
-= nrows_scrolled
;
12682 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
12685 /* Scroll the display. */
12686 run
.current_y
= first_reusable_row
->y
;
12687 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12688 run
.height
= it
.last_visible_y
- run
.current_y
;
12689 dy
= run
.current_y
- run
.desired_y
;
12694 FRAME_RIF (f
)->update_window_begin_hook (w
);
12695 FRAME_RIF (f
)->clear_window_mouse_face (w
);
12696 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
12697 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
12701 /* Adjust Y positions of reused rows. */
12702 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12703 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12704 max_y
= it
.last_visible_y
;
12705 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12708 row
->visible_height
= row
->height
;
12709 if (row
->y
< min_y
)
12710 row
->visible_height
-= min_y
- row
->y
;
12711 if (row
->y
+ row
->height
> max_y
)
12712 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12713 row
->redraw_fringe_bitmaps_p
= 1;
12716 /* Scroll the current matrix. */
12717 xassert (nrows_scrolled
> 0);
12718 rotate_matrix (w
->current_matrix
,
12720 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12723 /* Disable rows not reused. */
12724 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12725 row
->enabled_p
= 0;
12727 /* Point may have moved to a different line, so we cannot assume that
12728 the previous cursor position is valid; locate the correct row. */
12731 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12732 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
12736 w
->cursor
.y
= row
->y
;
12738 if (row
< bottom_row
)
12740 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
12741 while (glyph
->charpos
< PT
)
12744 w
->cursor
.x
+= glyph
->pixel_width
;
12750 /* Adjust window end. A null value of last_text_row means that
12751 the window end is in reused rows which in turn means that
12752 only its vpos can have changed. */
12755 w
->window_end_bytepos
12756 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12758 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12760 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12765 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12768 w
->window_end_valid
= Qnil
;
12769 w
->desired_matrix
->no_scrolling_p
= 1;
12772 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12782 /************************************************************************
12783 Window redisplay reusing current matrix when buffer has changed
12784 ************************************************************************/
12786 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12787 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12789 static struct glyph_row
*
12790 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12791 struct glyph_row
*));
12794 /* Return the last row in MATRIX displaying text. If row START is
12795 non-null, start searching with that row. IT gives the dimensions
12796 of the display. Value is null if matrix is empty; otherwise it is
12797 a pointer to the row found. */
12799 static struct glyph_row
*
12800 find_last_row_displaying_text (matrix
, it
, start
)
12801 struct glyph_matrix
*matrix
;
12803 struct glyph_row
*start
;
12805 struct glyph_row
*row
, *row_found
;
12807 /* Set row_found to the last row in IT->w's current matrix
12808 displaying text. The loop looks funny but think of partially
12811 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12812 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12814 xassert (row
->enabled_p
);
12816 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12825 /* Return the last row in the current matrix of W that is not affected
12826 by changes at the start of current_buffer that occurred since W's
12827 current matrix was built. Value is null if no such row exists.
12829 BEG_UNCHANGED us the number of characters unchanged at the start of
12830 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12831 first changed character in current_buffer. Characters at positions <
12832 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12833 when the current matrix was built. */
12835 static struct glyph_row
*
12836 find_last_unchanged_at_beg_row (w
)
12839 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12840 struct glyph_row
*row
;
12841 struct glyph_row
*row_found
= NULL
;
12842 int yb
= window_text_bottom_y (w
);
12844 /* Find the last row displaying unchanged text. */
12845 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12846 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12847 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12849 if (/* If row ends before first_changed_pos, it is unchanged,
12850 except in some case. */
12851 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12852 /* When row ends in ZV and we write at ZV it is not
12854 && !row
->ends_at_zv_p
12855 /* When first_changed_pos is the end of a continued line,
12856 row is not unchanged because it may be no longer
12858 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12859 && (row
->continued_p
12860 || row
->exact_window_width_line_p
)))
12863 /* Stop if last visible row. */
12864 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12874 /* Find the first glyph row in the current matrix of W that is not
12875 affected by changes at the end of current_buffer since the
12876 time W's current matrix was built.
12878 Return in *DELTA the number of chars by which buffer positions in
12879 unchanged text at the end of current_buffer must be adjusted.
12881 Return in *DELTA_BYTES the corresponding number of bytes.
12883 Value is null if no such row exists, i.e. all rows are affected by
12886 static struct glyph_row
*
12887 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12889 int *delta
, *delta_bytes
;
12891 struct glyph_row
*row
;
12892 struct glyph_row
*row_found
= NULL
;
12894 *delta
= *delta_bytes
= 0;
12896 /* Display must not have been paused, otherwise the current matrix
12897 is not up to date. */
12898 if (NILP (w
->window_end_valid
))
12901 /* A value of window_end_pos >= END_UNCHANGED means that the window
12902 end is in the range of changed text. If so, there is no
12903 unchanged row at the end of W's current matrix. */
12904 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12907 /* Set row to the last row in W's current matrix displaying text. */
12908 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12910 /* If matrix is entirely empty, no unchanged row exists. */
12911 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12913 /* The value of row is the last glyph row in the matrix having a
12914 meaningful buffer position in it. The end position of row
12915 corresponds to window_end_pos. This allows us to translate
12916 buffer positions in the current matrix to current buffer
12917 positions for characters not in changed text. */
12918 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12919 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12920 int last_unchanged_pos
, last_unchanged_pos_old
;
12921 struct glyph_row
*first_text_row
12922 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12924 *delta
= Z
- Z_old
;
12925 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12927 /* Set last_unchanged_pos to the buffer position of the last
12928 character in the buffer that has not been changed. Z is the
12929 index + 1 of the last character in current_buffer, i.e. by
12930 subtracting END_UNCHANGED we get the index of the last
12931 unchanged character, and we have to add BEG to get its buffer
12933 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12934 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12936 /* Search backward from ROW for a row displaying a line that
12937 starts at a minimum position >= last_unchanged_pos_old. */
12938 for (; row
> first_text_row
; --row
)
12940 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12943 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12948 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12955 /* Make sure that glyph rows in the current matrix of window W
12956 reference the same glyph memory as corresponding rows in the
12957 frame's frame matrix. This function is called after scrolling W's
12958 current matrix on a terminal frame in try_window_id and
12959 try_window_reusing_current_matrix. */
12962 sync_frame_with_window_matrix_rows (w
)
12965 struct frame
*f
= XFRAME (w
->frame
);
12966 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12968 /* Preconditions: W must be a leaf window and full-width. Its frame
12969 must have a frame matrix. */
12970 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12971 xassert (WINDOW_FULL_WIDTH_P (w
));
12972 xassert (!FRAME_WINDOW_P (f
));
12974 /* If W is a full-width window, glyph pointers in W's current matrix
12975 have, by definition, to be the same as glyph pointers in the
12976 corresponding frame matrix. Note that frame matrices have no
12977 marginal areas (see build_frame_matrix). */
12978 window_row
= w
->current_matrix
->rows
;
12979 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12980 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12981 while (window_row
< window_row_end
)
12983 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12984 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12986 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12987 frame_row
->glyphs
[TEXT_AREA
] = start
;
12988 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12989 frame_row
->glyphs
[LAST_AREA
] = end
;
12991 /* Disable frame rows whose corresponding window rows have
12992 been disabled in try_window_id. */
12993 if (!window_row
->enabled_p
)
12994 frame_row
->enabled_p
= 0;
12996 ++window_row
, ++frame_row
;
13001 /* Find the glyph row in window W containing CHARPOS. Consider all
13002 rows between START and END (not inclusive). END null means search
13003 all rows to the end of the display area of W. Value is the row
13004 containing CHARPOS or null. */
13007 row_containing_pos (w
, charpos
, start
, end
, dy
)
13010 struct glyph_row
*start
, *end
;
13013 struct glyph_row
*row
= start
;
13016 /* If we happen to start on a header-line, skip that. */
13017 if (row
->mode_line_p
)
13020 if ((end
&& row
>= end
) || !row
->enabled_p
)
13023 last_y
= window_text_bottom_y (w
) - dy
;
13027 /* Give up if we have gone too far. */
13028 if (end
&& row
>= end
)
13030 /* This formerly returned if they were equal.
13031 I think that both quantities are of a "last plus one" type;
13032 if so, when they are equal, the row is within the screen. -- rms. */
13033 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13036 /* If it is in this row, return this row. */
13037 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13038 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13039 /* The end position of a row equals the start
13040 position of the next row. If CHARPOS is there, we
13041 would rather display it in the next line, except
13042 when this line ends in ZV. */
13043 && !row
->ends_at_zv_p
13044 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13045 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13052 /* Try to redisplay window W by reusing its existing display. W's
13053 current matrix must be up to date when this function is called,
13054 i.e. window_end_valid must not be nil.
13058 1 if display has been updated
13059 0 if otherwise unsuccessful
13060 -1 if redisplay with same window start is known not to succeed
13062 The following steps are performed:
13064 1. Find the last row in the current matrix of W that is not
13065 affected by changes at the start of current_buffer. If no such row
13068 2. Find the first row in W's current matrix that is not affected by
13069 changes at the end of current_buffer. Maybe there is no such row.
13071 3. Display lines beginning with the row + 1 found in step 1 to the
13072 row found in step 2 or, if step 2 didn't find a row, to the end of
13075 4. If cursor is not known to appear on the window, give up.
13077 5. If display stopped at the row found in step 2, scroll the
13078 display and current matrix as needed.
13080 6. Maybe display some lines at the end of W, if we must. This can
13081 happen under various circumstances, like a partially visible line
13082 becoming fully visible, or because newly displayed lines are displayed
13083 in smaller font sizes.
13085 7. Update W's window end information. */
13091 struct frame
*f
= XFRAME (w
->frame
);
13092 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13093 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13094 struct glyph_row
*last_unchanged_at_beg_row
;
13095 struct glyph_row
*first_unchanged_at_end_row
;
13096 struct glyph_row
*row
;
13097 struct glyph_row
*bottom_row
;
13100 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13101 struct text_pos start_pos
;
13103 int first_unchanged_at_end_vpos
= 0;
13104 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13105 struct text_pos start
;
13106 int first_changed_charpos
, last_changed_charpos
;
13109 if (inhibit_try_window_id
)
13113 /* This is handy for debugging. */
13115 #define GIVE_UP(X) \
13117 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13121 #define GIVE_UP(X) return 0
13124 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13126 /* Don't use this for mini-windows because these can show
13127 messages and mini-buffers, and we don't handle that here. */
13128 if (MINI_WINDOW_P (w
))
13131 /* This flag is used to prevent redisplay optimizations. */
13132 if (windows_or_buffers_changed
|| cursor_type_changed
)
13135 /* Verify that narrowing has not changed.
13136 Also verify that we were not told to prevent redisplay optimizations.
13137 It would be nice to further
13138 reduce the number of cases where this prevents try_window_id. */
13139 if (current_buffer
->clip_changed
13140 || current_buffer
->prevent_redisplay_optimizations_p
)
13143 /* Window must either use window-based redisplay or be full width. */
13144 if (!FRAME_WINDOW_P (f
)
13145 && (!FRAME_LINE_INS_DEL_OK (f
)
13146 || !WINDOW_FULL_WIDTH_P (w
)))
13149 /* Give up if point is not known NOT to appear in W. */
13150 if (PT
< CHARPOS (start
))
13153 /* Another way to prevent redisplay optimizations. */
13154 if (XFASTINT (w
->last_modified
) == 0)
13157 /* Verify that window is not hscrolled. */
13158 if (XFASTINT (w
->hscroll
) != 0)
13161 /* Verify that display wasn't paused. */
13162 if (NILP (w
->window_end_valid
))
13165 /* Can't use this if highlighting a region because a cursor movement
13166 will do more than just set the cursor. */
13167 if (!NILP (Vtransient_mark_mode
)
13168 && !NILP (current_buffer
->mark_active
))
13171 /* Likewise if highlighting trailing whitespace. */
13172 if (!NILP (Vshow_trailing_whitespace
))
13175 /* Likewise if showing a region. */
13176 if (!NILP (w
->region_showing
))
13179 /* Can use this if overlay arrow position and or string have changed. */
13180 if (overlay_arrows_changed_p ())
13184 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13185 only if buffer has really changed. The reason is that the gap is
13186 initially at Z for freshly visited files. The code below would
13187 set end_unchanged to 0 in that case. */
13188 if (MODIFF
> SAVE_MODIFF
13189 /* This seems to happen sometimes after saving a buffer. */
13190 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13192 if (GPT
- BEG
< BEG_UNCHANGED
)
13193 BEG_UNCHANGED
= GPT
- BEG
;
13194 if (Z
- GPT
< END_UNCHANGED
)
13195 END_UNCHANGED
= Z
- GPT
;
13198 /* The position of the first and last character that has been changed. */
13199 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13200 last_changed_charpos
= Z
- END_UNCHANGED
;
13202 /* If window starts after a line end, and the last change is in
13203 front of that newline, then changes don't affect the display.
13204 This case happens with stealth-fontification. Note that although
13205 the display is unchanged, glyph positions in the matrix have to
13206 be adjusted, of course. */
13207 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13208 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13209 && ((last_changed_charpos
< CHARPOS (start
)
13210 && CHARPOS (start
) == BEGV
)
13211 || (last_changed_charpos
< CHARPOS (start
) - 1
13212 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13214 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13215 struct glyph_row
*r0
;
13217 /* Compute how many chars/bytes have been added to or removed
13218 from the buffer. */
13219 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13220 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13222 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13224 /* Give up if PT is not in the window. Note that it already has
13225 been checked at the start of try_window_id that PT is not in
13226 front of the window start. */
13227 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13230 /* If window start is unchanged, we can reuse the whole matrix
13231 as is, after adjusting glyph positions. No need to compute
13232 the window end again, since its offset from Z hasn't changed. */
13233 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13234 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13235 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13236 /* PT must not be in a partially visible line. */
13237 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13238 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13240 /* Adjust positions in the glyph matrix. */
13241 if (delta
|| delta_bytes
)
13243 struct glyph_row
*r1
13244 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13245 increment_matrix_positions (w
->current_matrix
,
13246 MATRIX_ROW_VPOS (r0
, current_matrix
),
13247 MATRIX_ROW_VPOS (r1
, current_matrix
),
13248 delta
, delta_bytes
);
13251 /* Set the cursor. */
13252 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13254 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13261 /* Handle the case that changes are all below what is displayed in
13262 the window, and that PT is in the window. This shortcut cannot
13263 be taken if ZV is visible in the window, and text has been added
13264 there that is visible in the window. */
13265 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13266 /* ZV is not visible in the window, or there are no
13267 changes at ZV, actually. */
13268 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13269 || first_changed_charpos
== last_changed_charpos
))
13271 struct glyph_row
*r0
;
13273 /* Give up if PT is not in the window. Note that it already has
13274 been checked at the start of try_window_id that PT is not in
13275 front of the window start. */
13276 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13279 /* If window start is unchanged, we can reuse the whole matrix
13280 as is, without changing glyph positions since no text has
13281 been added/removed in front of the window end. */
13282 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13283 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13284 /* PT must not be in a partially visible line. */
13285 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13286 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13288 /* We have to compute the window end anew since text
13289 can have been added/removed after it. */
13291 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13292 w
->window_end_bytepos
13293 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13295 /* Set the cursor. */
13296 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13298 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13305 /* Give up if window start is in the changed area.
13307 The condition used to read
13309 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13311 but why that was tested escapes me at the moment. */
13312 if (CHARPOS (start
) >= first_changed_charpos
13313 && CHARPOS (start
) <= last_changed_charpos
)
13316 /* Check that window start agrees with the start of the first glyph
13317 row in its current matrix. Check this after we know the window
13318 start is not in changed text, otherwise positions would not be
13320 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13321 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13324 /* Give up if the window ends in strings. Overlay strings
13325 at the end are difficult to handle, so don't try. */
13326 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13327 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13330 /* Compute the position at which we have to start displaying new
13331 lines. Some of the lines at the top of the window might be
13332 reusable because they are not displaying changed text. Find the
13333 last row in W's current matrix not affected by changes at the
13334 start of current_buffer. Value is null if changes start in the
13335 first line of window. */
13336 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13337 if (last_unchanged_at_beg_row
)
13339 /* Avoid starting to display in the moddle of a character, a TAB
13340 for instance. This is easier than to set up the iterator
13341 exactly, and it's not a frequent case, so the additional
13342 effort wouldn't really pay off. */
13343 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13344 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13345 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13346 --last_unchanged_at_beg_row
;
13348 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13351 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13353 start_pos
= it
.current
.pos
;
13355 /* Start displaying new lines in the desired matrix at the same
13356 vpos we would use in the current matrix, i.e. below
13357 last_unchanged_at_beg_row. */
13358 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13360 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13361 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13363 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13367 /* There are no reusable lines at the start of the window.
13368 Start displaying in the first text line. */
13369 start_display (&it
, w
, start
);
13370 it
.vpos
= it
.first_vpos
;
13371 start_pos
= it
.current
.pos
;
13374 /* Find the first row that is not affected by changes at the end of
13375 the buffer. Value will be null if there is no unchanged row, in
13376 which case we must redisplay to the end of the window. delta
13377 will be set to the value by which buffer positions beginning with
13378 first_unchanged_at_end_row have to be adjusted due to text
13380 first_unchanged_at_end_row
13381 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13382 IF_DEBUG (debug_delta
= delta
);
13383 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13385 /* Set stop_pos to the buffer position up to which we will have to
13386 display new lines. If first_unchanged_at_end_row != NULL, this
13387 is the buffer position of the start of the line displayed in that
13388 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13389 that we don't stop at a buffer position. */
13391 if (first_unchanged_at_end_row
)
13393 xassert (last_unchanged_at_beg_row
== NULL
13394 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13396 /* If this is a continuation line, move forward to the next one
13397 that isn't. Changes in lines above affect this line.
13398 Caution: this may move first_unchanged_at_end_row to a row
13399 not displaying text. */
13400 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13401 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13402 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13403 < it
.last_visible_y
))
13404 ++first_unchanged_at_end_row
;
13406 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13407 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13408 >= it
.last_visible_y
))
13409 first_unchanged_at_end_row
= NULL
;
13412 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13414 first_unchanged_at_end_vpos
13415 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13416 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13419 else if (last_unchanged_at_beg_row
== NULL
)
13425 /* Either there is no unchanged row at the end, or the one we have
13426 now displays text. This is a necessary condition for the window
13427 end pos calculation at the end of this function. */
13428 xassert (first_unchanged_at_end_row
== NULL
13429 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13431 debug_last_unchanged_at_beg_vpos
13432 = (last_unchanged_at_beg_row
13433 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13435 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13437 #endif /* GLYPH_DEBUG != 0 */
13440 /* Display new lines. Set last_text_row to the last new line
13441 displayed which has text on it, i.e. might end up as being the
13442 line where the window_end_vpos is. */
13443 w
->cursor
.vpos
= -1;
13444 last_text_row
= NULL
;
13445 overlay_arrow_seen
= 0;
13446 while (it
.current_y
< it
.last_visible_y
13447 && !fonts_changed_p
13448 && (first_unchanged_at_end_row
== NULL
13449 || IT_CHARPOS (it
) < stop_pos
))
13451 if (display_line (&it
))
13452 last_text_row
= it
.glyph_row
- 1;
13455 if (fonts_changed_p
)
13459 /* Compute differences in buffer positions, y-positions etc. for
13460 lines reused at the bottom of the window. Compute what we can
13462 if (first_unchanged_at_end_row
13463 /* No lines reused because we displayed everything up to the
13464 bottom of the window. */
13465 && it
.current_y
< it
.last_visible_y
)
13468 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13470 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13471 run
.current_y
= first_unchanged_at_end_row
->y
;
13472 run
.desired_y
= run
.current_y
+ dy
;
13473 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13477 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13478 first_unchanged_at_end_row
= NULL
;
13480 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13483 /* Find the cursor if not already found. We have to decide whether
13484 PT will appear on this window (it sometimes doesn't, but this is
13485 not a very frequent case.) This decision has to be made before
13486 the current matrix is altered. A value of cursor.vpos < 0 means
13487 that PT is either in one of the lines beginning at
13488 first_unchanged_at_end_row or below the window. Don't care for
13489 lines that might be displayed later at the window end; as
13490 mentioned, this is not a frequent case. */
13491 if (w
->cursor
.vpos
< 0)
13493 /* Cursor in unchanged rows at the top? */
13494 if (PT
< CHARPOS (start_pos
)
13495 && last_unchanged_at_beg_row
)
13497 row
= row_containing_pos (w
, PT
,
13498 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13499 last_unchanged_at_beg_row
+ 1, 0);
13501 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13504 /* Start from first_unchanged_at_end_row looking for PT. */
13505 else if (first_unchanged_at_end_row
)
13507 row
= row_containing_pos (w
, PT
- delta
,
13508 first_unchanged_at_end_row
, NULL
, 0);
13510 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13511 delta_bytes
, dy
, dvpos
);
13514 /* Give up if cursor was not found. */
13515 if (w
->cursor
.vpos
< 0)
13517 clear_glyph_matrix (w
->desired_matrix
);
13522 /* Don't let the cursor end in the scroll margins. */
13524 int this_scroll_margin
, cursor_height
;
13526 this_scroll_margin
= max (0, scroll_margin
);
13527 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13528 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13529 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13531 if ((w
->cursor
.y
< this_scroll_margin
13532 && CHARPOS (start
) > BEGV
)
13533 /* Old redisplay didn't take scroll margin into account at the bottom,
13534 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13535 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13536 ? cursor_height
+ this_scroll_margin
13537 : 1)) > it
.last_visible_y
)
13539 w
->cursor
.vpos
= -1;
13540 clear_glyph_matrix (w
->desired_matrix
);
13545 /* Scroll the display. Do it before changing the current matrix so
13546 that xterm.c doesn't get confused about where the cursor glyph is
13548 if (dy
&& run
.height
)
13552 if (FRAME_WINDOW_P (f
))
13554 FRAME_RIF (f
)->update_window_begin_hook (w
);
13555 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13556 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13557 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13561 /* Terminal frame. In this case, dvpos gives the number of
13562 lines to scroll by; dvpos < 0 means scroll up. */
13563 int first_unchanged_at_end_vpos
13564 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13565 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13566 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13567 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13568 + window_internal_height (w
));
13570 /* Perform the operation on the screen. */
13573 /* Scroll last_unchanged_at_beg_row to the end of the
13574 window down dvpos lines. */
13575 set_terminal_window (f
, end
);
13577 /* On dumb terminals delete dvpos lines at the end
13578 before inserting dvpos empty lines. */
13579 if (!FRAME_SCROLL_REGION_OK (f
))
13580 ins_del_lines (f
, end
- dvpos
, -dvpos
);
13582 /* Insert dvpos empty lines in front of
13583 last_unchanged_at_beg_row. */
13584 ins_del_lines (f
, from
, dvpos
);
13586 else if (dvpos
< 0)
13588 /* Scroll up last_unchanged_at_beg_vpos to the end of
13589 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13590 set_terminal_window (f
, end
);
13592 /* Delete dvpos lines in front of
13593 last_unchanged_at_beg_vpos. ins_del_lines will set
13594 the cursor to the given vpos and emit |dvpos| delete
13596 ins_del_lines (f
, from
+ dvpos
, dvpos
);
13598 /* On a dumb terminal insert dvpos empty lines at the
13600 if (!FRAME_SCROLL_REGION_OK (f
))
13601 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
13604 set_terminal_window (f
, 0);
13610 /* Shift reused rows of the current matrix to the right position.
13611 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13613 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13614 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13617 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13618 bottom_vpos
, dvpos
);
13619 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13622 else if (dvpos
> 0)
13624 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13625 bottom_vpos
, dvpos
);
13626 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13627 first_unchanged_at_end_vpos
+ dvpos
, 0);
13630 /* For frame-based redisplay, make sure that current frame and window
13631 matrix are in sync with respect to glyph memory. */
13632 if (!FRAME_WINDOW_P (f
))
13633 sync_frame_with_window_matrix_rows (w
);
13635 /* Adjust buffer positions in reused rows. */
13637 increment_matrix_positions (current_matrix
,
13638 first_unchanged_at_end_vpos
+ dvpos
,
13639 bottom_vpos
, delta
, delta_bytes
);
13641 /* Adjust Y positions. */
13643 shift_glyph_matrix (w
, current_matrix
,
13644 first_unchanged_at_end_vpos
+ dvpos
,
13647 if (first_unchanged_at_end_row
)
13648 first_unchanged_at_end_row
+= dvpos
;
13650 /* If scrolling up, there may be some lines to display at the end of
13652 last_text_row_at_end
= NULL
;
13655 /* Scrolling up can leave for example a partially visible line
13656 at the end of the window to be redisplayed. */
13657 /* Set last_row to the glyph row in the current matrix where the
13658 window end line is found. It has been moved up or down in
13659 the matrix by dvpos. */
13660 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13661 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13663 /* If last_row is the window end line, it should display text. */
13664 xassert (last_row
->displays_text_p
);
13666 /* If window end line was partially visible before, begin
13667 displaying at that line. Otherwise begin displaying with the
13668 line following it. */
13669 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13671 init_to_row_start (&it
, w
, last_row
);
13672 it
.vpos
= last_vpos
;
13673 it
.current_y
= last_row
->y
;
13677 init_to_row_end (&it
, w
, last_row
);
13678 it
.vpos
= 1 + last_vpos
;
13679 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13683 /* We may start in a continuation line. If so, we have to
13684 get the right continuation_lines_width and current_x. */
13685 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13686 it
.hpos
= it
.current_x
= 0;
13688 /* Display the rest of the lines at the window end. */
13689 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13690 while (it
.current_y
< it
.last_visible_y
13691 && !fonts_changed_p
)
13693 /* Is it always sure that the display agrees with lines in
13694 the current matrix? I don't think so, so we mark rows
13695 displayed invalid in the current matrix by setting their
13696 enabled_p flag to zero. */
13697 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13698 if (display_line (&it
))
13699 last_text_row_at_end
= it
.glyph_row
- 1;
13703 /* Update window_end_pos and window_end_vpos. */
13704 if (first_unchanged_at_end_row
13705 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13706 && !last_text_row_at_end
)
13708 /* Window end line if one of the preserved rows from the current
13709 matrix. Set row to the last row displaying text in current
13710 matrix starting at first_unchanged_at_end_row, after
13712 xassert (first_unchanged_at_end_row
->displays_text_p
);
13713 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13714 first_unchanged_at_end_row
);
13715 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13717 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13718 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13720 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13721 xassert (w
->window_end_bytepos
>= 0);
13722 IF_DEBUG (debug_method_add (w
, "A"));
13724 else if (last_text_row_at_end
)
13727 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13728 w
->window_end_bytepos
13729 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13731 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13732 xassert (w
->window_end_bytepos
>= 0);
13733 IF_DEBUG (debug_method_add (w
, "B"));
13735 else if (last_text_row
)
13737 /* We have displayed either to the end of the window or at the
13738 end of the window, i.e. the last row with text is to be found
13739 in the desired matrix. */
13741 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13742 w
->window_end_bytepos
13743 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13745 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13746 xassert (w
->window_end_bytepos
>= 0);
13748 else if (first_unchanged_at_end_row
== NULL
13749 && last_text_row
== NULL
13750 && last_text_row_at_end
== NULL
)
13752 /* Displayed to end of window, but no line containing text was
13753 displayed. Lines were deleted at the end of the window. */
13754 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13755 int vpos
= XFASTINT (w
->window_end_vpos
);
13756 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13757 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13760 row
== NULL
&& vpos
>= first_vpos
;
13761 --vpos
, --current_row
, --desired_row
)
13763 if (desired_row
->enabled_p
)
13765 if (desired_row
->displays_text_p
)
13768 else if (current_row
->displays_text_p
)
13772 xassert (row
!= NULL
);
13773 w
->window_end_vpos
= make_number (vpos
+ 1);
13774 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13775 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13776 xassert (w
->window_end_bytepos
>= 0);
13777 IF_DEBUG (debug_method_add (w
, "C"));
13782 #if 0 /* This leads to problems, for instance when the cursor is
13783 at ZV, and the cursor line displays no text. */
13784 /* Disable rows below what's displayed in the window. This makes
13785 debugging easier. */
13786 enable_glyph_matrix_rows (current_matrix
,
13787 XFASTINT (w
->window_end_vpos
) + 1,
13791 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13792 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13794 /* Record that display has not been completed. */
13795 w
->window_end_valid
= Qnil
;
13796 w
->desired_matrix
->no_scrolling_p
= 1;
13804 /***********************************************************************
13805 More debugging support
13806 ***********************************************************************/
13810 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13811 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13812 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13815 /* Dump the contents of glyph matrix MATRIX on stderr.
13817 GLYPHS 0 means don't show glyph contents.
13818 GLYPHS 1 means show glyphs in short form
13819 GLYPHS > 1 means show glyphs in long form. */
13822 dump_glyph_matrix (matrix
, glyphs
)
13823 struct glyph_matrix
*matrix
;
13827 for (i
= 0; i
< matrix
->nrows
; ++i
)
13828 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13832 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13833 the glyph row and area where the glyph comes from. */
13836 dump_glyph (row
, glyph
, area
)
13837 struct glyph_row
*row
;
13838 struct glyph
*glyph
;
13841 if (glyph
->type
== CHAR_GLYPH
)
13844 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13845 glyph
- row
->glyphs
[TEXT_AREA
],
13848 (BUFFERP (glyph
->object
)
13850 : (STRINGP (glyph
->object
)
13853 glyph
->pixel_width
,
13855 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13859 glyph
->left_box_line_p
,
13860 glyph
->right_box_line_p
);
13862 else if (glyph
->type
== STRETCH_GLYPH
)
13865 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13866 glyph
- row
->glyphs
[TEXT_AREA
],
13869 (BUFFERP (glyph
->object
)
13871 : (STRINGP (glyph
->object
)
13874 glyph
->pixel_width
,
13878 glyph
->left_box_line_p
,
13879 glyph
->right_box_line_p
);
13881 else if (glyph
->type
== IMAGE_GLYPH
)
13884 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13885 glyph
- row
->glyphs
[TEXT_AREA
],
13888 (BUFFERP (glyph
->object
)
13890 : (STRINGP (glyph
->object
)
13893 glyph
->pixel_width
,
13897 glyph
->left_box_line_p
,
13898 glyph
->right_box_line_p
);
13903 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13904 GLYPHS 0 means don't show glyph contents.
13905 GLYPHS 1 means show glyphs in short form
13906 GLYPHS > 1 means show glyphs in long form. */
13909 dump_glyph_row (row
, vpos
, glyphs
)
13910 struct glyph_row
*row
;
13915 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13916 fprintf (stderr
, "=======================================================================\n");
13918 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13919 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13921 MATRIX_ROW_START_CHARPOS (row
),
13922 MATRIX_ROW_END_CHARPOS (row
),
13923 row
->used
[TEXT_AREA
],
13924 row
->contains_overlapping_glyphs_p
,
13926 row
->truncated_on_left_p
,
13927 row
->truncated_on_right_p
,
13928 row
->overlay_arrow_p
,
13930 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13931 row
->displays_text_p
,
13934 row
->ends_in_middle_of_char_p
,
13935 row
->starts_in_middle_of_char_p
,
13941 row
->visible_height
,
13944 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13945 row
->end
.overlay_string_index
,
13946 row
->continuation_lines_width
);
13947 fprintf (stderr
, "%9d %5d\n",
13948 CHARPOS (row
->start
.string_pos
),
13949 CHARPOS (row
->end
.string_pos
));
13950 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13951 row
->end
.dpvec_index
);
13958 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13960 struct glyph
*glyph
= row
->glyphs
[area
];
13961 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13963 /* Glyph for a line end in text. */
13964 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13967 if (glyph
< glyph_end
)
13968 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13970 for (; glyph
< glyph_end
; ++glyph
)
13971 dump_glyph (row
, glyph
, area
);
13974 else if (glyphs
== 1)
13978 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13980 char *s
= (char *) alloca (row
->used
[area
] + 1);
13983 for (i
= 0; i
< row
->used
[area
]; ++i
)
13985 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13986 if (glyph
->type
== CHAR_GLYPH
13987 && glyph
->u
.ch
< 0x80
13988 && glyph
->u
.ch
>= ' ')
13989 s
[i
] = glyph
->u
.ch
;
13995 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14001 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14002 Sdump_glyph_matrix
, 0, 1, "p",
14003 doc
: /* Dump the current matrix of the selected window to stderr.
14004 Shows contents of glyph row structures. With non-nil
14005 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14006 glyphs in short form, otherwise show glyphs in long form. */)
14008 Lisp_Object glyphs
;
14010 struct window
*w
= XWINDOW (selected_window
);
14011 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14013 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14014 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14015 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14016 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14017 fprintf (stderr
, "=============================================\n");
14018 dump_glyph_matrix (w
->current_matrix
,
14019 NILP (glyphs
) ? 0 : XINT (glyphs
));
14024 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14025 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14028 struct frame
*f
= XFRAME (selected_frame
);
14029 dump_glyph_matrix (f
->current_matrix
, 1);
14034 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14035 doc
: /* Dump glyph row ROW to stderr.
14036 GLYPH 0 means don't dump glyphs.
14037 GLYPH 1 means dump glyphs in short form.
14038 GLYPH > 1 or omitted means dump glyphs in long form. */)
14040 Lisp_Object row
, glyphs
;
14042 struct glyph_matrix
*matrix
;
14045 CHECK_NUMBER (row
);
14046 matrix
= XWINDOW (selected_window
)->current_matrix
;
14048 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14049 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14051 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14056 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14057 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14058 GLYPH 0 means don't dump glyphs.
14059 GLYPH 1 means dump glyphs in short form.
14060 GLYPH > 1 or omitted means dump glyphs in long form. */)
14062 Lisp_Object row
, glyphs
;
14064 struct frame
*sf
= SELECTED_FRAME ();
14065 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14068 CHECK_NUMBER (row
);
14070 if (vpos
>= 0 && vpos
< m
->nrows
)
14071 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14072 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14077 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14078 doc
: /* Toggle tracing of redisplay.
14079 With ARG, turn tracing on if and only if ARG is positive. */)
14084 trace_redisplay_p
= !trace_redisplay_p
;
14087 arg
= Fprefix_numeric_value (arg
);
14088 trace_redisplay_p
= XINT (arg
) > 0;
14095 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14096 doc
: /* Like `format', but print result to stderr.
14097 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14102 Lisp_Object s
= Fformat (nargs
, args
);
14103 fprintf (stderr
, "%s", SDATA (s
));
14107 #endif /* GLYPH_DEBUG */
14111 /***********************************************************************
14112 Building Desired Matrix Rows
14113 ***********************************************************************/
14115 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14116 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14118 static struct glyph_row
*
14119 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14121 Lisp_Object overlay_arrow_string
;
14123 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14124 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14125 struct buffer
*old
= current_buffer
;
14126 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14127 int arrow_len
= SCHARS (overlay_arrow_string
);
14128 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14129 const unsigned char *p
;
14132 int n_glyphs_before
;
14134 set_buffer_temp (buffer
);
14135 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14136 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14137 SET_TEXT_POS (it
.position
, 0, 0);
14139 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14141 while (p
< arrow_end
)
14143 Lisp_Object face
, ilisp
;
14145 /* Get the next character. */
14147 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14149 it
.c
= *p
, it
.len
= 1;
14152 /* Get its face. */
14153 ilisp
= make_number (p
- arrow_string
);
14154 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14155 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14157 /* Compute its width, get its glyphs. */
14158 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14159 SET_TEXT_POS (it
.position
, -1, -1);
14160 PRODUCE_GLYPHS (&it
);
14162 /* If this character doesn't fit any more in the line, we have
14163 to remove some glyphs. */
14164 if (it
.current_x
> it
.last_visible_x
)
14166 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14171 set_buffer_temp (old
);
14172 return it
.glyph_row
;
14176 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14177 glyphs are only inserted for terminal frames since we can't really
14178 win with truncation glyphs when partially visible glyphs are
14179 involved. Which glyphs to insert is determined by
14180 produce_special_glyphs. */
14183 insert_left_trunc_glyphs (it
)
14186 struct it truncate_it
;
14187 struct glyph
*from
, *end
, *to
, *toend
;
14189 xassert (!FRAME_WINDOW_P (it
->f
));
14191 /* Get the truncation glyphs. */
14193 truncate_it
.current_x
= 0;
14194 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14195 truncate_it
.glyph_row
= &scratch_glyph_row
;
14196 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14197 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14198 truncate_it
.object
= make_number (0);
14199 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14201 /* Overwrite glyphs from IT with truncation glyphs. */
14202 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14203 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14204 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14205 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14210 /* There may be padding glyphs left over. Overwrite them too. */
14211 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14213 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14219 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14223 /* Compute the pixel height and width of IT->glyph_row.
14225 Most of the time, ascent and height of a display line will be equal
14226 to the max_ascent and max_height values of the display iterator
14227 structure. This is not the case if
14229 1. We hit ZV without displaying anything. In this case, max_ascent
14230 and max_height will be zero.
14232 2. We have some glyphs that don't contribute to the line height.
14233 (The glyph row flag contributes_to_line_height_p is for future
14234 pixmap extensions).
14236 The first case is easily covered by using default values because in
14237 these cases, the line height does not really matter, except that it
14238 must not be zero. */
14241 compute_line_metrics (it
)
14244 struct glyph_row
*row
= it
->glyph_row
;
14247 if (FRAME_WINDOW_P (it
->f
))
14249 int i
, min_y
, max_y
;
14251 /* The line may consist of one space only, that was added to
14252 place the cursor on it. If so, the row's height hasn't been
14254 if (row
->height
== 0)
14256 if (it
->max_ascent
+ it
->max_descent
== 0)
14257 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14258 row
->ascent
= it
->max_ascent
;
14259 row
->height
= it
->max_ascent
+ it
->max_descent
;
14260 row
->phys_ascent
= it
->max_phys_ascent
;
14261 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14262 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14265 /* Compute the width of this line. */
14266 row
->pixel_width
= row
->x
;
14267 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14268 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14270 xassert (row
->pixel_width
>= 0);
14271 xassert (row
->ascent
>= 0 && row
->height
> 0);
14273 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14274 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14276 /* If first line's physical ascent is larger than its logical
14277 ascent, use the physical ascent, and make the row taller.
14278 This makes accented characters fully visible. */
14279 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14280 && row
->phys_ascent
> row
->ascent
)
14282 row
->height
+= row
->phys_ascent
- row
->ascent
;
14283 row
->ascent
= row
->phys_ascent
;
14286 /* Compute how much of the line is visible. */
14287 row
->visible_height
= row
->height
;
14289 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14290 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14292 if (row
->y
< min_y
)
14293 row
->visible_height
-= min_y
- row
->y
;
14294 if (row
->y
+ row
->height
> max_y
)
14295 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14299 row
->pixel_width
= row
->used
[TEXT_AREA
];
14300 if (row
->continued_p
)
14301 row
->pixel_width
-= it
->continuation_pixel_width
;
14302 else if (row
->truncated_on_right_p
)
14303 row
->pixel_width
-= it
->truncation_pixel_width
;
14304 row
->ascent
= row
->phys_ascent
= 0;
14305 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14306 row
->extra_line_spacing
= 0;
14309 /* Compute a hash code for this row. */
14311 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14312 for (i
= 0; i
< row
->used
[area
]; ++i
)
14313 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14314 + row
->glyphs
[area
][i
].u
.val
14315 + row
->glyphs
[area
][i
].face_id
14316 + row
->glyphs
[area
][i
].padding_p
14317 + (row
->glyphs
[area
][i
].type
<< 2));
14319 it
->max_ascent
= it
->max_descent
= 0;
14320 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14324 /* Append one space to the glyph row of iterator IT if doing a
14325 window-based redisplay. The space has the same face as
14326 IT->face_id. Value is non-zero if a space was added.
14328 This function is called to make sure that there is always one glyph
14329 at the end of a glyph row that the cursor can be set on under
14330 window-systems. (If there weren't such a glyph we would not know
14331 how wide and tall a box cursor should be displayed).
14333 At the same time this space let's a nicely handle clearing to the
14334 end of the line if the row ends in italic text. */
14337 append_space_for_newline (it
, default_face_p
)
14339 int default_face_p
;
14341 if (FRAME_WINDOW_P (it
->f
))
14343 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14345 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14346 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14348 /* Save some values that must not be changed.
14349 Must save IT->c and IT->len because otherwise
14350 ITERATOR_AT_END_P wouldn't work anymore after
14351 append_space_for_newline has been called. */
14352 enum display_element_type saved_what
= it
->what
;
14353 int saved_c
= it
->c
, saved_len
= it
->len
;
14354 int saved_x
= it
->current_x
;
14355 int saved_face_id
= it
->face_id
;
14356 struct text_pos saved_pos
;
14357 Lisp_Object saved_object
;
14360 saved_object
= it
->object
;
14361 saved_pos
= it
->position
;
14363 it
->what
= IT_CHARACTER
;
14364 bzero (&it
->position
, sizeof it
->position
);
14365 it
->object
= make_number (0);
14369 if (default_face_p
)
14370 it
->face_id
= DEFAULT_FACE_ID
;
14371 else if (it
->face_before_selective_p
)
14372 it
->face_id
= it
->saved_face_id
;
14373 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14374 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14376 PRODUCE_GLYPHS (it
);
14378 it
->override_ascent
= -1;
14379 it
->constrain_row_ascent_descent_p
= 0;
14380 it
->current_x
= saved_x
;
14381 it
->object
= saved_object
;
14382 it
->position
= saved_pos
;
14383 it
->what
= saved_what
;
14384 it
->face_id
= saved_face_id
;
14385 it
->len
= saved_len
;
14395 /* Extend the face of the last glyph in the text area of IT->glyph_row
14396 to the end of the display line. Called from display_line.
14397 If the glyph row is empty, add a space glyph to it so that we
14398 know the face to draw. Set the glyph row flag fill_line_p. */
14401 extend_face_to_end_of_line (it
)
14405 struct frame
*f
= it
->f
;
14407 /* If line is already filled, do nothing. */
14408 if (it
->current_x
>= it
->last_visible_x
)
14411 /* Face extension extends the background and box of IT->face_id
14412 to the end of the line. If the background equals the background
14413 of the frame, we don't have to do anything. */
14414 if (it
->face_before_selective_p
)
14415 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14417 face
= FACE_FROM_ID (f
, it
->face_id
);
14419 if (FRAME_WINDOW_P (f
)
14420 && face
->box
== FACE_NO_BOX
14421 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14425 /* Set the glyph row flag indicating that the face of the last glyph
14426 in the text area has to be drawn to the end of the text area. */
14427 it
->glyph_row
->fill_line_p
= 1;
14429 /* If current character of IT is not ASCII, make sure we have the
14430 ASCII face. This will be automatically undone the next time
14431 get_next_display_element returns a multibyte character. Note
14432 that the character will always be single byte in unibyte text. */
14433 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14435 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14438 if (FRAME_WINDOW_P (f
))
14440 /* If the row is empty, add a space with the current face of IT,
14441 so that we know which face to draw. */
14442 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14444 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14445 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14446 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14451 /* Save some values that must not be changed. */
14452 int saved_x
= it
->current_x
;
14453 struct text_pos saved_pos
;
14454 Lisp_Object saved_object
;
14455 enum display_element_type saved_what
= it
->what
;
14456 int saved_face_id
= it
->face_id
;
14458 saved_object
= it
->object
;
14459 saved_pos
= it
->position
;
14461 it
->what
= IT_CHARACTER
;
14462 bzero (&it
->position
, sizeof it
->position
);
14463 it
->object
= make_number (0);
14466 it
->face_id
= face
->id
;
14468 PRODUCE_GLYPHS (it
);
14470 while (it
->current_x
<= it
->last_visible_x
)
14471 PRODUCE_GLYPHS (it
);
14473 /* Don't count these blanks really. It would let us insert a left
14474 truncation glyph below and make us set the cursor on them, maybe. */
14475 it
->current_x
= saved_x
;
14476 it
->object
= saved_object
;
14477 it
->position
= saved_pos
;
14478 it
->what
= saved_what
;
14479 it
->face_id
= saved_face_id
;
14484 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14485 trailing whitespace. */
14488 trailing_whitespace_p (charpos
)
14491 int bytepos
= CHAR_TO_BYTE (charpos
);
14494 while (bytepos
< ZV_BYTE
14495 && (c
= FETCH_CHAR (bytepos
),
14496 c
== ' ' || c
== '\t'))
14499 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14501 if (bytepos
!= PT_BYTE
)
14508 /* Highlight trailing whitespace, if any, in ROW. */
14511 highlight_trailing_whitespace (f
, row
)
14513 struct glyph_row
*row
;
14515 int used
= row
->used
[TEXT_AREA
];
14519 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14520 struct glyph
*glyph
= start
+ used
- 1;
14522 /* Skip over glyphs inserted to display the cursor at the
14523 end of a line, for extending the face of the last glyph
14524 to the end of the line on terminals, and for truncation
14525 and continuation glyphs. */
14526 while (glyph
>= start
14527 && glyph
->type
== CHAR_GLYPH
14528 && INTEGERP (glyph
->object
))
14531 /* If last glyph is a space or stretch, and it's trailing
14532 whitespace, set the face of all trailing whitespace glyphs in
14533 IT->glyph_row to `trailing-whitespace'. */
14535 && BUFFERP (glyph
->object
)
14536 && (glyph
->type
== STRETCH_GLYPH
14537 || (glyph
->type
== CHAR_GLYPH
14538 && glyph
->u
.ch
== ' '))
14539 && trailing_whitespace_p (glyph
->charpos
))
14541 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14543 while (glyph
>= start
14544 && BUFFERP (glyph
->object
)
14545 && (glyph
->type
== STRETCH_GLYPH
14546 || (glyph
->type
== CHAR_GLYPH
14547 && glyph
->u
.ch
== ' ')))
14548 (glyph
--)->face_id
= face_id
;
14554 /* Value is non-zero if glyph row ROW in window W should be
14555 used to hold the cursor. */
14558 cursor_row_p (w
, row
)
14560 struct glyph_row
*row
;
14562 int cursor_row_p
= 1;
14564 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14566 /* If the row ends with a newline from a string, we don't want
14567 the cursor there (if the row is continued it doesn't end in a
14569 if (CHARPOS (row
->end
.string_pos
) >= 0
14570 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14571 cursor_row_p
= row
->continued_p
;
14573 /* If the row ends at ZV, display the cursor at the end of that
14574 row instead of at the start of the row below. */
14575 else if (row
->ends_at_zv_p
)
14581 return cursor_row_p
;
14585 /* Construct the glyph row IT->glyph_row in the desired matrix of
14586 IT->w from text at the current position of IT. See dispextern.h
14587 for an overview of struct it. Value is non-zero if
14588 IT->glyph_row displays text, as opposed to a line displaying ZV
14595 struct glyph_row
*row
= it
->glyph_row
;
14596 int overlay_arrow_bitmap
;
14597 Lisp_Object overlay_arrow_string
;
14599 /* We always start displaying at hpos zero even if hscrolled. */
14600 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14602 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14603 >= it
->w
->desired_matrix
->nrows
)
14605 it
->w
->nrows_scale_factor
++;
14606 fonts_changed_p
= 1;
14610 /* Is IT->w showing the region? */
14611 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14613 /* Clear the result glyph row and enable it. */
14614 prepare_desired_row (row
);
14616 row
->y
= it
->current_y
;
14617 row
->start
= it
->start
;
14618 row
->continuation_lines_width
= it
->continuation_lines_width
;
14619 row
->displays_text_p
= 1;
14620 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14621 it
->starts_in_middle_of_char_p
= 0;
14623 /* Arrange the overlays nicely for our purposes. Usually, we call
14624 display_line on only one line at a time, in which case this
14625 can't really hurt too much, or we call it on lines which appear
14626 one after another in the buffer, in which case all calls to
14627 recenter_overlay_lists but the first will be pretty cheap. */
14628 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14630 /* Move over display elements that are not visible because we are
14631 hscrolled. This may stop at an x-position < IT->first_visible_x
14632 if the first glyph is partially visible or if we hit a line end. */
14633 if (it
->current_x
< it
->first_visible_x
)
14634 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14635 MOVE_TO_POS
| MOVE_TO_X
);
14637 /* Get the initial row height. This is either the height of the
14638 text hscrolled, if there is any, or zero. */
14639 row
->ascent
= it
->max_ascent
;
14640 row
->height
= it
->max_ascent
+ it
->max_descent
;
14641 row
->phys_ascent
= it
->max_phys_ascent
;
14642 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14643 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14645 /* Loop generating characters. The loop is left with IT on the next
14646 character to display. */
14649 int n_glyphs_before
, hpos_before
, x_before
;
14651 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14653 /* Retrieve the next thing to display. Value is zero if end of
14655 if (!get_next_display_element (it
))
14657 /* Maybe add a space at the end of this line that is used to
14658 display the cursor there under X. Set the charpos of the
14659 first glyph of blank lines not corresponding to any text
14661 #ifdef HAVE_WINDOW_SYSTEM
14662 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14663 row
->exact_window_width_line_p
= 1;
14665 #endif /* HAVE_WINDOW_SYSTEM */
14666 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14667 || row
->used
[TEXT_AREA
] == 0)
14669 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14670 row
->displays_text_p
= 0;
14672 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14673 && (!MINI_WINDOW_P (it
->w
)
14674 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14675 row
->indicate_empty_line_p
= 1;
14678 it
->continuation_lines_width
= 0;
14679 row
->ends_at_zv_p
= 1;
14683 /* Now, get the metrics of what we want to display. This also
14684 generates glyphs in `row' (which is IT->glyph_row). */
14685 n_glyphs_before
= row
->used
[TEXT_AREA
];
14688 /* Remember the line height so far in case the next element doesn't
14689 fit on the line. */
14690 if (!it
->truncate_lines_p
)
14692 ascent
= it
->max_ascent
;
14693 descent
= it
->max_descent
;
14694 phys_ascent
= it
->max_phys_ascent
;
14695 phys_descent
= it
->max_phys_descent
;
14698 PRODUCE_GLYPHS (it
);
14700 /* If this display element was in marginal areas, continue with
14702 if (it
->area
!= TEXT_AREA
)
14704 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14705 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14706 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14707 row
->phys_height
= max (row
->phys_height
,
14708 it
->max_phys_ascent
+ it
->max_phys_descent
);
14709 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14710 it
->max_extra_line_spacing
);
14711 set_iterator_to_next (it
, 1);
14715 /* Does the display element fit on the line? If we truncate
14716 lines, we should draw past the right edge of the window. If
14717 we don't truncate, we want to stop so that we can display the
14718 continuation glyph before the right margin. If lines are
14719 continued, there are two possible strategies for characters
14720 resulting in more than 1 glyph (e.g. tabs): Display as many
14721 glyphs as possible in this line and leave the rest for the
14722 continuation line, or display the whole element in the next
14723 line. Original redisplay did the former, so we do it also. */
14724 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14725 hpos_before
= it
->hpos
;
14728 if (/* Not a newline. */
14730 /* Glyphs produced fit entirely in the line. */
14731 && it
->current_x
< it
->last_visible_x
)
14733 it
->hpos
+= nglyphs
;
14734 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14735 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14736 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14737 row
->phys_height
= max (row
->phys_height
,
14738 it
->max_phys_ascent
+ it
->max_phys_descent
);
14739 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14740 it
->max_extra_line_spacing
);
14741 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14742 row
->x
= x
- it
->first_visible_x
;
14747 struct glyph
*glyph
;
14749 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14751 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14752 new_x
= x
+ glyph
->pixel_width
;
14754 if (/* Lines are continued. */
14755 !it
->truncate_lines_p
14756 && (/* Glyph doesn't fit on the line. */
14757 new_x
> it
->last_visible_x
14758 /* Or it fits exactly on a window system frame. */
14759 || (new_x
== it
->last_visible_x
14760 && FRAME_WINDOW_P (it
->f
))))
14762 /* End of a continued line. */
14765 || (new_x
== it
->last_visible_x
14766 && FRAME_WINDOW_P (it
->f
)))
14768 /* Current glyph is the only one on the line or
14769 fits exactly on the line. We must continue
14770 the line because we can't draw the cursor
14771 after the glyph. */
14772 row
->continued_p
= 1;
14773 it
->current_x
= new_x
;
14774 it
->continuation_lines_width
+= new_x
;
14776 if (i
== nglyphs
- 1)
14778 set_iterator_to_next (it
, 1);
14779 #ifdef HAVE_WINDOW_SYSTEM
14780 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14782 if (!get_next_display_element (it
))
14784 row
->exact_window_width_line_p
= 1;
14785 it
->continuation_lines_width
= 0;
14786 row
->continued_p
= 0;
14787 row
->ends_at_zv_p
= 1;
14789 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14791 row
->continued_p
= 0;
14792 row
->exact_window_width_line_p
= 1;
14794 else if (it
->method
== next_element_from_display_vector
)
14795 it
->face_id
= it
->saved_face_id
;
14797 #endif /* HAVE_WINDOW_SYSTEM */
14800 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14801 && !FRAME_WINDOW_P (it
->f
))
14803 /* A padding glyph that doesn't fit on this line.
14804 This means the whole character doesn't fit
14806 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14808 /* Fill the rest of the row with continuation
14809 glyphs like in 20.x. */
14810 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14811 < row
->glyphs
[1 + TEXT_AREA
])
14812 produce_special_glyphs (it
, IT_CONTINUATION
);
14814 row
->continued_p
= 1;
14815 it
->current_x
= x_before
;
14816 it
->continuation_lines_width
+= x_before
;
14818 /* Restore the height to what it was before the
14819 element not fitting on the line. */
14820 it
->max_ascent
= ascent
;
14821 it
->max_descent
= descent
;
14822 it
->max_phys_ascent
= phys_ascent
;
14823 it
->max_phys_descent
= phys_descent
;
14825 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14827 /* A TAB that extends past the right edge of the
14828 window. This produces a single glyph on
14829 window system frames. We leave the glyph in
14830 this row and let it fill the row, but don't
14831 consume the TAB. */
14832 it
->continuation_lines_width
+= it
->last_visible_x
;
14833 row
->ends_in_middle_of_char_p
= 1;
14834 row
->continued_p
= 1;
14835 glyph
->pixel_width
= it
->last_visible_x
- x
;
14836 it
->starts_in_middle_of_char_p
= 1;
14840 /* Something other than a TAB that draws past
14841 the right edge of the window. Restore
14842 positions to values before the element. */
14843 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14845 /* Display continuation glyphs. */
14846 if (!FRAME_WINDOW_P (it
->f
))
14847 produce_special_glyphs (it
, IT_CONTINUATION
);
14848 row
->continued_p
= 1;
14850 it
->continuation_lines_width
+= x
;
14852 if (nglyphs
> 1 && i
> 0)
14854 row
->ends_in_middle_of_char_p
= 1;
14855 it
->starts_in_middle_of_char_p
= 1;
14858 /* Restore the height to what it was before the
14859 element not fitting on the line. */
14860 it
->max_ascent
= ascent
;
14861 it
->max_descent
= descent
;
14862 it
->max_phys_ascent
= phys_ascent
;
14863 it
->max_phys_descent
= phys_descent
;
14868 else if (new_x
> it
->first_visible_x
)
14870 /* Increment number of glyphs actually displayed. */
14873 if (x
< it
->first_visible_x
)
14874 /* Glyph is partially visible, i.e. row starts at
14875 negative X position. */
14876 row
->x
= x
- it
->first_visible_x
;
14880 /* Glyph is completely off the left margin of the
14881 window. This should not happen because of the
14882 move_it_in_display_line at the start of this
14883 function, unless the text display area of the
14884 window is empty. */
14885 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14889 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14890 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14891 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14892 row
->phys_height
= max (row
->phys_height
,
14893 it
->max_phys_ascent
+ it
->max_phys_descent
);
14894 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14895 it
->max_extra_line_spacing
);
14897 /* End of this display line if row is continued. */
14898 if (row
->continued_p
|| row
->ends_at_zv_p
)
14903 /* Is this a line end? If yes, we're also done, after making
14904 sure that a non-default face is extended up to the right
14905 margin of the window. */
14906 if (ITERATOR_AT_END_OF_LINE_P (it
))
14908 int used_before
= row
->used
[TEXT_AREA
];
14910 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14912 #ifdef HAVE_WINDOW_SYSTEM
14913 /* Add a space at the end of the line that is used to
14914 display the cursor there. */
14915 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14916 append_space_for_newline (it
, 0);
14917 #endif /* HAVE_WINDOW_SYSTEM */
14919 /* Extend the face to the end of the line. */
14920 extend_face_to_end_of_line (it
);
14922 /* Make sure we have the position. */
14923 if (used_before
== 0)
14924 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14926 /* Consume the line end. This skips over invisible lines. */
14927 set_iterator_to_next (it
, 1);
14928 it
->continuation_lines_width
= 0;
14932 /* Proceed with next display element. Note that this skips
14933 over lines invisible because of selective display. */
14934 set_iterator_to_next (it
, 1);
14936 /* If we truncate lines, we are done when the last displayed
14937 glyphs reach past the right margin of the window. */
14938 if (it
->truncate_lines_p
14939 && (FRAME_WINDOW_P (it
->f
)
14940 ? (it
->current_x
>= it
->last_visible_x
)
14941 : (it
->current_x
> it
->last_visible_x
)))
14943 /* Maybe add truncation glyphs. */
14944 if (!FRAME_WINDOW_P (it
->f
))
14948 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14949 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14952 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14954 row
->used
[TEXT_AREA
] = i
;
14955 produce_special_glyphs (it
, IT_TRUNCATION
);
14958 #ifdef HAVE_WINDOW_SYSTEM
14961 /* Don't truncate if we can overflow newline into fringe. */
14962 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14964 if (!get_next_display_element (it
))
14966 it
->continuation_lines_width
= 0;
14967 row
->ends_at_zv_p
= 1;
14968 row
->exact_window_width_line_p
= 1;
14971 if (ITERATOR_AT_END_OF_LINE_P (it
))
14973 row
->exact_window_width_line_p
= 1;
14974 goto at_end_of_line
;
14978 #endif /* HAVE_WINDOW_SYSTEM */
14980 row
->truncated_on_right_p
= 1;
14981 it
->continuation_lines_width
= 0;
14982 reseat_at_next_visible_line_start (it
, 0);
14983 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14984 it
->hpos
= hpos_before
;
14985 it
->current_x
= x_before
;
14990 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14991 at the left window margin. */
14992 if (it
->first_visible_x
14993 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14995 if (!FRAME_WINDOW_P (it
->f
))
14996 insert_left_trunc_glyphs (it
);
14997 row
->truncated_on_left_p
= 1;
15000 /* If the start of this line is the overlay arrow-position, then
15001 mark this glyph row as the one containing the overlay arrow.
15002 This is clearly a mess with variable size fonts. It would be
15003 better to let it be displayed like cursors under X. */
15004 if (! overlay_arrow_seen
15005 && (overlay_arrow_string
15006 = overlay_arrow_at_row (it
, row
, &overlay_arrow_bitmap
),
15007 !NILP (overlay_arrow_string
)))
15009 /* Overlay arrow in window redisplay is a fringe bitmap. */
15010 if (STRINGP (overlay_arrow_string
))
15012 struct glyph_row
*arrow_row
15013 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15014 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15015 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15016 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15017 struct glyph
*p2
, *end
;
15019 /* Copy the arrow glyphs. */
15020 while (glyph
< arrow_end
)
15023 /* Throw away padding glyphs. */
15025 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15026 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15032 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15037 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
15038 row
->overlay_arrow_p
= 1;
15040 overlay_arrow_seen
= 1;
15043 /* Compute pixel dimensions of this line. */
15044 compute_line_metrics (it
);
15046 /* Remember the position at which this line ends. */
15047 row
->end
= it
->current
;
15049 /* Save fringe bitmaps in this row. */
15050 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15051 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15052 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15053 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15055 it
->left_user_fringe_bitmap
= 0;
15056 it
->left_user_fringe_face_id
= 0;
15057 it
->right_user_fringe_bitmap
= 0;
15058 it
->right_user_fringe_face_id
= 0;
15060 /* Maybe set the cursor. */
15061 if (it
->w
->cursor
.vpos
< 0
15062 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15063 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15064 && cursor_row_p (it
->w
, row
))
15065 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15067 /* Highlight trailing whitespace. */
15068 if (!NILP (Vshow_trailing_whitespace
))
15069 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15071 /* Prepare for the next line. This line starts horizontally at (X
15072 HPOS) = (0 0). Vertical positions are incremented. As a
15073 convenience for the caller, IT->glyph_row is set to the next
15075 it
->current_x
= it
->hpos
= 0;
15076 it
->current_y
+= row
->height
;
15079 it
->start
= it
->current
;
15080 return row
->displays_text_p
;
15085 /***********************************************************************
15087 ***********************************************************************/
15089 /* Redisplay the menu bar in the frame for window W.
15091 The menu bar of X frames that don't have X toolkit support is
15092 displayed in a special window W->frame->menu_bar_window.
15094 The menu bar of terminal frames is treated specially as far as
15095 glyph matrices are concerned. Menu bar lines are not part of
15096 windows, so the update is done directly on the frame matrix rows
15097 for the menu bar. */
15100 display_menu_bar (w
)
15103 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15108 /* Don't do all this for graphical frames. */
15110 if (!NILP (Vwindow_system
))
15113 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15118 if (FRAME_MAC_P (f
))
15122 #ifdef USE_X_TOOLKIT
15123 xassert (!FRAME_WINDOW_P (f
));
15124 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15125 it
.first_visible_x
= 0;
15126 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15127 #else /* not USE_X_TOOLKIT */
15128 if (FRAME_WINDOW_P (f
))
15130 /* Menu bar lines are displayed in the desired matrix of the
15131 dummy window menu_bar_window. */
15132 struct window
*menu_w
;
15133 xassert (WINDOWP (f
->menu_bar_window
));
15134 menu_w
= XWINDOW (f
->menu_bar_window
);
15135 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15137 it
.first_visible_x
= 0;
15138 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15142 /* This is a TTY frame, i.e. character hpos/vpos are used as
15144 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15146 it
.first_visible_x
= 0;
15147 it
.last_visible_x
= FRAME_COLS (f
);
15149 #endif /* not USE_X_TOOLKIT */
15151 if (! mode_line_inverse_video
)
15152 /* Force the menu-bar to be displayed in the default face. */
15153 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15155 /* Clear all rows of the menu bar. */
15156 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15158 struct glyph_row
*row
= it
.glyph_row
+ i
;
15159 clear_glyph_row (row
);
15160 row
->enabled_p
= 1;
15161 row
->full_width_p
= 1;
15164 /* Display all items of the menu bar. */
15165 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15166 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15168 Lisp_Object string
;
15170 /* Stop at nil string. */
15171 string
= AREF (items
, i
+ 1);
15175 /* Remember where item was displayed. */
15176 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15178 /* Display the item, pad with one space. */
15179 if (it
.current_x
< it
.last_visible_x
)
15180 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15181 SCHARS (string
) + 1, 0, 0, -1);
15184 /* Fill out the line with spaces. */
15185 if (it
.current_x
< it
.last_visible_x
)
15186 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15188 /* Compute the total height of the lines. */
15189 compute_line_metrics (&it
);
15194 /***********************************************************************
15196 ***********************************************************************/
15198 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15199 FORCE is non-zero, redisplay mode lines unconditionally.
15200 Otherwise, redisplay only mode lines that are garbaged. Value is
15201 the number of windows whose mode lines were redisplayed. */
15204 redisplay_mode_lines (window
, force
)
15205 Lisp_Object window
;
15210 while (!NILP (window
))
15212 struct window
*w
= XWINDOW (window
);
15214 if (WINDOWP (w
->hchild
))
15215 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15216 else if (WINDOWP (w
->vchild
))
15217 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15219 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15220 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15222 struct text_pos lpoint
;
15223 struct buffer
*old
= current_buffer
;
15225 /* Set the window's buffer for the mode line display. */
15226 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15227 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15229 /* Point refers normally to the selected window. For any
15230 other window, set up appropriate value. */
15231 if (!EQ (window
, selected_window
))
15233 struct text_pos pt
;
15235 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15236 if (CHARPOS (pt
) < BEGV
)
15237 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15238 else if (CHARPOS (pt
) > (ZV
- 1))
15239 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15241 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15244 /* Display mode lines. */
15245 clear_glyph_matrix (w
->desired_matrix
);
15246 if (display_mode_lines (w
))
15249 w
->must_be_updated_p
= 1;
15252 /* Restore old settings. */
15253 set_buffer_internal_1 (old
);
15254 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15264 /* Display the mode and/or top line of window W. Value is the number
15265 of mode lines displayed. */
15268 display_mode_lines (w
)
15271 Lisp_Object old_selected_window
, old_selected_frame
;
15274 old_selected_frame
= selected_frame
;
15275 selected_frame
= w
->frame
;
15276 old_selected_window
= selected_window
;
15277 XSETWINDOW (selected_window
, w
);
15279 /* These will be set while the mode line specs are processed. */
15280 line_number_displayed
= 0;
15281 w
->column_number_displayed
= Qnil
;
15283 if (WINDOW_WANTS_MODELINE_P (w
))
15285 struct window
*sel_w
= XWINDOW (old_selected_window
);
15287 /* Select mode line face based on the real selected window. */
15288 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15289 current_buffer
->mode_line_format
);
15293 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15295 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15296 current_buffer
->header_line_format
);
15300 selected_frame
= old_selected_frame
;
15301 selected_window
= old_selected_window
;
15306 /* Display mode or top line of window W. FACE_ID specifies which line
15307 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15308 FORMAT is the mode line format to display. Value is the pixel
15309 height of the mode line displayed. */
15312 display_mode_line (w
, face_id
, format
)
15314 enum face_id face_id
;
15315 Lisp_Object format
;
15320 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15321 prepare_desired_row (it
.glyph_row
);
15323 it
.glyph_row
->mode_line_p
= 1;
15325 if (! mode_line_inverse_video
)
15326 /* Force the mode-line to be displayed in the default face. */
15327 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15329 /* Temporarily make frame's keyboard the current kboard so that
15330 kboard-local variables in the mode_line_format will get the right
15332 push_frame_kboard (it
.f
);
15333 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15334 pop_frame_kboard ();
15336 /* Fill up with spaces. */
15337 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15339 compute_line_metrics (&it
);
15340 it
.glyph_row
->full_width_p
= 1;
15341 it
.glyph_row
->continued_p
= 0;
15342 it
.glyph_row
->truncated_on_left_p
= 0;
15343 it
.glyph_row
->truncated_on_right_p
= 0;
15345 /* Make a 3D mode-line have a shadow at its right end. */
15346 face
= FACE_FROM_ID (it
.f
, face_id
);
15347 extend_face_to_end_of_line (&it
);
15348 if (face
->box
!= FACE_NO_BOX
)
15350 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15351 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15352 last
->right_box_line_p
= 1;
15355 return it
.glyph_row
->height
;
15358 /* Alist that caches the results of :propertize.
15359 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15360 Lisp_Object mode_line_proptrans_alist
;
15362 /* List of strings making up the mode-line. */
15363 Lisp_Object mode_line_string_list
;
15365 /* Base face property when building propertized mode line string. */
15366 static Lisp_Object mode_line_string_face
;
15367 static Lisp_Object mode_line_string_face_prop
;
15370 /* Contribute ELT to the mode line for window IT->w. How it
15371 translates into text depends on its data type.
15373 IT describes the display environment in which we display, as usual.
15375 DEPTH is the depth in recursion. It is used to prevent
15376 infinite recursion here.
15378 FIELD_WIDTH is the number of characters the display of ELT should
15379 occupy in the mode line, and PRECISION is the maximum number of
15380 characters to display from ELT's representation. See
15381 display_string for details.
15383 Returns the hpos of the end of the text generated by ELT.
15385 PROPS is a property list to add to any string we encounter.
15387 If RISKY is nonzero, remove (disregard) any properties in any string
15388 we encounter, and ignore :eval and :propertize.
15390 If the global variable `frame_title_ptr' is non-NULL, then the output
15391 is passed to `store_frame_title' instead of `display_string'. */
15394 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15397 int field_width
, precision
;
15398 Lisp_Object elt
, props
;
15401 int n
= 0, field
, prec
;
15406 elt
= build_string ("*too-deep*");
15410 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15414 /* A string: output it and check for %-constructs within it. */
15416 const unsigned char *this, *lisp_string
;
15418 if (!NILP (props
) || risky
)
15420 Lisp_Object oprops
, aelt
;
15421 oprops
= Ftext_properties_at (make_number (0), elt
);
15423 /* If the starting string's properties are not what
15424 we want, translate the string. Also, if the string
15425 is risky, do that anyway. */
15427 if (NILP (Fequal (props
, oprops
)) || risky
)
15429 /* If the starting string has properties,
15430 merge the specified ones onto the existing ones. */
15431 if (! NILP (oprops
) && !risky
)
15435 oprops
= Fcopy_sequence (oprops
);
15437 while (CONSP (tem
))
15439 oprops
= Fplist_put (oprops
, XCAR (tem
),
15440 XCAR (XCDR (tem
)));
15441 tem
= XCDR (XCDR (tem
));
15446 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15447 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15449 mode_line_proptrans_alist
15450 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15457 elt
= Fcopy_sequence (elt
);
15458 Fset_text_properties (make_number (0), Flength (elt
),
15460 /* Add this item to mode_line_proptrans_alist. */
15461 mode_line_proptrans_alist
15462 = Fcons (Fcons (elt
, props
),
15463 mode_line_proptrans_alist
);
15464 /* Truncate mode_line_proptrans_alist
15465 to at most 50 elements. */
15466 tem
= Fnthcdr (make_number (50),
15467 mode_line_proptrans_alist
);
15469 XSETCDR (tem
, Qnil
);
15474 this = SDATA (elt
);
15475 lisp_string
= this;
15479 prec
= precision
- n
;
15480 if (frame_title_ptr
)
15481 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15482 else if (!NILP (mode_line_string_list
))
15483 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15485 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15486 0, prec
, 0, STRING_MULTIBYTE (elt
));
15491 while ((precision
<= 0 || n
< precision
)
15493 && (frame_title_ptr
15494 || !NILP (mode_line_string_list
)
15495 || it
->current_x
< it
->last_visible_x
))
15497 const unsigned char *last
= this;
15499 /* Advance to end of string or next format specifier. */
15500 while ((c
= *this++) != '\0' && c
!= '%')
15503 if (this - 1 != last
)
15505 int nchars
, nbytes
;
15507 /* Output to end of string or up to '%'. Field width
15508 is length of string. Don't output more than
15509 PRECISION allows us. */
15512 prec
= c_string_width (last
, this - last
, precision
- n
,
15515 if (frame_title_ptr
)
15516 n
+= store_frame_title (last
, 0, prec
);
15517 else if (!NILP (mode_line_string_list
))
15519 int bytepos
= last
- lisp_string
;
15520 int charpos
= string_byte_to_char (elt
, bytepos
);
15521 int endpos
= (precision
<= 0
15522 ? string_byte_to_char (elt
,
15523 this - lisp_string
)
15524 : charpos
+ nchars
);
15526 n
+= store_mode_line_string (NULL
,
15527 Fsubstring (elt
, make_number (charpos
),
15528 make_number (endpos
)),
15533 int bytepos
= last
- lisp_string
;
15534 int charpos
= string_byte_to_char (elt
, bytepos
);
15535 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15537 STRING_MULTIBYTE (elt
));
15540 else /* c == '%' */
15542 const unsigned char *percent_position
= this;
15544 /* Get the specified minimum width. Zero means
15547 while ((c
= *this++) >= '0' && c
<= '9')
15548 field
= field
* 10 + c
- '0';
15550 /* Don't pad beyond the total padding allowed. */
15551 if (field_width
- n
> 0 && field
> field_width
- n
)
15552 field
= field_width
- n
;
15554 /* Note that either PRECISION <= 0 or N < PRECISION. */
15555 prec
= precision
- n
;
15558 n
+= display_mode_element (it
, depth
, field
, prec
,
15559 Vglobal_mode_string
, props
,
15564 int bytepos
, charpos
;
15565 unsigned char *spec
;
15567 bytepos
= percent_position
- lisp_string
;
15568 charpos
= (STRING_MULTIBYTE (elt
)
15569 ? string_byte_to_char (elt
, bytepos
)
15573 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15575 if (frame_title_ptr
)
15576 n
+= store_frame_title (spec
, field
, prec
);
15577 else if (!NILP (mode_line_string_list
))
15579 int len
= strlen (spec
);
15580 Lisp_Object tem
= make_string (spec
, len
);
15581 props
= Ftext_properties_at (make_number (charpos
), elt
);
15582 /* Should only keep face property in props */
15583 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15587 int nglyphs_before
, nwritten
;
15589 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15590 nwritten
= display_string (spec
, Qnil
, elt
,
15595 /* Assign to the glyphs written above the
15596 string where the `%x' came from, position
15600 struct glyph
*glyph
15601 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15605 for (i
= 0; i
< nwritten
; ++i
)
15607 glyph
[i
].object
= elt
;
15608 glyph
[i
].charpos
= charpos
;
15623 /* A symbol: process the value of the symbol recursively
15624 as if it appeared here directly. Avoid error if symbol void.
15625 Special case: if value of symbol is a string, output the string
15628 register Lisp_Object tem
;
15630 /* If the variable is not marked as risky to set
15631 then its contents are risky to use. */
15632 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15635 tem
= Fboundp (elt
);
15638 tem
= Fsymbol_value (elt
);
15639 /* If value is a string, output that string literally:
15640 don't check for % within it. */
15644 if (!EQ (tem
, elt
))
15646 /* Give up right away for nil or t. */
15656 register Lisp_Object car
, tem
;
15658 /* A cons cell: five distinct cases.
15659 If first element is :eval or :propertize, do something special.
15660 If first element is a string or a cons, process all the elements
15661 and effectively concatenate them.
15662 If first element is a negative number, truncate displaying cdr to
15663 at most that many characters. If positive, pad (with spaces)
15664 to at least that many characters.
15665 If first element is a symbol, process the cadr or caddr recursively
15666 according to whether the symbol's value is non-nil or nil. */
15668 if (EQ (car
, QCeval
))
15670 /* An element of the form (:eval FORM) means evaluate FORM
15671 and use the result as mode line elements. */
15676 if (CONSP (XCDR (elt
)))
15679 spec
= safe_eval (XCAR (XCDR (elt
)));
15680 n
+= display_mode_element (it
, depth
, field_width
- n
,
15681 precision
- n
, spec
, props
,
15685 else if (EQ (car
, QCpropertize
))
15687 /* An element of the form (:propertize ELT PROPS...)
15688 means display ELT but applying properties PROPS. */
15693 if (CONSP (XCDR (elt
)))
15694 n
+= display_mode_element (it
, depth
, field_width
- n
,
15695 precision
- n
, XCAR (XCDR (elt
)),
15696 XCDR (XCDR (elt
)), risky
);
15698 else if (SYMBOLP (car
))
15700 tem
= Fboundp (car
);
15704 /* elt is now the cdr, and we know it is a cons cell.
15705 Use its car if CAR has a non-nil value. */
15708 tem
= Fsymbol_value (car
);
15715 /* Symbol's value is nil (or symbol is unbound)
15716 Get the cddr of the original list
15717 and if possible find the caddr and use that. */
15721 else if (!CONSP (elt
))
15726 else if (INTEGERP (car
))
15728 register int lim
= XINT (car
);
15732 /* Negative int means reduce maximum width. */
15733 if (precision
<= 0)
15736 precision
= min (precision
, -lim
);
15740 /* Padding specified. Don't let it be more than
15741 current maximum. */
15743 lim
= min (precision
, lim
);
15745 /* If that's more padding than already wanted, queue it.
15746 But don't reduce padding already specified even if
15747 that is beyond the current truncation point. */
15748 field_width
= max (lim
, field_width
);
15752 else if (STRINGP (car
) || CONSP (car
))
15754 register int limit
= 50;
15755 /* Limit is to protect against circular lists. */
15758 && (precision
<= 0 || n
< precision
))
15760 n
+= display_mode_element (it
, depth
, field_width
- n
,
15761 precision
- n
, XCAR (elt
),
15771 elt
= build_string ("*invalid*");
15775 /* Pad to FIELD_WIDTH. */
15776 if (field_width
> 0 && n
< field_width
)
15778 if (frame_title_ptr
)
15779 n
+= store_frame_title ("", field_width
- n
, 0);
15780 else if (!NILP (mode_line_string_list
))
15781 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15783 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15790 /* Store a mode-line string element in mode_line_string_list.
15792 If STRING is non-null, display that C string. Otherwise, the Lisp
15793 string LISP_STRING is displayed.
15795 FIELD_WIDTH is the minimum number of output glyphs to produce.
15796 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15797 with spaces. FIELD_WIDTH <= 0 means don't pad.
15799 PRECISION is the maximum number of characters to output from
15800 STRING. PRECISION <= 0 means don't truncate the string.
15802 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15803 properties to the string.
15805 PROPS are the properties to add to the string.
15806 The mode_line_string_face face property is always added to the string.
15810 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15812 Lisp_Object lisp_string
;
15821 if (string
!= NULL
)
15823 len
= strlen (string
);
15824 if (precision
> 0 && len
> precision
)
15826 lisp_string
= make_string (string
, len
);
15828 props
= mode_line_string_face_prop
;
15829 else if (!NILP (mode_line_string_face
))
15831 Lisp_Object face
= Fsafe_plist_get (props
, Qface
);
15832 props
= Fcopy_sequence (props
);
15834 face
= mode_line_string_face
;
15836 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15837 props
= Fplist_put (props
, Qface
, face
);
15839 Fadd_text_properties (make_number (0), make_number (len
),
15840 props
, lisp_string
);
15844 len
= XFASTINT (Flength (lisp_string
));
15845 if (precision
> 0 && len
> precision
)
15848 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15851 if (!NILP (mode_line_string_face
))
15855 props
= Ftext_properties_at (make_number (0), lisp_string
);
15856 face
= Fsafe_plist_get (props
, Qface
);
15858 face
= mode_line_string_face
;
15860 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15861 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15863 lisp_string
= Fcopy_sequence (lisp_string
);
15866 Fadd_text_properties (make_number (0), make_number (len
),
15867 props
, lisp_string
);
15872 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15876 if (field_width
> len
)
15878 field_width
-= len
;
15879 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15881 Fadd_text_properties (make_number (0), make_number (field_width
),
15882 props
, lisp_string
);
15883 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15891 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15893 doc
: /* Return the mode-line of selected window as a string.
15894 First optional arg FORMAT specifies a different format string (see
15895 `mode-line-format' for details) to use. If FORMAT is t, return
15896 the buffer's header-line. Second optional arg WINDOW specifies a
15897 different window to use as the context for the formatting.
15898 If third optional arg NO-PROPS is non-nil, string is not propertized.
15899 Fourth optional arg BUFFER specifies which buffer to use. */)
15900 (format
, window
, no_props
, buffer
)
15901 Lisp_Object format
, window
, no_props
, buffer
;
15906 struct buffer
*old_buffer
= NULL
;
15907 enum face_id face_id
= DEFAULT_FACE_ID
;
15910 window
= selected_window
;
15911 CHECK_WINDOW (window
);
15912 w
= XWINDOW (window
);
15915 buffer
= w
->buffer
;
15917 CHECK_BUFFER (buffer
);
15919 if (XBUFFER (buffer
) != current_buffer
)
15921 old_buffer
= current_buffer
;
15922 set_buffer_internal_1 (XBUFFER (buffer
));
15925 if (NILP (format
) || EQ (format
, Qt
))
15927 face_id
= (NILP (format
)
15928 ? CURRENT_MODE_LINE_FACE_ID (w
)
15929 : HEADER_LINE_FACE_ID
);
15930 format
= (NILP (format
)
15931 ? current_buffer
->mode_line_format
15932 : current_buffer
->header_line_format
);
15935 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15937 if (NILP (no_props
))
15939 mode_line_string_face
15940 = (face_id
== MODE_LINE_FACE_ID
? Qmode_line
15941 : face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
15942 : face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15944 mode_line_string_face_prop
15945 = (NILP (mode_line_string_face
) ? Qnil
15946 : Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
)));
15948 /* We need a dummy last element in mode_line_string_list to
15949 indicate we are building the propertized mode-line string.
15950 Using mode_line_string_face_prop here GC protects it. */
15951 mode_line_string_list
15952 = Fcons (mode_line_string_face_prop
, Qnil
);
15953 frame_title_ptr
= NULL
;
15957 mode_line_string_face_prop
= Qnil
;
15958 mode_line_string_list
= Qnil
;
15959 frame_title_ptr
= frame_title_buf
;
15962 push_frame_kboard (it
.f
);
15963 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15964 pop_frame_kboard ();
15967 set_buffer_internal_1 (old_buffer
);
15969 if (NILP (no_props
))
15972 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15973 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15974 make_string ("", 0));
15975 mode_line_string_face_prop
= Qnil
;
15976 mode_line_string_list
= Qnil
;
15980 len
= frame_title_ptr
- frame_title_buf
;
15981 if (len
> 0 && frame_title_ptr
[-1] == '-')
15983 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15984 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15986 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15987 if (len
> frame_title_ptr
- frame_title_buf
)
15988 len
= frame_title_ptr
- frame_title_buf
;
15991 frame_title_ptr
= NULL
;
15992 return make_string (frame_title_buf
, len
);
15995 /* Write a null-terminated, right justified decimal representation of
15996 the positive integer D to BUF using a minimal field width WIDTH. */
15999 pint2str (buf
, width
, d
)
16000 register char *buf
;
16001 register int width
;
16004 register char *p
= buf
;
16012 *p
++ = d
% 10 + '0';
16017 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16028 /* Write a null-terminated, right justified decimal and "human
16029 readable" representation of the nonnegative integer D to BUF using
16030 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16032 static const char power_letter
[] =
16046 pint2hrstr (buf
, width
, d
)
16051 /* We aim to represent the nonnegative integer D as
16052 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16055 /* -1 means: do not use TENTHS. */
16059 /* Length of QUOTIENT.TENTHS as a string. */
16065 if (1000 <= quotient
)
16067 /* Scale to the appropriate EXPONENT. */
16070 remainder
= quotient
% 1000;
16074 while (1000 <= quotient
);
16076 /* Round to nearest and decide whether to use TENTHS or not. */
16079 tenths
= remainder
/ 100;
16080 if (50 <= remainder
% 100)
16087 if (quotient
== 10)
16095 if (500 <= remainder
)
16097 if (quotient
< 999)
16108 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16109 if (tenths
== -1 && quotient
<= 99)
16116 p
= psuffix
= buf
+ max (width
, length
);
16118 /* Print EXPONENT. */
16120 *psuffix
++ = power_letter
[exponent
];
16123 /* Print TENTHS. */
16126 *--p
= '0' + tenths
;
16130 /* Print QUOTIENT. */
16133 int digit
= quotient
% 10;
16134 *--p
= '0' + digit
;
16136 while ((quotient
/= 10) != 0);
16138 /* Print leading spaces. */
16143 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16144 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16145 type of CODING_SYSTEM. Return updated pointer into BUF. */
16147 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16150 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16151 Lisp_Object coding_system
;
16152 register char *buf
;
16156 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16157 const unsigned char *eol_str
;
16159 /* The EOL conversion we are using. */
16160 Lisp_Object eoltype
;
16162 val
= Fget (coding_system
, Qcoding_system
);
16165 if (!VECTORP (val
)) /* Not yet decided. */
16170 eoltype
= eol_mnemonic_undecided
;
16171 /* Don't mention EOL conversion if it isn't decided. */
16175 Lisp_Object eolvalue
;
16177 eolvalue
= Fget (coding_system
, Qeol_type
);
16180 *buf
++ = XFASTINT (AREF (val
, 1));
16184 /* The EOL conversion that is normal on this system. */
16186 if (NILP (eolvalue
)) /* Not yet decided. */
16187 eoltype
= eol_mnemonic_undecided
;
16188 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16189 eoltype
= eol_mnemonic_undecided
;
16190 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16191 eoltype
= (XFASTINT (eolvalue
) == 0
16192 ? eol_mnemonic_unix
16193 : (XFASTINT (eolvalue
) == 1
16194 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16200 /* Mention the EOL conversion if it is not the usual one. */
16201 if (STRINGP (eoltype
))
16203 eol_str
= SDATA (eoltype
);
16204 eol_str_len
= SBYTES (eoltype
);
16206 else if (INTEGERP (eoltype
)
16207 && CHAR_VALID_P (XINT (eoltype
), 0))
16209 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16210 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16215 eol_str
= invalid_eol_type
;
16216 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16218 bcopy (eol_str
, buf
, eol_str_len
);
16219 buf
+= eol_str_len
;
16225 /* Return a string for the output of a mode line %-spec for window W,
16226 generated by character C. PRECISION >= 0 means don't return a
16227 string longer than that value. FIELD_WIDTH > 0 means pad the
16228 string returned with spaces to that value. Return 1 in *MULTIBYTE
16229 if the result is multibyte text.
16231 Note we operate on the current buffer for most purposes,
16232 the exception being w->base_line_pos. */
16234 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16237 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16240 int field_width
, precision
;
16244 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16245 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16246 struct buffer
*b
= current_buffer
;
16254 if (!NILP (b
->read_only
))
16256 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16261 /* This differs from %* only for a modified read-only buffer. */
16262 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16264 if (!NILP (b
->read_only
))
16269 /* This differs from %* in ignoring read-only-ness. */
16270 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16282 if (command_loop_level
> 5)
16284 p
= decode_mode_spec_buf
;
16285 for (i
= 0; i
< command_loop_level
; i
++)
16288 return decode_mode_spec_buf
;
16296 if (command_loop_level
> 5)
16298 p
= decode_mode_spec_buf
;
16299 for (i
= 0; i
< command_loop_level
; i
++)
16302 return decode_mode_spec_buf
;
16309 /* Let lots_of_dashes be a string of infinite length. */
16310 if (!NILP (mode_line_string_list
))
16312 if (field_width
<= 0
16313 || field_width
> sizeof (lots_of_dashes
))
16315 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16316 decode_mode_spec_buf
[i
] = '-';
16317 decode_mode_spec_buf
[i
] = '\0';
16318 return decode_mode_spec_buf
;
16321 return lots_of_dashes
;
16330 int col
= (int) current_column (); /* iftc */
16331 w
->column_number_displayed
= make_number (col
);
16332 pint2str (decode_mode_spec_buf
, field_width
, col
);
16333 return decode_mode_spec_buf
;
16337 /* %F displays the frame name. */
16338 if (!NILP (f
->title
))
16339 return (char *) SDATA (f
->title
);
16340 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16341 return (char *) SDATA (f
->name
);
16350 int size
= ZV
- BEGV
;
16351 pint2str (decode_mode_spec_buf
, field_width
, size
);
16352 return decode_mode_spec_buf
;
16357 int size
= ZV
- BEGV
;
16358 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16359 return decode_mode_spec_buf
;
16364 int startpos
= XMARKER (w
->start
)->charpos
;
16365 int startpos_byte
= marker_byte_position (w
->start
);
16366 int line
, linepos
, linepos_byte
, topline
;
16368 int height
= WINDOW_TOTAL_LINES (w
);
16370 /* If we decided that this buffer isn't suitable for line numbers,
16371 don't forget that too fast. */
16372 if (EQ (w
->base_line_pos
, w
->buffer
))
16374 /* But do forget it, if the window shows a different buffer now. */
16375 else if (BUFFERP (w
->base_line_pos
))
16376 w
->base_line_pos
= Qnil
;
16378 /* If the buffer is very big, don't waste time. */
16379 if (INTEGERP (Vline_number_display_limit
)
16380 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16382 w
->base_line_pos
= Qnil
;
16383 w
->base_line_number
= Qnil
;
16387 if (!NILP (w
->base_line_number
)
16388 && !NILP (w
->base_line_pos
)
16389 && XFASTINT (w
->base_line_pos
) <= startpos
)
16391 line
= XFASTINT (w
->base_line_number
);
16392 linepos
= XFASTINT (w
->base_line_pos
);
16393 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16398 linepos
= BUF_BEGV (b
);
16399 linepos_byte
= BUF_BEGV_BYTE (b
);
16402 /* Count lines from base line to window start position. */
16403 nlines
= display_count_lines (linepos
, linepos_byte
,
16407 topline
= nlines
+ line
;
16409 /* Determine a new base line, if the old one is too close
16410 or too far away, or if we did not have one.
16411 "Too close" means it's plausible a scroll-down would
16412 go back past it. */
16413 if (startpos
== BUF_BEGV (b
))
16415 w
->base_line_number
= make_number (topline
);
16416 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16418 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16419 || linepos
== BUF_BEGV (b
))
16421 int limit
= BUF_BEGV (b
);
16422 int limit_byte
= BUF_BEGV_BYTE (b
);
16424 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16426 if (startpos
- distance
> limit
)
16428 limit
= startpos
- distance
;
16429 limit_byte
= CHAR_TO_BYTE (limit
);
16432 nlines
= display_count_lines (startpos
, startpos_byte
,
16434 - (height
* 2 + 30),
16436 /* If we couldn't find the lines we wanted within
16437 line_number_display_limit_width chars per line,
16438 give up on line numbers for this window. */
16439 if (position
== limit_byte
&& limit
== startpos
- distance
)
16441 w
->base_line_pos
= w
->buffer
;
16442 w
->base_line_number
= Qnil
;
16446 w
->base_line_number
= make_number (topline
- nlines
);
16447 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16450 /* Now count lines from the start pos to point. */
16451 nlines
= display_count_lines (startpos
, startpos_byte
,
16452 PT_BYTE
, PT
, &junk
);
16454 /* Record that we did display the line number. */
16455 line_number_displayed
= 1;
16457 /* Make the string to show. */
16458 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16459 return decode_mode_spec_buf
;
16462 char* p
= decode_mode_spec_buf
;
16463 int pad
= field_width
- 2;
16469 return decode_mode_spec_buf
;
16475 obj
= b
->mode_name
;
16479 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16485 int pos
= marker_position (w
->start
);
16486 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16488 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16490 if (pos
<= BUF_BEGV (b
))
16495 else if (pos
<= BUF_BEGV (b
))
16499 if (total
> 1000000)
16500 /* Do it differently for a large value, to avoid overflow. */
16501 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16503 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16504 /* We can't normally display a 3-digit number,
16505 so get us a 2-digit number that is close. */
16508 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16509 return decode_mode_spec_buf
;
16513 /* Display percentage of size above the bottom of the screen. */
16516 int toppos
= marker_position (w
->start
);
16517 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16518 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16520 if (botpos
>= BUF_ZV (b
))
16522 if (toppos
<= BUF_BEGV (b
))
16529 if (total
> 1000000)
16530 /* Do it differently for a large value, to avoid overflow. */
16531 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16533 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16534 /* We can't normally display a 3-digit number,
16535 so get us a 2-digit number that is close. */
16538 if (toppos
<= BUF_BEGV (b
))
16539 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16541 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16542 return decode_mode_spec_buf
;
16547 /* status of process */
16548 obj
= Fget_buffer_process (Fcurrent_buffer ());
16550 return "no process";
16551 #ifdef subprocesses
16552 obj
= Fsymbol_name (Fprocess_status (obj
));
16556 case 't': /* indicate TEXT or BINARY */
16557 #ifdef MODE_LINE_BINARY_TEXT
16558 return MODE_LINE_BINARY_TEXT (b
);
16564 /* coding-system (not including end-of-line format) */
16566 /* coding-system (including end-of-line type) */
16568 int eol_flag
= (c
== 'Z');
16569 char *p
= decode_mode_spec_buf
;
16571 if (! FRAME_WINDOW_P (f
))
16573 /* No need to mention EOL here--the terminal never needs
16574 to do EOL conversion. */
16575 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
16576 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
16578 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16581 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16582 #ifdef subprocesses
16583 obj
= Fget_buffer_process (Fcurrent_buffer ());
16584 if (PROCESSP (obj
))
16586 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16588 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16591 #endif /* subprocesses */
16594 return decode_mode_spec_buf
;
16600 *multibyte
= STRING_MULTIBYTE (obj
);
16601 return (char *) SDATA (obj
);
16608 /* Count up to COUNT lines starting from START / START_BYTE.
16609 But don't go beyond LIMIT_BYTE.
16610 Return the number of lines thus found (always nonnegative).
16612 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16615 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16616 int start
, start_byte
, limit_byte
, count
;
16619 register unsigned char *cursor
;
16620 unsigned char *base
;
16622 register int ceiling
;
16623 register unsigned char *ceiling_addr
;
16624 int orig_count
= count
;
16626 /* If we are not in selective display mode,
16627 check only for newlines. */
16628 int selective_display
= (!NILP (current_buffer
->selective_display
)
16629 && !INTEGERP (current_buffer
->selective_display
));
16633 while (start_byte
< limit_byte
)
16635 ceiling
= BUFFER_CEILING_OF (start_byte
);
16636 ceiling
= min (limit_byte
- 1, ceiling
);
16637 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16638 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16641 if (selective_display
)
16642 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16645 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16648 if (cursor
!= ceiling_addr
)
16652 start_byte
+= cursor
- base
+ 1;
16653 *byte_pos_ptr
= start_byte
;
16657 if (++cursor
== ceiling_addr
)
16663 start_byte
+= cursor
- base
;
16668 while (start_byte
> limit_byte
)
16670 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16671 ceiling
= max (limit_byte
, ceiling
);
16672 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16673 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16676 if (selective_display
)
16677 while (--cursor
!= ceiling_addr
16678 && *cursor
!= '\n' && *cursor
!= 015)
16681 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16684 if (cursor
!= ceiling_addr
)
16688 start_byte
+= cursor
- base
+ 1;
16689 *byte_pos_ptr
= start_byte
;
16690 /* When scanning backwards, we should
16691 not count the newline posterior to which we stop. */
16692 return - orig_count
- 1;
16698 /* Here we add 1 to compensate for the last decrement
16699 of CURSOR, which took it past the valid range. */
16700 start_byte
+= cursor
- base
+ 1;
16704 *byte_pos_ptr
= limit_byte
;
16707 return - orig_count
+ count
;
16708 return orig_count
- count
;
16714 /***********************************************************************
16716 ***********************************************************************/
16718 /* Display a NUL-terminated string, starting with index START.
16720 If STRING is non-null, display that C string. Otherwise, the Lisp
16721 string LISP_STRING is displayed.
16723 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16724 FACE_STRING. Display STRING or LISP_STRING with the face at
16725 FACE_STRING_POS in FACE_STRING:
16727 Display the string in the environment given by IT, but use the
16728 standard display table, temporarily.
16730 FIELD_WIDTH is the minimum number of output glyphs to produce.
16731 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16732 with spaces. If STRING has more characters, more than FIELD_WIDTH
16733 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16735 PRECISION is the maximum number of characters to output from
16736 STRING. PRECISION < 0 means don't truncate the string.
16738 This is roughly equivalent to printf format specifiers:
16740 FIELD_WIDTH PRECISION PRINTF
16741 ----------------------------------------
16747 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16748 display them, and < 0 means obey the current buffer's value of
16749 enable_multibyte_characters.
16751 Value is the number of glyphs produced. */
16754 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16755 start
, it
, field_width
, precision
, max_x
, multibyte
)
16756 unsigned char *string
;
16757 Lisp_Object lisp_string
;
16758 Lisp_Object face_string
;
16759 int face_string_pos
;
16762 int field_width
, precision
, max_x
;
16765 int hpos_at_start
= it
->hpos
;
16766 int saved_face_id
= it
->face_id
;
16767 struct glyph_row
*row
= it
->glyph_row
;
16769 /* Initialize the iterator IT for iteration over STRING beginning
16770 with index START. */
16771 reseat_to_string (it
, string
, lisp_string
, start
,
16772 precision
, field_width
, multibyte
);
16774 /* If displaying STRING, set up the face of the iterator
16775 from LISP_STRING, if that's given. */
16776 if (STRINGP (face_string
))
16782 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16783 0, it
->region_beg_charpos
,
16784 it
->region_end_charpos
,
16785 &endptr
, it
->base_face_id
, 0);
16786 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16787 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16790 /* Set max_x to the maximum allowed X position. Don't let it go
16791 beyond the right edge of the window. */
16793 max_x
= it
->last_visible_x
;
16795 max_x
= min (max_x
, it
->last_visible_x
);
16797 /* Skip over display elements that are not visible. because IT->w is
16799 if (it
->current_x
< it
->first_visible_x
)
16800 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16801 MOVE_TO_POS
| MOVE_TO_X
);
16803 row
->ascent
= it
->max_ascent
;
16804 row
->height
= it
->max_ascent
+ it
->max_descent
;
16805 row
->phys_ascent
= it
->max_phys_ascent
;
16806 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16807 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16809 /* This condition is for the case that we are called with current_x
16810 past last_visible_x. */
16811 while (it
->current_x
< max_x
)
16813 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16815 /* Get the next display element. */
16816 if (!get_next_display_element (it
))
16819 /* Produce glyphs. */
16820 x_before
= it
->current_x
;
16821 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16822 PRODUCE_GLYPHS (it
);
16824 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16827 while (i
< nglyphs
)
16829 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16831 if (!it
->truncate_lines_p
16832 && x
+ glyph
->pixel_width
> max_x
)
16834 /* End of continued line or max_x reached. */
16835 if (CHAR_GLYPH_PADDING_P (*glyph
))
16837 /* A wide character is unbreakable. */
16838 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16839 it
->current_x
= x_before
;
16843 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16848 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16850 /* Glyph is at least partially visible. */
16852 if (x
< it
->first_visible_x
)
16853 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16857 /* Glyph is off the left margin of the display area.
16858 Should not happen. */
16862 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16863 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16864 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16865 row
->phys_height
= max (row
->phys_height
,
16866 it
->max_phys_ascent
+ it
->max_phys_descent
);
16867 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16868 it
->max_extra_line_spacing
);
16869 x
+= glyph
->pixel_width
;
16873 /* Stop if max_x reached. */
16877 /* Stop at line ends. */
16878 if (ITERATOR_AT_END_OF_LINE_P (it
))
16880 it
->continuation_lines_width
= 0;
16884 set_iterator_to_next (it
, 1);
16886 /* Stop if truncating at the right edge. */
16887 if (it
->truncate_lines_p
16888 && it
->current_x
>= it
->last_visible_x
)
16890 /* Add truncation mark, but don't do it if the line is
16891 truncated at a padding space. */
16892 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16894 if (!FRAME_WINDOW_P (it
->f
))
16898 if (it
->current_x
> it
->last_visible_x
)
16900 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16901 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16903 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16905 row
->used
[TEXT_AREA
] = i
;
16906 produce_special_glyphs (it
, IT_TRUNCATION
);
16909 produce_special_glyphs (it
, IT_TRUNCATION
);
16911 it
->glyph_row
->truncated_on_right_p
= 1;
16917 /* Maybe insert a truncation at the left. */
16918 if (it
->first_visible_x
16919 && IT_CHARPOS (*it
) > 0)
16921 if (!FRAME_WINDOW_P (it
->f
))
16922 insert_left_trunc_glyphs (it
);
16923 it
->glyph_row
->truncated_on_left_p
= 1;
16926 it
->face_id
= saved_face_id
;
16928 /* Value is number of columns displayed. */
16929 return it
->hpos
- hpos_at_start
;
16934 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16935 appears as an element of LIST or as the car of an element of LIST.
16936 If PROPVAL is a list, compare each element against LIST in that
16937 way, and return 1/2 if any element of PROPVAL is found in LIST.
16938 Otherwise return 0. This function cannot quit.
16939 The return value is 2 if the text is invisible but with an ellipsis
16940 and 1 if it's invisible and without an ellipsis. */
16943 invisible_p (propval
, list
)
16944 register Lisp_Object propval
;
16947 register Lisp_Object tail
, proptail
;
16949 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16951 register Lisp_Object tem
;
16953 if (EQ (propval
, tem
))
16955 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16956 return NILP (XCDR (tem
)) ? 1 : 2;
16959 if (CONSP (propval
))
16961 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16963 Lisp_Object propelt
;
16964 propelt
= XCAR (proptail
);
16965 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16967 register Lisp_Object tem
;
16969 if (EQ (propelt
, tem
))
16971 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16972 return NILP (XCDR (tem
)) ? 1 : 2;
16980 /* Calculate a width or height in pixels from a specification using
16981 the following elements:
16984 NUM - a (fractional) multiple of the default font width/height
16985 (NUM) - specifies exactly NUM pixels
16986 UNIT - a fixed number of pixels, see below.
16987 ELEMENT - size of a display element in pixels, see below.
16988 (NUM . SPEC) - equals NUM * SPEC
16989 (+ SPEC SPEC ...) - add pixel values
16990 (- SPEC SPEC ...) - subtract pixel values
16991 (- SPEC) - negate pixel value
16994 INT or FLOAT - a number constant
16995 SYMBOL - use symbol's (buffer local) variable binding.
16998 in - pixels per inch *)
16999 mm - pixels per 1/1000 meter *)
17000 cm - pixels per 1/100 meter *)
17001 width - width of current font in pixels.
17002 height - height of current font in pixels.
17004 *) using the ratio(s) defined in display-pixels-per-inch.
17008 left-fringe - left fringe width in pixels
17009 right-fringe - right fringe width in pixels
17011 left-margin - left margin width in pixels
17012 right-margin - right margin width in pixels
17014 scroll-bar - scroll-bar area width in pixels
17018 Pixels corresponding to 5 inches:
17021 Total width of non-text areas on left side of window (if scroll-bar is on left):
17022 '(space :width (+ left-fringe left-margin scroll-bar))
17024 Align to first text column (in header line):
17025 '(space :align-to 0)
17027 Align to middle of text area minus half the width of variable `my-image'
17028 containing a loaded image:
17029 '(space :align-to (0.5 . (- text my-image)))
17031 Width of left margin minus width of 1 character in the default font:
17032 '(space :width (- left-margin 1))
17034 Width of left margin minus width of 2 characters in the current font:
17035 '(space :width (- left-margin (2 . width)))
17037 Center 1 character over left-margin (in header line):
17038 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17040 Different ways to express width of left fringe plus left margin minus one pixel:
17041 '(space :width (- (+ left-fringe left-margin) (1)))
17042 '(space :width (+ left-fringe left-margin (- (1))))
17043 '(space :width (+ left-fringe left-margin (-1)))
17047 #define NUMVAL(X) \
17048 ((INTEGERP (X) || FLOATP (X)) \
17053 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17058 int width_p
, *align_to
;
17062 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17063 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17066 return OK_PIXELS (0);
17068 if (SYMBOLP (prop
))
17070 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17072 char *unit
= SDATA (SYMBOL_NAME (prop
));
17074 if (unit
[0] == 'i' && unit
[1] == 'n')
17076 else if (unit
[0] == 'm' && unit
[1] == 'm')
17078 else if (unit
[0] == 'c' && unit
[1] == 'm')
17085 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17086 || (CONSP (Vdisplay_pixels_per_inch
)
17088 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17089 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17091 return OK_PIXELS (ppi
/ pixels
);
17097 #ifdef HAVE_WINDOW_SYSTEM
17098 if (EQ (prop
, Qheight
))
17099 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17100 if (EQ (prop
, Qwidth
))
17101 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17103 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17104 return OK_PIXELS (1);
17107 if (EQ (prop
, Qtext
))
17108 return OK_PIXELS (width_p
17109 ? window_box_width (it
->w
, TEXT_AREA
)
17110 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17112 if (align_to
&& *align_to
< 0)
17115 if (EQ (prop
, Qleft
))
17116 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17117 if (EQ (prop
, Qright
))
17118 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17119 if (EQ (prop
, Qcenter
))
17120 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17121 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17122 if (EQ (prop
, Qleft_fringe
))
17123 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17124 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17125 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17126 if (EQ (prop
, Qright_fringe
))
17127 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17128 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17129 : window_box_right_offset (it
->w
, TEXT_AREA
));
17130 if (EQ (prop
, Qleft_margin
))
17131 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17132 if (EQ (prop
, Qright_margin
))
17133 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17134 if (EQ (prop
, Qscroll_bar
))
17135 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17137 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17138 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17139 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17144 if (EQ (prop
, Qleft_fringe
))
17145 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17146 if (EQ (prop
, Qright_fringe
))
17147 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17148 if (EQ (prop
, Qleft_margin
))
17149 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17150 if (EQ (prop
, Qright_margin
))
17151 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17152 if (EQ (prop
, Qscroll_bar
))
17153 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17156 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17159 if (INTEGERP (prop
) || FLOATP (prop
))
17161 int base_unit
= (width_p
17162 ? FRAME_COLUMN_WIDTH (it
->f
)
17163 : FRAME_LINE_HEIGHT (it
->f
));
17164 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17169 Lisp_Object car
= XCAR (prop
);
17170 Lisp_Object cdr
= XCDR (prop
);
17174 #ifdef HAVE_WINDOW_SYSTEM
17175 if (valid_image_p (prop
))
17177 int id
= lookup_image (it
->f
, prop
);
17178 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17180 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17183 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17189 while (CONSP (cdr
))
17191 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17192 font
, width_p
, align_to
))
17195 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17200 if (EQ (car
, Qminus
))
17202 return OK_PIXELS (pixels
);
17205 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17208 if (INTEGERP (car
) || FLOATP (car
))
17211 pixels
= XFLOATINT (car
);
17213 return OK_PIXELS (pixels
);
17214 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17215 font
, width_p
, align_to
))
17216 return OK_PIXELS (pixels
* fact
);
17227 /***********************************************************************
17229 ***********************************************************************/
17231 #ifdef HAVE_WINDOW_SYSTEM
17236 dump_glyph_string (s
)
17237 struct glyph_string
*s
;
17239 fprintf (stderr
, "glyph string\n");
17240 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17241 s
->x
, s
->y
, s
->width
, s
->height
);
17242 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17243 fprintf (stderr
, " hl = %d\n", s
->hl
);
17244 fprintf (stderr
, " left overhang = %d, right = %d\n",
17245 s
->left_overhang
, s
->right_overhang
);
17246 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17247 fprintf (stderr
, " extends to end of line = %d\n",
17248 s
->extends_to_end_of_line_p
);
17249 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17250 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17253 #endif /* GLYPH_DEBUG */
17255 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17256 of XChar2b structures for S; it can't be allocated in
17257 init_glyph_string because it must be allocated via `alloca'. W
17258 is the window on which S is drawn. ROW and AREA are the glyph row
17259 and area within the row from which S is constructed. START is the
17260 index of the first glyph structure covered by S. HL is a
17261 face-override for drawing S. */
17264 #define OPTIONAL_HDC(hdc) hdc,
17265 #define DECLARE_HDC(hdc) HDC hdc;
17266 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17267 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17270 #ifndef OPTIONAL_HDC
17271 #define OPTIONAL_HDC(hdc)
17272 #define DECLARE_HDC(hdc)
17273 #define ALLOCATE_HDC(hdc, f)
17274 #define RELEASE_HDC(hdc, f)
17278 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17279 struct glyph_string
*s
;
17283 struct glyph_row
*row
;
17284 enum glyph_row_area area
;
17286 enum draw_glyphs_face hl
;
17288 bzero (s
, sizeof *s
);
17290 s
->f
= XFRAME (w
->frame
);
17294 s
->display
= FRAME_X_DISPLAY (s
->f
);
17295 s
->window
= FRAME_X_WINDOW (s
->f
);
17296 s
->char2b
= char2b
;
17300 s
->first_glyph
= row
->glyphs
[area
] + start
;
17301 s
->height
= row
->height
;
17302 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17304 /* Display the internal border below the tool-bar window. */
17305 if (WINDOWP (s
->f
->tool_bar_window
)
17306 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17307 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17309 s
->ybase
= s
->y
+ row
->ascent
;
17313 /* Append the list of glyph strings with head H and tail T to the list
17314 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17317 append_glyph_string_lists (head
, tail
, h
, t
)
17318 struct glyph_string
**head
, **tail
;
17319 struct glyph_string
*h
, *t
;
17333 /* Prepend the list of glyph strings with head H and tail T to the
17334 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17338 prepend_glyph_string_lists (head
, tail
, h
, t
)
17339 struct glyph_string
**head
, **tail
;
17340 struct glyph_string
*h
, *t
;
17354 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17355 Set *HEAD and *TAIL to the resulting list. */
17358 append_glyph_string (head
, tail
, s
)
17359 struct glyph_string
**head
, **tail
;
17360 struct glyph_string
*s
;
17362 s
->next
= s
->prev
= NULL
;
17363 append_glyph_string_lists (head
, tail
, s
, s
);
17367 /* Get face and two-byte form of character glyph GLYPH on frame F.
17368 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17369 a pointer to a realized face that is ready for display. */
17371 static INLINE
struct face
*
17372 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17374 struct glyph
*glyph
;
17380 xassert (glyph
->type
== CHAR_GLYPH
);
17381 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17386 if (!glyph
->multibyte_p
)
17388 /* Unibyte case. We don't have to encode, but we have to make
17389 sure to use a face suitable for unibyte. */
17390 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17392 else if (glyph
->u
.ch
< 128
17393 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17395 /* Case of ASCII in a face known to fit ASCII. */
17396 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17400 int c1
, c2
, charset
;
17402 /* Split characters into bytes. If c2 is -1 afterwards, C is
17403 really a one-byte character so that byte1 is zero. */
17404 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17406 STORE_XCHAR2B (char2b
, c1
, c2
);
17408 STORE_XCHAR2B (char2b
, 0, c1
);
17410 /* Maybe encode the character in *CHAR2B. */
17411 if (charset
!= CHARSET_ASCII
)
17413 struct font_info
*font_info
17414 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17417 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17421 /* Make sure X resources of the face are allocated. */
17422 xassert (face
!= NULL
);
17423 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17428 /* Fill glyph string S with composition components specified by S->cmp.
17430 FACES is an array of faces for all components of this composition.
17431 S->gidx is the index of the first component for S.
17432 OVERLAPS_P non-zero means S should draw the foreground only, and
17433 use its physical height for clipping.
17435 Value is the index of a component not in S. */
17438 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17439 struct glyph_string
*s
;
17440 struct face
**faces
;
17447 s
->for_overlaps_p
= overlaps_p
;
17449 s
->face
= faces
[s
->gidx
];
17450 s
->font
= s
->face
->font
;
17451 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17453 /* For all glyphs of this composition, starting at the offset
17454 S->gidx, until we reach the end of the definition or encounter a
17455 glyph that requires the different face, add it to S. */
17457 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17460 /* All glyph strings for the same composition has the same width,
17461 i.e. the width set for the first component of the composition. */
17463 s
->width
= s
->first_glyph
->pixel_width
;
17465 /* If the specified font could not be loaded, use the frame's
17466 default font, but record the fact that we couldn't load it in
17467 the glyph string so that we can draw rectangles for the
17468 characters of the glyph string. */
17469 if (s
->font
== NULL
)
17471 s
->font_not_found_p
= 1;
17472 s
->font
= FRAME_FONT (s
->f
);
17475 /* Adjust base line for subscript/superscript text. */
17476 s
->ybase
+= s
->first_glyph
->voffset
;
17478 xassert (s
->face
&& s
->face
->gc
);
17480 /* This glyph string must always be drawn with 16-bit functions. */
17483 return s
->gidx
+ s
->nchars
;
17487 /* Fill glyph string S from a sequence of character glyphs.
17489 FACE_ID is the face id of the string. START is the index of the
17490 first glyph to consider, END is the index of the last + 1.
17491 OVERLAPS_P non-zero means S should draw the foreground only, and
17492 use its physical height for clipping.
17494 Value is the index of the first glyph not in S. */
17497 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17498 struct glyph_string
*s
;
17500 int start
, end
, overlaps_p
;
17502 struct glyph
*glyph
, *last
;
17504 int glyph_not_available_p
;
17506 xassert (s
->f
== XFRAME (s
->w
->frame
));
17507 xassert (s
->nchars
== 0);
17508 xassert (start
>= 0 && end
> start
);
17510 s
->for_overlaps_p
= overlaps_p
,
17511 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17512 last
= s
->row
->glyphs
[s
->area
] + end
;
17513 voffset
= glyph
->voffset
;
17515 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17517 while (glyph
< last
17518 && glyph
->type
== CHAR_GLYPH
17519 && glyph
->voffset
== voffset
17520 /* Same face id implies same font, nowadays. */
17521 && glyph
->face_id
== face_id
17522 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17526 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17527 s
->char2b
+ s
->nchars
,
17529 s
->two_byte_p
= two_byte_p
;
17531 xassert (s
->nchars
<= end
- start
);
17532 s
->width
+= glyph
->pixel_width
;
17536 s
->font
= s
->face
->font
;
17537 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17539 /* If the specified font could not be loaded, use the frame's font,
17540 but record the fact that we couldn't load it in
17541 S->font_not_found_p so that we can draw rectangles for the
17542 characters of the glyph string. */
17543 if (s
->font
== NULL
|| glyph_not_available_p
)
17545 s
->font_not_found_p
= 1;
17546 s
->font
= FRAME_FONT (s
->f
);
17549 /* Adjust base line for subscript/superscript text. */
17550 s
->ybase
+= voffset
;
17552 xassert (s
->face
&& s
->face
->gc
);
17553 return glyph
- s
->row
->glyphs
[s
->area
];
17557 /* Fill glyph string S from image glyph S->first_glyph. */
17560 fill_image_glyph_string (s
)
17561 struct glyph_string
*s
;
17563 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17564 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17566 s
->slice
= s
->first_glyph
->slice
;
17567 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17568 s
->font
= s
->face
->font
;
17569 s
->width
= s
->first_glyph
->pixel_width
;
17571 /* Adjust base line for subscript/superscript text. */
17572 s
->ybase
+= s
->first_glyph
->voffset
;
17576 /* Fill glyph string S from a sequence of stretch glyphs.
17578 ROW is the glyph row in which the glyphs are found, AREA is the
17579 area within the row. START is the index of the first glyph to
17580 consider, END is the index of the last + 1.
17582 Value is the index of the first glyph not in S. */
17585 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17586 struct glyph_string
*s
;
17587 struct glyph_row
*row
;
17588 enum glyph_row_area area
;
17591 struct glyph
*glyph
, *last
;
17592 int voffset
, face_id
;
17594 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17596 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17597 last
= s
->row
->glyphs
[s
->area
] + end
;
17598 face_id
= glyph
->face_id
;
17599 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17600 s
->font
= s
->face
->font
;
17601 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17602 s
->width
= glyph
->pixel_width
;
17603 voffset
= glyph
->voffset
;
17607 && glyph
->type
== STRETCH_GLYPH
17608 && glyph
->voffset
== voffset
17609 && glyph
->face_id
== face_id
);
17611 s
->width
+= glyph
->pixel_width
;
17613 /* Adjust base line for subscript/superscript text. */
17614 s
->ybase
+= voffset
;
17616 /* The case that face->gc == 0 is handled when drawing the glyph
17617 string by calling PREPARE_FACE_FOR_DISPLAY. */
17619 return glyph
- s
->row
->glyphs
[s
->area
];
17624 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17625 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17626 assumed to be zero. */
17629 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17630 struct glyph
*glyph
;
17634 *left
= *right
= 0;
17636 if (glyph
->type
== CHAR_GLYPH
)
17640 struct font_info
*font_info
;
17644 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17646 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17647 if (font
/* ++KFS: Should this be font_info ? */
17648 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17650 if (pcm
->rbearing
> pcm
->width
)
17651 *right
= pcm
->rbearing
- pcm
->width
;
17652 if (pcm
->lbearing
< 0)
17653 *left
= -pcm
->lbearing
;
17659 /* Return the index of the first glyph preceding glyph string S that
17660 is overwritten by S because of S's left overhang. Value is -1
17661 if no glyphs are overwritten. */
17664 left_overwritten (s
)
17665 struct glyph_string
*s
;
17669 if (s
->left_overhang
)
17672 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17673 int first
= s
->first_glyph
- glyphs
;
17675 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17676 x
-= glyphs
[i
].pixel_width
;
17687 /* Return the index of the first glyph preceding glyph string S that
17688 is overwriting S because of its right overhang. Value is -1 if no
17689 glyph in front of S overwrites S. */
17692 left_overwriting (s
)
17693 struct glyph_string
*s
;
17696 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17697 int first
= s
->first_glyph
- glyphs
;
17701 for (i
= first
- 1; i
>= 0; --i
)
17704 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17707 x
-= glyphs
[i
].pixel_width
;
17714 /* Return the index of the last glyph following glyph string S that is
17715 not overwritten by S because of S's right overhang. Value is -1 if
17716 no such glyph is found. */
17719 right_overwritten (s
)
17720 struct glyph_string
*s
;
17724 if (s
->right_overhang
)
17727 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17728 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17729 int end
= s
->row
->used
[s
->area
];
17731 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17732 x
+= glyphs
[i
].pixel_width
;
17741 /* Return the index of the last glyph following glyph string S that
17742 overwrites S because of its left overhang. Value is negative
17743 if no such glyph is found. */
17746 right_overwriting (s
)
17747 struct glyph_string
*s
;
17750 int end
= s
->row
->used
[s
->area
];
17751 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17752 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17756 for (i
= first
; i
< end
; ++i
)
17759 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17762 x
+= glyphs
[i
].pixel_width
;
17769 /* Get face and two-byte form of character C in face FACE_ID on frame
17770 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17771 means we want to display multibyte text. DISPLAY_P non-zero means
17772 make sure that X resources for the face returned are allocated.
17773 Value is a pointer to a realized face that is ready for display if
17774 DISPLAY_P is non-zero. */
17776 static INLINE
struct face
*
17777 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17781 int multibyte_p
, display_p
;
17783 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17787 /* Unibyte case. We don't have to encode, but we have to make
17788 sure to use a face suitable for unibyte. */
17789 STORE_XCHAR2B (char2b
, 0, c
);
17790 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17791 face
= FACE_FROM_ID (f
, face_id
);
17793 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17795 /* Case of ASCII in a face known to fit ASCII. */
17796 STORE_XCHAR2B (char2b
, 0, c
);
17800 int c1
, c2
, charset
;
17802 /* Split characters into bytes. If c2 is -1 afterwards, C is
17803 really a one-byte character so that byte1 is zero. */
17804 SPLIT_CHAR (c
, charset
, c1
, c2
);
17806 STORE_XCHAR2B (char2b
, c1
, c2
);
17808 STORE_XCHAR2B (char2b
, 0, c1
);
17810 /* Maybe encode the character in *CHAR2B. */
17811 if (face
->font
!= NULL
)
17813 struct font_info
*font_info
17814 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17816 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
17820 /* Make sure X resources of the face are allocated. */
17821 #ifdef HAVE_X_WINDOWS
17825 xassert (face
!= NULL
);
17826 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17833 /* Set background width of glyph string S. START is the index of the
17834 first glyph following S. LAST_X is the right-most x-position + 1
17835 in the drawing area. */
17838 set_glyph_string_background_width (s
, start
, last_x
)
17839 struct glyph_string
*s
;
17843 /* If the face of this glyph string has to be drawn to the end of
17844 the drawing area, set S->extends_to_end_of_line_p. */
17845 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17847 if (start
== s
->row
->used
[s
->area
]
17848 && s
->area
== TEXT_AREA
17849 && ((s
->hl
== DRAW_NORMAL_TEXT
17850 && (s
->row
->fill_line_p
17851 || s
->face
->background
!= default_face
->background
17852 || s
->face
->stipple
!= default_face
->stipple
17853 || s
->row
->mouse_face_p
))
17854 || s
->hl
== DRAW_MOUSE_FACE
17855 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17856 && s
->row
->fill_line_p
)))
17857 s
->extends_to_end_of_line_p
= 1;
17859 /* If S extends its face to the end of the line, set its
17860 background_width to the distance to the right edge of the drawing
17862 if (s
->extends_to_end_of_line_p
)
17863 s
->background_width
= last_x
- s
->x
+ 1;
17865 s
->background_width
= s
->width
;
17869 /* Compute overhangs and x-positions for glyph string S and its
17870 predecessors, or successors. X is the starting x-position for S.
17871 BACKWARD_P non-zero means process predecessors. */
17874 compute_overhangs_and_x (s
, x
, backward_p
)
17875 struct glyph_string
*s
;
17883 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17884 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17894 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
17895 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
17905 /* The following macros are only called from draw_glyphs below.
17906 They reference the following parameters of that function directly:
17907 `w', `row', `area', and `overlap_p'
17908 as well as the following local variables:
17909 `s', `f', and `hdc' (in W32) */
17912 /* On W32, silently add local `hdc' variable to argument list of
17913 init_glyph_string. */
17914 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17915 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17917 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17918 init_glyph_string (s, char2b, w, row, area, start, hl)
17921 /* Add a glyph string for a stretch glyph to the list of strings
17922 between HEAD and TAIL. START is the index of the stretch glyph in
17923 row area AREA of glyph row ROW. END is the index of the last glyph
17924 in that glyph row area. X is the current output position assigned
17925 to the new glyph string constructed. HL overrides that face of the
17926 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17927 is the right-most x-position of the drawing area. */
17929 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17930 and below -- keep them on one line. */
17931 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17934 s = (struct glyph_string *) alloca (sizeof *s); \
17935 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17936 START = fill_stretch_glyph_string (s, row, area, START, END); \
17937 append_glyph_string (&HEAD, &TAIL, s); \
17943 /* Add a glyph string for an image glyph to the list of strings
17944 between HEAD and TAIL. START is the index of the image glyph in
17945 row area AREA of glyph row ROW. END is the index of the last glyph
17946 in that glyph row area. X is the current output position assigned
17947 to the new glyph string constructed. HL overrides that face of the
17948 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17949 is the right-most x-position of the drawing area. */
17951 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17954 s = (struct glyph_string *) alloca (sizeof *s); \
17955 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17956 fill_image_glyph_string (s); \
17957 append_glyph_string (&HEAD, &TAIL, s); \
17964 /* Add a glyph string for a sequence of character glyphs to the list
17965 of strings between HEAD and TAIL. START is the index of the first
17966 glyph in row area AREA of glyph row ROW that is part of the new
17967 glyph string. END is the index of the last glyph in that glyph row
17968 area. X is the current output position assigned to the new glyph
17969 string constructed. HL overrides that face of the glyph; e.g. it
17970 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17971 right-most x-position of the drawing area. */
17973 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17979 c = (row)->glyphs[area][START].u.ch; \
17980 face_id = (row)->glyphs[area][START].face_id; \
17982 s = (struct glyph_string *) alloca (sizeof *s); \
17983 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17984 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17985 append_glyph_string (&HEAD, &TAIL, s); \
17987 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17992 /* Add a glyph string for a composite sequence to the list of strings
17993 between HEAD and TAIL. START is the index of the first glyph in
17994 row area AREA of glyph row ROW that is part of the new glyph
17995 string. END is the index of the last glyph in that glyph row area.
17996 X is the current output position assigned to the new glyph string
17997 constructed. HL overrides that face of the glyph; e.g. it is
17998 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17999 x-position of the drawing area. */
18001 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18003 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18004 int face_id = (row)->glyphs[area][START].face_id; \
18005 struct face *base_face = FACE_FROM_ID (f, face_id); \
18006 struct composition *cmp = composition_table[cmp_id]; \
18007 int glyph_len = cmp->glyph_len; \
18009 struct face **faces; \
18010 struct glyph_string *first_s = NULL; \
18013 base_face = base_face->ascii_face; \
18014 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18015 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18016 /* At first, fill in `char2b' and `faces'. */ \
18017 for (n = 0; n < glyph_len; n++) \
18019 int c = COMPOSITION_GLYPH (cmp, n); \
18020 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18021 faces[n] = FACE_FROM_ID (f, this_face_id); \
18022 get_char_face_and_encoding (f, c, this_face_id, \
18023 char2b + n, 1, 1); \
18026 /* Make glyph_strings for each glyph sequence that is drawable by \
18027 the same face, and append them to HEAD/TAIL. */ \
18028 for (n = 0; n < cmp->glyph_len;) \
18030 s = (struct glyph_string *) alloca (sizeof *s); \
18031 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18032 append_glyph_string (&(HEAD), &(TAIL), s); \
18040 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18048 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18049 of AREA of glyph row ROW on window W between indices START and END.
18050 HL overrides the face for drawing glyph strings, e.g. it is
18051 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18052 x-positions of the drawing area.
18054 This is an ugly monster macro construct because we must use alloca
18055 to allocate glyph strings (because draw_glyphs can be called
18056 asynchronously). */
18058 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18061 HEAD = TAIL = NULL; \
18062 while (START < END) \
18064 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18065 switch (first_glyph->type) \
18068 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18072 case COMPOSITE_GLYPH: \
18073 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18077 case STRETCH_GLYPH: \
18078 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18082 case IMAGE_GLYPH: \
18083 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18091 set_glyph_string_background_width (s, START, LAST_X); \
18098 /* Draw glyphs between START and END in AREA of ROW on window W,
18099 starting at x-position X. X is relative to AREA in W. HL is a
18100 face-override with the following meaning:
18102 DRAW_NORMAL_TEXT draw normally
18103 DRAW_CURSOR draw in cursor face
18104 DRAW_MOUSE_FACE draw in mouse face.
18105 DRAW_INVERSE_VIDEO draw in mode line face
18106 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18107 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18109 If OVERLAPS_P is non-zero, draw only the foreground of characters
18110 and clip to the physical height of ROW.
18112 Value is the x-position reached, relative to AREA of W. */
18115 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18118 struct glyph_row
*row
;
18119 enum glyph_row_area area
;
18121 enum draw_glyphs_face hl
;
18124 struct glyph_string
*head
, *tail
;
18125 struct glyph_string
*s
;
18126 int last_x
, area_width
;
18129 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18132 ALLOCATE_HDC (hdc
, f
);
18134 /* Let's rather be paranoid than getting a SEGV. */
18135 end
= min (end
, row
->used
[area
]);
18136 start
= max (0, start
);
18137 start
= min (end
, start
);
18139 /* Translate X to frame coordinates. Set last_x to the right
18140 end of the drawing area. */
18141 if (row
->full_width_p
)
18143 /* X is relative to the left edge of W, without scroll bars
18145 x
+= WINDOW_LEFT_EDGE_X (w
);
18146 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18150 int area_left
= window_box_left (w
, area
);
18152 area_width
= window_box_width (w
, area
);
18153 last_x
= area_left
+ area_width
;
18156 /* Build a doubly-linked list of glyph_string structures between
18157 head and tail from what we have to draw. Note that the macro
18158 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18159 the reason we use a separate variable `i'. */
18161 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18163 x_reached
= tail
->x
+ tail
->background_width
;
18167 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18168 the row, redraw some glyphs in front or following the glyph
18169 strings built above. */
18170 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18173 struct glyph_string
*h
, *t
;
18175 /* Compute overhangs for all glyph strings. */
18176 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
18177 for (s
= head
; s
; s
= s
->next
)
18178 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
18180 /* Prepend glyph strings for glyphs in front of the first glyph
18181 string that are overwritten because of the first glyph
18182 string's left overhang. The background of all strings
18183 prepended must be drawn because the first glyph string
18185 i
= left_overwritten (head
);
18189 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18190 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18192 compute_overhangs_and_x (t
, head
->x
, 1);
18193 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18196 /* Prepend glyph strings for glyphs in front of the first glyph
18197 string that overwrite that glyph string because of their
18198 right overhang. For these strings, only the foreground must
18199 be drawn, because it draws over the glyph string at `head'.
18200 The background must not be drawn because this would overwrite
18201 right overhangs of preceding glyphs for which no glyph
18203 i
= left_overwriting (head
);
18206 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18207 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18208 for (s
= h
; s
; s
= s
->next
)
18209 s
->background_filled_p
= 1;
18210 compute_overhangs_and_x (t
, head
->x
, 1);
18211 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18214 /* Append glyphs strings for glyphs following the last glyph
18215 string tail that are overwritten by tail. The background of
18216 these strings has to be drawn because tail's foreground draws
18218 i
= right_overwritten (tail
);
18221 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18222 DRAW_NORMAL_TEXT
, x
, last_x
);
18223 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18224 append_glyph_string_lists (&head
, &tail
, h
, t
);
18227 /* Append glyph strings for glyphs following the last glyph
18228 string tail that overwrite tail. The foreground of such
18229 glyphs has to be drawn because it writes into the background
18230 of tail. The background must not be drawn because it could
18231 paint over the foreground of following glyphs. */
18232 i
= right_overwriting (tail
);
18235 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18236 DRAW_NORMAL_TEXT
, x
, last_x
);
18237 for (s
= h
; s
; s
= s
->next
)
18238 s
->background_filled_p
= 1;
18239 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18240 append_glyph_string_lists (&head
, &tail
, h
, t
);
18244 /* Draw all strings. */
18245 for (s
= head
; s
; s
= s
->next
)
18246 FRAME_RIF (f
)->draw_glyph_string (s
);
18248 if (area
== TEXT_AREA
18249 && !row
->full_width_p
18250 /* When drawing overlapping rows, only the glyph strings'
18251 foreground is drawn, which doesn't erase a cursor
18255 int x0
= head
? head
->x
: x
;
18256 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18258 int text_left
= window_box_left (w
, TEXT_AREA
);
18262 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18263 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18266 /* Value is the x-position up to which drawn, relative to AREA of W.
18267 This doesn't include parts drawn because of overhangs. */
18268 if (row
->full_width_p
)
18269 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18271 x_reached
-= window_box_left (w
, area
);
18273 RELEASE_HDC (hdc
, f
);
18278 /* Expand row matrix if too narrow. Don't expand if area
18281 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18283 if (!fonts_changed_p \
18284 && (it->glyph_row->glyphs[area] \
18285 < it->glyph_row->glyphs[area + 1])) \
18287 it->w->ncols_scale_factor++; \
18288 fonts_changed_p = 1; \
18292 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18293 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18299 struct glyph
*glyph
;
18300 enum glyph_row_area area
= it
->area
;
18302 xassert (it
->glyph_row
);
18303 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18305 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18306 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18308 glyph
->charpos
= CHARPOS (it
->position
);
18309 glyph
->object
= it
->object
;
18310 glyph
->pixel_width
= it
->pixel_width
;
18311 glyph
->ascent
= it
->ascent
;
18312 glyph
->descent
= it
->descent
;
18313 glyph
->voffset
= it
->voffset
;
18314 glyph
->type
= CHAR_GLYPH
;
18315 glyph
->multibyte_p
= it
->multibyte_p
;
18316 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18317 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18318 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18319 || it
->phys_descent
> it
->descent
);
18320 glyph
->padding_p
= 0;
18321 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18322 glyph
->face_id
= it
->face_id
;
18323 glyph
->u
.ch
= it
->char_to_display
;
18324 glyph
->slice
= null_glyph_slice
;
18325 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18326 ++it
->glyph_row
->used
[area
];
18329 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18332 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18333 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18336 append_composite_glyph (it
)
18339 struct glyph
*glyph
;
18340 enum glyph_row_area area
= it
->area
;
18342 xassert (it
->glyph_row
);
18344 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18345 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18347 glyph
->charpos
= CHARPOS (it
->position
);
18348 glyph
->object
= it
->object
;
18349 glyph
->pixel_width
= it
->pixel_width
;
18350 glyph
->ascent
= it
->ascent
;
18351 glyph
->descent
= it
->descent
;
18352 glyph
->voffset
= it
->voffset
;
18353 glyph
->type
= COMPOSITE_GLYPH
;
18354 glyph
->multibyte_p
= it
->multibyte_p
;
18355 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18356 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18357 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18358 || it
->phys_descent
> it
->descent
);
18359 glyph
->padding_p
= 0;
18360 glyph
->glyph_not_available_p
= 0;
18361 glyph
->face_id
= it
->face_id
;
18362 glyph
->u
.cmp_id
= it
->cmp_id
;
18363 glyph
->slice
= null_glyph_slice
;
18364 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18365 ++it
->glyph_row
->used
[area
];
18368 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18372 /* Change IT->ascent and IT->height according to the setting of
18376 take_vertical_position_into_account (it
)
18381 if (it
->voffset
< 0)
18382 /* Increase the ascent so that we can display the text higher
18384 it
->ascent
-= it
->voffset
;
18386 /* Increase the descent so that we can display the text lower
18388 it
->descent
+= it
->voffset
;
18393 /* Produce glyphs/get display metrics for the image IT is loaded with.
18394 See the description of struct display_iterator in dispextern.h for
18395 an overview of struct display_iterator. */
18398 produce_image_glyph (it
)
18404 struct glyph_slice slice
;
18406 xassert (it
->what
== IT_IMAGE
);
18408 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18410 /* Make sure X resources of the face is loaded. */
18411 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18413 if (it
->image_id
< 0)
18415 /* Fringe bitmap. */
18416 it
->ascent
= it
->phys_ascent
= 0;
18417 it
->descent
= it
->phys_descent
= 0;
18418 it
->pixel_width
= 0;
18423 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18425 /* Make sure X resources of the image is loaded. */
18426 prepare_image_for_display (it
->f
, img
);
18428 slice
.x
= slice
.y
= 0;
18429 slice
.width
= img
->width
;
18430 slice
.height
= img
->height
;
18432 if (INTEGERP (it
->slice
.x
))
18433 slice
.x
= XINT (it
->slice
.x
);
18434 else if (FLOATP (it
->slice
.x
))
18435 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18437 if (INTEGERP (it
->slice
.y
))
18438 slice
.y
= XINT (it
->slice
.y
);
18439 else if (FLOATP (it
->slice
.y
))
18440 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18442 if (INTEGERP (it
->slice
.width
))
18443 slice
.width
= XINT (it
->slice
.width
);
18444 else if (FLOATP (it
->slice
.width
))
18445 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18447 if (INTEGERP (it
->slice
.height
))
18448 slice
.height
= XINT (it
->slice
.height
);
18449 else if (FLOATP (it
->slice
.height
))
18450 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18452 if (slice
.x
>= img
->width
)
18453 slice
.x
= img
->width
;
18454 if (slice
.y
>= img
->height
)
18455 slice
.y
= img
->height
;
18456 if (slice
.x
+ slice
.width
>= img
->width
)
18457 slice
.width
= img
->width
- slice
.x
;
18458 if (slice
.y
+ slice
.height
> img
->height
)
18459 slice
.height
= img
->height
- slice
.y
;
18461 if (slice
.width
== 0 || slice
.height
== 0)
18464 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18466 it
->descent
= slice
.height
- glyph_ascent
;
18468 it
->descent
+= img
->vmargin
;
18469 if (slice
.y
+ slice
.height
== img
->height
)
18470 it
->descent
+= img
->vmargin
;
18471 it
->phys_descent
= it
->descent
;
18473 it
->pixel_width
= slice
.width
;
18475 it
->pixel_width
+= img
->hmargin
;
18476 if (slice
.x
+ slice
.width
== img
->width
)
18477 it
->pixel_width
+= img
->hmargin
;
18479 /* It's quite possible for images to have an ascent greater than
18480 their height, so don't get confused in that case. */
18481 if (it
->descent
< 0)
18484 #if 0 /* this breaks image tiling */
18485 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18486 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18487 if (face_ascent
> it
->ascent
)
18488 it
->ascent
= it
->phys_ascent
= face_ascent
;
18493 if (face
->box
!= FACE_NO_BOX
)
18495 if (face
->box_line_width
> 0)
18498 it
->ascent
+= face
->box_line_width
;
18499 if (slice
.y
+ slice
.height
== img
->height
)
18500 it
->descent
+= face
->box_line_width
;
18503 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18504 it
->pixel_width
+= abs (face
->box_line_width
);
18505 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18506 it
->pixel_width
+= abs (face
->box_line_width
);
18509 take_vertical_position_into_account (it
);
18513 struct glyph
*glyph
;
18514 enum glyph_row_area area
= it
->area
;
18516 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18517 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18519 glyph
->charpos
= CHARPOS (it
->position
);
18520 glyph
->object
= it
->object
;
18521 glyph
->pixel_width
= it
->pixel_width
;
18522 glyph
->ascent
= glyph_ascent
;
18523 glyph
->descent
= it
->descent
;
18524 glyph
->voffset
= it
->voffset
;
18525 glyph
->type
= IMAGE_GLYPH
;
18526 glyph
->multibyte_p
= it
->multibyte_p
;
18527 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18528 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18529 glyph
->overlaps_vertically_p
= 0;
18530 glyph
->padding_p
= 0;
18531 glyph
->glyph_not_available_p
= 0;
18532 glyph
->face_id
= it
->face_id
;
18533 glyph
->u
.img_id
= img
->id
;
18534 glyph
->slice
= slice
;
18535 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18536 ++it
->glyph_row
->used
[area
];
18539 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18544 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18545 of the glyph, WIDTH and HEIGHT are the width and height of the
18546 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18549 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18551 Lisp_Object object
;
18555 struct glyph
*glyph
;
18556 enum glyph_row_area area
= it
->area
;
18558 xassert (ascent
>= 0 && ascent
<= height
);
18560 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18561 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18563 glyph
->charpos
= CHARPOS (it
->position
);
18564 glyph
->object
= object
;
18565 glyph
->pixel_width
= width
;
18566 glyph
->ascent
= ascent
;
18567 glyph
->descent
= height
- ascent
;
18568 glyph
->voffset
= it
->voffset
;
18569 glyph
->type
= STRETCH_GLYPH
;
18570 glyph
->multibyte_p
= it
->multibyte_p
;
18571 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18572 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18573 glyph
->overlaps_vertically_p
= 0;
18574 glyph
->padding_p
= 0;
18575 glyph
->glyph_not_available_p
= 0;
18576 glyph
->face_id
= it
->face_id
;
18577 glyph
->u
.stretch
.ascent
= ascent
;
18578 glyph
->u
.stretch
.height
= height
;
18579 glyph
->slice
= null_glyph_slice
;
18580 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18581 ++it
->glyph_row
->used
[area
];
18584 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18588 /* Produce a stretch glyph for iterator IT. IT->object is the value
18589 of the glyph property displayed. The value must be a list
18590 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18593 1. `:width WIDTH' specifies that the space should be WIDTH *
18594 canonical char width wide. WIDTH may be an integer or floating
18597 2. `:relative-width FACTOR' specifies that the width of the stretch
18598 should be computed from the width of the first character having the
18599 `glyph' property, and should be FACTOR times that width.
18601 3. `:align-to HPOS' specifies that the space should be wide enough
18602 to reach HPOS, a value in canonical character units.
18604 Exactly one of the above pairs must be present.
18606 4. `:height HEIGHT' specifies that the height of the stretch produced
18607 should be HEIGHT, measured in canonical character units.
18609 5. `:relative-height FACTOR' specifies that the height of the
18610 stretch should be FACTOR times the height of the characters having
18611 the glyph property.
18613 Either none or exactly one of 4 or 5 must be present.
18615 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18616 of the stretch should be used for the ascent of the stretch.
18617 ASCENT must be in the range 0 <= ASCENT <= 100. */
18620 produce_stretch_glyph (it
)
18623 /* (space :width WIDTH :height HEIGHT ...) */
18624 Lisp_Object prop
, plist
;
18625 int width
= 0, height
= 0, align_to
= -1;
18626 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18629 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18630 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18632 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18634 /* List should start with `space'. */
18635 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18636 plist
= XCDR (it
->object
);
18638 /* Compute the width of the stretch. */
18639 if ((prop
= Fsafe_plist_get (plist
, QCwidth
), !NILP (prop
))
18640 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18642 /* Absolute width `:width WIDTH' specified and valid. */
18643 zero_width_ok_p
= 1;
18646 else if (prop
= Fsafe_plist_get (plist
, QCrelative_width
),
18649 /* Relative width `:relative-width FACTOR' specified and valid.
18650 Compute the width of the characters having the `glyph'
18653 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18656 if (it
->multibyte_p
)
18658 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18659 - IT_BYTEPOS (*it
));
18660 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18663 it2
.c
= *p
, it2
.len
= 1;
18665 it2
.glyph_row
= NULL
;
18666 it2
.what
= IT_CHARACTER
;
18667 x_produce_glyphs (&it2
);
18668 width
= NUMVAL (prop
) * it2
.pixel_width
;
18670 else if ((prop
= Fsafe_plist_get (plist
, QCalign_to
), !NILP (prop
))
18671 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18673 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18674 align_to
= (align_to
< 0
18676 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18677 else if (align_to
< 0)
18678 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18679 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18680 zero_width_ok_p
= 1;
18683 /* Nothing specified -> width defaults to canonical char width. */
18684 width
= FRAME_COLUMN_WIDTH (it
->f
);
18686 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18689 /* Compute height. */
18690 if ((prop
= Fsafe_plist_get (plist
, QCheight
), !NILP (prop
))
18691 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18694 zero_height_ok_p
= 1;
18696 else if (prop
= Fsafe_plist_get (plist
, QCrelative_height
),
18698 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18700 height
= FONT_HEIGHT (font
);
18702 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18705 /* Compute percentage of height used for ascent. If
18706 `:ascent ASCENT' is present and valid, use that. Otherwise,
18707 derive the ascent from the font in use. */
18708 if (prop
= Fsafe_plist_get (plist
, QCascent
),
18709 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18710 ascent
= height
* NUMVAL (prop
) / 100.0;
18711 else if (!NILP (prop
)
18712 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18713 ascent
= min (max (0, (int)tem
), height
);
18715 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18717 if (width
> 0 && height
> 0 && it
->glyph_row
)
18719 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18720 if (!STRINGP (object
))
18721 object
= it
->w
->buffer
;
18722 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18725 it
->pixel_width
= width
;
18726 it
->ascent
= it
->phys_ascent
= ascent
;
18727 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18728 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18730 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18732 if (face
->box_line_width
> 0)
18734 it
->ascent
+= face
->box_line_width
;
18735 it
->descent
+= face
->box_line_width
;
18738 if (it
->start_of_box_run_p
)
18739 it
->pixel_width
+= abs (face
->box_line_width
);
18740 if (it
->end_of_box_run_p
)
18741 it
->pixel_width
+= abs (face
->box_line_width
);
18744 take_vertical_position_into_account (it
);
18747 /* Calculate line-height and line-spacing properties.
18748 An integer value specifies explicit pixel value.
18749 A float value specifies relative value to current face height.
18750 A cons (float . face-name) specifies relative value to
18751 height of specified face font.
18753 Returns height in pixels, or nil. */
18756 calc_line_height_property (it
, prop
, font
, boff
, total
)
18762 Lisp_Object position
, val
;
18763 Lisp_Object face_name
= Qnil
;
18764 int ascent
, descent
, height
, override
;
18766 if (STRINGP (it
->object
))
18767 position
= make_number (IT_STRING_CHARPOS (*it
));
18768 else if (BUFFERP (it
->object
))
18769 position
= make_number (IT_CHARPOS (*it
));
18773 val
= Fget_char_property (position
, prop
, it
->object
);
18778 if (total
&& CONSP (val
) && EQ (XCAR (val
), Qtotal
))
18784 if (INTEGERP (val
))
18789 face_name
= XCDR (val
);
18792 else if (SYMBOLP (val
))
18798 override
= EQ (prop
, Qline_height
);
18800 if (NILP (face_name
))
18802 font
= FRAME_FONT (it
->f
);
18803 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18805 else if (EQ (face_name
, Qt
))
18813 struct font_info
*font_info
;
18815 face_id
= lookup_named_face (it
->f
, face_name
, ' ');
18817 return make_number (-1);
18819 face
= FACE_FROM_ID (it
->f
, face_id
);
18822 return make_number (-1);
18824 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18825 boff
= font_info
->baseline_offset
;
18826 if (font_info
->vertical_centering
)
18827 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18830 ascent
= FONT_BASE (font
) + boff
;
18831 descent
= FONT_DESCENT (font
) - boff
;
18835 it
->override_ascent
= ascent
;
18836 it
->override_descent
= descent
;
18837 it
->override_boff
= boff
;
18840 height
= ascent
+ descent
;
18842 height
= (int)(XFLOAT_DATA (val
) * height
);
18843 else if (INTEGERP (val
))
18844 height
*= XINT (val
);
18846 return make_number (height
);
18851 Produce glyphs/get display metrics for the display element IT is
18852 loaded with. See the description of struct display_iterator in
18853 dispextern.h for an overview of struct display_iterator. */
18856 x_produce_glyphs (it
)
18859 int extra_line_spacing
= it
->extra_line_spacing
;
18861 it
->glyph_not_available_p
= 0;
18863 if (it
->what
== IT_CHARACTER
)
18867 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18869 int font_not_found_p
;
18870 struct font_info
*font_info
;
18871 int boff
; /* baseline offset */
18872 /* We may change it->multibyte_p upon unibyte<->multibyte
18873 conversion. So, save the current value now and restore it
18876 Note: It seems that we don't have to record multibyte_p in
18877 struct glyph because the character code itself tells if or
18878 not the character is multibyte. Thus, in the future, we must
18879 consider eliminating the field `multibyte_p' in the struct
18881 int saved_multibyte_p
= it
->multibyte_p
;
18883 /* Maybe translate single-byte characters to multibyte, or the
18885 it
->char_to_display
= it
->c
;
18886 if (!ASCII_BYTE_P (it
->c
))
18888 if (unibyte_display_via_language_environment
18889 && SINGLE_BYTE_CHAR_P (it
->c
)
18891 || !NILP (Vnonascii_translation_table
)))
18893 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18894 it
->multibyte_p
= 1;
18895 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18896 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18898 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18899 && !it
->multibyte_p
)
18901 it
->multibyte_p
= 1;
18902 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18903 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18907 /* Get font to use. Encode IT->char_to_display. */
18908 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18909 &char2b
, it
->multibyte_p
, 0);
18912 /* When no suitable font found, use the default font. */
18913 font_not_found_p
= font
== NULL
;
18914 if (font_not_found_p
)
18916 font
= FRAME_FONT (it
->f
);
18917 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18922 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18923 boff
= font_info
->baseline_offset
;
18924 if (font_info
->vertical_centering
)
18925 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18928 if (it
->char_to_display
>= ' '
18929 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
18931 /* Either unibyte or ASCII. */
18936 pcm
= FRAME_RIF (it
->f
)->per_char_metric
18937 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
18939 if (it
->override_ascent
>= 0)
18941 it
->ascent
= it
->override_ascent
;
18942 it
->descent
= it
->override_descent
;
18943 boff
= it
->override_boff
;
18947 it
->ascent
= FONT_BASE (font
) + boff
;
18948 it
->descent
= FONT_DESCENT (font
) - boff
;
18953 it
->phys_ascent
= pcm
->ascent
+ boff
;
18954 it
->phys_descent
= pcm
->descent
- boff
;
18955 it
->pixel_width
= pcm
->width
;
18959 it
->glyph_not_available_p
= 1;
18960 it
->phys_ascent
= it
->ascent
;
18961 it
->phys_descent
= it
->descent
;
18962 it
->pixel_width
= FONT_WIDTH (font
);
18965 if (it
->constrain_row_ascent_descent_p
)
18967 if (it
->descent
> it
->max_descent
)
18969 it
->ascent
+= it
->descent
- it
->max_descent
;
18970 it
->descent
= it
->max_descent
;
18972 if (it
->ascent
> it
->max_ascent
)
18974 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
18975 it
->ascent
= it
->max_ascent
;
18977 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
18978 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
18979 extra_line_spacing
= 0;
18982 /* If this is a space inside a region of text with
18983 `space-width' property, change its width. */
18984 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
18986 it
->pixel_width
*= XFLOATINT (it
->space_width
);
18988 /* If face has a box, add the box thickness to the character
18989 height. If character has a box line to the left and/or
18990 right, add the box line width to the character's width. */
18991 if (face
->box
!= FACE_NO_BOX
)
18993 int thick
= face
->box_line_width
;
18997 it
->ascent
+= thick
;
18998 it
->descent
+= thick
;
19003 if (it
->start_of_box_run_p
)
19004 it
->pixel_width
+= thick
;
19005 if (it
->end_of_box_run_p
)
19006 it
->pixel_width
+= thick
;
19009 /* If face has an overline, add the height of the overline
19010 (1 pixel) and a 1 pixel margin to the character height. */
19011 if (face
->overline_p
)
19014 if (it
->constrain_row_ascent_descent_p
)
19016 if (it
->ascent
> it
->max_ascent
)
19017 it
->ascent
= it
->max_ascent
;
19018 if (it
->descent
> it
->max_descent
)
19019 it
->descent
= it
->max_descent
;
19022 take_vertical_position_into_account (it
);
19024 /* If we have to actually produce glyphs, do it. */
19029 /* Translate a space with a `space-width' property
19030 into a stretch glyph. */
19031 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19032 / FONT_HEIGHT (font
));
19033 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19034 it
->ascent
+ it
->descent
, ascent
);
19039 /* If characters with lbearing or rbearing are displayed
19040 in this line, record that fact in a flag of the
19041 glyph row. This is used to optimize X output code. */
19042 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19043 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19046 else if (it
->char_to_display
== '\n')
19048 /* A newline has no width but we need the height of the line.
19049 But if previous part of the line set a height, don't
19050 increase that height */
19052 Lisp_Object height
;
19054 it
->override_ascent
= -1;
19055 it
->pixel_width
= 0;
19058 height
= calc_line_height_property(it
, Qline_height
, font
, boff
, 0);
19060 if (it
->override_ascent
>= 0)
19062 it
->ascent
= it
->override_ascent
;
19063 it
->descent
= it
->override_descent
;
19064 boff
= it
->override_boff
;
19068 it
->ascent
= FONT_BASE (font
) + boff
;
19069 it
->descent
= FONT_DESCENT (font
) - boff
;
19072 if (EQ (height
, make_number(0)))
19074 if (it
->descent
> it
->max_descent
)
19076 it
->ascent
+= it
->descent
- it
->max_descent
;
19077 it
->descent
= it
->max_descent
;
19079 if (it
->ascent
> it
->max_ascent
)
19081 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19082 it
->ascent
= it
->max_ascent
;
19084 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19085 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19086 it
->constrain_row_ascent_descent_p
= 1;
19087 extra_line_spacing
= 0;
19091 Lisp_Object spacing
;
19094 it
->phys_ascent
= it
->ascent
;
19095 it
->phys_descent
= it
->descent
;
19097 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19098 && face
->box
!= FACE_NO_BOX
19099 && face
->box_line_width
> 0)
19101 it
->ascent
+= face
->box_line_width
;
19102 it
->descent
+= face
->box_line_width
;
19105 && XINT (height
) > it
->ascent
+ it
->descent
)
19106 it
->ascent
= XINT (height
) - it
->descent
;
19108 spacing
= calc_line_height_property(it
, Qline_spacing
, font
, boff
, &total
);
19109 if (INTEGERP (spacing
))
19111 extra_line_spacing
= XINT (spacing
);
19113 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19117 else if (it
->char_to_display
== '\t')
19119 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
19120 int x
= it
->current_x
+ it
->continuation_lines_width
;
19121 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19123 /* If the distance from the current position to the next tab
19124 stop is less than a canonical character width, use the
19125 tab stop after that. */
19126 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
19127 next_tab_x
+= tab_width
;
19129 it
->pixel_width
= next_tab_x
- x
;
19131 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19132 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19136 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19137 it
->ascent
+ it
->descent
, it
->ascent
);
19142 /* A multi-byte character. Assume that the display width of the
19143 character is the width of the character multiplied by the
19144 width of the font. */
19146 /* If we found a font, this font should give us the right
19147 metrics. If we didn't find a font, use the frame's
19148 default font and calculate the width of the character
19149 from the charset width; this is what old redisplay code
19152 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19153 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19155 if (font_not_found_p
|| !pcm
)
19157 int charset
= CHAR_CHARSET (it
->char_to_display
);
19159 it
->glyph_not_available_p
= 1;
19160 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19161 * CHARSET_WIDTH (charset
));
19162 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19163 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19167 it
->pixel_width
= pcm
->width
;
19168 it
->phys_ascent
= pcm
->ascent
+ boff
;
19169 it
->phys_descent
= pcm
->descent
- boff
;
19171 && (pcm
->lbearing
< 0
19172 || pcm
->rbearing
> pcm
->width
))
19173 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19176 it
->ascent
= FONT_BASE (font
) + boff
;
19177 it
->descent
= FONT_DESCENT (font
) - boff
;
19178 if (face
->box
!= FACE_NO_BOX
)
19180 int thick
= face
->box_line_width
;
19184 it
->ascent
+= thick
;
19185 it
->descent
+= thick
;
19190 if (it
->start_of_box_run_p
)
19191 it
->pixel_width
+= thick
;
19192 if (it
->end_of_box_run_p
)
19193 it
->pixel_width
+= thick
;
19196 /* If face has an overline, add the height of the overline
19197 (1 pixel) and a 1 pixel margin to the character height. */
19198 if (face
->overline_p
)
19201 take_vertical_position_into_account (it
);
19206 it
->multibyte_p
= saved_multibyte_p
;
19208 else if (it
->what
== IT_COMPOSITION
)
19210 /* Note: A composition is represented as one glyph in the
19211 glyph matrix. There are no padding glyphs. */
19214 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19216 int font_not_found_p
;
19217 struct font_info
*font_info
;
19218 int boff
; /* baseline offset */
19219 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19221 /* Maybe translate single-byte characters to multibyte. */
19222 it
->char_to_display
= it
->c
;
19223 if (unibyte_display_via_language_environment
19224 && SINGLE_BYTE_CHAR_P (it
->c
)
19227 && !NILP (Vnonascii_translation_table
))))
19229 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19232 /* Get face and font to use. Encode IT->char_to_display. */
19233 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19234 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19235 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19236 &char2b
, it
->multibyte_p
, 0);
19239 /* When no suitable font found, use the default font. */
19240 font_not_found_p
= font
== NULL
;
19241 if (font_not_found_p
)
19243 font
= FRAME_FONT (it
->f
);
19244 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19249 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19250 boff
= font_info
->baseline_offset
;
19251 if (font_info
->vertical_centering
)
19252 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19255 /* There are no padding glyphs, so there is only one glyph to
19256 produce for the composition. Important is that pixel_width,
19257 ascent and descent are the values of what is drawn by
19258 draw_glyphs (i.e. the values of the overall glyphs composed). */
19261 /* If we have not yet calculated pixel size data of glyphs of
19262 the composition for the current face font, calculate them
19263 now. Theoretically, we have to check all fonts for the
19264 glyphs, but that requires much time and memory space. So,
19265 here we check only the font of the first glyph. This leads
19266 to incorrect display very rarely, and C-l (recenter) can
19267 correct the display anyway. */
19268 if (cmp
->font
!= (void *) font
)
19270 /* Ascent and descent of the font of the first character of
19271 this composition (adjusted by baseline offset). Ascent
19272 and descent of overall glyphs should not be less than
19273 them respectively. */
19274 int font_ascent
= FONT_BASE (font
) + boff
;
19275 int font_descent
= FONT_DESCENT (font
) - boff
;
19276 /* Bounding box of the overall glyphs. */
19277 int leftmost
, rightmost
, lowest
, highest
;
19278 int i
, width
, ascent
, descent
;
19280 cmp
->font
= (void *) font
;
19282 /* Initialize the bounding box. */
19284 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19285 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19287 width
= pcm
->width
;
19288 ascent
= pcm
->ascent
;
19289 descent
= pcm
->descent
;
19293 width
= FONT_WIDTH (font
);
19294 ascent
= FONT_BASE (font
);
19295 descent
= FONT_DESCENT (font
);
19299 lowest
= - descent
+ boff
;
19300 highest
= ascent
+ boff
;
19304 && font_info
->default_ascent
19305 && CHAR_TABLE_P (Vuse_default_ascent
)
19306 && !NILP (Faref (Vuse_default_ascent
,
19307 make_number (it
->char_to_display
))))
19308 highest
= font_info
->default_ascent
+ boff
;
19310 /* Draw the first glyph at the normal position. It may be
19311 shifted to right later if some other glyphs are drawn at
19313 cmp
->offsets
[0] = 0;
19314 cmp
->offsets
[1] = boff
;
19316 /* Set cmp->offsets for the remaining glyphs. */
19317 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19319 int left
, right
, btm
, top
;
19320 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19321 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19323 face
= FACE_FROM_ID (it
->f
, face_id
);
19324 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19325 &char2b
, it
->multibyte_p
, 0);
19329 font
= FRAME_FONT (it
->f
);
19330 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19336 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19337 boff
= font_info
->baseline_offset
;
19338 if (font_info
->vertical_centering
)
19339 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19343 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
19344 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19346 width
= pcm
->width
;
19347 ascent
= pcm
->ascent
;
19348 descent
= pcm
->descent
;
19352 width
= FONT_WIDTH (font
);
19357 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19359 /* Relative composition with or without
19360 alternate chars. */
19361 left
= (leftmost
+ rightmost
- width
) / 2;
19362 btm
= - descent
+ boff
;
19363 if (font_info
&& font_info
->relative_compose
19364 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19365 || NILP (Faref (Vignore_relative_composition
,
19366 make_number (ch
)))))
19369 if (- descent
>= font_info
->relative_compose
)
19370 /* One extra pixel between two glyphs. */
19372 else if (ascent
<= 0)
19373 /* One extra pixel between two glyphs. */
19374 btm
= lowest
- 1 - ascent
- descent
;
19379 /* A composition rule is specified by an integer
19380 value that encodes global and new reference
19381 points (GREF and NREF). GREF and NREF are
19382 specified by numbers as below:
19384 0---1---2 -- ascent
19388 9--10--11 -- center
19390 ---3---4---5--- baseline
19392 6---7---8 -- descent
19394 int rule
= COMPOSITION_RULE (cmp
, i
);
19395 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19397 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19398 grefx
= gref
% 3, nrefx
= nref
% 3;
19399 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19402 + grefx
* (rightmost
- leftmost
) / 2
19403 - nrefx
* width
/ 2);
19404 btm
= ((grefy
== 0 ? highest
19406 : grefy
== 2 ? lowest
19407 : (highest
+ lowest
) / 2)
19408 - (nrefy
== 0 ? ascent
+ descent
19409 : nrefy
== 1 ? descent
- boff
19411 : (ascent
+ descent
) / 2));
19414 cmp
->offsets
[i
* 2] = left
;
19415 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19417 /* Update the bounding box of the overall glyphs. */
19418 right
= left
+ width
;
19419 top
= btm
+ descent
+ ascent
;
19420 if (left
< leftmost
)
19422 if (right
> rightmost
)
19430 /* If there are glyphs whose x-offsets are negative,
19431 shift all glyphs to the right and make all x-offsets
19435 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19436 cmp
->offsets
[i
* 2] -= leftmost
;
19437 rightmost
-= leftmost
;
19440 cmp
->pixel_width
= rightmost
;
19441 cmp
->ascent
= highest
;
19442 cmp
->descent
= - lowest
;
19443 if (cmp
->ascent
< font_ascent
)
19444 cmp
->ascent
= font_ascent
;
19445 if (cmp
->descent
< font_descent
)
19446 cmp
->descent
= font_descent
;
19449 it
->pixel_width
= cmp
->pixel_width
;
19450 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19451 it
->descent
= it
->phys_descent
= cmp
->descent
;
19453 if (face
->box
!= FACE_NO_BOX
)
19455 int thick
= face
->box_line_width
;
19459 it
->ascent
+= thick
;
19460 it
->descent
+= thick
;
19465 if (it
->start_of_box_run_p
)
19466 it
->pixel_width
+= thick
;
19467 if (it
->end_of_box_run_p
)
19468 it
->pixel_width
+= thick
;
19471 /* If face has an overline, add the height of the overline
19472 (1 pixel) and a 1 pixel margin to the character height. */
19473 if (face
->overline_p
)
19476 take_vertical_position_into_account (it
);
19479 append_composite_glyph (it
);
19481 else if (it
->what
== IT_IMAGE
)
19482 produce_image_glyph (it
);
19483 else if (it
->what
== IT_STRETCH
)
19484 produce_stretch_glyph (it
);
19486 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19487 because this isn't true for images with `:ascent 100'. */
19488 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19489 if (it
->area
== TEXT_AREA
)
19490 it
->current_x
+= it
->pixel_width
;
19492 if (extra_line_spacing
> 0)
19494 it
->descent
+= extra_line_spacing
;
19495 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19496 it
->max_extra_line_spacing
= extra_line_spacing
;
19499 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19500 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19501 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19502 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19506 Output LEN glyphs starting at START at the nominal cursor position.
19507 Advance the nominal cursor over the text. The global variable
19508 updated_window contains the window being updated, updated_row is
19509 the glyph row being updated, and updated_area is the area of that
19510 row being updated. */
19513 x_write_glyphs (start
, len
)
19514 struct glyph
*start
;
19519 xassert (updated_window
&& updated_row
);
19522 /* Write glyphs. */
19524 hpos
= start
- updated_row
->glyphs
[updated_area
];
19525 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19526 updated_row
, updated_area
,
19528 DRAW_NORMAL_TEXT
, 0);
19530 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19531 if (updated_area
== TEXT_AREA
19532 && updated_window
->phys_cursor_on_p
19533 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19534 && updated_window
->phys_cursor
.hpos
>= hpos
19535 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19536 updated_window
->phys_cursor_on_p
= 0;
19540 /* Advance the output cursor. */
19541 output_cursor
.hpos
+= len
;
19542 output_cursor
.x
= x
;
19547 Insert LEN glyphs from START at the nominal cursor position. */
19550 x_insert_glyphs (start
, len
)
19551 struct glyph
*start
;
19556 int line_height
, shift_by_width
, shifted_region_width
;
19557 struct glyph_row
*row
;
19558 struct glyph
*glyph
;
19559 int frame_x
, frame_y
, hpos
;
19561 xassert (updated_window
&& updated_row
);
19563 w
= updated_window
;
19564 f
= XFRAME (WINDOW_FRAME (w
));
19566 /* Get the height of the line we are in. */
19568 line_height
= row
->height
;
19570 /* Get the width of the glyphs to insert. */
19571 shift_by_width
= 0;
19572 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19573 shift_by_width
+= glyph
->pixel_width
;
19575 /* Get the width of the region to shift right. */
19576 shifted_region_width
= (window_box_width (w
, updated_area
)
19581 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19582 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19584 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19585 line_height
, shift_by_width
);
19587 /* Write the glyphs. */
19588 hpos
= start
- row
->glyphs
[updated_area
];
19589 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19591 DRAW_NORMAL_TEXT
, 0);
19593 /* Advance the output cursor. */
19594 output_cursor
.hpos
+= len
;
19595 output_cursor
.x
+= shift_by_width
;
19601 Erase the current text line from the nominal cursor position
19602 (inclusive) to pixel column TO_X (exclusive). The idea is that
19603 everything from TO_X onward is already erased.
19605 TO_X is a pixel position relative to updated_area of
19606 updated_window. TO_X == -1 means clear to the end of this area. */
19609 x_clear_end_of_line (to_x
)
19613 struct window
*w
= updated_window
;
19614 int max_x
, min_y
, max_y
;
19615 int from_x
, from_y
, to_y
;
19617 xassert (updated_window
&& updated_row
);
19618 f
= XFRAME (w
->frame
);
19620 if (updated_row
->full_width_p
)
19621 max_x
= WINDOW_TOTAL_WIDTH (w
);
19623 max_x
= window_box_width (w
, updated_area
);
19624 max_y
= window_text_bottom_y (w
);
19626 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19627 of window. For TO_X > 0, truncate to end of drawing area. */
19633 to_x
= min (to_x
, max_x
);
19635 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19637 /* Notice if the cursor will be cleared by this operation. */
19638 if (!updated_row
->full_width_p
)
19639 notice_overwritten_cursor (w
, updated_area
,
19640 output_cursor
.x
, -1,
19642 MATRIX_ROW_BOTTOM_Y (updated_row
));
19644 from_x
= output_cursor
.x
;
19646 /* Translate to frame coordinates. */
19647 if (updated_row
->full_width_p
)
19649 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19650 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19654 int area_left
= window_box_left (w
, updated_area
);
19655 from_x
+= area_left
;
19659 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19660 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19661 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19663 /* Prevent inadvertently clearing to end of the X window. */
19664 if (to_x
> from_x
&& to_y
> from_y
)
19667 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
19668 to_x
- from_x
, to_y
- from_y
);
19673 #endif /* HAVE_WINDOW_SYSTEM */
19677 /***********************************************************************
19679 ***********************************************************************/
19681 /* Value is the internal representation of the specified cursor type
19682 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19683 of the bar cursor. */
19685 static enum text_cursor_kinds
19686 get_specified_cursor_type (arg
, width
)
19690 enum text_cursor_kinds type
;
19695 if (EQ (arg
, Qbox
))
19696 return FILLED_BOX_CURSOR
;
19698 if (EQ (arg
, Qhollow
))
19699 return HOLLOW_BOX_CURSOR
;
19701 if (EQ (arg
, Qbar
))
19708 && EQ (XCAR (arg
), Qbar
)
19709 && INTEGERP (XCDR (arg
))
19710 && XINT (XCDR (arg
)) >= 0)
19712 *width
= XINT (XCDR (arg
));
19716 if (EQ (arg
, Qhbar
))
19719 return HBAR_CURSOR
;
19723 && EQ (XCAR (arg
), Qhbar
)
19724 && INTEGERP (XCDR (arg
))
19725 && XINT (XCDR (arg
)) >= 0)
19727 *width
= XINT (XCDR (arg
));
19728 return HBAR_CURSOR
;
19731 /* Treat anything unknown as "hollow box cursor".
19732 It was bad to signal an error; people have trouble fixing
19733 .Xdefaults with Emacs, when it has something bad in it. */
19734 type
= HOLLOW_BOX_CURSOR
;
19739 /* Set the default cursor types for specified frame. */
19741 set_frame_cursor_types (f
, arg
)
19748 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19749 FRAME_CURSOR_WIDTH (f
) = width
;
19751 /* By default, set up the blink-off state depending on the on-state. */
19753 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19756 FRAME_BLINK_OFF_CURSOR (f
)
19757 = get_specified_cursor_type (XCDR (tem
), &width
);
19758 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19761 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19765 /* Return the cursor we want to be displayed in window W. Return
19766 width of bar/hbar cursor through WIDTH arg. Return with
19767 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19768 (i.e. if the `system caret' should track this cursor).
19770 In a mini-buffer window, we want the cursor only to appear if we
19771 are reading input from this window. For the selected window, we
19772 want the cursor type given by the frame parameter or buffer local
19773 setting of cursor-type. If explicitly marked off, draw no cursor.
19774 In all other cases, we want a hollow box cursor. */
19776 static enum text_cursor_kinds
19777 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19779 struct glyph
*glyph
;
19781 int *active_cursor
;
19783 struct frame
*f
= XFRAME (w
->frame
);
19784 struct buffer
*b
= XBUFFER (w
->buffer
);
19785 int cursor_type
= DEFAULT_CURSOR
;
19786 Lisp_Object alt_cursor
;
19787 int non_selected
= 0;
19789 *active_cursor
= 1;
19792 if (cursor_in_echo_area
19793 && FRAME_HAS_MINIBUF_P (f
)
19794 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19796 if (w
== XWINDOW (echo_area_window
))
19798 *width
= FRAME_CURSOR_WIDTH (f
);
19799 return FRAME_DESIRED_CURSOR (f
);
19802 *active_cursor
= 0;
19806 /* Nonselected window or nonselected frame. */
19807 else if (w
!= XWINDOW (f
->selected_window
)
19808 #ifdef HAVE_WINDOW_SYSTEM
19809 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19813 *active_cursor
= 0;
19815 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19821 /* Never display a cursor in a window in which cursor-type is nil. */
19822 if (NILP (b
->cursor_type
))
19825 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19828 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19829 return get_specified_cursor_type (alt_cursor
, width
);
19832 /* Get the normal cursor type for this window. */
19833 if (EQ (b
->cursor_type
, Qt
))
19835 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19836 *width
= FRAME_CURSOR_WIDTH (f
);
19839 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19841 /* Use normal cursor if not blinked off. */
19842 if (!w
->cursor_off_p
)
19844 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19845 if (cursor_type
== FILLED_BOX_CURSOR
)
19846 cursor_type
= HOLLOW_BOX_CURSOR
;
19848 return cursor_type
;
19851 /* Cursor is blinked off, so determine how to "toggle" it. */
19853 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19854 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19855 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19857 /* Then see if frame has specified a specific blink off cursor type. */
19858 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19860 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19861 return FRAME_BLINK_OFF_CURSOR (f
);
19865 /* Some people liked having a permanently visible blinking cursor,
19866 while others had very strong opinions against it. So it was
19867 decided to remove it. KFS 2003-09-03 */
19869 /* Finally perform built-in cursor blinking:
19870 filled box <-> hollow box
19871 wide [h]bar <-> narrow [h]bar
19872 narrow [h]bar <-> no cursor
19873 other type <-> no cursor */
19875 if (cursor_type
== FILLED_BOX_CURSOR
)
19876 return HOLLOW_BOX_CURSOR
;
19878 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19881 return cursor_type
;
19889 #ifdef HAVE_WINDOW_SYSTEM
19891 /* Notice when the text cursor of window W has been completely
19892 overwritten by a drawing operation that outputs glyphs in AREA
19893 starting at X0 and ending at X1 in the line starting at Y0 and
19894 ending at Y1. X coordinates are area-relative. X1 < 0 means all
19895 the rest of the line after X0 has been written. Y coordinates
19896 are window-relative. */
19899 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
19901 enum glyph_row_area area
;
19902 int x0
, y0
, x1
, y1
;
19904 int cx0
, cx1
, cy0
, cy1
;
19905 struct glyph_row
*row
;
19907 if (!w
->phys_cursor_on_p
)
19909 if (area
!= TEXT_AREA
)
19912 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
19913 if (!row
->displays_text_p
)
19916 if (row
->cursor_in_fringe_p
)
19918 row
->cursor_in_fringe_p
= 0;
19919 draw_fringe_bitmap (w
, row
, 0);
19920 w
->phys_cursor_on_p
= 0;
19924 cx0
= w
->phys_cursor
.x
;
19925 cx1
= cx0
+ w
->phys_cursor_width
;
19926 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
19929 /* The cursor image will be completely removed from the
19930 screen if the output area intersects the cursor area in
19931 y-direction. When we draw in [y0 y1[, and some part of
19932 the cursor is at y < y0, that part must have been drawn
19933 before. When scrolling, the cursor is erased before
19934 actually scrolling, so we don't come here. When not
19935 scrolling, the rows above the old cursor row must have
19936 changed, and in this case these rows must have written
19937 over the cursor image.
19939 Likewise if part of the cursor is below y1, with the
19940 exception of the cursor being in the first blank row at
19941 the buffer and window end because update_text_area
19942 doesn't draw that row. (Except when it does, but
19943 that's handled in update_text_area.) */
19945 cy0
= w
->phys_cursor
.y
;
19946 cy1
= cy0
+ w
->phys_cursor_height
;
19947 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
19950 w
->phys_cursor_on_p
= 0;
19953 #endif /* HAVE_WINDOW_SYSTEM */
19956 /************************************************************************
19958 ************************************************************************/
19960 #ifdef HAVE_WINDOW_SYSTEM
19963 Fix the display of area AREA of overlapping row ROW in window W. */
19966 x_fix_overlapping_area (w
, row
, area
)
19968 struct glyph_row
*row
;
19969 enum glyph_row_area area
;
19976 for (i
= 0; i
< row
->used
[area
];)
19978 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
19980 int start
= i
, start_x
= x
;
19984 x
+= row
->glyphs
[area
][i
].pixel_width
;
19987 while (i
< row
->used
[area
]
19988 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
19990 draw_glyphs (w
, start_x
, row
, area
,
19992 DRAW_NORMAL_TEXT
, 1);
19996 x
+= row
->glyphs
[area
][i
].pixel_width
;
20006 Draw the cursor glyph of window W in glyph row ROW. See the
20007 comment of draw_glyphs for the meaning of HL. */
20010 draw_phys_cursor_glyph (w
, row
, hl
)
20012 struct glyph_row
*row
;
20013 enum draw_glyphs_face hl
;
20015 /* If cursor hpos is out of bounds, don't draw garbage. This can
20016 happen in mini-buffer windows when switching between echo area
20017 glyphs and mini-buffer. */
20018 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20020 int on_p
= w
->phys_cursor_on_p
;
20022 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20023 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20025 w
->phys_cursor_on_p
= on_p
;
20027 if (hl
== DRAW_CURSOR
)
20028 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20029 /* When we erase the cursor, and ROW is overlapped by other
20030 rows, make sure that these overlapping parts of other rows
20032 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20034 if (row
> w
->current_matrix
->rows
20035 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20036 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20038 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20039 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20040 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20047 Erase the image of a cursor of window W from the screen. */
20050 erase_phys_cursor (w
)
20053 struct frame
*f
= XFRAME (w
->frame
);
20054 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20055 int hpos
= w
->phys_cursor
.hpos
;
20056 int vpos
= w
->phys_cursor
.vpos
;
20057 int mouse_face_here_p
= 0;
20058 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20059 struct glyph_row
*cursor_row
;
20060 struct glyph
*cursor_glyph
;
20061 enum draw_glyphs_face hl
;
20063 /* No cursor displayed or row invalidated => nothing to do on the
20065 if (w
->phys_cursor_type
== NO_CURSOR
)
20066 goto mark_cursor_off
;
20068 /* VPOS >= active_glyphs->nrows means that window has been resized.
20069 Don't bother to erase the cursor. */
20070 if (vpos
>= active_glyphs
->nrows
)
20071 goto mark_cursor_off
;
20073 /* If row containing cursor is marked invalid, there is nothing we
20075 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20076 if (!cursor_row
->enabled_p
)
20077 goto mark_cursor_off
;
20079 /* If line spacing is > 0, old cursor may only be partially visible in
20080 window after split-window. So adjust visible height. */
20081 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20082 window_text_bottom_y (w
) - cursor_row
->y
);
20084 /* If row is completely invisible, don't attempt to delete a cursor which
20085 isn't there. This can happen if cursor is at top of a window, and
20086 we switch to a buffer with a header line in that window. */
20087 if (cursor_row
->visible_height
<= 0)
20088 goto mark_cursor_off
;
20090 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20091 if (cursor_row
->cursor_in_fringe_p
)
20093 cursor_row
->cursor_in_fringe_p
= 0;
20094 draw_fringe_bitmap (w
, cursor_row
, 0);
20095 goto mark_cursor_off
;
20098 /* This can happen when the new row is shorter than the old one.
20099 In this case, either draw_glyphs or clear_end_of_line
20100 should have cleared the cursor. Note that we wouldn't be
20101 able to erase the cursor in this case because we don't have a
20102 cursor glyph at hand. */
20103 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20104 goto mark_cursor_off
;
20106 /* If the cursor is in the mouse face area, redisplay that when
20107 we clear the cursor. */
20108 if (! NILP (dpyinfo
->mouse_face_window
)
20109 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20110 && (vpos
> dpyinfo
->mouse_face_beg_row
20111 || (vpos
== dpyinfo
->mouse_face_beg_row
20112 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20113 && (vpos
< dpyinfo
->mouse_face_end_row
20114 || (vpos
== dpyinfo
->mouse_face_end_row
20115 && hpos
< dpyinfo
->mouse_face_end_col
))
20116 /* Don't redraw the cursor's spot in mouse face if it is at the
20117 end of a line (on a newline). The cursor appears there, but
20118 mouse highlighting does not. */
20119 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20120 mouse_face_here_p
= 1;
20122 /* Maybe clear the display under the cursor. */
20123 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20126 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20129 cursor_glyph
= get_phys_cursor_glyph (w
);
20130 if (cursor_glyph
== NULL
)
20131 goto mark_cursor_off
;
20133 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20134 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20135 width
= min (cursor_glyph
->pixel_width
,
20136 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20138 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20141 /* Erase the cursor by redrawing the character underneath it. */
20142 if (mouse_face_here_p
)
20143 hl
= DRAW_MOUSE_FACE
;
20145 hl
= DRAW_NORMAL_TEXT
;
20146 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20149 w
->phys_cursor_on_p
= 0;
20150 w
->phys_cursor_type
= NO_CURSOR
;
20155 Display or clear cursor of window W. If ON is zero, clear the
20156 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20157 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20160 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20162 int on
, hpos
, vpos
, x
, y
;
20164 struct frame
*f
= XFRAME (w
->frame
);
20165 int new_cursor_type
;
20166 int new_cursor_width
;
20168 struct glyph_row
*glyph_row
;
20169 struct glyph
*glyph
;
20171 /* This is pointless on invisible frames, and dangerous on garbaged
20172 windows and frames; in the latter case, the frame or window may
20173 be in the midst of changing its size, and x and y may be off the
20175 if (! FRAME_VISIBLE_P (f
)
20176 || FRAME_GARBAGED_P (f
)
20177 || vpos
>= w
->current_matrix
->nrows
20178 || hpos
>= w
->current_matrix
->matrix_w
)
20181 /* If cursor is off and we want it off, return quickly. */
20182 if (!on
&& !w
->phys_cursor_on_p
)
20185 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20186 /* If cursor row is not enabled, we don't really know where to
20187 display the cursor. */
20188 if (!glyph_row
->enabled_p
)
20190 w
->phys_cursor_on_p
= 0;
20195 if (!glyph_row
->exact_window_width_line_p
20196 || hpos
< glyph_row
->used
[TEXT_AREA
])
20197 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20199 xassert (interrupt_input_blocked
);
20201 /* Set new_cursor_type to the cursor we want to be displayed. */
20202 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20203 &new_cursor_width
, &active_cursor
);
20205 /* If cursor is currently being shown and we don't want it to be or
20206 it is in the wrong place, or the cursor type is not what we want,
20208 if (w
->phys_cursor_on_p
20210 || w
->phys_cursor
.x
!= x
20211 || w
->phys_cursor
.y
!= y
20212 || new_cursor_type
!= w
->phys_cursor_type
20213 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20214 && new_cursor_width
!= w
->phys_cursor_width
)))
20215 erase_phys_cursor (w
);
20217 /* Don't check phys_cursor_on_p here because that flag is only set
20218 to zero in some cases where we know that the cursor has been
20219 completely erased, to avoid the extra work of erasing the cursor
20220 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20221 still not be visible, or it has only been partly erased. */
20224 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20225 w
->phys_cursor_height
= glyph_row
->height
;
20227 /* Set phys_cursor_.* before x_draw_.* is called because some
20228 of them may need the information. */
20229 w
->phys_cursor
.x
= x
;
20230 w
->phys_cursor
.y
= glyph_row
->y
;
20231 w
->phys_cursor
.hpos
= hpos
;
20232 w
->phys_cursor
.vpos
= vpos
;
20235 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
20236 new_cursor_type
, new_cursor_width
,
20237 on
, active_cursor
);
20241 /* Switch the display of W's cursor on or off, according to the value
20245 update_window_cursor (w
, on
)
20249 /* Don't update cursor in windows whose frame is in the process
20250 of being deleted. */
20251 if (w
->current_matrix
)
20254 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20255 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20261 /* Call update_window_cursor with parameter ON_P on all leaf windows
20262 in the window tree rooted at W. */
20265 update_cursor_in_window_tree (w
, on_p
)
20271 if (!NILP (w
->hchild
))
20272 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20273 else if (!NILP (w
->vchild
))
20274 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20276 update_window_cursor (w
, on_p
);
20278 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20284 Display the cursor on window W, or clear it, according to ON_P.
20285 Don't change the cursor's position. */
20288 x_update_cursor (f
, on_p
)
20292 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20297 Clear the cursor of window W to background color, and mark the
20298 cursor as not shown. This is used when the text where the cursor
20299 is is about to be rewritten. */
20305 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20306 update_window_cursor (w
, 0);
20311 Display the active region described by mouse_face_* according to DRAW. */
20314 show_mouse_face (dpyinfo
, draw
)
20315 Display_Info
*dpyinfo
;
20316 enum draw_glyphs_face draw
;
20318 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20319 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20321 if (/* If window is in the process of being destroyed, don't bother
20323 w
->current_matrix
!= NULL
20324 /* Don't update mouse highlight if hidden */
20325 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20326 /* Recognize when we are called to operate on rows that don't exist
20327 anymore. This can happen when a window is split. */
20328 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20330 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20331 struct glyph_row
*row
, *first
, *last
;
20333 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20334 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20336 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20338 int start_hpos
, end_hpos
, start_x
;
20340 /* For all but the first row, the highlight starts at column 0. */
20343 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20344 start_x
= dpyinfo
->mouse_face_beg_x
;
20353 end_hpos
= dpyinfo
->mouse_face_end_col
;
20355 end_hpos
= row
->used
[TEXT_AREA
];
20357 if (end_hpos
> start_hpos
)
20359 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20360 start_hpos
, end_hpos
,
20364 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20368 /* When we've written over the cursor, arrange for it to
20369 be displayed again. */
20370 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20373 display_and_set_cursor (w
, 1,
20374 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20375 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20380 /* Change the mouse cursor. */
20381 if (draw
== DRAW_NORMAL_TEXT
)
20382 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20383 else if (draw
== DRAW_MOUSE_FACE
)
20384 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20386 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20390 Clear out the mouse-highlighted active region.
20391 Redraw it un-highlighted first. Value is non-zero if mouse
20392 face was actually drawn unhighlighted. */
20395 clear_mouse_face (dpyinfo
)
20396 Display_Info
*dpyinfo
;
20400 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20402 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20406 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20407 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20408 dpyinfo
->mouse_face_window
= Qnil
;
20409 dpyinfo
->mouse_face_overlay
= Qnil
;
20415 Non-zero if physical cursor of window W is within mouse face. */
20418 cursor_in_mouse_face_p (w
)
20421 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20422 int in_mouse_face
= 0;
20424 if (WINDOWP (dpyinfo
->mouse_face_window
)
20425 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20427 int hpos
= w
->phys_cursor
.hpos
;
20428 int vpos
= w
->phys_cursor
.vpos
;
20430 if (vpos
>= dpyinfo
->mouse_face_beg_row
20431 && vpos
<= dpyinfo
->mouse_face_end_row
20432 && (vpos
> dpyinfo
->mouse_face_beg_row
20433 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20434 && (vpos
< dpyinfo
->mouse_face_end_row
20435 || hpos
< dpyinfo
->mouse_face_end_col
20436 || dpyinfo
->mouse_face_past_end
))
20440 return in_mouse_face
;
20446 /* Find the glyph matrix position of buffer position CHARPOS in window
20447 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20448 current glyphs must be up to date. If CHARPOS is above window
20449 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20450 of last line in W. In the row containing CHARPOS, stop before glyphs
20451 having STOP as object. */
20453 #if 1 /* This is a version of fast_find_position that's more correct
20454 in the presence of hscrolling, for example. I didn't install
20455 it right away because the problem fixed is minor, it failed
20456 in 20.x as well, and I think it's too risky to install
20457 so near the release of 21.1. 2001-09-25 gerd. */
20460 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20463 int *hpos
, *vpos
, *x
, *y
;
20466 struct glyph_row
*row
, *first
;
20467 struct glyph
*glyph
, *end
;
20470 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20471 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20476 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20480 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20483 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20489 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20491 glyph
= row
->glyphs
[TEXT_AREA
];
20492 end
= glyph
+ row
->used
[TEXT_AREA
];
20494 /* Skip over glyphs not having an object at the start of the row.
20495 These are special glyphs like truncation marks on terminal
20497 if (row
->displays_text_p
)
20499 && INTEGERP (glyph
->object
)
20500 && !EQ (stop
, glyph
->object
)
20501 && glyph
->charpos
< 0)
20503 *x
+= glyph
->pixel_width
;
20508 && !INTEGERP (glyph
->object
)
20509 && !EQ (stop
, glyph
->object
)
20510 && (!BUFFERP (glyph
->object
)
20511 || glyph
->charpos
< charpos
))
20513 *x
+= glyph
->pixel_width
;
20517 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20524 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20527 int *hpos
, *vpos
, *x
, *y
;
20532 int maybe_next_line_p
= 0;
20533 int line_start_position
;
20534 int yb
= window_text_bottom_y (w
);
20535 struct glyph_row
*row
, *best_row
;
20536 int row_vpos
, best_row_vpos
;
20539 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20540 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20542 while (row
->y
< yb
)
20544 if (row
->used
[TEXT_AREA
])
20545 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20547 line_start_position
= 0;
20549 if (line_start_position
> pos
)
20551 /* If the position sought is the end of the buffer,
20552 don't include the blank lines at the bottom of the window. */
20553 else if (line_start_position
== pos
20554 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20556 maybe_next_line_p
= 1;
20559 else if (line_start_position
> 0)
20562 best_row_vpos
= row_vpos
;
20565 if (row
->y
+ row
->height
>= yb
)
20572 /* Find the right column within BEST_ROW. */
20574 current_x
= best_row
->x
;
20575 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20577 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20578 int charpos
= glyph
->charpos
;
20580 if (BUFFERP (glyph
->object
))
20582 if (charpos
== pos
)
20585 *vpos
= best_row_vpos
;
20590 else if (charpos
> pos
)
20593 else if (EQ (glyph
->object
, stop
))
20598 current_x
+= glyph
->pixel_width
;
20601 /* If we're looking for the end of the buffer,
20602 and we didn't find it in the line we scanned,
20603 use the start of the following line. */
20604 if (maybe_next_line_p
)
20609 current_x
= best_row
->x
;
20612 *vpos
= best_row_vpos
;
20613 *hpos
= lastcol
+ 1;
20622 /* Find the position of the glyph for position POS in OBJECT in
20623 window W's current matrix, and return in *X, *Y the pixel
20624 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20626 RIGHT_P non-zero means return the position of the right edge of the
20627 glyph, RIGHT_P zero means return the left edge position.
20629 If no glyph for POS exists in the matrix, return the position of
20630 the glyph with the next smaller position that is in the matrix, if
20631 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20632 exists in the matrix, return the position of the glyph with the
20633 next larger position in OBJECT.
20635 Value is non-zero if a glyph was found. */
20638 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20641 Lisp_Object object
;
20642 int *hpos
, *vpos
, *x
, *y
;
20645 int yb
= window_text_bottom_y (w
);
20646 struct glyph_row
*r
;
20647 struct glyph
*best_glyph
= NULL
;
20648 struct glyph_row
*best_row
= NULL
;
20651 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20652 r
->enabled_p
&& r
->y
< yb
;
20655 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20656 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20659 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20660 if (EQ (g
->object
, object
))
20662 if (g
->charpos
== pos
)
20669 else if (best_glyph
== NULL
20670 || ((abs (g
->charpos
- pos
)
20671 < abs (best_glyph
->charpos
- pos
))
20674 : g
->charpos
> pos
)))
20688 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20692 *x
+= best_glyph
->pixel_width
;
20697 *vpos
= best_row
- w
->current_matrix
->rows
;
20700 return best_glyph
!= NULL
;
20704 /* See if position X, Y is within a hot-spot of an image. */
20707 on_hot_spot_p (hot_spot
, x
, y
)
20708 Lisp_Object hot_spot
;
20711 if (!CONSP (hot_spot
))
20714 if (EQ (XCAR (hot_spot
), Qrect
))
20716 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20717 Lisp_Object rect
= XCDR (hot_spot
);
20721 if (!CONSP (XCAR (rect
)))
20723 if (!CONSP (XCDR (rect
)))
20725 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20727 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20729 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20731 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20735 else if (EQ (XCAR (hot_spot
), Qcircle
))
20737 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20738 Lisp_Object circ
= XCDR (hot_spot
);
20739 Lisp_Object lr
, lx0
, ly0
;
20741 && CONSP (XCAR (circ
))
20742 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20743 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20744 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20746 double r
= XFLOATINT (lr
);
20747 double dx
= XINT (lx0
) - x
;
20748 double dy
= XINT (ly0
) - y
;
20749 return (dx
* dx
+ dy
* dy
<= r
* r
);
20752 else if (EQ (XCAR (hot_spot
), Qpoly
))
20754 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20755 if (VECTORP (XCDR (hot_spot
)))
20757 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20758 Lisp_Object
*poly
= v
->contents
;
20762 Lisp_Object lx
, ly
;
20765 /* Need an even number of coordinates, and at least 3 edges. */
20766 if (n
< 6 || n
& 1)
20769 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20770 If count is odd, we are inside polygon. Pixels on edges
20771 may or may not be included depending on actual geometry of the
20773 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20774 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20776 x0
= XINT (lx
), y0
= XINT (ly
);
20777 for (i
= 0; i
< n
; i
+= 2)
20779 int x1
= x0
, y1
= y0
;
20780 if ((lx
= poly
[i
], !INTEGERP (lx
))
20781 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20783 x0
= XINT (lx
), y0
= XINT (ly
);
20785 /* Does this segment cross the X line? */
20793 if (y
> y0
&& y
> y1
)
20795 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20805 find_hot_spot (map
, x
, y
)
20809 while (CONSP (map
))
20811 if (CONSP (XCAR (map
))
20812 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20820 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20822 doc
: /* Lookup in image map MAP coordinates X and Y.
20823 An image map is an alist where each element has the format (AREA ID PLIST).
20824 An AREA is specified as either a rectangle, a circle, or a polygon:
20825 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20826 pixel coordinates of the upper left and bottom right corners.
20827 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20828 and the radius of the circle; r may be a float or integer.
20829 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20830 vector describes one corner in the polygon.
20831 Returns the alist element for the first matching AREA in MAP. */)
20842 return find_hot_spot (map
, XINT (x
), XINT (y
));
20846 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20848 define_frame_cursor1 (f
, cursor
, pointer
)
20851 Lisp_Object pointer
;
20853 /* Do not change cursor shape while dragging mouse. */
20854 if (!NILP (do_mouse_tracking
))
20857 if (!NILP (pointer
))
20859 if (EQ (pointer
, Qarrow
))
20860 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20861 else if (EQ (pointer
, Qhand
))
20862 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20863 else if (EQ (pointer
, Qtext
))
20864 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20865 else if (EQ (pointer
, intern ("hdrag")))
20866 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20867 #ifdef HAVE_X_WINDOWS
20868 else if (EQ (pointer
, intern ("vdrag")))
20869 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20871 else if (EQ (pointer
, intern ("hourglass")))
20872 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20873 else if (EQ (pointer
, Qmodeline
))
20874 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20876 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20879 if (cursor
!= No_Cursor
)
20880 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
20883 /* Take proper action when mouse has moved to the mode or header line
20884 or marginal area AREA of window W, x-position X and y-position Y.
20885 X is relative to the start of the text display area of W, so the
20886 width of bitmap areas and scroll bars must be subtracted to get a
20887 position relative to the start of the mode line. */
20890 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
20893 enum window_part area
;
20895 struct frame
*f
= XFRAME (w
->frame
);
20896 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20897 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20898 Lisp_Object pointer
= Qnil
;
20899 int charpos
, dx
, dy
, width
, height
;
20900 Lisp_Object string
, object
= Qnil
;
20901 Lisp_Object pos
, help
;
20903 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
20904 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
20905 &object
, &dx
, &dy
, &width
, &height
);
20908 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
20909 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
20910 &object
, &dx
, &dy
, &width
, &height
);
20915 if (IMAGEP (object
))
20917 Lisp_Object image_map
, hotspot
;
20918 if ((image_map
= Fsafe_plist_get (XCDR (object
), QCmap
),
20920 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
20922 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
20924 Lisp_Object area_id
, plist
;
20926 area_id
= XCAR (hotspot
);
20927 /* Could check AREA_ID to see if we enter/leave this hot-spot.
20928 If so, we could look for mouse-enter, mouse-leave
20929 properties in PLIST (and do something...). */
20930 hotspot
= XCDR (hotspot
);
20931 if (CONSP (hotspot
)
20932 && (plist
= XCAR (hotspot
), CONSP (plist
)))
20934 pointer
= Fsafe_plist_get (plist
, Qpointer
);
20935 if (NILP (pointer
))
20937 help
= Fsafe_plist_get (plist
, Qhelp_echo
);
20940 help_echo_string
= help
;
20941 /* Is this correct? ++kfs */
20942 XSETWINDOW (help_echo_window
, w
);
20943 help_echo_object
= w
->buffer
;
20944 help_echo_pos
= charpos
;
20947 if (NILP (pointer
))
20948 pointer
= Fsafe_plist_get (XCDR (object
), QCpointer
);
20952 if (STRINGP (string
))
20954 pos
= make_number (charpos
);
20955 /* If we're on a string with `help-echo' text property, arrange
20956 for the help to be displayed. This is done by setting the
20957 global variable help_echo_string to the help string. */
20960 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
20963 help_echo_string
= help
;
20964 XSETWINDOW (help_echo_window
, w
);
20965 help_echo_object
= string
;
20966 help_echo_pos
= charpos
;
20970 if (NILP (pointer
))
20971 pointer
= Fget_text_property (pos
, Qpointer
, string
);
20973 /* Change the mouse pointer according to what is under X/Y. */
20974 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
20977 map
= Fget_text_property (pos
, Qlocal_map
, string
);
20978 if (!KEYMAPP (map
))
20979 map
= Fget_text_property (pos
, Qkeymap
, string
);
20980 if (!KEYMAPP (map
))
20981 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
20985 define_frame_cursor1 (f
, cursor
, pointer
);
20990 Take proper action when the mouse has moved to position X, Y on
20991 frame F as regards highlighting characters that have mouse-face
20992 properties. Also de-highlighting chars where the mouse was before.
20993 X and Y can be negative or out of range. */
20996 note_mouse_highlight (f
, x
, y
)
21000 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21001 enum window_part part
;
21002 Lisp_Object window
;
21004 Cursor cursor
= No_Cursor
;
21005 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21008 /* When a menu is active, don't highlight because this looks odd. */
21009 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21010 if (popup_activated ())
21014 if (NILP (Vmouse_highlight
)
21015 || !f
->glyphs_initialized_p
)
21018 dpyinfo
->mouse_face_mouse_x
= x
;
21019 dpyinfo
->mouse_face_mouse_y
= y
;
21020 dpyinfo
->mouse_face_mouse_frame
= f
;
21022 if (dpyinfo
->mouse_face_defer
)
21025 if (gc_in_progress
)
21027 dpyinfo
->mouse_face_deferred_gc
= 1;
21031 /* Which window is that in? */
21032 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21034 /* If we were displaying active text in another window, clear that.
21035 Also clear if we move out of text area in same window. */
21036 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21037 || (part
!= ON_TEXT
&& !NILP (dpyinfo
->mouse_face_window
)))
21038 clear_mouse_face (dpyinfo
);
21040 /* Not on a window -> return. */
21041 if (!WINDOWP (window
))
21044 /* Reset help_echo_string. It will get recomputed below. */
21045 help_echo_string
= Qnil
;
21047 /* Convert to window-relative pixel coordinates. */
21048 w
= XWINDOW (window
);
21049 frame_to_window_pixel_xy (w
, &x
, &y
);
21051 /* Handle tool-bar window differently since it doesn't display a
21053 if (EQ (window
, f
->tool_bar_window
))
21055 note_tool_bar_highlight (f
, x
, y
);
21059 /* Mouse is on the mode, header line or margin? */
21060 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21061 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21063 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
21067 if (part
== ON_VERTICAL_BORDER
)
21068 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21069 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21070 || part
== ON_SCROLL_BAR
)
21071 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21073 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21075 /* Are we in a window whose display is up to date?
21076 And verify the buffer's text has not changed. */
21077 b
= XBUFFER (w
->buffer
);
21078 if (part
== ON_TEXT
21079 && EQ (w
->window_end_valid
, w
->buffer
)
21080 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21081 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21083 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21084 struct glyph
*glyph
;
21085 Lisp_Object object
;
21086 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21087 Lisp_Object
*overlay_vec
= NULL
;
21089 struct buffer
*obuf
;
21090 int obegv
, ozv
, same_region
;
21092 /* Find the glyph under X/Y. */
21093 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21095 /* Look for :pointer property on image. */
21096 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21098 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21099 if (img
!= NULL
&& IMAGEP (img
->spec
))
21101 Lisp_Object image_map
, hotspot
;
21102 if ((image_map
= Fsafe_plist_get (XCDR (img
->spec
), QCmap
),
21104 && (hotspot
= find_hot_spot (image_map
,
21105 glyph
->slice
.x
+ dx
,
21106 glyph
->slice
.y
+ dy
),
21108 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21110 Lisp_Object area_id
, plist
;
21112 area_id
= XCAR (hotspot
);
21113 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21114 If so, we could look for mouse-enter, mouse-leave
21115 properties in PLIST (and do something...). */
21116 hotspot
= XCDR (hotspot
);
21117 if (CONSP (hotspot
)
21118 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21120 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21121 if (NILP (pointer
))
21123 help_echo_string
= Fsafe_plist_get (plist
, Qhelp_echo
);
21124 if (!NILP (help_echo_string
))
21126 help_echo_window
= window
;
21127 help_echo_object
= glyph
->object
;
21128 help_echo_pos
= glyph
->charpos
;
21132 if (NILP (pointer
))
21133 pointer
= Fsafe_plist_get (XCDR (img
->spec
), QCpointer
);
21137 /* Clear mouse face if X/Y not over text. */
21139 || area
!= TEXT_AREA
21140 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21142 if (clear_mouse_face (dpyinfo
))
21143 cursor
= No_Cursor
;
21144 if (NILP (pointer
))
21146 if (area
!= TEXT_AREA
)
21147 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21149 pointer
= Vvoid_text_area_pointer
;
21154 pos
= glyph
->charpos
;
21155 object
= glyph
->object
;
21156 if (!STRINGP (object
) && !BUFFERP (object
))
21159 /* If we get an out-of-range value, return now; avoid an error. */
21160 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21163 /* Make the window's buffer temporarily current for
21164 overlays_at and compute_char_face. */
21165 obuf
= current_buffer
;
21166 current_buffer
= b
;
21172 /* Is this char mouse-active or does it have help-echo? */
21173 position
= make_number (pos
);
21175 if (BUFFERP (object
))
21177 /* Put all the overlays we want in a vector in overlay_vec. */
21178 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21179 /* Sort overlays into increasing priority order. */
21180 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21185 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21186 && vpos
>= dpyinfo
->mouse_face_beg_row
21187 && vpos
<= dpyinfo
->mouse_face_end_row
21188 && (vpos
> dpyinfo
->mouse_face_beg_row
21189 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21190 && (vpos
< dpyinfo
->mouse_face_end_row
21191 || hpos
< dpyinfo
->mouse_face_end_col
21192 || dpyinfo
->mouse_face_past_end
));
21195 cursor
= No_Cursor
;
21197 /* Check mouse-face highlighting. */
21199 /* If there exists an overlay with mouse-face overlapping
21200 the one we are currently highlighting, we have to
21201 check if we enter the overlapping overlay, and then
21202 highlight only that. */
21203 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21204 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21206 /* Find the highest priority overlay that has a mouse-face
21209 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21211 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21212 if (!NILP (mouse_face
))
21213 overlay
= overlay_vec
[i
];
21216 /* If we're actually highlighting the same overlay as
21217 before, there's no need to do that again. */
21218 if (!NILP (overlay
)
21219 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21220 goto check_help_echo
;
21222 dpyinfo
->mouse_face_overlay
= overlay
;
21224 /* Clear the display of the old active region, if any. */
21225 if (clear_mouse_face (dpyinfo
))
21226 cursor
= No_Cursor
;
21228 /* If no overlay applies, get a text property. */
21229 if (NILP (overlay
))
21230 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21232 /* Handle the overlay case. */
21233 if (!NILP (overlay
))
21235 /* Find the range of text around this char that
21236 should be active. */
21237 Lisp_Object before
, after
;
21240 before
= Foverlay_start (overlay
);
21241 after
= Foverlay_end (overlay
);
21242 /* Record this as the current active region. */
21243 fast_find_position (w
, XFASTINT (before
),
21244 &dpyinfo
->mouse_face_beg_col
,
21245 &dpyinfo
->mouse_face_beg_row
,
21246 &dpyinfo
->mouse_face_beg_x
,
21247 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21249 dpyinfo
->mouse_face_past_end
21250 = !fast_find_position (w
, XFASTINT (after
),
21251 &dpyinfo
->mouse_face_end_col
,
21252 &dpyinfo
->mouse_face_end_row
,
21253 &dpyinfo
->mouse_face_end_x
,
21254 &dpyinfo
->mouse_face_end_y
, Qnil
);
21255 dpyinfo
->mouse_face_window
= window
;
21257 dpyinfo
->mouse_face_face_id
21258 = face_at_buffer_position (w
, pos
, 0, 0,
21260 !dpyinfo
->mouse_face_hidden
);
21262 /* Display it as active. */
21263 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21264 cursor
= No_Cursor
;
21266 /* Handle the text property case. */
21267 else if (!NILP (mouse_face
) && BUFFERP (object
))
21269 /* Find the range of text around this char that
21270 should be active. */
21271 Lisp_Object before
, after
, beginning
, end
;
21274 beginning
= Fmarker_position (w
->start
);
21275 end
= make_number (BUF_Z (XBUFFER (object
))
21276 - XFASTINT (w
->window_end_pos
));
21278 = Fprevious_single_property_change (make_number (pos
+ 1),
21280 object
, beginning
);
21282 = Fnext_single_property_change (position
, Qmouse_face
,
21285 /* Record this as the current active region. */
21286 fast_find_position (w
, XFASTINT (before
),
21287 &dpyinfo
->mouse_face_beg_col
,
21288 &dpyinfo
->mouse_face_beg_row
,
21289 &dpyinfo
->mouse_face_beg_x
,
21290 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21291 dpyinfo
->mouse_face_past_end
21292 = !fast_find_position (w
, XFASTINT (after
),
21293 &dpyinfo
->mouse_face_end_col
,
21294 &dpyinfo
->mouse_face_end_row
,
21295 &dpyinfo
->mouse_face_end_x
,
21296 &dpyinfo
->mouse_face_end_y
, Qnil
);
21297 dpyinfo
->mouse_face_window
= window
;
21299 if (BUFFERP (object
))
21300 dpyinfo
->mouse_face_face_id
21301 = face_at_buffer_position (w
, pos
, 0, 0,
21303 !dpyinfo
->mouse_face_hidden
);
21305 /* Display it as active. */
21306 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21307 cursor
= No_Cursor
;
21309 else if (!NILP (mouse_face
) && STRINGP (object
))
21314 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21317 e
= Fnext_single_property_change (position
, Qmouse_face
,
21320 b
= make_number (0);
21322 e
= make_number (SCHARS (object
) - 1);
21323 fast_find_string_pos (w
, XINT (b
), object
,
21324 &dpyinfo
->mouse_face_beg_col
,
21325 &dpyinfo
->mouse_face_beg_row
,
21326 &dpyinfo
->mouse_face_beg_x
,
21327 &dpyinfo
->mouse_face_beg_y
, 0);
21328 fast_find_string_pos (w
, XINT (e
), object
,
21329 &dpyinfo
->mouse_face_end_col
,
21330 &dpyinfo
->mouse_face_end_row
,
21331 &dpyinfo
->mouse_face_end_x
,
21332 &dpyinfo
->mouse_face_end_y
, 1);
21333 dpyinfo
->mouse_face_past_end
= 0;
21334 dpyinfo
->mouse_face_window
= window
;
21335 dpyinfo
->mouse_face_face_id
21336 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21337 glyph
->face_id
, 1);
21338 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21339 cursor
= No_Cursor
;
21341 else if (STRINGP (object
) && NILP (mouse_face
))
21343 /* A string which doesn't have mouse-face, but
21344 the text ``under'' it might have. */
21345 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21346 int start
= MATRIX_ROW_START_CHARPOS (r
);
21348 pos
= string_buffer_position (w
, object
, start
);
21350 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21354 if (!NILP (mouse_face
) && !NILP (overlay
))
21356 Lisp_Object before
= Foverlay_start (overlay
);
21357 Lisp_Object after
= Foverlay_end (overlay
);
21360 /* Note that we might not be able to find position
21361 BEFORE in the glyph matrix if the overlay is
21362 entirely covered by a `display' property. In
21363 this case, we overshoot. So let's stop in
21364 the glyph matrix before glyphs for OBJECT. */
21365 fast_find_position (w
, XFASTINT (before
),
21366 &dpyinfo
->mouse_face_beg_col
,
21367 &dpyinfo
->mouse_face_beg_row
,
21368 &dpyinfo
->mouse_face_beg_x
,
21369 &dpyinfo
->mouse_face_beg_y
,
21372 dpyinfo
->mouse_face_past_end
21373 = !fast_find_position (w
, XFASTINT (after
),
21374 &dpyinfo
->mouse_face_end_col
,
21375 &dpyinfo
->mouse_face_end_row
,
21376 &dpyinfo
->mouse_face_end_x
,
21377 &dpyinfo
->mouse_face_end_y
,
21379 dpyinfo
->mouse_face_window
= window
;
21380 dpyinfo
->mouse_face_face_id
21381 = face_at_buffer_position (w
, pos
, 0, 0,
21383 !dpyinfo
->mouse_face_hidden
);
21385 /* Display it as active. */
21386 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21387 cursor
= No_Cursor
;
21394 /* Look for a `help-echo' property. */
21395 if (NILP (help_echo_string
)) {
21396 Lisp_Object help
, overlay
;
21398 /* Check overlays first. */
21399 help
= overlay
= Qnil
;
21400 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21402 overlay
= overlay_vec
[i
];
21403 help
= Foverlay_get (overlay
, Qhelp_echo
);
21408 help_echo_string
= help
;
21409 help_echo_window
= window
;
21410 help_echo_object
= overlay
;
21411 help_echo_pos
= pos
;
21415 Lisp_Object object
= glyph
->object
;
21416 int charpos
= glyph
->charpos
;
21418 /* Try text properties. */
21419 if (STRINGP (object
)
21421 && charpos
< SCHARS (object
))
21423 help
= Fget_text_property (make_number (charpos
),
21424 Qhelp_echo
, object
);
21427 /* If the string itself doesn't specify a help-echo,
21428 see if the buffer text ``under'' it does. */
21429 struct glyph_row
*r
21430 = MATRIX_ROW (w
->current_matrix
, vpos
);
21431 int start
= MATRIX_ROW_START_CHARPOS (r
);
21432 int pos
= string_buffer_position (w
, object
, start
);
21435 help
= Fget_char_property (make_number (pos
),
21436 Qhelp_echo
, w
->buffer
);
21440 object
= w
->buffer
;
21445 else if (BUFFERP (object
)
21448 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21453 help_echo_string
= help
;
21454 help_echo_window
= window
;
21455 help_echo_object
= object
;
21456 help_echo_pos
= charpos
;
21461 /* Look for a `pointer' property. */
21462 if (NILP (pointer
))
21464 /* Check overlays first. */
21465 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21466 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21468 if (NILP (pointer
))
21470 Lisp_Object object
= glyph
->object
;
21471 int charpos
= glyph
->charpos
;
21473 /* Try text properties. */
21474 if (STRINGP (object
)
21476 && charpos
< SCHARS (object
))
21478 pointer
= Fget_text_property (make_number (charpos
),
21480 if (NILP (pointer
))
21482 /* If the string itself doesn't specify a pointer,
21483 see if the buffer text ``under'' it does. */
21484 struct glyph_row
*r
21485 = MATRIX_ROW (w
->current_matrix
, vpos
);
21486 int start
= MATRIX_ROW_START_CHARPOS (r
);
21487 int pos
= string_buffer_position (w
, object
, start
);
21489 pointer
= Fget_char_property (make_number (pos
),
21490 Qpointer
, w
->buffer
);
21493 else if (BUFFERP (object
)
21496 pointer
= Fget_text_property (make_number (charpos
),
21503 current_buffer
= obuf
;
21508 define_frame_cursor1 (f
, cursor
, pointer
);
21513 Clear any mouse-face on window W. This function is part of the
21514 redisplay interface, and is called from try_window_id and similar
21515 functions to ensure the mouse-highlight is off. */
21518 x_clear_window_mouse_face (w
)
21521 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21522 Lisp_Object window
;
21525 XSETWINDOW (window
, w
);
21526 if (EQ (window
, dpyinfo
->mouse_face_window
))
21527 clear_mouse_face (dpyinfo
);
21533 Just discard the mouse face information for frame F, if any.
21534 This is used when the size of F is changed. */
21537 cancel_mouse_face (f
)
21540 Lisp_Object window
;
21541 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21543 window
= dpyinfo
->mouse_face_window
;
21544 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21546 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21547 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21548 dpyinfo
->mouse_face_window
= Qnil
;
21553 #endif /* HAVE_WINDOW_SYSTEM */
21556 /***********************************************************************
21558 ***********************************************************************/
21560 #ifdef HAVE_WINDOW_SYSTEM
21562 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21563 which intersects rectangle R. R is in window-relative coordinates. */
21566 expose_area (w
, row
, r
, area
)
21568 struct glyph_row
*row
;
21570 enum glyph_row_area area
;
21572 struct glyph
*first
= row
->glyphs
[area
];
21573 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21574 struct glyph
*last
;
21575 int first_x
, start_x
, x
;
21577 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21578 /* If row extends face to end of line write the whole line. */
21579 draw_glyphs (w
, 0, row
, area
,
21580 0, row
->used
[area
],
21581 DRAW_NORMAL_TEXT
, 0);
21584 /* Set START_X to the window-relative start position for drawing glyphs of
21585 AREA. The first glyph of the text area can be partially visible.
21586 The first glyphs of other areas cannot. */
21587 start_x
= window_box_left_offset (w
, area
);
21589 if (area
== TEXT_AREA
)
21592 /* Find the first glyph that must be redrawn. */
21594 && x
+ first
->pixel_width
< r
->x
)
21596 x
+= first
->pixel_width
;
21600 /* Find the last one. */
21604 && x
< r
->x
+ r
->width
)
21606 x
+= last
->pixel_width
;
21612 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21613 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21614 DRAW_NORMAL_TEXT
, 0);
21619 /* Redraw the parts of the glyph row ROW on window W intersecting
21620 rectangle R. R is in window-relative coordinates. Value is
21621 non-zero if mouse-face was overwritten. */
21624 expose_line (w
, row
, r
)
21626 struct glyph_row
*row
;
21629 xassert (row
->enabled_p
);
21631 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21632 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21633 0, row
->used
[TEXT_AREA
],
21634 DRAW_NORMAL_TEXT
, 0);
21637 if (row
->used
[LEFT_MARGIN_AREA
])
21638 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21639 if (row
->used
[TEXT_AREA
])
21640 expose_area (w
, row
, r
, TEXT_AREA
);
21641 if (row
->used
[RIGHT_MARGIN_AREA
])
21642 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21643 draw_row_fringe_bitmaps (w
, row
);
21646 return row
->mouse_face_p
;
21650 /* Redraw those parts of glyphs rows during expose event handling that
21651 overlap other rows. Redrawing of an exposed line writes over parts
21652 of lines overlapping that exposed line; this function fixes that.
21654 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21655 row in W's current matrix that is exposed and overlaps other rows.
21656 LAST_OVERLAPPING_ROW is the last such row. */
21659 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21661 struct glyph_row
*first_overlapping_row
;
21662 struct glyph_row
*last_overlapping_row
;
21664 struct glyph_row
*row
;
21666 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21667 if (row
->overlapping_p
)
21669 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21671 if (row
->used
[LEFT_MARGIN_AREA
])
21672 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21674 if (row
->used
[TEXT_AREA
])
21675 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21677 if (row
->used
[RIGHT_MARGIN_AREA
])
21678 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21683 /* Return non-zero if W's cursor intersects rectangle R. */
21686 phys_cursor_in_rect_p (w
, r
)
21690 XRectangle cr
, result
;
21691 struct glyph
*cursor_glyph
;
21693 cursor_glyph
= get_phys_cursor_glyph (w
);
21696 /* r is relative to W's box, but w->phys_cursor.x is relative
21697 to left edge of W's TEXT area. Adjust it. */
21698 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21699 cr
.y
= w
->phys_cursor
.y
;
21700 cr
.width
= cursor_glyph
->pixel_width
;
21701 cr
.height
= w
->phys_cursor_height
;
21702 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21703 I assume the effect is the same -- and this is portable. */
21704 return x_intersect_rectangles (&cr
, r
, &result
);
21706 /* If we don't understand the format, pretend we're not in the hot-spot. */
21712 Draw a vertical window border to the right of window W if W doesn't
21713 have vertical scroll bars. */
21716 x_draw_vertical_border (w
)
21719 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21721 /* We could do better, if we knew what type of scroll-bar the adjacent
21722 windows (on either side) have... But we don't :-(
21723 However, I think this works ok. ++KFS 2003-04-25 */
21725 /* Redraw borders between horizontally adjacent windows. Don't
21726 do it for frames with vertical scroll bars because either the
21727 right scroll bar of a window, or the left scroll bar of its
21728 neighbor will suffice as a border. */
21729 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
21732 if (!WINDOW_RIGHTMOST_P (w
)
21733 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21735 int x0
, x1
, y0
, y1
;
21737 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21740 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
21742 else if (!WINDOW_LEFTMOST_P (w
)
21743 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21745 int x0
, x1
, y0
, y1
;
21747 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21750 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
21755 /* Redraw the part of window W intersection rectangle FR. Pixel
21756 coordinates in FR are frame-relative. Call this function with
21757 input blocked. Value is non-zero if the exposure overwrites
21761 expose_window (w
, fr
)
21765 struct frame
*f
= XFRAME (w
->frame
);
21767 int mouse_face_overwritten_p
= 0;
21769 /* If window is not yet fully initialized, do nothing. This can
21770 happen when toolkit scroll bars are used and a window is split.
21771 Reconfiguring the scroll bar will generate an expose for a newly
21773 if (w
->current_matrix
== NULL
)
21776 /* When we're currently updating the window, display and current
21777 matrix usually don't agree. Arrange for a thorough display
21779 if (w
== updated_window
)
21781 SET_FRAME_GARBAGED (f
);
21785 /* Frame-relative pixel rectangle of W. */
21786 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21787 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21788 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21789 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21791 if (x_intersect_rectangles (fr
, &wr
, &r
))
21793 int yb
= window_text_bottom_y (w
);
21794 struct glyph_row
*row
;
21795 int cursor_cleared_p
;
21796 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21798 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21799 r
.x
, r
.y
, r
.width
, r
.height
));
21801 /* Convert to window coordinates. */
21802 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21803 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21805 /* Turn off the cursor. */
21806 if (!w
->pseudo_window_p
21807 && phys_cursor_in_rect_p (w
, &r
))
21809 x_clear_cursor (w
);
21810 cursor_cleared_p
= 1;
21813 cursor_cleared_p
= 0;
21815 /* Update lines intersecting rectangle R. */
21816 first_overlapping_row
= last_overlapping_row
= NULL
;
21817 for (row
= w
->current_matrix
->rows
;
21822 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21824 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21825 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21826 || (r
.y
>= y0
&& r
.y
< y1
)
21827 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21829 if (row
->overlapping_p
)
21831 if (first_overlapping_row
== NULL
)
21832 first_overlapping_row
= row
;
21833 last_overlapping_row
= row
;
21836 if (expose_line (w
, row
, &r
))
21837 mouse_face_overwritten_p
= 1;
21844 /* Display the mode line if there is one. */
21845 if (WINDOW_WANTS_MODELINE_P (w
)
21846 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21848 && row
->y
< r
.y
+ r
.height
)
21850 if (expose_line (w
, row
, &r
))
21851 mouse_face_overwritten_p
= 1;
21854 if (!w
->pseudo_window_p
)
21856 /* Fix the display of overlapping rows. */
21857 if (first_overlapping_row
)
21858 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21860 /* Draw border between windows. */
21861 x_draw_vertical_border (w
);
21863 /* Turn the cursor on again. */
21864 if (cursor_cleared_p
)
21865 update_window_cursor (w
, 1);
21870 /* Display scroll bar for this window. */
21871 if (!NILP (w
->vertical_scroll_bar
))
21874 If this doesn't work here (maybe some header files are missing),
21875 make a function in macterm.c and call it to do the job! */
21877 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
21883 return mouse_face_overwritten_p
;
21888 /* Redraw (parts) of all windows in the window tree rooted at W that
21889 intersect R. R contains frame pixel coordinates. Value is
21890 non-zero if the exposure overwrites mouse-face. */
21893 expose_window_tree (w
, r
)
21897 struct frame
*f
= XFRAME (w
->frame
);
21898 int mouse_face_overwritten_p
= 0;
21900 while (w
&& !FRAME_GARBAGED_P (f
))
21902 if (!NILP (w
->hchild
))
21903 mouse_face_overwritten_p
21904 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21905 else if (!NILP (w
->vchild
))
21906 mouse_face_overwritten_p
21907 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
21909 mouse_face_overwritten_p
|= expose_window (w
, r
);
21911 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
21914 return mouse_face_overwritten_p
;
21919 Redisplay an exposed area of frame F. X and Y are the upper-left
21920 corner of the exposed rectangle. W and H are width and height of
21921 the exposed area. All are pixel values. W or H zero means redraw
21922 the entire frame. */
21925 expose_frame (f
, x
, y
, w
, h
)
21930 int mouse_face_overwritten_p
= 0;
21932 TRACE ((stderr
, "expose_frame "));
21934 /* No need to redraw if frame will be redrawn soon. */
21935 if (FRAME_GARBAGED_P (f
))
21937 TRACE ((stderr
, " garbaged\n"));
21942 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
21943 or deactivated here, for unknown reasons, activated scroll bars
21944 are shown in deactivated frames in some instances. */
21945 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
21946 activate_scroll_bars (f
);
21948 deactivate_scroll_bars (f
);
21951 /* If basic faces haven't been realized yet, there is no point in
21952 trying to redraw anything. This can happen when we get an expose
21953 event while Emacs is starting, e.g. by moving another window. */
21954 if (FRAME_FACE_CACHE (f
) == NULL
21955 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
21957 TRACE ((stderr
, " no faces\n"));
21961 if (w
== 0 || h
== 0)
21964 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
21965 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
21975 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
21976 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
21978 if (WINDOWP (f
->tool_bar_window
))
21979 mouse_face_overwritten_p
21980 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
21982 #ifdef HAVE_X_WINDOWS
21984 #ifndef USE_X_TOOLKIT
21985 if (WINDOWP (f
->menu_bar_window
))
21986 mouse_face_overwritten_p
21987 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
21988 #endif /* not USE_X_TOOLKIT */
21992 /* Some window managers support a focus-follows-mouse style with
21993 delayed raising of frames. Imagine a partially obscured frame,
21994 and moving the mouse into partially obscured mouse-face on that
21995 frame. The visible part of the mouse-face will be highlighted,
21996 then the WM raises the obscured frame. With at least one WM, KDE
21997 2.1, Emacs is not getting any event for the raising of the frame
21998 (even tried with SubstructureRedirectMask), only Expose events.
21999 These expose events will draw text normally, i.e. not
22000 highlighted. Which means we must redo the highlight here.
22001 Subsume it under ``we love X''. --gerd 2001-08-15 */
22002 /* Included in Windows version because Windows most likely does not
22003 do the right thing if any third party tool offers
22004 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22005 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22007 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22008 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22010 int x
= dpyinfo
->mouse_face_mouse_x
;
22011 int y
= dpyinfo
->mouse_face_mouse_y
;
22012 clear_mouse_face (dpyinfo
);
22013 note_mouse_highlight (f
, x
, y
);
22020 Determine the intersection of two rectangles R1 and R2. Return
22021 the intersection in *RESULT. Value is non-zero if RESULT is not
22025 x_intersect_rectangles (r1
, r2
, result
)
22026 XRectangle
*r1
, *r2
, *result
;
22028 XRectangle
*left
, *right
;
22029 XRectangle
*upper
, *lower
;
22030 int intersection_p
= 0;
22032 /* Rearrange so that R1 is the left-most rectangle. */
22034 left
= r1
, right
= r2
;
22036 left
= r2
, right
= r1
;
22038 /* X0 of the intersection is right.x0, if this is inside R1,
22039 otherwise there is no intersection. */
22040 if (right
->x
<= left
->x
+ left
->width
)
22042 result
->x
= right
->x
;
22044 /* The right end of the intersection is the minimum of the
22045 the right ends of left and right. */
22046 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22049 /* Same game for Y. */
22051 upper
= r1
, lower
= r2
;
22053 upper
= r2
, lower
= r1
;
22055 /* The upper end of the intersection is lower.y0, if this is inside
22056 of upper. Otherwise, there is no intersection. */
22057 if (lower
->y
<= upper
->y
+ upper
->height
)
22059 result
->y
= lower
->y
;
22061 /* The lower end of the intersection is the minimum of the lower
22062 ends of upper and lower. */
22063 result
->height
= (min (lower
->y
+ lower
->height
,
22064 upper
->y
+ upper
->height
)
22066 intersection_p
= 1;
22070 return intersection_p
;
22073 #endif /* HAVE_WINDOW_SYSTEM */
22076 /***********************************************************************
22078 ***********************************************************************/
22083 Vwith_echo_area_save_vector
= Qnil
;
22084 staticpro (&Vwith_echo_area_save_vector
);
22086 Vmessage_stack
= Qnil
;
22087 staticpro (&Vmessage_stack
);
22089 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22090 staticpro (&Qinhibit_redisplay
);
22092 message_dolog_marker1
= Fmake_marker ();
22093 staticpro (&message_dolog_marker1
);
22094 message_dolog_marker2
= Fmake_marker ();
22095 staticpro (&message_dolog_marker2
);
22096 message_dolog_marker3
= Fmake_marker ();
22097 staticpro (&message_dolog_marker3
);
22100 defsubr (&Sdump_frame_glyph_matrix
);
22101 defsubr (&Sdump_glyph_matrix
);
22102 defsubr (&Sdump_glyph_row
);
22103 defsubr (&Sdump_tool_bar_row
);
22104 defsubr (&Strace_redisplay
);
22105 defsubr (&Strace_to_stderr
);
22107 #ifdef HAVE_WINDOW_SYSTEM
22108 defsubr (&Stool_bar_lines_needed
);
22109 defsubr (&Slookup_image_map
);
22111 defsubr (&Sformat_mode_line
);
22113 staticpro (&Qmenu_bar_update_hook
);
22114 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22116 staticpro (&Qoverriding_terminal_local_map
);
22117 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22119 staticpro (&Qoverriding_local_map
);
22120 Qoverriding_local_map
= intern ("overriding-local-map");
22122 staticpro (&Qwindow_scroll_functions
);
22123 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22125 staticpro (&Qredisplay_end_trigger_functions
);
22126 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22128 staticpro (&Qinhibit_point_motion_hooks
);
22129 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22131 QCdata
= intern (":data");
22132 staticpro (&QCdata
);
22133 Qdisplay
= intern ("display");
22134 staticpro (&Qdisplay
);
22135 Qspace_width
= intern ("space-width");
22136 staticpro (&Qspace_width
);
22137 Qraise
= intern ("raise");
22138 staticpro (&Qraise
);
22139 Qslice
= intern ("slice");
22140 staticpro (&Qslice
);
22141 Qspace
= intern ("space");
22142 staticpro (&Qspace
);
22143 Qmargin
= intern ("margin");
22144 staticpro (&Qmargin
);
22145 Qpointer
= intern ("pointer");
22146 staticpro (&Qpointer
);
22147 Qleft_margin
= intern ("left-margin");
22148 staticpro (&Qleft_margin
);
22149 Qright_margin
= intern ("right-margin");
22150 staticpro (&Qright_margin
);
22151 Qcenter
= intern ("center");
22152 staticpro (&Qcenter
);
22153 Qline_height
= intern ("line-height");
22154 staticpro (&Qline_height
);
22155 Qtotal
= intern ("total");
22156 staticpro (&Qtotal
);
22157 QCalign_to
= intern (":align-to");
22158 staticpro (&QCalign_to
);
22159 QCrelative_width
= intern (":relative-width");
22160 staticpro (&QCrelative_width
);
22161 QCrelative_height
= intern (":relative-height");
22162 staticpro (&QCrelative_height
);
22163 QCeval
= intern (":eval");
22164 staticpro (&QCeval
);
22165 QCpropertize
= intern (":propertize");
22166 staticpro (&QCpropertize
);
22167 QCfile
= intern (":file");
22168 staticpro (&QCfile
);
22169 Qfontified
= intern ("fontified");
22170 staticpro (&Qfontified
);
22171 Qfontification_functions
= intern ("fontification-functions");
22172 staticpro (&Qfontification_functions
);
22173 Qtrailing_whitespace
= intern ("trailing-whitespace");
22174 staticpro (&Qtrailing_whitespace
);
22175 Qimage
= intern ("image");
22176 staticpro (&Qimage
);
22177 QCmap
= intern (":map");
22178 staticpro (&QCmap
);
22179 QCpointer
= intern (":pointer");
22180 staticpro (&QCpointer
);
22181 Qrect
= intern ("rect");
22182 staticpro (&Qrect
);
22183 Qcircle
= intern ("circle");
22184 staticpro (&Qcircle
);
22185 Qpoly
= intern ("poly");
22186 staticpro (&Qpoly
);
22187 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22188 staticpro (&Qmessage_truncate_lines
);
22189 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
22190 staticpro (&Qcursor_in_non_selected_windows
);
22191 Qgrow_only
= intern ("grow-only");
22192 staticpro (&Qgrow_only
);
22193 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22194 staticpro (&Qinhibit_menubar_update
);
22195 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22196 staticpro (&Qinhibit_eval_during_redisplay
);
22197 Qposition
= intern ("position");
22198 staticpro (&Qposition
);
22199 Qbuffer_position
= intern ("buffer-position");
22200 staticpro (&Qbuffer_position
);
22201 Qobject
= intern ("object");
22202 staticpro (&Qobject
);
22203 Qbar
= intern ("bar");
22205 Qhbar
= intern ("hbar");
22206 staticpro (&Qhbar
);
22207 Qbox
= intern ("box");
22209 Qhollow
= intern ("hollow");
22210 staticpro (&Qhollow
);
22211 Qhand
= intern ("hand");
22212 staticpro (&Qhand
);
22213 Qarrow
= intern ("arrow");
22214 staticpro (&Qarrow
);
22215 Qtext
= intern ("text");
22216 staticpro (&Qtext
);
22217 Qrisky_local_variable
= intern ("risky-local-variable");
22218 staticpro (&Qrisky_local_variable
);
22219 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22220 staticpro (&Qinhibit_free_realized_faces
);
22222 list_of_error
= Fcons (Fcons (intern ("error"),
22223 Fcons (intern ("void-variable"), Qnil
)),
22225 staticpro (&list_of_error
);
22227 Qlast_arrow_position
= intern ("last-arrow-position");
22228 staticpro (&Qlast_arrow_position
);
22229 Qlast_arrow_string
= intern ("last-arrow-string");
22230 staticpro (&Qlast_arrow_string
);
22232 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22233 staticpro (&Qoverlay_arrow_string
);
22234 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22235 staticpro (&Qoverlay_arrow_bitmap
);
22237 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22238 staticpro (&echo_buffer
[0]);
22239 staticpro (&echo_buffer
[1]);
22241 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22242 staticpro (&echo_area_buffer
[0]);
22243 staticpro (&echo_area_buffer
[1]);
22245 Vmessages_buffer_name
= build_string ("*Messages*");
22246 staticpro (&Vmessages_buffer_name
);
22248 mode_line_proptrans_alist
= Qnil
;
22249 staticpro (&mode_line_proptrans_alist
);
22251 mode_line_string_list
= Qnil
;
22252 staticpro (&mode_line_string_list
);
22254 help_echo_string
= Qnil
;
22255 staticpro (&help_echo_string
);
22256 help_echo_object
= Qnil
;
22257 staticpro (&help_echo_object
);
22258 help_echo_window
= Qnil
;
22259 staticpro (&help_echo_window
);
22260 previous_help_echo_string
= Qnil
;
22261 staticpro (&previous_help_echo_string
);
22262 help_echo_pos
= -1;
22264 #ifdef HAVE_WINDOW_SYSTEM
22265 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22266 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22267 For example, if a block cursor is over a tab, it will be drawn as
22268 wide as that tab on the display. */);
22269 x_stretch_cursor_p
= 0;
22272 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22273 doc
: /* *Non-nil means highlight trailing whitespace.
22274 The face used for trailing whitespace is `trailing-whitespace'. */);
22275 Vshow_trailing_whitespace
= Qnil
;
22277 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22278 doc
: /* *The pointer shape to show in void text areas.
22279 Nil means to show the text pointer. Other options are `arrow', `text',
22280 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22281 Vvoid_text_area_pointer
= Qarrow
;
22283 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22284 doc
: /* Non-nil means don't actually do any redisplay.
22285 This is used for internal purposes. */);
22286 Vinhibit_redisplay
= Qnil
;
22288 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22289 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22290 Vglobal_mode_string
= Qnil
;
22292 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22293 doc
: /* Marker for where to display an arrow on top of the buffer text.
22294 This must be the beginning of a line in order to work.
22295 See also `overlay-arrow-string'. */);
22296 Voverlay_arrow_position
= Qnil
;
22298 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22299 doc
: /* String to display as an arrow in non-window frames.
22300 See also `overlay-arrow-position'. */);
22301 Voverlay_arrow_string
= Qnil
;
22303 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22304 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22305 The symbols on this list are examined during redisplay to determine
22306 where to display overlay arrows. */);
22307 Voverlay_arrow_variable_list
22308 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22310 DEFVAR_INT ("scroll-step", &scroll_step
,
22311 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22312 If that fails to bring point back on frame, point is centered instead.
22313 If this is zero, point is always centered after it moves off frame.
22314 If you want scrolling to always be a line at a time, you should set
22315 `scroll-conservatively' to a large value rather than set this to 1. */);
22317 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22318 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22319 A value of zero means to scroll the text to center point vertically
22320 in the window. */);
22321 scroll_conservatively
= 0;
22323 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22324 doc
: /* *Number of lines of margin at the top and bottom of a window.
22325 Recenter the window whenever point gets within this many lines
22326 of the top or bottom of the window. */);
22329 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22330 doc
: /* Pixels per inch on current display.
22331 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22332 Vdisplay_pixels_per_inch
= make_float (72.0);
22335 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22338 DEFVAR_BOOL ("truncate-partial-width-windows",
22339 &truncate_partial_width_windows
,
22340 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22341 truncate_partial_width_windows
= 1;
22343 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22344 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22345 Any other value means to use the appropriate face, `mode-line',
22346 `header-line', or `menu' respectively. */);
22347 mode_line_inverse_video
= 1;
22349 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22350 doc
: /* *Maximum buffer size for which line number should be displayed.
22351 If the buffer is bigger than this, the line number does not appear
22352 in the mode line. A value of nil means no limit. */);
22353 Vline_number_display_limit
= Qnil
;
22355 DEFVAR_INT ("line-number-display-limit-width",
22356 &line_number_display_limit_width
,
22357 doc
: /* *Maximum line width (in characters) for line number display.
22358 If the average length of the lines near point is bigger than this, then the
22359 line number may be omitted from the mode line. */);
22360 line_number_display_limit_width
= 200;
22362 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22363 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22364 highlight_nonselected_windows
= 0;
22366 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22367 doc
: /* Non-nil if more than one frame is visible on this display.
22368 Minibuffer-only frames don't count, but iconified frames do.
22369 This variable is not guaranteed to be accurate except while processing
22370 `frame-title-format' and `icon-title-format'. */);
22372 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22373 doc
: /* Template for displaying the title bar of visible frames.
22374 \(Assuming the window manager supports this feature.)
22375 This variable has the same structure as `mode-line-format' (which see),
22376 and is used only on frames for which no explicit name has been set
22377 \(see `modify-frame-parameters'). */);
22379 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22380 doc
: /* Template for displaying the title bar of an iconified frame.
22381 \(Assuming the window manager supports this feature.)
22382 This variable has the same structure as `mode-line-format' (which see),
22383 and is used only on frames for which no explicit name has been set
22384 \(see `modify-frame-parameters'). */);
22386 = Vframe_title_format
22387 = Fcons (intern ("multiple-frames"),
22388 Fcons (build_string ("%b"),
22389 Fcons (Fcons (empty_string
,
22390 Fcons (intern ("invocation-name"),
22391 Fcons (build_string ("@"),
22392 Fcons (intern ("system-name"),
22396 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22397 doc
: /* Maximum number of lines to keep in the message log buffer.
22398 If nil, disable message logging. If t, log messages but don't truncate
22399 the buffer when it becomes large. */);
22400 Vmessage_log_max
= make_number (50);
22402 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22403 doc
: /* Functions called before redisplay, if window sizes have changed.
22404 The value should be a list of functions that take one argument.
22405 Just before redisplay, for each frame, if any of its windows have changed
22406 size since the last redisplay, or have been split or deleted,
22407 all the functions in the list are called, with the frame as argument. */);
22408 Vwindow_size_change_functions
= Qnil
;
22410 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22411 doc
: /* List of functions to call before redisplaying a window with scrolling.
22412 Each function is called with two arguments, the window
22413 and its new display-start position. Note that the value of `window-end'
22414 is not valid when these functions are called. */);
22415 Vwindow_scroll_functions
= Qnil
;
22417 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22418 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22419 mouse_autoselect_window
= 0;
22421 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22422 doc
: /* *Non-nil means automatically resize tool-bars.
22423 This increases a tool-bar's height if not all tool-bar items are visible.
22424 It decreases a tool-bar's height when it would display blank lines
22426 auto_resize_tool_bars_p
= 1;
22428 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22429 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22430 auto_raise_tool_bar_buttons_p
= 1;
22432 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
22433 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
22434 make_cursor_line_fully_visible_p
= 1;
22436 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22437 doc
: /* *Margin around tool-bar buttons in pixels.
22438 If an integer, use that for both horizontal and vertical margins.
22439 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22440 HORZ specifying the horizontal margin, and VERT specifying the
22441 vertical margin. */);
22442 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22444 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22445 doc
: /* *Relief thickness of tool-bar buttons. */);
22446 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22448 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22449 doc
: /* List of functions to call to fontify regions of text.
22450 Each function is called with one argument POS. Functions must
22451 fontify a region starting at POS in the current buffer, and give
22452 fontified regions the property `fontified'. */);
22453 Vfontification_functions
= Qnil
;
22454 Fmake_variable_buffer_local (Qfontification_functions
);
22456 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22457 &unibyte_display_via_language_environment
,
22458 doc
: /* *Non-nil means display unibyte text according to language environment.
22459 Specifically this means that unibyte non-ASCII characters
22460 are displayed by converting them to the equivalent multibyte characters
22461 according to the current language environment. As a result, they are
22462 displayed according to the current fontset. */);
22463 unibyte_display_via_language_environment
= 0;
22465 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22466 doc
: /* *Maximum height for resizing mini-windows.
22467 If a float, it specifies a fraction of the mini-window frame's height.
22468 If an integer, it specifies a number of lines. */);
22469 Vmax_mini_window_height
= make_float (0.25);
22471 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22472 doc
: /* *How to resize mini-windows.
22473 A value of nil means don't automatically resize mini-windows.
22474 A value of t means resize them to fit the text displayed in them.
22475 A value of `grow-only', the default, means let mini-windows grow
22476 only, until their display becomes empty, at which point the windows
22477 go back to their normal size. */);
22478 Vresize_mini_windows
= Qgrow_only
;
22480 DEFVAR_LISP ("cursor-in-non-selected-windows",
22481 &Vcursor_in_non_selected_windows
,
22482 doc
: /* *Cursor type to display in non-selected windows.
22483 t means to use hollow box cursor. See `cursor-type' for other values. */);
22484 Vcursor_in_non_selected_windows
= Qt
;
22486 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22487 doc
: /* Alist specifying how to blink the cursor off.
22488 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22489 `cursor-type' frame-parameter or variable equals ON-STATE,
22490 comparing using `equal', Emacs uses OFF-STATE to specify
22491 how to blink it off. */);
22492 Vblink_cursor_alist
= Qnil
;
22494 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22495 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22496 automatic_hscrolling_p
= 1;
22498 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22499 doc
: /* *How many columns away from the window edge point is allowed to get
22500 before automatic hscrolling will horizontally scroll the window. */);
22501 hscroll_margin
= 5;
22503 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22504 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22505 When point is less than `automatic-hscroll-margin' columns from the window
22506 edge, automatic hscrolling will scroll the window by the amount of columns
22507 determined by this variable. If its value is a positive integer, scroll that
22508 many columns. If it's a positive floating-point number, it specifies the
22509 fraction of the window's width to scroll. If it's nil or zero, point will be
22510 centered horizontally after the scroll. Any other value, including negative
22511 numbers, are treated as if the value were zero.
22513 Automatic hscrolling always moves point outside the scroll margin, so if
22514 point was more than scroll step columns inside the margin, the window will
22515 scroll more than the value given by the scroll step.
22517 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22518 and `scroll-right' overrides this variable's effect. */);
22519 Vhscroll_step
= make_number (0);
22521 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22522 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22523 Bind this around calls to `message' to let it take effect. */);
22524 message_truncate_lines
= 0;
22526 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22527 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22528 Can be used to update submenus whose contents should vary. */);
22529 Vmenu_bar_update_hook
= Qnil
;
22531 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22532 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22533 inhibit_menubar_update
= 0;
22535 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22536 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22537 inhibit_eval_during_redisplay
= 0;
22539 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22540 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22541 inhibit_free_realized_faces
= 0;
22544 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22545 doc
: /* Inhibit try_window_id display optimization. */);
22546 inhibit_try_window_id
= 0;
22548 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22549 doc
: /* Inhibit try_window_reusing display optimization. */);
22550 inhibit_try_window_reusing
= 0;
22552 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22553 doc
: /* Inhibit try_cursor_movement display optimization. */);
22554 inhibit_try_cursor_movement
= 0;
22555 #endif /* GLYPH_DEBUG */
22559 /* Initialize this module when Emacs starts. */
22564 Lisp_Object root_window
;
22565 struct window
*mini_w
;
22567 current_header_line_height
= current_mode_line_height
= -1;
22569 CHARPOS (this_line_start_pos
) = 0;
22571 mini_w
= XWINDOW (minibuf_window
);
22572 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22574 if (!noninteractive
)
22576 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22579 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22580 set_window_height (root_window
,
22581 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22583 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22584 set_window_height (minibuf_window
, 1, 0);
22586 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22587 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22589 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22590 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22591 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22593 /* The default ellipsis glyphs `...'. */
22594 for (i
= 0; i
< 3; ++i
)
22595 default_invis_vector
[i
] = make_number ('.');
22599 /* Allocate the buffer for frame titles.
22600 Also used for `format-mode-line'. */
22602 frame_title_buf
= (char *) xmalloc (size
);
22603 frame_title_buf_end
= frame_title_buf
+ size
;
22604 frame_title_ptr
= NULL
;
22607 help_echo_showing_p
= 0;
22611 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22612 (do not change this comment) */