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, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
175 #include "keyboard.h"
178 #include "termchar.h"
179 #include "dispextern.h"
181 #include "character.h"
184 #include "commands.h"
188 #include "termhooks.h"
189 #include "intervals.h"
192 #include "region-cache.h"
195 #include "blockinput.h"
197 #ifdef HAVE_X_WINDOWS
212 #ifndef FRAME_X_OUTPUT
213 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
216 #define INFINITY 10000000
218 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
219 || defined(HAVE_NS) || defined (USE_GTK)
220 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
221 extern int pending_menu_activation
;
224 extern int interrupt_input
;
225 extern int command_loop_level
;
227 extern Lisp_Object do_mouse_tracking
;
229 extern int minibuffer_auto_raise
;
230 extern Lisp_Object Vminibuffer_list
;
232 extern Lisp_Object Qface
;
233 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
235 extern Lisp_Object Voverriding_local_map
;
236 extern Lisp_Object Voverriding_local_map_menu_flag
;
237 extern Lisp_Object Qmenu_item
;
238 extern Lisp_Object Qwhen
;
239 extern Lisp_Object Qhelp_echo
;
240 extern Lisp_Object Qbefore_string
, Qafter_string
;
242 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
243 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
244 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
245 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
246 Lisp_Object Qinhibit_point_motion_hooks
;
247 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
248 Lisp_Object Qfontified
;
249 Lisp_Object Qgrow_only
;
250 Lisp_Object Qinhibit_eval_during_redisplay
;
251 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
254 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
257 Lisp_Object Qarrow
, Qhand
, Qtext
;
259 Lisp_Object Qrisky_local_variable
;
261 /* Holds the list (error). */
262 Lisp_Object list_of_error
;
264 /* Functions called to fontify regions of text. */
266 Lisp_Object Vfontification_functions
;
267 Lisp_Object Qfontification_functions
;
269 /* Non-nil means automatically select any window when the mouse
270 cursor moves into it. */
271 Lisp_Object Vmouse_autoselect_window
;
273 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
274 Lisp_Object Vline_prefix
, Qline_prefix
;
276 /* Non-zero means draw tool bar buttons raised when the mouse moves
279 int auto_raise_tool_bar_buttons_p
;
281 /* Non-zero means to reposition window if cursor line is only partially visible. */
283 int make_cursor_line_fully_visible_p
;
285 /* Margin below tool bar in pixels. 0 or nil means no margin.
286 If value is `internal-border-width' or `border-width',
287 the corresponding frame parameter is used. */
289 Lisp_Object Vtool_bar_border
;
291 /* Margin around tool bar buttons in pixels. */
293 Lisp_Object Vtool_bar_button_margin
;
295 /* Thickness of shadow to draw around tool bar buttons. */
297 EMACS_INT tool_bar_button_relief
;
299 /* Non-nil means automatically resize tool-bars so that all tool-bar
300 items are visible, and no blank lines remain.
302 If value is `grow-only', only make tool-bar bigger. */
304 Lisp_Object Vauto_resize_tool_bars
;
306 /* Non-zero means draw block and hollow cursor as wide as the glyph
307 under it. For example, if a block cursor is over a tab, it will be
308 drawn as wide as that tab on the display. */
310 int x_stretch_cursor_p
;
312 /* Non-nil means don't actually do any redisplay. */
314 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
316 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
318 int inhibit_eval_during_redisplay
;
320 /* Names of text properties relevant for redisplay. */
322 Lisp_Object Qdisplay
;
323 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
325 /* Symbols used in text property values. */
327 Lisp_Object Vdisplay_pixels_per_inch
;
328 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
329 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
332 Lisp_Object Qmargin
, Qpointer
;
333 Lisp_Object Qline_height
;
334 extern Lisp_Object Qheight
;
335 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
336 extern Lisp_Object Qscroll_bar
;
337 extern Lisp_Object Qcursor
;
339 /* Non-nil means highlight trailing whitespace. */
341 Lisp_Object Vshow_trailing_whitespace
;
343 /* Non-nil means escape non-break space and hyphens. */
345 Lisp_Object Vnobreak_char_display
;
347 #ifdef HAVE_WINDOW_SYSTEM
348 extern Lisp_Object Voverflow_newline_into_fringe
;
350 /* Test if overflow newline into fringe. Called with iterator IT
351 at or past right window margin, and with IT->current_x set. */
353 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
354 (!NILP (Voverflow_newline_into_fringe) \
355 && FRAME_WINDOW_P (it->f) \
356 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
357 && it->current_x == it->last_visible_x \
358 && it->line_wrap != WORD_WRAP)
360 #else /* !HAVE_WINDOW_SYSTEM */
361 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
362 #endif /* HAVE_WINDOW_SYSTEM */
364 /* Test if the display element loaded in IT is a space or tab
365 character. This is used to determine word wrapping. */
367 #define IT_DISPLAYING_WHITESPACE(it) \
368 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
370 /* Non-nil means show the text cursor in void text areas
371 i.e. in blank areas after eol and eob. This used to be
372 the default in 21.3. */
374 Lisp_Object Vvoid_text_area_pointer
;
376 /* Name of the face used to highlight trailing whitespace. */
378 Lisp_Object Qtrailing_whitespace
;
380 /* Name and number of the face used to highlight escape glyphs. */
382 Lisp_Object Qescape_glyph
;
384 /* Name and number of the face used to highlight non-breaking spaces. */
386 Lisp_Object Qnobreak_space
;
388 /* The symbol `image' which is the car of the lists used to represent
393 /* The image map types. */
394 Lisp_Object QCmap
, QCpointer
;
395 Lisp_Object Qrect
, Qcircle
, Qpoly
;
397 /* Non-zero means print newline to stdout before next mini-buffer
400 int noninteractive_need_newline
;
402 /* Non-zero means print newline to message log before next message. */
404 static int message_log_need_newline
;
406 /* Three markers that message_dolog uses.
407 It could allocate them itself, but that causes trouble
408 in handling memory-full errors. */
409 static Lisp_Object message_dolog_marker1
;
410 static Lisp_Object message_dolog_marker2
;
411 static Lisp_Object message_dolog_marker3
;
413 /* The buffer position of the first character appearing entirely or
414 partially on the line of the selected window which contains the
415 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
416 redisplay optimization in redisplay_internal. */
418 static struct text_pos this_line_start_pos
;
420 /* Number of characters past the end of the line above, including the
421 terminating newline. */
423 static struct text_pos this_line_end_pos
;
425 /* The vertical positions and the height of this line. */
427 static int this_line_vpos
;
428 static int this_line_y
;
429 static int this_line_pixel_height
;
431 /* X position at which this display line starts. Usually zero;
432 negative if first character is partially visible. */
434 static int this_line_start_x
;
436 /* Buffer that this_line_.* variables are referring to. */
438 static struct buffer
*this_line_buffer
;
440 /* Nonzero means truncate lines in all windows less wide than the
443 Lisp_Object Vtruncate_partial_width_windows
;
445 /* A flag to control how to display unibyte 8-bit character. */
447 int unibyte_display_via_language_environment
;
449 /* Nonzero means we have more than one non-mini-buffer-only frame.
450 Not guaranteed to be accurate except while parsing
451 frame-title-format. */
455 Lisp_Object Vglobal_mode_string
;
458 /* List of variables (symbols) which hold markers for overlay arrows.
459 The symbols on this list are examined during redisplay to determine
460 where to display overlay arrows. */
462 Lisp_Object Voverlay_arrow_variable_list
;
464 /* Marker for where to display an arrow on top of the buffer text. */
466 Lisp_Object Voverlay_arrow_position
;
468 /* String to display for the arrow. Only used on terminal frames. */
470 Lisp_Object Voverlay_arrow_string
;
472 /* Values of those variables at last redisplay are stored as
473 properties on `overlay-arrow-position' symbol. However, if
474 Voverlay_arrow_position is a marker, last-arrow-position is its
475 numerical position. */
477 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
479 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
480 properties on a symbol in overlay-arrow-variable-list. */
482 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
484 /* Like mode-line-format, but for the title bar on a visible frame. */
486 Lisp_Object Vframe_title_format
;
488 /* Like mode-line-format, but for the title bar on an iconified frame. */
490 Lisp_Object Vicon_title_format
;
492 /* List of functions to call when a window's size changes. These
493 functions get one arg, a frame on which one or more windows' sizes
496 static Lisp_Object Vwindow_size_change_functions
;
498 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
500 /* Nonzero if an overlay arrow has been displayed in this window. */
502 static int overlay_arrow_seen
;
504 /* Nonzero means highlight the region even in nonselected windows. */
506 int highlight_nonselected_windows
;
508 /* If cursor motion alone moves point off frame, try scrolling this
509 many lines up or down if that will bring it back. */
511 static EMACS_INT scroll_step
;
513 /* Nonzero means scroll just far enough to bring point back on the
514 screen, when appropriate. */
516 static EMACS_INT scroll_conservatively
;
518 /* Recenter the window whenever point gets within this many lines of
519 the top or bottom of the window. This value is translated into a
520 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
521 that there is really a fixed pixel height scroll margin. */
523 EMACS_INT scroll_margin
;
525 /* Number of windows showing the buffer of the selected window (or
526 another buffer with the same base buffer). keyboard.c refers to
531 /* Vector containing glyphs for an ellipsis `...'. */
533 static Lisp_Object default_invis_vector
[3];
535 /* Zero means display the mode-line/header-line/menu-bar in the default face
536 (this slightly odd definition is for compatibility with previous versions
537 of emacs), non-zero means display them using their respective faces.
539 This variable is deprecated. */
541 int mode_line_inverse_video
;
543 /* Prompt to display in front of the mini-buffer contents. */
545 Lisp_Object minibuf_prompt
;
547 /* Width of current mini-buffer prompt. Only set after display_line
548 of the line that contains the prompt. */
550 int minibuf_prompt_width
;
552 /* This is the window where the echo area message was displayed. It
553 is always a mini-buffer window, but it may not be the same window
554 currently active as a mini-buffer. */
556 Lisp_Object echo_area_window
;
558 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
559 pushes the current message and the value of
560 message_enable_multibyte on the stack, the function restore_message
561 pops the stack and displays MESSAGE again. */
563 Lisp_Object Vmessage_stack
;
565 /* Nonzero means multibyte characters were enabled when the echo area
566 message was specified. */
568 int message_enable_multibyte
;
570 /* Nonzero if we should redraw the mode lines on the next redisplay. */
572 int update_mode_lines
;
574 /* Nonzero if window sizes or contents have changed since last
575 redisplay that finished. */
577 int windows_or_buffers_changed
;
579 /* Nonzero means a frame's cursor type has been changed. */
581 int cursor_type_changed
;
583 /* Nonzero after display_mode_line if %l was used and it displayed a
586 int line_number_displayed
;
588 /* Maximum buffer size for which to display line numbers. */
590 Lisp_Object Vline_number_display_limit
;
592 /* Line width to consider when repositioning for line number display. */
594 static EMACS_INT line_number_display_limit_width
;
596 /* Number of lines to keep in the message log buffer. t means
597 infinite. nil means don't log at all. */
599 Lisp_Object Vmessage_log_max
;
601 /* The name of the *Messages* buffer, a string. */
603 static Lisp_Object Vmessages_buffer_name
;
605 /* Current, index 0, and last displayed echo area message. Either
606 buffers from echo_buffers, or nil to indicate no message. */
608 Lisp_Object echo_area_buffer
[2];
610 /* The buffers referenced from echo_area_buffer. */
612 static Lisp_Object echo_buffer
[2];
614 /* A vector saved used in with_area_buffer to reduce consing. */
616 static Lisp_Object Vwith_echo_area_save_vector
;
618 /* Non-zero means display_echo_area should display the last echo area
619 message again. Set by redisplay_preserve_echo_area. */
621 static int display_last_displayed_message_p
;
623 /* Nonzero if echo area is being used by print; zero if being used by
626 int message_buf_print
;
628 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
630 Lisp_Object Qinhibit_menubar_update
;
631 int inhibit_menubar_update
;
633 /* When evaluating expressions from menu bar items (enable conditions,
634 for instance), this is the frame they are being processed for. */
636 Lisp_Object Vmenu_updating_frame
;
638 /* Maximum height for resizing mini-windows. Either a float
639 specifying a fraction of the available height, or an integer
640 specifying a number of lines. */
642 Lisp_Object Vmax_mini_window_height
;
644 /* Non-zero means messages should be displayed with truncated
645 lines instead of being continued. */
647 int message_truncate_lines
;
648 Lisp_Object Qmessage_truncate_lines
;
650 /* Set to 1 in clear_message to make redisplay_internal aware
651 of an emptied echo area. */
653 static int message_cleared_p
;
655 /* How to blink the default frame cursor off. */
656 Lisp_Object Vblink_cursor_alist
;
658 /* A scratch glyph row with contents used for generating truncation
659 glyphs. Also used in direct_output_for_insert. */
661 #define MAX_SCRATCH_GLYPHS 100
662 struct glyph_row scratch_glyph_row
;
663 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
665 /* Ascent and height of the last line processed by move_it_to. */
667 static int last_max_ascent
, last_height
;
669 /* Non-zero if there's a help-echo in the echo area. */
671 int help_echo_showing_p
;
673 /* If >= 0, computed, exact values of mode-line and header-line height
674 to use in the macros CURRENT_MODE_LINE_HEIGHT and
675 CURRENT_HEADER_LINE_HEIGHT. */
677 int current_mode_line_height
, current_header_line_height
;
679 /* The maximum distance to look ahead for text properties. Values
680 that are too small let us call compute_char_face and similar
681 functions too often which is expensive. Values that are too large
682 let us call compute_char_face and alike too often because we
683 might not be interested in text properties that far away. */
685 #define TEXT_PROP_DISTANCE_LIMIT 100
689 /* Variables to turn off display optimizations from Lisp. */
691 int inhibit_try_window_id
, inhibit_try_window_reusing
;
692 int inhibit_try_cursor_movement
;
694 /* Non-zero means print traces of redisplay if compiled with
697 int trace_redisplay_p
;
699 #endif /* GLYPH_DEBUG */
701 #ifdef DEBUG_TRACE_MOVE
702 /* Non-zero means trace with TRACE_MOVE to stderr. */
705 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
707 #define TRACE_MOVE(x) (void) 0
710 /* Non-zero means automatically scroll windows horizontally to make
713 int automatic_hscrolling_p
;
714 Lisp_Object Qauto_hscroll_mode
;
716 /* How close to the margin can point get before the window is scrolled
718 EMACS_INT hscroll_margin
;
720 /* How much to scroll horizontally when point is inside the above margin. */
721 Lisp_Object Vhscroll_step
;
723 /* The variable `resize-mini-windows'. If nil, don't resize
724 mini-windows. If t, always resize them to fit the text they
725 display. If `grow-only', let mini-windows grow only until they
728 Lisp_Object Vresize_mini_windows
;
730 /* Buffer being redisplayed -- for redisplay_window_error. */
732 struct buffer
*displayed_buffer
;
734 /* Space between overline and text. */
736 EMACS_INT overline_margin
;
738 /* Require underline to be at least this many screen pixels below baseline
739 This to avoid underline "merging" with the base of letters at small
740 font sizes, particularly when x_use_underline_position_properties is on. */
742 EMACS_INT underline_minimum_offset
;
744 /* Value returned from text property handlers (see below). */
749 HANDLED_RECOMPUTE_PROPS
,
750 HANDLED_OVERLAY_STRING_CONSUMED
,
754 /* A description of text properties that redisplay is interested
759 /* The name of the property. */
762 /* A unique index for the property. */
765 /* A handler function called to set up iterator IT from the property
766 at IT's current position. Value is used to steer handle_stop. */
767 enum prop_handled (*handler
) P_ ((struct it
*it
));
770 static enum prop_handled handle_face_prop
P_ ((struct it
*));
771 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
772 static enum prop_handled handle_display_prop
P_ ((struct it
*));
773 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
774 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
775 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
777 /* Properties handled by iterators. */
779 static struct props it_props
[] =
781 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
782 /* Handle `face' before `display' because some sub-properties of
783 `display' need to know the face. */
784 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
785 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
786 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
787 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
791 /* Value is the position described by X. If X is a marker, value is
792 the marker_position of X. Otherwise, value is X. */
794 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
796 /* Enumeration returned by some move_it_.* functions internally. */
800 /* Not used. Undefined value. */
803 /* Move ended at the requested buffer position or ZV. */
804 MOVE_POS_MATCH_OR_ZV
,
806 /* Move ended at the requested X pixel position. */
809 /* Move within a line ended at the end of a line that must be
813 /* Move within a line ended at the end of a line that would
814 be displayed truncated. */
817 /* Move within a line ended at a line end. */
821 /* This counter is used to clear the face cache every once in a while
822 in redisplay_internal. It is incremented for each redisplay.
823 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
826 #define CLEAR_FACE_CACHE_COUNT 500
827 static int clear_face_cache_count
;
829 /* Similarly for the image cache. */
831 #ifdef HAVE_WINDOW_SYSTEM
832 #define CLEAR_IMAGE_CACHE_COUNT 101
833 static int clear_image_cache_count
;
836 /* Non-zero while redisplay_internal is in progress. */
840 /* Non-zero means don't free realized faces. Bound while freeing
841 realized faces is dangerous because glyph matrices might still
844 int inhibit_free_realized_faces
;
845 Lisp_Object Qinhibit_free_realized_faces
;
847 /* If a string, XTread_socket generates an event to display that string.
848 (The display is done in read_char.) */
850 Lisp_Object help_echo_string
;
851 Lisp_Object help_echo_window
;
852 Lisp_Object help_echo_object
;
855 /* Temporary variable for XTread_socket. */
857 Lisp_Object previous_help_echo_string
;
859 /* Null glyph slice */
861 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
863 /* Platform-independent portion of hourglass implementation. */
865 /* Non-zero means we're allowed to display a hourglass pointer. */
866 int display_hourglass_p
;
868 /* Non-zero means an hourglass cursor is currently shown. */
869 int hourglass_shown_p
;
871 /* If non-null, an asynchronous timer that, when it expires, displays
872 an hourglass cursor on all frames. */
873 struct atimer
*hourglass_atimer
;
875 /* Number of seconds to wait before displaying an hourglass cursor. */
876 Lisp_Object Vhourglass_delay
;
878 /* Default number of seconds to wait before displaying an hourglass
880 #define DEFAULT_HOURGLASS_DELAY 1
883 /* Function prototypes. */
885 static void setup_for_ellipsis
P_ ((struct it
*, int));
886 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
887 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
888 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
889 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
890 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
891 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
893 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
895 static void handle_line_prefix
P_ ((struct it
*));
897 static void pint2str
P_ ((char *, int, int));
898 static void pint2hrstr
P_ ((char *, int, int));
899 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
901 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
902 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
903 static void store_mode_line_noprop_char
P_ ((char));
904 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
905 static void x_consider_frame_title
P_ ((Lisp_Object
));
906 static void handle_stop
P_ ((struct it
*));
907 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
908 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
909 static void ensure_echo_area_buffers
P_ ((void));
910 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
911 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
912 static int with_echo_area_buffer
P_ ((struct window
*, int,
913 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
914 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
915 static void clear_garbaged_frames
P_ ((void));
916 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
918 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int display_echo_area
P_ ((struct window
*));
920 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
921 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
922 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
923 static int string_char_and_length
P_ ((const unsigned char *, int *));
924 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
926 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
927 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
928 static void insert_left_trunc_glyphs
P_ ((struct it
*));
929 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
931 static void extend_face_to_end_of_line
P_ ((struct it
*));
932 static int append_space_for_newline
P_ ((struct it
*, int));
933 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
934 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
935 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
936 static int trailing_whitespace_p
P_ ((int));
937 static int message_log_check_duplicate
P_ ((int, int, int, int));
938 static void push_it
P_ ((struct it
*));
939 static void pop_it
P_ ((struct it
*));
940 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
941 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
942 static void redisplay_internal
P_ ((int));
943 static int echo_area_display
P_ ((int));
944 static void redisplay_windows
P_ ((Lisp_Object
));
945 static void redisplay_window
P_ ((Lisp_Object
, int));
946 static Lisp_Object
redisplay_window_error ();
947 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
948 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
949 static int update_menu_bar
P_ ((struct frame
*, int, int));
950 static int try_window_reusing_current_matrix
P_ ((struct window
*));
951 static int try_window_id
P_ ((struct window
*));
952 static int display_line
P_ ((struct it
*));
953 static int display_mode_lines
P_ ((struct window
*));
954 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
955 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
956 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
957 static char *decode_mode_spec
P_ ((struct window
*, int, int, int,
959 static void display_menu_bar
P_ ((struct window
*));
960 static int display_count_lines
P_ ((int, int, int, int, int *));
961 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
962 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
963 static void compute_line_metrics
P_ ((struct it
*));
964 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
965 static int get_overlay_strings
P_ ((struct it
*, int));
966 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
967 static void next_overlay_string
P_ ((struct it
*));
968 static void reseat
P_ ((struct it
*, struct text_pos
, int));
969 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
970 static void back_to_previous_visible_line_start
P_ ((struct it
*));
971 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
972 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
973 static int next_element_from_ellipsis
P_ ((struct it
*));
974 static int next_element_from_display_vector
P_ ((struct it
*));
975 static int next_element_from_string
P_ ((struct it
*));
976 static int next_element_from_c_string
P_ ((struct it
*));
977 static int next_element_from_buffer
P_ ((struct it
*));
978 static int next_element_from_composition
P_ ((struct it
*));
979 static int next_element_from_image
P_ ((struct it
*));
980 static int next_element_from_stretch
P_ ((struct it
*));
981 static void load_overlay_strings
P_ ((struct it
*, int));
982 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
983 struct display_pos
*));
984 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
985 Lisp_Object
, int, int, int, int));
986 static enum move_it_result
987 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
988 enum move_operation_enum
);
989 void move_it_vertically_backward
P_ ((struct it
*, int));
990 static void init_to_row_start
P_ ((struct it
*, struct window
*,
991 struct glyph_row
*));
992 static int init_to_row_end
P_ ((struct it
*, struct window
*,
993 struct glyph_row
*));
994 static void back_to_previous_line_start
P_ ((struct it
*));
995 static int forward_to_next_line_start
P_ ((struct it
*, int *));
996 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
998 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
999 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
1000 static int number_of_chars
P_ ((unsigned char *, int));
1001 static void compute_stop_pos
P_ ((struct it
*));
1002 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1004 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1005 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1006 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1007 Lisp_Object
, Lisp_Object
,
1008 struct text_pos
*, int));
1009 static int underlying_face_id
P_ ((struct it
*));
1010 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1013 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1014 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1016 #ifdef HAVE_WINDOW_SYSTEM
1018 static void update_tool_bar
P_ ((struct frame
*, int));
1019 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1020 static int redisplay_tool_bar
P_ ((struct frame
*));
1021 static void display_tool_bar_line
P_ ((struct it
*, int));
1022 static void notice_overwritten_cursor
P_ ((struct window
*,
1023 enum glyph_row_area
,
1024 int, int, int, int));
1028 #endif /* HAVE_WINDOW_SYSTEM */
1031 /***********************************************************************
1032 Window display dimensions
1033 ***********************************************************************/
1035 /* Return the bottom boundary y-position for text lines in window W.
1036 This is the first y position at which a line cannot start.
1037 It is relative to the top of the window.
1039 This is the height of W minus the height of a mode line, if any. */
1042 window_text_bottom_y (w
)
1045 int height
= WINDOW_TOTAL_HEIGHT (w
);
1047 if (WINDOW_WANTS_MODELINE_P (w
))
1048 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1052 /* Return the pixel width of display area AREA of window W. AREA < 0
1053 means return the total width of W, not including fringes to
1054 the left and right of the window. */
1057 window_box_width (w
, area
)
1061 int cols
= XFASTINT (w
->total_cols
);
1064 if (!w
->pseudo_window_p
)
1066 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1068 if (area
== TEXT_AREA
)
1070 if (INTEGERP (w
->left_margin_cols
))
1071 cols
-= XFASTINT (w
->left_margin_cols
);
1072 if (INTEGERP (w
->right_margin_cols
))
1073 cols
-= XFASTINT (w
->right_margin_cols
);
1074 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1076 else if (area
== LEFT_MARGIN_AREA
)
1078 cols
= (INTEGERP (w
->left_margin_cols
)
1079 ? XFASTINT (w
->left_margin_cols
) : 0);
1082 else if (area
== RIGHT_MARGIN_AREA
)
1084 cols
= (INTEGERP (w
->right_margin_cols
)
1085 ? XFASTINT (w
->right_margin_cols
) : 0);
1090 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1094 /* Return the pixel height of the display area of window W, not
1095 including mode lines of W, if any. */
1098 window_box_height (w
)
1101 struct frame
*f
= XFRAME (w
->frame
);
1102 int height
= WINDOW_TOTAL_HEIGHT (w
);
1104 xassert (height
>= 0);
1106 /* Note: the code below that determines the mode-line/header-line
1107 height is essentially the same as that contained in the macro
1108 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1109 the appropriate glyph row has its `mode_line_p' flag set,
1110 and if it doesn't, uses estimate_mode_line_height instead. */
1112 if (WINDOW_WANTS_MODELINE_P (w
))
1114 struct glyph_row
*ml_row
1115 = (w
->current_matrix
&& w
->current_matrix
->rows
1116 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1118 if (ml_row
&& ml_row
->mode_line_p
)
1119 height
-= ml_row
->height
;
1121 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1124 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1126 struct glyph_row
*hl_row
1127 = (w
->current_matrix
&& w
->current_matrix
->rows
1128 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1130 if (hl_row
&& hl_row
->mode_line_p
)
1131 height
-= hl_row
->height
;
1133 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1136 /* With a very small font and a mode-line that's taller than
1137 default, we might end up with a negative height. */
1138 return max (0, height
);
1141 /* Return the window-relative coordinate of the left edge of display
1142 area AREA of window W. AREA < 0 means return the left edge of the
1143 whole window, to the right of the left fringe of W. */
1146 window_box_left_offset (w
, area
)
1152 if (w
->pseudo_window_p
)
1155 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1157 if (area
== TEXT_AREA
)
1158 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1159 + window_box_width (w
, LEFT_MARGIN_AREA
));
1160 else if (area
== RIGHT_MARGIN_AREA
)
1161 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1162 + window_box_width (w
, LEFT_MARGIN_AREA
)
1163 + window_box_width (w
, TEXT_AREA
)
1164 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1166 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1167 else if (area
== LEFT_MARGIN_AREA
1168 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1169 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1175 /* Return the window-relative coordinate of the right edge of display
1176 area AREA of window W. AREA < 0 means return the left edge of the
1177 whole window, to the left of the right fringe of W. */
1180 window_box_right_offset (w
, area
)
1184 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1187 /* Return the frame-relative coordinate of the left edge of display
1188 area AREA of window W. AREA < 0 means return the left edge of the
1189 whole window, to the right of the left fringe of W. */
1192 window_box_left (w
, area
)
1196 struct frame
*f
= XFRAME (w
->frame
);
1199 if (w
->pseudo_window_p
)
1200 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1202 x
= (WINDOW_LEFT_EDGE_X (w
)
1203 + window_box_left_offset (w
, area
));
1209 /* Return the frame-relative coordinate of the right edge of display
1210 area AREA of window W. AREA < 0 means return the left edge of the
1211 whole window, to the left of the right fringe of W. */
1214 window_box_right (w
, area
)
1218 return window_box_left (w
, area
) + window_box_width (w
, area
);
1221 /* Get the bounding box of the display area AREA of window W, without
1222 mode lines, in frame-relative coordinates. AREA < 0 means the
1223 whole window, not including the left and right fringes of
1224 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1225 coordinates of the upper-left corner of the box. Return in
1226 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1229 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1232 int *box_x
, *box_y
, *box_width
, *box_height
;
1235 *box_width
= window_box_width (w
, area
);
1237 *box_height
= window_box_height (w
);
1239 *box_x
= window_box_left (w
, area
);
1242 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1243 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1244 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1249 /* Get the bounding box of the display area AREA of window W, without
1250 mode lines. AREA < 0 means the whole window, not including the
1251 left and right fringe of the window. Return in *TOP_LEFT_X
1252 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1253 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1254 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1258 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1259 bottom_right_x
, bottom_right_y
)
1262 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1264 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1266 *bottom_right_x
+= *top_left_x
;
1267 *bottom_right_y
+= *top_left_y
;
1272 /***********************************************************************
1274 ***********************************************************************/
1276 /* Return the bottom y-position of the line the iterator IT is in.
1277 This can modify IT's settings. */
1283 int line_height
= it
->max_ascent
+ it
->max_descent
;
1284 int line_top_y
= it
->current_y
;
1286 if (line_height
== 0)
1289 line_height
= last_height
;
1290 else if (IT_CHARPOS (*it
) < ZV
)
1292 move_it_by_lines (it
, 1, 1);
1293 line_height
= (it
->max_ascent
|| it
->max_descent
1294 ? it
->max_ascent
+ it
->max_descent
1299 struct glyph_row
*row
= it
->glyph_row
;
1301 /* Use the default character height. */
1302 it
->glyph_row
= NULL
;
1303 it
->what
= IT_CHARACTER
;
1306 PRODUCE_GLYPHS (it
);
1307 line_height
= it
->ascent
+ it
->descent
;
1308 it
->glyph_row
= row
;
1312 return line_top_y
+ line_height
;
1316 /* Return 1 if position CHARPOS is visible in window W.
1317 CHARPOS < 0 means return info about WINDOW_END position.
1318 If visible, set *X and *Y to pixel coordinates of top left corner.
1319 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1320 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1323 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1325 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1328 struct text_pos top
;
1330 struct buffer
*old_buffer
= NULL
;
1332 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1335 if (XBUFFER (w
->buffer
) != current_buffer
)
1337 old_buffer
= current_buffer
;
1338 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1341 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1343 /* Compute exact mode line heights. */
1344 if (WINDOW_WANTS_MODELINE_P (w
))
1345 current_mode_line_height
1346 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1347 current_buffer
->mode_line_format
);
1349 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1350 current_header_line_height
1351 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1352 current_buffer
->header_line_format
);
1354 start_display (&it
, w
, top
);
1355 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1356 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1358 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1360 /* We have reached CHARPOS, or passed it. How the call to
1361 move_it_to can overshoot: (i) If CHARPOS is on invisible
1362 text, move_it_to stops at the end of the invisible text,
1363 after CHARPOS. (ii) If CHARPOS is in a display vector,
1364 move_it_to stops on its last glyph. */
1365 int top_x
= it
.current_x
;
1366 int top_y
= it
.current_y
;
1367 enum it_method it_method
= it
.method
;
1368 /* Calling line_bottom_y may change it.method, it.position, etc. */
1369 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1370 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1372 if (top_y
< window_top_y
)
1373 visible_p
= bottom_y
> window_top_y
;
1374 else if (top_y
< it
.last_visible_y
)
1378 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1380 /* We stopped on the last glyph of a display vector.
1381 Try and recompute. Hack alert! */
1382 if (charpos
< 2 || top
.charpos
>= charpos
)
1383 top_x
= it
.glyph_row
->x
;
1387 start_display (&it2
, w
, top
);
1388 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1389 get_next_display_element (&it2
);
1390 PRODUCE_GLYPHS (&it2
);
1391 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1392 || it2
.current_x
> it2
.last_visible_x
)
1393 top_x
= it
.glyph_row
->x
;
1396 top_x
= it2
.current_x
;
1397 top_y
= it2
.current_y
;
1403 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1404 *rtop
= max (0, window_top_y
- top_y
);
1405 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1406 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1407 - max (top_y
, window_top_y
)));
1416 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1417 move_it_by_lines (&it
, 1, 0);
1418 if (charpos
< IT_CHARPOS (it
)
1419 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1422 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1424 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1425 *rtop
= max (0, -it2
.current_y
);
1426 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1427 - it
.last_visible_y
));
1428 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1430 - max (it2
.current_y
,
1431 WINDOW_HEADER_LINE_HEIGHT (w
))));
1437 set_buffer_internal_1 (old_buffer
);
1439 current_header_line_height
= current_mode_line_height
= -1;
1441 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1442 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1445 /* Debugging code. */
1447 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1448 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1450 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1457 /* Return the next character from STR which is MAXLEN bytes long.
1458 Return in *LEN the length of the character. This is like
1459 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1460 we find one, we return a `?', but with the length of the invalid
1464 string_char_and_length (str
, len
)
1465 const unsigned char *str
;
1470 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1471 if (!CHAR_VALID_P (c
, 1))
1472 /* We may not change the length here because other places in Emacs
1473 don't use this function, i.e. they silently accept invalid
1482 /* Given a position POS containing a valid character and byte position
1483 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1485 static struct text_pos
1486 string_pos_nchars_ahead (pos
, string
, nchars
)
1487 struct text_pos pos
;
1491 xassert (STRINGP (string
) && nchars
>= 0);
1493 if (STRING_MULTIBYTE (string
))
1495 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1496 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1501 string_char_and_length (p
, &len
);
1502 p
+= len
, rest
-= len
;
1503 xassert (rest
>= 0);
1505 BYTEPOS (pos
) += len
;
1509 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1515 /* Value is the text position, i.e. character and byte position,
1516 for character position CHARPOS in STRING. */
1518 static INLINE
struct text_pos
1519 string_pos (charpos
, string
)
1523 struct text_pos pos
;
1524 xassert (STRINGP (string
));
1525 xassert (charpos
>= 0);
1526 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1531 /* Value is a text position, i.e. character and byte position, for
1532 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1533 means recognize multibyte characters. */
1535 static struct text_pos
1536 c_string_pos (charpos
, s
, multibyte_p
)
1541 struct text_pos pos
;
1543 xassert (s
!= NULL
);
1544 xassert (charpos
>= 0);
1548 int rest
= strlen (s
), len
;
1550 SET_TEXT_POS (pos
, 0, 0);
1553 string_char_and_length (s
, &len
);
1554 s
+= len
, rest
-= len
;
1555 xassert (rest
>= 0);
1557 BYTEPOS (pos
) += len
;
1561 SET_TEXT_POS (pos
, charpos
, charpos
);
1567 /* Value is the number of characters in C string S. MULTIBYTE_P
1568 non-zero means recognize multibyte characters. */
1571 number_of_chars (s
, multibyte_p
)
1579 int rest
= strlen (s
), len
;
1580 unsigned char *p
= (unsigned char *) s
;
1582 for (nchars
= 0; rest
> 0; ++nchars
)
1584 string_char_and_length (p
, &len
);
1585 rest
-= len
, p
+= len
;
1589 nchars
= strlen (s
);
1595 /* Compute byte position NEWPOS->bytepos corresponding to
1596 NEWPOS->charpos. POS is a known position in string STRING.
1597 NEWPOS->charpos must be >= POS.charpos. */
1600 compute_string_pos (newpos
, pos
, string
)
1601 struct text_pos
*newpos
, pos
;
1604 xassert (STRINGP (string
));
1605 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1607 if (STRING_MULTIBYTE (string
))
1608 *newpos
= string_pos_nchars_ahead (pos
, string
,
1609 CHARPOS (*newpos
) - CHARPOS (pos
));
1611 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1615 Return an estimation of the pixel height of mode or header lines on
1616 frame F. FACE_ID specifies what line's height to estimate. */
1619 estimate_mode_line_height (f
, face_id
)
1621 enum face_id face_id
;
1623 #ifdef HAVE_WINDOW_SYSTEM
1624 if (FRAME_WINDOW_P (f
))
1626 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1628 /* This function is called so early when Emacs starts that the face
1629 cache and mode line face are not yet initialized. */
1630 if (FRAME_FACE_CACHE (f
))
1632 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1636 height
= FONT_HEIGHT (face
->font
);
1637 if (face
->box_line_width
> 0)
1638 height
+= 2 * face
->box_line_width
;
1649 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1650 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1651 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1652 not force the value into range. */
1655 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1657 register int pix_x
, pix_y
;
1659 NativeRectangle
*bounds
;
1663 #ifdef HAVE_WINDOW_SYSTEM
1664 if (FRAME_WINDOW_P (f
))
1666 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1667 even for negative values. */
1669 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1671 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1673 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1674 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1677 STORE_NATIVE_RECT (*bounds
,
1678 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1679 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1680 FRAME_COLUMN_WIDTH (f
) - 1,
1681 FRAME_LINE_HEIGHT (f
) - 1);
1687 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1688 pix_x
= FRAME_TOTAL_COLS (f
);
1692 else if (pix_y
> FRAME_LINES (f
))
1693 pix_y
= FRAME_LINES (f
);
1703 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1704 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1705 can't tell the positions because W's display is not up to date,
1709 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1712 int *frame_x
, *frame_y
;
1714 #ifdef HAVE_WINDOW_SYSTEM
1715 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1719 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1720 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1722 if (display_completed
)
1724 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1725 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1726 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1732 hpos
+= glyph
->pixel_width
;
1736 /* If first glyph is partially visible, its first visible position is still 0. */
1748 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1749 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1760 #ifdef HAVE_WINDOW_SYSTEM
1762 /* Find the glyph under window-relative coordinates X/Y in window W.
1763 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1764 strings. Return in *HPOS and *VPOS the row and column number of
1765 the glyph found. Return in *AREA the glyph area containing X.
1766 Value is a pointer to the glyph found or null if X/Y is not on
1767 text, or we can't tell because W's current matrix is not up to
1772 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1775 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1777 struct glyph
*glyph
, *end
;
1778 struct glyph_row
*row
= NULL
;
1781 /* Find row containing Y. Give up if some row is not enabled. */
1782 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1784 row
= MATRIX_ROW (w
->current_matrix
, i
);
1785 if (!row
->enabled_p
)
1787 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1794 /* Give up if Y is not in the window. */
1795 if (i
== w
->current_matrix
->nrows
)
1798 /* Get the glyph area containing X. */
1799 if (w
->pseudo_window_p
)
1806 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1808 *area
= LEFT_MARGIN_AREA
;
1809 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1811 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1814 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1818 *area
= RIGHT_MARGIN_AREA
;
1819 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1823 /* Find glyph containing X. */
1824 glyph
= row
->glyphs
[*area
];
1825 end
= glyph
+ row
->used
[*area
];
1827 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1829 x
-= glyph
->pixel_width
;
1839 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1842 *hpos
= glyph
- row
->glyphs
[*area
];
1848 Convert frame-relative x/y to coordinates relative to window W.
1849 Takes pseudo-windows into account. */
1852 frame_to_window_pixel_xy (w
, x
, y
)
1856 if (w
->pseudo_window_p
)
1858 /* A pseudo-window is always full-width, and starts at the
1859 left edge of the frame, plus a frame border. */
1860 struct frame
*f
= XFRAME (w
->frame
);
1861 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1862 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1866 *x
-= WINDOW_LEFT_EDGE_X (w
);
1867 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1872 Return in RECTS[] at most N clipping rectangles for glyph string S.
1873 Return the number of stored rectangles. */
1876 get_glyph_string_clip_rects (s
, rects
, n
)
1877 struct glyph_string
*s
;
1878 NativeRectangle
*rects
;
1886 if (s
->row
->full_width_p
)
1888 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1889 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1890 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1892 /* Unless displaying a mode or menu bar line, which are always
1893 fully visible, clip to the visible part of the row. */
1894 if (s
->w
->pseudo_window_p
)
1895 r
.height
= s
->row
->visible_height
;
1897 r
.height
= s
->height
;
1901 /* This is a text line that may be partially visible. */
1902 r
.x
= window_box_left (s
->w
, s
->area
);
1903 r
.width
= window_box_width (s
->w
, s
->area
);
1904 r
.height
= s
->row
->visible_height
;
1908 if (r
.x
< s
->clip_head
->x
)
1910 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1911 r
.width
-= s
->clip_head
->x
- r
.x
;
1914 r
.x
= s
->clip_head
->x
;
1917 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1919 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1920 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1925 /* If S draws overlapping rows, it's sufficient to use the top and
1926 bottom of the window for clipping because this glyph string
1927 intentionally draws over other lines. */
1928 if (s
->for_overlaps
)
1930 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1931 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1933 /* Alas, the above simple strategy does not work for the
1934 environments with anti-aliased text: if the same text is
1935 drawn onto the same place multiple times, it gets thicker.
1936 If the overlap we are processing is for the erased cursor, we
1937 take the intersection with the rectagle of the cursor. */
1938 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1940 XRectangle rc
, r_save
= r
;
1942 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1943 rc
.y
= s
->w
->phys_cursor
.y
;
1944 rc
.width
= s
->w
->phys_cursor_width
;
1945 rc
.height
= s
->w
->phys_cursor_height
;
1947 x_intersect_rectangles (&r_save
, &rc
, &r
);
1952 /* Don't use S->y for clipping because it doesn't take partially
1953 visible lines into account. For example, it can be negative for
1954 partially visible lines at the top of a window. */
1955 if (!s
->row
->full_width_p
1956 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1957 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1959 r
.y
= max (0, s
->row
->y
);
1962 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1964 /* If drawing the cursor, don't let glyph draw outside its
1965 advertised boundaries. Cleartype does this under some circumstances. */
1966 if (s
->hl
== DRAW_CURSOR
)
1968 struct glyph
*glyph
= s
->first_glyph
;
1973 r
.width
-= s
->x
- r
.x
;
1976 r
.width
= min (r
.width
, glyph
->pixel_width
);
1978 /* If r.y is below window bottom, ensure that we still see a cursor. */
1979 height
= min (glyph
->ascent
+ glyph
->descent
,
1980 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1981 max_y
= window_text_bottom_y (s
->w
) - height
;
1982 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1983 if (s
->ybase
- glyph
->ascent
> max_y
)
1990 /* Don't draw cursor glyph taller than our actual glyph. */
1991 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1992 if (height
< r
.height
)
1994 max_y
= r
.y
+ r
.height
;
1995 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1996 r
.height
= min (max_y
- r
.y
, height
);
2003 XRectangle r_save
= r
;
2005 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2009 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2010 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2012 #ifdef CONVERT_FROM_XRECT
2013 CONVERT_FROM_XRECT (r
, *rects
);
2021 /* If we are processing overlapping and allowed to return
2022 multiple clipping rectangles, we exclude the row of the glyph
2023 string from the clipping rectangle. This is to avoid drawing
2024 the same text on the environment with anti-aliasing. */
2025 #ifdef CONVERT_FROM_XRECT
2028 XRectangle
*rs
= rects
;
2030 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2032 if (s
->for_overlaps
& OVERLAPS_PRED
)
2035 if (r
.y
+ r
.height
> row_y
)
2038 rs
[i
].height
= row_y
- r
.y
;
2044 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2047 if (r
.y
< row_y
+ s
->row
->visible_height
)
2049 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2051 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2052 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2061 #ifdef CONVERT_FROM_XRECT
2062 for (i
= 0; i
< n
; i
++)
2063 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2070 Return in *NR the clipping rectangle for glyph string S. */
2073 get_glyph_string_clip_rect (s
, nr
)
2074 struct glyph_string
*s
;
2075 NativeRectangle
*nr
;
2077 get_glyph_string_clip_rects (s
, nr
, 1);
2082 Return the position and height of the phys cursor in window W.
2083 Set w->phys_cursor_width to width of phys cursor.
2087 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2089 struct glyph_row
*row
;
2090 struct glyph
*glyph
;
2091 int *xp
, *yp
, *heightp
;
2093 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2094 int x
, y
, wd
, h
, h0
, y0
;
2096 /* Compute the width of the rectangle to draw. If on a stretch
2097 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2098 rectangle as wide as the glyph, but use a canonical character
2100 wd
= glyph
->pixel_width
- 1;
2101 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2105 x
= w
->phys_cursor
.x
;
2112 if (glyph
->type
== STRETCH_GLYPH
2113 && !x_stretch_cursor_p
)
2114 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2115 w
->phys_cursor_width
= wd
;
2117 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2119 /* If y is below window bottom, ensure that we still see a cursor. */
2120 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2122 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2123 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2125 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2128 h
= max (h
- (y0
- y
) + 1, h0
);
2133 y0
= window_text_bottom_y (w
) - h0
;
2141 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2142 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2147 * Remember which glyph the mouse is over.
2151 remember_mouse_glyph (f
, gx
, gy
, rect
)
2154 NativeRectangle
*rect
;
2158 struct glyph_row
*r
, *gr
, *end_row
;
2159 enum window_part part
;
2160 enum glyph_row_area area
;
2161 int x
, y
, width
, height
;
2163 /* Try to determine frame pixel position and size of the glyph under
2164 frame pixel coordinates X/Y on frame F. */
2166 if (!f
->glyphs_initialized_p
2167 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2170 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2171 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2175 w
= XWINDOW (window
);
2176 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2177 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2179 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2180 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2182 if (w
->pseudo_window_p
)
2185 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2191 case ON_LEFT_MARGIN
:
2192 area
= LEFT_MARGIN_AREA
;
2195 case ON_RIGHT_MARGIN
:
2196 area
= RIGHT_MARGIN_AREA
;
2199 case ON_HEADER_LINE
:
2201 gr
= (part
== ON_HEADER_LINE
2202 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2203 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2206 goto text_glyph_row_found
;
2213 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2214 if (r
->y
+ r
->height
> y
)
2220 text_glyph_row_found
:
2223 struct glyph
*g
= gr
->glyphs
[area
];
2224 struct glyph
*end
= g
+ gr
->used
[area
];
2226 height
= gr
->height
;
2227 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2228 if (gx
+ g
->pixel_width
> x
)
2233 if (g
->type
== IMAGE_GLYPH
)
2235 /* Don't remember when mouse is over image, as
2236 image may have hot-spots. */
2237 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2240 width
= g
->pixel_width
;
2244 /* Use nominal char spacing at end of line. */
2246 gx
+= (x
/ width
) * width
;
2249 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2250 gx
+= window_box_left_offset (w
, area
);
2254 /* Use nominal line height at end of window. */
2255 gx
= (x
/ width
) * width
;
2257 gy
+= (y
/ height
) * height
;
2261 case ON_LEFT_FRINGE
:
2262 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2263 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2264 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2265 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2268 case ON_RIGHT_FRINGE
:
2269 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2270 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2271 : window_box_right_offset (w
, TEXT_AREA
));
2272 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2276 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2278 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2279 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2280 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2282 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2286 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2287 if (r
->y
+ r
->height
> y
)
2294 height
= gr
->height
;
2297 /* Use nominal line height at end of window. */
2299 gy
+= (y
/ height
) * height
;
2306 /* If there is no glyph under the mouse, then we divide the screen
2307 into a grid of the smallest glyph in the frame, and use that
2310 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2311 round down even for negative values. */
2317 gx
= (gx
/ width
) * width
;
2318 gy
= (gy
/ height
) * height
;
2323 gx
+= WINDOW_LEFT_EDGE_X (w
);
2324 gy
+= WINDOW_TOP_EDGE_Y (w
);
2327 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2329 /* Visible feedback for debugging. */
2332 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2333 f
->output_data
.x
->normal_gc
,
2334 gx
, gy
, width
, height
);
2340 #endif /* HAVE_WINDOW_SYSTEM */
2343 /***********************************************************************
2344 Lisp form evaluation
2345 ***********************************************************************/
2347 /* Error handler for safe_eval and safe_call. */
2350 safe_eval_handler (arg
)
2353 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2358 /* Evaluate SEXPR and return the result, or nil if something went
2359 wrong. Prevent redisplay during the evaluation. */
2361 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2362 Return the result, or nil if something went wrong. Prevent
2363 redisplay during the evaluation. */
2366 safe_call (nargs
, args
)
2372 if (inhibit_eval_during_redisplay
)
2376 int count
= SPECPDL_INDEX ();
2377 struct gcpro gcpro1
;
2380 gcpro1
.nvars
= nargs
;
2381 specbind (Qinhibit_redisplay
, Qt
);
2382 /* Use Qt to ensure debugger does not run,
2383 so there is no possibility of wanting to redisplay. */
2384 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2387 val
= unbind_to (count
, val
);
2394 /* Call function FN with one argument ARG.
2395 Return the result, or nil if something went wrong. */
2398 safe_call1 (fn
, arg
)
2399 Lisp_Object fn
, arg
;
2401 Lisp_Object args
[2];
2404 return safe_call (2, args
);
2407 static Lisp_Object Qeval
;
2410 safe_eval (Lisp_Object sexpr
)
2412 return safe_call1 (Qeval
, sexpr
);
2415 /* Call function FN with one argument ARG.
2416 Return the result, or nil if something went wrong. */
2419 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2421 Lisp_Object args
[3];
2425 return safe_call (3, args
);
2430 /***********************************************************************
2432 ***********************************************************************/
2436 /* Define CHECK_IT to perform sanity checks on iterators.
2437 This is for debugging. It is too slow to do unconditionally. */
2443 if (it
->method
== GET_FROM_STRING
)
2445 xassert (STRINGP (it
->string
));
2446 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2450 xassert (IT_STRING_CHARPOS (*it
) < 0);
2451 if (it
->method
== GET_FROM_BUFFER
)
2453 /* Check that character and byte positions agree. */
2454 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2459 xassert (it
->current
.dpvec_index
>= 0);
2461 xassert (it
->current
.dpvec_index
< 0);
2464 #define CHECK_IT(IT) check_it ((IT))
2468 #define CHECK_IT(IT) (void) 0
2475 /* Check that the window end of window W is what we expect it
2476 to be---the last row in the current matrix displaying text. */
2479 check_window_end (w
)
2482 if (!MINI_WINDOW_P (w
)
2483 && !NILP (w
->window_end_valid
))
2485 struct glyph_row
*row
;
2486 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2487 XFASTINT (w
->window_end_vpos
)),
2489 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2490 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2494 #define CHECK_WINDOW_END(W) check_window_end ((W))
2496 #else /* not GLYPH_DEBUG */
2498 #define CHECK_WINDOW_END(W) (void) 0
2500 #endif /* not GLYPH_DEBUG */
2504 /***********************************************************************
2505 Iterator initialization
2506 ***********************************************************************/
2508 /* Initialize IT for displaying current_buffer in window W, starting
2509 at character position CHARPOS. CHARPOS < 0 means that no buffer
2510 position is specified which is useful when the iterator is assigned
2511 a position later. BYTEPOS is the byte position corresponding to
2512 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2514 If ROW is not null, calls to produce_glyphs with IT as parameter
2515 will produce glyphs in that row.
2517 BASE_FACE_ID is the id of a base face to use. It must be one of
2518 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2519 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2520 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2522 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2523 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2524 will be initialized to use the corresponding mode line glyph row of
2525 the desired matrix of W. */
2528 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2531 int charpos
, bytepos
;
2532 struct glyph_row
*row
;
2533 enum face_id base_face_id
;
2535 int highlight_region_p
;
2536 enum face_id remapped_base_face_id
= base_face_id
;
2538 /* Some precondition checks. */
2539 xassert (w
!= NULL
&& it
!= NULL
);
2540 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2543 /* If face attributes have been changed since the last redisplay,
2544 free realized faces now because they depend on face definitions
2545 that might have changed. Don't free faces while there might be
2546 desired matrices pending which reference these faces. */
2547 if (face_change_count
&& !inhibit_free_realized_faces
)
2549 face_change_count
= 0;
2550 free_all_realized_faces (Qnil
);
2553 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2554 if (! NILP (Vface_remapping_alist
))
2555 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2557 /* Use one of the mode line rows of W's desired matrix if
2561 if (base_face_id
== MODE_LINE_FACE_ID
2562 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2563 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2564 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2565 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2569 bzero (it
, sizeof *it
);
2570 it
->current
.overlay_string_index
= -1;
2571 it
->current
.dpvec_index
= -1;
2572 it
->base_face_id
= remapped_base_face_id
;
2574 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2576 /* The window in which we iterate over current_buffer: */
2577 XSETWINDOW (it
->window
, w
);
2579 it
->f
= XFRAME (w
->frame
);
2583 /* Extra space between lines (on window systems only). */
2584 if (base_face_id
== DEFAULT_FACE_ID
2585 && FRAME_WINDOW_P (it
->f
))
2587 if (NATNUMP (current_buffer
->extra_line_spacing
))
2588 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2589 else if (FLOATP (current_buffer
->extra_line_spacing
))
2590 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2591 * FRAME_LINE_HEIGHT (it
->f
));
2592 else if (it
->f
->extra_line_spacing
> 0)
2593 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2594 it
->max_extra_line_spacing
= 0;
2597 /* If realized faces have been removed, e.g. because of face
2598 attribute changes of named faces, recompute them. When running
2599 in batch mode, the face cache of the initial frame is null. If
2600 we happen to get called, make a dummy face cache. */
2601 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2602 init_frame_faces (it
->f
);
2603 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2604 recompute_basic_faces (it
->f
);
2606 /* Current value of the `slice', `space-width', and 'height' properties. */
2607 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2608 it
->space_width
= Qnil
;
2609 it
->font_height
= Qnil
;
2610 it
->override_ascent
= -1;
2612 /* Are control characters displayed as `^C'? */
2613 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2615 /* -1 means everything between a CR and the following line end
2616 is invisible. >0 means lines indented more than this value are
2618 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2619 ? XFASTINT (current_buffer
->selective_display
)
2620 : (!NILP (current_buffer
->selective_display
)
2622 it
->selective_display_ellipsis_p
2623 = !NILP (current_buffer
->selective_display_ellipses
);
2625 /* Display table to use. */
2626 it
->dp
= window_display_table (w
);
2628 /* Are multibyte characters enabled in current_buffer? */
2629 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2631 /* Non-zero if we should highlight the region. */
2633 = (!NILP (Vtransient_mark_mode
)
2634 && !NILP (current_buffer
->mark_active
)
2635 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2637 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2638 start and end of a visible region in window IT->w. Set both to
2639 -1 to indicate no region. */
2640 if (highlight_region_p
2641 /* Maybe highlight only in selected window. */
2642 && (/* Either show region everywhere. */
2643 highlight_nonselected_windows
2644 /* Or show region in the selected window. */
2645 || w
== XWINDOW (selected_window
)
2646 /* Or show the region if we are in the mini-buffer and W is
2647 the window the mini-buffer refers to. */
2648 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2649 && WINDOWP (minibuf_selected_window
)
2650 && w
== XWINDOW (minibuf_selected_window
))))
2652 int charpos
= marker_position (current_buffer
->mark
);
2653 it
->region_beg_charpos
= min (PT
, charpos
);
2654 it
->region_end_charpos
= max (PT
, charpos
);
2657 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2659 /* Get the position at which the redisplay_end_trigger hook should
2660 be run, if it is to be run at all. */
2661 if (MARKERP (w
->redisplay_end_trigger
)
2662 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2663 it
->redisplay_end_trigger_charpos
2664 = marker_position (w
->redisplay_end_trigger
);
2665 else if (INTEGERP (w
->redisplay_end_trigger
))
2666 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2668 /* Correct bogus values of tab_width. */
2669 it
->tab_width
= XINT (current_buffer
->tab_width
);
2670 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2673 /* Are lines in the display truncated? */
2674 if (base_face_id
!= DEFAULT_FACE_ID
2675 || XINT (it
->w
->hscroll
)
2676 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2677 && ((!NILP (Vtruncate_partial_width_windows
)
2678 && !INTEGERP (Vtruncate_partial_width_windows
))
2679 || (INTEGERP (Vtruncate_partial_width_windows
)
2680 && (WINDOW_TOTAL_COLS (it
->w
)
2681 < XINT (Vtruncate_partial_width_windows
))))))
2682 it
->line_wrap
= TRUNCATE
;
2683 else if (NILP (current_buffer
->truncate_lines
))
2684 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2685 ? WINDOW_WRAP
: WORD_WRAP
;
2687 it
->line_wrap
= TRUNCATE
;
2689 /* Get dimensions of truncation and continuation glyphs. These are
2690 displayed as fringe bitmaps under X, so we don't need them for such
2692 if (!FRAME_WINDOW_P (it
->f
))
2694 if (it
->line_wrap
== TRUNCATE
)
2696 /* We will need the truncation glyph. */
2697 xassert (it
->glyph_row
== NULL
);
2698 produce_special_glyphs (it
, IT_TRUNCATION
);
2699 it
->truncation_pixel_width
= it
->pixel_width
;
2703 /* We will need the continuation glyph. */
2704 xassert (it
->glyph_row
== NULL
);
2705 produce_special_glyphs (it
, IT_CONTINUATION
);
2706 it
->continuation_pixel_width
= it
->pixel_width
;
2709 /* Reset these values to zero because the produce_special_glyphs
2710 above has changed them. */
2711 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2712 it
->phys_ascent
= it
->phys_descent
= 0;
2715 /* Set this after getting the dimensions of truncation and
2716 continuation glyphs, so that we don't produce glyphs when calling
2717 produce_special_glyphs, above. */
2718 it
->glyph_row
= row
;
2719 it
->area
= TEXT_AREA
;
2721 /* Get the dimensions of the display area. The display area
2722 consists of the visible window area plus a horizontally scrolled
2723 part to the left of the window. All x-values are relative to the
2724 start of this total display area. */
2725 if (base_face_id
!= DEFAULT_FACE_ID
)
2727 /* Mode lines, menu bar in terminal frames. */
2728 it
->first_visible_x
= 0;
2729 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2734 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2735 it
->last_visible_x
= (it
->first_visible_x
2736 + window_box_width (w
, TEXT_AREA
));
2738 /* If we truncate lines, leave room for the truncator glyph(s) at
2739 the right margin. Otherwise, leave room for the continuation
2740 glyph(s). Truncation and continuation glyphs are not inserted
2741 for window-based redisplay. */
2742 if (!FRAME_WINDOW_P (it
->f
))
2744 if (it
->line_wrap
== TRUNCATE
)
2745 it
->last_visible_x
-= it
->truncation_pixel_width
;
2747 it
->last_visible_x
-= it
->continuation_pixel_width
;
2750 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2751 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2754 /* Leave room for a border glyph. */
2755 if (!FRAME_WINDOW_P (it
->f
)
2756 && !WINDOW_RIGHTMOST_P (it
->w
))
2757 it
->last_visible_x
-= 1;
2759 it
->last_visible_y
= window_text_bottom_y (w
);
2761 /* For mode lines and alike, arrange for the first glyph having a
2762 left box line if the face specifies a box. */
2763 if (base_face_id
!= DEFAULT_FACE_ID
)
2767 it
->face_id
= remapped_base_face_id
;
2769 /* If we have a boxed mode line, make the first character appear
2770 with a left box line. */
2771 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2772 if (face
->box
!= FACE_NO_BOX
)
2773 it
->start_of_box_run_p
= 1;
2776 /* If a buffer position was specified, set the iterator there,
2777 getting overlays and face properties from that position. */
2778 if (charpos
>= BUF_BEG (current_buffer
))
2780 it
->end_charpos
= ZV
;
2782 IT_CHARPOS (*it
) = charpos
;
2784 /* Compute byte position if not specified. */
2785 if (bytepos
< charpos
)
2786 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2788 IT_BYTEPOS (*it
) = bytepos
;
2790 it
->start
= it
->current
;
2792 /* Compute faces etc. */
2793 reseat (it
, it
->current
.pos
, 1);
2800 /* Initialize IT for the display of window W with window start POS. */
2803 start_display (it
, w
, pos
)
2806 struct text_pos pos
;
2808 struct glyph_row
*row
;
2809 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2811 row
= w
->desired_matrix
->rows
+ first_vpos
;
2812 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2813 it
->first_vpos
= first_vpos
;
2815 /* Don't reseat to previous visible line start if current start
2816 position is in a string or image. */
2817 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2819 int start_at_line_beg_p
;
2820 int first_y
= it
->current_y
;
2822 /* If window start is not at a line start, skip forward to POS to
2823 get the correct continuation lines width. */
2824 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2825 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2826 if (!start_at_line_beg_p
)
2830 reseat_at_previous_visible_line_start (it
);
2831 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2833 new_x
= it
->current_x
+ it
->pixel_width
;
2835 /* If lines are continued, this line may end in the middle
2836 of a multi-glyph character (e.g. a control character
2837 displayed as \003, or in the middle of an overlay
2838 string). In this case move_it_to above will not have
2839 taken us to the start of the continuation line but to the
2840 end of the continued line. */
2841 if (it
->current_x
> 0
2842 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2843 && (/* And glyph doesn't fit on the line. */
2844 new_x
> it
->last_visible_x
2845 /* Or it fits exactly and we're on a window
2847 || (new_x
== it
->last_visible_x
2848 && FRAME_WINDOW_P (it
->f
))))
2850 if (it
->current
.dpvec_index
>= 0
2851 || it
->current
.overlay_string_index
>= 0)
2853 set_iterator_to_next (it
, 1);
2854 move_it_in_display_line_to (it
, -1, -1, 0);
2857 it
->continuation_lines_width
+= it
->current_x
;
2860 /* We're starting a new display line, not affected by the
2861 height of the continued line, so clear the appropriate
2862 fields in the iterator structure. */
2863 it
->max_ascent
= it
->max_descent
= 0;
2864 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2866 it
->current_y
= first_y
;
2868 it
->current_x
= it
->hpos
= 0;
2874 /* Return 1 if POS is a position in ellipses displayed for invisible
2875 text. W is the window we display, for text property lookup. */
2878 in_ellipses_for_invisible_text_p (pos
, w
)
2879 struct display_pos
*pos
;
2882 Lisp_Object prop
, window
;
2884 int charpos
= CHARPOS (pos
->pos
);
2886 /* If POS specifies a position in a display vector, this might
2887 be for an ellipsis displayed for invisible text. We won't
2888 get the iterator set up for delivering that ellipsis unless
2889 we make sure that it gets aware of the invisible text. */
2890 if (pos
->dpvec_index
>= 0
2891 && pos
->overlay_string_index
< 0
2892 && CHARPOS (pos
->string_pos
) < 0
2894 && (XSETWINDOW (window
, w
),
2895 prop
= Fget_char_property (make_number (charpos
),
2896 Qinvisible
, window
),
2897 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2899 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2901 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2908 /* Initialize IT for stepping through current_buffer in window W,
2909 starting at position POS that includes overlay string and display
2910 vector/ control character translation position information. Value
2911 is zero if there are overlay strings with newlines at POS. */
2914 init_from_display_pos (it
, w
, pos
)
2917 struct display_pos
*pos
;
2919 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2920 int i
, overlay_strings_with_newlines
= 0;
2922 /* If POS specifies a position in a display vector, this might
2923 be for an ellipsis displayed for invisible text. We won't
2924 get the iterator set up for delivering that ellipsis unless
2925 we make sure that it gets aware of the invisible text. */
2926 if (in_ellipses_for_invisible_text_p (pos
, w
))
2932 /* Keep in mind: the call to reseat in init_iterator skips invisible
2933 text, so we might end up at a position different from POS. This
2934 is only a problem when POS is a row start after a newline and an
2935 overlay starts there with an after-string, and the overlay has an
2936 invisible property. Since we don't skip invisible text in
2937 display_line and elsewhere immediately after consuming the
2938 newline before the row start, such a POS will not be in a string,
2939 but the call to init_iterator below will move us to the
2941 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2943 /* This only scans the current chunk -- it should scan all chunks.
2944 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2945 to 16 in 22.1 to make this a lesser problem. */
2946 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2948 const char *s
= SDATA (it
->overlay_strings
[i
]);
2949 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2951 while (s
< e
&& *s
!= '\n')
2956 overlay_strings_with_newlines
= 1;
2961 /* If position is within an overlay string, set up IT to the right
2963 if (pos
->overlay_string_index
>= 0)
2967 /* If the first overlay string happens to have a `display'
2968 property for an image, the iterator will be set up for that
2969 image, and we have to undo that setup first before we can
2970 correct the overlay string index. */
2971 if (it
->method
== GET_FROM_IMAGE
)
2974 /* We already have the first chunk of overlay strings in
2975 IT->overlay_strings. Load more until the one for
2976 pos->overlay_string_index is in IT->overlay_strings. */
2977 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2979 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2980 it
->current
.overlay_string_index
= 0;
2983 load_overlay_strings (it
, 0);
2984 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2988 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2989 relative_index
= (it
->current
.overlay_string_index
2990 % OVERLAY_STRING_CHUNK_SIZE
);
2991 it
->string
= it
->overlay_strings
[relative_index
];
2992 xassert (STRINGP (it
->string
));
2993 it
->current
.string_pos
= pos
->string_pos
;
2994 it
->method
= GET_FROM_STRING
;
2997 if (CHARPOS (pos
->string_pos
) >= 0)
2999 /* Recorded position is not in an overlay string, but in another
3000 string. This can only be a string from a `display' property.
3001 IT should already be filled with that string. */
3002 it
->current
.string_pos
= pos
->string_pos
;
3003 xassert (STRINGP (it
->string
));
3006 /* Restore position in display vector translations, control
3007 character translations or ellipses. */
3008 if (pos
->dpvec_index
>= 0)
3010 if (it
->dpvec
== NULL
)
3011 get_next_display_element (it
);
3012 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3013 it
->current
.dpvec_index
= pos
->dpvec_index
;
3017 return !overlay_strings_with_newlines
;
3021 /* Initialize IT for stepping through current_buffer in window W
3022 starting at ROW->start. */
3025 init_to_row_start (it
, w
, row
)
3028 struct glyph_row
*row
;
3030 init_from_display_pos (it
, w
, &row
->start
);
3031 it
->start
= row
->start
;
3032 it
->continuation_lines_width
= row
->continuation_lines_width
;
3037 /* Initialize IT for stepping through current_buffer in window W
3038 starting in the line following ROW, i.e. starting at ROW->end.
3039 Value is zero if there are overlay strings with newlines at ROW's
3043 init_to_row_end (it
, w
, row
)
3046 struct glyph_row
*row
;
3050 if (init_from_display_pos (it
, w
, &row
->end
))
3052 if (row
->continued_p
)
3053 it
->continuation_lines_width
3054 = row
->continuation_lines_width
+ row
->pixel_width
;
3065 /***********************************************************************
3067 ***********************************************************************/
3069 /* Called when IT reaches IT->stop_charpos. Handle text property and
3070 overlay changes. Set IT->stop_charpos to the next position where
3077 enum prop_handled handled
;
3078 int handle_overlay_change_p
;
3082 it
->current
.dpvec_index
= -1;
3083 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3084 it
->ignore_overlay_strings_at_pos_p
= 0;
3087 /* Use face of preceding text for ellipsis (if invisible) */
3088 if (it
->selective_display_ellipsis_p
)
3089 it
->saved_face_id
= it
->face_id
;
3093 handled
= HANDLED_NORMALLY
;
3095 /* Call text property handlers. */
3096 for (p
= it_props
; p
->handler
; ++p
)
3098 handled
= p
->handler (it
);
3100 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3102 else if (handled
== HANDLED_RETURN
)
3104 /* We still want to show before and after strings from
3105 overlays even if the actual buffer text is replaced. */
3106 if (!handle_overlay_change_p
3108 || !get_overlay_strings_1 (it
, 0, 0))
3111 setup_for_ellipsis (it
, 0);
3112 /* When handling a display spec, we might load an
3113 empty string. In that case, discard it here. We
3114 used to discard it in handle_single_display_spec,
3115 but that causes get_overlay_strings_1, above, to
3116 ignore overlay strings that we must check. */
3117 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3121 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3125 it
->ignore_overlay_strings_at_pos_p
= 1;
3126 it
->string_from_display_prop_p
= 0;
3127 handle_overlay_change_p
= 0;
3129 handled
= HANDLED_RECOMPUTE_PROPS
;
3132 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3133 handle_overlay_change_p
= 0;
3136 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3138 /* Don't check for overlay strings below when set to deliver
3139 characters from a display vector. */
3140 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3141 handle_overlay_change_p
= 0;
3143 /* Handle overlay changes.
3144 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3145 if it finds overlays. */
3146 if (handle_overlay_change_p
)
3147 handled
= handle_overlay_change (it
);
3152 setup_for_ellipsis (it
, 0);
3156 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3158 /* Determine where to stop next. */
3159 if (handled
== HANDLED_NORMALLY
)
3160 compute_stop_pos (it
);
3164 /* Compute IT->stop_charpos from text property and overlay change
3165 information for IT's current position. */
3168 compute_stop_pos (it
)
3171 register INTERVAL iv
, next_iv
;
3172 Lisp_Object object
, limit
, position
;
3173 EMACS_INT charpos
, bytepos
;
3175 /* If nowhere else, stop at the end. */
3176 it
->stop_charpos
= it
->end_charpos
;
3178 if (STRINGP (it
->string
))
3180 /* Strings are usually short, so don't limit the search for
3182 object
= it
->string
;
3184 charpos
= IT_STRING_CHARPOS (*it
);
3185 bytepos
= IT_STRING_BYTEPOS (*it
);
3191 /* If next overlay change is in front of the current stop pos
3192 (which is IT->end_charpos), stop there. Note: value of
3193 next_overlay_change is point-max if no overlay change
3195 charpos
= IT_CHARPOS (*it
);
3196 bytepos
= IT_BYTEPOS (*it
);
3197 pos
= next_overlay_change (charpos
);
3198 if (pos
< it
->stop_charpos
)
3199 it
->stop_charpos
= pos
;
3201 /* If showing the region, we have to stop at the region
3202 start or end because the face might change there. */
3203 if (it
->region_beg_charpos
> 0)
3205 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3206 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3207 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3208 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3211 /* Set up variables for computing the stop position from text
3212 property changes. */
3213 XSETBUFFER (object
, current_buffer
);
3214 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3217 /* Get the interval containing IT's position. Value is a null
3218 interval if there isn't such an interval. */
3219 position
= make_number (charpos
);
3220 iv
= validate_interval_range (object
, &position
, &position
, 0);
3221 if (!NULL_INTERVAL_P (iv
))
3223 Lisp_Object values_here
[LAST_PROP_IDX
];
3226 /* Get properties here. */
3227 for (p
= it_props
; p
->handler
; ++p
)
3228 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3230 /* Look for an interval following iv that has different
3232 for (next_iv
= next_interval (iv
);
3233 (!NULL_INTERVAL_P (next_iv
)
3235 || XFASTINT (limit
) > next_iv
->position
));
3236 next_iv
= next_interval (next_iv
))
3238 for (p
= it_props
; p
->handler
; ++p
)
3240 Lisp_Object new_value
;
3242 new_value
= textget (next_iv
->plist
, *p
->name
);
3243 if (!EQ (values_here
[p
->idx
], new_value
))
3251 if (!NULL_INTERVAL_P (next_iv
))
3253 if (INTEGERP (limit
)
3254 && next_iv
->position
>= XFASTINT (limit
))
3255 /* No text property change up to limit. */
3256 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3258 /* Text properties change in next_iv. */
3259 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3263 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3264 it
->stop_charpos
, it
->string
);
3266 xassert (STRINGP (it
->string
)
3267 || (it
->stop_charpos
>= BEGV
3268 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3272 /* Return the position of the next overlay change after POS in
3273 current_buffer. Value is point-max if no overlay change
3274 follows. This is like `next-overlay-change' but doesn't use
3278 next_overlay_change (pos
)
3283 Lisp_Object
*overlays
;
3286 /* Get all overlays at the given position. */
3287 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3289 /* If any of these overlays ends before endpos,
3290 use its ending point instead. */
3291 for (i
= 0; i
< noverlays
; ++i
)
3296 oend
= OVERLAY_END (overlays
[i
]);
3297 oendpos
= OVERLAY_POSITION (oend
);
3298 endpos
= min (endpos
, oendpos
);
3306 /***********************************************************************
3308 ***********************************************************************/
3310 /* Handle changes in the `fontified' property of the current buffer by
3311 calling hook functions from Qfontification_functions to fontify
3314 static enum prop_handled
3315 handle_fontified_prop (it
)
3318 Lisp_Object prop
, pos
;
3319 enum prop_handled handled
= HANDLED_NORMALLY
;
3321 if (!NILP (Vmemory_full
))
3324 /* Get the value of the `fontified' property at IT's current buffer
3325 position. (The `fontified' property doesn't have a special
3326 meaning in strings.) If the value is nil, call functions from
3327 Qfontification_functions. */
3328 if (!STRINGP (it
->string
)
3330 && !NILP (Vfontification_functions
)
3331 && !NILP (Vrun_hooks
)
3332 && (pos
= make_number (IT_CHARPOS (*it
)),
3333 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3334 /* Ignore the special cased nil value always present at EOB since
3335 no amount of fontifying will be able to change it. */
3336 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3338 int count
= SPECPDL_INDEX ();
3341 val
= Vfontification_functions
;
3342 specbind (Qfontification_functions
, Qnil
);
3344 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3345 safe_call1 (val
, pos
);
3348 Lisp_Object globals
, fn
;
3349 struct gcpro gcpro1
, gcpro2
;
3352 GCPRO2 (val
, globals
);
3354 for (; CONSP (val
); val
= XCDR (val
))
3360 /* A value of t indicates this hook has a local
3361 binding; it means to run the global binding too.
3362 In a global value, t should not occur. If it
3363 does, we must ignore it to avoid an endless
3365 for (globals
= Fdefault_value (Qfontification_functions
);
3367 globals
= XCDR (globals
))
3369 fn
= XCAR (globals
);
3371 safe_call1 (fn
, pos
);
3375 safe_call1 (fn
, pos
);
3381 unbind_to (count
, Qnil
);
3383 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3384 something. This avoids an endless loop if they failed to
3385 fontify the text for which reason ever. */
3386 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3387 handled
= HANDLED_RECOMPUTE_PROPS
;
3395 /***********************************************************************
3397 ***********************************************************************/
3399 /* Set up iterator IT from face properties at its current position.
3400 Called from handle_stop. */
3402 static enum prop_handled
3403 handle_face_prop (it
)
3407 EMACS_INT next_stop
;
3409 if (!STRINGP (it
->string
))
3412 = face_at_buffer_position (it
->w
,
3414 it
->region_beg_charpos
,
3415 it
->region_end_charpos
,
3418 + TEXT_PROP_DISTANCE_LIMIT
),
3419 0, it
->base_face_id
);
3421 /* Is this a start of a run of characters with box face?
3422 Caveat: this can be called for a freshly initialized
3423 iterator; face_id is -1 in this case. We know that the new
3424 face will not change until limit, i.e. if the new face has a
3425 box, all characters up to limit will have one. But, as
3426 usual, we don't know whether limit is really the end. */
3427 if (new_face_id
!= it
->face_id
)
3429 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3431 /* If new face has a box but old face has not, this is
3432 the start of a run of characters with box, i.e. it has
3433 a shadow on the left side. The value of face_id of the
3434 iterator will be -1 if this is the initial call that gets
3435 the face. In this case, we have to look in front of IT's
3436 position and see whether there is a face != new_face_id. */
3437 it
->start_of_box_run_p
3438 = (new_face
->box
!= FACE_NO_BOX
3439 && (it
->face_id
>= 0
3440 || IT_CHARPOS (*it
) == BEG
3441 || new_face_id
!= face_before_it_pos (it
)));
3442 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3447 int base_face_id
, bufpos
;
3449 Lisp_Object from_overlay
3450 = (it
->current
.overlay_string_index
>= 0
3451 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3454 /* See if we got to this string directly or indirectly from
3455 an overlay property. That includes the before-string or
3456 after-string of an overlay, strings in display properties
3457 provided by an overlay, their text properties, etc.
3459 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3460 if (! NILP (from_overlay
))
3461 for (i
= it
->sp
- 1; i
>= 0; i
--)
3463 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3465 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3466 else if (! NILP (it
->stack
[i
].from_overlay
))
3467 from_overlay
= it
->stack
[i
].from_overlay
;
3469 if (!NILP (from_overlay
))
3473 if (! NILP (from_overlay
))
3475 bufpos
= IT_CHARPOS (*it
);
3476 /* For a string from an overlay, the base face depends
3477 only on text properties and ignores overlays. */
3479 = face_for_overlay_string (it
->w
,
3481 it
->region_beg_charpos
,
3482 it
->region_end_charpos
,
3485 + TEXT_PROP_DISTANCE_LIMIT
),
3493 /* For strings from a `display' property, use the face at
3494 IT's current buffer position as the base face to merge
3495 with, so that overlay strings appear in the same face as
3496 surrounding text, unless they specify their own
3498 base_face_id
= underlying_face_id (it
);
3501 new_face_id
= face_at_string_position (it
->w
,
3503 IT_STRING_CHARPOS (*it
),
3505 it
->region_beg_charpos
,
3506 it
->region_end_charpos
,
3510 /* Is this a start of a run of characters with box? Caveat:
3511 this can be called for a freshly allocated iterator; face_id
3512 is -1 is this case. We know that the new face will not
3513 change until the next check pos, i.e. if the new face has a
3514 box, all characters up to that position will have a
3515 box. But, as usual, we don't know whether that position
3516 is really the end. */
3517 if (new_face_id
!= it
->face_id
)
3519 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3520 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3522 /* If new face has a box but old face hasn't, this is the
3523 start of a run of characters with box, i.e. it has a
3524 shadow on the left side. */
3525 it
->start_of_box_run_p
3526 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3527 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3531 it
->face_id
= new_face_id
;
3532 return HANDLED_NORMALLY
;
3536 /* Return the ID of the face ``underlying'' IT's current position,
3537 which is in a string. If the iterator is associated with a
3538 buffer, return the face at IT's current buffer position.
3539 Otherwise, use the iterator's base_face_id. */
3542 underlying_face_id (it
)
3545 int face_id
= it
->base_face_id
, i
;
3547 xassert (STRINGP (it
->string
));
3549 for (i
= it
->sp
- 1; i
>= 0; --i
)
3550 if (NILP (it
->stack
[i
].string
))
3551 face_id
= it
->stack
[i
].face_id
;
3557 /* Compute the face one character before or after the current position
3558 of IT. BEFORE_P non-zero means get the face in front of IT's
3559 position. Value is the id of the face. */
3562 face_before_or_after_it_pos (it
, before_p
)
3567 EMACS_INT next_check_charpos
;
3568 struct text_pos pos
;
3570 xassert (it
->s
== NULL
);
3572 if (STRINGP (it
->string
))
3574 int bufpos
, base_face_id
;
3576 /* No face change past the end of the string (for the case
3577 we are padding with spaces). No face change before the
3579 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3580 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3583 /* Set pos to the position before or after IT's current position. */
3585 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3587 /* For composition, we must check the character after the
3589 pos
= (it
->what
== IT_COMPOSITION
3590 ? string_pos (IT_STRING_CHARPOS (*it
)
3591 + it
->cmp_it
.nchars
, it
->string
)
3592 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3594 if (it
->current
.overlay_string_index
>= 0)
3595 bufpos
= IT_CHARPOS (*it
);
3599 base_face_id
= underlying_face_id (it
);
3601 /* Get the face for ASCII, or unibyte. */
3602 face_id
= face_at_string_position (it
->w
,
3606 it
->region_beg_charpos
,
3607 it
->region_end_charpos
,
3608 &next_check_charpos
,
3611 /* Correct the face for charsets different from ASCII. Do it
3612 for the multibyte case only. The face returned above is
3613 suitable for unibyte text if IT->string is unibyte. */
3614 if (STRING_MULTIBYTE (it
->string
))
3616 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3617 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3619 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3621 c
= string_char_and_length (p
, &len
);
3622 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3627 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3628 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3631 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3632 pos
= it
->current
.pos
;
3635 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3638 if (it
->what
== IT_COMPOSITION
)
3639 /* For composition, we must check the position after the
3641 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3643 INC_TEXT_POS (pos
, it
->multibyte_p
);
3646 /* Determine face for CHARSET_ASCII, or unibyte. */
3647 face_id
= face_at_buffer_position (it
->w
,
3649 it
->region_beg_charpos
,
3650 it
->region_end_charpos
,
3651 &next_check_charpos
,
3654 /* Correct the face for charsets different from ASCII. Do it
3655 for the multibyte case only. The face returned above is
3656 suitable for unibyte text if current_buffer is unibyte. */
3657 if (it
->multibyte_p
)
3659 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3660 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3661 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3670 /***********************************************************************
3672 ***********************************************************************/
3674 /* Set up iterator IT from invisible properties at its current
3675 position. Called from handle_stop. */
3677 static enum prop_handled
3678 handle_invisible_prop (it
)
3681 enum prop_handled handled
= HANDLED_NORMALLY
;
3683 if (STRINGP (it
->string
))
3685 extern Lisp_Object Qinvisible
;
3686 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3688 /* Get the value of the invisible text property at the
3689 current position. Value will be nil if there is no such
3691 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3692 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3695 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3697 handled
= HANDLED_RECOMPUTE_PROPS
;
3699 /* Get the position at which the next change of the
3700 invisible text property can be found in IT->string.
3701 Value will be nil if the property value is the same for
3702 all the rest of IT->string. */
3703 XSETINT (limit
, SCHARS (it
->string
));
3704 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3707 /* Text at current position is invisible. The next
3708 change in the property is at position end_charpos.
3709 Move IT's current position to that position. */
3710 if (INTEGERP (end_charpos
)
3711 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3713 struct text_pos old
;
3714 old
= it
->current
.string_pos
;
3715 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3716 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3720 /* The rest of the string is invisible. If this is an
3721 overlay string, proceed with the next overlay string
3722 or whatever comes and return a character from there. */
3723 if (it
->current
.overlay_string_index
>= 0)
3725 next_overlay_string (it
);
3726 /* Don't check for overlay strings when we just
3727 finished processing them. */
3728 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3732 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3733 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3741 EMACS_INT newpos
, next_stop
, start_charpos
;
3742 Lisp_Object pos
, prop
, overlay
;
3744 /* First of all, is there invisible text at this position? */
3745 start_charpos
= IT_CHARPOS (*it
);
3746 pos
= make_number (IT_CHARPOS (*it
));
3747 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3749 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3751 /* If we are on invisible text, skip over it. */
3752 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3754 /* Record whether we have to display an ellipsis for the
3756 int display_ellipsis_p
= invis_p
== 2;
3758 handled
= HANDLED_RECOMPUTE_PROPS
;
3760 /* Loop skipping over invisible text. The loop is left at
3761 ZV or with IT on the first char being visible again. */
3764 /* Try to skip some invisible text. Return value is the
3765 position reached which can be equal to IT's position
3766 if there is nothing invisible here. This skips both
3767 over invisible text properties and overlays with
3768 invisible property. */
3769 newpos
= skip_invisible (IT_CHARPOS (*it
),
3770 &next_stop
, ZV
, it
->window
);
3772 /* If we skipped nothing at all we weren't at invisible
3773 text in the first place. If everything to the end of
3774 the buffer was skipped, end the loop. */
3775 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3779 /* We skipped some characters but not necessarily
3780 all there are. Check if we ended up on visible
3781 text. Fget_char_property returns the property of
3782 the char before the given position, i.e. if we
3783 get invis_p = 0, this means that the char at
3784 newpos is visible. */
3785 pos
= make_number (newpos
);
3786 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3787 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3790 /* If we ended up on invisible text, proceed to
3791 skip starting with next_stop. */
3793 IT_CHARPOS (*it
) = next_stop
;
3795 /* If there are adjacent invisible texts, don't lose the
3796 second one's ellipsis. */
3798 display_ellipsis_p
= 1;
3802 /* The position newpos is now either ZV or on visible text. */
3803 IT_CHARPOS (*it
) = newpos
;
3804 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3806 /* If there are before-strings at the start of invisible
3807 text, and the text is invisible because of a text
3808 property, arrange to show before-strings because 20.x did
3809 it that way. (If the text is invisible because of an
3810 overlay property instead of a text property, this is
3811 already handled in the overlay code.) */
3813 && get_overlay_strings (it
, start_charpos
))
3815 handled
= HANDLED_RECOMPUTE_PROPS
;
3816 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3818 else if (display_ellipsis_p
)
3820 /* Make sure that the glyphs of the ellipsis will get
3821 correct `charpos' values. If we would not update
3822 it->position here, the glyphs would belong to the
3823 last visible character _before_ the invisible
3824 text, which confuses `set_cursor_from_row'.
3826 We use the last invisible position instead of the
3827 first because this way the cursor is always drawn on
3828 the first "." of the ellipsis, whenever PT is inside
3829 the invisible text. Otherwise the cursor would be
3830 placed _after_ the ellipsis when the point is after the
3831 first invisible character. */
3832 if (!STRINGP (it
->object
))
3834 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3835 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3838 /* Let the ellipsis display before
3839 considering any properties of the following char.
3840 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3841 handled
= HANDLED_RETURN
;
3850 /* Make iterator IT return `...' next.
3851 Replaces LEN characters from buffer. */
3854 setup_for_ellipsis (it
, len
)
3858 /* Use the display table definition for `...'. Invalid glyphs
3859 will be handled by the method returning elements from dpvec. */
3860 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3862 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3863 it
->dpvec
= v
->contents
;
3864 it
->dpend
= v
->contents
+ v
->size
;
3868 /* Default `...'. */
3869 it
->dpvec
= default_invis_vector
;
3870 it
->dpend
= default_invis_vector
+ 3;
3873 it
->dpvec_char_len
= len
;
3874 it
->current
.dpvec_index
= 0;
3875 it
->dpvec_face_id
= -1;
3877 /* Remember the current face id in case glyphs specify faces.
3878 IT's face is restored in set_iterator_to_next.
3879 saved_face_id was set to preceding char's face in handle_stop. */
3880 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3881 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3883 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3889 /***********************************************************************
3891 ***********************************************************************/
3893 /* Set up iterator IT from `display' property at its current position.
3894 Called from handle_stop.
3895 We return HANDLED_RETURN if some part of the display property
3896 overrides the display of the buffer text itself.
3897 Otherwise we return HANDLED_NORMALLY. */
3899 static enum prop_handled
3900 handle_display_prop (it
)
3903 Lisp_Object prop
, object
, overlay
;
3904 struct text_pos
*position
;
3905 /* Nonzero if some property replaces the display of the text itself. */
3906 int display_replaced_p
= 0;
3908 if (STRINGP (it
->string
))
3910 object
= it
->string
;
3911 position
= &it
->current
.string_pos
;
3915 XSETWINDOW (object
, it
->w
);
3916 position
= &it
->current
.pos
;
3919 /* Reset those iterator values set from display property values. */
3920 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3921 it
->space_width
= Qnil
;
3922 it
->font_height
= Qnil
;
3925 /* We don't support recursive `display' properties, i.e. string
3926 values that have a string `display' property, that have a string
3927 `display' property etc. */
3928 if (!it
->string_from_display_prop_p
)
3929 it
->area
= TEXT_AREA
;
3931 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3932 Qdisplay
, object
, &overlay
);
3934 return HANDLED_NORMALLY
;
3935 /* Now OVERLAY is the overlay that gave us this property, or nil
3936 if it was a text property. */
3938 if (!STRINGP (it
->string
))
3939 object
= it
->w
->buffer
;
3942 /* Simple properties. */
3943 && !EQ (XCAR (prop
), Qimage
)
3944 && !EQ (XCAR (prop
), Qspace
)
3945 && !EQ (XCAR (prop
), Qwhen
)
3946 && !EQ (XCAR (prop
), Qslice
)
3947 && !EQ (XCAR (prop
), Qspace_width
)
3948 && !EQ (XCAR (prop
), Qheight
)
3949 && !EQ (XCAR (prop
), Qraise
)
3950 /* Marginal area specifications. */
3951 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3952 && !EQ (XCAR (prop
), Qleft_fringe
)
3953 && !EQ (XCAR (prop
), Qright_fringe
)
3954 && !NILP (XCAR (prop
)))
3956 for (; CONSP (prop
); prop
= XCDR (prop
))
3958 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3959 position
, display_replaced_p
))
3961 display_replaced_p
= 1;
3962 /* If some text in a string is replaced, `position' no
3963 longer points to the position of `object'. */
3964 if (STRINGP (object
))
3969 else if (VECTORP (prop
))
3972 for (i
= 0; i
< ASIZE (prop
); ++i
)
3973 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3974 position
, display_replaced_p
))
3976 display_replaced_p
= 1;
3977 /* If some text in a string is replaced, `position' no
3978 longer points to the position of `object'. */
3979 if (STRINGP (object
))
3985 if (handle_single_display_spec (it
, prop
, object
, overlay
,
3987 display_replaced_p
= 1;
3990 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3994 /* Value is the position of the end of the `display' property starting
3995 at START_POS in OBJECT. */
3997 static struct text_pos
3998 display_prop_end (it
, object
, start_pos
)
4001 struct text_pos start_pos
;
4004 struct text_pos end_pos
;
4006 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4007 Qdisplay
, object
, Qnil
);
4008 CHARPOS (end_pos
) = XFASTINT (end
);
4009 if (STRINGP (object
))
4010 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4012 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4018 /* Set up IT from a single `display' specification PROP. OBJECT
4019 is the object in which the `display' property was found. *POSITION
4020 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4021 means that we previously saw a display specification which already
4022 replaced text display with something else, for example an image;
4023 we ignore such properties after the first one has been processed.
4025 OVERLAY is the overlay this `display' property came from,
4026 or nil if it was a text property.
4028 If PROP is a `space' or `image' specification, and in some other
4029 cases too, set *POSITION to the position where the `display'
4032 Value is non-zero if something was found which replaces the display
4033 of buffer or string text. */
4036 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4037 display_replaced_before_p
)
4041 Lisp_Object overlay
;
4042 struct text_pos
*position
;
4043 int display_replaced_before_p
;
4046 Lisp_Object location
, value
;
4047 struct text_pos start_pos
, save_pos
;
4050 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4051 If the result is non-nil, use VALUE instead of SPEC. */
4053 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4062 if (!NILP (form
) && !EQ (form
, Qt
))
4064 int count
= SPECPDL_INDEX ();
4065 struct gcpro gcpro1
;
4067 /* Bind `object' to the object having the `display' property, a
4068 buffer or string. Bind `position' to the position in the
4069 object where the property was found, and `buffer-position'
4070 to the current position in the buffer. */
4071 specbind (Qobject
, object
);
4072 specbind (Qposition
, make_number (CHARPOS (*position
)));
4073 specbind (Qbuffer_position
,
4074 make_number (STRINGP (object
)
4075 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4077 form
= safe_eval (form
);
4079 unbind_to (count
, Qnil
);
4085 /* Handle `(height HEIGHT)' specifications. */
4087 && EQ (XCAR (spec
), Qheight
)
4088 && CONSP (XCDR (spec
)))
4090 if (!FRAME_WINDOW_P (it
->f
))
4093 it
->font_height
= XCAR (XCDR (spec
));
4094 if (!NILP (it
->font_height
))
4096 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4097 int new_height
= -1;
4099 if (CONSP (it
->font_height
)
4100 && (EQ (XCAR (it
->font_height
), Qplus
)
4101 || EQ (XCAR (it
->font_height
), Qminus
))
4102 && CONSP (XCDR (it
->font_height
))
4103 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4105 /* `(+ N)' or `(- N)' where N is an integer. */
4106 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4107 if (EQ (XCAR (it
->font_height
), Qplus
))
4109 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4111 else if (FUNCTIONP (it
->font_height
))
4113 /* Call function with current height as argument.
4114 Value is the new height. */
4116 height
= safe_call1 (it
->font_height
,
4117 face
->lface
[LFACE_HEIGHT_INDEX
]);
4118 if (NUMBERP (height
))
4119 new_height
= XFLOATINT (height
);
4121 else if (NUMBERP (it
->font_height
))
4123 /* Value is a multiple of the canonical char height. */
4126 face
= FACE_FROM_ID (it
->f
,
4127 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4128 new_height
= (XFLOATINT (it
->font_height
)
4129 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4133 /* Evaluate IT->font_height with `height' bound to the
4134 current specified height to get the new height. */
4135 int count
= SPECPDL_INDEX ();
4137 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4138 value
= safe_eval (it
->font_height
);
4139 unbind_to (count
, Qnil
);
4141 if (NUMBERP (value
))
4142 new_height
= XFLOATINT (value
);
4146 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4152 /* Handle `(space-width WIDTH)'. */
4154 && EQ (XCAR (spec
), Qspace_width
)
4155 && CONSP (XCDR (spec
)))
4157 if (!FRAME_WINDOW_P (it
->f
))
4160 value
= XCAR (XCDR (spec
));
4161 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4162 it
->space_width
= value
;
4167 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4169 && EQ (XCAR (spec
), Qslice
))
4173 if (!FRAME_WINDOW_P (it
->f
))
4176 if (tem
= XCDR (spec
), CONSP (tem
))
4178 it
->slice
.x
= XCAR (tem
);
4179 if (tem
= XCDR (tem
), CONSP (tem
))
4181 it
->slice
.y
= XCAR (tem
);
4182 if (tem
= XCDR (tem
), CONSP (tem
))
4184 it
->slice
.width
= XCAR (tem
);
4185 if (tem
= XCDR (tem
), CONSP (tem
))
4186 it
->slice
.height
= XCAR (tem
);
4194 /* Handle `(raise FACTOR)'. */
4196 && EQ (XCAR (spec
), Qraise
)
4197 && CONSP (XCDR (spec
)))
4199 if (!FRAME_WINDOW_P (it
->f
))
4202 #ifdef HAVE_WINDOW_SYSTEM
4203 value
= XCAR (XCDR (spec
));
4204 if (NUMBERP (value
))
4206 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4207 it
->voffset
= - (XFLOATINT (value
)
4208 * (FONT_HEIGHT (face
->font
)));
4210 #endif /* HAVE_WINDOW_SYSTEM */
4215 /* Don't handle the other kinds of display specifications
4216 inside a string that we got from a `display' property. */
4217 if (it
->string_from_display_prop_p
)
4220 /* Characters having this form of property are not displayed, so
4221 we have to find the end of the property. */
4222 start_pos
= *position
;
4223 *position
= display_prop_end (it
, object
, start_pos
);
4226 /* Stop the scan at that end position--we assume that all
4227 text properties change there. */
4228 it
->stop_charpos
= position
->charpos
;
4230 /* Handle `(left-fringe BITMAP [FACE])'
4231 and `(right-fringe BITMAP [FACE])'. */
4233 && (EQ (XCAR (spec
), Qleft_fringe
)
4234 || EQ (XCAR (spec
), Qright_fringe
))
4235 && CONSP (XCDR (spec
)))
4237 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4240 if (!FRAME_WINDOW_P (it
->f
))
4241 /* If we return here, POSITION has been advanced
4242 across the text with this property. */
4245 #ifdef HAVE_WINDOW_SYSTEM
4246 value
= XCAR (XCDR (spec
));
4247 if (!SYMBOLP (value
)
4248 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4249 /* If we return here, POSITION has been advanced
4250 across the text with this property. */
4253 if (CONSP (XCDR (XCDR (spec
))))
4255 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4256 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4262 /* Save current settings of IT so that we can restore them
4263 when we are finished with the glyph property value. */
4265 save_pos
= it
->position
;
4266 it
->position
= *position
;
4268 it
->position
= save_pos
;
4270 it
->area
= TEXT_AREA
;
4271 it
->what
= IT_IMAGE
;
4272 it
->image_id
= -1; /* no image */
4273 it
->position
= start_pos
;
4274 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4275 it
->method
= GET_FROM_IMAGE
;
4276 it
->from_overlay
= Qnil
;
4277 it
->face_id
= face_id
;
4279 /* Say that we haven't consumed the characters with
4280 `display' property yet. The call to pop_it in
4281 set_iterator_to_next will clean this up. */
4282 *position
= start_pos
;
4284 if (EQ (XCAR (spec
), Qleft_fringe
))
4286 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4287 it
->left_user_fringe_face_id
= face_id
;
4291 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4292 it
->right_user_fringe_face_id
= face_id
;
4294 #endif /* HAVE_WINDOW_SYSTEM */
4298 /* Prepare to handle `((margin left-margin) ...)',
4299 `((margin right-margin) ...)' and `((margin nil) ...)'
4300 prefixes for display specifications. */
4301 location
= Qunbound
;
4302 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4306 value
= XCDR (spec
);
4308 value
= XCAR (value
);
4311 if (EQ (XCAR (tem
), Qmargin
)
4312 && (tem
= XCDR (tem
),
4313 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4315 || EQ (tem
, Qleft_margin
)
4316 || EQ (tem
, Qright_margin
))))
4320 if (EQ (location
, Qunbound
))
4326 /* After this point, VALUE is the property after any
4327 margin prefix has been stripped. It must be a string,
4328 an image specification, or `(space ...)'.
4330 LOCATION specifies where to display: `left-margin',
4331 `right-margin' or nil. */
4333 valid_p
= (STRINGP (value
)
4334 #ifdef HAVE_WINDOW_SYSTEM
4335 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4336 #endif /* not HAVE_WINDOW_SYSTEM */
4337 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4339 if (valid_p
&& !display_replaced_before_p
)
4341 /* Save current settings of IT so that we can restore them
4342 when we are finished with the glyph property value. */
4343 save_pos
= it
->position
;
4344 it
->position
= *position
;
4346 it
->position
= save_pos
;
4347 it
->from_overlay
= overlay
;
4349 if (NILP (location
))
4350 it
->area
= TEXT_AREA
;
4351 else if (EQ (location
, Qleft_margin
))
4352 it
->area
= LEFT_MARGIN_AREA
;
4354 it
->area
= RIGHT_MARGIN_AREA
;
4356 if (STRINGP (value
))
4359 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4360 it
->current
.overlay_string_index
= -1;
4361 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4362 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4363 it
->method
= GET_FROM_STRING
;
4364 it
->stop_charpos
= 0;
4365 it
->string_from_display_prop_p
= 1;
4366 /* Say that we haven't consumed the characters with
4367 `display' property yet. The call to pop_it in
4368 set_iterator_to_next will clean this up. */
4369 if (BUFFERP (object
))
4370 *position
= start_pos
;
4372 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4374 it
->method
= GET_FROM_STRETCH
;
4376 *position
= it
->position
= start_pos
;
4378 #ifdef HAVE_WINDOW_SYSTEM
4381 it
->what
= IT_IMAGE
;
4382 it
->image_id
= lookup_image (it
->f
, value
);
4383 it
->position
= start_pos
;
4384 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4385 it
->method
= GET_FROM_IMAGE
;
4387 /* Say that we haven't consumed the characters with
4388 `display' property yet. The call to pop_it in
4389 set_iterator_to_next will clean this up. */
4390 *position
= start_pos
;
4392 #endif /* HAVE_WINDOW_SYSTEM */
4397 /* Invalid property or property not supported. Restore
4398 POSITION to what it was before. */
4399 *position
= start_pos
;
4404 /* Check if SPEC is a display sub-property value whose text should be
4405 treated as intangible. */
4408 single_display_spec_intangible_p (prop
)
4411 /* Skip over `when FORM'. */
4412 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4426 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4427 we don't need to treat text as intangible. */
4428 if (EQ (XCAR (prop
), Qmargin
))
4436 || EQ (XCAR (prop
), Qleft_margin
)
4437 || EQ (XCAR (prop
), Qright_margin
))
4441 return (CONSP (prop
)
4442 && (EQ (XCAR (prop
), Qimage
)
4443 || EQ (XCAR (prop
), Qspace
)));
4447 /* Check if PROP is a display property value whose text should be
4448 treated as intangible. */
4451 display_prop_intangible_p (prop
)
4455 && CONSP (XCAR (prop
))
4456 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4458 /* A list of sub-properties. */
4459 while (CONSP (prop
))
4461 if (single_display_spec_intangible_p (XCAR (prop
)))
4466 else if (VECTORP (prop
))
4468 /* A vector of sub-properties. */
4470 for (i
= 0; i
< ASIZE (prop
); ++i
)
4471 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4475 return single_display_spec_intangible_p (prop
);
4481 /* Return 1 if PROP is a display sub-property value containing STRING. */
4484 single_display_spec_string_p (prop
, string
)
4485 Lisp_Object prop
, string
;
4487 if (EQ (string
, prop
))
4490 /* Skip over `when FORM'. */
4491 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4500 /* Skip over `margin LOCATION'. */
4501 if (EQ (XCAR (prop
), Qmargin
))
4512 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4516 /* Return 1 if STRING appears in the `display' property PROP. */
4519 display_prop_string_p (prop
, string
)
4520 Lisp_Object prop
, string
;
4523 && CONSP (XCAR (prop
))
4524 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4526 /* A list of sub-properties. */
4527 while (CONSP (prop
))
4529 if (single_display_spec_string_p (XCAR (prop
), string
))
4534 else if (VECTORP (prop
))
4536 /* A vector of sub-properties. */
4538 for (i
= 0; i
< ASIZE (prop
); ++i
)
4539 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4543 return single_display_spec_string_p (prop
, string
);
4549 /* Determine which buffer position in W's buffer STRING comes from.
4550 AROUND_CHARPOS is an approximate position where it could come from.
4551 Value is the buffer position or 0 if it couldn't be determined.
4553 W's buffer must be current.
4555 This function is necessary because we don't record buffer positions
4556 in glyphs generated from strings (to keep struct glyph small).
4557 This function may only use code that doesn't eval because it is
4558 called asynchronously from note_mouse_highlight. */
4561 string_buffer_position (w
, string
, around_charpos
)
4566 Lisp_Object limit
, prop
, pos
;
4567 const int MAX_DISTANCE
= 1000;
4570 pos
= make_number (around_charpos
);
4571 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4572 while (!found
&& !EQ (pos
, limit
))
4574 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4575 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4578 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4583 pos
= make_number (around_charpos
);
4584 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4585 while (!found
&& !EQ (pos
, limit
))
4587 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4588 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4591 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4596 return found
? XINT (pos
) : 0;
4601 /***********************************************************************
4602 `composition' property
4603 ***********************************************************************/
4605 /* Set up iterator IT from `composition' property at its current
4606 position. Called from handle_stop. */
4608 static enum prop_handled
4609 handle_composition_prop (it
)
4612 Lisp_Object prop
, string
;
4613 EMACS_INT pos
, pos_byte
, start
, end
;
4615 if (STRINGP (it
->string
))
4619 pos
= IT_STRING_CHARPOS (*it
);
4620 pos_byte
= IT_STRING_BYTEPOS (*it
);
4621 string
= it
->string
;
4622 s
= SDATA (string
) + pos_byte
;
4623 it
->c
= STRING_CHAR (s
);
4627 pos
= IT_CHARPOS (*it
);
4628 pos_byte
= IT_BYTEPOS (*it
);
4630 it
->c
= FETCH_CHAR (pos_byte
);
4633 /* If there's a valid composition and point is not inside of the
4634 composition (in the case that the composition is from the current
4635 buffer), draw a glyph composed from the composition components. */
4636 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4637 && COMPOSITION_VALID_P (start
, end
, prop
)
4638 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4642 if (STRINGP (it
->string
))
4643 pos_byte
= string_char_to_byte (it
->string
, start
);
4645 pos_byte
= CHAR_TO_BYTE (start
);
4647 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4650 if (it
->cmp_it
.id
>= 0)
4653 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4654 it
->cmp_it
.nglyphs
= -1;
4658 return HANDLED_NORMALLY
;
4663 /***********************************************************************
4665 ***********************************************************************/
4667 /* The following structure is used to record overlay strings for
4668 later sorting in load_overlay_strings. */
4670 struct overlay_entry
4672 Lisp_Object overlay
;
4679 /* Set up iterator IT from overlay strings at its current position.
4680 Called from handle_stop. */
4682 static enum prop_handled
4683 handle_overlay_change (it
)
4686 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4687 return HANDLED_RECOMPUTE_PROPS
;
4689 return HANDLED_NORMALLY
;
4693 /* Set up the next overlay string for delivery by IT, if there is an
4694 overlay string to deliver. Called by set_iterator_to_next when the
4695 end of the current overlay string is reached. If there are more
4696 overlay strings to display, IT->string and
4697 IT->current.overlay_string_index are set appropriately here.
4698 Otherwise IT->string is set to nil. */
4701 next_overlay_string (it
)
4704 ++it
->current
.overlay_string_index
;
4705 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4707 /* No more overlay strings. Restore IT's settings to what
4708 they were before overlay strings were processed, and
4709 continue to deliver from current_buffer. */
4711 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4714 || (NILP (it
->string
)
4715 && it
->method
== GET_FROM_BUFFER
4716 && it
->stop_charpos
>= BEGV
4717 && it
->stop_charpos
<= it
->end_charpos
));
4718 it
->current
.overlay_string_index
= -1;
4719 it
->n_overlay_strings
= 0;
4720 it
->overlay_strings_charpos
= -1;
4722 /* If we're at the end of the buffer, record that we have
4723 processed the overlay strings there already, so that
4724 next_element_from_buffer doesn't try it again. */
4725 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4726 it
->overlay_strings_at_end_processed_p
= 1;
4730 /* There are more overlay strings to process. If
4731 IT->current.overlay_string_index has advanced to a position
4732 where we must load IT->overlay_strings with more strings, do
4733 it. We must load at the IT->overlay_strings_charpos where
4734 IT->n_overlay_strings was originally computed; when invisible
4735 text is present, this might not be IT_CHARPOS (Bug#7016). */
4736 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4738 if (it
->current
.overlay_string_index
&& i
== 0)
4739 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4741 /* Initialize IT to deliver display elements from the overlay
4743 it
->string
= it
->overlay_strings
[i
];
4744 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4745 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4746 it
->method
= GET_FROM_STRING
;
4747 it
->stop_charpos
= 0;
4748 if (it
->cmp_it
.stop_pos
>= 0)
4749 it
->cmp_it
.stop_pos
= 0;
4756 /* Compare two overlay_entry structures E1 and E2. Used as a
4757 comparison function for qsort in load_overlay_strings. Overlay
4758 strings for the same position are sorted so that
4760 1. All after-strings come in front of before-strings, except
4761 when they come from the same overlay.
4763 2. Within after-strings, strings are sorted so that overlay strings
4764 from overlays with higher priorities come first.
4766 2. Within before-strings, strings are sorted so that overlay
4767 strings from overlays with higher priorities come last.
4769 Value is analogous to strcmp. */
4773 compare_overlay_entries (e1
, e2
)
4776 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4777 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4780 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4782 /* Let after-strings appear in front of before-strings if
4783 they come from different overlays. */
4784 if (EQ (entry1
->overlay
, entry2
->overlay
))
4785 result
= entry1
->after_string_p
? 1 : -1;
4787 result
= entry1
->after_string_p
? -1 : 1;
4789 else if (entry1
->after_string_p
)
4790 /* After-strings sorted in order of decreasing priority. */
4791 result
= entry2
->priority
- entry1
->priority
;
4793 /* Before-strings sorted in order of increasing priority. */
4794 result
= entry1
->priority
- entry2
->priority
;
4800 /* Load the vector IT->overlay_strings with overlay strings from IT's
4801 current buffer position, or from CHARPOS if that is > 0. Set
4802 IT->n_overlays to the total number of overlay strings found.
4804 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4805 a time. On entry into load_overlay_strings,
4806 IT->current.overlay_string_index gives the number of overlay
4807 strings that have already been loaded by previous calls to this
4810 IT->add_overlay_start contains an additional overlay start
4811 position to consider for taking overlay strings from, if non-zero.
4812 This position comes into play when the overlay has an `invisible'
4813 property, and both before and after-strings. When we've skipped to
4814 the end of the overlay, because of its `invisible' property, we
4815 nevertheless want its before-string to appear.
4816 IT->add_overlay_start will contain the overlay start position
4819 Overlay strings are sorted so that after-string strings come in
4820 front of before-string strings. Within before and after-strings,
4821 strings are sorted by overlay priority. See also function
4822 compare_overlay_entries. */
4825 load_overlay_strings (it
, charpos
)
4829 extern Lisp_Object Qwindow
, Qpriority
;
4830 Lisp_Object overlay
, window
, str
, invisible
;
4831 struct Lisp_Overlay
*ov
;
4834 int n
= 0, i
, j
, invis_p
;
4835 struct overlay_entry
*entries
4836 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4839 charpos
= IT_CHARPOS (*it
);
4841 /* Append the overlay string STRING of overlay OVERLAY to vector
4842 `entries' which has size `size' and currently contains `n'
4843 elements. AFTER_P non-zero means STRING is an after-string of
4845 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4848 Lisp_Object priority; \
4852 int new_size = 2 * size; \
4853 struct overlay_entry *old = entries; \
4855 (struct overlay_entry *) alloca (new_size \
4856 * sizeof *entries); \
4857 bcopy (old, entries, size * sizeof *entries); \
4861 entries[n].string = (STRING); \
4862 entries[n].overlay = (OVERLAY); \
4863 priority = Foverlay_get ((OVERLAY), Qpriority); \
4864 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4865 entries[n].after_string_p = (AFTER_P); \
4870 /* Process overlay before the overlay center. */
4871 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4873 XSETMISC (overlay
, ov
);
4874 xassert (OVERLAYP (overlay
));
4875 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4876 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4881 /* Skip this overlay if it doesn't start or end at IT's current
4883 if (end
!= charpos
&& start
!= charpos
)
4886 /* Skip this overlay if it doesn't apply to IT->w. */
4887 window
= Foverlay_get (overlay
, Qwindow
);
4888 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4891 /* If the text ``under'' the overlay is invisible, both before-
4892 and after-strings from this overlay are visible; start and
4893 end position are indistinguishable. */
4894 invisible
= Foverlay_get (overlay
, Qinvisible
);
4895 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4897 /* If overlay has a non-empty before-string, record it. */
4898 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4899 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4901 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4903 /* If overlay has a non-empty after-string, record it. */
4904 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4905 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4907 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4910 /* Process overlays after the overlay center. */
4911 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4913 XSETMISC (overlay
, ov
);
4914 xassert (OVERLAYP (overlay
));
4915 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4916 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4918 if (start
> charpos
)
4921 /* Skip this overlay if it doesn't start or end at IT's current
4923 if (end
!= charpos
&& start
!= charpos
)
4926 /* Skip this overlay if it doesn't apply to IT->w. */
4927 window
= Foverlay_get (overlay
, Qwindow
);
4928 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4931 /* If the text ``under'' the overlay is invisible, it has a zero
4932 dimension, and both before- and after-strings apply. */
4933 invisible
= Foverlay_get (overlay
, Qinvisible
);
4934 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4936 /* If overlay has a non-empty before-string, record it. */
4937 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4938 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4940 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4942 /* If overlay has a non-empty after-string, record it. */
4943 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4944 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4946 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4949 #undef RECORD_OVERLAY_STRING
4953 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4955 /* Record number of overlay strings, and where we computed it. */
4956 it
->n_overlay_strings
= n
;
4957 it
->overlay_strings_charpos
= charpos
;
4959 /* IT->current.overlay_string_index is the number of overlay strings
4960 that have already been consumed by IT. Copy some of the
4961 remaining overlay strings to IT->overlay_strings. */
4963 j
= it
->current
.overlay_string_index
;
4964 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4966 it
->overlay_strings
[i
] = entries
[j
].string
;
4967 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4974 /* Get the first chunk of overlay strings at IT's current buffer
4975 position, or at CHARPOS if that is > 0. Value is non-zero if at
4976 least one overlay string was found. */
4979 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4984 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4985 process. This fills IT->overlay_strings with strings, and sets
4986 IT->n_overlay_strings to the total number of strings to process.
4987 IT->pos.overlay_string_index has to be set temporarily to zero
4988 because load_overlay_strings needs this; it must be set to -1
4989 when no overlay strings are found because a zero value would
4990 indicate a position in the first overlay string. */
4991 it
->current
.overlay_string_index
= 0;
4992 load_overlay_strings (it
, charpos
);
4994 /* If we found overlay strings, set up IT to deliver display
4995 elements from the first one. Otherwise set up IT to deliver
4996 from current_buffer. */
4997 if (it
->n_overlay_strings
)
4999 /* Make sure we know settings in current_buffer, so that we can
5000 restore meaningful values when we're done with the overlay
5003 compute_stop_pos (it
);
5004 xassert (it
->face_id
>= 0);
5006 /* Save IT's settings. They are restored after all overlay
5007 strings have been processed. */
5008 xassert (!compute_stop_p
|| it
->sp
== 0);
5010 /* When called from handle_stop, there might be an empty display
5011 string loaded. In that case, don't bother saving it. */
5012 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5015 /* Set up IT to deliver display elements from the first overlay
5017 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5018 it
->string
= it
->overlay_strings
[0];
5019 it
->from_overlay
= Qnil
;
5020 it
->stop_charpos
= 0;
5021 xassert (STRINGP (it
->string
));
5022 it
->end_charpos
= SCHARS (it
->string
);
5023 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5024 it
->method
= GET_FROM_STRING
;
5028 it
->current
.overlay_string_index
= -1;
5033 get_overlay_strings (it
, charpos
)
5038 it
->method
= GET_FROM_BUFFER
;
5040 (void) get_overlay_strings_1 (it
, charpos
, 1);
5044 /* Value is non-zero if we found at least one overlay string. */
5045 return STRINGP (it
->string
);
5050 /***********************************************************************
5051 Saving and restoring state
5052 ***********************************************************************/
5054 /* Save current settings of IT on IT->stack. Called, for example,
5055 before setting up IT for an overlay string, to be able to restore
5056 IT's settings to what they were after the overlay string has been
5063 struct iterator_stack_entry
*p
;
5065 xassert (it
->sp
< IT_STACK_SIZE
);
5066 p
= it
->stack
+ it
->sp
;
5068 p
->stop_charpos
= it
->stop_charpos
;
5069 p
->cmp_it
= it
->cmp_it
;
5070 xassert (it
->face_id
>= 0);
5071 p
->face_id
= it
->face_id
;
5072 p
->string
= it
->string
;
5073 p
->method
= it
->method
;
5074 p
->from_overlay
= it
->from_overlay
;
5077 case GET_FROM_IMAGE
:
5078 p
->u
.image
.object
= it
->object
;
5079 p
->u
.image
.image_id
= it
->image_id
;
5080 p
->u
.image
.slice
= it
->slice
;
5082 case GET_FROM_STRETCH
:
5083 p
->u
.stretch
.object
= it
->object
;
5086 p
->position
= it
->position
;
5087 p
->current
= it
->current
;
5088 p
->end_charpos
= it
->end_charpos
;
5089 p
->string_nchars
= it
->string_nchars
;
5091 p
->multibyte_p
= it
->multibyte_p
;
5092 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5093 p
->space_width
= it
->space_width
;
5094 p
->font_height
= it
->font_height
;
5095 p
->voffset
= it
->voffset
;
5096 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5097 p
->display_ellipsis_p
= 0;
5098 p
->line_wrap
= it
->line_wrap
;
5103 /* Restore IT's settings from IT->stack. Called, for example, when no
5104 more overlay strings must be processed, and we return to delivering
5105 display elements from a buffer, or when the end of a string from a
5106 `display' property is reached and we return to delivering display
5107 elements from an overlay string, or from a buffer. */
5113 struct iterator_stack_entry
*p
;
5115 xassert (it
->sp
> 0);
5117 p
= it
->stack
+ it
->sp
;
5118 it
->stop_charpos
= p
->stop_charpos
;
5119 it
->cmp_it
= p
->cmp_it
;
5120 it
->face_id
= p
->face_id
;
5121 it
->current
= p
->current
;
5122 it
->position
= p
->position
;
5123 it
->string
= p
->string
;
5124 it
->from_overlay
= p
->from_overlay
;
5125 if (NILP (it
->string
))
5126 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5127 it
->method
= p
->method
;
5130 case GET_FROM_IMAGE
:
5131 it
->image_id
= p
->u
.image
.image_id
;
5132 it
->object
= p
->u
.image
.object
;
5133 it
->slice
= p
->u
.image
.slice
;
5135 case GET_FROM_STRETCH
:
5136 it
->object
= p
->u
.comp
.object
;
5138 case GET_FROM_BUFFER
:
5139 it
->object
= it
->w
->buffer
;
5141 case GET_FROM_STRING
:
5142 it
->object
= it
->string
;
5144 case GET_FROM_DISPLAY_VECTOR
:
5146 it
->method
= GET_FROM_C_STRING
;
5147 else if (STRINGP (it
->string
))
5148 it
->method
= GET_FROM_STRING
;
5151 it
->method
= GET_FROM_BUFFER
;
5152 it
->object
= it
->w
->buffer
;
5155 it
->end_charpos
= p
->end_charpos
;
5156 it
->string_nchars
= p
->string_nchars
;
5158 it
->multibyte_p
= p
->multibyte_p
;
5159 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5160 it
->space_width
= p
->space_width
;
5161 it
->font_height
= p
->font_height
;
5162 it
->voffset
= p
->voffset
;
5163 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5164 it
->line_wrap
= p
->line_wrap
;
5169 /***********************************************************************
5171 ***********************************************************************/
5173 /* Set IT's current position to the previous line start. */
5176 back_to_previous_line_start (it
)
5179 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5180 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5184 /* Move IT to the next line start.
5186 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5187 we skipped over part of the text (as opposed to moving the iterator
5188 continuously over the text). Otherwise, don't change the value
5191 Newlines may come from buffer text, overlay strings, or strings
5192 displayed via the `display' property. That's the reason we can't
5193 simply use find_next_newline_no_quit.
5195 Note that this function may not skip over invisible text that is so
5196 because of text properties and immediately follows a newline. If
5197 it would, function reseat_at_next_visible_line_start, when called
5198 from set_iterator_to_next, would effectively make invisible
5199 characters following a newline part of the wrong glyph row, which
5200 leads to wrong cursor motion. */
5203 forward_to_next_line_start (it
, skipped_p
)
5207 int old_selective
, newline_found_p
, n
;
5208 const int MAX_NEWLINE_DISTANCE
= 500;
5210 /* If already on a newline, just consume it to avoid unintended
5211 skipping over invisible text below. */
5212 if (it
->what
== IT_CHARACTER
5214 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5216 set_iterator_to_next (it
, 0);
5221 /* Don't handle selective display in the following. It's (a)
5222 unnecessary because it's done by the caller, and (b) leads to an
5223 infinite recursion because next_element_from_ellipsis indirectly
5224 calls this function. */
5225 old_selective
= it
->selective
;
5228 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5229 from buffer text. */
5230 for (n
= newline_found_p
= 0;
5231 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5232 n
+= STRINGP (it
->string
) ? 0 : 1)
5234 if (!get_next_display_element (it
))
5236 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5237 set_iterator_to_next (it
, 0);
5240 /* If we didn't find a newline near enough, see if we can use a
5242 if (!newline_found_p
)
5244 int start
= IT_CHARPOS (*it
);
5245 int limit
= find_next_newline_no_quit (start
, 1);
5248 xassert (!STRINGP (it
->string
));
5250 /* If there isn't any `display' property in sight, and no
5251 overlays, we can just use the position of the newline in
5253 if (it
->stop_charpos
>= limit
5254 || ((pos
= Fnext_single_property_change (make_number (start
),
5256 Qnil
, make_number (limit
)),
5258 && next_overlay_change (start
) == ZV
))
5260 IT_CHARPOS (*it
) = limit
;
5261 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5262 *skipped_p
= newline_found_p
= 1;
5266 while (get_next_display_element (it
)
5267 && !newline_found_p
)
5269 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5270 set_iterator_to_next (it
, 0);
5275 it
->selective
= old_selective
;
5276 return newline_found_p
;
5280 /* Set IT's current position to the previous visible line start. Skip
5281 invisible text that is so either due to text properties or due to
5282 selective display. Caution: this does not change IT->current_x and
5286 back_to_previous_visible_line_start (it
)
5289 while (IT_CHARPOS (*it
) > BEGV
)
5291 back_to_previous_line_start (it
);
5293 if (IT_CHARPOS (*it
) <= BEGV
)
5296 /* If selective > 0, then lines indented more than that values
5298 if (it
->selective
> 0
5299 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5300 (double) it
->selective
)) /* iftc */
5303 /* Check the newline before point for invisibility. */
5306 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5307 Qinvisible
, it
->window
);
5308 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5312 if (IT_CHARPOS (*it
) <= BEGV
)
5319 Lisp_Object val
, overlay
;
5321 /* If newline is part of a composition, continue from start of composition */
5322 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5323 && beg
< IT_CHARPOS (*it
))
5326 /* If newline is replaced by a display property, find start of overlay
5327 or interval and continue search from that point. */
5329 pos
= --IT_CHARPOS (it2
);
5332 it2
.string_from_display_prop_p
= 0;
5333 if (handle_display_prop (&it2
) == HANDLED_RETURN
5334 && !NILP (val
= get_char_property_and_overlay
5335 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5336 && (OVERLAYP (overlay
)
5337 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5338 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5341 /* Newline is not replaced by anything -- so we are done. */
5347 IT_CHARPOS (*it
) = beg
;
5348 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5352 it
->continuation_lines_width
= 0;
5354 xassert (IT_CHARPOS (*it
) >= BEGV
);
5355 xassert (IT_CHARPOS (*it
) == BEGV
5356 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5361 /* Reseat iterator IT at the previous visible line start. Skip
5362 invisible text that is so either due to text properties or due to
5363 selective display. At the end, update IT's overlay information,
5364 face information etc. */
5367 reseat_at_previous_visible_line_start (it
)
5370 back_to_previous_visible_line_start (it
);
5371 reseat (it
, it
->current
.pos
, 1);
5376 /* Reseat iterator IT on the next visible line start in the current
5377 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5378 preceding the line start. Skip over invisible text that is so
5379 because of selective display. Compute faces, overlays etc at the
5380 new position. Note that this function does not skip over text that
5381 is invisible because of text properties. */
5384 reseat_at_next_visible_line_start (it
, on_newline_p
)
5388 int newline_found_p
, skipped_p
= 0;
5390 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5392 /* Skip over lines that are invisible because they are indented
5393 more than the value of IT->selective. */
5394 if (it
->selective
> 0)
5395 while (IT_CHARPOS (*it
) < ZV
5396 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5397 (double) it
->selective
)) /* iftc */
5399 xassert (IT_BYTEPOS (*it
) == BEGV
5400 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5401 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5404 /* Position on the newline if that's what's requested. */
5405 if (on_newline_p
&& newline_found_p
)
5407 if (STRINGP (it
->string
))
5409 if (IT_STRING_CHARPOS (*it
) > 0)
5411 --IT_STRING_CHARPOS (*it
);
5412 --IT_STRING_BYTEPOS (*it
);
5415 else if (IT_CHARPOS (*it
) > BEGV
)
5419 reseat (it
, it
->current
.pos
, 0);
5423 reseat (it
, it
->current
.pos
, 0);
5430 /***********************************************************************
5431 Changing an iterator's position
5432 ***********************************************************************/
5434 /* Change IT's current position to POS in current_buffer. If FORCE_P
5435 is non-zero, always check for text properties at the new position.
5436 Otherwise, text properties are only looked up if POS >=
5437 IT->check_charpos of a property. */
5440 reseat (it
, pos
, force_p
)
5442 struct text_pos pos
;
5445 int original_pos
= IT_CHARPOS (*it
);
5447 reseat_1 (it
, pos
, 0);
5449 /* Determine where to check text properties. Avoid doing it
5450 where possible because text property lookup is very expensive. */
5452 || CHARPOS (pos
) > it
->stop_charpos
5453 || CHARPOS (pos
) < original_pos
)
5460 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5461 IT->stop_pos to POS, also. */
5464 reseat_1 (it
, pos
, set_stop_p
)
5466 struct text_pos pos
;
5469 /* Don't call this function when scanning a C string. */
5470 xassert (it
->s
== NULL
);
5472 /* POS must be a reasonable value. */
5473 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5475 it
->current
.pos
= it
->position
= pos
;
5476 it
->end_charpos
= ZV
;
5478 it
->current
.dpvec_index
= -1;
5479 it
->current
.overlay_string_index
= -1;
5480 IT_STRING_CHARPOS (*it
) = -1;
5481 IT_STRING_BYTEPOS (*it
) = -1;
5483 it
->string_from_display_prop_p
= 0;
5484 it
->method
= GET_FROM_BUFFER
;
5485 it
->object
= it
->w
->buffer
;
5486 it
->area
= TEXT_AREA
;
5487 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5489 it
->string_from_display_prop_p
= 0;
5490 it
->face_before_selective_p
= 0;
5493 it
->stop_charpos
= CHARPOS (pos
);
5497 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5498 If S is non-null, it is a C string to iterate over. Otherwise,
5499 STRING gives a Lisp string to iterate over.
5501 If PRECISION > 0, don't return more then PRECISION number of
5502 characters from the string.
5504 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5505 characters have been returned. FIELD_WIDTH < 0 means an infinite
5508 MULTIBYTE = 0 means disable processing of multibyte characters,
5509 MULTIBYTE > 0 means enable it,
5510 MULTIBYTE < 0 means use IT->multibyte_p.
5512 IT must be initialized via a prior call to init_iterator before
5513 calling this function. */
5516 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5521 int precision
, field_width
, multibyte
;
5523 /* No region in strings. */
5524 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5526 /* No text property checks performed by default, but see below. */
5527 it
->stop_charpos
= -1;
5529 /* Set iterator position and end position. */
5530 bzero (&it
->current
, sizeof it
->current
);
5531 it
->current
.overlay_string_index
= -1;
5532 it
->current
.dpvec_index
= -1;
5533 xassert (charpos
>= 0);
5535 /* If STRING is specified, use its multibyteness, otherwise use the
5536 setting of MULTIBYTE, if specified. */
5538 it
->multibyte_p
= multibyte
> 0;
5542 xassert (STRINGP (string
));
5543 it
->string
= string
;
5545 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5546 it
->method
= GET_FROM_STRING
;
5547 it
->current
.string_pos
= string_pos (charpos
, string
);
5554 /* Note that we use IT->current.pos, not it->current.string_pos,
5555 for displaying C strings. */
5556 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5557 if (it
->multibyte_p
)
5559 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5560 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5564 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5565 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5568 it
->method
= GET_FROM_C_STRING
;
5571 /* PRECISION > 0 means don't return more than PRECISION characters
5573 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5574 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5576 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5577 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5578 FIELD_WIDTH < 0 means infinite field width. This is useful for
5579 padding with `-' at the end of a mode line. */
5580 if (field_width
< 0)
5581 field_width
= INFINITY
;
5582 if (field_width
> it
->end_charpos
- charpos
)
5583 it
->end_charpos
= charpos
+ field_width
;
5585 /* Use the standard display table for displaying strings. */
5586 if (DISP_TABLE_P (Vstandard_display_table
))
5587 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5589 it
->stop_charpos
= charpos
;
5590 if (s
== NULL
&& it
->multibyte_p
)
5592 EMACS_INT endpos
= SCHARS (it
->string
);
5593 if (endpos
> it
->end_charpos
)
5594 endpos
= it
->end_charpos
;
5595 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5603 /***********************************************************************
5605 ***********************************************************************/
5607 /* Map enum it_method value to corresponding next_element_from_* function. */
5609 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5611 next_element_from_buffer
,
5612 next_element_from_display_vector
,
5613 next_element_from_string
,
5614 next_element_from_c_string
,
5615 next_element_from_image
,
5616 next_element_from_stretch
5619 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5622 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5623 (possibly with the following characters). */
5625 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5626 ((IT)->cmp_it.id >= 0 \
5627 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5628 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5629 END_CHARPOS, (IT)->w, \
5630 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5634 /* Load IT's display element fields with information about the next
5635 display element from the current position of IT. Value is zero if
5636 end of buffer (or C string) is reached. */
5638 static struct frame
*last_escape_glyph_frame
= NULL
;
5639 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5640 static int last_escape_glyph_merged_face_id
= 0;
5643 get_next_display_element (it
)
5646 /* Non-zero means that we found a display element. Zero means that
5647 we hit the end of what we iterate over. Performance note: the
5648 function pointer `method' used here turns out to be faster than
5649 using a sequence of if-statements. */
5653 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5655 if (it
->what
== IT_CHARACTER
)
5657 /* Map via display table or translate control characters.
5658 IT->c, IT->len etc. have been set to the next character by
5659 the function call above. If we have a display table, and it
5660 contains an entry for IT->c, translate it. Don't do this if
5661 IT->c itself comes from a display table, otherwise we could
5662 end up in an infinite recursion. (An alternative could be to
5663 count the recursion depth of this function and signal an
5664 error when a certain maximum depth is reached.) Is it worth
5666 if (success_p
&& it
->dpvec
== NULL
)
5669 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5670 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5671 nbsp_or_shy
= char_is_other
;
5672 int c
= it
->c
; /* This is the character to display. */
5674 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5676 xassert (SINGLE_BYTE_CHAR_P (c
));
5677 if (unibyte_display_via_language_environment
)
5679 c
= DECODE_CHAR (unibyte
, c
);
5681 c
= BYTE8_TO_CHAR (it
->c
);
5684 c
= BYTE8_TO_CHAR (it
->c
);
5688 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5691 struct Lisp_Vector
*v
= XVECTOR (dv
);
5693 /* Return the first character from the display table
5694 entry, if not empty. If empty, don't display the
5695 current character. */
5698 it
->dpvec_char_len
= it
->len
;
5699 it
->dpvec
= v
->contents
;
5700 it
->dpend
= v
->contents
+ v
->size
;
5701 it
->current
.dpvec_index
= 0;
5702 it
->dpvec_face_id
= -1;
5703 it
->saved_face_id
= it
->face_id
;
5704 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5709 set_iterator_to_next (it
, 0);
5714 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5715 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5716 : c
== 0xAD ? char_is_soft_hyphen
5719 /* Translate control characters into `\003' or `^C' form.
5720 Control characters coming from a display table entry are
5721 currently not translated because we use IT->dpvec to hold
5722 the translation. This could easily be changed but I
5723 don't believe that it is worth doing.
5725 NBSP and SOFT-HYPEN are property translated too.
5727 Non-printable characters and raw-byte characters are also
5728 translated to octal form. */
5729 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5730 ? (it
->area
!= TEXT_AREA
5731 /* In mode line, treat \n, \t like other crl chars. */
5734 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5735 || (c
!= '\n' && c
!= '\t'))
5738 || ! CHAR_PRINTABLE_P (c
))))
5740 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5741 or a non-printable character which must be displayed
5742 either as '\003' or as `^C' where the '\\' and '^'
5743 can be defined in the display table. Fill
5744 IT->ctl_chars with glyphs for what we have to
5745 display. Then, set IT->dpvec to these glyphs. */
5748 int face_id
, lface_id
= 0 ;
5751 /* Handle control characters with ^. */
5753 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5757 g
= '^'; /* default glyph for Control */
5758 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5760 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5761 && GLYPH_CODE_CHAR_VALID_P (gc
))
5763 g
= GLYPH_CODE_CHAR (gc
);
5764 lface_id
= GLYPH_CODE_FACE (gc
);
5768 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5770 else if (it
->f
== last_escape_glyph_frame
5771 && it
->face_id
== last_escape_glyph_face_id
)
5773 face_id
= last_escape_glyph_merged_face_id
;
5777 /* Merge the escape-glyph face into the current face. */
5778 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5780 last_escape_glyph_frame
= it
->f
;
5781 last_escape_glyph_face_id
= it
->face_id
;
5782 last_escape_glyph_merged_face_id
= face_id
;
5785 XSETINT (it
->ctl_chars
[0], g
);
5786 XSETINT (it
->ctl_chars
[1], c
^ 0100);
5788 goto display_control
;
5791 /* Handle non-break space in the mode where it only gets
5794 if (EQ (Vnobreak_char_display
, Qt
)
5795 && nbsp_or_shy
== char_is_nbsp
)
5797 /* Merge the no-break-space face into the current face. */
5798 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5802 XSETINT (it
->ctl_chars
[0], ' ');
5804 goto display_control
;
5807 /* Handle sequences that start with the "escape glyph". */
5809 /* the default escape glyph is \. */
5810 escape_glyph
= '\\';
5813 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5814 && GLYPH_CODE_CHAR_VALID_P (gc
))
5816 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5817 lface_id
= GLYPH_CODE_FACE (gc
);
5821 /* The display table specified a face.
5822 Merge it into face_id and also into escape_glyph. */
5823 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5826 else if (it
->f
== last_escape_glyph_frame
5827 && it
->face_id
== last_escape_glyph_face_id
)
5829 face_id
= last_escape_glyph_merged_face_id
;
5833 /* Merge the escape-glyph face into the current face. */
5834 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5836 last_escape_glyph_frame
= it
->f
;
5837 last_escape_glyph_face_id
= it
->face_id
;
5838 last_escape_glyph_merged_face_id
= face_id
;
5841 /* Handle soft hyphens in the mode where they only get
5844 if (EQ (Vnobreak_char_display
, Qt
)
5845 && nbsp_or_shy
== char_is_soft_hyphen
)
5847 XSETINT (it
->ctl_chars
[0], '-');
5849 goto display_control
;
5852 /* Handle non-break space and soft hyphen
5853 with the escape glyph. */
5857 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5858 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5859 XSETINT (it
->ctl_chars
[1], c
);
5861 goto display_control
;
5868 if (CHAR_BYTE8_P (c
))
5869 /* Display \200 instead of \17777600. */
5870 c
= CHAR_TO_BYTE8 (c
);
5871 len
= sprintf (str
, "%03o", c
);
5873 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5874 for (i
= 0; i
< len
; i
++)
5875 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
5880 /* Set up IT->dpvec and return first character from it. */
5881 it
->dpvec_char_len
= it
->len
;
5882 it
->dpvec
= it
->ctl_chars
;
5883 it
->dpend
= it
->dpvec
+ ctl_len
;
5884 it
->current
.dpvec_index
= 0;
5885 it
->dpvec_face_id
= face_id
;
5886 it
->saved_face_id
= it
->face_id
;
5887 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5891 it
->char_to_display
= c
;
5895 it
->char_to_display
= it
->c
;
5899 #ifdef HAVE_WINDOW_SYSTEM
5900 /* Adjust face id for a multibyte character. There are no multibyte
5901 character in unibyte text. */
5902 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5905 && FRAME_WINDOW_P (it
->f
))
5907 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5909 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5911 /* Automatic composition with glyph-string. */
5912 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5914 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5918 int pos
= (it
->s
? -1
5919 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5920 : IT_CHARPOS (*it
));
5922 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
5928 /* Is this character the last one of a run of characters with
5929 box? If yes, set IT->end_of_box_run_p to 1. */
5933 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5935 int face_id
= underlying_face_id (it
);
5936 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5940 if (face
->box
== FACE_NO_BOX
)
5942 /* If the box comes from face properties in a
5943 display string, check faces in that string. */
5944 int string_face_id
= face_after_it_pos (it
);
5945 it
->end_of_box_run_p
5946 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5949 /* Otherwise, the box comes from the underlying face.
5950 If this is the last string character displayed, check
5951 the next buffer location. */
5952 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
5953 && (it
->current
.overlay_string_index
5954 == it
->n_overlay_strings
- 1))
5958 struct text_pos pos
= it
->current
.pos
;
5959 INC_TEXT_POS (pos
, it
->multibyte_p
);
5961 next_face_id
= face_at_buffer_position
5962 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
5963 it
->region_end_charpos
, &ignore
,
5964 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
5966 it
->end_of_box_run_p
5967 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
5974 int face_id
= face_after_it_pos (it
);
5975 it
->end_of_box_run_p
5976 = (face_id
!= it
->face_id
5977 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
5981 /* Value is 0 if end of buffer or string reached. */
5986 /* Move IT to the next display element.
5988 RESEAT_P non-zero means if called on a newline in buffer text,
5989 skip to the next visible line start.
5991 Functions get_next_display_element and set_iterator_to_next are
5992 separate because I find this arrangement easier to handle than a
5993 get_next_display_element function that also increments IT's
5994 position. The way it is we can first look at an iterator's current
5995 display element, decide whether it fits on a line, and if it does,
5996 increment the iterator position. The other way around we probably
5997 would either need a flag indicating whether the iterator has to be
5998 incremented the next time, or we would have to implement a
5999 decrement position function which would not be easy to write. */
6002 set_iterator_to_next (it
, reseat_p
)
6006 /* Reset flags indicating start and end of a sequence of characters
6007 with box. Reset them at the start of this function because
6008 moving the iterator to a new position might set them. */
6009 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6013 case GET_FROM_BUFFER
:
6014 /* The current display element of IT is a character from
6015 current_buffer. Advance in the buffer, and maybe skip over
6016 invisible lines that are so because of selective display. */
6017 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6018 reseat_at_next_visible_line_start (it
, 0);
6019 else if (it
->cmp_it
.id
>= 0)
6021 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6022 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6023 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6024 it
->cmp_it
.from
= it
->cmp_it
.to
;
6028 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6029 IT_BYTEPOS (*it
), it
->stop_charpos
,
6035 xassert (it
->len
!= 0);
6036 IT_BYTEPOS (*it
) += it
->len
;
6037 IT_CHARPOS (*it
) += 1;
6038 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6042 case GET_FROM_C_STRING
:
6043 /* Current display element of IT is from a C string. */
6044 IT_BYTEPOS (*it
) += it
->len
;
6045 IT_CHARPOS (*it
) += 1;
6048 case GET_FROM_DISPLAY_VECTOR
:
6049 /* Current display element of IT is from a display table entry.
6050 Advance in the display table definition. Reset it to null if
6051 end reached, and continue with characters from buffers/
6053 ++it
->current
.dpvec_index
;
6055 /* Restore face of the iterator to what they were before the
6056 display vector entry (these entries may contain faces). */
6057 it
->face_id
= it
->saved_face_id
;
6059 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6061 int recheck_faces
= it
->ellipsis_p
;
6064 it
->method
= GET_FROM_C_STRING
;
6065 else if (STRINGP (it
->string
))
6066 it
->method
= GET_FROM_STRING
;
6069 it
->method
= GET_FROM_BUFFER
;
6070 it
->object
= it
->w
->buffer
;
6074 it
->current
.dpvec_index
= -1;
6076 /* Skip over characters which were displayed via IT->dpvec. */
6077 if (it
->dpvec_char_len
< 0)
6078 reseat_at_next_visible_line_start (it
, 1);
6079 else if (it
->dpvec_char_len
> 0)
6081 if (it
->method
== GET_FROM_STRING
6082 && it
->n_overlay_strings
> 0)
6083 it
->ignore_overlay_strings_at_pos_p
= 1;
6084 it
->len
= it
->dpvec_char_len
;
6085 set_iterator_to_next (it
, reseat_p
);
6088 /* Maybe recheck faces after display vector */
6090 it
->stop_charpos
= IT_CHARPOS (*it
);
6094 case GET_FROM_STRING
:
6095 /* Current display element is a character from a Lisp string. */
6096 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6097 if (it
->cmp_it
.id
>= 0)
6099 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6100 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6101 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6102 it
->cmp_it
.from
= it
->cmp_it
.to
;
6106 composition_compute_stop_pos (&it
->cmp_it
,
6107 IT_STRING_CHARPOS (*it
),
6108 IT_STRING_BYTEPOS (*it
),
6109 it
->stop_charpos
, it
->string
);
6114 IT_STRING_BYTEPOS (*it
) += it
->len
;
6115 IT_STRING_CHARPOS (*it
) += 1;
6118 consider_string_end
:
6120 if (it
->current
.overlay_string_index
>= 0)
6122 /* IT->string is an overlay string. Advance to the
6123 next, if there is one. */
6124 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6127 next_overlay_string (it
);
6129 setup_for_ellipsis (it
, 0);
6134 /* IT->string is not an overlay string. If we reached
6135 its end, and there is something on IT->stack, proceed
6136 with what is on the stack. This can be either another
6137 string, this time an overlay string, or a buffer. */
6138 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6142 if (it
->method
== GET_FROM_STRING
)
6143 goto consider_string_end
;
6148 case GET_FROM_IMAGE
:
6149 case GET_FROM_STRETCH
:
6150 /* The position etc with which we have to proceed are on
6151 the stack. The position may be at the end of a string,
6152 if the `display' property takes up the whole string. */
6153 xassert (it
->sp
> 0);
6155 if (it
->method
== GET_FROM_STRING
)
6156 goto consider_string_end
;
6160 /* There are no other methods defined, so this should be a bug. */
6164 xassert (it
->method
!= GET_FROM_STRING
6165 || (STRINGP (it
->string
)
6166 && IT_STRING_CHARPOS (*it
) >= 0));
6169 /* Load IT's display element fields with information about the next
6170 display element which comes from a display table entry or from the
6171 result of translating a control character to one of the forms `^C'
6174 IT->dpvec holds the glyphs to return as characters.
6175 IT->saved_face_id holds the face id before the display vector--it
6176 is restored into IT->face_id in set_iterator_to_next. */
6179 next_element_from_display_vector (it
)
6185 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6187 it
->face_id
= it
->saved_face_id
;
6189 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6190 That seemed totally bogus - so I changed it... */
6191 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6193 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6195 it
->c
= GLYPH_CODE_CHAR (gc
);
6196 it
->len
= CHAR_BYTES (it
->c
);
6198 /* The entry may contain a face id to use. Such a face id is
6199 the id of a Lisp face, not a realized face. A face id of
6200 zero means no face is specified. */
6201 if (it
->dpvec_face_id
>= 0)
6202 it
->face_id
= it
->dpvec_face_id
;
6205 int lface_id
= GLYPH_CODE_FACE (gc
);
6207 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6212 /* Display table entry is invalid. Return a space. */
6213 it
->c
= ' ', it
->len
= 1;
6215 /* Don't change position and object of the iterator here. They are
6216 still the values of the character that had this display table
6217 entry or was translated, and that's what we want. */
6218 it
->what
= IT_CHARACTER
;
6223 /* Load IT with the next display element from Lisp string IT->string.
6224 IT->current.string_pos is the current position within the string.
6225 If IT->current.overlay_string_index >= 0, the Lisp string is an
6229 next_element_from_string (it
)
6232 struct text_pos position
;
6234 xassert (STRINGP (it
->string
));
6235 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6236 position
= it
->current
.string_pos
;
6238 /* Time to check for invisible text? */
6239 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6240 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6244 /* Since a handler may have changed IT->method, we must
6246 return GET_NEXT_DISPLAY_ELEMENT (it
);
6249 if (it
->current
.overlay_string_index
>= 0)
6251 /* Get the next character from an overlay string. In overlay
6252 strings, There is no field width or padding with spaces to
6254 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6259 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6260 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6261 && next_element_from_composition (it
))
6265 else if (STRING_MULTIBYTE (it
->string
))
6267 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6268 const unsigned char *s
= (SDATA (it
->string
)
6269 + IT_STRING_BYTEPOS (*it
));
6270 it
->c
= string_char_and_length (s
, &it
->len
);
6274 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6280 /* Get the next character from a Lisp string that is not an
6281 overlay string. Such strings come from the mode line, for
6282 example. We may have to pad with spaces, or truncate the
6283 string. See also next_element_from_c_string. */
6284 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6289 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6291 /* Pad with spaces. */
6292 it
->c
= ' ', it
->len
= 1;
6293 CHARPOS (position
) = BYTEPOS (position
) = -1;
6295 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6296 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6297 && next_element_from_composition (it
))
6301 else if (STRING_MULTIBYTE (it
->string
))
6303 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6304 const unsigned char *s
= (SDATA (it
->string
)
6305 + IT_STRING_BYTEPOS (*it
));
6306 it
->c
= string_char_and_length (s
, &it
->len
);
6310 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6315 /* Record what we have and where it came from. */
6316 it
->what
= IT_CHARACTER
;
6317 it
->object
= it
->string
;
6318 it
->position
= position
;
6323 /* Load IT with next display element from C string IT->s.
6324 IT->string_nchars is the maximum number of characters to return
6325 from the string. IT->end_charpos may be greater than
6326 IT->string_nchars when this function is called, in which case we
6327 may have to return padding spaces. Value is zero if end of string
6328 reached, including padding spaces. */
6331 next_element_from_c_string (it
)
6337 it
->what
= IT_CHARACTER
;
6338 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6341 /* IT's position can be greater IT->string_nchars in case a field
6342 width or precision has been specified when the iterator was
6344 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6346 /* End of the game. */
6350 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6352 /* Pad with spaces. */
6353 it
->c
= ' ', it
->len
= 1;
6354 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6356 else if (it
->multibyte_p
)
6358 /* Implementation note: The calls to strlen apparently aren't a
6359 performance problem because there is no noticeable performance
6360 difference between Emacs running in unibyte or multibyte mode. */
6361 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6362 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6365 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6371 /* Set up IT to return characters from an ellipsis, if appropriate.
6372 The definition of the ellipsis glyphs may come from a display table
6373 entry. This function fills IT with the first glyph from the
6374 ellipsis if an ellipsis is to be displayed. */
6377 next_element_from_ellipsis (it
)
6380 if (it
->selective_display_ellipsis_p
)
6381 setup_for_ellipsis (it
, it
->len
);
6384 /* The face at the current position may be different from the
6385 face we find after the invisible text. Remember what it
6386 was in IT->saved_face_id, and signal that it's there by
6387 setting face_before_selective_p. */
6388 it
->saved_face_id
= it
->face_id
;
6389 it
->method
= GET_FROM_BUFFER
;
6390 it
->object
= it
->w
->buffer
;
6391 reseat_at_next_visible_line_start (it
, 1);
6392 it
->face_before_selective_p
= 1;
6395 return GET_NEXT_DISPLAY_ELEMENT (it
);
6399 /* Deliver an image display element. The iterator IT is already
6400 filled with image information (done in handle_display_prop). Value
6405 next_element_from_image (it
)
6408 it
->what
= IT_IMAGE
;
6409 it
->ignore_overlay_strings_at_pos_p
= 0;
6414 /* Fill iterator IT with next display element from a stretch glyph
6415 property. IT->object is the value of the text property. Value is
6419 next_element_from_stretch (it
)
6422 it
->what
= IT_STRETCH
;
6427 /* Load IT with the next display element from current_buffer. Value
6428 is zero if end of buffer reached. IT->stop_charpos is the next
6429 position at which to stop and check for text properties or buffer
6433 next_element_from_buffer (it
)
6438 xassert (IT_CHARPOS (*it
) >= BEGV
);
6440 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6442 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6444 int overlay_strings_follow_p
;
6446 /* End of the game, except when overlay strings follow that
6447 haven't been returned yet. */
6448 if (it
->overlay_strings_at_end_processed_p
)
6449 overlay_strings_follow_p
= 0;
6452 it
->overlay_strings_at_end_processed_p
= 1;
6453 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6456 if (overlay_strings_follow_p
)
6457 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6461 it
->position
= it
->current
.pos
;
6468 return GET_NEXT_DISPLAY_ELEMENT (it
);
6473 /* No face changes, overlays etc. in sight, so just return a
6474 character from current_buffer. */
6477 /* Maybe run the redisplay end trigger hook. Performance note:
6478 This doesn't seem to cost measurable time. */
6479 if (it
->redisplay_end_trigger_charpos
6481 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6482 run_redisplay_end_trigger_hook (it
);
6484 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6486 && next_element_from_composition (it
))
6491 /* Get the next character, maybe multibyte. */
6492 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6493 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6494 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6496 it
->c
= *p
, it
->len
= 1;
6498 /* Record what we have and where it came from. */
6499 it
->what
= IT_CHARACTER
;
6500 it
->object
= it
->w
->buffer
;
6501 it
->position
= it
->current
.pos
;
6503 /* Normally we return the character found above, except when we
6504 really want to return an ellipsis for selective display. */
6509 /* A value of selective > 0 means hide lines indented more
6510 than that number of columns. */
6511 if (it
->selective
> 0
6512 && IT_CHARPOS (*it
) + 1 < ZV
6513 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6514 IT_BYTEPOS (*it
) + 1,
6515 (double) it
->selective
)) /* iftc */
6517 success_p
= next_element_from_ellipsis (it
);
6518 it
->dpvec_char_len
= -1;
6521 else if (it
->c
== '\r' && it
->selective
== -1)
6523 /* A value of selective == -1 means that everything from the
6524 CR to the end of the line is invisible, with maybe an
6525 ellipsis displayed for it. */
6526 success_p
= next_element_from_ellipsis (it
);
6527 it
->dpvec_char_len
= -1;
6532 /* Value is zero if end of buffer reached. */
6533 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6538 /* Run the redisplay end trigger hook for IT. */
6541 run_redisplay_end_trigger_hook (it
)
6544 Lisp_Object args
[3];
6546 /* IT->glyph_row should be non-null, i.e. we should be actually
6547 displaying something, or otherwise we should not run the hook. */
6548 xassert (it
->glyph_row
);
6550 /* Set up hook arguments. */
6551 args
[0] = Qredisplay_end_trigger_functions
;
6552 args
[1] = it
->window
;
6553 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6554 it
->redisplay_end_trigger_charpos
= 0;
6556 /* Since we are *trying* to run these functions, don't try to run
6557 them again, even if they get an error. */
6558 it
->w
->redisplay_end_trigger
= Qnil
;
6559 Frun_hook_with_args (3, args
);
6561 /* Notice if it changed the face of the character we are on. */
6562 handle_face_prop (it
);
6566 /* Deliver a composition display element. Unlike the other
6567 next_element_from_XXX, this function is not registered in the array
6568 get_next_element[]. It is called from next_element_from_buffer and
6569 next_element_from_string when necessary. */
6572 next_element_from_composition (it
)
6575 it
->what
= IT_COMPOSITION
;
6576 it
->len
= it
->cmp_it
.nbytes
;
6577 if (STRINGP (it
->string
))
6581 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6582 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6585 it
->position
= it
->current
.string_pos
;
6586 it
->object
= it
->string
;
6587 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6588 IT_STRING_BYTEPOS (*it
), it
->string
);
6594 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6595 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6598 it
->position
= it
->current
.pos
;
6599 it
->object
= it
->w
->buffer
;
6600 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6601 IT_BYTEPOS (*it
), Qnil
);
6608 /***********************************************************************
6609 Moving an iterator without producing glyphs
6610 ***********************************************************************/
6612 /* Check if iterator is at a position corresponding to a valid buffer
6613 position after some move_it_ call. */
6615 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6616 ((it)->method == GET_FROM_STRING \
6617 ? IT_STRING_CHARPOS (*it) == 0 \
6621 /* Move iterator IT to a specified buffer or X position within one
6622 line on the display without producing glyphs.
6624 OP should be a bit mask including some or all of these bits:
6625 MOVE_TO_X: Stop on reaching x-position TO_X.
6626 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6627 Regardless of OP's value, stop in reaching the end of the display line.
6629 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6630 This means, in particular, that TO_X includes window's horizontal
6633 The return value has several possible values that
6634 say what condition caused the scan to stop:
6636 MOVE_POS_MATCH_OR_ZV
6637 - when TO_POS or ZV was reached.
6640 -when TO_X was reached before TO_POS or ZV were reached.
6643 - when we reached the end of the display area and the line must
6647 - when we reached the end of the display area and the line is
6651 - when we stopped at a line end, i.e. a newline or a CR and selective
6654 static enum move_it_result
6655 move_it_in_display_line_to (struct it
*it
,
6656 EMACS_INT to_charpos
, int to_x
,
6657 enum move_operation_enum op
)
6659 enum move_it_result result
= MOVE_UNDEFINED
;
6660 struct glyph_row
*saved_glyph_row
;
6661 struct it wrap_it
, atpos_it
, atx_it
;
6664 /* Don't produce glyphs in produce_glyphs. */
6665 saved_glyph_row
= it
->glyph_row
;
6666 it
->glyph_row
= NULL
;
6668 /* Use wrap_it to save a copy of IT wherever a word wrap could
6669 occur. Use atpos_it to save a copy of IT at the desired buffer
6670 position, if found, so that we can scan ahead and check if the
6671 word later overshoots the window edge. Use atx_it similarly, for
6677 #define BUFFER_POS_REACHED_P() \
6678 ((op & MOVE_TO_POS) != 0 \
6679 && BUFFERP (it->object) \
6680 && IT_CHARPOS (*it) >= to_charpos \
6681 && (it->method == GET_FROM_BUFFER \
6682 || (it->method == GET_FROM_DISPLAY_VECTOR \
6683 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6685 /* If there's a line-/wrap-prefix, handle it. */
6686 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6687 && it
->current_y
< it
->last_visible_y
)
6688 handle_line_prefix (it
);
6692 int x
, i
, ascent
= 0, descent
= 0;
6694 /* Utility macro to reset an iterator with x, ascent, and descent. */
6695 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6696 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6697 (IT)->max_descent = descent)
6699 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6701 if ((op
& MOVE_TO_POS
) != 0
6702 && BUFFERP (it
->object
)
6703 && it
->method
== GET_FROM_BUFFER
6704 && IT_CHARPOS (*it
) > to_charpos
)
6706 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6708 result
= MOVE_POS_MATCH_OR_ZV
;
6711 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6712 /* If wrap_it is valid, the current position might be in a
6713 word that is wrapped. So, save the iterator in
6714 atpos_it and continue to see if wrapping happens. */
6718 /* Stop when ZV reached.
6719 We used to stop here when TO_CHARPOS reached as well, but that is
6720 too soon if this glyph does not fit on this line. So we handle it
6721 explicitly below. */
6722 if (!get_next_display_element (it
))
6724 result
= MOVE_POS_MATCH_OR_ZV
;
6728 if (it
->line_wrap
== TRUNCATE
)
6730 if (BUFFER_POS_REACHED_P ())
6732 result
= MOVE_POS_MATCH_OR_ZV
;
6738 if (it
->line_wrap
== WORD_WRAP
)
6740 if (IT_DISPLAYING_WHITESPACE (it
))
6744 /* We have reached a glyph that follows one or more
6745 whitespace characters. If the position is
6746 already found, we are done. */
6747 if (atpos_it
.sp
>= 0)
6750 result
= MOVE_POS_MATCH_OR_ZV
;
6756 result
= MOVE_X_REACHED
;
6759 /* Otherwise, we can wrap here. */
6766 /* Remember the line height for the current line, in case
6767 the next element doesn't fit on the line. */
6768 ascent
= it
->max_ascent
;
6769 descent
= it
->max_descent
;
6771 /* The call to produce_glyphs will get the metrics of the
6772 display element IT is loaded with. Record the x-position
6773 before this display element, in case it doesn't fit on the
6777 PRODUCE_GLYPHS (it
);
6779 if (it
->area
!= TEXT_AREA
)
6781 set_iterator_to_next (it
, 1);
6785 /* The number of glyphs we get back in IT->nglyphs will normally
6786 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6787 character on a terminal frame, or (iii) a line end. For the
6788 second case, IT->nglyphs - 1 padding glyphs will be present.
6789 (On X frames, there is only one glyph produced for a
6790 composite character.)
6792 The behavior implemented below means, for continuation lines,
6793 that as many spaces of a TAB as fit on the current line are
6794 displayed there. For terminal frames, as many glyphs of a
6795 multi-glyph character are displayed in the current line, too.
6796 This is what the old redisplay code did, and we keep it that
6797 way. Under X, the whole shape of a complex character must
6798 fit on the line or it will be completely displayed in the
6801 Note that both for tabs and padding glyphs, all glyphs have
6805 /* More than one glyph or glyph doesn't fit on line. All
6806 glyphs have the same width. */
6807 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6809 int x_before_this_char
= x
;
6810 int hpos_before_this_char
= it
->hpos
;
6812 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6814 new_x
= x
+ single_glyph_width
;
6816 /* We want to leave anything reaching TO_X to the caller. */
6817 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6819 if (BUFFER_POS_REACHED_P ())
6821 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6822 goto buffer_pos_reached
;
6823 if (atpos_it
.sp
< 0)
6826 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6831 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6834 result
= MOVE_X_REACHED
;
6840 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6845 if (/* Lines are continued. */
6846 it
->line_wrap
!= TRUNCATE
6847 && (/* And glyph doesn't fit on the line. */
6848 new_x
> it
->last_visible_x
6849 /* Or it fits exactly and we're on a window
6851 || (new_x
== it
->last_visible_x
6852 && FRAME_WINDOW_P (it
->f
))))
6854 if (/* IT->hpos == 0 means the very first glyph
6855 doesn't fit on the line, e.g. a wide image. */
6857 || (new_x
== it
->last_visible_x
6858 && FRAME_WINDOW_P (it
->f
)))
6861 it
->current_x
= new_x
;
6863 /* The character's last glyph just barely fits
6865 if (i
== it
->nglyphs
- 1)
6867 /* If this is the destination position,
6868 return a position *before* it in this row,
6869 now that we know it fits in this row. */
6870 if (BUFFER_POS_REACHED_P ())
6872 if (it
->line_wrap
!= WORD_WRAP
6875 it
->hpos
= hpos_before_this_char
;
6876 it
->current_x
= x_before_this_char
;
6877 result
= MOVE_POS_MATCH_OR_ZV
;
6880 if (it
->line_wrap
== WORD_WRAP
6884 atpos_it
.current_x
= x_before_this_char
;
6885 atpos_it
.hpos
= hpos_before_this_char
;
6889 set_iterator_to_next (it
, 1);
6890 /* On graphical terminals, newlines may
6891 "overflow" into the fringe if
6892 overflow-newline-into-fringe is non-nil.
6893 On text-only terminals, newlines may
6894 overflow into the last glyph on the
6896 if (!FRAME_WINDOW_P (it
->f
)
6897 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6899 if (!get_next_display_element (it
))
6901 result
= MOVE_POS_MATCH_OR_ZV
;
6904 if (BUFFER_POS_REACHED_P ())
6906 if (ITERATOR_AT_END_OF_LINE_P (it
))
6907 result
= MOVE_POS_MATCH_OR_ZV
;
6909 result
= MOVE_LINE_CONTINUED
;
6912 if (ITERATOR_AT_END_OF_LINE_P (it
))
6914 result
= MOVE_NEWLINE_OR_CR
;
6921 IT_RESET_X_ASCENT_DESCENT (it
);
6923 if (wrap_it
.sp
>= 0)
6930 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6932 result
= MOVE_LINE_CONTINUED
;
6936 if (BUFFER_POS_REACHED_P ())
6938 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6939 goto buffer_pos_reached
;
6940 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6943 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6947 if (new_x
> it
->first_visible_x
)
6949 /* Glyph is visible. Increment number of glyphs that
6950 would be displayed. */
6955 if (result
!= MOVE_UNDEFINED
)
6958 else if (BUFFER_POS_REACHED_P ())
6961 IT_RESET_X_ASCENT_DESCENT (it
);
6962 result
= MOVE_POS_MATCH_OR_ZV
;
6965 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6967 /* Stop when TO_X specified and reached. This check is
6968 necessary here because of lines consisting of a line end,
6969 only. The line end will not produce any glyphs and we
6970 would never get MOVE_X_REACHED. */
6971 xassert (it
->nglyphs
== 0);
6972 result
= MOVE_X_REACHED
;
6976 /* Is this a line end? If yes, we're done. */
6977 if (ITERATOR_AT_END_OF_LINE_P (it
))
6979 result
= MOVE_NEWLINE_OR_CR
;
6983 /* The current display element has been consumed. Advance
6985 set_iterator_to_next (it
, 1);
6987 /* Stop if lines are truncated and IT's current x-position is
6988 past the right edge of the window now. */
6989 if (it
->line_wrap
== TRUNCATE
6990 && it
->current_x
>= it
->last_visible_x
)
6992 if (!FRAME_WINDOW_P (it
->f
)
6993 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6995 if (!get_next_display_element (it
)
6996 || BUFFER_POS_REACHED_P ())
6998 result
= MOVE_POS_MATCH_OR_ZV
;
7001 if (ITERATOR_AT_END_OF_LINE_P (it
))
7003 result
= MOVE_NEWLINE_OR_CR
;
7007 result
= MOVE_LINE_TRUNCATED
;
7010 #undef IT_RESET_X_ASCENT_DESCENT
7013 #undef BUFFER_POS_REACHED_P
7015 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7016 restore the saved iterator. */
7017 if (atpos_it
.sp
>= 0)
7019 else if (atx_it
.sp
>= 0)
7024 /* Restore the iterator settings altered at the beginning of this
7026 it
->glyph_row
= saved_glyph_row
;
7030 /* For external use. */
7032 move_it_in_display_line (struct it
*it
,
7033 EMACS_INT to_charpos
, int to_x
,
7034 enum move_operation_enum op
)
7036 if (it
->line_wrap
== WORD_WRAP
7037 && (op
& MOVE_TO_X
))
7039 struct it save_it
= *it
;
7040 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7041 /* When word-wrap is on, TO_X may lie past the end
7042 of a wrapped line. Then it->current is the
7043 character on the next line, so backtrack to the
7044 space before the wrap point. */
7045 if (skip
== MOVE_LINE_CONTINUED
)
7047 int prev_x
= max (it
->current_x
- 1, 0);
7049 move_it_in_display_line_to
7050 (it
, -1, prev_x
, MOVE_TO_X
);
7054 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7058 /* Move IT forward until it satisfies one or more of the criteria in
7059 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7061 OP is a bit-mask that specifies where to stop, and in particular,
7062 which of those four position arguments makes a difference. See the
7063 description of enum move_operation_enum.
7065 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7066 screen line, this function will set IT to the next position >
7070 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7072 int to_charpos
, to_x
, to_y
, to_vpos
;
7075 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7076 int line_height
, line_start_x
= 0, reached
= 0;
7080 if (op
& MOVE_TO_VPOS
)
7082 /* If no TO_CHARPOS and no TO_X specified, stop at the
7083 start of the line TO_VPOS. */
7084 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7086 if (it
->vpos
== to_vpos
)
7092 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7096 /* TO_VPOS >= 0 means stop at TO_X in the line at
7097 TO_VPOS, or at TO_POS, whichever comes first. */
7098 if (it
->vpos
== to_vpos
)
7104 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7106 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7111 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7113 /* We have reached TO_X but not in the line we want. */
7114 skip
= move_it_in_display_line_to (it
, to_charpos
,
7116 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7124 else if (op
& MOVE_TO_Y
)
7126 struct it it_backup
;
7128 if (it
->line_wrap
== WORD_WRAP
)
7131 /* TO_Y specified means stop at TO_X in the line containing
7132 TO_Y---or at TO_CHARPOS if this is reached first. The
7133 problem is that we can't really tell whether the line
7134 contains TO_Y before we have completely scanned it, and
7135 this may skip past TO_X. What we do is to first scan to
7138 If TO_X is not specified, use a TO_X of zero. The reason
7139 is to make the outcome of this function more predictable.
7140 If we didn't use TO_X == 0, we would stop at the end of
7141 the line which is probably not what a caller would expect
7143 skip
= move_it_in_display_line_to
7144 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7145 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7147 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7148 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7150 else if (skip
== MOVE_X_REACHED
)
7152 /* If TO_X was reached, we want to know whether TO_Y is
7153 in the line. We know this is the case if the already
7154 scanned glyphs make the line tall enough. Otherwise,
7155 we must check by scanning the rest of the line. */
7156 line_height
= it
->max_ascent
+ it
->max_descent
;
7157 if (to_y
>= it
->current_y
7158 && to_y
< it
->current_y
+ line_height
)
7164 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7165 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7167 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7168 line_height
= it
->max_ascent
+ it
->max_descent
;
7169 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7171 if (to_y
>= it
->current_y
7172 && to_y
< it
->current_y
+ line_height
)
7174 /* If TO_Y is in this line and TO_X was reached
7175 above, we scanned too far. We have to restore
7176 IT's settings to the ones before skipping. */
7183 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7189 /* Check whether TO_Y is in this line. */
7190 line_height
= it
->max_ascent
+ it
->max_descent
;
7191 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7193 if (to_y
>= it
->current_y
7194 && to_y
< it
->current_y
+ line_height
)
7196 /* When word-wrap is on, TO_X may lie past the end
7197 of a wrapped line. Then it->current is the
7198 character on the next line, so backtrack to the
7199 space before the wrap point. */
7200 if (skip
== MOVE_LINE_CONTINUED
7201 && it
->line_wrap
== WORD_WRAP
)
7203 int prev_x
= max (it
->current_x
- 1, 0);
7205 skip
= move_it_in_display_line_to
7206 (it
, -1, prev_x
, MOVE_TO_X
);
7215 else if (BUFFERP (it
->object
)
7216 && (it
->method
== GET_FROM_BUFFER
7217 || it
->method
== GET_FROM_STRETCH
)
7218 && IT_CHARPOS (*it
) >= to_charpos
)
7219 skip
= MOVE_POS_MATCH_OR_ZV
;
7221 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7225 case MOVE_POS_MATCH_OR_ZV
:
7229 case MOVE_NEWLINE_OR_CR
:
7230 set_iterator_to_next (it
, 1);
7231 it
->continuation_lines_width
= 0;
7234 case MOVE_LINE_TRUNCATED
:
7235 it
->continuation_lines_width
= 0;
7236 reseat_at_next_visible_line_start (it
, 0);
7237 if ((op
& MOVE_TO_POS
) != 0
7238 && IT_CHARPOS (*it
) > to_charpos
)
7245 case MOVE_LINE_CONTINUED
:
7246 /* For continued lines ending in a tab, some of the glyphs
7247 associated with the tab are displayed on the current
7248 line. Since it->current_x does not include these glyphs,
7249 we use it->last_visible_x instead. */
7252 it
->continuation_lines_width
+= it
->last_visible_x
;
7253 /* When moving by vpos, ensure that the iterator really
7254 advances to the next line (bug#847, bug#969). Fixme:
7255 do we need to do this in other circumstances? */
7256 if (it
->current_x
!= it
->last_visible_x
7257 && (op
& MOVE_TO_VPOS
)
7258 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7260 line_start_x
= it
->current_x
+ it
->pixel_width
7261 - it
->last_visible_x
;
7262 set_iterator_to_next (it
, 0);
7266 it
->continuation_lines_width
+= it
->current_x
;
7273 /* Reset/increment for the next run. */
7274 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7275 it
->current_x
= line_start_x
;
7278 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7280 last_height
= it
->max_ascent
+ it
->max_descent
;
7281 last_max_ascent
= it
->max_ascent
;
7282 it
->max_ascent
= it
->max_descent
= 0;
7287 /* On text terminals, we may stop at the end of a line in the middle
7288 of a multi-character glyph. If the glyph itself is continued,
7289 i.e. it is actually displayed on the next line, don't treat this
7290 stopping point as valid; move to the next line instead (unless
7291 that brings us offscreen). */
7292 if (!FRAME_WINDOW_P (it
->f
)
7294 && IT_CHARPOS (*it
) == to_charpos
7295 && it
->what
== IT_CHARACTER
7297 && it
->line_wrap
== WINDOW_WRAP
7298 && it
->current_x
== it
->last_visible_x
- 1
7301 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7303 it
->continuation_lines_width
+= it
->current_x
;
7304 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7305 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7307 last_height
= it
->max_ascent
+ it
->max_descent
;
7308 last_max_ascent
= it
->max_ascent
;
7311 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7315 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7317 If DY > 0, move IT backward at least that many pixels. DY = 0
7318 means move IT backward to the preceding line start or BEGV. This
7319 function may move over more than DY pixels if IT->current_y - DY
7320 ends up in the middle of a line; in this case IT->current_y will be
7321 set to the top of the line moved to. */
7324 move_it_vertically_backward (it
, dy
)
7335 start_pos
= IT_CHARPOS (*it
);
7337 /* Estimate how many newlines we must move back. */
7338 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7340 /* Set the iterator's position that many lines back. */
7341 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7342 back_to_previous_visible_line_start (it
);
7344 /* Reseat the iterator here. When moving backward, we don't want
7345 reseat to skip forward over invisible text, set up the iterator
7346 to deliver from overlay strings at the new position etc. So,
7347 use reseat_1 here. */
7348 reseat_1 (it
, it
->current
.pos
, 1);
7350 /* We are now surely at a line start. */
7351 it
->current_x
= it
->hpos
= 0;
7352 it
->continuation_lines_width
= 0;
7354 /* Move forward and see what y-distance we moved. First move to the
7355 start of the next line so that we get its height. We need this
7356 height to be able to tell whether we reached the specified
7359 it2
.max_ascent
= it2
.max_descent
= 0;
7362 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7363 MOVE_TO_POS
| MOVE_TO_VPOS
);
7365 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7366 xassert (IT_CHARPOS (*it
) >= BEGV
);
7369 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7370 xassert (IT_CHARPOS (*it
) >= BEGV
);
7371 /* H is the actual vertical distance from the position in *IT
7372 and the starting position. */
7373 h
= it2
.current_y
- it
->current_y
;
7374 /* NLINES is the distance in number of lines. */
7375 nlines
= it2
.vpos
- it
->vpos
;
7377 /* Correct IT's y and vpos position
7378 so that they are relative to the starting point. */
7384 /* DY == 0 means move to the start of the screen line. The
7385 value of nlines is > 0 if continuation lines were involved. */
7387 move_it_by_lines (it
, nlines
, 1);
7391 /* The y-position we try to reach, relative to *IT.
7392 Note that H has been subtracted in front of the if-statement. */
7393 int target_y
= it
->current_y
+ h
- dy
;
7394 int y0
= it3
.current_y
;
7395 int y1
= line_bottom_y (&it3
);
7396 int line_height
= y1
- y0
;
7398 /* If we did not reach target_y, try to move further backward if
7399 we can. If we moved too far backward, try to move forward. */
7400 if (target_y
< it
->current_y
7401 /* This is heuristic. In a window that's 3 lines high, with
7402 a line height of 13 pixels each, recentering with point
7403 on the bottom line will try to move -39/2 = 19 pixels
7404 backward. Try to avoid moving into the first line. */
7405 && (it
->current_y
- target_y
7406 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7407 && IT_CHARPOS (*it
) > BEGV
)
7409 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7410 target_y
- it
->current_y
));
7411 dy
= it
->current_y
- target_y
;
7412 goto move_further_back
;
7414 else if (target_y
>= it
->current_y
+ line_height
7415 && IT_CHARPOS (*it
) < ZV
)
7417 /* Should move forward by at least one line, maybe more.
7419 Note: Calling move_it_by_lines can be expensive on
7420 terminal frames, where compute_motion is used (via
7421 vmotion) to do the job, when there are very long lines
7422 and truncate-lines is nil. That's the reason for
7423 treating terminal frames specially here. */
7425 if (!FRAME_WINDOW_P (it
->f
))
7426 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7431 move_it_by_lines (it
, 1, 1);
7433 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7440 /* Move IT by a specified amount of pixel lines DY. DY negative means
7441 move backwards. DY = 0 means move to start of screen line. At the
7442 end, IT will be on the start of a screen line. */
7445 move_it_vertically (it
, dy
)
7450 move_it_vertically_backward (it
, -dy
);
7453 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7454 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7455 MOVE_TO_POS
| MOVE_TO_Y
);
7456 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7458 /* If buffer ends in ZV without a newline, move to the start of
7459 the line to satisfy the post-condition. */
7460 if (IT_CHARPOS (*it
) == ZV
7462 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7463 move_it_by_lines (it
, 0, 0);
7468 /* Move iterator IT past the end of the text line it is in. */
7471 move_it_past_eol (it
)
7474 enum move_it_result rc
;
7476 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7477 if (rc
== MOVE_NEWLINE_OR_CR
)
7478 set_iterator_to_next (it
, 0);
7482 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7483 negative means move up. DVPOS == 0 means move to the start of the
7484 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7485 NEED_Y_P is zero, IT->current_y will be left unchanged.
7487 Further optimization ideas: If we would know that IT->f doesn't use
7488 a face with proportional font, we could be faster for
7489 truncate-lines nil. */
7492 move_it_by_lines (it
, dvpos
, need_y_p
)
7494 int dvpos
, need_y_p
;
7496 struct position pos
;
7498 /* The commented-out optimization uses vmotion on terminals. This
7499 gives bad results, because elements like it->what, on which
7500 callers such as pos_visible_p rely, aren't updated. */
7501 /* if (!FRAME_WINDOW_P (it->f))
7503 struct text_pos textpos;
7505 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7506 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7507 reseat (it, textpos, 1);
7508 it->vpos += pos.vpos;
7509 it->current_y += pos.vpos;
7515 /* DVPOS == 0 means move to the start of the screen line. */
7516 move_it_vertically_backward (it
, 0);
7517 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7518 /* Let next call to line_bottom_y calculate real line height */
7523 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7524 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7525 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7530 int start_charpos
, i
;
7532 /* Start at the beginning of the screen line containing IT's
7533 position. This may actually move vertically backwards,
7534 in case of overlays, so adjust dvpos accordingly. */
7536 move_it_vertically_backward (it
, 0);
7539 /* Go back -DVPOS visible lines and reseat the iterator there. */
7540 start_charpos
= IT_CHARPOS (*it
);
7541 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7542 back_to_previous_visible_line_start (it
);
7543 reseat (it
, it
->current
.pos
, 1);
7545 /* Move further back if we end up in a string or an image. */
7546 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7548 /* First try to move to start of display line. */
7550 move_it_vertically_backward (it
, 0);
7552 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7554 /* If start of line is still in string or image,
7555 move further back. */
7556 back_to_previous_visible_line_start (it
);
7557 reseat (it
, it
->current
.pos
, 1);
7561 it
->current_x
= it
->hpos
= 0;
7563 /* Above call may have moved too far if continuation lines
7564 are involved. Scan forward and see if it did. */
7566 it2
.vpos
= it2
.current_y
= 0;
7567 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7568 it
->vpos
-= it2
.vpos
;
7569 it
->current_y
-= it2
.current_y
;
7570 it
->current_x
= it
->hpos
= 0;
7572 /* If we moved too far back, move IT some lines forward. */
7573 if (it2
.vpos
> -dvpos
)
7575 int delta
= it2
.vpos
+ dvpos
;
7577 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7578 /* Move back again if we got too far ahead. */
7579 if (IT_CHARPOS (*it
) >= start_charpos
)
7585 /* Return 1 if IT points into the middle of a display vector. */
7588 in_display_vector_p (it
)
7591 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7592 && it
->current
.dpvec_index
> 0
7593 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7597 /***********************************************************************
7599 ***********************************************************************/
7602 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7606 add_to_log (format
, arg1
, arg2
)
7608 Lisp_Object arg1
, arg2
;
7610 Lisp_Object args
[3];
7611 Lisp_Object msg
, fmt
;
7614 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7617 /* Do nothing if called asynchronously. Inserting text into
7618 a buffer may call after-change-functions and alike and
7619 that would means running Lisp asynchronously. */
7620 if (handling_signal
)
7624 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7626 args
[0] = fmt
= build_string (format
);
7629 msg
= Fformat (3, args
);
7631 len
= SBYTES (msg
) + 1;
7632 SAFE_ALLOCA (buffer
, char *, len
);
7633 bcopy (SDATA (msg
), buffer
, len
);
7635 message_dolog (buffer
, len
- 1, 1, 0);
7642 /* Output a newline in the *Messages* buffer if "needs" one. */
7645 message_log_maybe_newline ()
7647 if (message_log_need_newline
)
7648 message_dolog ("", 0, 1, 0);
7652 /* Add a string M of length NBYTES to the message log, optionally
7653 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7654 nonzero, means interpret the contents of M as multibyte. This
7655 function calls low-level routines in order to bypass text property
7656 hooks, etc. which might not be safe to run.
7658 This may GC (insert may run before/after change hooks),
7659 so the buffer M must NOT point to a Lisp string. */
7662 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7664 int nbytes
, nlflag
, multibyte
;
7666 if (!NILP (Vmemory_full
))
7669 if (!NILP (Vmessage_log_max
))
7671 struct buffer
*oldbuf
;
7672 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7673 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7674 int point_at_end
= 0;
7676 Lisp_Object old_deactivate_mark
, tem
;
7677 struct gcpro gcpro1
;
7679 old_deactivate_mark
= Vdeactivate_mark
;
7680 oldbuf
= current_buffer
;
7681 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7682 current_buffer
->undo_list
= Qt
;
7684 oldpoint
= message_dolog_marker1
;
7685 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7686 oldbegv
= message_dolog_marker2
;
7687 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7688 oldzv
= message_dolog_marker3
;
7689 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7690 GCPRO1 (old_deactivate_mark
);
7698 BEGV_BYTE
= BEG_BYTE
;
7701 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7703 /* Insert the string--maybe converting multibyte to single byte
7704 or vice versa, so that all the text fits the buffer. */
7706 && NILP (current_buffer
->enable_multibyte_characters
))
7708 int i
, c
, char_bytes
;
7709 unsigned char work
[1];
7711 /* Convert a multibyte string to single-byte
7712 for the *Message* buffer. */
7713 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7715 c
= string_char_and_length (m
+ i
, &char_bytes
);
7716 work
[0] = (ASCII_CHAR_P (c
)
7718 : multibyte_char_to_unibyte (c
, Qnil
));
7719 insert_1_both (work
, 1, 1, 1, 0, 0);
7722 else if (! multibyte
7723 && ! NILP (current_buffer
->enable_multibyte_characters
))
7725 int i
, c
, char_bytes
;
7726 unsigned char *msg
= (unsigned char *) m
;
7727 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7728 /* Convert a single-byte string to multibyte
7729 for the *Message* buffer. */
7730 for (i
= 0; i
< nbytes
; i
++)
7733 MAKE_CHAR_MULTIBYTE (c
);
7734 char_bytes
= CHAR_STRING (c
, str
);
7735 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7739 insert_1 (m
, nbytes
, 1, 0, 0);
7743 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7744 insert_1 ("\n", 1, 1, 0, 0);
7746 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7748 this_bol_byte
= PT_BYTE
;
7750 /* See if this line duplicates the previous one.
7751 If so, combine duplicates. */
7754 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7756 prev_bol_byte
= PT_BYTE
;
7758 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7759 this_bol
, this_bol_byte
);
7762 del_range_both (prev_bol
, prev_bol_byte
,
7763 this_bol
, this_bol_byte
, 0);
7769 /* If you change this format, don't forget to also
7770 change message_log_check_duplicate. */
7771 sprintf (dupstr
, " [%d times]", dup
);
7772 duplen
= strlen (dupstr
);
7773 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7774 insert_1 (dupstr
, duplen
, 1, 0, 1);
7779 /* If we have more than the desired maximum number of lines
7780 in the *Messages* buffer now, delete the oldest ones.
7781 This is safe because we don't have undo in this buffer. */
7783 if (NATNUMP (Vmessage_log_max
))
7785 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7786 -XFASTINT (Vmessage_log_max
) - 1, 0);
7787 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7790 BEGV
= XMARKER (oldbegv
)->charpos
;
7791 BEGV_BYTE
= marker_byte_position (oldbegv
);
7800 ZV
= XMARKER (oldzv
)->charpos
;
7801 ZV_BYTE
= marker_byte_position (oldzv
);
7805 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7807 /* We can't do Fgoto_char (oldpoint) because it will run some
7809 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7810 XMARKER (oldpoint
)->bytepos
);
7813 unchain_marker (XMARKER (oldpoint
));
7814 unchain_marker (XMARKER (oldbegv
));
7815 unchain_marker (XMARKER (oldzv
));
7817 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7818 set_buffer_internal (oldbuf
);
7820 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7821 message_log_need_newline
= !nlflag
;
7822 Vdeactivate_mark
= old_deactivate_mark
;
7827 /* We are at the end of the buffer after just having inserted a newline.
7828 (Note: We depend on the fact we won't be crossing the gap.)
7829 Check to see if the most recent message looks a lot like the previous one.
7830 Return 0 if different, 1 if the new one should just replace it, or a
7831 value N > 1 if we should also append " [N times]". */
7834 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7835 int prev_bol
, this_bol
;
7836 int prev_bol_byte
, this_bol_byte
;
7839 int len
= Z_BYTE
- 1 - this_bol_byte
;
7841 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7842 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7844 for (i
= 0; i
< len
; i
++)
7846 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7854 if (*p1
++ == ' ' && *p1
++ == '[')
7857 while (*p1
>= '0' && *p1
<= '9')
7858 n
= n
* 10 + *p1
++ - '0';
7859 if (strncmp (p1
, " times]\n", 8) == 0)
7866 /* Display an echo area message M with a specified length of NBYTES
7867 bytes. The string may include null characters. If M is 0, clear
7868 out any existing message, and let the mini-buffer text show
7871 This may GC, so the buffer M must NOT point to a Lisp string. */
7874 message2 (m
, nbytes
, multibyte
)
7879 /* First flush out any partial line written with print. */
7880 message_log_maybe_newline ();
7882 message_dolog (m
, nbytes
, 1, multibyte
);
7883 message2_nolog (m
, nbytes
, multibyte
);
7887 /* The non-logging counterpart of message2. */
7890 message2_nolog (m
, nbytes
, multibyte
)
7892 int nbytes
, multibyte
;
7894 struct frame
*sf
= SELECTED_FRAME ();
7895 message_enable_multibyte
= multibyte
;
7897 if (FRAME_INITIAL_P (sf
))
7899 if (noninteractive_need_newline
)
7900 putc ('\n', stderr
);
7901 noninteractive_need_newline
= 0;
7903 fwrite (m
, nbytes
, 1, stderr
);
7904 if (cursor_in_echo_area
== 0)
7905 fprintf (stderr
, "\n");
7908 /* A null message buffer means that the frame hasn't really been
7909 initialized yet. Error messages get reported properly by
7910 cmd_error, so this must be just an informative message; toss it. */
7911 else if (INTERACTIVE
7912 && sf
->glyphs_initialized_p
7913 && FRAME_MESSAGE_BUF (sf
))
7915 Lisp_Object mini_window
;
7918 /* Get the frame containing the mini-buffer
7919 that the selected frame is using. */
7920 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7921 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7923 FRAME_SAMPLE_VISIBILITY (f
);
7924 if (FRAME_VISIBLE_P (sf
)
7925 && ! FRAME_VISIBLE_P (f
))
7926 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7930 set_message (m
, Qnil
, nbytes
, multibyte
);
7931 if (minibuffer_auto_raise
)
7932 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7935 clear_message (1, 1);
7937 do_pending_window_change (0);
7938 echo_area_display (1);
7939 do_pending_window_change (0);
7940 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7941 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7946 /* Display an echo area message M with a specified length of NBYTES
7947 bytes. The string may include null characters. If M is not a
7948 string, clear out any existing message, and let the mini-buffer
7951 This function cancels echoing. */
7954 message3 (m
, nbytes
, multibyte
)
7959 struct gcpro gcpro1
;
7962 clear_message (1,1);
7965 /* First flush out any partial line written with print. */
7966 message_log_maybe_newline ();
7972 SAFE_ALLOCA (buffer
, char *, nbytes
);
7973 bcopy (SDATA (m
), buffer
, nbytes
);
7974 message_dolog (buffer
, nbytes
, 1, multibyte
);
7977 message3_nolog (m
, nbytes
, multibyte
);
7983 /* The non-logging version of message3.
7984 This does not cancel echoing, because it is used for echoing.
7985 Perhaps we need to make a separate function for echoing
7986 and make this cancel echoing. */
7989 message3_nolog (m
, nbytes
, multibyte
)
7991 int nbytes
, multibyte
;
7993 struct frame
*sf
= SELECTED_FRAME ();
7994 message_enable_multibyte
= multibyte
;
7996 if (FRAME_INITIAL_P (sf
))
7998 if (noninteractive_need_newline
)
7999 putc ('\n', stderr
);
8000 noninteractive_need_newline
= 0;
8002 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8003 if (cursor_in_echo_area
== 0)
8004 fprintf (stderr
, "\n");
8007 /* A null message buffer means that the frame hasn't really been
8008 initialized yet. Error messages get reported properly by
8009 cmd_error, so this must be just an informative message; toss it. */
8010 else if (INTERACTIVE
8011 && sf
->glyphs_initialized_p
8012 && FRAME_MESSAGE_BUF (sf
))
8014 Lisp_Object mini_window
;
8018 /* Get the frame containing the mini-buffer
8019 that the selected frame is using. */
8020 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8021 frame
= XWINDOW (mini_window
)->frame
;
8024 FRAME_SAMPLE_VISIBILITY (f
);
8025 if (FRAME_VISIBLE_P (sf
)
8026 && !FRAME_VISIBLE_P (f
))
8027 Fmake_frame_visible (frame
);
8029 if (STRINGP (m
) && SCHARS (m
) > 0)
8031 set_message (NULL
, m
, nbytes
, multibyte
);
8032 if (minibuffer_auto_raise
)
8033 Fraise_frame (frame
);
8034 /* Assume we are not echoing.
8035 (If we are, echo_now will override this.) */
8036 echo_message_buffer
= Qnil
;
8039 clear_message (1, 1);
8041 do_pending_window_change (0);
8042 echo_area_display (1);
8043 do_pending_window_change (0);
8044 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8045 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8050 /* Display a null-terminated echo area message M. If M is 0, clear
8051 out any existing message, and let the mini-buffer text show through.
8053 The buffer M must continue to exist until after the echo area gets
8054 cleared or some other message gets displayed there. Do not pass
8055 text that is stored in a Lisp string. Do not pass text in a buffer
8056 that was alloca'd. */
8062 message2 (m
, (m
? strlen (m
) : 0), 0);
8066 /* The non-logging counterpart of message1. */
8072 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8075 /* Display a message M which contains a single %s
8076 which gets replaced with STRING. */
8079 message_with_string (m
, string
, log
)
8084 CHECK_STRING (string
);
8090 if (noninteractive_need_newline
)
8091 putc ('\n', stderr
);
8092 noninteractive_need_newline
= 0;
8093 fprintf (stderr
, m
, SDATA (string
));
8094 if (!cursor_in_echo_area
)
8095 fprintf (stderr
, "\n");
8099 else if (INTERACTIVE
)
8101 /* The frame whose minibuffer we're going to display the message on.
8102 It may be larger than the selected frame, so we need
8103 to use its buffer, not the selected frame's buffer. */
8104 Lisp_Object mini_window
;
8105 struct frame
*f
, *sf
= SELECTED_FRAME ();
8107 /* Get the frame containing the minibuffer
8108 that the selected frame is using. */
8109 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8110 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8112 /* A null message buffer means that the frame hasn't really been
8113 initialized yet. Error messages get reported properly by
8114 cmd_error, so this must be just an informative message; toss it. */
8115 if (FRAME_MESSAGE_BUF (f
))
8117 Lisp_Object args
[2], message
;
8118 struct gcpro gcpro1
, gcpro2
;
8120 args
[0] = build_string (m
);
8121 args
[1] = message
= string
;
8122 GCPRO2 (args
[0], message
);
8125 message
= Fformat (2, args
);
8128 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8130 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8134 /* Print should start at the beginning of the message
8135 buffer next time. */
8136 message_buf_print
= 0;
8142 /* Dump an informative message to the minibuf. If M is 0, clear out
8143 any existing message, and let the mini-buffer text show through. */
8147 message (m
, a1
, a2
, a3
)
8149 EMACS_INT a1
, a2
, a3
;
8155 if (noninteractive_need_newline
)
8156 putc ('\n', stderr
);
8157 noninteractive_need_newline
= 0;
8158 fprintf (stderr
, m
, a1
, a2
, a3
);
8159 if (cursor_in_echo_area
== 0)
8160 fprintf (stderr
, "\n");
8164 else if (INTERACTIVE
)
8166 /* The frame whose mini-buffer we're going to display the message
8167 on. It may be larger than the selected frame, so we need to
8168 use its buffer, not the selected frame's buffer. */
8169 Lisp_Object mini_window
;
8170 struct frame
*f
, *sf
= SELECTED_FRAME ();
8172 /* Get the frame containing the mini-buffer
8173 that the selected frame is using. */
8174 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8175 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8177 /* A null message buffer means that the frame hasn't really been
8178 initialized yet. Error messages get reported properly by
8179 cmd_error, so this must be just an informative message; toss
8181 if (FRAME_MESSAGE_BUF (f
))
8192 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8193 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8195 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8196 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8198 #endif /* NO_ARG_ARRAY */
8200 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8205 /* Print should start at the beginning of the message
8206 buffer next time. */
8207 message_buf_print
= 0;
8213 /* The non-logging version of message. */
8216 message_nolog (m
, a1
, a2
, a3
)
8218 EMACS_INT a1
, a2
, a3
;
8220 Lisp_Object old_log_max
;
8221 old_log_max
= Vmessage_log_max
;
8222 Vmessage_log_max
= Qnil
;
8223 message (m
, a1
, a2
, a3
);
8224 Vmessage_log_max
= old_log_max
;
8228 /* Display the current message in the current mini-buffer. This is
8229 only called from error handlers in process.c, and is not time
8235 if (!NILP (echo_area_buffer
[0]))
8238 string
= Fcurrent_message ();
8239 message3 (string
, SBYTES (string
),
8240 !NILP (current_buffer
->enable_multibyte_characters
));
8245 /* Make sure echo area buffers in `echo_buffers' are live.
8246 If they aren't, make new ones. */
8249 ensure_echo_area_buffers ()
8253 for (i
= 0; i
< 2; ++i
)
8254 if (!BUFFERP (echo_buffer
[i
])
8255 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8258 Lisp_Object old_buffer
;
8261 old_buffer
= echo_buffer
[i
];
8262 sprintf (name
, " *Echo Area %d*", i
);
8263 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8264 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8265 /* to force word wrap in echo area -
8266 it was decided to postpone this*/
8267 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8269 for (j
= 0; j
< 2; ++j
)
8270 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8271 echo_area_buffer
[j
] = echo_buffer
[i
];
8276 /* Call FN with args A1..A4 with either the current or last displayed
8277 echo_area_buffer as current buffer.
8279 WHICH zero means use the current message buffer
8280 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8281 from echo_buffer[] and clear it.
8283 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8284 suitable buffer from echo_buffer[] and clear it.
8286 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8287 that the current message becomes the last displayed one, make
8288 choose a suitable buffer for echo_area_buffer[0], and clear it.
8290 Value is what FN returns. */
8293 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8296 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8302 int this_one
, the_other
, clear_buffer_p
, rc
;
8303 int count
= SPECPDL_INDEX ();
8305 /* If buffers aren't live, make new ones. */
8306 ensure_echo_area_buffers ();
8311 this_one
= 0, the_other
= 1;
8313 this_one
= 1, the_other
= 0;
8316 this_one
= 0, the_other
= 1;
8319 /* We need a fresh one in case the current echo buffer equals
8320 the one containing the last displayed echo area message. */
8321 if (!NILP (echo_area_buffer
[this_one
])
8322 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8323 echo_area_buffer
[this_one
] = Qnil
;
8326 /* Choose a suitable buffer from echo_buffer[] is we don't
8328 if (NILP (echo_area_buffer
[this_one
]))
8330 echo_area_buffer
[this_one
]
8331 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8332 ? echo_buffer
[the_other
]
8333 : echo_buffer
[this_one
]);
8337 buffer
= echo_area_buffer
[this_one
];
8339 /* Don't get confused by reusing the buffer used for echoing
8340 for a different purpose. */
8341 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8344 record_unwind_protect (unwind_with_echo_area_buffer
,
8345 with_echo_area_buffer_unwind_data (w
));
8347 /* Make the echo area buffer current. Note that for display
8348 purposes, it is not necessary that the displayed window's buffer
8349 == current_buffer, except for text property lookup. So, let's
8350 only set that buffer temporarily here without doing a full
8351 Fset_window_buffer. We must also change w->pointm, though,
8352 because otherwise an assertions in unshow_buffer fails, and Emacs
8354 set_buffer_internal_1 (XBUFFER (buffer
));
8358 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8361 current_buffer
->undo_list
= Qt
;
8362 current_buffer
->read_only
= Qnil
;
8363 specbind (Qinhibit_read_only
, Qt
);
8364 specbind (Qinhibit_modification_hooks
, Qt
);
8366 if (clear_buffer_p
&& Z
> BEG
)
8369 xassert (BEGV
>= BEG
);
8370 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8372 rc
= fn (a1
, a2
, a3
, a4
);
8374 xassert (BEGV
>= BEG
);
8375 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8377 unbind_to (count
, Qnil
);
8382 /* Save state that should be preserved around the call to the function
8383 FN called in with_echo_area_buffer. */
8386 with_echo_area_buffer_unwind_data (w
)
8390 Lisp_Object vector
, tmp
;
8392 /* Reduce consing by keeping one vector in
8393 Vwith_echo_area_save_vector. */
8394 vector
= Vwith_echo_area_save_vector
;
8395 Vwith_echo_area_save_vector
= Qnil
;
8398 vector
= Fmake_vector (make_number (7), Qnil
);
8400 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8401 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8402 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8406 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8407 ASET (vector
, i
, w
->buffer
); ++i
;
8408 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8409 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8414 for (; i
< end
; ++i
)
8415 ASET (vector
, i
, Qnil
);
8418 xassert (i
== ASIZE (vector
));
8423 /* Restore global state from VECTOR which was created by
8424 with_echo_area_buffer_unwind_data. */
8427 unwind_with_echo_area_buffer (vector
)
8430 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8431 Vdeactivate_mark
= AREF (vector
, 1);
8432 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8434 if (WINDOWP (AREF (vector
, 3)))
8437 Lisp_Object buffer
, charpos
, bytepos
;
8439 w
= XWINDOW (AREF (vector
, 3));
8440 buffer
= AREF (vector
, 4);
8441 charpos
= AREF (vector
, 5);
8442 bytepos
= AREF (vector
, 6);
8445 set_marker_both (w
->pointm
, buffer
,
8446 XFASTINT (charpos
), XFASTINT (bytepos
));
8449 Vwith_echo_area_save_vector
= vector
;
8454 /* Set up the echo area for use by print functions. MULTIBYTE_P
8455 non-zero means we will print multibyte. */
8458 setup_echo_area_for_printing (multibyte_p
)
8461 /* If we can't find an echo area any more, exit. */
8462 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8465 ensure_echo_area_buffers ();
8467 if (!message_buf_print
)
8469 /* A message has been output since the last time we printed.
8470 Choose a fresh echo area buffer. */
8471 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8472 echo_area_buffer
[0] = echo_buffer
[1];
8474 echo_area_buffer
[0] = echo_buffer
[0];
8476 /* Switch to that buffer and clear it. */
8477 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8478 current_buffer
->truncate_lines
= Qnil
;
8482 int count
= SPECPDL_INDEX ();
8483 specbind (Qinhibit_read_only
, Qt
);
8484 /* Note that undo recording is always disabled. */
8486 unbind_to (count
, Qnil
);
8488 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8490 /* Set up the buffer for the multibyteness we need. */
8492 != !NILP (current_buffer
->enable_multibyte_characters
))
8493 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8495 /* Raise the frame containing the echo area. */
8496 if (minibuffer_auto_raise
)
8498 struct frame
*sf
= SELECTED_FRAME ();
8499 Lisp_Object mini_window
;
8500 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8501 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8504 message_log_maybe_newline ();
8505 message_buf_print
= 1;
8509 if (NILP (echo_area_buffer
[0]))
8511 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8512 echo_area_buffer
[0] = echo_buffer
[1];
8514 echo_area_buffer
[0] = echo_buffer
[0];
8517 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8519 /* Someone switched buffers between print requests. */
8520 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8521 current_buffer
->truncate_lines
= Qnil
;
8527 /* Display an echo area message in window W. Value is non-zero if W's
8528 height is changed. If display_last_displayed_message_p is
8529 non-zero, display the message that was last displayed, otherwise
8530 display the current message. */
8533 display_echo_area (w
)
8536 int i
, no_message_p
, window_height_changed_p
, count
;
8538 /* Temporarily disable garbage collections while displaying the echo
8539 area. This is done because a GC can print a message itself.
8540 That message would modify the echo area buffer's contents while a
8541 redisplay of the buffer is going on, and seriously confuse
8543 count
= inhibit_garbage_collection ();
8545 /* If there is no message, we must call display_echo_area_1
8546 nevertheless because it resizes the window. But we will have to
8547 reset the echo_area_buffer in question to nil at the end because
8548 with_echo_area_buffer will sets it to an empty buffer. */
8549 i
= display_last_displayed_message_p
? 1 : 0;
8550 no_message_p
= NILP (echo_area_buffer
[i
]);
8552 window_height_changed_p
8553 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8554 display_echo_area_1
,
8555 (EMACS_INT
) w
, Qnil
, 0, 0);
8558 echo_area_buffer
[i
] = Qnil
;
8560 unbind_to (count
, Qnil
);
8561 return window_height_changed_p
;
8565 /* Helper for display_echo_area. Display the current buffer which
8566 contains the current echo area message in window W, a mini-window,
8567 a pointer to which is passed in A1. A2..A4 are currently not used.
8568 Change the height of W so that all of the message is displayed.
8569 Value is non-zero if height of W was changed. */
8572 display_echo_area_1 (a1
, a2
, a3
, a4
)
8577 struct window
*w
= (struct window
*) a1
;
8579 struct text_pos start
;
8580 int window_height_changed_p
= 0;
8582 /* Do this before displaying, so that we have a large enough glyph
8583 matrix for the display. If we can't get enough space for the
8584 whole text, display the last N lines. That works by setting w->start. */
8585 window_height_changed_p
= resize_mini_window (w
, 0);
8587 /* Use the starting position chosen by resize_mini_window. */
8588 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8591 clear_glyph_matrix (w
->desired_matrix
);
8592 XSETWINDOW (window
, w
);
8593 try_window (window
, start
, 0);
8595 return window_height_changed_p
;
8599 /* Resize the echo area window to exactly the size needed for the
8600 currently displayed message, if there is one. If a mini-buffer
8601 is active, don't shrink it. */
8604 resize_echo_area_exactly ()
8606 if (BUFFERP (echo_area_buffer
[0])
8607 && WINDOWP (echo_area_window
))
8609 struct window
*w
= XWINDOW (echo_area_window
);
8611 Lisp_Object resize_exactly
;
8613 if (minibuf_level
== 0)
8614 resize_exactly
= Qt
;
8616 resize_exactly
= Qnil
;
8618 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8619 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8622 ++windows_or_buffers_changed
;
8623 ++update_mode_lines
;
8624 redisplay_internal (0);
8630 /* Callback function for with_echo_area_buffer, when used from
8631 resize_echo_area_exactly. A1 contains a pointer to the window to
8632 resize, EXACTLY non-nil means resize the mini-window exactly to the
8633 size of the text displayed. A3 and A4 are not used. Value is what
8634 resize_mini_window returns. */
8637 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8639 Lisp_Object exactly
;
8642 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8646 /* Resize mini-window W to fit the size of its contents. EXACT_P
8647 means size the window exactly to the size needed. Otherwise, it's
8648 only enlarged until W's buffer is empty.
8650 Set W->start to the right place to begin display. If the whole
8651 contents fit, start at the beginning. Otherwise, start so as
8652 to make the end of the contents appear. This is particularly
8653 important for y-or-n-p, but seems desirable generally.
8655 Value is non-zero if the window height has been changed. */
8658 resize_mini_window (w
, exact_p
)
8662 struct frame
*f
= XFRAME (w
->frame
);
8663 int window_height_changed_p
= 0;
8665 xassert (MINI_WINDOW_P (w
));
8667 /* By default, start display at the beginning. */
8668 set_marker_both (w
->start
, w
->buffer
,
8669 BUF_BEGV (XBUFFER (w
->buffer
)),
8670 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8672 /* Don't resize windows while redisplaying a window; it would
8673 confuse redisplay functions when the size of the window they are
8674 displaying changes from under them. Such a resizing can happen,
8675 for instance, when which-func prints a long message while
8676 we are running fontification-functions. We're running these
8677 functions with safe_call which binds inhibit-redisplay to t. */
8678 if (!NILP (Vinhibit_redisplay
))
8681 /* Nil means don't try to resize. */
8682 if (NILP (Vresize_mini_windows
)
8683 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8686 if (!FRAME_MINIBUF_ONLY_P (f
))
8689 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8690 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8691 int height
, max_height
;
8692 int unit
= FRAME_LINE_HEIGHT (f
);
8693 struct text_pos start
;
8694 struct buffer
*old_current_buffer
= NULL
;
8696 if (current_buffer
!= XBUFFER (w
->buffer
))
8698 old_current_buffer
= current_buffer
;
8699 set_buffer_internal (XBUFFER (w
->buffer
));
8702 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8704 /* Compute the max. number of lines specified by the user. */
8705 if (FLOATP (Vmax_mini_window_height
))
8706 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8707 else if (INTEGERP (Vmax_mini_window_height
))
8708 max_height
= XINT (Vmax_mini_window_height
);
8710 max_height
= total_height
/ 4;
8712 /* Correct that max. height if it's bogus. */
8713 max_height
= max (1, max_height
);
8714 max_height
= min (total_height
, max_height
);
8716 /* Find out the height of the text in the window. */
8717 if (it
.line_wrap
== TRUNCATE
)
8722 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8723 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8724 height
= it
.current_y
+ last_height
;
8726 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8727 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8728 height
= (height
+ unit
- 1) / unit
;
8731 /* Compute a suitable window start. */
8732 if (height
> max_height
)
8734 height
= max_height
;
8735 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8736 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8737 start
= it
.current
.pos
;
8740 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8741 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8743 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8745 /* Let it grow only, until we display an empty message, in which
8746 case the window shrinks again. */
8747 if (height
> WINDOW_TOTAL_LINES (w
))
8749 int old_height
= WINDOW_TOTAL_LINES (w
);
8750 freeze_window_starts (f
, 1);
8751 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8752 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8754 else if (height
< WINDOW_TOTAL_LINES (w
)
8755 && (exact_p
|| BEGV
== ZV
))
8757 int old_height
= WINDOW_TOTAL_LINES (w
);
8758 freeze_window_starts (f
, 0);
8759 shrink_mini_window (w
);
8760 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8765 /* Always resize to exact size needed. */
8766 if (height
> WINDOW_TOTAL_LINES (w
))
8768 int old_height
= WINDOW_TOTAL_LINES (w
);
8769 freeze_window_starts (f
, 1);
8770 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8771 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8773 else if (height
< WINDOW_TOTAL_LINES (w
))
8775 int old_height
= WINDOW_TOTAL_LINES (w
);
8776 freeze_window_starts (f
, 0);
8777 shrink_mini_window (w
);
8781 freeze_window_starts (f
, 1);
8782 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8785 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8789 if (old_current_buffer
)
8790 set_buffer_internal (old_current_buffer
);
8793 return window_height_changed_p
;
8797 /* Value is the current message, a string, or nil if there is no
8805 if (!BUFFERP (echo_area_buffer
[0]))
8809 with_echo_area_buffer (0, 0, current_message_1
,
8810 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8812 echo_area_buffer
[0] = Qnil
;
8820 current_message_1 (a1
, a2
, a3
, a4
)
8825 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8828 *msg
= make_buffer_string (BEG
, Z
, 1);
8835 /* Push the current message on Vmessage_stack for later restauration
8836 by restore_message. Value is non-zero if the current message isn't
8837 empty. This is a relatively infrequent operation, so it's not
8838 worth optimizing. */
8844 msg
= current_message ();
8845 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8846 return STRINGP (msg
);
8850 /* Restore message display from the top of Vmessage_stack. */
8857 xassert (CONSP (Vmessage_stack
));
8858 msg
= XCAR (Vmessage_stack
);
8860 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8862 message3_nolog (msg
, 0, 0);
8866 /* Handler for record_unwind_protect calling pop_message. */
8869 pop_message_unwind (dummy
)
8876 /* Pop the top-most entry off Vmessage_stack. */
8881 xassert (CONSP (Vmessage_stack
));
8882 Vmessage_stack
= XCDR (Vmessage_stack
);
8886 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8887 exits. If the stack is not empty, we have a missing pop_message
8891 check_message_stack ()
8893 if (!NILP (Vmessage_stack
))
8898 /* Truncate to NCHARS what will be displayed in the echo area the next
8899 time we display it---but don't redisplay it now. */
8902 truncate_echo_area (nchars
)
8906 echo_area_buffer
[0] = Qnil
;
8907 /* A null message buffer means that the frame hasn't really been
8908 initialized yet. Error messages get reported properly by
8909 cmd_error, so this must be just an informative message; toss it. */
8910 else if (!noninteractive
8912 && !NILP (echo_area_buffer
[0]))
8914 struct frame
*sf
= SELECTED_FRAME ();
8915 if (FRAME_MESSAGE_BUF (sf
))
8916 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8921 /* Helper function for truncate_echo_area. Truncate the current
8922 message to at most NCHARS characters. */
8925 truncate_message_1 (nchars
, a2
, a3
, a4
)
8930 if (BEG
+ nchars
< Z
)
8931 del_range (BEG
+ nchars
, Z
);
8933 echo_area_buffer
[0] = Qnil
;
8938 /* Set the current message to a substring of S or STRING.
8940 If STRING is a Lisp string, set the message to the first NBYTES
8941 bytes from STRING. NBYTES zero means use the whole string. If
8942 STRING is multibyte, the message will be displayed multibyte.
8944 If S is not null, set the message to the first LEN bytes of S. LEN
8945 zero means use the whole string. MULTIBYTE_P non-zero means S is
8946 multibyte. Display the message multibyte in that case.
8948 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8949 to t before calling set_message_1 (which calls insert).
8953 set_message (s
, string
, nbytes
, multibyte_p
)
8956 int nbytes
, multibyte_p
;
8958 message_enable_multibyte
8959 = ((s
&& multibyte_p
)
8960 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8962 with_echo_area_buffer (0, -1, set_message_1
,
8963 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8964 message_buf_print
= 0;
8965 help_echo_showing_p
= 0;
8969 /* Helper function for set_message. Arguments have the same meaning
8970 as there, with A1 corresponding to S and A2 corresponding to STRING
8971 This function is called with the echo area buffer being
8975 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8978 EMACS_INT nbytes
, multibyte_p
;
8980 const char *s
= (const char *) a1
;
8981 Lisp_Object string
= a2
;
8983 /* Change multibyteness of the echo buffer appropriately. */
8984 if (message_enable_multibyte
8985 != !NILP (current_buffer
->enable_multibyte_characters
))
8986 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8988 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8990 /* Insert new message at BEG. */
8991 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8993 if (STRINGP (string
))
8998 nbytes
= SBYTES (string
);
8999 nchars
= string_byte_to_char (string
, nbytes
);
9001 /* This function takes care of single/multibyte conversion. We
9002 just have to ensure that the echo area buffer has the right
9003 setting of enable_multibyte_characters. */
9004 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9009 nbytes
= strlen (s
);
9011 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9013 /* Convert from multi-byte to single-byte. */
9015 unsigned char work
[1];
9017 /* Convert a multibyte string to single-byte. */
9018 for (i
= 0; i
< nbytes
; i
+= n
)
9020 c
= string_char_and_length (s
+ i
, &n
);
9021 work
[0] = (ASCII_CHAR_P (c
)
9023 : multibyte_char_to_unibyte (c
, Qnil
));
9024 insert_1_both (work
, 1, 1, 1, 0, 0);
9027 else if (!multibyte_p
9028 && !NILP (current_buffer
->enable_multibyte_characters
))
9030 /* Convert from single-byte to multi-byte. */
9032 const unsigned char *msg
= (const unsigned char *) s
;
9033 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9035 /* Convert a single-byte string to multibyte. */
9036 for (i
= 0; i
< nbytes
; i
++)
9039 MAKE_CHAR_MULTIBYTE (c
);
9040 n
= CHAR_STRING (c
, str
);
9041 insert_1_both (str
, 1, n
, 1, 0, 0);
9045 insert_1 (s
, nbytes
, 1, 0, 0);
9052 /* Clear messages. CURRENT_P non-zero means clear the current
9053 message. LAST_DISPLAYED_P non-zero means clear the message
9057 clear_message (current_p
, last_displayed_p
)
9058 int current_p
, last_displayed_p
;
9062 echo_area_buffer
[0] = Qnil
;
9063 message_cleared_p
= 1;
9066 if (last_displayed_p
)
9067 echo_area_buffer
[1] = Qnil
;
9069 message_buf_print
= 0;
9072 /* Clear garbaged frames.
9074 This function is used where the old redisplay called
9075 redraw_garbaged_frames which in turn called redraw_frame which in
9076 turn called clear_frame. The call to clear_frame was a source of
9077 flickering. I believe a clear_frame is not necessary. It should
9078 suffice in the new redisplay to invalidate all current matrices,
9079 and ensure a complete redisplay of all windows. */
9082 clear_garbaged_frames ()
9086 Lisp_Object tail
, frame
;
9087 int changed_count
= 0;
9089 FOR_EACH_FRAME (tail
, frame
)
9091 struct frame
*f
= XFRAME (frame
);
9093 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9097 Fredraw_frame (frame
);
9098 f
->force_flush_display_p
= 1;
9100 clear_current_matrices (f
);
9109 ++windows_or_buffers_changed
;
9114 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9115 is non-zero update selected_frame. Value is non-zero if the
9116 mini-windows height has been changed. */
9119 echo_area_display (update_frame_p
)
9122 Lisp_Object mini_window
;
9125 int window_height_changed_p
= 0;
9126 struct frame
*sf
= SELECTED_FRAME ();
9128 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9129 w
= XWINDOW (mini_window
);
9130 f
= XFRAME (WINDOW_FRAME (w
));
9132 /* Don't display if frame is invisible or not yet initialized. */
9133 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9136 #ifdef HAVE_WINDOW_SYSTEM
9137 /* When Emacs starts, selected_frame may be the initial terminal
9138 frame. If we let this through, a message would be displayed on
9140 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9142 #endif /* HAVE_WINDOW_SYSTEM */
9144 /* Redraw garbaged frames. */
9146 clear_garbaged_frames ();
9148 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9150 echo_area_window
= mini_window
;
9151 window_height_changed_p
= display_echo_area (w
);
9152 w
->must_be_updated_p
= 1;
9154 /* Update the display, unless called from redisplay_internal.
9155 Also don't update the screen during redisplay itself. The
9156 update will happen at the end of redisplay, and an update
9157 here could cause confusion. */
9158 if (update_frame_p
&& !redisplaying_p
)
9162 /* If the display update has been interrupted by pending
9163 input, update mode lines in the frame. Due to the
9164 pending input, it might have been that redisplay hasn't
9165 been called, so that mode lines above the echo area are
9166 garbaged. This looks odd, so we prevent it here. */
9167 if (!display_completed
)
9168 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9170 if (window_height_changed_p
9171 /* Don't do this if Emacs is shutting down. Redisplay
9172 needs to run hooks. */
9173 && !NILP (Vrun_hooks
))
9175 /* Must update other windows. Likewise as in other
9176 cases, don't let this update be interrupted by
9178 int count
= SPECPDL_INDEX ();
9179 specbind (Qredisplay_dont_pause
, Qt
);
9180 windows_or_buffers_changed
= 1;
9181 redisplay_internal (0);
9182 unbind_to (count
, Qnil
);
9184 else if (FRAME_WINDOW_P (f
) && n
== 0)
9186 /* Window configuration is the same as before.
9187 Can do with a display update of the echo area,
9188 unless we displayed some mode lines. */
9189 update_single_window (w
, 1);
9190 FRAME_RIF (f
)->flush_display (f
);
9193 update_frame (f
, 1, 1);
9195 /* If cursor is in the echo area, make sure that the next
9196 redisplay displays the minibuffer, so that the cursor will
9197 be replaced with what the minibuffer wants. */
9198 if (cursor_in_echo_area
)
9199 ++windows_or_buffers_changed
;
9202 else if (!EQ (mini_window
, selected_window
))
9203 windows_or_buffers_changed
++;
9205 /* Last displayed message is now the current message. */
9206 echo_area_buffer
[1] = echo_area_buffer
[0];
9207 /* Inform read_char that we're not echoing. */
9208 echo_message_buffer
= Qnil
;
9210 /* Prevent redisplay optimization in redisplay_internal by resetting
9211 this_line_start_pos. This is done because the mini-buffer now
9212 displays the message instead of its buffer text. */
9213 if (EQ (mini_window
, selected_window
))
9214 CHARPOS (this_line_start_pos
) = 0;
9216 return window_height_changed_p
;
9221 /***********************************************************************
9222 Mode Lines and Frame Titles
9223 ***********************************************************************/
9225 /* A buffer for constructing non-propertized mode-line strings and
9226 frame titles in it; allocated from the heap in init_xdisp and
9227 resized as needed in store_mode_line_noprop_char. */
9229 static char *mode_line_noprop_buf
;
9231 /* The buffer's end, and a current output position in it. */
9233 static char *mode_line_noprop_buf_end
;
9234 static char *mode_line_noprop_ptr
;
9236 #define MODE_LINE_NOPROP_LEN(start) \
9237 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9240 MODE_LINE_DISPLAY
= 0,
9246 /* Alist that caches the results of :propertize.
9247 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9248 static Lisp_Object mode_line_proptrans_alist
;
9250 /* List of strings making up the mode-line. */
9251 static Lisp_Object mode_line_string_list
;
9253 /* Base face property when building propertized mode line string. */
9254 static Lisp_Object mode_line_string_face
;
9255 static Lisp_Object mode_line_string_face_prop
;
9258 /* Unwind data for mode line strings */
9260 static Lisp_Object Vmode_line_unwind_vector
;
9263 format_mode_line_unwind_data (struct buffer
*obuf
,
9267 Lisp_Object vector
, tmp
;
9269 /* Reduce consing by keeping one vector in
9270 Vwith_echo_area_save_vector. */
9271 vector
= Vmode_line_unwind_vector
;
9272 Vmode_line_unwind_vector
= Qnil
;
9275 vector
= Fmake_vector (make_number (8), Qnil
);
9277 ASET (vector
, 0, make_number (mode_line_target
));
9278 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9279 ASET (vector
, 2, mode_line_string_list
);
9280 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9281 ASET (vector
, 4, mode_line_string_face
);
9282 ASET (vector
, 5, mode_line_string_face_prop
);
9285 XSETBUFFER (tmp
, obuf
);
9288 ASET (vector
, 6, tmp
);
9289 ASET (vector
, 7, owin
);
9295 unwind_format_mode_line (vector
)
9298 mode_line_target
= XINT (AREF (vector
, 0));
9299 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9300 mode_line_string_list
= AREF (vector
, 2);
9301 if (! EQ (AREF (vector
, 3), Qt
))
9302 mode_line_proptrans_alist
= AREF (vector
, 3);
9303 mode_line_string_face
= AREF (vector
, 4);
9304 mode_line_string_face_prop
= AREF (vector
, 5);
9306 if (!NILP (AREF (vector
, 7)))
9307 /* Select window before buffer, since it may change the buffer. */
9308 Fselect_window (AREF (vector
, 7), Qt
);
9310 if (!NILP (AREF (vector
, 6)))
9312 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9313 ASET (vector
, 6, Qnil
);
9316 Vmode_line_unwind_vector
= vector
;
9321 /* Store a single character C for the frame title in mode_line_noprop_buf.
9322 Re-allocate mode_line_noprop_buf if necessary. */
9326 store_mode_line_noprop_char (char c
)
9328 store_mode_line_noprop_char (c
)
9332 /* If output position has reached the end of the allocated buffer,
9333 double the buffer's size. */
9334 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9336 int len
= MODE_LINE_NOPROP_LEN (0);
9337 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9338 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9339 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9340 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9343 *mode_line_noprop_ptr
++ = c
;
9347 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9348 mode_line_noprop_ptr. STR is the string to store. Do not copy
9349 characters that yield more columns than PRECISION; PRECISION <= 0
9350 means copy the whole string. Pad with spaces until FIELD_WIDTH
9351 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9352 pad. Called from display_mode_element when it is used to build a
9356 store_mode_line_noprop (str
, field_width
, precision
)
9357 const unsigned char *str
;
9358 int field_width
, precision
;
9363 /* Copy at most PRECISION chars from STR. */
9364 nbytes
= strlen (str
);
9365 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9367 store_mode_line_noprop_char (*str
++);
9369 /* Fill up with spaces until FIELD_WIDTH reached. */
9370 while (field_width
> 0
9373 store_mode_line_noprop_char (' ');
9380 /***********************************************************************
9382 ***********************************************************************/
9384 #ifdef HAVE_WINDOW_SYSTEM
9386 /* Set the title of FRAME, if it has changed. The title format is
9387 Vicon_title_format if FRAME is iconified, otherwise it is
9388 frame_title_format. */
9391 x_consider_frame_title (frame
)
9394 struct frame
*f
= XFRAME (frame
);
9396 if (FRAME_WINDOW_P (f
)
9397 || FRAME_MINIBUF_ONLY_P (f
)
9398 || f
->explicit_name
)
9400 /* Do we have more than one visible frame on this X display? */
9407 int count
= SPECPDL_INDEX ();
9409 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9411 Lisp_Object other_frame
= XCAR (tail
);
9412 struct frame
*tf
= XFRAME (other_frame
);
9415 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9416 && !FRAME_MINIBUF_ONLY_P (tf
)
9417 && !EQ (other_frame
, tip_frame
)
9418 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9422 /* Set global variable indicating that multiple frames exist. */
9423 multiple_frames
= CONSP (tail
);
9425 /* Switch to the buffer of selected window of the frame. Set up
9426 mode_line_target so that display_mode_element will output into
9427 mode_line_noprop_buf; then display the title. */
9428 record_unwind_protect (unwind_format_mode_line
,
9429 format_mode_line_unwind_data
9430 (current_buffer
, selected_window
, 0));
9432 Fselect_window (f
->selected_window
, Qt
);
9433 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9434 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9436 mode_line_target
= MODE_LINE_TITLE
;
9437 title_start
= MODE_LINE_NOPROP_LEN (0);
9438 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9439 NULL
, DEFAULT_FACE_ID
);
9440 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9441 len
= MODE_LINE_NOPROP_LEN (title_start
);
9442 title
= mode_line_noprop_buf
+ title_start
;
9443 unbind_to (count
, Qnil
);
9445 /* Set the title only if it's changed. This avoids consing in
9446 the common case where it hasn't. (If it turns out that we've
9447 already wasted too much time by walking through the list with
9448 display_mode_element, then we might need to optimize at a
9449 higher level than this.) */
9450 if (! STRINGP (f
->name
)
9451 || SBYTES (f
->name
) != len
9452 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9453 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9457 #endif /* not HAVE_WINDOW_SYSTEM */
9462 /***********************************************************************
9464 ***********************************************************************/
9467 /* Prepare for redisplay by updating menu-bar item lists when
9468 appropriate. This can call eval. */
9471 prepare_menu_bars ()
9474 struct gcpro gcpro1
, gcpro2
;
9476 Lisp_Object tooltip_frame
;
9478 #ifdef HAVE_WINDOW_SYSTEM
9479 tooltip_frame
= tip_frame
;
9481 tooltip_frame
= Qnil
;
9484 /* Update all frame titles based on their buffer names, etc. We do
9485 this before the menu bars so that the buffer-menu will show the
9486 up-to-date frame titles. */
9487 #ifdef HAVE_WINDOW_SYSTEM
9488 if (windows_or_buffers_changed
|| update_mode_lines
)
9490 Lisp_Object tail
, frame
;
9492 FOR_EACH_FRAME (tail
, frame
)
9495 if (!EQ (frame
, tooltip_frame
)
9496 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9497 x_consider_frame_title (frame
);
9500 #endif /* HAVE_WINDOW_SYSTEM */
9502 /* Update the menu bar item lists, if appropriate. This has to be
9503 done before any actual redisplay or generation of display lines. */
9504 all_windows
= (update_mode_lines
9505 || buffer_shared
> 1
9506 || windows_or_buffers_changed
);
9509 Lisp_Object tail
, frame
;
9510 int count
= SPECPDL_INDEX ();
9511 /* 1 means that update_menu_bar has run its hooks
9512 so any further calls to update_menu_bar shouldn't do so again. */
9513 int menu_bar_hooks_run
= 0;
9515 record_unwind_save_match_data ();
9517 FOR_EACH_FRAME (tail
, frame
)
9521 /* Ignore tooltip frame. */
9522 if (EQ (frame
, tooltip_frame
))
9525 /* If a window on this frame changed size, report that to
9526 the user and clear the size-change flag. */
9527 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9529 Lisp_Object functions
;
9531 /* Clear flag first in case we get an error below. */
9532 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9533 functions
= Vwindow_size_change_functions
;
9534 GCPRO2 (tail
, functions
);
9536 while (CONSP (functions
))
9538 if (!EQ (XCAR (functions
), Qt
))
9539 call1 (XCAR (functions
), frame
);
9540 functions
= XCDR (functions
);
9546 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9547 #ifdef HAVE_WINDOW_SYSTEM
9548 update_tool_bar (f
, 0);
9551 if (windows_or_buffers_changed
9553 ns_set_doc_edited (f
, Fbuffer_modified_p
9554 (XWINDOW (f
->selected_window
)->buffer
));
9559 unbind_to (count
, Qnil
);
9563 struct frame
*sf
= SELECTED_FRAME ();
9564 update_menu_bar (sf
, 1, 0);
9565 #ifdef HAVE_WINDOW_SYSTEM
9566 update_tool_bar (sf
, 1);
9570 /* Motif needs this. See comment in xmenu.c. Turn it off when
9571 pending_menu_activation is not defined. */
9572 #ifdef USE_X_TOOLKIT
9573 pending_menu_activation
= 0;
9578 /* Update the menu bar item list for frame F. This has to be done
9579 before we start to fill in any display lines, because it can call
9582 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9584 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9585 already ran the menu bar hooks for this redisplay, so there
9586 is no need to run them again. The return value is the
9587 updated value of this flag, to pass to the next call. */
9590 update_menu_bar (f
, save_match_data
, hooks_run
)
9592 int save_match_data
;
9596 register struct window
*w
;
9598 /* If called recursively during a menu update, do nothing. This can
9599 happen when, for instance, an activate-menubar-hook causes a
9601 if (inhibit_menubar_update
)
9604 window
= FRAME_SELECTED_WINDOW (f
);
9605 w
= XWINDOW (window
);
9607 if (FRAME_WINDOW_P (f
)
9609 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9610 || defined (HAVE_NS) || defined (USE_GTK)
9611 FRAME_EXTERNAL_MENU_BAR (f
)
9613 FRAME_MENU_BAR_LINES (f
) > 0
9615 : FRAME_MENU_BAR_LINES (f
) > 0)
9617 /* If the user has switched buffers or windows, we need to
9618 recompute to reflect the new bindings. But we'll
9619 recompute when update_mode_lines is set too; that means
9620 that people can use force-mode-line-update to request
9621 that the menu bar be recomputed. The adverse effect on
9622 the rest of the redisplay algorithm is about the same as
9623 windows_or_buffers_changed anyway. */
9624 if (windows_or_buffers_changed
9625 /* This used to test w->update_mode_line, but we believe
9626 there is no need to recompute the menu in that case. */
9627 || update_mode_lines
9628 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9629 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9630 != !NILP (w
->last_had_star
))
9631 || ((!NILP (Vtransient_mark_mode
)
9632 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9633 != !NILP (w
->region_showing
)))
9635 struct buffer
*prev
= current_buffer
;
9636 int count
= SPECPDL_INDEX ();
9638 specbind (Qinhibit_menubar_update
, Qt
);
9640 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9641 if (save_match_data
)
9642 record_unwind_save_match_data ();
9643 if (NILP (Voverriding_local_map_menu_flag
))
9645 specbind (Qoverriding_terminal_local_map
, Qnil
);
9646 specbind (Qoverriding_local_map
, Qnil
);
9651 /* Run the Lucid hook. */
9652 safe_run_hooks (Qactivate_menubar_hook
);
9654 /* If it has changed current-menubar from previous value,
9655 really recompute the menu-bar from the value. */
9656 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9657 call0 (Qrecompute_lucid_menubar
);
9659 safe_run_hooks (Qmenu_bar_update_hook
);
9664 XSETFRAME (Vmenu_updating_frame
, f
);
9665 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9667 /* Redisplay the menu bar in case we changed it. */
9668 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9669 || defined (HAVE_NS) || defined (USE_GTK)
9670 if (FRAME_WINDOW_P (f
))
9672 #if defined (HAVE_NS)
9673 /* All frames on Mac OS share the same menubar. So only
9674 the selected frame should be allowed to set it. */
9675 if (f
== SELECTED_FRAME ())
9677 set_frame_menubar (f
, 0, 0);
9680 /* On a terminal screen, the menu bar is an ordinary screen
9681 line, and this makes it get updated. */
9682 w
->update_mode_line
= Qt
;
9683 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9684 /* In the non-toolkit version, the menu bar is an ordinary screen
9685 line, and this makes it get updated. */
9686 w
->update_mode_line
= Qt
;
9687 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9689 unbind_to (count
, Qnil
);
9690 set_buffer_internal_1 (prev
);
9699 /***********************************************************************
9701 ***********************************************************************/
9703 #ifdef HAVE_WINDOW_SYSTEM
9706 Nominal cursor position -- where to draw output.
9707 HPOS and VPOS are window relative glyph matrix coordinates.
9708 X and Y are window relative pixel coordinates. */
9710 struct cursor_pos output_cursor
;
9714 Set the global variable output_cursor to CURSOR. All cursor
9715 positions are relative to updated_window. */
9718 set_output_cursor (cursor
)
9719 struct cursor_pos
*cursor
;
9721 output_cursor
.hpos
= cursor
->hpos
;
9722 output_cursor
.vpos
= cursor
->vpos
;
9723 output_cursor
.x
= cursor
->x
;
9724 output_cursor
.y
= cursor
->y
;
9729 Set a nominal cursor position.
9731 HPOS and VPOS are column/row positions in a window glyph matrix. X
9732 and Y are window text area relative pixel positions.
9734 If this is done during an update, updated_window will contain the
9735 window that is being updated and the position is the future output
9736 cursor position for that window. If updated_window is null, use
9737 selected_window and display the cursor at the given position. */
9740 x_cursor_to (vpos
, hpos
, y
, x
)
9741 int vpos
, hpos
, y
, x
;
9745 /* If updated_window is not set, work on selected_window. */
9749 w
= XWINDOW (selected_window
);
9751 /* Set the output cursor. */
9752 output_cursor
.hpos
= hpos
;
9753 output_cursor
.vpos
= vpos
;
9754 output_cursor
.x
= x
;
9755 output_cursor
.y
= y
;
9757 /* If not called as part of an update, really display the cursor.
9758 This will also set the cursor position of W. */
9759 if (updated_window
== NULL
)
9762 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9763 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9764 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9769 #endif /* HAVE_WINDOW_SYSTEM */
9772 /***********************************************************************
9774 ***********************************************************************/
9776 #ifdef HAVE_WINDOW_SYSTEM
9778 /* Where the mouse was last time we reported a mouse event. */
9780 FRAME_PTR last_mouse_frame
;
9782 /* Tool-bar item index of the item on which a mouse button was pressed
9785 int last_tool_bar_item
;
9789 update_tool_bar_unwind (frame
)
9792 selected_frame
= frame
;
9796 /* Update the tool-bar item list for frame F. This has to be done
9797 before we start to fill in any display lines. Called from
9798 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9799 and restore it here. */
9802 update_tool_bar (f
, save_match_data
)
9804 int save_match_data
;
9806 #if defined (USE_GTK) || defined (HAVE_NS)
9807 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9809 int do_update
= WINDOWP (f
->tool_bar_window
)
9810 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9818 window
= FRAME_SELECTED_WINDOW (f
);
9819 w
= XWINDOW (window
);
9821 /* If the user has switched buffers or windows, we need to
9822 recompute to reflect the new bindings. But we'll
9823 recompute when update_mode_lines is set too; that means
9824 that people can use force-mode-line-update to request
9825 that the menu bar be recomputed. The adverse effect on
9826 the rest of the redisplay algorithm is about the same as
9827 windows_or_buffers_changed anyway. */
9828 if (windows_or_buffers_changed
9829 || !NILP (w
->update_mode_line
)
9830 || update_mode_lines
9831 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9832 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9833 != !NILP (w
->last_had_star
))
9834 || ((!NILP (Vtransient_mark_mode
)
9835 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9836 != !NILP (w
->region_showing
)))
9838 struct buffer
*prev
= current_buffer
;
9839 int count
= SPECPDL_INDEX ();
9840 Lisp_Object frame
, new_tool_bar
;
9842 struct gcpro gcpro1
;
9844 /* Set current_buffer to the buffer of the selected
9845 window of the frame, so that we get the right local
9847 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9849 /* Save match data, if we must. */
9850 if (save_match_data
)
9851 record_unwind_save_match_data ();
9853 /* Make sure that we don't accidentally use bogus keymaps. */
9854 if (NILP (Voverriding_local_map_menu_flag
))
9856 specbind (Qoverriding_terminal_local_map
, Qnil
);
9857 specbind (Qoverriding_local_map
, Qnil
);
9860 GCPRO1 (new_tool_bar
);
9862 /* We must temporarily set the selected frame to this frame
9863 before calling tool_bar_items, because the calculation of
9864 the tool-bar keymap uses the selected frame (see
9865 `tool-bar-make-keymap' in tool-bar.el). */
9866 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9867 XSETFRAME (frame
, f
);
9868 selected_frame
= frame
;
9870 /* Build desired tool-bar items from keymaps. */
9871 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9874 /* Redisplay the tool-bar if we changed it. */
9875 if (new_n_tool_bar
!= f
->n_tool_bar_items
9876 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9878 /* Redisplay that happens asynchronously due to an expose event
9879 may access f->tool_bar_items. Make sure we update both
9880 variables within BLOCK_INPUT so no such event interrupts. */
9882 f
->tool_bar_items
= new_tool_bar
;
9883 f
->n_tool_bar_items
= new_n_tool_bar
;
9884 w
->update_mode_line
= Qt
;
9890 unbind_to (count
, Qnil
);
9891 set_buffer_internal_1 (prev
);
9897 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9898 F's desired tool-bar contents. F->tool_bar_items must have
9899 been set up previously by calling prepare_menu_bars. */
9902 build_desired_tool_bar_string (f
)
9905 int i
, size
, size_needed
;
9906 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9907 Lisp_Object image
, plist
, props
;
9909 image
= plist
= props
= Qnil
;
9910 GCPRO3 (image
, plist
, props
);
9912 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9913 Otherwise, make a new string. */
9915 /* The size of the string we might be able to reuse. */
9916 size
= (STRINGP (f
->desired_tool_bar_string
)
9917 ? SCHARS (f
->desired_tool_bar_string
)
9920 /* We need one space in the string for each image. */
9921 size_needed
= f
->n_tool_bar_items
;
9923 /* Reuse f->desired_tool_bar_string, if possible. */
9924 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9925 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9929 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9930 Fremove_text_properties (make_number (0), make_number (size
),
9931 props
, f
->desired_tool_bar_string
);
9934 /* Put a `display' property on the string for the images to display,
9935 put a `menu_item' property on tool-bar items with a value that
9936 is the index of the item in F's tool-bar item vector. */
9937 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9939 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9941 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9942 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9943 int hmargin
, vmargin
, relief
, idx
, end
;
9944 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9946 /* If image is a vector, choose the image according to the
9948 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9949 if (VECTORP (image
))
9953 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9954 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9957 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9958 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9960 xassert (ASIZE (image
) >= idx
);
9961 image
= AREF (image
, idx
);
9966 /* Ignore invalid image specifications. */
9967 if (!valid_image_p (image
))
9970 /* Display the tool-bar button pressed, or depressed. */
9971 plist
= Fcopy_sequence (XCDR (image
));
9973 /* Compute margin and relief to draw. */
9974 relief
= (tool_bar_button_relief
>= 0
9975 ? tool_bar_button_relief
9976 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9977 hmargin
= vmargin
= relief
;
9979 if (INTEGERP (Vtool_bar_button_margin
)
9980 && XINT (Vtool_bar_button_margin
) > 0)
9982 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9983 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9985 else if (CONSP (Vtool_bar_button_margin
))
9987 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9988 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9989 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9991 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9992 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9993 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9996 if (auto_raise_tool_bar_buttons_p
)
9998 /* Add a `:relief' property to the image spec if the item is
10002 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10009 /* If image is selected, display it pressed, i.e. with a
10010 negative relief. If it's not selected, display it with a
10012 plist
= Fplist_put (plist
, QCrelief
,
10014 ? make_number (-relief
)
10015 : make_number (relief
)));
10020 /* Put a margin around the image. */
10021 if (hmargin
|| vmargin
)
10023 if (hmargin
== vmargin
)
10024 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10026 plist
= Fplist_put (plist
, QCmargin
,
10027 Fcons (make_number (hmargin
),
10028 make_number (vmargin
)));
10031 /* If button is not enabled, and we don't have special images
10032 for the disabled state, make the image appear disabled by
10033 applying an appropriate algorithm to it. */
10034 if (!enabled_p
&& idx
< 0)
10035 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10037 /* Put a `display' text property on the string for the image to
10038 display. Put a `menu-item' property on the string that gives
10039 the start of this item's properties in the tool-bar items
10041 image
= Fcons (Qimage
, plist
);
10042 props
= list4 (Qdisplay
, image
,
10043 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10045 /* Let the last image hide all remaining spaces in the tool bar
10046 string. The string can be longer than needed when we reuse a
10047 previous string. */
10048 if (i
+ 1 == f
->n_tool_bar_items
)
10049 end
= SCHARS (f
->desired_tool_bar_string
);
10052 Fadd_text_properties (make_number (i
), make_number (end
),
10053 props
, f
->desired_tool_bar_string
);
10061 /* Display one line of the tool-bar of frame IT->f.
10063 HEIGHT specifies the desired height of the tool-bar line.
10064 If the actual height of the glyph row is less than HEIGHT, the
10065 row's height is increased to HEIGHT, and the icons are centered
10066 vertically in the new height.
10068 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10069 count a final empty row in case the tool-bar width exactly matches
10074 display_tool_bar_line (it
, height
)
10078 struct glyph_row
*row
= it
->glyph_row
;
10079 int max_x
= it
->last_visible_x
;
10080 struct glyph
*last
;
10082 prepare_desired_row (row
);
10083 row
->y
= it
->current_y
;
10085 /* Note that this isn't made use of if the face hasn't a box,
10086 so there's no need to check the face here. */
10087 it
->start_of_box_run_p
= 1;
10089 while (it
->current_x
< max_x
)
10091 int x
, n_glyphs_before
, i
, nglyphs
;
10092 struct it it_before
;
10094 /* Get the next display element. */
10095 if (!get_next_display_element (it
))
10097 /* Don't count empty row if we are counting needed tool-bar lines. */
10098 if (height
< 0 && !it
->hpos
)
10103 /* Produce glyphs. */
10104 n_glyphs_before
= row
->used
[TEXT_AREA
];
10107 PRODUCE_GLYPHS (it
);
10109 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10111 x
= it_before
.current_x
;
10112 while (i
< nglyphs
)
10114 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10116 if (x
+ glyph
->pixel_width
> max_x
)
10118 /* Glyph doesn't fit on line. Backtrack. */
10119 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10121 /* If this is the only glyph on this line, it will never fit on the
10122 toolbar, so skip it. But ensure there is at least one glyph,
10123 so we don't accidentally disable the tool-bar. */
10124 if (n_glyphs_before
== 0
10125 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10131 x
+= glyph
->pixel_width
;
10135 /* Stop at line ends. */
10136 if (ITERATOR_AT_END_OF_LINE_P (it
))
10139 set_iterator_to_next (it
, 1);
10144 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10146 /* Use default face for the border below the tool bar.
10148 FIXME: When auto-resize-tool-bars is grow-only, there is
10149 no additional border below the possibly empty tool-bar lines.
10150 So to make the extra empty lines look "normal", we have to
10151 use the tool-bar face for the border too. */
10152 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10153 it
->face_id
= DEFAULT_FACE_ID
;
10155 extend_face_to_end_of_line (it
);
10156 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10157 last
->right_box_line_p
= 1;
10158 if (last
== row
->glyphs
[TEXT_AREA
])
10159 last
->left_box_line_p
= 1;
10161 /* Make line the desired height and center it vertically. */
10162 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10164 /* Don't add more than one line height. */
10165 height
%= FRAME_LINE_HEIGHT (it
->f
);
10166 it
->max_ascent
+= height
/ 2;
10167 it
->max_descent
+= (height
+ 1) / 2;
10170 compute_line_metrics (it
);
10172 /* If line is empty, make it occupy the rest of the tool-bar. */
10173 if (!row
->displays_text_p
)
10175 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10176 row
->visible_height
= row
->height
;
10177 row
->ascent
= row
->phys_ascent
= 0;
10178 row
->extra_line_spacing
= 0;
10181 row
->full_width_p
= 1;
10182 row
->continued_p
= 0;
10183 row
->truncated_on_left_p
= 0;
10184 row
->truncated_on_right_p
= 0;
10186 it
->current_x
= it
->hpos
= 0;
10187 it
->current_y
+= row
->height
;
10193 /* Max tool-bar height. */
10195 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10196 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10198 /* Value is the number of screen lines needed to make all tool-bar
10199 items of frame F visible. The number of actual rows needed is
10200 returned in *N_ROWS if non-NULL. */
10203 tool_bar_lines_needed (f
, n_rows
)
10207 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10209 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10210 the desired matrix, so use (unused) mode-line row as temporary row to
10211 avoid destroying the first tool-bar row. */
10212 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10214 /* Initialize an iterator for iteration over
10215 F->desired_tool_bar_string in the tool-bar window of frame F. */
10216 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10217 it
.first_visible_x
= 0;
10218 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10219 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10221 while (!ITERATOR_AT_END_P (&it
))
10223 clear_glyph_row (temp_row
);
10224 it
.glyph_row
= temp_row
;
10225 display_tool_bar_line (&it
, -1);
10227 clear_glyph_row (temp_row
);
10229 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10231 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10233 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10237 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10239 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10248 frame
= selected_frame
;
10250 CHECK_FRAME (frame
);
10251 f
= XFRAME (frame
);
10253 if (WINDOWP (f
->tool_bar_window
)
10254 || (w
= XWINDOW (f
->tool_bar_window
),
10255 WINDOW_TOTAL_LINES (w
) > 0))
10257 update_tool_bar (f
, 1);
10258 if (f
->n_tool_bar_items
)
10260 build_desired_tool_bar_string (f
);
10261 nlines
= tool_bar_lines_needed (f
, NULL
);
10265 return make_number (nlines
);
10269 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10270 height should be changed. */
10273 redisplay_tool_bar (f
)
10278 struct glyph_row
*row
;
10280 #if defined (USE_GTK) || defined (HAVE_NS)
10281 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10282 update_frame_tool_bar (f
);
10286 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10287 do anything. This means you must start with tool-bar-lines
10288 non-zero to get the auto-sizing effect. Or in other words, you
10289 can turn off tool-bars by specifying tool-bar-lines zero. */
10290 if (!WINDOWP (f
->tool_bar_window
)
10291 || (w
= XWINDOW (f
->tool_bar_window
),
10292 WINDOW_TOTAL_LINES (w
) == 0))
10295 /* Set up an iterator for the tool-bar window. */
10296 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10297 it
.first_visible_x
= 0;
10298 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10299 row
= it
.glyph_row
;
10301 /* Build a string that represents the contents of the tool-bar. */
10302 build_desired_tool_bar_string (f
);
10303 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10305 if (f
->n_tool_bar_rows
== 0)
10309 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10310 nlines
!= WINDOW_TOTAL_LINES (w
)))
10312 extern Lisp_Object Qtool_bar_lines
;
10314 int old_height
= WINDOW_TOTAL_LINES (w
);
10316 XSETFRAME (frame
, f
);
10317 Fmodify_frame_parameters (frame
,
10318 Fcons (Fcons (Qtool_bar_lines
,
10319 make_number (nlines
)),
10321 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10323 clear_glyph_matrix (w
->desired_matrix
);
10324 fonts_changed_p
= 1;
10330 /* Display as many lines as needed to display all tool-bar items. */
10332 if (f
->n_tool_bar_rows
> 0)
10334 int border
, rows
, height
, extra
;
10336 if (INTEGERP (Vtool_bar_border
))
10337 border
= XINT (Vtool_bar_border
);
10338 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10339 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10340 else if (EQ (Vtool_bar_border
, Qborder_width
))
10341 border
= f
->border_width
;
10347 rows
= f
->n_tool_bar_rows
;
10348 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10349 extra
= it
.last_visible_y
- border
- height
* rows
;
10351 while (it
.current_y
< it
.last_visible_y
)
10354 if (extra
> 0 && rows
-- > 0)
10356 h
= (extra
+ rows
- 1) / rows
;
10359 display_tool_bar_line (&it
, height
+ h
);
10364 while (it
.current_y
< it
.last_visible_y
)
10365 display_tool_bar_line (&it
, 0);
10368 /* It doesn't make much sense to try scrolling in the tool-bar
10369 window, so don't do it. */
10370 w
->desired_matrix
->no_scrolling_p
= 1;
10371 w
->must_be_updated_p
= 1;
10373 if (!NILP (Vauto_resize_tool_bars
))
10375 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10376 int change_height_p
= 0;
10378 /* If we couldn't display everything, change the tool-bar's
10379 height if there is room for more. */
10380 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10381 && it
.current_y
< max_tool_bar_height
)
10382 change_height_p
= 1;
10384 row
= it
.glyph_row
- 1;
10386 /* If there are blank lines at the end, except for a partially
10387 visible blank line at the end that is smaller than
10388 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10389 if (!row
->displays_text_p
10390 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10391 change_height_p
= 1;
10393 /* If row displays tool-bar items, but is partially visible,
10394 change the tool-bar's height. */
10395 if (row
->displays_text_p
10396 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10397 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10398 change_height_p
= 1;
10400 /* Resize windows as needed by changing the `tool-bar-lines'
10401 frame parameter. */
10402 if (change_height_p
)
10404 extern Lisp_Object Qtool_bar_lines
;
10406 int old_height
= WINDOW_TOTAL_LINES (w
);
10408 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10410 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10411 && !f
->minimize_tool_bar_window_p
)
10412 ? (nlines
> old_height
)
10413 : (nlines
!= old_height
));
10414 f
->minimize_tool_bar_window_p
= 0;
10416 if (change_height_p
)
10418 XSETFRAME (frame
, f
);
10419 Fmodify_frame_parameters (frame
,
10420 Fcons (Fcons (Qtool_bar_lines
,
10421 make_number (nlines
)),
10423 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10425 clear_glyph_matrix (w
->desired_matrix
);
10426 f
->n_tool_bar_rows
= nrows
;
10427 fonts_changed_p
= 1;
10434 f
->minimize_tool_bar_window_p
= 0;
10439 /* Get information about the tool-bar item which is displayed in GLYPH
10440 on frame F. Return in *PROP_IDX the index where tool-bar item
10441 properties start in F->tool_bar_items. Value is zero if
10442 GLYPH doesn't display a tool-bar item. */
10445 tool_bar_item_info (f
, glyph
, prop_idx
)
10447 struct glyph
*glyph
;
10454 /* This function can be called asynchronously, which means we must
10455 exclude any possibility that Fget_text_property signals an
10457 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10458 charpos
= max (0, charpos
);
10460 /* Get the text property `menu-item' at pos. The value of that
10461 property is the start index of this item's properties in
10462 F->tool_bar_items. */
10463 prop
= Fget_text_property (make_number (charpos
),
10464 Qmenu_item
, f
->current_tool_bar_string
);
10465 if (INTEGERP (prop
))
10467 *prop_idx
= XINT (prop
);
10477 /* Get information about the tool-bar item at position X/Y on frame F.
10478 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10479 the current matrix of the tool-bar window of F, or NULL if not
10480 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10481 item in F->tool_bar_items. Value is
10483 -1 if X/Y is not on a tool-bar item
10484 0 if X/Y is on the same item that was highlighted before.
10488 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10491 struct glyph
**glyph
;
10492 int *hpos
, *vpos
, *prop_idx
;
10494 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10495 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10498 /* Find the glyph under X/Y. */
10499 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10500 if (*glyph
== NULL
)
10503 /* Get the start of this tool-bar item's properties in
10504 f->tool_bar_items. */
10505 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10508 /* Is mouse on the highlighted item? */
10509 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10510 && *vpos
>= dpyinfo
->mouse_face_beg_row
10511 && *vpos
<= dpyinfo
->mouse_face_end_row
10512 && (*vpos
> dpyinfo
->mouse_face_beg_row
10513 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10514 && (*vpos
< dpyinfo
->mouse_face_end_row
10515 || *hpos
< dpyinfo
->mouse_face_end_col
10516 || dpyinfo
->mouse_face_past_end
))
10524 Handle mouse button event on the tool-bar of frame F, at
10525 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10526 0 for button release. MODIFIERS is event modifiers for button
10530 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10533 unsigned int modifiers
;
10535 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10536 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10537 int hpos
, vpos
, prop_idx
;
10538 struct glyph
*glyph
;
10539 Lisp_Object enabled_p
;
10541 /* If not on the highlighted tool-bar item, return. */
10542 frame_to_window_pixel_xy (w
, &x
, &y
);
10543 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10546 /* If item is disabled, do nothing. */
10547 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10548 if (NILP (enabled_p
))
10553 /* Show item in pressed state. */
10554 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10555 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10556 last_tool_bar_item
= prop_idx
;
10560 Lisp_Object key
, frame
;
10561 struct input_event event
;
10562 EVENT_INIT (event
);
10564 /* Show item in released state. */
10565 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10566 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10568 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10570 XSETFRAME (frame
, f
);
10571 event
.kind
= TOOL_BAR_EVENT
;
10572 event
.frame_or_window
= frame
;
10574 kbd_buffer_store_event (&event
);
10576 event
.kind
= TOOL_BAR_EVENT
;
10577 event
.frame_or_window
= frame
;
10579 event
.modifiers
= modifiers
;
10580 kbd_buffer_store_event (&event
);
10581 last_tool_bar_item
= -1;
10586 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10587 tool-bar window-relative coordinates X/Y. Called from
10588 note_mouse_highlight. */
10591 note_tool_bar_highlight (f
, x
, y
)
10595 Lisp_Object window
= f
->tool_bar_window
;
10596 struct window
*w
= XWINDOW (window
);
10597 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10599 struct glyph
*glyph
;
10600 struct glyph_row
*row
;
10602 Lisp_Object enabled_p
;
10604 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10605 int mouse_down_p
, rc
;
10607 /* Function note_mouse_highlight is called with negative x(y
10608 values when mouse moves outside of the frame. */
10609 if (x
<= 0 || y
<= 0)
10611 clear_mouse_face (dpyinfo
);
10615 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10618 /* Not on tool-bar item. */
10619 clear_mouse_face (dpyinfo
);
10623 /* On same tool-bar item as before. */
10624 goto set_help_echo
;
10626 clear_mouse_face (dpyinfo
);
10628 /* Mouse is down, but on different tool-bar item? */
10629 mouse_down_p
= (dpyinfo
->grabbed
10630 && f
== last_mouse_frame
10631 && FRAME_LIVE_P (f
));
10633 && last_tool_bar_item
!= prop_idx
)
10636 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10637 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10639 /* If tool-bar item is not enabled, don't highlight it. */
10640 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10641 if (!NILP (enabled_p
))
10643 /* Compute the x-position of the glyph. In front and past the
10644 image is a space. We include this in the highlighted area. */
10645 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10646 for (i
= x
= 0; i
< hpos
; ++i
)
10647 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10649 /* Record this as the current active region. */
10650 dpyinfo
->mouse_face_beg_col
= hpos
;
10651 dpyinfo
->mouse_face_beg_row
= vpos
;
10652 dpyinfo
->mouse_face_beg_x
= x
;
10653 dpyinfo
->mouse_face_beg_y
= row
->y
;
10654 dpyinfo
->mouse_face_past_end
= 0;
10656 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10657 dpyinfo
->mouse_face_end_row
= vpos
;
10658 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10659 dpyinfo
->mouse_face_end_y
= row
->y
;
10660 dpyinfo
->mouse_face_window
= window
;
10661 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10663 /* Display it as active. */
10664 show_mouse_face (dpyinfo
, draw
);
10665 dpyinfo
->mouse_face_image_state
= draw
;
10670 /* Set help_echo_string to a help string to display for this tool-bar item.
10671 XTread_socket does the rest. */
10672 help_echo_object
= help_echo_window
= Qnil
;
10673 help_echo_pos
= -1;
10674 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10675 if (NILP (help_echo_string
))
10676 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10679 #endif /* HAVE_WINDOW_SYSTEM */
10683 /************************************************************************
10684 Horizontal scrolling
10685 ************************************************************************/
10687 static int hscroll_window_tree
P_ ((Lisp_Object
));
10688 static int hscroll_windows
P_ ((Lisp_Object
));
10690 /* For all leaf windows in the window tree rooted at WINDOW, set their
10691 hscroll value so that PT is (i) visible in the window, and (ii) so
10692 that it is not within a certain margin at the window's left and
10693 right border. Value is non-zero if any window's hscroll has been
10697 hscroll_window_tree (window
)
10698 Lisp_Object window
;
10700 int hscrolled_p
= 0;
10701 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10702 int hscroll_step_abs
= 0;
10703 double hscroll_step_rel
= 0;
10705 if (hscroll_relative_p
)
10707 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10708 if (hscroll_step_rel
< 0)
10710 hscroll_relative_p
= 0;
10711 hscroll_step_abs
= 0;
10714 else if (INTEGERP (Vhscroll_step
))
10716 hscroll_step_abs
= XINT (Vhscroll_step
);
10717 if (hscroll_step_abs
< 0)
10718 hscroll_step_abs
= 0;
10721 hscroll_step_abs
= 0;
10723 while (WINDOWP (window
))
10725 struct window
*w
= XWINDOW (window
);
10727 if (WINDOWP (w
->hchild
))
10728 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10729 else if (WINDOWP (w
->vchild
))
10730 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10731 else if (w
->cursor
.vpos
>= 0)
10734 int text_area_width
;
10735 struct glyph_row
*current_cursor_row
10736 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10737 struct glyph_row
*desired_cursor_row
10738 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10739 struct glyph_row
*cursor_row
10740 = (desired_cursor_row
->enabled_p
10741 ? desired_cursor_row
10742 : current_cursor_row
);
10744 text_area_width
= window_box_width (w
, TEXT_AREA
);
10746 /* Scroll when cursor is inside this scroll margin. */
10747 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10749 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10750 && ((XFASTINT (w
->hscroll
)
10751 && w
->cursor
.x
<= h_margin
)
10752 || (cursor_row
->enabled_p
10753 && cursor_row
->truncated_on_right_p
10754 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10758 struct buffer
*saved_current_buffer
;
10762 /* Find point in a display of infinite width. */
10763 saved_current_buffer
= current_buffer
;
10764 current_buffer
= XBUFFER (w
->buffer
);
10766 if (w
== XWINDOW (selected_window
))
10767 pt
= BUF_PT (current_buffer
);
10770 pt
= marker_position (w
->pointm
);
10771 pt
= max (BEGV
, pt
);
10775 /* Move iterator to pt starting at cursor_row->start in
10776 a line with infinite width. */
10777 init_to_row_start (&it
, w
, cursor_row
);
10778 it
.last_visible_x
= INFINITY
;
10779 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10780 current_buffer
= saved_current_buffer
;
10782 /* Position cursor in window. */
10783 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10784 hscroll
= max (0, (it
.current_x
10785 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10786 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10787 : (text_area_width
/ 2))))
10788 / FRAME_COLUMN_WIDTH (it
.f
);
10789 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10791 if (hscroll_relative_p
)
10792 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10795 wanted_x
= text_area_width
10796 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10799 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10803 if (hscroll_relative_p
)
10804 wanted_x
= text_area_width
* hscroll_step_rel
10807 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10810 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10812 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10814 /* Don't call Fset_window_hscroll if value hasn't
10815 changed because it will prevent redisplay
10817 if (XFASTINT (w
->hscroll
) != hscroll
)
10819 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10820 w
->hscroll
= make_number (hscroll
);
10829 /* Value is non-zero if hscroll of any leaf window has been changed. */
10830 return hscrolled_p
;
10834 /* Set hscroll so that cursor is visible and not inside horizontal
10835 scroll margins for all windows in the tree rooted at WINDOW. See
10836 also hscroll_window_tree above. Value is non-zero if any window's
10837 hscroll has been changed. If it has, desired matrices on the frame
10838 of WINDOW are cleared. */
10841 hscroll_windows (window
)
10842 Lisp_Object window
;
10844 int hscrolled_p
= hscroll_window_tree (window
);
10846 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10847 return hscrolled_p
;
10852 /************************************************************************
10854 ************************************************************************/
10856 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10857 to a non-zero value. This is sometimes handy to have in a debugger
10862 /* First and last unchanged row for try_window_id. */
10864 int debug_first_unchanged_at_end_vpos
;
10865 int debug_last_unchanged_at_beg_vpos
;
10867 /* Delta vpos and y. */
10869 int debug_dvpos
, debug_dy
;
10871 /* Delta in characters and bytes for try_window_id. */
10873 int debug_delta
, debug_delta_bytes
;
10875 /* Values of window_end_pos and window_end_vpos at the end of
10878 EMACS_INT debug_end_pos
, debug_end_vpos
;
10880 /* Append a string to W->desired_matrix->method. FMT is a printf
10881 format string. A1...A9 are a supplement for a variable-length
10882 argument list. If trace_redisplay_p is non-zero also printf the
10883 resulting string to stderr. */
10886 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10889 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10892 char *method
= w
->desired_matrix
->method
;
10893 int len
= strlen (method
);
10894 int size
= sizeof w
->desired_matrix
->method
;
10895 int remaining
= size
- len
- 1;
10897 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10898 if (len
&& remaining
)
10901 --remaining
, ++len
;
10904 strncpy (method
+ len
, buffer
, remaining
);
10906 if (trace_redisplay_p
)
10907 fprintf (stderr
, "%p (%s): %s\n",
10909 ((BUFFERP (w
->buffer
)
10910 && STRINGP (XBUFFER (w
->buffer
)->name
))
10911 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10916 #endif /* GLYPH_DEBUG */
10919 /* Value is non-zero if all changes in window W, which displays
10920 current_buffer, are in the text between START and END. START is a
10921 buffer position, END is given as a distance from Z. Used in
10922 redisplay_internal for display optimization. */
10925 text_outside_line_unchanged_p (w
, start
, end
)
10929 int unchanged_p
= 1;
10931 /* If text or overlays have changed, see where. */
10932 if (XFASTINT (w
->last_modified
) < MODIFF
10933 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10935 /* Gap in the line? */
10936 if (GPT
< start
|| Z
- GPT
< end
)
10939 /* Changes start in front of the line, or end after it? */
10941 && (BEG_UNCHANGED
< start
- 1
10942 || END_UNCHANGED
< end
))
10945 /* If selective display, can't optimize if changes start at the
10946 beginning of the line. */
10948 && INTEGERP (current_buffer
->selective_display
)
10949 && XINT (current_buffer
->selective_display
) > 0
10950 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10953 /* If there are overlays at the start or end of the line, these
10954 may have overlay strings with newlines in them. A change at
10955 START, for instance, may actually concern the display of such
10956 overlay strings as well, and they are displayed on different
10957 lines. So, quickly rule out this case. (For the future, it
10958 might be desirable to implement something more telling than
10959 just BEG/END_UNCHANGED.) */
10962 if (BEG
+ BEG_UNCHANGED
== start
10963 && overlay_touches_p (start
))
10965 if (END_UNCHANGED
== end
10966 && overlay_touches_p (Z
- end
))
10971 return unchanged_p
;
10975 /* Do a frame update, taking possible shortcuts into account. This is
10976 the main external entry point for redisplay.
10978 If the last redisplay displayed an echo area message and that message
10979 is no longer requested, we clear the echo area or bring back the
10980 mini-buffer if that is in use. */
10985 redisplay_internal (0);
10990 overlay_arrow_string_or_property (var
)
10995 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10998 return Voverlay_arrow_string
;
11001 /* Return 1 if there are any overlay-arrows in current_buffer. */
11003 overlay_arrow_in_current_buffer_p ()
11007 for (vlist
= Voverlay_arrow_variable_list
;
11009 vlist
= XCDR (vlist
))
11011 Lisp_Object var
= XCAR (vlist
);
11014 if (!SYMBOLP (var
))
11016 val
= find_symbol_value (var
);
11018 && current_buffer
== XMARKER (val
)->buffer
)
11025 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11029 overlay_arrows_changed_p ()
11033 for (vlist
= Voverlay_arrow_variable_list
;
11035 vlist
= XCDR (vlist
))
11037 Lisp_Object var
= XCAR (vlist
);
11038 Lisp_Object val
, pstr
;
11040 if (!SYMBOLP (var
))
11042 val
= find_symbol_value (var
);
11043 if (!MARKERP (val
))
11045 if (! EQ (COERCE_MARKER (val
),
11046 Fget (var
, Qlast_arrow_position
))
11047 || ! (pstr
= overlay_arrow_string_or_property (var
),
11048 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11054 /* Mark overlay arrows to be updated on next redisplay. */
11057 update_overlay_arrows (up_to_date
)
11062 for (vlist
= Voverlay_arrow_variable_list
;
11064 vlist
= XCDR (vlist
))
11066 Lisp_Object var
= XCAR (vlist
);
11068 if (!SYMBOLP (var
))
11071 if (up_to_date
> 0)
11073 Lisp_Object val
= find_symbol_value (var
);
11074 Fput (var
, Qlast_arrow_position
,
11075 COERCE_MARKER (val
));
11076 Fput (var
, Qlast_arrow_string
,
11077 overlay_arrow_string_or_property (var
));
11079 else if (up_to_date
< 0
11080 || !NILP (Fget (var
, Qlast_arrow_position
)))
11082 Fput (var
, Qlast_arrow_position
, Qt
);
11083 Fput (var
, Qlast_arrow_string
, Qt
);
11089 /* Return overlay arrow string to display at row.
11090 Return integer (bitmap number) for arrow bitmap in left fringe.
11091 Return nil if no overlay arrow. */
11094 overlay_arrow_at_row (it
, row
)
11096 struct glyph_row
*row
;
11100 for (vlist
= Voverlay_arrow_variable_list
;
11102 vlist
= XCDR (vlist
))
11104 Lisp_Object var
= XCAR (vlist
);
11107 if (!SYMBOLP (var
))
11110 val
= find_symbol_value (var
);
11113 && current_buffer
== XMARKER (val
)->buffer
11114 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11116 if (FRAME_WINDOW_P (it
->f
)
11117 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11119 #ifdef HAVE_WINDOW_SYSTEM
11120 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11123 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11124 return make_number (fringe_bitmap
);
11127 return make_number (-1); /* Use default arrow bitmap */
11129 return overlay_arrow_string_or_property (var
);
11136 /* Return 1 if point moved out of or into a composition. Otherwise
11137 return 0. PREV_BUF and PREV_PT are the last point buffer and
11138 position. BUF and PT are the current point buffer and position. */
11141 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11142 struct buffer
*prev_buf
, *buf
;
11145 EMACS_INT start
, end
;
11147 Lisp_Object buffer
;
11149 XSETBUFFER (buffer
, buf
);
11150 /* Check a composition at the last point if point moved within the
11152 if (prev_buf
== buf
)
11155 /* Point didn't move. */
11158 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11159 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11160 && COMPOSITION_VALID_P (start
, end
, prop
)
11161 && start
< prev_pt
&& end
> prev_pt
)
11162 /* The last point was within the composition. Return 1 iff
11163 point moved out of the composition. */
11164 return (pt
<= start
|| pt
>= end
);
11167 /* Check a composition at the current point. */
11168 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11169 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11170 && COMPOSITION_VALID_P (start
, end
, prop
)
11171 && start
< pt
&& end
> pt
);
11175 /* Reconsider the setting of B->clip_changed which is displayed
11179 reconsider_clip_changes (w
, b
)
11183 if (b
->clip_changed
11184 && !NILP (w
->window_end_valid
)
11185 && w
->current_matrix
->buffer
== b
11186 && w
->current_matrix
->zv
== BUF_ZV (b
)
11187 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11188 b
->clip_changed
= 0;
11190 /* If display wasn't paused, and W is not a tool bar window, see if
11191 point has been moved into or out of a composition. In that case,
11192 we set b->clip_changed to 1 to force updating the screen. If
11193 b->clip_changed has already been set to 1, we can skip this
11195 if (!b
->clip_changed
11196 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11200 if (w
== XWINDOW (selected_window
))
11201 pt
= BUF_PT (current_buffer
);
11203 pt
= marker_position (w
->pointm
);
11205 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11206 || pt
!= XINT (w
->last_point
))
11207 && check_point_in_composition (w
->current_matrix
->buffer
,
11208 XINT (w
->last_point
),
11209 XBUFFER (w
->buffer
), pt
))
11210 b
->clip_changed
= 1;
11215 /* Select FRAME to forward the values of frame-local variables into C
11216 variables so that the redisplay routines can access those values
11220 select_frame_for_redisplay (frame
)
11223 Lisp_Object tail
, symbol
, val
;
11224 Lisp_Object old
= selected_frame
;
11225 struct Lisp_Symbol
*sym
;
11227 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11229 selected_frame
= frame
;
11233 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11234 if (CONSP (XCAR (tail
))
11235 && (symbol
= XCAR (XCAR (tail
)),
11237 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11239 (BUFFER_LOCAL_VALUEP (val
)))
11240 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11241 /* Use find_symbol_value rather than Fsymbol_value
11242 to avoid an error if it is void. */
11243 find_symbol_value (symbol
);
11244 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11248 #define STOP_POLLING \
11249 do { if (! polling_stopped_here) stop_polling (); \
11250 polling_stopped_here = 1; } while (0)
11252 #define RESUME_POLLING \
11253 do { if (polling_stopped_here) start_polling (); \
11254 polling_stopped_here = 0; } while (0)
11257 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11258 response to any user action; therefore, we should preserve the echo
11259 area. (Actually, our caller does that job.) Perhaps in the future
11260 avoid recentering windows if it is not necessary; currently that
11261 causes some problems. */
11264 redisplay_internal (preserve_echo_area
)
11265 int preserve_echo_area
;
11267 struct window
*w
= XWINDOW (selected_window
);
11270 int must_finish
= 0;
11271 struct text_pos tlbufpos
, tlendpos
;
11272 int number_of_visible_frames
;
11275 int polling_stopped_here
= 0;
11276 Lisp_Object old_frame
= selected_frame
;
11278 /* Non-zero means redisplay has to consider all windows on all
11279 frames. Zero means, only selected_window is considered. */
11280 int consider_all_windows_p
;
11282 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11284 /* No redisplay if running in batch mode or frame is not yet fully
11285 initialized, or redisplay is explicitly turned off by setting
11286 Vinhibit_redisplay. */
11287 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11288 || !NILP (Vinhibit_redisplay
))
11291 /* Don't examine these until after testing Vinhibit_redisplay.
11292 When Emacs is shutting down, perhaps because its connection to
11293 X has dropped, we should not look at them at all. */
11294 f
= XFRAME (w
->frame
);
11295 sf
= SELECTED_FRAME ();
11297 if (!f
->glyphs_initialized_p
)
11300 /* The flag redisplay_performed_directly_p is set by
11301 direct_output_for_insert when it already did the whole screen
11302 update necessary. */
11303 if (redisplay_performed_directly_p
)
11305 redisplay_performed_directly_p
= 0;
11306 if (!hscroll_windows (selected_window
))
11310 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11311 if (popup_activated ())
11315 /* I don't think this happens but let's be paranoid. */
11316 if (redisplaying_p
)
11319 /* Record a function that resets redisplaying_p to its old value
11320 when we leave this function. */
11321 count
= SPECPDL_INDEX ();
11322 record_unwind_protect (unwind_redisplay
,
11323 Fcons (make_number (redisplaying_p
), selected_frame
));
11325 specbind (Qinhibit_free_realized_faces
, Qnil
);
11328 Lisp_Object tail
, frame
;
11330 FOR_EACH_FRAME (tail
, frame
)
11332 struct frame
*f
= XFRAME (frame
);
11333 f
->already_hscrolled_p
= 0;
11338 if (!EQ (old_frame
, selected_frame
)
11339 && FRAME_LIVE_P (XFRAME (old_frame
)))
11340 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11341 selected_frame and selected_window to be temporarily out-of-sync so
11342 when we come back here via `goto retry', we need to resync because we
11343 may need to run Elisp code (via prepare_menu_bars). */
11344 select_frame_for_redisplay (old_frame
);
11347 reconsider_clip_changes (w
, current_buffer
);
11348 last_escape_glyph_frame
= NULL
;
11349 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11351 /* If new fonts have been loaded that make a glyph matrix adjustment
11352 necessary, do it. */
11353 if (fonts_changed_p
)
11355 adjust_glyphs (NULL
);
11356 ++windows_or_buffers_changed
;
11357 fonts_changed_p
= 0;
11360 /* If face_change_count is non-zero, init_iterator will free all
11361 realized faces, which includes the faces referenced from current
11362 matrices. So, we can't reuse current matrices in this case. */
11363 if (face_change_count
)
11364 ++windows_or_buffers_changed
;
11366 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11367 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11369 /* Since frames on a single ASCII terminal share the same
11370 display area, displaying a different frame means redisplay
11371 the whole thing. */
11372 windows_or_buffers_changed
++;
11373 SET_FRAME_GARBAGED (sf
);
11375 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11377 FRAME_TTY (sf
)->previous_frame
= sf
;
11380 /* Set the visible flags for all frames. Do this before checking
11381 for resized or garbaged frames; they want to know if their frames
11382 are visible. See the comment in frame.h for
11383 FRAME_SAMPLE_VISIBILITY. */
11385 Lisp_Object tail
, frame
;
11387 number_of_visible_frames
= 0;
11389 FOR_EACH_FRAME (tail
, frame
)
11391 struct frame
*f
= XFRAME (frame
);
11393 FRAME_SAMPLE_VISIBILITY (f
);
11394 if (FRAME_VISIBLE_P (f
))
11395 ++number_of_visible_frames
;
11396 clear_desired_matrices (f
);
11400 /* Notice any pending interrupt request to change frame size. */
11401 do_pending_window_change (1);
11403 /* Clear frames marked as garbaged. */
11404 if (frame_garbaged
)
11405 clear_garbaged_frames ();
11407 /* Build menubar and tool-bar items. */
11408 if (NILP (Vmemory_full
))
11409 prepare_menu_bars ();
11411 if (windows_or_buffers_changed
)
11412 update_mode_lines
++;
11414 /* Detect case that we need to write or remove a star in the mode line. */
11415 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11417 w
->update_mode_line
= Qt
;
11418 if (buffer_shared
> 1)
11419 update_mode_lines
++;
11422 /* Avoid invocation of point motion hooks by `current_column' below. */
11423 count1
= SPECPDL_INDEX ();
11424 specbind (Qinhibit_point_motion_hooks
, Qt
);
11426 /* If %c is in the mode line, update it if needed. */
11427 if (!NILP (w
->column_number_displayed
)
11428 /* This alternative quickly identifies a common case
11429 where no change is needed. */
11430 && !(PT
== XFASTINT (w
->last_point
)
11431 && XFASTINT (w
->last_modified
) >= MODIFF
11432 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11433 && (XFASTINT (w
->column_number_displayed
)
11434 != (int) current_column ())) /* iftc */
11435 w
->update_mode_line
= Qt
;
11437 unbind_to (count1
, Qnil
);
11439 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11441 /* The variable buffer_shared is set in redisplay_window and
11442 indicates that we redisplay a buffer in different windows. See
11444 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11445 || cursor_type_changed
);
11447 /* If specs for an arrow have changed, do thorough redisplay
11448 to ensure we remove any arrow that should no longer exist. */
11449 if (overlay_arrows_changed_p ())
11450 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11452 /* Normally the message* functions will have already displayed and
11453 updated the echo area, but the frame may have been trashed, or
11454 the update may have been preempted, so display the echo area
11455 again here. Checking message_cleared_p captures the case that
11456 the echo area should be cleared. */
11457 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11458 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11459 || (message_cleared_p
11460 && minibuf_level
== 0
11461 /* If the mini-window is currently selected, this means the
11462 echo-area doesn't show through. */
11463 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11465 int window_height_changed_p
= echo_area_display (0);
11468 /* If we don't display the current message, don't clear the
11469 message_cleared_p flag, because, if we did, we wouldn't clear
11470 the echo area in the next redisplay which doesn't preserve
11472 if (!display_last_displayed_message_p
)
11473 message_cleared_p
= 0;
11475 if (fonts_changed_p
)
11477 else if (window_height_changed_p
)
11479 consider_all_windows_p
= 1;
11480 ++update_mode_lines
;
11481 ++windows_or_buffers_changed
;
11483 /* If window configuration was changed, frames may have been
11484 marked garbaged. Clear them or we will experience
11485 surprises wrt scrolling. */
11486 if (frame_garbaged
)
11487 clear_garbaged_frames ();
11490 else if (EQ (selected_window
, minibuf_window
)
11491 && (current_buffer
->clip_changed
11492 || XFASTINT (w
->last_modified
) < MODIFF
11493 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11494 && resize_mini_window (w
, 0))
11496 /* Resized active mini-window to fit the size of what it is
11497 showing if its contents might have changed. */
11499 /* FIXME: this causes all frames to be updated, which seems unnecessary
11500 since only the current frame needs to be considered. This function needs
11501 to be rewritten with two variables, consider_all_windows and
11502 consider_all_frames. */
11503 consider_all_windows_p
= 1;
11504 ++windows_or_buffers_changed
;
11505 ++update_mode_lines
;
11507 /* If window configuration was changed, frames may have been
11508 marked garbaged. Clear them or we will experience
11509 surprises wrt scrolling. */
11510 if (frame_garbaged
)
11511 clear_garbaged_frames ();
11515 /* If showing the region, and mark has changed, we must redisplay
11516 the whole window. The assignment to this_line_start_pos prevents
11517 the optimization directly below this if-statement. */
11518 if (((!NILP (Vtransient_mark_mode
)
11519 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11520 != !NILP (w
->region_showing
))
11521 || (!NILP (w
->region_showing
)
11522 && !EQ (w
->region_showing
,
11523 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11524 CHARPOS (this_line_start_pos
) = 0;
11526 /* Optimize the case that only the line containing the cursor in the
11527 selected window has changed. Variables starting with this_ are
11528 set in display_line and record information about the line
11529 containing the cursor. */
11530 tlbufpos
= this_line_start_pos
;
11531 tlendpos
= this_line_end_pos
;
11532 if (!consider_all_windows_p
11533 && CHARPOS (tlbufpos
) > 0
11534 && NILP (w
->update_mode_line
)
11535 && !current_buffer
->clip_changed
11536 && !current_buffer
->prevent_redisplay_optimizations_p
11537 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11538 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11539 /* Make sure recorded data applies to current buffer, etc. */
11540 && this_line_buffer
== current_buffer
11541 && current_buffer
== XBUFFER (w
->buffer
)
11542 && NILP (w
->force_start
)
11543 && NILP (w
->optional_new_start
)
11544 /* Point must be on the line that we have info recorded about. */
11545 && PT
>= CHARPOS (tlbufpos
)
11546 && PT
<= Z
- CHARPOS (tlendpos
)
11547 /* All text outside that line, including its final newline,
11548 must be unchanged. */
11549 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11550 CHARPOS (tlendpos
)))
11552 if (CHARPOS (tlbufpos
) > BEGV
11553 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11554 && (CHARPOS (tlbufpos
) == ZV
11555 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11556 /* Former continuation line has disappeared by becoming empty. */
11558 else if (XFASTINT (w
->last_modified
) < MODIFF
11559 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11560 || MINI_WINDOW_P (w
))
11562 /* We have to handle the case of continuation around a
11563 wide-column character (see the comment in indent.c around
11566 For instance, in the following case:
11568 -------- Insert --------
11569 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11570 J_I_ ==> J_I_ `^^' are cursors.
11574 As we have to redraw the line above, we cannot use this
11578 int line_height_before
= this_line_pixel_height
;
11580 /* Note that start_display will handle the case that the
11581 line starting at tlbufpos is a continuation line. */
11582 start_display (&it
, w
, tlbufpos
);
11584 /* Implementation note: It this still necessary? */
11585 if (it
.current_x
!= this_line_start_x
)
11588 TRACE ((stderr
, "trying display optimization 1\n"));
11589 w
->cursor
.vpos
= -1;
11590 overlay_arrow_seen
= 0;
11591 it
.vpos
= this_line_vpos
;
11592 it
.current_y
= this_line_y
;
11593 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11594 display_line (&it
);
11596 /* If line contains point, is not continued,
11597 and ends at same distance from eob as before, we win. */
11598 if (w
->cursor
.vpos
>= 0
11599 /* Line is not continued, otherwise this_line_start_pos
11600 would have been set to 0 in display_line. */
11601 && CHARPOS (this_line_start_pos
)
11602 /* Line ends as before. */
11603 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11604 /* Line has same height as before. Otherwise other lines
11605 would have to be shifted up or down. */
11606 && this_line_pixel_height
== line_height_before
)
11608 /* If this is not the window's last line, we must adjust
11609 the charstarts of the lines below. */
11610 if (it
.current_y
< it
.last_visible_y
)
11612 struct glyph_row
*row
11613 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11614 int delta
, delta_bytes
;
11616 /* We used to distinguish between two cases here,
11617 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11618 when the line ends in a newline or the end of the
11619 buffer's accessible portion. But both cases did
11620 the same, so they were collapsed. */
11622 - CHARPOS (tlendpos
)
11623 - MATRIX_ROW_START_CHARPOS (row
));
11624 delta_bytes
= (Z_BYTE
11625 - BYTEPOS (tlendpos
)
11626 - MATRIX_ROW_START_BYTEPOS (row
));
11628 increment_matrix_positions (w
->current_matrix
,
11629 this_line_vpos
+ 1,
11630 w
->current_matrix
->nrows
,
11631 delta
, delta_bytes
);
11634 /* If this row displays text now but previously didn't,
11635 or vice versa, w->window_end_vpos may have to be
11637 if ((it
.glyph_row
- 1)->displays_text_p
)
11639 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11640 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11642 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11643 && this_line_vpos
> 0)
11644 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11645 w
->window_end_valid
= Qnil
;
11647 /* Update hint: No need to try to scroll in update_window. */
11648 w
->desired_matrix
->no_scrolling_p
= 1;
11651 *w
->desired_matrix
->method
= 0;
11652 debug_method_add (w
, "optimization 1");
11654 #ifdef HAVE_WINDOW_SYSTEM
11655 update_window_fringes (w
, 0);
11662 else if (/* Cursor position hasn't changed. */
11663 PT
== XFASTINT (w
->last_point
)
11664 /* Make sure the cursor was last displayed
11665 in this window. Otherwise we have to reposition it. */
11666 && 0 <= w
->cursor
.vpos
11667 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11671 do_pending_window_change (1);
11673 /* We used to always goto end_of_redisplay here, but this
11674 isn't enough if we have a blinking cursor. */
11675 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11676 goto end_of_redisplay
;
11680 /* If highlighting the region, or if the cursor is in the echo area,
11681 then we can't just move the cursor. */
11682 else if (! (!NILP (Vtransient_mark_mode
)
11683 && !NILP (current_buffer
->mark_active
))
11684 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11685 || highlight_nonselected_windows
)
11686 && NILP (w
->region_showing
)
11687 && NILP (Vshow_trailing_whitespace
)
11688 && !cursor_in_echo_area
)
11691 struct glyph_row
*row
;
11693 /* Skip from tlbufpos to PT and see where it is. Note that
11694 PT may be in invisible text. If so, we will end at the
11695 next visible position. */
11696 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11697 NULL
, DEFAULT_FACE_ID
);
11698 it
.current_x
= this_line_start_x
;
11699 it
.current_y
= this_line_y
;
11700 it
.vpos
= this_line_vpos
;
11702 /* The call to move_it_to stops in front of PT, but
11703 moves over before-strings. */
11704 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11706 if (it
.vpos
== this_line_vpos
11707 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11710 xassert (this_line_vpos
== it
.vpos
);
11711 xassert (this_line_y
== it
.current_y
);
11712 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11714 *w
->desired_matrix
->method
= 0;
11715 debug_method_add (w
, "optimization 3");
11724 /* Text changed drastically or point moved off of line. */
11725 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11728 CHARPOS (this_line_start_pos
) = 0;
11729 consider_all_windows_p
|= buffer_shared
> 1;
11730 ++clear_face_cache_count
;
11731 #ifdef HAVE_WINDOW_SYSTEM
11732 ++clear_image_cache_count
;
11735 /* Build desired matrices, and update the display. If
11736 consider_all_windows_p is non-zero, do it for all windows on all
11737 frames. Otherwise do it for selected_window, only. */
11739 if (consider_all_windows_p
)
11741 Lisp_Object tail
, frame
;
11743 FOR_EACH_FRAME (tail
, frame
)
11744 XFRAME (frame
)->updated_p
= 0;
11746 /* Recompute # windows showing selected buffer. This will be
11747 incremented each time such a window is displayed. */
11750 FOR_EACH_FRAME (tail
, frame
)
11752 struct frame
*f
= XFRAME (frame
);
11754 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11756 if (! EQ (frame
, selected_frame
))
11757 /* Select the frame, for the sake of frame-local
11759 select_frame_for_redisplay (frame
);
11761 /* Mark all the scroll bars to be removed; we'll redeem
11762 the ones we want when we redisplay their windows. */
11763 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11764 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11766 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11767 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11769 /* The X error handler may have deleted that frame. */
11770 if (!FRAME_LIVE_P (f
))
11773 /* Any scroll bars which redisplay_windows should have
11774 nuked should now go away. */
11775 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11776 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11778 /* If fonts changed, display again. */
11779 /* ??? rms: I suspect it is a mistake to jump all the way
11780 back to retry here. It should just retry this frame. */
11781 if (fonts_changed_p
)
11784 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11786 /* See if we have to hscroll. */
11787 if (!f
->already_hscrolled_p
)
11789 f
->already_hscrolled_p
= 1;
11790 if (hscroll_windows (f
->root_window
))
11794 /* Prevent various kinds of signals during display
11795 update. stdio is not robust about handling
11796 signals, which can cause an apparent I/O
11798 if (interrupt_input
)
11799 unrequest_sigio ();
11802 /* Update the display. */
11803 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11804 pause
|= update_frame (f
, 0, 0);
11810 if (!EQ (old_frame
, selected_frame
)
11811 && FRAME_LIVE_P (XFRAME (old_frame
)))
11812 /* We played a bit fast-and-loose above and allowed selected_frame
11813 and selected_window to be temporarily out-of-sync but let's make
11814 sure this stays contained. */
11815 select_frame_for_redisplay (old_frame
);
11816 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11820 /* Do the mark_window_display_accurate after all windows have
11821 been redisplayed because this call resets flags in buffers
11822 which are needed for proper redisplay. */
11823 FOR_EACH_FRAME (tail
, frame
)
11825 struct frame
*f
= XFRAME (frame
);
11828 mark_window_display_accurate (f
->root_window
, 1);
11829 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11830 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11835 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11837 Lisp_Object mini_window
;
11838 struct frame
*mini_frame
;
11840 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11841 /* Use list_of_error, not Qerror, so that
11842 we catch only errors and don't run the debugger. */
11843 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11845 redisplay_window_error
);
11847 /* Compare desired and current matrices, perform output. */
11850 /* If fonts changed, display again. */
11851 if (fonts_changed_p
)
11854 /* Prevent various kinds of signals during display update.
11855 stdio is not robust about handling signals,
11856 which can cause an apparent I/O error. */
11857 if (interrupt_input
)
11858 unrequest_sigio ();
11861 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11863 if (hscroll_windows (selected_window
))
11866 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11867 pause
= update_frame (sf
, 0, 0);
11870 /* We may have called echo_area_display at the top of this
11871 function. If the echo area is on another frame, that may
11872 have put text on a frame other than the selected one, so the
11873 above call to update_frame would not have caught it. Catch
11875 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11876 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11878 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11880 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11881 pause
|= update_frame (mini_frame
, 0, 0);
11882 if (!pause
&& hscroll_windows (mini_window
))
11887 /* If display was paused because of pending input, make sure we do a
11888 thorough update the next time. */
11891 /* Prevent the optimization at the beginning of
11892 redisplay_internal that tries a single-line update of the
11893 line containing the cursor in the selected window. */
11894 CHARPOS (this_line_start_pos
) = 0;
11896 /* Let the overlay arrow be updated the next time. */
11897 update_overlay_arrows (0);
11899 /* If we pause after scrolling, some rows in the current
11900 matrices of some windows are not valid. */
11901 if (!WINDOW_FULL_WIDTH_P (w
)
11902 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11903 update_mode_lines
= 1;
11907 if (!consider_all_windows_p
)
11909 /* This has already been done above if
11910 consider_all_windows_p is set. */
11911 mark_window_display_accurate_1 (w
, 1);
11913 /* Say overlay arrows are up to date. */
11914 update_overlay_arrows (1);
11916 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11917 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11920 update_mode_lines
= 0;
11921 windows_or_buffers_changed
= 0;
11922 cursor_type_changed
= 0;
11925 /* Start SIGIO interrupts coming again. Having them off during the
11926 code above makes it less likely one will discard output, but not
11927 impossible, since there might be stuff in the system buffer here.
11928 But it is much hairier to try to do anything about that. */
11929 if (interrupt_input
)
11933 /* If a frame has become visible which was not before, redisplay
11934 again, so that we display it. Expose events for such a frame
11935 (which it gets when becoming visible) don't call the parts of
11936 redisplay constructing glyphs, so simply exposing a frame won't
11937 display anything in this case. So, we have to display these
11938 frames here explicitly. */
11941 Lisp_Object tail
, frame
;
11944 FOR_EACH_FRAME (tail
, frame
)
11946 int this_is_visible
= 0;
11948 if (XFRAME (frame
)->visible
)
11949 this_is_visible
= 1;
11950 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11951 if (XFRAME (frame
)->visible
)
11952 this_is_visible
= 1;
11954 if (this_is_visible
)
11958 if (new_count
!= number_of_visible_frames
)
11959 windows_or_buffers_changed
++;
11962 /* Change frame size now if a change is pending. */
11963 do_pending_window_change (1);
11965 /* If we just did a pending size change, or have additional
11966 visible frames, redisplay again. */
11967 if (windows_or_buffers_changed
&& !pause
)
11970 /* Clear the face cache eventually. */
11971 if (consider_all_windows_p
)
11973 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11975 clear_face_cache (0);
11976 clear_face_cache_count
= 0;
11978 #ifdef HAVE_WINDOW_SYSTEM
11979 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11981 clear_image_caches (Qnil
);
11982 clear_image_cache_count
= 0;
11984 #endif /* HAVE_WINDOW_SYSTEM */
11988 unbind_to (count
, Qnil
);
11993 /* Redisplay, but leave alone any recent echo area message unless
11994 another message has been requested in its place.
11996 This is useful in situations where you need to redisplay but no
11997 user action has occurred, making it inappropriate for the message
11998 area to be cleared. See tracking_off and
11999 wait_reading_process_output for examples of these situations.
12001 FROM_WHERE is an integer saying from where this function was
12002 called. This is useful for debugging. */
12005 redisplay_preserve_echo_area (from_where
)
12008 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12010 if (!NILP (echo_area_buffer
[1]))
12012 /* We have a previously displayed message, but no current
12013 message. Redisplay the previous message. */
12014 display_last_displayed_message_p
= 1;
12015 redisplay_internal (1);
12016 display_last_displayed_message_p
= 0;
12019 redisplay_internal (1);
12021 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12022 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12023 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12027 /* Function registered with record_unwind_protect in
12028 redisplay_internal. Reset redisplaying_p to the value it had
12029 before redisplay_internal was called, and clear
12030 prevent_freeing_realized_faces_p. It also selects the previously
12031 selected frame, unless it has been deleted (by an X connection
12032 failure during redisplay, for example). */
12035 unwind_redisplay (val
)
12038 Lisp_Object old_redisplaying_p
, old_frame
;
12040 old_redisplaying_p
= XCAR (val
);
12041 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12042 old_frame
= XCDR (val
);
12043 if (! EQ (old_frame
, selected_frame
)
12044 && FRAME_LIVE_P (XFRAME (old_frame
)))
12045 select_frame_for_redisplay (old_frame
);
12050 /* Mark the display of window W as accurate or inaccurate. If
12051 ACCURATE_P is non-zero mark display of W as accurate. If
12052 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12053 redisplay_internal is called. */
12056 mark_window_display_accurate_1 (w
, accurate_p
)
12060 if (BUFFERP (w
->buffer
))
12062 struct buffer
*b
= XBUFFER (w
->buffer
);
12065 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12066 w
->last_overlay_modified
12067 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12069 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12073 b
->clip_changed
= 0;
12074 b
->prevent_redisplay_optimizations_p
= 0;
12076 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12077 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12078 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12079 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12081 w
->current_matrix
->buffer
= b
;
12082 w
->current_matrix
->begv
= BUF_BEGV (b
);
12083 w
->current_matrix
->zv
= BUF_ZV (b
);
12085 w
->last_cursor
= w
->cursor
;
12086 w
->last_cursor_off_p
= w
->cursor_off_p
;
12088 if (w
== XWINDOW (selected_window
))
12089 w
->last_point
= make_number (BUF_PT (b
));
12091 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12097 w
->window_end_valid
= w
->buffer
;
12098 w
->update_mode_line
= Qnil
;
12103 /* Mark the display of windows in the window tree rooted at WINDOW as
12104 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12105 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12106 be redisplayed the next time redisplay_internal is called. */
12109 mark_window_display_accurate (window
, accurate_p
)
12110 Lisp_Object window
;
12115 for (; !NILP (window
); window
= w
->next
)
12117 w
= XWINDOW (window
);
12118 mark_window_display_accurate_1 (w
, accurate_p
);
12120 if (!NILP (w
->vchild
))
12121 mark_window_display_accurate (w
->vchild
, accurate_p
);
12122 if (!NILP (w
->hchild
))
12123 mark_window_display_accurate (w
->hchild
, accurate_p
);
12128 update_overlay_arrows (1);
12132 /* Force a thorough redisplay the next time by setting
12133 last_arrow_position and last_arrow_string to t, which is
12134 unequal to any useful value of Voverlay_arrow_... */
12135 update_overlay_arrows (-1);
12140 /* Return value in display table DP (Lisp_Char_Table *) for character
12141 C. Since a display table doesn't have any parent, we don't have to
12142 follow parent. Do not call this function directly but use the
12143 macro DISP_CHAR_VECTOR. */
12146 disp_char_vector (dp
, c
)
12147 struct Lisp_Char_Table
*dp
;
12152 if (ASCII_CHAR_P (c
))
12155 if (SUB_CHAR_TABLE_P (val
))
12156 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12162 XSETCHAR_TABLE (table
, dp
);
12163 val
= char_table_ref (table
, c
);
12172 /***********************************************************************
12174 ***********************************************************************/
12176 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12179 redisplay_windows (window
)
12180 Lisp_Object window
;
12182 while (!NILP (window
))
12184 struct window
*w
= XWINDOW (window
);
12186 if (!NILP (w
->hchild
))
12187 redisplay_windows (w
->hchild
);
12188 else if (!NILP (w
->vchild
))
12189 redisplay_windows (w
->vchild
);
12190 else if (!NILP (w
->buffer
))
12192 displayed_buffer
= XBUFFER (w
->buffer
);
12193 /* Use list_of_error, not Qerror, so that
12194 we catch only errors and don't run the debugger. */
12195 internal_condition_case_1 (redisplay_window_0
, window
,
12197 redisplay_window_error
);
12205 redisplay_window_error ()
12207 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12212 redisplay_window_0 (window
)
12213 Lisp_Object window
;
12215 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12216 redisplay_window (window
, 0);
12221 redisplay_window_1 (window
)
12222 Lisp_Object window
;
12224 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12225 redisplay_window (window
, 1);
12230 /* Increment GLYPH until it reaches END or CONDITION fails while
12231 adding (GLYPH)->pixel_width to X. */
12233 #define SKIP_GLYPHS(glyph, end, x, condition) \
12236 (x) += (glyph)->pixel_width; \
12239 while ((glyph) < (end) && (condition))
12242 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12243 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12244 which positions recorded in ROW differ from current buffer
12247 Return 0 if cursor is not on this row, 1 otherwise. */
12250 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12252 struct glyph_row
*row
;
12253 struct glyph_matrix
*matrix
;
12254 int delta
, delta_bytes
, dy
, dvpos
;
12256 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12257 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12258 struct glyph
*cursor
= NULL
;
12259 /* The first glyph that starts a sequence of glyphs from a string
12260 that is a value of a display property. */
12261 struct glyph
*string_start
;
12262 /* The X coordinate of string_start. */
12263 int string_start_x
;
12264 /* The last known character position in row. */
12265 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12266 /* The last known character position before string_start. */
12267 int string_before_pos
;
12270 /* Last buffer position covered by an overlay. */
12271 int cursor_from_overlay_pos
= 0;
12272 int pt_old
= PT
- delta
;
12274 /* Skip over glyphs not having an object at the start of the row.
12275 These are special glyphs like truncation marks on terminal
12277 if (row
->displays_text_p
)
12279 && INTEGERP (glyph
->object
)
12280 && glyph
->charpos
< 0)
12282 x
+= glyph
->pixel_width
;
12286 string_start
= NULL
;
12288 && !INTEGERP (glyph
->object
)
12289 && (!BUFFERP (glyph
->object
)
12290 || (last_pos
= glyph
->charpos
) < pt_old
12291 || glyph
->avoid_cursor_p
))
12293 if (! STRINGP (glyph
->object
))
12295 string_start
= NULL
;
12296 x
+= glyph
->pixel_width
;
12298 /* If we are beyond the cursor position computed from the
12299 last overlay seen, that overlay is not in effect for
12300 current cursor position. Reset the cursor information
12301 computed from that overlay. */
12302 if (cursor_from_overlay_pos
12303 && last_pos
>= cursor_from_overlay_pos
)
12305 cursor_from_overlay_pos
= 0;
12311 if (string_start
== NULL
)
12313 string_before_pos
= last_pos
;
12314 string_start
= glyph
;
12315 string_start_x
= x
;
12317 /* Skip all glyphs from a string. */
12322 if ((cursor
== NULL
|| glyph
> cursor
)
12323 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12324 Qcursor
, (glyph
)->object
),
12326 && (pos
= string_buffer_position (w
, glyph
->object
,
12327 string_before_pos
),
12328 (pos
== 0 /* from overlay */
12329 || pos
== pt_old
)))
12331 /* Compute the first buffer position after the overlay.
12332 If the `cursor' property tells us how many positions
12333 are associated with the overlay, use that. Otherwise,
12334 estimate from the buffer positions of the glyphs
12335 before and after the overlay. */
12336 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12337 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12341 x
+= glyph
->pixel_width
;
12344 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12348 if (cursor
!= NULL
)
12353 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12355 /* Scan back over the ellipsis glyphs, decrementing positions. */
12356 while (glyph
> row
->glyphs
[TEXT_AREA
]
12357 && (glyph
- 1)->charpos
== last_pos
)
12358 glyph
--, x
-= glyph
->pixel_width
;
12359 /* That loop always goes one position too far, including the
12360 glyph before the ellipsis. So scan forward over that one. */
12361 x
+= glyph
->pixel_width
;
12364 else if (string_start
12365 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12367 /* We may have skipped over point because the previous glyphs
12368 are from string. As there's no easy way to know the
12369 character position of the current glyph, find the correct
12370 glyph on point by scanning from string_start again. */
12372 Lisp_Object string
;
12373 struct glyph
*stop
= glyph
;
12376 limit
= make_number (pt_old
+ 1);
12377 glyph
= string_start
;
12378 x
= string_start_x
;
12379 string
= glyph
->object
;
12380 pos
= string_buffer_position (w
, string
, string_before_pos
);
12381 /* If POS == 0, STRING is from overlay. We skip such glyphs
12382 because we always put the cursor after overlay strings. */
12383 while (pos
== 0 && glyph
< stop
)
12385 string
= glyph
->object
;
12386 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12388 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12391 while (glyph
< stop
)
12393 pos
= XINT (Fnext_single_char_property_change
12394 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12397 /* Skip glyphs from the same string. */
12398 string
= glyph
->object
;
12399 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12400 /* Skip glyphs from an overlay. */
12401 while (glyph
< stop
12402 && ! string_buffer_position (w
, glyph
->object
, pos
))
12404 string
= glyph
->object
;
12405 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12409 /* If we reached the end of the line, and END was from a string,
12410 the cursor is not on this line. */
12411 if (glyph
== end
&& row
->continued_p
)
12415 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12417 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12418 w
->cursor
.y
= row
->y
+ dy
;
12420 if (w
== XWINDOW (selected_window
))
12422 if (!row
->continued_p
12423 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12426 this_line_buffer
= XBUFFER (w
->buffer
);
12428 CHARPOS (this_line_start_pos
)
12429 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12430 BYTEPOS (this_line_start_pos
)
12431 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12433 CHARPOS (this_line_end_pos
)
12434 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12435 BYTEPOS (this_line_end_pos
)
12436 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12438 this_line_y
= w
->cursor
.y
;
12439 this_line_pixel_height
= row
->height
;
12440 this_line_vpos
= w
->cursor
.vpos
;
12441 this_line_start_x
= row
->x
;
12444 CHARPOS (this_line_start_pos
) = 0;
12451 /* Run window scroll functions, if any, for WINDOW with new window
12452 start STARTP. Sets the window start of WINDOW to that position.
12454 We assume that the window's buffer is really current. */
12456 static INLINE
struct text_pos
12457 run_window_scroll_functions (window
, startp
)
12458 Lisp_Object window
;
12459 struct text_pos startp
;
12461 struct window
*w
= XWINDOW (window
);
12462 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12464 if (current_buffer
!= XBUFFER (w
->buffer
))
12467 if (!NILP (Vwindow_scroll_functions
))
12469 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12470 make_number (CHARPOS (startp
)));
12471 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12472 /* In case the hook functions switch buffers. */
12473 if (current_buffer
!= XBUFFER (w
->buffer
))
12474 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12481 /* Make sure the line containing the cursor is fully visible.
12482 A value of 1 means there is nothing to be done.
12483 (Either the line is fully visible, or it cannot be made so,
12484 or we cannot tell.)
12486 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12487 is higher than window.
12489 A value of 0 means the caller should do scrolling
12490 as if point had gone off the screen. */
12493 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12496 int current_matrix_p
;
12498 struct glyph_matrix
*matrix
;
12499 struct glyph_row
*row
;
12502 if (!make_cursor_line_fully_visible_p
)
12505 /* It's not always possible to find the cursor, e.g, when a window
12506 is full of overlay strings. Don't do anything in that case. */
12507 if (w
->cursor
.vpos
< 0)
12510 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12511 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12513 /* If the cursor row is not partially visible, there's nothing to do. */
12514 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12517 /* If the row the cursor is in is taller than the window's height,
12518 it's not clear what to do, so do nothing. */
12519 window_height
= window_box_height (w
);
12520 if (row
->height
>= window_height
)
12522 if (!force_p
|| MINI_WINDOW_P (w
)
12523 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12530 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12531 non-zero means only WINDOW is redisplayed in redisplay_internal.
12532 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12533 in redisplay_window to bring a partially visible line into view in
12534 the case that only the cursor has moved.
12536 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12537 last screen line's vertical height extends past the end of the screen.
12541 1 if scrolling succeeded
12543 0 if scrolling didn't find point.
12545 -1 if new fonts have been loaded so that we must interrupt
12546 redisplay, adjust glyph matrices, and try again. */
12552 SCROLLING_NEED_LARGER_MATRICES
12556 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12557 scroll_step
, temp_scroll_step
, last_line_misfit
)
12558 Lisp_Object window
;
12559 int just_this_one_p
;
12560 EMACS_INT scroll_conservatively
, scroll_step
;
12561 int temp_scroll_step
;
12562 int last_line_misfit
;
12564 struct window
*w
= XWINDOW (window
);
12565 struct frame
*f
= XFRAME (w
->frame
);
12566 struct text_pos pos
, startp
;
12568 int this_scroll_margin
, scroll_max
, rc
, height
;
12569 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12570 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12571 Lisp_Object aggressive
;
12572 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12575 debug_method_add (w
, "try_scrolling");
12578 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12580 /* Compute scroll margin height in pixels. We scroll when point is
12581 within this distance from the top or bottom of the window. */
12582 if (scroll_margin
> 0)
12583 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
12584 * FRAME_LINE_HEIGHT (f
);
12586 this_scroll_margin
= 0;
12588 /* Force scroll_conservatively to have a reasonable value, to avoid
12589 overflow while computing how much to scroll. Note that the user
12590 can supply scroll-conservatively equal to `most-positive-fixnum',
12591 which can be larger than INT_MAX. */
12592 if (scroll_conservatively
> scroll_limit
)
12594 scroll_conservatively
= scroll_limit
;
12595 scroll_max
= INT_MAX
;
12597 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12598 /* Compute how much we should try to scroll maximally to bring
12599 point into view. */
12600 scroll_max
= (max (scroll_step
,
12601 max (scroll_conservatively
, temp_scroll_step
))
12602 * FRAME_LINE_HEIGHT (f
));
12603 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12604 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12605 /* We're trying to scroll because of aggressive scrolling but no
12606 scroll_step is set. Choose an arbitrary one. */
12607 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12613 /* Decide whether to scroll down. */
12614 if (PT
> CHARPOS (startp
))
12616 int scroll_margin_y
;
12618 /* Compute the pixel ypos of the scroll margin, then move it to
12619 either that ypos or PT, whichever comes first. */
12620 start_display (&it
, w
, startp
);
12621 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12622 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12623 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12624 (MOVE_TO_POS
| MOVE_TO_Y
));
12626 if (PT
> CHARPOS (it
.current
.pos
))
12628 int y0
= line_bottom_y (&it
);
12630 /* Compute the distance from the scroll margin to PT
12631 (including the height of the cursor line). Moving the
12632 iterator unconditionally to PT can be slow if PT is far
12633 away, so stop 10 lines past the window bottom (is there a
12634 way to do the right thing quickly?). */
12635 move_it_to (&it
, PT
, -1,
12636 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
12637 -1, MOVE_TO_POS
| MOVE_TO_Y
);
12638 dy
= line_bottom_y (&it
) - y0
;
12640 if (dy
> scroll_max
)
12641 return SCROLLING_FAILED
;
12649 /* Point is in or below the bottom scroll margin, so move the
12650 window start down. If scrolling conservatively, move it just
12651 enough down to make point visible. If scroll_step is set,
12652 move it down by scroll_step. */
12653 if (scroll_conservatively
)
12655 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12656 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12657 else if (scroll_step
|| temp_scroll_step
)
12658 amount_to_scroll
= scroll_max
;
12661 aggressive
= current_buffer
->scroll_up_aggressively
;
12662 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12663 if (NUMBERP (aggressive
))
12665 double float_amount
= XFLOATINT (aggressive
) * height
;
12666 amount_to_scroll
= float_amount
;
12667 if (amount_to_scroll
== 0 && float_amount
> 0)
12668 amount_to_scroll
= 1;
12672 if (amount_to_scroll
<= 0)
12673 return SCROLLING_FAILED
;
12675 start_display (&it
, w
, startp
);
12676 move_it_vertically (&it
, amount_to_scroll
);
12678 /* If STARTP is unchanged, move it down another screen line. */
12679 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12680 move_it_by_lines (&it
, 1, 1);
12681 startp
= it
.current
.pos
;
12685 struct text_pos scroll_margin_pos
= startp
;
12687 /* See if point is inside the scroll margin at the top of the
12689 if (this_scroll_margin
)
12691 start_display (&it
, w
, startp
);
12692 move_it_vertically (&it
, this_scroll_margin
);
12693 scroll_margin_pos
= it
.current
.pos
;
12696 if (PT
< CHARPOS (scroll_margin_pos
))
12698 /* Point is in the scroll margin at the top of the window or
12699 above what is displayed in the window. */
12702 /* Compute the vertical distance from PT to the scroll
12703 margin position. Give up if distance is greater than
12705 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12706 start_display (&it
, w
, pos
);
12708 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12709 it
.last_visible_y
, -1,
12710 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12711 dy
= it
.current_y
- y0
;
12712 if (dy
> scroll_max
)
12713 return SCROLLING_FAILED
;
12715 /* Compute new window start. */
12716 start_display (&it
, w
, startp
);
12718 if (scroll_conservatively
)
12720 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12721 else if (scroll_step
|| temp_scroll_step
)
12722 amount_to_scroll
= scroll_max
;
12725 aggressive
= current_buffer
->scroll_down_aggressively
;
12726 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12727 if (NUMBERP (aggressive
))
12729 double float_amount
= XFLOATINT (aggressive
) * height
;
12730 amount_to_scroll
= float_amount
;
12731 if (amount_to_scroll
== 0 && float_amount
> 0)
12732 amount_to_scroll
= 1;
12736 if (amount_to_scroll
<= 0)
12737 return SCROLLING_FAILED
;
12739 move_it_vertically_backward (&it
, amount_to_scroll
);
12740 startp
= it
.current
.pos
;
12744 /* Run window scroll functions. */
12745 startp
= run_window_scroll_functions (window
, startp
);
12747 /* Display the window. Give up if new fonts are loaded, or if point
12749 if (!try_window (window
, startp
, 0))
12750 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12751 else if (w
->cursor
.vpos
< 0)
12753 clear_glyph_matrix (w
->desired_matrix
);
12754 rc
= SCROLLING_FAILED
;
12758 /* Maybe forget recorded base line for line number display. */
12759 if (!just_this_one_p
12760 || current_buffer
->clip_changed
12761 || BEG_UNCHANGED
< CHARPOS (startp
))
12762 w
->base_line_number
= Qnil
;
12764 /* If cursor ends up on a partially visible line,
12765 treat that as being off the bottom of the screen. */
12766 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
12767 /* It's possible that the cursor is on the first line of the
12768 buffer, which is partially obscured due to a vscroll
12769 (Bug#7537). In that case, avoid looping forever . */
12770 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
12772 clear_glyph_matrix (w
->desired_matrix
);
12773 ++extra_scroll_margin_lines
;
12776 rc
= SCROLLING_SUCCESS
;
12783 /* Compute a suitable window start for window W if display of W starts
12784 on a continuation line. Value is non-zero if a new window start
12787 The new window start will be computed, based on W's width, starting
12788 from the start of the continued line. It is the start of the
12789 screen line with the minimum distance from the old start W->start. */
12792 compute_window_start_on_continuation_line (w
)
12795 struct text_pos pos
, start_pos
;
12796 int window_start_changed_p
= 0;
12798 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12800 /* If window start is on a continuation line... Window start may be
12801 < BEGV in case there's invisible text at the start of the
12802 buffer (M-x rmail, for example). */
12803 if (CHARPOS (start_pos
) > BEGV
12804 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12807 struct glyph_row
*row
;
12809 /* Handle the case that the window start is out of range. */
12810 if (CHARPOS (start_pos
) < BEGV
)
12811 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12812 else if (CHARPOS (start_pos
) > ZV
)
12813 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12815 /* Find the start of the continued line. This should be fast
12816 because scan_buffer is fast (newline cache). */
12817 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12818 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12819 row
, DEFAULT_FACE_ID
);
12820 reseat_at_previous_visible_line_start (&it
);
12822 /* If the line start is "too far" away from the window start,
12823 say it takes too much time to compute a new window start. */
12824 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12825 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12827 int min_distance
, distance
;
12829 /* Move forward by display lines to find the new window
12830 start. If window width was enlarged, the new start can
12831 be expected to be > the old start. If window width was
12832 decreased, the new window start will be < the old start.
12833 So, we're looking for the display line start with the
12834 minimum distance from the old window start. */
12835 pos
= it
.current
.pos
;
12836 min_distance
= INFINITY
;
12837 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12838 distance
< min_distance
)
12840 min_distance
= distance
;
12841 pos
= it
.current
.pos
;
12842 move_it_by_lines (&it
, 1, 0);
12845 /* Set the window start there. */
12846 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12847 window_start_changed_p
= 1;
12851 return window_start_changed_p
;
12855 /* Try cursor movement in case text has not changed in window WINDOW,
12856 with window start STARTP. Value is
12858 CURSOR_MOVEMENT_SUCCESS if successful
12860 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12862 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12863 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12864 we want to scroll as if scroll-step were set to 1. See the code.
12866 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12867 which case we have to abort this redisplay, and adjust matrices
12872 CURSOR_MOVEMENT_SUCCESS
,
12873 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12874 CURSOR_MOVEMENT_MUST_SCROLL
,
12875 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12879 try_cursor_movement (window
, startp
, scroll_step
)
12880 Lisp_Object window
;
12881 struct text_pos startp
;
12884 struct window
*w
= XWINDOW (window
);
12885 struct frame
*f
= XFRAME (w
->frame
);
12886 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12889 if (inhibit_try_cursor_movement
)
12893 /* Handle case where text has not changed, only point, and it has
12894 not moved off the frame. */
12895 if (/* Point may be in this window. */
12896 PT
>= CHARPOS (startp
)
12897 /* Selective display hasn't changed. */
12898 && !current_buffer
->clip_changed
12899 /* Function force-mode-line-update is used to force a thorough
12900 redisplay. It sets either windows_or_buffers_changed or
12901 update_mode_lines. So don't take a shortcut here for these
12903 && !update_mode_lines
12904 && !windows_or_buffers_changed
12905 && !cursor_type_changed
12906 /* Can't use this case if highlighting a region. When a
12907 region exists, cursor movement has to do more than just
12909 && !(!NILP (Vtransient_mark_mode
)
12910 && !NILP (current_buffer
->mark_active
))
12911 && NILP (w
->region_showing
)
12912 && NILP (Vshow_trailing_whitespace
)
12913 /* Right after splitting windows, last_point may be nil. */
12914 && INTEGERP (w
->last_point
)
12915 /* This code is not used for mini-buffer for the sake of the case
12916 of redisplaying to replace an echo area message; since in
12917 that case the mini-buffer contents per se are usually
12918 unchanged. This code is of no real use in the mini-buffer
12919 since the handling of this_line_start_pos, etc., in redisplay
12920 handles the same cases. */
12921 && !EQ (window
, minibuf_window
)
12922 /* When splitting windows or for new windows, it happens that
12923 redisplay is called with a nil window_end_vpos or one being
12924 larger than the window. This should really be fixed in
12925 window.c. I don't have this on my list, now, so we do
12926 approximately the same as the old redisplay code. --gerd. */
12927 && INTEGERP (w
->window_end_vpos
)
12928 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12929 && (FRAME_WINDOW_P (f
)
12930 || !overlay_arrow_in_current_buffer_p ()))
12932 int this_scroll_margin
, top_scroll_margin
;
12933 struct glyph_row
*row
= NULL
;
12936 debug_method_add (w
, "cursor movement");
12939 /* Scroll if point within this distance from the top or bottom
12940 of the window. This is a pixel value. */
12941 if (scroll_margin
> 0)
12943 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12944 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12947 this_scroll_margin
= 0;
12949 top_scroll_margin
= this_scroll_margin
;
12950 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12951 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12953 /* Start with the row the cursor was displayed during the last
12954 not paused redisplay. Give up if that row is not valid. */
12955 if (w
->last_cursor
.vpos
< 0
12956 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12957 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12960 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12961 if (row
->mode_line_p
)
12963 if (!row
->enabled_p
)
12964 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12967 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12970 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12972 if (PT
> XFASTINT (w
->last_point
))
12974 /* Point has moved forward. */
12975 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12976 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12978 xassert (row
->enabled_p
);
12982 /* The end position of a row equals the start position
12983 of the next row. If PT is there, we would rather
12984 display it in the next line. */
12985 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12986 && MATRIX_ROW_END_CHARPOS (row
) == PT
12987 && !cursor_row_p (w
, row
))
12990 /* If within the scroll margin, scroll. Note that
12991 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12992 the next line would be drawn, and that
12993 this_scroll_margin can be zero. */
12994 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12995 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12996 /* Line is completely visible last line in window
12997 and PT is to be set in the next line. */
12998 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12999 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13000 && !row
->ends_at_zv_p
13001 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13004 else if (PT
< XFASTINT (w
->last_point
))
13006 /* Cursor has to be moved backward. Note that PT >=
13007 CHARPOS (startp) because of the outer if-statement. */
13008 while (!row
->mode_line_p
13009 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13010 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13011 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13012 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13013 row
> w
->current_matrix
->rows
13014 && (row
-1)->ends_in_newline_from_string_p
))))
13015 && (row
->y
> top_scroll_margin
13016 || CHARPOS (startp
) == BEGV
))
13018 xassert (row
->enabled_p
);
13022 /* Consider the following case: Window starts at BEGV,
13023 there is invisible, intangible text at BEGV, so that
13024 display starts at some point START > BEGV. It can
13025 happen that we are called with PT somewhere between
13026 BEGV and START. Try to handle that case. */
13027 if (row
< w
->current_matrix
->rows
13028 || row
->mode_line_p
)
13030 row
= w
->current_matrix
->rows
;
13031 if (row
->mode_line_p
)
13035 /* Due to newlines in overlay strings, we may have to
13036 skip forward over overlay strings. */
13037 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13038 && MATRIX_ROW_END_CHARPOS (row
) == PT
13039 && !cursor_row_p (w
, row
))
13042 /* If within the scroll margin, scroll. */
13043 if (row
->y
< top_scroll_margin
13044 && CHARPOS (startp
) != BEGV
)
13049 /* Cursor did not move. So don't scroll even if cursor line
13050 is partially visible, as it was so before. */
13051 rc
= CURSOR_MOVEMENT_SUCCESS
;
13054 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13055 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13057 /* if PT is not in the glyph row, give up. */
13058 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13060 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13061 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13062 && make_cursor_line_fully_visible_p
)
13064 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13065 && !row
->ends_at_zv_p
13066 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13067 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13068 else if (row
->height
> window_box_height (w
))
13070 /* If we end up in a partially visible line, let's
13071 make it fully visible, except when it's taller
13072 than the window, in which case we can't do much
13075 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13079 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13080 if (!cursor_row_fully_visible_p (w
, 0, 1))
13081 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13083 rc
= CURSOR_MOVEMENT_SUCCESS
;
13087 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13092 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13094 rc
= CURSOR_MOVEMENT_SUCCESS
;
13099 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13100 && MATRIX_ROW_START_CHARPOS (row
) == PT
13101 && cursor_row_p (w
, row
));
13110 set_vertical_scroll_bar (w
)
13113 int start
, end
, whole
;
13115 /* Calculate the start and end positions for the current window.
13116 At some point, it would be nice to choose between scrollbars
13117 which reflect the whole buffer size, with special markers
13118 indicating narrowing, and scrollbars which reflect only the
13121 Note that mini-buffers sometimes aren't displaying any text. */
13122 if (!MINI_WINDOW_P (w
)
13123 || (w
== XWINDOW (minibuf_window
)
13124 && NILP (echo_area_buffer
[0])))
13126 struct buffer
*buf
= XBUFFER (w
->buffer
);
13127 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13128 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13129 /* I don't think this is guaranteed to be right. For the
13130 moment, we'll pretend it is. */
13131 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13135 if (whole
< (end
- start
))
13136 whole
= end
- start
;
13139 start
= end
= whole
= 0;
13141 /* Indicate what this scroll bar ought to be displaying now. */
13142 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13143 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13144 (w
, end
- start
, whole
, start
);
13148 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13149 selected_window is redisplayed.
13151 We can return without actually redisplaying the window if
13152 fonts_changed_p is nonzero. In that case, redisplay_internal will
13156 redisplay_window (window
, just_this_one_p
)
13157 Lisp_Object window
;
13158 int just_this_one_p
;
13160 struct window
*w
= XWINDOW (window
);
13161 struct frame
*f
= XFRAME (w
->frame
);
13162 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13163 struct buffer
*old
= current_buffer
;
13164 struct text_pos lpoint
, opoint
, startp
;
13165 int update_mode_line
;
13168 /* Record it now because it's overwritten. */
13169 int current_matrix_up_to_date_p
= 0;
13170 int used_current_matrix_p
= 0;
13171 /* This is less strict than current_matrix_up_to_date_p.
13172 It indictes that the buffer contents and narrowing are unchanged. */
13173 int buffer_unchanged_p
= 0;
13174 int temp_scroll_step
= 0;
13175 int count
= SPECPDL_INDEX ();
13177 int centering_position
= -1;
13178 int last_line_misfit
= 0;
13179 int beg_unchanged
, end_unchanged
;
13181 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13184 /* W must be a leaf window here. */
13185 xassert (!NILP (w
->buffer
));
13187 *w
->desired_matrix
->method
= 0;
13191 reconsider_clip_changes (w
, buffer
);
13193 /* Has the mode line to be updated? */
13194 update_mode_line
= (!NILP (w
->update_mode_line
)
13195 || update_mode_lines
13196 || buffer
->clip_changed
13197 || buffer
->prevent_redisplay_optimizations_p
);
13199 if (MINI_WINDOW_P (w
))
13201 if (w
== XWINDOW (echo_area_window
)
13202 && !NILP (echo_area_buffer
[0]))
13204 if (update_mode_line
)
13205 /* We may have to update a tty frame's menu bar or a
13206 tool-bar. Example `M-x C-h C-h C-g'. */
13207 goto finish_menu_bars
;
13209 /* We've already displayed the echo area glyphs in this window. */
13210 goto finish_scroll_bars
;
13212 else if ((w
!= XWINDOW (minibuf_window
)
13213 || minibuf_level
== 0)
13214 /* When buffer is nonempty, redisplay window normally. */
13215 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13216 /* Quail displays non-mini buffers in minibuffer window.
13217 In that case, redisplay the window normally. */
13218 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13220 /* W is a mini-buffer window, but it's not active, so clear
13222 int yb
= window_text_bottom_y (w
);
13223 struct glyph_row
*row
;
13226 for (y
= 0, row
= w
->desired_matrix
->rows
;
13228 y
+= row
->height
, ++row
)
13229 blank_row (w
, row
, y
);
13230 goto finish_scroll_bars
;
13233 clear_glyph_matrix (w
->desired_matrix
);
13236 /* Otherwise set up data on this window; select its buffer and point
13238 /* Really select the buffer, for the sake of buffer-local
13240 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13242 current_matrix_up_to_date_p
13243 = (!NILP (w
->window_end_valid
)
13244 && !current_buffer
->clip_changed
13245 && !current_buffer
->prevent_redisplay_optimizations_p
13246 && XFASTINT (w
->last_modified
) >= MODIFF
13247 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13249 /* Run the window-bottom-change-functions
13250 if it is possible that the text on the screen has changed
13251 (either due to modification of the text, or any other reason). */
13252 if (!current_matrix_up_to_date_p
13253 && !NILP (Vwindow_text_change_functions
))
13255 safe_run_hooks (Qwindow_text_change_functions
);
13259 beg_unchanged
= BEG_UNCHANGED
;
13260 end_unchanged
= END_UNCHANGED
;
13262 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13264 specbind (Qinhibit_point_motion_hooks
, Qt
);
13267 = (!NILP (w
->window_end_valid
)
13268 && !current_buffer
->clip_changed
13269 && XFASTINT (w
->last_modified
) >= MODIFF
13270 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13272 /* When windows_or_buffers_changed is non-zero, we can't rely on
13273 the window end being valid, so set it to nil there. */
13274 if (windows_or_buffers_changed
)
13276 /* If window starts on a continuation line, maybe adjust the
13277 window start in case the window's width changed. */
13278 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13279 compute_window_start_on_continuation_line (w
);
13281 w
->window_end_valid
= Qnil
;
13284 /* Some sanity checks. */
13285 CHECK_WINDOW_END (w
);
13286 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13288 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13291 /* If %c is in mode line, update it if needed. */
13292 if (!NILP (w
->column_number_displayed
)
13293 /* This alternative quickly identifies a common case
13294 where no change is needed. */
13295 && !(PT
== XFASTINT (w
->last_point
)
13296 && XFASTINT (w
->last_modified
) >= MODIFF
13297 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13298 && (XFASTINT (w
->column_number_displayed
)
13299 != (int) current_column ())) /* iftc */
13300 update_mode_line
= 1;
13302 /* Count number of windows showing the selected buffer. An indirect
13303 buffer counts as its base buffer. */
13304 if (!just_this_one_p
)
13306 struct buffer
*current_base
, *window_base
;
13307 current_base
= current_buffer
;
13308 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13309 if (current_base
->base_buffer
)
13310 current_base
= current_base
->base_buffer
;
13311 if (window_base
->base_buffer
)
13312 window_base
= window_base
->base_buffer
;
13313 if (current_base
== window_base
)
13317 /* Point refers normally to the selected window. For any other
13318 window, set up appropriate value. */
13319 if (!EQ (window
, selected_window
))
13321 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13322 int new_pt_byte
= marker_byte_position (w
->pointm
);
13326 new_pt_byte
= BEGV_BYTE
;
13327 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13329 else if (new_pt
> (ZV
- 1))
13332 new_pt_byte
= ZV_BYTE
;
13333 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13336 /* We don't use SET_PT so that the point-motion hooks don't run. */
13337 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13340 /* If any of the character widths specified in the display table
13341 have changed, invalidate the width run cache. It's true that
13342 this may be a bit late to catch such changes, but the rest of
13343 redisplay goes (non-fatally) haywire when the display table is
13344 changed, so why should we worry about doing any better? */
13345 if (current_buffer
->width_run_cache
)
13347 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13349 if (! disptab_matches_widthtab (disptab
,
13350 XVECTOR (current_buffer
->width_table
)))
13352 invalidate_region_cache (current_buffer
,
13353 current_buffer
->width_run_cache
,
13355 recompute_width_table (current_buffer
, disptab
);
13359 /* If window-start is screwed up, choose a new one. */
13360 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13363 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13365 /* If someone specified a new starting point but did not insist,
13366 check whether it can be used. */
13367 if (!NILP (w
->optional_new_start
)
13368 && CHARPOS (startp
) >= BEGV
13369 && CHARPOS (startp
) <= ZV
)
13371 w
->optional_new_start
= Qnil
;
13372 start_display (&it
, w
, startp
);
13373 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13374 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13375 if (IT_CHARPOS (it
) == PT
)
13376 w
->force_start
= Qt
;
13377 /* IT may overshoot PT if text at PT is invisible. */
13378 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13379 w
->force_start
= Qt
;
13384 /* Handle case where place to start displaying has been specified,
13385 unless the specified location is outside the accessible range. */
13386 if (!NILP (w
->force_start
)
13387 || w
->frozen_window_start_p
)
13389 /* We set this later on if we have to adjust point. */
13392 w
->force_start
= Qnil
;
13394 w
->window_end_valid
= Qnil
;
13396 /* Forget any recorded base line for line number display. */
13397 if (!buffer_unchanged_p
)
13398 w
->base_line_number
= Qnil
;
13400 /* Redisplay the mode line. Select the buffer properly for that.
13401 Also, run the hook window-scroll-functions
13402 because we have scrolled. */
13403 /* Note, we do this after clearing force_start because
13404 if there's an error, it is better to forget about force_start
13405 than to get into an infinite loop calling the hook functions
13406 and having them get more errors. */
13407 if (!update_mode_line
13408 || ! NILP (Vwindow_scroll_functions
))
13410 update_mode_line
= 1;
13411 w
->update_mode_line
= Qt
;
13412 startp
= run_window_scroll_functions (window
, startp
);
13415 w
->last_modified
= make_number (0);
13416 w
->last_overlay_modified
= make_number (0);
13417 if (CHARPOS (startp
) < BEGV
)
13418 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13419 else if (CHARPOS (startp
) > ZV
)
13420 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13422 /* Redisplay, then check if cursor has been set during the
13423 redisplay. Give up if new fonts were loaded. */
13424 /* We used to issue a CHECK_MARGINS argument to try_window here,
13425 but this causes scrolling to fail when point begins inside
13426 the scroll margin (bug#148) -- cyd */
13427 if (!try_window (window
, startp
, 0))
13429 w
->force_start
= Qt
;
13430 clear_glyph_matrix (w
->desired_matrix
);
13431 goto need_larger_matrices
;
13434 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13436 /* If point does not appear, try to move point so it does
13437 appear. The desired matrix has been built above, so we
13438 can use it here. */
13439 new_vpos
= window_box_height (w
) / 2;
13442 if (!cursor_row_fully_visible_p (w
, 0, 0))
13444 /* Point does appear, but on a line partly visible at end of window.
13445 Move it back to a fully-visible line. */
13446 new_vpos
= window_box_height (w
);
13449 /* If we need to move point for either of the above reasons,
13450 now actually do it. */
13453 struct glyph_row
*row
;
13455 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13456 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13459 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13460 MATRIX_ROW_START_BYTEPOS (row
));
13462 if (w
!= XWINDOW (selected_window
))
13463 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13464 else if (current_buffer
== old
)
13465 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13467 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13469 /* If we are highlighting the region, then we just changed
13470 the region, so redisplay to show it. */
13471 if (!NILP (Vtransient_mark_mode
)
13472 && !NILP (current_buffer
->mark_active
))
13474 clear_glyph_matrix (w
->desired_matrix
);
13475 if (!try_window (window
, startp
, 0))
13476 goto need_larger_matrices
;
13481 debug_method_add (w
, "forced window start");
13486 /* Handle case where text has not changed, only point, and it has
13487 not moved off the frame, and we are not retrying after hscroll.
13488 (current_matrix_up_to_date_p is nonzero when retrying.) */
13489 if (current_matrix_up_to_date_p
13490 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13491 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13495 case CURSOR_MOVEMENT_SUCCESS
:
13496 used_current_matrix_p
= 1;
13499 case CURSOR_MOVEMENT_MUST_SCROLL
:
13500 goto try_to_scroll
;
13506 /* If current starting point was originally the beginning of a line
13507 but no longer is, find a new starting point. */
13508 else if (!NILP (w
->start_at_line_beg
)
13509 && !(CHARPOS (startp
) <= BEGV
13510 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13513 debug_method_add (w
, "recenter 1");
13518 /* Try scrolling with try_window_id. Value is > 0 if update has
13519 been done, it is -1 if we know that the same window start will
13520 not work. It is 0 if unsuccessful for some other reason. */
13521 else if ((tem
= try_window_id (w
)) != 0)
13524 debug_method_add (w
, "try_window_id %d", tem
);
13527 if (fonts_changed_p
)
13528 goto need_larger_matrices
;
13532 /* Otherwise try_window_id has returned -1 which means that we
13533 don't want the alternative below this comment to execute. */
13535 else if (CHARPOS (startp
) >= BEGV
13536 && CHARPOS (startp
) <= ZV
13537 && PT
>= CHARPOS (startp
)
13538 && (CHARPOS (startp
) < ZV
13539 /* Avoid starting at end of buffer. */
13540 || CHARPOS (startp
) == BEGV
13541 || (XFASTINT (w
->last_modified
) >= MODIFF
13542 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13545 /* If first window line is a continuation line, and window start
13546 is inside the modified region, but the first change is before
13547 current window start, we must select a new window start.
13549 However, if this is the result of a down-mouse event (e.g. by
13550 extending the mouse-drag-overlay), we don't want to select a
13551 new window start, since that would change the position under
13552 the mouse, resulting in an unwanted mouse-movement rather
13553 than a simple mouse-click. */
13554 if (NILP (w
->start_at_line_beg
)
13555 && NILP (do_mouse_tracking
)
13556 && CHARPOS (startp
) > BEGV
13557 && CHARPOS (startp
) > BEG
+ beg_unchanged
13558 && CHARPOS (startp
) <= Z
- end_unchanged
13559 /* Even if w->start_at_line_beg is nil, a new window may
13560 start at a line_beg, since that's how set_buffer_window
13561 sets it. So, we need to check the return value of
13562 compute_window_start_on_continuation_line. (See also
13564 && XMARKER (w
->start
)->buffer
== current_buffer
13565 && compute_window_start_on_continuation_line (w
))
13567 w
->force_start
= Qt
;
13568 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13573 debug_method_add (w
, "same window start");
13576 /* Try to redisplay starting at same place as before.
13577 If point has not moved off frame, accept the results. */
13578 if (!current_matrix_up_to_date_p
13579 /* Don't use try_window_reusing_current_matrix in this case
13580 because a window scroll function can have changed the
13582 || !NILP (Vwindow_scroll_functions
)
13583 || MINI_WINDOW_P (w
)
13584 || !(used_current_matrix_p
13585 = try_window_reusing_current_matrix (w
)))
13587 IF_DEBUG (debug_method_add (w
, "1"));
13588 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
13589 /* -1 means we need to scroll.
13590 0 means we need new matrices, but fonts_changed_p
13591 is set in that case, so we will detect it below. */
13592 goto try_to_scroll
;
13595 if (fonts_changed_p
)
13596 goto need_larger_matrices
;
13598 if (w
->cursor
.vpos
>= 0)
13600 if (!just_this_one_p
13601 || current_buffer
->clip_changed
13602 || BEG_UNCHANGED
< CHARPOS (startp
))
13603 /* Forget any recorded base line for line number display. */
13604 w
->base_line_number
= Qnil
;
13606 if (!cursor_row_fully_visible_p (w
, 1, 0))
13608 clear_glyph_matrix (w
->desired_matrix
);
13609 last_line_misfit
= 1;
13611 /* Drop through and scroll. */
13616 clear_glyph_matrix (w
->desired_matrix
);
13621 w
->last_modified
= make_number (0);
13622 w
->last_overlay_modified
= make_number (0);
13624 /* Redisplay the mode line. Select the buffer properly for that. */
13625 if (!update_mode_line
)
13627 update_mode_line
= 1;
13628 w
->update_mode_line
= Qt
;
13631 /* Try to scroll by specified few lines. */
13632 if ((scroll_conservatively
13634 || temp_scroll_step
13635 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13636 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13637 && !current_buffer
->clip_changed
13638 && CHARPOS (startp
) >= BEGV
13639 && CHARPOS (startp
) <= ZV
)
13641 /* The function returns -1 if new fonts were loaded, 1 if
13642 successful, 0 if not successful. */
13643 int rc
= try_scrolling (window
, just_this_one_p
,
13644 scroll_conservatively
,
13646 temp_scroll_step
, last_line_misfit
);
13649 case SCROLLING_SUCCESS
:
13652 case SCROLLING_NEED_LARGER_MATRICES
:
13653 goto need_larger_matrices
;
13655 case SCROLLING_FAILED
:
13663 /* Finally, just choose place to start which centers point */
13666 if (centering_position
< 0)
13667 centering_position
= window_box_height (w
) / 2;
13670 debug_method_add (w
, "recenter");
13673 /* w->vscroll = 0; */
13675 /* Forget any previously recorded base line for line number display. */
13676 if (!buffer_unchanged_p
)
13677 w
->base_line_number
= Qnil
;
13679 /* Move backward half the height of the window. */
13680 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13681 it
.current_y
= it
.last_visible_y
;
13682 move_it_vertically_backward (&it
, centering_position
);
13683 xassert (IT_CHARPOS (it
) >= BEGV
);
13685 /* The function move_it_vertically_backward may move over more
13686 than the specified y-distance. If it->w is small, e.g. a
13687 mini-buffer window, we may end up in front of the window's
13688 display area. Start displaying at the start of the line
13689 containing PT in this case. */
13690 if (it
.current_y
<= 0)
13692 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13693 move_it_vertically_backward (&it
, 0);
13697 it
.current_x
= it
.hpos
= 0;
13699 /* Set startp here explicitly in case that helps avoid an infinite loop
13700 in case the window-scroll-functions functions get errors. */
13701 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13703 /* Run scroll hooks. */
13704 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13706 /* Redisplay the window. */
13707 if (!current_matrix_up_to_date_p
13708 || windows_or_buffers_changed
13709 || cursor_type_changed
13710 /* Don't use try_window_reusing_current_matrix in this case
13711 because it can have changed the buffer. */
13712 || !NILP (Vwindow_scroll_functions
)
13713 || !just_this_one_p
13714 || MINI_WINDOW_P (w
)
13715 || !(used_current_matrix_p
13716 = try_window_reusing_current_matrix (w
)))
13717 try_window (window
, startp
, 0);
13719 /* If new fonts have been loaded (due to fontsets), give up. We
13720 have to start a new redisplay since we need to re-adjust glyph
13722 if (fonts_changed_p
)
13723 goto need_larger_matrices
;
13725 /* If cursor did not appear assume that the middle of the window is
13726 in the first line of the window. Do it again with the next line.
13727 (Imagine a window of height 100, displaying two lines of height
13728 60. Moving back 50 from it->last_visible_y will end in the first
13730 if (w
->cursor
.vpos
< 0)
13732 if (!NILP (w
->window_end_valid
)
13733 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13735 clear_glyph_matrix (w
->desired_matrix
);
13736 move_it_by_lines (&it
, 1, 0);
13737 try_window (window
, it
.current
.pos
, 0);
13739 else if (PT
< IT_CHARPOS (it
))
13741 clear_glyph_matrix (w
->desired_matrix
);
13742 move_it_by_lines (&it
, -1, 0);
13743 try_window (window
, it
.current
.pos
, 0);
13747 /* Not much we can do about it. */
13751 /* Consider the following case: Window starts at BEGV, there is
13752 invisible, intangible text at BEGV, so that display starts at
13753 some point START > BEGV. It can happen that we are called with
13754 PT somewhere between BEGV and START. Try to handle that case. */
13755 if (w
->cursor
.vpos
< 0)
13757 struct glyph_row
*row
= w
->current_matrix
->rows
;
13758 if (row
->mode_line_p
)
13760 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13763 if (!cursor_row_fully_visible_p (w
, 0, 0))
13765 /* If vscroll is enabled, disable it and try again. */
13769 clear_glyph_matrix (w
->desired_matrix
);
13773 /* If centering point failed to make the whole line visible,
13774 put point at the top instead. That has to make the whole line
13775 visible, if it can be done. */
13776 if (centering_position
== 0)
13779 clear_glyph_matrix (w
->desired_matrix
);
13780 centering_position
= 0;
13786 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13787 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13788 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13791 /* Display the mode line, if we must. */
13792 if ((update_mode_line
13793 /* If window not full width, must redo its mode line
13794 if (a) the window to its side is being redone and
13795 (b) we do a frame-based redisplay. This is a consequence
13796 of how inverted lines are drawn in frame-based redisplay. */
13797 || (!just_this_one_p
13798 && !FRAME_WINDOW_P (f
)
13799 && !WINDOW_FULL_WIDTH_P (w
))
13800 /* Line number to display. */
13801 || INTEGERP (w
->base_line_pos
)
13802 /* Column number is displayed and different from the one displayed. */
13803 || (!NILP (w
->column_number_displayed
)
13804 && (XFASTINT (w
->column_number_displayed
)
13805 != (int) current_column ()))) /* iftc */
13806 /* This means that the window has a mode line. */
13807 && (WINDOW_WANTS_MODELINE_P (w
)
13808 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13810 display_mode_lines (w
);
13812 /* If mode line height has changed, arrange for a thorough
13813 immediate redisplay using the correct mode line height. */
13814 if (WINDOW_WANTS_MODELINE_P (w
)
13815 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13817 fonts_changed_p
= 1;
13818 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13819 = DESIRED_MODE_LINE_HEIGHT (w
);
13822 /* If header line height has changed, arrange for a thorough
13823 immediate redisplay using the correct header line height. */
13824 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13825 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13827 fonts_changed_p
= 1;
13828 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13829 = DESIRED_HEADER_LINE_HEIGHT (w
);
13832 if (fonts_changed_p
)
13833 goto need_larger_matrices
;
13836 if (!line_number_displayed
13837 && !BUFFERP (w
->base_line_pos
))
13839 w
->base_line_pos
= Qnil
;
13840 w
->base_line_number
= Qnil
;
13845 /* When we reach a frame's selected window, redo the frame's menu bar. */
13846 if (update_mode_line
13847 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13849 int redisplay_menu_p
= 0;
13850 int redisplay_tool_bar_p
= 0;
13852 if (FRAME_WINDOW_P (f
))
13854 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13855 || defined (HAVE_NS) || defined (USE_GTK)
13856 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13858 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13862 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13864 if (redisplay_menu_p
)
13865 display_menu_bar (w
);
13867 #ifdef HAVE_WINDOW_SYSTEM
13868 if (FRAME_WINDOW_P (f
))
13870 #if defined (USE_GTK) || defined (HAVE_NS)
13871 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13873 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13874 && (FRAME_TOOL_BAR_LINES (f
) > 0
13875 || !NILP (Vauto_resize_tool_bars
));
13878 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13880 extern int ignore_mouse_drag_p
;
13881 ignore_mouse_drag_p
= 1;
13887 #ifdef HAVE_WINDOW_SYSTEM
13888 if (FRAME_WINDOW_P (f
)
13889 && update_window_fringes (w
, (just_this_one_p
13890 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13891 || w
->pseudo_window_p
)))
13895 if (draw_window_fringes (w
, 1))
13896 x_draw_vertical_border (w
);
13900 #endif /* HAVE_WINDOW_SYSTEM */
13902 /* We go to this label, with fonts_changed_p nonzero,
13903 if it is necessary to try again using larger glyph matrices.
13904 We have to redeem the scroll bar even in this case,
13905 because the loop in redisplay_internal expects that. */
13906 need_larger_matrices
:
13908 finish_scroll_bars
:
13910 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13912 /* Set the thumb's position and size. */
13913 set_vertical_scroll_bar (w
);
13915 /* Note that we actually used the scroll bar attached to this
13916 window, so it shouldn't be deleted at the end of redisplay. */
13917 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13918 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13921 /* Restore current_buffer and value of point in it. The window
13922 update may have changed the buffer, so first make sure `opoint'
13923 is still valid (Bug#6177). */
13924 if (CHARPOS (opoint
) < BEGV
)
13925 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13926 else if (CHARPOS (opoint
) > ZV
)
13927 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
13929 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13931 set_buffer_internal_1 (old
);
13932 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13933 shorter. This can be caused by log truncation in *Messages*. */
13934 if (CHARPOS (lpoint
) <= ZV
)
13935 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13937 unbind_to (count
, Qnil
);
13941 /* Build the complete desired matrix of WINDOW with a window start
13942 buffer position POS.
13944 Value is 1 if successful. It is zero if fonts were loaded during
13945 redisplay which makes re-adjusting glyph matrices necessary, and -1
13946 if point would appear in the scroll margins.
13947 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
13948 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
13952 try_window (window
, pos
, flags
)
13953 Lisp_Object window
;
13954 struct text_pos pos
;
13957 struct window
*w
= XWINDOW (window
);
13959 struct glyph_row
*last_text_row
= NULL
;
13960 struct frame
*f
= XFRAME (w
->frame
);
13962 /* Make POS the new window start. */
13963 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13965 /* Mark cursor position as unknown. No overlay arrow seen. */
13966 w
->cursor
.vpos
= -1;
13967 overlay_arrow_seen
= 0;
13969 /* Initialize iterator and info to start at POS. */
13970 start_display (&it
, w
, pos
);
13972 /* Display all lines of W. */
13973 while (it
.current_y
< it
.last_visible_y
)
13975 if (display_line (&it
))
13976 last_text_row
= it
.glyph_row
- 1;
13977 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
13981 /* Don't let the cursor end in the scroll margins. */
13982 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
13983 && !MINI_WINDOW_P (w
))
13985 int this_scroll_margin
;
13987 if (scroll_margin
> 0)
13989 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13990 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13993 this_scroll_margin
= 0;
13995 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13996 && w
->cursor
.y
< this_scroll_margin
13997 && CHARPOS (pos
) > BEGV
13998 && IT_CHARPOS (it
) < ZV
)
13999 /* rms: considering make_cursor_line_fully_visible_p here
14000 seems to give wrong results. We don't want to recenter
14001 when the last line is partly visible, we want to allow
14002 that case to be handled in the usual way. */
14003 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14005 w
->cursor
.vpos
= -1;
14006 clear_glyph_matrix (w
->desired_matrix
);
14011 /* If bottom moved off end of frame, change mode line percentage. */
14012 if (XFASTINT (w
->window_end_pos
) <= 0
14013 && Z
!= IT_CHARPOS (it
))
14014 w
->update_mode_line
= Qt
;
14016 /* Set window_end_pos to the offset of the last character displayed
14017 on the window from the end of current_buffer. Set
14018 window_end_vpos to its row number. */
14021 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14022 w
->window_end_bytepos
14023 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14025 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14027 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14028 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14029 ->displays_text_p
);
14033 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14034 w
->window_end_pos
= make_number (Z
- ZV
);
14035 w
->window_end_vpos
= make_number (0);
14038 /* But that is not valid info until redisplay finishes. */
14039 w
->window_end_valid
= Qnil
;
14045 /************************************************************************
14046 Window redisplay reusing current matrix when buffer has not changed
14047 ************************************************************************/
14049 /* Try redisplay of window W showing an unchanged buffer with a
14050 different window start than the last time it was displayed by
14051 reusing its current matrix. Value is non-zero if successful.
14052 W->start is the new window start. */
14055 try_window_reusing_current_matrix (w
)
14058 struct frame
*f
= XFRAME (w
->frame
);
14059 struct glyph_row
*row
, *bottom_row
;
14062 struct text_pos start
, new_start
;
14063 int nrows_scrolled
, i
;
14064 struct glyph_row
*last_text_row
;
14065 struct glyph_row
*last_reused_text_row
;
14066 struct glyph_row
*start_row
;
14067 int start_vpos
, min_y
, max_y
;
14070 if (inhibit_try_window_reusing
)
14074 if (/* This function doesn't handle terminal frames. */
14075 !FRAME_WINDOW_P (f
)
14076 /* Don't try to reuse the display if windows have been split
14078 || windows_or_buffers_changed
14079 || cursor_type_changed
)
14082 /* Can't do this if region may have changed. */
14083 if ((!NILP (Vtransient_mark_mode
)
14084 && !NILP (current_buffer
->mark_active
))
14085 || !NILP (w
->region_showing
)
14086 || !NILP (Vshow_trailing_whitespace
))
14089 /* If top-line visibility has changed, give up. */
14090 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14091 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14094 /* Give up if old or new display is scrolled vertically. We could
14095 make this function handle this, but right now it doesn't. */
14096 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14097 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14100 /* The variable new_start now holds the new window start. The old
14101 start `start' can be determined from the current matrix. */
14102 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14103 start
= start_row
->start
.pos
;
14104 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14106 /* Clear the desired matrix for the display below. */
14107 clear_glyph_matrix (w
->desired_matrix
);
14109 if (CHARPOS (new_start
) <= CHARPOS (start
))
14113 /* Don't use this method if the display starts with an ellipsis
14114 displayed for invisible text. It's not easy to handle that case
14115 below, and it's certainly not worth the effort since this is
14116 not a frequent case. */
14117 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14120 IF_DEBUG (debug_method_add (w
, "twu1"));
14122 /* Display up to a row that can be reused. The variable
14123 last_text_row is set to the last row displayed that displays
14124 text. Note that it.vpos == 0 if or if not there is a
14125 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14126 start_display (&it
, w
, new_start
);
14127 first_row_y
= it
.current_y
;
14128 w
->cursor
.vpos
= -1;
14129 last_text_row
= last_reused_text_row
= NULL
;
14131 while (it
.current_y
< it
.last_visible_y
14132 && !fonts_changed_p
)
14134 /* If we have reached into the characters in the START row,
14135 that means the line boundaries have changed. So we
14136 can't start copying with the row START. Maybe it will
14137 work to start copying with the following row. */
14138 while (IT_CHARPOS (it
) > CHARPOS (start
))
14140 /* Advance to the next row as the "start". */
14142 start
= start_row
->start
.pos
;
14143 /* If there are no more rows to try, or just one, give up. */
14144 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14145 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14146 || CHARPOS (start
) == ZV
)
14148 clear_glyph_matrix (w
->desired_matrix
);
14152 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14154 /* If we have reached alignment,
14155 we can copy the rest of the rows. */
14156 if (IT_CHARPOS (it
) == CHARPOS (start
))
14159 if (display_line (&it
))
14160 last_text_row
= it
.glyph_row
- 1;
14163 /* A value of current_y < last_visible_y means that we stopped
14164 at the previous window start, which in turn means that we
14165 have at least one reusable row. */
14166 if (it
.current_y
< it
.last_visible_y
)
14168 /* IT.vpos always starts from 0; it counts text lines. */
14169 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14171 /* Find PT if not already found in the lines displayed. */
14172 if (w
->cursor
.vpos
< 0)
14174 int dy
= it
.current_y
- start_row
->y
;
14176 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14177 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14179 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14180 dy
, nrows_scrolled
);
14183 clear_glyph_matrix (w
->desired_matrix
);
14188 /* Scroll the display. Do it before the current matrix is
14189 changed. The problem here is that update has not yet
14190 run, i.e. part of the current matrix is not up to date.
14191 scroll_run_hook will clear the cursor, and use the
14192 current matrix to get the height of the row the cursor is
14194 run
.current_y
= start_row
->y
;
14195 run
.desired_y
= it
.current_y
;
14196 run
.height
= it
.last_visible_y
- it
.current_y
;
14198 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14201 FRAME_RIF (f
)->update_window_begin_hook (w
);
14202 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14203 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14204 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14208 /* Shift current matrix down by nrows_scrolled lines. */
14209 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14210 rotate_matrix (w
->current_matrix
,
14212 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14215 /* Disable lines that must be updated. */
14216 for (i
= 0; i
< nrows_scrolled
; ++i
)
14217 (start_row
+ i
)->enabled_p
= 0;
14219 /* Re-compute Y positions. */
14220 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14221 max_y
= it
.last_visible_y
;
14222 for (row
= start_row
+ nrows_scrolled
;
14226 row
->y
= it
.current_y
;
14227 row
->visible_height
= row
->height
;
14229 if (row
->y
< min_y
)
14230 row
->visible_height
-= min_y
- row
->y
;
14231 if (row
->y
+ row
->height
> max_y
)
14232 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14233 row
->redraw_fringe_bitmaps_p
= 1;
14235 it
.current_y
+= row
->height
;
14237 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14238 last_reused_text_row
= row
;
14239 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14243 /* Disable lines in the current matrix which are now
14244 below the window. */
14245 for (++row
; row
< bottom_row
; ++row
)
14246 row
->enabled_p
= row
->mode_line_p
= 0;
14249 /* Update window_end_pos etc.; last_reused_text_row is the last
14250 reused row from the current matrix containing text, if any.
14251 The value of last_text_row is the last displayed line
14252 containing text. */
14253 if (last_reused_text_row
)
14255 w
->window_end_bytepos
14256 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14258 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14260 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14261 w
->current_matrix
));
14263 else if (last_text_row
)
14265 w
->window_end_bytepos
14266 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14268 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14270 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14274 /* This window must be completely empty. */
14275 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14276 w
->window_end_pos
= make_number (Z
- ZV
);
14277 w
->window_end_vpos
= make_number (0);
14279 w
->window_end_valid
= Qnil
;
14281 /* Update hint: don't try scrolling again in update_window. */
14282 w
->desired_matrix
->no_scrolling_p
= 1;
14285 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14289 else if (CHARPOS (new_start
) > CHARPOS (start
))
14291 struct glyph_row
*pt_row
, *row
;
14292 struct glyph_row
*first_reusable_row
;
14293 struct glyph_row
*first_row_to_display
;
14295 int yb
= window_text_bottom_y (w
);
14297 /* Find the row starting at new_start, if there is one. Don't
14298 reuse a partially visible line at the end. */
14299 first_reusable_row
= start_row
;
14300 while (first_reusable_row
->enabled_p
14301 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14302 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14303 < CHARPOS (new_start
)))
14304 ++first_reusable_row
;
14306 /* Give up if there is no row to reuse. */
14307 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14308 || !first_reusable_row
->enabled_p
14309 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14310 != CHARPOS (new_start
)))
14313 /* We can reuse fully visible rows beginning with
14314 first_reusable_row to the end of the window. Set
14315 first_row_to_display to the first row that cannot be reused.
14316 Set pt_row to the row containing point, if there is any. */
14318 for (first_row_to_display
= first_reusable_row
;
14319 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14320 ++first_row_to_display
)
14322 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14323 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14324 pt_row
= first_row_to_display
;
14327 /* Start displaying at the start of first_row_to_display. */
14328 xassert (first_row_to_display
->y
< yb
);
14329 init_to_row_start (&it
, w
, first_row_to_display
);
14331 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14333 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14335 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14336 + WINDOW_HEADER_LINE_HEIGHT (w
));
14338 /* Display lines beginning with first_row_to_display in the
14339 desired matrix. Set last_text_row to the last row displayed
14340 that displays text. */
14341 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14342 if (pt_row
== NULL
)
14343 w
->cursor
.vpos
= -1;
14344 last_text_row
= NULL
;
14345 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14346 if (display_line (&it
))
14347 last_text_row
= it
.glyph_row
- 1;
14349 /* If point is in a reused row, adjust y and vpos of the cursor
14353 w
->cursor
.vpos
-= nrows_scrolled
;
14354 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14357 /* Give up if point isn't in a row displayed or reused. (This
14358 also handles the case where w->cursor.vpos < nrows_scrolled
14359 after the calls to display_line, which can happen with scroll
14360 margins. See bug#1295.) */
14361 if (w
->cursor
.vpos
< 0)
14363 clear_glyph_matrix (w
->desired_matrix
);
14367 /* Scroll the display. */
14368 run
.current_y
= first_reusable_row
->y
;
14369 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14370 run
.height
= it
.last_visible_y
- run
.current_y
;
14371 dy
= run
.current_y
- run
.desired_y
;
14376 FRAME_RIF (f
)->update_window_begin_hook (w
);
14377 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14378 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14379 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14383 /* Adjust Y positions of reused rows. */
14384 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14385 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14386 max_y
= it
.last_visible_y
;
14387 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14390 row
->visible_height
= row
->height
;
14391 if (row
->y
< min_y
)
14392 row
->visible_height
-= min_y
- row
->y
;
14393 if (row
->y
+ row
->height
> max_y
)
14394 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14395 row
->redraw_fringe_bitmaps_p
= 1;
14398 /* Scroll the current matrix. */
14399 xassert (nrows_scrolled
> 0);
14400 rotate_matrix (w
->current_matrix
,
14402 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14405 /* Disable rows not reused. */
14406 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14407 row
->enabled_p
= 0;
14409 /* Point may have moved to a different line, so we cannot assume that
14410 the previous cursor position is valid; locate the correct row. */
14413 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14414 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14418 w
->cursor
.y
= row
->y
;
14420 if (row
< bottom_row
)
14422 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14423 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14426 && (!BUFFERP (glyph
->object
)
14427 || glyph
->charpos
< PT
);
14431 w
->cursor
.x
+= glyph
->pixel_width
;
14436 /* Adjust window end. A null value of last_text_row means that
14437 the window end is in reused rows which in turn means that
14438 only its vpos can have changed. */
14441 w
->window_end_bytepos
14442 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14444 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14446 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14451 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14454 w
->window_end_valid
= Qnil
;
14455 w
->desired_matrix
->no_scrolling_p
= 1;
14458 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14468 /************************************************************************
14469 Window redisplay reusing current matrix when buffer has changed
14470 ************************************************************************/
14472 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14473 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14475 static struct glyph_row
*
14476 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14477 struct glyph_row
*));
14480 /* Return the last row in MATRIX displaying text. If row START is
14481 non-null, start searching with that row. IT gives the dimensions
14482 of the display. Value is null if matrix is empty; otherwise it is
14483 a pointer to the row found. */
14485 static struct glyph_row
*
14486 find_last_row_displaying_text (matrix
, it
, start
)
14487 struct glyph_matrix
*matrix
;
14489 struct glyph_row
*start
;
14491 struct glyph_row
*row
, *row_found
;
14493 /* Set row_found to the last row in IT->w's current matrix
14494 displaying text. The loop looks funny but think of partially
14497 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14498 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14500 xassert (row
->enabled_p
);
14502 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14511 /* Return the last row in the current matrix of W that is not affected
14512 by changes at the start of current_buffer that occurred since W's
14513 current matrix was built. Value is null if no such row exists.
14515 BEG_UNCHANGED us the number of characters unchanged at the start of
14516 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14517 first changed character in current_buffer. Characters at positions <
14518 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14519 when the current matrix was built. */
14521 static struct glyph_row
*
14522 find_last_unchanged_at_beg_row (w
)
14525 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14526 struct glyph_row
*row
;
14527 struct glyph_row
*row_found
= NULL
;
14528 int yb
= window_text_bottom_y (w
);
14530 /* Find the last row displaying unchanged text. */
14531 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14532 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14533 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14536 if (/* If row ends before first_changed_pos, it is unchanged,
14537 except in some case. */
14538 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14539 /* When row ends in ZV and we write at ZV it is not
14541 && !row
->ends_at_zv_p
14542 /* When first_changed_pos is the end of a continued line,
14543 row is not unchanged because it may be no longer
14545 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14546 && (row
->continued_p
14547 || row
->exact_window_width_line_p
)))
14550 /* Stop if last visible row. */
14551 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14559 /* Find the first glyph row in the current matrix of W that is not
14560 affected by changes at the end of current_buffer since the
14561 time W's current matrix was built.
14563 Return in *DELTA the number of chars by which buffer positions in
14564 unchanged text at the end of current_buffer must be adjusted.
14566 Return in *DELTA_BYTES the corresponding number of bytes.
14568 Value is null if no such row exists, i.e. all rows are affected by
14571 static struct glyph_row
*
14572 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14574 int *delta
, *delta_bytes
;
14576 struct glyph_row
*row
;
14577 struct glyph_row
*row_found
= NULL
;
14579 *delta
= *delta_bytes
= 0;
14581 /* Display must not have been paused, otherwise the current matrix
14582 is not up to date. */
14583 eassert (!NILP (w
->window_end_valid
));
14585 /* A value of window_end_pos >= END_UNCHANGED means that the window
14586 end is in the range of changed text. If so, there is no
14587 unchanged row at the end of W's current matrix. */
14588 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14591 /* Set row to the last row in W's current matrix displaying text. */
14592 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14594 /* If matrix is entirely empty, no unchanged row exists. */
14595 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14597 /* The value of row is the last glyph row in the matrix having a
14598 meaningful buffer position in it. The end position of row
14599 corresponds to window_end_pos. This allows us to translate
14600 buffer positions in the current matrix to current buffer
14601 positions for characters not in changed text. */
14602 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14603 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14604 int last_unchanged_pos
, last_unchanged_pos_old
;
14605 struct glyph_row
*first_text_row
14606 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14608 *delta
= Z
- Z_old
;
14609 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14611 /* Set last_unchanged_pos to the buffer position of the last
14612 character in the buffer that has not been changed. Z is the
14613 index + 1 of the last character in current_buffer, i.e. by
14614 subtracting END_UNCHANGED we get the index of the last
14615 unchanged character, and we have to add BEG to get its buffer
14617 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14618 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14620 /* Search backward from ROW for a row displaying a line that
14621 starts at a minimum position >= last_unchanged_pos_old. */
14622 for (; row
> first_text_row
; --row
)
14624 /* This used to abort, but it can happen.
14625 It is ok to just stop the search instead here. KFS. */
14626 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14629 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14634 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14640 /* Make sure that glyph rows in the current matrix of window W
14641 reference the same glyph memory as corresponding rows in the
14642 frame's frame matrix. This function is called after scrolling W's
14643 current matrix on a terminal frame in try_window_id and
14644 try_window_reusing_current_matrix. */
14647 sync_frame_with_window_matrix_rows (w
)
14650 struct frame
*f
= XFRAME (w
->frame
);
14651 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14653 /* Preconditions: W must be a leaf window and full-width. Its frame
14654 must have a frame matrix. */
14655 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14656 xassert (WINDOW_FULL_WIDTH_P (w
));
14657 xassert (!FRAME_WINDOW_P (f
));
14659 /* If W is a full-width window, glyph pointers in W's current matrix
14660 have, by definition, to be the same as glyph pointers in the
14661 corresponding frame matrix. Note that frame matrices have no
14662 marginal areas (see build_frame_matrix). */
14663 window_row
= w
->current_matrix
->rows
;
14664 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14665 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14666 while (window_row
< window_row_end
)
14668 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14669 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14671 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14672 frame_row
->glyphs
[TEXT_AREA
] = start
;
14673 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14674 frame_row
->glyphs
[LAST_AREA
] = end
;
14676 /* Disable frame rows whose corresponding window rows have
14677 been disabled in try_window_id. */
14678 if (!window_row
->enabled_p
)
14679 frame_row
->enabled_p
= 0;
14681 ++window_row
, ++frame_row
;
14686 /* Find the glyph row in window W containing CHARPOS. Consider all
14687 rows between START and END (not inclusive). END null means search
14688 all rows to the end of the display area of W. Value is the row
14689 containing CHARPOS or null. */
14692 row_containing_pos (w
, charpos
, start
, end
, dy
)
14695 struct glyph_row
*start
, *end
;
14698 struct glyph_row
*row
= start
;
14701 /* If we happen to start on a header-line, skip that. */
14702 if (row
->mode_line_p
)
14705 if ((end
&& row
>= end
) || !row
->enabled_p
)
14708 last_y
= window_text_bottom_y (w
) - dy
;
14712 /* Give up if we have gone too far. */
14713 if (end
&& row
>= end
)
14715 /* This formerly returned if they were equal.
14716 I think that both quantities are of a "last plus one" type;
14717 if so, when they are equal, the row is within the screen. -- rms. */
14718 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14721 /* If it is in this row, return this row. */
14722 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14723 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14724 /* The end position of a row equals the start
14725 position of the next row. If CHARPOS is there, we
14726 would rather display it in the next line, except
14727 when this line ends in ZV. */
14728 && !row
->ends_at_zv_p
14729 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14730 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14737 /* Try to redisplay window W by reusing its existing display. W's
14738 current matrix must be up to date when this function is called,
14739 i.e. window_end_valid must not be nil.
14743 1 if display has been updated
14744 0 if otherwise unsuccessful
14745 -1 if redisplay with same window start is known not to succeed
14747 The following steps are performed:
14749 1. Find the last row in the current matrix of W that is not
14750 affected by changes at the start of current_buffer. If no such row
14753 2. Find the first row in W's current matrix that is not affected by
14754 changes at the end of current_buffer. Maybe there is no such row.
14756 3. Display lines beginning with the row + 1 found in step 1 to the
14757 row found in step 2 or, if step 2 didn't find a row, to the end of
14760 4. If cursor is not known to appear on the window, give up.
14762 5. If display stopped at the row found in step 2, scroll the
14763 display and current matrix as needed.
14765 6. Maybe display some lines at the end of W, if we must. This can
14766 happen under various circumstances, like a partially visible line
14767 becoming fully visible, or because newly displayed lines are displayed
14768 in smaller font sizes.
14770 7. Update W's window end information. */
14776 struct frame
*f
= XFRAME (w
->frame
);
14777 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14778 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14779 struct glyph_row
*last_unchanged_at_beg_row
;
14780 struct glyph_row
*first_unchanged_at_end_row
;
14781 struct glyph_row
*row
;
14782 struct glyph_row
*bottom_row
;
14785 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14786 struct text_pos start_pos
;
14788 int first_unchanged_at_end_vpos
= 0;
14789 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14790 struct text_pos start
;
14791 int first_changed_charpos
, last_changed_charpos
;
14794 if (inhibit_try_window_id
)
14798 /* This is handy for debugging. */
14800 #define GIVE_UP(X) \
14802 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14806 #define GIVE_UP(X) return 0
14809 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14811 /* Don't use this for mini-windows because these can show
14812 messages and mini-buffers, and we don't handle that here. */
14813 if (MINI_WINDOW_P (w
))
14816 /* This flag is used to prevent redisplay optimizations. */
14817 if (windows_or_buffers_changed
|| cursor_type_changed
)
14820 /* Verify that narrowing has not changed.
14821 Also verify that we were not told to prevent redisplay optimizations.
14822 It would be nice to further
14823 reduce the number of cases where this prevents try_window_id. */
14824 if (current_buffer
->clip_changed
14825 || current_buffer
->prevent_redisplay_optimizations_p
)
14828 /* Window must either use window-based redisplay or be full width. */
14829 if (!FRAME_WINDOW_P (f
)
14830 && (!FRAME_LINE_INS_DEL_OK (f
)
14831 || !WINDOW_FULL_WIDTH_P (w
)))
14834 /* Give up if point is known NOT to appear in W. */
14835 if (PT
< CHARPOS (start
))
14838 /* Another way to prevent redisplay optimizations. */
14839 if (XFASTINT (w
->last_modified
) == 0)
14842 /* Verify that window is not hscrolled. */
14843 if (XFASTINT (w
->hscroll
) != 0)
14846 /* Verify that display wasn't paused. */
14847 if (NILP (w
->window_end_valid
))
14850 /* Can't use this if highlighting a region because a cursor movement
14851 will do more than just set the cursor. */
14852 if (!NILP (Vtransient_mark_mode
)
14853 && !NILP (current_buffer
->mark_active
))
14856 /* Likewise if highlighting trailing whitespace. */
14857 if (!NILP (Vshow_trailing_whitespace
))
14860 /* Likewise if showing a region. */
14861 if (!NILP (w
->region_showing
))
14864 /* Can't use this if overlay arrow position and/or string have
14866 if (overlay_arrows_changed_p ())
14869 /* When word-wrap is on, adding a space to the first word of a
14870 wrapped line can change the wrap position, altering the line
14871 above it. It might be worthwhile to handle this more
14872 intelligently, but for now just redisplay from scratch. */
14873 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14876 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14877 only if buffer has really changed. The reason is that the gap is
14878 initially at Z for freshly visited files. The code below would
14879 set end_unchanged to 0 in that case. */
14880 if (MODIFF
> SAVE_MODIFF
14881 /* This seems to happen sometimes after saving a buffer. */
14882 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14884 if (GPT
- BEG
< BEG_UNCHANGED
)
14885 BEG_UNCHANGED
= GPT
- BEG
;
14886 if (Z
- GPT
< END_UNCHANGED
)
14887 END_UNCHANGED
= Z
- GPT
;
14890 /* The position of the first and last character that has been changed. */
14891 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14892 last_changed_charpos
= Z
- END_UNCHANGED
;
14894 /* If window starts after a line end, and the last change is in
14895 front of that newline, then changes don't affect the display.
14896 This case happens with stealth-fontification. Note that although
14897 the display is unchanged, glyph positions in the matrix have to
14898 be adjusted, of course. */
14899 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14900 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14901 && ((last_changed_charpos
< CHARPOS (start
)
14902 && CHARPOS (start
) == BEGV
)
14903 || (last_changed_charpos
< CHARPOS (start
) - 1
14904 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14906 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14907 struct glyph_row
*r0
;
14909 /* Compute how many chars/bytes have been added to or removed
14910 from the buffer. */
14911 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14912 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14914 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14916 /* Give up if PT is not in the window. Note that it already has
14917 been checked at the start of try_window_id that PT is not in
14918 front of the window start. */
14919 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14922 /* If window start is unchanged, we can reuse the whole matrix
14923 as is, after adjusting glyph positions. No need to compute
14924 the window end again, since its offset from Z hasn't changed. */
14925 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14926 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14927 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14928 /* PT must not be in a partially visible line. */
14929 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14930 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14932 /* Adjust positions in the glyph matrix. */
14933 if (delta
|| delta_bytes
)
14935 struct glyph_row
*r1
14936 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14937 increment_matrix_positions (w
->current_matrix
,
14938 MATRIX_ROW_VPOS (r0
, current_matrix
),
14939 MATRIX_ROW_VPOS (r1
, current_matrix
),
14940 delta
, delta_bytes
);
14943 /* Set the cursor. */
14944 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14946 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14953 /* Handle the case that changes are all below what is displayed in
14954 the window, and that PT is in the window. This shortcut cannot
14955 be taken if ZV is visible in the window, and text has been added
14956 there that is visible in the window. */
14957 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14958 /* ZV is not visible in the window, or there are no
14959 changes at ZV, actually. */
14960 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14961 || first_changed_charpos
== last_changed_charpos
))
14963 struct glyph_row
*r0
;
14965 /* Give up if PT is not in the window. Note that it already has
14966 been checked at the start of try_window_id that PT is not in
14967 front of the window start. */
14968 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14971 /* If window start is unchanged, we can reuse the whole matrix
14972 as is, without changing glyph positions since no text has
14973 been added/removed in front of the window end. */
14974 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14975 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14976 /* PT must not be in a partially visible line. */
14977 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14978 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14980 /* We have to compute the window end anew since text
14981 can have been added/removed after it. */
14983 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14984 w
->window_end_bytepos
14985 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14987 /* Set the cursor. */
14988 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14990 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14997 /* Give up if window start is in the changed area.
14999 The condition used to read
15001 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15003 but why that was tested escapes me at the moment. */
15004 if (CHARPOS (start
) >= first_changed_charpos
15005 && CHARPOS (start
) <= last_changed_charpos
)
15008 /* Check that window start agrees with the start of the first glyph
15009 row in its current matrix. Check this after we know the window
15010 start is not in changed text, otherwise positions would not be
15012 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15013 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15016 /* Give up if the window ends in strings. Overlay strings
15017 at the end are difficult to handle, so don't try. */
15018 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15019 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15022 /* Compute the position at which we have to start displaying new
15023 lines. Some of the lines at the top of the window might be
15024 reusable because they are not displaying changed text. Find the
15025 last row in W's current matrix not affected by changes at the
15026 start of current_buffer. Value is null if changes start in the
15027 first line of window. */
15028 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15029 if (last_unchanged_at_beg_row
)
15031 /* Avoid starting to display in the moddle of a character, a TAB
15032 for instance. This is easier than to set up the iterator
15033 exactly, and it's not a frequent case, so the additional
15034 effort wouldn't really pay off. */
15035 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15036 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15037 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15038 --last_unchanged_at_beg_row
;
15040 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15043 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15045 start_pos
= it
.current
.pos
;
15047 /* Start displaying new lines in the desired matrix at the same
15048 vpos we would use in the current matrix, i.e. below
15049 last_unchanged_at_beg_row. */
15050 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15052 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15053 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15055 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15059 /* There are no reusable lines at the start of the window.
15060 Start displaying in the first text line. */
15061 start_display (&it
, w
, start
);
15062 it
.vpos
= it
.first_vpos
;
15063 start_pos
= it
.current
.pos
;
15066 /* Find the first row that is not affected by changes at the end of
15067 the buffer. Value will be null if there is no unchanged row, in
15068 which case we must redisplay to the end of the window. delta
15069 will be set to the value by which buffer positions beginning with
15070 first_unchanged_at_end_row have to be adjusted due to text
15072 first_unchanged_at_end_row
15073 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15074 IF_DEBUG (debug_delta
= delta
);
15075 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15077 /* Set stop_pos to the buffer position up to which we will have to
15078 display new lines. If first_unchanged_at_end_row != NULL, this
15079 is the buffer position of the start of the line displayed in that
15080 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15081 that we don't stop at a buffer position. */
15083 if (first_unchanged_at_end_row
)
15085 xassert (last_unchanged_at_beg_row
== NULL
15086 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15088 /* If this is a continuation line, move forward to the next one
15089 that isn't. Changes in lines above affect this line.
15090 Caution: this may move first_unchanged_at_end_row to a row
15091 not displaying text. */
15092 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15093 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15094 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15095 < it
.last_visible_y
))
15096 ++first_unchanged_at_end_row
;
15098 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15099 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15100 >= it
.last_visible_y
))
15101 first_unchanged_at_end_row
= NULL
;
15104 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15106 first_unchanged_at_end_vpos
15107 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15108 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15111 else if (last_unchanged_at_beg_row
== NULL
)
15117 /* Either there is no unchanged row at the end, or the one we have
15118 now displays text. This is a necessary condition for the window
15119 end pos calculation at the end of this function. */
15120 xassert (first_unchanged_at_end_row
== NULL
15121 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15123 debug_last_unchanged_at_beg_vpos
15124 = (last_unchanged_at_beg_row
15125 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15127 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15129 #endif /* GLYPH_DEBUG != 0 */
15132 /* Display new lines. Set last_text_row to the last new line
15133 displayed which has text on it, i.e. might end up as being the
15134 line where the window_end_vpos is. */
15135 w
->cursor
.vpos
= -1;
15136 last_text_row
= NULL
;
15137 overlay_arrow_seen
= 0;
15138 while (it
.current_y
< it
.last_visible_y
15139 && !fonts_changed_p
15140 && (first_unchanged_at_end_row
== NULL
15141 || IT_CHARPOS (it
) < stop_pos
))
15143 if (display_line (&it
))
15144 last_text_row
= it
.glyph_row
- 1;
15147 if (fonts_changed_p
)
15151 /* Compute differences in buffer positions, y-positions etc. for
15152 lines reused at the bottom of the window. Compute what we can
15154 if (first_unchanged_at_end_row
15155 /* No lines reused because we displayed everything up to the
15156 bottom of the window. */
15157 && it
.current_y
< it
.last_visible_y
)
15160 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15162 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15163 run
.current_y
= first_unchanged_at_end_row
->y
;
15164 run
.desired_y
= run
.current_y
+ dy
;
15165 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15169 delta
= delta_bytes
= dvpos
= dy
15170 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15171 first_unchanged_at_end_row
= NULL
;
15173 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15176 /* Find the cursor if not already found. We have to decide whether
15177 PT will appear on this window (it sometimes doesn't, but this is
15178 not a very frequent case.) This decision has to be made before
15179 the current matrix is altered. A value of cursor.vpos < 0 means
15180 that PT is either in one of the lines beginning at
15181 first_unchanged_at_end_row or below the window. Don't care for
15182 lines that might be displayed later at the window end; as
15183 mentioned, this is not a frequent case. */
15184 if (w
->cursor
.vpos
< 0)
15186 /* Cursor in unchanged rows at the top? */
15187 if (PT
< CHARPOS (start_pos
)
15188 && last_unchanged_at_beg_row
)
15190 row
= row_containing_pos (w
, PT
,
15191 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15192 last_unchanged_at_beg_row
+ 1, 0);
15194 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15197 /* Start from first_unchanged_at_end_row looking for PT. */
15198 else if (first_unchanged_at_end_row
)
15200 row
= row_containing_pos (w
, PT
- delta
,
15201 first_unchanged_at_end_row
, NULL
, 0);
15203 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15204 delta_bytes
, dy
, dvpos
);
15207 /* Give up if cursor was not found. */
15208 if (w
->cursor
.vpos
< 0)
15210 clear_glyph_matrix (w
->desired_matrix
);
15215 /* Don't let the cursor end in the scroll margins. */
15217 int this_scroll_margin
, cursor_height
;
15219 this_scroll_margin
= max (0, scroll_margin
);
15220 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15221 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15222 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15224 if ((w
->cursor
.y
< this_scroll_margin
15225 && CHARPOS (start
) > BEGV
)
15226 /* Old redisplay didn't take scroll margin into account at the bottom,
15227 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15228 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15229 ? cursor_height
+ this_scroll_margin
15230 : 1)) > it
.last_visible_y
)
15232 w
->cursor
.vpos
= -1;
15233 clear_glyph_matrix (w
->desired_matrix
);
15238 /* Scroll the display. Do it before changing the current matrix so
15239 that xterm.c doesn't get confused about where the cursor glyph is
15241 if (dy
&& run
.height
)
15245 if (FRAME_WINDOW_P (f
))
15247 FRAME_RIF (f
)->update_window_begin_hook (w
);
15248 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15249 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15250 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15254 /* Terminal frame. In this case, dvpos gives the number of
15255 lines to scroll by; dvpos < 0 means scroll up. */
15256 int first_unchanged_at_end_vpos
15257 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15258 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15259 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15260 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15261 + window_internal_height (w
));
15263 /* Perform the operation on the screen. */
15266 /* Scroll last_unchanged_at_beg_row to the end of the
15267 window down dvpos lines. */
15268 set_terminal_window (f
, end
);
15270 /* On dumb terminals delete dvpos lines at the end
15271 before inserting dvpos empty lines. */
15272 if (!FRAME_SCROLL_REGION_OK (f
))
15273 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15275 /* Insert dvpos empty lines in front of
15276 last_unchanged_at_beg_row. */
15277 ins_del_lines (f
, from
, dvpos
);
15279 else if (dvpos
< 0)
15281 /* Scroll up last_unchanged_at_beg_vpos to the end of
15282 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15283 set_terminal_window (f
, end
);
15285 /* Delete dvpos lines in front of
15286 last_unchanged_at_beg_vpos. ins_del_lines will set
15287 the cursor to the given vpos and emit |dvpos| delete
15289 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15291 /* On a dumb terminal insert dvpos empty lines at the
15293 if (!FRAME_SCROLL_REGION_OK (f
))
15294 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15297 set_terminal_window (f
, 0);
15303 /* Shift reused rows of the current matrix to the right position.
15304 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15306 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15307 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15310 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15311 bottom_vpos
, dvpos
);
15312 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15315 else if (dvpos
> 0)
15317 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15318 bottom_vpos
, dvpos
);
15319 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15320 first_unchanged_at_end_vpos
+ dvpos
, 0);
15323 /* For frame-based redisplay, make sure that current frame and window
15324 matrix are in sync with respect to glyph memory. */
15325 if (!FRAME_WINDOW_P (f
))
15326 sync_frame_with_window_matrix_rows (w
);
15328 /* Adjust buffer positions in reused rows. */
15329 if (delta
|| delta_bytes
)
15330 increment_matrix_positions (current_matrix
,
15331 first_unchanged_at_end_vpos
+ dvpos
,
15332 bottom_vpos
, delta
, delta_bytes
);
15334 /* Adjust Y positions. */
15336 shift_glyph_matrix (w
, current_matrix
,
15337 first_unchanged_at_end_vpos
+ dvpos
,
15340 if (first_unchanged_at_end_row
)
15342 first_unchanged_at_end_row
+= dvpos
;
15343 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15344 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15345 first_unchanged_at_end_row
= NULL
;
15348 /* If scrolling up, there may be some lines to display at the end of
15350 last_text_row_at_end
= NULL
;
15353 /* Scrolling up can leave for example a partially visible line
15354 at the end of the window to be redisplayed. */
15355 /* Set last_row to the glyph row in the current matrix where the
15356 window end line is found. It has been moved up or down in
15357 the matrix by dvpos. */
15358 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15359 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15361 /* If last_row is the window end line, it should display text. */
15362 xassert (last_row
->displays_text_p
);
15364 /* If window end line was partially visible before, begin
15365 displaying at that line. Otherwise begin displaying with the
15366 line following it. */
15367 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15369 init_to_row_start (&it
, w
, last_row
);
15370 it
.vpos
= last_vpos
;
15371 it
.current_y
= last_row
->y
;
15375 init_to_row_end (&it
, w
, last_row
);
15376 it
.vpos
= 1 + last_vpos
;
15377 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15381 /* We may start in a continuation line. If so, we have to
15382 get the right continuation_lines_width and current_x. */
15383 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15384 it
.hpos
= it
.current_x
= 0;
15386 /* Display the rest of the lines at the window end. */
15387 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15388 while (it
.current_y
< it
.last_visible_y
15389 && !fonts_changed_p
)
15391 /* Is it always sure that the display agrees with lines in
15392 the current matrix? I don't think so, so we mark rows
15393 displayed invalid in the current matrix by setting their
15394 enabled_p flag to zero. */
15395 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15396 if (display_line (&it
))
15397 last_text_row_at_end
= it
.glyph_row
- 1;
15401 /* Update window_end_pos and window_end_vpos. */
15402 if (first_unchanged_at_end_row
15403 && !last_text_row_at_end
)
15405 /* Window end line if one of the preserved rows from the current
15406 matrix. Set row to the last row displaying text in current
15407 matrix starting at first_unchanged_at_end_row, after
15409 xassert (first_unchanged_at_end_row
->displays_text_p
);
15410 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15411 first_unchanged_at_end_row
);
15412 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15414 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15415 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15417 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15418 xassert (w
->window_end_bytepos
>= 0);
15419 IF_DEBUG (debug_method_add (w
, "A"));
15421 else if (last_text_row_at_end
)
15424 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15425 w
->window_end_bytepos
15426 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15428 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15429 xassert (w
->window_end_bytepos
>= 0);
15430 IF_DEBUG (debug_method_add (w
, "B"));
15432 else if (last_text_row
)
15434 /* We have displayed either to the end of the window or at the
15435 end of the window, i.e. the last row with text is to be found
15436 in the desired matrix. */
15438 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15439 w
->window_end_bytepos
15440 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15442 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15443 xassert (w
->window_end_bytepos
>= 0);
15445 else if (first_unchanged_at_end_row
== NULL
15446 && last_text_row
== NULL
15447 && last_text_row_at_end
== NULL
)
15449 /* Displayed to end of window, but no line containing text was
15450 displayed. Lines were deleted at the end of the window. */
15451 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15452 int vpos
= XFASTINT (w
->window_end_vpos
);
15453 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15454 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15457 row
== NULL
&& vpos
>= first_vpos
;
15458 --vpos
, --current_row
, --desired_row
)
15460 if (desired_row
->enabled_p
)
15462 if (desired_row
->displays_text_p
)
15465 else if (current_row
->displays_text_p
)
15469 xassert (row
!= NULL
);
15470 w
->window_end_vpos
= make_number (vpos
+ 1);
15471 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15472 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15473 xassert (w
->window_end_bytepos
>= 0);
15474 IF_DEBUG (debug_method_add (w
, "C"));
15479 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15480 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15482 /* Record that display has not been completed. */
15483 w
->window_end_valid
= Qnil
;
15484 w
->desired_matrix
->no_scrolling_p
= 1;
15492 /***********************************************************************
15493 More debugging support
15494 ***********************************************************************/
15498 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15499 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15500 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15503 /* Dump the contents of glyph matrix MATRIX on stderr.
15505 GLYPHS 0 means don't show glyph contents.
15506 GLYPHS 1 means show glyphs in short form
15507 GLYPHS > 1 means show glyphs in long form. */
15510 dump_glyph_matrix (matrix
, glyphs
)
15511 struct glyph_matrix
*matrix
;
15515 for (i
= 0; i
< matrix
->nrows
; ++i
)
15516 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15520 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15521 the glyph row and area where the glyph comes from. */
15524 dump_glyph (row
, glyph
, area
)
15525 struct glyph_row
*row
;
15526 struct glyph
*glyph
;
15529 if (glyph
->type
== CHAR_GLYPH
)
15532 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15533 glyph
- row
->glyphs
[TEXT_AREA
],
15536 (BUFFERP (glyph
->object
)
15538 : (STRINGP (glyph
->object
)
15541 glyph
->pixel_width
,
15543 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15547 glyph
->left_box_line_p
,
15548 glyph
->right_box_line_p
);
15550 else if (glyph
->type
== STRETCH_GLYPH
)
15553 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15554 glyph
- row
->glyphs
[TEXT_AREA
],
15557 (BUFFERP (glyph
->object
)
15559 : (STRINGP (glyph
->object
)
15562 glyph
->pixel_width
,
15566 glyph
->left_box_line_p
,
15567 glyph
->right_box_line_p
);
15569 else if (glyph
->type
== IMAGE_GLYPH
)
15572 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15573 glyph
- row
->glyphs
[TEXT_AREA
],
15576 (BUFFERP (glyph
->object
)
15578 : (STRINGP (glyph
->object
)
15581 glyph
->pixel_width
,
15585 glyph
->left_box_line_p
,
15586 glyph
->right_box_line_p
);
15588 else if (glyph
->type
== COMPOSITE_GLYPH
)
15591 " %5d %4c %6d %c %3d 0x%05x",
15592 glyph
- row
->glyphs
[TEXT_AREA
],
15595 (BUFFERP (glyph
->object
)
15597 : (STRINGP (glyph
->object
)
15600 glyph
->pixel_width
,
15602 if (glyph
->u
.cmp
.automatic
)
15605 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
15606 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
15608 glyph
->left_box_line_p
,
15609 glyph
->right_box_line_p
);
15614 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15615 GLYPHS 0 means don't show glyph contents.
15616 GLYPHS 1 means show glyphs in short form
15617 GLYPHS > 1 means show glyphs in long form. */
15620 dump_glyph_row (row
, vpos
, glyphs
)
15621 struct glyph_row
*row
;
15626 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15627 fprintf (stderr
, "======================================================================\n");
15629 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15630 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15632 MATRIX_ROW_START_CHARPOS (row
),
15633 MATRIX_ROW_END_CHARPOS (row
),
15634 row
->used
[TEXT_AREA
],
15635 row
->contains_overlapping_glyphs_p
,
15637 row
->truncated_on_left_p
,
15638 row
->truncated_on_right_p
,
15640 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15641 row
->displays_text_p
,
15644 row
->ends_in_middle_of_char_p
,
15645 row
->starts_in_middle_of_char_p
,
15651 row
->visible_height
,
15654 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15655 row
->end
.overlay_string_index
,
15656 row
->continuation_lines_width
);
15657 fprintf (stderr
, "%9d %5d\n",
15658 CHARPOS (row
->start
.string_pos
),
15659 CHARPOS (row
->end
.string_pos
));
15660 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15661 row
->end
.dpvec_index
);
15668 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15670 struct glyph
*glyph
= row
->glyphs
[area
];
15671 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15673 /* Glyph for a line end in text. */
15674 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15677 if (glyph
< glyph_end
)
15678 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15680 for (; glyph
< glyph_end
; ++glyph
)
15681 dump_glyph (row
, glyph
, area
);
15684 else if (glyphs
== 1)
15688 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15690 char *s
= (char *) alloca (row
->used
[area
] + 1);
15693 for (i
= 0; i
< row
->used
[area
]; ++i
)
15695 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15696 if (glyph
->type
== CHAR_GLYPH
15697 && glyph
->u
.ch
< 0x80
15698 && glyph
->u
.ch
>= ' ')
15699 s
[i
] = glyph
->u
.ch
;
15705 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15711 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15712 Sdump_glyph_matrix
, 0, 1, "p",
15713 doc
: /* Dump the current matrix of the selected window to stderr.
15714 Shows contents of glyph row structures. With non-nil
15715 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15716 glyphs in short form, otherwise show glyphs in long form. */)
15718 Lisp_Object glyphs
;
15720 struct window
*w
= XWINDOW (selected_window
);
15721 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15723 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15724 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15725 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15726 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15727 fprintf (stderr
, "=============================================\n");
15728 dump_glyph_matrix (w
->current_matrix
,
15729 NILP (glyphs
) ? 0 : XINT (glyphs
));
15734 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15735 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15738 struct frame
*f
= XFRAME (selected_frame
);
15739 dump_glyph_matrix (f
->current_matrix
, 1);
15744 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15745 doc
: /* Dump glyph row ROW to stderr.
15746 GLYPH 0 means don't dump glyphs.
15747 GLYPH 1 means dump glyphs in short form.
15748 GLYPH > 1 or omitted means dump glyphs in long form. */)
15750 Lisp_Object row
, glyphs
;
15752 struct glyph_matrix
*matrix
;
15755 CHECK_NUMBER (row
);
15756 matrix
= XWINDOW (selected_window
)->current_matrix
;
15758 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15759 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15761 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15766 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15767 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15768 GLYPH 0 means don't dump glyphs.
15769 GLYPH 1 means dump glyphs in short form.
15770 GLYPH > 1 or omitted means dump glyphs in long form. */)
15772 Lisp_Object row
, glyphs
;
15774 struct frame
*sf
= SELECTED_FRAME ();
15775 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15778 CHECK_NUMBER (row
);
15780 if (vpos
>= 0 && vpos
< m
->nrows
)
15781 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15782 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15787 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15788 doc
: /* Toggle tracing of redisplay.
15789 With ARG, turn tracing on if and only if ARG is positive. */)
15794 trace_redisplay_p
= !trace_redisplay_p
;
15797 arg
= Fprefix_numeric_value (arg
);
15798 trace_redisplay_p
= XINT (arg
) > 0;
15805 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15806 doc
: /* Like `format', but print result to stderr.
15807 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15812 Lisp_Object s
= Fformat (nargs
, args
);
15813 fprintf (stderr
, "%s", SDATA (s
));
15817 #endif /* GLYPH_DEBUG */
15821 /***********************************************************************
15822 Building Desired Matrix Rows
15823 ***********************************************************************/
15825 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15826 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15828 static struct glyph_row
*
15829 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15831 Lisp_Object overlay_arrow_string
;
15833 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15834 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15835 struct buffer
*old
= current_buffer
;
15836 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15837 int arrow_len
= SCHARS (overlay_arrow_string
);
15838 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15839 const unsigned char *p
;
15842 int n_glyphs_before
;
15844 set_buffer_temp (buffer
);
15845 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15846 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15847 SET_TEXT_POS (it
.position
, 0, 0);
15849 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15851 while (p
< arrow_end
)
15853 Lisp_Object face
, ilisp
;
15855 /* Get the next character. */
15857 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
15860 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
15861 if (! ASCII_CHAR_P (it
.c
))
15862 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
15866 /* Get its face. */
15867 ilisp
= make_number (p
- arrow_string
);
15868 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15869 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
15871 /* Compute its width, get its glyphs. */
15872 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15873 SET_TEXT_POS (it
.position
, -1, -1);
15874 PRODUCE_GLYPHS (&it
);
15876 /* If this character doesn't fit any more in the line, we have
15877 to remove some glyphs. */
15878 if (it
.current_x
> it
.last_visible_x
)
15880 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15885 set_buffer_temp (old
);
15886 return it
.glyph_row
;
15890 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15891 glyphs are only inserted for terminal frames since we can't really
15892 win with truncation glyphs when partially visible glyphs are
15893 involved. Which glyphs to insert is determined by
15894 produce_special_glyphs. */
15897 insert_left_trunc_glyphs (it
)
15900 struct it truncate_it
;
15901 struct glyph
*from
, *end
, *to
, *toend
;
15903 xassert (!FRAME_WINDOW_P (it
->f
));
15905 /* Get the truncation glyphs. */
15907 truncate_it
.current_x
= 0;
15908 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15909 truncate_it
.glyph_row
= &scratch_glyph_row
;
15910 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15911 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15912 truncate_it
.object
= make_number (0);
15913 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15915 /* Overwrite glyphs from IT with truncation glyphs. */
15916 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15917 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15918 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15919 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15924 /* There may be padding glyphs left over. Overwrite them too. */
15925 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15927 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15933 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15937 /* Compute the pixel height and width of IT->glyph_row.
15939 Most of the time, ascent and height of a display line will be equal
15940 to the max_ascent and max_height values of the display iterator
15941 structure. This is not the case if
15943 1. We hit ZV without displaying anything. In this case, max_ascent
15944 and max_height will be zero.
15946 2. We have some glyphs that don't contribute to the line height.
15947 (The glyph row flag contributes_to_line_height_p is for future
15948 pixmap extensions).
15950 The first case is easily covered by using default values because in
15951 these cases, the line height does not really matter, except that it
15952 must not be zero. */
15955 compute_line_metrics (it
)
15958 struct glyph_row
*row
= it
->glyph_row
;
15961 if (FRAME_WINDOW_P (it
->f
))
15963 int i
, min_y
, max_y
;
15965 /* The line may consist of one space only, that was added to
15966 place the cursor on it. If so, the row's height hasn't been
15968 if (row
->height
== 0)
15970 if (it
->max_ascent
+ it
->max_descent
== 0)
15971 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15972 row
->ascent
= it
->max_ascent
;
15973 row
->height
= it
->max_ascent
+ it
->max_descent
;
15974 row
->phys_ascent
= it
->max_phys_ascent
;
15975 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15976 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15979 /* Compute the width of this line. */
15980 row
->pixel_width
= row
->x
;
15981 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15982 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15984 xassert (row
->pixel_width
>= 0);
15985 xassert (row
->ascent
>= 0 && row
->height
> 0);
15987 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15988 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15990 /* If first line's physical ascent is larger than its logical
15991 ascent, use the physical ascent, and make the row taller.
15992 This makes accented characters fully visible. */
15993 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15994 && row
->phys_ascent
> row
->ascent
)
15996 row
->height
+= row
->phys_ascent
- row
->ascent
;
15997 row
->ascent
= row
->phys_ascent
;
16000 /* Compute how much of the line is visible. */
16001 row
->visible_height
= row
->height
;
16003 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16004 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16006 if (row
->y
< min_y
)
16007 row
->visible_height
-= min_y
- row
->y
;
16008 if (row
->y
+ row
->height
> max_y
)
16009 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16013 row
->pixel_width
= row
->used
[TEXT_AREA
];
16014 if (row
->continued_p
)
16015 row
->pixel_width
-= it
->continuation_pixel_width
;
16016 else if (row
->truncated_on_right_p
)
16017 row
->pixel_width
-= it
->truncation_pixel_width
;
16018 row
->ascent
= row
->phys_ascent
= 0;
16019 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16020 row
->extra_line_spacing
= 0;
16023 /* Compute a hash code for this row. */
16025 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16026 for (i
= 0; i
< row
->used
[area
]; ++i
)
16027 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16028 + row
->glyphs
[area
][i
].u
.val
16029 + row
->glyphs
[area
][i
].face_id
16030 + row
->glyphs
[area
][i
].padding_p
16031 + (row
->glyphs
[area
][i
].type
<< 2));
16033 it
->max_ascent
= it
->max_descent
= 0;
16034 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16038 /* Append one space to the glyph row of iterator IT if doing a
16039 window-based redisplay. The space has the same face as
16040 IT->face_id. Value is non-zero if a space was added.
16042 This function is called to make sure that there is always one glyph
16043 at the end of a glyph row that the cursor can be set on under
16044 window-systems. (If there weren't such a glyph we would not know
16045 how wide and tall a box cursor should be displayed).
16047 At the same time this space let's a nicely handle clearing to the
16048 end of the line if the row ends in italic text. */
16051 append_space_for_newline (it
, default_face_p
)
16053 int default_face_p
;
16055 if (FRAME_WINDOW_P (it
->f
))
16057 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16059 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16060 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16062 /* Save some values that must not be changed.
16063 Must save IT->c and IT->len because otherwise
16064 ITERATOR_AT_END_P wouldn't work anymore after
16065 append_space_for_newline has been called. */
16066 enum display_element_type saved_what
= it
->what
;
16067 int saved_c
= it
->c
, saved_len
= it
->len
;
16068 int saved_char_to_display
= it
->char_to_display
;
16069 int saved_x
= it
->current_x
;
16070 int saved_face_id
= it
->face_id
;
16071 struct text_pos saved_pos
;
16072 Lisp_Object saved_object
;
16075 saved_object
= it
->object
;
16076 saved_pos
= it
->position
;
16078 it
->what
= IT_CHARACTER
;
16079 bzero (&it
->position
, sizeof it
->position
);
16080 it
->object
= make_number (0);
16081 it
->c
= it
->char_to_display
= ' ';
16084 if (default_face_p
)
16085 it
->face_id
= DEFAULT_FACE_ID
;
16086 else if (it
->face_before_selective_p
)
16087 it
->face_id
= it
->saved_face_id
;
16088 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16089 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16091 PRODUCE_GLYPHS (it
);
16093 it
->override_ascent
= -1;
16094 it
->constrain_row_ascent_descent_p
= 0;
16095 it
->current_x
= saved_x
;
16096 it
->object
= saved_object
;
16097 it
->position
= saved_pos
;
16098 it
->what
= saved_what
;
16099 it
->face_id
= saved_face_id
;
16100 it
->len
= saved_len
;
16102 it
->char_to_display
= saved_char_to_display
;
16111 /* Extend the face of the last glyph in the text area of IT->glyph_row
16112 to the end of the display line. Called from display_line.
16113 If the glyph row is empty, add a space glyph to it so that we
16114 know the face to draw. Set the glyph row flag fill_line_p. */
16117 extend_face_to_end_of_line (it
)
16121 struct frame
*f
= it
->f
;
16123 /* If line is already filled, do nothing. */
16124 if (it
->current_x
>= it
->last_visible_x
)
16127 /* Face extension extends the background and box of IT->face_id
16128 to the end of the line. If the background equals the background
16129 of the frame, we don't have to do anything. */
16130 if (it
->face_before_selective_p
)
16131 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16133 face
= FACE_FROM_ID (f
, it
->face_id
);
16135 if (FRAME_WINDOW_P (f
)
16136 && it
->glyph_row
->displays_text_p
16137 && face
->box
== FACE_NO_BOX
16138 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16142 /* Set the glyph row flag indicating that the face of the last glyph
16143 in the text area has to be drawn to the end of the text area. */
16144 it
->glyph_row
->fill_line_p
= 1;
16146 /* If current character of IT is not ASCII, make sure we have the
16147 ASCII face. This will be automatically undone the next time
16148 get_next_display_element returns a multibyte character. Note
16149 that the character will always be single byte in unibyte
16151 if (!ASCII_CHAR_P (it
->c
))
16153 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16156 if (FRAME_WINDOW_P (f
))
16158 /* If the row is empty, add a space with the current face of IT,
16159 so that we know which face to draw. */
16160 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16162 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16163 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16164 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16169 /* Save some values that must not be changed. */
16170 int saved_x
= it
->current_x
;
16171 struct text_pos saved_pos
;
16172 Lisp_Object saved_object
;
16173 enum display_element_type saved_what
= it
->what
;
16174 int saved_face_id
= it
->face_id
;
16176 saved_object
= it
->object
;
16177 saved_pos
= it
->position
;
16179 it
->what
= IT_CHARACTER
;
16180 bzero (&it
->position
, sizeof it
->position
);
16181 it
->object
= make_number (0);
16182 it
->c
= it
->char_to_display
= ' ';
16184 it
->face_id
= face
->id
;
16186 PRODUCE_GLYPHS (it
);
16188 while (it
->current_x
<= it
->last_visible_x
)
16189 PRODUCE_GLYPHS (it
);
16191 /* Don't count these blanks really. It would let us insert a left
16192 truncation glyph below and make us set the cursor on them, maybe. */
16193 it
->current_x
= saved_x
;
16194 it
->object
= saved_object
;
16195 it
->position
= saved_pos
;
16196 it
->what
= saved_what
;
16197 it
->face_id
= saved_face_id
;
16202 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16203 trailing whitespace. */
16206 trailing_whitespace_p (charpos
)
16209 int bytepos
= CHAR_TO_BYTE (charpos
);
16212 while (bytepos
< ZV_BYTE
16213 && (c
= FETCH_CHAR (bytepos
),
16214 c
== ' ' || c
== '\t'))
16217 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16219 if (bytepos
!= PT_BYTE
)
16226 /* Highlight trailing whitespace, if any, in ROW. */
16229 highlight_trailing_whitespace (f
, row
)
16231 struct glyph_row
*row
;
16233 int used
= row
->used
[TEXT_AREA
];
16237 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16238 struct glyph
*glyph
= start
+ used
- 1;
16240 /* Skip over glyphs inserted to display the cursor at the
16241 end of a line, for extending the face of the last glyph
16242 to the end of the line on terminals, and for truncation
16243 and continuation glyphs. */
16244 while (glyph
>= start
16245 && glyph
->type
== CHAR_GLYPH
16246 && INTEGERP (glyph
->object
))
16249 /* If last glyph is a space or stretch, and it's trailing
16250 whitespace, set the face of all trailing whitespace glyphs in
16251 IT->glyph_row to `trailing-whitespace'. */
16253 && BUFFERP (glyph
->object
)
16254 && (glyph
->type
== STRETCH_GLYPH
16255 || (glyph
->type
== CHAR_GLYPH
16256 && glyph
->u
.ch
== ' '))
16257 && trailing_whitespace_p (glyph
->charpos
))
16259 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16263 while (glyph
>= start
16264 && BUFFERP (glyph
->object
)
16265 && (glyph
->type
== STRETCH_GLYPH
16266 || (glyph
->type
== CHAR_GLYPH
16267 && glyph
->u
.ch
== ' ')))
16268 (glyph
--)->face_id
= face_id
;
16274 /* Value is non-zero if glyph row ROW in window W should be
16275 used to hold the cursor. */
16278 cursor_row_p (w
, row
)
16280 struct glyph_row
*row
;
16282 int cursor_row_p
= 1;
16284 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16286 /* Suppose the row ends on a string.
16287 Unless the row is continued, that means it ends on a newline
16288 in the string. If it's anything other than a display string
16289 (e.g. a before-string from an overlay), we don't want the
16290 cursor there. (This heuristic seems to give the optimal
16291 behavior for the various types of multi-line strings.) */
16292 if (CHARPOS (row
->end
.string_pos
) >= 0)
16294 if (row
->continued_p
)
16298 /* Check for `display' property. */
16299 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16300 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16301 struct glyph
*glyph
;
16304 for (glyph
= end
; glyph
>= beg
; --glyph
)
16305 if (STRINGP (glyph
->object
))
16308 = Fget_char_property (make_number (PT
),
16312 && display_prop_string_p (prop
, glyph
->object
));
16317 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16319 /* If the row ends in middle of a real character,
16320 and the line is continued, we want the cursor here.
16321 That's because MATRIX_ROW_END_CHARPOS would equal
16322 PT if PT is before the character. */
16323 if (!row
->ends_in_ellipsis_p
)
16324 cursor_row_p
= row
->continued_p
;
16326 /* If the row ends in an ellipsis, then
16327 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16328 We want that position to be displayed after the ellipsis. */
16331 /* If the row ends at ZV, display the cursor at the end of that
16332 row instead of at the start of the row below. */
16333 else if (row
->ends_at_zv_p
)
16339 return cursor_row_p
;
16344 /* Push the display property PROP so that it will be rendered at the
16345 current position in IT. Return 1 if PROP was successfully pushed,
16349 push_display_prop (struct it
*it
, Lisp_Object prop
)
16353 if (STRINGP (prop
))
16355 if (SCHARS (prop
) == 0)
16362 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16363 it
->current
.overlay_string_index
= -1;
16364 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16365 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16366 it
->method
= GET_FROM_STRING
;
16367 it
->stop_charpos
= 0;
16369 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16371 it
->method
= GET_FROM_STRETCH
;
16374 #ifdef HAVE_WINDOW_SYSTEM
16375 else if (IMAGEP (prop
))
16377 it
->what
= IT_IMAGE
;
16378 it
->image_id
= lookup_image (it
->f
, prop
);
16379 it
->method
= GET_FROM_IMAGE
;
16381 #endif /* HAVE_WINDOW_SYSTEM */
16384 pop_it (it
); /* bogus display property, give up */
16391 /* Return the character-property PROP at the current position in IT. */
16394 get_it_property (it
, prop
)
16398 Lisp_Object position
;
16400 if (STRINGP (it
->object
))
16401 position
= make_number (IT_STRING_CHARPOS (*it
));
16402 else if (BUFFERP (it
->object
))
16403 position
= make_number (IT_CHARPOS (*it
));
16407 return Fget_char_property (position
, prop
, it
->object
);
16410 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16413 handle_line_prefix (struct it
*it
)
16415 Lisp_Object prefix
;
16416 if (it
->continuation_lines_width
> 0)
16418 prefix
= get_it_property (it
, Qwrap_prefix
);
16420 prefix
= Vwrap_prefix
;
16424 prefix
= get_it_property (it
, Qline_prefix
);
16426 prefix
= Vline_prefix
;
16428 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
16430 /* If the prefix is wider than the window, and we try to wrap
16431 it, it would acquire its own wrap prefix, and so on till the
16432 iterator stack overflows. So, don't wrap the prefix. */
16433 it
->line_wrap
= TRUNCATE
;
16434 it
->avoid_cursor_p
= 1;
16440 /* Construct the glyph row IT->glyph_row in the desired matrix of
16441 IT->w from text at the current position of IT. See dispextern.h
16442 for an overview of struct it. Value is non-zero if
16443 IT->glyph_row displays text, as opposed to a line displaying ZV
16450 struct glyph_row
*row
= it
->glyph_row
;
16451 Lisp_Object overlay_arrow_string
;
16453 int may_wrap
= 0, wrap_x
;
16454 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16455 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16456 int wrap_row_extra_line_spacing
;
16458 /* We always start displaying at hpos zero even if hscrolled. */
16459 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16461 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16462 >= it
->w
->desired_matrix
->nrows
)
16464 it
->w
->nrows_scale_factor
++;
16465 fonts_changed_p
= 1;
16469 /* Is IT->w showing the region? */
16470 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16472 /* Clear the result glyph row and enable it. */
16473 prepare_desired_row (row
);
16475 row
->y
= it
->current_y
;
16476 row
->start
= it
->start
;
16477 row
->continuation_lines_width
= it
->continuation_lines_width
;
16478 row
->displays_text_p
= 1;
16479 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16480 it
->starts_in_middle_of_char_p
= 0;
16482 /* Arrange the overlays nicely for our purposes. Usually, we call
16483 display_line on only one line at a time, in which case this
16484 can't really hurt too much, or we call it on lines which appear
16485 one after another in the buffer, in which case all calls to
16486 recenter_overlay_lists but the first will be pretty cheap. */
16487 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16489 /* Move over display elements that are not visible because we are
16490 hscrolled. This may stop at an x-position < IT->first_visible_x
16491 if the first glyph is partially visible or if we hit a line end. */
16492 if (it
->current_x
< it
->first_visible_x
)
16494 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16495 MOVE_TO_POS
| MOVE_TO_X
);
16499 /* We only do this when not calling `move_it_in_display_line_to'
16500 above, because move_it_in_display_line_to calls
16501 handle_line_prefix itself. */
16502 handle_line_prefix (it
);
16505 /* Get the initial row height. This is either the height of the
16506 text hscrolled, if there is any, or zero. */
16507 row
->ascent
= it
->max_ascent
;
16508 row
->height
= it
->max_ascent
+ it
->max_descent
;
16509 row
->phys_ascent
= it
->max_phys_ascent
;
16510 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16511 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16513 /* Loop generating characters. The loop is left with IT on the next
16514 character to display. */
16517 int n_glyphs_before
, hpos_before
, x_before
;
16519 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16521 /* Retrieve the next thing to display. Value is zero if end of
16523 if (!get_next_display_element (it
))
16525 /* Maybe add a space at the end of this line that is used to
16526 display the cursor there under X. Set the charpos of the
16527 first glyph of blank lines not corresponding to any text
16529 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16530 row
->exact_window_width_line_p
= 1;
16531 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16532 || row
->used
[TEXT_AREA
] == 0)
16534 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16535 row
->displays_text_p
= 0;
16537 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16538 && (!MINI_WINDOW_P (it
->w
)
16539 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16540 row
->indicate_empty_line_p
= 1;
16543 it
->continuation_lines_width
= 0;
16544 row
->ends_at_zv_p
= 1;
16548 /* Now, get the metrics of what we want to display. This also
16549 generates glyphs in `row' (which is IT->glyph_row). */
16550 n_glyphs_before
= row
->used
[TEXT_AREA
];
16553 /* Remember the line height so far in case the next element doesn't
16554 fit on the line. */
16555 if (it
->line_wrap
!= TRUNCATE
)
16557 ascent
= it
->max_ascent
;
16558 descent
= it
->max_descent
;
16559 phys_ascent
= it
->max_phys_ascent
;
16560 phys_descent
= it
->max_phys_descent
;
16562 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16564 if (IT_DISPLAYING_WHITESPACE (it
))
16570 wrap_row_used
= row
->used
[TEXT_AREA
];
16571 wrap_row_ascent
= row
->ascent
;
16572 wrap_row_height
= row
->height
;
16573 wrap_row_phys_ascent
= row
->phys_ascent
;
16574 wrap_row_phys_height
= row
->phys_height
;
16575 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16581 PRODUCE_GLYPHS (it
);
16583 /* If this display element was in marginal areas, continue with
16585 if (it
->area
!= TEXT_AREA
)
16587 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16588 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16589 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16590 row
->phys_height
= max (row
->phys_height
,
16591 it
->max_phys_ascent
+ it
->max_phys_descent
);
16592 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16593 it
->max_extra_line_spacing
);
16594 set_iterator_to_next (it
, 1);
16598 /* Does the display element fit on the line? If we truncate
16599 lines, we should draw past the right edge of the window. If
16600 we don't truncate, we want to stop so that we can display the
16601 continuation glyph before the right margin. If lines are
16602 continued, there are two possible strategies for characters
16603 resulting in more than 1 glyph (e.g. tabs): Display as many
16604 glyphs as possible in this line and leave the rest for the
16605 continuation line, or display the whole element in the next
16606 line. Original redisplay did the former, so we do it also. */
16607 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16608 hpos_before
= it
->hpos
;
16611 if (/* Not a newline. */
16613 /* Glyphs produced fit entirely in the line. */
16614 && it
->current_x
< it
->last_visible_x
)
16616 it
->hpos
+= nglyphs
;
16617 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16618 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16619 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16620 row
->phys_height
= max (row
->phys_height
,
16621 it
->max_phys_ascent
+ it
->max_phys_descent
);
16622 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16623 it
->max_extra_line_spacing
);
16624 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16625 row
->x
= x
- it
->first_visible_x
;
16630 struct glyph
*glyph
;
16632 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16634 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16635 new_x
= x
+ glyph
->pixel_width
;
16637 if (/* Lines are continued. */
16638 it
->line_wrap
!= TRUNCATE
16639 && (/* Glyph doesn't fit on the line. */
16640 new_x
> it
->last_visible_x
16641 /* Or it fits exactly on a window system frame. */
16642 || (new_x
== it
->last_visible_x
16643 && FRAME_WINDOW_P (it
->f
))))
16645 /* End of a continued line. */
16648 || (new_x
== it
->last_visible_x
16649 && FRAME_WINDOW_P (it
->f
)))
16651 /* Current glyph is the only one on the line or
16652 fits exactly on the line. We must continue
16653 the line because we can't draw the cursor
16654 after the glyph. */
16655 row
->continued_p
= 1;
16656 it
->current_x
= new_x
;
16657 it
->continuation_lines_width
+= new_x
;
16659 if (i
== nglyphs
- 1)
16661 /* If line-wrap is on, check if a previous
16662 wrap point was found. */
16663 if (wrap_row_used
> 0
16664 /* Even if there is a previous wrap
16665 point, continue the line here as
16666 usual, if (i) the previous character
16667 was a space or tab AND (ii) the
16668 current character is not. */
16670 || IT_DISPLAYING_WHITESPACE (it
)))
16673 set_iterator_to_next (it
, 1);
16674 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16676 if (!get_next_display_element (it
))
16678 row
->exact_window_width_line_p
= 1;
16679 it
->continuation_lines_width
= 0;
16680 row
->continued_p
= 0;
16681 row
->ends_at_zv_p
= 1;
16683 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16685 row
->continued_p
= 0;
16686 row
->exact_window_width_line_p
= 1;
16691 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16692 && !FRAME_WINDOW_P (it
->f
))
16694 /* A padding glyph that doesn't fit on this line.
16695 This means the whole character doesn't fit
16697 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16699 /* Fill the rest of the row with continuation
16700 glyphs like in 20.x. */
16701 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16702 < row
->glyphs
[1 + TEXT_AREA
])
16703 produce_special_glyphs (it
, IT_CONTINUATION
);
16705 row
->continued_p
= 1;
16706 it
->current_x
= x_before
;
16707 it
->continuation_lines_width
+= x_before
;
16709 /* Restore the height to what it was before the
16710 element not fitting on the line. */
16711 it
->max_ascent
= ascent
;
16712 it
->max_descent
= descent
;
16713 it
->max_phys_ascent
= phys_ascent
;
16714 it
->max_phys_descent
= phys_descent
;
16716 else if (wrap_row_used
> 0)
16720 it
->continuation_lines_width
+= wrap_x
;
16721 row
->used
[TEXT_AREA
] = wrap_row_used
;
16722 row
->ascent
= wrap_row_ascent
;
16723 row
->height
= wrap_row_height
;
16724 row
->phys_ascent
= wrap_row_phys_ascent
;
16725 row
->phys_height
= wrap_row_phys_height
;
16726 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16727 row
->continued_p
= 1;
16728 row
->ends_at_zv_p
= 0;
16729 row
->exact_window_width_line_p
= 0;
16730 it
->continuation_lines_width
+= x
;
16732 /* Make sure that a non-default face is extended
16733 up to the right margin of the window. */
16734 extend_face_to_end_of_line (it
);
16736 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16738 /* A TAB that extends past the right edge of the
16739 window. This produces a single glyph on
16740 window system frames. We leave the glyph in
16741 this row and let it fill the row, but don't
16742 consume the TAB. */
16743 it
->continuation_lines_width
+= it
->last_visible_x
;
16744 row
->ends_in_middle_of_char_p
= 1;
16745 row
->continued_p
= 1;
16746 glyph
->pixel_width
= it
->last_visible_x
- x
;
16747 it
->starts_in_middle_of_char_p
= 1;
16751 /* Something other than a TAB that draws past
16752 the right edge of the window. Restore
16753 positions to values before the element. */
16754 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16756 /* Display continuation glyphs. */
16757 if (!FRAME_WINDOW_P (it
->f
))
16758 produce_special_glyphs (it
, IT_CONTINUATION
);
16759 row
->continued_p
= 1;
16761 it
->current_x
= x_before
;
16762 it
->continuation_lines_width
+= x
;
16763 extend_face_to_end_of_line (it
);
16765 if (nglyphs
> 1 && i
> 0)
16767 row
->ends_in_middle_of_char_p
= 1;
16768 it
->starts_in_middle_of_char_p
= 1;
16771 /* Restore the height to what it was before the
16772 element not fitting on the line. */
16773 it
->max_ascent
= ascent
;
16774 it
->max_descent
= descent
;
16775 it
->max_phys_ascent
= phys_ascent
;
16776 it
->max_phys_descent
= phys_descent
;
16781 else if (new_x
> it
->first_visible_x
)
16783 /* Increment number of glyphs actually displayed. */
16786 if (x
< it
->first_visible_x
)
16787 /* Glyph is partially visible, i.e. row starts at
16788 negative X position. */
16789 row
->x
= x
- it
->first_visible_x
;
16793 /* Glyph is completely off the left margin of the
16794 window. This should not happen because of the
16795 move_it_in_display_line at the start of this
16796 function, unless the text display area of the
16797 window is empty. */
16798 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16802 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16803 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16804 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16805 row
->phys_height
= max (row
->phys_height
,
16806 it
->max_phys_ascent
+ it
->max_phys_descent
);
16807 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16808 it
->max_extra_line_spacing
);
16810 /* End of this display line if row is continued. */
16811 if (row
->continued_p
|| row
->ends_at_zv_p
)
16816 /* Is this a line end? If yes, we're also done, after making
16817 sure that a non-default face is extended up to the right
16818 margin of the window. */
16819 if (ITERATOR_AT_END_OF_LINE_P (it
))
16821 int used_before
= row
->used
[TEXT_AREA
];
16823 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16825 /* Add a space at the end of the line that is used to
16826 display the cursor there. */
16827 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16828 append_space_for_newline (it
, 0);
16830 /* Extend the face to the end of the line. */
16831 extend_face_to_end_of_line (it
);
16833 /* Make sure we have the position. */
16834 if (used_before
== 0)
16835 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16837 /* Consume the line end. This skips over invisible lines. */
16838 set_iterator_to_next (it
, 1);
16839 it
->continuation_lines_width
= 0;
16843 /* Proceed with next display element. Note that this skips
16844 over lines invisible because of selective display. */
16845 set_iterator_to_next (it
, 1);
16847 /* If we truncate lines, we are done when the last displayed
16848 glyphs reach past the right margin of the window. */
16849 if (it
->line_wrap
== TRUNCATE
16850 && (FRAME_WINDOW_P (it
->f
)
16851 ? (it
->current_x
>= it
->last_visible_x
)
16852 : (it
->current_x
> it
->last_visible_x
)))
16854 /* Maybe add truncation glyphs. */
16855 if (!FRAME_WINDOW_P (it
->f
))
16859 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16860 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16863 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16865 row
->used
[TEXT_AREA
] = i
;
16866 produce_special_glyphs (it
, IT_TRUNCATION
);
16869 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16871 /* Don't truncate if we can overflow newline into fringe. */
16872 if (!get_next_display_element (it
))
16874 it
->continuation_lines_width
= 0;
16875 row
->ends_at_zv_p
= 1;
16876 row
->exact_window_width_line_p
= 1;
16879 if (ITERATOR_AT_END_OF_LINE_P (it
))
16881 row
->exact_window_width_line_p
= 1;
16882 goto at_end_of_line
;
16886 row
->truncated_on_right_p
= 1;
16887 it
->continuation_lines_width
= 0;
16888 reseat_at_next_visible_line_start (it
, 0);
16889 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16890 it
->hpos
= hpos_before
;
16891 it
->current_x
= x_before
;
16896 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16897 at the left window margin. */
16898 if (it
->first_visible_x
16899 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16901 if (!FRAME_WINDOW_P (it
->f
))
16902 insert_left_trunc_glyphs (it
);
16903 row
->truncated_on_left_p
= 1;
16906 /* If the start of this line is the overlay arrow-position, then
16907 mark this glyph row as the one containing the overlay arrow.
16908 This is clearly a mess with variable size fonts. It would be
16909 better to let it be displayed like cursors under X. */
16910 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16911 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16912 !NILP (overlay_arrow_string
)))
16914 /* Overlay arrow in window redisplay is a fringe bitmap. */
16915 if (STRINGP (overlay_arrow_string
))
16917 struct glyph_row
*arrow_row
16918 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16919 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16920 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16921 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16922 struct glyph
*p2
, *end
;
16924 /* Copy the arrow glyphs. */
16925 while (glyph
< arrow_end
)
16928 /* Throw away padding glyphs. */
16930 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16931 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16937 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16942 xassert (INTEGERP (overlay_arrow_string
));
16943 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16945 overlay_arrow_seen
= 1;
16948 /* Compute pixel dimensions of this line. */
16949 compute_line_metrics (it
);
16951 /* Remember the position at which this line ends. */
16952 row
->end
= it
->current
;
16954 /* Record whether this row ends inside an ellipsis. */
16955 row
->ends_in_ellipsis_p
16956 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16957 && it
->ellipsis_p
);
16959 /* Save fringe bitmaps in this row. */
16960 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16961 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16962 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16963 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16965 it
->left_user_fringe_bitmap
= 0;
16966 it
->left_user_fringe_face_id
= 0;
16967 it
->right_user_fringe_bitmap
= 0;
16968 it
->right_user_fringe_face_id
= 0;
16970 /* Maybe set the cursor. */
16971 if (it
->w
->cursor
.vpos
< 0
16972 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16973 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16974 && cursor_row_p (it
->w
, row
))
16975 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16977 /* Highlight trailing whitespace. */
16978 if (!NILP (Vshow_trailing_whitespace
))
16979 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16981 /* Prepare for the next line. This line starts horizontally at (X
16982 HPOS) = (0 0). Vertical positions are incremented. As a
16983 convenience for the caller, IT->glyph_row is set to the next
16985 it
->current_x
= it
->hpos
= 0;
16986 it
->current_y
+= row
->height
;
16989 it
->start
= it
->current
;
16990 return row
->displays_text_p
;
16995 /***********************************************************************
16997 ***********************************************************************/
16999 /* Redisplay the menu bar in the frame for window W.
17001 The menu bar of X frames that don't have X toolkit support is
17002 displayed in a special window W->frame->menu_bar_window.
17004 The menu bar of terminal frames is treated specially as far as
17005 glyph matrices are concerned. Menu bar lines are not part of
17006 windows, so the update is done directly on the frame matrix rows
17007 for the menu bar. */
17010 display_menu_bar (w
)
17013 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17018 /* Don't do all this for graphical frames. */
17020 if (FRAME_W32_P (f
))
17023 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17029 if (FRAME_NS_P (f
))
17031 #endif /* HAVE_NS */
17033 #ifdef USE_X_TOOLKIT
17034 xassert (!FRAME_WINDOW_P (f
));
17035 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17036 it
.first_visible_x
= 0;
17037 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17038 #else /* not USE_X_TOOLKIT */
17039 if (FRAME_WINDOW_P (f
))
17041 /* Menu bar lines are displayed in the desired matrix of the
17042 dummy window menu_bar_window. */
17043 struct window
*menu_w
;
17044 xassert (WINDOWP (f
->menu_bar_window
));
17045 menu_w
= XWINDOW (f
->menu_bar_window
);
17046 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17048 it
.first_visible_x
= 0;
17049 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17053 /* This is a TTY frame, i.e. character hpos/vpos are used as
17055 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17057 it
.first_visible_x
= 0;
17058 it
.last_visible_x
= FRAME_COLS (f
);
17060 #endif /* not USE_X_TOOLKIT */
17062 if (! mode_line_inverse_video
)
17063 /* Force the menu-bar to be displayed in the default face. */
17064 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17066 /* Clear all rows of the menu bar. */
17067 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17069 struct glyph_row
*row
= it
.glyph_row
+ i
;
17070 clear_glyph_row (row
);
17071 row
->enabled_p
= 1;
17072 row
->full_width_p
= 1;
17075 /* Display all items of the menu bar. */
17076 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17077 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17079 Lisp_Object string
;
17081 /* Stop at nil string. */
17082 string
= AREF (items
, i
+ 1);
17086 /* Remember where item was displayed. */
17087 ASET (items
, i
+ 3, make_number (it
.hpos
));
17089 /* Display the item, pad with one space. */
17090 if (it
.current_x
< it
.last_visible_x
)
17091 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17092 SCHARS (string
) + 1, 0, 0, -1);
17095 /* Fill out the line with spaces. */
17096 if (it
.current_x
< it
.last_visible_x
)
17097 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17099 /* Compute the total height of the lines. */
17100 compute_line_metrics (&it
);
17105 /***********************************************************************
17107 ***********************************************************************/
17109 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17110 FORCE is non-zero, redisplay mode lines unconditionally.
17111 Otherwise, redisplay only mode lines that are garbaged. Value is
17112 the number of windows whose mode lines were redisplayed. */
17115 redisplay_mode_lines (window
, force
)
17116 Lisp_Object window
;
17121 while (!NILP (window
))
17123 struct window
*w
= XWINDOW (window
);
17125 if (WINDOWP (w
->hchild
))
17126 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17127 else if (WINDOWP (w
->vchild
))
17128 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17130 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17131 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17133 struct text_pos lpoint
;
17134 struct buffer
*old
= current_buffer
;
17136 /* Set the window's buffer for the mode line display. */
17137 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17138 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17140 /* Point refers normally to the selected window. For any
17141 other window, set up appropriate value. */
17142 if (!EQ (window
, selected_window
))
17144 struct text_pos pt
;
17146 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17147 if (CHARPOS (pt
) < BEGV
)
17148 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17149 else if (CHARPOS (pt
) > (ZV
- 1))
17150 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17152 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17155 /* Display mode lines. */
17156 clear_glyph_matrix (w
->desired_matrix
);
17157 if (display_mode_lines (w
))
17160 w
->must_be_updated_p
= 1;
17163 /* Restore old settings. */
17164 set_buffer_internal_1 (old
);
17165 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17175 /* Display the mode and/or header line of window W. Value is the
17176 sum number of mode lines and header lines displayed. */
17179 display_mode_lines (w
)
17182 Lisp_Object old_selected_window
, old_selected_frame
;
17185 old_selected_frame
= selected_frame
;
17186 selected_frame
= w
->frame
;
17187 old_selected_window
= selected_window
;
17188 XSETWINDOW (selected_window
, w
);
17190 /* These will be set while the mode line specs are processed. */
17191 line_number_displayed
= 0;
17192 w
->column_number_displayed
= Qnil
;
17194 if (WINDOW_WANTS_MODELINE_P (w
))
17196 struct window
*sel_w
= XWINDOW (old_selected_window
);
17198 /* Select mode line face based on the real selected window. */
17199 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17200 current_buffer
->mode_line_format
);
17204 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17206 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17207 current_buffer
->header_line_format
);
17211 selected_frame
= old_selected_frame
;
17212 selected_window
= old_selected_window
;
17217 /* Display mode or header line of window W. FACE_ID specifies which
17218 line to display; it is either MODE_LINE_FACE_ID or
17219 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
17220 display. Value is the pixel height of the mode/header line
17224 display_mode_line (w
, face_id
, format
)
17226 enum face_id face_id
;
17227 Lisp_Object format
;
17231 int count
= SPECPDL_INDEX ();
17233 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17234 /* Don't extend on a previously drawn mode-line.
17235 This may happen if called from pos_visible_p. */
17236 it
.glyph_row
->enabled_p
= 0;
17237 prepare_desired_row (it
.glyph_row
);
17239 it
.glyph_row
->mode_line_p
= 1;
17241 if (! mode_line_inverse_video
)
17242 /* Force the mode-line to be displayed in the default face. */
17243 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17245 record_unwind_protect (unwind_format_mode_line
,
17246 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17248 mode_line_target
= MODE_LINE_DISPLAY
;
17250 /* Temporarily make frame's keyboard the current kboard so that
17251 kboard-local variables in the mode_line_format will get the right
17253 push_kboard (FRAME_KBOARD (it
.f
));
17254 record_unwind_save_match_data ();
17255 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17258 unbind_to (count
, Qnil
);
17260 /* Fill up with spaces. */
17261 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17263 compute_line_metrics (&it
);
17264 it
.glyph_row
->full_width_p
= 1;
17265 it
.glyph_row
->continued_p
= 0;
17266 it
.glyph_row
->truncated_on_left_p
= 0;
17267 it
.glyph_row
->truncated_on_right_p
= 0;
17269 /* Make a 3D mode-line have a shadow at its right end. */
17270 face
= FACE_FROM_ID (it
.f
, face_id
);
17271 extend_face_to_end_of_line (&it
);
17272 if (face
->box
!= FACE_NO_BOX
)
17274 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17275 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17276 last
->right_box_line_p
= 1;
17279 return it
.glyph_row
->height
;
17282 /* Move element ELT in LIST to the front of LIST.
17283 Return the updated list. */
17286 move_elt_to_front (elt
, list
)
17287 Lisp_Object elt
, list
;
17289 register Lisp_Object tail
, prev
;
17290 register Lisp_Object tem
;
17294 while (CONSP (tail
))
17300 /* Splice out the link TAIL. */
17302 list
= XCDR (tail
);
17304 Fsetcdr (prev
, XCDR (tail
));
17306 /* Now make it the first. */
17307 Fsetcdr (tail
, list
);
17312 tail
= XCDR (tail
);
17316 /* Not found--return unchanged LIST. */
17320 /* Contribute ELT to the mode line for window IT->w. How it
17321 translates into text depends on its data type.
17323 IT describes the display environment in which we display, as usual.
17325 DEPTH is the depth in recursion. It is used to prevent
17326 infinite recursion here.
17328 FIELD_WIDTH is the number of characters the display of ELT should
17329 occupy in the mode line, and PRECISION is the maximum number of
17330 characters to display from ELT's representation. See
17331 display_string for details.
17333 Returns the hpos of the end of the text generated by ELT.
17335 PROPS is a property list to add to any string we encounter.
17337 If RISKY is nonzero, remove (disregard) any properties in any string
17338 we encounter, and ignore :eval and :propertize.
17340 The global variable `mode_line_target' determines whether the
17341 output is passed to `store_mode_line_noprop',
17342 `store_mode_line_string', or `display_string'. */
17345 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17348 int field_width
, precision
;
17349 Lisp_Object elt
, props
;
17352 int n
= 0, field
, prec
;
17357 elt
= build_string ("*too-deep*");
17361 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17365 /* A string: output it and check for %-constructs within it. */
17369 if (SCHARS (elt
) > 0
17370 && (!NILP (props
) || risky
))
17372 Lisp_Object oprops
, aelt
;
17373 oprops
= Ftext_properties_at (make_number (0), elt
);
17375 /* If the starting string's properties are not what
17376 we want, translate the string. Also, if the string
17377 is risky, do that anyway. */
17379 if (NILP (Fequal (props
, oprops
)) || risky
)
17381 /* If the starting string has properties,
17382 merge the specified ones onto the existing ones. */
17383 if (! NILP (oprops
) && !risky
)
17387 oprops
= Fcopy_sequence (oprops
);
17389 while (CONSP (tem
))
17391 oprops
= Fplist_put (oprops
, XCAR (tem
),
17392 XCAR (XCDR (tem
)));
17393 tem
= XCDR (XCDR (tem
));
17398 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17399 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17401 /* AELT is what we want. Move it to the front
17402 without consing. */
17404 mode_line_proptrans_alist
17405 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17411 /* If AELT has the wrong props, it is useless.
17412 so get rid of it. */
17414 mode_line_proptrans_alist
17415 = Fdelq (aelt
, mode_line_proptrans_alist
);
17417 elt
= Fcopy_sequence (elt
);
17418 Fset_text_properties (make_number (0), Flength (elt
),
17420 /* Add this item to mode_line_proptrans_alist. */
17421 mode_line_proptrans_alist
17422 = Fcons (Fcons (elt
, props
),
17423 mode_line_proptrans_alist
);
17424 /* Truncate mode_line_proptrans_alist
17425 to at most 50 elements. */
17426 tem
= Fnthcdr (make_number (50),
17427 mode_line_proptrans_alist
);
17429 XSETCDR (tem
, Qnil
);
17438 prec
= precision
- n
;
17439 switch (mode_line_target
)
17441 case MODE_LINE_NOPROP
:
17442 case MODE_LINE_TITLE
:
17443 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17445 case MODE_LINE_STRING
:
17446 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17448 case MODE_LINE_DISPLAY
:
17449 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17450 0, prec
, 0, STRING_MULTIBYTE (elt
));
17457 /* Handle the non-literal case. */
17459 while ((precision
<= 0 || n
< precision
)
17460 && SREF (elt
, offset
) != 0
17461 && (mode_line_target
!= MODE_LINE_DISPLAY
17462 || it
->current_x
< it
->last_visible_x
))
17464 int last_offset
= offset
;
17466 /* Advance to end of string or next format specifier. */
17467 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17470 if (offset
- 1 != last_offset
)
17472 int nchars
, nbytes
;
17474 /* Output to end of string or up to '%'. Field width
17475 is length of string. Don't output more than
17476 PRECISION allows us. */
17479 prec
= c_string_width (SDATA (elt
) + last_offset
,
17480 offset
- last_offset
, precision
- n
,
17483 switch (mode_line_target
)
17485 case MODE_LINE_NOPROP
:
17486 case MODE_LINE_TITLE
:
17487 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17489 case MODE_LINE_STRING
:
17491 int bytepos
= last_offset
;
17492 int charpos
= string_byte_to_char (elt
, bytepos
);
17493 int endpos
= (precision
<= 0
17494 ? string_byte_to_char (elt
, offset
)
17495 : charpos
+ nchars
);
17497 n
+= store_mode_line_string (NULL
,
17498 Fsubstring (elt
, make_number (charpos
),
17499 make_number (endpos
)),
17503 case MODE_LINE_DISPLAY
:
17505 int bytepos
= last_offset
;
17506 int charpos
= string_byte_to_char (elt
, bytepos
);
17508 if (precision
<= 0)
17509 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17510 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17512 STRING_MULTIBYTE (elt
));
17517 else /* c == '%' */
17519 int percent_position
= offset
;
17521 /* Get the specified minimum width. Zero means
17524 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17525 field
= field
* 10 + c
- '0';
17527 /* Don't pad beyond the total padding allowed. */
17528 if (field_width
- n
> 0 && field
> field_width
- n
)
17529 field
= field_width
- n
;
17531 /* Note that either PRECISION <= 0 or N < PRECISION. */
17532 prec
= precision
- n
;
17535 n
+= display_mode_element (it
, depth
, field
, prec
,
17536 Vglobal_mode_string
, props
,
17541 int bytepos
, charpos
;
17542 unsigned char *spec
;
17543 Lisp_Object string
;
17545 bytepos
= percent_position
;
17546 charpos
= (STRING_MULTIBYTE (elt
)
17547 ? string_byte_to_char (elt
, bytepos
)
17549 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
17550 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
17552 switch (mode_line_target
)
17554 case MODE_LINE_NOPROP
:
17555 case MODE_LINE_TITLE
:
17556 n
+= store_mode_line_noprop (spec
, field
, prec
);
17558 case MODE_LINE_STRING
:
17560 int len
= strlen (spec
);
17561 Lisp_Object tem
= make_string (spec
, len
);
17562 props
= Ftext_properties_at (make_number (charpos
), elt
);
17563 /* Should only keep face property in props */
17564 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17567 case MODE_LINE_DISPLAY
:
17569 int nglyphs_before
, nwritten
;
17571 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17572 nwritten
= display_string (spec
, string
, elt
,
17577 /* Assign to the glyphs written above the
17578 string where the `%x' came from, position
17582 struct glyph
*glyph
17583 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17587 for (i
= 0; i
< nwritten
; ++i
)
17589 glyph
[i
].object
= elt
;
17590 glyph
[i
].charpos
= charpos
;
17607 /* A symbol: process the value of the symbol recursively
17608 as if it appeared here directly. Avoid error if symbol void.
17609 Special case: if value of symbol is a string, output the string
17612 register Lisp_Object tem
;
17614 /* If the variable is not marked as risky to set
17615 then its contents are risky to use. */
17616 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17619 tem
= Fboundp (elt
);
17622 tem
= Fsymbol_value (elt
);
17623 /* If value is a string, output that string literally:
17624 don't check for % within it. */
17628 if (!EQ (tem
, elt
))
17630 /* Give up right away for nil or t. */
17640 register Lisp_Object car
, tem
;
17642 /* A cons cell: five distinct cases.
17643 If first element is :eval or :propertize, do something special.
17644 If first element is a string or a cons, process all the elements
17645 and effectively concatenate them.
17646 If first element is a negative number, truncate displaying cdr to
17647 at most that many characters. If positive, pad (with spaces)
17648 to at least that many characters.
17649 If first element is a symbol, process the cadr or caddr recursively
17650 according to whether the symbol's value is non-nil or nil. */
17652 if (EQ (car
, QCeval
))
17654 /* An element of the form (:eval FORM) means evaluate FORM
17655 and use the result as mode line elements. */
17660 if (CONSP (XCDR (elt
)))
17663 spec
= safe_eval (XCAR (XCDR (elt
)));
17664 n
+= display_mode_element (it
, depth
, field_width
- n
,
17665 precision
- n
, spec
, props
,
17669 else if (EQ (car
, QCpropertize
))
17671 /* An element of the form (:propertize ELT PROPS...)
17672 means display ELT but applying properties PROPS. */
17677 if (CONSP (XCDR (elt
)))
17678 n
+= display_mode_element (it
, depth
, field_width
- n
,
17679 precision
- n
, XCAR (XCDR (elt
)),
17680 XCDR (XCDR (elt
)), risky
);
17682 else if (SYMBOLP (car
))
17684 tem
= Fboundp (car
);
17688 /* elt is now the cdr, and we know it is a cons cell.
17689 Use its car if CAR has a non-nil value. */
17692 tem
= Fsymbol_value (car
);
17699 /* Symbol's value is nil (or symbol is unbound)
17700 Get the cddr of the original list
17701 and if possible find the caddr and use that. */
17705 else if (!CONSP (elt
))
17710 else if (INTEGERP (car
))
17712 register int lim
= XINT (car
);
17716 /* Negative int means reduce maximum width. */
17717 if (precision
<= 0)
17720 precision
= min (precision
, -lim
);
17724 /* Padding specified. Don't let it be more than
17725 current maximum. */
17727 lim
= min (precision
, lim
);
17729 /* If that's more padding than already wanted, queue it.
17730 But don't reduce padding already specified even if
17731 that is beyond the current truncation point. */
17732 field_width
= max (lim
, field_width
);
17736 else if (STRINGP (car
) || CONSP (car
))
17738 Lisp_Object halftail
= elt
;
17742 && (precision
<= 0 || n
< precision
))
17744 n
+= display_mode_element (it
, depth
,
17745 /* Do padding only after the last
17746 element in the list. */
17747 (! CONSP (XCDR (elt
))
17750 precision
- n
, XCAR (elt
),
17754 if ((len
& 1) == 0)
17755 halftail
= XCDR (halftail
);
17756 /* Check for cycle. */
17757 if (EQ (halftail
, elt
))
17766 elt
= build_string ("*invalid*");
17770 /* Pad to FIELD_WIDTH. */
17771 if (field_width
> 0 && n
< field_width
)
17773 switch (mode_line_target
)
17775 case MODE_LINE_NOPROP
:
17776 case MODE_LINE_TITLE
:
17777 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17779 case MODE_LINE_STRING
:
17780 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17782 case MODE_LINE_DISPLAY
:
17783 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17792 /* Store a mode-line string element in mode_line_string_list.
17794 If STRING is non-null, display that C string. Otherwise, the Lisp
17795 string LISP_STRING is displayed.
17797 FIELD_WIDTH is the minimum number of output glyphs to produce.
17798 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17799 with spaces. FIELD_WIDTH <= 0 means don't pad.
17801 PRECISION is the maximum number of characters to output from
17802 STRING. PRECISION <= 0 means don't truncate the string.
17804 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17805 properties to the string.
17807 PROPS are the properties to add to the string.
17808 The mode_line_string_face face property is always added to the string.
17812 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17814 Lisp_Object lisp_string
;
17823 if (string
!= NULL
)
17825 len
= strlen (string
);
17826 if (precision
> 0 && len
> precision
)
17828 lisp_string
= make_string (string
, len
);
17830 props
= mode_line_string_face_prop
;
17831 else if (!NILP (mode_line_string_face
))
17833 Lisp_Object face
= Fplist_get (props
, Qface
);
17834 props
= Fcopy_sequence (props
);
17836 face
= mode_line_string_face
;
17838 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17839 props
= Fplist_put (props
, Qface
, face
);
17841 Fadd_text_properties (make_number (0), make_number (len
),
17842 props
, lisp_string
);
17846 len
= XFASTINT (Flength (lisp_string
));
17847 if (precision
> 0 && len
> precision
)
17850 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17853 if (!NILP (mode_line_string_face
))
17857 props
= Ftext_properties_at (make_number (0), lisp_string
);
17858 face
= Fplist_get (props
, Qface
);
17860 face
= mode_line_string_face
;
17862 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17863 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17865 lisp_string
= Fcopy_sequence (lisp_string
);
17868 Fadd_text_properties (make_number (0), make_number (len
),
17869 props
, lisp_string
);
17874 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17878 if (field_width
> len
)
17880 field_width
-= len
;
17881 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17883 Fadd_text_properties (make_number (0), make_number (field_width
),
17884 props
, lisp_string
);
17885 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17893 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17895 doc
: /* Format a string out of a mode line format specification.
17896 First arg FORMAT specifies the mode line format (see `mode-line-format'
17897 for details) to use.
17899 Optional second arg FACE specifies the face property to put
17900 on all characters for which no face is specified.
17901 The value t means whatever face the window's mode line currently uses
17902 \(either `mode-line' or `mode-line-inactive', depending).
17903 A value of nil means the default is no face property.
17904 If FACE is an integer, the value string has no text properties.
17906 Optional third and fourth args WINDOW and BUFFER specify the window
17907 and buffer to use as the context for the formatting (defaults
17908 are the selected window and the window's buffer). */)
17909 (format
, face
, window
, buffer
)
17910 Lisp_Object format
, face
, window
, buffer
;
17915 struct buffer
*old_buffer
= NULL
;
17917 int no_props
= INTEGERP (face
);
17918 int count
= SPECPDL_INDEX ();
17920 int string_start
= 0;
17923 window
= selected_window
;
17924 CHECK_WINDOW (window
);
17925 w
= XWINDOW (window
);
17928 buffer
= w
->buffer
;
17929 CHECK_BUFFER (buffer
);
17931 /* Make formatting the modeline a non-op when noninteractive, otherwise
17932 there will be problems later caused by a partially initialized frame. */
17933 if (NILP (format
) || noninteractive
)
17934 return empty_unibyte_string
;
17942 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17943 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17947 face_id
= DEFAULT_FACE_ID
;
17949 if (XBUFFER (buffer
) != current_buffer
)
17950 old_buffer
= current_buffer
;
17952 /* Save things including mode_line_proptrans_alist,
17953 and set that to nil so that we don't alter the outer value. */
17954 record_unwind_protect (unwind_format_mode_line
,
17955 format_mode_line_unwind_data
17956 (old_buffer
, selected_window
, 1));
17957 mode_line_proptrans_alist
= Qnil
;
17959 Fselect_window (window
, Qt
);
17961 set_buffer_internal_1 (XBUFFER (buffer
));
17963 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17967 mode_line_target
= MODE_LINE_NOPROP
;
17968 mode_line_string_face_prop
= Qnil
;
17969 mode_line_string_list
= Qnil
;
17970 string_start
= MODE_LINE_NOPROP_LEN (0);
17974 mode_line_target
= MODE_LINE_STRING
;
17975 mode_line_string_list
= Qnil
;
17976 mode_line_string_face
= face
;
17977 mode_line_string_face_prop
17978 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17981 push_kboard (FRAME_KBOARD (it
.f
));
17982 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17987 len
= MODE_LINE_NOPROP_LEN (string_start
);
17988 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17992 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17993 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17994 empty_unibyte_string
);
17997 unbind_to (count
, Qnil
);
18001 /* Write a null-terminated, right justified decimal representation of
18002 the positive integer D to BUF using a minimal field width WIDTH. */
18005 pint2str (buf
, width
, d
)
18006 register char *buf
;
18007 register int width
;
18010 register char *p
= buf
;
18018 *p
++ = d
% 10 + '0';
18023 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18034 /* Write a null-terminated, right justified decimal and "human
18035 readable" representation of the nonnegative integer D to BUF using
18036 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18038 static const char power_letter
[] =
18052 pint2hrstr (buf
, width
, d
)
18057 /* We aim to represent the nonnegative integer D as
18058 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18061 /* -1 means: do not use TENTHS. */
18065 /* Length of QUOTIENT.TENTHS as a string. */
18071 if (1000 <= quotient
)
18073 /* Scale to the appropriate EXPONENT. */
18076 remainder
= quotient
% 1000;
18080 while (1000 <= quotient
);
18082 /* Round to nearest and decide whether to use TENTHS or not. */
18085 tenths
= remainder
/ 100;
18086 if (50 <= remainder
% 100)
18093 if (quotient
== 10)
18101 if (500 <= remainder
)
18103 if (quotient
< 999)
18114 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18115 if (tenths
== -1 && quotient
<= 99)
18122 p
= psuffix
= buf
+ max (width
, length
);
18124 /* Print EXPONENT. */
18126 *psuffix
++ = power_letter
[exponent
];
18129 /* Print TENTHS. */
18132 *--p
= '0' + tenths
;
18136 /* Print QUOTIENT. */
18139 int digit
= quotient
% 10;
18140 *--p
= '0' + digit
;
18142 while ((quotient
/= 10) != 0);
18144 /* Print leading spaces. */
18149 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18150 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18151 type of CODING_SYSTEM. Return updated pointer into BUF. */
18153 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18156 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18157 Lisp_Object coding_system
;
18158 register char *buf
;
18162 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18163 const unsigned char *eol_str
;
18165 /* The EOL conversion we are using. */
18166 Lisp_Object eoltype
;
18168 val
= CODING_SYSTEM_SPEC (coding_system
);
18171 if (!VECTORP (val
)) /* Not yet decided. */
18176 eoltype
= eol_mnemonic_undecided
;
18177 /* Don't mention EOL conversion if it isn't decided. */
18182 Lisp_Object eolvalue
;
18184 attrs
= AREF (val
, 0);
18185 eolvalue
= AREF (val
, 2);
18188 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18192 /* The EOL conversion that is normal on this system. */
18194 if (NILP (eolvalue
)) /* Not yet decided. */
18195 eoltype
= eol_mnemonic_undecided
;
18196 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18197 eoltype
= eol_mnemonic_undecided
;
18198 else /* eolvalue is Qunix, Qdos, or Qmac. */
18199 eoltype
= (EQ (eolvalue
, Qunix
)
18200 ? eol_mnemonic_unix
18201 : (EQ (eolvalue
, Qdos
) == 1
18202 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18208 /* Mention the EOL conversion if it is not the usual one. */
18209 if (STRINGP (eoltype
))
18211 eol_str
= SDATA (eoltype
);
18212 eol_str_len
= SBYTES (eoltype
);
18214 else if (CHARACTERP (eoltype
))
18216 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18217 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18222 eol_str
= invalid_eol_type
;
18223 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18225 bcopy (eol_str
, buf
, eol_str_len
);
18226 buf
+= eol_str_len
;
18232 /* Return a string for the output of a mode line %-spec for window W,
18233 generated by character C. PRECISION >= 0 means don't return a
18234 string longer than that value. FIELD_WIDTH > 0 means pad the
18235 string returned with spaces to that value. Return a Lisp string in
18236 *STRING if the resulting string is taken from that Lisp string.
18238 Note we operate on the current buffer for most purposes,
18239 the exception being w->base_line_pos. */
18241 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18244 decode_mode_spec (w
, c
, field_width
, precision
, string
)
18247 int field_width
, precision
;
18248 Lisp_Object
*string
;
18251 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18252 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18253 struct buffer
*b
= current_buffer
;
18261 if (!NILP (b
->read_only
))
18263 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18268 /* This differs from %* only for a modified read-only buffer. */
18269 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18271 if (!NILP (b
->read_only
))
18276 /* This differs from %* in ignoring read-only-ness. */
18277 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18289 if (command_loop_level
> 5)
18291 p
= decode_mode_spec_buf
;
18292 for (i
= 0; i
< command_loop_level
; i
++)
18295 return decode_mode_spec_buf
;
18303 if (command_loop_level
> 5)
18305 p
= decode_mode_spec_buf
;
18306 for (i
= 0; i
< command_loop_level
; i
++)
18309 return decode_mode_spec_buf
;
18316 /* Let lots_of_dashes be a string of infinite length. */
18317 if (mode_line_target
== MODE_LINE_NOPROP
||
18318 mode_line_target
== MODE_LINE_STRING
)
18320 if (field_width
<= 0
18321 || field_width
> sizeof (lots_of_dashes
))
18323 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18324 decode_mode_spec_buf
[i
] = '-';
18325 decode_mode_spec_buf
[i
] = '\0';
18326 return decode_mode_spec_buf
;
18329 return lots_of_dashes
;
18337 /* %c and %l are ignored in `frame-title-format'.
18338 (In redisplay_internal, the frame title is drawn _before_ the
18339 windows are updated, so the stuff which depends on actual
18340 window contents (such as %l) may fail to render properly, or
18341 even crash emacs.) */
18342 if (mode_line_target
== MODE_LINE_TITLE
)
18346 int col
= (int) current_column (); /* iftc */
18347 w
->column_number_displayed
= make_number (col
);
18348 pint2str (decode_mode_spec_buf
, field_width
, col
);
18349 return decode_mode_spec_buf
;
18353 #ifndef SYSTEM_MALLOC
18355 if (NILP (Vmemory_full
))
18358 return "!MEM FULL! ";
18365 /* %F displays the frame name. */
18366 if (!NILP (f
->title
))
18367 return (char *) SDATA (f
->title
);
18368 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18369 return (char *) SDATA (f
->name
);
18378 int size
= ZV
- BEGV
;
18379 pint2str (decode_mode_spec_buf
, field_width
, size
);
18380 return decode_mode_spec_buf
;
18385 int size
= ZV
- BEGV
;
18386 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18387 return decode_mode_spec_buf
;
18392 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18393 int topline
, nlines
, junk
, height
;
18395 /* %c and %l are ignored in `frame-title-format'. */
18396 if (mode_line_target
== MODE_LINE_TITLE
)
18399 startpos
= XMARKER (w
->start
)->charpos
;
18400 startpos_byte
= marker_byte_position (w
->start
);
18401 height
= WINDOW_TOTAL_LINES (w
);
18403 /* If we decided that this buffer isn't suitable for line numbers,
18404 don't forget that too fast. */
18405 if (EQ (w
->base_line_pos
, w
->buffer
))
18407 /* But do forget it, if the window shows a different buffer now. */
18408 else if (BUFFERP (w
->base_line_pos
))
18409 w
->base_line_pos
= Qnil
;
18411 /* If the buffer is very big, don't waste time. */
18412 if (INTEGERP (Vline_number_display_limit
)
18413 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18415 w
->base_line_pos
= Qnil
;
18416 w
->base_line_number
= Qnil
;
18420 if (INTEGERP (w
->base_line_number
)
18421 && INTEGERP (w
->base_line_pos
)
18422 && XFASTINT (w
->base_line_pos
) <= startpos
)
18424 line
= XFASTINT (w
->base_line_number
);
18425 linepos
= XFASTINT (w
->base_line_pos
);
18426 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18431 linepos
= BUF_BEGV (b
);
18432 linepos_byte
= BUF_BEGV_BYTE (b
);
18435 /* Count lines from base line to window start position. */
18436 nlines
= display_count_lines (linepos
, linepos_byte
,
18440 topline
= nlines
+ line
;
18442 /* Determine a new base line, if the old one is too close
18443 or too far away, or if we did not have one.
18444 "Too close" means it's plausible a scroll-down would
18445 go back past it. */
18446 if (startpos
== BUF_BEGV (b
))
18448 w
->base_line_number
= make_number (topline
);
18449 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18451 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18452 || linepos
== BUF_BEGV (b
))
18454 int limit
= BUF_BEGV (b
);
18455 int limit_byte
= BUF_BEGV_BYTE (b
);
18457 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18459 if (startpos
- distance
> limit
)
18461 limit
= startpos
- distance
;
18462 limit_byte
= CHAR_TO_BYTE (limit
);
18465 nlines
= display_count_lines (startpos
, startpos_byte
,
18467 - (height
* 2 + 30),
18469 /* If we couldn't find the lines we wanted within
18470 line_number_display_limit_width chars per line,
18471 give up on line numbers for this window. */
18472 if (position
== limit_byte
&& limit
== startpos
- distance
)
18474 w
->base_line_pos
= w
->buffer
;
18475 w
->base_line_number
= Qnil
;
18479 w
->base_line_number
= make_number (topline
- nlines
);
18480 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18483 /* Now count lines from the start pos to point. */
18484 nlines
= display_count_lines (startpos
, startpos_byte
,
18485 PT_BYTE
, PT
, &junk
);
18487 /* Record that we did display the line number. */
18488 line_number_displayed
= 1;
18490 /* Make the string to show. */
18491 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18492 return decode_mode_spec_buf
;
18495 char* p
= decode_mode_spec_buf
;
18496 int pad
= field_width
- 2;
18502 return decode_mode_spec_buf
;
18508 obj
= b
->mode_name
;
18512 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18518 int pos
= marker_position (w
->start
);
18519 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18521 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18523 if (pos
<= BUF_BEGV (b
))
18528 else if (pos
<= BUF_BEGV (b
))
18532 if (total
> 1000000)
18533 /* Do it differently for a large value, to avoid overflow. */
18534 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18536 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18537 /* We can't normally display a 3-digit number,
18538 so get us a 2-digit number that is close. */
18541 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18542 return decode_mode_spec_buf
;
18546 /* Display percentage of size above the bottom of the screen. */
18549 int toppos
= marker_position (w
->start
);
18550 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18551 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18553 if (botpos
>= BUF_ZV (b
))
18555 if (toppos
<= BUF_BEGV (b
))
18562 if (total
> 1000000)
18563 /* Do it differently for a large value, to avoid overflow. */
18564 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18566 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18567 /* We can't normally display a 3-digit number,
18568 so get us a 2-digit number that is close. */
18571 if (toppos
<= BUF_BEGV (b
))
18572 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18574 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18575 return decode_mode_spec_buf
;
18580 /* status of process */
18581 obj
= Fget_buffer_process (Fcurrent_buffer ());
18583 return "no process";
18584 #ifdef subprocesses
18585 obj
= Fsymbol_name (Fprocess_status (obj
));
18591 int count
= inhibit_garbage_collection ();
18592 Lisp_Object val
= call1 (intern ("file-remote-p"),
18593 current_buffer
->directory
);
18594 unbind_to (count
, Qnil
);
18602 case 't': /* indicate TEXT or BINARY */
18603 #ifdef MODE_LINE_BINARY_TEXT
18604 return MODE_LINE_BINARY_TEXT (b
);
18610 /* coding-system (not including end-of-line format) */
18612 /* coding-system (including end-of-line type) */
18614 int eol_flag
= (c
== 'Z');
18615 char *p
= decode_mode_spec_buf
;
18617 if (! FRAME_WINDOW_P (f
))
18619 /* No need to mention EOL here--the terminal never needs
18620 to do EOL conversion. */
18621 p
= decode_mode_spec_coding (CODING_ID_NAME
18622 (FRAME_KEYBOARD_CODING (f
)->id
),
18624 p
= decode_mode_spec_coding (CODING_ID_NAME
18625 (FRAME_TERMINAL_CODING (f
)->id
),
18628 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18631 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18632 #ifdef subprocesses
18633 obj
= Fget_buffer_process (Fcurrent_buffer ());
18634 if (PROCESSP (obj
))
18636 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18638 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18641 #endif /* subprocesses */
18644 return decode_mode_spec_buf
;
18651 return (char *) SDATA (obj
);
18658 /* Count up to COUNT lines starting from START / START_BYTE.
18659 But don't go beyond LIMIT_BYTE.
18660 Return the number of lines thus found (always nonnegative).
18662 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18665 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18666 int start
, start_byte
, limit_byte
, count
;
18669 register unsigned char *cursor
;
18670 unsigned char *base
;
18672 register int ceiling
;
18673 register unsigned char *ceiling_addr
;
18674 int orig_count
= count
;
18676 /* If we are not in selective display mode,
18677 check only for newlines. */
18678 int selective_display
= (!NILP (current_buffer
->selective_display
)
18679 && !INTEGERP (current_buffer
->selective_display
));
18683 while (start_byte
< limit_byte
)
18685 ceiling
= BUFFER_CEILING_OF (start_byte
);
18686 ceiling
= min (limit_byte
- 1, ceiling
);
18687 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18688 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18691 if (selective_display
)
18692 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18695 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18698 if (cursor
!= ceiling_addr
)
18702 start_byte
+= cursor
- base
+ 1;
18703 *byte_pos_ptr
= start_byte
;
18707 if (++cursor
== ceiling_addr
)
18713 start_byte
+= cursor
- base
;
18718 while (start_byte
> limit_byte
)
18720 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18721 ceiling
= max (limit_byte
, ceiling
);
18722 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18723 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18726 if (selective_display
)
18727 while (--cursor
!= ceiling_addr
18728 && *cursor
!= '\n' && *cursor
!= 015)
18731 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18734 if (cursor
!= ceiling_addr
)
18738 start_byte
+= cursor
- base
+ 1;
18739 *byte_pos_ptr
= start_byte
;
18740 /* When scanning backwards, we should
18741 not count the newline posterior to which we stop. */
18742 return - orig_count
- 1;
18748 /* Here we add 1 to compensate for the last decrement
18749 of CURSOR, which took it past the valid range. */
18750 start_byte
+= cursor
- base
+ 1;
18754 *byte_pos_ptr
= limit_byte
;
18757 return - orig_count
+ count
;
18758 return orig_count
- count
;
18764 /***********************************************************************
18766 ***********************************************************************/
18768 /* Display a NUL-terminated string, starting with index START.
18770 If STRING is non-null, display that C string. Otherwise, the Lisp
18771 string LISP_STRING is displayed. There's a case that STRING is
18772 non-null and LISP_STRING is not nil. It means STRING is a string
18773 data of LISP_STRING. In that case, we display LISP_STRING while
18774 ignoring its text properties.
18776 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18777 FACE_STRING. Display STRING or LISP_STRING with the face at
18778 FACE_STRING_POS in FACE_STRING:
18780 Display the string in the environment given by IT, but use the
18781 standard display table, temporarily.
18783 FIELD_WIDTH is the minimum number of output glyphs to produce.
18784 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18785 with spaces. If STRING has more characters, more than FIELD_WIDTH
18786 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18788 PRECISION is the maximum number of characters to output from
18789 STRING. PRECISION < 0 means don't truncate the string.
18791 This is roughly equivalent to printf format specifiers:
18793 FIELD_WIDTH PRECISION PRINTF
18794 ----------------------------------------
18800 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18801 display them, and < 0 means obey the current buffer's value of
18802 enable_multibyte_characters.
18804 Value is the number of columns displayed. */
18807 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18808 start
, it
, field_width
, precision
, max_x
, multibyte
)
18809 unsigned char *string
;
18810 Lisp_Object lisp_string
;
18811 Lisp_Object face_string
;
18812 EMACS_INT face_string_pos
;
18815 int field_width
, precision
, max_x
;
18818 int hpos_at_start
= it
->hpos
;
18819 int saved_face_id
= it
->face_id
;
18820 struct glyph_row
*row
= it
->glyph_row
;
18822 /* Initialize the iterator IT for iteration over STRING beginning
18823 with index START. */
18824 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
18825 precision
, field_width
, multibyte
);
18826 if (string
&& STRINGP (lisp_string
))
18827 /* LISP_STRING is the one returned by decode_mode_spec. We should
18828 ignore its text properties. */
18829 it
->stop_charpos
= -1;
18831 /* If displaying STRING, set up the face of the iterator
18832 from LISP_STRING, if that's given. */
18833 if (STRINGP (face_string
))
18839 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18840 0, it
->region_beg_charpos
,
18841 it
->region_end_charpos
,
18842 &endptr
, it
->base_face_id
, 0);
18843 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18844 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18847 /* Set max_x to the maximum allowed X position. Don't let it go
18848 beyond the right edge of the window. */
18850 max_x
= it
->last_visible_x
;
18852 max_x
= min (max_x
, it
->last_visible_x
);
18854 /* Skip over display elements that are not visible. because IT->w is
18856 if (it
->current_x
< it
->first_visible_x
)
18857 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18858 MOVE_TO_POS
| MOVE_TO_X
);
18860 row
->ascent
= it
->max_ascent
;
18861 row
->height
= it
->max_ascent
+ it
->max_descent
;
18862 row
->phys_ascent
= it
->max_phys_ascent
;
18863 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18864 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18866 /* This condition is for the case that we are called with current_x
18867 past last_visible_x. */
18868 while (it
->current_x
< max_x
)
18870 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18872 /* Get the next display element. */
18873 if (!get_next_display_element (it
))
18876 /* Produce glyphs. */
18877 x_before
= it
->current_x
;
18878 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18879 PRODUCE_GLYPHS (it
);
18881 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18884 while (i
< nglyphs
)
18886 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18888 if (it
->line_wrap
!= TRUNCATE
18889 && x
+ glyph
->pixel_width
> max_x
)
18891 /* End of continued line or max_x reached. */
18892 if (CHAR_GLYPH_PADDING_P (*glyph
))
18894 /* A wide character is unbreakable. */
18895 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18896 it
->current_x
= x_before
;
18900 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18905 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18907 /* Glyph is at least partially visible. */
18909 if (x
< it
->first_visible_x
)
18910 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18914 /* Glyph is off the left margin of the display area.
18915 Should not happen. */
18919 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18920 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18921 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18922 row
->phys_height
= max (row
->phys_height
,
18923 it
->max_phys_ascent
+ it
->max_phys_descent
);
18924 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18925 it
->max_extra_line_spacing
);
18926 x
+= glyph
->pixel_width
;
18930 /* Stop if max_x reached. */
18934 /* Stop at line ends. */
18935 if (ITERATOR_AT_END_OF_LINE_P (it
))
18937 it
->continuation_lines_width
= 0;
18941 set_iterator_to_next (it
, 1);
18943 /* Stop if truncating at the right edge. */
18944 if (it
->line_wrap
== TRUNCATE
18945 && it
->current_x
>= it
->last_visible_x
)
18947 /* Add truncation mark, but don't do it if the line is
18948 truncated at a padding space. */
18949 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18951 if (!FRAME_WINDOW_P (it
->f
))
18955 if (it
->current_x
> it
->last_visible_x
)
18957 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18958 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18960 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18962 row
->used
[TEXT_AREA
] = i
;
18963 produce_special_glyphs (it
, IT_TRUNCATION
);
18966 produce_special_glyphs (it
, IT_TRUNCATION
);
18968 it
->glyph_row
->truncated_on_right_p
= 1;
18974 /* Maybe insert a truncation at the left. */
18975 if (it
->first_visible_x
18976 && IT_CHARPOS (*it
) > 0)
18978 if (!FRAME_WINDOW_P (it
->f
))
18979 insert_left_trunc_glyphs (it
);
18980 it
->glyph_row
->truncated_on_left_p
= 1;
18983 it
->face_id
= saved_face_id
;
18985 /* Value is number of columns displayed. */
18986 return it
->hpos
- hpos_at_start
;
18991 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18992 appears as an element of LIST or as the car of an element of LIST.
18993 If PROPVAL is a list, compare each element against LIST in that
18994 way, and return 1/2 if any element of PROPVAL is found in LIST.
18995 Otherwise return 0. This function cannot quit.
18996 The return value is 2 if the text is invisible but with an ellipsis
18997 and 1 if it's invisible and without an ellipsis. */
19000 invisible_p (propval
, list
)
19001 register Lisp_Object propval
;
19004 register Lisp_Object tail
, proptail
;
19006 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19008 register Lisp_Object tem
;
19010 if (EQ (propval
, tem
))
19012 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19013 return NILP (XCDR (tem
)) ? 1 : 2;
19016 if (CONSP (propval
))
19018 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19020 Lisp_Object propelt
;
19021 propelt
= XCAR (proptail
);
19022 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19024 register Lisp_Object tem
;
19026 if (EQ (propelt
, tem
))
19028 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19029 return NILP (XCDR (tem
)) ? 1 : 2;
19037 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19038 doc
: /* Non-nil if the property makes the text invisible.
19039 POS-OR-PROP can be a marker or number, in which case it is taken to be
19040 a position in the current buffer and the value of the `invisible' property
19041 is checked; or it can be some other value, which is then presumed to be the
19042 value of the `invisible' property of the text of interest.
19043 The non-nil value returned can be t for truly invisible text or something
19044 else if the text is replaced by an ellipsis. */)
19046 Lisp_Object pos_or_prop
;
19049 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19050 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19052 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19053 return (invis
== 0 ? Qnil
19055 : make_number (invis
));
19058 /* Calculate a width or height in pixels from a specification using
19059 the following elements:
19062 NUM - a (fractional) multiple of the default font width/height
19063 (NUM) - specifies exactly NUM pixels
19064 UNIT - a fixed number of pixels, see below.
19065 ELEMENT - size of a display element in pixels, see below.
19066 (NUM . SPEC) - equals NUM * SPEC
19067 (+ SPEC SPEC ...) - add pixel values
19068 (- SPEC SPEC ...) - subtract pixel values
19069 (- SPEC) - negate pixel value
19072 INT or FLOAT - a number constant
19073 SYMBOL - use symbol's (buffer local) variable binding.
19076 in - pixels per inch *)
19077 mm - pixels per 1/1000 meter *)
19078 cm - pixels per 1/100 meter *)
19079 width - width of current font in pixels.
19080 height - height of current font in pixels.
19082 *) using the ratio(s) defined in display-pixels-per-inch.
19086 left-fringe - left fringe width in pixels
19087 right-fringe - right fringe width in pixels
19089 left-margin - left margin width in pixels
19090 right-margin - right margin width in pixels
19092 scroll-bar - scroll-bar area width in pixels
19096 Pixels corresponding to 5 inches:
19099 Total width of non-text areas on left side of window (if scroll-bar is on left):
19100 '(space :width (+ left-fringe left-margin scroll-bar))
19102 Align to first text column (in header line):
19103 '(space :align-to 0)
19105 Align to middle of text area minus half the width of variable `my-image'
19106 containing a loaded image:
19107 '(space :align-to (0.5 . (- text my-image)))
19109 Width of left margin minus width of 1 character in the default font:
19110 '(space :width (- left-margin 1))
19112 Width of left margin minus width of 2 characters in the current font:
19113 '(space :width (- left-margin (2 . width)))
19115 Center 1 character over left-margin (in header line):
19116 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19118 Different ways to express width of left fringe plus left margin minus one pixel:
19119 '(space :width (- (+ left-fringe left-margin) (1)))
19120 '(space :width (+ left-fringe left-margin (- (1))))
19121 '(space :width (+ left-fringe left-margin (-1)))
19125 #define NUMVAL(X) \
19126 ((INTEGERP (X) || FLOATP (X)) \
19131 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19136 int width_p
, *align_to
;
19140 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19141 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19144 return OK_PIXELS (0);
19146 xassert (FRAME_LIVE_P (it
->f
));
19148 if (SYMBOLP (prop
))
19150 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19152 char *unit
= SDATA (SYMBOL_NAME (prop
));
19154 if (unit
[0] == 'i' && unit
[1] == 'n')
19156 else if (unit
[0] == 'm' && unit
[1] == 'm')
19158 else if (unit
[0] == 'c' && unit
[1] == 'm')
19165 #ifdef HAVE_WINDOW_SYSTEM
19166 if (FRAME_WINDOW_P (it
->f
)
19168 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19169 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19171 return OK_PIXELS (ppi
/ pixels
);
19174 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19175 || (CONSP (Vdisplay_pixels_per_inch
)
19177 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19178 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19180 return OK_PIXELS (ppi
/ pixels
);
19186 #ifdef HAVE_WINDOW_SYSTEM
19187 if (EQ (prop
, Qheight
))
19188 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19189 if (EQ (prop
, Qwidth
))
19190 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19192 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19193 return OK_PIXELS (1);
19196 if (EQ (prop
, Qtext
))
19197 return OK_PIXELS (width_p
19198 ? window_box_width (it
->w
, TEXT_AREA
)
19199 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19201 if (align_to
&& *align_to
< 0)
19204 if (EQ (prop
, Qleft
))
19205 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19206 if (EQ (prop
, Qright
))
19207 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19208 if (EQ (prop
, Qcenter
))
19209 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19210 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19211 if (EQ (prop
, Qleft_fringe
))
19212 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19213 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19214 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19215 if (EQ (prop
, Qright_fringe
))
19216 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19217 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19218 : window_box_right_offset (it
->w
, TEXT_AREA
));
19219 if (EQ (prop
, Qleft_margin
))
19220 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19221 if (EQ (prop
, Qright_margin
))
19222 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19223 if (EQ (prop
, Qscroll_bar
))
19224 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19226 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19227 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19228 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19233 if (EQ (prop
, Qleft_fringe
))
19234 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19235 if (EQ (prop
, Qright_fringe
))
19236 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19237 if (EQ (prop
, Qleft_margin
))
19238 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19239 if (EQ (prop
, Qright_margin
))
19240 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19241 if (EQ (prop
, Qscroll_bar
))
19242 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19245 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19248 if (INTEGERP (prop
) || FLOATP (prop
))
19250 int base_unit
= (width_p
19251 ? FRAME_COLUMN_WIDTH (it
->f
)
19252 : FRAME_LINE_HEIGHT (it
->f
));
19253 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19258 Lisp_Object car
= XCAR (prop
);
19259 Lisp_Object cdr
= XCDR (prop
);
19263 #ifdef HAVE_WINDOW_SYSTEM
19264 if (FRAME_WINDOW_P (it
->f
)
19265 && valid_image_p (prop
))
19267 int id
= lookup_image (it
->f
, prop
);
19268 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19270 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19273 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19279 while (CONSP (cdr
))
19281 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19282 font
, width_p
, align_to
))
19285 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19290 if (EQ (car
, Qminus
))
19292 return OK_PIXELS (pixels
);
19295 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19298 if (INTEGERP (car
) || FLOATP (car
))
19301 pixels
= XFLOATINT (car
);
19303 return OK_PIXELS (pixels
);
19304 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19305 font
, width_p
, align_to
))
19306 return OK_PIXELS (pixels
* fact
);
19317 /***********************************************************************
19319 ***********************************************************************/
19321 #ifdef HAVE_WINDOW_SYSTEM
19326 dump_glyph_string (s
)
19327 struct glyph_string
*s
;
19329 fprintf (stderr
, "glyph string\n");
19330 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19331 s
->x
, s
->y
, s
->width
, s
->height
);
19332 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19333 fprintf (stderr
, " hl = %d\n", s
->hl
);
19334 fprintf (stderr
, " left overhang = %d, right = %d\n",
19335 s
->left_overhang
, s
->right_overhang
);
19336 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19337 fprintf (stderr
, " extends to end of line = %d\n",
19338 s
->extends_to_end_of_line_p
);
19339 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19340 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19343 #endif /* GLYPH_DEBUG */
19345 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19346 of XChar2b structures for S; it can't be allocated in
19347 init_glyph_string because it must be allocated via `alloca'. W
19348 is the window on which S is drawn. ROW and AREA are the glyph row
19349 and area within the row from which S is constructed. START is the
19350 index of the first glyph structure covered by S. HL is a
19351 face-override for drawing S. */
19354 #define OPTIONAL_HDC(hdc) hdc,
19355 #define DECLARE_HDC(hdc) HDC hdc;
19356 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19357 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19360 #ifndef OPTIONAL_HDC
19361 #define OPTIONAL_HDC(hdc)
19362 #define DECLARE_HDC(hdc)
19363 #define ALLOCATE_HDC(hdc, f)
19364 #define RELEASE_HDC(hdc, f)
19368 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19369 struct glyph_string
*s
;
19373 struct glyph_row
*row
;
19374 enum glyph_row_area area
;
19376 enum draw_glyphs_face hl
;
19378 bzero (s
, sizeof *s
);
19380 s
->f
= XFRAME (w
->frame
);
19384 s
->display
= FRAME_X_DISPLAY (s
->f
);
19385 s
->window
= FRAME_X_WINDOW (s
->f
);
19386 s
->char2b
= char2b
;
19390 s
->first_glyph
= row
->glyphs
[area
] + start
;
19391 s
->height
= row
->height
;
19392 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19393 s
->ybase
= s
->y
+ row
->ascent
;
19397 /* Append the list of glyph strings with head H and tail T to the list
19398 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19401 append_glyph_string_lists (head
, tail
, h
, t
)
19402 struct glyph_string
**head
, **tail
;
19403 struct glyph_string
*h
, *t
;
19417 /* Prepend the list of glyph strings with head H and tail T to the
19418 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19422 prepend_glyph_string_lists (head
, tail
, h
, t
)
19423 struct glyph_string
**head
, **tail
;
19424 struct glyph_string
*h
, *t
;
19438 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19439 Set *HEAD and *TAIL to the resulting list. */
19442 append_glyph_string (head
, tail
, s
)
19443 struct glyph_string
**head
, **tail
;
19444 struct glyph_string
*s
;
19446 s
->next
= s
->prev
= NULL
;
19447 append_glyph_string_lists (head
, tail
, s
, s
);
19451 /* Get face and two-byte form of character C in face FACE_ID on frame
19452 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19453 means we want to display multibyte text. DISPLAY_P non-zero means
19454 make sure that X resources for the face returned are allocated.
19455 Value is a pointer to a realized face that is ready for display if
19456 DISPLAY_P is non-zero. */
19458 static INLINE
struct face
*
19459 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19463 int multibyte_p
, display_p
;
19465 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19469 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19471 if (code
!= FONT_INVALID_CODE
)
19472 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19474 STORE_XCHAR2B (char2b
, 0, 0);
19477 /* Make sure X resources of the face are allocated. */
19478 #ifdef HAVE_X_WINDOWS
19482 xassert (face
!= NULL
);
19483 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19490 /* Get face and two-byte form of character glyph GLYPH on frame F.
19491 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19492 a pointer to a realized face that is ready for display. */
19494 static INLINE
struct face
*
19495 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19497 struct glyph
*glyph
;
19503 xassert (glyph
->type
== CHAR_GLYPH
);
19504 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19513 if (CHAR_BYTE8_P (glyph
->u
.ch
))
19514 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
19516 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19518 if (code
!= FONT_INVALID_CODE
)
19519 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19521 STORE_XCHAR2B (char2b
, 0, 0);
19524 /* Make sure X resources of the face are allocated. */
19525 xassert (face
!= NULL
);
19526 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19531 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
19532 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
19535 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
19539 if (CHAR_BYTE8_P (c
))
19540 code
= CHAR_TO_BYTE8 (c
);
19542 code
= font
->driver
->encode_char (font
, c
);
19544 if (code
== FONT_INVALID_CODE
)
19546 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19551 /* Fill glyph string S with composition components specified by S->cmp.
19553 BASE_FACE is the base face of the composition.
19554 S->cmp_from is the index of the first component for S.
19556 OVERLAPS non-zero means S should draw the foreground only, and use
19557 its physical height for clipping. See also draw_glyphs.
19559 Value is the index of a component not in S. */
19562 fill_composite_glyph_string (s
, base_face
, overlaps
)
19563 struct glyph_string
*s
;
19564 struct face
*base_face
;
19568 /* For all glyphs of this composition, starting at the offset
19569 S->cmp_from, until we reach the end of the definition or encounter a
19570 glyph that requires the different face, add it to S. */
19575 s
->for_overlaps
= overlaps
;
19578 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
19580 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19584 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19587 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19588 s
->char2b
+ i
, 1, 1);
19594 s
->font
= s
->face
->font
;
19596 else if (s
->face
!= face
)
19604 /* All glyph strings for the same composition has the same width,
19605 i.e. the width set for the first component of the composition. */
19606 s
->width
= s
->first_glyph
->pixel_width
;
19608 /* If the specified font could not be loaded, use the frame's
19609 default font, but record the fact that we couldn't load it in
19610 the glyph string so that we can draw rectangles for the
19611 characters of the glyph string. */
19612 if (s
->font
== NULL
)
19614 s
->font_not_found_p
= 1;
19615 s
->font
= FRAME_FONT (s
->f
);
19618 /* Adjust base line for subscript/superscript text. */
19619 s
->ybase
+= s
->first_glyph
->voffset
;
19621 /* This glyph string must always be drawn with 16-bit functions. */
19628 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
19629 struct glyph_string
*s
;
19631 int start
, end
, overlaps
;
19633 struct glyph
*glyph
, *last
;
19634 Lisp_Object lgstring
;
19637 s
->for_overlaps
= overlaps
;
19638 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19639 last
= s
->row
->glyphs
[s
->area
] + end
;
19640 s
->cmp_id
= glyph
->u
.cmp
.id
;
19641 s
->cmp_from
= glyph
->u
.cmp
.from
;
19642 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
19643 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19644 lgstring
= composition_gstring_from_id (s
->cmp_id
);
19645 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
19647 while (glyph
< last
19648 && glyph
->u
.cmp
.automatic
19649 && glyph
->u
.cmp
.id
== s
->cmp_id
19650 && s
->cmp_to
== glyph
->u
.cmp
.from
)
19651 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
19653 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
19655 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
19656 unsigned code
= LGLYPH_CODE (lglyph
);
19658 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
19660 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
19661 return glyph
- s
->row
->glyphs
[s
->area
];
19665 /* Fill glyph string S from a sequence of character glyphs.
19667 FACE_ID is the face id of the string. START is the index of the
19668 first glyph to consider, END is the index of the last + 1.
19669 OVERLAPS non-zero means S should draw the foreground only, and use
19670 its physical height for clipping. See also draw_glyphs.
19672 Value is the index of the first glyph not in S. */
19675 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19676 struct glyph_string
*s
;
19678 int start
, end
, overlaps
;
19680 struct glyph
*glyph
, *last
;
19682 int glyph_not_available_p
;
19684 xassert (s
->f
== XFRAME (s
->w
->frame
));
19685 xassert (s
->nchars
== 0);
19686 xassert (start
>= 0 && end
> start
);
19688 s
->for_overlaps
= overlaps
;
19689 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19690 last
= s
->row
->glyphs
[s
->area
] + end
;
19691 voffset
= glyph
->voffset
;
19692 s
->padding_p
= glyph
->padding_p
;
19693 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19695 while (glyph
< last
19696 && glyph
->type
== CHAR_GLYPH
19697 && glyph
->voffset
== voffset
19698 /* Same face id implies same font, nowadays. */
19699 && glyph
->face_id
== face_id
19700 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19704 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19705 s
->char2b
+ s
->nchars
,
19707 s
->two_byte_p
= two_byte_p
;
19709 xassert (s
->nchars
<= end
- start
);
19710 s
->width
+= glyph
->pixel_width
;
19711 if (glyph
++->padding_p
!= s
->padding_p
)
19715 s
->font
= s
->face
->font
;
19717 /* If the specified font could not be loaded, use the frame's font,
19718 but record the fact that we couldn't load it in
19719 S->font_not_found_p so that we can draw rectangles for the
19720 characters of the glyph string. */
19721 if (s
->font
== NULL
|| glyph_not_available_p
)
19723 s
->font_not_found_p
= 1;
19724 s
->font
= FRAME_FONT (s
->f
);
19727 /* Adjust base line for subscript/superscript text. */
19728 s
->ybase
+= voffset
;
19730 xassert (s
->face
&& s
->face
->gc
);
19731 return glyph
- s
->row
->glyphs
[s
->area
];
19735 /* Fill glyph string S from image glyph S->first_glyph. */
19738 fill_image_glyph_string (s
)
19739 struct glyph_string
*s
;
19741 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19742 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19744 s
->slice
= s
->first_glyph
->slice
;
19745 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19746 s
->font
= s
->face
->font
;
19747 s
->width
= s
->first_glyph
->pixel_width
;
19749 /* Adjust base line for subscript/superscript text. */
19750 s
->ybase
+= s
->first_glyph
->voffset
;
19754 /* Fill glyph string S from a sequence of stretch glyphs.
19756 ROW is the glyph row in which the glyphs are found, AREA is the
19757 area within the row. START is the index of the first glyph to
19758 consider, END is the index of the last + 1.
19760 Value is the index of the first glyph not in S. */
19763 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19764 struct glyph_string
*s
;
19765 struct glyph_row
*row
;
19766 enum glyph_row_area area
;
19769 struct glyph
*glyph
, *last
;
19770 int voffset
, face_id
;
19772 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19774 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19775 last
= s
->row
->glyphs
[s
->area
] + end
;
19776 face_id
= glyph
->face_id
;
19777 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19778 s
->font
= s
->face
->font
;
19779 s
->width
= glyph
->pixel_width
;
19781 voffset
= glyph
->voffset
;
19785 && glyph
->type
== STRETCH_GLYPH
19786 && glyph
->voffset
== voffset
19787 && glyph
->face_id
== face_id
);
19789 s
->width
+= glyph
->pixel_width
;
19791 /* Adjust base line for subscript/superscript text. */
19792 s
->ybase
+= voffset
;
19794 /* The case that face->gc == 0 is handled when drawing the glyph
19795 string by calling PREPARE_FACE_FOR_DISPLAY. */
19797 return glyph
- s
->row
->glyphs
[s
->area
];
19800 static struct font_metrics
*
19801 get_per_char_metric (f
, font
, char2b
)
19806 static struct font_metrics metrics
;
19807 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19809 if (! font
|| code
== FONT_INVALID_CODE
)
19811 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19816 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19817 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19818 assumed to be zero. */
19821 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19822 struct glyph
*glyph
;
19826 *left
= *right
= 0;
19828 if (glyph
->type
== CHAR_GLYPH
)
19832 struct font_metrics
*pcm
;
19834 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19835 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19837 if (pcm
->rbearing
> pcm
->width
)
19838 *right
= pcm
->rbearing
- pcm
->width
;
19839 if (pcm
->lbearing
< 0)
19840 *left
= -pcm
->lbearing
;
19843 else if (glyph
->type
== COMPOSITE_GLYPH
)
19845 if (! glyph
->u
.cmp
.automatic
)
19847 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
19849 if (cmp
->rbearing
> cmp
->pixel_width
)
19850 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19851 if (cmp
->lbearing
< 0)
19852 *left
= - cmp
->lbearing
;
19856 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
19857 struct font_metrics metrics
;
19859 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
19860 glyph
->u
.cmp
.to
+ 1, &metrics
);
19861 if (metrics
.rbearing
> metrics
.width
)
19862 *right
= metrics
.rbearing
- metrics
.width
;
19863 if (metrics
.lbearing
< 0)
19864 *left
= - metrics
.lbearing
;
19870 /* Return the index of the first glyph preceding glyph string S that
19871 is overwritten by S because of S's left overhang. Value is -1
19872 if no glyphs are overwritten. */
19875 left_overwritten (s
)
19876 struct glyph_string
*s
;
19880 if (s
->left_overhang
)
19883 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19884 int first
= s
->first_glyph
- glyphs
;
19886 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19887 x
-= glyphs
[i
].pixel_width
;
19898 /* Return the index of the first glyph preceding glyph string S that
19899 is overwriting S because of its right overhang. Value is -1 if no
19900 glyph in front of S overwrites S. */
19903 left_overwriting (s
)
19904 struct glyph_string
*s
;
19907 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19908 int first
= s
->first_glyph
- glyphs
;
19912 for (i
= first
- 1; i
>= 0; --i
)
19915 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19918 x
-= glyphs
[i
].pixel_width
;
19925 /* Return the index of the last glyph following glyph string S that is
19926 overwritten by S because of S's right overhang. Value is -1 if
19927 no such glyph is found. */
19930 right_overwritten (s
)
19931 struct glyph_string
*s
;
19935 if (s
->right_overhang
)
19938 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19939 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19940 int end
= s
->row
->used
[s
->area
];
19942 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19943 x
+= glyphs
[i
].pixel_width
;
19952 /* Return the index of the last glyph following glyph string S that
19953 overwrites S because of its left overhang. Value is negative
19954 if no such glyph is found. */
19957 right_overwriting (s
)
19958 struct glyph_string
*s
;
19961 int end
= s
->row
->used
[s
->area
];
19962 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19963 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19967 for (i
= first
; i
< end
; ++i
)
19970 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19973 x
+= glyphs
[i
].pixel_width
;
19980 /* Set background width of glyph string S. START is the index of the
19981 first glyph following S. LAST_X is the right-most x-position + 1
19982 in the drawing area. */
19985 set_glyph_string_background_width (s
, start
, last_x
)
19986 struct glyph_string
*s
;
19990 /* If the face of this glyph string has to be drawn to the end of
19991 the drawing area, set S->extends_to_end_of_line_p. */
19993 if (start
== s
->row
->used
[s
->area
]
19994 && s
->area
== TEXT_AREA
19995 && ((s
->row
->fill_line_p
19996 && (s
->hl
== DRAW_NORMAL_TEXT
19997 || s
->hl
== DRAW_IMAGE_RAISED
19998 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19999 || s
->hl
== DRAW_MOUSE_FACE
))
20000 s
->extends_to_end_of_line_p
= 1;
20002 /* If S extends its face to the end of the line, set its
20003 background_width to the distance to the right edge of the drawing
20005 if (s
->extends_to_end_of_line_p
)
20006 s
->background_width
= last_x
- s
->x
+ 1;
20008 s
->background_width
= s
->width
;
20012 /* Compute overhangs and x-positions for glyph string S and its
20013 predecessors, or successors. X is the starting x-position for S.
20014 BACKWARD_P non-zero means process predecessors. */
20017 compute_overhangs_and_x (s
, x
, backward_p
)
20018 struct glyph_string
*s
;
20026 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20027 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20037 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20038 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20048 /* The following macros are only called from draw_glyphs below.
20049 They reference the following parameters of that function directly:
20050 `w', `row', `area', and `overlap_p'
20051 as well as the following local variables:
20052 `s', `f', and `hdc' (in W32) */
20055 /* On W32, silently add local `hdc' variable to argument list of
20056 init_glyph_string. */
20057 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20058 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20060 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20061 init_glyph_string (s, char2b, w, row, area, start, hl)
20064 /* Add a glyph string for a stretch glyph to the list of strings
20065 between HEAD and TAIL. START is the index of the stretch glyph in
20066 row area AREA of glyph row ROW. END is the index of the last glyph
20067 in that glyph row area. X is the current output position assigned
20068 to the new glyph string constructed. HL overrides that face of the
20069 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20070 is the right-most x-position of the drawing area. */
20072 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20073 and below -- keep them on one line. */
20074 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20077 s = (struct glyph_string *) alloca (sizeof *s); \
20078 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20079 START = fill_stretch_glyph_string (s, row, area, START, END); \
20080 append_glyph_string (&HEAD, &TAIL, s); \
20086 /* Add a glyph string for an image glyph to the list of strings
20087 between HEAD and TAIL. START is the index of the image glyph in
20088 row area AREA of glyph row ROW. END is the index of the last glyph
20089 in that glyph row area. X is the current output position assigned
20090 to the new glyph string constructed. HL overrides that face of the
20091 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20092 is the right-most x-position of the drawing area. */
20094 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20097 s = (struct glyph_string *) alloca (sizeof *s); \
20098 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20099 fill_image_glyph_string (s); \
20100 append_glyph_string (&HEAD, &TAIL, s); \
20107 /* Add a glyph string for a sequence of character glyphs to the list
20108 of strings between HEAD and TAIL. START is the index of the first
20109 glyph in row area AREA of glyph row ROW that is part of the new
20110 glyph string. END is the index of the last glyph in that glyph row
20111 area. X is the current output position assigned to the new glyph
20112 string constructed. HL overrides that face of the glyph; e.g. it
20113 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20114 right-most x-position of the drawing area. */
20116 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20122 face_id = (row)->glyphs[area][START].face_id; \
20124 s = (struct glyph_string *) alloca (sizeof *s); \
20125 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20126 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20127 append_glyph_string (&HEAD, &TAIL, s); \
20129 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20134 /* Add a glyph string for a composite sequence to the list of strings
20135 between HEAD and TAIL. START is the index of the first glyph in
20136 row area AREA of glyph row ROW that is part of the new glyph
20137 string. END is the index of the last glyph in that glyph row area.
20138 X is the current output position assigned to the new glyph string
20139 constructed. HL overrides that face of the glyph; e.g. it is
20140 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20141 x-position of the drawing area. */
20143 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20145 int face_id = (row)->glyphs[area][START].face_id; \
20146 struct face *base_face = FACE_FROM_ID (f, face_id); \
20147 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20148 struct composition *cmp = composition_table[cmp_id]; \
20150 struct glyph_string *first_s; \
20153 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20155 /* Make glyph_strings for each glyph sequence that is drawable by \
20156 the same face, and append them to HEAD/TAIL. */ \
20157 for (n = 0; n < cmp->glyph_len;) \
20159 s = (struct glyph_string *) alloca (sizeof *s); \
20160 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20161 append_glyph_string (&(HEAD), &(TAIL), s); \
20167 n = fill_composite_glyph_string (s, base_face, overlaps); \
20175 /* Add a glyph string for a glyph-string sequence to the list of strings
20176 between HEAD and TAIL. */
20178 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20182 Lisp_Object gstring; \
20184 face_id = (row)->glyphs[area][START].face_id; \
20185 gstring = (composition_gstring_from_id \
20186 ((row)->glyphs[area][START].u.cmp.id)); \
20187 s = (struct glyph_string *) alloca (sizeof *s); \
20188 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20189 * LGSTRING_GLYPH_LEN (gstring)); \
20190 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20191 append_glyph_string (&(HEAD), &(TAIL), s); \
20193 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20197 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20198 of AREA of glyph row ROW on window W between indices START and END.
20199 HL overrides the face for drawing glyph strings, e.g. it is
20200 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20201 x-positions of the drawing area.
20203 This is an ugly monster macro construct because we must use alloca
20204 to allocate glyph strings (because draw_glyphs can be called
20205 asynchronously). */
20207 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20210 HEAD = TAIL = NULL; \
20211 while (START < END) \
20213 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20214 switch (first_glyph->type) \
20217 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20221 case COMPOSITE_GLYPH: \
20222 if (first_glyph->u.cmp.automatic) \
20223 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20226 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20230 case STRETCH_GLYPH: \
20231 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20235 case IMAGE_GLYPH: \
20236 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20246 set_glyph_string_background_width (s, START, LAST_X); \
20253 /* Draw glyphs between START and END in AREA of ROW on window W,
20254 starting at x-position X. X is relative to AREA in W. HL is a
20255 face-override with the following meaning:
20257 DRAW_NORMAL_TEXT draw normally
20258 DRAW_CURSOR draw in cursor face
20259 DRAW_MOUSE_FACE draw in mouse face.
20260 DRAW_INVERSE_VIDEO draw in mode line face
20261 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20262 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20264 If OVERLAPS is non-zero, draw only the foreground of characters and
20265 clip to the physical height of ROW. Non-zero value also defines
20266 the overlapping part to be drawn:
20268 OVERLAPS_PRED overlap with preceding rows
20269 OVERLAPS_SUCC overlap with succeeding rows
20270 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20271 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20273 Value is the x-position reached, relative to AREA of W. */
20276 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20279 struct glyph_row
*row
;
20280 enum glyph_row_area area
;
20281 EMACS_INT start
, end
;
20282 enum draw_glyphs_face hl
;
20285 struct glyph_string
*head
, *tail
;
20286 struct glyph_string
*s
;
20287 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20288 int i
, j
, x_reached
, last_x
, area_left
= 0;
20289 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20292 ALLOCATE_HDC (hdc
, f
);
20294 /* Let's rather be paranoid than getting a SEGV. */
20295 end
= min (end
, row
->used
[area
]);
20296 start
= max (0, start
);
20297 start
= min (end
, start
);
20299 /* Translate X to frame coordinates. Set last_x to the right
20300 end of the drawing area. */
20301 if (row
->full_width_p
)
20303 /* X is relative to the left edge of W, without scroll bars
20305 area_left
= WINDOW_LEFT_EDGE_X (w
);
20306 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20310 area_left
= window_box_left (w
, area
);
20311 last_x
= area_left
+ window_box_width (w
, area
);
20315 /* Build a doubly-linked list of glyph_string structures between
20316 head and tail from what we have to draw. Note that the macro
20317 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20318 the reason we use a separate variable `i'. */
20320 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20322 x_reached
= tail
->x
+ tail
->background_width
;
20326 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20327 the row, redraw some glyphs in front or following the glyph
20328 strings built above. */
20329 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20331 struct glyph_string
*h
, *t
;
20332 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20333 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20336 /* If mouse highlighting is on, we may need to draw adjacent
20337 glyphs using mouse-face highlighting. */
20338 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20340 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20342 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20343 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20345 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20347 check_mouse_face
= 1;
20348 mouse_beg_col
= (row
== mouse_beg_row
)
20349 ? dpyinfo
->mouse_face_beg_col
: 0;
20350 mouse_end_col
= (row
== mouse_end_row
)
20351 ? dpyinfo
->mouse_face_end_col
20352 : row
->used
[TEXT_AREA
];
20356 /* Compute overhangs for all glyph strings. */
20357 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20358 for (s
= head
; s
; s
= s
->next
)
20359 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20361 /* Prepend glyph strings for glyphs in front of the first glyph
20362 string that are overwritten because of the first glyph
20363 string's left overhang. The background of all strings
20364 prepended must be drawn because the first glyph string
20366 i
= left_overwritten (head
);
20369 enum draw_glyphs_face overlap_hl
;
20371 /* If this row contains mouse highlighting, attempt to draw
20372 the overlapped glyphs with the correct highlight. This
20373 code fails if the overlap encompasses more than one glyph
20374 and mouse-highlight spans only some of these glyphs.
20375 However, making it work perfectly involves a lot more
20376 code, and I don't know if the pathological case occurs in
20377 practice, so we'll stick to this for now. --- cyd */
20378 if (check_mouse_face
20379 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20380 overlap_hl
= DRAW_MOUSE_FACE
;
20382 overlap_hl
= DRAW_NORMAL_TEXT
;
20385 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20386 overlap_hl
, dummy_x
, last_x
);
20388 compute_overhangs_and_x (t
, head
->x
, 1);
20389 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20393 /* Prepend glyph strings for glyphs in front of the first glyph
20394 string that overwrite that glyph string because of their
20395 right overhang. For these strings, only the foreground must
20396 be drawn, because it draws over the glyph string at `head'.
20397 The background must not be drawn because this would overwrite
20398 right overhangs of preceding glyphs for which no glyph
20400 i
= left_overwriting (head
);
20403 enum draw_glyphs_face overlap_hl
;
20405 if (check_mouse_face
20406 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20407 overlap_hl
= DRAW_MOUSE_FACE
;
20409 overlap_hl
= DRAW_NORMAL_TEXT
;
20412 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20413 overlap_hl
, dummy_x
, last_x
);
20414 for (s
= h
; s
; s
= s
->next
)
20415 s
->background_filled_p
= 1;
20416 compute_overhangs_and_x (t
, head
->x
, 1);
20417 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20420 /* Append glyphs strings for glyphs following the last glyph
20421 string tail that are overwritten by tail. The background of
20422 these strings has to be drawn because tail's foreground draws
20424 i
= right_overwritten (tail
);
20427 enum draw_glyphs_face overlap_hl
;
20429 if (check_mouse_face
20430 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20431 overlap_hl
= DRAW_MOUSE_FACE
;
20433 overlap_hl
= DRAW_NORMAL_TEXT
;
20435 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20436 overlap_hl
, x
, last_x
);
20437 /* Because BUILD_GLYPH_STRINGS updates the first argument,
20438 we don't have `end = i;' here. */
20439 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20440 append_glyph_string_lists (&head
, &tail
, h
, t
);
20444 /* Append glyph strings for glyphs following the last glyph
20445 string tail that overwrite tail. The foreground of such
20446 glyphs has to be drawn because it writes into the background
20447 of tail. The background must not be drawn because it could
20448 paint over the foreground of following glyphs. */
20449 i
= right_overwriting (tail
);
20452 enum draw_glyphs_face overlap_hl
;
20453 if (check_mouse_face
20454 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20455 overlap_hl
= DRAW_MOUSE_FACE
;
20457 overlap_hl
= DRAW_NORMAL_TEXT
;
20460 i
++; /* We must include the Ith glyph. */
20461 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20462 overlap_hl
, x
, last_x
);
20463 for (s
= h
; s
; s
= s
->next
)
20464 s
->background_filled_p
= 1;
20465 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20466 append_glyph_string_lists (&head
, &tail
, h
, t
);
20468 if (clip_head
|| clip_tail
)
20469 for (s
= head
; s
; s
= s
->next
)
20471 s
->clip_head
= clip_head
;
20472 s
->clip_tail
= clip_tail
;
20476 /* Draw all strings. */
20477 for (s
= head
; s
; s
= s
->next
)
20478 FRAME_RIF (f
)->draw_glyph_string (s
);
20481 /* When focus a sole frame and move horizontally, this sets on_p to 0
20482 causing a failure to erase prev cursor position. */
20483 if (area
== TEXT_AREA
20484 && !row
->full_width_p
20485 /* When drawing overlapping rows, only the glyph strings'
20486 foreground is drawn, which doesn't erase a cursor
20490 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20491 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20492 : (tail
? tail
->x
+ tail
->background_width
: x
));
20496 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20497 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20501 /* Value is the x-position up to which drawn, relative to AREA of W.
20502 This doesn't include parts drawn because of overhangs. */
20503 if (row
->full_width_p
)
20504 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20506 x_reached
-= area_left
;
20508 RELEASE_HDC (hdc
, f
);
20513 /* Expand row matrix if too narrow. Don't expand if area
20516 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20518 if (!fonts_changed_p \
20519 && (it->glyph_row->glyphs[area] \
20520 < it->glyph_row->glyphs[area + 1])) \
20522 it->w->ncols_scale_factor++; \
20523 fonts_changed_p = 1; \
20527 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20528 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20534 struct glyph
*glyph
;
20535 enum glyph_row_area area
= it
->area
;
20537 xassert (it
->glyph_row
);
20538 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20540 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20541 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20543 glyph
->charpos
= CHARPOS (it
->position
);
20544 glyph
->object
= it
->object
;
20545 if (it
->pixel_width
> 0)
20547 glyph
->pixel_width
= it
->pixel_width
;
20548 glyph
->padding_p
= 0;
20552 /* Assure at least 1-pixel width. Otherwise, cursor can't
20553 be displayed correctly. */
20554 glyph
->pixel_width
= 1;
20555 glyph
->padding_p
= 1;
20557 glyph
->ascent
= it
->ascent
;
20558 glyph
->descent
= it
->descent
;
20559 glyph
->voffset
= it
->voffset
;
20560 glyph
->type
= CHAR_GLYPH
;
20561 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20562 glyph
->multibyte_p
= it
->multibyte_p
;
20563 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20564 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20565 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20566 || it
->phys_descent
> it
->descent
);
20567 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20568 glyph
->face_id
= it
->face_id
;
20569 glyph
->u
.ch
= it
->char_to_display
;
20570 glyph
->slice
= null_glyph_slice
;
20571 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20572 ++it
->glyph_row
->used
[area
];
20575 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20578 /* Store one glyph for the composition IT->cmp_it.id in
20579 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
20583 append_composite_glyph (it
)
20586 struct glyph
*glyph
;
20587 enum glyph_row_area area
= it
->area
;
20589 xassert (it
->glyph_row
);
20591 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20592 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20594 glyph
->charpos
= CHARPOS (it
->position
);
20595 glyph
->object
= it
->object
;
20596 glyph
->pixel_width
= it
->pixel_width
;
20597 glyph
->ascent
= it
->ascent
;
20598 glyph
->descent
= it
->descent
;
20599 glyph
->voffset
= it
->voffset
;
20600 glyph
->type
= COMPOSITE_GLYPH
;
20601 if (it
->cmp_it
.ch
< 0)
20603 glyph
->u
.cmp
.automatic
= 0;
20604 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20608 glyph
->u
.cmp
.automatic
= 1;
20609 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20610 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
20611 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
20613 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20614 glyph
->multibyte_p
= it
->multibyte_p
;
20615 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20616 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20617 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20618 || it
->phys_descent
> it
->descent
);
20619 glyph
->padding_p
= 0;
20620 glyph
->glyph_not_available_p
= 0;
20621 glyph
->face_id
= it
->face_id
;
20622 glyph
->slice
= null_glyph_slice
;
20623 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20624 ++it
->glyph_row
->used
[area
];
20627 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20631 /* Change IT->ascent and IT->height according to the setting of
20635 take_vertical_position_into_account (it
)
20640 if (it
->voffset
< 0)
20641 /* Increase the ascent so that we can display the text higher
20643 it
->ascent
-= it
->voffset
;
20645 /* Increase the descent so that we can display the text lower
20647 it
->descent
+= it
->voffset
;
20652 /* Produce glyphs/get display metrics for the image IT is loaded with.
20653 See the description of struct display_iterator in dispextern.h for
20654 an overview of struct display_iterator. */
20657 produce_image_glyph (it
)
20662 int glyph_ascent
, crop
;
20663 struct glyph_slice slice
;
20665 xassert (it
->what
== IT_IMAGE
);
20667 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20669 /* Make sure X resources of the face is loaded. */
20670 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20672 if (it
->image_id
< 0)
20674 /* Fringe bitmap. */
20675 it
->ascent
= it
->phys_ascent
= 0;
20676 it
->descent
= it
->phys_descent
= 0;
20677 it
->pixel_width
= 0;
20682 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20684 /* Make sure X resources of the image is loaded. */
20685 prepare_image_for_display (it
->f
, img
);
20687 slice
.x
= slice
.y
= 0;
20688 slice
.width
= img
->width
;
20689 slice
.height
= img
->height
;
20691 if (INTEGERP (it
->slice
.x
))
20692 slice
.x
= XINT (it
->slice
.x
);
20693 else if (FLOATP (it
->slice
.x
))
20694 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20696 if (INTEGERP (it
->slice
.y
))
20697 slice
.y
= XINT (it
->slice
.y
);
20698 else if (FLOATP (it
->slice
.y
))
20699 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20701 if (INTEGERP (it
->slice
.width
))
20702 slice
.width
= XINT (it
->slice
.width
);
20703 else if (FLOATP (it
->slice
.width
))
20704 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20706 if (INTEGERP (it
->slice
.height
))
20707 slice
.height
= XINT (it
->slice
.height
);
20708 else if (FLOATP (it
->slice
.height
))
20709 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20711 if (slice
.x
>= img
->width
)
20712 slice
.x
= img
->width
;
20713 if (slice
.y
>= img
->height
)
20714 slice
.y
= img
->height
;
20715 if (slice
.x
+ slice
.width
>= img
->width
)
20716 slice
.width
= img
->width
- slice
.x
;
20717 if (slice
.y
+ slice
.height
> img
->height
)
20718 slice
.height
= img
->height
- slice
.y
;
20720 if (slice
.width
== 0 || slice
.height
== 0)
20723 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20725 it
->descent
= slice
.height
- glyph_ascent
;
20727 it
->descent
+= img
->vmargin
;
20728 if (slice
.y
+ slice
.height
== img
->height
)
20729 it
->descent
+= img
->vmargin
;
20730 it
->phys_descent
= it
->descent
;
20732 it
->pixel_width
= slice
.width
;
20734 it
->pixel_width
+= img
->hmargin
;
20735 if (slice
.x
+ slice
.width
== img
->width
)
20736 it
->pixel_width
+= img
->hmargin
;
20738 /* It's quite possible for images to have an ascent greater than
20739 their height, so don't get confused in that case. */
20740 if (it
->descent
< 0)
20745 if (face
->box
!= FACE_NO_BOX
)
20747 if (face
->box_line_width
> 0)
20750 it
->ascent
+= face
->box_line_width
;
20751 if (slice
.y
+ slice
.height
== img
->height
)
20752 it
->descent
+= face
->box_line_width
;
20755 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20756 it
->pixel_width
+= eabs (face
->box_line_width
);
20757 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20758 it
->pixel_width
+= eabs (face
->box_line_width
);
20761 take_vertical_position_into_account (it
);
20763 /* Automatically crop wide image glyphs at right edge so we can
20764 draw the cursor on same display row. */
20765 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20766 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20768 it
->pixel_width
-= crop
;
20769 slice
.width
-= crop
;
20774 struct glyph
*glyph
;
20775 enum glyph_row_area area
= it
->area
;
20777 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20778 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20780 glyph
->charpos
= CHARPOS (it
->position
);
20781 glyph
->object
= it
->object
;
20782 glyph
->pixel_width
= it
->pixel_width
;
20783 glyph
->ascent
= glyph_ascent
;
20784 glyph
->descent
= it
->descent
;
20785 glyph
->voffset
= it
->voffset
;
20786 glyph
->type
= IMAGE_GLYPH
;
20787 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20788 glyph
->multibyte_p
= it
->multibyte_p
;
20789 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20790 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20791 glyph
->overlaps_vertically_p
= 0;
20792 glyph
->padding_p
= 0;
20793 glyph
->glyph_not_available_p
= 0;
20794 glyph
->face_id
= it
->face_id
;
20795 glyph
->u
.img_id
= img
->id
;
20796 glyph
->slice
= slice
;
20797 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20798 ++it
->glyph_row
->used
[area
];
20801 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20806 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20807 of the glyph, WIDTH and HEIGHT are the width and height of the
20808 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20811 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20813 Lisp_Object object
;
20817 struct glyph
*glyph
;
20818 enum glyph_row_area area
= it
->area
;
20820 xassert (ascent
>= 0 && ascent
<= height
);
20822 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20823 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20825 glyph
->charpos
= CHARPOS (it
->position
);
20826 glyph
->object
= object
;
20827 glyph
->pixel_width
= width
;
20828 glyph
->ascent
= ascent
;
20829 glyph
->descent
= height
- ascent
;
20830 glyph
->voffset
= it
->voffset
;
20831 glyph
->type
= STRETCH_GLYPH
;
20832 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20833 glyph
->multibyte_p
= it
->multibyte_p
;
20834 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20835 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20836 glyph
->overlaps_vertically_p
= 0;
20837 glyph
->padding_p
= 0;
20838 glyph
->glyph_not_available_p
= 0;
20839 glyph
->face_id
= it
->face_id
;
20840 glyph
->u
.stretch
.ascent
= ascent
;
20841 glyph
->u
.stretch
.height
= height
;
20842 glyph
->slice
= null_glyph_slice
;
20843 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20844 ++it
->glyph_row
->used
[area
];
20847 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20851 /* Produce a stretch glyph for iterator IT. IT->object is the value
20852 of the glyph property displayed. The value must be a list
20853 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20856 1. `:width WIDTH' specifies that the space should be WIDTH *
20857 canonical char width wide. WIDTH may be an integer or floating
20860 2. `:relative-width FACTOR' specifies that the width of the stretch
20861 should be computed from the width of the first character having the
20862 `glyph' property, and should be FACTOR times that width.
20864 3. `:align-to HPOS' specifies that the space should be wide enough
20865 to reach HPOS, a value in canonical character units.
20867 Exactly one of the above pairs must be present.
20869 4. `:height HEIGHT' specifies that the height of the stretch produced
20870 should be HEIGHT, measured in canonical character units.
20872 5. `:relative-height FACTOR' specifies that the height of the
20873 stretch should be FACTOR times the height of the characters having
20874 the glyph property.
20876 Either none or exactly one of 4 or 5 must be present.
20878 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20879 of the stretch should be used for the ascent of the stretch.
20880 ASCENT must be in the range 0 <= ASCENT <= 100. */
20883 produce_stretch_glyph (it
)
20886 /* (space :width WIDTH :height HEIGHT ...) */
20887 Lisp_Object prop
, plist
;
20888 int width
= 0, height
= 0, align_to
= -1;
20889 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20892 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20893 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20895 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20897 /* List should start with `space'. */
20898 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20899 plist
= XCDR (it
->object
);
20901 /* Compute the width of the stretch. */
20902 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20903 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20905 /* Absolute width `:width WIDTH' specified and valid. */
20906 zero_width_ok_p
= 1;
20909 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20912 /* Relative width `:relative-width FACTOR' specified and valid.
20913 Compute the width of the characters having the `glyph'
20916 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20919 if (it
->multibyte_p
)
20921 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20922 - IT_BYTEPOS (*it
));
20923 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
20927 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
20928 if (! ASCII_CHAR_P (it2
.c
))
20929 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
20932 it2
.glyph_row
= NULL
;
20933 it2
.what
= IT_CHARACTER
;
20934 x_produce_glyphs (&it2
);
20935 width
= NUMVAL (prop
) * it2
.pixel_width
;
20937 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20938 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20940 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20941 align_to
= (align_to
< 0
20943 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20944 else if (align_to
< 0)
20945 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20946 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20947 zero_width_ok_p
= 1;
20950 /* Nothing specified -> width defaults to canonical char width. */
20951 width
= FRAME_COLUMN_WIDTH (it
->f
);
20953 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20956 /* Compute height. */
20957 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20958 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20961 zero_height_ok_p
= 1;
20963 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20965 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20967 height
= FONT_HEIGHT (font
);
20969 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20972 /* Compute percentage of height used for ascent. If
20973 `:ascent ASCENT' is present and valid, use that. Otherwise,
20974 derive the ascent from the font in use. */
20975 if (prop
= Fplist_get (plist
, QCascent
),
20976 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20977 ascent
= height
* NUMVAL (prop
) / 100.0;
20978 else if (!NILP (prop
)
20979 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20980 ascent
= min (max (0, (int)tem
), height
);
20982 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20984 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20985 && it
->current_x
+ width
> it
->last_visible_x
)
20986 width
= it
->last_visible_x
- it
->current_x
- 1;
20988 if (width
> 0 && height
> 0 && it
->glyph_row
)
20990 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20991 if (!STRINGP (object
))
20992 object
= it
->w
->buffer
;
20993 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20996 it
->pixel_width
= width
;
20997 it
->ascent
= it
->phys_ascent
= ascent
;
20998 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20999 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21001 take_vertical_position_into_account (it
);
21004 /* Calculate line-height and line-spacing properties.
21005 An integer value specifies explicit pixel value.
21006 A float value specifies relative value to current face height.
21007 A cons (float . face-name) specifies relative value to
21008 height of specified face font.
21010 Returns height in pixels, or nil. */
21014 calc_line_height_property (it
, val
, font
, boff
, override
)
21018 int boff
, override
;
21020 Lisp_Object face_name
= Qnil
;
21021 int ascent
, descent
, height
;
21023 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21028 face_name
= XCAR (val
);
21030 if (!NUMBERP (val
))
21031 val
= make_number (1);
21032 if (NILP (face_name
))
21034 height
= it
->ascent
+ it
->descent
;
21039 if (NILP (face_name
))
21041 font
= FRAME_FONT (it
->f
);
21042 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21044 else if (EQ (face_name
, Qt
))
21053 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21055 return make_number (-1);
21057 face
= FACE_FROM_ID (it
->f
, face_id
);
21060 return make_number (-1);
21061 boff
= font
->baseline_offset
;
21062 if (font
->vertical_centering
)
21063 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21066 ascent
= FONT_BASE (font
) + boff
;
21067 descent
= FONT_DESCENT (font
) - boff
;
21071 it
->override_ascent
= ascent
;
21072 it
->override_descent
= descent
;
21073 it
->override_boff
= boff
;
21076 height
= ascent
+ descent
;
21080 height
= (int)(XFLOAT_DATA (val
) * height
);
21081 else if (INTEGERP (val
))
21082 height
*= XINT (val
);
21084 return make_number (height
);
21089 Produce glyphs/get display metrics for the display element IT is
21090 loaded with. See the description of struct it in dispextern.h
21091 for an overview of struct it. */
21094 x_produce_glyphs (it
)
21097 int extra_line_spacing
= it
->extra_line_spacing
;
21099 it
->glyph_not_available_p
= 0;
21101 if (it
->what
== IT_CHARACTER
)
21104 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21105 struct font
*font
= face
->font
;
21106 int font_not_found_p
= font
== NULL
;
21107 struct font_metrics
*pcm
= NULL
;
21108 int boff
; /* baseline offset */
21110 if (font_not_found_p
)
21112 /* When no suitable font found, display an empty box based
21113 on the metrics of the font of the default face (or what
21115 struct face
*no_font_face
21116 = FACE_FROM_ID (it
->f
,
21117 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21118 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21119 font
= no_font_face
->font
;
21120 boff
= font
->baseline_offset
;
21124 boff
= font
->baseline_offset
;
21125 if (font
->vertical_centering
)
21126 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21129 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
21135 if (it
->override_ascent
>= 0)
21137 it
->ascent
= it
->override_ascent
;
21138 it
->descent
= it
->override_descent
;
21139 boff
= it
->override_boff
;
21143 it
->ascent
= FONT_BASE (font
) + boff
;
21144 it
->descent
= FONT_DESCENT (font
) - boff
;
21147 if (! font_not_found_p
21148 && get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
21150 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21151 if (pcm
->width
== 0
21152 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
21158 it
->phys_ascent
= pcm
->ascent
+ boff
;
21159 it
->phys_descent
= pcm
->descent
- boff
;
21160 it
->pixel_width
= pcm
->width
;
21164 it
->glyph_not_available_p
= 1;
21165 it
->phys_ascent
= it
->ascent
;
21166 it
->phys_descent
= it
->descent
;
21167 it
->pixel_width
= font
->space_width
;
21170 if (it
->constrain_row_ascent_descent_p
)
21172 if (it
->descent
> it
->max_descent
)
21174 it
->ascent
+= it
->descent
- it
->max_descent
;
21175 it
->descent
= it
->max_descent
;
21177 if (it
->ascent
> it
->max_ascent
)
21179 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21180 it
->ascent
= it
->max_ascent
;
21182 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21183 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21184 extra_line_spacing
= 0;
21187 /* If this is a space inside a region of text with
21188 `space-width' property, change its width. */
21189 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21191 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21193 /* If face has a box, add the box thickness to the character
21194 height. If character has a box line to the left and/or
21195 right, add the box line width to the character's width. */
21196 if (face
->box
!= FACE_NO_BOX
)
21198 int thick
= face
->box_line_width
;
21202 it
->ascent
+= thick
;
21203 it
->descent
+= thick
;
21208 if (it
->start_of_box_run_p
)
21209 it
->pixel_width
+= thick
;
21210 if (it
->end_of_box_run_p
)
21211 it
->pixel_width
+= thick
;
21214 /* If face has an overline, add the height of the overline
21215 (1 pixel) and a 1 pixel margin to the character height. */
21216 if (face
->overline_p
)
21217 it
->ascent
+= overline_margin
;
21219 if (it
->constrain_row_ascent_descent_p
)
21221 if (it
->ascent
> it
->max_ascent
)
21222 it
->ascent
= it
->max_ascent
;
21223 if (it
->descent
> it
->max_descent
)
21224 it
->descent
= it
->max_descent
;
21227 take_vertical_position_into_account (it
);
21229 /* If we have to actually produce glyphs, do it. */
21234 /* Translate a space with a `space-width' property
21235 into a stretch glyph. */
21236 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21237 / FONT_HEIGHT (font
));
21238 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21239 it
->ascent
+ it
->descent
, ascent
);
21244 /* If characters with lbearing or rbearing are displayed
21245 in this line, record that fact in a flag of the
21246 glyph row. This is used to optimize X output code. */
21247 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21248 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21250 if (! stretched_p
&& it
->pixel_width
== 0)
21251 /* We assure that all visible glyphs have at least 1-pixel
21253 it
->pixel_width
= 1;
21255 else if (it
->char_to_display
== '\n')
21257 /* A newline has no width, but we need the height of the
21258 line. But if previous part of the line sets a height,
21259 don't increase that height */
21261 Lisp_Object height
;
21262 Lisp_Object total_height
= Qnil
;
21264 it
->override_ascent
= -1;
21265 it
->pixel_width
= 0;
21268 height
= get_it_property(it
, Qline_height
);
21269 /* Split (line-height total-height) list */
21271 && CONSP (XCDR (height
))
21272 && NILP (XCDR (XCDR (height
))))
21274 total_height
= XCAR (XCDR (height
));
21275 height
= XCAR (height
);
21277 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21279 if (it
->override_ascent
>= 0)
21281 it
->ascent
= it
->override_ascent
;
21282 it
->descent
= it
->override_descent
;
21283 boff
= it
->override_boff
;
21287 it
->ascent
= FONT_BASE (font
) + boff
;
21288 it
->descent
= FONT_DESCENT (font
) - boff
;
21291 if (EQ (height
, Qt
))
21293 if (it
->descent
> it
->max_descent
)
21295 it
->ascent
+= it
->descent
- it
->max_descent
;
21296 it
->descent
= it
->max_descent
;
21298 if (it
->ascent
> it
->max_ascent
)
21300 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21301 it
->ascent
= it
->max_ascent
;
21303 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21304 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21305 it
->constrain_row_ascent_descent_p
= 1;
21306 extra_line_spacing
= 0;
21310 Lisp_Object spacing
;
21312 it
->phys_ascent
= it
->ascent
;
21313 it
->phys_descent
= it
->descent
;
21315 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21316 && face
->box
!= FACE_NO_BOX
21317 && face
->box_line_width
> 0)
21319 it
->ascent
+= face
->box_line_width
;
21320 it
->descent
+= face
->box_line_width
;
21323 && XINT (height
) > it
->ascent
+ it
->descent
)
21324 it
->ascent
= XINT (height
) - it
->descent
;
21326 if (!NILP (total_height
))
21327 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21330 spacing
= get_it_property(it
, Qline_spacing
);
21331 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21333 if (INTEGERP (spacing
))
21335 extra_line_spacing
= XINT (spacing
);
21336 if (!NILP (total_height
))
21337 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21341 else /* i.e. (it->char_to_display == '\t') */
21343 if (font
->space_width
> 0)
21345 int tab_width
= it
->tab_width
* font
->space_width
;
21346 int x
= it
->current_x
+ it
->continuation_lines_width
;
21347 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21349 /* If the distance from the current position to the next tab
21350 stop is less than a space character width, use the
21351 tab stop after that. */
21352 if (next_tab_x
- x
< font
->space_width
)
21353 next_tab_x
+= tab_width
;
21355 it
->pixel_width
= next_tab_x
- x
;
21357 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21358 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21362 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21363 it
->ascent
+ it
->descent
, it
->ascent
);
21368 it
->pixel_width
= 0;
21373 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
21375 /* A static composition.
21377 Note: A composition is represented as one glyph in the
21378 glyph matrix. There are no padding glyphs.
21380 Important note: pixel_width, ascent, and descent are the
21381 values of what is drawn by draw_glyphs (i.e. the values of
21382 the overall glyphs composed). */
21383 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21384 int boff
; /* baseline offset */
21385 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
21386 int glyph_len
= cmp
->glyph_len
;
21387 struct font
*font
= face
->font
;
21391 /* If we have not yet calculated pixel size data of glyphs of
21392 the composition for the current face font, calculate them
21393 now. Theoretically, we have to check all fonts for the
21394 glyphs, but that requires much time and memory space. So,
21395 here we check only the font of the first glyph. This may
21396 lead to incorrect display, but it's very rare, and C-l
21397 (recenter-top-bottom) can correct the display anyway. */
21398 if (! cmp
->font
|| cmp
->font
!= font
)
21400 /* Ascent and descent of the font of the first character
21401 of this composition (adjusted by baseline offset).
21402 Ascent and descent of overall glyphs should not be less
21403 than these, respectively. */
21404 int font_ascent
, font_descent
, font_height
;
21405 /* Bounding box of the overall glyphs. */
21406 int leftmost
, rightmost
, lowest
, highest
;
21407 int lbearing
, rbearing
;
21408 int i
, width
, ascent
, descent
;
21409 int left_padded
= 0, right_padded
= 0;
21412 struct font_metrics
*pcm
;
21413 int font_not_found_p
;
21416 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21417 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21419 if (glyph_len
< cmp
->glyph_len
)
21421 for (i
= 0; i
< glyph_len
; i
++)
21423 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21425 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21430 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21431 : IT_CHARPOS (*it
));
21432 /* If no suitable font is found, use the default font. */
21433 font_not_found_p
= font
== NULL
;
21434 if (font_not_found_p
)
21436 face
= face
->ascii_face
;
21439 boff
= font
->baseline_offset
;
21440 if (font
->vertical_centering
)
21441 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21442 font_ascent
= FONT_BASE (font
) + boff
;
21443 font_descent
= FONT_DESCENT (font
) - boff
;
21444 font_height
= FONT_HEIGHT (font
);
21446 cmp
->font
= (void *) font
;
21449 if (! font_not_found_p
)
21451 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21452 &char2b
, it
->multibyte_p
, 0);
21453 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21456 /* Initialize the bounding box. */
21459 width
= pcm
->width
;
21460 ascent
= pcm
->ascent
;
21461 descent
= pcm
->descent
;
21462 lbearing
= pcm
->lbearing
;
21463 rbearing
= pcm
->rbearing
;
21467 width
= font
->space_width
;
21468 ascent
= FONT_BASE (font
);
21469 descent
= FONT_DESCENT (font
);
21476 lowest
= - descent
+ boff
;
21477 highest
= ascent
+ boff
;
21479 if (! font_not_found_p
21480 && font
->default_ascent
21481 && CHAR_TABLE_P (Vuse_default_ascent
)
21482 && !NILP (Faref (Vuse_default_ascent
,
21483 make_number (it
->char_to_display
))))
21484 highest
= font
->default_ascent
+ boff
;
21486 /* Draw the first glyph at the normal position. It may be
21487 shifted to right later if some other glyphs are drawn
21489 cmp
->offsets
[i
* 2] = 0;
21490 cmp
->offsets
[i
* 2 + 1] = boff
;
21491 cmp
->lbearing
= lbearing
;
21492 cmp
->rbearing
= rbearing
;
21494 /* Set cmp->offsets for the remaining glyphs. */
21495 for (i
++; i
< glyph_len
; i
++)
21497 int left
, right
, btm
, top
;
21498 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21500 struct face
*this_face
;
21505 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21506 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21507 font
= this_face
->font
;
21513 this_boff
= font
->baseline_offset
;
21514 if (font
->vertical_centering
)
21515 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21516 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21517 &char2b
, it
->multibyte_p
, 0);
21518 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21521 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21524 width
= pcm
->width
;
21525 ascent
= pcm
->ascent
;
21526 descent
= pcm
->descent
;
21527 lbearing
= pcm
->lbearing
;
21528 rbearing
= pcm
->rbearing
;
21529 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21531 /* Relative composition with or without
21532 alternate chars. */
21533 left
= (leftmost
+ rightmost
- width
) / 2;
21534 btm
= - descent
+ boff
;
21535 if (font
->relative_compose
21536 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21537 || NILP (Faref (Vignore_relative_composition
,
21538 make_number (ch
)))))
21541 if (- descent
>= font
->relative_compose
)
21542 /* One extra pixel between two glyphs. */
21544 else if (ascent
<= 0)
21545 /* One extra pixel between two glyphs. */
21546 btm
= lowest
- 1 - ascent
- descent
;
21551 /* A composition rule is specified by an integer
21552 value that encodes global and new reference
21553 points (GREF and NREF). GREF and NREF are
21554 specified by numbers as below:
21556 0---1---2 -- ascent
21560 9--10--11 -- center
21562 ---3---4---5--- baseline
21564 6---7---8 -- descent
21566 int rule
= COMPOSITION_RULE (cmp
, i
);
21567 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21569 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21570 grefx
= gref
% 3, nrefx
= nref
% 3;
21571 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21573 xoff
= font_height
* (xoff
- 128) / 256;
21575 yoff
= font_height
* (yoff
- 128) / 256;
21578 + grefx
* (rightmost
- leftmost
) / 2
21579 - nrefx
* width
/ 2
21582 btm
= ((grefy
== 0 ? highest
21584 : grefy
== 2 ? lowest
21585 : (highest
+ lowest
) / 2)
21586 - (nrefy
== 0 ? ascent
+ descent
21587 : nrefy
== 1 ? descent
- boff
21589 : (ascent
+ descent
) / 2)
21593 cmp
->offsets
[i
* 2] = left
;
21594 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21596 /* Update the bounding box of the overall glyphs. */
21599 right
= left
+ width
;
21600 if (left
< leftmost
)
21602 if (right
> rightmost
)
21605 top
= btm
+ descent
+ ascent
;
21611 if (cmp
->lbearing
> left
+ lbearing
)
21612 cmp
->lbearing
= left
+ lbearing
;
21613 if (cmp
->rbearing
< left
+ rbearing
)
21614 cmp
->rbearing
= left
+ rbearing
;
21618 /* If there are glyphs whose x-offsets are negative,
21619 shift all glyphs to the right and make all x-offsets
21623 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21624 cmp
->offsets
[i
* 2] -= leftmost
;
21625 rightmost
-= leftmost
;
21626 cmp
->lbearing
-= leftmost
;
21627 cmp
->rbearing
-= leftmost
;
21630 if (left_padded
&& cmp
->lbearing
< 0)
21632 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21633 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21634 rightmost
-= cmp
->lbearing
;
21635 cmp
->rbearing
-= cmp
->lbearing
;
21638 if (right_padded
&& rightmost
< cmp
->rbearing
)
21640 rightmost
= cmp
->rbearing
;
21643 cmp
->pixel_width
= rightmost
;
21644 cmp
->ascent
= highest
;
21645 cmp
->descent
= - lowest
;
21646 if (cmp
->ascent
< font_ascent
)
21647 cmp
->ascent
= font_ascent
;
21648 if (cmp
->descent
< font_descent
)
21649 cmp
->descent
= font_descent
;
21653 && (cmp
->lbearing
< 0
21654 || cmp
->rbearing
> cmp
->pixel_width
))
21655 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21657 it
->pixel_width
= cmp
->pixel_width
;
21658 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21659 it
->descent
= it
->phys_descent
= cmp
->descent
;
21660 if (face
->box
!= FACE_NO_BOX
)
21662 int thick
= face
->box_line_width
;
21666 it
->ascent
+= thick
;
21667 it
->descent
+= thick
;
21672 if (it
->start_of_box_run_p
)
21673 it
->pixel_width
+= thick
;
21674 if (it
->end_of_box_run_p
)
21675 it
->pixel_width
+= thick
;
21678 /* If face has an overline, add the height of the overline
21679 (1 pixel) and a 1 pixel margin to the character height. */
21680 if (face
->overline_p
)
21681 it
->ascent
+= overline_margin
;
21683 take_vertical_position_into_account (it
);
21684 if (it
->ascent
< 0)
21686 if (it
->descent
< 0)
21690 append_composite_glyph (it
);
21692 else if (it
->what
== IT_COMPOSITION
)
21694 /* A dynamic (automatic) composition. */
21695 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21696 Lisp_Object gstring
;
21697 struct font_metrics metrics
;
21699 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
21701 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
21704 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
21705 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21706 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
21707 it
->descent
= it
->phys_descent
= metrics
.descent
;
21708 if (face
->box
!= FACE_NO_BOX
)
21710 int thick
= face
->box_line_width
;
21714 it
->ascent
+= thick
;
21715 it
->descent
+= thick
;
21720 if (it
->start_of_box_run_p
)
21721 it
->pixel_width
+= thick
;
21722 if (it
->end_of_box_run_p
)
21723 it
->pixel_width
+= thick
;
21725 /* If face has an overline, add the height of the overline
21726 (1 pixel) and a 1 pixel margin to the character height. */
21727 if (face
->overline_p
)
21728 it
->ascent
+= overline_margin
;
21729 take_vertical_position_into_account (it
);
21730 if (it
->ascent
< 0)
21732 if (it
->descent
< 0)
21736 append_composite_glyph (it
);
21738 else if (it
->what
== IT_IMAGE
)
21739 produce_image_glyph (it
);
21740 else if (it
->what
== IT_STRETCH
)
21741 produce_stretch_glyph (it
);
21743 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21744 because this isn't true for images with `:ascent 100'. */
21745 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21746 if (it
->area
== TEXT_AREA
)
21747 it
->current_x
+= it
->pixel_width
;
21749 if (extra_line_spacing
> 0)
21751 it
->descent
+= extra_line_spacing
;
21752 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21753 it
->max_extra_line_spacing
= extra_line_spacing
;
21756 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21757 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21758 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21759 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21763 Output LEN glyphs starting at START at the nominal cursor position.
21764 Advance the nominal cursor over the text. The global variable
21765 updated_window contains the window being updated, updated_row is
21766 the glyph row being updated, and updated_area is the area of that
21767 row being updated. */
21770 x_write_glyphs (start
, len
)
21771 struct glyph
*start
;
21776 xassert (updated_window
&& updated_row
);
21779 /* Write glyphs. */
21781 hpos
= start
- updated_row
->glyphs
[updated_area
];
21782 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21783 updated_row
, updated_area
,
21785 DRAW_NORMAL_TEXT
, 0);
21787 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21788 if (updated_area
== TEXT_AREA
21789 && updated_window
->phys_cursor_on_p
21790 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21791 && updated_window
->phys_cursor
.hpos
>= hpos
21792 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21793 updated_window
->phys_cursor_on_p
= 0;
21797 /* Advance the output cursor. */
21798 output_cursor
.hpos
+= len
;
21799 output_cursor
.x
= x
;
21804 Insert LEN glyphs from START at the nominal cursor position. */
21807 x_insert_glyphs (start
, len
)
21808 struct glyph
*start
;
21813 int line_height
, shift_by_width
, shifted_region_width
;
21814 struct glyph_row
*row
;
21815 struct glyph
*glyph
;
21816 int frame_x
, frame_y
;
21819 xassert (updated_window
&& updated_row
);
21821 w
= updated_window
;
21822 f
= XFRAME (WINDOW_FRAME (w
));
21824 /* Get the height of the line we are in. */
21826 line_height
= row
->height
;
21828 /* Get the width of the glyphs to insert. */
21829 shift_by_width
= 0;
21830 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21831 shift_by_width
+= glyph
->pixel_width
;
21833 /* Get the width of the region to shift right. */
21834 shifted_region_width
= (window_box_width (w
, updated_area
)
21839 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21840 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21842 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21843 line_height
, shift_by_width
);
21845 /* Write the glyphs. */
21846 hpos
= start
- row
->glyphs
[updated_area
];
21847 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21849 DRAW_NORMAL_TEXT
, 0);
21851 /* Advance the output cursor. */
21852 output_cursor
.hpos
+= len
;
21853 output_cursor
.x
+= shift_by_width
;
21859 Erase the current text line from the nominal cursor position
21860 (inclusive) to pixel column TO_X (exclusive). The idea is that
21861 everything from TO_X onward is already erased.
21863 TO_X is a pixel position relative to updated_area of
21864 updated_window. TO_X == -1 means clear to the end of this area. */
21867 x_clear_end_of_line (to_x
)
21871 struct window
*w
= updated_window
;
21872 int max_x
, min_y
, max_y
;
21873 int from_x
, from_y
, to_y
;
21875 xassert (updated_window
&& updated_row
);
21876 f
= XFRAME (w
->frame
);
21878 if (updated_row
->full_width_p
)
21879 max_x
= WINDOW_TOTAL_WIDTH (w
);
21881 max_x
= window_box_width (w
, updated_area
);
21882 max_y
= window_text_bottom_y (w
);
21884 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21885 of window. For TO_X > 0, truncate to end of drawing area. */
21891 to_x
= min (to_x
, max_x
);
21893 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21895 /* Notice if the cursor will be cleared by this operation. */
21896 if (!updated_row
->full_width_p
)
21897 notice_overwritten_cursor (w
, updated_area
,
21898 output_cursor
.x
, -1,
21900 MATRIX_ROW_BOTTOM_Y (updated_row
));
21902 from_x
= output_cursor
.x
;
21904 /* Translate to frame coordinates. */
21905 if (updated_row
->full_width_p
)
21907 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21908 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21912 int area_left
= window_box_left (w
, updated_area
);
21913 from_x
+= area_left
;
21917 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21918 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21919 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21921 /* Prevent inadvertently clearing to end of the X window. */
21922 if (to_x
> from_x
&& to_y
> from_y
)
21925 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21926 to_x
- from_x
, to_y
- from_y
);
21931 #endif /* HAVE_WINDOW_SYSTEM */
21935 /***********************************************************************
21937 ***********************************************************************/
21939 /* Value is the internal representation of the specified cursor type
21940 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21941 of the bar cursor. */
21943 static enum text_cursor_kinds
21944 get_specified_cursor_type (arg
, width
)
21948 enum text_cursor_kinds type
;
21953 if (EQ (arg
, Qbox
))
21954 return FILLED_BOX_CURSOR
;
21956 if (EQ (arg
, Qhollow
))
21957 return HOLLOW_BOX_CURSOR
;
21959 if (EQ (arg
, Qbar
))
21966 && EQ (XCAR (arg
), Qbar
)
21967 && INTEGERP (XCDR (arg
))
21968 && XINT (XCDR (arg
)) >= 0)
21970 *width
= XINT (XCDR (arg
));
21974 if (EQ (arg
, Qhbar
))
21977 return HBAR_CURSOR
;
21981 && EQ (XCAR (arg
), Qhbar
)
21982 && INTEGERP (XCDR (arg
))
21983 && XINT (XCDR (arg
)) >= 0)
21985 *width
= XINT (XCDR (arg
));
21986 return HBAR_CURSOR
;
21989 /* Treat anything unknown as "hollow box cursor".
21990 It was bad to signal an error; people have trouble fixing
21991 .Xdefaults with Emacs, when it has something bad in it. */
21992 type
= HOLLOW_BOX_CURSOR
;
21997 /* Set the default cursor types for specified frame. */
21999 set_frame_cursor_types (f
, arg
)
22006 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22007 FRAME_CURSOR_WIDTH (f
) = width
;
22009 /* By default, set up the blink-off state depending on the on-state. */
22011 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22014 FRAME_BLINK_OFF_CURSOR (f
)
22015 = get_specified_cursor_type (XCDR (tem
), &width
);
22016 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22019 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22023 /* Return the cursor we want to be displayed in window W. Return
22024 width of bar/hbar cursor through WIDTH arg. Return with
22025 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22026 (i.e. if the `system caret' should track this cursor).
22028 In a mini-buffer window, we want the cursor only to appear if we
22029 are reading input from this window. For the selected window, we
22030 want the cursor type given by the frame parameter or buffer local
22031 setting of cursor-type. If explicitly marked off, draw no cursor.
22032 In all other cases, we want a hollow box cursor. */
22034 static enum text_cursor_kinds
22035 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22037 struct glyph
*glyph
;
22039 int *active_cursor
;
22041 struct frame
*f
= XFRAME (w
->frame
);
22042 struct buffer
*b
= XBUFFER (w
->buffer
);
22043 int cursor_type
= DEFAULT_CURSOR
;
22044 Lisp_Object alt_cursor
;
22045 int non_selected
= 0;
22047 *active_cursor
= 1;
22050 if (cursor_in_echo_area
22051 && FRAME_HAS_MINIBUF_P (f
)
22052 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22054 if (w
== XWINDOW (echo_area_window
))
22056 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22058 *width
= FRAME_CURSOR_WIDTH (f
);
22059 return FRAME_DESIRED_CURSOR (f
);
22062 return get_specified_cursor_type (b
->cursor_type
, width
);
22065 *active_cursor
= 0;
22069 /* Detect a nonselected window or nonselected frame. */
22070 else if (w
!= XWINDOW (f
->selected_window
)
22071 #ifdef HAVE_WINDOW_SYSTEM
22072 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22076 *active_cursor
= 0;
22078 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22084 /* Never display a cursor in a window in which cursor-type is nil. */
22085 if (NILP (b
->cursor_type
))
22088 /* Get the normal cursor type for this window. */
22089 if (EQ (b
->cursor_type
, Qt
))
22091 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22092 *width
= FRAME_CURSOR_WIDTH (f
);
22095 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22097 /* Use cursor-in-non-selected-windows instead
22098 for non-selected window or frame. */
22101 alt_cursor
= b
->cursor_in_non_selected_windows
;
22102 if (!EQ (Qt
, alt_cursor
))
22103 return get_specified_cursor_type (alt_cursor
, width
);
22104 /* t means modify the normal cursor type. */
22105 if (cursor_type
== FILLED_BOX_CURSOR
)
22106 cursor_type
= HOLLOW_BOX_CURSOR
;
22107 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22109 return cursor_type
;
22112 /* Use normal cursor if not blinked off. */
22113 if (!w
->cursor_off_p
)
22115 #ifdef HAVE_WINDOW_SYSTEM
22116 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22118 if (cursor_type
== FILLED_BOX_CURSOR
)
22120 /* Using a block cursor on large images can be very annoying.
22121 So use a hollow cursor for "large" images.
22122 If image is not transparent (no mask), also use hollow cursor. */
22123 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22124 if (img
!= NULL
&& IMAGEP (img
->spec
))
22126 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22127 where N = size of default frame font size.
22128 This should cover most of the "tiny" icons people may use. */
22130 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22131 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22132 cursor_type
= HOLLOW_BOX_CURSOR
;
22135 else if (cursor_type
!= NO_CURSOR
)
22137 /* Display current only supports BOX and HOLLOW cursors for images.
22138 So for now, unconditionally use a HOLLOW cursor when cursor is
22139 not a solid box cursor. */
22140 cursor_type
= HOLLOW_BOX_CURSOR
;
22144 return cursor_type
;
22147 /* Cursor is blinked off, so determine how to "toggle" it. */
22149 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22150 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22151 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22153 /* Then see if frame has specified a specific blink off cursor type. */
22154 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22156 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22157 return FRAME_BLINK_OFF_CURSOR (f
);
22161 /* Some people liked having a permanently visible blinking cursor,
22162 while others had very strong opinions against it. So it was
22163 decided to remove it. KFS 2003-09-03 */
22165 /* Finally perform built-in cursor blinking:
22166 filled box <-> hollow box
22167 wide [h]bar <-> narrow [h]bar
22168 narrow [h]bar <-> no cursor
22169 other type <-> no cursor */
22171 if (cursor_type
== FILLED_BOX_CURSOR
)
22172 return HOLLOW_BOX_CURSOR
;
22174 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22177 return cursor_type
;
22185 #ifdef HAVE_WINDOW_SYSTEM
22187 /* Notice when the text cursor of window W has been completely
22188 overwritten by a drawing operation that outputs glyphs in AREA
22189 starting at X0 and ending at X1 in the line starting at Y0 and
22190 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22191 the rest of the line after X0 has been written. Y coordinates
22192 are window-relative. */
22195 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22197 enum glyph_row_area area
;
22198 int x0
, y0
, x1
, y1
;
22200 int cx0
, cx1
, cy0
, cy1
;
22201 struct glyph_row
*row
;
22203 if (!w
->phys_cursor_on_p
)
22205 if (area
!= TEXT_AREA
)
22208 if (w
->phys_cursor
.vpos
< 0
22209 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22210 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22211 !(row
->enabled_p
&& row
->displays_text_p
)))
22214 if (row
->cursor_in_fringe_p
)
22216 row
->cursor_in_fringe_p
= 0;
22217 draw_fringe_bitmap (w
, row
, 0);
22218 w
->phys_cursor_on_p
= 0;
22222 cx0
= w
->phys_cursor
.x
;
22223 cx1
= cx0
+ w
->phys_cursor_width
;
22224 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22227 /* The cursor image will be completely removed from the
22228 screen if the output area intersects the cursor area in
22229 y-direction. When we draw in [y0 y1[, and some part of
22230 the cursor is at y < y0, that part must have been drawn
22231 before. When scrolling, the cursor is erased before
22232 actually scrolling, so we don't come here. When not
22233 scrolling, the rows above the old cursor row must have
22234 changed, and in this case these rows must have written
22235 over the cursor image.
22237 Likewise if part of the cursor is below y1, with the
22238 exception of the cursor being in the first blank row at
22239 the buffer and window end because update_text_area
22240 doesn't draw that row. (Except when it does, but
22241 that's handled in update_text_area.) */
22243 cy0
= w
->phys_cursor
.y
;
22244 cy1
= cy0
+ w
->phys_cursor_height
;
22245 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22248 w
->phys_cursor_on_p
= 0;
22251 #endif /* HAVE_WINDOW_SYSTEM */
22254 /************************************************************************
22256 ************************************************************************/
22258 #ifdef HAVE_WINDOW_SYSTEM
22261 Fix the display of area AREA of overlapping row ROW in window W
22262 with respect to the overlapping part OVERLAPS. */
22265 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22267 struct glyph_row
*row
;
22268 enum glyph_row_area area
;
22276 for (i
= 0; i
< row
->used
[area
];)
22278 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22280 int start
= i
, start_x
= x
;
22284 x
+= row
->glyphs
[area
][i
].pixel_width
;
22287 while (i
< row
->used
[area
]
22288 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22290 draw_glyphs (w
, start_x
, row
, area
,
22292 DRAW_NORMAL_TEXT
, overlaps
);
22296 x
+= row
->glyphs
[area
][i
].pixel_width
;
22306 Draw the cursor glyph of window W in glyph row ROW. See the
22307 comment of draw_glyphs for the meaning of HL. */
22310 draw_phys_cursor_glyph (w
, row
, hl
)
22312 struct glyph_row
*row
;
22313 enum draw_glyphs_face hl
;
22315 /* If cursor hpos is out of bounds, don't draw garbage. This can
22316 happen in mini-buffer windows when switching between echo area
22317 glyphs and mini-buffer. */
22318 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22320 int on_p
= w
->phys_cursor_on_p
;
22322 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22323 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22325 w
->phys_cursor_on_p
= on_p
;
22327 if (hl
== DRAW_CURSOR
)
22328 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22329 /* When we erase the cursor, and ROW is overlapped by other
22330 rows, make sure that these overlapping parts of other rows
22332 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22334 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22336 if (row
> w
->current_matrix
->rows
22337 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22338 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22339 OVERLAPS_ERASED_CURSOR
);
22341 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22342 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22343 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22344 OVERLAPS_ERASED_CURSOR
);
22351 Erase the image of a cursor of window W from the screen. */
22354 erase_phys_cursor (w
)
22357 struct frame
*f
= XFRAME (w
->frame
);
22358 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22359 int hpos
= w
->phys_cursor
.hpos
;
22360 int vpos
= w
->phys_cursor
.vpos
;
22361 int mouse_face_here_p
= 0;
22362 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22363 struct glyph_row
*cursor_row
;
22364 struct glyph
*cursor_glyph
;
22365 enum draw_glyphs_face hl
;
22367 /* No cursor displayed or row invalidated => nothing to do on the
22369 if (w
->phys_cursor_type
== NO_CURSOR
)
22370 goto mark_cursor_off
;
22372 /* VPOS >= active_glyphs->nrows means that window has been resized.
22373 Don't bother to erase the cursor. */
22374 if (vpos
>= active_glyphs
->nrows
)
22375 goto mark_cursor_off
;
22377 /* If row containing cursor is marked invalid, there is nothing we
22379 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22380 if (!cursor_row
->enabled_p
)
22381 goto mark_cursor_off
;
22383 /* If line spacing is > 0, old cursor may only be partially visible in
22384 window after split-window. So adjust visible height. */
22385 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22386 window_text_bottom_y (w
) - cursor_row
->y
);
22388 /* If row is completely invisible, don't attempt to delete a cursor which
22389 isn't there. This can happen if cursor is at top of a window, and
22390 we switch to a buffer with a header line in that window. */
22391 if (cursor_row
->visible_height
<= 0)
22392 goto mark_cursor_off
;
22394 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22395 if (cursor_row
->cursor_in_fringe_p
)
22397 cursor_row
->cursor_in_fringe_p
= 0;
22398 draw_fringe_bitmap (w
, cursor_row
, 0);
22399 goto mark_cursor_off
;
22402 /* This can happen when the new row is shorter than the old one.
22403 In this case, either draw_glyphs or clear_end_of_line
22404 should have cleared the cursor. Note that we wouldn't be
22405 able to erase the cursor in this case because we don't have a
22406 cursor glyph at hand. */
22407 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22408 goto mark_cursor_off
;
22410 /* If the cursor is in the mouse face area, redisplay that when
22411 we clear the cursor. */
22412 if (! NILP (dpyinfo
->mouse_face_window
)
22413 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22414 && (vpos
> dpyinfo
->mouse_face_beg_row
22415 || (vpos
== dpyinfo
->mouse_face_beg_row
22416 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22417 && (vpos
< dpyinfo
->mouse_face_end_row
22418 || (vpos
== dpyinfo
->mouse_face_end_row
22419 && hpos
< dpyinfo
->mouse_face_end_col
))
22420 /* Don't redraw the cursor's spot in mouse face if it is at the
22421 end of a line (on a newline). The cursor appears there, but
22422 mouse highlighting does not. */
22423 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22424 mouse_face_here_p
= 1;
22426 /* Maybe clear the display under the cursor. */
22427 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22430 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22433 cursor_glyph
= get_phys_cursor_glyph (w
);
22434 if (cursor_glyph
== NULL
)
22435 goto mark_cursor_off
;
22437 width
= cursor_glyph
->pixel_width
;
22438 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22439 x
= w
->phys_cursor
.x
;
22441 width
-= left_x
- x
;
22442 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22443 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22444 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22447 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22450 /* Erase the cursor by redrawing the character underneath it. */
22451 if (mouse_face_here_p
)
22452 hl
= DRAW_MOUSE_FACE
;
22454 hl
= DRAW_NORMAL_TEXT
;
22455 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22458 w
->phys_cursor_on_p
= 0;
22459 w
->phys_cursor_type
= NO_CURSOR
;
22464 Display or clear cursor of window W. If ON is zero, clear the
22465 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22466 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22469 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22471 int on
, hpos
, vpos
, x
, y
;
22473 struct frame
*f
= XFRAME (w
->frame
);
22474 int new_cursor_type
;
22475 int new_cursor_width
;
22477 struct glyph_row
*glyph_row
;
22478 struct glyph
*glyph
;
22480 /* This is pointless on invisible frames, and dangerous on garbaged
22481 windows and frames; in the latter case, the frame or window may
22482 be in the midst of changing its size, and x and y may be off the
22484 if (! FRAME_VISIBLE_P (f
)
22485 || FRAME_GARBAGED_P (f
)
22486 || vpos
>= w
->current_matrix
->nrows
22487 || hpos
>= w
->current_matrix
->matrix_w
)
22490 /* If cursor is off and we want it off, return quickly. */
22491 if (!on
&& !w
->phys_cursor_on_p
)
22494 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22495 /* If cursor row is not enabled, we don't really know where to
22496 display the cursor. */
22497 if (!glyph_row
->enabled_p
)
22499 w
->phys_cursor_on_p
= 0;
22504 if (!glyph_row
->exact_window_width_line_p
22505 || hpos
< glyph_row
->used
[TEXT_AREA
])
22506 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22508 xassert (interrupt_input_blocked
);
22510 /* Set new_cursor_type to the cursor we want to be displayed. */
22511 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22512 &new_cursor_width
, &active_cursor
);
22514 /* If cursor is currently being shown and we don't want it to be or
22515 it is in the wrong place, or the cursor type is not what we want,
22517 if (w
->phys_cursor_on_p
22519 || w
->phys_cursor
.x
!= x
22520 || w
->phys_cursor
.y
!= y
22521 || new_cursor_type
!= w
->phys_cursor_type
22522 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22523 && new_cursor_width
!= w
->phys_cursor_width
)))
22524 erase_phys_cursor (w
);
22526 /* Don't check phys_cursor_on_p here because that flag is only set
22527 to zero in some cases where we know that the cursor has been
22528 completely erased, to avoid the extra work of erasing the cursor
22529 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22530 still not be visible, or it has only been partly erased. */
22533 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22534 w
->phys_cursor_height
= glyph_row
->height
;
22536 /* Set phys_cursor_.* before x_draw_.* is called because some
22537 of them may need the information. */
22538 w
->phys_cursor
.x
= x
;
22539 w
->phys_cursor
.y
= glyph_row
->y
;
22540 w
->phys_cursor
.hpos
= hpos
;
22541 w
->phys_cursor
.vpos
= vpos
;
22544 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22545 new_cursor_type
, new_cursor_width
,
22546 on
, active_cursor
);
22550 /* Switch the display of W's cursor on or off, according to the value
22554 update_window_cursor (w
, on
)
22558 /* Don't update cursor in windows whose frame is in the process
22559 of being deleted. */
22560 if (w
->current_matrix
)
22563 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22564 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22570 /* Call update_window_cursor with parameter ON_P on all leaf windows
22571 in the window tree rooted at W. */
22574 update_cursor_in_window_tree (w
, on_p
)
22580 if (!NILP (w
->hchild
))
22581 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22582 else if (!NILP (w
->vchild
))
22583 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22585 update_window_cursor (w
, on_p
);
22587 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22593 Display the cursor on window W, or clear it, according to ON_P.
22594 Don't change the cursor's position. */
22597 x_update_cursor (f
, on_p
)
22601 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22606 Clear the cursor of window W to background color, and mark the
22607 cursor as not shown. This is used when the text where the cursor
22608 is about to be rewritten. */
22614 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22615 update_window_cursor (w
, 0);
22620 Display the active region described by mouse_face_* according to DRAW. */
22623 show_mouse_face (dpyinfo
, draw
)
22624 Display_Info
*dpyinfo
;
22625 enum draw_glyphs_face draw
;
22627 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22628 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22630 if (/* If window is in the process of being destroyed, don't bother
22632 w
->current_matrix
!= NULL
22633 /* Don't update mouse highlight if hidden */
22634 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22635 /* Recognize when we are called to operate on rows that don't exist
22636 anymore. This can happen when a window is split. */
22637 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22639 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22640 struct glyph_row
*row
, *first
, *last
;
22642 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22643 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22645 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22647 int start_hpos
, end_hpos
, start_x
;
22649 /* For all but the first row, the highlight starts at column 0. */
22652 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22653 start_x
= dpyinfo
->mouse_face_beg_x
;
22662 end_hpos
= dpyinfo
->mouse_face_end_col
;
22665 end_hpos
= row
->used
[TEXT_AREA
];
22666 if (draw
== DRAW_NORMAL_TEXT
)
22667 row
->fill_line_p
= 1; /* Clear to end of line */
22670 if (end_hpos
> start_hpos
)
22672 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22673 start_hpos
, end_hpos
,
22677 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22681 /* When we've written over the cursor, arrange for it to
22682 be displayed again. */
22683 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22686 display_and_set_cursor (w
, 1,
22687 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22688 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22693 /* Change the mouse cursor. */
22694 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22695 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22696 else if (draw
== DRAW_MOUSE_FACE
)
22697 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22699 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22703 Clear out the mouse-highlighted active region.
22704 Redraw it un-highlighted first. Value is non-zero if mouse
22705 face was actually drawn unhighlighted. */
22708 clear_mouse_face (dpyinfo
)
22709 Display_Info
*dpyinfo
;
22713 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22715 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22719 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22720 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22721 dpyinfo
->mouse_face_window
= Qnil
;
22722 dpyinfo
->mouse_face_overlay
= Qnil
;
22728 Non-zero if physical cursor of window W is within mouse face. */
22731 cursor_in_mouse_face_p (w
)
22734 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22735 int in_mouse_face
= 0;
22737 if (WINDOWP (dpyinfo
->mouse_face_window
)
22738 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22740 int hpos
= w
->phys_cursor
.hpos
;
22741 int vpos
= w
->phys_cursor
.vpos
;
22743 if (vpos
>= dpyinfo
->mouse_face_beg_row
22744 && vpos
<= dpyinfo
->mouse_face_end_row
22745 && (vpos
> dpyinfo
->mouse_face_beg_row
22746 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22747 && (vpos
< dpyinfo
->mouse_face_end_row
22748 || hpos
< dpyinfo
->mouse_face_end_col
22749 || dpyinfo
->mouse_face_past_end
))
22753 return in_mouse_face
;
22759 /* This function sets the mouse_face_* elements of DPYINFO, assuming
22760 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
22761 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
22762 for the overlay or run of text properties specifying the mouse
22763 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
22764 before-string and after-string that must also be highlighted.
22765 DISPLAY_STRING, if non-nil, is a display string that may cover some
22766 or all of the highlighted text. */
22769 mouse_face_from_buffer_pos (Lisp_Object window
,
22770 Display_Info
*dpyinfo
,
22771 EMACS_INT mouse_charpos
,
22772 EMACS_INT start_charpos
,
22773 EMACS_INT end_charpos
,
22774 Lisp_Object before_string
,
22775 Lisp_Object after_string
,
22776 Lisp_Object display_string
)
22778 struct window
*w
= XWINDOW (window
);
22779 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22780 struct glyph_row
*row
;
22781 struct glyph
*glyph
, *end
;
22785 xassert (NILP (display_string
) || STRINGP (display_string
));
22786 xassert (NILP (before_string
) || STRINGP (before_string
));
22787 xassert (NILP (after_string
) || STRINGP (after_string
));
22789 /* Find the first highlighted glyph. */
22790 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
22792 dpyinfo
->mouse_face_beg_col
= 0;
22793 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22794 dpyinfo
->mouse_face_beg_x
= first
->x
;
22795 dpyinfo
->mouse_face_beg_y
= first
->y
;
22799 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
22801 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22803 /* If the before-string or display-string contains newlines,
22804 row_containing_pos skips to its last row. Move back. */
22805 if (!NILP (before_string
) || !NILP (display_string
))
22807 struct glyph_row
*prev
;
22808 while ((prev
= row
- 1, prev
>= first
)
22809 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
22810 && prev
->used
[TEXT_AREA
] > 0)
22812 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22813 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22814 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
22816 || !(EQ (glyph
->object
, before_string
)
22817 || EQ (glyph
->object
, display_string
)))
22823 glyph
= row
->glyphs
[TEXT_AREA
];
22824 end
= glyph
+ row
->used
[TEXT_AREA
];
22826 dpyinfo
->mouse_face_beg_y
= row
->y
;
22827 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22829 /* Skip truncation glyphs at the start of the glyph row. */
22830 if (row
->displays_text_p
)
22832 && INTEGERP (glyph
->object
)
22833 && glyph
->charpos
< 0;
22835 x
+= glyph
->pixel_width
;
22837 /* Scan the glyph row, stopping before BEFORE_STRING or
22838 DISPLAY_STRING or START_CHARPOS. */
22840 && !INTEGERP (glyph
->object
)
22841 && !EQ (glyph
->object
, before_string
)
22842 && !EQ (glyph
->object
, display_string
)
22843 && !(BUFFERP (glyph
->object
)
22844 && glyph
->charpos
>= start_charpos
);
22846 x
+= glyph
->pixel_width
;
22848 dpyinfo
->mouse_face_beg_x
= x
;
22849 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22852 /* Find the last highlighted glyph. */
22853 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
22856 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22857 dpyinfo
->mouse_face_past_end
= 1;
22859 else if (!NILP (after_string
))
22861 /* If the after-string has newlines, advance to its last row. */
22862 struct glyph_row
*next
;
22863 struct glyph_row
*last
22864 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22866 for (next
= row
+ 1;
22868 && next
->used
[TEXT_AREA
] > 0
22869 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
22874 glyph
= row
->glyphs
[TEXT_AREA
];
22875 end
= glyph
+ row
->used
[TEXT_AREA
];
22877 dpyinfo
->mouse_face_end_y
= row
->y
;
22878 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22880 /* Skip truncation glyphs at the start of the row. */
22881 if (row
->displays_text_p
)
22883 && INTEGERP (glyph
->object
)
22884 && glyph
->charpos
< 0;
22886 x
+= glyph
->pixel_width
;
22888 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
22891 && !INTEGERP (glyph
->object
)
22892 && !EQ (glyph
->object
, after_string
)
22893 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
22895 x
+= glyph
->pixel_width
;
22897 /* If we found AFTER_STRING, consume it and stop. */
22898 if (EQ (glyph
->object
, after_string
))
22900 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
22901 x
+= glyph
->pixel_width
;
22905 /* If there's no after-string, we must check if we overshot,
22906 which might be the case if we stopped after a string glyph.
22907 That glyph may belong to a before-string or display-string
22908 associated with the end position, which must not be
22910 Lisp_Object prev_object
;
22913 while (glyph
> row
->glyphs
[TEXT_AREA
])
22915 prev_object
= (glyph
- 1)->object
;
22916 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
22919 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
22920 if (pos
&& pos
< end_charpos
)
22923 for (; glyph
> row
->glyphs
[TEXT_AREA
]
22924 && EQ ((glyph
- 1)->object
, prev_object
);
22926 x
-= (glyph
- 1)->pixel_width
;
22930 dpyinfo
->mouse_face_end_x
= x
;
22931 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22932 dpyinfo
->mouse_face_window
= window
;
22933 dpyinfo
->mouse_face_face_id
22934 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
22936 !dpyinfo
->mouse_face_hidden
, -1);
22937 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22941 /* Find the position of the glyph for position POS in OBJECT in
22942 window W's current matrix, and return in *X, *Y the pixel
22943 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22945 RIGHT_P non-zero means return the position of the right edge of the
22946 glyph, RIGHT_P zero means return the left edge position.
22948 If no glyph for POS exists in the matrix, return the position of
22949 the glyph with the next smaller position that is in the matrix, if
22950 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22951 exists in the matrix, return the position of the glyph with the
22952 next larger position in OBJECT.
22954 Value is non-zero if a glyph was found. */
22957 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22960 Lisp_Object object
;
22961 int *hpos
, *vpos
, *x
, *y
;
22964 int yb
= window_text_bottom_y (w
);
22965 struct glyph_row
*r
;
22966 struct glyph
*best_glyph
= NULL
;
22967 struct glyph_row
*best_row
= NULL
;
22970 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22971 r
->enabled_p
&& r
->y
< yb
;
22974 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22975 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22978 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22979 if (EQ (g
->object
, object
))
22981 if (g
->charpos
== pos
)
22988 else if (best_glyph
== NULL
22989 || ((eabs (g
->charpos
- pos
)
22990 < eabs (best_glyph
->charpos
- pos
))
22993 : g
->charpos
> pos
)))
23007 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23011 *x
+= best_glyph
->pixel_width
;
23016 *vpos
= best_row
- w
->current_matrix
->rows
;
23019 return best_glyph
!= NULL
;
23023 /* See if position X, Y is within a hot-spot of an image. */
23026 on_hot_spot_p (hot_spot
, x
, y
)
23027 Lisp_Object hot_spot
;
23030 if (!CONSP (hot_spot
))
23033 if (EQ (XCAR (hot_spot
), Qrect
))
23035 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23036 Lisp_Object rect
= XCDR (hot_spot
);
23040 if (!CONSP (XCAR (rect
)))
23042 if (!CONSP (XCDR (rect
)))
23044 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23046 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23048 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23050 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23054 else if (EQ (XCAR (hot_spot
), Qcircle
))
23056 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23057 Lisp_Object circ
= XCDR (hot_spot
);
23058 Lisp_Object lr
, lx0
, ly0
;
23060 && CONSP (XCAR (circ
))
23061 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23062 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23063 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23065 double r
= XFLOATINT (lr
);
23066 double dx
= XINT (lx0
) - x
;
23067 double dy
= XINT (ly0
) - y
;
23068 return (dx
* dx
+ dy
* dy
<= r
* r
);
23071 else if (EQ (XCAR (hot_spot
), Qpoly
))
23073 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23074 if (VECTORP (XCDR (hot_spot
)))
23076 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23077 Lisp_Object
*poly
= v
->contents
;
23081 Lisp_Object lx
, ly
;
23084 /* Need an even number of coordinates, and at least 3 edges. */
23085 if (n
< 6 || n
& 1)
23088 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23089 If count is odd, we are inside polygon. Pixels on edges
23090 may or may not be included depending on actual geometry of the
23092 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23093 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23095 x0
= XINT (lx
), y0
= XINT (ly
);
23096 for (i
= 0; i
< n
; i
+= 2)
23098 int x1
= x0
, y1
= y0
;
23099 if ((lx
= poly
[i
], !INTEGERP (lx
))
23100 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23102 x0
= XINT (lx
), y0
= XINT (ly
);
23104 /* Does this segment cross the X line? */
23112 if (y
> y0
&& y
> y1
)
23114 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23124 find_hot_spot (map
, x
, y
)
23128 while (CONSP (map
))
23130 if (CONSP (XCAR (map
))
23131 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23139 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23141 doc
: /* Lookup in image map MAP coordinates X and Y.
23142 An image map is an alist where each element has the format (AREA ID PLIST).
23143 An AREA is specified as either a rectangle, a circle, or a polygon:
23144 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23145 pixel coordinates of the upper left and bottom right corners.
23146 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23147 and the radius of the circle; r may be a float or integer.
23148 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23149 vector describes one corner in the polygon.
23150 Returns the alist element for the first matching AREA in MAP. */)
23161 return find_hot_spot (map
, XINT (x
), XINT (y
));
23165 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23167 define_frame_cursor1 (f
, cursor
, pointer
)
23170 Lisp_Object pointer
;
23172 /* Do not change cursor shape while dragging mouse. */
23173 if (!NILP (do_mouse_tracking
))
23176 if (!NILP (pointer
))
23178 if (EQ (pointer
, Qarrow
))
23179 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23180 else if (EQ (pointer
, Qhand
))
23181 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23182 else if (EQ (pointer
, Qtext
))
23183 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23184 else if (EQ (pointer
, intern ("hdrag")))
23185 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23186 #ifdef HAVE_X_WINDOWS
23187 else if (EQ (pointer
, intern ("vdrag")))
23188 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23190 else if (EQ (pointer
, intern ("hourglass")))
23191 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23192 else if (EQ (pointer
, Qmodeline
))
23193 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23195 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23198 if (cursor
!= No_Cursor
)
23199 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23202 /* Take proper action when mouse has moved to the mode or header line
23203 or marginal area AREA of window W, x-position X and y-position Y.
23204 X is relative to the start of the text display area of W, so the
23205 width of bitmap areas and scroll bars must be subtracted to get a
23206 position relative to the start of the mode line. */
23209 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23210 Lisp_Object window
;
23212 enum window_part area
;
23214 struct window
*w
= XWINDOW (window
);
23215 struct frame
*f
= XFRAME (w
->frame
);
23216 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23217 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23218 Lisp_Object pointer
= Qnil
;
23219 int charpos
, dx
, dy
, width
, height
;
23220 Lisp_Object string
, object
= Qnil
;
23221 Lisp_Object pos
, help
;
23223 Lisp_Object mouse_face
;
23224 int original_x_pixel
= x
;
23225 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23226 struct glyph_row
*row
;
23228 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23233 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23234 &object
, &dx
, &dy
, &width
, &height
);
23236 row
= (area
== ON_MODE_LINE
23237 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23238 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23241 if (row
->mode_line_p
&& row
->enabled_p
)
23243 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23244 end
= glyph
+ row
->used
[TEXT_AREA
];
23246 for (x0
= original_x_pixel
;
23247 glyph
< end
&& x0
>= glyph
->pixel_width
;
23249 x0
-= glyph
->pixel_width
;
23257 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23258 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23259 &object
, &dx
, &dy
, &width
, &height
);
23264 if (IMAGEP (object
))
23266 Lisp_Object image_map
, hotspot
;
23267 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23269 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23271 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23273 Lisp_Object area_id
, plist
;
23275 area_id
= XCAR (hotspot
);
23276 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23277 If so, we could look for mouse-enter, mouse-leave
23278 properties in PLIST (and do something...). */
23279 hotspot
= XCDR (hotspot
);
23280 if (CONSP (hotspot
)
23281 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23283 pointer
= Fplist_get (plist
, Qpointer
);
23284 if (NILP (pointer
))
23286 help
= Fplist_get (plist
, Qhelp_echo
);
23289 help_echo_string
= help
;
23290 /* Is this correct? ++kfs */
23291 XSETWINDOW (help_echo_window
, w
);
23292 help_echo_object
= w
->buffer
;
23293 help_echo_pos
= charpos
;
23297 if (NILP (pointer
))
23298 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23301 if (STRINGP (string
))
23303 pos
= make_number (charpos
);
23304 /* If we're on a string with `help-echo' text property, arrange
23305 for the help to be displayed. This is done by setting the
23306 global variable help_echo_string to the help string. */
23309 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23312 help_echo_string
= help
;
23313 XSETWINDOW (help_echo_window
, w
);
23314 help_echo_object
= string
;
23315 help_echo_pos
= charpos
;
23319 if (NILP (pointer
))
23320 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23322 /* Change the mouse pointer according to what is under X/Y. */
23323 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23326 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23327 if (!KEYMAPP (map
))
23328 map
= Fget_text_property (pos
, Qkeymap
, string
);
23329 if (!KEYMAPP (map
))
23330 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23333 /* Change the mouse face according to what is under X/Y. */
23334 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23335 if (!NILP (mouse_face
)
23336 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23341 struct glyph
* tmp_glyph
;
23345 int total_pixel_width
;
23350 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23351 Qmouse_face
, string
, Qnil
);
23353 b
= make_number (0);
23355 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23357 e
= make_number (SCHARS (string
));
23359 /* Calculate the position(glyph position: GPOS) of GLYPH in
23360 displayed string. GPOS is different from CHARPOS.
23362 CHARPOS is the position of glyph in internal string
23363 object. A mode line string format has structures which
23364 is converted to a flatten by emacs lisp interpreter.
23365 The internal string is an element of the structures.
23366 The displayed string is the flatten string. */
23368 if (glyph
> row_start_glyph
)
23370 tmp_glyph
= glyph
- 1;
23371 while (tmp_glyph
>= row_start_glyph
23372 && tmp_glyph
->charpos
>= XINT (b
)
23373 && EQ (tmp_glyph
->object
, glyph
->object
))
23380 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23381 displayed string holding GLYPH.
23383 GSEQ_LENGTH is different from SCHARS (STRING).
23384 SCHARS (STRING) returns the length of the internal string. */
23385 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23386 tmp_glyph
->charpos
< XINT (e
);
23387 tmp_glyph
++, gseq_length
++)
23389 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23393 total_pixel_width
= 0;
23394 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23395 total_pixel_width
+= tmp_glyph
->pixel_width
;
23397 /* Pre calculation of re-rendering position */
23399 hpos
= (area
== ON_MODE_LINE
23400 ? (w
->current_matrix
)->nrows
- 1
23403 /* If the re-rendering position is included in the last
23404 re-rendering area, we should do nothing. */
23405 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23406 && dpyinfo
->mouse_face_beg_col
<= vpos
23407 && vpos
< dpyinfo
->mouse_face_end_col
23408 && dpyinfo
->mouse_face_beg_row
== hpos
)
23411 if (clear_mouse_face (dpyinfo
))
23412 cursor
= No_Cursor
;
23414 dpyinfo
->mouse_face_beg_col
= vpos
;
23415 dpyinfo
->mouse_face_beg_row
= hpos
;
23417 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23418 dpyinfo
->mouse_face_beg_y
= 0;
23420 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23421 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23423 dpyinfo
->mouse_face_end_x
= 0;
23424 dpyinfo
->mouse_face_end_y
= 0;
23426 dpyinfo
->mouse_face_past_end
= 0;
23427 dpyinfo
->mouse_face_window
= window
;
23429 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23432 glyph
->face_id
, 1);
23433 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23435 if (NILP (pointer
))
23438 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23439 clear_mouse_face (dpyinfo
);
23441 define_frame_cursor1 (f
, cursor
, pointer
);
23446 Take proper action when the mouse has moved to position X, Y on
23447 frame F as regards highlighting characters that have mouse-face
23448 properties. Also de-highlighting chars where the mouse was before.
23449 X and Y can be negative or out of range. */
23452 note_mouse_highlight (f
, x
, y
)
23456 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23457 enum window_part part
;
23458 Lisp_Object window
;
23460 Cursor cursor
= No_Cursor
;
23461 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23464 /* When a menu is active, don't highlight because this looks odd. */
23465 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23466 if (popup_activated ())
23470 if (NILP (Vmouse_highlight
)
23471 || !f
->glyphs_initialized_p
23472 || f
->pointer_invisible
)
23475 dpyinfo
->mouse_face_mouse_x
= x
;
23476 dpyinfo
->mouse_face_mouse_y
= y
;
23477 dpyinfo
->mouse_face_mouse_frame
= f
;
23479 if (dpyinfo
->mouse_face_defer
)
23482 if (gc_in_progress
)
23484 dpyinfo
->mouse_face_deferred_gc
= 1;
23488 /* Which window is that in? */
23489 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23491 /* If we were displaying active text in another window, clear that.
23492 Also clear if we move out of text area in same window. */
23493 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23494 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23495 && !NILP (dpyinfo
->mouse_face_window
)))
23496 clear_mouse_face (dpyinfo
);
23498 /* Not on a window -> return. */
23499 if (!WINDOWP (window
))
23502 /* Reset help_echo_string. It will get recomputed below. */
23503 help_echo_string
= Qnil
;
23505 /* Convert to window-relative pixel coordinates. */
23506 w
= XWINDOW (window
);
23507 frame_to_window_pixel_xy (w
, &x
, &y
);
23509 /* Handle tool-bar window differently since it doesn't display a
23511 if (EQ (window
, f
->tool_bar_window
))
23513 note_tool_bar_highlight (f
, x
, y
);
23517 /* Mouse is on the mode, header line or margin? */
23518 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23519 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23521 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23525 if (part
== ON_VERTICAL_BORDER
)
23527 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23528 help_echo_string
= build_string ("drag-mouse-1: resize");
23530 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23531 || part
== ON_SCROLL_BAR
)
23532 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23534 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23536 /* Are we in a window whose display is up to date?
23537 And verify the buffer's text has not changed. */
23538 b
= XBUFFER (w
->buffer
);
23539 if (part
== ON_TEXT
23540 && EQ (w
->window_end_valid
, w
->buffer
)
23541 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23542 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23544 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23545 struct glyph
*glyph
;
23546 Lisp_Object object
;
23547 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23548 Lisp_Object
*overlay_vec
= NULL
;
23550 struct buffer
*obuf
;
23551 int obegv
, ozv
, same_region
;
23553 /* Find the glyph under X/Y. */
23554 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23556 /* Look for :pointer property on image. */
23557 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23559 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23560 if (img
!= NULL
&& IMAGEP (img
->spec
))
23562 Lisp_Object image_map
, hotspot
;
23563 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23565 && (hotspot
= find_hot_spot (image_map
,
23566 glyph
->slice
.x
+ dx
,
23567 glyph
->slice
.y
+ dy
),
23569 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23571 Lisp_Object area_id
, plist
;
23573 area_id
= XCAR (hotspot
);
23574 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23575 If so, we could look for mouse-enter, mouse-leave
23576 properties in PLIST (and do something...). */
23577 hotspot
= XCDR (hotspot
);
23578 if (CONSP (hotspot
)
23579 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23581 pointer
= Fplist_get (plist
, Qpointer
);
23582 if (NILP (pointer
))
23584 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23585 if (!NILP (help_echo_string
))
23587 help_echo_window
= window
;
23588 help_echo_object
= glyph
->object
;
23589 help_echo_pos
= glyph
->charpos
;
23593 if (NILP (pointer
))
23594 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23598 /* Clear mouse face if X/Y not over text. */
23600 || area
!= TEXT_AREA
23601 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23603 if (clear_mouse_face (dpyinfo
))
23604 cursor
= No_Cursor
;
23605 if (NILP (pointer
))
23607 if (area
!= TEXT_AREA
)
23608 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23610 pointer
= Vvoid_text_area_pointer
;
23615 pos
= glyph
->charpos
;
23616 object
= glyph
->object
;
23617 if (!STRINGP (object
) && !BUFFERP (object
))
23620 /* If we get an out-of-range value, return now; avoid an error. */
23621 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23624 /* Make the window's buffer temporarily current for
23625 overlays_at and compute_char_face. */
23626 obuf
= current_buffer
;
23627 current_buffer
= b
;
23633 /* Is this char mouse-active or does it have help-echo? */
23634 position
= make_number (pos
);
23636 if (BUFFERP (object
))
23638 /* Put all the overlays we want in a vector in overlay_vec. */
23639 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23640 /* Sort overlays into increasing priority order. */
23641 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23646 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23647 && vpos
>= dpyinfo
->mouse_face_beg_row
23648 && vpos
<= dpyinfo
->mouse_face_end_row
23649 && (vpos
> dpyinfo
->mouse_face_beg_row
23650 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23651 && (vpos
< dpyinfo
->mouse_face_end_row
23652 || hpos
< dpyinfo
->mouse_face_end_col
23653 || dpyinfo
->mouse_face_past_end
));
23656 cursor
= No_Cursor
;
23658 /* Check mouse-face highlighting. */
23660 /* If there exists an overlay with mouse-face overlapping
23661 the one we are currently highlighting, we have to
23662 check if we enter the overlapping overlay, and then
23663 highlight only that. */
23664 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23665 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23667 /* Find the highest priority overlay with a mouse-face. */
23669 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23671 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23672 if (!NILP (mouse_face
))
23673 overlay
= overlay_vec
[i
];
23676 /* If we're highlighting the same overlay as before, there's
23677 no need to do that again. */
23678 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23679 goto check_help_echo
;
23680 dpyinfo
->mouse_face_overlay
= overlay
;
23682 /* Clear the display of the old active region, if any. */
23683 if (clear_mouse_face (dpyinfo
))
23684 cursor
= No_Cursor
;
23686 /* If no overlay applies, get a text property. */
23687 if (NILP (overlay
))
23688 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23690 /* Next, compute the bounds of the mouse highlighting and
23692 if (!NILP (mouse_face
) && STRINGP (object
))
23694 /* The mouse-highlighting comes from a display string
23695 with a mouse-face. */
23699 b
= Fprevious_single_property_change
23700 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
23701 e
= Fnext_single_property_change
23702 (position
, Qmouse_face
, object
, Qnil
);
23704 b
= make_number (0);
23706 e
= make_number (SCHARS (object
) - 1);
23708 fast_find_string_pos (w
, XINT (b
), object
,
23709 &dpyinfo
->mouse_face_beg_col
,
23710 &dpyinfo
->mouse_face_beg_row
,
23711 &dpyinfo
->mouse_face_beg_x
,
23712 &dpyinfo
->mouse_face_beg_y
, 0);
23713 fast_find_string_pos (w
, XINT (e
), object
,
23714 &dpyinfo
->mouse_face_end_col
,
23715 &dpyinfo
->mouse_face_end_row
,
23716 &dpyinfo
->mouse_face_end_x
,
23717 &dpyinfo
->mouse_face_end_y
, 1);
23718 dpyinfo
->mouse_face_past_end
= 0;
23719 dpyinfo
->mouse_face_window
= window
;
23720 dpyinfo
->mouse_face_face_id
23721 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23722 glyph
->face_id
, 1);
23723 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23724 cursor
= No_Cursor
;
23728 /* The mouse-highlighting, if any, comes from an overlay
23729 or text property in the buffer. */
23730 Lisp_Object buffer
, display_string
;
23732 if (STRINGP (object
))
23734 /* If we are on a display string with no mouse-face,
23735 check if the text under it has one. */
23736 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23737 int start
= MATRIX_ROW_START_CHARPOS (r
);
23738 pos
= string_buffer_position (w
, object
, start
);
23741 mouse_face
= get_char_property_and_overlay
23742 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
23743 buffer
= w
->buffer
;
23744 display_string
= object
;
23750 display_string
= Qnil
;
23753 if (!NILP (mouse_face
))
23755 Lisp_Object before
, after
;
23756 Lisp_Object before_string
, after_string
;
23758 if (NILP (overlay
))
23760 /* Handle the text property case. */
23761 before
= Fprevious_single_property_change
23762 (make_number (pos
+ 1), Qmouse_face
, buffer
,
23763 Fmarker_position (w
->start
));
23764 after
= Fnext_single_property_change
23765 (make_number (pos
), Qmouse_face
, buffer
,
23766 make_number (BUF_Z (XBUFFER (buffer
))
23767 - XFASTINT (w
->window_end_pos
)));
23768 before_string
= after_string
= Qnil
;
23772 /* Handle the overlay case. */
23773 before
= Foverlay_start (overlay
);
23774 after
= Foverlay_end (overlay
);
23775 before_string
= Foverlay_get (overlay
, Qbefore_string
);
23776 after_string
= Foverlay_get (overlay
, Qafter_string
);
23778 if (!STRINGP (before_string
)) before_string
= Qnil
;
23779 if (!STRINGP (after_string
)) after_string
= Qnil
;
23782 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
23785 before_string
, after_string
,
23787 cursor
= No_Cursor
;
23794 /* Look for a `help-echo' property. */
23795 if (NILP (help_echo_string
)) {
23796 Lisp_Object help
, overlay
;
23798 /* Check overlays first. */
23799 help
= overlay
= Qnil
;
23800 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23802 overlay
= overlay_vec
[i
];
23803 help
= Foverlay_get (overlay
, Qhelp_echo
);
23808 help_echo_string
= help
;
23809 help_echo_window
= window
;
23810 help_echo_object
= overlay
;
23811 help_echo_pos
= pos
;
23815 Lisp_Object object
= glyph
->object
;
23816 int charpos
= glyph
->charpos
;
23818 /* Try text properties. */
23819 if (STRINGP (object
)
23821 && charpos
< SCHARS (object
))
23823 help
= Fget_text_property (make_number (charpos
),
23824 Qhelp_echo
, object
);
23827 /* If the string itself doesn't specify a help-echo,
23828 see if the buffer text ``under'' it does. */
23829 struct glyph_row
*r
23830 = MATRIX_ROW (w
->current_matrix
, vpos
);
23831 int start
= MATRIX_ROW_START_CHARPOS (r
);
23832 int pos
= string_buffer_position (w
, object
, start
);
23835 help
= Fget_char_property (make_number (pos
),
23836 Qhelp_echo
, w
->buffer
);
23840 object
= w
->buffer
;
23845 else if (BUFFERP (object
)
23848 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23853 help_echo_string
= help
;
23854 help_echo_window
= window
;
23855 help_echo_object
= object
;
23856 help_echo_pos
= charpos
;
23861 /* Look for a `pointer' property. */
23862 if (NILP (pointer
))
23864 /* Check overlays first. */
23865 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23866 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23868 if (NILP (pointer
))
23870 Lisp_Object object
= glyph
->object
;
23871 int charpos
= glyph
->charpos
;
23873 /* Try text properties. */
23874 if (STRINGP (object
)
23876 && charpos
< SCHARS (object
))
23878 pointer
= Fget_text_property (make_number (charpos
),
23880 if (NILP (pointer
))
23882 /* If the string itself doesn't specify a pointer,
23883 see if the buffer text ``under'' it does. */
23884 struct glyph_row
*r
23885 = MATRIX_ROW (w
->current_matrix
, vpos
);
23886 int start
= MATRIX_ROW_START_CHARPOS (r
);
23887 int pos
= string_buffer_position (w
, object
, start
);
23889 pointer
= Fget_char_property (make_number (pos
),
23890 Qpointer
, w
->buffer
);
23893 else if (BUFFERP (object
)
23896 pointer
= Fget_text_property (make_number (charpos
),
23903 current_buffer
= obuf
;
23908 define_frame_cursor1 (f
, cursor
, pointer
);
23913 Clear any mouse-face on window W. This function is part of the
23914 redisplay interface, and is called from try_window_id and similar
23915 functions to ensure the mouse-highlight is off. */
23918 x_clear_window_mouse_face (w
)
23921 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23922 Lisp_Object window
;
23925 XSETWINDOW (window
, w
);
23926 if (EQ (window
, dpyinfo
->mouse_face_window
))
23927 clear_mouse_face (dpyinfo
);
23933 Just discard the mouse face information for frame F, if any.
23934 This is used when the size of F is changed. */
23937 cancel_mouse_face (f
)
23940 Lisp_Object window
;
23941 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23943 window
= dpyinfo
->mouse_face_window
;
23944 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23946 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23947 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23948 dpyinfo
->mouse_face_window
= Qnil
;
23953 #endif /* HAVE_WINDOW_SYSTEM */
23956 /***********************************************************************
23958 ***********************************************************************/
23960 #ifdef HAVE_WINDOW_SYSTEM
23962 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23963 which intersects rectangle R. R is in window-relative coordinates. */
23966 expose_area (w
, row
, r
, area
)
23968 struct glyph_row
*row
;
23970 enum glyph_row_area area
;
23972 struct glyph
*first
= row
->glyphs
[area
];
23973 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23974 struct glyph
*last
;
23975 int first_x
, start_x
, x
;
23977 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23978 /* If row extends face to end of line write the whole line. */
23979 draw_glyphs (w
, 0, row
, area
,
23980 0, row
->used
[area
],
23981 DRAW_NORMAL_TEXT
, 0);
23984 /* Set START_X to the window-relative start position for drawing glyphs of
23985 AREA. The first glyph of the text area can be partially visible.
23986 The first glyphs of other areas cannot. */
23987 start_x
= window_box_left_offset (w
, area
);
23989 if (area
== TEXT_AREA
)
23992 /* Find the first glyph that must be redrawn. */
23994 && x
+ first
->pixel_width
< r
->x
)
23996 x
+= first
->pixel_width
;
24000 /* Find the last one. */
24004 && x
< r
->x
+ r
->width
)
24006 x
+= last
->pixel_width
;
24012 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24013 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24014 DRAW_NORMAL_TEXT
, 0);
24019 /* Redraw the parts of the glyph row ROW on window W intersecting
24020 rectangle R. R is in window-relative coordinates. Value is
24021 non-zero if mouse-face was overwritten. */
24024 expose_line (w
, row
, r
)
24026 struct glyph_row
*row
;
24029 xassert (row
->enabled_p
);
24031 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24032 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24033 0, row
->used
[TEXT_AREA
],
24034 DRAW_NORMAL_TEXT
, 0);
24037 if (row
->used
[LEFT_MARGIN_AREA
])
24038 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24039 if (row
->used
[TEXT_AREA
])
24040 expose_area (w
, row
, r
, TEXT_AREA
);
24041 if (row
->used
[RIGHT_MARGIN_AREA
])
24042 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24043 draw_row_fringe_bitmaps (w
, row
);
24046 return row
->mouse_face_p
;
24050 /* Redraw those parts of glyphs rows during expose event handling that
24051 overlap other rows. Redrawing of an exposed line writes over parts
24052 of lines overlapping that exposed line; this function fixes that.
24054 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24055 row in W's current matrix that is exposed and overlaps other rows.
24056 LAST_OVERLAPPING_ROW is the last such row. */
24059 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24061 struct glyph_row
*first_overlapping_row
;
24062 struct glyph_row
*last_overlapping_row
;
24065 struct glyph_row
*row
;
24067 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24068 if (row
->overlapping_p
)
24070 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24073 if (row
->used
[LEFT_MARGIN_AREA
])
24074 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24076 if (row
->used
[TEXT_AREA
])
24077 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24079 if (row
->used
[RIGHT_MARGIN_AREA
])
24080 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24086 /* Return non-zero if W's cursor intersects rectangle R. */
24089 phys_cursor_in_rect_p (w
, r
)
24093 XRectangle cr
, result
;
24094 struct glyph
*cursor_glyph
;
24095 struct glyph_row
*row
;
24097 if (w
->phys_cursor
.vpos
>= 0
24098 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24099 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24101 && row
->cursor_in_fringe_p
)
24103 /* Cursor is in the fringe. */
24104 cr
.x
= window_box_right_offset (w
,
24105 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24106 ? RIGHT_MARGIN_AREA
24109 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24110 cr
.height
= row
->height
;
24111 return x_intersect_rectangles (&cr
, r
, &result
);
24114 cursor_glyph
= get_phys_cursor_glyph (w
);
24117 /* r is relative to W's box, but w->phys_cursor.x is relative
24118 to left edge of W's TEXT area. Adjust it. */
24119 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24120 cr
.y
= w
->phys_cursor
.y
;
24121 cr
.width
= cursor_glyph
->pixel_width
;
24122 cr
.height
= w
->phys_cursor_height
;
24123 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24124 I assume the effect is the same -- and this is portable. */
24125 return x_intersect_rectangles (&cr
, r
, &result
);
24127 /* If we don't understand the format, pretend we're not in the hot-spot. */
24133 Draw a vertical window border to the right of window W if W doesn't
24134 have vertical scroll bars. */
24137 x_draw_vertical_border (w
)
24140 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24142 /* We could do better, if we knew what type of scroll-bar the adjacent
24143 windows (on either side) have... But we don't :-(
24144 However, I think this works ok. ++KFS 2003-04-25 */
24146 /* Redraw borders between horizontally adjacent windows. Don't
24147 do it for frames with vertical scroll bars because either the
24148 right scroll bar of a window, or the left scroll bar of its
24149 neighbor will suffice as a border. */
24150 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24153 if (!WINDOW_RIGHTMOST_P (w
)
24154 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24156 int x0
, x1
, y0
, y1
;
24158 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24161 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24164 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24166 else if (!WINDOW_LEFTMOST_P (w
)
24167 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24169 int x0
, x1
, y0
, y1
;
24171 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24174 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24177 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24182 /* Redraw the part of window W intersection rectangle FR. Pixel
24183 coordinates in FR are frame-relative. Call this function with
24184 input blocked. Value is non-zero if the exposure overwrites
24188 expose_window (w
, fr
)
24192 struct frame
*f
= XFRAME (w
->frame
);
24194 int mouse_face_overwritten_p
= 0;
24196 /* If window is not yet fully initialized, do nothing. This can
24197 happen when toolkit scroll bars are used and a window is split.
24198 Reconfiguring the scroll bar will generate an expose for a newly
24200 if (w
->current_matrix
== NULL
)
24203 /* When we're currently updating the window, display and current
24204 matrix usually don't agree. Arrange for a thorough display
24206 if (w
== updated_window
)
24208 SET_FRAME_GARBAGED (f
);
24212 /* Frame-relative pixel rectangle of W. */
24213 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24214 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24215 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24216 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24218 if (x_intersect_rectangles (fr
, &wr
, &r
))
24220 int yb
= window_text_bottom_y (w
);
24221 struct glyph_row
*row
;
24222 int cursor_cleared_p
;
24223 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24225 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24226 r
.x
, r
.y
, r
.width
, r
.height
));
24228 /* Convert to window coordinates. */
24229 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24230 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24232 /* Turn off the cursor. */
24233 if (!w
->pseudo_window_p
24234 && phys_cursor_in_rect_p (w
, &r
))
24236 x_clear_cursor (w
);
24237 cursor_cleared_p
= 1;
24240 cursor_cleared_p
= 0;
24242 /* Update lines intersecting rectangle R. */
24243 first_overlapping_row
= last_overlapping_row
= NULL
;
24244 for (row
= w
->current_matrix
->rows
;
24249 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24251 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24252 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24253 || (r
.y
>= y0
&& r
.y
< y1
)
24254 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24256 /* A header line may be overlapping, but there is no need
24257 to fix overlapping areas for them. KFS 2005-02-12 */
24258 if (row
->overlapping_p
&& !row
->mode_line_p
)
24260 if (first_overlapping_row
== NULL
)
24261 first_overlapping_row
= row
;
24262 last_overlapping_row
= row
;
24266 if (expose_line (w
, row
, &r
))
24267 mouse_face_overwritten_p
= 1;
24270 else if (row
->overlapping_p
)
24272 /* We must redraw a row overlapping the exposed area. */
24274 ? y0
+ row
->phys_height
> r
.y
24275 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24277 if (first_overlapping_row
== NULL
)
24278 first_overlapping_row
= row
;
24279 last_overlapping_row
= row
;
24287 /* Display the mode line if there is one. */
24288 if (WINDOW_WANTS_MODELINE_P (w
)
24289 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24291 && row
->y
< r
.y
+ r
.height
)
24293 if (expose_line (w
, row
, &r
))
24294 mouse_face_overwritten_p
= 1;
24297 if (!w
->pseudo_window_p
)
24299 /* Fix the display of overlapping rows. */
24300 if (first_overlapping_row
)
24301 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24304 /* Draw border between windows. */
24305 x_draw_vertical_border (w
);
24307 /* Turn the cursor on again. */
24308 if (cursor_cleared_p
)
24309 update_window_cursor (w
, 1);
24313 return mouse_face_overwritten_p
;
24318 /* Redraw (parts) of all windows in the window tree rooted at W that
24319 intersect R. R contains frame pixel coordinates. Value is
24320 non-zero if the exposure overwrites mouse-face. */
24323 expose_window_tree (w
, r
)
24327 struct frame
*f
= XFRAME (w
->frame
);
24328 int mouse_face_overwritten_p
= 0;
24330 while (w
&& !FRAME_GARBAGED_P (f
))
24332 if (!NILP (w
->hchild
))
24333 mouse_face_overwritten_p
24334 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24335 else if (!NILP (w
->vchild
))
24336 mouse_face_overwritten_p
24337 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24339 mouse_face_overwritten_p
|= expose_window (w
, r
);
24341 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24344 return mouse_face_overwritten_p
;
24349 Redisplay an exposed area of frame F. X and Y are the upper-left
24350 corner of the exposed rectangle. W and H are width and height of
24351 the exposed area. All are pixel values. W or H zero means redraw
24352 the entire frame. */
24355 expose_frame (f
, x
, y
, w
, h
)
24360 int mouse_face_overwritten_p
= 0;
24362 TRACE ((stderr
, "expose_frame "));
24364 /* No need to redraw if frame will be redrawn soon. */
24365 if (FRAME_GARBAGED_P (f
))
24367 TRACE ((stderr
, " garbaged\n"));
24371 /* If basic faces haven't been realized yet, there is no point in
24372 trying to redraw anything. This can happen when we get an expose
24373 event while Emacs is starting, e.g. by moving another window. */
24374 if (FRAME_FACE_CACHE (f
) == NULL
24375 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24377 TRACE ((stderr
, " no faces\n"));
24381 if (w
== 0 || h
== 0)
24384 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24385 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24395 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24396 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24398 if (WINDOWP (f
->tool_bar_window
))
24399 mouse_face_overwritten_p
24400 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24402 #ifdef HAVE_X_WINDOWS
24404 #ifndef USE_X_TOOLKIT
24405 if (WINDOWP (f
->menu_bar_window
))
24406 mouse_face_overwritten_p
24407 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24408 #endif /* not USE_X_TOOLKIT */
24412 /* Some window managers support a focus-follows-mouse style with
24413 delayed raising of frames. Imagine a partially obscured frame,
24414 and moving the mouse into partially obscured mouse-face on that
24415 frame. The visible part of the mouse-face will be highlighted,
24416 then the WM raises the obscured frame. With at least one WM, KDE
24417 2.1, Emacs is not getting any event for the raising of the frame
24418 (even tried with SubstructureRedirectMask), only Expose events.
24419 These expose events will draw text normally, i.e. not
24420 highlighted. Which means we must redo the highlight here.
24421 Subsume it under ``we love X''. --gerd 2001-08-15 */
24422 /* Included in Windows version because Windows most likely does not
24423 do the right thing if any third party tool offers
24424 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24425 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24427 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24428 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24430 int x
= dpyinfo
->mouse_face_mouse_x
;
24431 int y
= dpyinfo
->mouse_face_mouse_y
;
24432 clear_mouse_face (dpyinfo
);
24433 note_mouse_highlight (f
, x
, y
);
24440 Determine the intersection of two rectangles R1 and R2. Return
24441 the intersection in *RESULT. Value is non-zero if RESULT is not
24445 x_intersect_rectangles (r1
, r2
, result
)
24446 XRectangle
*r1
, *r2
, *result
;
24448 XRectangle
*left
, *right
;
24449 XRectangle
*upper
, *lower
;
24450 int intersection_p
= 0;
24452 /* Rearrange so that R1 is the left-most rectangle. */
24454 left
= r1
, right
= r2
;
24456 left
= r2
, right
= r1
;
24458 /* X0 of the intersection is right.x0, if this is inside R1,
24459 otherwise there is no intersection. */
24460 if (right
->x
<= left
->x
+ left
->width
)
24462 result
->x
= right
->x
;
24464 /* The right end of the intersection is the minimum of the
24465 the right ends of left and right. */
24466 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24469 /* Same game for Y. */
24471 upper
= r1
, lower
= r2
;
24473 upper
= r2
, lower
= r1
;
24475 /* The upper end of the intersection is lower.y0, if this is inside
24476 of upper. Otherwise, there is no intersection. */
24477 if (lower
->y
<= upper
->y
+ upper
->height
)
24479 result
->y
= lower
->y
;
24481 /* The lower end of the intersection is the minimum of the lower
24482 ends of upper and lower. */
24483 result
->height
= (min (lower
->y
+ lower
->height
,
24484 upper
->y
+ upper
->height
)
24486 intersection_p
= 1;
24490 return intersection_p
;
24493 #endif /* HAVE_WINDOW_SYSTEM */
24496 /***********************************************************************
24498 ***********************************************************************/
24503 Vwith_echo_area_save_vector
= Qnil
;
24504 staticpro (&Vwith_echo_area_save_vector
);
24506 Vmessage_stack
= Qnil
;
24507 staticpro (&Vmessage_stack
);
24509 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
24510 staticpro (&Qinhibit_redisplay
);
24512 message_dolog_marker1
= Fmake_marker ();
24513 staticpro (&message_dolog_marker1
);
24514 message_dolog_marker2
= Fmake_marker ();
24515 staticpro (&message_dolog_marker2
);
24516 message_dolog_marker3
= Fmake_marker ();
24517 staticpro (&message_dolog_marker3
);
24520 defsubr (&Sdump_frame_glyph_matrix
);
24521 defsubr (&Sdump_glyph_matrix
);
24522 defsubr (&Sdump_glyph_row
);
24523 defsubr (&Sdump_tool_bar_row
);
24524 defsubr (&Strace_redisplay
);
24525 defsubr (&Strace_to_stderr
);
24527 #ifdef HAVE_WINDOW_SYSTEM
24528 defsubr (&Stool_bar_lines_needed
);
24529 defsubr (&Slookup_image_map
);
24531 defsubr (&Sformat_mode_line
);
24532 defsubr (&Sinvisible_p
);
24534 staticpro (&Qmenu_bar_update_hook
);
24535 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
24537 staticpro (&Qoverriding_terminal_local_map
);
24538 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
24540 staticpro (&Qoverriding_local_map
);
24541 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
24543 staticpro (&Qwindow_scroll_functions
);
24544 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
24546 staticpro (&Qwindow_text_change_functions
);
24547 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
24549 staticpro (&Qredisplay_end_trigger_functions
);
24550 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
24552 staticpro (&Qinhibit_point_motion_hooks
);
24553 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
24555 Qeval
= intern_c_string ("eval");
24556 staticpro (&Qeval
);
24558 QCdata
= intern_c_string (":data");
24559 staticpro (&QCdata
);
24560 Qdisplay
= intern_c_string ("display");
24561 staticpro (&Qdisplay
);
24562 Qspace_width
= intern_c_string ("space-width");
24563 staticpro (&Qspace_width
);
24564 Qraise
= intern_c_string ("raise");
24565 staticpro (&Qraise
);
24566 Qslice
= intern_c_string ("slice");
24567 staticpro (&Qslice
);
24568 Qspace
= intern_c_string ("space");
24569 staticpro (&Qspace
);
24570 Qmargin
= intern_c_string ("margin");
24571 staticpro (&Qmargin
);
24572 Qpointer
= intern_c_string ("pointer");
24573 staticpro (&Qpointer
);
24574 Qleft_margin
= intern_c_string ("left-margin");
24575 staticpro (&Qleft_margin
);
24576 Qright_margin
= intern_c_string ("right-margin");
24577 staticpro (&Qright_margin
);
24578 Qcenter
= intern_c_string ("center");
24579 staticpro (&Qcenter
);
24580 Qline_height
= intern_c_string ("line-height");
24581 staticpro (&Qline_height
);
24582 QCalign_to
= intern_c_string (":align-to");
24583 staticpro (&QCalign_to
);
24584 QCrelative_width
= intern_c_string (":relative-width");
24585 staticpro (&QCrelative_width
);
24586 QCrelative_height
= intern_c_string (":relative-height");
24587 staticpro (&QCrelative_height
);
24588 QCeval
= intern_c_string (":eval");
24589 staticpro (&QCeval
);
24590 QCpropertize
= intern_c_string (":propertize");
24591 staticpro (&QCpropertize
);
24592 QCfile
= intern_c_string (":file");
24593 staticpro (&QCfile
);
24594 Qfontified
= intern_c_string ("fontified");
24595 staticpro (&Qfontified
);
24596 Qfontification_functions
= intern_c_string ("fontification-functions");
24597 staticpro (&Qfontification_functions
);
24598 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
24599 staticpro (&Qtrailing_whitespace
);
24600 Qescape_glyph
= intern_c_string ("escape-glyph");
24601 staticpro (&Qescape_glyph
);
24602 Qnobreak_space
= intern_c_string ("nobreak-space");
24603 staticpro (&Qnobreak_space
);
24604 Qimage
= intern_c_string ("image");
24605 staticpro (&Qimage
);
24606 QCmap
= intern_c_string (":map");
24607 staticpro (&QCmap
);
24608 QCpointer
= intern_c_string (":pointer");
24609 staticpro (&QCpointer
);
24610 Qrect
= intern_c_string ("rect");
24611 staticpro (&Qrect
);
24612 Qcircle
= intern_c_string ("circle");
24613 staticpro (&Qcircle
);
24614 Qpoly
= intern_c_string ("poly");
24615 staticpro (&Qpoly
);
24616 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
24617 staticpro (&Qmessage_truncate_lines
);
24618 Qgrow_only
= intern_c_string ("grow-only");
24619 staticpro (&Qgrow_only
);
24620 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
24621 staticpro (&Qinhibit_menubar_update
);
24622 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
24623 staticpro (&Qinhibit_eval_during_redisplay
);
24624 Qposition
= intern_c_string ("position");
24625 staticpro (&Qposition
);
24626 Qbuffer_position
= intern_c_string ("buffer-position");
24627 staticpro (&Qbuffer_position
);
24628 Qobject
= intern_c_string ("object");
24629 staticpro (&Qobject
);
24630 Qbar
= intern_c_string ("bar");
24632 Qhbar
= intern_c_string ("hbar");
24633 staticpro (&Qhbar
);
24634 Qbox
= intern_c_string ("box");
24636 Qhollow
= intern_c_string ("hollow");
24637 staticpro (&Qhollow
);
24638 Qhand
= intern_c_string ("hand");
24639 staticpro (&Qhand
);
24640 Qarrow
= intern_c_string ("arrow");
24641 staticpro (&Qarrow
);
24642 Qtext
= intern_c_string ("text");
24643 staticpro (&Qtext
);
24644 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
24645 staticpro (&Qrisky_local_variable
);
24646 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
24647 staticpro (&Qinhibit_free_realized_faces
);
24649 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
24650 Fcons (intern_c_string ("void-variable"), Qnil
)),
24652 staticpro (&list_of_error
);
24654 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
24655 staticpro (&Qlast_arrow_position
);
24656 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
24657 staticpro (&Qlast_arrow_string
);
24659 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
24660 staticpro (&Qoverlay_arrow_string
);
24661 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
24662 staticpro (&Qoverlay_arrow_bitmap
);
24664 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24665 staticpro (&echo_buffer
[0]);
24666 staticpro (&echo_buffer
[1]);
24668 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24669 staticpro (&echo_area_buffer
[0]);
24670 staticpro (&echo_area_buffer
[1]);
24672 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
24673 staticpro (&Vmessages_buffer_name
);
24675 mode_line_proptrans_alist
= Qnil
;
24676 staticpro (&mode_line_proptrans_alist
);
24677 mode_line_string_list
= Qnil
;
24678 staticpro (&mode_line_string_list
);
24679 mode_line_string_face
= Qnil
;
24680 staticpro (&mode_line_string_face
);
24681 mode_line_string_face_prop
= Qnil
;
24682 staticpro (&mode_line_string_face_prop
);
24683 Vmode_line_unwind_vector
= Qnil
;
24684 staticpro (&Vmode_line_unwind_vector
);
24686 help_echo_string
= Qnil
;
24687 staticpro (&help_echo_string
);
24688 help_echo_object
= Qnil
;
24689 staticpro (&help_echo_object
);
24690 help_echo_window
= Qnil
;
24691 staticpro (&help_echo_window
);
24692 previous_help_echo_string
= Qnil
;
24693 staticpro (&previous_help_echo_string
);
24694 help_echo_pos
= -1;
24696 #ifdef HAVE_WINDOW_SYSTEM
24697 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24698 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24699 For example, if a block cursor is over a tab, it will be drawn as
24700 wide as that tab on the display. */);
24701 x_stretch_cursor_p
= 0;
24704 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24705 doc
: /* *Non-nil means highlight trailing whitespace.
24706 The face used for trailing whitespace is `trailing-whitespace'. */);
24707 Vshow_trailing_whitespace
= Qnil
;
24709 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24710 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24711 A value of t means highlight the character itself (for nobreak space,
24712 use face `nobreak-space').
24713 A value of nil means no highlighting.
24714 Other values mean display the escape glyph followed by an ordinary
24715 space or ordinary hyphen. */);
24716 Vnobreak_char_display
= Qt
;
24718 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24719 doc
: /* *The pointer shape to show in void text areas.
24720 A value of nil means to show the text pointer. Other options are `arrow',
24721 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24722 Vvoid_text_area_pointer
= Qarrow
;
24724 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24725 doc
: /* Non-nil means don't actually do any redisplay.
24726 This is used for internal purposes. */);
24727 Vinhibit_redisplay
= Qnil
;
24729 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24730 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24731 Vglobal_mode_string
= Qnil
;
24733 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24734 doc
: /* Marker for where to display an arrow on top of the buffer text.
24735 This must be the beginning of a line in order to work.
24736 See also `overlay-arrow-string'. */);
24737 Voverlay_arrow_position
= Qnil
;
24739 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24740 doc
: /* String to display as an arrow in non-window frames.
24741 See also `overlay-arrow-position'. */);
24742 Voverlay_arrow_string
= make_pure_c_string ("=>");
24744 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24745 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24746 The symbols on this list are examined during redisplay to determine
24747 where to display overlay arrows. */);
24748 Voverlay_arrow_variable_list
24749 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
24751 DEFVAR_INT ("scroll-step", &scroll_step
,
24752 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24753 If that fails to bring point back on frame, point is centered instead.
24754 If this is zero, point is always centered after it moves off frame.
24755 If you want scrolling to always be a line at a time, you should set
24756 `scroll-conservatively' to a large value rather than set this to 1. */);
24758 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24759 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24760 If point moves off-screen, redisplay will scroll by up to
24761 `scroll-conservatively' lines in order to bring point just barely
24762 onto the screen again. If that cannot be done, then redisplay
24763 recenters point as usual.
24765 A value of zero means always recenter point if it moves off screen. */);
24766 scroll_conservatively
= 0;
24768 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24769 doc
: /* *Number of lines of margin at the top and bottom of a window.
24770 Recenter the window whenever point gets within this many lines
24771 of the top or bottom of the window. */);
24774 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24775 doc
: /* Pixels per inch value for non-window system displays.
24776 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24777 Vdisplay_pixels_per_inch
= make_float (72.0);
24780 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24783 DEFVAR_LISP ("truncate-partial-width-windows",
24784 &Vtruncate_partial_width_windows
,
24785 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
24786 For an integer value, truncate lines in each window narrower than the
24787 full frame width, provided the window width is less than that integer;
24788 otherwise, respect the value of `truncate-lines'.
24790 For any other non-nil value, truncate lines in all windows that do
24791 not span the full frame width.
24793 A value of nil means to respect the value of `truncate-lines'.
24795 If `word-wrap' is enabled, you might want to reduce this. */);
24796 Vtruncate_partial_width_windows
= make_number (50);
24798 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24799 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24800 Any other value means to use the appropriate face, `mode-line',
24801 `header-line', or `menu' respectively. */);
24802 mode_line_inverse_video
= 1;
24804 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24805 doc
: /* *Maximum buffer size for which line number should be displayed.
24806 If the buffer is bigger than this, the line number does not appear
24807 in the mode line. A value of nil means no limit. */);
24808 Vline_number_display_limit
= Qnil
;
24810 DEFVAR_INT ("line-number-display-limit-width",
24811 &line_number_display_limit_width
,
24812 doc
: /* *Maximum line width (in characters) for line number display.
24813 If the average length of the lines near point is bigger than this, then the
24814 line number may be omitted from the mode line. */);
24815 line_number_display_limit_width
= 200;
24817 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24818 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24819 highlight_nonselected_windows
= 0;
24821 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24822 doc
: /* Non-nil if more than one frame is visible on this display.
24823 Minibuffer-only frames don't count, but iconified frames do.
24824 This variable is not guaranteed to be accurate except while processing
24825 `frame-title-format' and `icon-title-format'. */);
24827 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24828 doc
: /* Template for displaying the title bar of visible frames.
24829 \(Assuming the window manager supports this feature.)
24831 This variable has the same structure as `mode-line-format', except that
24832 the %c and %l constructs are ignored. It is used only on frames for
24833 which no explicit name has been set \(see `modify-frame-parameters'). */);
24835 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24836 doc
: /* Template for displaying the title bar of an iconified frame.
24837 \(Assuming the window manager supports this feature.)
24838 This variable has the same structure as `mode-line-format' (which see),
24839 and is used only on frames for which no explicit name has been set
24840 \(see `modify-frame-parameters'). */);
24842 = Vframe_title_format
24843 = pure_cons (intern_c_string ("multiple-frames"),
24844 pure_cons (make_pure_c_string ("%b"),
24845 pure_cons (pure_cons (empty_unibyte_string
,
24846 pure_cons (intern_c_string ("invocation-name"),
24847 pure_cons (make_pure_c_string ("@"),
24848 pure_cons (intern_c_string ("system-name"),
24852 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24853 doc
: /* Maximum number of lines to keep in the message log buffer.
24854 If nil, disable message logging. If t, log messages but don't truncate
24855 the buffer when it becomes large. */);
24856 Vmessage_log_max
= make_number (100);
24858 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24859 doc
: /* Functions called before redisplay, if window sizes have changed.
24860 The value should be a list of functions that take one argument.
24861 Just before redisplay, for each frame, if any of its windows have changed
24862 size since the last redisplay, or have been split or deleted,
24863 all the functions in the list are called, with the frame as argument. */);
24864 Vwindow_size_change_functions
= Qnil
;
24866 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24867 doc
: /* List of functions to call before redisplaying a window with scrolling.
24868 Each function is called with two arguments, the window and its new
24869 display-start position. Note that these functions are also called by
24870 `set-window-buffer'. Also note that the value of `window-end' is not
24871 valid when these functions are called. */);
24872 Vwindow_scroll_functions
= Qnil
;
24874 DEFVAR_LISP ("window-text-change-functions",
24875 &Vwindow_text_change_functions
,
24876 doc
: /* Functions to call in redisplay when text in the window might change. */);
24877 Vwindow_text_change_functions
= Qnil
;
24879 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24880 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24881 Each function is called with two arguments, the window and the end trigger value.
24882 See `set-window-redisplay-end-trigger'. */);
24883 Vredisplay_end_trigger_functions
= Qnil
;
24885 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24886 doc
: /* *Non-nil means autoselect window with mouse pointer.
24887 If nil, do not autoselect windows.
24888 A positive number means delay autoselection by that many seconds: a
24889 window is autoselected only after the mouse has remained in that
24890 window for the duration of the delay.
24891 A negative number has a similar effect, but causes windows to be
24892 autoselected only after the mouse has stopped moving. \(Because of
24893 the way Emacs compares mouse events, you will occasionally wait twice
24894 that time before the window gets selected.\)
24895 Any other value means to autoselect window instantaneously when the
24896 mouse pointer enters it.
24898 Autoselection selects the minibuffer only if it is active, and never
24899 unselects the minibuffer if it is active.
24901 When customizing this variable make sure that the actual value of
24902 `focus-follows-mouse' matches the behavior of your window manager. */);
24903 Vmouse_autoselect_window
= Qnil
;
24905 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24906 doc
: /* *Non-nil means automatically resize tool-bars.
24907 This dynamically changes the tool-bar's height to the minimum height
24908 that is needed to make all tool-bar items visible.
24909 If value is `grow-only', the tool-bar's height is only increased
24910 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24911 Vauto_resize_tool_bars
= Qt
;
24913 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24914 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24915 auto_raise_tool_bar_buttons_p
= 1;
24917 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24918 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24919 make_cursor_line_fully_visible_p
= 1;
24921 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24922 doc
: /* *Border below tool-bar in pixels.
24923 If an integer, use it as the height of the border.
24924 If it is one of `internal-border-width' or `border-width', use the
24925 value of the corresponding frame parameter.
24926 Otherwise, no border is added below the tool-bar. */);
24927 Vtool_bar_border
= Qinternal_border_width
;
24929 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24930 doc
: /* *Margin around tool-bar buttons in pixels.
24931 If an integer, use that for both horizontal and vertical margins.
24932 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24933 HORZ specifying the horizontal margin, and VERT specifying the
24934 vertical margin. */);
24935 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24937 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24938 doc
: /* *Relief thickness of tool-bar buttons. */);
24939 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24941 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24942 doc
: /* List of functions to call to fontify regions of text.
24943 Each function is called with one argument POS. Functions must
24944 fontify a region starting at POS in the current buffer, and give
24945 fontified regions the property `fontified'. */);
24946 Vfontification_functions
= Qnil
;
24947 Fmake_variable_buffer_local (Qfontification_functions
);
24949 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24950 &unibyte_display_via_language_environment
,
24951 doc
: /* *Non-nil means display unibyte text according to language environment.
24952 Specifically, this means that raw bytes in the range 160-255 decimal
24953 are displayed by converting them to the equivalent multibyte characters
24954 according to the current language environment. As a result, they are
24955 displayed according to the current fontset.
24957 Note that this variable affects only how these bytes are displayed,
24958 but does not change the fact they are interpreted as raw bytes. */);
24959 unibyte_display_via_language_environment
= 0;
24961 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24962 doc
: /* *Maximum height for resizing mini-windows.
24963 If a float, it specifies a fraction of the mini-window frame's height.
24964 If an integer, it specifies a number of lines. */);
24965 Vmax_mini_window_height
= make_float (0.25);
24967 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24968 doc
: /* *How to resize mini-windows.
24969 A value of nil means don't automatically resize mini-windows.
24970 A value of t means resize them to fit the text displayed in them.
24971 A value of `grow-only', the default, means let mini-windows grow
24972 only, until their display becomes empty, at which point the windows
24973 go back to their normal size. */);
24974 Vresize_mini_windows
= Qgrow_only
;
24976 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24977 doc
: /* Alist specifying how to blink the cursor off.
24978 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24979 `cursor-type' frame-parameter or variable equals ON-STATE,
24980 comparing using `equal', Emacs uses OFF-STATE to specify
24981 how to blink it off. ON-STATE and OFF-STATE are values for
24982 the `cursor-type' frame parameter.
24984 If a frame's ON-STATE has no entry in this list,
24985 the frame's other specifications determine how to blink the cursor off. */);
24986 Vblink_cursor_alist
= Qnil
;
24988 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24989 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24990 automatic_hscrolling_p
= 1;
24991 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
24992 staticpro (&Qauto_hscroll_mode
);
24994 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24995 doc
: /* *How many columns away from the window edge point is allowed to get
24996 before automatic hscrolling will horizontally scroll the window. */);
24997 hscroll_margin
= 5;
24999 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25000 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25001 When point is less than `hscroll-margin' columns from the window
25002 edge, automatic hscrolling will scroll the window by the amount of columns
25003 determined by this variable. If its value is a positive integer, scroll that
25004 many columns. If it's a positive floating-point number, it specifies the
25005 fraction of the window's width to scroll. If it's nil or zero, point will be
25006 centered horizontally after the scroll. Any other value, including negative
25007 numbers, are treated as if the value were zero.
25009 Automatic hscrolling always moves point outside the scroll margin, so if
25010 point was more than scroll step columns inside the margin, the window will
25011 scroll more than the value given by the scroll step.
25013 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25014 and `scroll-right' overrides this variable's effect. */);
25015 Vhscroll_step
= make_number (0);
25017 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25018 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25019 Bind this around calls to `message' to let it take effect. */);
25020 message_truncate_lines
= 0;
25022 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25023 doc
: /* Normal hook run to update the menu bar definitions.
25024 Redisplay runs this hook before it redisplays the menu bar.
25025 This is used to update submenus such as Buffers,
25026 whose contents depend on various data. */);
25027 Vmenu_bar_update_hook
= Qnil
;
25029 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25030 doc
: /* Frame for which we are updating a menu.
25031 The enable predicate for a menu binding should check this variable. */);
25032 Vmenu_updating_frame
= Qnil
;
25034 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25035 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25036 inhibit_menubar_update
= 0;
25038 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25039 doc
: /* Prefix prepended to all continuation lines at display time.
25040 The value may be a string, an image, or a stretch-glyph; it is
25041 interpreted in the same way as the value of a `display' text property.
25043 This variable is overridden by any `wrap-prefix' text or overlay
25046 To add a prefix to non-continuation lines, use `line-prefix'. */);
25047 Vwrap_prefix
= Qnil
;
25048 staticpro (&Qwrap_prefix
);
25049 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25050 Fmake_variable_buffer_local (Qwrap_prefix
);
25052 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25053 doc
: /* Prefix prepended to all non-continuation lines at display time.
25054 The value may be a string, an image, or a stretch-glyph; it is
25055 interpreted in the same way as the value of a `display' text property.
25057 This variable is overridden by any `line-prefix' text or overlay
25060 To add a prefix to continuation lines, use `wrap-prefix'. */);
25061 Vline_prefix
= Qnil
;
25062 staticpro (&Qline_prefix
);
25063 Qline_prefix
= intern_c_string ("line-prefix");
25064 Fmake_variable_buffer_local (Qline_prefix
);
25066 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25067 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25068 inhibit_eval_during_redisplay
= 0;
25070 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25071 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25072 inhibit_free_realized_faces
= 0;
25075 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25076 doc
: /* Inhibit try_window_id display optimization. */);
25077 inhibit_try_window_id
= 0;
25079 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25080 doc
: /* Inhibit try_window_reusing display optimization. */);
25081 inhibit_try_window_reusing
= 0;
25083 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25084 doc
: /* Inhibit try_cursor_movement display optimization. */);
25085 inhibit_try_cursor_movement
= 0;
25086 #endif /* GLYPH_DEBUG */
25088 DEFVAR_INT ("overline-margin", &overline_margin
,
25089 doc
: /* *Space between overline and text, in pixels.
25090 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25091 margin to the caracter height. */);
25092 overline_margin
= 2;
25094 DEFVAR_INT ("underline-minimum-offset",
25095 &underline_minimum_offset
,
25096 doc
: /* Minimum distance between baseline and underline.
25097 This can improve legibility of underlined text at small font sizes,
25098 particularly when using variable `x-use-underline-position-properties'
25099 with fonts that specify an UNDERLINE_POSITION relatively close to the
25100 baseline. The default value is 1. */);
25101 underline_minimum_offset
= 1;
25103 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25104 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25105 display_hourglass_p
= 1;
25107 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25108 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25109 Value must be an integer or float. */);
25110 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25112 hourglass_atimer
= NULL
;
25113 hourglass_shown_p
= 0;
25117 /* Initialize this module when Emacs starts. */
25122 Lisp_Object root_window
;
25123 struct window
*mini_w
;
25125 current_header_line_height
= current_mode_line_height
= -1;
25127 CHARPOS (this_line_start_pos
) = 0;
25129 mini_w
= XWINDOW (minibuf_window
);
25130 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25132 if (!noninteractive
)
25134 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25137 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25138 set_window_height (root_window
,
25139 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25141 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25142 set_window_height (minibuf_window
, 1, 0);
25144 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25145 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25147 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25148 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25149 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25151 /* The default ellipsis glyphs `...'. */
25152 for (i
= 0; i
< 3; ++i
)
25153 default_invis_vector
[i
] = make_number ('.');
25157 /* Allocate the buffer for frame titles.
25158 Also used for `format-mode-line'. */
25160 mode_line_noprop_buf
= (char *) xmalloc (size
);
25161 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25162 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25163 mode_line_target
= MODE_LINE_DISPLAY
;
25166 help_echo_showing_p
= 0;
25169 /* Since w32 does not support atimers, it defines its own implementation of
25170 the following three functions in w32fns.c. */
25173 /* Platform-independent portion of hourglass implementation. */
25175 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25177 hourglass_started ()
25179 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25182 /* Cancel a currently active hourglass timer, and start a new one. */
25186 #if defined (HAVE_WINDOW_SYSTEM)
25188 int secs
, usecs
= 0;
25190 cancel_hourglass ();
25192 if (INTEGERP (Vhourglass_delay
)
25193 && XINT (Vhourglass_delay
) > 0)
25194 secs
= XFASTINT (Vhourglass_delay
);
25195 else if (FLOATP (Vhourglass_delay
)
25196 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25199 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25200 secs
= XFASTINT (tem
);
25201 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25204 secs
= DEFAULT_HOURGLASS_DELAY
;
25206 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25207 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25208 show_hourglass
, NULL
);
25213 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25216 cancel_hourglass ()
25218 #if defined (HAVE_WINDOW_SYSTEM)
25219 if (hourglass_atimer
)
25221 cancel_atimer (hourglass_atimer
);
25222 hourglass_atimer
= NULL
;
25225 if (hourglass_shown_p
)
25229 #endif /* ! WINDOWSNT */
25231 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25232 (do not change this comment) */