1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-zero means automatically select any window when the mouse
260 cursor moves into it. */
261 int mouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin around tool bar buttons in pixels. */
274 Lisp_Object Vtool_bar_button_margin
;
276 /* Thickness of shadow to draw around tool bar buttons. */
278 EMACS_INT tool_bar_button_relief
;
280 /* Non-zero means automatically resize tool-bars so that all tool-bar
281 items are visible, and no blank lines remain. */
283 int auto_resize_tool_bars_p
;
285 /* Non-zero means draw block and hollow cursor as wide as the glyph
286 under it. For example, if a block cursor is over a tab, it will be
287 drawn as wide as that tab on the display. */
289 int x_stretch_cursor_p
;
291 /* Non-nil means don't actually do any redisplay. */
293 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
295 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
297 int inhibit_eval_during_redisplay
;
299 /* Names of text properties relevant for redisplay. */
301 Lisp_Object Qdisplay
;
302 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
304 /* Symbols used in text property values. */
306 Lisp_Object Vdisplay_pixels_per_inch
;
307 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
308 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
311 Lisp_Object Qmargin
, Qpointer
;
312 Lisp_Object Qline_height
;
313 extern Lisp_Object Qheight
;
314 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
315 extern Lisp_Object Qscroll_bar
;
316 extern Lisp_Object Qcursor
;
318 /* Non-nil means highlight trailing whitespace. */
320 Lisp_Object Vshow_trailing_whitespace
;
322 /* Non-nil means escape non-break space and hyphens. */
324 Lisp_Object Vnobreak_char_display
;
326 #ifdef HAVE_WINDOW_SYSTEM
327 extern Lisp_Object Voverflow_newline_into_fringe
;
329 /* Test if overflow newline into fringe. Called with iterator IT
330 at or past right window margin, and with IT->current_x set. */
332 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
333 (!NILP (Voverflow_newline_into_fringe) \
334 && FRAME_WINDOW_P (it->f) \
335 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
336 && it->current_x == it->last_visible_x)
338 #endif /* HAVE_WINDOW_SYSTEM */
340 /* Non-nil means show the text cursor in void text areas
341 i.e. in blank areas after eol and eob. This used to be
342 the default in 21.3. */
344 Lisp_Object Vvoid_text_area_pointer
;
346 /* Name of the face used to highlight trailing whitespace. */
348 Lisp_Object Qtrailing_whitespace
;
350 /* Name and number of the face used to highlight escape glyphs. */
352 Lisp_Object Qescape_glyph
;
354 /* Name and number of the face used to highlight non-breaking spaces. */
356 Lisp_Object Qnobreak_space
;
358 /* The symbol `image' which is the car of the lists used to represent
363 /* The image map types. */
364 Lisp_Object QCmap
, QCpointer
;
365 Lisp_Object Qrect
, Qcircle
, Qpoly
;
367 /* Non-zero means print newline to stdout before next mini-buffer
370 int noninteractive_need_newline
;
372 /* Non-zero means print newline to message log before next message. */
374 static int message_log_need_newline
;
376 /* Three markers that message_dolog uses.
377 It could allocate them itself, but that causes trouble
378 in handling memory-full errors. */
379 static Lisp_Object message_dolog_marker1
;
380 static Lisp_Object message_dolog_marker2
;
381 static Lisp_Object message_dolog_marker3
;
383 /* The buffer position of the first character appearing entirely or
384 partially on the line of the selected window which contains the
385 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
386 redisplay optimization in redisplay_internal. */
388 static struct text_pos this_line_start_pos
;
390 /* Number of characters past the end of the line above, including the
391 terminating newline. */
393 static struct text_pos this_line_end_pos
;
395 /* The vertical positions and the height of this line. */
397 static int this_line_vpos
;
398 static int this_line_y
;
399 static int this_line_pixel_height
;
401 /* X position at which this display line starts. Usually zero;
402 negative if first character is partially visible. */
404 static int this_line_start_x
;
406 /* Buffer that this_line_.* variables are referring to. */
408 static struct buffer
*this_line_buffer
;
410 /* Nonzero means truncate lines in all windows less wide than the
413 int truncate_partial_width_windows
;
415 /* A flag to control how to display unibyte 8-bit character. */
417 int unibyte_display_via_language_environment
;
419 /* Nonzero means we have more than one non-mini-buffer-only frame.
420 Not guaranteed to be accurate except while parsing
421 frame-title-format. */
425 Lisp_Object Vglobal_mode_string
;
428 /* List of variables (symbols) which hold markers for overlay arrows.
429 The symbols on this list are examined during redisplay to determine
430 where to display overlay arrows. */
432 Lisp_Object Voverlay_arrow_variable_list
;
434 /* Marker for where to display an arrow on top of the buffer text. */
436 Lisp_Object Voverlay_arrow_position
;
438 /* String to display for the arrow. Only used on terminal frames. */
440 Lisp_Object Voverlay_arrow_string
;
442 /* Values of those variables at last redisplay are stored as
443 properties on `overlay-arrow-position' symbol. However, if
444 Voverlay_arrow_position is a marker, last-arrow-position is its
445 numerical position. */
447 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
449 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
450 properties on a symbol in overlay-arrow-variable-list. */
452 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
454 /* Like mode-line-format, but for the title bar on a visible frame. */
456 Lisp_Object Vframe_title_format
;
458 /* Like mode-line-format, but for the title bar on an iconified frame. */
460 Lisp_Object Vicon_title_format
;
462 /* List of functions to call when a window's size changes. These
463 functions get one arg, a frame on which one or more windows' sizes
466 static Lisp_Object Vwindow_size_change_functions
;
468 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
470 /* Nonzero if an overlay arrow has been displayed in this window. */
472 static int overlay_arrow_seen
;
474 /* Nonzero means highlight the region even in nonselected windows. */
476 int highlight_nonselected_windows
;
478 /* If cursor motion alone moves point off frame, try scrolling this
479 many lines up or down if that will bring it back. */
481 static EMACS_INT scroll_step
;
483 /* Nonzero means scroll just far enough to bring point back on the
484 screen, when appropriate. */
486 static EMACS_INT scroll_conservatively
;
488 /* Recenter the window whenever point gets within this many lines of
489 the top or bottom of the window. This value is translated into a
490 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
491 that there is really a fixed pixel height scroll margin. */
493 EMACS_INT scroll_margin
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* Zero means display the mode-line/header-line/menu-bar in the default face
506 (this slightly odd definition is for compatibility with previous versions
507 of emacs), non-zero means display them using their respective faces.
509 This variable is deprecated. */
511 int mode_line_inverse_video
;
513 /* Prompt to display in front of the mini-buffer contents. */
515 Lisp_Object minibuf_prompt
;
517 /* Width of current mini-buffer prompt. Only set after display_line
518 of the line that contains the prompt. */
520 int minibuf_prompt_width
;
522 /* This is the window where the echo area message was displayed. It
523 is always a mini-buffer window, but it may not be the same window
524 currently active as a mini-buffer. */
526 Lisp_Object echo_area_window
;
528 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
529 pushes the current message and the value of
530 message_enable_multibyte on the stack, the function restore_message
531 pops the stack and displays MESSAGE again. */
533 Lisp_Object Vmessage_stack
;
535 /* Nonzero means multibyte characters were enabled when the echo area
536 message was specified. */
538 int message_enable_multibyte
;
540 /* Nonzero if we should redraw the mode lines on the next redisplay. */
542 int update_mode_lines
;
544 /* Nonzero if window sizes or contents have changed since last
545 redisplay that finished. */
547 int windows_or_buffers_changed
;
549 /* Nonzero means a frame's cursor type has been changed. */
551 int cursor_type_changed
;
553 /* Nonzero after display_mode_line if %l was used and it displayed a
556 int line_number_displayed
;
558 /* Maximum buffer size for which to display line numbers. */
560 Lisp_Object Vline_number_display_limit
;
562 /* Line width to consider when repositioning for line number display. */
564 static EMACS_INT line_number_display_limit_width
;
566 /* Number of lines to keep in the message log buffer. t means
567 infinite. nil means don't log at all. */
569 Lisp_Object Vmessage_log_max
;
571 /* The name of the *Messages* buffer, a string. */
573 static Lisp_Object Vmessages_buffer_name
;
575 /* Current, index 0, and last displayed echo area message. Either
576 buffers from echo_buffers, or nil to indicate no message. */
578 Lisp_Object echo_area_buffer
[2];
580 /* The buffers referenced from echo_area_buffer. */
582 static Lisp_Object echo_buffer
[2];
584 /* A vector saved used in with_area_buffer to reduce consing. */
586 static Lisp_Object Vwith_echo_area_save_vector
;
588 /* Non-zero means display_echo_area should display the last echo area
589 message again. Set by redisplay_preserve_echo_area. */
591 static int display_last_displayed_message_p
;
593 /* Nonzero if echo area is being used by print; zero if being used by
596 int message_buf_print
;
598 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
600 Lisp_Object Qinhibit_menubar_update
;
601 int inhibit_menubar_update
;
603 /* Maximum height for resizing mini-windows. Either a float
604 specifying a fraction of the available height, or an integer
605 specifying a number of lines. */
607 Lisp_Object Vmax_mini_window_height
;
609 /* Non-zero means messages should be displayed with truncated
610 lines instead of being continued. */
612 int message_truncate_lines
;
613 Lisp_Object Qmessage_truncate_lines
;
615 /* Set to 1 in clear_message to make redisplay_internal aware
616 of an emptied echo area. */
618 static int message_cleared_p
;
620 /* How to blink the default frame cursor off. */
621 Lisp_Object Vblink_cursor_alist
;
623 /* A scratch glyph row with contents used for generating truncation
624 glyphs. Also used in direct_output_for_insert. */
626 #define MAX_SCRATCH_GLYPHS 100
627 struct glyph_row scratch_glyph_row
;
628 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
630 /* Ascent and height of the last line processed by move_it_to. */
632 static int last_max_ascent
, last_height
;
634 /* Non-zero if there's a help-echo in the echo area. */
636 int help_echo_showing_p
;
638 /* If >= 0, computed, exact values of mode-line and header-line height
639 to use in the macros CURRENT_MODE_LINE_HEIGHT and
640 CURRENT_HEADER_LINE_HEIGHT. */
642 int current_mode_line_height
, current_header_line_height
;
644 /* The maximum distance to look ahead for text properties. Values
645 that are too small let us call compute_char_face and similar
646 functions too often which is expensive. Values that are too large
647 let us call compute_char_face and alike too often because we
648 might not be interested in text properties that far away. */
650 #define TEXT_PROP_DISTANCE_LIMIT 100
654 /* Variables to turn off display optimizations from Lisp. */
656 int inhibit_try_window_id
, inhibit_try_window_reusing
;
657 int inhibit_try_cursor_movement
;
659 /* Non-zero means print traces of redisplay if compiled with
662 int trace_redisplay_p
;
664 #endif /* GLYPH_DEBUG */
666 #ifdef DEBUG_TRACE_MOVE
667 /* Non-zero means trace with TRACE_MOVE to stderr. */
670 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
672 #define TRACE_MOVE(x) (void) 0
675 /* Non-zero means automatically scroll windows horizontally to make
678 int automatic_hscrolling_p
;
680 /* How close to the margin can point get before the window is scrolled
682 EMACS_INT hscroll_margin
;
684 /* How much to scroll horizontally when point is inside the above margin. */
685 Lisp_Object Vhscroll_step
;
687 /* The variable `resize-mini-windows'. If nil, don't resize
688 mini-windows. If t, always resize them to fit the text they
689 display. If `grow-only', let mini-windows grow only until they
692 Lisp_Object Vresize_mini_windows
;
694 /* Buffer being redisplayed -- for redisplay_window_error. */
696 struct buffer
*displayed_buffer
;
698 /* Value returned from text property handlers (see below). */
703 HANDLED_RECOMPUTE_PROPS
,
704 HANDLED_OVERLAY_STRING_CONSUMED
,
708 /* A description of text properties that redisplay is interested
713 /* The name of the property. */
716 /* A unique index for the property. */
719 /* A handler function called to set up iterator IT from the property
720 at IT's current position. Value is used to steer handle_stop. */
721 enum prop_handled (*handler
) P_ ((struct it
*it
));
724 static enum prop_handled handle_face_prop
P_ ((struct it
*));
725 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
726 static enum prop_handled handle_display_prop
P_ ((struct it
*));
727 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
728 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
729 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
731 /* Properties handled by iterators. */
733 static struct props it_props
[] =
735 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
736 /* Handle `face' before `display' because some sub-properties of
737 `display' need to know the face. */
738 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
739 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
740 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
741 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
745 /* Value is the position described by X. If X is a marker, value is
746 the marker_position of X. Otherwise, value is X. */
748 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
750 /* Enumeration returned by some move_it_.* functions internally. */
754 /* Not used. Undefined value. */
757 /* Move ended at the requested buffer position or ZV. */
758 MOVE_POS_MATCH_OR_ZV
,
760 /* Move ended at the requested X pixel position. */
763 /* Move within a line ended at the end of a line that must be
767 /* Move within a line ended at the end of a line that would
768 be displayed truncated. */
771 /* Move within a line ended at a line end. */
775 /* This counter is used to clear the face cache every once in a while
776 in redisplay_internal. It is incremented for each redisplay.
777 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
780 #define CLEAR_FACE_CACHE_COUNT 500
781 static int clear_face_cache_count
;
783 /* Similarly for the image cache. */
785 #ifdef HAVE_WINDOW_SYSTEM
786 #define CLEAR_IMAGE_CACHE_COUNT 101
787 static int clear_image_cache_count
;
790 /* Non-zero while redisplay_internal is in progress. */
794 /* Non-zero means don't free realized faces. Bound while freeing
795 realized faces is dangerous because glyph matrices might still
798 int inhibit_free_realized_faces
;
799 Lisp_Object Qinhibit_free_realized_faces
;
801 /* If a string, XTread_socket generates an event to display that string.
802 (The display is done in read_char.) */
804 Lisp_Object help_echo_string
;
805 Lisp_Object help_echo_window
;
806 Lisp_Object help_echo_object
;
809 /* Temporary variable for XTread_socket. */
811 Lisp_Object previous_help_echo_string
;
813 /* Null glyph slice */
815 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
818 /* Function prototypes. */
820 static void setup_for_ellipsis
P_ ((struct it
*, int));
821 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
822 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
823 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
824 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
825 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
826 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
829 static int invisible_text_between_p
P_ ((struct it
*, int, int));
832 static void pint2str
P_ ((char *, int, int));
833 static void pint2hrstr
P_ ((char *, int, int));
834 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
836 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
837 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
838 static void store_mode_line_noprop_char
P_ ((char));
839 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
840 static void x_consider_frame_title
P_ ((Lisp_Object
));
841 static void handle_stop
P_ ((struct it
*));
842 static int tool_bar_lines_needed
P_ ((struct frame
*));
843 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
844 static void ensure_echo_area_buffers
P_ ((void));
845 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
846 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
847 static int with_echo_area_buffer
P_ ((struct window
*, int,
848 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
849 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
850 static void clear_garbaged_frames
P_ ((void));
851 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
852 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
853 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
854 static int display_echo_area
P_ ((struct window
*));
855 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
856 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
857 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
858 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
859 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
861 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
862 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
863 static void insert_left_trunc_glyphs
P_ ((struct it
*));
864 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
866 static void extend_face_to_end_of_line
P_ ((struct it
*));
867 static int append_space_for_newline
P_ ((struct it
*, int));
868 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
869 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
870 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
871 static int trailing_whitespace_p
P_ ((int));
872 static int message_log_check_duplicate
P_ ((int, int, int, int));
873 static void push_it
P_ ((struct it
*));
874 static void pop_it
P_ ((struct it
*));
875 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
876 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
877 static void redisplay_internal
P_ ((int));
878 static int echo_area_display
P_ ((int));
879 static void redisplay_windows
P_ ((Lisp_Object
));
880 static void redisplay_window
P_ ((Lisp_Object
, int));
881 static Lisp_Object
redisplay_window_error ();
882 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
883 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
884 static void update_menu_bar
P_ ((struct frame
*, int));
885 static int try_window_reusing_current_matrix
P_ ((struct window
*));
886 static int try_window_id
P_ ((struct window
*));
887 static int display_line
P_ ((struct it
*));
888 static int display_mode_lines
P_ ((struct window
*));
889 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
890 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
891 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
892 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
893 static void display_menu_bar
P_ ((struct window
*));
894 static int display_count_lines
P_ ((int, int, int, int, int *));
895 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
896 int, int, struct it
*, int, int, int, int));
897 static void compute_line_metrics
P_ ((struct it
*));
898 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
899 static int get_overlay_strings
P_ ((struct it
*, int));
900 static void next_overlay_string
P_ ((struct it
*));
901 static void reseat
P_ ((struct it
*, struct text_pos
, int));
902 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
903 static void back_to_previous_visible_line_start
P_ ((struct it
*));
904 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
905 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
906 static int next_element_from_ellipsis
P_ ((struct it
*));
907 static int next_element_from_display_vector
P_ ((struct it
*));
908 static int next_element_from_string
P_ ((struct it
*));
909 static int next_element_from_c_string
P_ ((struct it
*));
910 static int next_element_from_buffer
P_ ((struct it
*));
911 static int next_element_from_composition
P_ ((struct it
*));
912 static int next_element_from_image
P_ ((struct it
*));
913 static int next_element_from_stretch
P_ ((struct it
*));
914 static void load_overlay_strings
P_ ((struct it
*, int));
915 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
916 struct display_pos
*));
917 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
918 Lisp_Object
, int, int, int, int));
919 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
921 void move_it_vertically_backward
P_ ((struct it
*, int));
922 static void init_to_row_start
P_ ((struct it
*, struct window
*,
923 struct glyph_row
*));
924 static int init_to_row_end
P_ ((struct it
*, struct window
*,
925 struct glyph_row
*));
926 static void back_to_previous_line_start
P_ ((struct it
*));
927 static int forward_to_next_line_start
P_ ((struct it
*, int *));
928 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
930 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
931 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
932 static int number_of_chars
P_ ((unsigned char *, int));
933 static void compute_stop_pos
P_ ((struct it
*));
934 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
936 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
937 static int next_overlay_change
P_ ((int));
938 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
939 Lisp_Object
, struct text_pos
*,
941 static int underlying_face_id
P_ ((struct it
*));
942 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
945 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
946 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
948 #ifdef HAVE_WINDOW_SYSTEM
950 static void update_tool_bar
P_ ((struct frame
*, int));
951 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
952 static int redisplay_tool_bar
P_ ((struct frame
*));
953 static void display_tool_bar_line
P_ ((struct it
*));
954 static void notice_overwritten_cursor
P_ ((struct window
*,
956 int, int, int, int));
960 #endif /* HAVE_WINDOW_SYSTEM */
963 /***********************************************************************
964 Window display dimensions
965 ***********************************************************************/
967 /* Return the bottom boundary y-position for text lines in window W.
968 This is the first y position at which a line cannot start.
969 It is relative to the top of the window.
971 This is the height of W minus the height of a mode line, if any. */
974 window_text_bottom_y (w
)
977 int height
= WINDOW_TOTAL_HEIGHT (w
);
979 if (WINDOW_WANTS_MODELINE_P (w
))
980 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
984 /* Return the pixel width of display area AREA of window W. AREA < 0
985 means return the total width of W, not including fringes to
986 the left and right of the window. */
989 window_box_width (w
, area
)
993 int cols
= XFASTINT (w
->total_cols
);
996 if (!w
->pseudo_window_p
)
998 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1000 if (area
== TEXT_AREA
)
1002 if (INTEGERP (w
->left_margin_cols
))
1003 cols
-= XFASTINT (w
->left_margin_cols
);
1004 if (INTEGERP (w
->right_margin_cols
))
1005 cols
-= XFASTINT (w
->right_margin_cols
);
1006 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1008 else if (area
== LEFT_MARGIN_AREA
)
1010 cols
= (INTEGERP (w
->left_margin_cols
)
1011 ? XFASTINT (w
->left_margin_cols
) : 0);
1014 else if (area
== RIGHT_MARGIN_AREA
)
1016 cols
= (INTEGERP (w
->right_margin_cols
)
1017 ? XFASTINT (w
->right_margin_cols
) : 0);
1022 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1026 /* Return the pixel height of the display area of window W, not
1027 including mode lines of W, if any. */
1030 window_box_height (w
)
1033 struct frame
*f
= XFRAME (w
->frame
);
1034 int height
= WINDOW_TOTAL_HEIGHT (w
);
1036 xassert (height
>= 0);
1038 /* Note: the code below that determines the mode-line/header-line
1039 height is essentially the same as that contained in the macro
1040 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1041 the appropriate glyph row has its `mode_line_p' flag set,
1042 and if it doesn't, uses estimate_mode_line_height instead. */
1044 if (WINDOW_WANTS_MODELINE_P (w
))
1046 struct glyph_row
*ml_row
1047 = (w
->current_matrix
&& w
->current_matrix
->rows
1048 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1050 if (ml_row
&& ml_row
->mode_line_p
)
1051 height
-= ml_row
->height
;
1053 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1056 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1058 struct glyph_row
*hl_row
1059 = (w
->current_matrix
&& w
->current_matrix
->rows
1060 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1062 if (hl_row
&& hl_row
->mode_line_p
)
1063 height
-= hl_row
->height
;
1065 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1068 /* With a very small font and a mode-line that's taller than
1069 default, we might end up with a negative height. */
1070 return max (0, height
);
1073 /* Return the window-relative coordinate of the left edge of display
1074 area AREA of window W. AREA < 0 means return the left edge of the
1075 whole window, to the right of the left fringe of W. */
1078 window_box_left_offset (w
, area
)
1084 if (w
->pseudo_window_p
)
1087 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1089 if (area
== TEXT_AREA
)
1090 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1091 + window_box_width (w
, LEFT_MARGIN_AREA
));
1092 else if (area
== RIGHT_MARGIN_AREA
)
1093 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1094 + window_box_width (w
, LEFT_MARGIN_AREA
)
1095 + window_box_width (w
, TEXT_AREA
)
1096 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1098 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1099 else if (area
== LEFT_MARGIN_AREA
1100 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1101 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1107 /* Return the window-relative coordinate of the right edge of display
1108 area AREA of window W. AREA < 0 means return the left edge of the
1109 whole window, to the left of the right fringe of W. */
1112 window_box_right_offset (w
, area
)
1116 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1119 /* Return the frame-relative coordinate of the left edge of display
1120 area AREA of window W. AREA < 0 means return the left edge of the
1121 whole window, to the right of the left fringe of W. */
1124 window_box_left (w
, area
)
1128 struct frame
*f
= XFRAME (w
->frame
);
1131 if (w
->pseudo_window_p
)
1132 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1134 x
= (WINDOW_LEFT_EDGE_X (w
)
1135 + window_box_left_offset (w
, area
));
1141 /* Return the frame-relative coordinate of the right edge of display
1142 area AREA of window W. AREA < 0 means return the left edge of the
1143 whole window, to the left of the right fringe of W. */
1146 window_box_right (w
, area
)
1150 return window_box_left (w
, area
) + window_box_width (w
, area
);
1153 /* Get the bounding box of the display area AREA of window W, without
1154 mode lines, in frame-relative coordinates. AREA < 0 means the
1155 whole window, not including the left and right fringes of
1156 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1157 coordinates of the upper-left corner of the box. Return in
1158 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1161 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1164 int *box_x
, *box_y
, *box_width
, *box_height
;
1167 *box_width
= window_box_width (w
, area
);
1169 *box_height
= window_box_height (w
);
1171 *box_x
= window_box_left (w
, area
);
1174 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1175 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1176 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1181 /* Get the bounding box of the display area AREA of window W, without
1182 mode lines. AREA < 0 means the whole window, not including the
1183 left and right fringe of the window. Return in *TOP_LEFT_X
1184 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1185 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1186 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1190 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1191 bottom_right_x
, bottom_right_y
)
1194 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1196 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1198 *bottom_right_x
+= *top_left_x
;
1199 *bottom_right_y
+= *top_left_y
;
1204 /***********************************************************************
1206 ***********************************************************************/
1208 /* Return the bottom y-position of the line the iterator IT is in.
1209 This can modify IT's settings. */
1215 int line_height
= it
->max_ascent
+ it
->max_descent
;
1216 int line_top_y
= it
->current_y
;
1218 if (line_height
== 0)
1221 line_height
= last_height
;
1222 else if (IT_CHARPOS (*it
) < ZV
)
1224 move_it_by_lines (it
, 1, 1);
1225 line_height
= (it
->max_ascent
|| it
->max_descent
1226 ? it
->max_ascent
+ it
->max_descent
1231 struct glyph_row
*row
= it
->glyph_row
;
1233 /* Use the default character height. */
1234 it
->glyph_row
= NULL
;
1235 it
->what
= IT_CHARACTER
;
1238 PRODUCE_GLYPHS (it
);
1239 line_height
= it
->ascent
+ it
->descent
;
1240 it
->glyph_row
= row
;
1244 return line_top_y
+ line_height
;
1248 /* Return 1 if position CHARPOS is visible in window W.
1249 If visible, set *X and *Y to pixel coordinates of top left corner.
1250 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1251 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1252 and header-lines heights. */
1255 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1257 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1260 struct text_pos top
;
1262 struct buffer
*old_buffer
= NULL
;
1267 if (XBUFFER (w
->buffer
) != current_buffer
)
1269 old_buffer
= current_buffer
;
1270 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1273 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1275 /* Compute exact mode line heights, if requested. */
1276 if (exact_mode_line_heights_p
)
1278 if (WINDOW_WANTS_MODELINE_P (w
))
1279 current_mode_line_height
1280 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1281 current_buffer
->mode_line_format
);
1283 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1284 current_header_line_height
1285 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1286 current_buffer
->header_line_format
);
1289 start_display (&it
, w
, top
);
1290 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1291 MOVE_TO_POS
| MOVE_TO_Y
);
1293 /* Note that we may overshoot because of invisible text. */
1294 if (IT_CHARPOS (it
) >= charpos
)
1296 int top_x
= it
.current_x
;
1297 int top_y
= it
.current_y
;
1298 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1299 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1301 if (top_y
< window_top_y
)
1302 visible_p
= bottom_y
> window_top_y
;
1303 else if (top_y
< it
.last_visible_y
)
1308 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1309 *rtop
= max (0, window_top_y
- top_y
);
1310 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1318 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1319 move_it_by_lines (&it
, 1, 0);
1320 if (charpos
< IT_CHARPOS (it
))
1323 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1325 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1326 *rtop
= max (0, -it2
.current_y
);
1327 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1328 - it
.last_visible_y
));
1333 set_buffer_internal_1 (old_buffer
);
1335 current_header_line_height
= current_mode_line_height
= -1;
1337 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1338 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1344 /* Return the next character from STR which is MAXLEN bytes long.
1345 Return in *LEN the length of the character. This is like
1346 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1347 we find one, we return a `?', but with the length of the invalid
1351 string_char_and_length (str
, maxlen
, len
)
1352 const unsigned char *str
;
1357 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1358 if (!CHAR_VALID_P (c
, 1))
1359 /* We may not change the length here because other places in Emacs
1360 don't use this function, i.e. they silently accept invalid
1369 /* Given a position POS containing a valid character and byte position
1370 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1372 static struct text_pos
1373 string_pos_nchars_ahead (pos
, string
, nchars
)
1374 struct text_pos pos
;
1378 xassert (STRINGP (string
) && nchars
>= 0);
1380 if (STRING_MULTIBYTE (string
))
1382 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1383 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1388 string_char_and_length (p
, rest
, &len
);
1389 p
+= len
, rest
-= len
;
1390 xassert (rest
>= 0);
1392 BYTEPOS (pos
) += len
;
1396 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1402 /* Value is the text position, i.e. character and byte position,
1403 for character position CHARPOS in STRING. */
1405 static INLINE
struct text_pos
1406 string_pos (charpos
, string
)
1410 struct text_pos pos
;
1411 xassert (STRINGP (string
));
1412 xassert (charpos
>= 0);
1413 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1418 /* Value is a text position, i.e. character and byte position, for
1419 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1420 means recognize multibyte characters. */
1422 static struct text_pos
1423 c_string_pos (charpos
, s
, multibyte_p
)
1428 struct text_pos pos
;
1430 xassert (s
!= NULL
);
1431 xassert (charpos
>= 0);
1435 int rest
= strlen (s
), len
;
1437 SET_TEXT_POS (pos
, 0, 0);
1440 string_char_and_length (s
, rest
, &len
);
1441 s
+= len
, rest
-= len
;
1442 xassert (rest
>= 0);
1444 BYTEPOS (pos
) += len
;
1448 SET_TEXT_POS (pos
, charpos
, charpos
);
1454 /* Value is the number of characters in C string S. MULTIBYTE_P
1455 non-zero means recognize multibyte characters. */
1458 number_of_chars (s
, multibyte_p
)
1466 int rest
= strlen (s
), len
;
1467 unsigned char *p
= (unsigned char *) s
;
1469 for (nchars
= 0; rest
> 0; ++nchars
)
1471 string_char_and_length (p
, rest
, &len
);
1472 rest
-= len
, p
+= len
;
1476 nchars
= strlen (s
);
1482 /* Compute byte position NEWPOS->bytepos corresponding to
1483 NEWPOS->charpos. POS is a known position in string STRING.
1484 NEWPOS->charpos must be >= POS.charpos. */
1487 compute_string_pos (newpos
, pos
, string
)
1488 struct text_pos
*newpos
, pos
;
1491 xassert (STRINGP (string
));
1492 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1494 if (STRING_MULTIBYTE (string
))
1495 *newpos
= string_pos_nchars_ahead (pos
, string
,
1496 CHARPOS (*newpos
) - CHARPOS (pos
));
1498 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1502 Return an estimation of the pixel height of mode or top lines on
1503 frame F. FACE_ID specifies what line's height to estimate. */
1506 estimate_mode_line_height (f
, face_id
)
1508 enum face_id face_id
;
1510 #ifdef HAVE_WINDOW_SYSTEM
1511 if (FRAME_WINDOW_P (f
))
1513 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1515 /* This function is called so early when Emacs starts that the face
1516 cache and mode line face are not yet initialized. */
1517 if (FRAME_FACE_CACHE (f
))
1519 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1523 height
= FONT_HEIGHT (face
->font
);
1524 if (face
->box_line_width
> 0)
1525 height
+= 2 * face
->box_line_width
;
1536 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1537 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1538 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1539 not force the value into range. */
1542 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1544 register int pix_x
, pix_y
;
1546 NativeRectangle
*bounds
;
1550 #ifdef HAVE_WINDOW_SYSTEM
1551 if (FRAME_WINDOW_P (f
))
1553 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1554 even for negative values. */
1556 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1558 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1560 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1561 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1564 STORE_NATIVE_RECT (*bounds
,
1565 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1566 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1567 FRAME_COLUMN_WIDTH (f
) - 1,
1568 FRAME_LINE_HEIGHT (f
) - 1);
1574 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1575 pix_x
= FRAME_TOTAL_COLS (f
);
1579 else if (pix_y
> FRAME_LINES (f
))
1580 pix_y
= FRAME_LINES (f
);
1590 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1591 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1592 can't tell the positions because W's display is not up to date,
1596 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1599 int *frame_x
, *frame_y
;
1601 #ifdef HAVE_WINDOW_SYSTEM
1602 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1606 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1607 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1609 if (display_completed
)
1611 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1612 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1613 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1619 hpos
+= glyph
->pixel_width
;
1623 /* If first glyph is partially visible, its first visible position is still 0. */
1635 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1636 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1647 #ifdef HAVE_WINDOW_SYSTEM
1649 /* Find the glyph under window-relative coordinates X/Y in window W.
1650 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1651 strings. Return in *HPOS and *VPOS the row and column number of
1652 the glyph found. Return in *AREA the glyph area containing X.
1653 Value is a pointer to the glyph found or null if X/Y is not on
1654 text, or we can't tell because W's current matrix is not up to
1657 static struct glyph
*
1658 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1661 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1663 struct glyph
*glyph
, *end
;
1664 struct glyph_row
*row
= NULL
;
1667 /* Find row containing Y. Give up if some row is not enabled. */
1668 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1670 row
= MATRIX_ROW (w
->current_matrix
, i
);
1671 if (!row
->enabled_p
)
1673 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1680 /* Give up if Y is not in the window. */
1681 if (i
== w
->current_matrix
->nrows
)
1684 /* Get the glyph area containing X. */
1685 if (w
->pseudo_window_p
)
1692 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1694 *area
= LEFT_MARGIN_AREA
;
1695 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1697 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1700 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1704 *area
= RIGHT_MARGIN_AREA
;
1705 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1709 /* Find glyph containing X. */
1710 glyph
= row
->glyphs
[*area
];
1711 end
= glyph
+ row
->used
[*area
];
1713 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1715 x
-= glyph
->pixel_width
;
1725 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1728 *hpos
= glyph
- row
->glyphs
[*area
];
1734 Convert frame-relative x/y to coordinates relative to window W.
1735 Takes pseudo-windows into account. */
1738 frame_to_window_pixel_xy (w
, x
, y
)
1742 if (w
->pseudo_window_p
)
1744 /* A pseudo-window is always full-width, and starts at the
1745 left edge of the frame, plus a frame border. */
1746 struct frame
*f
= XFRAME (w
->frame
);
1747 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1748 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1752 *x
-= WINDOW_LEFT_EDGE_X (w
);
1753 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1758 Return in RECTS[] at most N clipping rectangles for glyph string S.
1759 Return the number of stored rectangles. */
1762 get_glyph_string_clip_rects (s
, rects
, n
)
1763 struct glyph_string
*s
;
1764 NativeRectangle
*rects
;
1772 if (s
->row
->full_width_p
)
1774 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1775 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1776 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1778 /* Unless displaying a mode or menu bar line, which are always
1779 fully visible, clip to the visible part of the row. */
1780 if (s
->w
->pseudo_window_p
)
1781 r
.height
= s
->row
->visible_height
;
1783 r
.height
= s
->height
;
1787 /* This is a text line that may be partially visible. */
1788 r
.x
= window_box_left (s
->w
, s
->area
);
1789 r
.width
= window_box_width (s
->w
, s
->area
);
1790 r
.height
= s
->row
->visible_height
;
1794 if (r
.x
< s
->clip_head
->x
)
1796 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1797 r
.width
-= s
->clip_head
->x
- r
.x
;
1800 r
.x
= s
->clip_head
->x
;
1803 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1805 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1806 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1811 /* If S draws overlapping rows, it's sufficient to use the top and
1812 bottom of the window for clipping because this glyph string
1813 intentionally draws over other lines. */
1814 if (s
->for_overlaps
)
1816 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1817 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1819 /* Alas, the above simple strategy does not work for the
1820 environments with anti-aliased text: if the same text is
1821 drawn onto the same place multiple times, it gets thicker.
1822 If the overlap we are processing is for the erased cursor, we
1823 take the intersection with the rectagle of the cursor. */
1824 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1826 XRectangle rc
, r_save
= r
;
1828 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1829 rc
.y
= s
->w
->phys_cursor
.y
;
1830 rc
.width
= s
->w
->phys_cursor_width
;
1831 rc
.height
= s
->w
->phys_cursor_height
;
1833 x_intersect_rectangles (&r_save
, &rc
, &r
);
1838 /* Don't use S->y for clipping because it doesn't take partially
1839 visible lines into account. For example, it can be negative for
1840 partially visible lines at the top of a window. */
1841 if (!s
->row
->full_width_p
1842 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1843 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1845 r
.y
= max (0, s
->row
->y
);
1847 /* If drawing a tool-bar window, draw it over the internal border
1848 at the top of the window. */
1849 if (WINDOWP (s
->f
->tool_bar_window
)
1850 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1851 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1854 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1856 /* If drawing the cursor, don't let glyph draw outside its
1857 advertised boundaries. Cleartype does this under some circumstances. */
1858 if (s
->hl
== DRAW_CURSOR
)
1860 struct glyph
*glyph
= s
->first_glyph
;
1865 r
.width
-= s
->x
- r
.x
;
1868 r
.width
= min (r
.width
, glyph
->pixel_width
);
1870 /* If r.y is below window bottom, ensure that we still see a cursor. */
1871 height
= min (glyph
->ascent
+ glyph
->descent
,
1872 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1873 max_y
= window_text_bottom_y (s
->w
) - height
;
1874 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1875 if (s
->ybase
- glyph
->ascent
> max_y
)
1882 /* Don't draw cursor glyph taller than our actual glyph. */
1883 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1884 if (height
< r
.height
)
1886 max_y
= r
.y
+ r
.height
;
1887 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1888 r
.height
= min (max_y
- r
.y
, height
);
1893 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1894 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1896 #ifdef CONVERT_FROM_XRECT
1897 CONVERT_FROM_XRECT (r
, *rects
);
1905 /* If we are processing overlapping and allowed to return
1906 multiple clipping rectangles, we exclude the row of the glyph
1907 string from the clipping rectangle. This is to avoid drawing
1908 the same text on the environment with anti-aliasing. */
1909 #ifdef CONVERT_FROM_XRECT
1912 XRectangle
*rs
= rects
;
1914 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1916 if (s
->for_overlaps
& OVERLAPS_PRED
)
1919 if (r
.y
+ r
.height
> row_y
)
1922 rs
[i
].height
= row_y
- r
.y
;
1928 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1931 if (r
.y
< row_y
+ s
->row
->visible_height
)
1933 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1935 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1936 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1945 #ifdef CONVERT_FROM_XRECT
1946 for (i
= 0; i
< n
; i
++)
1947 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1954 Return in *NR the clipping rectangle for glyph string S. */
1957 get_glyph_string_clip_rect (s
, nr
)
1958 struct glyph_string
*s
;
1959 NativeRectangle
*nr
;
1961 get_glyph_string_clip_rects (s
, nr
, 1);
1966 Return the position and height of the phys cursor in window W.
1967 Set w->phys_cursor_width to width of phys cursor.
1971 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1973 struct glyph_row
*row
;
1974 struct glyph
*glyph
;
1977 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1978 int y
, wd
, h
, h0
, y0
;
1980 /* Compute the width of the rectangle to draw. If on a stretch
1981 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1982 rectangle as wide as the glyph, but use a canonical character
1984 wd
= glyph
->pixel_width
- 1;
1988 if (glyph
->type
== STRETCH_GLYPH
1989 && !x_stretch_cursor_p
)
1990 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1991 w
->phys_cursor_width
= wd
;
1993 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1995 /* If y is below window bottom, ensure that we still see a cursor. */
1996 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1998 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1999 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2001 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2004 h
= max (h
- (y0
- y
) + 1, h0
);
2009 y0
= window_text_bottom_y (w
) - h0
;
2018 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2022 * Remember which glyph the mouse is over.
2026 remember_mouse_glyph (f
, gx
, gy
, rect
)
2029 NativeRectangle
*rect
;
2033 struct glyph_row
*r
, *gr
, *end_row
;
2034 enum window_part part
;
2035 enum glyph_row_area area
;
2036 int x
, y
, width
, height
;
2038 /* Try to determine frame pixel position and size of the glyph under
2039 frame pixel coordinates X/Y on frame F. */
2041 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2044 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2045 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2049 w
= XWINDOW (window
);
2050 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2051 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2053 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2054 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2056 if (w
->pseudo_window_p
)
2059 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2065 case ON_LEFT_MARGIN
:
2066 area
= LEFT_MARGIN_AREA
;
2069 case ON_RIGHT_MARGIN
:
2070 area
= RIGHT_MARGIN_AREA
;
2073 case ON_HEADER_LINE
:
2075 gr
= (part
== ON_HEADER_LINE
2076 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2077 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2080 goto text_glyph_row_found
;
2087 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2088 if (r
->y
+ r
->height
> y
)
2094 text_glyph_row_found
:
2097 struct glyph
*g
= gr
->glyphs
[area
];
2098 struct glyph
*end
= g
+ gr
->used
[area
];
2100 height
= gr
->height
;
2101 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2102 if (gx
+ g
->pixel_width
> x
)
2107 if (g
->type
== IMAGE_GLYPH
)
2109 /* Don't remember when mouse is over image, as
2110 image may have hot-spots. */
2111 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2114 width
= g
->pixel_width
;
2118 /* Use nominal char spacing at end of line. */
2120 gx
+= (x
/ width
) * width
;
2123 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2124 gx
+= window_box_left_offset (w
, area
);
2128 /* Use nominal line height at end of window. */
2129 gx
= (x
/ width
) * width
;
2131 gy
+= (y
/ height
) * height
;
2135 case ON_LEFT_FRINGE
:
2136 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2137 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2138 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2139 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2142 case ON_RIGHT_FRINGE
:
2143 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2144 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2145 : window_box_right_offset (w
, TEXT_AREA
));
2146 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2150 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2152 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2153 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2154 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2156 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2160 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2161 if (r
->y
+ r
->height
> y
)
2168 height
= gr
->height
;
2171 /* Use nominal line height at end of window. */
2173 gy
+= (y
/ height
) * height
;
2180 /* If there is no glyph under the mouse, then we divide the screen
2181 into a grid of the smallest glyph in the frame, and use that
2184 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2185 round down even for negative values. */
2191 gx
= (gx
/ width
) * width
;
2192 gy
= (gy
/ height
) * height
;
2197 gx
+= WINDOW_LEFT_EDGE_X (w
);
2198 gy
+= WINDOW_TOP_EDGE_Y (w
);
2201 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2203 /* Visible feedback for debugging. */
2206 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2207 f
->output_data
.x
->normal_gc
,
2208 gx
, gy
, width
, height
);
2214 #endif /* HAVE_WINDOW_SYSTEM */
2217 /***********************************************************************
2218 Lisp form evaluation
2219 ***********************************************************************/
2221 /* Error handler for safe_eval and safe_call. */
2224 safe_eval_handler (arg
)
2227 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2232 /* Evaluate SEXPR and return the result, or nil if something went
2233 wrong. Prevent redisplay during the evaluation. */
2241 if (inhibit_eval_during_redisplay
)
2245 int count
= SPECPDL_INDEX ();
2246 struct gcpro gcpro1
;
2249 specbind (Qinhibit_redisplay
, Qt
);
2250 /* Use Qt to ensure debugger does not run,
2251 so there is no possibility of wanting to redisplay. */
2252 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2255 val
= unbind_to (count
, val
);
2262 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2263 Return the result, or nil if something went wrong. Prevent
2264 redisplay during the evaluation. */
2267 safe_call (nargs
, args
)
2273 if (inhibit_eval_during_redisplay
)
2277 int count
= SPECPDL_INDEX ();
2278 struct gcpro gcpro1
;
2281 gcpro1
.nvars
= nargs
;
2282 specbind (Qinhibit_redisplay
, Qt
);
2283 /* Use Qt to ensure debugger does not run,
2284 so there is no possibility of wanting to redisplay. */
2285 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2288 val
= unbind_to (count
, val
);
2295 /* Call function FN with one argument ARG.
2296 Return the result, or nil if something went wrong. */
2299 safe_call1 (fn
, arg
)
2300 Lisp_Object fn
, arg
;
2302 Lisp_Object args
[2];
2305 return safe_call (2, args
);
2310 /***********************************************************************
2312 ***********************************************************************/
2316 /* Define CHECK_IT to perform sanity checks on iterators.
2317 This is for debugging. It is too slow to do unconditionally. */
2323 if (it
->method
== GET_FROM_STRING
)
2325 xassert (STRINGP (it
->string
));
2326 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2330 xassert (IT_STRING_CHARPOS (*it
) < 0);
2331 if (it
->method
== GET_FROM_BUFFER
)
2333 /* Check that character and byte positions agree. */
2334 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2339 xassert (it
->current
.dpvec_index
>= 0);
2341 xassert (it
->current
.dpvec_index
< 0);
2344 #define CHECK_IT(IT) check_it ((IT))
2348 #define CHECK_IT(IT) (void) 0
2355 /* Check that the window end of window W is what we expect it
2356 to be---the last row in the current matrix displaying text. */
2359 check_window_end (w
)
2362 if (!MINI_WINDOW_P (w
)
2363 && !NILP (w
->window_end_valid
))
2365 struct glyph_row
*row
;
2366 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2367 XFASTINT (w
->window_end_vpos
)),
2369 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2370 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2374 #define CHECK_WINDOW_END(W) check_window_end ((W))
2376 #else /* not GLYPH_DEBUG */
2378 #define CHECK_WINDOW_END(W) (void) 0
2380 #endif /* not GLYPH_DEBUG */
2384 /***********************************************************************
2385 Iterator initialization
2386 ***********************************************************************/
2388 /* Initialize IT for displaying current_buffer in window W, starting
2389 at character position CHARPOS. CHARPOS < 0 means that no buffer
2390 position is specified which is useful when the iterator is assigned
2391 a position later. BYTEPOS is the byte position corresponding to
2392 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2394 If ROW is not null, calls to produce_glyphs with IT as parameter
2395 will produce glyphs in that row.
2397 BASE_FACE_ID is the id of a base face to use. It must be one of
2398 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2399 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2400 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2402 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2403 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2404 will be initialized to use the corresponding mode line glyph row of
2405 the desired matrix of W. */
2408 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2411 int charpos
, bytepos
;
2412 struct glyph_row
*row
;
2413 enum face_id base_face_id
;
2415 int highlight_region_p
;
2417 /* Some precondition checks. */
2418 xassert (w
!= NULL
&& it
!= NULL
);
2419 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2422 /* If face attributes have been changed since the last redisplay,
2423 free realized faces now because they depend on face definitions
2424 that might have changed. Don't free faces while there might be
2425 desired matrices pending which reference these faces. */
2426 if (face_change_count
&& !inhibit_free_realized_faces
)
2428 face_change_count
= 0;
2429 free_all_realized_faces (Qnil
);
2432 /* Use one of the mode line rows of W's desired matrix if
2436 if (base_face_id
== MODE_LINE_FACE_ID
2437 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2438 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2439 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2440 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2444 bzero (it
, sizeof *it
);
2445 it
->current
.overlay_string_index
= -1;
2446 it
->current
.dpvec_index
= -1;
2447 it
->base_face_id
= base_face_id
;
2449 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2451 /* The window in which we iterate over current_buffer: */
2452 XSETWINDOW (it
->window
, w
);
2454 it
->f
= XFRAME (w
->frame
);
2456 /* Extra space between lines (on window systems only). */
2457 if (base_face_id
== DEFAULT_FACE_ID
2458 && FRAME_WINDOW_P (it
->f
))
2460 if (NATNUMP (current_buffer
->extra_line_spacing
))
2461 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2462 else if (FLOATP (current_buffer
->extra_line_spacing
))
2463 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2464 * FRAME_LINE_HEIGHT (it
->f
));
2465 else if (it
->f
->extra_line_spacing
> 0)
2466 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2467 it
->max_extra_line_spacing
= 0;
2470 /* If realized faces have been removed, e.g. because of face
2471 attribute changes of named faces, recompute them. When running
2472 in batch mode, the face cache of the initial frame is null. If
2473 we happen to get called, make a dummy face cache. */
2474 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2475 init_frame_faces (it
->f
);
2476 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2477 recompute_basic_faces (it
->f
);
2479 /* Current value of the `slice', `space-width', and 'height' properties. */
2480 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2481 it
->space_width
= Qnil
;
2482 it
->font_height
= Qnil
;
2483 it
->override_ascent
= -1;
2485 /* Are control characters displayed as `^C'? */
2486 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2488 /* -1 means everything between a CR and the following line end
2489 is invisible. >0 means lines indented more than this value are
2491 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2492 ? XFASTINT (current_buffer
->selective_display
)
2493 : (!NILP (current_buffer
->selective_display
)
2495 it
->selective_display_ellipsis_p
2496 = !NILP (current_buffer
->selective_display_ellipses
);
2498 /* Display table to use. */
2499 it
->dp
= window_display_table (w
);
2501 /* Are multibyte characters enabled in current_buffer? */
2502 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2504 /* Non-zero if we should highlight the region. */
2506 = (!NILP (Vtransient_mark_mode
)
2507 && !NILP (current_buffer
->mark_active
)
2508 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2510 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2511 start and end of a visible region in window IT->w. Set both to
2512 -1 to indicate no region. */
2513 if (highlight_region_p
2514 /* Maybe highlight only in selected window. */
2515 && (/* Either show region everywhere. */
2516 highlight_nonselected_windows
2517 /* Or show region in the selected window. */
2518 || w
== XWINDOW (selected_window
)
2519 /* Or show the region if we are in the mini-buffer and W is
2520 the window the mini-buffer refers to. */
2521 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2522 && WINDOWP (minibuf_selected_window
)
2523 && w
== XWINDOW (minibuf_selected_window
))))
2525 int charpos
= marker_position (current_buffer
->mark
);
2526 it
->region_beg_charpos
= min (PT
, charpos
);
2527 it
->region_end_charpos
= max (PT
, charpos
);
2530 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2532 /* Get the position at which the redisplay_end_trigger hook should
2533 be run, if it is to be run at all. */
2534 if (MARKERP (w
->redisplay_end_trigger
)
2535 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2536 it
->redisplay_end_trigger_charpos
2537 = marker_position (w
->redisplay_end_trigger
);
2538 else if (INTEGERP (w
->redisplay_end_trigger
))
2539 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2541 /* Correct bogus values of tab_width. */
2542 it
->tab_width
= XINT (current_buffer
->tab_width
);
2543 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2546 /* Are lines in the display truncated? */
2547 it
->truncate_lines_p
2548 = (base_face_id
!= DEFAULT_FACE_ID
2549 || XINT (it
->w
->hscroll
)
2550 || (truncate_partial_width_windows
2551 && !WINDOW_FULL_WIDTH_P (it
->w
))
2552 || !NILP (current_buffer
->truncate_lines
));
2554 /* Get dimensions of truncation and continuation glyphs. These are
2555 displayed as fringe bitmaps under X, so we don't need them for such
2557 if (!FRAME_WINDOW_P (it
->f
))
2559 if (it
->truncate_lines_p
)
2561 /* We will need the truncation glyph. */
2562 xassert (it
->glyph_row
== NULL
);
2563 produce_special_glyphs (it
, IT_TRUNCATION
);
2564 it
->truncation_pixel_width
= it
->pixel_width
;
2568 /* We will need the continuation glyph. */
2569 xassert (it
->glyph_row
== NULL
);
2570 produce_special_glyphs (it
, IT_CONTINUATION
);
2571 it
->continuation_pixel_width
= it
->pixel_width
;
2574 /* Reset these values to zero because the produce_special_glyphs
2575 above has changed them. */
2576 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2577 it
->phys_ascent
= it
->phys_descent
= 0;
2580 /* Set this after getting the dimensions of truncation and
2581 continuation glyphs, so that we don't produce glyphs when calling
2582 produce_special_glyphs, above. */
2583 it
->glyph_row
= row
;
2584 it
->area
= TEXT_AREA
;
2586 /* Get the dimensions of the display area. The display area
2587 consists of the visible window area plus a horizontally scrolled
2588 part to the left of the window. All x-values are relative to the
2589 start of this total display area. */
2590 if (base_face_id
!= DEFAULT_FACE_ID
)
2592 /* Mode lines, menu bar in terminal frames. */
2593 it
->first_visible_x
= 0;
2594 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2599 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2600 it
->last_visible_x
= (it
->first_visible_x
2601 + window_box_width (w
, TEXT_AREA
));
2603 /* If we truncate lines, leave room for the truncator glyph(s) at
2604 the right margin. Otherwise, leave room for the continuation
2605 glyph(s). Truncation and continuation glyphs are not inserted
2606 for window-based redisplay. */
2607 if (!FRAME_WINDOW_P (it
->f
))
2609 if (it
->truncate_lines_p
)
2610 it
->last_visible_x
-= it
->truncation_pixel_width
;
2612 it
->last_visible_x
-= it
->continuation_pixel_width
;
2615 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2616 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2619 /* Leave room for a border glyph. */
2620 if (!FRAME_WINDOW_P (it
->f
)
2621 && !WINDOW_RIGHTMOST_P (it
->w
))
2622 it
->last_visible_x
-= 1;
2624 it
->last_visible_y
= window_text_bottom_y (w
);
2626 /* For mode lines and alike, arrange for the first glyph having a
2627 left box line if the face specifies a box. */
2628 if (base_face_id
!= DEFAULT_FACE_ID
)
2632 it
->face_id
= base_face_id
;
2634 /* If we have a boxed mode line, make the first character appear
2635 with a left box line. */
2636 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2637 if (face
->box
!= FACE_NO_BOX
)
2638 it
->start_of_box_run_p
= 1;
2641 /* If a buffer position was specified, set the iterator there,
2642 getting overlays and face properties from that position. */
2643 if (charpos
>= BUF_BEG (current_buffer
))
2645 it
->end_charpos
= ZV
;
2647 IT_CHARPOS (*it
) = charpos
;
2649 /* Compute byte position if not specified. */
2650 if (bytepos
< charpos
)
2651 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2653 IT_BYTEPOS (*it
) = bytepos
;
2655 it
->start
= it
->current
;
2657 /* Compute faces etc. */
2658 reseat (it
, it
->current
.pos
, 1);
2665 /* Initialize IT for the display of window W with window start POS. */
2668 start_display (it
, w
, pos
)
2671 struct text_pos pos
;
2673 struct glyph_row
*row
;
2674 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2676 row
= w
->desired_matrix
->rows
+ first_vpos
;
2677 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2678 it
->first_vpos
= first_vpos
;
2680 /* Don't reseat to previous visible line start if current start
2681 position is in a string or image. */
2682 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2684 int start_at_line_beg_p
;
2685 int first_y
= it
->current_y
;
2687 /* If window start is not at a line start, skip forward to POS to
2688 get the correct continuation lines width. */
2689 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2690 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2691 if (!start_at_line_beg_p
)
2695 reseat_at_previous_visible_line_start (it
);
2696 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2698 new_x
= it
->current_x
+ it
->pixel_width
;
2700 /* If lines are continued, this line may end in the middle
2701 of a multi-glyph character (e.g. a control character
2702 displayed as \003, or in the middle of an overlay
2703 string). In this case move_it_to above will not have
2704 taken us to the start of the continuation line but to the
2705 end of the continued line. */
2706 if (it
->current_x
> 0
2707 && !it
->truncate_lines_p
/* Lines are continued. */
2708 && (/* And glyph doesn't fit on the line. */
2709 new_x
> it
->last_visible_x
2710 /* Or it fits exactly and we're on a window
2712 || (new_x
== it
->last_visible_x
2713 && FRAME_WINDOW_P (it
->f
))))
2715 if (it
->current
.dpvec_index
>= 0
2716 || it
->current
.overlay_string_index
>= 0)
2718 set_iterator_to_next (it
, 1);
2719 move_it_in_display_line_to (it
, -1, -1, 0);
2722 it
->continuation_lines_width
+= it
->current_x
;
2725 /* We're starting a new display line, not affected by the
2726 height of the continued line, so clear the appropriate
2727 fields in the iterator structure. */
2728 it
->max_ascent
= it
->max_descent
= 0;
2729 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2731 it
->current_y
= first_y
;
2733 it
->current_x
= it
->hpos
= 0;
2737 #if 0 /* Don't assert the following because start_display is sometimes
2738 called intentionally with a window start that is not at a
2739 line start. Please leave this code in as a comment. */
2741 /* Window start should be on a line start, now. */
2742 xassert (it
->continuation_lines_width
2743 || IT_CHARPOS (it
) == BEGV
2744 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2749 /* Return 1 if POS is a position in ellipses displayed for invisible
2750 text. W is the window we display, for text property lookup. */
2753 in_ellipses_for_invisible_text_p (pos
, w
)
2754 struct display_pos
*pos
;
2757 Lisp_Object prop
, window
;
2759 int charpos
= CHARPOS (pos
->pos
);
2761 /* If POS specifies a position in a display vector, this might
2762 be for an ellipsis displayed for invisible text. We won't
2763 get the iterator set up for delivering that ellipsis unless
2764 we make sure that it gets aware of the invisible text. */
2765 if (pos
->dpvec_index
>= 0
2766 && pos
->overlay_string_index
< 0
2767 && CHARPOS (pos
->string_pos
) < 0
2769 && (XSETWINDOW (window
, w
),
2770 prop
= Fget_char_property (make_number (charpos
),
2771 Qinvisible
, window
),
2772 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2774 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2776 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2783 /* Initialize IT for stepping through current_buffer in window W,
2784 starting at position POS that includes overlay string and display
2785 vector/ control character translation position information. Value
2786 is zero if there are overlay strings with newlines at POS. */
2789 init_from_display_pos (it
, w
, pos
)
2792 struct display_pos
*pos
;
2794 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2795 int i
, overlay_strings_with_newlines
= 0;
2797 /* If POS specifies a position in a display vector, this might
2798 be for an ellipsis displayed for invisible text. We won't
2799 get the iterator set up for delivering that ellipsis unless
2800 we make sure that it gets aware of the invisible text. */
2801 if (in_ellipses_for_invisible_text_p (pos
, w
))
2807 /* Keep in mind: the call to reseat in init_iterator skips invisible
2808 text, so we might end up at a position different from POS. This
2809 is only a problem when POS is a row start after a newline and an
2810 overlay starts there with an after-string, and the overlay has an
2811 invisible property. Since we don't skip invisible text in
2812 display_line and elsewhere immediately after consuming the
2813 newline before the row start, such a POS will not be in a string,
2814 but the call to init_iterator below will move us to the
2816 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2818 /* This only scans the current chunk -- it should scan all chunks.
2819 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2820 to 16 in 22.1 to make this a lesser problem. */
2821 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2823 const char *s
= SDATA (it
->overlay_strings
[i
]);
2824 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2826 while (s
< e
&& *s
!= '\n')
2831 overlay_strings_with_newlines
= 1;
2836 /* If position is within an overlay string, set up IT to the right
2838 if (pos
->overlay_string_index
>= 0)
2842 /* If the first overlay string happens to have a `display'
2843 property for an image, the iterator will be set up for that
2844 image, and we have to undo that setup first before we can
2845 correct the overlay string index. */
2846 if (it
->method
== GET_FROM_IMAGE
)
2849 /* We already have the first chunk of overlay strings in
2850 IT->overlay_strings. Load more until the one for
2851 pos->overlay_string_index is in IT->overlay_strings. */
2852 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2854 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2855 it
->current
.overlay_string_index
= 0;
2858 load_overlay_strings (it
, 0);
2859 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2863 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2864 relative_index
= (it
->current
.overlay_string_index
2865 % OVERLAY_STRING_CHUNK_SIZE
);
2866 it
->string
= it
->overlay_strings
[relative_index
];
2867 xassert (STRINGP (it
->string
));
2868 it
->current
.string_pos
= pos
->string_pos
;
2869 it
->method
= GET_FROM_STRING
;
2872 #if 0 /* This is bogus because POS not having an overlay string
2873 position does not mean it's after the string. Example: A
2874 line starting with a before-string and initialization of IT
2875 to the previous row's end position. */
2876 else if (it
->current
.overlay_string_index
>= 0)
2878 /* If POS says we're already after an overlay string ending at
2879 POS, make sure to pop the iterator because it will be in
2880 front of that overlay string. When POS is ZV, we've thereby
2881 also ``processed'' overlay strings at ZV. */
2884 it
->current
.overlay_string_index
= -1;
2885 it
->method
= GET_FROM_BUFFER
;
2886 if (CHARPOS (pos
->pos
) == ZV
)
2887 it
->overlay_strings_at_end_processed_p
= 1;
2891 if (CHARPOS (pos
->string_pos
) >= 0)
2893 /* Recorded position is not in an overlay string, but in another
2894 string. This can only be a string from a `display' property.
2895 IT should already be filled with that string. */
2896 it
->current
.string_pos
= pos
->string_pos
;
2897 xassert (STRINGP (it
->string
));
2900 /* Restore position in display vector translations, control
2901 character translations or ellipses. */
2902 if (pos
->dpvec_index
>= 0)
2904 if (it
->dpvec
== NULL
)
2905 get_next_display_element (it
);
2906 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2907 it
->current
.dpvec_index
= pos
->dpvec_index
;
2911 return !overlay_strings_with_newlines
;
2915 /* Initialize IT for stepping through current_buffer in window W
2916 starting at ROW->start. */
2919 init_to_row_start (it
, w
, row
)
2922 struct glyph_row
*row
;
2924 init_from_display_pos (it
, w
, &row
->start
);
2925 it
->start
= row
->start
;
2926 it
->continuation_lines_width
= row
->continuation_lines_width
;
2931 /* Initialize IT for stepping through current_buffer in window W
2932 starting in the line following ROW, i.e. starting at ROW->end.
2933 Value is zero if there are overlay strings with newlines at ROW's
2937 init_to_row_end (it
, w
, row
)
2940 struct glyph_row
*row
;
2944 if (init_from_display_pos (it
, w
, &row
->end
))
2946 if (row
->continued_p
)
2947 it
->continuation_lines_width
2948 = row
->continuation_lines_width
+ row
->pixel_width
;
2959 /***********************************************************************
2961 ***********************************************************************/
2963 /* Called when IT reaches IT->stop_charpos. Handle text property and
2964 overlay changes. Set IT->stop_charpos to the next position where
2971 enum prop_handled handled
;
2972 int handle_overlay_change_p
;
2976 it
->current
.dpvec_index
= -1;
2977 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2978 it
->ignore_overlay_strings_at_pos_p
= 0;
2980 /* Use face of preceding text for ellipsis (if invisible) */
2981 if (it
->selective_display_ellipsis_p
)
2982 it
->saved_face_id
= it
->face_id
;
2986 handled
= HANDLED_NORMALLY
;
2988 /* Call text property handlers. */
2989 for (p
= it_props
; p
->handler
; ++p
)
2991 handled
= p
->handler (it
);
2993 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2995 else if (handled
== HANDLED_RETURN
)
2997 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2998 handle_overlay_change_p
= 0;
3001 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3003 /* Don't check for overlay strings below when set to deliver
3004 characters from a display vector. */
3005 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3006 handle_overlay_change_p
= 0;
3008 /* Handle overlay changes. */
3009 if (handle_overlay_change_p
)
3010 handled
= handle_overlay_change (it
);
3012 /* Determine where to stop next. */
3013 if (handled
== HANDLED_NORMALLY
)
3014 compute_stop_pos (it
);
3017 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3021 /* Compute IT->stop_charpos from text property and overlay change
3022 information for IT's current position. */
3025 compute_stop_pos (it
)
3028 register INTERVAL iv
, next_iv
;
3029 Lisp_Object object
, limit
, position
;
3031 /* If nowhere else, stop at the end. */
3032 it
->stop_charpos
= it
->end_charpos
;
3034 if (STRINGP (it
->string
))
3036 /* Strings are usually short, so don't limit the search for
3038 object
= it
->string
;
3040 position
= make_number (IT_STRING_CHARPOS (*it
));
3046 /* If next overlay change is in front of the current stop pos
3047 (which is IT->end_charpos), stop there. Note: value of
3048 next_overlay_change is point-max if no overlay change
3050 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3051 if (charpos
< it
->stop_charpos
)
3052 it
->stop_charpos
= charpos
;
3054 /* If showing the region, we have to stop at the region
3055 start or end because the face might change there. */
3056 if (it
->region_beg_charpos
> 0)
3058 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3059 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3060 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3061 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3064 /* Set up variables for computing the stop position from text
3065 property changes. */
3066 XSETBUFFER (object
, current_buffer
);
3067 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3068 position
= make_number (IT_CHARPOS (*it
));
3072 /* Get the interval containing IT's position. Value is a null
3073 interval if there isn't such an interval. */
3074 iv
= validate_interval_range (object
, &position
, &position
, 0);
3075 if (!NULL_INTERVAL_P (iv
))
3077 Lisp_Object values_here
[LAST_PROP_IDX
];
3080 /* Get properties here. */
3081 for (p
= it_props
; p
->handler
; ++p
)
3082 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3084 /* Look for an interval following iv that has different
3086 for (next_iv
= next_interval (iv
);
3087 (!NULL_INTERVAL_P (next_iv
)
3089 || XFASTINT (limit
) > next_iv
->position
));
3090 next_iv
= next_interval (next_iv
))
3092 for (p
= it_props
; p
->handler
; ++p
)
3094 Lisp_Object new_value
;
3096 new_value
= textget (next_iv
->plist
, *p
->name
);
3097 if (!EQ (values_here
[p
->idx
], new_value
))
3105 if (!NULL_INTERVAL_P (next_iv
))
3107 if (INTEGERP (limit
)
3108 && next_iv
->position
>= XFASTINT (limit
))
3109 /* No text property change up to limit. */
3110 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3112 /* Text properties change in next_iv. */
3113 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3117 xassert (STRINGP (it
->string
)
3118 || (it
->stop_charpos
>= BEGV
3119 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3123 /* Return the position of the next overlay change after POS in
3124 current_buffer. Value is point-max if no overlay change
3125 follows. This is like `next-overlay-change' but doesn't use
3129 next_overlay_change (pos
)
3134 Lisp_Object
*overlays
;
3137 /* Get all overlays at the given position. */
3138 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3140 /* If any of these overlays ends before endpos,
3141 use its ending point instead. */
3142 for (i
= 0; i
< noverlays
; ++i
)
3147 oend
= OVERLAY_END (overlays
[i
]);
3148 oendpos
= OVERLAY_POSITION (oend
);
3149 endpos
= min (endpos
, oendpos
);
3157 /***********************************************************************
3159 ***********************************************************************/
3161 /* Handle changes in the `fontified' property of the current buffer by
3162 calling hook functions from Qfontification_functions to fontify
3165 static enum prop_handled
3166 handle_fontified_prop (it
)
3169 Lisp_Object prop
, pos
;
3170 enum prop_handled handled
= HANDLED_NORMALLY
;
3172 if (!NILP (Vmemory_full
))
3175 /* Get the value of the `fontified' property at IT's current buffer
3176 position. (The `fontified' property doesn't have a special
3177 meaning in strings.) If the value is nil, call functions from
3178 Qfontification_functions. */
3179 if (!STRINGP (it
->string
)
3181 && !NILP (Vfontification_functions
)
3182 && !NILP (Vrun_hooks
)
3183 && (pos
= make_number (IT_CHARPOS (*it
)),
3184 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3187 int count
= SPECPDL_INDEX ();
3190 val
= Vfontification_functions
;
3191 specbind (Qfontification_functions
, Qnil
);
3193 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3194 safe_call1 (val
, pos
);
3197 Lisp_Object globals
, fn
;
3198 struct gcpro gcpro1
, gcpro2
;
3201 GCPRO2 (val
, globals
);
3203 for (; CONSP (val
); val
= XCDR (val
))
3209 /* A value of t indicates this hook has a local
3210 binding; it means to run the global binding too.
3211 In a global value, t should not occur. If it
3212 does, we must ignore it to avoid an endless
3214 for (globals
= Fdefault_value (Qfontification_functions
);
3216 globals
= XCDR (globals
))
3218 fn
= XCAR (globals
);
3220 safe_call1 (fn
, pos
);
3224 safe_call1 (fn
, pos
);
3230 unbind_to (count
, Qnil
);
3232 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3233 something. This avoids an endless loop if they failed to
3234 fontify the text for which reason ever. */
3235 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3236 handled
= HANDLED_RECOMPUTE_PROPS
;
3244 /***********************************************************************
3246 ***********************************************************************/
3248 /* Set up iterator IT from face properties at its current position.
3249 Called from handle_stop. */
3251 static enum prop_handled
3252 handle_face_prop (it
)
3255 int new_face_id
, next_stop
;
3257 if (!STRINGP (it
->string
))
3260 = face_at_buffer_position (it
->w
,
3262 it
->region_beg_charpos
,
3263 it
->region_end_charpos
,
3266 + TEXT_PROP_DISTANCE_LIMIT
),
3269 /* Is this a start of a run of characters with box face?
3270 Caveat: this can be called for a freshly initialized
3271 iterator; face_id is -1 in this case. We know that the new
3272 face will not change until limit, i.e. if the new face has a
3273 box, all characters up to limit will have one. But, as
3274 usual, we don't know whether limit is really the end. */
3275 if (new_face_id
!= it
->face_id
)
3277 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3279 /* If new face has a box but old face has not, this is
3280 the start of a run of characters with box, i.e. it has
3281 a shadow on the left side. The value of face_id of the
3282 iterator will be -1 if this is the initial call that gets
3283 the face. In this case, we have to look in front of IT's
3284 position and see whether there is a face != new_face_id. */
3285 it
->start_of_box_run_p
3286 = (new_face
->box
!= FACE_NO_BOX
3287 && (it
->face_id
>= 0
3288 || IT_CHARPOS (*it
) == BEG
3289 || new_face_id
!= face_before_it_pos (it
)));
3290 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3295 int base_face_id
, bufpos
;
3297 if (it
->current
.overlay_string_index
>= 0)
3298 bufpos
= IT_CHARPOS (*it
);
3302 /* For strings from a buffer, i.e. overlay strings or strings
3303 from a `display' property, use the face at IT's current
3304 buffer position as the base face to merge with, so that
3305 overlay strings appear in the same face as surrounding
3306 text, unless they specify their own faces. */
3307 base_face_id
= underlying_face_id (it
);
3309 new_face_id
= face_at_string_position (it
->w
,
3311 IT_STRING_CHARPOS (*it
),
3313 it
->region_beg_charpos
,
3314 it
->region_end_charpos
,
3318 #if 0 /* This shouldn't be neccessary. Let's check it. */
3319 /* If IT is used to display a mode line we would really like to
3320 use the mode line face instead of the frame's default face. */
3321 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3322 && new_face_id
== DEFAULT_FACE_ID
)
3323 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3326 /* Is this a start of a run of characters with box? Caveat:
3327 this can be called for a freshly allocated iterator; face_id
3328 is -1 is this case. We know that the new face will not
3329 change until the next check pos, i.e. if the new face has a
3330 box, all characters up to that position will have a
3331 box. But, as usual, we don't know whether that position
3332 is really the end. */
3333 if (new_face_id
!= it
->face_id
)
3335 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3336 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3338 /* If new face has a box but old face hasn't, this is the
3339 start of a run of characters with box, i.e. it has a
3340 shadow on the left side. */
3341 it
->start_of_box_run_p
3342 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3343 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3347 it
->face_id
= new_face_id
;
3348 return HANDLED_NORMALLY
;
3352 /* Return the ID of the face ``underlying'' IT's current position,
3353 which is in a string. If the iterator is associated with a
3354 buffer, return the face at IT's current buffer position.
3355 Otherwise, use the iterator's base_face_id. */
3358 underlying_face_id (it
)
3361 int face_id
= it
->base_face_id
, i
;
3363 xassert (STRINGP (it
->string
));
3365 for (i
= it
->sp
- 1; i
>= 0; --i
)
3366 if (NILP (it
->stack
[i
].string
))
3367 face_id
= it
->stack
[i
].face_id
;
3373 /* Compute the face one character before or after the current position
3374 of IT. BEFORE_P non-zero means get the face in front of IT's
3375 position. Value is the id of the face. */
3378 face_before_or_after_it_pos (it
, before_p
)
3383 int next_check_charpos
;
3384 struct text_pos pos
;
3386 xassert (it
->s
== NULL
);
3388 if (STRINGP (it
->string
))
3390 int bufpos
, base_face_id
;
3392 /* No face change past the end of the string (for the case
3393 we are padding with spaces). No face change before the
3395 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3396 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3399 /* Set pos to the position before or after IT's current position. */
3401 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3403 /* For composition, we must check the character after the
3405 pos
= (it
->what
== IT_COMPOSITION
3406 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3407 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3409 if (it
->current
.overlay_string_index
>= 0)
3410 bufpos
= IT_CHARPOS (*it
);
3414 base_face_id
= underlying_face_id (it
);
3416 /* Get the face for ASCII, or unibyte. */
3417 face_id
= face_at_string_position (it
->w
,
3421 it
->region_beg_charpos
,
3422 it
->region_end_charpos
,
3423 &next_check_charpos
,
3426 /* Correct the face for charsets different from ASCII. Do it
3427 for the multibyte case only. The face returned above is
3428 suitable for unibyte text if IT->string is unibyte. */
3429 if (STRING_MULTIBYTE (it
->string
))
3431 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3432 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3434 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3436 c
= string_char_and_length (p
, rest
, &len
);
3437 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3442 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3443 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3446 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3447 pos
= it
->current
.pos
;
3450 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3453 if (it
->what
== IT_COMPOSITION
)
3454 /* For composition, we must check the position after the
3456 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3458 INC_TEXT_POS (pos
, it
->multibyte_p
);
3461 /* Determine face for CHARSET_ASCII, or unibyte. */
3462 face_id
= face_at_buffer_position (it
->w
,
3464 it
->region_beg_charpos
,
3465 it
->region_end_charpos
,
3466 &next_check_charpos
,
3469 /* Correct the face for charsets different from ASCII. Do it
3470 for the multibyte case only. The face returned above is
3471 suitable for unibyte text if current_buffer is unibyte. */
3472 if (it
->multibyte_p
)
3474 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3475 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3476 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3485 /***********************************************************************
3487 ***********************************************************************/
3489 /* Set up iterator IT from invisible properties at its current
3490 position. Called from handle_stop. */
3492 static enum prop_handled
3493 handle_invisible_prop (it
)
3496 enum prop_handled handled
= HANDLED_NORMALLY
;
3498 if (STRINGP (it
->string
))
3500 extern Lisp_Object Qinvisible
;
3501 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3503 /* Get the value of the invisible text property at the
3504 current position. Value will be nil if there is no such
3506 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3507 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3510 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3512 handled
= HANDLED_RECOMPUTE_PROPS
;
3514 /* Get the position at which the next change of the
3515 invisible text property can be found in IT->string.
3516 Value will be nil if the property value is the same for
3517 all the rest of IT->string. */
3518 XSETINT (limit
, SCHARS (it
->string
));
3519 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3522 /* Text at current position is invisible. The next
3523 change in the property is at position end_charpos.
3524 Move IT's current position to that position. */
3525 if (INTEGERP (end_charpos
)
3526 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3528 struct text_pos old
;
3529 old
= it
->current
.string_pos
;
3530 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3531 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3535 /* The rest of the string is invisible. If this is an
3536 overlay string, proceed with the next overlay string
3537 or whatever comes and return a character from there. */
3538 if (it
->current
.overlay_string_index
>= 0)
3540 next_overlay_string (it
);
3541 /* Don't check for overlay strings when we just
3542 finished processing them. */
3543 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3547 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3548 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3555 int invis_p
, newpos
, next_stop
, start_charpos
;
3556 Lisp_Object pos
, prop
, overlay
;
3558 /* First of all, is there invisible text at this position? */
3559 start_charpos
= IT_CHARPOS (*it
);
3560 pos
= make_number (IT_CHARPOS (*it
));
3561 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3563 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3565 /* If we are on invisible text, skip over it. */
3566 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3568 /* Record whether we have to display an ellipsis for the
3570 int display_ellipsis_p
= invis_p
== 2;
3572 handled
= HANDLED_RECOMPUTE_PROPS
;
3574 /* Loop skipping over invisible text. The loop is left at
3575 ZV or with IT on the first char being visible again. */
3578 /* Try to skip some invisible text. Return value is the
3579 position reached which can be equal to IT's position
3580 if there is nothing invisible here. This skips both
3581 over invisible text properties and overlays with
3582 invisible property. */
3583 newpos
= skip_invisible (IT_CHARPOS (*it
),
3584 &next_stop
, ZV
, it
->window
);
3586 /* If we skipped nothing at all we weren't at invisible
3587 text in the first place. If everything to the end of
3588 the buffer was skipped, end the loop. */
3589 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3593 /* We skipped some characters but not necessarily
3594 all there are. Check if we ended up on visible
3595 text. Fget_char_property returns the property of
3596 the char before the given position, i.e. if we
3597 get invis_p = 0, this means that the char at
3598 newpos is visible. */
3599 pos
= make_number (newpos
);
3600 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3601 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3604 /* If we ended up on invisible text, proceed to
3605 skip starting with next_stop. */
3607 IT_CHARPOS (*it
) = next_stop
;
3609 /* If there are adjacent invisible texts, don't lose the
3610 second one's ellipsis. */
3612 display_ellipsis_p
= 1;
3616 /* The position newpos is now either ZV or on visible text. */
3617 IT_CHARPOS (*it
) = newpos
;
3618 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3620 /* If there are before-strings at the start of invisible
3621 text, and the text is invisible because of a text
3622 property, arrange to show before-strings because 20.x did
3623 it that way. (If the text is invisible because of an
3624 overlay property instead of a text property, this is
3625 already handled in the overlay code.) */
3627 && get_overlay_strings (it
, start_charpos
))
3629 handled
= HANDLED_RECOMPUTE_PROPS
;
3630 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3632 else if (display_ellipsis_p
)
3634 /* Make sure that the glyphs of the ellipsis will get
3635 correct `charpos' values. If we would not update
3636 it->position here, the glyphs would belong to the
3637 last visible character _before_ the invisible
3638 text, which confuses `set_cursor_from_row'.
3640 We use the last invisible position instead of the
3641 first because this way the cursor is always drawn on
3642 the first "." of the ellipsis, whenever PT is inside
3643 the invisible text. Otherwise the cursor would be
3644 placed _after_ the ellipsis when the point is after the
3645 first invisible character. */
3646 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3647 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3648 setup_for_ellipsis (it
, 0);
3657 /* Make iterator IT return `...' next.
3658 Replaces LEN characters from buffer. */
3661 setup_for_ellipsis (it
, len
)
3665 /* Use the display table definition for `...'. Invalid glyphs
3666 will be handled by the method returning elements from dpvec. */
3667 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3669 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3670 it
->dpvec
= v
->contents
;
3671 it
->dpend
= v
->contents
+ v
->size
;
3675 /* Default `...'. */
3676 it
->dpvec
= default_invis_vector
;
3677 it
->dpend
= default_invis_vector
+ 3;
3680 it
->dpvec_char_len
= len
;
3681 it
->current
.dpvec_index
= 0;
3682 it
->dpvec_face_id
= -1;
3684 /* Remember the current face id in case glyphs specify faces.
3685 IT's face is restored in set_iterator_to_next.
3686 saved_face_id was set to preceding char's face in handle_stop. */
3687 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3688 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3690 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3696 /***********************************************************************
3698 ***********************************************************************/
3700 /* Set up iterator IT from `display' property at its current position.
3701 Called from handle_stop.
3702 We return HANDLED_RETURN if some part of the display property
3703 overrides the display of the buffer text itself.
3704 Otherwise we return HANDLED_NORMALLY. */
3706 static enum prop_handled
3707 handle_display_prop (it
)
3710 Lisp_Object prop
, object
;
3711 struct text_pos
*position
;
3712 /* Nonzero if some property replaces the display of the text itself. */
3713 int display_replaced_p
= 0;
3715 if (STRINGP (it
->string
))
3717 object
= it
->string
;
3718 position
= &it
->current
.string_pos
;
3722 XSETWINDOW (object
, it
->w
);
3723 position
= &it
->current
.pos
;
3726 /* Reset those iterator values set from display property values. */
3727 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3728 it
->space_width
= Qnil
;
3729 it
->font_height
= Qnil
;
3732 /* We don't support recursive `display' properties, i.e. string
3733 values that have a string `display' property, that have a string
3734 `display' property etc. */
3735 if (!it
->string_from_display_prop_p
)
3736 it
->area
= TEXT_AREA
;
3738 prop
= Fget_char_property (make_number (position
->charpos
),
3741 return HANDLED_NORMALLY
;
3743 if (!STRINGP (it
->string
))
3744 object
= it
->w
->buffer
;
3747 /* Simple properties. */
3748 && !EQ (XCAR (prop
), Qimage
)
3749 && !EQ (XCAR (prop
), Qspace
)
3750 && !EQ (XCAR (prop
), Qwhen
)
3751 && !EQ (XCAR (prop
), Qslice
)
3752 && !EQ (XCAR (prop
), Qspace_width
)
3753 && !EQ (XCAR (prop
), Qheight
)
3754 && !EQ (XCAR (prop
), Qraise
)
3755 /* Marginal area specifications. */
3756 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3757 && !EQ (XCAR (prop
), Qleft_fringe
)
3758 && !EQ (XCAR (prop
), Qright_fringe
)
3759 && !NILP (XCAR (prop
)))
3761 for (; CONSP (prop
); prop
= XCDR (prop
))
3763 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3764 position
, display_replaced_p
))
3765 display_replaced_p
= 1;
3768 else if (VECTORP (prop
))
3771 for (i
= 0; i
< ASIZE (prop
); ++i
)
3772 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3773 position
, display_replaced_p
))
3774 display_replaced_p
= 1;
3778 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3779 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3780 return HANDLED_RECOMPUTE_PROPS
;
3782 display_replaced_p
= 1;
3785 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3789 /* Value is the position of the end of the `display' property starting
3790 at START_POS in OBJECT. */
3792 static struct text_pos
3793 display_prop_end (it
, object
, start_pos
)
3796 struct text_pos start_pos
;
3799 struct text_pos end_pos
;
3801 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3802 Qdisplay
, object
, Qnil
);
3803 CHARPOS (end_pos
) = XFASTINT (end
);
3804 if (STRINGP (object
))
3805 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3807 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3813 /* Set up IT from a single `display' specification PROP. OBJECT
3814 is the object in which the `display' property was found. *POSITION
3815 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3816 means that we previously saw a display specification which already
3817 replaced text display with something else, for example an image;
3818 we ignore such properties after the first one has been processed.
3820 If PROP is a `space' or `image' specification, and in some other
3821 cases too, set *POSITION to the position where the `display'
3824 Value is non-zero if something was found which replaces the display
3825 of buffer or string text. Specifically, the value is -1 if that
3826 "something" is "nothing". */
3829 handle_single_display_spec (it
, spec
, object
, position
,
3830 display_replaced_before_p
)
3834 struct text_pos
*position
;
3835 int display_replaced_before_p
;
3838 Lisp_Object location
, value
;
3839 struct text_pos start_pos
;
3842 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3843 If the result is non-nil, use VALUE instead of SPEC. */
3845 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3854 if (!NILP (form
) && !EQ (form
, Qt
))
3856 int count
= SPECPDL_INDEX ();
3857 struct gcpro gcpro1
;
3859 /* Bind `object' to the object having the `display' property, a
3860 buffer or string. Bind `position' to the position in the
3861 object where the property was found, and `buffer-position'
3862 to the current position in the buffer. */
3863 specbind (Qobject
, object
);
3864 specbind (Qposition
, make_number (CHARPOS (*position
)));
3865 specbind (Qbuffer_position
,
3866 make_number (STRINGP (object
)
3867 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3869 form
= safe_eval (form
);
3871 unbind_to (count
, Qnil
);
3877 /* Handle `(height HEIGHT)' specifications. */
3879 && EQ (XCAR (spec
), Qheight
)
3880 && CONSP (XCDR (spec
)))
3882 if (!FRAME_WINDOW_P (it
->f
))
3885 it
->font_height
= XCAR (XCDR (spec
));
3886 if (!NILP (it
->font_height
))
3888 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3889 int new_height
= -1;
3891 if (CONSP (it
->font_height
)
3892 && (EQ (XCAR (it
->font_height
), Qplus
)
3893 || EQ (XCAR (it
->font_height
), Qminus
))
3894 && CONSP (XCDR (it
->font_height
))
3895 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3897 /* `(+ N)' or `(- N)' where N is an integer. */
3898 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3899 if (EQ (XCAR (it
->font_height
), Qplus
))
3901 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3903 else if (FUNCTIONP (it
->font_height
))
3905 /* Call function with current height as argument.
3906 Value is the new height. */
3908 height
= safe_call1 (it
->font_height
,
3909 face
->lface
[LFACE_HEIGHT_INDEX
]);
3910 if (NUMBERP (height
))
3911 new_height
= XFLOATINT (height
);
3913 else if (NUMBERP (it
->font_height
))
3915 /* Value is a multiple of the canonical char height. */
3918 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3919 new_height
= (XFLOATINT (it
->font_height
)
3920 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3924 /* Evaluate IT->font_height with `height' bound to the
3925 current specified height to get the new height. */
3926 int count
= SPECPDL_INDEX ();
3928 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3929 value
= safe_eval (it
->font_height
);
3930 unbind_to (count
, Qnil
);
3932 if (NUMBERP (value
))
3933 new_height
= XFLOATINT (value
);
3937 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3943 /* Handle `(space_width WIDTH)'. */
3945 && EQ (XCAR (spec
), Qspace_width
)
3946 && CONSP (XCDR (spec
)))
3948 if (!FRAME_WINDOW_P (it
->f
))
3951 value
= XCAR (XCDR (spec
));
3952 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3953 it
->space_width
= value
;
3958 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3960 && EQ (XCAR (spec
), Qslice
))
3964 if (!FRAME_WINDOW_P (it
->f
))
3967 if (tem
= XCDR (spec
), CONSP (tem
))
3969 it
->slice
.x
= XCAR (tem
);
3970 if (tem
= XCDR (tem
), CONSP (tem
))
3972 it
->slice
.y
= XCAR (tem
);
3973 if (tem
= XCDR (tem
), CONSP (tem
))
3975 it
->slice
.width
= XCAR (tem
);
3976 if (tem
= XCDR (tem
), CONSP (tem
))
3977 it
->slice
.height
= XCAR (tem
);
3985 /* Handle `(raise FACTOR)'. */
3987 && EQ (XCAR (spec
), Qraise
)
3988 && CONSP (XCDR (spec
)))
3990 if (!FRAME_WINDOW_P (it
->f
))
3993 #ifdef HAVE_WINDOW_SYSTEM
3994 value
= XCAR (XCDR (spec
));
3995 if (NUMBERP (value
))
3997 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3998 it
->voffset
= - (XFLOATINT (value
)
3999 * (FONT_HEIGHT (face
->font
)));
4001 #endif /* HAVE_WINDOW_SYSTEM */
4006 /* Don't handle the other kinds of display specifications
4007 inside a string that we got from a `display' property. */
4008 if (it
->string_from_display_prop_p
)
4011 /* Characters having this form of property are not displayed, so
4012 we have to find the end of the property. */
4013 start_pos
= *position
;
4014 *position
= display_prop_end (it
, object
, start_pos
);
4017 /* Stop the scan at that end position--we assume that all
4018 text properties change there. */
4019 it
->stop_charpos
= position
->charpos
;
4021 /* Handle `(left-fringe BITMAP [FACE])'
4022 and `(right-fringe BITMAP [FACE])'. */
4024 && (EQ (XCAR (spec
), Qleft_fringe
)
4025 || EQ (XCAR (spec
), Qright_fringe
))
4026 && CONSP (XCDR (spec
)))
4028 int face_id
= DEFAULT_FACE_ID
;
4031 if (!FRAME_WINDOW_P (it
->f
))
4032 /* If we return here, POSITION has been advanced
4033 across the text with this property. */
4036 #ifdef HAVE_WINDOW_SYSTEM
4037 value
= XCAR (XCDR (spec
));
4038 if (!SYMBOLP (value
)
4039 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4040 /* If we return here, POSITION has been advanced
4041 across the text with this property. */
4044 if (CONSP (XCDR (XCDR (spec
))))
4046 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4047 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4048 'A', FRINGE_FACE_ID
, 0);
4053 /* Save current settings of IT so that we can restore them
4054 when we are finished with the glyph property value. */
4058 it
->area
= TEXT_AREA
;
4059 it
->what
= IT_IMAGE
;
4060 it
->image_id
= -1; /* no image */
4061 it
->position
= start_pos
;
4062 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4063 it
->method
= GET_FROM_IMAGE
;
4064 it
->face_id
= face_id
;
4066 /* Say that we haven't consumed the characters with
4067 `display' property yet. The call to pop_it in
4068 set_iterator_to_next will clean this up. */
4069 *position
= start_pos
;
4071 if (EQ (XCAR (spec
), Qleft_fringe
))
4073 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4074 it
->left_user_fringe_face_id
= face_id
;
4078 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4079 it
->right_user_fringe_face_id
= face_id
;
4081 #endif /* HAVE_WINDOW_SYSTEM */
4085 /* Prepare to handle `((margin left-margin) ...)',
4086 `((margin right-margin) ...)' and `((margin nil) ...)'
4087 prefixes for display specifications. */
4088 location
= Qunbound
;
4089 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4093 value
= XCDR (spec
);
4095 value
= XCAR (value
);
4098 if (EQ (XCAR (tem
), Qmargin
)
4099 && (tem
= XCDR (tem
),
4100 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4102 || EQ (tem
, Qleft_margin
)
4103 || EQ (tem
, Qright_margin
))))
4107 if (EQ (location
, Qunbound
))
4113 /* After this point, VALUE is the property after any
4114 margin prefix has been stripped. It must be a string,
4115 an image specification, or `(space ...)'.
4117 LOCATION specifies where to display: `left-margin',
4118 `right-margin' or nil. */
4120 valid_p
= (STRINGP (value
)
4121 #ifdef HAVE_WINDOW_SYSTEM
4122 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4123 #endif /* not HAVE_WINDOW_SYSTEM */
4124 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4126 if (valid_p
&& !display_replaced_before_p
)
4128 /* Save current settings of IT so that we can restore them
4129 when we are finished with the glyph property value. */
4131 if (NILP (location
))
4132 it
->area
= TEXT_AREA
;
4133 else if (EQ (location
, Qleft_margin
))
4134 it
->area
= LEFT_MARGIN_AREA
;
4136 it
->area
= RIGHT_MARGIN_AREA
;
4138 if (STRINGP (value
))
4140 if (SCHARS (value
) == 0)
4143 return -1; /* Replaced by "", i.e. nothing. */
4146 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4147 it
->current
.overlay_string_index
= -1;
4148 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4149 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4150 it
->method
= GET_FROM_STRING
;
4151 it
->stop_charpos
= 0;
4152 it
->string_from_display_prop_p
= 1;
4153 /* Say that we haven't consumed the characters with
4154 `display' property yet. The call to pop_it in
4155 set_iterator_to_next will clean this up. */
4156 *position
= start_pos
;
4158 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4160 it
->method
= GET_FROM_STRETCH
;
4162 *position
= it
->position
= start_pos
;
4164 #ifdef HAVE_WINDOW_SYSTEM
4167 it
->what
= IT_IMAGE
;
4168 it
->image_id
= lookup_image (it
->f
, value
);
4169 it
->position
= start_pos
;
4170 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4171 it
->method
= GET_FROM_IMAGE
;
4173 /* Say that we haven't consumed the characters with
4174 `display' property yet. The call to pop_it in
4175 set_iterator_to_next will clean this up. */
4176 *position
= start_pos
;
4178 #endif /* HAVE_WINDOW_SYSTEM */
4183 /* Invalid property or property not supported. Restore
4184 POSITION to what it was before. */
4185 *position
= start_pos
;
4190 /* Check if SPEC is a display sub-property value whose text should be
4191 treated as intangible. */
4194 single_display_spec_intangible_p (prop
)
4197 /* Skip over `when FORM'. */
4198 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4212 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4213 we don't need to treat text as intangible. */
4214 if (EQ (XCAR (prop
), Qmargin
))
4222 || EQ (XCAR (prop
), Qleft_margin
)
4223 || EQ (XCAR (prop
), Qright_margin
))
4227 return (CONSP (prop
)
4228 && (EQ (XCAR (prop
), Qimage
)
4229 || EQ (XCAR (prop
), Qspace
)));
4233 /* Check if PROP is a display property value whose text should be
4234 treated as intangible. */
4237 display_prop_intangible_p (prop
)
4241 && CONSP (XCAR (prop
))
4242 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4244 /* A list of sub-properties. */
4245 while (CONSP (prop
))
4247 if (single_display_spec_intangible_p (XCAR (prop
)))
4252 else if (VECTORP (prop
))
4254 /* A vector of sub-properties. */
4256 for (i
= 0; i
< ASIZE (prop
); ++i
)
4257 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4261 return single_display_spec_intangible_p (prop
);
4267 /* Return 1 if PROP is a display sub-property value containing STRING. */
4270 single_display_spec_string_p (prop
, string
)
4271 Lisp_Object prop
, string
;
4273 if (EQ (string
, prop
))
4276 /* Skip over `when FORM'. */
4277 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4286 /* Skip over `margin LOCATION'. */
4287 if (EQ (XCAR (prop
), Qmargin
))
4298 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4302 /* Return 1 if STRING appears in the `display' property PROP. */
4305 display_prop_string_p (prop
, string
)
4306 Lisp_Object prop
, string
;
4309 && CONSP (XCAR (prop
))
4310 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4312 /* A list of sub-properties. */
4313 while (CONSP (prop
))
4315 if (single_display_spec_string_p (XCAR (prop
), string
))
4320 else if (VECTORP (prop
))
4322 /* A vector of sub-properties. */
4324 for (i
= 0; i
< ASIZE (prop
); ++i
)
4325 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4329 return single_display_spec_string_p (prop
, string
);
4335 /* Determine from which buffer position in W's buffer STRING comes
4336 from. AROUND_CHARPOS is an approximate position where it could
4337 be from. Value is the buffer position or 0 if it couldn't be
4340 W's buffer must be current.
4342 This function is necessary because we don't record buffer positions
4343 in glyphs generated from strings (to keep struct glyph small).
4344 This function may only use code that doesn't eval because it is
4345 called asynchronously from note_mouse_highlight. */
4348 string_buffer_position (w
, string
, around_charpos
)
4353 Lisp_Object limit
, prop
, pos
;
4354 const int MAX_DISTANCE
= 1000;
4357 pos
= make_number (around_charpos
);
4358 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4359 while (!found
&& !EQ (pos
, limit
))
4361 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4362 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4365 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4370 pos
= make_number (around_charpos
);
4371 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4372 while (!found
&& !EQ (pos
, limit
))
4374 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4375 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4378 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4383 return found
? XINT (pos
) : 0;
4388 /***********************************************************************
4389 `composition' property
4390 ***********************************************************************/
4392 /* Set up iterator IT from `composition' property at its current
4393 position. Called from handle_stop. */
4395 static enum prop_handled
4396 handle_composition_prop (it
)
4399 Lisp_Object prop
, string
;
4400 int pos
, pos_byte
, end
;
4401 enum prop_handled handled
= HANDLED_NORMALLY
;
4403 if (STRINGP (it
->string
))
4405 pos
= IT_STRING_CHARPOS (*it
);
4406 pos_byte
= IT_STRING_BYTEPOS (*it
);
4407 string
= it
->string
;
4411 pos
= IT_CHARPOS (*it
);
4412 pos_byte
= IT_BYTEPOS (*it
);
4416 /* If there's a valid composition and point is not inside of the
4417 composition (in the case that the composition is from the current
4418 buffer), draw a glyph composed from the composition components. */
4419 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4420 && COMPOSITION_VALID_P (pos
, end
, prop
)
4421 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4423 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4427 it
->method
= GET_FROM_COMPOSITION
;
4429 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4430 /* For a terminal, draw only the first character of the
4432 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4433 it
->len
= (STRINGP (it
->string
)
4434 ? string_char_to_byte (it
->string
, end
)
4435 : CHAR_TO_BYTE (end
)) - pos_byte
;
4436 it
->stop_charpos
= end
;
4437 handled
= HANDLED_RETURN
;
4446 /***********************************************************************
4448 ***********************************************************************/
4450 /* The following structure is used to record overlay strings for
4451 later sorting in load_overlay_strings. */
4453 struct overlay_entry
4455 Lisp_Object overlay
;
4462 /* Set up iterator IT from overlay strings at its current position.
4463 Called from handle_stop. */
4465 static enum prop_handled
4466 handle_overlay_change (it
)
4469 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4470 return HANDLED_RECOMPUTE_PROPS
;
4472 return HANDLED_NORMALLY
;
4476 /* Set up the next overlay string for delivery by IT, if there is an
4477 overlay string to deliver. Called by set_iterator_to_next when the
4478 end of the current overlay string is reached. If there are more
4479 overlay strings to display, IT->string and
4480 IT->current.overlay_string_index are set appropriately here.
4481 Otherwise IT->string is set to nil. */
4484 next_overlay_string (it
)
4487 ++it
->current
.overlay_string_index
;
4488 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4490 /* No more overlay strings. Restore IT's settings to what
4491 they were before overlay strings were processed, and
4492 continue to deliver from current_buffer. */
4493 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4496 xassert (it
->stop_charpos
>= BEGV
4497 && it
->stop_charpos
<= it
->end_charpos
);
4499 it
->current
.overlay_string_index
= -1;
4500 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4501 it
->n_overlay_strings
= 0;
4502 it
->method
= GET_FROM_BUFFER
;
4504 /* If we're at the end of the buffer, record that we have
4505 processed the overlay strings there already, so that
4506 next_element_from_buffer doesn't try it again. */
4507 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4508 it
->overlay_strings_at_end_processed_p
= 1;
4510 /* If we have to display `...' for invisible text, set
4511 the iterator up for that. */
4512 if (display_ellipsis_p
)
4513 setup_for_ellipsis (it
, 0);
4517 /* There are more overlay strings to process. If
4518 IT->current.overlay_string_index has advanced to a position
4519 where we must load IT->overlay_strings with more strings, do
4521 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4523 if (it
->current
.overlay_string_index
&& i
== 0)
4524 load_overlay_strings (it
, 0);
4526 /* Initialize IT to deliver display elements from the overlay
4528 it
->string
= it
->overlay_strings
[i
];
4529 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4530 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4531 it
->method
= GET_FROM_STRING
;
4532 it
->stop_charpos
= 0;
4539 /* Compare two overlay_entry structures E1 and E2. Used as a
4540 comparison function for qsort in load_overlay_strings. Overlay
4541 strings for the same position are sorted so that
4543 1. All after-strings come in front of before-strings, except
4544 when they come from the same overlay.
4546 2. Within after-strings, strings are sorted so that overlay strings
4547 from overlays with higher priorities come first.
4549 2. Within before-strings, strings are sorted so that overlay
4550 strings from overlays with higher priorities come last.
4552 Value is analogous to strcmp. */
4556 compare_overlay_entries (e1
, e2
)
4559 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4560 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4563 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4565 /* Let after-strings appear in front of before-strings if
4566 they come from different overlays. */
4567 if (EQ (entry1
->overlay
, entry2
->overlay
))
4568 result
= entry1
->after_string_p
? 1 : -1;
4570 result
= entry1
->after_string_p
? -1 : 1;
4572 else if (entry1
->after_string_p
)
4573 /* After-strings sorted in order of decreasing priority. */
4574 result
= entry2
->priority
- entry1
->priority
;
4576 /* Before-strings sorted in order of increasing priority. */
4577 result
= entry1
->priority
- entry2
->priority
;
4583 /* Load the vector IT->overlay_strings with overlay strings from IT's
4584 current buffer position, or from CHARPOS if that is > 0. Set
4585 IT->n_overlays to the total number of overlay strings found.
4587 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4588 a time. On entry into load_overlay_strings,
4589 IT->current.overlay_string_index gives the number of overlay
4590 strings that have already been loaded by previous calls to this
4593 IT->add_overlay_start contains an additional overlay start
4594 position to consider for taking overlay strings from, if non-zero.
4595 This position comes into play when the overlay has an `invisible'
4596 property, and both before and after-strings. When we've skipped to
4597 the end of the overlay, because of its `invisible' property, we
4598 nevertheless want its before-string to appear.
4599 IT->add_overlay_start will contain the overlay start position
4602 Overlay strings are sorted so that after-string strings come in
4603 front of before-string strings. Within before and after-strings,
4604 strings are sorted by overlay priority. See also function
4605 compare_overlay_entries. */
4608 load_overlay_strings (it
, charpos
)
4612 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4613 Lisp_Object overlay
, window
, str
, invisible
;
4614 struct Lisp_Overlay
*ov
;
4617 int n
= 0, i
, j
, invis_p
;
4618 struct overlay_entry
*entries
4619 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4622 charpos
= IT_CHARPOS (*it
);
4624 /* Append the overlay string STRING of overlay OVERLAY to vector
4625 `entries' which has size `size' and currently contains `n'
4626 elements. AFTER_P non-zero means STRING is an after-string of
4628 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4631 Lisp_Object priority; \
4635 int new_size = 2 * size; \
4636 struct overlay_entry *old = entries; \
4638 (struct overlay_entry *) alloca (new_size \
4639 * sizeof *entries); \
4640 bcopy (old, entries, size * sizeof *entries); \
4644 entries[n].string = (STRING); \
4645 entries[n].overlay = (OVERLAY); \
4646 priority = Foverlay_get ((OVERLAY), Qpriority); \
4647 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4648 entries[n].after_string_p = (AFTER_P); \
4653 /* Process overlay before the overlay center. */
4654 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4656 XSETMISC (overlay
, ov
);
4657 xassert (OVERLAYP (overlay
));
4658 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4659 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4664 /* Skip this overlay if it doesn't start or end at IT's current
4666 if (end
!= charpos
&& start
!= charpos
)
4669 /* Skip this overlay if it doesn't apply to IT->w. */
4670 window
= Foverlay_get (overlay
, Qwindow
);
4671 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4674 /* If the text ``under'' the overlay is invisible, both before-
4675 and after-strings from this overlay are visible; start and
4676 end position are indistinguishable. */
4677 invisible
= Foverlay_get (overlay
, Qinvisible
);
4678 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4680 /* If overlay has a non-empty before-string, record it. */
4681 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4682 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4684 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4686 /* If overlay has a non-empty after-string, record it. */
4687 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4688 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4690 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4693 /* Process overlays after the overlay center. */
4694 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4696 XSETMISC (overlay
, ov
);
4697 xassert (OVERLAYP (overlay
));
4698 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4699 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4701 if (start
> charpos
)
4704 /* Skip this overlay if it doesn't start or end at IT's current
4706 if (end
!= charpos
&& start
!= charpos
)
4709 /* Skip this overlay if it doesn't apply to IT->w. */
4710 window
= Foverlay_get (overlay
, Qwindow
);
4711 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4714 /* If the text ``under'' the overlay is invisible, it has a zero
4715 dimension, and both before- and after-strings apply. */
4716 invisible
= Foverlay_get (overlay
, Qinvisible
);
4717 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4719 /* If overlay has a non-empty before-string, record it. */
4720 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4721 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4723 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4725 /* If overlay has a non-empty after-string, record it. */
4726 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4727 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4729 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4732 #undef RECORD_OVERLAY_STRING
4736 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4738 /* Record the total number of strings to process. */
4739 it
->n_overlay_strings
= n
;
4741 /* IT->current.overlay_string_index is the number of overlay strings
4742 that have already been consumed by IT. Copy some of the
4743 remaining overlay strings to IT->overlay_strings. */
4745 j
= it
->current
.overlay_string_index
;
4746 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4747 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4753 /* Get the first chunk of overlay strings at IT's current buffer
4754 position, or at CHARPOS if that is > 0. Value is non-zero if at
4755 least one overlay string was found. */
4758 get_overlay_strings (it
, charpos
)
4762 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4763 process. This fills IT->overlay_strings with strings, and sets
4764 IT->n_overlay_strings to the total number of strings to process.
4765 IT->pos.overlay_string_index has to be set temporarily to zero
4766 because load_overlay_strings needs this; it must be set to -1
4767 when no overlay strings are found because a zero value would
4768 indicate a position in the first overlay string. */
4769 it
->current
.overlay_string_index
= 0;
4770 load_overlay_strings (it
, charpos
);
4772 /* If we found overlay strings, set up IT to deliver display
4773 elements from the first one. Otherwise set up IT to deliver
4774 from current_buffer. */
4775 if (it
->n_overlay_strings
)
4777 /* Make sure we know settings in current_buffer, so that we can
4778 restore meaningful values when we're done with the overlay
4780 compute_stop_pos (it
);
4781 xassert (it
->face_id
>= 0);
4783 /* Save IT's settings. They are restored after all overlay
4784 strings have been processed. */
4785 xassert (it
->sp
== 0);
4788 /* Set up IT to deliver display elements from the first overlay
4790 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4791 it
->string
= it
->overlay_strings
[0];
4792 it
->stop_charpos
= 0;
4793 xassert (STRINGP (it
->string
));
4794 it
->end_charpos
= SCHARS (it
->string
);
4795 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4796 it
->method
= GET_FROM_STRING
;
4801 it
->current
.overlay_string_index
= -1;
4802 it
->method
= GET_FROM_BUFFER
;
4807 /* Value is non-zero if we found at least one overlay string. */
4808 return STRINGP (it
->string
);
4813 /***********************************************************************
4814 Saving and restoring state
4815 ***********************************************************************/
4817 /* Save current settings of IT on IT->stack. Called, for example,
4818 before setting up IT for an overlay string, to be able to restore
4819 IT's settings to what they were after the overlay string has been
4826 struct iterator_stack_entry
*p
;
4828 xassert (it
->sp
< 2);
4829 p
= it
->stack
+ it
->sp
;
4831 p
->stop_charpos
= it
->stop_charpos
;
4832 xassert (it
->face_id
>= 0);
4833 p
->face_id
= it
->face_id
;
4834 p
->string
= it
->string
;
4835 p
->pos
= it
->current
;
4836 p
->end_charpos
= it
->end_charpos
;
4837 p
->string_nchars
= it
->string_nchars
;
4839 p
->multibyte_p
= it
->multibyte_p
;
4840 p
->slice
= it
->slice
;
4841 p
->space_width
= it
->space_width
;
4842 p
->font_height
= it
->font_height
;
4843 p
->voffset
= it
->voffset
;
4844 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4845 p
->display_ellipsis_p
= 0;
4850 /* Restore IT's settings from IT->stack. Called, for example, when no
4851 more overlay strings must be processed, and we return to delivering
4852 display elements from a buffer, or when the end of a string from a
4853 `display' property is reached and we return to delivering display
4854 elements from an overlay string, or from a buffer. */
4860 struct iterator_stack_entry
*p
;
4862 xassert (it
->sp
> 0);
4864 p
= it
->stack
+ it
->sp
;
4865 it
->stop_charpos
= p
->stop_charpos
;
4866 it
->face_id
= p
->face_id
;
4867 it
->string
= p
->string
;
4868 it
->current
= p
->pos
;
4869 it
->end_charpos
= p
->end_charpos
;
4870 it
->string_nchars
= p
->string_nchars
;
4872 it
->multibyte_p
= p
->multibyte_p
;
4873 it
->slice
= p
->slice
;
4874 it
->space_width
= p
->space_width
;
4875 it
->font_height
= p
->font_height
;
4876 it
->voffset
= p
->voffset
;
4877 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4882 /***********************************************************************
4884 ***********************************************************************/
4886 /* Set IT's current position to the previous line start. */
4889 back_to_previous_line_start (it
)
4892 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4893 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4897 /* Move IT to the next line start.
4899 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4900 we skipped over part of the text (as opposed to moving the iterator
4901 continuously over the text). Otherwise, don't change the value
4904 Newlines may come from buffer text, overlay strings, or strings
4905 displayed via the `display' property. That's the reason we can't
4906 simply use find_next_newline_no_quit.
4908 Note that this function may not skip over invisible text that is so
4909 because of text properties and immediately follows a newline. If
4910 it would, function reseat_at_next_visible_line_start, when called
4911 from set_iterator_to_next, would effectively make invisible
4912 characters following a newline part of the wrong glyph row, which
4913 leads to wrong cursor motion. */
4916 forward_to_next_line_start (it
, skipped_p
)
4920 int old_selective
, newline_found_p
, n
;
4921 const int MAX_NEWLINE_DISTANCE
= 500;
4923 /* If already on a newline, just consume it to avoid unintended
4924 skipping over invisible text below. */
4925 if (it
->what
== IT_CHARACTER
4927 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4929 set_iterator_to_next (it
, 0);
4934 /* Don't handle selective display in the following. It's (a)
4935 unnecessary because it's done by the caller, and (b) leads to an
4936 infinite recursion because next_element_from_ellipsis indirectly
4937 calls this function. */
4938 old_selective
= it
->selective
;
4941 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4942 from buffer text. */
4943 for (n
= newline_found_p
= 0;
4944 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4945 n
+= STRINGP (it
->string
) ? 0 : 1)
4947 if (!get_next_display_element (it
))
4949 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4950 set_iterator_to_next (it
, 0);
4953 /* If we didn't find a newline near enough, see if we can use a
4955 if (!newline_found_p
)
4957 int start
= IT_CHARPOS (*it
);
4958 int limit
= find_next_newline_no_quit (start
, 1);
4961 xassert (!STRINGP (it
->string
));
4963 /* If there isn't any `display' property in sight, and no
4964 overlays, we can just use the position of the newline in
4966 if (it
->stop_charpos
>= limit
4967 || ((pos
= Fnext_single_property_change (make_number (start
),
4969 Qnil
, make_number (limit
)),
4971 && next_overlay_change (start
) == ZV
))
4973 IT_CHARPOS (*it
) = limit
;
4974 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4975 *skipped_p
= newline_found_p
= 1;
4979 while (get_next_display_element (it
)
4980 && !newline_found_p
)
4982 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4983 set_iterator_to_next (it
, 0);
4988 it
->selective
= old_selective
;
4989 return newline_found_p
;
4993 /* Set IT's current position to the previous visible line start. Skip
4994 invisible text that is so either due to text properties or due to
4995 selective display. Caution: this does not change IT->current_x and
4999 back_to_previous_visible_line_start (it
)
5002 while (IT_CHARPOS (*it
) > BEGV
)
5004 back_to_previous_line_start (it
);
5005 if (IT_CHARPOS (*it
) <= BEGV
)
5008 /* If selective > 0, then lines indented more than that values
5010 if (it
->selective
> 0
5011 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5012 (double) it
->selective
)) /* iftc */
5015 /* Check the newline before point for invisibility. */
5018 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5019 Qinvisible
, it
->window
);
5020 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5024 /* If newline has a display property that replaces the newline with something
5025 else (image or text), find start of overlay or interval and continue search
5027 if (IT_CHARPOS (*it
) > BEGV
)
5029 struct it it2
= *it
;
5032 Lisp_Object val
, overlay
;
5034 pos
= --IT_CHARPOS (it2
);
5037 if (handle_display_prop (&it2
) == HANDLED_RETURN
5038 && !NILP (val
= get_char_property_and_overlay
5039 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5040 && (OVERLAYP (overlay
)
5041 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5042 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5046 IT_CHARPOS (*it
) = beg
;
5047 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5055 xassert (IT_CHARPOS (*it
) >= BEGV
);
5056 xassert (IT_CHARPOS (*it
) == BEGV
5057 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5062 /* Reseat iterator IT at the previous visible line start. Skip
5063 invisible text that is so either due to text properties or due to
5064 selective display. At the end, update IT's overlay information,
5065 face information etc. */
5068 reseat_at_previous_visible_line_start (it
)
5071 back_to_previous_visible_line_start (it
);
5072 reseat (it
, it
->current
.pos
, 1);
5077 /* Reseat iterator IT on the next visible line start in the current
5078 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5079 preceding the line start. Skip over invisible text that is so
5080 because of selective display. Compute faces, overlays etc at the
5081 new position. Note that this function does not skip over text that
5082 is invisible because of text properties. */
5085 reseat_at_next_visible_line_start (it
, on_newline_p
)
5089 int newline_found_p
, skipped_p
= 0;
5091 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5093 /* Skip over lines that are invisible because they are indented
5094 more than the value of IT->selective. */
5095 if (it
->selective
> 0)
5096 while (IT_CHARPOS (*it
) < ZV
5097 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5098 (double) it
->selective
)) /* iftc */
5100 xassert (IT_BYTEPOS (*it
) == BEGV
5101 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5102 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5105 /* Position on the newline if that's what's requested. */
5106 if (on_newline_p
&& newline_found_p
)
5108 if (STRINGP (it
->string
))
5110 if (IT_STRING_CHARPOS (*it
) > 0)
5112 --IT_STRING_CHARPOS (*it
);
5113 --IT_STRING_BYTEPOS (*it
);
5116 else if (IT_CHARPOS (*it
) > BEGV
)
5120 reseat (it
, it
->current
.pos
, 0);
5124 reseat (it
, it
->current
.pos
, 0);
5131 /***********************************************************************
5132 Changing an iterator's position
5133 ***********************************************************************/
5135 /* Change IT's current position to POS in current_buffer. If FORCE_P
5136 is non-zero, always check for text properties at the new position.
5137 Otherwise, text properties are only looked up if POS >=
5138 IT->check_charpos of a property. */
5141 reseat (it
, pos
, force_p
)
5143 struct text_pos pos
;
5146 int original_pos
= IT_CHARPOS (*it
);
5148 reseat_1 (it
, pos
, 0);
5150 /* Determine where to check text properties. Avoid doing it
5151 where possible because text property lookup is very expensive. */
5153 || CHARPOS (pos
) > it
->stop_charpos
5154 || CHARPOS (pos
) < original_pos
)
5161 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5162 IT->stop_pos to POS, also. */
5165 reseat_1 (it
, pos
, set_stop_p
)
5167 struct text_pos pos
;
5170 /* Don't call this function when scanning a C string. */
5171 xassert (it
->s
== NULL
);
5173 /* POS must be a reasonable value. */
5174 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5176 it
->current
.pos
= it
->position
= pos
;
5177 XSETBUFFER (it
->object
, current_buffer
);
5178 it
->end_charpos
= ZV
;
5180 it
->current
.dpvec_index
= -1;
5181 it
->current
.overlay_string_index
= -1;
5182 IT_STRING_CHARPOS (*it
) = -1;
5183 IT_STRING_BYTEPOS (*it
) = -1;
5185 it
->method
= GET_FROM_BUFFER
;
5186 /* RMS: I added this to fix a bug in move_it_vertically_backward
5187 where it->area continued to relate to the starting point
5188 for the backward motion. Bug report from
5189 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
5190 However, I am not sure whether reseat still does the right thing
5191 in general after this change. */
5192 it
->area
= TEXT_AREA
;
5193 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5195 it
->face_before_selective_p
= 0;
5198 it
->stop_charpos
= CHARPOS (pos
);
5202 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5203 If S is non-null, it is a C string to iterate over. Otherwise,
5204 STRING gives a Lisp string to iterate over.
5206 If PRECISION > 0, don't return more then PRECISION number of
5207 characters from the string.
5209 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5210 characters have been returned. FIELD_WIDTH < 0 means an infinite
5213 MULTIBYTE = 0 means disable processing of multibyte characters,
5214 MULTIBYTE > 0 means enable it,
5215 MULTIBYTE < 0 means use IT->multibyte_p.
5217 IT must be initialized via a prior call to init_iterator before
5218 calling this function. */
5221 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5226 int precision
, field_width
, multibyte
;
5228 /* No region in strings. */
5229 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5231 /* No text property checks performed by default, but see below. */
5232 it
->stop_charpos
= -1;
5234 /* Set iterator position and end position. */
5235 bzero (&it
->current
, sizeof it
->current
);
5236 it
->current
.overlay_string_index
= -1;
5237 it
->current
.dpvec_index
= -1;
5238 xassert (charpos
>= 0);
5240 /* If STRING is specified, use its multibyteness, otherwise use the
5241 setting of MULTIBYTE, if specified. */
5243 it
->multibyte_p
= multibyte
> 0;
5247 xassert (STRINGP (string
));
5248 it
->string
= string
;
5250 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5251 it
->method
= GET_FROM_STRING
;
5252 it
->current
.string_pos
= string_pos (charpos
, string
);
5259 /* Note that we use IT->current.pos, not it->current.string_pos,
5260 for displaying C strings. */
5261 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5262 if (it
->multibyte_p
)
5264 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5265 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5269 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5270 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5273 it
->method
= GET_FROM_C_STRING
;
5276 /* PRECISION > 0 means don't return more than PRECISION characters
5278 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5279 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5281 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5282 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5283 FIELD_WIDTH < 0 means infinite field width. This is useful for
5284 padding with `-' at the end of a mode line. */
5285 if (field_width
< 0)
5286 field_width
= INFINITY
;
5287 if (field_width
> it
->end_charpos
- charpos
)
5288 it
->end_charpos
= charpos
+ field_width
;
5290 /* Use the standard display table for displaying strings. */
5291 if (DISP_TABLE_P (Vstandard_display_table
))
5292 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5294 it
->stop_charpos
= charpos
;
5300 /***********************************************************************
5302 ***********************************************************************/
5304 /* Map enum it_method value to corresponding next_element_from_* function. */
5306 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5308 next_element_from_buffer
,
5309 next_element_from_display_vector
,
5310 next_element_from_composition
,
5311 next_element_from_string
,
5312 next_element_from_c_string
,
5313 next_element_from_image
,
5314 next_element_from_stretch
5318 /* Load IT's display element fields with information about the next
5319 display element from the current position of IT. Value is zero if
5320 end of buffer (or C string) is reached. */
5322 static struct frame
*last_escape_glyph_frame
= NULL
;
5323 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5324 static int last_escape_glyph_merged_face_id
= 0;
5327 get_next_display_element (it
)
5330 /* Non-zero means that we found a display element. Zero means that
5331 we hit the end of what we iterate over. Performance note: the
5332 function pointer `method' used here turns out to be faster than
5333 using a sequence of if-statements. */
5337 success_p
= (*get_next_element
[it
->method
]) (it
);
5339 if (it
->what
== IT_CHARACTER
)
5341 /* Map via display table or translate control characters.
5342 IT->c, IT->len etc. have been set to the next character by
5343 the function call above. If we have a display table, and it
5344 contains an entry for IT->c, translate it. Don't do this if
5345 IT->c itself comes from a display table, otherwise we could
5346 end up in an infinite recursion. (An alternative could be to
5347 count the recursion depth of this function and signal an
5348 error when a certain maximum depth is reached.) Is it worth
5350 if (success_p
&& it
->dpvec
== NULL
)
5355 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5358 struct Lisp_Vector
*v
= XVECTOR (dv
);
5360 /* Return the first character from the display table
5361 entry, if not empty. If empty, don't display the
5362 current character. */
5365 it
->dpvec_char_len
= it
->len
;
5366 it
->dpvec
= v
->contents
;
5367 it
->dpend
= v
->contents
+ v
->size
;
5368 it
->current
.dpvec_index
= 0;
5369 it
->dpvec_face_id
= -1;
5370 it
->saved_face_id
= it
->face_id
;
5371 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5376 set_iterator_to_next (it
, 0);
5381 /* Translate control characters into `\003' or `^C' form.
5382 Control characters coming from a display table entry are
5383 currently not translated because we use IT->dpvec to hold
5384 the translation. This could easily be changed but I
5385 don't believe that it is worth doing.
5387 If it->multibyte_p is nonzero, eight-bit characters and
5388 non-printable multibyte characters are also translated to
5391 If it->multibyte_p is zero, eight-bit characters that
5392 don't have corresponding multibyte char code are also
5393 translated to octal form. */
5394 else if ((it
->c
< ' '
5395 && (it
->area
!= TEXT_AREA
5396 /* In mode line, treat \n like other crl chars. */
5398 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5399 || (it
->c
!= '\n' && it
->c
!= '\t')))
5403 || !CHAR_PRINTABLE_P (it
->c
)
5404 || (!NILP (Vnobreak_char_display
)
5405 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5406 || it
->c
== 0x920 || it
->c
== 0x92d
5407 || it
->c
== 0xe20 || it
->c
== 0xe2d
5408 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5410 && (!unibyte_display_via_language_environment
5411 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5413 /* IT->c is a control character which must be displayed
5414 either as '\003' or as `^C' where the '\\' and '^'
5415 can be defined in the display table. Fill
5416 IT->ctl_chars with glyphs for what we have to
5417 display. Then, set IT->dpvec to these glyphs. */
5420 int face_id
, lface_id
= 0 ;
5423 /* Handle control characters with ^. */
5425 if (it
->c
< 128 && it
->ctl_arrow_p
)
5427 g
= '^'; /* default glyph for Control */
5428 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5430 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5431 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5433 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5434 lface_id
= FAST_GLYPH_FACE (g
);
5438 g
= FAST_GLYPH_CHAR (g
);
5439 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5442 else if (it
->f
== last_escape_glyph_frame
5443 && it
->face_id
== last_escape_glyph_face_id
)
5445 face_id
= last_escape_glyph_merged_face_id
;
5449 /* Merge the escape-glyph face into the current face. */
5450 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5452 last_escape_glyph_frame
= it
->f
;
5453 last_escape_glyph_face_id
= it
->face_id
;
5454 last_escape_glyph_merged_face_id
= face_id
;
5457 XSETINT (it
->ctl_chars
[0], g
);
5459 XSETINT (it
->ctl_chars
[1], g
);
5461 goto display_control
;
5464 /* Handle non-break space in the mode where it only gets
5467 if (EQ (Vnobreak_char_display
, Qt
)
5468 && (it
->c
== 0x8a0 || it
->c
== 0x920
5469 || it
->c
== 0xe20 || it
->c
== 0xf20))
5471 /* Merge the no-break-space face into the current face. */
5472 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5476 XSETINT (it
->ctl_chars
[0], g
);
5478 goto display_control
;
5481 /* Handle sequences that start with the "escape glyph". */
5483 /* the default escape glyph is \. */
5484 escape_glyph
= '\\';
5487 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5488 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5490 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5491 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5495 /* The display table specified a face.
5496 Merge it into face_id and also into escape_glyph. */
5497 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5498 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5501 else if (it
->f
== last_escape_glyph_frame
5502 && it
->face_id
== last_escape_glyph_face_id
)
5504 face_id
= last_escape_glyph_merged_face_id
;
5508 /* Merge the escape-glyph face into the current face. */
5509 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5511 last_escape_glyph_frame
= it
->f
;
5512 last_escape_glyph_face_id
= it
->face_id
;
5513 last_escape_glyph_merged_face_id
= face_id
;
5516 /* Handle soft hyphens in the mode where they only get
5519 if (EQ (Vnobreak_char_display
, Qt
)
5520 && (it
->c
== 0x8ad || it
->c
== 0x92d
5521 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5524 XSETINT (it
->ctl_chars
[0], g
);
5526 goto display_control
;
5529 /* Handle non-break space and soft hyphen
5530 with the escape glyph. */
5532 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5533 || it
->c
== 0x920 || it
->c
== 0x92d
5534 || it
->c
== 0xe20 || it
->c
== 0xe2d
5535 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5537 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5538 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5539 XSETINT (it
->ctl_chars
[1], g
);
5541 goto display_control
;
5545 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5549 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5550 if (SINGLE_BYTE_CHAR_P (it
->c
))
5551 str
[0] = it
->c
, len
= 1;
5554 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5557 /* It's an invalid character, which shouldn't
5558 happen actually, but due to bugs it may
5559 happen. Let's print the char as is, there's
5560 not much meaningful we can do with it. */
5562 str
[1] = it
->c
>> 8;
5563 str
[2] = it
->c
>> 16;
5564 str
[3] = it
->c
>> 24;
5569 for (i
= 0; i
< len
; i
++)
5571 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5572 /* Insert three more glyphs into IT->ctl_chars for
5573 the octal display of the character. */
5574 g
= ((str
[i
] >> 6) & 7) + '0';
5575 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5576 g
= ((str
[i
] >> 3) & 7) + '0';
5577 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5578 g
= (str
[i
] & 7) + '0';
5579 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5585 /* Set up IT->dpvec and return first character from it. */
5586 it
->dpvec_char_len
= it
->len
;
5587 it
->dpvec
= it
->ctl_chars
;
5588 it
->dpend
= it
->dpvec
+ ctl_len
;
5589 it
->current
.dpvec_index
= 0;
5590 it
->dpvec_face_id
= face_id
;
5591 it
->saved_face_id
= it
->face_id
;
5592 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5598 /* Adjust face id for a multibyte character. There are no
5599 multibyte character in unibyte text. */
5602 && FRAME_WINDOW_P (it
->f
))
5604 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5605 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5609 /* Is this character the last one of a run of characters with
5610 box? If yes, set IT->end_of_box_run_p to 1. */
5617 it
->end_of_box_run_p
5618 = ((face_id
= face_after_it_pos (it
),
5619 face_id
!= it
->face_id
)
5620 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5621 face
->box
== FACE_NO_BOX
));
5624 /* Value is 0 if end of buffer or string reached. */
5629 /* Move IT to the next display element.
5631 RESEAT_P non-zero means if called on a newline in buffer text,
5632 skip to the next visible line start.
5634 Functions get_next_display_element and set_iterator_to_next are
5635 separate because I find this arrangement easier to handle than a
5636 get_next_display_element function that also increments IT's
5637 position. The way it is we can first look at an iterator's current
5638 display element, decide whether it fits on a line, and if it does,
5639 increment the iterator position. The other way around we probably
5640 would either need a flag indicating whether the iterator has to be
5641 incremented the next time, or we would have to implement a
5642 decrement position function which would not be easy to write. */
5645 set_iterator_to_next (it
, reseat_p
)
5649 /* Reset flags indicating start and end of a sequence of characters
5650 with box. Reset them at the start of this function because
5651 moving the iterator to a new position might set them. */
5652 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5656 case GET_FROM_BUFFER
:
5657 /* The current display element of IT is a character from
5658 current_buffer. Advance in the buffer, and maybe skip over
5659 invisible lines that are so because of selective display. */
5660 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5661 reseat_at_next_visible_line_start (it
, 0);
5664 xassert (it
->len
!= 0);
5665 IT_BYTEPOS (*it
) += it
->len
;
5666 IT_CHARPOS (*it
) += 1;
5667 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5671 case GET_FROM_COMPOSITION
:
5672 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5673 if (STRINGP (it
->string
))
5675 IT_STRING_BYTEPOS (*it
) += it
->len
;
5676 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5677 it
->method
= GET_FROM_STRING
;
5678 goto consider_string_end
;
5682 IT_BYTEPOS (*it
) += it
->len
;
5683 IT_CHARPOS (*it
) += it
->cmp_len
;
5684 it
->method
= GET_FROM_BUFFER
;
5688 case GET_FROM_C_STRING
:
5689 /* Current display element of IT is from a C string. */
5690 IT_BYTEPOS (*it
) += it
->len
;
5691 IT_CHARPOS (*it
) += 1;
5694 case GET_FROM_DISPLAY_VECTOR
:
5695 /* Current display element of IT is from a display table entry.
5696 Advance in the display table definition. Reset it to null if
5697 end reached, and continue with characters from buffers/
5699 ++it
->current
.dpvec_index
;
5701 /* Restore face of the iterator to what they were before the
5702 display vector entry (these entries may contain faces). */
5703 it
->face_id
= it
->saved_face_id
;
5705 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5707 int recheck_faces
= it
->ellipsis_p
;
5710 it
->method
= GET_FROM_C_STRING
;
5711 else if (STRINGP (it
->string
))
5712 it
->method
= GET_FROM_STRING
;
5714 it
->method
= GET_FROM_BUFFER
;
5717 it
->current
.dpvec_index
= -1;
5719 /* Skip over characters which were displayed via IT->dpvec. */
5720 if (it
->dpvec_char_len
< 0)
5721 reseat_at_next_visible_line_start (it
, 1);
5722 else if (it
->dpvec_char_len
> 0)
5724 if (it
->method
== GET_FROM_STRING
5725 && it
->n_overlay_strings
> 0)
5726 it
->ignore_overlay_strings_at_pos_p
= 1;
5727 it
->len
= it
->dpvec_char_len
;
5728 set_iterator_to_next (it
, reseat_p
);
5731 /* Maybe recheck faces after display vector */
5733 it
->stop_charpos
= IT_CHARPOS (*it
);
5737 case GET_FROM_STRING
:
5738 /* Current display element is a character from a Lisp string. */
5739 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5740 IT_STRING_BYTEPOS (*it
) += it
->len
;
5741 IT_STRING_CHARPOS (*it
) += 1;
5743 consider_string_end
:
5745 if (it
->current
.overlay_string_index
>= 0)
5747 /* IT->string is an overlay string. Advance to the
5748 next, if there is one. */
5749 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5750 next_overlay_string (it
);
5754 /* IT->string is not an overlay string. If we reached
5755 its end, and there is something on IT->stack, proceed
5756 with what is on the stack. This can be either another
5757 string, this time an overlay string, or a buffer. */
5758 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5762 if (STRINGP (it
->string
))
5763 goto consider_string_end
;
5764 it
->method
= GET_FROM_BUFFER
;
5769 case GET_FROM_IMAGE
:
5770 case GET_FROM_STRETCH
:
5771 /* The position etc with which we have to proceed are on
5772 the stack. The position may be at the end of a string,
5773 if the `display' property takes up the whole string. */
5774 xassert (it
->sp
> 0);
5777 if (STRINGP (it
->string
))
5779 it
->method
= GET_FROM_STRING
;
5780 goto consider_string_end
;
5782 it
->method
= GET_FROM_BUFFER
;
5786 /* There are no other methods defined, so this should be a bug. */
5790 xassert (it
->method
!= GET_FROM_STRING
5791 || (STRINGP (it
->string
)
5792 && IT_STRING_CHARPOS (*it
) >= 0));
5795 /* Load IT's display element fields with information about the next
5796 display element which comes from a display table entry or from the
5797 result of translating a control character to one of the forms `^C'
5800 IT->dpvec holds the glyphs to return as characters.
5801 IT->saved_face_id holds the face id before the display vector--
5802 it is restored into IT->face_idin set_iterator_to_next. */
5805 next_element_from_display_vector (it
)
5809 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5811 it
->face_id
= it
->saved_face_id
;
5813 if (INTEGERP (*it
->dpvec
)
5814 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5818 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5819 it
->c
= FAST_GLYPH_CHAR (g
);
5820 it
->len
= CHAR_BYTES (it
->c
);
5822 /* The entry may contain a face id to use. Such a face id is
5823 the id of a Lisp face, not a realized face. A face id of
5824 zero means no face is specified. */
5825 if (it
->dpvec_face_id
>= 0)
5826 it
->face_id
= it
->dpvec_face_id
;
5829 int lface_id
= FAST_GLYPH_FACE (g
);
5831 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5836 /* Display table entry is invalid. Return a space. */
5837 it
->c
= ' ', it
->len
= 1;
5839 /* Don't change position and object of the iterator here. They are
5840 still the values of the character that had this display table
5841 entry or was translated, and that's what we want. */
5842 it
->what
= IT_CHARACTER
;
5847 /* Load IT with the next display element from Lisp string IT->string.
5848 IT->current.string_pos is the current position within the string.
5849 If IT->current.overlay_string_index >= 0, the Lisp string is an
5853 next_element_from_string (it
)
5856 struct text_pos position
;
5858 xassert (STRINGP (it
->string
));
5859 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5860 position
= it
->current
.string_pos
;
5862 /* Time to check for invisible text? */
5863 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5864 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5868 /* Since a handler may have changed IT->method, we must
5870 return get_next_display_element (it
);
5873 if (it
->current
.overlay_string_index
>= 0)
5875 /* Get the next character from an overlay string. In overlay
5876 strings, There is no field width or padding with spaces to
5878 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5883 else if (STRING_MULTIBYTE (it
->string
))
5885 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5886 const unsigned char *s
= (SDATA (it
->string
)
5887 + IT_STRING_BYTEPOS (*it
));
5888 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5892 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5898 /* Get the next character from a Lisp string that is not an
5899 overlay string. Such strings come from the mode line, for
5900 example. We may have to pad with spaces, or truncate the
5901 string. See also next_element_from_c_string. */
5902 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5907 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5909 /* Pad with spaces. */
5910 it
->c
= ' ', it
->len
= 1;
5911 CHARPOS (position
) = BYTEPOS (position
) = -1;
5913 else if (STRING_MULTIBYTE (it
->string
))
5915 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5916 const unsigned char *s
= (SDATA (it
->string
)
5917 + IT_STRING_BYTEPOS (*it
));
5918 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5922 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5927 /* Record what we have and where it came from. Note that we store a
5928 buffer position in IT->position although it could arguably be a
5930 it
->what
= IT_CHARACTER
;
5931 it
->object
= it
->string
;
5932 it
->position
= position
;
5937 /* Load IT with next display element from C string IT->s.
5938 IT->string_nchars is the maximum number of characters to return
5939 from the string. IT->end_charpos may be greater than
5940 IT->string_nchars when this function is called, in which case we
5941 may have to return padding spaces. Value is zero if end of string
5942 reached, including padding spaces. */
5945 next_element_from_c_string (it
)
5951 it
->what
= IT_CHARACTER
;
5952 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5955 /* IT's position can be greater IT->string_nchars in case a field
5956 width or precision has been specified when the iterator was
5958 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5960 /* End of the game. */
5964 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5966 /* Pad with spaces. */
5967 it
->c
= ' ', it
->len
= 1;
5968 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5970 else if (it
->multibyte_p
)
5972 /* Implementation note: The calls to strlen apparently aren't a
5973 performance problem because there is no noticeable performance
5974 difference between Emacs running in unibyte or multibyte mode. */
5975 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5976 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5980 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5986 /* Set up IT to return characters from an ellipsis, if appropriate.
5987 The definition of the ellipsis glyphs may come from a display table
5988 entry. This function Fills IT with the first glyph from the
5989 ellipsis if an ellipsis is to be displayed. */
5992 next_element_from_ellipsis (it
)
5995 if (it
->selective_display_ellipsis_p
)
5996 setup_for_ellipsis (it
, it
->len
);
5999 /* The face at the current position may be different from the
6000 face we find after the invisible text. Remember what it
6001 was in IT->saved_face_id, and signal that it's there by
6002 setting face_before_selective_p. */
6003 it
->saved_face_id
= it
->face_id
;
6004 it
->method
= GET_FROM_BUFFER
;
6005 reseat_at_next_visible_line_start (it
, 1);
6006 it
->face_before_selective_p
= 1;
6009 return get_next_display_element (it
);
6013 /* Deliver an image display element. The iterator IT is already
6014 filled with image information (done in handle_display_prop). Value
6019 next_element_from_image (it
)
6022 it
->what
= IT_IMAGE
;
6027 /* Fill iterator IT with next display element from a stretch glyph
6028 property. IT->object is the value of the text property. Value is
6032 next_element_from_stretch (it
)
6035 it
->what
= IT_STRETCH
;
6040 /* Load IT with the next display element from current_buffer. Value
6041 is zero if end of buffer reached. IT->stop_charpos is the next
6042 position at which to stop and check for text properties or buffer
6046 next_element_from_buffer (it
)
6051 /* Check this assumption, otherwise, we would never enter the
6052 if-statement, below. */
6053 xassert (IT_CHARPOS (*it
) >= BEGV
6054 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6056 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6058 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6060 int overlay_strings_follow_p
;
6062 /* End of the game, except when overlay strings follow that
6063 haven't been returned yet. */
6064 if (it
->overlay_strings_at_end_processed_p
)
6065 overlay_strings_follow_p
= 0;
6068 it
->overlay_strings_at_end_processed_p
= 1;
6069 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6072 if (overlay_strings_follow_p
)
6073 success_p
= get_next_display_element (it
);
6077 it
->position
= it
->current
.pos
;
6084 return get_next_display_element (it
);
6089 /* No face changes, overlays etc. in sight, so just return a
6090 character from current_buffer. */
6093 /* Maybe run the redisplay end trigger hook. Performance note:
6094 This doesn't seem to cost measurable time. */
6095 if (it
->redisplay_end_trigger_charpos
6097 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6098 run_redisplay_end_trigger_hook (it
);
6100 /* Get the next character, maybe multibyte. */
6101 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6102 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6104 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6105 - IT_BYTEPOS (*it
));
6106 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6109 it
->c
= *p
, it
->len
= 1;
6111 /* Record what we have and where it came from. */
6112 it
->what
= IT_CHARACTER
;;
6113 it
->object
= it
->w
->buffer
;
6114 it
->position
= it
->current
.pos
;
6116 /* Normally we return the character found above, except when we
6117 really want to return an ellipsis for selective display. */
6122 /* A value of selective > 0 means hide lines indented more
6123 than that number of columns. */
6124 if (it
->selective
> 0
6125 && IT_CHARPOS (*it
) + 1 < ZV
6126 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6127 IT_BYTEPOS (*it
) + 1,
6128 (double) it
->selective
)) /* iftc */
6130 success_p
= next_element_from_ellipsis (it
);
6131 it
->dpvec_char_len
= -1;
6134 else if (it
->c
== '\r' && it
->selective
== -1)
6136 /* A value of selective == -1 means that everything from the
6137 CR to the end of the line is invisible, with maybe an
6138 ellipsis displayed for it. */
6139 success_p
= next_element_from_ellipsis (it
);
6140 it
->dpvec_char_len
= -1;
6145 /* Value is zero if end of buffer reached. */
6146 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6151 /* Run the redisplay end trigger hook for IT. */
6154 run_redisplay_end_trigger_hook (it
)
6157 Lisp_Object args
[3];
6159 /* IT->glyph_row should be non-null, i.e. we should be actually
6160 displaying something, or otherwise we should not run the hook. */
6161 xassert (it
->glyph_row
);
6163 /* Set up hook arguments. */
6164 args
[0] = Qredisplay_end_trigger_functions
;
6165 args
[1] = it
->window
;
6166 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6167 it
->redisplay_end_trigger_charpos
= 0;
6169 /* Since we are *trying* to run these functions, don't try to run
6170 them again, even if they get an error. */
6171 it
->w
->redisplay_end_trigger
= Qnil
;
6172 Frun_hook_with_args (3, args
);
6174 /* Notice if it changed the face of the character we are on. */
6175 handle_face_prop (it
);
6179 /* Deliver a composition display element. The iterator IT is already
6180 filled with composition information (done in
6181 handle_composition_prop). Value is always 1. */
6184 next_element_from_composition (it
)
6187 it
->what
= IT_COMPOSITION
;
6188 it
->position
= (STRINGP (it
->string
)
6189 ? it
->current
.string_pos
6196 /***********************************************************************
6197 Moving an iterator without producing glyphs
6198 ***********************************************************************/
6200 /* Check if iterator is at a position corresponding to a valid buffer
6201 position after some move_it_ call. */
6203 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6204 ((it)->method == GET_FROM_STRING \
6205 ? IT_STRING_CHARPOS (*it) == 0 \
6209 /* Move iterator IT to a specified buffer or X position within one
6210 line on the display without producing glyphs.
6212 OP should be a bit mask including some or all of these bits:
6213 MOVE_TO_X: Stop on reaching x-position TO_X.
6214 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6215 Regardless of OP's value, stop in reaching the end of the display line.
6217 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6218 This means, in particular, that TO_X includes window's horizontal
6221 The return value has several possible values that
6222 say what condition caused the scan to stop:
6224 MOVE_POS_MATCH_OR_ZV
6225 - when TO_POS or ZV was reached.
6228 -when TO_X was reached before TO_POS or ZV were reached.
6231 - when we reached the end of the display area and the line must
6235 - when we reached the end of the display area and the line is
6239 - when we stopped at a line end, i.e. a newline or a CR and selective
6242 static enum move_it_result
6243 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6245 int to_charpos
, to_x
, op
;
6247 enum move_it_result result
= MOVE_UNDEFINED
;
6248 struct glyph_row
*saved_glyph_row
;
6250 /* Don't produce glyphs in produce_glyphs. */
6251 saved_glyph_row
= it
->glyph_row
;
6252 it
->glyph_row
= NULL
;
6254 #define BUFFER_POS_REACHED_P() \
6255 ((op & MOVE_TO_POS) != 0 \
6256 && BUFFERP (it->object) \
6257 && IT_CHARPOS (*it) >= to_charpos \
6258 && (it->method == GET_FROM_BUFFER \
6259 || (it->method == GET_FROM_DISPLAY_VECTOR \
6260 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6265 int x
, i
, ascent
= 0, descent
= 0;
6267 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6268 if ((op
& MOVE_TO_POS
) != 0
6269 && BUFFERP (it
->object
)
6270 && it
->method
== GET_FROM_BUFFER
6271 && IT_CHARPOS (*it
) > to_charpos
)
6273 result
= MOVE_POS_MATCH_OR_ZV
;
6277 /* Stop when ZV reached.
6278 We used to stop here when TO_CHARPOS reached as well, but that is
6279 too soon if this glyph does not fit on this line. So we handle it
6280 explicitly below. */
6281 if (!get_next_display_element (it
)
6282 || (it
->truncate_lines_p
6283 && BUFFER_POS_REACHED_P ()))
6285 result
= MOVE_POS_MATCH_OR_ZV
;
6289 /* The call to produce_glyphs will get the metrics of the
6290 display element IT is loaded with. We record in x the
6291 x-position before this display element in case it does not
6295 /* Remember the line height so far in case the next element doesn't
6297 if (!it
->truncate_lines_p
)
6299 ascent
= it
->max_ascent
;
6300 descent
= it
->max_descent
;
6303 PRODUCE_GLYPHS (it
);
6305 if (it
->area
!= TEXT_AREA
)
6307 set_iterator_to_next (it
, 1);
6311 /* The number of glyphs we get back in IT->nglyphs will normally
6312 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6313 character on a terminal frame, or (iii) a line end. For the
6314 second case, IT->nglyphs - 1 padding glyphs will be present
6315 (on X frames, there is only one glyph produced for a
6316 composite character.
6318 The behavior implemented below means, for continuation lines,
6319 that as many spaces of a TAB as fit on the current line are
6320 displayed there. For terminal frames, as many glyphs of a
6321 multi-glyph character are displayed in the current line, too.
6322 This is what the old redisplay code did, and we keep it that
6323 way. Under X, the whole shape of a complex character must
6324 fit on the line or it will be completely displayed in the
6327 Note that both for tabs and padding glyphs, all glyphs have
6331 /* More than one glyph or glyph doesn't fit on line. All
6332 glyphs have the same width. */
6333 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6335 int x_before_this_char
= x
;
6336 int hpos_before_this_char
= it
->hpos
;
6338 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6340 new_x
= x
+ single_glyph_width
;
6342 /* We want to leave anything reaching TO_X to the caller. */
6343 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6345 if (BUFFER_POS_REACHED_P ())
6346 goto buffer_pos_reached
;
6348 result
= MOVE_X_REACHED
;
6351 else if (/* Lines are continued. */
6352 !it
->truncate_lines_p
6353 && (/* And glyph doesn't fit on the line. */
6354 new_x
> it
->last_visible_x
6355 /* Or it fits exactly and we're on a window
6357 || (new_x
== it
->last_visible_x
6358 && FRAME_WINDOW_P (it
->f
))))
6360 if (/* IT->hpos == 0 means the very first glyph
6361 doesn't fit on the line, e.g. a wide image. */
6363 || (new_x
== it
->last_visible_x
6364 && FRAME_WINDOW_P (it
->f
)))
6367 it
->current_x
= new_x
;
6369 /* The character's last glyph just barely fits
6371 if (i
== it
->nglyphs
- 1)
6373 /* If this is the destination position,
6374 return a position *before* it in this row,
6375 now that we know it fits in this row. */
6376 if (BUFFER_POS_REACHED_P ())
6378 it
->hpos
= hpos_before_this_char
;
6379 it
->current_x
= x_before_this_char
;
6380 result
= MOVE_POS_MATCH_OR_ZV
;
6384 set_iterator_to_next (it
, 1);
6385 #ifdef HAVE_WINDOW_SYSTEM
6386 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6388 if (!get_next_display_element (it
))
6390 result
= MOVE_POS_MATCH_OR_ZV
;
6393 if (BUFFER_POS_REACHED_P ())
6395 if (ITERATOR_AT_END_OF_LINE_P (it
))
6396 result
= MOVE_POS_MATCH_OR_ZV
;
6398 result
= MOVE_LINE_CONTINUED
;
6401 if (ITERATOR_AT_END_OF_LINE_P (it
))
6403 result
= MOVE_NEWLINE_OR_CR
;
6407 #endif /* HAVE_WINDOW_SYSTEM */
6413 it
->max_ascent
= ascent
;
6414 it
->max_descent
= descent
;
6417 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6419 result
= MOVE_LINE_CONTINUED
;
6422 else if (BUFFER_POS_REACHED_P ())
6423 goto buffer_pos_reached
;
6424 else if (new_x
> it
->first_visible_x
)
6426 /* Glyph is visible. Increment number of glyphs that
6427 would be displayed. */
6432 /* Glyph is completely off the left margin of the display
6433 area. Nothing to do. */
6437 if (result
!= MOVE_UNDEFINED
)
6440 else if (BUFFER_POS_REACHED_P ())
6444 it
->max_ascent
= ascent
;
6445 it
->max_descent
= descent
;
6446 result
= MOVE_POS_MATCH_OR_ZV
;
6449 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6451 /* Stop when TO_X specified and reached. This check is
6452 necessary here because of lines consisting of a line end,
6453 only. The line end will not produce any glyphs and we
6454 would never get MOVE_X_REACHED. */
6455 xassert (it
->nglyphs
== 0);
6456 result
= MOVE_X_REACHED
;
6460 /* Is this a line end? If yes, we're done. */
6461 if (ITERATOR_AT_END_OF_LINE_P (it
))
6463 result
= MOVE_NEWLINE_OR_CR
;
6467 /* The current display element has been consumed. Advance
6469 set_iterator_to_next (it
, 1);
6471 /* Stop if lines are truncated and IT's current x-position is
6472 past the right edge of the window now. */
6473 if (it
->truncate_lines_p
6474 && it
->current_x
>= it
->last_visible_x
)
6476 #ifdef HAVE_WINDOW_SYSTEM
6477 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6479 if (!get_next_display_element (it
)
6480 || BUFFER_POS_REACHED_P ())
6482 result
= MOVE_POS_MATCH_OR_ZV
;
6485 if (ITERATOR_AT_END_OF_LINE_P (it
))
6487 result
= MOVE_NEWLINE_OR_CR
;
6491 #endif /* HAVE_WINDOW_SYSTEM */
6492 result
= MOVE_LINE_TRUNCATED
;
6497 #undef BUFFER_POS_REACHED_P
6499 /* Restore the iterator settings altered at the beginning of this
6501 it
->glyph_row
= saved_glyph_row
;
6506 /* Move IT forward until it satisfies one or more of the criteria in
6507 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6509 OP is a bit-mask that specifies where to stop, and in particular,
6510 which of those four position arguments makes a difference. See the
6511 description of enum move_operation_enum.
6513 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6514 screen line, this function will set IT to the next position >
6518 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6520 int to_charpos
, to_x
, to_y
, to_vpos
;
6523 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6529 if (op
& MOVE_TO_VPOS
)
6531 /* If no TO_CHARPOS and no TO_X specified, stop at the
6532 start of the line TO_VPOS. */
6533 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6535 if (it
->vpos
== to_vpos
)
6541 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6545 /* TO_VPOS >= 0 means stop at TO_X in the line at
6546 TO_VPOS, or at TO_POS, whichever comes first. */
6547 if (it
->vpos
== to_vpos
)
6553 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6555 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6560 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6562 /* We have reached TO_X but not in the line we want. */
6563 skip
= move_it_in_display_line_to (it
, to_charpos
,
6565 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6573 else if (op
& MOVE_TO_Y
)
6575 struct it it_backup
;
6577 /* TO_Y specified means stop at TO_X in the line containing
6578 TO_Y---or at TO_CHARPOS if this is reached first. The
6579 problem is that we can't really tell whether the line
6580 contains TO_Y before we have completely scanned it, and
6581 this may skip past TO_X. What we do is to first scan to
6584 If TO_X is not specified, use a TO_X of zero. The reason
6585 is to make the outcome of this function more predictable.
6586 If we didn't use TO_X == 0, we would stop at the end of
6587 the line which is probably not what a caller would expect
6589 skip
= move_it_in_display_line_to (it
, to_charpos
,
6593 | (op
& MOVE_TO_POS
)));
6595 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6596 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6602 /* If TO_X was reached, we would like to know whether TO_Y
6603 is in the line. This can only be said if we know the
6604 total line height which requires us to scan the rest of
6606 if (skip
== MOVE_X_REACHED
)
6609 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6610 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6612 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6615 /* Now, decide whether TO_Y is in this line. */
6616 line_height
= it
->max_ascent
+ it
->max_descent
;
6617 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6619 if (to_y
>= it
->current_y
6620 && to_y
< it
->current_y
+ line_height
)
6622 if (skip
== MOVE_X_REACHED
)
6623 /* If TO_Y is in this line and TO_X was reached above,
6624 we scanned too far. We have to restore IT's settings
6625 to the ones before skipping. */
6629 else if (skip
== MOVE_X_REACHED
)
6632 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6640 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6644 case MOVE_POS_MATCH_OR_ZV
:
6648 case MOVE_NEWLINE_OR_CR
:
6649 set_iterator_to_next (it
, 1);
6650 it
->continuation_lines_width
= 0;
6653 case MOVE_LINE_TRUNCATED
:
6654 it
->continuation_lines_width
= 0;
6655 reseat_at_next_visible_line_start (it
, 0);
6656 if ((op
& MOVE_TO_POS
) != 0
6657 && IT_CHARPOS (*it
) > to_charpos
)
6664 case MOVE_LINE_CONTINUED
:
6665 it
->continuation_lines_width
+= it
->current_x
;
6672 /* Reset/increment for the next run. */
6673 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6674 it
->current_x
= it
->hpos
= 0;
6675 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6677 last_height
= it
->max_ascent
+ it
->max_descent
;
6678 last_max_ascent
= it
->max_ascent
;
6679 it
->max_ascent
= it
->max_descent
= 0;
6684 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6688 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6690 If DY > 0, move IT backward at least that many pixels. DY = 0
6691 means move IT backward to the preceding line start or BEGV. This
6692 function may move over more than DY pixels if IT->current_y - DY
6693 ends up in the middle of a line; in this case IT->current_y will be
6694 set to the top of the line moved to. */
6697 move_it_vertically_backward (it
, dy
)
6708 start_pos
= IT_CHARPOS (*it
);
6710 /* Estimate how many newlines we must move back. */
6711 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6713 /* Set the iterator's position that many lines back. */
6714 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6715 back_to_previous_visible_line_start (it
);
6717 /* Reseat the iterator here. When moving backward, we don't want
6718 reseat to skip forward over invisible text, set up the iterator
6719 to deliver from overlay strings at the new position etc. So,
6720 use reseat_1 here. */
6721 reseat_1 (it
, it
->current
.pos
, 1);
6723 /* We are now surely at a line start. */
6724 it
->current_x
= it
->hpos
= 0;
6725 it
->continuation_lines_width
= 0;
6727 /* Move forward and see what y-distance we moved. First move to the
6728 start of the next line so that we get its height. We need this
6729 height to be able to tell whether we reached the specified
6732 it2
.max_ascent
= it2
.max_descent
= 0;
6735 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6736 MOVE_TO_POS
| MOVE_TO_VPOS
);
6738 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6739 xassert (IT_CHARPOS (*it
) >= BEGV
);
6742 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6743 xassert (IT_CHARPOS (*it
) >= BEGV
);
6744 /* H is the actual vertical distance from the position in *IT
6745 and the starting position. */
6746 h
= it2
.current_y
- it
->current_y
;
6747 /* NLINES is the distance in number of lines. */
6748 nlines
= it2
.vpos
- it
->vpos
;
6750 /* Correct IT's y and vpos position
6751 so that they are relative to the starting point. */
6757 /* DY == 0 means move to the start of the screen line. The
6758 value of nlines is > 0 if continuation lines were involved. */
6760 move_it_by_lines (it
, nlines
, 1);
6762 /* I think this assert is bogus if buffer contains
6763 invisible text or images. KFS. */
6764 xassert (IT_CHARPOS (*it
) <= start_pos
);
6769 /* The y-position we try to reach, relative to *IT.
6770 Note that H has been subtracted in front of the if-statement. */
6771 int target_y
= it
->current_y
+ h
- dy
;
6772 int y0
= it3
.current_y
;
6773 int y1
= line_bottom_y (&it3
);
6774 int line_height
= y1
- y0
;
6776 /* If we did not reach target_y, try to move further backward if
6777 we can. If we moved too far backward, try to move forward. */
6778 if (target_y
< it
->current_y
6779 /* This is heuristic. In a window that's 3 lines high, with
6780 a line height of 13 pixels each, recentering with point
6781 on the bottom line will try to move -39/2 = 19 pixels
6782 backward. Try to avoid moving into the first line. */
6783 && (it
->current_y
- target_y
6784 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6785 && IT_CHARPOS (*it
) > BEGV
)
6787 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6788 target_y
- it
->current_y
));
6789 dy
= it
->current_y
- target_y
;
6790 goto move_further_back
;
6792 else if (target_y
>= it
->current_y
+ line_height
6793 && IT_CHARPOS (*it
) < ZV
)
6795 /* Should move forward by at least one line, maybe more.
6797 Note: Calling move_it_by_lines can be expensive on
6798 terminal frames, where compute_motion is used (via
6799 vmotion) to do the job, when there are very long lines
6800 and truncate-lines is nil. That's the reason for
6801 treating terminal frames specially here. */
6803 if (!FRAME_WINDOW_P (it
->f
))
6804 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6809 move_it_by_lines (it
, 1, 1);
6811 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6815 /* I think this assert is bogus if buffer contains
6816 invisible text or images. KFS. */
6817 xassert (IT_CHARPOS (*it
) >= BEGV
);
6824 /* Move IT by a specified amount of pixel lines DY. DY negative means
6825 move backwards. DY = 0 means move to start of screen line. At the
6826 end, IT will be on the start of a screen line. */
6829 move_it_vertically (it
, dy
)
6834 move_it_vertically_backward (it
, -dy
);
6837 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6838 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6839 MOVE_TO_POS
| MOVE_TO_Y
);
6840 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6842 /* If buffer ends in ZV without a newline, move to the start of
6843 the line to satisfy the post-condition. */
6844 if (IT_CHARPOS (*it
) == ZV
6846 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6847 move_it_by_lines (it
, 0, 0);
6852 /* Move iterator IT past the end of the text line it is in. */
6855 move_it_past_eol (it
)
6858 enum move_it_result rc
;
6860 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6861 if (rc
== MOVE_NEWLINE_OR_CR
)
6862 set_iterator_to_next (it
, 0);
6866 #if 0 /* Currently not used. */
6868 /* Return non-zero if some text between buffer positions START_CHARPOS
6869 and END_CHARPOS is invisible. IT->window is the window for text
6873 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6875 int start_charpos
, end_charpos
;
6877 Lisp_Object prop
, limit
;
6878 int invisible_found_p
;
6880 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6882 /* Is text at START invisible? */
6883 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6885 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6886 invisible_found_p
= 1;
6889 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6891 make_number (end_charpos
));
6892 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6895 return invisible_found_p
;
6901 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6902 negative means move up. DVPOS == 0 means move to the start of the
6903 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6904 NEED_Y_P is zero, IT->current_y will be left unchanged.
6906 Further optimization ideas: If we would know that IT->f doesn't use
6907 a face with proportional font, we could be faster for
6908 truncate-lines nil. */
6911 move_it_by_lines (it
, dvpos
, need_y_p
)
6913 int dvpos
, need_y_p
;
6915 struct position pos
;
6917 if (!FRAME_WINDOW_P (it
->f
))
6919 struct text_pos textpos
;
6921 /* We can use vmotion on frames without proportional fonts. */
6922 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6923 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6924 reseat (it
, textpos
, 1);
6925 it
->vpos
+= pos
.vpos
;
6926 it
->current_y
+= pos
.vpos
;
6928 else if (dvpos
== 0)
6930 /* DVPOS == 0 means move to the start of the screen line. */
6931 move_it_vertically_backward (it
, 0);
6932 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6933 /* Let next call to line_bottom_y calculate real line height */
6938 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6939 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6940 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6945 int start_charpos
, i
;
6947 /* Start at the beginning of the screen line containing IT's
6948 position. This may actually move vertically backwards,
6949 in case of overlays, so adjust dvpos accordingly. */
6951 move_it_vertically_backward (it
, 0);
6954 /* Go back -DVPOS visible lines and reseat the iterator there. */
6955 start_charpos
= IT_CHARPOS (*it
);
6956 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6957 back_to_previous_visible_line_start (it
);
6958 reseat (it
, it
->current
.pos
, 1);
6960 /* Move further back if we end up in a string or an image. */
6961 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6963 /* First try to move to start of display line. */
6965 move_it_vertically_backward (it
, 0);
6967 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6969 /* If start of line is still in string or image,
6970 move further back. */
6971 back_to_previous_visible_line_start (it
);
6972 reseat (it
, it
->current
.pos
, 1);
6976 it
->current_x
= it
->hpos
= 0;
6978 /* Above call may have moved too far if continuation lines
6979 are involved. Scan forward and see if it did. */
6981 it2
.vpos
= it2
.current_y
= 0;
6982 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6983 it
->vpos
-= it2
.vpos
;
6984 it
->current_y
-= it2
.current_y
;
6985 it
->current_x
= it
->hpos
= 0;
6987 /* If we moved too far back, move IT some lines forward. */
6988 if (it2
.vpos
> -dvpos
)
6990 int delta
= it2
.vpos
+ dvpos
;
6992 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6993 /* Move back again if we got too far ahead. */
6994 if (IT_CHARPOS (*it
) >= start_charpos
)
7000 /* Return 1 if IT points into the middle of a display vector. */
7003 in_display_vector_p (it
)
7006 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7007 && it
->current
.dpvec_index
> 0
7008 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7012 /***********************************************************************
7014 ***********************************************************************/
7017 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7021 add_to_log (format
, arg1
, arg2
)
7023 Lisp_Object arg1
, arg2
;
7025 Lisp_Object args
[3];
7026 Lisp_Object msg
, fmt
;
7029 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7032 /* Do nothing if called asynchronously. Inserting text into
7033 a buffer may call after-change-functions and alike and
7034 that would means running Lisp asynchronously. */
7035 if (handling_signal
)
7039 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7041 args
[0] = fmt
= build_string (format
);
7044 msg
= Fformat (3, args
);
7046 len
= SBYTES (msg
) + 1;
7047 SAFE_ALLOCA (buffer
, char *, len
);
7048 bcopy (SDATA (msg
), buffer
, len
);
7050 message_dolog (buffer
, len
- 1, 1, 0);
7057 /* Output a newline in the *Messages* buffer if "needs" one. */
7060 message_log_maybe_newline ()
7062 if (message_log_need_newline
)
7063 message_dolog ("", 0, 1, 0);
7067 /* Add a string M of length NBYTES to the message log, optionally
7068 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7069 nonzero, means interpret the contents of M as multibyte. This
7070 function calls low-level routines in order to bypass text property
7071 hooks, etc. which might not be safe to run.
7073 This may GC (insert may run before/after change hooks),
7074 so the buffer M must NOT point to a Lisp string. */
7077 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7079 int nbytes
, nlflag
, multibyte
;
7081 if (!NILP (Vmemory_full
))
7084 if (!NILP (Vmessage_log_max
))
7086 struct buffer
*oldbuf
;
7087 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7088 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7089 int point_at_end
= 0;
7091 Lisp_Object old_deactivate_mark
, tem
;
7092 struct gcpro gcpro1
;
7094 old_deactivate_mark
= Vdeactivate_mark
;
7095 oldbuf
= current_buffer
;
7096 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7097 current_buffer
->undo_list
= Qt
;
7099 oldpoint
= message_dolog_marker1
;
7100 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7101 oldbegv
= message_dolog_marker2
;
7102 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7103 oldzv
= message_dolog_marker3
;
7104 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7105 GCPRO1 (old_deactivate_mark
);
7113 BEGV_BYTE
= BEG_BYTE
;
7116 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7118 /* Insert the string--maybe converting multibyte to single byte
7119 or vice versa, so that all the text fits the buffer. */
7121 && NILP (current_buffer
->enable_multibyte_characters
))
7123 int i
, c
, char_bytes
;
7124 unsigned char work
[1];
7126 /* Convert a multibyte string to single-byte
7127 for the *Message* buffer. */
7128 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7130 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7131 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7133 : multibyte_char_to_unibyte (c
, Qnil
));
7134 insert_1_both (work
, 1, 1, 1, 0, 0);
7137 else if (! multibyte
7138 && ! NILP (current_buffer
->enable_multibyte_characters
))
7140 int i
, c
, char_bytes
;
7141 unsigned char *msg
= (unsigned char *) m
;
7142 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7143 /* Convert a single-byte string to multibyte
7144 for the *Message* buffer. */
7145 for (i
= 0; i
< nbytes
; i
++)
7147 c
= unibyte_char_to_multibyte (msg
[i
]);
7148 char_bytes
= CHAR_STRING (c
, str
);
7149 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7153 insert_1 (m
, nbytes
, 1, 0, 0);
7157 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7158 insert_1 ("\n", 1, 1, 0, 0);
7160 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7162 this_bol_byte
= PT_BYTE
;
7164 /* See if this line duplicates the previous one.
7165 If so, combine duplicates. */
7168 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7170 prev_bol_byte
= PT_BYTE
;
7172 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7173 this_bol
, this_bol_byte
);
7176 del_range_both (prev_bol
, prev_bol_byte
,
7177 this_bol
, this_bol_byte
, 0);
7183 /* If you change this format, don't forget to also
7184 change message_log_check_duplicate. */
7185 sprintf (dupstr
, " [%d times]", dup
);
7186 duplen
= strlen (dupstr
);
7187 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7188 insert_1 (dupstr
, duplen
, 1, 0, 1);
7193 /* If we have more than the desired maximum number of lines
7194 in the *Messages* buffer now, delete the oldest ones.
7195 This is safe because we don't have undo in this buffer. */
7197 if (NATNUMP (Vmessage_log_max
))
7199 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7200 -XFASTINT (Vmessage_log_max
) - 1, 0);
7201 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7204 BEGV
= XMARKER (oldbegv
)->charpos
;
7205 BEGV_BYTE
= marker_byte_position (oldbegv
);
7214 ZV
= XMARKER (oldzv
)->charpos
;
7215 ZV_BYTE
= marker_byte_position (oldzv
);
7219 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7221 /* We can't do Fgoto_char (oldpoint) because it will run some
7223 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7224 XMARKER (oldpoint
)->bytepos
);
7227 unchain_marker (XMARKER (oldpoint
));
7228 unchain_marker (XMARKER (oldbegv
));
7229 unchain_marker (XMARKER (oldzv
));
7231 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7232 set_buffer_internal (oldbuf
);
7234 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7235 message_log_need_newline
= !nlflag
;
7236 Vdeactivate_mark
= old_deactivate_mark
;
7241 /* We are at the end of the buffer after just having inserted a newline.
7242 (Note: We depend on the fact we won't be crossing the gap.)
7243 Check to see if the most recent message looks a lot like the previous one.
7244 Return 0 if different, 1 if the new one should just replace it, or a
7245 value N > 1 if we should also append " [N times]". */
7248 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7249 int prev_bol
, this_bol
;
7250 int prev_bol_byte
, this_bol_byte
;
7253 int len
= Z_BYTE
- 1 - this_bol_byte
;
7255 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7256 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7258 for (i
= 0; i
< len
; i
++)
7260 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7268 if (*p1
++ == ' ' && *p1
++ == '[')
7271 while (*p1
>= '0' && *p1
<= '9')
7272 n
= n
* 10 + *p1
++ - '0';
7273 if (strncmp (p1
, " times]\n", 8) == 0)
7280 /* Display an echo area message M with a specified length of NBYTES
7281 bytes. The string may include null characters. If M is 0, clear
7282 out any existing message, and let the mini-buffer text show
7285 This may GC, so the buffer M must NOT point to a Lisp string. */
7288 message2 (m
, nbytes
, multibyte
)
7293 /* First flush out any partial line written with print. */
7294 message_log_maybe_newline ();
7296 message_dolog (m
, nbytes
, 1, multibyte
);
7297 message2_nolog (m
, nbytes
, multibyte
);
7301 /* The non-logging counterpart of message2. */
7304 message2_nolog (m
, nbytes
, multibyte
)
7306 int nbytes
, multibyte
;
7308 struct frame
*sf
= SELECTED_FRAME ();
7309 message_enable_multibyte
= multibyte
;
7313 if (noninteractive_need_newline
)
7314 putc ('\n', stderr
);
7315 noninteractive_need_newline
= 0;
7317 fwrite (m
, nbytes
, 1, stderr
);
7318 if (cursor_in_echo_area
== 0)
7319 fprintf (stderr
, "\n");
7322 /* A null message buffer means that the frame hasn't really been
7323 initialized yet. Error messages get reported properly by
7324 cmd_error, so this must be just an informative message; toss it. */
7325 else if (INTERACTIVE
7326 && sf
->glyphs_initialized_p
7327 && FRAME_MESSAGE_BUF (sf
))
7329 Lisp_Object mini_window
;
7332 /* Get the frame containing the mini-buffer
7333 that the selected frame is using. */
7334 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7335 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7337 FRAME_SAMPLE_VISIBILITY (f
);
7338 if (FRAME_VISIBLE_P (sf
)
7339 && ! FRAME_VISIBLE_P (f
))
7340 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7344 set_message (m
, Qnil
, nbytes
, multibyte
);
7345 if (minibuffer_auto_raise
)
7346 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7349 clear_message (1, 1);
7351 do_pending_window_change (0);
7352 echo_area_display (1);
7353 do_pending_window_change (0);
7354 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7355 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7360 /* Display an echo area message M with a specified length of NBYTES
7361 bytes. The string may include null characters. If M is not a
7362 string, clear out any existing message, and let the mini-buffer
7365 This function cancels echoing. */
7368 message3 (m
, nbytes
, multibyte
)
7373 struct gcpro gcpro1
;
7376 clear_message (1,1);
7379 /* First flush out any partial line written with print. */
7380 message_log_maybe_newline ();
7386 SAFE_ALLOCA (buffer
, char *, nbytes
);
7387 bcopy (SDATA (m
), buffer
, nbytes
);
7388 message_dolog (buffer
, nbytes
, 1, multibyte
);
7391 message3_nolog (m
, nbytes
, multibyte
);
7397 /* The non-logging version of message3.
7398 This does not cancel echoing, because it is used for echoing.
7399 Perhaps we need to make a separate function for echoing
7400 and make this cancel echoing. */
7403 message3_nolog (m
, nbytes
, multibyte
)
7405 int nbytes
, multibyte
;
7407 struct frame
*sf
= SELECTED_FRAME ();
7408 message_enable_multibyte
= multibyte
;
7412 if (noninteractive_need_newline
)
7413 putc ('\n', stderr
);
7414 noninteractive_need_newline
= 0;
7416 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7417 if (cursor_in_echo_area
== 0)
7418 fprintf (stderr
, "\n");
7421 /* A null message buffer means that the frame hasn't really been
7422 initialized yet. Error messages get reported properly by
7423 cmd_error, so this must be just an informative message; toss it. */
7424 else if (INTERACTIVE
7425 && sf
->glyphs_initialized_p
7426 && FRAME_MESSAGE_BUF (sf
))
7428 Lisp_Object mini_window
;
7432 /* Get the frame containing the mini-buffer
7433 that the selected frame is using. */
7434 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7435 frame
= XWINDOW (mini_window
)->frame
;
7438 FRAME_SAMPLE_VISIBILITY (f
);
7439 if (FRAME_VISIBLE_P (sf
)
7440 && !FRAME_VISIBLE_P (f
))
7441 Fmake_frame_visible (frame
);
7443 if (STRINGP (m
) && SCHARS (m
) > 0)
7445 set_message (NULL
, m
, nbytes
, multibyte
);
7446 if (minibuffer_auto_raise
)
7447 Fraise_frame (frame
);
7448 /* Assume we are not echoing.
7449 (If we are, echo_now will override this.) */
7450 echo_message_buffer
= Qnil
;
7453 clear_message (1, 1);
7455 do_pending_window_change (0);
7456 echo_area_display (1);
7457 do_pending_window_change (0);
7458 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7459 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7464 /* Display a null-terminated echo area message M. If M is 0, clear
7465 out any existing message, and let the mini-buffer text show through.
7467 The buffer M must continue to exist until after the echo area gets
7468 cleared or some other message gets displayed there. Do not pass
7469 text that is stored in a Lisp string. Do not pass text in a buffer
7470 that was alloca'd. */
7476 message2 (m
, (m
? strlen (m
) : 0), 0);
7480 /* The non-logging counterpart of message1. */
7486 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7489 /* Display a message M which contains a single %s
7490 which gets replaced with STRING. */
7493 message_with_string (m
, string
, log
)
7498 CHECK_STRING (string
);
7504 if (noninteractive_need_newline
)
7505 putc ('\n', stderr
);
7506 noninteractive_need_newline
= 0;
7507 fprintf (stderr
, m
, SDATA (string
));
7508 if (cursor_in_echo_area
== 0)
7509 fprintf (stderr
, "\n");
7513 else if (INTERACTIVE
)
7515 /* The frame whose minibuffer we're going to display the message on.
7516 It may be larger than the selected frame, so we need
7517 to use its buffer, not the selected frame's buffer. */
7518 Lisp_Object mini_window
;
7519 struct frame
*f
, *sf
= SELECTED_FRAME ();
7521 /* Get the frame containing the minibuffer
7522 that the selected frame is using. */
7523 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7524 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7526 /* A null message buffer means that the frame hasn't really been
7527 initialized yet. Error messages get reported properly by
7528 cmd_error, so this must be just an informative message; toss it. */
7529 if (FRAME_MESSAGE_BUF (f
))
7531 Lisp_Object args
[2], message
;
7532 struct gcpro gcpro1
, gcpro2
;
7534 args
[0] = build_string (m
);
7535 args
[1] = message
= string
;
7536 GCPRO2 (args
[0], message
);
7539 message
= Fformat (2, args
);
7542 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7544 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7548 /* Print should start at the beginning of the message
7549 buffer next time. */
7550 message_buf_print
= 0;
7556 /* Dump an informative message to the minibuf. If M is 0, clear out
7557 any existing message, and let the mini-buffer text show through. */
7561 message (m
, a1
, a2
, a3
)
7563 EMACS_INT a1
, a2
, a3
;
7569 if (noninteractive_need_newline
)
7570 putc ('\n', stderr
);
7571 noninteractive_need_newline
= 0;
7572 fprintf (stderr
, m
, a1
, a2
, a3
);
7573 if (cursor_in_echo_area
== 0)
7574 fprintf (stderr
, "\n");
7578 else if (INTERACTIVE
)
7580 /* The frame whose mini-buffer we're going to display the message
7581 on. It may be larger than the selected frame, so we need to
7582 use its buffer, not the selected frame's buffer. */
7583 Lisp_Object mini_window
;
7584 struct frame
*f
, *sf
= SELECTED_FRAME ();
7586 /* Get the frame containing the mini-buffer
7587 that the selected frame is using. */
7588 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7589 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7591 /* A null message buffer means that the frame hasn't really been
7592 initialized yet. Error messages get reported properly by
7593 cmd_error, so this must be just an informative message; toss
7595 if (FRAME_MESSAGE_BUF (f
))
7606 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7607 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7609 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7610 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7612 #endif /* NO_ARG_ARRAY */
7614 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7619 /* Print should start at the beginning of the message
7620 buffer next time. */
7621 message_buf_print
= 0;
7627 /* The non-logging version of message. */
7630 message_nolog (m
, a1
, a2
, a3
)
7632 EMACS_INT a1
, a2
, a3
;
7634 Lisp_Object old_log_max
;
7635 old_log_max
= Vmessage_log_max
;
7636 Vmessage_log_max
= Qnil
;
7637 message (m
, a1
, a2
, a3
);
7638 Vmessage_log_max
= old_log_max
;
7642 /* Display the current message in the current mini-buffer. This is
7643 only called from error handlers in process.c, and is not time
7649 if (!NILP (echo_area_buffer
[0]))
7652 string
= Fcurrent_message ();
7653 message3 (string
, SBYTES (string
),
7654 !NILP (current_buffer
->enable_multibyte_characters
));
7659 /* Make sure echo area buffers in `echo_buffers' are live.
7660 If they aren't, make new ones. */
7663 ensure_echo_area_buffers ()
7667 for (i
= 0; i
< 2; ++i
)
7668 if (!BUFFERP (echo_buffer
[i
])
7669 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7672 Lisp_Object old_buffer
;
7675 old_buffer
= echo_buffer
[i
];
7676 sprintf (name
, " *Echo Area %d*", i
);
7677 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7678 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7680 for (j
= 0; j
< 2; ++j
)
7681 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7682 echo_area_buffer
[j
] = echo_buffer
[i
];
7687 /* Call FN with args A1..A4 with either the current or last displayed
7688 echo_area_buffer as current buffer.
7690 WHICH zero means use the current message buffer
7691 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7692 from echo_buffer[] and clear it.
7694 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7695 suitable buffer from echo_buffer[] and clear it.
7697 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7698 that the current message becomes the last displayed one, make
7699 choose a suitable buffer for echo_area_buffer[0], and clear it.
7701 Value is what FN returns. */
7704 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7707 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7713 int this_one
, the_other
, clear_buffer_p
, rc
;
7714 int count
= SPECPDL_INDEX ();
7716 /* If buffers aren't live, make new ones. */
7717 ensure_echo_area_buffers ();
7722 this_one
= 0, the_other
= 1;
7724 this_one
= 1, the_other
= 0;
7727 this_one
= 0, the_other
= 1;
7730 /* We need a fresh one in case the current echo buffer equals
7731 the one containing the last displayed echo area message. */
7732 if (!NILP (echo_area_buffer
[this_one
])
7733 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7734 echo_area_buffer
[this_one
] = Qnil
;
7737 /* Choose a suitable buffer from echo_buffer[] is we don't
7739 if (NILP (echo_area_buffer
[this_one
]))
7741 echo_area_buffer
[this_one
]
7742 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7743 ? echo_buffer
[the_other
]
7744 : echo_buffer
[this_one
]);
7748 buffer
= echo_area_buffer
[this_one
];
7750 /* Don't get confused by reusing the buffer used for echoing
7751 for a different purpose. */
7752 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7755 record_unwind_protect (unwind_with_echo_area_buffer
,
7756 with_echo_area_buffer_unwind_data (w
));
7758 /* Make the echo area buffer current. Note that for display
7759 purposes, it is not necessary that the displayed window's buffer
7760 == current_buffer, except for text property lookup. So, let's
7761 only set that buffer temporarily here without doing a full
7762 Fset_window_buffer. We must also change w->pointm, though,
7763 because otherwise an assertions in unshow_buffer fails, and Emacs
7765 set_buffer_internal_1 (XBUFFER (buffer
));
7769 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7772 current_buffer
->undo_list
= Qt
;
7773 current_buffer
->read_only
= Qnil
;
7774 specbind (Qinhibit_read_only
, Qt
);
7775 specbind (Qinhibit_modification_hooks
, Qt
);
7777 if (clear_buffer_p
&& Z
> BEG
)
7780 xassert (BEGV
>= BEG
);
7781 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7783 rc
= fn (a1
, a2
, a3
, a4
);
7785 xassert (BEGV
>= BEG
);
7786 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7788 unbind_to (count
, Qnil
);
7793 /* Save state that should be preserved around the call to the function
7794 FN called in with_echo_area_buffer. */
7797 with_echo_area_buffer_unwind_data (w
)
7803 /* Reduce consing by keeping one vector in
7804 Vwith_echo_area_save_vector. */
7805 vector
= Vwith_echo_area_save_vector
;
7806 Vwith_echo_area_save_vector
= Qnil
;
7809 vector
= Fmake_vector (make_number (7), Qnil
);
7811 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7812 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7813 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7817 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7818 AREF (vector
, i
) = w
->buffer
; ++i
;
7819 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7820 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7825 for (; i
< end
; ++i
)
7826 AREF (vector
, i
) = Qnil
;
7829 xassert (i
== ASIZE (vector
));
7834 /* Restore global state from VECTOR which was created by
7835 with_echo_area_buffer_unwind_data. */
7838 unwind_with_echo_area_buffer (vector
)
7841 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7842 Vdeactivate_mark
= AREF (vector
, 1);
7843 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7845 if (WINDOWP (AREF (vector
, 3)))
7848 Lisp_Object buffer
, charpos
, bytepos
;
7850 w
= XWINDOW (AREF (vector
, 3));
7851 buffer
= AREF (vector
, 4);
7852 charpos
= AREF (vector
, 5);
7853 bytepos
= AREF (vector
, 6);
7856 set_marker_both (w
->pointm
, buffer
,
7857 XFASTINT (charpos
), XFASTINT (bytepos
));
7860 Vwith_echo_area_save_vector
= vector
;
7865 /* Set up the echo area for use by print functions. MULTIBYTE_P
7866 non-zero means we will print multibyte. */
7869 setup_echo_area_for_printing (multibyte_p
)
7872 /* If we can't find an echo area any more, exit. */
7873 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7876 ensure_echo_area_buffers ();
7878 if (!message_buf_print
)
7880 /* A message has been output since the last time we printed.
7881 Choose a fresh echo area buffer. */
7882 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7883 echo_area_buffer
[0] = echo_buffer
[1];
7885 echo_area_buffer
[0] = echo_buffer
[0];
7887 /* Switch to that buffer and clear it. */
7888 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7889 current_buffer
->truncate_lines
= Qnil
;
7893 int count
= SPECPDL_INDEX ();
7894 specbind (Qinhibit_read_only
, Qt
);
7895 /* Note that undo recording is always disabled. */
7897 unbind_to (count
, Qnil
);
7899 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7901 /* Set up the buffer for the multibyteness we need. */
7903 != !NILP (current_buffer
->enable_multibyte_characters
))
7904 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7906 /* Raise the frame containing the echo area. */
7907 if (minibuffer_auto_raise
)
7909 struct frame
*sf
= SELECTED_FRAME ();
7910 Lisp_Object mini_window
;
7911 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7912 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7915 message_log_maybe_newline ();
7916 message_buf_print
= 1;
7920 if (NILP (echo_area_buffer
[0]))
7922 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7923 echo_area_buffer
[0] = echo_buffer
[1];
7925 echo_area_buffer
[0] = echo_buffer
[0];
7928 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7930 /* Someone switched buffers between print requests. */
7931 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7932 current_buffer
->truncate_lines
= Qnil
;
7938 /* Display an echo area message in window W. Value is non-zero if W's
7939 height is changed. If display_last_displayed_message_p is
7940 non-zero, display the message that was last displayed, otherwise
7941 display the current message. */
7944 display_echo_area (w
)
7947 int i
, no_message_p
, window_height_changed_p
, count
;
7949 /* Temporarily disable garbage collections while displaying the echo
7950 area. This is done because a GC can print a message itself.
7951 That message would modify the echo area buffer's contents while a
7952 redisplay of the buffer is going on, and seriously confuse
7954 count
= inhibit_garbage_collection ();
7956 /* If there is no message, we must call display_echo_area_1
7957 nevertheless because it resizes the window. But we will have to
7958 reset the echo_area_buffer in question to nil at the end because
7959 with_echo_area_buffer will sets it to an empty buffer. */
7960 i
= display_last_displayed_message_p
? 1 : 0;
7961 no_message_p
= NILP (echo_area_buffer
[i
]);
7963 window_height_changed_p
7964 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7965 display_echo_area_1
,
7966 (EMACS_INT
) w
, Qnil
, 0, 0);
7969 echo_area_buffer
[i
] = Qnil
;
7971 unbind_to (count
, Qnil
);
7972 return window_height_changed_p
;
7976 /* Helper for display_echo_area. Display the current buffer which
7977 contains the current echo area message in window W, a mini-window,
7978 a pointer to which is passed in A1. A2..A4 are currently not used.
7979 Change the height of W so that all of the message is displayed.
7980 Value is non-zero if height of W was changed. */
7983 display_echo_area_1 (a1
, a2
, a3
, a4
)
7988 struct window
*w
= (struct window
*) a1
;
7990 struct text_pos start
;
7991 int window_height_changed_p
= 0;
7993 /* Do this before displaying, so that we have a large enough glyph
7994 matrix for the display. If we can't get enough space for the
7995 whole text, display the last N lines. That works by setting w->start. */
7996 window_height_changed_p
= resize_mini_window (w
, 0);
7998 /* Use the starting position chosen by resize_mini_window. */
7999 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8002 clear_glyph_matrix (w
->desired_matrix
);
8003 XSETWINDOW (window
, w
);
8004 try_window (window
, start
, 0);
8006 return window_height_changed_p
;
8010 /* Resize the echo area window to exactly the size needed for the
8011 currently displayed message, if there is one. If a mini-buffer
8012 is active, don't shrink it. */
8015 resize_echo_area_exactly ()
8017 if (BUFFERP (echo_area_buffer
[0])
8018 && WINDOWP (echo_area_window
))
8020 struct window
*w
= XWINDOW (echo_area_window
);
8022 Lisp_Object resize_exactly
;
8024 if (minibuf_level
== 0)
8025 resize_exactly
= Qt
;
8027 resize_exactly
= Qnil
;
8029 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8030 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8033 ++windows_or_buffers_changed
;
8034 ++update_mode_lines
;
8035 redisplay_internal (0);
8041 /* Callback function for with_echo_area_buffer, when used from
8042 resize_echo_area_exactly. A1 contains a pointer to the window to
8043 resize, EXACTLY non-nil means resize the mini-window exactly to the
8044 size of the text displayed. A3 and A4 are not used. Value is what
8045 resize_mini_window returns. */
8048 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8050 Lisp_Object exactly
;
8053 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8057 /* Resize mini-window W to fit the size of its contents. EXACT:P
8058 means size the window exactly to the size needed. Otherwise, it's
8059 only enlarged until W's buffer is empty.
8061 Set W->start to the right place to begin display. If the whole
8062 contents fit, start at the beginning. Otherwise, start so as
8063 to make the end of the contents appear. This is particularly
8064 important for y-or-n-p, but seems desirable generally.
8066 Value is non-zero if the window height has been changed. */
8069 resize_mini_window (w
, exact_p
)
8073 struct frame
*f
= XFRAME (w
->frame
);
8074 int window_height_changed_p
= 0;
8076 xassert (MINI_WINDOW_P (w
));
8078 /* By default, start display at the beginning. */
8079 set_marker_both (w
->start
, w
->buffer
,
8080 BUF_BEGV (XBUFFER (w
->buffer
)),
8081 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8083 /* Don't resize windows while redisplaying a window; it would
8084 confuse redisplay functions when the size of the window they are
8085 displaying changes from under them. Such a resizing can happen,
8086 for instance, when which-func prints a long message while
8087 we are running fontification-functions. We're running these
8088 functions with safe_call which binds inhibit-redisplay to t. */
8089 if (!NILP (Vinhibit_redisplay
))
8092 /* Nil means don't try to resize. */
8093 if (NILP (Vresize_mini_windows
)
8094 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8097 if (!FRAME_MINIBUF_ONLY_P (f
))
8100 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8101 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8102 int height
, max_height
;
8103 int unit
= FRAME_LINE_HEIGHT (f
);
8104 struct text_pos start
;
8105 struct buffer
*old_current_buffer
= NULL
;
8107 if (current_buffer
!= XBUFFER (w
->buffer
))
8109 old_current_buffer
= current_buffer
;
8110 set_buffer_internal (XBUFFER (w
->buffer
));
8113 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8115 /* Compute the max. number of lines specified by the user. */
8116 if (FLOATP (Vmax_mini_window_height
))
8117 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8118 else if (INTEGERP (Vmax_mini_window_height
))
8119 max_height
= XINT (Vmax_mini_window_height
);
8121 max_height
= total_height
/ 4;
8123 /* Correct that max. height if it's bogus. */
8124 max_height
= max (1, max_height
);
8125 max_height
= min (total_height
, max_height
);
8127 /* Find out the height of the text in the window. */
8128 if (it
.truncate_lines_p
)
8133 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8134 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8135 height
= it
.current_y
+ last_height
;
8137 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8138 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8139 height
= (height
+ unit
- 1) / unit
;
8142 /* Compute a suitable window start. */
8143 if (height
> max_height
)
8145 height
= max_height
;
8146 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8147 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8148 start
= it
.current
.pos
;
8151 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8152 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8154 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8156 /* Let it grow only, until we display an empty message, in which
8157 case the window shrinks again. */
8158 if (height
> WINDOW_TOTAL_LINES (w
))
8160 int old_height
= WINDOW_TOTAL_LINES (w
);
8161 freeze_window_starts (f
, 1);
8162 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8163 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8165 else if (height
< WINDOW_TOTAL_LINES (w
)
8166 && (exact_p
|| BEGV
== ZV
))
8168 int old_height
= WINDOW_TOTAL_LINES (w
);
8169 freeze_window_starts (f
, 0);
8170 shrink_mini_window (w
);
8171 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8176 /* Always resize to exact size needed. */
8177 if (height
> WINDOW_TOTAL_LINES (w
))
8179 int old_height
= WINDOW_TOTAL_LINES (w
);
8180 freeze_window_starts (f
, 1);
8181 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8182 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8184 else if (height
< WINDOW_TOTAL_LINES (w
))
8186 int old_height
= WINDOW_TOTAL_LINES (w
);
8187 freeze_window_starts (f
, 0);
8188 shrink_mini_window (w
);
8192 freeze_window_starts (f
, 1);
8193 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8196 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8200 if (old_current_buffer
)
8201 set_buffer_internal (old_current_buffer
);
8204 return window_height_changed_p
;
8208 /* Value is the current message, a string, or nil if there is no
8216 if (NILP (echo_area_buffer
[0]))
8220 with_echo_area_buffer (0, 0, current_message_1
,
8221 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8223 echo_area_buffer
[0] = Qnil
;
8231 current_message_1 (a1
, a2
, a3
, a4
)
8236 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8239 *msg
= make_buffer_string (BEG
, Z
, 1);
8246 /* Push the current message on Vmessage_stack for later restauration
8247 by restore_message. Value is non-zero if the current message isn't
8248 empty. This is a relatively infrequent operation, so it's not
8249 worth optimizing. */
8255 msg
= current_message ();
8256 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8257 return STRINGP (msg
);
8261 /* Restore message display from the top of Vmessage_stack. */
8268 xassert (CONSP (Vmessage_stack
));
8269 msg
= XCAR (Vmessage_stack
);
8271 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8273 message3_nolog (msg
, 0, 0);
8277 /* Handler for record_unwind_protect calling pop_message. */
8280 pop_message_unwind (dummy
)
8287 /* Pop the top-most entry off Vmessage_stack. */
8292 xassert (CONSP (Vmessage_stack
));
8293 Vmessage_stack
= XCDR (Vmessage_stack
);
8297 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8298 exits. If the stack is not empty, we have a missing pop_message
8302 check_message_stack ()
8304 if (!NILP (Vmessage_stack
))
8309 /* Truncate to NCHARS what will be displayed in the echo area the next
8310 time we display it---but don't redisplay it now. */
8313 truncate_echo_area (nchars
)
8317 echo_area_buffer
[0] = Qnil
;
8318 /* A null message buffer means that the frame hasn't really been
8319 initialized yet. Error messages get reported properly by
8320 cmd_error, so this must be just an informative message; toss it. */
8321 else if (!noninteractive
8323 && !NILP (echo_area_buffer
[0]))
8325 struct frame
*sf
= SELECTED_FRAME ();
8326 if (FRAME_MESSAGE_BUF (sf
))
8327 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8332 /* Helper function for truncate_echo_area. Truncate the current
8333 message to at most NCHARS characters. */
8336 truncate_message_1 (nchars
, a2
, a3
, a4
)
8341 if (BEG
+ nchars
< Z
)
8342 del_range (BEG
+ nchars
, Z
);
8344 echo_area_buffer
[0] = Qnil
;
8349 /* Set the current message to a substring of S or STRING.
8351 If STRING is a Lisp string, set the message to the first NBYTES
8352 bytes from STRING. NBYTES zero means use the whole string. If
8353 STRING is multibyte, the message will be displayed multibyte.
8355 If S is not null, set the message to the first LEN bytes of S. LEN
8356 zero means use the whole string. MULTIBYTE_P non-zero means S is
8357 multibyte. Display the message multibyte in that case.
8359 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8360 to t before calling set_message_1 (which calls insert).
8364 set_message (s
, string
, nbytes
, multibyte_p
)
8367 int nbytes
, multibyte_p
;
8369 message_enable_multibyte
8370 = ((s
&& multibyte_p
)
8371 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8373 with_echo_area_buffer (0, -1, set_message_1
,
8374 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8375 message_buf_print
= 0;
8376 help_echo_showing_p
= 0;
8380 /* Helper function for set_message. Arguments have the same meaning
8381 as there, with A1 corresponding to S and A2 corresponding to STRING
8382 This function is called with the echo area buffer being
8386 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8389 EMACS_INT nbytes
, multibyte_p
;
8391 const char *s
= (const char *) a1
;
8392 Lisp_Object string
= a2
;
8394 /* Change multibyteness of the echo buffer appropriately. */
8395 if (message_enable_multibyte
8396 != !NILP (current_buffer
->enable_multibyte_characters
))
8397 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8399 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8401 /* Insert new message at BEG. */
8402 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8404 if (STRINGP (string
))
8409 nbytes
= SBYTES (string
);
8410 nchars
= string_byte_to_char (string
, nbytes
);
8412 /* This function takes care of single/multibyte conversion. We
8413 just have to ensure that the echo area buffer has the right
8414 setting of enable_multibyte_characters. */
8415 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8420 nbytes
= strlen (s
);
8422 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8424 /* Convert from multi-byte to single-byte. */
8426 unsigned char work
[1];
8428 /* Convert a multibyte string to single-byte. */
8429 for (i
= 0; i
< nbytes
; i
+= n
)
8431 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8432 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8434 : multibyte_char_to_unibyte (c
, Qnil
));
8435 insert_1_both (work
, 1, 1, 1, 0, 0);
8438 else if (!multibyte_p
8439 && !NILP (current_buffer
->enable_multibyte_characters
))
8441 /* Convert from single-byte to multi-byte. */
8443 const unsigned char *msg
= (const unsigned char *) s
;
8444 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8446 /* Convert a single-byte string to multibyte. */
8447 for (i
= 0; i
< nbytes
; i
++)
8449 c
= unibyte_char_to_multibyte (msg
[i
]);
8450 n
= CHAR_STRING (c
, str
);
8451 insert_1_both (str
, 1, n
, 1, 0, 0);
8455 insert_1 (s
, nbytes
, 1, 0, 0);
8462 /* Clear messages. CURRENT_P non-zero means clear the current
8463 message. LAST_DISPLAYED_P non-zero means clear the message
8467 clear_message (current_p
, last_displayed_p
)
8468 int current_p
, last_displayed_p
;
8472 echo_area_buffer
[0] = Qnil
;
8473 message_cleared_p
= 1;
8476 if (last_displayed_p
)
8477 echo_area_buffer
[1] = Qnil
;
8479 message_buf_print
= 0;
8482 /* Clear garbaged frames.
8484 This function is used where the old redisplay called
8485 redraw_garbaged_frames which in turn called redraw_frame which in
8486 turn called clear_frame. The call to clear_frame was a source of
8487 flickering. I believe a clear_frame is not necessary. It should
8488 suffice in the new redisplay to invalidate all current matrices,
8489 and ensure a complete redisplay of all windows. */
8492 clear_garbaged_frames ()
8496 Lisp_Object tail
, frame
;
8497 int changed_count
= 0;
8499 FOR_EACH_FRAME (tail
, frame
)
8501 struct frame
*f
= XFRAME (frame
);
8503 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8507 Fredraw_frame (frame
);
8508 f
->force_flush_display_p
= 1;
8510 clear_current_matrices (f
);
8519 ++windows_or_buffers_changed
;
8524 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8525 is non-zero update selected_frame. Value is non-zero if the
8526 mini-windows height has been changed. */
8529 echo_area_display (update_frame_p
)
8532 Lisp_Object mini_window
;
8535 int window_height_changed_p
= 0;
8536 struct frame
*sf
= SELECTED_FRAME ();
8538 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8539 w
= XWINDOW (mini_window
);
8540 f
= XFRAME (WINDOW_FRAME (w
));
8542 /* Don't display if frame is invisible or not yet initialized. */
8543 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8546 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8548 #ifdef HAVE_WINDOW_SYSTEM
8549 /* When Emacs starts, selected_frame may be the initial terminal
8550 frame. If we let this through, a message would be displayed on
8552 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8554 #endif /* HAVE_WINDOW_SYSTEM */
8557 /* Redraw garbaged frames. */
8559 clear_garbaged_frames ();
8561 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8563 echo_area_window
= mini_window
;
8564 window_height_changed_p
= display_echo_area (w
);
8565 w
->must_be_updated_p
= 1;
8567 /* Update the display, unless called from redisplay_internal.
8568 Also don't update the screen during redisplay itself. The
8569 update will happen at the end of redisplay, and an update
8570 here could cause confusion. */
8571 if (update_frame_p
&& !redisplaying_p
)
8575 /* If the display update has been interrupted by pending
8576 input, update mode lines in the frame. Due to the
8577 pending input, it might have been that redisplay hasn't
8578 been called, so that mode lines above the echo area are
8579 garbaged. This looks odd, so we prevent it here. */
8580 if (!display_completed
)
8581 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8583 if (window_height_changed_p
8584 /* Don't do this if Emacs is shutting down. Redisplay
8585 needs to run hooks. */
8586 && !NILP (Vrun_hooks
))
8588 /* Must update other windows. Likewise as in other
8589 cases, don't let this update be interrupted by
8591 int count
= SPECPDL_INDEX ();
8592 specbind (Qredisplay_dont_pause
, Qt
);
8593 windows_or_buffers_changed
= 1;
8594 redisplay_internal (0);
8595 unbind_to (count
, Qnil
);
8597 else if (FRAME_WINDOW_P (f
) && n
== 0)
8599 /* Window configuration is the same as before.
8600 Can do with a display update of the echo area,
8601 unless we displayed some mode lines. */
8602 update_single_window (w
, 1);
8603 FRAME_RIF (f
)->flush_display (f
);
8606 update_frame (f
, 1, 1);
8608 /* If cursor is in the echo area, make sure that the next
8609 redisplay displays the minibuffer, so that the cursor will
8610 be replaced with what the minibuffer wants. */
8611 if (cursor_in_echo_area
)
8612 ++windows_or_buffers_changed
;
8615 else if (!EQ (mini_window
, selected_window
))
8616 windows_or_buffers_changed
++;
8618 /* Last displayed message is now the current message. */
8619 echo_area_buffer
[1] = echo_area_buffer
[0];
8620 /* Inform read_char that we're not echoing. */
8621 echo_message_buffer
= Qnil
;
8623 /* Prevent redisplay optimization in redisplay_internal by resetting
8624 this_line_start_pos. This is done because the mini-buffer now
8625 displays the message instead of its buffer text. */
8626 if (EQ (mini_window
, selected_window
))
8627 CHARPOS (this_line_start_pos
) = 0;
8629 return window_height_changed_p
;
8634 /***********************************************************************
8635 Mode Lines and Frame Titles
8636 ***********************************************************************/
8638 /* A buffer for constructing non-propertized mode-line strings and
8639 frame titles in it; allocated from the heap in init_xdisp and
8640 resized as needed in store_mode_line_noprop_char. */
8642 static char *mode_line_noprop_buf
;
8644 /* The buffer's end, and a current output position in it. */
8646 static char *mode_line_noprop_buf_end
;
8647 static char *mode_line_noprop_ptr
;
8649 #define MODE_LINE_NOPROP_LEN(start) \
8650 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8653 MODE_LINE_DISPLAY
= 0,
8659 /* Alist that caches the results of :propertize.
8660 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8661 static Lisp_Object mode_line_proptrans_alist
;
8663 /* List of strings making up the mode-line. */
8664 static Lisp_Object mode_line_string_list
;
8666 /* Base face property when building propertized mode line string. */
8667 static Lisp_Object mode_line_string_face
;
8668 static Lisp_Object mode_line_string_face_prop
;
8671 /* Unwind data for mode line strings */
8673 static Lisp_Object Vmode_line_unwind_vector
;
8676 format_mode_line_unwind_data (obuf
, save_proptrans
)
8677 struct buffer
*obuf
;
8681 /* Reduce consing by keeping one vector in
8682 Vwith_echo_area_save_vector. */
8683 vector
= Vmode_line_unwind_vector
;
8684 Vmode_line_unwind_vector
= Qnil
;
8687 vector
= Fmake_vector (make_number (7), Qnil
);
8689 AREF (vector
, 0) = make_number (mode_line_target
);
8690 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8691 AREF (vector
, 2) = mode_line_string_list
;
8692 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8693 AREF (vector
, 4) = mode_line_string_face
;
8694 AREF (vector
, 5) = mode_line_string_face_prop
;
8697 XSETBUFFER (AREF (vector
, 6), obuf
);
8699 AREF (vector
, 6) = Qnil
;
8705 unwind_format_mode_line (vector
)
8708 mode_line_target
= XINT (AREF (vector
, 0));
8709 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8710 mode_line_string_list
= AREF (vector
, 2);
8711 if (! EQ (AREF (vector
, 3), Qt
))
8712 mode_line_proptrans_alist
= AREF (vector
, 3);
8713 mode_line_string_face
= AREF (vector
, 4);
8714 mode_line_string_face_prop
= AREF (vector
, 5);
8716 if (!NILP (AREF (vector
, 6)))
8718 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8719 AREF (vector
, 6) = Qnil
;
8722 Vmode_line_unwind_vector
= vector
;
8727 /* Store a single character C for the frame title in mode_line_noprop_buf.
8728 Re-allocate mode_line_noprop_buf if necessary. */
8732 store_mode_line_noprop_char (char c
)
8734 store_mode_line_noprop_char (c
)
8738 /* If output position has reached the end of the allocated buffer,
8739 double the buffer's size. */
8740 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8742 int len
= MODE_LINE_NOPROP_LEN (0);
8743 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8744 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8745 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8746 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8749 *mode_line_noprop_ptr
++ = c
;
8753 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8754 mode_line_noprop_ptr. STR is the string to store. Do not copy
8755 characters that yield more columns than PRECISION; PRECISION <= 0
8756 means copy the whole string. Pad with spaces until FIELD_WIDTH
8757 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8758 pad. Called from display_mode_element when it is used to build a
8762 store_mode_line_noprop (str
, field_width
, precision
)
8763 const unsigned char *str
;
8764 int field_width
, precision
;
8769 /* Copy at most PRECISION chars from STR. */
8770 nbytes
= strlen (str
);
8771 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8773 store_mode_line_noprop_char (*str
++);
8775 /* Fill up with spaces until FIELD_WIDTH reached. */
8776 while (field_width
> 0
8779 store_mode_line_noprop_char (' ');
8786 /***********************************************************************
8788 ***********************************************************************/
8790 #ifdef HAVE_WINDOW_SYSTEM
8792 /* Set the title of FRAME, if it has changed. The title format is
8793 Vicon_title_format if FRAME is iconified, otherwise it is
8794 frame_title_format. */
8797 x_consider_frame_title (frame
)
8800 struct frame
*f
= XFRAME (frame
);
8802 if (FRAME_WINDOW_P (f
)
8803 || FRAME_MINIBUF_ONLY_P (f
)
8804 || f
->explicit_name
)
8806 /* Do we have more than one visible frame on this X display? */
8813 int count
= SPECPDL_INDEX ();
8815 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8817 Lisp_Object other_frame
= XCAR (tail
);
8818 struct frame
*tf
= XFRAME (other_frame
);
8821 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8822 && !FRAME_MINIBUF_ONLY_P (tf
)
8823 && !EQ (other_frame
, tip_frame
)
8824 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8828 /* Set global variable indicating that multiple frames exist. */
8829 multiple_frames
= CONSP (tail
);
8831 /* Switch to the buffer of selected window of the frame. Set up
8832 mode_line_target so that display_mode_element will output into
8833 mode_line_noprop_buf; then display the title. */
8834 record_unwind_protect (unwind_format_mode_line
,
8835 format_mode_line_unwind_data (current_buffer
, 0));
8837 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8838 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8840 mode_line_target
= MODE_LINE_TITLE
;
8841 title_start
= MODE_LINE_NOPROP_LEN (0);
8842 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8843 NULL
, DEFAULT_FACE_ID
);
8844 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8845 len
= MODE_LINE_NOPROP_LEN (title_start
);
8846 title
= mode_line_noprop_buf
+ title_start
;
8847 unbind_to (count
, Qnil
);
8849 /* Set the title only if it's changed. This avoids consing in
8850 the common case where it hasn't. (If it turns out that we've
8851 already wasted too much time by walking through the list with
8852 display_mode_element, then we might need to optimize at a
8853 higher level than this.) */
8854 if (! STRINGP (f
->name
)
8855 || SBYTES (f
->name
) != len
8856 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8857 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8861 #endif /* not HAVE_WINDOW_SYSTEM */
8866 /***********************************************************************
8868 ***********************************************************************/
8871 /* Prepare for redisplay by updating menu-bar item lists when
8872 appropriate. This can call eval. */
8875 prepare_menu_bars ()
8878 struct gcpro gcpro1
, gcpro2
;
8880 Lisp_Object tooltip_frame
;
8882 #ifdef HAVE_WINDOW_SYSTEM
8883 tooltip_frame
= tip_frame
;
8885 tooltip_frame
= Qnil
;
8888 /* Update all frame titles based on their buffer names, etc. We do
8889 this before the menu bars so that the buffer-menu will show the
8890 up-to-date frame titles. */
8891 #ifdef HAVE_WINDOW_SYSTEM
8892 if (windows_or_buffers_changed
|| update_mode_lines
)
8894 Lisp_Object tail
, frame
;
8896 FOR_EACH_FRAME (tail
, frame
)
8899 if (!EQ (frame
, tooltip_frame
)
8900 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8901 x_consider_frame_title (frame
);
8904 #endif /* HAVE_WINDOW_SYSTEM */
8906 /* Update the menu bar item lists, if appropriate. This has to be
8907 done before any actual redisplay or generation of display lines. */
8908 all_windows
= (update_mode_lines
8909 || buffer_shared
> 1
8910 || windows_or_buffers_changed
);
8913 Lisp_Object tail
, frame
;
8914 int count
= SPECPDL_INDEX ();
8916 record_unwind_save_match_data ();
8918 FOR_EACH_FRAME (tail
, frame
)
8922 /* Ignore tooltip frame. */
8923 if (EQ (frame
, tooltip_frame
))
8926 /* If a window on this frame changed size, report that to
8927 the user and clear the size-change flag. */
8928 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8930 Lisp_Object functions
;
8932 /* Clear flag first in case we get an error below. */
8933 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8934 functions
= Vwindow_size_change_functions
;
8935 GCPRO2 (tail
, functions
);
8937 while (CONSP (functions
))
8939 call1 (XCAR (functions
), frame
);
8940 functions
= XCDR (functions
);
8946 update_menu_bar (f
, 0);
8947 #ifdef HAVE_WINDOW_SYSTEM
8948 update_tool_bar (f
, 0);
8953 unbind_to (count
, Qnil
);
8957 struct frame
*sf
= SELECTED_FRAME ();
8958 update_menu_bar (sf
, 1);
8959 #ifdef HAVE_WINDOW_SYSTEM
8960 update_tool_bar (sf
, 1);
8964 /* Motif needs this. See comment in xmenu.c. Turn it off when
8965 pending_menu_activation is not defined. */
8966 #ifdef USE_X_TOOLKIT
8967 pending_menu_activation
= 0;
8972 /* Update the menu bar item list for frame F. This has to be done
8973 before we start to fill in any display lines, because it can call
8976 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8979 update_menu_bar (f
, save_match_data
)
8981 int save_match_data
;
8984 register struct window
*w
;
8986 /* If called recursively during a menu update, do nothing. This can
8987 happen when, for instance, an activate-menubar-hook causes a
8989 if (inhibit_menubar_update
)
8992 window
= FRAME_SELECTED_WINDOW (f
);
8993 w
= XWINDOW (window
);
8995 #if 0 /* The if statement below this if statement used to include the
8996 condition !NILP (w->update_mode_line), rather than using
8997 update_mode_lines directly, and this if statement may have
8998 been added to make that condition work. Now the if
8999 statement below matches its comment, this isn't needed. */
9000 if (update_mode_lines
)
9001 w
->update_mode_line
= Qt
;
9004 if (FRAME_WINDOW_P (f
)
9006 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9007 || defined (USE_GTK)
9008 FRAME_EXTERNAL_MENU_BAR (f
)
9010 FRAME_MENU_BAR_LINES (f
) > 0
9012 : FRAME_MENU_BAR_LINES (f
) > 0)
9014 /* If the user has switched buffers or windows, we need to
9015 recompute to reflect the new bindings. But we'll
9016 recompute when update_mode_lines is set too; that means
9017 that people can use force-mode-line-update to request
9018 that the menu bar be recomputed. The adverse effect on
9019 the rest of the redisplay algorithm is about the same as
9020 windows_or_buffers_changed anyway. */
9021 if (windows_or_buffers_changed
9022 /* This used to test w->update_mode_line, but we believe
9023 there is no need to recompute the menu in that case. */
9024 || update_mode_lines
9025 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9026 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9027 != !NILP (w
->last_had_star
))
9028 || ((!NILP (Vtransient_mark_mode
)
9029 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9030 != !NILP (w
->region_showing
)))
9032 struct buffer
*prev
= current_buffer
;
9033 int count
= SPECPDL_INDEX ();
9035 specbind (Qinhibit_menubar_update
, Qt
);
9037 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9038 if (save_match_data
)
9039 record_unwind_save_match_data ();
9040 if (NILP (Voverriding_local_map_menu_flag
))
9042 specbind (Qoverriding_terminal_local_map
, Qnil
);
9043 specbind (Qoverriding_local_map
, Qnil
);
9046 /* Run the Lucid hook. */
9047 safe_run_hooks (Qactivate_menubar_hook
);
9049 /* If it has changed current-menubar from previous value,
9050 really recompute the menu-bar from the value. */
9051 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9052 call0 (Qrecompute_lucid_menubar
);
9054 safe_run_hooks (Qmenu_bar_update_hook
);
9055 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9057 /* Redisplay the menu bar in case we changed it. */
9058 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9059 || defined (USE_GTK)
9060 if (FRAME_WINDOW_P (f
)
9061 #if defined (MAC_OS)
9062 /* All frames on Mac OS share the same menubar. So only the
9063 selected frame should be allowed to set it. */
9064 && f
== SELECTED_FRAME ()
9067 set_frame_menubar (f
, 0, 0);
9069 /* On a terminal screen, the menu bar is an ordinary screen
9070 line, and this makes it get updated. */
9071 w
->update_mode_line
= Qt
;
9072 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9073 /* In the non-toolkit version, the menu bar is an ordinary screen
9074 line, and this makes it get updated. */
9075 w
->update_mode_line
= Qt
;
9076 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9078 unbind_to (count
, Qnil
);
9079 set_buffer_internal_1 (prev
);
9086 /***********************************************************************
9088 ***********************************************************************/
9090 #ifdef HAVE_WINDOW_SYSTEM
9093 Nominal cursor position -- where to draw output.
9094 HPOS and VPOS are window relative glyph matrix coordinates.
9095 X and Y are window relative pixel coordinates. */
9097 struct cursor_pos output_cursor
;
9101 Set the global variable output_cursor to CURSOR. All cursor
9102 positions are relative to updated_window. */
9105 set_output_cursor (cursor
)
9106 struct cursor_pos
*cursor
;
9108 output_cursor
.hpos
= cursor
->hpos
;
9109 output_cursor
.vpos
= cursor
->vpos
;
9110 output_cursor
.x
= cursor
->x
;
9111 output_cursor
.y
= cursor
->y
;
9116 Set a nominal cursor position.
9118 HPOS and VPOS are column/row positions in a window glyph matrix. X
9119 and Y are window text area relative pixel positions.
9121 If this is done during an update, updated_window will contain the
9122 window that is being updated and the position is the future output
9123 cursor position for that window. If updated_window is null, use
9124 selected_window and display the cursor at the given position. */
9127 x_cursor_to (vpos
, hpos
, y
, x
)
9128 int vpos
, hpos
, y
, x
;
9132 /* If updated_window is not set, work on selected_window. */
9136 w
= XWINDOW (selected_window
);
9138 /* Set the output cursor. */
9139 output_cursor
.hpos
= hpos
;
9140 output_cursor
.vpos
= vpos
;
9141 output_cursor
.x
= x
;
9142 output_cursor
.y
= y
;
9144 /* If not called as part of an update, really display the cursor.
9145 This will also set the cursor position of W. */
9146 if (updated_window
== NULL
)
9149 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9150 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9151 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9156 #endif /* HAVE_WINDOW_SYSTEM */
9159 /***********************************************************************
9161 ***********************************************************************/
9163 #ifdef HAVE_WINDOW_SYSTEM
9165 /* Where the mouse was last time we reported a mouse event. */
9167 FRAME_PTR last_mouse_frame
;
9169 /* Tool-bar item index of the item on which a mouse button was pressed
9172 int last_tool_bar_item
;
9175 /* Update the tool-bar item list for frame F. This has to be done
9176 before we start to fill in any display lines. Called from
9177 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9178 and restore it here. */
9181 update_tool_bar (f
, save_match_data
)
9183 int save_match_data
;
9186 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9188 int do_update
= WINDOWP (f
->tool_bar_window
)
9189 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9197 window
= FRAME_SELECTED_WINDOW (f
);
9198 w
= XWINDOW (window
);
9200 /* If the user has switched buffers or windows, we need to
9201 recompute to reflect the new bindings. But we'll
9202 recompute when update_mode_lines is set too; that means
9203 that people can use force-mode-line-update to request
9204 that the menu bar be recomputed. The adverse effect on
9205 the rest of the redisplay algorithm is about the same as
9206 windows_or_buffers_changed anyway. */
9207 if (windows_or_buffers_changed
9208 || !NILP (w
->update_mode_line
)
9209 || update_mode_lines
9210 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9211 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9212 != !NILP (w
->last_had_star
))
9213 || ((!NILP (Vtransient_mark_mode
)
9214 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9215 != !NILP (w
->region_showing
)))
9217 struct buffer
*prev
= current_buffer
;
9218 int count
= SPECPDL_INDEX ();
9219 Lisp_Object new_tool_bar
;
9221 struct gcpro gcpro1
;
9223 /* Set current_buffer to the buffer of the selected
9224 window of the frame, so that we get the right local
9226 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9228 /* Save match data, if we must. */
9229 if (save_match_data
)
9230 record_unwind_save_match_data ();
9232 /* Make sure that we don't accidentally use bogus keymaps. */
9233 if (NILP (Voverriding_local_map_menu_flag
))
9235 specbind (Qoverriding_terminal_local_map
, Qnil
);
9236 specbind (Qoverriding_local_map
, Qnil
);
9239 GCPRO1 (new_tool_bar
);
9241 /* Build desired tool-bar items from keymaps. */
9242 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9245 /* Redisplay the tool-bar if we changed it. */
9246 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9248 /* Redisplay that happens asynchronously due to an expose event
9249 may access f->tool_bar_items. Make sure we update both
9250 variables within BLOCK_INPUT so no such event interrupts. */
9252 f
->tool_bar_items
= new_tool_bar
;
9253 f
->n_tool_bar_items
= new_n_tool_bar
;
9254 w
->update_mode_line
= Qt
;
9260 unbind_to (count
, Qnil
);
9261 set_buffer_internal_1 (prev
);
9267 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9268 F's desired tool-bar contents. F->tool_bar_items must have
9269 been set up previously by calling prepare_menu_bars. */
9272 build_desired_tool_bar_string (f
)
9275 int i
, size
, size_needed
;
9276 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9277 Lisp_Object image
, plist
, props
;
9279 image
= plist
= props
= Qnil
;
9280 GCPRO3 (image
, plist
, props
);
9282 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9283 Otherwise, make a new string. */
9285 /* The size of the string we might be able to reuse. */
9286 size
= (STRINGP (f
->desired_tool_bar_string
)
9287 ? SCHARS (f
->desired_tool_bar_string
)
9290 /* We need one space in the string for each image. */
9291 size_needed
= f
->n_tool_bar_items
;
9293 /* Reuse f->desired_tool_bar_string, if possible. */
9294 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9295 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9299 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9300 Fremove_text_properties (make_number (0), make_number (size
),
9301 props
, f
->desired_tool_bar_string
);
9304 /* Put a `display' property on the string for the images to display,
9305 put a `menu_item' property on tool-bar items with a value that
9306 is the index of the item in F's tool-bar item vector. */
9307 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9309 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9311 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9312 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9313 int hmargin
, vmargin
, relief
, idx
, end
;
9314 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9316 /* If image is a vector, choose the image according to the
9318 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9319 if (VECTORP (image
))
9323 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9324 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9327 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9328 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9330 xassert (ASIZE (image
) >= idx
);
9331 image
= AREF (image
, idx
);
9336 /* Ignore invalid image specifications. */
9337 if (!valid_image_p (image
))
9340 /* Display the tool-bar button pressed, or depressed. */
9341 plist
= Fcopy_sequence (XCDR (image
));
9343 /* Compute margin and relief to draw. */
9344 relief
= (tool_bar_button_relief
>= 0
9345 ? tool_bar_button_relief
9346 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9347 hmargin
= vmargin
= relief
;
9349 if (INTEGERP (Vtool_bar_button_margin
)
9350 && XINT (Vtool_bar_button_margin
) > 0)
9352 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9353 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9355 else if (CONSP (Vtool_bar_button_margin
))
9357 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9358 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9359 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9361 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9362 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9363 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9366 if (auto_raise_tool_bar_buttons_p
)
9368 /* Add a `:relief' property to the image spec if the item is
9372 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9379 /* If image is selected, display it pressed, i.e. with a
9380 negative relief. If it's not selected, display it with a
9382 plist
= Fplist_put (plist
, QCrelief
,
9384 ? make_number (-relief
)
9385 : make_number (relief
)));
9390 /* Put a margin around the image. */
9391 if (hmargin
|| vmargin
)
9393 if (hmargin
== vmargin
)
9394 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9396 plist
= Fplist_put (plist
, QCmargin
,
9397 Fcons (make_number (hmargin
),
9398 make_number (vmargin
)));
9401 /* If button is not enabled, and we don't have special images
9402 for the disabled state, make the image appear disabled by
9403 applying an appropriate algorithm to it. */
9404 if (!enabled_p
&& idx
< 0)
9405 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9407 /* Put a `display' text property on the string for the image to
9408 display. Put a `menu-item' property on the string that gives
9409 the start of this item's properties in the tool-bar items
9411 image
= Fcons (Qimage
, plist
);
9412 props
= list4 (Qdisplay
, image
,
9413 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9415 /* Let the last image hide all remaining spaces in the tool bar
9416 string. The string can be longer than needed when we reuse a
9418 if (i
+ 1 == f
->n_tool_bar_items
)
9419 end
= SCHARS (f
->desired_tool_bar_string
);
9422 Fadd_text_properties (make_number (i
), make_number (end
),
9423 props
, f
->desired_tool_bar_string
);
9431 /* Display one line of the tool-bar of frame IT->f. */
9434 display_tool_bar_line (it
)
9437 struct glyph_row
*row
= it
->glyph_row
;
9438 int max_x
= it
->last_visible_x
;
9441 prepare_desired_row (row
);
9442 row
->y
= it
->current_y
;
9444 /* Note that this isn't made use of if the face hasn't a box,
9445 so there's no need to check the face here. */
9446 it
->start_of_box_run_p
= 1;
9448 while (it
->current_x
< max_x
)
9450 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9452 /* Get the next display element. */
9453 if (!get_next_display_element (it
))
9456 /* Produce glyphs. */
9457 x_before
= it
->current_x
;
9458 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9459 PRODUCE_GLYPHS (it
);
9461 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9466 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9468 if (x
+ glyph
->pixel_width
> max_x
)
9470 /* Glyph doesn't fit on line. */
9471 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9477 x
+= glyph
->pixel_width
;
9481 /* Stop at line ends. */
9482 if (ITERATOR_AT_END_OF_LINE_P (it
))
9485 set_iterator_to_next (it
, 1);
9490 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9491 extend_face_to_end_of_line (it
);
9492 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9493 last
->right_box_line_p
= 1;
9494 if (last
== row
->glyphs
[TEXT_AREA
])
9495 last
->left_box_line_p
= 1;
9496 compute_line_metrics (it
);
9498 /* If line is empty, make it occupy the rest of the tool-bar. */
9499 if (!row
->displays_text_p
)
9501 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9502 row
->ascent
= row
->phys_ascent
= 0;
9503 row
->extra_line_spacing
= 0;
9506 row
->full_width_p
= 1;
9507 row
->continued_p
= 0;
9508 row
->truncated_on_left_p
= 0;
9509 row
->truncated_on_right_p
= 0;
9511 it
->current_x
= it
->hpos
= 0;
9512 it
->current_y
+= row
->height
;
9518 /* Value is the number of screen lines needed to make all tool-bar
9519 items of frame F visible. */
9522 tool_bar_lines_needed (f
)
9525 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9528 /* Initialize an iterator for iteration over
9529 F->desired_tool_bar_string in the tool-bar window of frame F. */
9530 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9531 it
.first_visible_x
= 0;
9532 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9533 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9535 while (!ITERATOR_AT_END_P (&it
))
9537 it
.glyph_row
= w
->desired_matrix
->rows
;
9538 clear_glyph_row (it
.glyph_row
);
9539 display_tool_bar_line (&it
);
9542 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9546 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9548 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9557 frame
= selected_frame
;
9559 CHECK_FRAME (frame
);
9562 if (WINDOWP (f
->tool_bar_window
)
9563 || (w
= XWINDOW (f
->tool_bar_window
),
9564 WINDOW_TOTAL_LINES (w
) > 0))
9566 update_tool_bar (f
, 1);
9567 if (f
->n_tool_bar_items
)
9569 build_desired_tool_bar_string (f
);
9570 nlines
= tool_bar_lines_needed (f
);
9574 return make_number (nlines
);
9578 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9579 height should be changed. */
9582 redisplay_tool_bar (f
)
9587 struct glyph_row
*row
;
9588 int change_height_p
= 0;
9591 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9592 update_frame_tool_bar (f
);
9596 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9597 do anything. This means you must start with tool-bar-lines
9598 non-zero to get the auto-sizing effect. Or in other words, you
9599 can turn off tool-bars by specifying tool-bar-lines zero. */
9600 if (!WINDOWP (f
->tool_bar_window
)
9601 || (w
= XWINDOW (f
->tool_bar_window
),
9602 WINDOW_TOTAL_LINES (w
) == 0))
9605 /* Set up an iterator for the tool-bar window. */
9606 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9607 it
.first_visible_x
= 0;
9608 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9611 /* Build a string that represents the contents of the tool-bar. */
9612 build_desired_tool_bar_string (f
);
9613 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9615 /* Display as many lines as needed to display all tool-bar items. */
9616 while (it
.current_y
< it
.last_visible_y
)
9617 display_tool_bar_line (&it
);
9619 /* It doesn't make much sense to try scrolling in the tool-bar
9620 window, so don't do it. */
9621 w
->desired_matrix
->no_scrolling_p
= 1;
9622 w
->must_be_updated_p
= 1;
9624 if (auto_resize_tool_bars_p
)
9628 /* If we couldn't display everything, change the tool-bar's
9630 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9631 change_height_p
= 1;
9633 /* If there are blank lines at the end, except for a partially
9634 visible blank line at the end that is smaller than
9635 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9636 row
= it
.glyph_row
- 1;
9637 if (!row
->displays_text_p
9638 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9639 change_height_p
= 1;
9641 /* If row displays tool-bar items, but is partially visible,
9642 change the tool-bar's height. */
9643 if (row
->displays_text_p
9644 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9645 change_height_p
= 1;
9647 /* Resize windows as needed by changing the `tool-bar-lines'
9650 && (nlines
= tool_bar_lines_needed (f
),
9651 nlines
!= WINDOW_TOTAL_LINES (w
)))
9653 extern Lisp_Object Qtool_bar_lines
;
9655 int old_height
= WINDOW_TOTAL_LINES (w
);
9657 XSETFRAME (frame
, f
);
9658 clear_glyph_matrix (w
->desired_matrix
);
9659 Fmodify_frame_parameters (frame
,
9660 Fcons (Fcons (Qtool_bar_lines
,
9661 make_number (nlines
)),
9663 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9664 fonts_changed_p
= 1;
9668 return change_height_p
;
9672 /* Get information about the tool-bar item which is displayed in GLYPH
9673 on frame F. Return in *PROP_IDX the index where tool-bar item
9674 properties start in F->tool_bar_items. Value is zero if
9675 GLYPH doesn't display a tool-bar item. */
9678 tool_bar_item_info (f
, glyph
, prop_idx
)
9680 struct glyph
*glyph
;
9687 /* This function can be called asynchronously, which means we must
9688 exclude any possibility that Fget_text_property signals an
9690 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9691 charpos
= max (0, charpos
);
9693 /* Get the text property `menu-item' at pos. The value of that
9694 property is the start index of this item's properties in
9695 F->tool_bar_items. */
9696 prop
= Fget_text_property (make_number (charpos
),
9697 Qmenu_item
, f
->current_tool_bar_string
);
9698 if (INTEGERP (prop
))
9700 *prop_idx
= XINT (prop
);
9710 /* Get information about the tool-bar item at position X/Y on frame F.
9711 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9712 the current matrix of the tool-bar window of F, or NULL if not
9713 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9714 item in F->tool_bar_items. Value is
9716 -1 if X/Y is not on a tool-bar item
9717 0 if X/Y is on the same item that was highlighted before.
9721 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9724 struct glyph
**glyph
;
9725 int *hpos
, *vpos
, *prop_idx
;
9727 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9728 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9731 /* Find the glyph under X/Y. */
9732 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9736 /* Get the start of this tool-bar item's properties in
9737 f->tool_bar_items. */
9738 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9741 /* Is mouse on the highlighted item? */
9742 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9743 && *vpos
>= dpyinfo
->mouse_face_beg_row
9744 && *vpos
<= dpyinfo
->mouse_face_end_row
9745 && (*vpos
> dpyinfo
->mouse_face_beg_row
9746 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9747 && (*vpos
< dpyinfo
->mouse_face_end_row
9748 || *hpos
< dpyinfo
->mouse_face_end_col
9749 || dpyinfo
->mouse_face_past_end
))
9757 Handle mouse button event on the tool-bar of frame F, at
9758 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9759 0 for button release. MODIFIERS is event modifiers for button
9763 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9766 unsigned int modifiers
;
9768 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9769 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9770 int hpos
, vpos
, prop_idx
;
9771 struct glyph
*glyph
;
9772 Lisp_Object enabled_p
;
9774 /* If not on the highlighted tool-bar item, return. */
9775 frame_to_window_pixel_xy (w
, &x
, &y
);
9776 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9779 /* If item is disabled, do nothing. */
9780 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9781 if (NILP (enabled_p
))
9786 /* Show item in pressed state. */
9787 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9788 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9789 last_tool_bar_item
= prop_idx
;
9793 Lisp_Object key
, frame
;
9794 struct input_event event
;
9797 /* Show item in released state. */
9798 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9799 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9801 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9803 XSETFRAME (frame
, f
);
9804 event
.kind
= TOOL_BAR_EVENT
;
9805 event
.frame_or_window
= frame
;
9807 kbd_buffer_store_event (&event
);
9809 event
.kind
= TOOL_BAR_EVENT
;
9810 event
.frame_or_window
= frame
;
9812 event
.modifiers
= modifiers
;
9813 kbd_buffer_store_event (&event
);
9814 last_tool_bar_item
= -1;
9819 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9820 tool-bar window-relative coordinates X/Y. Called from
9821 note_mouse_highlight. */
9824 note_tool_bar_highlight (f
, x
, y
)
9828 Lisp_Object window
= f
->tool_bar_window
;
9829 struct window
*w
= XWINDOW (window
);
9830 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9832 struct glyph
*glyph
;
9833 struct glyph_row
*row
;
9835 Lisp_Object enabled_p
;
9837 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9838 int mouse_down_p
, rc
;
9840 /* Function note_mouse_highlight is called with negative x(y
9841 values when mouse moves outside of the frame. */
9842 if (x
<= 0 || y
<= 0)
9844 clear_mouse_face (dpyinfo
);
9848 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9851 /* Not on tool-bar item. */
9852 clear_mouse_face (dpyinfo
);
9856 /* On same tool-bar item as before. */
9859 clear_mouse_face (dpyinfo
);
9861 /* Mouse is down, but on different tool-bar item? */
9862 mouse_down_p
= (dpyinfo
->grabbed
9863 && f
== last_mouse_frame
9864 && FRAME_LIVE_P (f
));
9866 && last_tool_bar_item
!= prop_idx
)
9869 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9870 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9872 /* If tool-bar item is not enabled, don't highlight it. */
9873 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9874 if (!NILP (enabled_p
))
9876 /* Compute the x-position of the glyph. In front and past the
9877 image is a space. We include this in the highlighted area. */
9878 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9879 for (i
= x
= 0; i
< hpos
; ++i
)
9880 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9882 /* Record this as the current active region. */
9883 dpyinfo
->mouse_face_beg_col
= hpos
;
9884 dpyinfo
->mouse_face_beg_row
= vpos
;
9885 dpyinfo
->mouse_face_beg_x
= x
;
9886 dpyinfo
->mouse_face_beg_y
= row
->y
;
9887 dpyinfo
->mouse_face_past_end
= 0;
9889 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9890 dpyinfo
->mouse_face_end_row
= vpos
;
9891 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9892 dpyinfo
->mouse_face_end_y
= row
->y
;
9893 dpyinfo
->mouse_face_window
= window
;
9894 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9896 /* Display it as active. */
9897 show_mouse_face (dpyinfo
, draw
);
9898 dpyinfo
->mouse_face_image_state
= draw
;
9903 /* Set help_echo_string to a help string to display for this tool-bar item.
9904 XTread_socket does the rest. */
9905 help_echo_object
= help_echo_window
= Qnil
;
9907 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9908 if (NILP (help_echo_string
))
9909 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9912 #endif /* HAVE_WINDOW_SYSTEM */
9916 /************************************************************************
9917 Horizontal scrolling
9918 ************************************************************************/
9920 static int hscroll_window_tree
P_ ((Lisp_Object
));
9921 static int hscroll_windows
P_ ((Lisp_Object
));
9923 /* For all leaf windows in the window tree rooted at WINDOW, set their
9924 hscroll value so that PT is (i) visible in the window, and (ii) so
9925 that it is not within a certain margin at the window's left and
9926 right border. Value is non-zero if any window's hscroll has been
9930 hscroll_window_tree (window
)
9933 int hscrolled_p
= 0;
9934 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9935 int hscroll_step_abs
= 0;
9936 double hscroll_step_rel
= 0;
9938 if (hscroll_relative_p
)
9940 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9941 if (hscroll_step_rel
< 0)
9943 hscroll_relative_p
= 0;
9944 hscroll_step_abs
= 0;
9947 else if (INTEGERP (Vhscroll_step
))
9949 hscroll_step_abs
= XINT (Vhscroll_step
);
9950 if (hscroll_step_abs
< 0)
9951 hscroll_step_abs
= 0;
9954 hscroll_step_abs
= 0;
9956 while (WINDOWP (window
))
9958 struct window
*w
= XWINDOW (window
);
9960 if (WINDOWP (w
->hchild
))
9961 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9962 else if (WINDOWP (w
->vchild
))
9963 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9964 else if (w
->cursor
.vpos
>= 0)
9967 int text_area_width
;
9968 struct glyph_row
*current_cursor_row
9969 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9970 struct glyph_row
*desired_cursor_row
9971 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9972 struct glyph_row
*cursor_row
9973 = (desired_cursor_row
->enabled_p
9974 ? desired_cursor_row
9975 : current_cursor_row
);
9977 text_area_width
= window_box_width (w
, TEXT_AREA
);
9979 /* Scroll when cursor is inside this scroll margin. */
9980 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9982 if ((XFASTINT (w
->hscroll
)
9983 && w
->cursor
.x
<= h_margin
)
9984 || (cursor_row
->enabled_p
9985 && cursor_row
->truncated_on_right_p
9986 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9990 struct buffer
*saved_current_buffer
;
9994 /* Find point in a display of infinite width. */
9995 saved_current_buffer
= current_buffer
;
9996 current_buffer
= XBUFFER (w
->buffer
);
9998 if (w
== XWINDOW (selected_window
))
9999 pt
= BUF_PT (current_buffer
);
10002 pt
= marker_position (w
->pointm
);
10003 pt
= max (BEGV
, pt
);
10007 /* Move iterator to pt starting at cursor_row->start in
10008 a line with infinite width. */
10009 init_to_row_start (&it
, w
, cursor_row
);
10010 it
.last_visible_x
= INFINITY
;
10011 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10012 current_buffer
= saved_current_buffer
;
10014 /* Position cursor in window. */
10015 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10016 hscroll
= max (0, (it
.current_x
10017 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10018 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10019 : (text_area_width
/ 2))))
10020 / FRAME_COLUMN_WIDTH (it
.f
);
10021 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10023 if (hscroll_relative_p
)
10024 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10027 wanted_x
= text_area_width
10028 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10031 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10035 if (hscroll_relative_p
)
10036 wanted_x
= text_area_width
* hscroll_step_rel
10039 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10042 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10044 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10046 /* Don't call Fset_window_hscroll if value hasn't
10047 changed because it will prevent redisplay
10049 if (XFASTINT (w
->hscroll
) != hscroll
)
10051 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10052 w
->hscroll
= make_number (hscroll
);
10061 /* Value is non-zero if hscroll of any leaf window has been changed. */
10062 return hscrolled_p
;
10066 /* Set hscroll so that cursor is visible and not inside horizontal
10067 scroll margins for all windows in the tree rooted at WINDOW. See
10068 also hscroll_window_tree above. Value is non-zero if any window's
10069 hscroll has been changed. If it has, desired matrices on the frame
10070 of WINDOW are cleared. */
10073 hscroll_windows (window
)
10074 Lisp_Object window
;
10078 if (automatic_hscrolling_p
)
10080 hscrolled_p
= hscroll_window_tree (window
);
10082 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10086 return hscrolled_p
;
10091 /************************************************************************
10093 ************************************************************************/
10095 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10096 to a non-zero value. This is sometimes handy to have in a debugger
10101 /* First and last unchanged row for try_window_id. */
10103 int debug_first_unchanged_at_end_vpos
;
10104 int debug_last_unchanged_at_beg_vpos
;
10106 /* Delta vpos and y. */
10108 int debug_dvpos
, debug_dy
;
10110 /* Delta in characters and bytes for try_window_id. */
10112 int debug_delta
, debug_delta_bytes
;
10114 /* Values of window_end_pos and window_end_vpos at the end of
10117 EMACS_INT debug_end_pos
, debug_end_vpos
;
10119 /* Append a string to W->desired_matrix->method. FMT is a printf
10120 format string. A1...A9 are a supplement for a variable-length
10121 argument list. If trace_redisplay_p is non-zero also printf the
10122 resulting string to stderr. */
10125 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10128 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10131 char *method
= w
->desired_matrix
->method
;
10132 int len
= strlen (method
);
10133 int size
= sizeof w
->desired_matrix
->method
;
10134 int remaining
= size
- len
- 1;
10136 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10137 if (len
&& remaining
)
10140 --remaining
, ++len
;
10143 strncpy (method
+ len
, buffer
, remaining
);
10145 if (trace_redisplay_p
)
10146 fprintf (stderr
, "%p (%s): %s\n",
10148 ((BUFFERP (w
->buffer
)
10149 && STRINGP (XBUFFER (w
->buffer
)->name
))
10150 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10155 #endif /* GLYPH_DEBUG */
10158 /* Value is non-zero if all changes in window W, which displays
10159 current_buffer, are in the text between START and END. START is a
10160 buffer position, END is given as a distance from Z. Used in
10161 redisplay_internal for display optimization. */
10164 text_outside_line_unchanged_p (w
, start
, end
)
10168 int unchanged_p
= 1;
10170 /* If text or overlays have changed, see where. */
10171 if (XFASTINT (w
->last_modified
) < MODIFF
10172 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10174 /* Gap in the line? */
10175 if (GPT
< start
|| Z
- GPT
< end
)
10178 /* Changes start in front of the line, or end after it? */
10180 && (BEG_UNCHANGED
< start
- 1
10181 || END_UNCHANGED
< end
))
10184 /* If selective display, can't optimize if changes start at the
10185 beginning of the line. */
10187 && INTEGERP (current_buffer
->selective_display
)
10188 && XINT (current_buffer
->selective_display
) > 0
10189 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10192 /* If there are overlays at the start or end of the line, these
10193 may have overlay strings with newlines in them. A change at
10194 START, for instance, may actually concern the display of such
10195 overlay strings as well, and they are displayed on different
10196 lines. So, quickly rule out this case. (For the future, it
10197 might be desirable to implement something more telling than
10198 just BEG/END_UNCHANGED.) */
10201 if (BEG
+ BEG_UNCHANGED
== start
10202 && overlay_touches_p (start
))
10204 if (END_UNCHANGED
== end
10205 && overlay_touches_p (Z
- end
))
10210 return unchanged_p
;
10214 /* Do a frame update, taking possible shortcuts into account. This is
10215 the main external entry point for redisplay.
10217 If the last redisplay displayed an echo area message and that message
10218 is no longer requested, we clear the echo area or bring back the
10219 mini-buffer if that is in use. */
10224 redisplay_internal (0);
10229 overlay_arrow_string_or_property (var
)
10234 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10237 return Voverlay_arrow_string
;
10240 /* Return 1 if there are any overlay-arrows in current_buffer. */
10242 overlay_arrow_in_current_buffer_p ()
10246 for (vlist
= Voverlay_arrow_variable_list
;
10248 vlist
= XCDR (vlist
))
10250 Lisp_Object var
= XCAR (vlist
);
10253 if (!SYMBOLP (var
))
10255 val
= find_symbol_value (var
);
10257 && current_buffer
== XMARKER (val
)->buffer
)
10264 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10268 overlay_arrows_changed_p ()
10272 for (vlist
= Voverlay_arrow_variable_list
;
10274 vlist
= XCDR (vlist
))
10276 Lisp_Object var
= XCAR (vlist
);
10277 Lisp_Object val
, pstr
;
10279 if (!SYMBOLP (var
))
10281 val
= find_symbol_value (var
);
10282 if (!MARKERP (val
))
10284 if (! EQ (COERCE_MARKER (val
),
10285 Fget (var
, Qlast_arrow_position
))
10286 || ! (pstr
= overlay_arrow_string_or_property (var
),
10287 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10293 /* Mark overlay arrows to be updated on next redisplay. */
10296 update_overlay_arrows (up_to_date
)
10301 for (vlist
= Voverlay_arrow_variable_list
;
10303 vlist
= XCDR (vlist
))
10305 Lisp_Object var
= XCAR (vlist
);
10307 if (!SYMBOLP (var
))
10310 if (up_to_date
> 0)
10312 Lisp_Object val
= find_symbol_value (var
);
10313 Fput (var
, Qlast_arrow_position
,
10314 COERCE_MARKER (val
));
10315 Fput (var
, Qlast_arrow_string
,
10316 overlay_arrow_string_or_property (var
));
10318 else if (up_to_date
< 0
10319 || !NILP (Fget (var
, Qlast_arrow_position
)))
10321 Fput (var
, Qlast_arrow_position
, Qt
);
10322 Fput (var
, Qlast_arrow_string
, Qt
);
10328 /* Return overlay arrow string to display at row.
10329 Return integer (bitmap number) for arrow bitmap in left fringe.
10330 Return nil if no overlay arrow. */
10333 overlay_arrow_at_row (it
, row
)
10335 struct glyph_row
*row
;
10339 for (vlist
= Voverlay_arrow_variable_list
;
10341 vlist
= XCDR (vlist
))
10343 Lisp_Object var
= XCAR (vlist
);
10346 if (!SYMBOLP (var
))
10349 val
= find_symbol_value (var
);
10352 && current_buffer
== XMARKER (val
)->buffer
10353 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10355 if (FRAME_WINDOW_P (it
->f
)
10356 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10358 #ifdef HAVE_WINDOW_SYSTEM
10359 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10362 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10363 return make_number (fringe_bitmap
);
10366 return make_number (-1); /* Use default arrow bitmap */
10368 return overlay_arrow_string_or_property (var
);
10375 /* Return 1 if point moved out of or into a composition. Otherwise
10376 return 0. PREV_BUF and PREV_PT are the last point buffer and
10377 position. BUF and PT are the current point buffer and position. */
10380 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10381 struct buffer
*prev_buf
, *buf
;
10386 Lisp_Object buffer
;
10388 XSETBUFFER (buffer
, buf
);
10389 /* Check a composition at the last point if point moved within the
10391 if (prev_buf
== buf
)
10394 /* Point didn't move. */
10397 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10398 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10399 && COMPOSITION_VALID_P (start
, end
, prop
)
10400 && start
< prev_pt
&& end
> prev_pt
)
10401 /* The last point was within the composition. Return 1 iff
10402 point moved out of the composition. */
10403 return (pt
<= start
|| pt
>= end
);
10406 /* Check a composition at the current point. */
10407 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10408 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10409 && COMPOSITION_VALID_P (start
, end
, prop
)
10410 && start
< pt
&& end
> pt
);
10414 /* Reconsider the setting of B->clip_changed which is displayed
10418 reconsider_clip_changes (w
, b
)
10422 if (b
->clip_changed
10423 && !NILP (w
->window_end_valid
)
10424 && w
->current_matrix
->buffer
== b
10425 && w
->current_matrix
->zv
== BUF_ZV (b
)
10426 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10427 b
->clip_changed
= 0;
10429 /* If display wasn't paused, and W is not a tool bar window, see if
10430 point has been moved into or out of a composition. In that case,
10431 we set b->clip_changed to 1 to force updating the screen. If
10432 b->clip_changed has already been set to 1, we can skip this
10434 if (!b
->clip_changed
10435 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10439 if (w
== XWINDOW (selected_window
))
10440 pt
= BUF_PT (current_buffer
);
10442 pt
= marker_position (w
->pointm
);
10444 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10445 || pt
!= XINT (w
->last_point
))
10446 && check_point_in_composition (w
->current_matrix
->buffer
,
10447 XINT (w
->last_point
),
10448 XBUFFER (w
->buffer
), pt
))
10449 b
->clip_changed
= 1;
10454 /* Select FRAME to forward the values of frame-local variables into C
10455 variables so that the redisplay routines can access those values
10459 select_frame_for_redisplay (frame
)
10462 Lisp_Object tail
, sym
, val
;
10463 Lisp_Object old
= selected_frame
;
10465 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
10467 selected_frame
= frame
;
10469 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10470 if (CONSP (XCAR (tail
))
10471 && (sym
= XCAR (XCAR (tail
)),
10473 && (sym
= indirect_variable (sym
),
10474 val
= SYMBOL_VALUE (sym
),
10475 (BUFFER_LOCAL_VALUEP (val
)
10476 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10477 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10478 /* Use find_symbol_value rather than Fsymbol_value
10479 to avoid an error if it is void. */
10480 find_symbol_value (sym
);
10482 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10483 if (CONSP (XCAR (tail
))
10484 && (sym
= XCAR (XCAR (tail
)),
10486 && (sym
= indirect_variable (sym
),
10487 val
= SYMBOL_VALUE (sym
),
10488 (BUFFER_LOCAL_VALUEP (val
)
10489 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10490 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10491 find_symbol_value (sym
);
10495 #define STOP_POLLING \
10496 do { if (! polling_stopped_here) stop_polling (); \
10497 polling_stopped_here = 1; } while (0)
10499 #define RESUME_POLLING \
10500 do { if (polling_stopped_here) start_polling (); \
10501 polling_stopped_here = 0; } while (0)
10504 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10505 response to any user action; therefore, we should preserve the echo
10506 area. (Actually, our caller does that job.) Perhaps in the future
10507 avoid recentering windows if it is not necessary; currently that
10508 causes some problems. */
10511 redisplay_internal (preserve_echo_area
)
10512 int preserve_echo_area
;
10514 struct window
*w
= XWINDOW (selected_window
);
10515 struct frame
*f
= XFRAME (w
->frame
);
10517 int must_finish
= 0;
10518 struct text_pos tlbufpos
, tlendpos
;
10519 int number_of_visible_frames
;
10521 struct frame
*sf
= SELECTED_FRAME ();
10522 int polling_stopped_here
= 0;
10524 /* Non-zero means redisplay has to consider all windows on all
10525 frames. Zero means, only selected_window is considered. */
10526 int consider_all_windows_p
;
10528 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10530 /* No redisplay if running in batch mode or frame is not yet fully
10531 initialized, or redisplay is explicitly turned off by setting
10532 Vinhibit_redisplay. */
10534 || !NILP (Vinhibit_redisplay
)
10535 || !f
->glyphs_initialized_p
)
10538 /* The flag redisplay_performed_directly_p is set by
10539 direct_output_for_insert when it already did the whole screen
10540 update necessary. */
10541 if (redisplay_performed_directly_p
)
10543 redisplay_performed_directly_p
= 0;
10544 if (!hscroll_windows (selected_window
))
10548 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10549 if (popup_activated ())
10553 /* I don't think this happens but let's be paranoid. */
10554 if (redisplaying_p
)
10557 /* Record a function that resets redisplaying_p to its old value
10558 when we leave this function. */
10559 count
= SPECPDL_INDEX ();
10560 record_unwind_protect (unwind_redisplay
,
10561 Fcons (make_number (redisplaying_p
), selected_frame
));
10563 specbind (Qinhibit_free_realized_faces
, Qnil
);
10566 Lisp_Object tail
, frame
;
10568 FOR_EACH_FRAME (tail
, frame
)
10570 struct frame
*f
= XFRAME (frame
);
10571 f
->already_hscrolled_p
= 0;
10577 reconsider_clip_changes (w
, current_buffer
);
10578 last_escape_glyph_frame
= NULL
;
10579 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10581 /* If new fonts have been loaded that make a glyph matrix adjustment
10582 necessary, do it. */
10583 if (fonts_changed_p
)
10585 adjust_glyphs (NULL
);
10586 ++windows_or_buffers_changed
;
10587 fonts_changed_p
= 0;
10590 /* If face_change_count is non-zero, init_iterator will free all
10591 realized faces, which includes the faces referenced from current
10592 matrices. So, we can't reuse current matrices in this case. */
10593 if (face_change_count
)
10594 ++windows_or_buffers_changed
;
10596 if (FRAME_TERMCAP_P (sf
)
10597 && FRAME_TTY (sf
)->previous_frame
!= sf
)
10599 /* Since frames on a single ASCII terminal share the same
10600 display area, displaying a different frame means redisplay
10601 the whole thing. */
10602 windows_or_buffers_changed
++;
10603 SET_FRAME_GARBAGED (sf
);
10604 FRAME_TTY (sf
)->previous_frame
= sf
;
10607 /* Set the visible flags for all frames. Do this before checking
10608 for resized or garbaged frames; they want to know if their frames
10609 are visible. See the comment in frame.h for
10610 FRAME_SAMPLE_VISIBILITY. */
10612 Lisp_Object tail
, frame
;
10614 number_of_visible_frames
= 0;
10616 FOR_EACH_FRAME (tail
, frame
)
10618 struct frame
*f
= XFRAME (frame
);
10620 FRAME_SAMPLE_VISIBILITY (f
);
10621 if (FRAME_VISIBLE_P (f
))
10622 ++number_of_visible_frames
;
10623 clear_desired_matrices (f
);
10628 /* Notice any pending interrupt request to change frame size. */
10629 do_pending_window_change (1);
10631 /* Clear frames marked as garbaged. */
10632 if (frame_garbaged
)
10633 clear_garbaged_frames ();
10635 /* Build menubar and tool-bar items. */
10636 if (NILP (Vmemory_full
))
10637 prepare_menu_bars ();
10639 if (windows_or_buffers_changed
)
10640 update_mode_lines
++;
10642 /* Detect case that we need to write or remove a star in the mode line. */
10643 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10645 w
->update_mode_line
= Qt
;
10646 if (buffer_shared
> 1)
10647 update_mode_lines
++;
10650 /* If %c is in the mode line, update it if needed. */
10651 if (!NILP (w
->column_number_displayed
)
10652 /* This alternative quickly identifies a common case
10653 where no change is needed. */
10654 && !(PT
== XFASTINT (w
->last_point
)
10655 && XFASTINT (w
->last_modified
) >= MODIFF
10656 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10657 && (XFASTINT (w
->column_number_displayed
)
10658 != (int) current_column ())) /* iftc */
10659 w
->update_mode_line
= Qt
;
10661 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10663 /* The variable buffer_shared is set in redisplay_window and
10664 indicates that we redisplay a buffer in different windows. See
10666 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10667 || cursor_type_changed
);
10669 /* If specs for an arrow have changed, do thorough redisplay
10670 to ensure we remove any arrow that should no longer exist. */
10671 if (overlay_arrows_changed_p ())
10672 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10674 /* Normally the message* functions will have already displayed and
10675 updated the echo area, but the frame may have been trashed, or
10676 the update may have been preempted, so display the echo area
10677 again here. Checking message_cleared_p captures the case that
10678 the echo area should be cleared. */
10679 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10680 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10681 || (message_cleared_p
10682 && minibuf_level
== 0
10683 /* If the mini-window is currently selected, this means the
10684 echo-area doesn't show through. */
10685 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10687 int window_height_changed_p
= echo_area_display (0);
10690 /* If we don't display the current message, don't clear the
10691 message_cleared_p flag, because, if we did, we wouldn't clear
10692 the echo area in the next redisplay which doesn't preserve
10694 if (!display_last_displayed_message_p
)
10695 message_cleared_p
= 0;
10697 if (fonts_changed_p
)
10699 else if (window_height_changed_p
)
10701 consider_all_windows_p
= 1;
10702 ++update_mode_lines
;
10703 ++windows_or_buffers_changed
;
10705 /* If window configuration was changed, frames may have been
10706 marked garbaged. Clear them or we will experience
10707 surprises wrt scrolling. */
10708 if (frame_garbaged
)
10709 clear_garbaged_frames ();
10712 else if (EQ (selected_window
, minibuf_window
)
10713 && (current_buffer
->clip_changed
10714 || XFASTINT (w
->last_modified
) < MODIFF
10715 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10716 && resize_mini_window (w
, 0))
10718 /* Resized active mini-window to fit the size of what it is
10719 showing if its contents might have changed. */
10721 consider_all_windows_p
= 1;
10722 ++windows_or_buffers_changed
;
10723 ++update_mode_lines
;
10725 /* If window configuration was changed, frames may have been
10726 marked garbaged. Clear them or we will experience
10727 surprises wrt scrolling. */
10728 if (frame_garbaged
)
10729 clear_garbaged_frames ();
10733 /* If showing the region, and mark has changed, we must redisplay
10734 the whole window. The assignment to this_line_start_pos prevents
10735 the optimization directly below this if-statement. */
10736 if (((!NILP (Vtransient_mark_mode
)
10737 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10738 != !NILP (w
->region_showing
))
10739 || (!NILP (w
->region_showing
)
10740 && !EQ (w
->region_showing
,
10741 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10742 CHARPOS (this_line_start_pos
) = 0;
10744 /* Optimize the case that only the line containing the cursor in the
10745 selected window has changed. Variables starting with this_ are
10746 set in display_line and record information about the line
10747 containing the cursor. */
10748 tlbufpos
= this_line_start_pos
;
10749 tlendpos
= this_line_end_pos
;
10750 if (!consider_all_windows_p
10751 && CHARPOS (tlbufpos
) > 0
10752 && NILP (w
->update_mode_line
)
10753 && !current_buffer
->clip_changed
10754 && !current_buffer
->prevent_redisplay_optimizations_p
10755 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10756 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10757 /* Make sure recorded data applies to current buffer, etc. */
10758 && this_line_buffer
== current_buffer
10759 && current_buffer
== XBUFFER (w
->buffer
)
10760 && NILP (w
->force_start
)
10761 && NILP (w
->optional_new_start
)
10762 /* Point must be on the line that we have info recorded about. */
10763 && PT
>= CHARPOS (tlbufpos
)
10764 && PT
<= Z
- CHARPOS (tlendpos
)
10765 /* All text outside that line, including its final newline,
10766 must be unchanged */
10767 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10768 CHARPOS (tlendpos
)))
10770 if (CHARPOS (tlbufpos
) > BEGV
10771 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10772 && (CHARPOS (tlbufpos
) == ZV
10773 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10774 /* Former continuation line has disappeared by becoming empty */
10776 else if (XFASTINT (w
->last_modified
) < MODIFF
10777 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10778 || MINI_WINDOW_P (w
))
10780 /* We have to handle the case of continuation around a
10781 wide-column character (See the comment in indent.c around
10784 For instance, in the following case:
10786 -------- Insert --------
10787 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10788 J_I_ ==> J_I_ `^^' are cursors.
10792 As we have to redraw the line above, we should goto cancel. */
10795 int line_height_before
= this_line_pixel_height
;
10797 /* Note that start_display will handle the case that the
10798 line starting at tlbufpos is a continuation lines. */
10799 start_display (&it
, w
, tlbufpos
);
10801 /* Implementation note: It this still necessary? */
10802 if (it
.current_x
!= this_line_start_x
)
10805 TRACE ((stderr
, "trying display optimization 1\n"));
10806 w
->cursor
.vpos
= -1;
10807 overlay_arrow_seen
= 0;
10808 it
.vpos
= this_line_vpos
;
10809 it
.current_y
= this_line_y
;
10810 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10811 display_line (&it
);
10813 /* If line contains point, is not continued,
10814 and ends at same distance from eob as before, we win */
10815 if (w
->cursor
.vpos
>= 0
10816 /* Line is not continued, otherwise this_line_start_pos
10817 would have been set to 0 in display_line. */
10818 && CHARPOS (this_line_start_pos
)
10819 /* Line ends as before. */
10820 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10821 /* Line has same height as before. Otherwise other lines
10822 would have to be shifted up or down. */
10823 && this_line_pixel_height
== line_height_before
)
10825 /* If this is not the window's last line, we must adjust
10826 the charstarts of the lines below. */
10827 if (it
.current_y
< it
.last_visible_y
)
10829 struct glyph_row
*row
10830 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10831 int delta
, delta_bytes
;
10833 if (Z
- CHARPOS (tlendpos
) == ZV
)
10835 /* This line ends at end of (accessible part of)
10836 buffer. There is no newline to count. */
10838 - CHARPOS (tlendpos
)
10839 - MATRIX_ROW_START_CHARPOS (row
));
10840 delta_bytes
= (Z_BYTE
10841 - BYTEPOS (tlendpos
)
10842 - MATRIX_ROW_START_BYTEPOS (row
));
10846 /* This line ends in a newline. Must take
10847 account of the newline and the rest of the
10848 text that follows. */
10850 - CHARPOS (tlendpos
)
10851 - MATRIX_ROW_START_CHARPOS (row
));
10852 delta_bytes
= (Z_BYTE
10853 - BYTEPOS (tlendpos
)
10854 - MATRIX_ROW_START_BYTEPOS (row
));
10857 increment_matrix_positions (w
->current_matrix
,
10858 this_line_vpos
+ 1,
10859 w
->current_matrix
->nrows
,
10860 delta
, delta_bytes
);
10863 /* If this row displays text now but previously didn't,
10864 or vice versa, w->window_end_vpos may have to be
10866 if ((it
.glyph_row
- 1)->displays_text_p
)
10868 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10869 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10871 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10872 && this_line_vpos
> 0)
10873 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10874 w
->window_end_valid
= Qnil
;
10876 /* Update hint: No need to try to scroll in update_window. */
10877 w
->desired_matrix
->no_scrolling_p
= 1;
10880 *w
->desired_matrix
->method
= 0;
10881 debug_method_add (w
, "optimization 1");
10883 #ifdef HAVE_WINDOW_SYSTEM
10884 update_window_fringes (w
, 0);
10891 else if (/* Cursor position hasn't changed. */
10892 PT
== XFASTINT (w
->last_point
)
10893 /* Make sure the cursor was last displayed
10894 in this window. Otherwise we have to reposition it. */
10895 && 0 <= w
->cursor
.vpos
10896 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10900 do_pending_window_change (1);
10902 /* We used to always goto end_of_redisplay here, but this
10903 isn't enough if we have a blinking cursor. */
10904 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10905 goto end_of_redisplay
;
10909 /* If highlighting the region, or if the cursor is in the echo area,
10910 then we can't just move the cursor. */
10911 else if (! (!NILP (Vtransient_mark_mode
)
10912 && !NILP (current_buffer
->mark_active
))
10913 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10914 || highlight_nonselected_windows
)
10915 && NILP (w
->region_showing
)
10916 && NILP (Vshow_trailing_whitespace
)
10917 && !cursor_in_echo_area
)
10920 struct glyph_row
*row
;
10922 /* Skip from tlbufpos to PT and see where it is. Note that
10923 PT may be in invisible text. If so, we will end at the
10924 next visible position. */
10925 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10926 NULL
, DEFAULT_FACE_ID
);
10927 it
.current_x
= this_line_start_x
;
10928 it
.current_y
= this_line_y
;
10929 it
.vpos
= this_line_vpos
;
10931 /* The call to move_it_to stops in front of PT, but
10932 moves over before-strings. */
10933 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10935 if (it
.vpos
== this_line_vpos
10936 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10939 xassert (this_line_vpos
== it
.vpos
);
10940 xassert (this_line_y
== it
.current_y
);
10941 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10943 *w
->desired_matrix
->method
= 0;
10944 debug_method_add (w
, "optimization 3");
10953 /* Text changed drastically or point moved off of line. */
10954 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10957 CHARPOS (this_line_start_pos
) = 0;
10958 consider_all_windows_p
|= buffer_shared
> 1;
10959 ++clear_face_cache_count
;
10960 #ifdef HAVE_WINDOW_SYSTEM
10961 ++clear_image_cache_count
;
10964 /* Build desired matrices, and update the display. If
10965 consider_all_windows_p is non-zero, do it for all windows on all
10966 frames. Otherwise do it for selected_window, only. */
10968 if (consider_all_windows_p
)
10970 Lisp_Object tail
, frame
;
10972 FOR_EACH_FRAME (tail
, frame
)
10973 XFRAME (frame
)->updated_p
= 0;
10975 /* Recompute # windows showing selected buffer. This will be
10976 incremented each time such a window is displayed. */
10979 FOR_EACH_FRAME (tail
, frame
)
10981 struct frame
*f
= XFRAME (frame
);
10983 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10985 if (! EQ (frame
, selected_frame
))
10986 /* Select the frame, for the sake of frame-local
10988 select_frame_for_redisplay (frame
);
10990 /* Mark all the scroll bars to be removed; we'll redeem
10991 the ones we want when we redisplay their windows. */
10992 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
10993 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
10995 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10996 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10998 /* Any scroll bars which redisplay_windows should have
10999 nuked should now go away. */
11000 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11001 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11003 /* If fonts changed, display again. */
11004 /* ??? rms: I suspect it is a mistake to jump all the way
11005 back to retry here. It should just retry this frame. */
11006 if (fonts_changed_p
)
11009 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11011 /* See if we have to hscroll. */
11012 if (!f
->already_hscrolled_p
)
11014 f
->already_hscrolled_p
= 1;
11015 if (hscroll_windows (f
->root_window
))
11019 /* Prevent various kinds of signals during display
11020 update. stdio is not robust about handling
11021 signals, which can cause an apparent I/O
11023 if (interrupt_input
)
11024 unrequest_sigio ();
11027 /* Update the display. */
11028 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11029 pause
|= update_frame (f
, 0, 0);
11030 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11042 /* Do the mark_window_display_accurate after all windows have
11043 been redisplayed because this call resets flags in buffers
11044 which are needed for proper redisplay. */
11045 FOR_EACH_FRAME (tail
, frame
)
11047 struct frame
*f
= XFRAME (frame
);
11050 mark_window_display_accurate (f
->root_window
, 1);
11051 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11052 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11057 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11059 Lisp_Object mini_window
;
11060 struct frame
*mini_frame
;
11062 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11063 /* Use list_of_error, not Qerror, so that
11064 we catch only errors and don't run the debugger. */
11065 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11067 redisplay_window_error
);
11069 /* Compare desired and current matrices, perform output. */
11072 /* If fonts changed, display again. */
11073 if (fonts_changed_p
)
11076 /* Prevent various kinds of signals during display update.
11077 stdio is not robust about handling signals,
11078 which can cause an apparent I/O error. */
11079 if (interrupt_input
)
11080 unrequest_sigio ();
11083 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11085 if (hscroll_windows (selected_window
))
11088 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11089 pause
= update_frame (sf
, 0, 0);
11092 /* We may have called echo_area_display at the top of this
11093 function. If the echo area is on another frame, that may
11094 have put text on a frame other than the selected one, so the
11095 above call to update_frame would not have caught it. Catch
11097 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11098 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11100 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11102 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11103 pause
|= update_frame (mini_frame
, 0, 0);
11104 if (!pause
&& hscroll_windows (mini_window
))
11109 /* If display was paused because of pending input, make sure we do a
11110 thorough update the next time. */
11113 /* Prevent the optimization at the beginning of
11114 redisplay_internal that tries a single-line update of the
11115 line containing the cursor in the selected window. */
11116 CHARPOS (this_line_start_pos
) = 0;
11118 /* Let the overlay arrow be updated the next time. */
11119 update_overlay_arrows (0);
11121 /* If we pause after scrolling, some rows in the current
11122 matrices of some windows are not valid. */
11123 if (!WINDOW_FULL_WIDTH_P (w
)
11124 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11125 update_mode_lines
= 1;
11129 if (!consider_all_windows_p
)
11131 /* This has already been done above if
11132 consider_all_windows_p is set. */
11133 mark_window_display_accurate_1 (w
, 1);
11135 /* Say overlay arrows are up to date. */
11136 update_overlay_arrows (1);
11138 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11139 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11142 update_mode_lines
= 0;
11143 windows_or_buffers_changed
= 0;
11144 cursor_type_changed
= 0;
11147 /* Start SIGIO interrupts coming again. Having them off during the
11148 code above makes it less likely one will discard output, but not
11149 impossible, since there might be stuff in the system buffer here.
11150 But it is much hairier to try to do anything about that. */
11151 if (interrupt_input
)
11155 /* If a frame has become visible which was not before, redisplay
11156 again, so that we display it. Expose events for such a frame
11157 (which it gets when becoming visible) don't call the parts of
11158 redisplay constructing glyphs, so simply exposing a frame won't
11159 display anything in this case. So, we have to display these
11160 frames here explicitly. */
11163 Lisp_Object tail
, frame
;
11166 FOR_EACH_FRAME (tail
, frame
)
11168 int this_is_visible
= 0;
11170 if (XFRAME (frame
)->visible
)
11171 this_is_visible
= 1;
11172 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11173 if (XFRAME (frame
)->visible
)
11174 this_is_visible
= 1;
11176 if (this_is_visible
)
11180 if (new_count
!= number_of_visible_frames
)
11181 windows_or_buffers_changed
++;
11184 /* Change frame size now if a change is pending. */
11185 do_pending_window_change (1);
11187 /* If we just did a pending size change, or have additional
11188 visible frames, redisplay again. */
11189 if (windows_or_buffers_changed
&& !pause
)
11192 /* Clear the face cache eventually. */
11193 if (consider_all_windows_p
)
11195 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11197 clear_face_cache (0);
11198 clear_face_cache_count
= 0;
11200 #ifdef HAVE_WINDOW_SYSTEM
11201 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11203 Lisp_Object tail
, frame
;
11204 FOR_EACH_FRAME (tail
, frame
)
11206 struct frame
*f
= XFRAME (frame
);
11207 if (FRAME_WINDOW_P (f
))
11208 clear_image_cache (f
, 0);
11210 clear_image_cache_count
= 0;
11212 #endif /* HAVE_WINDOW_SYSTEM */
11216 unbind_to (count
, Qnil
);
11221 /* Redisplay, but leave alone any recent echo area message unless
11222 another message has been requested in its place.
11224 This is useful in situations where you need to redisplay but no
11225 user action has occurred, making it inappropriate for the message
11226 area to be cleared. See tracking_off and
11227 wait_reading_process_output for examples of these situations.
11229 FROM_WHERE is an integer saying from where this function was
11230 called. This is useful for debugging. */
11233 redisplay_preserve_echo_area (from_where
)
11236 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11238 if (!NILP (echo_area_buffer
[1]))
11240 /* We have a previously displayed message, but no current
11241 message. Redisplay the previous message. */
11242 display_last_displayed_message_p
= 1;
11243 redisplay_internal (1);
11244 display_last_displayed_message_p
= 0;
11247 redisplay_internal (1);
11249 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11250 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11251 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
11255 /* Function registered with record_unwind_protect in
11256 redisplay_internal. Reset redisplaying_p to the value it had
11257 before redisplay_internal was called, and clear
11258 prevent_freeing_realized_faces_p. It also selects the previously
11259 selected frame, unless it has been deleted (by an X connection
11260 failure during redisplay, for example). */
11263 unwind_redisplay (val
)
11266 Lisp_Object old_redisplaying_p
, old_frame
;
11268 old_redisplaying_p
= XCAR (val
);
11269 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11270 old_frame
= XCDR (val
);
11271 if (! EQ (old_frame
, selected_frame
)
11272 && FRAME_LIVE_P (XFRAME (old_frame
)))
11273 select_frame_for_redisplay (old_frame
);
11278 /* Mark the display of window W as accurate or inaccurate. If
11279 ACCURATE_P is non-zero mark display of W as accurate. If
11280 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11281 redisplay_internal is called. */
11284 mark_window_display_accurate_1 (w
, accurate_p
)
11288 if (BUFFERP (w
->buffer
))
11290 struct buffer
*b
= XBUFFER (w
->buffer
);
11293 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11294 w
->last_overlay_modified
11295 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11297 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11301 b
->clip_changed
= 0;
11302 b
->prevent_redisplay_optimizations_p
= 0;
11304 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11305 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11306 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11307 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11309 w
->current_matrix
->buffer
= b
;
11310 w
->current_matrix
->begv
= BUF_BEGV (b
);
11311 w
->current_matrix
->zv
= BUF_ZV (b
);
11313 w
->last_cursor
= w
->cursor
;
11314 w
->last_cursor_off_p
= w
->cursor_off_p
;
11316 if (w
== XWINDOW (selected_window
))
11317 w
->last_point
= make_number (BUF_PT (b
));
11319 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11325 w
->window_end_valid
= w
->buffer
;
11326 #if 0 /* This is incorrect with variable-height lines. */
11327 xassert (XINT (w
->window_end_vpos
)
11328 < (WINDOW_TOTAL_LINES (w
)
11329 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11331 w
->update_mode_line
= Qnil
;
11336 /* Mark the display of windows in the window tree rooted at WINDOW as
11337 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11338 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11339 be redisplayed the next time redisplay_internal is called. */
11342 mark_window_display_accurate (window
, accurate_p
)
11343 Lisp_Object window
;
11348 for (; !NILP (window
); window
= w
->next
)
11350 w
= XWINDOW (window
);
11351 mark_window_display_accurate_1 (w
, accurate_p
);
11353 if (!NILP (w
->vchild
))
11354 mark_window_display_accurate (w
->vchild
, accurate_p
);
11355 if (!NILP (w
->hchild
))
11356 mark_window_display_accurate (w
->hchild
, accurate_p
);
11361 update_overlay_arrows (1);
11365 /* Force a thorough redisplay the next time by setting
11366 last_arrow_position and last_arrow_string to t, which is
11367 unequal to any useful value of Voverlay_arrow_... */
11368 update_overlay_arrows (-1);
11373 /* Return value in display table DP (Lisp_Char_Table *) for character
11374 C. Since a display table doesn't have any parent, we don't have to
11375 follow parent. Do not call this function directly but use the
11376 macro DISP_CHAR_VECTOR. */
11379 disp_char_vector (dp
, c
)
11380 struct Lisp_Char_Table
*dp
;
11386 if (SINGLE_BYTE_CHAR_P (c
))
11387 return (dp
->contents
[c
]);
11389 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11392 else if (code
[2] < 32)
11395 /* Here, the possible range of code[0] (== charset ID) is
11396 128..max_charset. Since the top level char table contains data
11397 for multibyte characters after 256th element, we must increment
11398 code[0] by 128 to get a correct index. */
11400 code
[3] = -1; /* anchor */
11402 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11404 val
= dp
->contents
[code
[i
]];
11405 if (!SUB_CHAR_TABLE_P (val
))
11406 return (NILP (val
) ? dp
->defalt
: val
);
11409 /* Here, val is a sub char table. We return the default value of
11411 return (dp
->defalt
);
11416 /***********************************************************************
11418 ***********************************************************************/
11420 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11423 redisplay_windows (window
)
11424 Lisp_Object window
;
11426 while (!NILP (window
))
11428 struct window
*w
= XWINDOW (window
);
11430 if (!NILP (w
->hchild
))
11431 redisplay_windows (w
->hchild
);
11432 else if (!NILP (w
->vchild
))
11433 redisplay_windows (w
->vchild
);
11436 displayed_buffer
= XBUFFER (w
->buffer
);
11437 /* Use list_of_error, not Qerror, so that
11438 we catch only errors and don't run the debugger. */
11439 internal_condition_case_1 (redisplay_window_0
, window
,
11441 redisplay_window_error
);
11449 redisplay_window_error ()
11451 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11456 redisplay_window_0 (window
)
11457 Lisp_Object window
;
11459 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11460 redisplay_window (window
, 0);
11465 redisplay_window_1 (window
)
11466 Lisp_Object window
;
11468 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11469 redisplay_window (window
, 1);
11474 /* Increment GLYPH until it reaches END or CONDITION fails while
11475 adding (GLYPH)->pixel_width to X. */
11477 #define SKIP_GLYPHS(glyph, end, x, condition) \
11480 (x) += (glyph)->pixel_width; \
11483 while ((glyph) < (end) && (condition))
11486 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11487 DELTA is the number of bytes by which positions recorded in ROW
11488 differ from current buffer positions. */
11491 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11493 struct glyph_row
*row
;
11494 struct glyph_matrix
*matrix
;
11495 int delta
, delta_bytes
, dy
, dvpos
;
11497 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11498 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11499 struct glyph
*cursor
= NULL
;
11500 /* The first glyph that starts a sequence of glyphs from string. */
11501 struct glyph
*string_start
;
11502 /* The X coordinate of string_start. */
11503 int string_start_x
;
11504 /* The last known character position. */
11505 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11506 /* The last known character position before string_start. */
11507 int string_before_pos
;
11510 int cursor_from_overlay_pos
= 0;
11511 int pt_old
= PT
- delta
;
11513 /* Skip over glyphs not having an object at the start of the row.
11514 These are special glyphs like truncation marks on terminal
11516 if (row
->displays_text_p
)
11518 && INTEGERP (glyph
->object
)
11519 && glyph
->charpos
< 0)
11521 x
+= glyph
->pixel_width
;
11525 string_start
= NULL
;
11527 && !INTEGERP (glyph
->object
)
11528 && (!BUFFERP (glyph
->object
)
11529 || (last_pos
= glyph
->charpos
) < pt_old
))
11531 if (! STRINGP (glyph
->object
))
11533 string_start
= NULL
;
11534 x
+= glyph
->pixel_width
;
11536 if (cursor_from_overlay_pos
11537 && last_pos
> cursor_from_overlay_pos
)
11539 cursor_from_overlay_pos
= 0;
11545 string_before_pos
= last_pos
;
11546 string_start
= glyph
;
11547 string_start_x
= x
;
11548 /* Skip all glyphs from string. */
11552 if ((cursor
== NULL
|| glyph
> cursor
)
11553 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11554 Qcursor
, (glyph
)->object
))
11555 && (pos
= string_buffer_position (w
, glyph
->object
,
11556 string_before_pos
),
11557 (pos
== 0 /* From overlay */
11558 || pos
== pt_old
)))
11560 /* Estimate overlay buffer position from the buffer
11561 positions of the glyphs before and after the overlay.
11562 Add 1 to last_pos so that if point corresponds to the
11563 glyph right after the overlay, we still use a 'cursor'
11564 property found in that overlay. */
11565 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11569 x
+= glyph
->pixel_width
;
11572 while (glyph
< end
&& STRINGP (glyph
->object
));
11576 if (cursor
!= NULL
)
11581 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11583 /* Scan back over the ellipsis glyphs, decrementing positions. */
11584 while (glyph
> row
->glyphs
[TEXT_AREA
]
11585 && (glyph
- 1)->charpos
== last_pos
)
11586 glyph
--, x
-= glyph
->pixel_width
;
11587 /* That loop always goes one position too far,
11588 including the glyph before the ellipsis.
11589 So scan forward over that one. */
11590 x
+= glyph
->pixel_width
;
11593 else if (string_start
11594 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11596 /* We may have skipped over point because the previous glyphs
11597 are from string. As there's no easy way to know the
11598 character position of the current glyph, find the correct
11599 glyph on point by scanning from string_start again. */
11601 Lisp_Object string
;
11604 limit
= make_number (pt_old
+ 1);
11606 glyph
= string_start
;
11607 x
= string_start_x
;
11608 string
= glyph
->object
;
11609 pos
= string_buffer_position (w
, string
, string_before_pos
);
11610 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11611 because we always put cursor after overlay strings. */
11612 while (pos
== 0 && glyph
< end
)
11614 string
= glyph
->object
;
11615 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11617 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11620 while (glyph
< end
)
11622 pos
= XINT (Fnext_single_char_property_change
11623 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11626 /* Skip glyphs from the same string. */
11627 string
= glyph
->object
;
11628 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11629 /* Skip glyphs from an overlay. */
11631 && ! string_buffer_position (w
, glyph
->object
, pos
))
11633 string
= glyph
->object
;
11634 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11639 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11641 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11642 w
->cursor
.y
= row
->y
+ dy
;
11644 if (w
== XWINDOW (selected_window
))
11646 if (!row
->continued_p
11647 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11650 this_line_buffer
= XBUFFER (w
->buffer
);
11652 CHARPOS (this_line_start_pos
)
11653 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11654 BYTEPOS (this_line_start_pos
)
11655 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11657 CHARPOS (this_line_end_pos
)
11658 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11659 BYTEPOS (this_line_end_pos
)
11660 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11662 this_line_y
= w
->cursor
.y
;
11663 this_line_pixel_height
= row
->height
;
11664 this_line_vpos
= w
->cursor
.vpos
;
11665 this_line_start_x
= row
->x
;
11668 CHARPOS (this_line_start_pos
) = 0;
11673 /* Run window scroll functions, if any, for WINDOW with new window
11674 start STARTP. Sets the window start of WINDOW to that position.
11676 We assume that the window's buffer is really current. */
11678 static INLINE
struct text_pos
11679 run_window_scroll_functions (window
, startp
)
11680 Lisp_Object window
;
11681 struct text_pos startp
;
11683 struct window
*w
= XWINDOW (window
);
11684 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11686 if (current_buffer
!= XBUFFER (w
->buffer
))
11689 if (!NILP (Vwindow_scroll_functions
))
11691 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11692 make_number (CHARPOS (startp
)));
11693 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11694 /* In case the hook functions switch buffers. */
11695 if (current_buffer
!= XBUFFER (w
->buffer
))
11696 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11703 /* Make sure the line containing the cursor is fully visible.
11704 A value of 1 means there is nothing to be done.
11705 (Either the line is fully visible, or it cannot be made so,
11706 or we cannot tell.)
11708 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11709 is higher than window.
11711 A value of 0 means the caller should do scrolling
11712 as if point had gone off the screen. */
11715 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11718 int current_matrix_p
;
11720 struct glyph_matrix
*matrix
;
11721 struct glyph_row
*row
;
11724 if (!make_cursor_line_fully_visible_p
)
11727 /* It's not always possible to find the cursor, e.g, when a window
11728 is full of overlay strings. Don't do anything in that case. */
11729 if (w
->cursor
.vpos
< 0)
11732 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11733 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11735 /* If the cursor row is not partially visible, there's nothing to do. */
11736 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11739 /* If the row the cursor is in is taller than the window's height,
11740 it's not clear what to do, so do nothing. */
11741 window_height
= window_box_height (w
);
11742 if (row
->height
>= window_height
)
11744 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11750 /* This code used to try to scroll the window just enough to make
11751 the line visible. It returned 0 to say that the caller should
11752 allocate larger glyph matrices. */
11754 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11756 int dy
= row
->height
- row
->visible_height
;
11759 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11761 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11763 int dy
= - (row
->height
- row
->visible_height
);
11766 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11769 /* When we change the cursor y-position of the selected window,
11770 change this_line_y as well so that the display optimization for
11771 the cursor line of the selected window in redisplay_internal uses
11772 the correct y-position. */
11773 if (w
== XWINDOW (selected_window
))
11774 this_line_y
= w
->cursor
.y
;
11776 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11777 redisplay with larger matrices. */
11778 if (matrix
->nrows
< required_matrix_height (w
))
11780 fonts_changed_p
= 1;
11789 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11790 non-zero means only WINDOW is redisplayed in redisplay_internal.
11791 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11792 in redisplay_window to bring a partially visible line into view in
11793 the case that only the cursor has moved.
11795 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11796 last screen line's vertical height extends past the end of the screen.
11800 1 if scrolling succeeded
11802 0 if scrolling didn't find point.
11804 -1 if new fonts have been loaded so that we must interrupt
11805 redisplay, adjust glyph matrices, and try again. */
11811 SCROLLING_NEED_LARGER_MATRICES
11815 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11816 scroll_step
, temp_scroll_step
, last_line_misfit
)
11817 Lisp_Object window
;
11818 int just_this_one_p
;
11819 EMACS_INT scroll_conservatively
, scroll_step
;
11820 int temp_scroll_step
;
11821 int last_line_misfit
;
11823 struct window
*w
= XWINDOW (window
);
11824 struct frame
*f
= XFRAME (w
->frame
);
11825 struct text_pos scroll_margin_pos
;
11826 struct text_pos pos
;
11827 struct text_pos startp
;
11829 Lisp_Object window_end
;
11830 int this_scroll_margin
;
11834 int amount_to_scroll
= 0;
11835 Lisp_Object aggressive
;
11837 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11840 debug_method_add (w
, "try_scrolling");
11843 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11845 /* Compute scroll margin height in pixels. We scroll when point is
11846 within this distance from the top or bottom of the window. */
11847 if (scroll_margin
> 0)
11849 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11850 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11853 this_scroll_margin
= 0;
11855 /* Force scroll_conservatively to have a reasonable value so it doesn't
11856 cause an overflow while computing how much to scroll. */
11857 if (scroll_conservatively
)
11858 scroll_conservatively
= min (scroll_conservatively
,
11859 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11861 /* Compute how much we should try to scroll maximally to bring point
11863 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11864 scroll_max
= max (scroll_step
,
11865 max (scroll_conservatively
, temp_scroll_step
));
11866 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11867 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11868 /* We're trying to scroll because of aggressive scrolling
11869 but no scroll_step is set. Choose an arbitrary one. Maybe
11870 there should be a variable for this. */
11874 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11876 /* Decide whether we have to scroll down. Start at the window end
11877 and move this_scroll_margin up to find the position of the scroll
11879 window_end
= Fwindow_end (window
, Qt
);
11883 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11884 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11886 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11888 start_display (&it
, w
, scroll_margin_pos
);
11889 if (this_scroll_margin
)
11890 move_it_vertically_backward (&it
, this_scroll_margin
);
11891 if (extra_scroll_margin_lines
)
11892 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11893 scroll_margin_pos
= it
.current
.pos
;
11896 if (PT
>= CHARPOS (scroll_margin_pos
))
11900 /* Point is in the scroll margin at the bottom of the window, or
11901 below. Compute a new window start that makes point visible. */
11903 /* Compute the distance from the scroll margin to PT.
11904 Give up if the distance is greater than scroll_max. */
11905 start_display (&it
, w
, scroll_margin_pos
);
11907 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11908 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11910 /* To make point visible, we have to move the window start
11911 down so that the line the cursor is in is visible, which
11912 means we have to add in the height of the cursor line. */
11913 dy
= line_bottom_y (&it
) - y0
;
11915 if (dy
> scroll_max
)
11916 return SCROLLING_FAILED
;
11918 /* Move the window start down. If scrolling conservatively,
11919 move it just enough down to make point visible. If
11920 scroll_step is set, move it down by scroll_step. */
11921 start_display (&it
, w
, startp
);
11923 if (scroll_conservatively
)
11924 /* Set AMOUNT_TO_SCROLL to at least one line,
11925 and at most scroll_conservatively lines. */
11927 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11928 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11929 else if (scroll_step
|| temp_scroll_step
)
11930 amount_to_scroll
= scroll_max
;
11933 aggressive
= current_buffer
->scroll_up_aggressively
;
11934 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11935 if (NUMBERP (aggressive
))
11937 double float_amount
= XFLOATINT (aggressive
) * height
;
11938 amount_to_scroll
= float_amount
;
11939 if (amount_to_scroll
== 0 && float_amount
> 0)
11940 amount_to_scroll
= 1;
11944 if (amount_to_scroll
<= 0)
11945 return SCROLLING_FAILED
;
11947 /* If moving by amount_to_scroll leaves STARTP unchanged,
11948 move it down one screen line. */
11950 move_it_vertically (&it
, amount_to_scroll
);
11951 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11952 move_it_by_lines (&it
, 1, 1);
11953 startp
= it
.current
.pos
;
11957 /* See if point is inside the scroll margin at the top of the
11959 scroll_margin_pos
= startp
;
11960 if (this_scroll_margin
)
11962 start_display (&it
, w
, startp
);
11963 move_it_vertically (&it
, this_scroll_margin
);
11964 scroll_margin_pos
= it
.current
.pos
;
11967 if (PT
< CHARPOS (scroll_margin_pos
))
11969 /* Point is in the scroll margin at the top of the window or
11970 above what is displayed in the window. */
11973 /* Compute the vertical distance from PT to the scroll
11974 margin position. Give up if distance is greater than
11976 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11977 start_display (&it
, w
, pos
);
11979 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11980 it
.last_visible_y
, -1,
11981 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11982 dy
= it
.current_y
- y0
;
11983 if (dy
> scroll_max
)
11984 return SCROLLING_FAILED
;
11986 /* Compute new window start. */
11987 start_display (&it
, w
, startp
);
11989 if (scroll_conservatively
)
11991 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11992 else if (scroll_step
|| temp_scroll_step
)
11993 amount_to_scroll
= scroll_max
;
11996 aggressive
= current_buffer
->scroll_down_aggressively
;
11997 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11998 if (NUMBERP (aggressive
))
12000 double float_amount
= XFLOATINT (aggressive
) * height
;
12001 amount_to_scroll
= float_amount
;
12002 if (amount_to_scroll
== 0 && float_amount
> 0)
12003 amount_to_scroll
= 1;
12007 if (amount_to_scroll
<= 0)
12008 return SCROLLING_FAILED
;
12010 move_it_vertically_backward (&it
, amount_to_scroll
);
12011 startp
= it
.current
.pos
;
12015 /* Run window scroll functions. */
12016 startp
= run_window_scroll_functions (window
, startp
);
12018 /* Display the window. Give up if new fonts are loaded, or if point
12020 if (!try_window (window
, startp
, 0))
12021 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12022 else if (w
->cursor
.vpos
< 0)
12024 clear_glyph_matrix (w
->desired_matrix
);
12025 rc
= SCROLLING_FAILED
;
12029 /* Maybe forget recorded base line for line number display. */
12030 if (!just_this_one_p
12031 || current_buffer
->clip_changed
12032 || BEG_UNCHANGED
< CHARPOS (startp
))
12033 w
->base_line_number
= Qnil
;
12035 /* If cursor ends up on a partially visible line,
12036 treat that as being off the bottom of the screen. */
12037 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12039 clear_glyph_matrix (w
->desired_matrix
);
12040 ++extra_scroll_margin_lines
;
12043 rc
= SCROLLING_SUCCESS
;
12050 /* Compute a suitable window start for window W if display of W starts
12051 on a continuation line. Value is non-zero if a new window start
12054 The new window start will be computed, based on W's width, starting
12055 from the start of the continued line. It is the start of the
12056 screen line with the minimum distance from the old start W->start. */
12059 compute_window_start_on_continuation_line (w
)
12062 struct text_pos pos
, start_pos
;
12063 int window_start_changed_p
= 0;
12065 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12067 /* If window start is on a continuation line... Window start may be
12068 < BEGV in case there's invisible text at the start of the
12069 buffer (M-x rmail, for example). */
12070 if (CHARPOS (start_pos
) > BEGV
12071 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12074 struct glyph_row
*row
;
12076 /* Handle the case that the window start is out of range. */
12077 if (CHARPOS (start_pos
) < BEGV
)
12078 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12079 else if (CHARPOS (start_pos
) > ZV
)
12080 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12082 /* Find the start of the continued line. This should be fast
12083 because scan_buffer is fast (newline cache). */
12084 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12085 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12086 row
, DEFAULT_FACE_ID
);
12087 reseat_at_previous_visible_line_start (&it
);
12089 /* If the line start is "too far" away from the window start,
12090 say it takes too much time to compute a new window start. */
12091 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12092 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12094 int min_distance
, distance
;
12096 /* Move forward by display lines to find the new window
12097 start. If window width was enlarged, the new start can
12098 be expected to be > the old start. If window width was
12099 decreased, the new window start will be < the old start.
12100 So, we're looking for the display line start with the
12101 minimum distance from the old window start. */
12102 pos
= it
.current
.pos
;
12103 min_distance
= INFINITY
;
12104 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12105 distance
< min_distance
)
12107 min_distance
= distance
;
12108 pos
= it
.current
.pos
;
12109 move_it_by_lines (&it
, 1, 0);
12112 /* Set the window start there. */
12113 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12114 window_start_changed_p
= 1;
12118 return window_start_changed_p
;
12122 /* Try cursor movement in case text has not changed in window WINDOW,
12123 with window start STARTP. Value is
12125 CURSOR_MOVEMENT_SUCCESS if successful
12127 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12129 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12130 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12131 we want to scroll as if scroll-step were set to 1. See the code.
12133 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12134 which case we have to abort this redisplay, and adjust matrices
12139 CURSOR_MOVEMENT_SUCCESS
,
12140 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12141 CURSOR_MOVEMENT_MUST_SCROLL
,
12142 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12146 try_cursor_movement (window
, startp
, scroll_step
)
12147 Lisp_Object window
;
12148 struct text_pos startp
;
12151 struct window
*w
= XWINDOW (window
);
12152 struct frame
*f
= XFRAME (w
->frame
);
12153 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12156 if (inhibit_try_cursor_movement
)
12160 /* Handle case where text has not changed, only point, and it has
12161 not moved off the frame. */
12162 if (/* Point may be in this window. */
12163 PT
>= CHARPOS (startp
)
12164 /* Selective display hasn't changed. */
12165 && !current_buffer
->clip_changed
12166 /* Function force-mode-line-update is used to force a thorough
12167 redisplay. It sets either windows_or_buffers_changed or
12168 update_mode_lines. So don't take a shortcut here for these
12170 && !update_mode_lines
12171 && !windows_or_buffers_changed
12172 && !cursor_type_changed
12173 /* Can't use this case if highlighting a region. When a
12174 region exists, cursor movement has to do more than just
12176 && !(!NILP (Vtransient_mark_mode
)
12177 && !NILP (current_buffer
->mark_active
))
12178 && NILP (w
->region_showing
)
12179 && NILP (Vshow_trailing_whitespace
)
12180 /* Right after splitting windows, last_point may be nil. */
12181 && INTEGERP (w
->last_point
)
12182 /* This code is not used for mini-buffer for the sake of the case
12183 of redisplaying to replace an echo area message; since in
12184 that case the mini-buffer contents per se are usually
12185 unchanged. This code is of no real use in the mini-buffer
12186 since the handling of this_line_start_pos, etc., in redisplay
12187 handles the same cases. */
12188 && !EQ (window
, minibuf_window
)
12189 /* When splitting windows or for new windows, it happens that
12190 redisplay is called with a nil window_end_vpos or one being
12191 larger than the window. This should really be fixed in
12192 window.c. I don't have this on my list, now, so we do
12193 approximately the same as the old redisplay code. --gerd. */
12194 && INTEGERP (w
->window_end_vpos
)
12195 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12196 && (FRAME_WINDOW_P (f
)
12197 || !overlay_arrow_in_current_buffer_p ()))
12199 int this_scroll_margin
, top_scroll_margin
;
12200 struct glyph_row
*row
= NULL
;
12203 debug_method_add (w
, "cursor movement");
12206 /* Scroll if point within this distance from the top or bottom
12207 of the window. This is a pixel value. */
12208 this_scroll_margin
= max (0, scroll_margin
);
12209 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12210 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12212 top_scroll_margin
= this_scroll_margin
;
12213 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12214 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12216 /* Start with the row the cursor was displayed during the last
12217 not paused redisplay. Give up if that row is not valid. */
12218 if (w
->last_cursor
.vpos
< 0
12219 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12220 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12223 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12224 if (row
->mode_line_p
)
12226 if (!row
->enabled_p
)
12227 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12230 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12233 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12235 if (PT
> XFASTINT (w
->last_point
))
12237 /* Point has moved forward. */
12238 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12239 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12241 xassert (row
->enabled_p
);
12245 /* The end position of a row equals the start position
12246 of the next row. If PT is there, we would rather
12247 display it in the next line. */
12248 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12249 && MATRIX_ROW_END_CHARPOS (row
) == PT
12250 && !cursor_row_p (w
, row
))
12253 /* If within the scroll margin, scroll. Note that
12254 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12255 the next line would be drawn, and that
12256 this_scroll_margin can be zero. */
12257 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12258 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12259 /* Line is completely visible last line in window
12260 and PT is to be set in the next line. */
12261 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12262 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12263 && !row
->ends_at_zv_p
12264 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12267 else if (PT
< XFASTINT (w
->last_point
))
12269 /* Cursor has to be moved backward. Note that PT >=
12270 CHARPOS (startp) because of the outer if-statement. */
12271 while (!row
->mode_line_p
12272 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12273 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12274 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12275 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12276 row
> w
->current_matrix
->rows
12277 && (row
-1)->ends_in_newline_from_string_p
))))
12278 && (row
->y
> top_scroll_margin
12279 || CHARPOS (startp
) == BEGV
))
12281 xassert (row
->enabled_p
);
12285 /* Consider the following case: Window starts at BEGV,
12286 there is invisible, intangible text at BEGV, so that
12287 display starts at some point START > BEGV. It can
12288 happen that we are called with PT somewhere between
12289 BEGV and START. Try to handle that case. */
12290 if (row
< w
->current_matrix
->rows
12291 || row
->mode_line_p
)
12293 row
= w
->current_matrix
->rows
;
12294 if (row
->mode_line_p
)
12298 /* Due to newlines in overlay strings, we may have to
12299 skip forward over overlay strings. */
12300 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12301 && MATRIX_ROW_END_CHARPOS (row
) == PT
12302 && !cursor_row_p (w
, row
))
12305 /* If within the scroll margin, scroll. */
12306 if (row
->y
< top_scroll_margin
12307 && CHARPOS (startp
) != BEGV
)
12312 /* Cursor did not move. So don't scroll even if cursor line
12313 is partially visible, as it was so before. */
12314 rc
= CURSOR_MOVEMENT_SUCCESS
;
12317 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12318 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12320 /* if PT is not in the glyph row, give up. */
12321 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12323 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12324 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12325 && make_cursor_line_fully_visible_p
)
12327 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12328 && !row
->ends_at_zv_p
12329 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12330 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12331 else if (row
->height
> window_box_height (w
))
12333 /* If we end up in a partially visible line, let's
12334 make it fully visible, except when it's taller
12335 than the window, in which case we can't do much
12338 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12342 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12343 if (!cursor_row_fully_visible_p (w
, 0, 1))
12344 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12346 rc
= CURSOR_MOVEMENT_SUCCESS
;
12350 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12353 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12354 rc
= CURSOR_MOVEMENT_SUCCESS
;
12363 set_vertical_scroll_bar (w
)
12366 int start
, end
, whole
;
12368 /* Calculate the start and end positions for the current window.
12369 At some point, it would be nice to choose between scrollbars
12370 which reflect the whole buffer size, with special markers
12371 indicating narrowing, and scrollbars which reflect only the
12374 Note that mini-buffers sometimes aren't displaying any text. */
12375 if (!MINI_WINDOW_P (w
)
12376 || (w
== XWINDOW (minibuf_window
)
12377 && NILP (echo_area_buffer
[0])))
12379 struct buffer
*buf
= XBUFFER (w
->buffer
);
12380 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12381 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12382 /* I don't think this is guaranteed to be right. For the
12383 moment, we'll pretend it is. */
12384 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12388 if (whole
< (end
- start
))
12389 whole
= end
- start
;
12392 start
= end
= whole
= 0;
12394 /* Indicate what this scroll bar ought to be displaying now. */
12395 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12396 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12397 (w
, end
- start
, whole
, start
);
12401 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12402 selected_window is redisplayed.
12404 We can return without actually redisplaying the window if
12405 fonts_changed_p is nonzero. In that case, redisplay_internal will
12409 redisplay_window (window
, just_this_one_p
)
12410 Lisp_Object window
;
12411 int just_this_one_p
;
12413 struct window
*w
= XWINDOW (window
);
12414 struct frame
*f
= XFRAME (w
->frame
);
12415 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12416 struct buffer
*old
= current_buffer
;
12417 struct text_pos lpoint
, opoint
, startp
;
12418 int update_mode_line
;
12421 /* Record it now because it's overwritten. */
12422 int current_matrix_up_to_date_p
= 0;
12423 int used_current_matrix_p
= 0;
12424 /* This is less strict than current_matrix_up_to_date_p.
12425 It indictes that the buffer contents and narrowing are unchanged. */
12426 int buffer_unchanged_p
= 0;
12427 int temp_scroll_step
= 0;
12428 int count
= SPECPDL_INDEX ();
12430 int centering_position
= -1;
12431 int last_line_misfit
= 0;
12433 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12436 /* W must be a leaf window here. */
12437 xassert (!NILP (w
->buffer
));
12439 *w
->desired_matrix
->method
= 0;
12442 specbind (Qinhibit_point_motion_hooks
, Qt
);
12444 reconsider_clip_changes (w
, buffer
);
12446 /* Has the mode line to be updated? */
12447 update_mode_line
= (!NILP (w
->update_mode_line
)
12448 || update_mode_lines
12449 || buffer
->clip_changed
12450 || buffer
->prevent_redisplay_optimizations_p
);
12452 if (MINI_WINDOW_P (w
))
12454 if (w
== XWINDOW (echo_area_window
)
12455 && !NILP (echo_area_buffer
[0]))
12457 if (update_mode_line
)
12458 /* We may have to update a tty frame's menu bar or a
12459 tool-bar. Example `M-x C-h C-h C-g'. */
12460 goto finish_menu_bars
;
12462 /* We've already displayed the echo area glyphs in this window. */
12463 goto finish_scroll_bars
;
12465 else if ((w
!= XWINDOW (minibuf_window
)
12466 || minibuf_level
== 0)
12467 /* When buffer is nonempty, redisplay window normally. */
12468 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12469 /* Quail displays non-mini buffers in minibuffer window.
12470 In that case, redisplay the window normally. */
12471 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12473 /* W is a mini-buffer window, but it's not active, so clear
12475 int yb
= window_text_bottom_y (w
);
12476 struct glyph_row
*row
;
12479 for (y
= 0, row
= w
->desired_matrix
->rows
;
12481 y
+= row
->height
, ++row
)
12482 blank_row (w
, row
, y
);
12483 goto finish_scroll_bars
;
12486 clear_glyph_matrix (w
->desired_matrix
);
12489 /* Otherwise set up data on this window; select its buffer and point
12491 /* Really select the buffer, for the sake of buffer-local
12493 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12494 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12496 current_matrix_up_to_date_p
12497 = (!NILP (w
->window_end_valid
)
12498 && !current_buffer
->clip_changed
12499 && !current_buffer
->prevent_redisplay_optimizations_p
12500 && XFASTINT (w
->last_modified
) >= MODIFF
12501 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12504 = (!NILP (w
->window_end_valid
)
12505 && !current_buffer
->clip_changed
12506 && XFASTINT (w
->last_modified
) >= MODIFF
12507 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12509 /* When windows_or_buffers_changed is non-zero, we can't rely on
12510 the window end being valid, so set it to nil there. */
12511 if (windows_or_buffers_changed
)
12513 /* If window starts on a continuation line, maybe adjust the
12514 window start in case the window's width changed. */
12515 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12516 compute_window_start_on_continuation_line (w
);
12518 w
->window_end_valid
= Qnil
;
12521 /* Some sanity checks. */
12522 CHECK_WINDOW_END (w
);
12523 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12525 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12528 /* If %c is in mode line, update it if needed. */
12529 if (!NILP (w
->column_number_displayed
)
12530 /* This alternative quickly identifies a common case
12531 where no change is needed. */
12532 && !(PT
== XFASTINT (w
->last_point
)
12533 && XFASTINT (w
->last_modified
) >= MODIFF
12534 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12535 && (XFASTINT (w
->column_number_displayed
)
12536 != (int) current_column ())) /* iftc */
12537 update_mode_line
= 1;
12539 /* Count number of windows showing the selected buffer. An indirect
12540 buffer counts as its base buffer. */
12541 if (!just_this_one_p
)
12543 struct buffer
*current_base
, *window_base
;
12544 current_base
= current_buffer
;
12545 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12546 if (current_base
->base_buffer
)
12547 current_base
= current_base
->base_buffer
;
12548 if (window_base
->base_buffer
)
12549 window_base
= window_base
->base_buffer
;
12550 if (current_base
== window_base
)
12554 /* Point refers normally to the selected window. For any other
12555 window, set up appropriate value. */
12556 if (!EQ (window
, selected_window
))
12558 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12559 int new_pt_byte
= marker_byte_position (w
->pointm
);
12563 new_pt_byte
= BEGV_BYTE
;
12564 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12566 else if (new_pt
> (ZV
- 1))
12569 new_pt_byte
= ZV_BYTE
;
12570 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12573 /* We don't use SET_PT so that the point-motion hooks don't run. */
12574 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12577 /* If any of the character widths specified in the display table
12578 have changed, invalidate the width run cache. It's true that
12579 this may be a bit late to catch such changes, but the rest of
12580 redisplay goes (non-fatally) haywire when the display table is
12581 changed, so why should we worry about doing any better? */
12582 if (current_buffer
->width_run_cache
)
12584 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12586 if (! disptab_matches_widthtab (disptab
,
12587 XVECTOR (current_buffer
->width_table
)))
12589 invalidate_region_cache (current_buffer
,
12590 current_buffer
->width_run_cache
,
12592 recompute_width_table (current_buffer
, disptab
);
12596 /* If window-start is screwed up, choose a new one. */
12597 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12600 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12602 /* If someone specified a new starting point but did not insist,
12603 check whether it can be used. */
12604 if (!NILP (w
->optional_new_start
)
12605 && CHARPOS (startp
) >= BEGV
12606 && CHARPOS (startp
) <= ZV
)
12608 w
->optional_new_start
= Qnil
;
12609 start_display (&it
, w
, startp
);
12610 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12611 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12612 if (IT_CHARPOS (it
) == PT
)
12613 w
->force_start
= Qt
;
12614 /* IT may overshoot PT if text at PT is invisible. */
12615 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12616 w
->force_start
= Qt
;
12621 /* Handle case where place to start displaying has been specified,
12622 unless the specified location is outside the accessible range. */
12623 if (!NILP (w
->force_start
)
12624 || w
->frozen_window_start_p
)
12626 /* We set this later on if we have to adjust point. */
12630 w
->force_start
= Qnil
;
12632 w
->window_end_valid
= Qnil
;
12634 /* Forget any recorded base line for line number display. */
12635 if (!buffer_unchanged_p
)
12636 w
->base_line_number
= Qnil
;
12638 /* Redisplay the mode line. Select the buffer properly for that.
12639 Also, run the hook window-scroll-functions
12640 because we have scrolled. */
12641 /* Note, we do this after clearing force_start because
12642 if there's an error, it is better to forget about force_start
12643 than to get into an infinite loop calling the hook functions
12644 and having them get more errors. */
12645 if (!update_mode_line
12646 || ! NILP (Vwindow_scroll_functions
))
12648 update_mode_line
= 1;
12649 w
->update_mode_line
= Qt
;
12650 startp
= run_window_scroll_functions (window
, startp
);
12653 w
->last_modified
= make_number (0);
12654 w
->last_overlay_modified
= make_number (0);
12655 if (CHARPOS (startp
) < BEGV
)
12656 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12657 else if (CHARPOS (startp
) > ZV
)
12658 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12660 /* Redisplay, then check if cursor has been set during the
12661 redisplay. Give up if new fonts were loaded. */
12662 val
= try_window (window
, startp
, 1);
12665 w
->force_start
= Qt
;
12666 clear_glyph_matrix (w
->desired_matrix
);
12667 goto need_larger_matrices
;
12669 /* Point was outside the scroll margins. */
12671 new_vpos
= window_box_height (w
) / 2;
12673 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12675 /* If point does not appear, try to move point so it does
12676 appear. The desired matrix has been built above, so we
12677 can use it here. */
12678 new_vpos
= window_box_height (w
) / 2;
12681 if (!cursor_row_fully_visible_p (w
, 0, 0))
12683 /* Point does appear, but on a line partly visible at end of window.
12684 Move it back to a fully-visible line. */
12685 new_vpos
= window_box_height (w
);
12688 /* If we need to move point for either of the above reasons,
12689 now actually do it. */
12692 struct glyph_row
*row
;
12694 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12695 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12698 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12699 MATRIX_ROW_START_BYTEPOS (row
));
12701 if (w
!= XWINDOW (selected_window
))
12702 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12703 else if (current_buffer
== old
)
12704 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12706 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12708 /* If we are highlighting the region, then we just changed
12709 the region, so redisplay to show it. */
12710 if (!NILP (Vtransient_mark_mode
)
12711 && !NILP (current_buffer
->mark_active
))
12713 clear_glyph_matrix (w
->desired_matrix
);
12714 if (!try_window (window
, startp
, 0))
12715 goto need_larger_matrices
;
12720 debug_method_add (w
, "forced window start");
12725 /* Handle case where text has not changed, only point, and it has
12726 not moved off the frame, and we are not retrying after hscroll.
12727 (current_matrix_up_to_date_p is nonzero when retrying.) */
12728 if (current_matrix_up_to_date_p
12729 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12730 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12734 case CURSOR_MOVEMENT_SUCCESS
:
12735 used_current_matrix_p
= 1;
12738 #if 0 /* try_cursor_movement never returns this value. */
12739 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12740 goto need_larger_matrices
;
12743 case CURSOR_MOVEMENT_MUST_SCROLL
:
12744 goto try_to_scroll
;
12750 /* If current starting point was originally the beginning of a line
12751 but no longer is, find a new starting point. */
12752 else if (!NILP (w
->start_at_line_beg
)
12753 && !(CHARPOS (startp
) <= BEGV
12754 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12757 debug_method_add (w
, "recenter 1");
12762 /* Try scrolling with try_window_id. Value is > 0 if update has
12763 been done, it is -1 if we know that the same window start will
12764 not work. It is 0 if unsuccessful for some other reason. */
12765 else if ((tem
= try_window_id (w
)) != 0)
12768 debug_method_add (w
, "try_window_id %d", tem
);
12771 if (fonts_changed_p
)
12772 goto need_larger_matrices
;
12776 /* Otherwise try_window_id has returned -1 which means that we
12777 don't want the alternative below this comment to execute. */
12779 else if (CHARPOS (startp
) >= BEGV
12780 && CHARPOS (startp
) <= ZV
12781 && PT
>= CHARPOS (startp
)
12782 && (CHARPOS (startp
) < ZV
12783 /* Avoid starting at end of buffer. */
12784 || CHARPOS (startp
) == BEGV
12785 || (XFASTINT (w
->last_modified
) >= MODIFF
12786 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12789 debug_method_add (w
, "same window start");
12792 /* Try to redisplay starting at same place as before.
12793 If point has not moved off frame, accept the results. */
12794 if (!current_matrix_up_to_date_p
12795 /* Don't use try_window_reusing_current_matrix in this case
12796 because a window scroll function can have changed the
12798 || !NILP (Vwindow_scroll_functions
)
12799 || MINI_WINDOW_P (w
)
12800 || !(used_current_matrix_p
12801 = try_window_reusing_current_matrix (w
)))
12803 IF_DEBUG (debug_method_add (w
, "1"));
12804 if (try_window (window
, startp
, 1) < 0)
12805 /* -1 means we need to scroll.
12806 0 means we need new matrices, but fonts_changed_p
12807 is set in that case, so we will detect it below. */
12808 goto try_to_scroll
;
12811 if (fonts_changed_p
)
12812 goto need_larger_matrices
;
12814 if (w
->cursor
.vpos
>= 0)
12816 if (!just_this_one_p
12817 || current_buffer
->clip_changed
12818 || BEG_UNCHANGED
< CHARPOS (startp
))
12819 /* Forget any recorded base line for line number display. */
12820 w
->base_line_number
= Qnil
;
12822 if (!cursor_row_fully_visible_p (w
, 1, 0))
12824 clear_glyph_matrix (w
->desired_matrix
);
12825 last_line_misfit
= 1;
12827 /* Drop through and scroll. */
12832 clear_glyph_matrix (w
->desired_matrix
);
12837 w
->last_modified
= make_number (0);
12838 w
->last_overlay_modified
= make_number (0);
12840 /* Redisplay the mode line. Select the buffer properly for that. */
12841 if (!update_mode_line
)
12843 update_mode_line
= 1;
12844 w
->update_mode_line
= Qt
;
12847 /* Try to scroll by specified few lines. */
12848 if ((scroll_conservatively
12850 || temp_scroll_step
12851 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12852 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12853 && !current_buffer
->clip_changed
12854 && CHARPOS (startp
) >= BEGV
12855 && CHARPOS (startp
) <= ZV
)
12857 /* The function returns -1 if new fonts were loaded, 1 if
12858 successful, 0 if not successful. */
12859 int rc
= try_scrolling (window
, just_this_one_p
,
12860 scroll_conservatively
,
12862 temp_scroll_step
, last_line_misfit
);
12865 case SCROLLING_SUCCESS
:
12868 case SCROLLING_NEED_LARGER_MATRICES
:
12869 goto need_larger_matrices
;
12871 case SCROLLING_FAILED
:
12879 /* Finally, just choose place to start which centers point */
12882 if (centering_position
< 0)
12883 centering_position
= window_box_height (w
) / 2;
12886 debug_method_add (w
, "recenter");
12889 /* w->vscroll = 0; */
12891 /* Forget any previously recorded base line for line number display. */
12892 if (!buffer_unchanged_p
)
12893 w
->base_line_number
= Qnil
;
12895 /* Move backward half the height of the window. */
12896 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12897 it
.current_y
= it
.last_visible_y
;
12898 move_it_vertically_backward (&it
, centering_position
);
12899 xassert (IT_CHARPOS (it
) >= BEGV
);
12901 /* The function move_it_vertically_backward may move over more
12902 than the specified y-distance. If it->w is small, e.g. a
12903 mini-buffer window, we may end up in front of the window's
12904 display area. Start displaying at the start of the line
12905 containing PT in this case. */
12906 if (it
.current_y
<= 0)
12908 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12909 move_it_vertically_backward (&it
, 0);
12911 /* I think this assert is bogus if buffer contains
12912 invisible text or images. KFS. */
12913 xassert (IT_CHARPOS (it
) <= PT
);
12918 it
.current_x
= it
.hpos
= 0;
12920 /* Set startp here explicitly in case that helps avoid an infinite loop
12921 in case the window-scroll-functions functions get errors. */
12922 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12924 /* Run scroll hooks. */
12925 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12927 /* Redisplay the window. */
12928 if (!current_matrix_up_to_date_p
12929 || windows_or_buffers_changed
12930 || cursor_type_changed
12931 /* Don't use try_window_reusing_current_matrix in this case
12932 because it can have changed the buffer. */
12933 || !NILP (Vwindow_scroll_functions
)
12934 || !just_this_one_p
12935 || MINI_WINDOW_P (w
)
12936 || !(used_current_matrix_p
12937 = try_window_reusing_current_matrix (w
)))
12938 try_window (window
, startp
, 0);
12940 /* If new fonts have been loaded (due to fontsets), give up. We
12941 have to start a new redisplay since we need to re-adjust glyph
12943 if (fonts_changed_p
)
12944 goto need_larger_matrices
;
12946 /* If cursor did not appear assume that the middle of the window is
12947 in the first line of the window. Do it again with the next line.
12948 (Imagine a window of height 100, displaying two lines of height
12949 60. Moving back 50 from it->last_visible_y will end in the first
12951 if (w
->cursor
.vpos
< 0)
12953 if (!NILP (w
->window_end_valid
)
12954 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12956 clear_glyph_matrix (w
->desired_matrix
);
12957 move_it_by_lines (&it
, 1, 0);
12958 try_window (window
, it
.current
.pos
, 0);
12960 else if (PT
< IT_CHARPOS (it
))
12962 clear_glyph_matrix (w
->desired_matrix
);
12963 move_it_by_lines (&it
, -1, 0);
12964 try_window (window
, it
.current
.pos
, 0);
12968 /* Not much we can do about it. */
12972 /* Consider the following case: Window starts at BEGV, there is
12973 invisible, intangible text at BEGV, so that display starts at
12974 some point START > BEGV. It can happen that we are called with
12975 PT somewhere between BEGV and START. Try to handle that case. */
12976 if (w
->cursor
.vpos
< 0)
12978 struct glyph_row
*row
= w
->current_matrix
->rows
;
12979 if (row
->mode_line_p
)
12981 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12984 if (!cursor_row_fully_visible_p (w
, 0, 0))
12986 /* If vscroll is enabled, disable it and try again. */
12990 clear_glyph_matrix (w
->desired_matrix
);
12994 /* If centering point failed to make the whole line visible,
12995 put point at the top instead. That has to make the whole line
12996 visible, if it can be done. */
12997 if (centering_position
== 0)
13000 clear_glyph_matrix (w
->desired_matrix
);
13001 centering_position
= 0;
13007 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13008 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13009 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13012 /* Display the mode line, if we must. */
13013 if ((update_mode_line
13014 /* If window not full width, must redo its mode line
13015 if (a) the window to its side is being redone and
13016 (b) we do a frame-based redisplay. This is a consequence
13017 of how inverted lines are drawn in frame-based redisplay. */
13018 || (!just_this_one_p
13019 && !FRAME_WINDOW_P (f
)
13020 && !WINDOW_FULL_WIDTH_P (w
))
13021 /* Line number to display. */
13022 || INTEGERP (w
->base_line_pos
)
13023 /* Column number is displayed and different from the one displayed. */
13024 || (!NILP (w
->column_number_displayed
)
13025 && (XFASTINT (w
->column_number_displayed
)
13026 != (int) current_column ()))) /* iftc */
13027 /* This means that the window has a mode line. */
13028 && (WINDOW_WANTS_MODELINE_P (w
)
13029 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13031 display_mode_lines (w
);
13033 /* If mode line height has changed, arrange for a thorough
13034 immediate redisplay using the correct mode line height. */
13035 if (WINDOW_WANTS_MODELINE_P (w
)
13036 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13038 fonts_changed_p
= 1;
13039 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13040 = DESIRED_MODE_LINE_HEIGHT (w
);
13043 /* If top line height has changed, arrange for a thorough
13044 immediate redisplay using the correct mode line height. */
13045 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13046 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13048 fonts_changed_p
= 1;
13049 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13050 = DESIRED_HEADER_LINE_HEIGHT (w
);
13053 if (fonts_changed_p
)
13054 goto need_larger_matrices
;
13057 if (!line_number_displayed
13058 && !BUFFERP (w
->base_line_pos
))
13060 w
->base_line_pos
= Qnil
;
13061 w
->base_line_number
= Qnil
;
13066 /* When we reach a frame's selected window, redo the frame's menu bar. */
13067 if (update_mode_line
13068 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13070 int redisplay_menu_p
= 0;
13071 int redisplay_tool_bar_p
= 0;
13073 if (FRAME_WINDOW_P (f
))
13075 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13076 || defined (USE_GTK)
13077 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13079 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13083 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13085 if (redisplay_menu_p
)
13086 display_menu_bar (w
);
13088 #ifdef HAVE_WINDOW_SYSTEM
13089 if (FRAME_WINDOW_P (f
))
13092 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13094 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13095 && (FRAME_TOOL_BAR_LINES (f
) > 0
13096 || auto_resize_tool_bars_p
);
13099 if (redisplay_tool_bar_p
)
13100 redisplay_tool_bar (f
);
13105 #ifdef HAVE_WINDOW_SYSTEM
13106 if (FRAME_WINDOW_P (f
)
13107 && update_window_fringes (w
, (just_this_one_p
13108 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13109 || w
->pseudo_window_p
)))
13113 if (draw_window_fringes (w
, 1))
13114 x_draw_vertical_border (w
);
13118 #endif /* HAVE_WINDOW_SYSTEM */
13120 /* We go to this label, with fonts_changed_p nonzero,
13121 if it is necessary to try again using larger glyph matrices.
13122 We have to redeem the scroll bar even in this case,
13123 because the loop in redisplay_internal expects that. */
13124 need_larger_matrices
:
13126 finish_scroll_bars
:
13128 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13130 /* Set the thumb's position and size. */
13131 set_vertical_scroll_bar (w
);
13133 /* Note that we actually used the scroll bar attached to this
13134 window, so it shouldn't be deleted at the end of redisplay. */
13135 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13136 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13139 /* Restore current_buffer and value of point in it. */
13140 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13141 set_buffer_internal_1 (old
);
13142 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13144 unbind_to (count
, Qnil
);
13148 /* Build the complete desired matrix of WINDOW with a window start
13149 buffer position POS.
13151 Value is 1 if successful. It is zero if fonts were loaded during
13152 redisplay which makes re-adjusting glyph matrices necessary, and -1
13153 if point would appear in the scroll margins.
13154 (We check that only if CHECK_MARGINS is nonzero. */
13157 try_window (window
, pos
, check_margins
)
13158 Lisp_Object window
;
13159 struct text_pos pos
;
13162 struct window
*w
= XWINDOW (window
);
13164 struct glyph_row
*last_text_row
= NULL
;
13166 /* Make POS the new window start. */
13167 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13169 /* Mark cursor position as unknown. No overlay arrow seen. */
13170 w
->cursor
.vpos
= -1;
13171 overlay_arrow_seen
= 0;
13173 /* Initialize iterator and info to start at POS. */
13174 start_display (&it
, w
, pos
);
13176 /* Display all lines of W. */
13177 while (it
.current_y
< it
.last_visible_y
)
13179 if (display_line (&it
))
13180 last_text_row
= it
.glyph_row
- 1;
13181 if (fonts_changed_p
)
13185 /* Don't let the cursor end in the scroll margins. */
13187 && !MINI_WINDOW_P (w
))
13189 int this_scroll_margin
;
13191 this_scroll_margin
= max (0, scroll_margin
);
13192 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13193 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13195 if ((w
->cursor
.y
< this_scroll_margin
13196 && CHARPOS (pos
) > BEGV
13197 && IT_CHARPOS (it
) < ZV
)
13198 /* rms: considering make_cursor_line_fully_visible_p here
13199 seems to give wrong results. We don't want to recenter
13200 when the last line is partly visible, we want to allow
13201 that case to be handled in the usual way. */
13202 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13204 w
->cursor
.vpos
= -1;
13205 clear_glyph_matrix (w
->desired_matrix
);
13210 /* If bottom moved off end of frame, change mode line percentage. */
13211 if (XFASTINT (w
->window_end_pos
) <= 0
13212 && Z
!= IT_CHARPOS (it
))
13213 w
->update_mode_line
= Qt
;
13215 /* Set window_end_pos to the offset of the last character displayed
13216 on the window from the end of current_buffer. Set
13217 window_end_vpos to its row number. */
13220 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13221 w
->window_end_bytepos
13222 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13224 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13226 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13227 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13228 ->displays_text_p
);
13232 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13233 w
->window_end_pos
= make_number (Z
- ZV
);
13234 w
->window_end_vpos
= make_number (0);
13237 /* But that is not valid info until redisplay finishes. */
13238 w
->window_end_valid
= Qnil
;
13244 /************************************************************************
13245 Window redisplay reusing current matrix when buffer has not changed
13246 ************************************************************************/
13248 /* Try redisplay of window W showing an unchanged buffer with a
13249 different window start than the last time it was displayed by
13250 reusing its current matrix. Value is non-zero if successful.
13251 W->start is the new window start. */
13254 try_window_reusing_current_matrix (w
)
13257 struct frame
*f
= XFRAME (w
->frame
);
13258 struct glyph_row
*row
, *bottom_row
;
13261 struct text_pos start
, new_start
;
13262 int nrows_scrolled
, i
;
13263 struct glyph_row
*last_text_row
;
13264 struct glyph_row
*last_reused_text_row
;
13265 struct glyph_row
*start_row
;
13266 int start_vpos
, min_y
, max_y
;
13269 if (inhibit_try_window_reusing
)
13273 if (/* This function doesn't handle terminal frames. */
13274 !FRAME_WINDOW_P (f
)
13275 /* Don't try to reuse the display if windows have been split
13277 || windows_or_buffers_changed
13278 || cursor_type_changed
)
13281 /* Can't do this if region may have changed. */
13282 if ((!NILP (Vtransient_mark_mode
)
13283 && !NILP (current_buffer
->mark_active
))
13284 || !NILP (w
->region_showing
)
13285 || !NILP (Vshow_trailing_whitespace
))
13288 /* If top-line visibility has changed, give up. */
13289 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13290 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13293 /* Give up if old or new display is scrolled vertically. We could
13294 make this function handle this, but right now it doesn't. */
13295 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13296 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13299 /* The variable new_start now holds the new window start. The old
13300 start `start' can be determined from the current matrix. */
13301 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13302 start
= start_row
->start
.pos
;
13303 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13305 /* Clear the desired matrix for the display below. */
13306 clear_glyph_matrix (w
->desired_matrix
);
13308 if (CHARPOS (new_start
) <= CHARPOS (start
))
13312 /* Don't use this method if the display starts with an ellipsis
13313 displayed for invisible text. It's not easy to handle that case
13314 below, and it's certainly not worth the effort since this is
13315 not a frequent case. */
13316 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13319 IF_DEBUG (debug_method_add (w
, "twu1"));
13321 /* Display up to a row that can be reused. The variable
13322 last_text_row is set to the last row displayed that displays
13323 text. Note that it.vpos == 0 if or if not there is a
13324 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13325 start_display (&it
, w
, new_start
);
13326 first_row_y
= it
.current_y
;
13327 w
->cursor
.vpos
= -1;
13328 last_text_row
= last_reused_text_row
= NULL
;
13330 while (it
.current_y
< it
.last_visible_y
13331 && !fonts_changed_p
)
13333 /* If we have reached into the characters in the START row,
13334 that means the line boundaries have changed. So we
13335 can't start copying with the row START. Maybe it will
13336 work to start copying with the following row. */
13337 while (IT_CHARPOS (it
) > CHARPOS (start
))
13339 /* Advance to the next row as the "start". */
13341 start
= start_row
->start
.pos
;
13342 /* If there are no more rows to try, or just one, give up. */
13343 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13344 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13345 || CHARPOS (start
) == ZV
)
13347 clear_glyph_matrix (w
->desired_matrix
);
13351 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13353 /* If we have reached alignment,
13354 we can copy the rest of the rows. */
13355 if (IT_CHARPOS (it
) == CHARPOS (start
))
13358 if (display_line (&it
))
13359 last_text_row
= it
.glyph_row
- 1;
13362 /* A value of current_y < last_visible_y means that we stopped
13363 at the previous window start, which in turn means that we
13364 have at least one reusable row. */
13365 if (it
.current_y
< it
.last_visible_y
)
13367 /* IT.vpos always starts from 0; it counts text lines. */
13368 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13370 /* Find PT if not already found in the lines displayed. */
13371 if (w
->cursor
.vpos
< 0)
13373 int dy
= it
.current_y
- start_row
->y
;
13375 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13376 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13378 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13379 dy
, nrows_scrolled
);
13382 clear_glyph_matrix (w
->desired_matrix
);
13387 /* Scroll the display. Do it before the current matrix is
13388 changed. The problem here is that update has not yet
13389 run, i.e. part of the current matrix is not up to date.
13390 scroll_run_hook will clear the cursor, and use the
13391 current matrix to get the height of the row the cursor is
13393 run
.current_y
= start_row
->y
;
13394 run
.desired_y
= it
.current_y
;
13395 run
.height
= it
.last_visible_y
- it
.current_y
;
13397 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13400 FRAME_RIF (f
)->update_window_begin_hook (w
);
13401 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13402 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13403 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13407 /* Shift current matrix down by nrows_scrolled lines. */
13408 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13409 rotate_matrix (w
->current_matrix
,
13411 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13414 /* Disable lines that must be updated. */
13415 for (i
= 0; i
< it
.vpos
; ++i
)
13416 (start_row
+ i
)->enabled_p
= 0;
13418 /* Re-compute Y positions. */
13419 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13420 max_y
= it
.last_visible_y
;
13421 for (row
= start_row
+ nrows_scrolled
;
13425 row
->y
= it
.current_y
;
13426 row
->visible_height
= row
->height
;
13428 if (row
->y
< min_y
)
13429 row
->visible_height
-= min_y
- row
->y
;
13430 if (row
->y
+ row
->height
> max_y
)
13431 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13432 row
->redraw_fringe_bitmaps_p
= 1;
13434 it
.current_y
+= row
->height
;
13436 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13437 last_reused_text_row
= row
;
13438 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13442 /* Disable lines in the current matrix which are now
13443 below the window. */
13444 for (++row
; row
< bottom_row
; ++row
)
13445 row
->enabled_p
= row
->mode_line_p
= 0;
13448 /* Update window_end_pos etc.; last_reused_text_row is the last
13449 reused row from the current matrix containing text, if any.
13450 The value of last_text_row is the last displayed line
13451 containing text. */
13452 if (last_reused_text_row
)
13454 w
->window_end_bytepos
13455 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13457 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13459 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13460 w
->current_matrix
));
13462 else if (last_text_row
)
13464 w
->window_end_bytepos
13465 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13467 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13469 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13473 /* This window must be completely empty. */
13474 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13475 w
->window_end_pos
= make_number (Z
- ZV
);
13476 w
->window_end_vpos
= make_number (0);
13478 w
->window_end_valid
= Qnil
;
13480 /* Update hint: don't try scrolling again in update_window. */
13481 w
->desired_matrix
->no_scrolling_p
= 1;
13484 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13488 else if (CHARPOS (new_start
) > CHARPOS (start
))
13490 struct glyph_row
*pt_row
, *row
;
13491 struct glyph_row
*first_reusable_row
;
13492 struct glyph_row
*first_row_to_display
;
13494 int yb
= window_text_bottom_y (w
);
13496 /* Find the row starting at new_start, if there is one. Don't
13497 reuse a partially visible line at the end. */
13498 first_reusable_row
= start_row
;
13499 while (first_reusable_row
->enabled_p
13500 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13501 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13502 < CHARPOS (new_start
)))
13503 ++first_reusable_row
;
13505 /* Give up if there is no row to reuse. */
13506 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13507 || !first_reusable_row
->enabled_p
13508 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13509 != CHARPOS (new_start
)))
13512 /* We can reuse fully visible rows beginning with
13513 first_reusable_row to the end of the window. Set
13514 first_row_to_display to the first row that cannot be reused.
13515 Set pt_row to the row containing point, if there is any. */
13517 for (first_row_to_display
= first_reusable_row
;
13518 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13519 ++first_row_to_display
)
13521 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13522 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13523 pt_row
= first_row_to_display
;
13526 /* Start displaying at the start of first_row_to_display. */
13527 xassert (first_row_to_display
->y
< yb
);
13528 init_to_row_start (&it
, w
, first_row_to_display
);
13530 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13532 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13534 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13535 + WINDOW_HEADER_LINE_HEIGHT (w
));
13537 /* Display lines beginning with first_row_to_display in the
13538 desired matrix. Set last_text_row to the last row displayed
13539 that displays text. */
13540 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13541 if (pt_row
== NULL
)
13542 w
->cursor
.vpos
= -1;
13543 last_text_row
= NULL
;
13544 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13545 if (display_line (&it
))
13546 last_text_row
= it
.glyph_row
- 1;
13548 /* Give up If point isn't in a row displayed or reused. */
13549 if (w
->cursor
.vpos
< 0)
13551 clear_glyph_matrix (w
->desired_matrix
);
13555 /* If point is in a reused row, adjust y and vpos of the cursor
13559 w
->cursor
.vpos
-= nrows_scrolled
;
13560 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13563 /* Scroll the display. */
13564 run
.current_y
= first_reusable_row
->y
;
13565 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13566 run
.height
= it
.last_visible_y
- run
.current_y
;
13567 dy
= run
.current_y
- run
.desired_y
;
13572 FRAME_RIF (f
)->update_window_begin_hook (w
);
13573 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13574 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13575 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13579 /* Adjust Y positions of reused rows. */
13580 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13581 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13582 max_y
= it
.last_visible_y
;
13583 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13586 row
->visible_height
= row
->height
;
13587 if (row
->y
< min_y
)
13588 row
->visible_height
-= min_y
- row
->y
;
13589 if (row
->y
+ row
->height
> max_y
)
13590 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13591 row
->redraw_fringe_bitmaps_p
= 1;
13594 /* Scroll the current matrix. */
13595 xassert (nrows_scrolled
> 0);
13596 rotate_matrix (w
->current_matrix
,
13598 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13601 /* Disable rows not reused. */
13602 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13603 row
->enabled_p
= 0;
13605 /* Point may have moved to a different line, so we cannot assume that
13606 the previous cursor position is valid; locate the correct row. */
13609 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13610 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13614 w
->cursor
.y
= row
->y
;
13616 if (row
< bottom_row
)
13618 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13619 while (glyph
->charpos
< PT
)
13622 w
->cursor
.x
+= glyph
->pixel_width
;
13628 /* Adjust window end. A null value of last_text_row means that
13629 the window end is in reused rows which in turn means that
13630 only its vpos can have changed. */
13633 w
->window_end_bytepos
13634 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13636 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13638 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13643 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13646 w
->window_end_valid
= Qnil
;
13647 w
->desired_matrix
->no_scrolling_p
= 1;
13650 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13660 /************************************************************************
13661 Window redisplay reusing current matrix when buffer has changed
13662 ************************************************************************/
13664 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13665 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13667 static struct glyph_row
*
13668 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13669 struct glyph_row
*));
13672 /* Return the last row in MATRIX displaying text. If row START is
13673 non-null, start searching with that row. IT gives the dimensions
13674 of the display. Value is null if matrix is empty; otherwise it is
13675 a pointer to the row found. */
13677 static struct glyph_row
*
13678 find_last_row_displaying_text (matrix
, it
, start
)
13679 struct glyph_matrix
*matrix
;
13681 struct glyph_row
*start
;
13683 struct glyph_row
*row
, *row_found
;
13685 /* Set row_found to the last row in IT->w's current matrix
13686 displaying text. The loop looks funny but think of partially
13689 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13690 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13692 xassert (row
->enabled_p
);
13694 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13703 /* Return the last row in the current matrix of W that is not affected
13704 by changes at the start of current_buffer that occurred since W's
13705 current matrix was built. Value is null if no such row exists.
13707 BEG_UNCHANGED us the number of characters unchanged at the start of
13708 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13709 first changed character in current_buffer. Characters at positions <
13710 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13711 when the current matrix was built. */
13713 static struct glyph_row
*
13714 find_last_unchanged_at_beg_row (w
)
13717 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13718 struct glyph_row
*row
;
13719 struct glyph_row
*row_found
= NULL
;
13720 int yb
= window_text_bottom_y (w
);
13722 /* Find the last row displaying unchanged text. */
13723 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13724 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13725 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13727 if (/* If row ends before first_changed_pos, it is unchanged,
13728 except in some case. */
13729 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13730 /* When row ends in ZV and we write at ZV it is not
13732 && !row
->ends_at_zv_p
13733 /* When first_changed_pos is the end of a continued line,
13734 row is not unchanged because it may be no longer
13736 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13737 && (row
->continued_p
13738 || row
->exact_window_width_line_p
)))
13741 /* Stop if last visible row. */
13742 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13752 /* Find the first glyph row in the current matrix of W that is not
13753 affected by changes at the end of current_buffer since the
13754 time W's current matrix was built.
13756 Return in *DELTA the number of chars by which buffer positions in
13757 unchanged text at the end of current_buffer must be adjusted.
13759 Return in *DELTA_BYTES the corresponding number of bytes.
13761 Value is null if no such row exists, i.e. all rows are affected by
13764 static struct glyph_row
*
13765 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13767 int *delta
, *delta_bytes
;
13769 struct glyph_row
*row
;
13770 struct glyph_row
*row_found
= NULL
;
13772 *delta
= *delta_bytes
= 0;
13774 /* Display must not have been paused, otherwise the current matrix
13775 is not up to date. */
13776 if (NILP (w
->window_end_valid
))
13779 /* A value of window_end_pos >= END_UNCHANGED means that the window
13780 end is in the range of changed text. If so, there is no
13781 unchanged row at the end of W's current matrix. */
13782 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13785 /* Set row to the last row in W's current matrix displaying text. */
13786 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13788 /* If matrix is entirely empty, no unchanged row exists. */
13789 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13791 /* The value of row is the last glyph row in the matrix having a
13792 meaningful buffer position in it. The end position of row
13793 corresponds to window_end_pos. This allows us to translate
13794 buffer positions in the current matrix to current buffer
13795 positions for characters not in changed text. */
13796 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13797 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13798 int last_unchanged_pos
, last_unchanged_pos_old
;
13799 struct glyph_row
*first_text_row
13800 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13802 *delta
= Z
- Z_old
;
13803 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13805 /* Set last_unchanged_pos to the buffer position of the last
13806 character in the buffer that has not been changed. Z is the
13807 index + 1 of the last character in current_buffer, i.e. by
13808 subtracting END_UNCHANGED we get the index of the last
13809 unchanged character, and we have to add BEG to get its buffer
13811 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13812 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13814 /* Search backward from ROW for a row displaying a line that
13815 starts at a minimum position >= last_unchanged_pos_old. */
13816 for (; row
> first_text_row
; --row
)
13818 /* This used to abort, but it can happen.
13819 It is ok to just stop the search instead here. KFS. */
13820 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13823 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13828 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13835 /* Make sure that glyph rows in the current matrix of window W
13836 reference the same glyph memory as corresponding rows in the
13837 frame's frame matrix. This function is called after scrolling W's
13838 current matrix on a terminal frame in try_window_id and
13839 try_window_reusing_current_matrix. */
13842 sync_frame_with_window_matrix_rows (w
)
13845 struct frame
*f
= XFRAME (w
->frame
);
13846 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13848 /* Preconditions: W must be a leaf window and full-width. Its frame
13849 must have a frame matrix. */
13850 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13851 xassert (WINDOW_FULL_WIDTH_P (w
));
13852 xassert (!FRAME_WINDOW_P (f
));
13854 /* If W is a full-width window, glyph pointers in W's current matrix
13855 have, by definition, to be the same as glyph pointers in the
13856 corresponding frame matrix. Note that frame matrices have no
13857 marginal areas (see build_frame_matrix). */
13858 window_row
= w
->current_matrix
->rows
;
13859 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13860 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13861 while (window_row
< window_row_end
)
13863 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13864 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13866 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13867 frame_row
->glyphs
[TEXT_AREA
] = start
;
13868 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13869 frame_row
->glyphs
[LAST_AREA
] = end
;
13871 /* Disable frame rows whose corresponding window rows have
13872 been disabled in try_window_id. */
13873 if (!window_row
->enabled_p
)
13874 frame_row
->enabled_p
= 0;
13876 ++window_row
, ++frame_row
;
13881 /* Find the glyph row in window W containing CHARPOS. Consider all
13882 rows between START and END (not inclusive). END null means search
13883 all rows to the end of the display area of W. Value is the row
13884 containing CHARPOS or null. */
13887 row_containing_pos (w
, charpos
, start
, end
, dy
)
13890 struct glyph_row
*start
, *end
;
13893 struct glyph_row
*row
= start
;
13896 /* If we happen to start on a header-line, skip that. */
13897 if (row
->mode_line_p
)
13900 if ((end
&& row
>= end
) || !row
->enabled_p
)
13903 last_y
= window_text_bottom_y (w
) - dy
;
13907 /* Give up if we have gone too far. */
13908 if (end
&& row
>= end
)
13910 /* This formerly returned if they were equal.
13911 I think that both quantities are of a "last plus one" type;
13912 if so, when they are equal, the row is within the screen. -- rms. */
13913 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13916 /* If it is in this row, return this row. */
13917 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13918 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13919 /* The end position of a row equals the start
13920 position of the next row. If CHARPOS is there, we
13921 would rather display it in the next line, except
13922 when this line ends in ZV. */
13923 && !row
->ends_at_zv_p
13924 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13925 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13932 /* Try to redisplay window W by reusing its existing display. W's
13933 current matrix must be up to date when this function is called,
13934 i.e. window_end_valid must not be nil.
13938 1 if display has been updated
13939 0 if otherwise unsuccessful
13940 -1 if redisplay with same window start is known not to succeed
13942 The following steps are performed:
13944 1. Find the last row in the current matrix of W that is not
13945 affected by changes at the start of current_buffer. If no such row
13948 2. Find the first row in W's current matrix that is not affected by
13949 changes at the end of current_buffer. Maybe there is no such row.
13951 3. Display lines beginning with the row + 1 found in step 1 to the
13952 row found in step 2 or, if step 2 didn't find a row, to the end of
13955 4. If cursor is not known to appear on the window, give up.
13957 5. If display stopped at the row found in step 2, scroll the
13958 display and current matrix as needed.
13960 6. Maybe display some lines at the end of W, if we must. This can
13961 happen under various circumstances, like a partially visible line
13962 becoming fully visible, or because newly displayed lines are displayed
13963 in smaller font sizes.
13965 7. Update W's window end information. */
13971 struct frame
*f
= XFRAME (w
->frame
);
13972 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13973 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13974 struct glyph_row
*last_unchanged_at_beg_row
;
13975 struct glyph_row
*first_unchanged_at_end_row
;
13976 struct glyph_row
*row
;
13977 struct glyph_row
*bottom_row
;
13980 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13981 struct text_pos start_pos
;
13983 int first_unchanged_at_end_vpos
= 0;
13984 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13985 struct text_pos start
;
13986 int first_changed_charpos
, last_changed_charpos
;
13989 if (inhibit_try_window_id
)
13993 /* This is handy for debugging. */
13995 #define GIVE_UP(X) \
13997 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14001 #define GIVE_UP(X) return 0
14004 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14006 /* Don't use this for mini-windows because these can show
14007 messages and mini-buffers, and we don't handle that here. */
14008 if (MINI_WINDOW_P (w
))
14011 /* This flag is used to prevent redisplay optimizations. */
14012 if (windows_or_buffers_changed
|| cursor_type_changed
)
14015 /* Verify that narrowing has not changed.
14016 Also verify that we were not told to prevent redisplay optimizations.
14017 It would be nice to further
14018 reduce the number of cases where this prevents try_window_id. */
14019 if (current_buffer
->clip_changed
14020 || current_buffer
->prevent_redisplay_optimizations_p
)
14023 /* Window must either use window-based redisplay or be full width. */
14024 if (!FRAME_WINDOW_P (f
)
14025 && (!FRAME_LINE_INS_DEL_OK (f
)
14026 || !WINDOW_FULL_WIDTH_P (w
)))
14029 /* Give up if point is not known NOT to appear in W. */
14030 if (PT
< CHARPOS (start
))
14033 /* Another way to prevent redisplay optimizations. */
14034 if (XFASTINT (w
->last_modified
) == 0)
14037 /* Verify that window is not hscrolled. */
14038 if (XFASTINT (w
->hscroll
) != 0)
14041 /* Verify that display wasn't paused. */
14042 if (NILP (w
->window_end_valid
))
14045 /* Can't use this if highlighting a region because a cursor movement
14046 will do more than just set the cursor. */
14047 if (!NILP (Vtransient_mark_mode
)
14048 && !NILP (current_buffer
->mark_active
))
14051 /* Likewise if highlighting trailing whitespace. */
14052 if (!NILP (Vshow_trailing_whitespace
))
14055 /* Likewise if showing a region. */
14056 if (!NILP (w
->region_showing
))
14059 /* Can use this if overlay arrow position and or string have changed. */
14060 if (overlay_arrows_changed_p ())
14064 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14065 only if buffer has really changed. The reason is that the gap is
14066 initially at Z for freshly visited files. The code below would
14067 set end_unchanged to 0 in that case. */
14068 if (MODIFF
> SAVE_MODIFF
14069 /* This seems to happen sometimes after saving a buffer. */
14070 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14072 if (GPT
- BEG
< BEG_UNCHANGED
)
14073 BEG_UNCHANGED
= GPT
- BEG
;
14074 if (Z
- GPT
< END_UNCHANGED
)
14075 END_UNCHANGED
= Z
- GPT
;
14078 /* The position of the first and last character that has been changed. */
14079 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14080 last_changed_charpos
= Z
- END_UNCHANGED
;
14082 /* If window starts after a line end, and the last change is in
14083 front of that newline, then changes don't affect the display.
14084 This case happens with stealth-fontification. Note that although
14085 the display is unchanged, glyph positions in the matrix have to
14086 be adjusted, of course. */
14087 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14088 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14089 && ((last_changed_charpos
< CHARPOS (start
)
14090 && CHARPOS (start
) == BEGV
)
14091 || (last_changed_charpos
< CHARPOS (start
) - 1
14092 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14094 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14095 struct glyph_row
*r0
;
14097 /* Compute how many chars/bytes have been added to or removed
14098 from the buffer. */
14099 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14100 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14102 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14104 /* Give up if PT is not in the window. Note that it already has
14105 been checked at the start of try_window_id that PT is not in
14106 front of the window start. */
14107 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14110 /* If window start is unchanged, we can reuse the whole matrix
14111 as is, after adjusting glyph positions. No need to compute
14112 the window end again, since its offset from Z hasn't changed. */
14113 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14114 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14115 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14116 /* PT must not be in a partially visible line. */
14117 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14118 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14120 /* Adjust positions in the glyph matrix. */
14121 if (delta
|| delta_bytes
)
14123 struct glyph_row
*r1
14124 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14125 increment_matrix_positions (w
->current_matrix
,
14126 MATRIX_ROW_VPOS (r0
, current_matrix
),
14127 MATRIX_ROW_VPOS (r1
, current_matrix
),
14128 delta
, delta_bytes
);
14131 /* Set the cursor. */
14132 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14134 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14141 /* Handle the case that changes are all below what is displayed in
14142 the window, and that PT is in the window. This shortcut cannot
14143 be taken if ZV is visible in the window, and text has been added
14144 there that is visible in the window. */
14145 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14146 /* ZV is not visible in the window, or there are no
14147 changes at ZV, actually. */
14148 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14149 || first_changed_charpos
== last_changed_charpos
))
14151 struct glyph_row
*r0
;
14153 /* Give up if PT is not in the window. Note that it already has
14154 been checked at the start of try_window_id that PT is not in
14155 front of the window start. */
14156 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14159 /* If window start is unchanged, we can reuse the whole matrix
14160 as is, without changing glyph positions since no text has
14161 been added/removed in front of the window end. */
14162 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14163 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14164 /* PT must not be in a partially visible line. */
14165 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14166 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14168 /* We have to compute the window end anew since text
14169 can have been added/removed after it. */
14171 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14172 w
->window_end_bytepos
14173 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14175 /* Set the cursor. */
14176 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14178 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14185 /* Give up if window start is in the changed area.
14187 The condition used to read
14189 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14191 but why that was tested escapes me at the moment. */
14192 if (CHARPOS (start
) >= first_changed_charpos
14193 && CHARPOS (start
) <= last_changed_charpos
)
14196 /* Check that window start agrees with the start of the first glyph
14197 row in its current matrix. Check this after we know the window
14198 start is not in changed text, otherwise positions would not be
14200 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14201 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14204 /* Give up if the window ends in strings. Overlay strings
14205 at the end are difficult to handle, so don't try. */
14206 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14207 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14210 /* Compute the position at which we have to start displaying new
14211 lines. Some of the lines at the top of the window might be
14212 reusable because they are not displaying changed text. Find the
14213 last row in W's current matrix not affected by changes at the
14214 start of current_buffer. Value is null if changes start in the
14215 first line of window. */
14216 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14217 if (last_unchanged_at_beg_row
)
14219 /* Avoid starting to display in the moddle of a character, a TAB
14220 for instance. This is easier than to set up the iterator
14221 exactly, and it's not a frequent case, so the additional
14222 effort wouldn't really pay off. */
14223 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14224 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14225 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14226 --last_unchanged_at_beg_row
;
14228 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14231 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14233 start_pos
= it
.current
.pos
;
14235 /* Start displaying new lines in the desired matrix at the same
14236 vpos we would use in the current matrix, i.e. below
14237 last_unchanged_at_beg_row. */
14238 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14240 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14241 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14243 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14247 /* There are no reusable lines at the start of the window.
14248 Start displaying in the first text line. */
14249 start_display (&it
, w
, start
);
14250 it
.vpos
= it
.first_vpos
;
14251 start_pos
= it
.current
.pos
;
14254 /* Find the first row that is not affected by changes at the end of
14255 the buffer. Value will be null if there is no unchanged row, in
14256 which case we must redisplay to the end of the window. delta
14257 will be set to the value by which buffer positions beginning with
14258 first_unchanged_at_end_row have to be adjusted due to text
14260 first_unchanged_at_end_row
14261 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14262 IF_DEBUG (debug_delta
= delta
);
14263 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14265 /* Set stop_pos to the buffer position up to which we will have to
14266 display new lines. If first_unchanged_at_end_row != NULL, this
14267 is the buffer position of the start of the line displayed in that
14268 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14269 that we don't stop at a buffer position. */
14271 if (first_unchanged_at_end_row
)
14273 xassert (last_unchanged_at_beg_row
== NULL
14274 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14276 /* If this is a continuation line, move forward to the next one
14277 that isn't. Changes in lines above affect this line.
14278 Caution: this may move first_unchanged_at_end_row to a row
14279 not displaying text. */
14280 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14281 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14282 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14283 < it
.last_visible_y
))
14284 ++first_unchanged_at_end_row
;
14286 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14287 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14288 >= it
.last_visible_y
))
14289 first_unchanged_at_end_row
= NULL
;
14292 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14294 first_unchanged_at_end_vpos
14295 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14296 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14299 else if (last_unchanged_at_beg_row
== NULL
)
14305 /* Either there is no unchanged row at the end, or the one we have
14306 now displays text. This is a necessary condition for the window
14307 end pos calculation at the end of this function. */
14308 xassert (first_unchanged_at_end_row
== NULL
14309 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14311 debug_last_unchanged_at_beg_vpos
14312 = (last_unchanged_at_beg_row
14313 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14315 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14317 #endif /* GLYPH_DEBUG != 0 */
14320 /* Display new lines. Set last_text_row to the last new line
14321 displayed which has text on it, i.e. might end up as being the
14322 line where the window_end_vpos is. */
14323 w
->cursor
.vpos
= -1;
14324 last_text_row
= NULL
;
14325 overlay_arrow_seen
= 0;
14326 while (it
.current_y
< it
.last_visible_y
14327 && !fonts_changed_p
14328 && (first_unchanged_at_end_row
== NULL
14329 || IT_CHARPOS (it
) < stop_pos
))
14331 if (display_line (&it
))
14332 last_text_row
= it
.glyph_row
- 1;
14335 if (fonts_changed_p
)
14339 /* Compute differences in buffer positions, y-positions etc. for
14340 lines reused at the bottom of the window. Compute what we can
14342 if (first_unchanged_at_end_row
14343 /* No lines reused because we displayed everything up to the
14344 bottom of the window. */
14345 && it
.current_y
< it
.last_visible_y
)
14348 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14350 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14351 run
.current_y
= first_unchanged_at_end_row
->y
;
14352 run
.desired_y
= run
.current_y
+ dy
;
14353 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14357 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14358 first_unchanged_at_end_row
= NULL
;
14360 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14363 /* Find the cursor if not already found. We have to decide whether
14364 PT will appear on this window (it sometimes doesn't, but this is
14365 not a very frequent case.) This decision has to be made before
14366 the current matrix is altered. A value of cursor.vpos < 0 means
14367 that PT is either in one of the lines beginning at
14368 first_unchanged_at_end_row or below the window. Don't care for
14369 lines that might be displayed later at the window end; as
14370 mentioned, this is not a frequent case. */
14371 if (w
->cursor
.vpos
< 0)
14373 /* Cursor in unchanged rows at the top? */
14374 if (PT
< CHARPOS (start_pos
)
14375 && last_unchanged_at_beg_row
)
14377 row
= row_containing_pos (w
, PT
,
14378 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14379 last_unchanged_at_beg_row
+ 1, 0);
14381 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14384 /* Start from first_unchanged_at_end_row looking for PT. */
14385 else if (first_unchanged_at_end_row
)
14387 row
= row_containing_pos (w
, PT
- delta
,
14388 first_unchanged_at_end_row
, NULL
, 0);
14390 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14391 delta_bytes
, dy
, dvpos
);
14394 /* Give up if cursor was not found. */
14395 if (w
->cursor
.vpos
< 0)
14397 clear_glyph_matrix (w
->desired_matrix
);
14402 /* Don't let the cursor end in the scroll margins. */
14404 int this_scroll_margin
, cursor_height
;
14406 this_scroll_margin
= max (0, scroll_margin
);
14407 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14408 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14409 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14411 if ((w
->cursor
.y
< this_scroll_margin
14412 && CHARPOS (start
) > BEGV
)
14413 /* Old redisplay didn't take scroll margin into account at the bottom,
14414 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14415 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14416 ? cursor_height
+ this_scroll_margin
14417 : 1)) > it
.last_visible_y
)
14419 w
->cursor
.vpos
= -1;
14420 clear_glyph_matrix (w
->desired_matrix
);
14425 /* Scroll the display. Do it before changing the current matrix so
14426 that xterm.c doesn't get confused about where the cursor glyph is
14428 if (dy
&& run
.height
)
14432 if (FRAME_WINDOW_P (f
))
14434 FRAME_RIF (f
)->update_window_begin_hook (w
);
14435 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14436 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14437 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14441 /* Terminal frame. In this case, dvpos gives the number of
14442 lines to scroll by; dvpos < 0 means scroll up. */
14443 int first_unchanged_at_end_vpos
14444 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14445 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14446 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14447 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14448 + window_internal_height (w
));
14450 /* Perform the operation on the screen. */
14453 /* Scroll last_unchanged_at_beg_row to the end of the
14454 window down dvpos lines. */
14455 set_terminal_window (f
, end
);
14457 /* On dumb terminals delete dvpos lines at the end
14458 before inserting dvpos empty lines. */
14459 if (!FRAME_SCROLL_REGION_OK (f
))
14460 ins_del_lines (f
, end
- dvpos
, -dvpos
);
14462 /* Insert dvpos empty lines in front of
14463 last_unchanged_at_beg_row. */
14464 ins_del_lines (f
, from
, dvpos
);
14466 else if (dvpos
< 0)
14468 /* Scroll up last_unchanged_at_beg_vpos to the end of
14469 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14470 set_terminal_window (f
, end
);
14472 /* Delete dvpos lines in front of
14473 last_unchanged_at_beg_vpos. ins_del_lines will set
14474 the cursor to the given vpos and emit |dvpos| delete
14476 ins_del_lines (f
, from
+ dvpos
, dvpos
);
14478 /* On a dumb terminal insert dvpos empty lines at the
14480 if (!FRAME_SCROLL_REGION_OK (f
))
14481 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
14484 set_terminal_window (f
, 0);
14490 /* Shift reused rows of the current matrix to the right position.
14491 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14493 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14494 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14497 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14498 bottom_vpos
, dvpos
);
14499 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14502 else if (dvpos
> 0)
14504 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14505 bottom_vpos
, dvpos
);
14506 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14507 first_unchanged_at_end_vpos
+ dvpos
, 0);
14510 /* For frame-based redisplay, make sure that current frame and window
14511 matrix are in sync with respect to glyph memory. */
14512 if (!FRAME_WINDOW_P (f
))
14513 sync_frame_with_window_matrix_rows (w
);
14515 /* Adjust buffer positions in reused rows. */
14517 increment_matrix_positions (current_matrix
,
14518 first_unchanged_at_end_vpos
+ dvpos
,
14519 bottom_vpos
, delta
, delta_bytes
);
14521 /* Adjust Y positions. */
14523 shift_glyph_matrix (w
, current_matrix
,
14524 first_unchanged_at_end_vpos
+ dvpos
,
14527 if (first_unchanged_at_end_row
)
14529 first_unchanged_at_end_row
+= dvpos
;
14530 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14531 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14532 first_unchanged_at_end_row
= NULL
;
14535 /* If scrolling up, there may be some lines to display at the end of
14537 last_text_row_at_end
= NULL
;
14540 /* Scrolling up can leave for example a partially visible line
14541 at the end of the window to be redisplayed. */
14542 /* Set last_row to the glyph row in the current matrix where the
14543 window end line is found. It has been moved up or down in
14544 the matrix by dvpos. */
14545 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14546 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14548 /* If last_row is the window end line, it should display text. */
14549 xassert (last_row
->displays_text_p
);
14551 /* If window end line was partially visible before, begin
14552 displaying at that line. Otherwise begin displaying with the
14553 line following it. */
14554 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14556 init_to_row_start (&it
, w
, last_row
);
14557 it
.vpos
= last_vpos
;
14558 it
.current_y
= last_row
->y
;
14562 init_to_row_end (&it
, w
, last_row
);
14563 it
.vpos
= 1 + last_vpos
;
14564 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14568 /* We may start in a continuation line. If so, we have to
14569 get the right continuation_lines_width and current_x. */
14570 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14571 it
.hpos
= it
.current_x
= 0;
14573 /* Display the rest of the lines at the window end. */
14574 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14575 while (it
.current_y
< it
.last_visible_y
14576 && !fonts_changed_p
)
14578 /* Is it always sure that the display agrees with lines in
14579 the current matrix? I don't think so, so we mark rows
14580 displayed invalid in the current matrix by setting their
14581 enabled_p flag to zero. */
14582 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14583 if (display_line (&it
))
14584 last_text_row_at_end
= it
.glyph_row
- 1;
14588 /* Update window_end_pos and window_end_vpos. */
14589 if (first_unchanged_at_end_row
14590 && !last_text_row_at_end
)
14592 /* Window end line if one of the preserved rows from the current
14593 matrix. Set row to the last row displaying text in current
14594 matrix starting at first_unchanged_at_end_row, after
14596 xassert (first_unchanged_at_end_row
->displays_text_p
);
14597 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14598 first_unchanged_at_end_row
);
14599 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14601 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14602 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14604 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14605 xassert (w
->window_end_bytepos
>= 0);
14606 IF_DEBUG (debug_method_add (w
, "A"));
14608 else if (last_text_row_at_end
)
14611 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14612 w
->window_end_bytepos
14613 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14615 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14616 xassert (w
->window_end_bytepos
>= 0);
14617 IF_DEBUG (debug_method_add (w
, "B"));
14619 else if (last_text_row
)
14621 /* We have displayed either to the end of the window or at the
14622 end of the window, i.e. the last row with text is to be found
14623 in the desired matrix. */
14625 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14626 w
->window_end_bytepos
14627 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14629 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14630 xassert (w
->window_end_bytepos
>= 0);
14632 else if (first_unchanged_at_end_row
== NULL
14633 && last_text_row
== NULL
14634 && last_text_row_at_end
== NULL
)
14636 /* Displayed to end of window, but no line containing text was
14637 displayed. Lines were deleted at the end of the window. */
14638 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14639 int vpos
= XFASTINT (w
->window_end_vpos
);
14640 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14641 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14644 row
== NULL
&& vpos
>= first_vpos
;
14645 --vpos
, --current_row
, --desired_row
)
14647 if (desired_row
->enabled_p
)
14649 if (desired_row
->displays_text_p
)
14652 else if (current_row
->displays_text_p
)
14656 xassert (row
!= NULL
);
14657 w
->window_end_vpos
= make_number (vpos
+ 1);
14658 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14659 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14660 xassert (w
->window_end_bytepos
>= 0);
14661 IF_DEBUG (debug_method_add (w
, "C"));
14666 #if 0 /* This leads to problems, for instance when the cursor is
14667 at ZV, and the cursor line displays no text. */
14668 /* Disable rows below what's displayed in the window. This makes
14669 debugging easier. */
14670 enable_glyph_matrix_rows (current_matrix
,
14671 XFASTINT (w
->window_end_vpos
) + 1,
14675 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14676 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14678 /* Record that display has not been completed. */
14679 w
->window_end_valid
= Qnil
;
14680 w
->desired_matrix
->no_scrolling_p
= 1;
14688 /***********************************************************************
14689 More debugging support
14690 ***********************************************************************/
14694 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14695 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14696 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14699 /* Dump the contents of glyph matrix MATRIX on stderr.
14701 GLYPHS 0 means don't show glyph contents.
14702 GLYPHS 1 means show glyphs in short form
14703 GLYPHS > 1 means show glyphs in long form. */
14706 dump_glyph_matrix (matrix
, glyphs
)
14707 struct glyph_matrix
*matrix
;
14711 for (i
= 0; i
< matrix
->nrows
; ++i
)
14712 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14716 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14717 the glyph row and area where the glyph comes from. */
14720 dump_glyph (row
, glyph
, area
)
14721 struct glyph_row
*row
;
14722 struct glyph
*glyph
;
14725 if (glyph
->type
== CHAR_GLYPH
)
14728 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14729 glyph
- row
->glyphs
[TEXT_AREA
],
14732 (BUFFERP (glyph
->object
)
14734 : (STRINGP (glyph
->object
)
14737 glyph
->pixel_width
,
14739 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14743 glyph
->left_box_line_p
,
14744 glyph
->right_box_line_p
);
14746 else if (glyph
->type
== STRETCH_GLYPH
)
14749 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14750 glyph
- row
->glyphs
[TEXT_AREA
],
14753 (BUFFERP (glyph
->object
)
14755 : (STRINGP (glyph
->object
)
14758 glyph
->pixel_width
,
14762 glyph
->left_box_line_p
,
14763 glyph
->right_box_line_p
);
14765 else if (glyph
->type
== IMAGE_GLYPH
)
14768 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14769 glyph
- row
->glyphs
[TEXT_AREA
],
14772 (BUFFERP (glyph
->object
)
14774 : (STRINGP (glyph
->object
)
14777 glyph
->pixel_width
,
14781 glyph
->left_box_line_p
,
14782 glyph
->right_box_line_p
);
14787 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14788 GLYPHS 0 means don't show glyph contents.
14789 GLYPHS 1 means show glyphs in short form
14790 GLYPHS > 1 means show glyphs in long form. */
14793 dump_glyph_row (row
, vpos
, glyphs
)
14794 struct glyph_row
*row
;
14799 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14800 fprintf (stderr
, "======================================================================\n");
14802 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14803 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14805 MATRIX_ROW_START_CHARPOS (row
),
14806 MATRIX_ROW_END_CHARPOS (row
),
14807 row
->used
[TEXT_AREA
],
14808 row
->contains_overlapping_glyphs_p
,
14810 row
->truncated_on_left_p
,
14811 row
->truncated_on_right_p
,
14813 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14814 row
->displays_text_p
,
14817 row
->ends_in_middle_of_char_p
,
14818 row
->starts_in_middle_of_char_p
,
14824 row
->visible_height
,
14827 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14828 row
->end
.overlay_string_index
,
14829 row
->continuation_lines_width
);
14830 fprintf (stderr
, "%9d %5d\n",
14831 CHARPOS (row
->start
.string_pos
),
14832 CHARPOS (row
->end
.string_pos
));
14833 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14834 row
->end
.dpvec_index
);
14841 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14843 struct glyph
*glyph
= row
->glyphs
[area
];
14844 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14846 /* Glyph for a line end in text. */
14847 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14850 if (glyph
< glyph_end
)
14851 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14853 for (; glyph
< glyph_end
; ++glyph
)
14854 dump_glyph (row
, glyph
, area
);
14857 else if (glyphs
== 1)
14861 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14863 char *s
= (char *) alloca (row
->used
[area
] + 1);
14866 for (i
= 0; i
< row
->used
[area
]; ++i
)
14868 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14869 if (glyph
->type
== CHAR_GLYPH
14870 && glyph
->u
.ch
< 0x80
14871 && glyph
->u
.ch
>= ' ')
14872 s
[i
] = glyph
->u
.ch
;
14878 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14884 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14885 Sdump_glyph_matrix
, 0, 1, "p",
14886 doc
: /* Dump the current matrix of the selected window to stderr.
14887 Shows contents of glyph row structures. With non-nil
14888 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14889 glyphs in short form, otherwise show glyphs in long form. */)
14891 Lisp_Object glyphs
;
14893 struct window
*w
= XWINDOW (selected_window
);
14894 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14896 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14897 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14898 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14899 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14900 fprintf (stderr
, "=============================================\n");
14901 dump_glyph_matrix (w
->current_matrix
,
14902 NILP (glyphs
) ? 0 : XINT (glyphs
));
14907 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14908 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14911 struct frame
*f
= XFRAME (selected_frame
);
14912 dump_glyph_matrix (f
->current_matrix
, 1);
14917 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14918 doc
: /* Dump glyph row ROW to stderr.
14919 GLYPH 0 means don't dump glyphs.
14920 GLYPH 1 means dump glyphs in short form.
14921 GLYPH > 1 or omitted means dump glyphs in long form. */)
14923 Lisp_Object row
, glyphs
;
14925 struct glyph_matrix
*matrix
;
14928 CHECK_NUMBER (row
);
14929 matrix
= XWINDOW (selected_window
)->current_matrix
;
14931 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14932 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14934 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14939 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14940 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14941 GLYPH 0 means don't dump glyphs.
14942 GLYPH 1 means dump glyphs in short form.
14943 GLYPH > 1 or omitted means dump glyphs in long form. */)
14945 Lisp_Object row
, glyphs
;
14947 struct frame
*sf
= SELECTED_FRAME ();
14948 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14951 CHECK_NUMBER (row
);
14953 if (vpos
>= 0 && vpos
< m
->nrows
)
14954 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14955 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14960 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14961 doc
: /* Toggle tracing of redisplay.
14962 With ARG, turn tracing on if and only if ARG is positive. */)
14967 trace_redisplay_p
= !trace_redisplay_p
;
14970 arg
= Fprefix_numeric_value (arg
);
14971 trace_redisplay_p
= XINT (arg
) > 0;
14978 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14979 doc
: /* Like `format', but print result to stderr.
14980 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14985 Lisp_Object s
= Fformat (nargs
, args
);
14986 fprintf (stderr
, "%s", SDATA (s
));
14990 #endif /* GLYPH_DEBUG */
14994 /***********************************************************************
14995 Building Desired Matrix Rows
14996 ***********************************************************************/
14998 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14999 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15001 static struct glyph_row
*
15002 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15004 Lisp_Object overlay_arrow_string
;
15006 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15007 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15008 struct buffer
*old
= current_buffer
;
15009 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15010 int arrow_len
= SCHARS (overlay_arrow_string
);
15011 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15012 const unsigned char *p
;
15015 int n_glyphs_before
;
15017 set_buffer_temp (buffer
);
15018 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15019 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15020 SET_TEXT_POS (it
.position
, 0, 0);
15022 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15024 while (p
< arrow_end
)
15026 Lisp_Object face
, ilisp
;
15028 /* Get the next character. */
15030 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15032 it
.c
= *p
, it
.len
= 1;
15035 /* Get its face. */
15036 ilisp
= make_number (p
- arrow_string
);
15037 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15038 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15040 /* Compute its width, get its glyphs. */
15041 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15042 SET_TEXT_POS (it
.position
, -1, -1);
15043 PRODUCE_GLYPHS (&it
);
15045 /* If this character doesn't fit any more in the line, we have
15046 to remove some glyphs. */
15047 if (it
.current_x
> it
.last_visible_x
)
15049 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15054 set_buffer_temp (old
);
15055 return it
.glyph_row
;
15059 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15060 glyphs are only inserted for terminal frames since we can't really
15061 win with truncation glyphs when partially visible glyphs are
15062 involved. Which glyphs to insert is determined by
15063 produce_special_glyphs. */
15066 insert_left_trunc_glyphs (it
)
15069 struct it truncate_it
;
15070 struct glyph
*from
, *end
, *to
, *toend
;
15072 xassert (!FRAME_WINDOW_P (it
->f
));
15074 /* Get the truncation glyphs. */
15076 truncate_it
.current_x
= 0;
15077 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15078 truncate_it
.glyph_row
= &scratch_glyph_row
;
15079 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15080 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15081 truncate_it
.object
= make_number (0);
15082 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15084 /* Overwrite glyphs from IT with truncation glyphs. */
15085 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15086 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15087 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15088 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15093 /* There may be padding glyphs left over. Overwrite them too. */
15094 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15096 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15102 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15106 /* Compute the pixel height and width of IT->glyph_row.
15108 Most of the time, ascent and height of a display line will be equal
15109 to the max_ascent and max_height values of the display iterator
15110 structure. This is not the case if
15112 1. We hit ZV without displaying anything. In this case, max_ascent
15113 and max_height will be zero.
15115 2. We have some glyphs that don't contribute to the line height.
15116 (The glyph row flag contributes_to_line_height_p is for future
15117 pixmap extensions).
15119 The first case is easily covered by using default values because in
15120 these cases, the line height does not really matter, except that it
15121 must not be zero. */
15124 compute_line_metrics (it
)
15127 struct glyph_row
*row
= it
->glyph_row
;
15130 if (FRAME_WINDOW_P (it
->f
))
15132 int i
, min_y
, max_y
;
15134 /* The line may consist of one space only, that was added to
15135 place the cursor on it. If so, the row's height hasn't been
15137 if (row
->height
== 0)
15139 if (it
->max_ascent
+ it
->max_descent
== 0)
15140 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15141 row
->ascent
= it
->max_ascent
;
15142 row
->height
= it
->max_ascent
+ it
->max_descent
;
15143 row
->phys_ascent
= it
->max_phys_ascent
;
15144 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15145 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15148 /* Compute the width of this line. */
15149 row
->pixel_width
= row
->x
;
15150 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15151 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15153 xassert (row
->pixel_width
>= 0);
15154 xassert (row
->ascent
>= 0 && row
->height
> 0);
15156 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15157 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15159 /* If first line's physical ascent is larger than its logical
15160 ascent, use the physical ascent, and make the row taller.
15161 This makes accented characters fully visible. */
15162 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15163 && row
->phys_ascent
> row
->ascent
)
15165 row
->height
+= row
->phys_ascent
- row
->ascent
;
15166 row
->ascent
= row
->phys_ascent
;
15169 /* Compute how much of the line is visible. */
15170 row
->visible_height
= row
->height
;
15172 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15173 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15175 if (row
->y
< min_y
)
15176 row
->visible_height
-= min_y
- row
->y
;
15177 if (row
->y
+ row
->height
> max_y
)
15178 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15182 row
->pixel_width
= row
->used
[TEXT_AREA
];
15183 if (row
->continued_p
)
15184 row
->pixel_width
-= it
->continuation_pixel_width
;
15185 else if (row
->truncated_on_right_p
)
15186 row
->pixel_width
-= it
->truncation_pixel_width
;
15187 row
->ascent
= row
->phys_ascent
= 0;
15188 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15189 row
->extra_line_spacing
= 0;
15192 /* Compute a hash code for this row. */
15194 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15195 for (i
= 0; i
< row
->used
[area
]; ++i
)
15196 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15197 + row
->glyphs
[area
][i
].u
.val
15198 + row
->glyphs
[area
][i
].face_id
15199 + row
->glyphs
[area
][i
].padding_p
15200 + (row
->glyphs
[area
][i
].type
<< 2));
15202 it
->max_ascent
= it
->max_descent
= 0;
15203 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15207 /* Append one space to the glyph row of iterator IT if doing a
15208 window-based redisplay. The space has the same face as
15209 IT->face_id. Value is non-zero if a space was added.
15211 This function is called to make sure that there is always one glyph
15212 at the end of a glyph row that the cursor can be set on under
15213 window-systems. (If there weren't such a glyph we would not know
15214 how wide and tall a box cursor should be displayed).
15216 At the same time this space let's a nicely handle clearing to the
15217 end of the line if the row ends in italic text. */
15220 append_space_for_newline (it
, default_face_p
)
15222 int default_face_p
;
15224 if (FRAME_WINDOW_P (it
->f
))
15226 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15228 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15229 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15231 /* Save some values that must not be changed.
15232 Must save IT->c and IT->len because otherwise
15233 ITERATOR_AT_END_P wouldn't work anymore after
15234 append_space_for_newline has been called. */
15235 enum display_element_type saved_what
= it
->what
;
15236 int saved_c
= it
->c
, saved_len
= it
->len
;
15237 int saved_x
= it
->current_x
;
15238 int saved_face_id
= it
->face_id
;
15239 struct text_pos saved_pos
;
15240 Lisp_Object saved_object
;
15243 saved_object
= it
->object
;
15244 saved_pos
= it
->position
;
15246 it
->what
= IT_CHARACTER
;
15247 bzero (&it
->position
, sizeof it
->position
);
15248 it
->object
= make_number (0);
15252 if (default_face_p
)
15253 it
->face_id
= DEFAULT_FACE_ID
;
15254 else if (it
->face_before_selective_p
)
15255 it
->face_id
= it
->saved_face_id
;
15256 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15257 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15259 PRODUCE_GLYPHS (it
);
15261 it
->override_ascent
= -1;
15262 it
->constrain_row_ascent_descent_p
= 0;
15263 it
->current_x
= saved_x
;
15264 it
->object
= saved_object
;
15265 it
->position
= saved_pos
;
15266 it
->what
= saved_what
;
15267 it
->face_id
= saved_face_id
;
15268 it
->len
= saved_len
;
15278 /* Extend the face of the last glyph in the text area of IT->glyph_row
15279 to the end of the display line. Called from display_line.
15280 If the glyph row is empty, add a space glyph to it so that we
15281 know the face to draw. Set the glyph row flag fill_line_p. */
15284 extend_face_to_end_of_line (it
)
15288 struct frame
*f
= it
->f
;
15290 /* If line is already filled, do nothing. */
15291 if (it
->current_x
>= it
->last_visible_x
)
15294 /* Face extension extends the background and box of IT->face_id
15295 to the end of the line. If the background equals the background
15296 of the frame, we don't have to do anything. */
15297 if (it
->face_before_selective_p
)
15298 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15300 face
= FACE_FROM_ID (f
, it
->face_id
);
15302 if (FRAME_WINDOW_P (f
)
15303 && face
->box
== FACE_NO_BOX
15304 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15308 /* Set the glyph row flag indicating that the face of the last glyph
15309 in the text area has to be drawn to the end of the text area. */
15310 it
->glyph_row
->fill_line_p
= 1;
15312 /* If current character of IT is not ASCII, make sure we have the
15313 ASCII face. This will be automatically undone the next time
15314 get_next_display_element returns a multibyte character. Note
15315 that the character will always be single byte in unibyte text. */
15316 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15318 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15321 if (FRAME_WINDOW_P (f
))
15323 /* If the row is empty, add a space with the current face of IT,
15324 so that we know which face to draw. */
15325 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15327 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15328 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15329 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15334 /* Save some values that must not be changed. */
15335 int saved_x
= it
->current_x
;
15336 struct text_pos saved_pos
;
15337 Lisp_Object saved_object
;
15338 enum display_element_type saved_what
= it
->what
;
15339 int saved_face_id
= it
->face_id
;
15341 saved_object
= it
->object
;
15342 saved_pos
= it
->position
;
15344 it
->what
= IT_CHARACTER
;
15345 bzero (&it
->position
, sizeof it
->position
);
15346 it
->object
= make_number (0);
15349 it
->face_id
= face
->id
;
15351 PRODUCE_GLYPHS (it
);
15353 while (it
->current_x
<= it
->last_visible_x
)
15354 PRODUCE_GLYPHS (it
);
15356 /* Don't count these blanks really. It would let us insert a left
15357 truncation glyph below and make us set the cursor on them, maybe. */
15358 it
->current_x
= saved_x
;
15359 it
->object
= saved_object
;
15360 it
->position
= saved_pos
;
15361 it
->what
= saved_what
;
15362 it
->face_id
= saved_face_id
;
15367 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15368 trailing whitespace. */
15371 trailing_whitespace_p (charpos
)
15374 int bytepos
= CHAR_TO_BYTE (charpos
);
15377 while (bytepos
< ZV_BYTE
15378 && (c
= FETCH_CHAR (bytepos
),
15379 c
== ' ' || c
== '\t'))
15382 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15384 if (bytepos
!= PT_BYTE
)
15391 /* Highlight trailing whitespace, if any, in ROW. */
15394 highlight_trailing_whitespace (f
, row
)
15396 struct glyph_row
*row
;
15398 int used
= row
->used
[TEXT_AREA
];
15402 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15403 struct glyph
*glyph
= start
+ used
- 1;
15405 /* Skip over glyphs inserted to display the cursor at the
15406 end of a line, for extending the face of the last glyph
15407 to the end of the line on terminals, and for truncation
15408 and continuation glyphs. */
15409 while (glyph
>= start
15410 && glyph
->type
== CHAR_GLYPH
15411 && INTEGERP (glyph
->object
))
15414 /* If last glyph is a space or stretch, and it's trailing
15415 whitespace, set the face of all trailing whitespace glyphs in
15416 IT->glyph_row to `trailing-whitespace'. */
15418 && BUFFERP (glyph
->object
)
15419 && (glyph
->type
== STRETCH_GLYPH
15420 || (glyph
->type
== CHAR_GLYPH
15421 && glyph
->u
.ch
== ' '))
15422 && trailing_whitespace_p (glyph
->charpos
))
15424 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15428 while (glyph
>= start
15429 && BUFFERP (glyph
->object
)
15430 && (glyph
->type
== STRETCH_GLYPH
15431 || (glyph
->type
== CHAR_GLYPH
15432 && glyph
->u
.ch
== ' ')))
15433 (glyph
--)->face_id
= face_id
;
15439 /* Value is non-zero if glyph row ROW in window W should be
15440 used to hold the cursor. */
15443 cursor_row_p (w
, row
)
15445 struct glyph_row
*row
;
15447 int cursor_row_p
= 1;
15449 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15451 /* If the row ends with a newline from a string, we don't want
15452 the cursor there, but we still want it at the start of the
15453 string if the string starts in this row.
15454 If the row is continued it doesn't end in a newline. */
15455 if (CHARPOS (row
->end
.string_pos
) >= 0)
15456 cursor_row_p
= (row
->continued_p
15457 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15458 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15460 /* If the row ends in middle of a real character,
15461 and the line is continued, we want the cursor here.
15462 That's because MATRIX_ROW_END_CHARPOS would equal
15463 PT if PT is before the character. */
15464 if (!row
->ends_in_ellipsis_p
)
15465 cursor_row_p
= row
->continued_p
;
15467 /* If the row ends in an ellipsis, then
15468 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15469 We want that position to be displayed after the ellipsis. */
15472 /* If the row ends at ZV, display the cursor at the end of that
15473 row instead of at the start of the row below. */
15474 else if (row
->ends_at_zv_p
)
15480 return cursor_row_p
;
15484 /* Construct the glyph row IT->glyph_row in the desired matrix of
15485 IT->w from text at the current position of IT. See dispextern.h
15486 for an overview of struct it. Value is non-zero if
15487 IT->glyph_row displays text, as opposed to a line displaying ZV
15494 struct glyph_row
*row
= it
->glyph_row
;
15495 Lisp_Object overlay_arrow_string
;
15497 /* We always start displaying at hpos zero even if hscrolled. */
15498 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15500 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15501 >= it
->w
->desired_matrix
->nrows
)
15503 it
->w
->nrows_scale_factor
++;
15504 fonts_changed_p
= 1;
15508 /* Is IT->w showing the region? */
15509 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15511 /* Clear the result glyph row and enable it. */
15512 prepare_desired_row (row
);
15514 row
->y
= it
->current_y
;
15515 row
->start
= it
->start
;
15516 row
->continuation_lines_width
= it
->continuation_lines_width
;
15517 row
->displays_text_p
= 1;
15518 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15519 it
->starts_in_middle_of_char_p
= 0;
15521 /* Arrange the overlays nicely for our purposes. Usually, we call
15522 display_line on only one line at a time, in which case this
15523 can't really hurt too much, or we call it on lines which appear
15524 one after another in the buffer, in which case all calls to
15525 recenter_overlay_lists but the first will be pretty cheap. */
15526 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15528 /* Move over display elements that are not visible because we are
15529 hscrolled. This may stop at an x-position < IT->first_visible_x
15530 if the first glyph is partially visible or if we hit a line end. */
15531 if (it
->current_x
< it
->first_visible_x
)
15533 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15534 MOVE_TO_POS
| MOVE_TO_X
);
15537 /* Get the initial row height. This is either the height of the
15538 text hscrolled, if there is any, or zero. */
15539 row
->ascent
= it
->max_ascent
;
15540 row
->height
= it
->max_ascent
+ it
->max_descent
;
15541 row
->phys_ascent
= it
->max_phys_ascent
;
15542 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15543 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15545 /* Loop generating characters. The loop is left with IT on the next
15546 character to display. */
15549 int n_glyphs_before
, hpos_before
, x_before
;
15551 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15553 /* Retrieve the next thing to display. Value is zero if end of
15555 if (!get_next_display_element (it
))
15557 /* Maybe add a space at the end of this line that is used to
15558 display the cursor there under X. Set the charpos of the
15559 first glyph of blank lines not corresponding to any text
15561 #ifdef HAVE_WINDOW_SYSTEM
15562 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15563 row
->exact_window_width_line_p
= 1;
15565 #endif /* HAVE_WINDOW_SYSTEM */
15566 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15567 || row
->used
[TEXT_AREA
] == 0)
15569 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15570 row
->displays_text_p
= 0;
15572 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15573 && (!MINI_WINDOW_P (it
->w
)
15574 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15575 row
->indicate_empty_line_p
= 1;
15578 it
->continuation_lines_width
= 0;
15579 row
->ends_at_zv_p
= 1;
15583 /* Now, get the metrics of what we want to display. This also
15584 generates glyphs in `row' (which is IT->glyph_row). */
15585 n_glyphs_before
= row
->used
[TEXT_AREA
];
15588 /* Remember the line height so far in case the next element doesn't
15589 fit on the line. */
15590 if (!it
->truncate_lines_p
)
15592 ascent
= it
->max_ascent
;
15593 descent
= it
->max_descent
;
15594 phys_ascent
= it
->max_phys_ascent
;
15595 phys_descent
= it
->max_phys_descent
;
15598 PRODUCE_GLYPHS (it
);
15600 /* If this display element was in marginal areas, continue with
15602 if (it
->area
!= TEXT_AREA
)
15604 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15605 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15606 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15607 row
->phys_height
= max (row
->phys_height
,
15608 it
->max_phys_ascent
+ it
->max_phys_descent
);
15609 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15610 it
->max_extra_line_spacing
);
15611 set_iterator_to_next (it
, 1);
15615 /* Does the display element fit on the line? If we truncate
15616 lines, we should draw past the right edge of the window. If
15617 we don't truncate, we want to stop so that we can display the
15618 continuation glyph before the right margin. If lines are
15619 continued, there are two possible strategies for characters
15620 resulting in more than 1 glyph (e.g. tabs): Display as many
15621 glyphs as possible in this line and leave the rest for the
15622 continuation line, or display the whole element in the next
15623 line. Original redisplay did the former, so we do it also. */
15624 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15625 hpos_before
= it
->hpos
;
15628 if (/* Not a newline. */
15630 /* Glyphs produced fit entirely in the line. */
15631 && it
->current_x
< it
->last_visible_x
)
15633 it
->hpos
+= nglyphs
;
15634 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15635 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15636 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15637 row
->phys_height
= max (row
->phys_height
,
15638 it
->max_phys_ascent
+ it
->max_phys_descent
);
15639 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15640 it
->max_extra_line_spacing
);
15641 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15642 row
->x
= x
- it
->first_visible_x
;
15647 struct glyph
*glyph
;
15649 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15651 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15652 new_x
= x
+ glyph
->pixel_width
;
15654 if (/* Lines are continued. */
15655 !it
->truncate_lines_p
15656 && (/* Glyph doesn't fit on the line. */
15657 new_x
> it
->last_visible_x
15658 /* Or it fits exactly on a window system frame. */
15659 || (new_x
== it
->last_visible_x
15660 && FRAME_WINDOW_P (it
->f
))))
15662 /* End of a continued line. */
15665 || (new_x
== it
->last_visible_x
15666 && FRAME_WINDOW_P (it
->f
)))
15668 /* Current glyph is the only one on the line or
15669 fits exactly on the line. We must continue
15670 the line because we can't draw the cursor
15671 after the glyph. */
15672 row
->continued_p
= 1;
15673 it
->current_x
= new_x
;
15674 it
->continuation_lines_width
+= new_x
;
15676 if (i
== nglyphs
- 1)
15678 set_iterator_to_next (it
, 1);
15679 #ifdef HAVE_WINDOW_SYSTEM
15680 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15682 if (!get_next_display_element (it
))
15684 row
->exact_window_width_line_p
= 1;
15685 it
->continuation_lines_width
= 0;
15686 row
->continued_p
= 0;
15687 row
->ends_at_zv_p
= 1;
15689 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15691 row
->continued_p
= 0;
15692 row
->exact_window_width_line_p
= 1;
15695 #endif /* HAVE_WINDOW_SYSTEM */
15698 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15699 && !FRAME_WINDOW_P (it
->f
))
15701 /* A padding glyph that doesn't fit on this line.
15702 This means the whole character doesn't fit
15704 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15706 /* Fill the rest of the row with continuation
15707 glyphs like in 20.x. */
15708 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15709 < row
->glyphs
[1 + TEXT_AREA
])
15710 produce_special_glyphs (it
, IT_CONTINUATION
);
15712 row
->continued_p
= 1;
15713 it
->current_x
= x_before
;
15714 it
->continuation_lines_width
+= x_before
;
15716 /* Restore the height to what it was before the
15717 element not fitting on the line. */
15718 it
->max_ascent
= ascent
;
15719 it
->max_descent
= descent
;
15720 it
->max_phys_ascent
= phys_ascent
;
15721 it
->max_phys_descent
= phys_descent
;
15723 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15725 /* A TAB that extends past the right edge of the
15726 window. This produces a single glyph on
15727 window system frames. We leave the glyph in
15728 this row and let it fill the row, but don't
15729 consume the TAB. */
15730 it
->continuation_lines_width
+= it
->last_visible_x
;
15731 row
->ends_in_middle_of_char_p
= 1;
15732 row
->continued_p
= 1;
15733 glyph
->pixel_width
= it
->last_visible_x
- x
;
15734 it
->starts_in_middle_of_char_p
= 1;
15738 /* Something other than a TAB that draws past
15739 the right edge of the window. Restore
15740 positions to values before the element. */
15741 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15743 /* Display continuation glyphs. */
15744 if (!FRAME_WINDOW_P (it
->f
))
15745 produce_special_glyphs (it
, IT_CONTINUATION
);
15746 row
->continued_p
= 1;
15748 it
->current_x
= x_before
;
15749 it
->continuation_lines_width
+= x
;
15750 extend_face_to_end_of_line (it
);
15752 if (nglyphs
> 1 && i
> 0)
15754 row
->ends_in_middle_of_char_p
= 1;
15755 it
->starts_in_middle_of_char_p
= 1;
15758 /* Restore the height to what it was before the
15759 element not fitting on the line. */
15760 it
->max_ascent
= ascent
;
15761 it
->max_descent
= descent
;
15762 it
->max_phys_ascent
= phys_ascent
;
15763 it
->max_phys_descent
= phys_descent
;
15768 else if (new_x
> it
->first_visible_x
)
15770 /* Increment number of glyphs actually displayed. */
15773 if (x
< it
->first_visible_x
)
15774 /* Glyph is partially visible, i.e. row starts at
15775 negative X position. */
15776 row
->x
= x
- it
->first_visible_x
;
15780 /* Glyph is completely off the left margin of the
15781 window. This should not happen because of the
15782 move_it_in_display_line at the start of this
15783 function, unless the text display area of the
15784 window is empty. */
15785 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15789 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15790 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15791 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15792 row
->phys_height
= max (row
->phys_height
,
15793 it
->max_phys_ascent
+ it
->max_phys_descent
);
15794 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15795 it
->max_extra_line_spacing
);
15797 /* End of this display line if row is continued. */
15798 if (row
->continued_p
|| row
->ends_at_zv_p
)
15803 /* Is this a line end? If yes, we're also done, after making
15804 sure that a non-default face is extended up to the right
15805 margin of the window. */
15806 if (ITERATOR_AT_END_OF_LINE_P (it
))
15808 int used_before
= row
->used
[TEXT_AREA
];
15810 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15812 #ifdef HAVE_WINDOW_SYSTEM
15813 /* Add a space at the end of the line that is used to
15814 display the cursor there. */
15815 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15816 append_space_for_newline (it
, 0);
15817 #endif /* HAVE_WINDOW_SYSTEM */
15819 /* Extend the face to the end of the line. */
15820 extend_face_to_end_of_line (it
);
15822 /* Make sure we have the position. */
15823 if (used_before
== 0)
15824 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15826 /* Consume the line end. This skips over invisible lines. */
15827 set_iterator_to_next (it
, 1);
15828 it
->continuation_lines_width
= 0;
15832 /* Proceed with next display element. Note that this skips
15833 over lines invisible because of selective display. */
15834 set_iterator_to_next (it
, 1);
15836 /* If we truncate lines, we are done when the last displayed
15837 glyphs reach past the right margin of the window. */
15838 if (it
->truncate_lines_p
15839 && (FRAME_WINDOW_P (it
->f
)
15840 ? (it
->current_x
>= it
->last_visible_x
)
15841 : (it
->current_x
> it
->last_visible_x
)))
15843 /* Maybe add truncation glyphs. */
15844 if (!FRAME_WINDOW_P (it
->f
))
15848 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15849 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15852 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15854 row
->used
[TEXT_AREA
] = i
;
15855 produce_special_glyphs (it
, IT_TRUNCATION
);
15858 #ifdef HAVE_WINDOW_SYSTEM
15861 /* Don't truncate if we can overflow newline into fringe. */
15862 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15864 if (!get_next_display_element (it
))
15866 it
->continuation_lines_width
= 0;
15867 row
->ends_at_zv_p
= 1;
15868 row
->exact_window_width_line_p
= 1;
15871 if (ITERATOR_AT_END_OF_LINE_P (it
))
15873 row
->exact_window_width_line_p
= 1;
15874 goto at_end_of_line
;
15878 #endif /* HAVE_WINDOW_SYSTEM */
15880 row
->truncated_on_right_p
= 1;
15881 it
->continuation_lines_width
= 0;
15882 reseat_at_next_visible_line_start (it
, 0);
15883 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15884 it
->hpos
= hpos_before
;
15885 it
->current_x
= x_before
;
15890 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15891 at the left window margin. */
15892 if (it
->first_visible_x
15893 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15895 if (!FRAME_WINDOW_P (it
->f
))
15896 insert_left_trunc_glyphs (it
);
15897 row
->truncated_on_left_p
= 1;
15900 /* If the start of this line is the overlay arrow-position, then
15901 mark this glyph row as the one containing the overlay arrow.
15902 This is clearly a mess with variable size fonts. It would be
15903 better to let it be displayed like cursors under X. */
15904 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15905 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15906 !NILP (overlay_arrow_string
)))
15908 /* Overlay arrow in window redisplay is a fringe bitmap. */
15909 if (STRINGP (overlay_arrow_string
))
15911 struct glyph_row
*arrow_row
15912 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15913 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15914 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15915 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15916 struct glyph
*p2
, *end
;
15918 /* Copy the arrow glyphs. */
15919 while (glyph
< arrow_end
)
15922 /* Throw away padding glyphs. */
15924 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15925 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15931 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15936 xassert (INTEGERP (overlay_arrow_string
));
15937 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15939 overlay_arrow_seen
= 1;
15942 /* Compute pixel dimensions of this line. */
15943 compute_line_metrics (it
);
15945 /* Remember the position at which this line ends. */
15946 row
->end
= it
->current
;
15948 /* Record whether this row ends inside an ellipsis. */
15949 row
->ends_in_ellipsis_p
15950 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15951 && it
->ellipsis_p
);
15953 /* Save fringe bitmaps in this row. */
15954 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15955 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15956 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15957 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15959 it
->left_user_fringe_bitmap
= 0;
15960 it
->left_user_fringe_face_id
= 0;
15961 it
->right_user_fringe_bitmap
= 0;
15962 it
->right_user_fringe_face_id
= 0;
15964 /* Maybe set the cursor. */
15965 if (it
->w
->cursor
.vpos
< 0
15966 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15967 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15968 && cursor_row_p (it
->w
, row
))
15969 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15971 /* Highlight trailing whitespace. */
15972 if (!NILP (Vshow_trailing_whitespace
))
15973 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15975 /* Prepare for the next line. This line starts horizontally at (X
15976 HPOS) = (0 0). Vertical positions are incremented. As a
15977 convenience for the caller, IT->glyph_row is set to the next
15979 it
->current_x
= it
->hpos
= 0;
15980 it
->current_y
+= row
->height
;
15983 it
->start
= it
->current
;
15984 return row
->displays_text_p
;
15989 /***********************************************************************
15991 ***********************************************************************/
15993 /* Redisplay the menu bar in the frame for window W.
15995 The menu bar of X frames that don't have X toolkit support is
15996 displayed in a special window W->frame->menu_bar_window.
15998 The menu bar of terminal frames is treated specially as far as
15999 glyph matrices are concerned. Menu bar lines are not part of
16000 windows, so the update is done directly on the frame matrix rows
16001 for the menu bar. */
16004 display_menu_bar (w
)
16007 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16012 /* Don't do all this for graphical frames. */
16014 if (!NILP (Vwindow_system
))
16017 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16022 if (FRAME_MAC_P (f
))
16026 #ifdef USE_X_TOOLKIT
16027 xassert (!FRAME_WINDOW_P (f
));
16028 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16029 it
.first_visible_x
= 0;
16030 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16031 #else /* not USE_X_TOOLKIT */
16032 if (FRAME_WINDOW_P (f
))
16034 /* Menu bar lines are displayed in the desired matrix of the
16035 dummy window menu_bar_window. */
16036 struct window
*menu_w
;
16037 xassert (WINDOWP (f
->menu_bar_window
));
16038 menu_w
= XWINDOW (f
->menu_bar_window
);
16039 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16041 it
.first_visible_x
= 0;
16042 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16046 /* This is a TTY frame, i.e. character hpos/vpos are used as
16048 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16050 it
.first_visible_x
= 0;
16051 it
.last_visible_x
= FRAME_COLS (f
);
16053 #endif /* not USE_X_TOOLKIT */
16055 if (! mode_line_inverse_video
)
16056 /* Force the menu-bar to be displayed in the default face. */
16057 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16059 /* Clear all rows of the menu bar. */
16060 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16062 struct glyph_row
*row
= it
.glyph_row
+ i
;
16063 clear_glyph_row (row
);
16064 row
->enabled_p
= 1;
16065 row
->full_width_p
= 1;
16068 /* Display all items of the menu bar. */
16069 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16070 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16072 Lisp_Object string
;
16074 /* Stop at nil string. */
16075 string
= AREF (items
, i
+ 1);
16079 /* Remember where item was displayed. */
16080 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16082 /* Display the item, pad with one space. */
16083 if (it
.current_x
< it
.last_visible_x
)
16084 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16085 SCHARS (string
) + 1, 0, 0, -1);
16088 /* Fill out the line with spaces. */
16089 if (it
.current_x
< it
.last_visible_x
)
16090 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16092 /* Compute the total height of the lines. */
16093 compute_line_metrics (&it
);
16098 /***********************************************************************
16100 ***********************************************************************/
16102 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16103 FORCE is non-zero, redisplay mode lines unconditionally.
16104 Otherwise, redisplay only mode lines that are garbaged. Value is
16105 the number of windows whose mode lines were redisplayed. */
16108 redisplay_mode_lines (window
, force
)
16109 Lisp_Object window
;
16114 while (!NILP (window
))
16116 struct window
*w
= XWINDOW (window
);
16118 if (WINDOWP (w
->hchild
))
16119 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16120 else if (WINDOWP (w
->vchild
))
16121 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16123 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16124 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16126 struct text_pos lpoint
;
16127 struct buffer
*old
= current_buffer
;
16129 /* Set the window's buffer for the mode line display. */
16130 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16131 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16133 /* Point refers normally to the selected window. For any
16134 other window, set up appropriate value. */
16135 if (!EQ (window
, selected_window
))
16137 struct text_pos pt
;
16139 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16140 if (CHARPOS (pt
) < BEGV
)
16141 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16142 else if (CHARPOS (pt
) > (ZV
- 1))
16143 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16145 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16148 /* Display mode lines. */
16149 clear_glyph_matrix (w
->desired_matrix
);
16150 if (display_mode_lines (w
))
16153 w
->must_be_updated_p
= 1;
16156 /* Restore old settings. */
16157 set_buffer_internal_1 (old
);
16158 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16168 /* Display the mode and/or top line of window W. Value is the number
16169 of mode lines displayed. */
16172 display_mode_lines (w
)
16175 Lisp_Object old_selected_window
, old_selected_frame
;
16178 old_selected_frame
= selected_frame
;
16179 selected_frame
= w
->frame
;
16180 old_selected_window
= selected_window
;
16181 XSETWINDOW (selected_window
, w
);
16183 /* These will be set while the mode line specs are processed. */
16184 line_number_displayed
= 0;
16185 w
->column_number_displayed
= Qnil
;
16187 if (WINDOW_WANTS_MODELINE_P (w
))
16189 struct window
*sel_w
= XWINDOW (old_selected_window
);
16191 /* Select mode line face based on the real selected window. */
16192 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16193 current_buffer
->mode_line_format
);
16197 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16199 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16200 current_buffer
->header_line_format
);
16204 selected_frame
= old_selected_frame
;
16205 selected_window
= old_selected_window
;
16210 /* Display mode or top line of window W. FACE_ID specifies which line
16211 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16212 FORMAT is the mode line format to display. Value is the pixel
16213 height of the mode line displayed. */
16216 display_mode_line (w
, face_id
, format
)
16218 enum face_id face_id
;
16219 Lisp_Object format
;
16223 int count
= SPECPDL_INDEX ();
16225 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16226 prepare_desired_row (it
.glyph_row
);
16228 it
.glyph_row
->mode_line_p
= 1;
16230 if (! mode_line_inverse_video
)
16231 /* Force the mode-line to be displayed in the default face. */
16232 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16234 record_unwind_protect (unwind_format_mode_line
,
16235 format_mode_line_unwind_data (NULL
, 0));
16237 mode_line_target
= MODE_LINE_DISPLAY
;
16239 /* Temporarily make frame's keyboard the current kboard so that
16240 kboard-local variables in the mode_line_format will get the right
16242 push_kboard (FRAME_KBOARD (it
.f
));
16243 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16246 unbind_to (count
, Qnil
);
16248 /* Fill up with spaces. */
16249 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16251 compute_line_metrics (&it
);
16252 it
.glyph_row
->full_width_p
= 1;
16253 it
.glyph_row
->continued_p
= 0;
16254 it
.glyph_row
->truncated_on_left_p
= 0;
16255 it
.glyph_row
->truncated_on_right_p
= 0;
16257 /* Make a 3D mode-line have a shadow at its right end. */
16258 face
= FACE_FROM_ID (it
.f
, face_id
);
16259 extend_face_to_end_of_line (&it
);
16260 if (face
->box
!= FACE_NO_BOX
)
16262 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16263 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16264 last
->right_box_line_p
= 1;
16267 return it
.glyph_row
->height
;
16270 /* Move element ELT in LIST to the front of LIST.
16271 Return the updated list. */
16274 move_elt_to_front (elt
, list
)
16275 Lisp_Object elt
, list
;
16277 register Lisp_Object tail
, prev
;
16278 register Lisp_Object tem
;
16282 while (CONSP (tail
))
16288 /* Splice out the link TAIL. */
16290 list
= XCDR (tail
);
16292 Fsetcdr (prev
, XCDR (tail
));
16294 /* Now make it the first. */
16295 Fsetcdr (tail
, list
);
16300 tail
= XCDR (tail
);
16304 /* Not found--return unchanged LIST. */
16308 /* Contribute ELT to the mode line for window IT->w. How it
16309 translates into text depends on its data type.
16311 IT describes the display environment in which we display, as usual.
16313 DEPTH is the depth in recursion. It is used to prevent
16314 infinite recursion here.
16316 FIELD_WIDTH is the number of characters the display of ELT should
16317 occupy in the mode line, and PRECISION is the maximum number of
16318 characters to display from ELT's representation. See
16319 display_string for details.
16321 Returns the hpos of the end of the text generated by ELT.
16323 PROPS is a property list to add to any string we encounter.
16325 If RISKY is nonzero, remove (disregard) any properties in any string
16326 we encounter, and ignore :eval and :propertize.
16328 The global variable `mode_line_target' determines whether the
16329 output is passed to `store_mode_line_noprop',
16330 `store_mode_line_string', or `display_string'. */
16333 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16336 int field_width
, precision
;
16337 Lisp_Object elt
, props
;
16340 int n
= 0, field
, prec
;
16345 elt
= build_string ("*too-deep*");
16349 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16353 /* A string: output it and check for %-constructs within it. */
16357 if (SCHARS (elt
) > 0
16358 && (!NILP (props
) || risky
))
16360 Lisp_Object oprops
, aelt
;
16361 oprops
= Ftext_properties_at (make_number (0), elt
);
16363 /* If the starting string's properties are not what
16364 we want, translate the string. Also, if the string
16365 is risky, do that anyway. */
16367 if (NILP (Fequal (props
, oprops
)) || risky
)
16369 /* If the starting string has properties,
16370 merge the specified ones onto the existing ones. */
16371 if (! NILP (oprops
) && !risky
)
16375 oprops
= Fcopy_sequence (oprops
);
16377 while (CONSP (tem
))
16379 oprops
= Fplist_put (oprops
, XCAR (tem
),
16380 XCAR (XCDR (tem
)));
16381 tem
= XCDR (XCDR (tem
));
16386 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16387 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16389 /* AELT is what we want. Move it to the front
16390 without consing. */
16392 mode_line_proptrans_alist
16393 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16399 /* If AELT has the wrong props, it is useless.
16400 so get rid of it. */
16402 mode_line_proptrans_alist
16403 = Fdelq (aelt
, mode_line_proptrans_alist
);
16405 elt
= Fcopy_sequence (elt
);
16406 Fset_text_properties (make_number (0), Flength (elt
),
16408 /* Add this item to mode_line_proptrans_alist. */
16409 mode_line_proptrans_alist
16410 = Fcons (Fcons (elt
, props
),
16411 mode_line_proptrans_alist
);
16412 /* Truncate mode_line_proptrans_alist
16413 to at most 50 elements. */
16414 tem
= Fnthcdr (make_number (50),
16415 mode_line_proptrans_alist
);
16417 XSETCDR (tem
, Qnil
);
16426 prec
= precision
- n
;
16427 switch (mode_line_target
)
16429 case MODE_LINE_NOPROP
:
16430 case MODE_LINE_TITLE
:
16431 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16433 case MODE_LINE_STRING
:
16434 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16436 case MODE_LINE_DISPLAY
:
16437 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16438 0, prec
, 0, STRING_MULTIBYTE (elt
));
16445 /* Handle the non-literal case. */
16447 while ((precision
<= 0 || n
< precision
)
16448 && SREF (elt
, offset
) != 0
16449 && (mode_line_target
!= MODE_LINE_DISPLAY
16450 || it
->current_x
< it
->last_visible_x
))
16452 int last_offset
= offset
;
16454 /* Advance to end of string or next format specifier. */
16455 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16458 if (offset
- 1 != last_offset
)
16460 int nchars
, nbytes
;
16462 /* Output to end of string or up to '%'. Field width
16463 is length of string. Don't output more than
16464 PRECISION allows us. */
16467 prec
= c_string_width (SDATA (elt
) + last_offset
,
16468 offset
- last_offset
, precision
- n
,
16471 switch (mode_line_target
)
16473 case MODE_LINE_NOPROP
:
16474 case MODE_LINE_TITLE
:
16475 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16477 case MODE_LINE_STRING
:
16479 int bytepos
= last_offset
;
16480 int charpos
= string_byte_to_char (elt
, bytepos
);
16481 int endpos
= (precision
<= 0
16482 ? string_byte_to_char (elt
, offset
)
16483 : charpos
+ nchars
);
16485 n
+= store_mode_line_string (NULL
,
16486 Fsubstring (elt
, make_number (charpos
),
16487 make_number (endpos
)),
16491 case MODE_LINE_DISPLAY
:
16493 int bytepos
= last_offset
;
16494 int charpos
= string_byte_to_char (elt
, bytepos
);
16495 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16497 STRING_MULTIBYTE (elt
));
16502 else /* c == '%' */
16504 int percent_position
= offset
;
16506 /* Get the specified minimum width. Zero means
16509 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16510 field
= field
* 10 + c
- '0';
16512 /* Don't pad beyond the total padding allowed. */
16513 if (field_width
- n
> 0 && field
> field_width
- n
)
16514 field
= field_width
- n
;
16516 /* Note that either PRECISION <= 0 or N < PRECISION. */
16517 prec
= precision
- n
;
16520 n
+= display_mode_element (it
, depth
, field
, prec
,
16521 Vglobal_mode_string
, props
,
16526 int bytepos
, charpos
;
16527 unsigned char *spec
;
16529 bytepos
= percent_position
;
16530 charpos
= (STRING_MULTIBYTE (elt
)
16531 ? string_byte_to_char (elt
, bytepos
)
16535 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16537 switch (mode_line_target
)
16539 case MODE_LINE_NOPROP
:
16540 case MODE_LINE_TITLE
:
16541 n
+= store_mode_line_noprop (spec
, field
, prec
);
16543 case MODE_LINE_STRING
:
16545 int len
= strlen (spec
);
16546 Lisp_Object tem
= make_string (spec
, len
);
16547 props
= Ftext_properties_at (make_number (charpos
), elt
);
16548 /* Should only keep face property in props */
16549 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16552 case MODE_LINE_DISPLAY
:
16554 int nglyphs_before
, nwritten
;
16556 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16557 nwritten
= display_string (spec
, Qnil
, elt
,
16562 /* Assign to the glyphs written above the
16563 string where the `%x' came from, position
16567 struct glyph
*glyph
16568 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16572 for (i
= 0; i
< nwritten
; ++i
)
16574 glyph
[i
].object
= elt
;
16575 glyph
[i
].charpos
= charpos
;
16592 /* A symbol: process the value of the symbol recursively
16593 as if it appeared here directly. Avoid error if symbol void.
16594 Special case: if value of symbol is a string, output the string
16597 register Lisp_Object tem
;
16599 /* If the variable is not marked as risky to set
16600 then its contents are risky to use. */
16601 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16604 tem
= Fboundp (elt
);
16607 tem
= Fsymbol_value (elt
);
16608 /* If value is a string, output that string literally:
16609 don't check for % within it. */
16613 if (!EQ (tem
, elt
))
16615 /* Give up right away for nil or t. */
16625 register Lisp_Object car
, tem
;
16627 /* A cons cell: five distinct cases.
16628 If first element is :eval or :propertize, do something special.
16629 If first element is a string or a cons, process all the elements
16630 and effectively concatenate them.
16631 If first element is a negative number, truncate displaying cdr to
16632 at most that many characters. If positive, pad (with spaces)
16633 to at least that many characters.
16634 If first element is a symbol, process the cadr or caddr recursively
16635 according to whether the symbol's value is non-nil or nil. */
16637 if (EQ (car
, QCeval
))
16639 /* An element of the form (:eval FORM) means evaluate FORM
16640 and use the result as mode line elements. */
16645 if (CONSP (XCDR (elt
)))
16648 spec
= safe_eval (XCAR (XCDR (elt
)));
16649 n
+= display_mode_element (it
, depth
, field_width
- n
,
16650 precision
- n
, spec
, props
,
16654 else if (EQ (car
, QCpropertize
))
16656 /* An element of the form (:propertize ELT PROPS...)
16657 means display ELT but applying properties PROPS. */
16662 if (CONSP (XCDR (elt
)))
16663 n
+= display_mode_element (it
, depth
, field_width
- n
,
16664 precision
- n
, XCAR (XCDR (elt
)),
16665 XCDR (XCDR (elt
)), risky
);
16667 else if (SYMBOLP (car
))
16669 tem
= Fboundp (car
);
16673 /* elt is now the cdr, and we know it is a cons cell.
16674 Use its car if CAR has a non-nil value. */
16677 tem
= Fsymbol_value (car
);
16684 /* Symbol's value is nil (or symbol is unbound)
16685 Get the cddr of the original list
16686 and if possible find the caddr and use that. */
16690 else if (!CONSP (elt
))
16695 else if (INTEGERP (car
))
16697 register int lim
= XINT (car
);
16701 /* Negative int means reduce maximum width. */
16702 if (precision
<= 0)
16705 precision
= min (precision
, -lim
);
16709 /* Padding specified. Don't let it be more than
16710 current maximum. */
16712 lim
= min (precision
, lim
);
16714 /* If that's more padding than already wanted, queue it.
16715 But don't reduce padding already specified even if
16716 that is beyond the current truncation point. */
16717 field_width
= max (lim
, field_width
);
16721 else if (STRINGP (car
) || CONSP (car
))
16723 register int limit
= 50;
16724 /* Limit is to protect against circular lists. */
16727 && (precision
<= 0 || n
< precision
))
16729 n
+= display_mode_element (it
, depth
,
16730 /* Do padding only after the last
16731 element in the list. */
16732 (! CONSP (XCDR (elt
))
16735 precision
- n
, XCAR (elt
),
16745 elt
= build_string ("*invalid*");
16749 /* Pad to FIELD_WIDTH. */
16750 if (field_width
> 0 && n
< field_width
)
16752 switch (mode_line_target
)
16754 case MODE_LINE_NOPROP
:
16755 case MODE_LINE_TITLE
:
16756 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16758 case MODE_LINE_STRING
:
16759 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16761 case MODE_LINE_DISPLAY
:
16762 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16771 /* Store a mode-line string element in mode_line_string_list.
16773 If STRING is non-null, display that C string. Otherwise, the Lisp
16774 string LISP_STRING is displayed.
16776 FIELD_WIDTH is the minimum number of output glyphs to produce.
16777 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16778 with spaces. FIELD_WIDTH <= 0 means don't pad.
16780 PRECISION is the maximum number of characters to output from
16781 STRING. PRECISION <= 0 means don't truncate the string.
16783 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16784 properties to the string.
16786 PROPS are the properties to add to the string.
16787 The mode_line_string_face face property is always added to the string.
16791 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16793 Lisp_Object lisp_string
;
16802 if (string
!= NULL
)
16804 len
= strlen (string
);
16805 if (precision
> 0 && len
> precision
)
16807 lisp_string
= make_string (string
, len
);
16809 props
= mode_line_string_face_prop
;
16810 else if (!NILP (mode_line_string_face
))
16812 Lisp_Object face
= Fplist_get (props
, Qface
);
16813 props
= Fcopy_sequence (props
);
16815 face
= mode_line_string_face
;
16817 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16818 props
= Fplist_put (props
, Qface
, face
);
16820 Fadd_text_properties (make_number (0), make_number (len
),
16821 props
, lisp_string
);
16825 len
= XFASTINT (Flength (lisp_string
));
16826 if (precision
> 0 && len
> precision
)
16829 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16832 if (!NILP (mode_line_string_face
))
16836 props
= Ftext_properties_at (make_number (0), lisp_string
);
16837 face
= Fplist_get (props
, Qface
);
16839 face
= mode_line_string_face
;
16841 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16842 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16844 lisp_string
= Fcopy_sequence (lisp_string
);
16847 Fadd_text_properties (make_number (0), make_number (len
),
16848 props
, lisp_string
);
16853 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16857 if (field_width
> len
)
16859 field_width
-= len
;
16860 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16862 Fadd_text_properties (make_number (0), make_number (field_width
),
16863 props
, lisp_string
);
16864 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16872 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16874 doc
: /* Format a string out of a mode line format specification.
16875 First arg FORMAT specifies the mode line format (see `mode-line-format'
16876 for details) to use.
16878 Optional second arg FACE specifies the face property to put
16879 on all characters for which no face is specified.
16880 t means whatever face the window's mode line currently uses
16881 \(either `mode-line' or `mode-line-inactive', depending).
16882 nil means the default is no face property.
16883 If FACE is an integer, the value string has no text properties.
16885 Optional third and fourth args WINDOW and BUFFER specify the window
16886 and buffer to use as the context for the formatting (defaults
16887 are the selected window and the window's buffer). */)
16888 (format
, face
, window
, buffer
)
16889 Lisp_Object format
, face
, window
, buffer
;
16894 struct buffer
*old_buffer
= NULL
;
16896 int no_props
= INTEGERP (face
);
16897 int count
= SPECPDL_INDEX ();
16899 int string_start
= 0;
16902 window
= selected_window
;
16903 CHECK_WINDOW (window
);
16904 w
= XWINDOW (window
);
16907 buffer
= w
->buffer
;
16908 CHECK_BUFFER (buffer
);
16911 return build_string ("");
16919 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16920 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16924 face_id
= DEFAULT_FACE_ID
;
16926 if (XBUFFER (buffer
) != current_buffer
)
16927 old_buffer
= current_buffer
;
16929 /* Save things including mode_line_proptrans_alist,
16930 and set that to nil so that we don't alter the outer value. */
16931 record_unwind_protect (unwind_format_mode_line
,
16932 format_mode_line_unwind_data (old_buffer
, 1));
16933 mode_line_proptrans_alist
= Qnil
;
16936 set_buffer_internal_1 (XBUFFER (buffer
));
16938 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16942 mode_line_target
= MODE_LINE_NOPROP
;
16943 mode_line_string_face_prop
= Qnil
;
16944 mode_line_string_list
= Qnil
;
16945 string_start
= MODE_LINE_NOPROP_LEN (0);
16949 mode_line_target
= MODE_LINE_STRING
;
16950 mode_line_string_list
= Qnil
;
16951 mode_line_string_face
= face
;
16952 mode_line_string_face_prop
16953 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16956 push_kboard (FRAME_KBOARD (it
.f
));
16957 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16962 len
= MODE_LINE_NOPROP_LEN (string_start
);
16963 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16967 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16968 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16969 make_string ("", 0));
16972 unbind_to (count
, Qnil
);
16976 /* Write a null-terminated, right justified decimal representation of
16977 the positive integer D to BUF using a minimal field width WIDTH. */
16980 pint2str (buf
, width
, d
)
16981 register char *buf
;
16982 register int width
;
16985 register char *p
= buf
;
16993 *p
++ = d
% 10 + '0';
16998 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17009 /* Write a null-terminated, right justified decimal and "human
17010 readable" representation of the nonnegative integer D to BUF using
17011 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17013 static const char power_letter
[] =
17027 pint2hrstr (buf
, width
, d
)
17032 /* We aim to represent the nonnegative integer D as
17033 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17036 /* -1 means: do not use TENTHS. */
17040 /* Length of QUOTIENT.TENTHS as a string. */
17046 if (1000 <= quotient
)
17048 /* Scale to the appropriate EXPONENT. */
17051 remainder
= quotient
% 1000;
17055 while (1000 <= quotient
);
17057 /* Round to nearest and decide whether to use TENTHS or not. */
17060 tenths
= remainder
/ 100;
17061 if (50 <= remainder
% 100)
17068 if (quotient
== 10)
17076 if (500 <= remainder
)
17078 if (quotient
< 999)
17089 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17090 if (tenths
== -1 && quotient
<= 99)
17097 p
= psuffix
= buf
+ max (width
, length
);
17099 /* Print EXPONENT. */
17101 *psuffix
++ = power_letter
[exponent
];
17104 /* Print TENTHS. */
17107 *--p
= '0' + tenths
;
17111 /* Print QUOTIENT. */
17114 int digit
= quotient
% 10;
17115 *--p
= '0' + digit
;
17117 while ((quotient
/= 10) != 0);
17119 /* Print leading spaces. */
17124 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17125 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17126 type of CODING_SYSTEM. Return updated pointer into BUF. */
17128 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17131 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17132 Lisp_Object coding_system
;
17133 register char *buf
;
17137 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17138 const unsigned char *eol_str
;
17140 /* The EOL conversion we are using. */
17141 Lisp_Object eoltype
;
17143 val
= Fget (coding_system
, Qcoding_system
);
17146 if (!VECTORP (val
)) /* Not yet decided. */
17151 eoltype
= eol_mnemonic_undecided
;
17152 /* Don't mention EOL conversion if it isn't decided. */
17156 Lisp_Object eolvalue
;
17158 eolvalue
= Fget (coding_system
, Qeol_type
);
17161 *buf
++ = XFASTINT (AREF (val
, 1));
17165 /* The EOL conversion that is normal on this system. */
17167 if (NILP (eolvalue
)) /* Not yet decided. */
17168 eoltype
= eol_mnemonic_undecided
;
17169 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17170 eoltype
= eol_mnemonic_undecided
;
17171 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17172 eoltype
= (XFASTINT (eolvalue
) == 0
17173 ? eol_mnemonic_unix
17174 : (XFASTINT (eolvalue
) == 1
17175 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17181 /* Mention the EOL conversion if it is not the usual one. */
17182 if (STRINGP (eoltype
))
17184 eol_str
= SDATA (eoltype
);
17185 eol_str_len
= SBYTES (eoltype
);
17187 else if (INTEGERP (eoltype
)
17188 && CHAR_VALID_P (XINT (eoltype
), 0))
17190 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17191 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17196 eol_str
= invalid_eol_type
;
17197 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17199 bcopy (eol_str
, buf
, eol_str_len
);
17200 buf
+= eol_str_len
;
17206 /* Return a string for the output of a mode line %-spec for window W,
17207 generated by character C. PRECISION >= 0 means don't return a
17208 string longer than that value. FIELD_WIDTH > 0 means pad the
17209 string returned with spaces to that value. Return 1 in *MULTIBYTE
17210 if the result is multibyte text.
17212 Note we operate on the current buffer for most purposes,
17213 the exception being w->base_line_pos. */
17215 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17218 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17221 int field_width
, precision
;
17225 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17226 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17227 struct buffer
*b
= current_buffer
;
17235 if (!NILP (b
->read_only
))
17237 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17242 /* This differs from %* only for a modified read-only buffer. */
17243 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17245 if (!NILP (b
->read_only
))
17250 /* This differs from %* in ignoring read-only-ness. */
17251 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17263 if (command_loop_level
> 5)
17265 p
= decode_mode_spec_buf
;
17266 for (i
= 0; i
< command_loop_level
; i
++)
17269 return decode_mode_spec_buf
;
17277 if (command_loop_level
> 5)
17279 p
= decode_mode_spec_buf
;
17280 for (i
= 0; i
< command_loop_level
; i
++)
17283 return decode_mode_spec_buf
;
17290 /* Let lots_of_dashes be a string of infinite length. */
17291 if (mode_line_target
== MODE_LINE_NOPROP
||
17292 mode_line_target
== MODE_LINE_STRING
)
17294 if (field_width
<= 0
17295 || field_width
> sizeof (lots_of_dashes
))
17297 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17298 decode_mode_spec_buf
[i
] = '-';
17299 decode_mode_spec_buf
[i
] = '\0';
17300 return decode_mode_spec_buf
;
17303 return lots_of_dashes
;
17312 int col
= (int) current_column (); /* iftc */
17313 w
->column_number_displayed
= make_number (col
);
17314 pint2str (decode_mode_spec_buf
, field_width
, col
);
17315 return decode_mode_spec_buf
;
17319 #ifndef SYSTEM_MALLOC
17321 if (NILP (Vmemory_full
))
17324 return "!MEM FULL! ";
17331 /* %F displays the frame name. */
17332 if (!NILP (f
->title
))
17333 return (char *) SDATA (f
->title
);
17334 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17335 return (char *) SDATA (f
->name
);
17344 int size
= ZV
- BEGV
;
17345 pint2str (decode_mode_spec_buf
, field_width
, size
);
17346 return decode_mode_spec_buf
;
17351 int size
= ZV
- BEGV
;
17352 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17353 return decode_mode_spec_buf
;
17358 int startpos
= XMARKER (w
->start
)->charpos
;
17359 int startpos_byte
= marker_byte_position (w
->start
);
17360 int line
, linepos
, linepos_byte
, topline
;
17362 int height
= WINDOW_TOTAL_LINES (w
);
17364 /* If we decided that this buffer isn't suitable for line numbers,
17365 don't forget that too fast. */
17366 if (EQ (w
->base_line_pos
, w
->buffer
))
17368 /* But do forget it, if the window shows a different buffer now. */
17369 else if (BUFFERP (w
->base_line_pos
))
17370 w
->base_line_pos
= Qnil
;
17372 /* If the buffer is very big, don't waste time. */
17373 if (INTEGERP (Vline_number_display_limit
)
17374 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17376 w
->base_line_pos
= Qnil
;
17377 w
->base_line_number
= Qnil
;
17381 if (!NILP (w
->base_line_number
)
17382 && !NILP (w
->base_line_pos
)
17383 && XFASTINT (w
->base_line_pos
) <= startpos
)
17385 line
= XFASTINT (w
->base_line_number
);
17386 linepos
= XFASTINT (w
->base_line_pos
);
17387 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17392 linepos
= BUF_BEGV (b
);
17393 linepos_byte
= BUF_BEGV_BYTE (b
);
17396 /* Count lines from base line to window start position. */
17397 nlines
= display_count_lines (linepos
, linepos_byte
,
17401 topline
= nlines
+ line
;
17403 /* Determine a new base line, if the old one is too close
17404 or too far away, or if we did not have one.
17405 "Too close" means it's plausible a scroll-down would
17406 go back past it. */
17407 if (startpos
== BUF_BEGV (b
))
17409 w
->base_line_number
= make_number (topline
);
17410 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17412 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17413 || linepos
== BUF_BEGV (b
))
17415 int limit
= BUF_BEGV (b
);
17416 int limit_byte
= BUF_BEGV_BYTE (b
);
17418 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17420 if (startpos
- distance
> limit
)
17422 limit
= startpos
- distance
;
17423 limit_byte
= CHAR_TO_BYTE (limit
);
17426 nlines
= display_count_lines (startpos
, startpos_byte
,
17428 - (height
* 2 + 30),
17430 /* If we couldn't find the lines we wanted within
17431 line_number_display_limit_width chars per line,
17432 give up on line numbers for this window. */
17433 if (position
== limit_byte
&& limit
== startpos
- distance
)
17435 w
->base_line_pos
= w
->buffer
;
17436 w
->base_line_number
= Qnil
;
17440 w
->base_line_number
= make_number (topline
- nlines
);
17441 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17444 /* Now count lines from the start pos to point. */
17445 nlines
= display_count_lines (startpos
, startpos_byte
,
17446 PT_BYTE
, PT
, &junk
);
17448 /* Record that we did display the line number. */
17449 line_number_displayed
= 1;
17451 /* Make the string to show. */
17452 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17453 return decode_mode_spec_buf
;
17456 char* p
= decode_mode_spec_buf
;
17457 int pad
= field_width
- 2;
17463 return decode_mode_spec_buf
;
17469 obj
= b
->mode_name
;
17473 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17479 int pos
= marker_position (w
->start
);
17480 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17482 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17484 if (pos
<= BUF_BEGV (b
))
17489 else if (pos
<= BUF_BEGV (b
))
17493 if (total
> 1000000)
17494 /* Do it differently for a large value, to avoid overflow. */
17495 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17497 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17498 /* We can't normally display a 3-digit number,
17499 so get us a 2-digit number that is close. */
17502 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17503 return decode_mode_spec_buf
;
17507 /* Display percentage of size above the bottom of the screen. */
17510 int toppos
= marker_position (w
->start
);
17511 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17512 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17514 if (botpos
>= BUF_ZV (b
))
17516 if (toppos
<= BUF_BEGV (b
))
17523 if (total
> 1000000)
17524 /* Do it differently for a large value, to avoid overflow. */
17525 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17527 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17528 /* We can't normally display a 3-digit number,
17529 so get us a 2-digit number that is close. */
17532 if (toppos
<= BUF_BEGV (b
))
17533 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17535 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17536 return decode_mode_spec_buf
;
17541 /* status of process */
17542 obj
= Fget_buffer_process (Fcurrent_buffer ());
17544 return "no process";
17545 #ifdef subprocesses
17546 obj
= Fsymbol_name (Fprocess_status (obj
));
17550 case 't': /* indicate TEXT or BINARY */
17551 #ifdef MODE_LINE_BINARY_TEXT
17552 return MODE_LINE_BINARY_TEXT (b
);
17558 /* coding-system (not including end-of-line format) */
17560 /* coding-system (including end-of-line type) */
17562 int eol_flag
= (c
== 'Z');
17563 char *p
= decode_mode_spec_buf
;
17565 if (! FRAME_WINDOW_P (f
))
17567 /* No need to mention EOL here--the terminal never needs
17568 to do EOL conversion. */
17569 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
17570 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
17572 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17575 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17576 #ifdef subprocesses
17577 obj
= Fget_buffer_process (Fcurrent_buffer ());
17578 if (PROCESSP (obj
))
17580 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17582 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17585 #endif /* subprocesses */
17588 return decode_mode_spec_buf
;
17594 *multibyte
= STRING_MULTIBYTE (obj
);
17595 return (char *) SDATA (obj
);
17602 /* Count up to COUNT lines starting from START / START_BYTE.
17603 But don't go beyond LIMIT_BYTE.
17604 Return the number of lines thus found (always nonnegative).
17606 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17609 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17610 int start
, start_byte
, limit_byte
, count
;
17613 register unsigned char *cursor
;
17614 unsigned char *base
;
17616 register int ceiling
;
17617 register unsigned char *ceiling_addr
;
17618 int orig_count
= count
;
17620 /* If we are not in selective display mode,
17621 check only for newlines. */
17622 int selective_display
= (!NILP (current_buffer
->selective_display
)
17623 && !INTEGERP (current_buffer
->selective_display
));
17627 while (start_byte
< limit_byte
)
17629 ceiling
= BUFFER_CEILING_OF (start_byte
);
17630 ceiling
= min (limit_byte
- 1, ceiling
);
17631 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17632 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17635 if (selective_display
)
17636 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17639 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17642 if (cursor
!= ceiling_addr
)
17646 start_byte
+= cursor
- base
+ 1;
17647 *byte_pos_ptr
= start_byte
;
17651 if (++cursor
== ceiling_addr
)
17657 start_byte
+= cursor
- base
;
17662 while (start_byte
> limit_byte
)
17664 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17665 ceiling
= max (limit_byte
, ceiling
);
17666 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17667 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17670 if (selective_display
)
17671 while (--cursor
!= ceiling_addr
17672 && *cursor
!= '\n' && *cursor
!= 015)
17675 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17678 if (cursor
!= ceiling_addr
)
17682 start_byte
+= cursor
- base
+ 1;
17683 *byte_pos_ptr
= start_byte
;
17684 /* When scanning backwards, we should
17685 not count the newline posterior to which we stop. */
17686 return - orig_count
- 1;
17692 /* Here we add 1 to compensate for the last decrement
17693 of CURSOR, which took it past the valid range. */
17694 start_byte
+= cursor
- base
+ 1;
17698 *byte_pos_ptr
= limit_byte
;
17701 return - orig_count
+ count
;
17702 return orig_count
- count
;
17708 /***********************************************************************
17710 ***********************************************************************/
17712 /* Display a NUL-terminated string, starting with index START.
17714 If STRING is non-null, display that C string. Otherwise, the Lisp
17715 string LISP_STRING is displayed.
17717 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17718 FACE_STRING. Display STRING or LISP_STRING with the face at
17719 FACE_STRING_POS in FACE_STRING:
17721 Display the string in the environment given by IT, but use the
17722 standard display table, temporarily.
17724 FIELD_WIDTH is the minimum number of output glyphs to produce.
17725 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17726 with spaces. If STRING has more characters, more than FIELD_WIDTH
17727 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17729 PRECISION is the maximum number of characters to output from
17730 STRING. PRECISION < 0 means don't truncate the string.
17732 This is roughly equivalent to printf format specifiers:
17734 FIELD_WIDTH PRECISION PRINTF
17735 ----------------------------------------
17741 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17742 display them, and < 0 means obey the current buffer's value of
17743 enable_multibyte_characters.
17745 Value is the number of glyphs produced. */
17748 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17749 start
, it
, field_width
, precision
, max_x
, multibyte
)
17750 unsigned char *string
;
17751 Lisp_Object lisp_string
;
17752 Lisp_Object face_string
;
17753 int face_string_pos
;
17756 int field_width
, precision
, max_x
;
17759 int hpos_at_start
= it
->hpos
;
17760 int saved_face_id
= it
->face_id
;
17761 struct glyph_row
*row
= it
->glyph_row
;
17763 /* Initialize the iterator IT for iteration over STRING beginning
17764 with index START. */
17765 reseat_to_string (it
, string
, lisp_string
, start
,
17766 precision
, field_width
, multibyte
);
17768 /* If displaying STRING, set up the face of the iterator
17769 from LISP_STRING, if that's given. */
17770 if (STRINGP (face_string
))
17776 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17777 0, it
->region_beg_charpos
,
17778 it
->region_end_charpos
,
17779 &endptr
, it
->base_face_id
, 0);
17780 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17781 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17784 /* Set max_x to the maximum allowed X position. Don't let it go
17785 beyond the right edge of the window. */
17787 max_x
= it
->last_visible_x
;
17789 max_x
= min (max_x
, it
->last_visible_x
);
17791 /* Skip over display elements that are not visible. because IT->w is
17793 if (it
->current_x
< it
->first_visible_x
)
17794 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17795 MOVE_TO_POS
| MOVE_TO_X
);
17797 row
->ascent
= it
->max_ascent
;
17798 row
->height
= it
->max_ascent
+ it
->max_descent
;
17799 row
->phys_ascent
= it
->max_phys_ascent
;
17800 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17801 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17803 /* This condition is for the case that we are called with current_x
17804 past last_visible_x. */
17805 while (it
->current_x
< max_x
)
17807 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17809 /* Get the next display element. */
17810 if (!get_next_display_element (it
))
17813 /* Produce glyphs. */
17814 x_before
= it
->current_x
;
17815 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17816 PRODUCE_GLYPHS (it
);
17818 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17821 while (i
< nglyphs
)
17823 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17825 if (!it
->truncate_lines_p
17826 && x
+ glyph
->pixel_width
> max_x
)
17828 /* End of continued line or max_x reached. */
17829 if (CHAR_GLYPH_PADDING_P (*glyph
))
17831 /* A wide character is unbreakable. */
17832 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17833 it
->current_x
= x_before
;
17837 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17842 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17844 /* Glyph is at least partially visible. */
17846 if (x
< it
->first_visible_x
)
17847 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17851 /* Glyph is off the left margin of the display area.
17852 Should not happen. */
17856 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17857 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17858 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17859 row
->phys_height
= max (row
->phys_height
,
17860 it
->max_phys_ascent
+ it
->max_phys_descent
);
17861 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17862 it
->max_extra_line_spacing
);
17863 x
+= glyph
->pixel_width
;
17867 /* Stop if max_x reached. */
17871 /* Stop at line ends. */
17872 if (ITERATOR_AT_END_OF_LINE_P (it
))
17874 it
->continuation_lines_width
= 0;
17878 set_iterator_to_next (it
, 1);
17880 /* Stop if truncating at the right edge. */
17881 if (it
->truncate_lines_p
17882 && it
->current_x
>= it
->last_visible_x
)
17884 /* Add truncation mark, but don't do it if the line is
17885 truncated at a padding space. */
17886 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17888 if (!FRAME_WINDOW_P (it
->f
))
17892 if (it
->current_x
> it
->last_visible_x
)
17894 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17895 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17897 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17899 row
->used
[TEXT_AREA
] = i
;
17900 produce_special_glyphs (it
, IT_TRUNCATION
);
17903 produce_special_glyphs (it
, IT_TRUNCATION
);
17905 it
->glyph_row
->truncated_on_right_p
= 1;
17911 /* Maybe insert a truncation at the left. */
17912 if (it
->first_visible_x
17913 && IT_CHARPOS (*it
) > 0)
17915 if (!FRAME_WINDOW_P (it
->f
))
17916 insert_left_trunc_glyphs (it
);
17917 it
->glyph_row
->truncated_on_left_p
= 1;
17920 it
->face_id
= saved_face_id
;
17922 /* Value is number of columns displayed. */
17923 return it
->hpos
- hpos_at_start
;
17928 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17929 appears as an element of LIST or as the car of an element of LIST.
17930 If PROPVAL is a list, compare each element against LIST in that
17931 way, and return 1/2 if any element of PROPVAL is found in LIST.
17932 Otherwise return 0. This function cannot quit.
17933 The return value is 2 if the text is invisible but with an ellipsis
17934 and 1 if it's invisible and without an ellipsis. */
17937 invisible_p (propval
, list
)
17938 register Lisp_Object propval
;
17941 register Lisp_Object tail
, proptail
;
17943 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17945 register Lisp_Object tem
;
17947 if (EQ (propval
, tem
))
17949 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17950 return NILP (XCDR (tem
)) ? 1 : 2;
17953 if (CONSP (propval
))
17955 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17957 Lisp_Object propelt
;
17958 propelt
= XCAR (proptail
);
17959 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17961 register Lisp_Object tem
;
17963 if (EQ (propelt
, tem
))
17965 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17966 return NILP (XCDR (tem
)) ? 1 : 2;
17974 /* Calculate a width or height in pixels from a specification using
17975 the following elements:
17978 NUM - a (fractional) multiple of the default font width/height
17979 (NUM) - specifies exactly NUM pixels
17980 UNIT - a fixed number of pixels, see below.
17981 ELEMENT - size of a display element in pixels, see below.
17982 (NUM . SPEC) - equals NUM * SPEC
17983 (+ SPEC SPEC ...) - add pixel values
17984 (- SPEC SPEC ...) - subtract pixel values
17985 (- SPEC) - negate pixel value
17988 INT or FLOAT - a number constant
17989 SYMBOL - use symbol's (buffer local) variable binding.
17992 in - pixels per inch *)
17993 mm - pixels per 1/1000 meter *)
17994 cm - pixels per 1/100 meter *)
17995 width - width of current font in pixels.
17996 height - height of current font in pixels.
17998 *) using the ratio(s) defined in display-pixels-per-inch.
18002 left-fringe - left fringe width in pixels
18003 right-fringe - right fringe width in pixels
18005 left-margin - left margin width in pixels
18006 right-margin - right margin width in pixels
18008 scroll-bar - scroll-bar area width in pixels
18012 Pixels corresponding to 5 inches:
18015 Total width of non-text areas on left side of window (if scroll-bar is on left):
18016 '(space :width (+ left-fringe left-margin scroll-bar))
18018 Align to first text column (in header line):
18019 '(space :align-to 0)
18021 Align to middle of text area minus half the width of variable `my-image'
18022 containing a loaded image:
18023 '(space :align-to (0.5 . (- text my-image)))
18025 Width of left margin minus width of 1 character in the default font:
18026 '(space :width (- left-margin 1))
18028 Width of left margin minus width of 2 characters in the current font:
18029 '(space :width (- left-margin (2 . width)))
18031 Center 1 character over left-margin (in header line):
18032 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18034 Different ways to express width of left fringe plus left margin minus one pixel:
18035 '(space :width (- (+ left-fringe left-margin) (1)))
18036 '(space :width (+ left-fringe left-margin (- (1))))
18037 '(space :width (+ left-fringe left-margin (-1)))
18041 #define NUMVAL(X) \
18042 ((INTEGERP (X) || FLOATP (X)) \
18047 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18052 int width_p
, *align_to
;
18056 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18057 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18060 return OK_PIXELS (0);
18062 xassert (FRAME_LIVE_P (it
->f
));
18064 if (SYMBOLP (prop
))
18066 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18068 char *unit
= SDATA (SYMBOL_NAME (prop
));
18070 if (unit
[0] == 'i' && unit
[1] == 'n')
18072 else if (unit
[0] == 'm' && unit
[1] == 'm')
18074 else if (unit
[0] == 'c' && unit
[1] == 'm')
18081 #ifdef HAVE_WINDOW_SYSTEM
18082 if (FRAME_WINDOW_P (it
->f
)
18084 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18085 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18087 return OK_PIXELS (ppi
/ pixels
);
18090 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18091 || (CONSP (Vdisplay_pixels_per_inch
)
18093 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18094 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18096 return OK_PIXELS (ppi
/ pixels
);
18102 #ifdef HAVE_WINDOW_SYSTEM
18103 if (EQ (prop
, Qheight
))
18104 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18105 if (EQ (prop
, Qwidth
))
18106 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18108 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18109 return OK_PIXELS (1);
18112 if (EQ (prop
, Qtext
))
18113 return OK_PIXELS (width_p
18114 ? window_box_width (it
->w
, TEXT_AREA
)
18115 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18117 if (align_to
&& *align_to
< 0)
18120 if (EQ (prop
, Qleft
))
18121 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18122 if (EQ (prop
, Qright
))
18123 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18124 if (EQ (prop
, Qcenter
))
18125 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18126 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18127 if (EQ (prop
, Qleft_fringe
))
18128 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18129 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18130 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18131 if (EQ (prop
, Qright_fringe
))
18132 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18133 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18134 : window_box_right_offset (it
->w
, TEXT_AREA
));
18135 if (EQ (prop
, Qleft_margin
))
18136 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18137 if (EQ (prop
, Qright_margin
))
18138 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18139 if (EQ (prop
, Qscroll_bar
))
18140 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18142 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18143 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18144 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18149 if (EQ (prop
, Qleft_fringe
))
18150 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18151 if (EQ (prop
, Qright_fringe
))
18152 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18153 if (EQ (prop
, Qleft_margin
))
18154 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18155 if (EQ (prop
, Qright_margin
))
18156 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18157 if (EQ (prop
, Qscroll_bar
))
18158 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18161 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18164 if (INTEGERP (prop
) || FLOATP (prop
))
18166 int base_unit
= (width_p
18167 ? FRAME_COLUMN_WIDTH (it
->f
)
18168 : FRAME_LINE_HEIGHT (it
->f
));
18169 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18174 Lisp_Object car
= XCAR (prop
);
18175 Lisp_Object cdr
= XCDR (prop
);
18179 #ifdef HAVE_WINDOW_SYSTEM
18180 if (FRAME_WINDOW_P (it
->f
)
18181 && valid_image_p (prop
))
18183 int id
= lookup_image (it
->f
, prop
);
18184 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18186 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18189 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18195 while (CONSP (cdr
))
18197 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18198 font
, width_p
, align_to
))
18201 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18206 if (EQ (car
, Qminus
))
18208 return OK_PIXELS (pixels
);
18211 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18214 if (INTEGERP (car
) || FLOATP (car
))
18217 pixels
= XFLOATINT (car
);
18219 return OK_PIXELS (pixels
);
18220 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18221 font
, width_p
, align_to
))
18222 return OK_PIXELS (pixels
* fact
);
18233 /***********************************************************************
18235 ***********************************************************************/
18237 #ifdef HAVE_WINDOW_SYSTEM
18242 dump_glyph_string (s
)
18243 struct glyph_string
*s
;
18245 fprintf (stderr
, "glyph string\n");
18246 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18247 s
->x
, s
->y
, s
->width
, s
->height
);
18248 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18249 fprintf (stderr
, " hl = %d\n", s
->hl
);
18250 fprintf (stderr
, " left overhang = %d, right = %d\n",
18251 s
->left_overhang
, s
->right_overhang
);
18252 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18253 fprintf (stderr
, " extends to end of line = %d\n",
18254 s
->extends_to_end_of_line_p
);
18255 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18256 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18259 #endif /* GLYPH_DEBUG */
18261 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18262 of XChar2b structures for S; it can't be allocated in
18263 init_glyph_string because it must be allocated via `alloca'. W
18264 is the window on which S is drawn. ROW and AREA are the glyph row
18265 and area within the row from which S is constructed. START is the
18266 index of the first glyph structure covered by S. HL is a
18267 face-override for drawing S. */
18270 #define OPTIONAL_HDC(hdc) hdc,
18271 #define DECLARE_HDC(hdc) HDC hdc;
18272 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18273 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18276 #ifndef OPTIONAL_HDC
18277 #define OPTIONAL_HDC(hdc)
18278 #define DECLARE_HDC(hdc)
18279 #define ALLOCATE_HDC(hdc, f)
18280 #define RELEASE_HDC(hdc, f)
18284 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18285 struct glyph_string
*s
;
18289 struct glyph_row
*row
;
18290 enum glyph_row_area area
;
18292 enum draw_glyphs_face hl
;
18294 bzero (s
, sizeof *s
);
18296 s
->f
= XFRAME (w
->frame
);
18300 s
->display
= FRAME_X_DISPLAY (s
->f
);
18301 s
->window
= FRAME_X_WINDOW (s
->f
);
18302 s
->char2b
= char2b
;
18306 s
->first_glyph
= row
->glyphs
[area
] + start
;
18307 s
->height
= row
->height
;
18308 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18310 /* Display the internal border below the tool-bar window. */
18311 if (WINDOWP (s
->f
->tool_bar_window
)
18312 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18313 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18315 s
->ybase
= s
->y
+ row
->ascent
;
18319 /* Append the list of glyph strings with head H and tail T to the list
18320 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18323 append_glyph_string_lists (head
, tail
, h
, t
)
18324 struct glyph_string
**head
, **tail
;
18325 struct glyph_string
*h
, *t
;
18339 /* Prepend the list of glyph strings with head H and tail T to the
18340 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18344 prepend_glyph_string_lists (head
, tail
, h
, t
)
18345 struct glyph_string
**head
, **tail
;
18346 struct glyph_string
*h
, *t
;
18360 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18361 Set *HEAD and *TAIL to the resulting list. */
18364 append_glyph_string (head
, tail
, s
)
18365 struct glyph_string
**head
, **tail
;
18366 struct glyph_string
*s
;
18368 s
->next
= s
->prev
= NULL
;
18369 append_glyph_string_lists (head
, tail
, s
, s
);
18373 /* Get face and two-byte form of character glyph GLYPH on frame F.
18374 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18375 a pointer to a realized face that is ready for display. */
18377 static INLINE
struct face
*
18378 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18380 struct glyph
*glyph
;
18386 xassert (glyph
->type
== CHAR_GLYPH
);
18387 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18392 if (!glyph
->multibyte_p
)
18394 /* Unibyte case. We don't have to encode, but we have to make
18395 sure to use a face suitable for unibyte. */
18396 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18398 else if (glyph
->u
.ch
< 128
18399 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18401 /* Case of ASCII in a face known to fit ASCII. */
18402 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18406 int c1
, c2
, charset
;
18408 /* Split characters into bytes. If c2 is -1 afterwards, C is
18409 really a one-byte character so that byte1 is zero. */
18410 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18412 STORE_XCHAR2B (char2b
, c1
, c2
);
18414 STORE_XCHAR2B (char2b
, 0, c1
);
18416 /* Maybe encode the character in *CHAR2B. */
18417 if (charset
!= CHARSET_ASCII
)
18419 struct font_info
*font_info
18420 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18423 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18427 /* Make sure X resources of the face are allocated. */
18428 xassert (face
!= NULL
);
18429 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18434 /* Fill glyph string S with composition components specified by S->cmp.
18436 FACES is an array of faces for all components of this composition.
18437 S->gidx is the index of the first component for S.
18439 OVERLAPS non-zero means S should draw the foreground only, and use
18440 its physical height for clipping. See also draw_glyphs.
18442 Value is the index of a component not in S. */
18445 fill_composite_glyph_string (s
, faces
, overlaps
)
18446 struct glyph_string
*s
;
18447 struct face
**faces
;
18454 s
->for_overlaps
= overlaps
;
18456 s
->face
= faces
[s
->gidx
];
18457 s
->font
= s
->face
->font
;
18458 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18460 /* For all glyphs of this composition, starting at the offset
18461 S->gidx, until we reach the end of the definition or encounter a
18462 glyph that requires the different face, add it to S. */
18464 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18467 /* All glyph strings for the same composition has the same width,
18468 i.e. the width set for the first component of the composition. */
18470 s
->width
= s
->first_glyph
->pixel_width
;
18472 /* If the specified font could not be loaded, use the frame's
18473 default font, but record the fact that we couldn't load it in
18474 the glyph string so that we can draw rectangles for the
18475 characters of the glyph string. */
18476 if (s
->font
== NULL
)
18478 s
->font_not_found_p
= 1;
18479 s
->font
= FRAME_FONT (s
->f
);
18482 /* Adjust base line for subscript/superscript text. */
18483 s
->ybase
+= s
->first_glyph
->voffset
;
18485 xassert (s
->face
&& s
->face
->gc
);
18487 /* This glyph string must always be drawn with 16-bit functions. */
18490 return s
->gidx
+ s
->nchars
;
18494 /* Fill glyph string S from a sequence of character glyphs.
18496 FACE_ID is the face id of the string. START is the index of the
18497 first glyph to consider, END is the index of the last + 1.
18498 OVERLAPS non-zero means S should draw the foreground only, and use
18499 its physical height for clipping. See also draw_glyphs.
18501 Value is the index of the first glyph not in S. */
18504 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18505 struct glyph_string
*s
;
18507 int start
, end
, overlaps
;
18509 struct glyph
*glyph
, *last
;
18511 int glyph_not_available_p
;
18513 xassert (s
->f
== XFRAME (s
->w
->frame
));
18514 xassert (s
->nchars
== 0);
18515 xassert (start
>= 0 && end
> start
);
18517 s
->for_overlaps
= overlaps
,
18518 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18519 last
= s
->row
->glyphs
[s
->area
] + end
;
18520 voffset
= glyph
->voffset
;
18522 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18524 while (glyph
< last
18525 && glyph
->type
== CHAR_GLYPH
18526 && glyph
->voffset
== voffset
18527 /* Same face id implies same font, nowadays. */
18528 && glyph
->face_id
== face_id
18529 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18533 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18534 s
->char2b
+ s
->nchars
,
18536 s
->two_byte_p
= two_byte_p
;
18538 xassert (s
->nchars
<= end
- start
);
18539 s
->width
+= glyph
->pixel_width
;
18543 s
->font
= s
->face
->font
;
18544 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18546 /* If the specified font could not be loaded, use the frame's font,
18547 but record the fact that we couldn't load it in
18548 S->font_not_found_p so that we can draw rectangles for the
18549 characters of the glyph string. */
18550 if (s
->font
== NULL
|| glyph_not_available_p
)
18552 s
->font_not_found_p
= 1;
18553 s
->font
= FRAME_FONT (s
->f
);
18556 /* Adjust base line for subscript/superscript text. */
18557 s
->ybase
+= voffset
;
18559 xassert (s
->face
&& s
->face
->gc
);
18560 return glyph
- s
->row
->glyphs
[s
->area
];
18564 /* Fill glyph string S from image glyph S->first_glyph. */
18567 fill_image_glyph_string (s
)
18568 struct glyph_string
*s
;
18570 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18571 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18573 s
->slice
= s
->first_glyph
->slice
;
18574 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18575 s
->font
= s
->face
->font
;
18576 s
->width
= s
->first_glyph
->pixel_width
;
18578 /* Adjust base line for subscript/superscript text. */
18579 s
->ybase
+= s
->first_glyph
->voffset
;
18583 /* Fill glyph string S from a sequence of stretch glyphs.
18585 ROW is the glyph row in which the glyphs are found, AREA is the
18586 area within the row. START is the index of the first glyph to
18587 consider, END is the index of the last + 1.
18589 Value is the index of the first glyph not in S. */
18592 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18593 struct glyph_string
*s
;
18594 struct glyph_row
*row
;
18595 enum glyph_row_area area
;
18598 struct glyph
*glyph
, *last
;
18599 int voffset
, face_id
;
18601 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18603 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18604 last
= s
->row
->glyphs
[s
->area
] + end
;
18605 face_id
= glyph
->face_id
;
18606 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18607 s
->font
= s
->face
->font
;
18608 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18609 s
->width
= glyph
->pixel_width
;
18610 voffset
= glyph
->voffset
;
18614 && glyph
->type
== STRETCH_GLYPH
18615 && glyph
->voffset
== voffset
18616 && glyph
->face_id
== face_id
);
18618 s
->width
+= glyph
->pixel_width
;
18620 /* Adjust base line for subscript/superscript text. */
18621 s
->ybase
+= voffset
;
18623 /* The case that face->gc == 0 is handled when drawing the glyph
18624 string by calling PREPARE_FACE_FOR_DISPLAY. */
18626 return glyph
- s
->row
->glyphs
[s
->area
];
18631 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18632 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18633 assumed to be zero. */
18636 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18637 struct glyph
*glyph
;
18641 *left
= *right
= 0;
18643 if (glyph
->type
== CHAR_GLYPH
)
18647 struct font_info
*font_info
;
18651 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18653 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18654 if (font
/* ++KFS: Should this be font_info ? */
18655 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18657 if (pcm
->rbearing
> pcm
->width
)
18658 *right
= pcm
->rbearing
- pcm
->width
;
18659 if (pcm
->lbearing
< 0)
18660 *left
= -pcm
->lbearing
;
18666 /* Return the index of the first glyph preceding glyph string S that
18667 is overwritten by S because of S's left overhang. Value is -1
18668 if no glyphs are overwritten. */
18671 left_overwritten (s
)
18672 struct glyph_string
*s
;
18676 if (s
->left_overhang
)
18679 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18680 int first
= s
->first_glyph
- glyphs
;
18682 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18683 x
-= glyphs
[i
].pixel_width
;
18694 /* Return the index of the first glyph preceding glyph string S that
18695 is overwriting S because of its right overhang. Value is -1 if no
18696 glyph in front of S overwrites S. */
18699 left_overwriting (s
)
18700 struct glyph_string
*s
;
18703 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18704 int first
= s
->first_glyph
- glyphs
;
18708 for (i
= first
- 1; i
>= 0; --i
)
18711 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18714 x
-= glyphs
[i
].pixel_width
;
18721 /* Return the index of the last glyph following glyph string S that is
18722 not overwritten by S because of S's right overhang. Value is -1 if
18723 no such glyph is found. */
18726 right_overwritten (s
)
18727 struct glyph_string
*s
;
18731 if (s
->right_overhang
)
18734 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18735 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18736 int end
= s
->row
->used
[s
->area
];
18738 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18739 x
+= glyphs
[i
].pixel_width
;
18748 /* Return the index of the last glyph following glyph string S that
18749 overwrites S because of its left overhang. Value is negative
18750 if no such glyph is found. */
18753 right_overwriting (s
)
18754 struct glyph_string
*s
;
18757 int end
= s
->row
->used
[s
->area
];
18758 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18759 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18763 for (i
= first
; i
< end
; ++i
)
18766 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18769 x
+= glyphs
[i
].pixel_width
;
18776 /* Get face and two-byte form of character C in face FACE_ID on frame
18777 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18778 means we want to display multibyte text. DISPLAY_P non-zero means
18779 make sure that X resources for the face returned are allocated.
18780 Value is a pointer to a realized face that is ready for display if
18781 DISPLAY_P is non-zero. */
18783 static INLINE
struct face
*
18784 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18788 int multibyte_p
, display_p
;
18790 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18794 /* Unibyte case. We don't have to encode, but we have to make
18795 sure to use a face suitable for unibyte. */
18796 STORE_XCHAR2B (char2b
, 0, c
);
18797 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18798 face
= FACE_FROM_ID (f
, face_id
);
18800 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18802 /* Case of ASCII in a face known to fit ASCII. */
18803 STORE_XCHAR2B (char2b
, 0, c
);
18807 int c1
, c2
, charset
;
18809 /* Split characters into bytes. If c2 is -1 afterwards, C is
18810 really a one-byte character so that byte1 is zero. */
18811 SPLIT_CHAR (c
, charset
, c1
, c2
);
18813 STORE_XCHAR2B (char2b
, c1
, c2
);
18815 STORE_XCHAR2B (char2b
, 0, c1
);
18817 /* Maybe encode the character in *CHAR2B. */
18818 if (face
->font
!= NULL
)
18820 struct font_info
*font_info
18821 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18823 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
18827 /* Make sure X resources of the face are allocated. */
18828 #ifdef HAVE_X_WINDOWS
18832 xassert (face
!= NULL
);
18833 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18840 /* Set background width of glyph string S. START is the index of the
18841 first glyph following S. LAST_X is the right-most x-position + 1
18842 in the drawing area. */
18845 set_glyph_string_background_width (s
, start
, last_x
)
18846 struct glyph_string
*s
;
18850 /* If the face of this glyph string has to be drawn to the end of
18851 the drawing area, set S->extends_to_end_of_line_p. */
18853 if (start
== s
->row
->used
[s
->area
]
18854 && s
->area
== TEXT_AREA
18855 && ((s
->row
->fill_line_p
18856 && (s
->hl
== DRAW_NORMAL_TEXT
18857 || s
->hl
== DRAW_IMAGE_RAISED
18858 || s
->hl
== DRAW_IMAGE_SUNKEN
))
18859 || s
->hl
== DRAW_MOUSE_FACE
))
18860 s
->extends_to_end_of_line_p
= 1;
18862 /* If S extends its face to the end of the line, set its
18863 background_width to the distance to the right edge of the drawing
18865 if (s
->extends_to_end_of_line_p
)
18866 s
->background_width
= last_x
- s
->x
+ 1;
18868 s
->background_width
= s
->width
;
18872 /* Compute overhangs and x-positions for glyph string S and its
18873 predecessors, or successors. X is the starting x-position for S.
18874 BACKWARD_P non-zero means process predecessors. */
18877 compute_overhangs_and_x (s
, x
, backward_p
)
18878 struct glyph_string
*s
;
18886 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
18887 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
18897 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
18898 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
18908 /* The following macros are only called from draw_glyphs below.
18909 They reference the following parameters of that function directly:
18910 `w', `row', `area', and `overlap_p'
18911 as well as the following local variables:
18912 `s', `f', and `hdc' (in W32) */
18915 /* On W32, silently add local `hdc' variable to argument list of
18916 init_glyph_string. */
18917 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18918 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18920 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18921 init_glyph_string (s, char2b, w, row, area, start, hl)
18924 /* Add a glyph string for a stretch glyph to the list of strings
18925 between HEAD and TAIL. START is the index of the stretch glyph in
18926 row area AREA of glyph row ROW. END is the index of the last glyph
18927 in that glyph row area. X is the current output position assigned
18928 to the new glyph string constructed. HL overrides that face of the
18929 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18930 is the right-most x-position of the drawing area. */
18932 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18933 and below -- keep them on one line. */
18934 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18937 s = (struct glyph_string *) alloca (sizeof *s); \
18938 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18939 START = fill_stretch_glyph_string (s, row, area, START, END); \
18940 append_glyph_string (&HEAD, &TAIL, s); \
18946 /* Add a glyph string for an image glyph to the list of strings
18947 between HEAD and TAIL. START is the index of the image glyph in
18948 row area AREA of glyph row ROW. END is the index of the last glyph
18949 in that glyph row area. X is the current output position assigned
18950 to the new glyph string constructed. HL overrides that face of the
18951 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18952 is the right-most x-position of the drawing area. */
18954 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18957 s = (struct glyph_string *) alloca (sizeof *s); \
18958 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18959 fill_image_glyph_string (s); \
18960 append_glyph_string (&HEAD, &TAIL, s); \
18967 /* Add a glyph string for a sequence of character glyphs to the list
18968 of strings between HEAD and TAIL. START is the index of the first
18969 glyph in row area AREA of glyph row ROW that is part of the new
18970 glyph string. END is the index of the last glyph in that glyph row
18971 area. X is the current output position assigned to the new glyph
18972 string constructed. HL overrides that face of the glyph; e.g. it
18973 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18974 right-most x-position of the drawing area. */
18976 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18982 c = (row)->glyphs[area][START].u.ch; \
18983 face_id = (row)->glyphs[area][START].face_id; \
18985 s = (struct glyph_string *) alloca (sizeof *s); \
18986 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18987 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18988 append_glyph_string (&HEAD, &TAIL, s); \
18990 START = fill_glyph_string (s, face_id, START, END, overlaps); \
18995 /* Add a glyph string for a composite sequence to the list of strings
18996 between HEAD and TAIL. START is the index of the first glyph in
18997 row area AREA of glyph row ROW that is part of the new glyph
18998 string. END is the index of the last glyph in that glyph row area.
18999 X is the current output position assigned to the new glyph string
19000 constructed. HL overrides that face of the glyph; e.g. it is
19001 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19002 x-position of the drawing area. */
19004 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19006 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19007 int face_id = (row)->glyphs[area][START].face_id; \
19008 struct face *base_face = FACE_FROM_ID (f, face_id); \
19009 struct composition *cmp = composition_table[cmp_id]; \
19010 int glyph_len = cmp->glyph_len; \
19012 struct face **faces; \
19013 struct glyph_string *first_s = NULL; \
19016 base_face = base_face->ascii_face; \
19017 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19018 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19019 /* At first, fill in `char2b' and `faces'. */ \
19020 for (n = 0; n < glyph_len; n++) \
19022 int c = COMPOSITION_GLYPH (cmp, n); \
19023 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19024 faces[n] = FACE_FROM_ID (f, this_face_id); \
19025 get_char_face_and_encoding (f, c, this_face_id, \
19026 char2b + n, 1, 1); \
19029 /* Make glyph_strings for each glyph sequence that is drawable by \
19030 the same face, and append them to HEAD/TAIL. */ \
19031 for (n = 0; n < cmp->glyph_len;) \
19033 s = (struct glyph_string *) alloca (sizeof *s); \
19034 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19035 append_glyph_string (&(HEAD), &(TAIL), s); \
19043 n = fill_composite_glyph_string (s, faces, overlaps); \
19051 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19052 of AREA of glyph row ROW on window W between indices START and END.
19053 HL overrides the face for drawing glyph strings, e.g. it is
19054 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19055 x-positions of the drawing area.
19057 This is an ugly monster macro construct because we must use alloca
19058 to allocate glyph strings (because draw_glyphs can be called
19059 asynchronously). */
19061 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19064 HEAD = TAIL = NULL; \
19065 while (START < END) \
19067 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19068 switch (first_glyph->type) \
19071 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19075 case COMPOSITE_GLYPH: \
19076 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19080 case STRETCH_GLYPH: \
19081 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19085 case IMAGE_GLYPH: \
19086 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19094 set_glyph_string_background_width (s, START, LAST_X); \
19101 /* Draw glyphs between START and END in AREA of ROW on window W,
19102 starting at x-position X. X is relative to AREA in W. HL is a
19103 face-override with the following meaning:
19105 DRAW_NORMAL_TEXT draw normally
19106 DRAW_CURSOR draw in cursor face
19107 DRAW_MOUSE_FACE draw in mouse face.
19108 DRAW_INVERSE_VIDEO draw in mode line face
19109 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19110 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19112 If OVERLAPS is non-zero, draw only the foreground of characters and
19113 clip to the physical height of ROW. Non-zero value also defines
19114 the overlapping part to be drawn:
19116 OVERLAPS_PRED overlap with preceding rows
19117 OVERLAPS_SUCC overlap with succeeding rows
19118 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19119 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19121 Value is the x-position reached, relative to AREA of W. */
19124 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19127 struct glyph_row
*row
;
19128 enum glyph_row_area area
;
19130 enum draw_glyphs_face hl
;
19133 struct glyph_string
*head
, *tail
;
19134 struct glyph_string
*s
;
19135 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19136 int last_x
, area_width
;
19139 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19142 ALLOCATE_HDC (hdc
, f
);
19144 /* Let's rather be paranoid than getting a SEGV. */
19145 end
= min (end
, row
->used
[area
]);
19146 start
= max (0, start
);
19147 start
= min (end
, start
);
19149 /* Translate X to frame coordinates. Set last_x to the right
19150 end of the drawing area. */
19151 if (row
->full_width_p
)
19153 /* X is relative to the left edge of W, without scroll bars
19155 x
+= WINDOW_LEFT_EDGE_X (w
);
19156 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19160 int area_left
= window_box_left (w
, area
);
19162 area_width
= window_box_width (w
, area
);
19163 last_x
= area_left
+ area_width
;
19166 /* Build a doubly-linked list of glyph_string structures between
19167 head and tail from what we have to draw. Note that the macro
19168 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19169 the reason we use a separate variable `i'. */
19171 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19173 x_reached
= tail
->x
+ tail
->background_width
;
19177 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19178 the row, redraw some glyphs in front or following the glyph
19179 strings built above. */
19180 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19183 struct glyph_string
*h
, *t
;
19185 /* Compute overhangs for all glyph strings. */
19186 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
19187 for (s
= head
; s
; s
= s
->next
)
19188 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
19190 /* Prepend glyph strings for glyphs in front of the first glyph
19191 string that are overwritten because of the first glyph
19192 string's left overhang. The background of all strings
19193 prepended must be drawn because the first glyph string
19195 i
= left_overwritten (head
);
19199 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19200 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19202 compute_overhangs_and_x (t
, head
->x
, 1);
19203 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19207 /* Prepend glyph strings for glyphs in front of the first glyph
19208 string that overwrite that glyph string because of their
19209 right overhang. For these strings, only the foreground must
19210 be drawn, because it draws over the glyph string at `head'.
19211 The background must not be drawn because this would overwrite
19212 right overhangs of preceding glyphs for which no glyph
19214 i
= left_overwriting (head
);
19218 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19219 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19220 for (s
= h
; s
; s
= s
->next
)
19221 s
->background_filled_p
= 1;
19222 compute_overhangs_and_x (t
, head
->x
, 1);
19223 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19226 /* Append glyphs strings for glyphs following the last glyph
19227 string tail that are overwritten by tail. The background of
19228 these strings has to be drawn because tail's foreground draws
19230 i
= right_overwritten (tail
);
19233 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19234 DRAW_NORMAL_TEXT
, x
, last_x
);
19235 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19236 append_glyph_string_lists (&head
, &tail
, h
, t
);
19240 /* Append glyph strings for glyphs following the last glyph
19241 string tail that overwrite tail. The foreground of such
19242 glyphs has to be drawn because it writes into the background
19243 of tail. The background must not be drawn because it could
19244 paint over the foreground of following glyphs. */
19245 i
= right_overwriting (tail
);
19249 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19250 DRAW_NORMAL_TEXT
, x
, last_x
);
19251 for (s
= h
; s
; s
= s
->next
)
19252 s
->background_filled_p
= 1;
19253 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19254 append_glyph_string_lists (&head
, &tail
, h
, t
);
19256 if (clip_head
|| clip_tail
)
19257 for (s
= head
; s
; s
= s
->next
)
19259 s
->clip_head
= clip_head
;
19260 s
->clip_tail
= clip_tail
;
19264 /* Draw all strings. */
19265 for (s
= head
; s
; s
= s
->next
)
19266 FRAME_RIF (f
)->draw_glyph_string (s
);
19268 if (area
== TEXT_AREA
19269 && !row
->full_width_p
19270 /* When drawing overlapping rows, only the glyph strings'
19271 foreground is drawn, which doesn't erase a cursor
19275 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19276 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19277 : (tail
? tail
->x
+ tail
->background_width
: x
));
19279 int text_left
= window_box_left (w
, TEXT_AREA
);
19283 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19284 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19287 /* Value is the x-position up to which drawn, relative to AREA of W.
19288 This doesn't include parts drawn because of overhangs. */
19289 if (row
->full_width_p
)
19290 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19292 x_reached
-= window_box_left (w
, area
);
19294 RELEASE_HDC (hdc
, f
);
19299 /* Expand row matrix if too narrow. Don't expand if area
19302 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19304 if (!fonts_changed_p \
19305 && (it->glyph_row->glyphs[area] \
19306 < it->glyph_row->glyphs[area + 1])) \
19308 it->w->ncols_scale_factor++; \
19309 fonts_changed_p = 1; \
19313 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19314 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19320 struct glyph
*glyph
;
19321 enum glyph_row_area area
= it
->area
;
19323 xassert (it
->glyph_row
);
19324 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19326 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19327 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19329 glyph
->charpos
= CHARPOS (it
->position
);
19330 glyph
->object
= it
->object
;
19331 glyph
->pixel_width
= it
->pixel_width
;
19332 glyph
->ascent
= it
->ascent
;
19333 glyph
->descent
= it
->descent
;
19334 glyph
->voffset
= it
->voffset
;
19335 glyph
->type
= CHAR_GLYPH
;
19336 glyph
->multibyte_p
= it
->multibyte_p
;
19337 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19338 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19339 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19340 || it
->phys_descent
> it
->descent
);
19341 glyph
->padding_p
= 0;
19342 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19343 glyph
->face_id
= it
->face_id
;
19344 glyph
->u
.ch
= it
->char_to_display
;
19345 glyph
->slice
= null_glyph_slice
;
19346 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19347 ++it
->glyph_row
->used
[area
];
19350 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19353 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19354 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19357 append_composite_glyph (it
)
19360 struct glyph
*glyph
;
19361 enum glyph_row_area area
= it
->area
;
19363 xassert (it
->glyph_row
);
19365 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19366 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19368 glyph
->charpos
= CHARPOS (it
->position
);
19369 glyph
->object
= it
->object
;
19370 glyph
->pixel_width
= it
->pixel_width
;
19371 glyph
->ascent
= it
->ascent
;
19372 glyph
->descent
= it
->descent
;
19373 glyph
->voffset
= it
->voffset
;
19374 glyph
->type
= COMPOSITE_GLYPH
;
19375 glyph
->multibyte_p
= it
->multibyte_p
;
19376 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19377 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19378 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19379 || it
->phys_descent
> it
->descent
);
19380 glyph
->padding_p
= 0;
19381 glyph
->glyph_not_available_p
= 0;
19382 glyph
->face_id
= it
->face_id
;
19383 glyph
->u
.cmp_id
= it
->cmp_id
;
19384 glyph
->slice
= null_glyph_slice
;
19385 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19386 ++it
->glyph_row
->used
[area
];
19389 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19393 /* Change IT->ascent and IT->height according to the setting of
19397 take_vertical_position_into_account (it
)
19402 if (it
->voffset
< 0)
19403 /* Increase the ascent so that we can display the text higher
19405 it
->ascent
-= it
->voffset
;
19407 /* Increase the descent so that we can display the text lower
19409 it
->descent
+= it
->voffset
;
19414 /* Produce glyphs/get display metrics for the image IT is loaded with.
19415 See the description of struct display_iterator in dispextern.h for
19416 an overview of struct display_iterator. */
19419 produce_image_glyph (it
)
19425 struct glyph_slice slice
;
19427 xassert (it
->what
== IT_IMAGE
);
19429 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19431 /* Make sure X resources of the face is loaded. */
19432 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19434 if (it
->image_id
< 0)
19436 /* Fringe bitmap. */
19437 it
->ascent
= it
->phys_ascent
= 0;
19438 it
->descent
= it
->phys_descent
= 0;
19439 it
->pixel_width
= 0;
19444 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19446 /* Make sure X resources of the image is loaded. */
19447 prepare_image_for_display (it
->f
, img
);
19449 slice
.x
= slice
.y
= 0;
19450 slice
.width
= img
->width
;
19451 slice
.height
= img
->height
;
19453 if (INTEGERP (it
->slice
.x
))
19454 slice
.x
= XINT (it
->slice
.x
);
19455 else if (FLOATP (it
->slice
.x
))
19456 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19458 if (INTEGERP (it
->slice
.y
))
19459 slice
.y
= XINT (it
->slice
.y
);
19460 else if (FLOATP (it
->slice
.y
))
19461 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19463 if (INTEGERP (it
->slice
.width
))
19464 slice
.width
= XINT (it
->slice
.width
);
19465 else if (FLOATP (it
->slice
.width
))
19466 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19468 if (INTEGERP (it
->slice
.height
))
19469 slice
.height
= XINT (it
->slice
.height
);
19470 else if (FLOATP (it
->slice
.height
))
19471 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19473 if (slice
.x
>= img
->width
)
19474 slice
.x
= img
->width
;
19475 if (slice
.y
>= img
->height
)
19476 slice
.y
= img
->height
;
19477 if (slice
.x
+ slice
.width
>= img
->width
)
19478 slice
.width
= img
->width
- slice
.x
;
19479 if (slice
.y
+ slice
.height
> img
->height
)
19480 slice
.height
= img
->height
- slice
.y
;
19482 if (slice
.width
== 0 || slice
.height
== 0)
19485 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19487 it
->descent
= slice
.height
- glyph_ascent
;
19489 it
->descent
+= img
->vmargin
;
19490 if (slice
.y
+ slice
.height
== img
->height
)
19491 it
->descent
+= img
->vmargin
;
19492 it
->phys_descent
= it
->descent
;
19494 it
->pixel_width
= slice
.width
;
19496 it
->pixel_width
+= img
->hmargin
;
19497 if (slice
.x
+ slice
.width
== img
->width
)
19498 it
->pixel_width
+= img
->hmargin
;
19500 /* It's quite possible for images to have an ascent greater than
19501 their height, so don't get confused in that case. */
19502 if (it
->descent
< 0)
19505 #if 0 /* this breaks image tiling */
19506 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19507 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19508 if (face_ascent
> it
->ascent
)
19509 it
->ascent
= it
->phys_ascent
= face_ascent
;
19514 if (face
->box
!= FACE_NO_BOX
)
19516 if (face
->box_line_width
> 0)
19519 it
->ascent
+= face
->box_line_width
;
19520 if (slice
.y
+ slice
.height
== img
->height
)
19521 it
->descent
+= face
->box_line_width
;
19524 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19525 it
->pixel_width
+= abs (face
->box_line_width
);
19526 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19527 it
->pixel_width
+= abs (face
->box_line_width
);
19530 take_vertical_position_into_account (it
);
19534 struct glyph
*glyph
;
19535 enum glyph_row_area area
= it
->area
;
19537 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19538 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19540 glyph
->charpos
= CHARPOS (it
->position
);
19541 glyph
->object
= it
->object
;
19542 glyph
->pixel_width
= it
->pixel_width
;
19543 glyph
->ascent
= glyph_ascent
;
19544 glyph
->descent
= it
->descent
;
19545 glyph
->voffset
= it
->voffset
;
19546 glyph
->type
= IMAGE_GLYPH
;
19547 glyph
->multibyte_p
= it
->multibyte_p
;
19548 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19549 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19550 glyph
->overlaps_vertically_p
= 0;
19551 glyph
->padding_p
= 0;
19552 glyph
->glyph_not_available_p
= 0;
19553 glyph
->face_id
= it
->face_id
;
19554 glyph
->u
.img_id
= img
->id
;
19555 glyph
->slice
= slice
;
19556 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19557 ++it
->glyph_row
->used
[area
];
19560 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19565 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19566 of the glyph, WIDTH and HEIGHT are the width and height of the
19567 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19570 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19572 Lisp_Object object
;
19576 struct glyph
*glyph
;
19577 enum glyph_row_area area
= it
->area
;
19579 xassert (ascent
>= 0 && ascent
<= height
);
19581 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19582 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19584 glyph
->charpos
= CHARPOS (it
->position
);
19585 glyph
->object
= object
;
19586 glyph
->pixel_width
= width
;
19587 glyph
->ascent
= ascent
;
19588 glyph
->descent
= height
- ascent
;
19589 glyph
->voffset
= it
->voffset
;
19590 glyph
->type
= STRETCH_GLYPH
;
19591 glyph
->multibyte_p
= it
->multibyte_p
;
19592 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19593 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19594 glyph
->overlaps_vertically_p
= 0;
19595 glyph
->padding_p
= 0;
19596 glyph
->glyph_not_available_p
= 0;
19597 glyph
->face_id
= it
->face_id
;
19598 glyph
->u
.stretch
.ascent
= ascent
;
19599 glyph
->u
.stretch
.height
= height
;
19600 glyph
->slice
= null_glyph_slice
;
19601 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19602 ++it
->glyph_row
->used
[area
];
19605 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19609 /* Produce a stretch glyph for iterator IT. IT->object is the value
19610 of the glyph property displayed. The value must be a list
19611 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19614 1. `:width WIDTH' specifies that the space should be WIDTH *
19615 canonical char width wide. WIDTH may be an integer or floating
19618 2. `:relative-width FACTOR' specifies that the width of the stretch
19619 should be computed from the width of the first character having the
19620 `glyph' property, and should be FACTOR times that width.
19622 3. `:align-to HPOS' specifies that the space should be wide enough
19623 to reach HPOS, a value in canonical character units.
19625 Exactly one of the above pairs must be present.
19627 4. `:height HEIGHT' specifies that the height of the stretch produced
19628 should be HEIGHT, measured in canonical character units.
19630 5. `:relative-height FACTOR' specifies that the height of the
19631 stretch should be FACTOR times the height of the characters having
19632 the glyph property.
19634 Either none or exactly one of 4 or 5 must be present.
19636 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19637 of the stretch should be used for the ascent of the stretch.
19638 ASCENT must be in the range 0 <= ASCENT <= 100. */
19641 produce_stretch_glyph (it
)
19644 /* (space :width WIDTH :height HEIGHT ...) */
19645 Lisp_Object prop
, plist
;
19646 int width
= 0, height
= 0, align_to
= -1;
19647 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19650 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19651 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19653 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19655 /* List should start with `space'. */
19656 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19657 plist
= XCDR (it
->object
);
19659 /* Compute the width of the stretch. */
19660 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19661 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19663 /* Absolute width `:width WIDTH' specified and valid. */
19664 zero_width_ok_p
= 1;
19667 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19670 /* Relative width `:relative-width FACTOR' specified and valid.
19671 Compute the width of the characters having the `glyph'
19674 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19677 if (it
->multibyte_p
)
19679 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19680 - IT_BYTEPOS (*it
));
19681 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19684 it2
.c
= *p
, it2
.len
= 1;
19686 it2
.glyph_row
= NULL
;
19687 it2
.what
= IT_CHARACTER
;
19688 x_produce_glyphs (&it2
);
19689 width
= NUMVAL (prop
) * it2
.pixel_width
;
19691 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19692 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19694 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19695 align_to
= (align_to
< 0
19697 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19698 else if (align_to
< 0)
19699 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19700 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19701 zero_width_ok_p
= 1;
19704 /* Nothing specified -> width defaults to canonical char width. */
19705 width
= FRAME_COLUMN_WIDTH (it
->f
);
19707 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19710 /* Compute height. */
19711 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19712 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19715 zero_height_ok_p
= 1;
19717 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19719 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19721 height
= FONT_HEIGHT (font
);
19723 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19726 /* Compute percentage of height used for ascent. If
19727 `:ascent ASCENT' is present and valid, use that. Otherwise,
19728 derive the ascent from the font in use. */
19729 if (prop
= Fplist_get (plist
, QCascent
),
19730 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19731 ascent
= height
* NUMVAL (prop
) / 100.0;
19732 else if (!NILP (prop
)
19733 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19734 ascent
= min (max (0, (int)tem
), height
);
19736 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19738 if (width
> 0 && !it
->truncate_lines_p
19739 && it
->current_x
+ width
> it
->last_visible_x
)
19740 width
= it
->last_visible_x
- it
->current_x
- 1;
19742 if (width
> 0 && height
> 0 && it
->glyph_row
)
19744 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19745 if (!STRINGP (object
))
19746 object
= it
->w
->buffer
;
19747 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19750 it
->pixel_width
= width
;
19751 it
->ascent
= it
->phys_ascent
= ascent
;
19752 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19753 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19755 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19757 if (face
->box_line_width
> 0)
19759 it
->ascent
+= face
->box_line_width
;
19760 it
->descent
+= face
->box_line_width
;
19763 if (it
->start_of_box_run_p
)
19764 it
->pixel_width
+= abs (face
->box_line_width
);
19765 if (it
->end_of_box_run_p
)
19766 it
->pixel_width
+= abs (face
->box_line_width
);
19769 take_vertical_position_into_account (it
);
19772 /* Get line-height and line-spacing property at point.
19773 If line-height has format (HEIGHT TOTAL), return TOTAL
19774 in TOTAL_HEIGHT. */
19777 get_line_height_property (it
, prop
)
19781 Lisp_Object position
;
19783 if (STRINGP (it
->object
))
19784 position
= make_number (IT_STRING_CHARPOS (*it
));
19785 else if (BUFFERP (it
->object
))
19786 position
= make_number (IT_CHARPOS (*it
));
19790 return Fget_char_property (position
, prop
, it
->object
);
19793 /* Calculate line-height and line-spacing properties.
19794 An integer value specifies explicit pixel value.
19795 A float value specifies relative value to current face height.
19796 A cons (float . face-name) specifies relative value to
19797 height of specified face font.
19799 Returns height in pixels, or nil. */
19803 calc_line_height_property (it
, val
, font
, boff
, override
)
19807 int boff
, override
;
19809 Lisp_Object face_name
= Qnil
;
19810 int ascent
, descent
, height
;
19812 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19817 face_name
= XCAR (val
);
19819 if (!NUMBERP (val
))
19820 val
= make_number (1);
19821 if (NILP (face_name
))
19823 height
= it
->ascent
+ it
->descent
;
19828 if (NILP (face_name
))
19830 font
= FRAME_FONT (it
->f
);
19831 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19833 else if (EQ (face_name
, Qt
))
19841 struct font_info
*font_info
;
19843 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19845 return make_number (-1);
19847 face
= FACE_FROM_ID (it
->f
, face_id
);
19850 return make_number (-1);
19852 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19853 boff
= font_info
->baseline_offset
;
19854 if (font_info
->vertical_centering
)
19855 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19858 ascent
= FONT_BASE (font
) + boff
;
19859 descent
= FONT_DESCENT (font
) - boff
;
19863 it
->override_ascent
= ascent
;
19864 it
->override_descent
= descent
;
19865 it
->override_boff
= boff
;
19868 height
= ascent
+ descent
;
19872 height
= (int)(XFLOAT_DATA (val
) * height
);
19873 else if (INTEGERP (val
))
19874 height
*= XINT (val
);
19876 return make_number (height
);
19881 Produce glyphs/get display metrics for the display element IT is
19882 loaded with. See the description of struct it in dispextern.h
19883 for an overview of struct it. */
19886 x_produce_glyphs (it
)
19889 int extra_line_spacing
= it
->extra_line_spacing
;
19891 it
->glyph_not_available_p
= 0;
19893 if (it
->what
== IT_CHARACTER
)
19897 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19899 int font_not_found_p
;
19900 struct font_info
*font_info
;
19901 int boff
; /* baseline offset */
19902 /* We may change it->multibyte_p upon unibyte<->multibyte
19903 conversion. So, save the current value now and restore it
19906 Note: It seems that we don't have to record multibyte_p in
19907 struct glyph because the character code itself tells if or
19908 not the character is multibyte. Thus, in the future, we must
19909 consider eliminating the field `multibyte_p' in the struct
19911 int saved_multibyte_p
= it
->multibyte_p
;
19913 /* Maybe translate single-byte characters to multibyte, or the
19915 it
->char_to_display
= it
->c
;
19916 if (!ASCII_BYTE_P (it
->c
))
19918 if (unibyte_display_via_language_environment
19919 && SINGLE_BYTE_CHAR_P (it
->c
)
19921 || !NILP (Vnonascii_translation_table
)))
19923 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19924 it
->multibyte_p
= 1;
19925 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19926 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19928 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19929 && !it
->multibyte_p
)
19931 it
->multibyte_p
= 1;
19932 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19933 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19937 /* Get font to use. Encode IT->char_to_display. */
19938 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19939 &char2b
, it
->multibyte_p
, 0);
19942 /* When no suitable font found, use the default font. */
19943 font_not_found_p
= font
== NULL
;
19944 if (font_not_found_p
)
19946 font
= FRAME_FONT (it
->f
);
19947 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19952 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19953 boff
= font_info
->baseline_offset
;
19954 if (font_info
->vertical_centering
)
19955 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19958 if (it
->char_to_display
>= ' '
19959 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19961 /* Either unibyte or ASCII. */
19966 pcm
= FRAME_RIF (it
->f
)->per_char_metric
19967 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19969 if (it
->override_ascent
>= 0)
19971 it
->ascent
= it
->override_ascent
;
19972 it
->descent
= it
->override_descent
;
19973 boff
= it
->override_boff
;
19977 it
->ascent
= FONT_BASE (font
) + boff
;
19978 it
->descent
= FONT_DESCENT (font
) - boff
;
19983 it
->phys_ascent
= pcm
->ascent
+ boff
;
19984 it
->phys_descent
= pcm
->descent
- boff
;
19985 it
->pixel_width
= pcm
->width
;
19989 it
->glyph_not_available_p
= 1;
19990 it
->phys_ascent
= it
->ascent
;
19991 it
->phys_descent
= it
->descent
;
19992 it
->pixel_width
= FONT_WIDTH (font
);
19995 if (it
->constrain_row_ascent_descent_p
)
19997 if (it
->descent
> it
->max_descent
)
19999 it
->ascent
+= it
->descent
- it
->max_descent
;
20000 it
->descent
= it
->max_descent
;
20002 if (it
->ascent
> it
->max_ascent
)
20004 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20005 it
->ascent
= it
->max_ascent
;
20007 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20008 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20009 extra_line_spacing
= 0;
20012 /* If this is a space inside a region of text with
20013 `space-width' property, change its width. */
20014 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20016 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20018 /* If face has a box, add the box thickness to the character
20019 height. If character has a box line to the left and/or
20020 right, add the box line width to the character's width. */
20021 if (face
->box
!= FACE_NO_BOX
)
20023 int thick
= face
->box_line_width
;
20027 it
->ascent
+= thick
;
20028 it
->descent
+= thick
;
20033 if (it
->start_of_box_run_p
)
20034 it
->pixel_width
+= thick
;
20035 if (it
->end_of_box_run_p
)
20036 it
->pixel_width
+= thick
;
20039 /* If face has an overline, add the height of the overline
20040 (1 pixel) and a 1 pixel margin to the character height. */
20041 if (face
->overline_p
)
20044 if (it
->constrain_row_ascent_descent_p
)
20046 if (it
->ascent
> it
->max_ascent
)
20047 it
->ascent
= it
->max_ascent
;
20048 if (it
->descent
> it
->max_descent
)
20049 it
->descent
= it
->max_descent
;
20052 take_vertical_position_into_account (it
);
20054 /* If we have to actually produce glyphs, do it. */
20059 /* Translate a space with a `space-width' property
20060 into a stretch glyph. */
20061 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20062 / FONT_HEIGHT (font
));
20063 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20064 it
->ascent
+ it
->descent
, ascent
);
20069 /* If characters with lbearing or rbearing are displayed
20070 in this line, record that fact in a flag of the
20071 glyph row. This is used to optimize X output code. */
20072 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20073 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20076 else if (it
->char_to_display
== '\n')
20078 /* A newline has no width but we need the height of the line.
20079 But if previous part of the line set a height, don't
20080 increase that height */
20082 Lisp_Object height
;
20083 Lisp_Object total_height
= Qnil
;
20085 it
->override_ascent
= -1;
20086 it
->pixel_width
= 0;
20089 height
= get_line_height_property(it
, Qline_height
);
20090 /* Split (line-height total-height) list */
20092 && CONSP (XCDR (height
))
20093 && NILP (XCDR (XCDR (height
))))
20095 total_height
= XCAR (XCDR (height
));
20096 height
= XCAR (height
);
20098 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20100 if (it
->override_ascent
>= 0)
20102 it
->ascent
= it
->override_ascent
;
20103 it
->descent
= it
->override_descent
;
20104 boff
= it
->override_boff
;
20108 it
->ascent
= FONT_BASE (font
) + boff
;
20109 it
->descent
= FONT_DESCENT (font
) - boff
;
20112 if (EQ (height
, Qt
))
20114 if (it
->descent
> it
->max_descent
)
20116 it
->ascent
+= it
->descent
- it
->max_descent
;
20117 it
->descent
= it
->max_descent
;
20119 if (it
->ascent
> it
->max_ascent
)
20121 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20122 it
->ascent
= it
->max_ascent
;
20124 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20125 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20126 it
->constrain_row_ascent_descent_p
= 1;
20127 extra_line_spacing
= 0;
20131 Lisp_Object spacing
;
20133 it
->phys_ascent
= it
->ascent
;
20134 it
->phys_descent
= it
->descent
;
20136 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20137 && face
->box
!= FACE_NO_BOX
20138 && face
->box_line_width
> 0)
20140 it
->ascent
+= face
->box_line_width
;
20141 it
->descent
+= face
->box_line_width
;
20144 && XINT (height
) > it
->ascent
+ it
->descent
)
20145 it
->ascent
= XINT (height
) - it
->descent
;
20147 if (!NILP (total_height
))
20148 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20151 spacing
= get_line_height_property(it
, Qline_spacing
);
20152 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20154 if (INTEGERP (spacing
))
20156 extra_line_spacing
= XINT (spacing
);
20157 if (!NILP (total_height
))
20158 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20162 else if (it
->char_to_display
== '\t')
20164 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20165 int x
= it
->current_x
+ it
->continuation_lines_width
;
20166 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20168 /* If the distance from the current position to the next tab
20169 stop is less than a space character width, use the
20170 tab stop after that. */
20171 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20172 next_tab_x
+= tab_width
;
20174 it
->pixel_width
= next_tab_x
- x
;
20176 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20177 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20181 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20182 it
->ascent
+ it
->descent
, it
->ascent
);
20187 /* A multi-byte character. Assume that the display width of the
20188 character is the width of the character multiplied by the
20189 width of the font. */
20191 /* If we found a font, this font should give us the right
20192 metrics. If we didn't find a font, use the frame's
20193 default font and calculate the width of the character
20194 from the charset width; this is what old redisplay code
20197 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20198 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20200 if (font_not_found_p
|| !pcm
)
20202 int charset
= CHAR_CHARSET (it
->char_to_display
);
20204 it
->glyph_not_available_p
= 1;
20205 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20206 * CHARSET_WIDTH (charset
));
20207 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20208 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20212 it
->pixel_width
= pcm
->width
;
20213 it
->phys_ascent
= pcm
->ascent
+ boff
;
20214 it
->phys_descent
= pcm
->descent
- boff
;
20216 && (pcm
->lbearing
< 0
20217 || pcm
->rbearing
> pcm
->width
))
20218 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20221 it
->ascent
= FONT_BASE (font
) + boff
;
20222 it
->descent
= FONT_DESCENT (font
) - boff
;
20223 if (face
->box
!= FACE_NO_BOX
)
20225 int thick
= face
->box_line_width
;
20229 it
->ascent
+= thick
;
20230 it
->descent
+= thick
;
20235 if (it
->start_of_box_run_p
)
20236 it
->pixel_width
+= thick
;
20237 if (it
->end_of_box_run_p
)
20238 it
->pixel_width
+= thick
;
20241 /* If face has an overline, add the height of the overline
20242 (1 pixel) and a 1 pixel margin to the character height. */
20243 if (face
->overline_p
)
20246 take_vertical_position_into_account (it
);
20251 it
->multibyte_p
= saved_multibyte_p
;
20253 else if (it
->what
== IT_COMPOSITION
)
20255 /* Note: A composition is represented as one glyph in the
20256 glyph matrix. There are no padding glyphs. */
20259 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20261 int font_not_found_p
;
20262 struct font_info
*font_info
;
20263 int boff
; /* baseline offset */
20264 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20266 /* Maybe translate single-byte characters to multibyte. */
20267 it
->char_to_display
= it
->c
;
20268 if (unibyte_display_via_language_environment
20269 && SINGLE_BYTE_CHAR_P (it
->c
)
20272 && !NILP (Vnonascii_translation_table
))))
20274 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20277 /* Get face and font to use. Encode IT->char_to_display. */
20278 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20279 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20280 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20281 &char2b
, it
->multibyte_p
, 0);
20284 /* When no suitable font found, use the default font. */
20285 font_not_found_p
= font
== NULL
;
20286 if (font_not_found_p
)
20288 font
= FRAME_FONT (it
->f
);
20289 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20294 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20295 boff
= font_info
->baseline_offset
;
20296 if (font_info
->vertical_centering
)
20297 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20300 /* There are no padding glyphs, so there is only one glyph to
20301 produce for the composition. Important is that pixel_width,
20302 ascent and descent are the values of what is drawn by
20303 draw_glyphs (i.e. the values of the overall glyphs composed). */
20306 /* If we have not yet calculated pixel size data of glyphs of
20307 the composition for the current face font, calculate them
20308 now. Theoretically, we have to check all fonts for the
20309 glyphs, but that requires much time and memory space. So,
20310 here we check only the font of the first glyph. This leads
20311 to incorrect display very rarely, and C-l (recenter) can
20312 correct the display anyway. */
20313 if (cmp
->font
!= (void *) font
)
20315 /* Ascent and descent of the font of the first character of
20316 this composition (adjusted by baseline offset). Ascent
20317 and descent of overall glyphs should not be less than
20318 them respectively. */
20319 int font_ascent
= FONT_BASE (font
) + boff
;
20320 int font_descent
= FONT_DESCENT (font
) - boff
;
20321 /* Bounding box of the overall glyphs. */
20322 int leftmost
, rightmost
, lowest
, highest
;
20323 int i
, width
, ascent
, descent
;
20325 cmp
->font
= (void *) font
;
20327 /* Initialize the bounding box. */
20329 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20330 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20332 width
= pcm
->width
;
20333 ascent
= pcm
->ascent
;
20334 descent
= pcm
->descent
;
20338 width
= FONT_WIDTH (font
);
20339 ascent
= FONT_BASE (font
);
20340 descent
= FONT_DESCENT (font
);
20344 lowest
= - descent
+ boff
;
20345 highest
= ascent
+ boff
;
20349 && font_info
->default_ascent
20350 && CHAR_TABLE_P (Vuse_default_ascent
)
20351 && !NILP (Faref (Vuse_default_ascent
,
20352 make_number (it
->char_to_display
))))
20353 highest
= font_info
->default_ascent
+ boff
;
20355 /* Draw the first glyph at the normal position. It may be
20356 shifted to right later if some other glyphs are drawn at
20358 cmp
->offsets
[0] = 0;
20359 cmp
->offsets
[1] = boff
;
20361 /* Set cmp->offsets for the remaining glyphs. */
20362 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20364 int left
, right
, btm
, top
;
20365 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20366 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20368 face
= FACE_FROM_ID (it
->f
, face_id
);
20369 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20370 &char2b
, it
->multibyte_p
, 0);
20374 font
= FRAME_FONT (it
->f
);
20375 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20381 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20382 boff
= font_info
->baseline_offset
;
20383 if (font_info
->vertical_centering
)
20384 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20388 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20389 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20391 width
= pcm
->width
;
20392 ascent
= pcm
->ascent
;
20393 descent
= pcm
->descent
;
20397 width
= FONT_WIDTH (font
);
20402 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20404 /* Relative composition with or without
20405 alternate chars. */
20406 left
= (leftmost
+ rightmost
- width
) / 2;
20407 btm
= - descent
+ boff
;
20408 if (font_info
&& font_info
->relative_compose
20409 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20410 || NILP (Faref (Vignore_relative_composition
,
20411 make_number (ch
)))))
20414 if (- descent
>= font_info
->relative_compose
)
20415 /* One extra pixel between two glyphs. */
20417 else if (ascent
<= 0)
20418 /* One extra pixel between two glyphs. */
20419 btm
= lowest
- 1 - ascent
- descent
;
20424 /* A composition rule is specified by an integer
20425 value that encodes global and new reference
20426 points (GREF and NREF). GREF and NREF are
20427 specified by numbers as below:
20429 0---1---2 -- ascent
20433 9--10--11 -- center
20435 ---3---4---5--- baseline
20437 6---7---8 -- descent
20439 int rule
= COMPOSITION_RULE (cmp
, i
);
20440 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20442 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20443 grefx
= gref
% 3, nrefx
= nref
% 3;
20444 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20447 + grefx
* (rightmost
- leftmost
) / 2
20448 - nrefx
* width
/ 2);
20449 btm
= ((grefy
== 0 ? highest
20451 : grefy
== 2 ? lowest
20452 : (highest
+ lowest
) / 2)
20453 - (nrefy
== 0 ? ascent
+ descent
20454 : nrefy
== 1 ? descent
- boff
20456 : (ascent
+ descent
) / 2));
20459 cmp
->offsets
[i
* 2] = left
;
20460 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20462 /* Update the bounding box of the overall glyphs. */
20463 right
= left
+ width
;
20464 top
= btm
+ descent
+ ascent
;
20465 if (left
< leftmost
)
20467 if (right
> rightmost
)
20475 /* If there are glyphs whose x-offsets are negative,
20476 shift all glyphs to the right and make all x-offsets
20480 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20481 cmp
->offsets
[i
* 2] -= leftmost
;
20482 rightmost
-= leftmost
;
20485 cmp
->pixel_width
= rightmost
;
20486 cmp
->ascent
= highest
;
20487 cmp
->descent
= - lowest
;
20488 if (cmp
->ascent
< font_ascent
)
20489 cmp
->ascent
= font_ascent
;
20490 if (cmp
->descent
< font_descent
)
20491 cmp
->descent
= font_descent
;
20494 it
->pixel_width
= cmp
->pixel_width
;
20495 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20496 it
->descent
= it
->phys_descent
= cmp
->descent
;
20498 if (face
->box
!= FACE_NO_BOX
)
20500 int thick
= face
->box_line_width
;
20504 it
->ascent
+= thick
;
20505 it
->descent
+= thick
;
20510 if (it
->start_of_box_run_p
)
20511 it
->pixel_width
+= thick
;
20512 if (it
->end_of_box_run_p
)
20513 it
->pixel_width
+= thick
;
20516 /* If face has an overline, add the height of the overline
20517 (1 pixel) and a 1 pixel margin to the character height. */
20518 if (face
->overline_p
)
20521 take_vertical_position_into_account (it
);
20524 append_composite_glyph (it
);
20526 else if (it
->what
== IT_IMAGE
)
20527 produce_image_glyph (it
);
20528 else if (it
->what
== IT_STRETCH
)
20529 produce_stretch_glyph (it
);
20531 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20532 because this isn't true for images with `:ascent 100'. */
20533 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20534 if (it
->area
== TEXT_AREA
)
20535 it
->current_x
+= it
->pixel_width
;
20537 if (extra_line_spacing
> 0)
20539 it
->descent
+= extra_line_spacing
;
20540 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20541 it
->max_extra_line_spacing
= extra_line_spacing
;
20544 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20545 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20546 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20547 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20551 Output LEN glyphs starting at START at the nominal cursor position.
20552 Advance the nominal cursor over the text. The global variable
20553 updated_window contains the window being updated, updated_row is
20554 the glyph row being updated, and updated_area is the area of that
20555 row being updated. */
20558 x_write_glyphs (start
, len
)
20559 struct glyph
*start
;
20564 xassert (updated_window
&& updated_row
);
20567 /* Write glyphs. */
20569 hpos
= start
- updated_row
->glyphs
[updated_area
];
20570 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20571 updated_row
, updated_area
,
20573 DRAW_NORMAL_TEXT
, 0);
20575 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20576 if (updated_area
== TEXT_AREA
20577 && updated_window
->phys_cursor_on_p
20578 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20579 && updated_window
->phys_cursor
.hpos
>= hpos
20580 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20581 updated_window
->phys_cursor_on_p
= 0;
20585 /* Advance the output cursor. */
20586 output_cursor
.hpos
+= len
;
20587 output_cursor
.x
= x
;
20592 Insert LEN glyphs from START at the nominal cursor position. */
20595 x_insert_glyphs (start
, len
)
20596 struct glyph
*start
;
20601 int line_height
, shift_by_width
, shifted_region_width
;
20602 struct glyph_row
*row
;
20603 struct glyph
*glyph
;
20604 int frame_x
, frame_y
, hpos
;
20606 xassert (updated_window
&& updated_row
);
20608 w
= updated_window
;
20609 f
= XFRAME (WINDOW_FRAME (w
));
20611 /* Get the height of the line we are in. */
20613 line_height
= row
->height
;
20615 /* Get the width of the glyphs to insert. */
20616 shift_by_width
= 0;
20617 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20618 shift_by_width
+= glyph
->pixel_width
;
20620 /* Get the width of the region to shift right. */
20621 shifted_region_width
= (window_box_width (w
, updated_area
)
20626 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20627 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20629 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20630 line_height
, shift_by_width
);
20632 /* Write the glyphs. */
20633 hpos
= start
- row
->glyphs
[updated_area
];
20634 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20636 DRAW_NORMAL_TEXT
, 0);
20638 /* Advance the output cursor. */
20639 output_cursor
.hpos
+= len
;
20640 output_cursor
.x
+= shift_by_width
;
20646 Erase the current text line from the nominal cursor position
20647 (inclusive) to pixel column TO_X (exclusive). The idea is that
20648 everything from TO_X onward is already erased.
20650 TO_X is a pixel position relative to updated_area of
20651 updated_window. TO_X == -1 means clear to the end of this area. */
20654 x_clear_end_of_line (to_x
)
20658 struct window
*w
= updated_window
;
20659 int max_x
, min_y
, max_y
;
20660 int from_x
, from_y
, to_y
;
20662 xassert (updated_window
&& updated_row
);
20663 f
= XFRAME (w
->frame
);
20665 if (updated_row
->full_width_p
)
20666 max_x
= WINDOW_TOTAL_WIDTH (w
);
20668 max_x
= window_box_width (w
, updated_area
);
20669 max_y
= window_text_bottom_y (w
);
20671 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20672 of window. For TO_X > 0, truncate to end of drawing area. */
20678 to_x
= min (to_x
, max_x
);
20680 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20682 /* Notice if the cursor will be cleared by this operation. */
20683 if (!updated_row
->full_width_p
)
20684 notice_overwritten_cursor (w
, updated_area
,
20685 output_cursor
.x
, -1,
20687 MATRIX_ROW_BOTTOM_Y (updated_row
));
20689 from_x
= output_cursor
.x
;
20691 /* Translate to frame coordinates. */
20692 if (updated_row
->full_width_p
)
20694 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20695 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20699 int area_left
= window_box_left (w
, updated_area
);
20700 from_x
+= area_left
;
20704 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20705 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20706 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20708 /* Prevent inadvertently clearing to end of the X window. */
20709 if (to_x
> from_x
&& to_y
> from_y
)
20712 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
20713 to_x
- from_x
, to_y
- from_y
);
20718 #endif /* HAVE_WINDOW_SYSTEM */
20722 /***********************************************************************
20724 ***********************************************************************/
20726 /* Value is the internal representation of the specified cursor type
20727 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20728 of the bar cursor. */
20730 static enum text_cursor_kinds
20731 get_specified_cursor_type (arg
, width
)
20735 enum text_cursor_kinds type
;
20740 if (EQ (arg
, Qbox
))
20741 return FILLED_BOX_CURSOR
;
20743 if (EQ (arg
, Qhollow
))
20744 return HOLLOW_BOX_CURSOR
;
20746 if (EQ (arg
, Qbar
))
20753 && EQ (XCAR (arg
), Qbar
)
20754 && INTEGERP (XCDR (arg
))
20755 && XINT (XCDR (arg
)) >= 0)
20757 *width
= XINT (XCDR (arg
));
20761 if (EQ (arg
, Qhbar
))
20764 return HBAR_CURSOR
;
20768 && EQ (XCAR (arg
), Qhbar
)
20769 && INTEGERP (XCDR (arg
))
20770 && XINT (XCDR (arg
)) >= 0)
20772 *width
= XINT (XCDR (arg
));
20773 return HBAR_CURSOR
;
20776 /* Treat anything unknown as "hollow box cursor".
20777 It was bad to signal an error; people have trouble fixing
20778 .Xdefaults with Emacs, when it has something bad in it. */
20779 type
= HOLLOW_BOX_CURSOR
;
20784 /* Set the default cursor types for specified frame. */
20786 set_frame_cursor_types (f
, arg
)
20793 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20794 FRAME_CURSOR_WIDTH (f
) = width
;
20796 /* By default, set up the blink-off state depending on the on-state. */
20798 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20801 FRAME_BLINK_OFF_CURSOR (f
)
20802 = get_specified_cursor_type (XCDR (tem
), &width
);
20803 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20806 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20810 /* Return the cursor we want to be displayed in window W. Return
20811 width of bar/hbar cursor through WIDTH arg. Return with
20812 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20813 (i.e. if the `system caret' should track this cursor).
20815 In a mini-buffer window, we want the cursor only to appear if we
20816 are reading input from this window. For the selected window, we
20817 want the cursor type given by the frame parameter or buffer local
20818 setting of cursor-type. If explicitly marked off, draw no cursor.
20819 In all other cases, we want a hollow box cursor. */
20821 static enum text_cursor_kinds
20822 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20824 struct glyph
*glyph
;
20826 int *active_cursor
;
20828 struct frame
*f
= XFRAME (w
->frame
);
20829 struct buffer
*b
= XBUFFER (w
->buffer
);
20830 int cursor_type
= DEFAULT_CURSOR
;
20831 Lisp_Object alt_cursor
;
20832 int non_selected
= 0;
20834 *active_cursor
= 1;
20837 if (cursor_in_echo_area
20838 && FRAME_HAS_MINIBUF_P (f
)
20839 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20841 if (w
== XWINDOW (echo_area_window
))
20843 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
20845 *width
= FRAME_CURSOR_WIDTH (f
);
20846 return FRAME_DESIRED_CURSOR (f
);
20849 return get_specified_cursor_type (b
->cursor_type
, width
);
20852 *active_cursor
= 0;
20856 /* Nonselected window or nonselected frame. */
20857 else if (w
!= XWINDOW (f
->selected_window
)
20858 #ifdef HAVE_WINDOW_SYSTEM
20859 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20863 *active_cursor
= 0;
20865 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20871 /* Never display a cursor in a window in which cursor-type is nil. */
20872 if (NILP (b
->cursor_type
))
20875 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20878 alt_cursor
= b
->cursor_in_non_selected_windows
;
20879 return get_specified_cursor_type (alt_cursor
, width
);
20882 /* Get the normal cursor type for this window. */
20883 if (EQ (b
->cursor_type
, Qt
))
20885 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20886 *width
= FRAME_CURSOR_WIDTH (f
);
20889 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20891 /* Use normal cursor if not blinked off. */
20892 if (!w
->cursor_off_p
)
20894 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20895 if (cursor_type
== FILLED_BOX_CURSOR
)
20896 cursor_type
= HOLLOW_BOX_CURSOR
;
20898 return cursor_type
;
20901 /* Cursor is blinked off, so determine how to "toggle" it. */
20903 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20904 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20905 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20907 /* Then see if frame has specified a specific blink off cursor type. */
20908 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20910 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20911 return FRAME_BLINK_OFF_CURSOR (f
);
20915 /* Some people liked having a permanently visible blinking cursor,
20916 while others had very strong opinions against it. So it was
20917 decided to remove it. KFS 2003-09-03 */
20919 /* Finally perform built-in cursor blinking:
20920 filled box <-> hollow box
20921 wide [h]bar <-> narrow [h]bar
20922 narrow [h]bar <-> no cursor
20923 other type <-> no cursor */
20925 if (cursor_type
== FILLED_BOX_CURSOR
)
20926 return HOLLOW_BOX_CURSOR
;
20928 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20931 return cursor_type
;
20939 #ifdef HAVE_WINDOW_SYSTEM
20941 /* Notice when the text cursor of window W has been completely
20942 overwritten by a drawing operation that outputs glyphs in AREA
20943 starting at X0 and ending at X1 in the line starting at Y0 and
20944 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20945 the rest of the line after X0 has been written. Y coordinates
20946 are window-relative. */
20949 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20951 enum glyph_row_area area
;
20952 int x0
, y0
, x1
, y1
;
20954 int cx0
, cx1
, cy0
, cy1
;
20955 struct glyph_row
*row
;
20957 if (!w
->phys_cursor_on_p
)
20959 if (area
!= TEXT_AREA
)
20962 if (w
->phys_cursor
.vpos
< 0
20963 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20964 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20965 !(row
->enabled_p
&& row
->displays_text_p
)))
20968 if (row
->cursor_in_fringe_p
)
20970 row
->cursor_in_fringe_p
= 0;
20971 draw_fringe_bitmap (w
, row
, 0);
20972 w
->phys_cursor_on_p
= 0;
20976 cx0
= w
->phys_cursor
.x
;
20977 cx1
= cx0
+ w
->phys_cursor_width
;
20978 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20981 /* The cursor image will be completely removed from the
20982 screen if the output area intersects the cursor area in
20983 y-direction. When we draw in [y0 y1[, and some part of
20984 the cursor is at y < y0, that part must have been drawn
20985 before. When scrolling, the cursor is erased before
20986 actually scrolling, so we don't come here. When not
20987 scrolling, the rows above the old cursor row must have
20988 changed, and in this case these rows must have written
20989 over the cursor image.
20991 Likewise if part of the cursor is below y1, with the
20992 exception of the cursor being in the first blank row at
20993 the buffer and window end because update_text_area
20994 doesn't draw that row. (Except when it does, but
20995 that's handled in update_text_area.) */
20997 cy0
= w
->phys_cursor
.y
;
20998 cy1
= cy0
+ w
->phys_cursor_height
;
20999 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21002 w
->phys_cursor_on_p
= 0;
21005 #endif /* HAVE_WINDOW_SYSTEM */
21008 /************************************************************************
21010 ************************************************************************/
21012 #ifdef HAVE_WINDOW_SYSTEM
21015 Fix the display of area AREA of overlapping row ROW in window W
21016 with respect to the overlapping part OVERLAPS. */
21019 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21021 struct glyph_row
*row
;
21022 enum glyph_row_area area
;
21030 for (i
= 0; i
< row
->used
[area
];)
21032 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21034 int start
= i
, start_x
= x
;
21038 x
+= row
->glyphs
[area
][i
].pixel_width
;
21041 while (i
< row
->used
[area
]
21042 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21044 draw_glyphs (w
, start_x
, row
, area
,
21046 DRAW_NORMAL_TEXT
, overlaps
);
21050 x
+= row
->glyphs
[area
][i
].pixel_width
;
21060 Draw the cursor glyph of window W in glyph row ROW. See the
21061 comment of draw_glyphs for the meaning of HL. */
21064 draw_phys_cursor_glyph (w
, row
, hl
)
21066 struct glyph_row
*row
;
21067 enum draw_glyphs_face hl
;
21069 /* If cursor hpos is out of bounds, don't draw garbage. This can
21070 happen in mini-buffer windows when switching between echo area
21071 glyphs and mini-buffer. */
21072 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21074 int on_p
= w
->phys_cursor_on_p
;
21076 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21077 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21079 w
->phys_cursor_on_p
= on_p
;
21081 if (hl
== DRAW_CURSOR
)
21082 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21083 /* When we erase the cursor, and ROW is overlapped by other
21084 rows, make sure that these overlapping parts of other rows
21086 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21088 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21090 if (row
> w
->current_matrix
->rows
21091 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21092 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21093 OVERLAPS_ERASED_CURSOR
);
21095 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21096 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21097 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21098 OVERLAPS_ERASED_CURSOR
);
21105 Erase the image of a cursor of window W from the screen. */
21108 erase_phys_cursor (w
)
21111 struct frame
*f
= XFRAME (w
->frame
);
21112 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21113 int hpos
= w
->phys_cursor
.hpos
;
21114 int vpos
= w
->phys_cursor
.vpos
;
21115 int mouse_face_here_p
= 0;
21116 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21117 struct glyph_row
*cursor_row
;
21118 struct glyph
*cursor_glyph
;
21119 enum draw_glyphs_face hl
;
21121 /* No cursor displayed or row invalidated => nothing to do on the
21123 if (w
->phys_cursor_type
== NO_CURSOR
)
21124 goto mark_cursor_off
;
21126 /* VPOS >= active_glyphs->nrows means that window has been resized.
21127 Don't bother to erase the cursor. */
21128 if (vpos
>= active_glyphs
->nrows
)
21129 goto mark_cursor_off
;
21131 /* If row containing cursor is marked invalid, there is nothing we
21133 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21134 if (!cursor_row
->enabled_p
)
21135 goto mark_cursor_off
;
21137 /* If line spacing is > 0, old cursor may only be partially visible in
21138 window after split-window. So adjust visible height. */
21139 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21140 window_text_bottom_y (w
) - cursor_row
->y
);
21142 /* If row is completely invisible, don't attempt to delete a cursor which
21143 isn't there. This can happen if cursor is at top of a window, and
21144 we switch to a buffer with a header line in that window. */
21145 if (cursor_row
->visible_height
<= 0)
21146 goto mark_cursor_off
;
21148 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21149 if (cursor_row
->cursor_in_fringe_p
)
21151 cursor_row
->cursor_in_fringe_p
= 0;
21152 draw_fringe_bitmap (w
, cursor_row
, 0);
21153 goto mark_cursor_off
;
21156 /* This can happen when the new row is shorter than the old one.
21157 In this case, either draw_glyphs or clear_end_of_line
21158 should have cleared the cursor. Note that we wouldn't be
21159 able to erase the cursor in this case because we don't have a
21160 cursor glyph at hand. */
21161 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21162 goto mark_cursor_off
;
21164 /* If the cursor is in the mouse face area, redisplay that when
21165 we clear the cursor. */
21166 if (! NILP (dpyinfo
->mouse_face_window
)
21167 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21168 && (vpos
> dpyinfo
->mouse_face_beg_row
21169 || (vpos
== dpyinfo
->mouse_face_beg_row
21170 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21171 && (vpos
< dpyinfo
->mouse_face_end_row
21172 || (vpos
== dpyinfo
->mouse_face_end_row
21173 && hpos
< dpyinfo
->mouse_face_end_col
))
21174 /* Don't redraw the cursor's spot in mouse face if it is at the
21175 end of a line (on a newline). The cursor appears there, but
21176 mouse highlighting does not. */
21177 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21178 mouse_face_here_p
= 1;
21180 /* Maybe clear the display under the cursor. */
21181 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21184 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21187 cursor_glyph
= get_phys_cursor_glyph (w
);
21188 if (cursor_glyph
== NULL
)
21189 goto mark_cursor_off
;
21191 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21192 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21193 width
= min (cursor_glyph
->pixel_width
,
21194 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21196 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21199 /* Erase the cursor by redrawing the character underneath it. */
21200 if (mouse_face_here_p
)
21201 hl
= DRAW_MOUSE_FACE
;
21203 hl
= DRAW_NORMAL_TEXT
;
21204 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21207 w
->phys_cursor_on_p
= 0;
21208 w
->phys_cursor_type
= NO_CURSOR
;
21213 Display or clear cursor of window W. If ON is zero, clear the
21214 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21215 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21218 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21220 int on
, hpos
, vpos
, x
, y
;
21222 struct frame
*f
= XFRAME (w
->frame
);
21223 int new_cursor_type
;
21224 int new_cursor_width
;
21226 struct glyph_row
*glyph_row
;
21227 struct glyph
*glyph
;
21229 /* This is pointless on invisible frames, and dangerous on garbaged
21230 windows and frames; in the latter case, the frame or window may
21231 be in the midst of changing its size, and x and y may be off the
21233 if (! FRAME_VISIBLE_P (f
)
21234 || FRAME_GARBAGED_P (f
)
21235 || vpos
>= w
->current_matrix
->nrows
21236 || hpos
>= w
->current_matrix
->matrix_w
)
21239 /* If cursor is off and we want it off, return quickly. */
21240 if (!on
&& !w
->phys_cursor_on_p
)
21243 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21244 /* If cursor row is not enabled, we don't really know where to
21245 display the cursor. */
21246 if (!glyph_row
->enabled_p
)
21248 w
->phys_cursor_on_p
= 0;
21253 if (!glyph_row
->exact_window_width_line_p
21254 || hpos
< glyph_row
->used
[TEXT_AREA
])
21255 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21257 xassert (interrupt_input_blocked
);
21259 /* Set new_cursor_type to the cursor we want to be displayed. */
21260 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21261 &new_cursor_width
, &active_cursor
);
21263 /* If cursor is currently being shown and we don't want it to be or
21264 it is in the wrong place, or the cursor type is not what we want,
21266 if (w
->phys_cursor_on_p
21268 || w
->phys_cursor
.x
!= x
21269 || w
->phys_cursor
.y
!= y
21270 || new_cursor_type
!= w
->phys_cursor_type
21271 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21272 && new_cursor_width
!= w
->phys_cursor_width
)))
21273 erase_phys_cursor (w
);
21275 /* Don't check phys_cursor_on_p here because that flag is only set
21276 to zero in some cases where we know that the cursor has been
21277 completely erased, to avoid the extra work of erasing the cursor
21278 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21279 still not be visible, or it has only been partly erased. */
21282 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21283 w
->phys_cursor_height
= glyph_row
->height
;
21285 /* Set phys_cursor_.* before x_draw_.* is called because some
21286 of them may need the information. */
21287 w
->phys_cursor
.x
= x
;
21288 w
->phys_cursor
.y
= glyph_row
->y
;
21289 w
->phys_cursor
.hpos
= hpos
;
21290 w
->phys_cursor
.vpos
= vpos
;
21293 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
21294 new_cursor_type
, new_cursor_width
,
21295 on
, active_cursor
);
21299 /* Switch the display of W's cursor on or off, according to the value
21303 update_window_cursor (w
, on
)
21307 /* Don't update cursor in windows whose frame is in the process
21308 of being deleted. */
21309 if (w
->current_matrix
)
21312 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21313 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21319 /* Call update_window_cursor with parameter ON_P on all leaf windows
21320 in the window tree rooted at W. */
21323 update_cursor_in_window_tree (w
, on_p
)
21329 if (!NILP (w
->hchild
))
21330 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21331 else if (!NILP (w
->vchild
))
21332 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21334 update_window_cursor (w
, on_p
);
21336 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21342 Display the cursor on window W, or clear it, according to ON_P.
21343 Don't change the cursor's position. */
21346 x_update_cursor (f
, on_p
)
21350 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21355 Clear the cursor of window W to background color, and mark the
21356 cursor as not shown. This is used when the text where the cursor
21357 is is about to be rewritten. */
21363 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21364 update_window_cursor (w
, 0);
21369 Display the active region described by mouse_face_* according to DRAW. */
21372 show_mouse_face (dpyinfo
, draw
)
21373 Display_Info
*dpyinfo
;
21374 enum draw_glyphs_face draw
;
21376 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21377 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21379 if (/* If window is in the process of being destroyed, don't bother
21381 w
->current_matrix
!= NULL
21382 /* Don't update mouse highlight if hidden */
21383 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21384 /* Recognize when we are called to operate on rows that don't exist
21385 anymore. This can happen when a window is split. */
21386 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21388 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21389 struct glyph_row
*row
, *first
, *last
;
21391 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21392 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21394 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21396 int start_hpos
, end_hpos
, start_x
;
21398 /* For all but the first row, the highlight starts at column 0. */
21401 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21402 start_x
= dpyinfo
->mouse_face_beg_x
;
21411 end_hpos
= dpyinfo
->mouse_face_end_col
;
21414 end_hpos
= row
->used
[TEXT_AREA
];
21415 if (draw
== DRAW_NORMAL_TEXT
)
21416 row
->fill_line_p
= 1; /* Clear to end of line */
21419 if (end_hpos
> start_hpos
)
21421 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21422 start_hpos
, end_hpos
,
21426 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21430 /* When we've written over the cursor, arrange for it to
21431 be displayed again. */
21432 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21435 display_and_set_cursor (w
, 1,
21436 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21437 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21442 /* Change the mouse cursor. */
21443 if (draw
== DRAW_NORMAL_TEXT
)
21444 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21445 else if (draw
== DRAW_MOUSE_FACE
)
21446 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21448 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21452 Clear out the mouse-highlighted active region.
21453 Redraw it un-highlighted first. Value is non-zero if mouse
21454 face was actually drawn unhighlighted. */
21457 clear_mouse_face (dpyinfo
)
21458 Display_Info
*dpyinfo
;
21462 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21464 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21468 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21469 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21470 dpyinfo
->mouse_face_window
= Qnil
;
21471 dpyinfo
->mouse_face_overlay
= Qnil
;
21477 Non-zero if physical cursor of window W is within mouse face. */
21480 cursor_in_mouse_face_p (w
)
21483 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21484 int in_mouse_face
= 0;
21486 if (WINDOWP (dpyinfo
->mouse_face_window
)
21487 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21489 int hpos
= w
->phys_cursor
.hpos
;
21490 int vpos
= w
->phys_cursor
.vpos
;
21492 if (vpos
>= dpyinfo
->mouse_face_beg_row
21493 && vpos
<= dpyinfo
->mouse_face_end_row
21494 && (vpos
> dpyinfo
->mouse_face_beg_row
21495 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21496 && (vpos
< dpyinfo
->mouse_face_end_row
21497 || hpos
< dpyinfo
->mouse_face_end_col
21498 || dpyinfo
->mouse_face_past_end
))
21502 return in_mouse_face
;
21508 /* Find the glyph matrix position of buffer position CHARPOS in window
21509 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21510 current glyphs must be up to date. If CHARPOS is above window
21511 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21512 of last line in W. In the row containing CHARPOS, stop before glyphs
21513 having STOP as object. */
21515 #if 1 /* This is a version of fast_find_position that's more correct
21516 in the presence of hscrolling, for example. I didn't install
21517 it right away because the problem fixed is minor, it failed
21518 in 20.x as well, and I think it's too risky to install
21519 so near the release of 21.1. 2001-09-25 gerd. */
21522 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21525 int *hpos
, *vpos
, *x
, *y
;
21528 struct glyph_row
*row
, *first
;
21529 struct glyph
*glyph
, *end
;
21532 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21533 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21538 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21542 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21545 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21549 /* If whole rows or last part of a row came from a display overlay,
21550 row_containing_pos will skip over such rows because their end pos
21551 equals the start pos of the overlay or interval.
21553 Move back if we have a STOP object and previous row's
21554 end glyph came from STOP. */
21557 struct glyph_row
*prev
;
21558 while ((prev
= row
- 1, prev
>= first
)
21559 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21560 && prev
->used
[TEXT_AREA
] > 0)
21562 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21563 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21564 while (--glyph
>= beg
21565 && INTEGERP (glyph
->object
));
21567 || !EQ (stop
, glyph
->object
))
21575 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21577 glyph
= row
->glyphs
[TEXT_AREA
];
21578 end
= glyph
+ row
->used
[TEXT_AREA
];
21580 /* Skip over glyphs not having an object at the start of the row.
21581 These are special glyphs like truncation marks on terminal
21583 if (row
->displays_text_p
)
21585 && INTEGERP (glyph
->object
)
21586 && !EQ (stop
, glyph
->object
)
21587 && glyph
->charpos
< 0)
21589 *x
+= glyph
->pixel_width
;
21594 && !INTEGERP (glyph
->object
)
21595 && !EQ (stop
, glyph
->object
)
21596 && (!BUFFERP (glyph
->object
)
21597 || glyph
->charpos
< charpos
))
21599 *x
+= glyph
->pixel_width
;
21603 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21610 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21613 int *hpos
, *vpos
, *x
, *y
;
21618 int maybe_next_line_p
= 0;
21619 int line_start_position
;
21620 int yb
= window_text_bottom_y (w
);
21621 struct glyph_row
*row
, *best_row
;
21622 int row_vpos
, best_row_vpos
;
21625 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21626 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21628 while (row
->y
< yb
)
21630 if (row
->used
[TEXT_AREA
])
21631 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21633 line_start_position
= 0;
21635 if (line_start_position
> pos
)
21637 /* If the position sought is the end of the buffer,
21638 don't include the blank lines at the bottom of the window. */
21639 else if (line_start_position
== pos
21640 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21642 maybe_next_line_p
= 1;
21645 else if (line_start_position
> 0)
21648 best_row_vpos
= row_vpos
;
21651 if (row
->y
+ row
->height
>= yb
)
21658 /* Find the right column within BEST_ROW. */
21660 current_x
= best_row
->x
;
21661 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21663 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21664 int charpos
= glyph
->charpos
;
21666 if (BUFFERP (glyph
->object
))
21668 if (charpos
== pos
)
21671 *vpos
= best_row_vpos
;
21676 else if (charpos
> pos
)
21679 else if (EQ (glyph
->object
, stop
))
21684 current_x
+= glyph
->pixel_width
;
21687 /* If we're looking for the end of the buffer,
21688 and we didn't find it in the line we scanned,
21689 use the start of the following line. */
21690 if (maybe_next_line_p
)
21695 current_x
= best_row
->x
;
21698 *vpos
= best_row_vpos
;
21699 *hpos
= lastcol
+ 1;
21708 /* Find the position of the glyph for position POS in OBJECT in
21709 window W's current matrix, and return in *X, *Y the pixel
21710 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21712 RIGHT_P non-zero means return the position of the right edge of the
21713 glyph, RIGHT_P zero means return the left edge position.
21715 If no glyph for POS exists in the matrix, return the position of
21716 the glyph with the next smaller position that is in the matrix, if
21717 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21718 exists in the matrix, return the position of the glyph with the
21719 next larger position in OBJECT.
21721 Value is non-zero if a glyph was found. */
21724 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21727 Lisp_Object object
;
21728 int *hpos
, *vpos
, *x
, *y
;
21731 int yb
= window_text_bottom_y (w
);
21732 struct glyph_row
*r
;
21733 struct glyph
*best_glyph
= NULL
;
21734 struct glyph_row
*best_row
= NULL
;
21737 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21738 r
->enabled_p
&& r
->y
< yb
;
21741 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21742 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21745 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21746 if (EQ (g
->object
, object
))
21748 if (g
->charpos
== pos
)
21755 else if (best_glyph
== NULL
21756 || ((abs (g
->charpos
- pos
)
21757 < abs (best_glyph
->charpos
- pos
))
21760 : g
->charpos
> pos
)))
21774 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21778 *x
+= best_glyph
->pixel_width
;
21783 *vpos
= best_row
- w
->current_matrix
->rows
;
21786 return best_glyph
!= NULL
;
21790 /* See if position X, Y is within a hot-spot of an image. */
21793 on_hot_spot_p (hot_spot
, x
, y
)
21794 Lisp_Object hot_spot
;
21797 if (!CONSP (hot_spot
))
21800 if (EQ (XCAR (hot_spot
), Qrect
))
21802 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21803 Lisp_Object rect
= XCDR (hot_spot
);
21807 if (!CONSP (XCAR (rect
)))
21809 if (!CONSP (XCDR (rect
)))
21811 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21813 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21815 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21817 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21821 else if (EQ (XCAR (hot_spot
), Qcircle
))
21823 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21824 Lisp_Object circ
= XCDR (hot_spot
);
21825 Lisp_Object lr
, lx0
, ly0
;
21827 && CONSP (XCAR (circ
))
21828 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21829 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21830 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21832 double r
= XFLOATINT (lr
);
21833 double dx
= XINT (lx0
) - x
;
21834 double dy
= XINT (ly0
) - y
;
21835 return (dx
* dx
+ dy
* dy
<= r
* r
);
21838 else if (EQ (XCAR (hot_spot
), Qpoly
))
21840 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21841 if (VECTORP (XCDR (hot_spot
)))
21843 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21844 Lisp_Object
*poly
= v
->contents
;
21848 Lisp_Object lx
, ly
;
21851 /* Need an even number of coordinates, and at least 3 edges. */
21852 if (n
< 6 || n
& 1)
21855 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21856 If count is odd, we are inside polygon. Pixels on edges
21857 may or may not be included depending on actual geometry of the
21859 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21860 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21862 x0
= XINT (lx
), y0
= XINT (ly
);
21863 for (i
= 0; i
< n
; i
+= 2)
21865 int x1
= x0
, y1
= y0
;
21866 if ((lx
= poly
[i
], !INTEGERP (lx
))
21867 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21869 x0
= XINT (lx
), y0
= XINT (ly
);
21871 /* Does this segment cross the X line? */
21879 if (y
> y0
&& y
> y1
)
21881 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21891 find_hot_spot (map
, x
, y
)
21895 while (CONSP (map
))
21897 if (CONSP (XCAR (map
))
21898 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21906 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21908 doc
: /* Lookup in image map MAP coordinates X and Y.
21909 An image map is an alist where each element has the format (AREA ID PLIST).
21910 An AREA is specified as either a rectangle, a circle, or a polygon:
21911 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21912 pixel coordinates of the upper left and bottom right corners.
21913 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21914 and the radius of the circle; r may be a float or integer.
21915 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21916 vector describes one corner in the polygon.
21917 Returns the alist element for the first matching AREA in MAP. */)
21928 return find_hot_spot (map
, XINT (x
), XINT (y
));
21932 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21934 define_frame_cursor1 (f
, cursor
, pointer
)
21937 Lisp_Object pointer
;
21939 /* Do not change cursor shape while dragging mouse. */
21940 if (!NILP (do_mouse_tracking
))
21943 if (!NILP (pointer
))
21945 if (EQ (pointer
, Qarrow
))
21946 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21947 else if (EQ (pointer
, Qhand
))
21948 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21949 else if (EQ (pointer
, Qtext
))
21950 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21951 else if (EQ (pointer
, intern ("hdrag")))
21952 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21953 #ifdef HAVE_X_WINDOWS
21954 else if (EQ (pointer
, intern ("vdrag")))
21955 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21957 else if (EQ (pointer
, intern ("hourglass")))
21958 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21959 else if (EQ (pointer
, Qmodeline
))
21960 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21962 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21965 if (cursor
!= No_Cursor
)
21966 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
21969 /* Take proper action when mouse has moved to the mode or header line
21970 or marginal area AREA of window W, x-position X and y-position Y.
21971 X is relative to the start of the text display area of W, so the
21972 width of bitmap areas and scroll bars must be subtracted to get a
21973 position relative to the start of the mode line. */
21976 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21977 Lisp_Object window
;
21979 enum window_part area
;
21981 struct window
*w
= XWINDOW (window
);
21982 struct frame
*f
= XFRAME (w
->frame
);
21983 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21984 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21985 Lisp_Object pointer
= Qnil
;
21986 int charpos
, dx
, dy
, width
, height
;
21987 Lisp_Object string
, object
= Qnil
;
21988 Lisp_Object pos
, help
;
21990 Lisp_Object mouse_face
;
21991 int original_x_pixel
= x
;
21992 struct glyph
* glyph
= NULL
;
21993 struct glyph_row
*row
;
21995 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22000 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22001 &object
, &dx
, &dy
, &width
, &height
);
22003 row
= (area
== ON_MODE_LINE
22004 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22005 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22008 if (row
->mode_line_p
&& row
->enabled_p
)
22010 glyph
= row
->glyphs
[TEXT_AREA
];
22011 end
= glyph
+ row
->used
[TEXT_AREA
];
22013 for (x0
= original_x_pixel
;
22014 glyph
< end
&& x0
>= glyph
->pixel_width
;
22016 x0
-= glyph
->pixel_width
;
22024 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22025 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22026 &object
, &dx
, &dy
, &width
, &height
);
22031 if (IMAGEP (object
))
22033 Lisp_Object image_map
, hotspot
;
22034 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22036 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22038 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22040 Lisp_Object area_id
, plist
;
22042 area_id
= XCAR (hotspot
);
22043 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22044 If so, we could look for mouse-enter, mouse-leave
22045 properties in PLIST (and do something...). */
22046 hotspot
= XCDR (hotspot
);
22047 if (CONSP (hotspot
)
22048 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22050 pointer
= Fplist_get (plist
, Qpointer
);
22051 if (NILP (pointer
))
22053 help
= Fplist_get (plist
, Qhelp_echo
);
22056 help_echo_string
= help
;
22057 /* Is this correct? ++kfs */
22058 XSETWINDOW (help_echo_window
, w
);
22059 help_echo_object
= w
->buffer
;
22060 help_echo_pos
= charpos
;
22064 if (NILP (pointer
))
22065 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22068 if (STRINGP (string
))
22070 pos
= make_number (charpos
);
22071 /* If we're on a string with `help-echo' text property, arrange
22072 for the help to be displayed. This is done by setting the
22073 global variable help_echo_string to the help string. */
22076 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22079 help_echo_string
= help
;
22080 XSETWINDOW (help_echo_window
, w
);
22081 help_echo_object
= string
;
22082 help_echo_pos
= charpos
;
22086 if (NILP (pointer
))
22087 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22089 /* Change the mouse pointer according to what is under X/Y. */
22090 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22093 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22094 if (!KEYMAPP (map
))
22095 map
= Fget_text_property (pos
, Qkeymap
, string
);
22096 if (!KEYMAPP (map
))
22097 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22100 /* Change the mouse face according to what is under X/Y. */
22101 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22102 if (!NILP (mouse_face
)
22103 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22108 struct glyph
* tmp_glyph
;
22112 int total_pixel_width
;
22117 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22118 Qmouse_face
, string
, Qnil
);
22120 b
= make_number (0);
22122 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22124 e
= make_number (SCHARS (string
));
22126 /* Calculate the position(glyph position: GPOS) of GLYPH in
22127 displayed string. GPOS is different from CHARPOS.
22129 CHARPOS is the position of glyph in internal string
22130 object. A mode line string format has structures which
22131 is converted to a flatten by emacs lisp interpreter.
22132 The internal string is an element of the structures.
22133 The displayed string is the flatten string. */
22134 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22135 tmp_glyph
->charpos
>= XINT (b
);
22136 tmp_glyph
--, gpos
++)
22138 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22142 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22143 displayed string holding GLYPH.
22145 GSEQ_LENGTH is different from SCHARS (STRING).
22146 SCHARS (STRING) returns the length of the internal string. */
22147 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22148 tmp_glyph
->charpos
< XINT (e
);
22149 tmp_glyph
++, gseq_length
++)
22151 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22155 total_pixel_width
= 0;
22156 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22157 total_pixel_width
+= tmp_glyph
->pixel_width
;
22159 /* Pre calculation of re-rendering position */
22161 hpos
= (area
== ON_MODE_LINE
22162 ? (w
->current_matrix
)->nrows
- 1
22165 /* If the re-rendering position is included in the last
22166 re-rendering area, we should do nothing. */
22167 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22168 && dpyinfo
->mouse_face_beg_col
<= vpos
22169 && vpos
< dpyinfo
->mouse_face_end_col
22170 && dpyinfo
->mouse_face_beg_row
== hpos
)
22173 if (clear_mouse_face (dpyinfo
))
22174 cursor
= No_Cursor
;
22176 dpyinfo
->mouse_face_beg_col
= vpos
;
22177 dpyinfo
->mouse_face_beg_row
= hpos
;
22179 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22180 dpyinfo
->mouse_face_beg_y
= 0;
22182 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22183 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22185 dpyinfo
->mouse_face_end_x
= 0;
22186 dpyinfo
->mouse_face_end_y
= 0;
22188 dpyinfo
->mouse_face_past_end
= 0;
22189 dpyinfo
->mouse_face_window
= window
;
22191 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22194 glyph
->face_id
, 1);
22195 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22197 if (NILP (pointer
))
22200 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22201 clear_mouse_face (dpyinfo
);
22203 define_frame_cursor1 (f
, cursor
, pointer
);
22208 Take proper action when the mouse has moved to position X, Y on
22209 frame F as regards highlighting characters that have mouse-face
22210 properties. Also de-highlighting chars where the mouse was before.
22211 X and Y can be negative or out of range. */
22214 note_mouse_highlight (f
, x
, y
)
22218 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22219 enum window_part part
;
22220 Lisp_Object window
;
22222 Cursor cursor
= No_Cursor
;
22223 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22226 /* When a menu is active, don't highlight because this looks odd. */
22227 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22228 if (popup_activated ())
22232 if (NILP (Vmouse_highlight
)
22233 || !f
->glyphs_initialized_p
)
22236 dpyinfo
->mouse_face_mouse_x
= x
;
22237 dpyinfo
->mouse_face_mouse_y
= y
;
22238 dpyinfo
->mouse_face_mouse_frame
= f
;
22240 if (dpyinfo
->mouse_face_defer
)
22243 if (gc_in_progress
)
22245 dpyinfo
->mouse_face_deferred_gc
= 1;
22249 /* Which window is that in? */
22250 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22252 /* If we were displaying active text in another window, clear that.
22253 Also clear if we move out of text area in same window. */
22254 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22255 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22256 && !NILP (dpyinfo
->mouse_face_window
)))
22257 clear_mouse_face (dpyinfo
);
22259 /* Not on a window -> return. */
22260 if (!WINDOWP (window
))
22263 /* Reset help_echo_string. It will get recomputed below. */
22264 help_echo_string
= Qnil
;
22266 /* Convert to window-relative pixel coordinates. */
22267 w
= XWINDOW (window
);
22268 frame_to_window_pixel_xy (w
, &x
, &y
);
22270 /* Handle tool-bar window differently since it doesn't display a
22272 if (EQ (window
, f
->tool_bar_window
))
22274 note_tool_bar_highlight (f
, x
, y
);
22278 /* Mouse is on the mode, header line or margin? */
22279 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22280 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22282 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22286 if (part
== ON_VERTICAL_BORDER
)
22287 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22288 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22289 || part
== ON_SCROLL_BAR
)
22290 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22292 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22294 /* Are we in a window whose display is up to date?
22295 And verify the buffer's text has not changed. */
22296 b
= XBUFFER (w
->buffer
);
22297 if (part
== ON_TEXT
22298 && EQ (w
->window_end_valid
, w
->buffer
)
22299 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22300 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22302 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22303 struct glyph
*glyph
;
22304 Lisp_Object object
;
22305 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22306 Lisp_Object
*overlay_vec
= NULL
;
22308 struct buffer
*obuf
;
22309 int obegv
, ozv
, same_region
;
22311 /* Find the glyph under X/Y. */
22312 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22314 /* Look for :pointer property on image. */
22315 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22317 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22318 if (img
!= NULL
&& IMAGEP (img
->spec
))
22320 Lisp_Object image_map
, hotspot
;
22321 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22323 && (hotspot
= find_hot_spot (image_map
,
22324 glyph
->slice
.x
+ dx
,
22325 glyph
->slice
.y
+ dy
),
22327 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22329 Lisp_Object area_id
, plist
;
22331 area_id
= XCAR (hotspot
);
22332 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22333 If so, we could look for mouse-enter, mouse-leave
22334 properties in PLIST (and do something...). */
22335 hotspot
= XCDR (hotspot
);
22336 if (CONSP (hotspot
)
22337 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22339 pointer
= Fplist_get (plist
, Qpointer
);
22340 if (NILP (pointer
))
22342 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22343 if (!NILP (help_echo_string
))
22345 help_echo_window
= window
;
22346 help_echo_object
= glyph
->object
;
22347 help_echo_pos
= glyph
->charpos
;
22351 if (NILP (pointer
))
22352 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22356 /* Clear mouse face if X/Y not over text. */
22358 || area
!= TEXT_AREA
22359 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22361 if (clear_mouse_face (dpyinfo
))
22362 cursor
= No_Cursor
;
22363 if (NILP (pointer
))
22365 if (area
!= TEXT_AREA
)
22366 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22368 pointer
= Vvoid_text_area_pointer
;
22373 pos
= glyph
->charpos
;
22374 object
= glyph
->object
;
22375 if (!STRINGP (object
) && !BUFFERP (object
))
22378 /* If we get an out-of-range value, return now; avoid an error. */
22379 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22382 /* Make the window's buffer temporarily current for
22383 overlays_at and compute_char_face. */
22384 obuf
= current_buffer
;
22385 current_buffer
= b
;
22391 /* Is this char mouse-active or does it have help-echo? */
22392 position
= make_number (pos
);
22394 if (BUFFERP (object
))
22396 /* Put all the overlays we want in a vector in overlay_vec. */
22397 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22398 /* Sort overlays into increasing priority order. */
22399 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22404 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22405 && vpos
>= dpyinfo
->mouse_face_beg_row
22406 && vpos
<= dpyinfo
->mouse_face_end_row
22407 && (vpos
> dpyinfo
->mouse_face_beg_row
22408 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22409 && (vpos
< dpyinfo
->mouse_face_end_row
22410 || hpos
< dpyinfo
->mouse_face_end_col
22411 || dpyinfo
->mouse_face_past_end
));
22414 cursor
= No_Cursor
;
22416 /* Check mouse-face highlighting. */
22418 /* If there exists an overlay with mouse-face overlapping
22419 the one we are currently highlighting, we have to
22420 check if we enter the overlapping overlay, and then
22421 highlight only that. */
22422 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22423 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22425 /* Find the highest priority overlay that has a mouse-face
22428 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22430 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22431 if (!NILP (mouse_face
))
22432 overlay
= overlay_vec
[i
];
22435 /* If we're actually highlighting the same overlay as
22436 before, there's no need to do that again. */
22437 if (!NILP (overlay
)
22438 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22439 goto check_help_echo
;
22441 dpyinfo
->mouse_face_overlay
= overlay
;
22443 /* Clear the display of the old active region, if any. */
22444 if (clear_mouse_face (dpyinfo
))
22445 cursor
= No_Cursor
;
22447 /* If no overlay applies, get a text property. */
22448 if (NILP (overlay
))
22449 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22451 /* Handle the overlay case. */
22452 if (!NILP (overlay
))
22454 /* Find the range of text around this char that
22455 should be active. */
22456 Lisp_Object before
, after
;
22459 before
= Foverlay_start (overlay
);
22460 after
= Foverlay_end (overlay
);
22461 /* Record this as the current active region. */
22462 fast_find_position (w
, XFASTINT (before
),
22463 &dpyinfo
->mouse_face_beg_col
,
22464 &dpyinfo
->mouse_face_beg_row
,
22465 &dpyinfo
->mouse_face_beg_x
,
22466 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22468 dpyinfo
->mouse_face_past_end
22469 = !fast_find_position (w
, XFASTINT (after
),
22470 &dpyinfo
->mouse_face_end_col
,
22471 &dpyinfo
->mouse_face_end_row
,
22472 &dpyinfo
->mouse_face_end_x
,
22473 &dpyinfo
->mouse_face_end_y
, Qnil
);
22474 dpyinfo
->mouse_face_window
= window
;
22476 dpyinfo
->mouse_face_face_id
22477 = face_at_buffer_position (w
, pos
, 0, 0,
22479 !dpyinfo
->mouse_face_hidden
);
22481 /* Display it as active. */
22482 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22483 cursor
= No_Cursor
;
22485 /* Handle the text property case. */
22486 else if (!NILP (mouse_face
) && BUFFERP (object
))
22488 /* Find the range of text around this char that
22489 should be active. */
22490 Lisp_Object before
, after
, beginning
, end
;
22493 beginning
= Fmarker_position (w
->start
);
22494 end
= make_number (BUF_Z (XBUFFER (object
))
22495 - XFASTINT (w
->window_end_pos
));
22497 = Fprevious_single_property_change (make_number (pos
+ 1),
22499 object
, beginning
);
22501 = Fnext_single_property_change (position
, Qmouse_face
,
22504 /* Record this as the current active region. */
22505 fast_find_position (w
, XFASTINT (before
),
22506 &dpyinfo
->mouse_face_beg_col
,
22507 &dpyinfo
->mouse_face_beg_row
,
22508 &dpyinfo
->mouse_face_beg_x
,
22509 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22510 dpyinfo
->mouse_face_past_end
22511 = !fast_find_position (w
, XFASTINT (after
),
22512 &dpyinfo
->mouse_face_end_col
,
22513 &dpyinfo
->mouse_face_end_row
,
22514 &dpyinfo
->mouse_face_end_x
,
22515 &dpyinfo
->mouse_face_end_y
, Qnil
);
22516 dpyinfo
->mouse_face_window
= window
;
22518 if (BUFFERP (object
))
22519 dpyinfo
->mouse_face_face_id
22520 = face_at_buffer_position (w
, pos
, 0, 0,
22522 !dpyinfo
->mouse_face_hidden
);
22524 /* Display it as active. */
22525 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22526 cursor
= No_Cursor
;
22528 else if (!NILP (mouse_face
) && STRINGP (object
))
22533 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22536 e
= Fnext_single_property_change (position
, Qmouse_face
,
22539 b
= make_number (0);
22541 e
= make_number (SCHARS (object
) - 1);
22543 fast_find_string_pos (w
, XINT (b
), object
,
22544 &dpyinfo
->mouse_face_beg_col
,
22545 &dpyinfo
->mouse_face_beg_row
,
22546 &dpyinfo
->mouse_face_beg_x
,
22547 &dpyinfo
->mouse_face_beg_y
, 0);
22548 fast_find_string_pos (w
, XINT (e
), object
,
22549 &dpyinfo
->mouse_face_end_col
,
22550 &dpyinfo
->mouse_face_end_row
,
22551 &dpyinfo
->mouse_face_end_x
,
22552 &dpyinfo
->mouse_face_end_y
, 1);
22553 dpyinfo
->mouse_face_past_end
= 0;
22554 dpyinfo
->mouse_face_window
= window
;
22555 dpyinfo
->mouse_face_face_id
22556 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22557 glyph
->face_id
, 1);
22558 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22559 cursor
= No_Cursor
;
22561 else if (STRINGP (object
) && NILP (mouse_face
))
22563 /* A string which doesn't have mouse-face, but
22564 the text ``under'' it might have. */
22565 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22566 int start
= MATRIX_ROW_START_CHARPOS (r
);
22568 pos
= string_buffer_position (w
, object
, start
);
22570 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22574 if (!NILP (mouse_face
) && !NILP (overlay
))
22576 Lisp_Object before
= Foverlay_start (overlay
);
22577 Lisp_Object after
= Foverlay_end (overlay
);
22580 /* Note that we might not be able to find position
22581 BEFORE in the glyph matrix if the overlay is
22582 entirely covered by a `display' property. In
22583 this case, we overshoot. So let's stop in
22584 the glyph matrix before glyphs for OBJECT. */
22585 fast_find_position (w
, XFASTINT (before
),
22586 &dpyinfo
->mouse_face_beg_col
,
22587 &dpyinfo
->mouse_face_beg_row
,
22588 &dpyinfo
->mouse_face_beg_x
,
22589 &dpyinfo
->mouse_face_beg_y
,
22592 dpyinfo
->mouse_face_past_end
22593 = !fast_find_position (w
, XFASTINT (after
),
22594 &dpyinfo
->mouse_face_end_col
,
22595 &dpyinfo
->mouse_face_end_row
,
22596 &dpyinfo
->mouse_face_end_x
,
22597 &dpyinfo
->mouse_face_end_y
,
22599 dpyinfo
->mouse_face_window
= window
;
22600 dpyinfo
->mouse_face_face_id
22601 = face_at_buffer_position (w
, pos
, 0, 0,
22603 !dpyinfo
->mouse_face_hidden
);
22605 /* Display it as active. */
22606 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22607 cursor
= No_Cursor
;
22614 /* Look for a `help-echo' property. */
22615 if (NILP (help_echo_string
)) {
22616 Lisp_Object help
, overlay
;
22618 /* Check overlays first. */
22619 help
= overlay
= Qnil
;
22620 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22622 overlay
= overlay_vec
[i
];
22623 help
= Foverlay_get (overlay
, Qhelp_echo
);
22628 help_echo_string
= help
;
22629 help_echo_window
= window
;
22630 help_echo_object
= overlay
;
22631 help_echo_pos
= pos
;
22635 Lisp_Object object
= glyph
->object
;
22636 int charpos
= glyph
->charpos
;
22638 /* Try text properties. */
22639 if (STRINGP (object
)
22641 && charpos
< SCHARS (object
))
22643 help
= Fget_text_property (make_number (charpos
),
22644 Qhelp_echo
, object
);
22647 /* If the string itself doesn't specify a help-echo,
22648 see if the buffer text ``under'' it does. */
22649 struct glyph_row
*r
22650 = MATRIX_ROW (w
->current_matrix
, vpos
);
22651 int start
= MATRIX_ROW_START_CHARPOS (r
);
22652 int pos
= string_buffer_position (w
, object
, start
);
22655 help
= Fget_char_property (make_number (pos
),
22656 Qhelp_echo
, w
->buffer
);
22660 object
= w
->buffer
;
22665 else if (BUFFERP (object
)
22668 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22673 help_echo_string
= help
;
22674 help_echo_window
= window
;
22675 help_echo_object
= object
;
22676 help_echo_pos
= charpos
;
22681 /* Look for a `pointer' property. */
22682 if (NILP (pointer
))
22684 /* Check overlays first. */
22685 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22686 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22688 if (NILP (pointer
))
22690 Lisp_Object object
= glyph
->object
;
22691 int charpos
= glyph
->charpos
;
22693 /* Try text properties. */
22694 if (STRINGP (object
)
22696 && charpos
< SCHARS (object
))
22698 pointer
= Fget_text_property (make_number (charpos
),
22700 if (NILP (pointer
))
22702 /* If the string itself doesn't specify a pointer,
22703 see if the buffer text ``under'' it does. */
22704 struct glyph_row
*r
22705 = MATRIX_ROW (w
->current_matrix
, vpos
);
22706 int start
= MATRIX_ROW_START_CHARPOS (r
);
22707 int pos
= string_buffer_position (w
, object
, start
);
22709 pointer
= Fget_char_property (make_number (pos
),
22710 Qpointer
, w
->buffer
);
22713 else if (BUFFERP (object
)
22716 pointer
= Fget_text_property (make_number (charpos
),
22723 current_buffer
= obuf
;
22728 define_frame_cursor1 (f
, cursor
, pointer
);
22733 Clear any mouse-face on window W. This function is part of the
22734 redisplay interface, and is called from try_window_id and similar
22735 functions to ensure the mouse-highlight is off. */
22738 x_clear_window_mouse_face (w
)
22741 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22742 Lisp_Object window
;
22745 XSETWINDOW (window
, w
);
22746 if (EQ (window
, dpyinfo
->mouse_face_window
))
22747 clear_mouse_face (dpyinfo
);
22753 Just discard the mouse face information for frame F, if any.
22754 This is used when the size of F is changed. */
22757 cancel_mouse_face (f
)
22760 Lisp_Object window
;
22761 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22763 window
= dpyinfo
->mouse_face_window
;
22764 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22766 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22767 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22768 dpyinfo
->mouse_face_window
= Qnil
;
22773 #endif /* HAVE_WINDOW_SYSTEM */
22776 /***********************************************************************
22778 ***********************************************************************/
22780 #ifdef HAVE_WINDOW_SYSTEM
22782 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22783 which intersects rectangle R. R is in window-relative coordinates. */
22786 expose_area (w
, row
, r
, area
)
22788 struct glyph_row
*row
;
22790 enum glyph_row_area area
;
22792 struct glyph
*first
= row
->glyphs
[area
];
22793 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22794 struct glyph
*last
;
22795 int first_x
, start_x
, x
;
22797 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22798 /* If row extends face to end of line write the whole line. */
22799 draw_glyphs (w
, 0, row
, area
,
22800 0, row
->used
[area
],
22801 DRAW_NORMAL_TEXT
, 0);
22804 /* Set START_X to the window-relative start position for drawing glyphs of
22805 AREA. The first glyph of the text area can be partially visible.
22806 The first glyphs of other areas cannot. */
22807 start_x
= window_box_left_offset (w
, area
);
22809 if (area
== TEXT_AREA
)
22812 /* Find the first glyph that must be redrawn. */
22814 && x
+ first
->pixel_width
< r
->x
)
22816 x
+= first
->pixel_width
;
22820 /* Find the last one. */
22824 && x
< r
->x
+ r
->width
)
22826 x
+= last
->pixel_width
;
22832 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22833 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22834 DRAW_NORMAL_TEXT
, 0);
22839 /* Redraw the parts of the glyph row ROW on window W intersecting
22840 rectangle R. R is in window-relative coordinates. Value is
22841 non-zero if mouse-face was overwritten. */
22844 expose_line (w
, row
, r
)
22846 struct glyph_row
*row
;
22849 xassert (row
->enabled_p
);
22851 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22852 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22853 0, row
->used
[TEXT_AREA
],
22854 DRAW_NORMAL_TEXT
, 0);
22857 if (row
->used
[LEFT_MARGIN_AREA
])
22858 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22859 if (row
->used
[TEXT_AREA
])
22860 expose_area (w
, row
, r
, TEXT_AREA
);
22861 if (row
->used
[RIGHT_MARGIN_AREA
])
22862 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22863 draw_row_fringe_bitmaps (w
, row
);
22866 return row
->mouse_face_p
;
22870 /* Redraw those parts of glyphs rows during expose event handling that
22871 overlap other rows. Redrawing of an exposed line writes over parts
22872 of lines overlapping that exposed line; this function fixes that.
22874 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22875 row in W's current matrix that is exposed and overlaps other rows.
22876 LAST_OVERLAPPING_ROW is the last such row. */
22879 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22881 struct glyph_row
*first_overlapping_row
;
22882 struct glyph_row
*last_overlapping_row
;
22884 struct glyph_row
*row
;
22886 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22887 if (row
->overlapping_p
)
22889 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22891 if (row
->used
[LEFT_MARGIN_AREA
])
22892 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
22894 if (row
->used
[TEXT_AREA
])
22895 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
22897 if (row
->used
[RIGHT_MARGIN_AREA
])
22898 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
22903 /* Return non-zero if W's cursor intersects rectangle R. */
22906 phys_cursor_in_rect_p (w
, r
)
22910 XRectangle cr
, result
;
22911 struct glyph
*cursor_glyph
;
22913 cursor_glyph
= get_phys_cursor_glyph (w
);
22916 /* r is relative to W's box, but w->phys_cursor.x is relative
22917 to left edge of W's TEXT area. Adjust it. */
22918 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22919 cr
.y
= w
->phys_cursor
.y
;
22920 cr
.width
= cursor_glyph
->pixel_width
;
22921 cr
.height
= w
->phys_cursor_height
;
22922 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22923 I assume the effect is the same -- and this is portable. */
22924 return x_intersect_rectangles (&cr
, r
, &result
);
22926 /* If we don't understand the format, pretend we're not in the hot-spot. */
22932 Draw a vertical window border to the right of window W if W doesn't
22933 have vertical scroll bars. */
22936 x_draw_vertical_border (w
)
22939 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22941 /* We could do better, if we knew what type of scroll-bar the adjacent
22942 windows (on either side) have... But we don't :-(
22943 However, I think this works ok. ++KFS 2003-04-25 */
22945 /* Redraw borders between horizontally adjacent windows. Don't
22946 do it for frames with vertical scroll bars because either the
22947 right scroll bar of a window, or the left scroll bar of its
22948 neighbor will suffice as a border. */
22949 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22952 if (!WINDOW_RIGHTMOST_P (w
)
22953 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22955 int x0
, x1
, y0
, y1
;
22957 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22960 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22963 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
22965 else if (!WINDOW_LEFTMOST_P (w
)
22966 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22968 int x0
, x1
, y0
, y1
;
22970 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22973 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22976 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
22981 /* Redraw the part of window W intersection rectangle FR. Pixel
22982 coordinates in FR are frame-relative. Call this function with
22983 input blocked. Value is non-zero if the exposure overwrites
22987 expose_window (w
, fr
)
22991 struct frame
*f
= XFRAME (w
->frame
);
22993 int mouse_face_overwritten_p
= 0;
22995 /* If window is not yet fully initialized, do nothing. This can
22996 happen when toolkit scroll bars are used and a window is split.
22997 Reconfiguring the scroll bar will generate an expose for a newly
22999 if (w
->current_matrix
== NULL
)
23002 /* When we're currently updating the window, display and current
23003 matrix usually don't agree. Arrange for a thorough display
23005 if (w
== updated_window
)
23007 SET_FRAME_GARBAGED (f
);
23011 /* Frame-relative pixel rectangle of W. */
23012 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23013 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23014 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23015 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23017 if (x_intersect_rectangles (fr
, &wr
, &r
))
23019 int yb
= window_text_bottom_y (w
);
23020 struct glyph_row
*row
;
23021 int cursor_cleared_p
;
23022 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23024 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23025 r
.x
, r
.y
, r
.width
, r
.height
));
23027 /* Convert to window coordinates. */
23028 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23029 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23031 /* Turn off the cursor. */
23032 if (!w
->pseudo_window_p
23033 && phys_cursor_in_rect_p (w
, &r
))
23035 x_clear_cursor (w
);
23036 cursor_cleared_p
= 1;
23039 cursor_cleared_p
= 0;
23041 /* Update lines intersecting rectangle R. */
23042 first_overlapping_row
= last_overlapping_row
= NULL
;
23043 for (row
= w
->current_matrix
->rows
;
23048 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23050 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23051 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23052 || (r
.y
>= y0
&& r
.y
< y1
)
23053 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23055 /* A header line may be overlapping, but there is no need
23056 to fix overlapping areas for them. KFS 2005-02-12 */
23057 if (row
->overlapping_p
&& !row
->mode_line_p
)
23059 if (first_overlapping_row
== NULL
)
23060 first_overlapping_row
= row
;
23061 last_overlapping_row
= row
;
23064 if (expose_line (w
, row
, &r
))
23065 mouse_face_overwritten_p
= 1;
23072 /* Display the mode line if there is one. */
23073 if (WINDOW_WANTS_MODELINE_P (w
)
23074 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23076 && row
->y
< r
.y
+ r
.height
)
23078 if (expose_line (w
, row
, &r
))
23079 mouse_face_overwritten_p
= 1;
23082 if (!w
->pseudo_window_p
)
23084 /* Fix the display of overlapping rows. */
23085 if (first_overlapping_row
)
23086 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23088 /* Draw border between windows. */
23089 x_draw_vertical_border (w
);
23091 /* Turn the cursor on again. */
23092 if (cursor_cleared_p
)
23093 update_window_cursor (w
, 1);
23097 return mouse_face_overwritten_p
;
23102 /* Redraw (parts) of all windows in the window tree rooted at W that
23103 intersect R. R contains frame pixel coordinates. Value is
23104 non-zero if the exposure overwrites mouse-face. */
23107 expose_window_tree (w
, r
)
23111 struct frame
*f
= XFRAME (w
->frame
);
23112 int mouse_face_overwritten_p
= 0;
23114 while (w
&& !FRAME_GARBAGED_P (f
))
23116 if (!NILP (w
->hchild
))
23117 mouse_face_overwritten_p
23118 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23119 else if (!NILP (w
->vchild
))
23120 mouse_face_overwritten_p
23121 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23123 mouse_face_overwritten_p
|= expose_window (w
, r
);
23125 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23128 return mouse_face_overwritten_p
;
23133 Redisplay an exposed area of frame F. X and Y are the upper-left
23134 corner of the exposed rectangle. W and H are width and height of
23135 the exposed area. All are pixel values. W or H zero means redraw
23136 the entire frame. */
23139 expose_frame (f
, x
, y
, w
, h
)
23144 int mouse_face_overwritten_p
= 0;
23146 TRACE ((stderr
, "expose_frame "));
23148 /* No need to redraw if frame will be redrawn soon. */
23149 if (FRAME_GARBAGED_P (f
))
23151 TRACE ((stderr
, " garbaged\n"));
23155 /* If basic faces haven't been realized yet, there is no point in
23156 trying to redraw anything. This can happen when we get an expose
23157 event while Emacs is starting, e.g. by moving another window. */
23158 if (FRAME_FACE_CACHE (f
) == NULL
23159 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23161 TRACE ((stderr
, " no faces\n"));
23165 if (w
== 0 || h
== 0)
23168 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23169 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23179 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23180 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23182 if (WINDOWP (f
->tool_bar_window
))
23183 mouse_face_overwritten_p
23184 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23186 #ifdef HAVE_X_WINDOWS
23188 #ifndef USE_X_TOOLKIT
23189 if (WINDOWP (f
->menu_bar_window
))
23190 mouse_face_overwritten_p
23191 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23192 #endif /* not USE_X_TOOLKIT */
23196 /* Some window managers support a focus-follows-mouse style with
23197 delayed raising of frames. Imagine a partially obscured frame,
23198 and moving the mouse into partially obscured mouse-face on that
23199 frame. The visible part of the mouse-face will be highlighted,
23200 then the WM raises the obscured frame. With at least one WM, KDE
23201 2.1, Emacs is not getting any event for the raising of the frame
23202 (even tried with SubstructureRedirectMask), only Expose events.
23203 These expose events will draw text normally, i.e. not
23204 highlighted. Which means we must redo the highlight here.
23205 Subsume it under ``we love X''. --gerd 2001-08-15 */
23206 /* Included in Windows version because Windows most likely does not
23207 do the right thing if any third party tool offers
23208 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23209 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23211 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23212 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23214 int x
= dpyinfo
->mouse_face_mouse_x
;
23215 int y
= dpyinfo
->mouse_face_mouse_y
;
23216 clear_mouse_face (dpyinfo
);
23217 note_mouse_highlight (f
, x
, y
);
23224 Determine the intersection of two rectangles R1 and R2. Return
23225 the intersection in *RESULT. Value is non-zero if RESULT is not
23229 x_intersect_rectangles (r1
, r2
, result
)
23230 XRectangle
*r1
, *r2
, *result
;
23232 XRectangle
*left
, *right
;
23233 XRectangle
*upper
, *lower
;
23234 int intersection_p
= 0;
23236 /* Rearrange so that R1 is the left-most rectangle. */
23238 left
= r1
, right
= r2
;
23240 left
= r2
, right
= r1
;
23242 /* X0 of the intersection is right.x0, if this is inside R1,
23243 otherwise there is no intersection. */
23244 if (right
->x
<= left
->x
+ left
->width
)
23246 result
->x
= right
->x
;
23248 /* The right end of the intersection is the minimum of the
23249 the right ends of left and right. */
23250 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23253 /* Same game for Y. */
23255 upper
= r1
, lower
= r2
;
23257 upper
= r2
, lower
= r1
;
23259 /* The upper end of the intersection is lower.y0, if this is inside
23260 of upper. Otherwise, there is no intersection. */
23261 if (lower
->y
<= upper
->y
+ upper
->height
)
23263 result
->y
= lower
->y
;
23265 /* The lower end of the intersection is the minimum of the lower
23266 ends of upper and lower. */
23267 result
->height
= (min (lower
->y
+ lower
->height
,
23268 upper
->y
+ upper
->height
)
23270 intersection_p
= 1;
23274 return intersection_p
;
23277 #endif /* HAVE_WINDOW_SYSTEM */
23280 /***********************************************************************
23282 ***********************************************************************/
23287 Vwith_echo_area_save_vector
= Qnil
;
23288 staticpro (&Vwith_echo_area_save_vector
);
23290 Vmessage_stack
= Qnil
;
23291 staticpro (&Vmessage_stack
);
23293 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23294 staticpro (&Qinhibit_redisplay
);
23296 message_dolog_marker1
= Fmake_marker ();
23297 staticpro (&message_dolog_marker1
);
23298 message_dolog_marker2
= Fmake_marker ();
23299 staticpro (&message_dolog_marker2
);
23300 message_dolog_marker3
= Fmake_marker ();
23301 staticpro (&message_dolog_marker3
);
23304 defsubr (&Sdump_frame_glyph_matrix
);
23305 defsubr (&Sdump_glyph_matrix
);
23306 defsubr (&Sdump_glyph_row
);
23307 defsubr (&Sdump_tool_bar_row
);
23308 defsubr (&Strace_redisplay
);
23309 defsubr (&Strace_to_stderr
);
23311 #ifdef HAVE_WINDOW_SYSTEM
23312 defsubr (&Stool_bar_lines_needed
);
23313 defsubr (&Slookup_image_map
);
23315 defsubr (&Sformat_mode_line
);
23317 staticpro (&Qmenu_bar_update_hook
);
23318 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23320 staticpro (&Qoverriding_terminal_local_map
);
23321 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23323 staticpro (&Qoverriding_local_map
);
23324 Qoverriding_local_map
= intern ("overriding-local-map");
23326 staticpro (&Qwindow_scroll_functions
);
23327 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23329 staticpro (&Qredisplay_end_trigger_functions
);
23330 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23332 staticpro (&Qinhibit_point_motion_hooks
);
23333 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23335 QCdata
= intern (":data");
23336 staticpro (&QCdata
);
23337 Qdisplay
= intern ("display");
23338 staticpro (&Qdisplay
);
23339 Qspace_width
= intern ("space-width");
23340 staticpro (&Qspace_width
);
23341 Qraise
= intern ("raise");
23342 staticpro (&Qraise
);
23343 Qslice
= intern ("slice");
23344 staticpro (&Qslice
);
23345 Qspace
= intern ("space");
23346 staticpro (&Qspace
);
23347 Qmargin
= intern ("margin");
23348 staticpro (&Qmargin
);
23349 Qpointer
= intern ("pointer");
23350 staticpro (&Qpointer
);
23351 Qleft_margin
= intern ("left-margin");
23352 staticpro (&Qleft_margin
);
23353 Qright_margin
= intern ("right-margin");
23354 staticpro (&Qright_margin
);
23355 Qcenter
= intern ("center");
23356 staticpro (&Qcenter
);
23357 Qline_height
= intern ("line-height");
23358 staticpro (&Qline_height
);
23359 QCalign_to
= intern (":align-to");
23360 staticpro (&QCalign_to
);
23361 QCrelative_width
= intern (":relative-width");
23362 staticpro (&QCrelative_width
);
23363 QCrelative_height
= intern (":relative-height");
23364 staticpro (&QCrelative_height
);
23365 QCeval
= intern (":eval");
23366 staticpro (&QCeval
);
23367 QCpropertize
= intern (":propertize");
23368 staticpro (&QCpropertize
);
23369 QCfile
= intern (":file");
23370 staticpro (&QCfile
);
23371 Qfontified
= intern ("fontified");
23372 staticpro (&Qfontified
);
23373 Qfontification_functions
= intern ("fontification-functions");
23374 staticpro (&Qfontification_functions
);
23375 Qtrailing_whitespace
= intern ("trailing-whitespace");
23376 staticpro (&Qtrailing_whitespace
);
23377 Qescape_glyph
= intern ("escape-glyph");
23378 staticpro (&Qescape_glyph
);
23379 Qnobreak_space
= intern ("nobreak-space");
23380 staticpro (&Qnobreak_space
);
23381 Qimage
= intern ("image");
23382 staticpro (&Qimage
);
23383 QCmap
= intern (":map");
23384 staticpro (&QCmap
);
23385 QCpointer
= intern (":pointer");
23386 staticpro (&QCpointer
);
23387 Qrect
= intern ("rect");
23388 staticpro (&Qrect
);
23389 Qcircle
= intern ("circle");
23390 staticpro (&Qcircle
);
23391 Qpoly
= intern ("poly");
23392 staticpro (&Qpoly
);
23393 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23394 staticpro (&Qmessage_truncate_lines
);
23395 Qgrow_only
= intern ("grow-only");
23396 staticpro (&Qgrow_only
);
23397 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23398 staticpro (&Qinhibit_menubar_update
);
23399 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23400 staticpro (&Qinhibit_eval_during_redisplay
);
23401 Qposition
= intern ("position");
23402 staticpro (&Qposition
);
23403 Qbuffer_position
= intern ("buffer-position");
23404 staticpro (&Qbuffer_position
);
23405 Qobject
= intern ("object");
23406 staticpro (&Qobject
);
23407 Qbar
= intern ("bar");
23409 Qhbar
= intern ("hbar");
23410 staticpro (&Qhbar
);
23411 Qbox
= intern ("box");
23413 Qhollow
= intern ("hollow");
23414 staticpro (&Qhollow
);
23415 Qhand
= intern ("hand");
23416 staticpro (&Qhand
);
23417 Qarrow
= intern ("arrow");
23418 staticpro (&Qarrow
);
23419 Qtext
= intern ("text");
23420 staticpro (&Qtext
);
23421 Qrisky_local_variable
= intern ("risky-local-variable");
23422 staticpro (&Qrisky_local_variable
);
23423 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23424 staticpro (&Qinhibit_free_realized_faces
);
23426 list_of_error
= Fcons (Fcons (intern ("error"),
23427 Fcons (intern ("void-variable"), Qnil
)),
23429 staticpro (&list_of_error
);
23431 Qlast_arrow_position
= intern ("last-arrow-position");
23432 staticpro (&Qlast_arrow_position
);
23433 Qlast_arrow_string
= intern ("last-arrow-string");
23434 staticpro (&Qlast_arrow_string
);
23436 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23437 staticpro (&Qoverlay_arrow_string
);
23438 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23439 staticpro (&Qoverlay_arrow_bitmap
);
23441 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23442 staticpro (&echo_buffer
[0]);
23443 staticpro (&echo_buffer
[1]);
23445 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23446 staticpro (&echo_area_buffer
[0]);
23447 staticpro (&echo_area_buffer
[1]);
23449 Vmessages_buffer_name
= build_string ("*Messages*");
23450 staticpro (&Vmessages_buffer_name
);
23452 mode_line_proptrans_alist
= Qnil
;
23453 staticpro (&mode_line_proptrans_alist
);
23454 mode_line_string_list
= Qnil
;
23455 staticpro (&mode_line_string_list
);
23456 mode_line_string_face
= Qnil
;
23457 staticpro (&mode_line_string_face
);
23458 mode_line_string_face_prop
= Qnil
;
23459 staticpro (&mode_line_string_face_prop
);
23460 Vmode_line_unwind_vector
= Qnil
;
23461 staticpro (&Vmode_line_unwind_vector
);
23463 help_echo_string
= Qnil
;
23464 staticpro (&help_echo_string
);
23465 help_echo_object
= Qnil
;
23466 staticpro (&help_echo_object
);
23467 help_echo_window
= Qnil
;
23468 staticpro (&help_echo_window
);
23469 previous_help_echo_string
= Qnil
;
23470 staticpro (&previous_help_echo_string
);
23471 help_echo_pos
= -1;
23473 #ifdef HAVE_WINDOW_SYSTEM
23474 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23475 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23476 For example, if a block cursor is over a tab, it will be drawn as
23477 wide as that tab on the display. */);
23478 x_stretch_cursor_p
= 0;
23481 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23482 doc
: /* *Non-nil means highlight trailing whitespace.
23483 The face used for trailing whitespace is `trailing-whitespace'. */);
23484 Vshow_trailing_whitespace
= Qnil
;
23486 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23487 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23488 A value of t means highlight the character itself (for nobreak space,
23489 use face `nobreak-space').
23490 A value of nil means no highlighting.
23491 Other values mean display the escape glyph followed by an ordinary
23492 space or ordinary hyphen. */);
23493 Vnobreak_char_display
= Qt
;
23495 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23496 doc
: /* *The pointer shape to show in void text areas.
23497 A value of nil means to show the text pointer. Other options are `arrow',
23498 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23499 Vvoid_text_area_pointer
= Qarrow
;
23501 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23502 doc
: /* Non-nil means don't actually do any redisplay.
23503 This is used for internal purposes. */);
23504 Vinhibit_redisplay
= Qnil
;
23506 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23507 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23508 Vglobal_mode_string
= Qnil
;
23510 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23511 doc
: /* Marker for where to display an arrow on top of the buffer text.
23512 This must be the beginning of a line in order to work.
23513 See also `overlay-arrow-string'. */);
23514 Voverlay_arrow_position
= Qnil
;
23516 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23517 doc
: /* String to display as an arrow in non-window frames.
23518 See also `overlay-arrow-position'. */);
23519 Voverlay_arrow_string
= build_string ("=>");
23521 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23522 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23523 The symbols on this list are examined during redisplay to determine
23524 where to display overlay arrows. */);
23525 Voverlay_arrow_variable_list
23526 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23528 DEFVAR_INT ("scroll-step", &scroll_step
,
23529 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23530 If that fails to bring point back on frame, point is centered instead.
23531 If this is zero, point is always centered after it moves off frame.
23532 If you want scrolling to always be a line at a time, you should set
23533 `scroll-conservatively' to a large value rather than set this to 1. */);
23535 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23536 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23537 A value of zero means to scroll the text to center point vertically
23538 in the window. */);
23539 scroll_conservatively
= 0;
23541 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23542 doc
: /* *Number of lines of margin at the top and bottom of a window.
23543 Recenter the window whenever point gets within this many lines
23544 of the top or bottom of the window. */);
23547 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23548 doc
: /* Pixels per inch value for non-window system displays.
23549 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23550 Vdisplay_pixels_per_inch
= make_float (72.0);
23553 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23556 DEFVAR_BOOL ("truncate-partial-width-windows",
23557 &truncate_partial_width_windows
,
23558 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23559 truncate_partial_width_windows
= 1;
23561 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23562 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23563 Any other value means to use the appropriate face, `mode-line',
23564 `header-line', or `menu' respectively. */);
23565 mode_line_inverse_video
= 1;
23567 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23568 doc
: /* *Maximum buffer size for which line number should be displayed.
23569 If the buffer is bigger than this, the line number does not appear
23570 in the mode line. A value of nil means no limit. */);
23571 Vline_number_display_limit
= Qnil
;
23573 DEFVAR_INT ("line-number-display-limit-width",
23574 &line_number_display_limit_width
,
23575 doc
: /* *Maximum line width (in characters) for line number display.
23576 If the average length of the lines near point is bigger than this, then the
23577 line number may be omitted from the mode line. */);
23578 line_number_display_limit_width
= 200;
23580 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23581 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23582 highlight_nonselected_windows
= 0;
23584 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23585 doc
: /* Non-nil if more than one frame is visible on this display.
23586 Minibuffer-only frames don't count, but iconified frames do.
23587 This variable is not guaranteed to be accurate except while processing
23588 `frame-title-format' and `icon-title-format'. */);
23590 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23591 doc
: /* Template for displaying the title bar of visible frames.
23592 \(Assuming the window manager supports this feature.)
23593 This variable has the same structure as `mode-line-format' (which see),
23594 and is used only on frames for which no explicit name has been set
23595 \(see `modify-frame-parameters'). */);
23597 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23598 doc
: /* Template for displaying the title bar of an iconified frame.
23599 \(Assuming the window manager supports this feature.)
23600 This variable has the same structure as `mode-line-format' (which see),
23601 and is used only on frames for which no explicit name has been set
23602 \(see `modify-frame-parameters'). */);
23604 = Vframe_title_format
23605 = Fcons (intern ("multiple-frames"),
23606 Fcons (build_string ("%b"),
23607 Fcons (Fcons (empty_string
,
23608 Fcons (intern ("invocation-name"),
23609 Fcons (build_string ("@"),
23610 Fcons (intern ("system-name"),
23614 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23615 doc
: /* Maximum number of lines to keep in the message log buffer.
23616 If nil, disable message logging. If t, log messages but don't truncate
23617 the buffer when it becomes large. */);
23618 Vmessage_log_max
= make_number (50);
23620 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23621 doc
: /* Functions called before redisplay, if window sizes have changed.
23622 The value should be a list of functions that take one argument.
23623 Just before redisplay, for each frame, if any of its windows have changed
23624 size since the last redisplay, or have been split or deleted,
23625 all the functions in the list are called, with the frame as argument. */);
23626 Vwindow_size_change_functions
= Qnil
;
23628 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23629 doc
: /* List of functions to call before redisplaying a window with scrolling.
23630 Each function is called with two arguments, the window
23631 and its new display-start position. Note that the value of `window-end'
23632 is not valid when these functions are called. */);
23633 Vwindow_scroll_functions
= Qnil
;
23635 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23636 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23637 Each function is called with two arguments, the window and the end trigger value.
23638 See `set-window-redisplay-end-trigger'. */);
23639 Vredisplay_end_trigger_functions
= Qnil
;
23641 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23642 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23643 mouse_autoselect_window
= 0;
23645 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23646 doc
: /* *Non-nil means automatically resize tool-bars.
23647 This increases a tool-bar's height if not all tool-bar items are visible.
23648 It decreases a tool-bar's height when it would display blank lines
23650 auto_resize_tool_bars_p
= 1;
23652 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23653 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23654 auto_raise_tool_bar_buttons_p
= 1;
23656 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23657 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23658 make_cursor_line_fully_visible_p
= 1;
23660 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23661 doc
: /* *Margin around tool-bar buttons in pixels.
23662 If an integer, use that for both horizontal and vertical margins.
23663 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23664 HORZ specifying the horizontal margin, and VERT specifying the
23665 vertical margin. */);
23666 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23668 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23669 doc
: /* *Relief thickness of tool-bar buttons. */);
23670 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23672 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23673 doc
: /* List of functions to call to fontify regions of text.
23674 Each function is called with one argument POS. Functions must
23675 fontify a region starting at POS in the current buffer, and give
23676 fontified regions the property `fontified'. */);
23677 Vfontification_functions
= Qnil
;
23678 Fmake_variable_buffer_local (Qfontification_functions
);
23680 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23681 &unibyte_display_via_language_environment
,
23682 doc
: /* *Non-nil means display unibyte text according to language environment.
23683 Specifically this means that unibyte non-ASCII characters
23684 are displayed by converting them to the equivalent multibyte characters
23685 according to the current language environment. As a result, they are
23686 displayed according to the current fontset. */);
23687 unibyte_display_via_language_environment
= 0;
23689 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23690 doc
: /* *Maximum height for resizing mini-windows.
23691 If a float, it specifies a fraction of the mini-window frame's height.
23692 If an integer, it specifies a number of lines. */);
23693 Vmax_mini_window_height
= make_float (0.25);
23695 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23696 doc
: /* *How to resize mini-windows.
23697 A value of nil means don't automatically resize mini-windows.
23698 A value of t means resize them to fit the text displayed in them.
23699 A value of `grow-only', the default, means let mini-windows grow
23700 only, until their display becomes empty, at which point the windows
23701 go back to their normal size. */);
23702 Vresize_mini_windows
= Qgrow_only
;
23704 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23705 doc
: /* Alist specifying how to blink the cursor off.
23706 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23707 `cursor-type' frame-parameter or variable equals ON-STATE,
23708 comparing using `equal', Emacs uses OFF-STATE to specify
23709 how to blink it off. ON-STATE and OFF-STATE are values for
23710 the `cursor-type' frame parameter.
23712 If a frame's ON-STATE has no entry in this list,
23713 the frame's other specifications determine how to blink the cursor off. */);
23714 Vblink_cursor_alist
= Qnil
;
23716 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23717 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23718 automatic_hscrolling_p
= 1;
23720 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23721 doc
: /* *How many columns away from the window edge point is allowed to get
23722 before automatic hscrolling will horizontally scroll the window. */);
23723 hscroll_margin
= 5;
23725 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23726 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23727 When point is less than `automatic-hscroll-margin' columns from the window
23728 edge, automatic hscrolling will scroll the window by the amount of columns
23729 determined by this variable. If its value is a positive integer, scroll that
23730 many columns. If it's a positive floating-point number, it specifies the
23731 fraction of the window's width to scroll. If it's nil or zero, point will be
23732 centered horizontally after the scroll. Any other value, including negative
23733 numbers, are treated as if the value were zero.
23735 Automatic hscrolling always moves point outside the scroll margin, so if
23736 point was more than scroll step columns inside the margin, the window will
23737 scroll more than the value given by the scroll step.
23739 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23740 and `scroll-right' overrides this variable's effect. */);
23741 Vhscroll_step
= make_number (0);
23743 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23744 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23745 Bind this around calls to `message' to let it take effect. */);
23746 message_truncate_lines
= 0;
23748 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23749 doc
: /* Normal hook run to update the menu bar definitions.
23750 Redisplay runs this hook before it redisplays the menu bar.
23751 This is used to update submenus such as Buffers,
23752 whose contents depend on various data. */);
23753 Vmenu_bar_update_hook
= Qnil
;
23755 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23756 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23757 inhibit_menubar_update
= 0;
23759 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23760 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23761 inhibit_eval_during_redisplay
= 0;
23763 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23764 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23765 inhibit_free_realized_faces
= 0;
23768 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23769 doc
: /* Inhibit try_window_id display optimization. */);
23770 inhibit_try_window_id
= 0;
23772 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23773 doc
: /* Inhibit try_window_reusing display optimization. */);
23774 inhibit_try_window_reusing
= 0;
23776 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23777 doc
: /* Inhibit try_cursor_movement display optimization. */);
23778 inhibit_try_cursor_movement
= 0;
23779 #endif /* GLYPH_DEBUG */
23783 /* Initialize this module when Emacs starts. */
23788 Lisp_Object root_window
;
23789 struct window
*mini_w
;
23791 current_header_line_height
= current_mode_line_height
= -1;
23793 CHARPOS (this_line_start_pos
) = 0;
23795 mini_w
= XWINDOW (minibuf_window
);
23796 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23798 if (!noninteractive
)
23800 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23803 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23804 set_window_height (root_window
,
23805 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23807 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23808 set_window_height (minibuf_window
, 1, 0);
23810 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23811 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23813 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23814 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23815 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23817 /* The default ellipsis glyphs `...'. */
23818 for (i
= 0; i
< 3; ++i
)
23819 default_invis_vector
[i
] = make_number ('.');
23823 /* Allocate the buffer for frame titles.
23824 Also used for `format-mode-line'. */
23826 mode_line_noprop_buf
= (char *) xmalloc (size
);
23827 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23828 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23829 mode_line_target
= MODE_LINE_DISPLAY
;
23832 help_echo_showing_p
= 0;
23836 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23837 (do not change this comment) */