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
, Qdefault
;
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. Return in *LEN the length of
1458 the character. This is like STRING_CHAR_AND_LENGTH but never
1459 returns an invalid character. If we find one, we return a `?', but
1460 with the length of the invalid character. */
1463 string_char_and_length (str
, len
)
1464 const unsigned char *str
;
1469 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1470 if (!CHAR_VALID_P (c
, 1))
1471 /* We may not change the length here because other places in Emacs
1472 don't use this function, i.e. they silently accept invalid
1481 /* Given a position POS containing a valid character and byte position
1482 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1484 static struct text_pos
1485 string_pos_nchars_ahead (pos
, string
, nchars
)
1486 struct text_pos pos
;
1490 xassert (STRINGP (string
) && nchars
>= 0);
1492 if (STRING_MULTIBYTE (string
))
1494 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1499 string_char_and_length (p
, &len
);
1502 BYTEPOS (pos
) += len
;
1506 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1512 /* Value is the text position, i.e. character and byte position,
1513 for character position CHARPOS in STRING. */
1515 static INLINE
struct text_pos
1516 string_pos (charpos
, string
)
1520 struct text_pos pos
;
1521 xassert (STRINGP (string
));
1522 xassert (charpos
>= 0);
1523 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1528 /* Value is a text position, i.e. character and byte position, for
1529 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1530 means recognize multibyte characters. */
1532 static struct text_pos
1533 c_string_pos (charpos
, s
, multibyte_p
)
1538 struct text_pos pos
;
1540 xassert (s
!= NULL
);
1541 xassert (charpos
>= 0);
1547 SET_TEXT_POS (pos
, 0, 0);
1550 string_char_and_length (s
, &len
);
1553 BYTEPOS (pos
) += len
;
1557 SET_TEXT_POS (pos
, charpos
, charpos
);
1563 /* Value is the number of characters in C string S. MULTIBYTE_P
1564 non-zero means recognize multibyte characters. */
1567 number_of_chars (s
, multibyte_p
)
1575 int rest
= strlen (s
), len
;
1576 unsigned char *p
= (unsigned char *) s
;
1578 for (nchars
= 0; rest
> 0; ++nchars
)
1580 string_char_and_length (p
, &len
);
1581 rest
-= len
, p
+= len
;
1585 nchars
= strlen (s
);
1591 /* Compute byte position NEWPOS->bytepos corresponding to
1592 NEWPOS->charpos. POS is a known position in string STRING.
1593 NEWPOS->charpos must be >= POS.charpos. */
1596 compute_string_pos (newpos
, pos
, string
)
1597 struct text_pos
*newpos
, pos
;
1600 xassert (STRINGP (string
));
1601 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1603 if (STRING_MULTIBYTE (string
))
1604 *newpos
= string_pos_nchars_ahead (pos
, string
,
1605 CHARPOS (*newpos
) - CHARPOS (pos
));
1607 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1611 Return an estimation of the pixel height of mode or header lines on
1612 frame F. FACE_ID specifies what line's height to estimate. */
1615 estimate_mode_line_height (f
, face_id
)
1617 enum face_id face_id
;
1619 #ifdef HAVE_WINDOW_SYSTEM
1620 if (FRAME_WINDOW_P (f
))
1622 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1624 /* This function is called so early when Emacs starts that the face
1625 cache and mode line face are not yet initialized. */
1626 if (FRAME_FACE_CACHE (f
))
1628 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1632 height
= FONT_HEIGHT (face
->font
);
1633 if (face
->box_line_width
> 0)
1634 height
+= 2 * face
->box_line_width
;
1645 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1646 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1647 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1648 not force the value into range. */
1651 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1653 register int pix_x
, pix_y
;
1655 NativeRectangle
*bounds
;
1659 #ifdef HAVE_WINDOW_SYSTEM
1660 if (FRAME_WINDOW_P (f
))
1662 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1663 even for negative values. */
1665 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1667 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1669 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1670 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1673 STORE_NATIVE_RECT (*bounds
,
1674 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1675 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1676 FRAME_COLUMN_WIDTH (f
) - 1,
1677 FRAME_LINE_HEIGHT (f
) - 1);
1683 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1684 pix_x
= FRAME_TOTAL_COLS (f
);
1688 else if (pix_y
> FRAME_LINES (f
))
1689 pix_y
= FRAME_LINES (f
);
1699 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1700 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1701 can't tell the positions because W's display is not up to date,
1705 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1708 int *frame_x
, *frame_y
;
1710 #ifdef HAVE_WINDOW_SYSTEM
1711 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1715 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1716 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1718 if (display_completed
)
1720 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1721 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1722 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1728 hpos
+= glyph
->pixel_width
;
1732 /* If first glyph is partially visible, its first visible position is still 0. */
1744 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1745 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1756 #ifdef HAVE_WINDOW_SYSTEM
1758 /* Find the glyph under window-relative coordinates X/Y in window W.
1759 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1760 strings. Return in *HPOS and *VPOS the row and column number of
1761 the glyph found. Return in *AREA the glyph area containing X.
1762 Value is a pointer to the glyph found or null if X/Y is not on
1763 text, or we can't tell because W's current matrix is not up to
1768 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1771 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1773 struct glyph
*glyph
, *end
;
1774 struct glyph_row
*row
= NULL
;
1777 /* Find row containing Y. Give up if some row is not enabled. */
1778 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1780 row
= MATRIX_ROW (w
->current_matrix
, i
);
1781 if (!row
->enabled_p
)
1783 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1790 /* Give up if Y is not in the window. */
1791 if (i
== w
->current_matrix
->nrows
)
1794 /* Get the glyph area containing X. */
1795 if (w
->pseudo_window_p
)
1802 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1804 *area
= LEFT_MARGIN_AREA
;
1805 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1807 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1810 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1814 *area
= RIGHT_MARGIN_AREA
;
1815 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1819 /* Find glyph containing X. */
1820 glyph
= row
->glyphs
[*area
];
1821 end
= glyph
+ row
->used
[*area
];
1823 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1825 x
-= glyph
->pixel_width
;
1835 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1838 *hpos
= glyph
- row
->glyphs
[*area
];
1844 Convert frame-relative x/y to coordinates relative to window W.
1845 Takes pseudo-windows into account. */
1848 frame_to_window_pixel_xy (w
, x
, y
)
1852 if (w
->pseudo_window_p
)
1854 /* A pseudo-window is always full-width, and starts at the
1855 left edge of the frame, plus a frame border. */
1856 struct frame
*f
= XFRAME (w
->frame
);
1857 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1858 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1862 *x
-= WINDOW_LEFT_EDGE_X (w
);
1863 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1868 Return in RECTS[] at most N clipping rectangles for glyph string S.
1869 Return the number of stored rectangles. */
1872 get_glyph_string_clip_rects (s
, rects
, n
)
1873 struct glyph_string
*s
;
1874 NativeRectangle
*rects
;
1882 if (s
->row
->full_width_p
)
1884 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1885 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1886 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1888 /* Unless displaying a mode or menu bar line, which are always
1889 fully visible, clip to the visible part of the row. */
1890 if (s
->w
->pseudo_window_p
)
1891 r
.height
= s
->row
->visible_height
;
1893 r
.height
= s
->height
;
1897 /* This is a text line that may be partially visible. */
1898 r
.x
= window_box_left (s
->w
, s
->area
);
1899 r
.width
= window_box_width (s
->w
, s
->area
);
1900 r
.height
= s
->row
->visible_height
;
1904 if (r
.x
< s
->clip_head
->x
)
1906 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1907 r
.width
-= s
->clip_head
->x
- r
.x
;
1910 r
.x
= s
->clip_head
->x
;
1913 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1915 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1916 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1921 /* If S draws overlapping rows, it's sufficient to use the top and
1922 bottom of the window for clipping because this glyph string
1923 intentionally draws over other lines. */
1924 if (s
->for_overlaps
)
1926 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1927 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1929 /* Alas, the above simple strategy does not work for the
1930 environments with anti-aliased text: if the same text is
1931 drawn onto the same place multiple times, it gets thicker.
1932 If the overlap we are processing is for the erased cursor, we
1933 take the intersection with the rectagle of the cursor. */
1934 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1936 XRectangle rc
, r_save
= r
;
1938 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1939 rc
.y
= s
->w
->phys_cursor
.y
;
1940 rc
.width
= s
->w
->phys_cursor_width
;
1941 rc
.height
= s
->w
->phys_cursor_height
;
1943 x_intersect_rectangles (&r_save
, &rc
, &r
);
1948 /* Don't use S->y for clipping because it doesn't take partially
1949 visible lines into account. For example, it can be negative for
1950 partially visible lines at the top of a window. */
1951 if (!s
->row
->full_width_p
1952 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1953 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1955 r
.y
= max (0, s
->row
->y
);
1958 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1960 /* If drawing the cursor, don't let glyph draw outside its
1961 advertised boundaries. Cleartype does this under some circumstances. */
1962 if (s
->hl
== DRAW_CURSOR
)
1964 struct glyph
*glyph
= s
->first_glyph
;
1969 r
.width
-= s
->x
- r
.x
;
1972 r
.width
= min (r
.width
, glyph
->pixel_width
);
1974 /* If r.y is below window bottom, ensure that we still see a cursor. */
1975 height
= min (glyph
->ascent
+ glyph
->descent
,
1976 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1977 max_y
= window_text_bottom_y (s
->w
) - height
;
1978 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1979 if (s
->ybase
- glyph
->ascent
> max_y
)
1986 /* Don't draw cursor glyph taller than our actual glyph. */
1987 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1988 if (height
< r
.height
)
1990 max_y
= r
.y
+ r
.height
;
1991 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1992 r
.height
= min (max_y
- r
.y
, height
);
1999 XRectangle r_save
= r
;
2001 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2005 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2006 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2008 #ifdef CONVERT_FROM_XRECT
2009 CONVERT_FROM_XRECT (r
, *rects
);
2017 /* If we are processing overlapping and allowed to return
2018 multiple clipping rectangles, we exclude the row of the glyph
2019 string from the clipping rectangle. This is to avoid drawing
2020 the same text on the environment with anti-aliasing. */
2021 #ifdef CONVERT_FROM_XRECT
2024 XRectangle
*rs
= rects
;
2026 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2028 if (s
->for_overlaps
& OVERLAPS_PRED
)
2031 if (r
.y
+ r
.height
> row_y
)
2034 rs
[i
].height
= row_y
- r
.y
;
2040 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2043 if (r
.y
< row_y
+ s
->row
->visible_height
)
2045 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2047 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2048 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2057 #ifdef CONVERT_FROM_XRECT
2058 for (i
= 0; i
< n
; i
++)
2059 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2066 Return in *NR the clipping rectangle for glyph string S. */
2069 get_glyph_string_clip_rect (s
, nr
)
2070 struct glyph_string
*s
;
2071 NativeRectangle
*nr
;
2073 get_glyph_string_clip_rects (s
, nr
, 1);
2078 Return the position and height of the phys cursor in window W.
2079 Set w->phys_cursor_width to width of phys cursor.
2083 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2085 struct glyph_row
*row
;
2086 struct glyph
*glyph
;
2087 int *xp
, *yp
, *heightp
;
2089 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2090 int x
, y
, wd
, h
, h0
, y0
;
2092 /* Compute the width of the rectangle to draw. If on a stretch
2093 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2094 rectangle as wide as the glyph, but use a canonical character
2096 wd
= glyph
->pixel_width
- 1;
2097 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2101 x
= w
->phys_cursor
.x
;
2108 if (glyph
->type
== STRETCH_GLYPH
2109 && !x_stretch_cursor_p
)
2110 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2111 w
->phys_cursor_width
= wd
;
2113 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2115 /* If y is below window bottom, ensure that we still see a cursor. */
2116 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2118 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2119 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2121 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2124 h
= max (h
- (y0
- y
) + 1, h0
);
2129 y0
= window_text_bottom_y (w
) - h0
;
2137 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2138 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2143 * Remember which glyph the mouse is over.
2147 remember_mouse_glyph (f
, gx
, gy
, rect
)
2150 NativeRectangle
*rect
;
2154 struct glyph_row
*r
, *gr
, *end_row
;
2155 enum window_part part
;
2156 enum glyph_row_area area
;
2157 int x
, y
, width
, height
;
2159 /* Try to determine frame pixel position and size of the glyph under
2160 frame pixel coordinates X/Y on frame F. */
2162 if (!f
->glyphs_initialized_p
2163 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2166 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2167 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2171 w
= XWINDOW (window
);
2172 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2173 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2175 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2176 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2178 if (w
->pseudo_window_p
)
2181 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2187 case ON_LEFT_MARGIN
:
2188 area
= LEFT_MARGIN_AREA
;
2191 case ON_RIGHT_MARGIN
:
2192 area
= RIGHT_MARGIN_AREA
;
2195 case ON_HEADER_LINE
:
2197 gr
= (part
== ON_HEADER_LINE
2198 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2199 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2202 goto text_glyph_row_found
;
2209 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2210 if (r
->y
+ r
->height
> y
)
2216 text_glyph_row_found
:
2219 struct glyph
*g
= gr
->glyphs
[area
];
2220 struct glyph
*end
= g
+ gr
->used
[area
];
2222 height
= gr
->height
;
2223 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2224 if (gx
+ g
->pixel_width
> x
)
2229 if (g
->type
== IMAGE_GLYPH
)
2231 /* Don't remember when mouse is over image, as
2232 image may have hot-spots. */
2233 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2236 width
= g
->pixel_width
;
2240 /* Use nominal char spacing at end of line. */
2242 gx
+= (x
/ width
) * width
;
2245 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2246 gx
+= window_box_left_offset (w
, area
);
2250 /* Use nominal line height at end of window. */
2251 gx
= (x
/ width
) * width
;
2253 gy
+= (y
/ height
) * height
;
2257 case ON_LEFT_FRINGE
:
2258 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2259 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2260 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2261 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2264 case ON_RIGHT_FRINGE
:
2265 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2266 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2267 : window_box_right_offset (w
, TEXT_AREA
));
2268 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2272 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2274 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2275 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2276 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2278 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2282 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2283 if (r
->y
+ r
->height
> y
)
2290 height
= gr
->height
;
2293 /* Use nominal line height at end of window. */
2295 gy
+= (y
/ height
) * height
;
2302 /* If there is no glyph under the mouse, then we divide the screen
2303 into a grid of the smallest glyph in the frame, and use that
2306 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2307 round down even for negative values. */
2313 gx
= (gx
/ width
) * width
;
2314 gy
= (gy
/ height
) * height
;
2319 gx
+= WINDOW_LEFT_EDGE_X (w
);
2320 gy
+= WINDOW_TOP_EDGE_Y (w
);
2323 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2325 /* Visible feedback for debugging. */
2328 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2329 f
->output_data
.x
->normal_gc
,
2330 gx
, gy
, width
, height
);
2336 #endif /* HAVE_WINDOW_SYSTEM */
2339 /***********************************************************************
2340 Lisp form evaluation
2341 ***********************************************************************/
2343 /* Error handler for safe_eval and safe_call. */
2346 safe_eval_handler (arg
)
2349 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2354 /* Evaluate SEXPR and return the result, or nil if something went
2355 wrong. Prevent redisplay during the evaluation. */
2357 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2358 Return the result, or nil if something went wrong. Prevent
2359 redisplay during the evaluation. */
2362 safe_call (nargs
, args
)
2368 if (inhibit_eval_during_redisplay
)
2372 int count
= SPECPDL_INDEX ();
2373 struct gcpro gcpro1
;
2376 gcpro1
.nvars
= nargs
;
2377 specbind (Qinhibit_redisplay
, Qt
);
2378 /* Use Qt to ensure debugger does not run,
2379 so there is no possibility of wanting to redisplay. */
2380 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2383 val
= unbind_to (count
, val
);
2390 /* Call function FN with one argument ARG.
2391 Return the result, or nil if something went wrong. */
2394 safe_call1 (fn
, arg
)
2395 Lisp_Object fn
, arg
;
2397 Lisp_Object args
[2];
2400 return safe_call (2, args
);
2403 static Lisp_Object Qeval
;
2406 safe_eval (Lisp_Object sexpr
)
2408 return safe_call1 (Qeval
, sexpr
);
2411 /* Call function FN with one argument ARG.
2412 Return the result, or nil if something went wrong. */
2415 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2417 Lisp_Object args
[3];
2421 return safe_call (3, args
);
2426 /***********************************************************************
2428 ***********************************************************************/
2432 /* Define CHECK_IT to perform sanity checks on iterators.
2433 This is for debugging. It is too slow to do unconditionally. */
2439 if (it
->method
== GET_FROM_STRING
)
2441 xassert (STRINGP (it
->string
));
2442 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2446 xassert (IT_STRING_CHARPOS (*it
) < 0);
2447 if (it
->method
== GET_FROM_BUFFER
)
2449 /* Check that character and byte positions agree. */
2450 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2455 xassert (it
->current
.dpvec_index
>= 0);
2457 xassert (it
->current
.dpvec_index
< 0);
2460 #define CHECK_IT(IT) check_it ((IT))
2464 #define CHECK_IT(IT) (void) 0
2471 /* Check that the window end of window W is what we expect it
2472 to be---the last row in the current matrix displaying text. */
2475 check_window_end (w
)
2478 if (!MINI_WINDOW_P (w
)
2479 && !NILP (w
->window_end_valid
))
2481 struct glyph_row
*row
;
2482 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2483 XFASTINT (w
->window_end_vpos
)),
2485 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2486 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2490 #define CHECK_WINDOW_END(W) check_window_end ((W))
2492 #else /* not GLYPH_DEBUG */
2494 #define CHECK_WINDOW_END(W) (void) 0
2496 #endif /* not GLYPH_DEBUG */
2500 /***********************************************************************
2501 Iterator initialization
2502 ***********************************************************************/
2504 /* Initialize IT for displaying current_buffer in window W, starting
2505 at character position CHARPOS. CHARPOS < 0 means that no buffer
2506 position is specified which is useful when the iterator is assigned
2507 a position later. BYTEPOS is the byte position corresponding to
2508 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2510 If ROW is not null, calls to produce_glyphs with IT as parameter
2511 will produce glyphs in that row.
2513 BASE_FACE_ID is the id of a base face to use. It must be one of
2514 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2515 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2516 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2518 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2519 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2520 will be initialized to use the corresponding mode line glyph row of
2521 the desired matrix of W. */
2524 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2527 int charpos
, bytepos
;
2528 struct glyph_row
*row
;
2529 enum face_id base_face_id
;
2531 int highlight_region_p
;
2532 enum face_id remapped_base_face_id
= base_face_id
;
2534 /* Some precondition checks. */
2535 xassert (w
!= NULL
&& it
!= NULL
);
2536 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2539 /* If face attributes have been changed since the last redisplay,
2540 free realized faces now because they depend on face definitions
2541 that might have changed. Don't free faces while there might be
2542 desired matrices pending which reference these faces. */
2543 if (face_change_count
&& !inhibit_free_realized_faces
)
2545 face_change_count
= 0;
2546 free_all_realized_faces (Qnil
);
2549 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2550 if (! NILP (Vface_remapping_alist
))
2551 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2553 /* Use one of the mode line rows of W's desired matrix if
2557 if (base_face_id
== MODE_LINE_FACE_ID
2558 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2559 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2560 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2561 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2565 bzero (it
, sizeof *it
);
2566 it
->current
.overlay_string_index
= -1;
2567 it
->current
.dpvec_index
= -1;
2568 it
->base_face_id
= remapped_base_face_id
;
2570 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2572 /* The window in which we iterate over current_buffer: */
2573 XSETWINDOW (it
->window
, w
);
2575 it
->f
= XFRAME (w
->frame
);
2579 /* Extra space between lines (on window systems only). */
2580 if (base_face_id
== DEFAULT_FACE_ID
2581 && FRAME_WINDOW_P (it
->f
))
2583 if (NATNUMP (current_buffer
->extra_line_spacing
))
2584 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2585 else if (FLOATP (current_buffer
->extra_line_spacing
))
2586 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2587 * FRAME_LINE_HEIGHT (it
->f
));
2588 else if (it
->f
->extra_line_spacing
> 0)
2589 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2590 it
->max_extra_line_spacing
= 0;
2593 /* If realized faces have been removed, e.g. because of face
2594 attribute changes of named faces, recompute them. When running
2595 in batch mode, the face cache of the initial frame is null. If
2596 we happen to get called, make a dummy face cache. */
2597 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2598 init_frame_faces (it
->f
);
2599 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2600 recompute_basic_faces (it
->f
);
2602 /* Current value of the `slice', `space-width', and 'height' properties. */
2603 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2604 it
->space_width
= Qnil
;
2605 it
->font_height
= Qnil
;
2606 it
->override_ascent
= -1;
2608 /* Are control characters displayed as `^C'? */
2609 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2611 /* -1 means everything between a CR and the following line end
2612 is invisible. >0 means lines indented more than this value are
2614 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2615 ? XFASTINT (current_buffer
->selective_display
)
2616 : (!NILP (current_buffer
->selective_display
)
2618 it
->selective_display_ellipsis_p
2619 = !NILP (current_buffer
->selective_display_ellipses
);
2621 /* Display table to use. */
2622 it
->dp
= window_display_table (w
);
2624 /* Are multibyte characters enabled in current_buffer? */
2625 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2627 /* Non-zero if we should highlight the region. */
2629 = (!NILP (Vtransient_mark_mode
)
2630 && !NILP (current_buffer
->mark_active
)
2631 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2633 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2634 start and end of a visible region in window IT->w. Set both to
2635 -1 to indicate no region. */
2636 if (highlight_region_p
2637 /* Maybe highlight only in selected window. */
2638 && (/* Either show region everywhere. */
2639 highlight_nonselected_windows
2640 /* Or show region in the selected window. */
2641 || w
== XWINDOW (selected_window
)
2642 /* Or show the region if we are in the mini-buffer and W is
2643 the window the mini-buffer refers to. */
2644 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2645 && WINDOWP (minibuf_selected_window
)
2646 && w
== XWINDOW (minibuf_selected_window
))))
2648 int charpos
= marker_position (current_buffer
->mark
);
2649 it
->region_beg_charpos
= min (PT
, charpos
);
2650 it
->region_end_charpos
= max (PT
, charpos
);
2653 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2655 /* Get the position at which the redisplay_end_trigger hook should
2656 be run, if it is to be run at all. */
2657 if (MARKERP (w
->redisplay_end_trigger
)
2658 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2659 it
->redisplay_end_trigger_charpos
2660 = marker_position (w
->redisplay_end_trigger
);
2661 else if (INTEGERP (w
->redisplay_end_trigger
))
2662 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2664 /* Correct bogus values of tab_width. */
2665 it
->tab_width
= XINT (current_buffer
->tab_width
);
2666 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2669 /* Are lines in the display truncated? */
2670 if (base_face_id
!= DEFAULT_FACE_ID
2671 || XINT (it
->w
->hscroll
)
2672 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2673 && ((!NILP (Vtruncate_partial_width_windows
)
2674 && !INTEGERP (Vtruncate_partial_width_windows
))
2675 || (INTEGERP (Vtruncate_partial_width_windows
)
2676 && (WINDOW_TOTAL_COLS (it
->w
)
2677 < XINT (Vtruncate_partial_width_windows
))))))
2678 it
->line_wrap
= TRUNCATE
;
2679 else if (NILP (current_buffer
->truncate_lines
))
2680 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2681 ? WINDOW_WRAP
: WORD_WRAP
;
2683 it
->line_wrap
= TRUNCATE
;
2685 /* Get dimensions of truncation and continuation glyphs. These are
2686 displayed as fringe bitmaps under X, so we don't need them for such
2688 if (!FRAME_WINDOW_P (it
->f
))
2690 if (it
->line_wrap
== TRUNCATE
)
2692 /* We will need the truncation glyph. */
2693 xassert (it
->glyph_row
== NULL
);
2694 produce_special_glyphs (it
, IT_TRUNCATION
);
2695 it
->truncation_pixel_width
= it
->pixel_width
;
2699 /* We will need the continuation glyph. */
2700 xassert (it
->glyph_row
== NULL
);
2701 produce_special_glyphs (it
, IT_CONTINUATION
);
2702 it
->continuation_pixel_width
= it
->pixel_width
;
2705 /* Reset these values to zero because the produce_special_glyphs
2706 above has changed them. */
2707 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2708 it
->phys_ascent
= it
->phys_descent
= 0;
2711 /* Set this after getting the dimensions of truncation and
2712 continuation glyphs, so that we don't produce glyphs when calling
2713 produce_special_glyphs, above. */
2714 it
->glyph_row
= row
;
2715 it
->area
= TEXT_AREA
;
2717 /* Get the dimensions of the display area. The display area
2718 consists of the visible window area plus a horizontally scrolled
2719 part to the left of the window. All x-values are relative to the
2720 start of this total display area. */
2721 if (base_face_id
!= DEFAULT_FACE_ID
)
2723 /* Mode lines, menu bar in terminal frames. */
2724 it
->first_visible_x
= 0;
2725 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2730 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2731 it
->last_visible_x
= (it
->first_visible_x
2732 + window_box_width (w
, TEXT_AREA
));
2734 /* If we truncate lines, leave room for the truncator glyph(s) at
2735 the right margin. Otherwise, leave room for the continuation
2736 glyph(s). Truncation and continuation glyphs are not inserted
2737 for window-based redisplay. */
2738 if (!FRAME_WINDOW_P (it
->f
))
2740 if (it
->line_wrap
== TRUNCATE
)
2741 it
->last_visible_x
-= it
->truncation_pixel_width
;
2743 it
->last_visible_x
-= it
->continuation_pixel_width
;
2746 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2747 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2750 /* Leave room for a border glyph. */
2751 if (!FRAME_WINDOW_P (it
->f
)
2752 && !WINDOW_RIGHTMOST_P (it
->w
))
2753 it
->last_visible_x
-= 1;
2755 it
->last_visible_y
= window_text_bottom_y (w
);
2757 /* For mode lines and alike, arrange for the first glyph having a
2758 left box line if the face specifies a box. */
2759 if (base_face_id
!= DEFAULT_FACE_ID
)
2763 it
->face_id
= remapped_base_face_id
;
2765 /* If we have a boxed mode line, make the first character appear
2766 with a left box line. */
2767 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2768 if (face
->box
!= FACE_NO_BOX
)
2769 it
->start_of_box_run_p
= 1;
2772 /* If a buffer position was specified, set the iterator there,
2773 getting overlays and face properties from that position. */
2774 if (charpos
>= BUF_BEG (current_buffer
))
2776 it
->end_charpos
= ZV
;
2778 IT_CHARPOS (*it
) = charpos
;
2780 /* Compute byte position if not specified. */
2781 if (bytepos
< charpos
)
2782 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2784 IT_BYTEPOS (*it
) = bytepos
;
2786 it
->start
= it
->current
;
2788 /* Compute faces etc. */
2789 reseat (it
, it
->current
.pos
, 1);
2796 /* Initialize IT for the display of window W with window start POS. */
2799 start_display (it
, w
, pos
)
2802 struct text_pos pos
;
2804 struct glyph_row
*row
;
2805 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2807 row
= w
->desired_matrix
->rows
+ first_vpos
;
2808 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2809 it
->first_vpos
= first_vpos
;
2811 /* Don't reseat to previous visible line start if current start
2812 position is in a string or image. */
2813 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2815 int start_at_line_beg_p
;
2816 int first_y
= it
->current_y
;
2818 /* If window start is not at a line start, skip forward to POS to
2819 get the correct continuation lines width. */
2820 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2821 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2822 if (!start_at_line_beg_p
)
2826 reseat_at_previous_visible_line_start (it
);
2827 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2829 new_x
= it
->current_x
+ it
->pixel_width
;
2831 /* If lines are continued, this line may end in the middle
2832 of a multi-glyph character (e.g. a control character
2833 displayed as \003, or in the middle of an overlay
2834 string). In this case move_it_to above will not have
2835 taken us to the start of the continuation line but to the
2836 end of the continued line. */
2837 if (it
->current_x
> 0
2838 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2839 && (/* And glyph doesn't fit on the line. */
2840 new_x
> it
->last_visible_x
2841 /* Or it fits exactly and we're on a window
2843 || (new_x
== it
->last_visible_x
2844 && FRAME_WINDOW_P (it
->f
))))
2846 if (it
->current
.dpvec_index
>= 0
2847 || it
->current
.overlay_string_index
>= 0)
2849 set_iterator_to_next (it
, 1);
2850 move_it_in_display_line_to (it
, -1, -1, 0);
2853 it
->continuation_lines_width
+= it
->current_x
;
2856 /* We're starting a new display line, not affected by the
2857 height of the continued line, so clear the appropriate
2858 fields in the iterator structure. */
2859 it
->max_ascent
= it
->max_descent
= 0;
2860 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2862 it
->current_y
= first_y
;
2864 it
->current_x
= it
->hpos
= 0;
2870 /* Return 1 if POS is a position in ellipses displayed for invisible
2871 text. W is the window we display, for text property lookup. */
2874 in_ellipses_for_invisible_text_p (pos
, w
)
2875 struct display_pos
*pos
;
2878 Lisp_Object prop
, window
;
2880 int charpos
= CHARPOS (pos
->pos
);
2882 /* If POS specifies a position in a display vector, this might
2883 be for an ellipsis displayed for invisible text. We won't
2884 get the iterator set up for delivering that ellipsis unless
2885 we make sure that it gets aware of the invisible text. */
2886 if (pos
->dpvec_index
>= 0
2887 && pos
->overlay_string_index
< 0
2888 && CHARPOS (pos
->string_pos
) < 0
2890 && (XSETWINDOW (window
, w
),
2891 prop
= Fget_char_property (make_number (charpos
),
2892 Qinvisible
, window
),
2893 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2895 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2897 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2904 /* Initialize IT for stepping through current_buffer in window W,
2905 starting at position POS that includes overlay string and display
2906 vector/ control character translation position information. Value
2907 is zero if there are overlay strings with newlines at POS. */
2910 init_from_display_pos (it
, w
, pos
)
2913 struct display_pos
*pos
;
2915 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2916 int i
, overlay_strings_with_newlines
= 0;
2918 /* If POS specifies a position in a display vector, this might
2919 be for an ellipsis displayed for invisible text. We won't
2920 get the iterator set up for delivering that ellipsis unless
2921 we make sure that it gets aware of the invisible text. */
2922 if (in_ellipses_for_invisible_text_p (pos
, w
))
2928 /* Keep in mind: the call to reseat in init_iterator skips invisible
2929 text, so we might end up at a position different from POS. This
2930 is only a problem when POS is a row start after a newline and an
2931 overlay starts there with an after-string, and the overlay has an
2932 invisible property. Since we don't skip invisible text in
2933 display_line and elsewhere immediately after consuming the
2934 newline before the row start, such a POS will not be in a string,
2935 but the call to init_iterator below will move us to the
2937 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2939 /* This only scans the current chunk -- it should scan all chunks.
2940 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2941 to 16 in 22.1 to make this a lesser problem. */
2942 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2944 const char *s
= SDATA (it
->overlay_strings
[i
]);
2945 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2947 while (s
< e
&& *s
!= '\n')
2952 overlay_strings_with_newlines
= 1;
2957 /* If position is within an overlay string, set up IT to the right
2959 if (pos
->overlay_string_index
>= 0)
2963 /* If the first overlay string happens to have a `display'
2964 property for an image, the iterator will be set up for that
2965 image, and we have to undo that setup first before we can
2966 correct the overlay string index. */
2967 if (it
->method
== GET_FROM_IMAGE
)
2970 /* We already have the first chunk of overlay strings in
2971 IT->overlay_strings. Load more until the one for
2972 pos->overlay_string_index is in IT->overlay_strings. */
2973 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2975 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2976 it
->current
.overlay_string_index
= 0;
2979 load_overlay_strings (it
, 0);
2980 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2984 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2985 relative_index
= (it
->current
.overlay_string_index
2986 % OVERLAY_STRING_CHUNK_SIZE
);
2987 it
->string
= it
->overlay_strings
[relative_index
];
2988 xassert (STRINGP (it
->string
));
2989 it
->current
.string_pos
= pos
->string_pos
;
2990 it
->method
= GET_FROM_STRING
;
2993 if (CHARPOS (pos
->string_pos
) >= 0)
2995 /* Recorded position is not in an overlay string, but in another
2996 string. This can only be a string from a `display' property.
2997 IT should already be filled with that string. */
2998 it
->current
.string_pos
= pos
->string_pos
;
2999 xassert (STRINGP (it
->string
));
3002 /* Restore position in display vector translations, control
3003 character translations or ellipses. */
3004 if (pos
->dpvec_index
>= 0)
3006 if (it
->dpvec
== NULL
)
3007 get_next_display_element (it
);
3008 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3009 it
->current
.dpvec_index
= pos
->dpvec_index
;
3013 return !overlay_strings_with_newlines
;
3017 /* Initialize IT for stepping through current_buffer in window W
3018 starting at ROW->start. */
3021 init_to_row_start (it
, w
, row
)
3024 struct glyph_row
*row
;
3026 init_from_display_pos (it
, w
, &row
->start
);
3027 it
->start
= row
->start
;
3028 it
->continuation_lines_width
= row
->continuation_lines_width
;
3033 /* Initialize IT for stepping through current_buffer in window W
3034 starting in the line following ROW, i.e. starting at ROW->end.
3035 Value is zero if there are overlay strings with newlines at ROW's
3039 init_to_row_end (it
, w
, row
)
3042 struct glyph_row
*row
;
3046 if (init_from_display_pos (it
, w
, &row
->end
))
3048 if (row
->continued_p
)
3049 it
->continuation_lines_width
3050 = row
->continuation_lines_width
+ row
->pixel_width
;
3061 /***********************************************************************
3063 ***********************************************************************/
3065 /* Called when IT reaches IT->stop_charpos. Handle text property and
3066 overlay changes. Set IT->stop_charpos to the next position where
3073 enum prop_handled handled
;
3074 int handle_overlay_change_p
;
3078 it
->current
.dpvec_index
= -1;
3079 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3080 it
->ignore_overlay_strings_at_pos_p
= 0;
3083 /* Use face of preceding text for ellipsis (if invisible) */
3084 if (it
->selective_display_ellipsis_p
)
3085 it
->saved_face_id
= it
->face_id
;
3089 handled
= HANDLED_NORMALLY
;
3091 /* Call text property handlers. */
3092 for (p
= it_props
; p
->handler
; ++p
)
3094 handled
= p
->handler (it
);
3096 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3098 else if (handled
== HANDLED_RETURN
)
3100 /* We still want to show before and after strings from
3101 overlays even if the actual buffer text is replaced. */
3102 if (!handle_overlay_change_p
3104 || !get_overlay_strings_1 (it
, 0, 0))
3107 setup_for_ellipsis (it
, 0);
3108 /* When handling a display spec, we might load an
3109 empty string. In that case, discard it here. We
3110 used to discard it in handle_single_display_spec,
3111 but that causes get_overlay_strings_1, above, to
3112 ignore overlay strings that we must check. */
3113 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3117 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3121 it
->ignore_overlay_strings_at_pos_p
= 1;
3122 it
->string_from_display_prop_p
= 0;
3123 handle_overlay_change_p
= 0;
3125 handled
= HANDLED_RECOMPUTE_PROPS
;
3128 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3129 handle_overlay_change_p
= 0;
3132 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3134 /* Don't check for overlay strings below when set to deliver
3135 characters from a display vector. */
3136 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3137 handle_overlay_change_p
= 0;
3139 /* Handle overlay changes.
3140 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3141 if it finds overlays. */
3142 if (handle_overlay_change_p
)
3143 handled
= handle_overlay_change (it
);
3148 setup_for_ellipsis (it
, 0);
3152 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3154 /* Determine where to stop next. */
3155 if (handled
== HANDLED_NORMALLY
)
3156 compute_stop_pos (it
);
3160 /* Compute IT->stop_charpos from text property and overlay change
3161 information for IT's current position. */
3164 compute_stop_pos (it
)
3167 register INTERVAL iv
, next_iv
;
3168 Lisp_Object object
, limit
, position
;
3169 EMACS_INT charpos
, bytepos
;
3171 /* If nowhere else, stop at the end. */
3172 it
->stop_charpos
= it
->end_charpos
;
3174 if (STRINGP (it
->string
))
3176 /* Strings are usually short, so don't limit the search for
3178 object
= it
->string
;
3180 charpos
= IT_STRING_CHARPOS (*it
);
3181 bytepos
= IT_STRING_BYTEPOS (*it
);
3187 /* If next overlay change is in front of the current stop pos
3188 (which is IT->end_charpos), stop there. Note: value of
3189 next_overlay_change is point-max if no overlay change
3191 charpos
= IT_CHARPOS (*it
);
3192 bytepos
= IT_BYTEPOS (*it
);
3193 pos
= next_overlay_change (charpos
);
3194 if (pos
< it
->stop_charpos
)
3195 it
->stop_charpos
= pos
;
3197 /* If showing the region, we have to stop at the region
3198 start or end because the face might change there. */
3199 if (it
->region_beg_charpos
> 0)
3201 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3202 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3203 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3204 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3207 /* Set up variables for computing the stop position from text
3208 property changes. */
3209 XSETBUFFER (object
, current_buffer
);
3210 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3213 /* Get the interval containing IT's position. Value is a null
3214 interval if there isn't such an interval. */
3215 position
= make_number (charpos
);
3216 iv
= validate_interval_range (object
, &position
, &position
, 0);
3217 if (!NULL_INTERVAL_P (iv
))
3219 Lisp_Object values_here
[LAST_PROP_IDX
];
3222 /* Get properties here. */
3223 for (p
= it_props
; p
->handler
; ++p
)
3224 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3226 /* Look for an interval following iv that has different
3228 for (next_iv
= next_interval (iv
);
3229 (!NULL_INTERVAL_P (next_iv
)
3231 || XFASTINT (limit
) > next_iv
->position
));
3232 next_iv
= next_interval (next_iv
))
3234 for (p
= it_props
; p
->handler
; ++p
)
3236 Lisp_Object new_value
;
3238 new_value
= textget (next_iv
->plist
, *p
->name
);
3239 if (!EQ (values_here
[p
->idx
], new_value
))
3247 if (!NULL_INTERVAL_P (next_iv
))
3249 if (INTEGERP (limit
)
3250 && next_iv
->position
>= XFASTINT (limit
))
3251 /* No text property change up to limit. */
3252 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3254 /* Text properties change in next_iv. */
3255 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3259 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3260 it
->stop_charpos
, it
->string
);
3262 xassert (STRINGP (it
->string
)
3263 || (it
->stop_charpos
>= BEGV
3264 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3268 /* Return the position of the next overlay change after POS in
3269 current_buffer. Value is point-max if no overlay change
3270 follows. This is like `next-overlay-change' but doesn't use
3274 next_overlay_change (pos
)
3279 Lisp_Object
*overlays
;
3282 /* Get all overlays at the given position. */
3283 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3285 /* If any of these overlays ends before endpos,
3286 use its ending point instead. */
3287 for (i
= 0; i
< noverlays
; ++i
)
3292 oend
= OVERLAY_END (overlays
[i
]);
3293 oendpos
= OVERLAY_POSITION (oend
);
3294 endpos
= min (endpos
, oendpos
);
3302 /***********************************************************************
3304 ***********************************************************************/
3306 /* Handle changes in the `fontified' property of the current buffer by
3307 calling hook functions from Qfontification_functions to fontify
3310 static enum prop_handled
3311 handle_fontified_prop (it
)
3314 Lisp_Object prop
, pos
;
3315 enum prop_handled handled
= HANDLED_NORMALLY
;
3317 if (!NILP (Vmemory_full
))
3320 /* Get the value of the `fontified' property at IT's current buffer
3321 position. (The `fontified' property doesn't have a special
3322 meaning in strings.) If the value is nil, call functions from
3323 Qfontification_functions. */
3324 if (!STRINGP (it
->string
)
3326 && !NILP (Vfontification_functions
)
3327 && !NILP (Vrun_hooks
)
3328 && (pos
= make_number (IT_CHARPOS (*it
)),
3329 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3330 /* Ignore the special cased nil value always present at EOB since
3331 no amount of fontifying will be able to change it. */
3332 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3334 int count
= SPECPDL_INDEX ();
3337 val
= Vfontification_functions
;
3338 specbind (Qfontification_functions
, Qnil
);
3340 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3341 safe_call1 (val
, pos
);
3344 Lisp_Object globals
, fn
;
3345 struct gcpro gcpro1
, gcpro2
;
3348 GCPRO2 (val
, globals
);
3350 for (; CONSP (val
); val
= XCDR (val
))
3356 /* A value of t indicates this hook has a local
3357 binding; it means to run the global binding too.
3358 In a global value, t should not occur. If it
3359 does, we must ignore it to avoid an endless
3361 for (globals
= Fdefault_value (Qfontification_functions
);
3363 globals
= XCDR (globals
))
3365 fn
= XCAR (globals
);
3367 safe_call1 (fn
, pos
);
3371 safe_call1 (fn
, pos
);
3377 unbind_to (count
, Qnil
);
3379 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3380 something. This avoids an endless loop if they failed to
3381 fontify the text for which reason ever. */
3382 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3383 handled
= HANDLED_RECOMPUTE_PROPS
;
3391 /***********************************************************************
3393 ***********************************************************************/
3395 /* Set up iterator IT from face properties at its current position.
3396 Called from handle_stop. */
3398 static enum prop_handled
3399 handle_face_prop (it
)
3403 EMACS_INT next_stop
;
3405 if (!STRINGP (it
->string
))
3408 = face_at_buffer_position (it
->w
,
3410 it
->region_beg_charpos
,
3411 it
->region_end_charpos
,
3414 + TEXT_PROP_DISTANCE_LIMIT
),
3415 0, it
->base_face_id
);
3417 /* Is this a start of a run of characters with box face?
3418 Caveat: this can be called for a freshly initialized
3419 iterator; face_id is -1 in this case. We know that the new
3420 face will not change until limit, i.e. if the new face has a
3421 box, all characters up to limit will have one. But, as
3422 usual, we don't know whether limit is really the end. */
3423 if (new_face_id
!= it
->face_id
)
3425 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3427 /* If new face has a box but old face has not, this is
3428 the start of a run of characters with box, i.e. it has
3429 a shadow on the left side. The value of face_id of the
3430 iterator will be -1 if this is the initial call that gets
3431 the face. In this case, we have to look in front of IT's
3432 position and see whether there is a face != new_face_id. */
3433 it
->start_of_box_run_p
3434 = (new_face
->box
!= FACE_NO_BOX
3435 && (it
->face_id
>= 0
3436 || IT_CHARPOS (*it
) == BEG
3437 || new_face_id
!= face_before_it_pos (it
)));
3438 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3443 int base_face_id
, bufpos
;
3445 Lisp_Object from_overlay
3446 = (it
->current
.overlay_string_index
>= 0
3447 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3450 /* See if we got to this string directly or indirectly from
3451 an overlay property. That includes the before-string or
3452 after-string of an overlay, strings in display properties
3453 provided by an overlay, their text properties, etc.
3455 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3456 if (! NILP (from_overlay
))
3457 for (i
= it
->sp
- 1; i
>= 0; i
--)
3459 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3461 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3462 else if (! NILP (it
->stack
[i
].from_overlay
))
3463 from_overlay
= it
->stack
[i
].from_overlay
;
3465 if (!NILP (from_overlay
))
3469 if (! NILP (from_overlay
))
3471 bufpos
= IT_CHARPOS (*it
);
3472 /* For a string from an overlay, the base face depends
3473 only on text properties and ignores overlays. */
3475 = face_for_overlay_string (it
->w
,
3477 it
->region_beg_charpos
,
3478 it
->region_end_charpos
,
3481 + TEXT_PROP_DISTANCE_LIMIT
),
3489 /* For strings from a `display' property, use the face at
3490 IT's current buffer position as the base face to merge
3491 with, so that overlay strings appear in the same face as
3492 surrounding text, unless they specify their own
3494 base_face_id
= underlying_face_id (it
);
3497 new_face_id
= face_at_string_position (it
->w
,
3499 IT_STRING_CHARPOS (*it
),
3501 it
->region_beg_charpos
,
3502 it
->region_end_charpos
,
3506 /* Is this a start of a run of characters with box? Caveat:
3507 this can be called for a freshly allocated iterator; face_id
3508 is -1 is this case. We know that the new face will not
3509 change until the next check pos, i.e. if the new face has a
3510 box, all characters up to that position will have a
3511 box. But, as usual, we don't know whether that position
3512 is really the end. */
3513 if (new_face_id
!= it
->face_id
)
3515 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3516 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3518 /* If new face has a box but old face hasn't, this is the
3519 start of a run of characters with box, i.e. it has a
3520 shadow on the left side. */
3521 it
->start_of_box_run_p
3522 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3523 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3527 it
->face_id
= new_face_id
;
3528 return HANDLED_NORMALLY
;
3532 /* Return the ID of the face ``underlying'' IT's current position,
3533 which is in a string. If the iterator is associated with a
3534 buffer, return the face at IT's current buffer position.
3535 Otherwise, use the iterator's base_face_id. */
3538 underlying_face_id (it
)
3541 int face_id
= it
->base_face_id
, i
;
3543 xassert (STRINGP (it
->string
));
3545 for (i
= it
->sp
- 1; i
>= 0; --i
)
3546 if (NILP (it
->stack
[i
].string
))
3547 face_id
= it
->stack
[i
].face_id
;
3553 /* Compute the face one character before or after the current position
3554 of IT. BEFORE_P non-zero means get the face in front of IT's
3555 position. Value is the id of the face. */
3558 face_before_or_after_it_pos (it
, before_p
)
3563 EMACS_INT next_check_charpos
;
3564 struct text_pos pos
;
3566 xassert (it
->s
== NULL
);
3568 if (STRINGP (it
->string
))
3570 int bufpos
, base_face_id
;
3572 /* No face change past the end of the string (for the case
3573 we are padding with spaces). No face change before the
3575 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3576 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3579 /* Set pos to the position before or after IT's current position. */
3581 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3583 /* For composition, we must check the character after the
3585 pos
= (it
->what
== IT_COMPOSITION
3586 ? string_pos (IT_STRING_CHARPOS (*it
)
3587 + it
->cmp_it
.nchars
, it
->string
)
3588 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3590 if (it
->current
.overlay_string_index
>= 0)
3591 bufpos
= IT_CHARPOS (*it
);
3595 base_face_id
= underlying_face_id (it
);
3597 /* Get the face for ASCII, or unibyte. */
3598 face_id
= face_at_string_position (it
->w
,
3602 it
->region_beg_charpos
,
3603 it
->region_end_charpos
,
3604 &next_check_charpos
,
3607 /* Correct the face for charsets different from ASCII. Do it
3608 for the multibyte case only. The face returned above is
3609 suitable for unibyte text if IT->string is unibyte. */
3610 if (STRING_MULTIBYTE (it
->string
))
3612 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3614 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3616 c
= string_char_and_length (p
, &len
);
3617 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3622 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3623 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3626 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3627 pos
= it
->current
.pos
;
3630 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3633 if (it
->what
== IT_COMPOSITION
)
3634 /* For composition, we must check the position after the
3636 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3638 INC_TEXT_POS (pos
, it
->multibyte_p
);
3641 /* Determine face for CHARSET_ASCII, or unibyte. */
3642 face_id
= face_at_buffer_position (it
->w
,
3644 it
->region_beg_charpos
,
3645 it
->region_end_charpos
,
3646 &next_check_charpos
,
3649 /* Correct the face for charsets different from ASCII. Do it
3650 for the multibyte case only. The face returned above is
3651 suitable for unibyte text if current_buffer is unibyte. */
3652 if (it
->multibyte_p
)
3654 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3655 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3656 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3665 /***********************************************************************
3667 ***********************************************************************/
3669 /* Set up iterator IT from invisible properties at its current
3670 position. Called from handle_stop. */
3672 static enum prop_handled
3673 handle_invisible_prop (it
)
3676 enum prop_handled handled
= HANDLED_NORMALLY
;
3678 if (STRINGP (it
->string
))
3680 extern Lisp_Object Qinvisible
;
3681 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3683 /* Get the value of the invisible text property at the
3684 current position. Value will be nil if there is no such
3686 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3687 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3690 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3692 handled
= HANDLED_RECOMPUTE_PROPS
;
3694 /* Get the position at which the next change of the
3695 invisible text property can be found in IT->string.
3696 Value will be nil if the property value is the same for
3697 all the rest of IT->string. */
3698 XSETINT (limit
, SCHARS (it
->string
));
3699 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3702 /* Text at current position is invisible. The next
3703 change in the property is at position end_charpos.
3704 Move IT's current position to that position. */
3705 if (INTEGERP (end_charpos
)
3706 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3708 struct text_pos old
;
3709 old
= it
->current
.string_pos
;
3710 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3711 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3715 /* The rest of the string is invisible. If this is an
3716 overlay string, proceed with the next overlay string
3717 or whatever comes and return a character from there. */
3718 if (it
->current
.overlay_string_index
>= 0)
3720 next_overlay_string (it
);
3721 /* Don't check for overlay strings when we just
3722 finished processing them. */
3723 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3727 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3728 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3736 EMACS_INT newpos
, next_stop
, start_charpos
;
3737 Lisp_Object pos
, prop
, overlay
;
3739 /* First of all, is there invisible text at this position? */
3740 start_charpos
= IT_CHARPOS (*it
);
3741 pos
= make_number (IT_CHARPOS (*it
));
3742 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3744 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3746 /* If we are on invisible text, skip over it. */
3747 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3749 /* Record whether we have to display an ellipsis for the
3751 int display_ellipsis_p
= invis_p
== 2;
3753 handled
= HANDLED_RECOMPUTE_PROPS
;
3755 /* Loop skipping over invisible text. The loop is left at
3756 ZV or with IT on the first char being visible again. */
3759 /* Try to skip some invisible text. Return value is the
3760 position reached which can be equal to IT's position
3761 if there is nothing invisible here. This skips both
3762 over invisible text properties and overlays with
3763 invisible property. */
3764 newpos
= skip_invisible (IT_CHARPOS (*it
),
3765 &next_stop
, ZV
, it
->window
);
3767 /* If we skipped nothing at all we weren't at invisible
3768 text in the first place. If everything to the end of
3769 the buffer was skipped, end the loop. */
3770 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3774 /* We skipped some characters but not necessarily
3775 all there are. Check if we ended up on visible
3776 text. Fget_char_property returns the property of
3777 the char before the given position, i.e. if we
3778 get invis_p = 0, this means that the char at
3779 newpos is visible. */
3780 pos
= make_number (newpos
);
3781 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3782 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3785 /* If we ended up on invisible text, proceed to
3786 skip starting with next_stop. */
3788 IT_CHARPOS (*it
) = next_stop
;
3790 /* If there are adjacent invisible texts, don't lose the
3791 second one's ellipsis. */
3793 display_ellipsis_p
= 1;
3797 /* The position newpos is now either ZV or on visible text. */
3798 IT_CHARPOS (*it
) = newpos
;
3799 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3801 /* If there are before-strings at the start of invisible
3802 text, and the text is invisible because of a text
3803 property, arrange to show before-strings because 20.x did
3804 it that way. (If the text is invisible because of an
3805 overlay property instead of a text property, this is
3806 already handled in the overlay code.) */
3808 && get_overlay_strings (it
, start_charpos
))
3810 handled
= HANDLED_RECOMPUTE_PROPS
;
3811 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3813 else if (display_ellipsis_p
)
3815 /* Make sure that the glyphs of the ellipsis will get
3816 correct `charpos' values. If we would not update
3817 it->position here, the glyphs would belong to the
3818 last visible character _before_ the invisible
3819 text, which confuses `set_cursor_from_row'.
3821 We use the last invisible position instead of the
3822 first because this way the cursor is always drawn on
3823 the first "." of the ellipsis, whenever PT is inside
3824 the invisible text. Otherwise the cursor would be
3825 placed _after_ the ellipsis when the point is after the
3826 first invisible character. */
3827 if (!STRINGP (it
->object
))
3829 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3830 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3833 /* Let the ellipsis display before
3834 considering any properties of the following char.
3835 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3836 handled
= HANDLED_RETURN
;
3845 /* Make iterator IT return `...' next.
3846 Replaces LEN characters from buffer. */
3849 setup_for_ellipsis (it
, len
)
3853 /* Use the display table definition for `...'. Invalid glyphs
3854 will be handled by the method returning elements from dpvec. */
3855 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3857 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3858 it
->dpvec
= v
->contents
;
3859 it
->dpend
= v
->contents
+ v
->size
;
3863 /* Default `...'. */
3864 it
->dpvec
= default_invis_vector
;
3865 it
->dpend
= default_invis_vector
+ 3;
3868 it
->dpvec_char_len
= len
;
3869 it
->current
.dpvec_index
= 0;
3870 it
->dpvec_face_id
= -1;
3872 /* Remember the current face id in case glyphs specify faces.
3873 IT's face is restored in set_iterator_to_next.
3874 saved_face_id was set to preceding char's face in handle_stop. */
3875 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3876 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3878 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3884 /***********************************************************************
3886 ***********************************************************************/
3888 /* Set up iterator IT from `display' property at its current position.
3889 Called from handle_stop.
3890 We return HANDLED_RETURN if some part of the display property
3891 overrides the display of the buffer text itself.
3892 Otherwise we return HANDLED_NORMALLY. */
3894 static enum prop_handled
3895 handle_display_prop (it
)
3898 Lisp_Object prop
, object
, overlay
;
3899 struct text_pos
*position
;
3900 /* Nonzero if some property replaces the display of the text itself. */
3901 int display_replaced_p
= 0;
3903 if (STRINGP (it
->string
))
3905 object
= it
->string
;
3906 position
= &it
->current
.string_pos
;
3910 XSETWINDOW (object
, it
->w
);
3911 position
= &it
->current
.pos
;
3914 /* Reset those iterator values set from display property values. */
3915 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3916 it
->space_width
= Qnil
;
3917 it
->font_height
= Qnil
;
3920 /* We don't support recursive `display' properties, i.e. string
3921 values that have a string `display' property, that have a string
3922 `display' property etc. */
3923 if (!it
->string_from_display_prop_p
)
3924 it
->area
= TEXT_AREA
;
3926 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3927 Qdisplay
, object
, &overlay
);
3929 return HANDLED_NORMALLY
;
3930 /* Now OVERLAY is the overlay that gave us this property, or nil
3931 if it was a text property. */
3933 if (!STRINGP (it
->string
))
3934 object
= it
->w
->buffer
;
3937 /* Simple properties. */
3938 && !EQ (XCAR (prop
), Qimage
)
3939 && !EQ (XCAR (prop
), Qspace
)
3940 && !EQ (XCAR (prop
), Qwhen
)
3941 && !EQ (XCAR (prop
), Qslice
)
3942 && !EQ (XCAR (prop
), Qspace_width
)
3943 && !EQ (XCAR (prop
), Qheight
)
3944 && !EQ (XCAR (prop
), Qraise
)
3945 /* Marginal area specifications. */
3946 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3947 && !EQ (XCAR (prop
), Qleft_fringe
)
3948 && !EQ (XCAR (prop
), Qright_fringe
)
3949 && !NILP (XCAR (prop
)))
3951 for (; CONSP (prop
); prop
= XCDR (prop
))
3953 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3954 position
, display_replaced_p
))
3956 display_replaced_p
= 1;
3957 /* If some text in a string is replaced, `position' no
3958 longer points to the position of `object'. */
3959 if (STRINGP (object
))
3964 else if (VECTORP (prop
))
3967 for (i
= 0; i
< ASIZE (prop
); ++i
)
3968 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3969 position
, display_replaced_p
))
3971 display_replaced_p
= 1;
3972 /* If some text in a string is replaced, `position' no
3973 longer points to the position of `object'. */
3974 if (STRINGP (object
))
3980 if (handle_single_display_spec (it
, prop
, object
, overlay
,
3982 display_replaced_p
= 1;
3985 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3989 /* Value is the position of the end of the `display' property starting
3990 at START_POS in OBJECT. */
3992 static struct text_pos
3993 display_prop_end (it
, object
, start_pos
)
3996 struct text_pos start_pos
;
3999 struct text_pos end_pos
;
4001 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4002 Qdisplay
, object
, Qnil
);
4003 CHARPOS (end_pos
) = XFASTINT (end
);
4004 if (STRINGP (object
))
4005 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4007 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4013 /* Set up IT from a single `display' specification PROP. OBJECT
4014 is the object in which the `display' property was found. *POSITION
4015 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4016 means that we previously saw a display specification which already
4017 replaced text display with something else, for example an image;
4018 we ignore such properties after the first one has been processed.
4020 OVERLAY is the overlay this `display' property came from,
4021 or nil if it was a text property.
4023 If PROP is a `space' or `image' specification, and in some other
4024 cases too, set *POSITION to the position where the `display'
4027 Value is non-zero if something was found which replaces the display
4028 of buffer or string text. */
4031 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4032 display_replaced_before_p
)
4036 Lisp_Object overlay
;
4037 struct text_pos
*position
;
4038 int display_replaced_before_p
;
4041 Lisp_Object location
, value
;
4042 struct text_pos start_pos
, save_pos
;
4045 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4046 If the result is non-nil, use VALUE instead of SPEC. */
4048 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4057 if (!NILP (form
) && !EQ (form
, Qt
))
4059 int count
= SPECPDL_INDEX ();
4060 struct gcpro gcpro1
;
4062 /* Bind `object' to the object having the `display' property, a
4063 buffer or string. Bind `position' to the position in the
4064 object where the property was found, and `buffer-position'
4065 to the current position in the buffer. */
4066 specbind (Qobject
, object
);
4067 specbind (Qposition
, make_number (CHARPOS (*position
)));
4068 specbind (Qbuffer_position
,
4069 make_number (STRINGP (object
)
4070 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4072 form
= safe_eval (form
);
4074 unbind_to (count
, Qnil
);
4080 /* Handle `(height HEIGHT)' specifications. */
4082 && EQ (XCAR (spec
), Qheight
)
4083 && CONSP (XCDR (spec
)))
4085 if (!FRAME_WINDOW_P (it
->f
))
4088 it
->font_height
= XCAR (XCDR (spec
));
4089 if (!NILP (it
->font_height
))
4091 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4092 int new_height
= -1;
4094 if (CONSP (it
->font_height
)
4095 && (EQ (XCAR (it
->font_height
), Qplus
)
4096 || EQ (XCAR (it
->font_height
), Qminus
))
4097 && CONSP (XCDR (it
->font_height
))
4098 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4100 /* `(+ N)' or `(- N)' where N is an integer. */
4101 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4102 if (EQ (XCAR (it
->font_height
), Qplus
))
4104 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4106 else if (FUNCTIONP (it
->font_height
))
4108 /* Call function with current height as argument.
4109 Value is the new height. */
4111 height
= safe_call1 (it
->font_height
,
4112 face
->lface
[LFACE_HEIGHT_INDEX
]);
4113 if (NUMBERP (height
))
4114 new_height
= XFLOATINT (height
);
4116 else if (NUMBERP (it
->font_height
))
4118 /* Value is a multiple of the canonical char height. */
4121 face
= FACE_FROM_ID (it
->f
,
4122 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4123 new_height
= (XFLOATINT (it
->font_height
)
4124 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4128 /* Evaluate IT->font_height with `height' bound to the
4129 current specified height to get the new height. */
4130 int count
= SPECPDL_INDEX ();
4132 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4133 value
= safe_eval (it
->font_height
);
4134 unbind_to (count
, Qnil
);
4136 if (NUMBERP (value
))
4137 new_height
= XFLOATINT (value
);
4141 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4147 /* Handle `(space-width WIDTH)'. */
4149 && EQ (XCAR (spec
), Qspace_width
)
4150 && CONSP (XCDR (spec
)))
4152 if (!FRAME_WINDOW_P (it
->f
))
4155 value
= XCAR (XCDR (spec
));
4156 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4157 it
->space_width
= value
;
4162 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4164 && EQ (XCAR (spec
), Qslice
))
4168 if (!FRAME_WINDOW_P (it
->f
))
4171 if (tem
= XCDR (spec
), CONSP (tem
))
4173 it
->slice
.x
= XCAR (tem
);
4174 if (tem
= XCDR (tem
), CONSP (tem
))
4176 it
->slice
.y
= XCAR (tem
);
4177 if (tem
= XCDR (tem
), CONSP (tem
))
4179 it
->slice
.width
= XCAR (tem
);
4180 if (tem
= XCDR (tem
), CONSP (tem
))
4181 it
->slice
.height
= XCAR (tem
);
4189 /* Handle `(raise FACTOR)'. */
4191 && EQ (XCAR (spec
), Qraise
)
4192 && CONSP (XCDR (spec
)))
4194 if (!FRAME_WINDOW_P (it
->f
))
4197 #ifdef HAVE_WINDOW_SYSTEM
4198 value
= XCAR (XCDR (spec
));
4199 if (NUMBERP (value
))
4201 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4202 it
->voffset
= - (XFLOATINT (value
)
4203 * (FONT_HEIGHT (face
->font
)));
4205 #endif /* HAVE_WINDOW_SYSTEM */
4210 /* Don't handle the other kinds of display specifications
4211 inside a string that we got from a `display' property. */
4212 if (it
->string_from_display_prop_p
)
4215 /* Characters having this form of property are not displayed, so
4216 we have to find the end of the property. */
4217 start_pos
= *position
;
4218 *position
= display_prop_end (it
, object
, start_pos
);
4221 /* Stop the scan at that end position--we assume that all
4222 text properties change there. */
4223 it
->stop_charpos
= position
->charpos
;
4225 /* Handle `(left-fringe BITMAP [FACE])'
4226 and `(right-fringe BITMAP [FACE])'. */
4228 && (EQ (XCAR (spec
), Qleft_fringe
)
4229 || EQ (XCAR (spec
), Qright_fringe
))
4230 && CONSP (XCDR (spec
)))
4232 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4235 if (!FRAME_WINDOW_P (it
->f
))
4236 /* If we return here, POSITION has been advanced
4237 across the text with this property. */
4240 #ifdef HAVE_WINDOW_SYSTEM
4241 value
= XCAR (XCDR (spec
));
4242 if (!SYMBOLP (value
)
4243 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4244 /* If we return here, POSITION has been advanced
4245 across the text with this property. */
4248 if (CONSP (XCDR (XCDR (spec
))))
4250 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4251 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4257 /* Save current settings of IT so that we can restore them
4258 when we are finished with the glyph property value. */
4260 save_pos
= it
->position
;
4261 it
->position
= *position
;
4263 it
->position
= save_pos
;
4265 it
->area
= TEXT_AREA
;
4266 it
->what
= IT_IMAGE
;
4267 it
->image_id
= -1; /* no image */
4268 it
->position
= start_pos
;
4269 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4270 it
->method
= GET_FROM_IMAGE
;
4271 it
->from_overlay
= Qnil
;
4272 it
->face_id
= face_id
;
4274 /* Say that we haven't consumed the characters with
4275 `display' property yet. The call to pop_it in
4276 set_iterator_to_next will clean this up. */
4277 *position
= start_pos
;
4279 if (EQ (XCAR (spec
), Qleft_fringe
))
4281 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4282 it
->left_user_fringe_face_id
= face_id
;
4286 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4287 it
->right_user_fringe_face_id
= face_id
;
4289 #endif /* HAVE_WINDOW_SYSTEM */
4293 /* Prepare to handle `((margin left-margin) ...)',
4294 `((margin right-margin) ...)' and `((margin nil) ...)'
4295 prefixes for display specifications. */
4296 location
= Qunbound
;
4297 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4301 value
= XCDR (spec
);
4303 value
= XCAR (value
);
4306 if (EQ (XCAR (tem
), Qmargin
)
4307 && (tem
= XCDR (tem
),
4308 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4310 || EQ (tem
, Qleft_margin
)
4311 || EQ (tem
, Qright_margin
))))
4315 if (EQ (location
, Qunbound
))
4321 /* After this point, VALUE is the property after any
4322 margin prefix has been stripped. It must be a string,
4323 an image specification, or `(space ...)'.
4325 LOCATION specifies where to display: `left-margin',
4326 `right-margin' or nil. */
4328 valid_p
= (STRINGP (value
)
4329 #ifdef HAVE_WINDOW_SYSTEM
4330 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4331 #endif /* not HAVE_WINDOW_SYSTEM */
4332 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4334 if (valid_p
&& !display_replaced_before_p
)
4336 /* Save current settings of IT so that we can restore them
4337 when we are finished with the glyph property value. */
4338 save_pos
= it
->position
;
4339 it
->position
= *position
;
4341 it
->position
= save_pos
;
4342 it
->from_overlay
= overlay
;
4344 if (NILP (location
))
4345 it
->area
= TEXT_AREA
;
4346 else if (EQ (location
, Qleft_margin
))
4347 it
->area
= LEFT_MARGIN_AREA
;
4349 it
->area
= RIGHT_MARGIN_AREA
;
4351 if (STRINGP (value
))
4354 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4355 it
->current
.overlay_string_index
= -1;
4356 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4357 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4358 it
->method
= GET_FROM_STRING
;
4359 it
->stop_charpos
= 0;
4360 it
->string_from_display_prop_p
= 1;
4361 /* Say that we haven't consumed the characters with
4362 `display' property yet. The call to pop_it in
4363 set_iterator_to_next will clean this up. */
4364 if (BUFFERP (object
))
4365 *position
= start_pos
;
4367 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4369 it
->method
= GET_FROM_STRETCH
;
4371 *position
= it
->position
= start_pos
;
4373 #ifdef HAVE_WINDOW_SYSTEM
4376 it
->what
= IT_IMAGE
;
4377 it
->image_id
= lookup_image (it
->f
, value
);
4378 it
->position
= start_pos
;
4379 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4380 it
->method
= GET_FROM_IMAGE
;
4382 /* Say that we haven't consumed the characters with
4383 `display' property yet. The call to pop_it in
4384 set_iterator_to_next will clean this up. */
4385 *position
= start_pos
;
4387 #endif /* HAVE_WINDOW_SYSTEM */
4392 /* Invalid property or property not supported. Restore
4393 POSITION to what it was before. */
4394 *position
= start_pos
;
4399 /* Check if SPEC is a display sub-property value whose text should be
4400 treated as intangible. */
4403 single_display_spec_intangible_p (prop
)
4406 /* Skip over `when FORM'. */
4407 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4421 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4422 we don't need to treat text as intangible. */
4423 if (EQ (XCAR (prop
), Qmargin
))
4431 || EQ (XCAR (prop
), Qleft_margin
)
4432 || EQ (XCAR (prop
), Qright_margin
))
4436 return (CONSP (prop
)
4437 && (EQ (XCAR (prop
), Qimage
)
4438 || EQ (XCAR (prop
), Qspace
)));
4442 /* Check if PROP is a display property value whose text should be
4443 treated as intangible. */
4446 display_prop_intangible_p (prop
)
4450 && CONSP (XCAR (prop
))
4451 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4453 /* A list of sub-properties. */
4454 while (CONSP (prop
))
4456 if (single_display_spec_intangible_p (XCAR (prop
)))
4461 else if (VECTORP (prop
))
4463 /* A vector of sub-properties. */
4465 for (i
= 0; i
< ASIZE (prop
); ++i
)
4466 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4470 return single_display_spec_intangible_p (prop
);
4476 /* Return 1 if PROP is a display sub-property value containing STRING. */
4479 single_display_spec_string_p (prop
, string
)
4480 Lisp_Object prop
, string
;
4482 if (EQ (string
, prop
))
4485 /* Skip over `when FORM'. */
4486 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4495 /* Skip over `margin LOCATION'. */
4496 if (EQ (XCAR (prop
), Qmargin
))
4507 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4511 /* Return 1 if STRING appears in the `display' property PROP. */
4514 display_prop_string_p (prop
, string
)
4515 Lisp_Object prop
, string
;
4518 && CONSP (XCAR (prop
))
4519 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4521 /* A list of sub-properties. */
4522 while (CONSP (prop
))
4524 if (single_display_spec_string_p (XCAR (prop
), string
))
4529 else if (VECTORP (prop
))
4531 /* A vector of sub-properties. */
4533 for (i
= 0; i
< ASIZE (prop
); ++i
)
4534 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4538 return single_display_spec_string_p (prop
, string
);
4544 /* Determine which buffer position in W's buffer STRING comes from.
4545 AROUND_CHARPOS is an approximate position where it could come from.
4546 Value is the buffer position or 0 if it couldn't be determined.
4548 W's buffer must be current.
4550 This function is necessary because we don't record buffer positions
4551 in glyphs generated from strings (to keep struct glyph small).
4552 This function may only use code that doesn't eval because it is
4553 called asynchronously from note_mouse_highlight. */
4556 string_buffer_position (w
, string
, around_charpos
)
4561 Lisp_Object limit
, prop
, pos
;
4562 const int MAX_DISTANCE
= 1000;
4565 pos
= make_number (around_charpos
);
4566 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4567 while (!found
&& !EQ (pos
, limit
))
4569 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4570 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4573 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4578 pos
= make_number (around_charpos
);
4579 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4580 while (!found
&& !EQ (pos
, limit
))
4582 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4583 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4586 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4591 return found
? XINT (pos
) : 0;
4596 /***********************************************************************
4597 `composition' property
4598 ***********************************************************************/
4600 /* Set up iterator IT from `composition' property at its current
4601 position. Called from handle_stop. */
4603 static enum prop_handled
4604 handle_composition_prop (it
)
4607 Lisp_Object prop
, string
;
4608 EMACS_INT pos
, pos_byte
, start
, end
;
4610 if (STRINGP (it
->string
))
4614 pos
= IT_STRING_CHARPOS (*it
);
4615 pos_byte
= IT_STRING_BYTEPOS (*it
);
4616 string
= it
->string
;
4617 s
= SDATA (string
) + pos_byte
;
4618 it
->c
= STRING_CHAR (s
);
4622 pos
= IT_CHARPOS (*it
);
4623 pos_byte
= IT_BYTEPOS (*it
);
4625 it
->c
= FETCH_CHAR (pos_byte
);
4628 /* If there's a valid composition and point is not inside of the
4629 composition (in the case that the composition is from the current
4630 buffer), draw a glyph composed from the composition components. */
4631 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4632 && COMPOSITION_VALID_P (start
, end
, prop
)
4633 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4637 if (STRINGP (it
->string
))
4638 pos_byte
= string_char_to_byte (it
->string
, start
);
4640 pos_byte
= CHAR_TO_BYTE (start
);
4642 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4645 if (it
->cmp_it
.id
>= 0)
4648 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4649 it
->cmp_it
.nglyphs
= -1;
4653 return HANDLED_NORMALLY
;
4658 /***********************************************************************
4660 ***********************************************************************/
4662 /* The following structure is used to record overlay strings for
4663 later sorting in load_overlay_strings. */
4665 struct overlay_entry
4667 Lisp_Object overlay
;
4674 /* Set up iterator IT from overlay strings at its current position.
4675 Called from handle_stop. */
4677 static enum prop_handled
4678 handle_overlay_change (it
)
4681 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4682 return HANDLED_RECOMPUTE_PROPS
;
4684 return HANDLED_NORMALLY
;
4688 /* Set up the next overlay string for delivery by IT, if there is an
4689 overlay string to deliver. Called by set_iterator_to_next when the
4690 end of the current overlay string is reached. If there are more
4691 overlay strings to display, IT->string and
4692 IT->current.overlay_string_index are set appropriately here.
4693 Otherwise IT->string is set to nil. */
4696 next_overlay_string (it
)
4699 ++it
->current
.overlay_string_index
;
4700 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4702 /* No more overlay strings. Restore IT's settings to what
4703 they were before overlay strings were processed, and
4704 continue to deliver from current_buffer. */
4706 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4709 || (NILP (it
->string
)
4710 && it
->method
== GET_FROM_BUFFER
4711 && it
->stop_charpos
>= BEGV
4712 && it
->stop_charpos
<= it
->end_charpos
));
4713 it
->current
.overlay_string_index
= -1;
4714 it
->n_overlay_strings
= 0;
4715 it
->overlay_strings_charpos
= -1;
4717 /* If we're at the end of the buffer, record that we have
4718 processed the overlay strings there already, so that
4719 next_element_from_buffer doesn't try it again. */
4720 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4721 it
->overlay_strings_at_end_processed_p
= 1;
4725 /* There are more overlay strings to process. If
4726 IT->current.overlay_string_index has advanced to a position
4727 where we must load IT->overlay_strings with more strings, do
4728 it. We must load at the IT->overlay_strings_charpos where
4729 IT->n_overlay_strings was originally computed; when invisible
4730 text is present, this might not be IT_CHARPOS (Bug#7016). */
4731 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4733 if (it
->current
.overlay_string_index
&& i
== 0)
4734 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4736 /* Initialize IT to deliver display elements from the overlay
4738 it
->string
= it
->overlay_strings
[i
];
4739 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4740 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4741 it
->method
= GET_FROM_STRING
;
4742 it
->stop_charpos
= 0;
4743 if (it
->cmp_it
.stop_pos
>= 0)
4744 it
->cmp_it
.stop_pos
= 0;
4751 /* Compare two overlay_entry structures E1 and E2. Used as a
4752 comparison function for qsort in load_overlay_strings. Overlay
4753 strings for the same position are sorted so that
4755 1. All after-strings come in front of before-strings, except
4756 when they come from the same overlay.
4758 2. Within after-strings, strings are sorted so that overlay strings
4759 from overlays with higher priorities come first.
4761 2. Within before-strings, strings are sorted so that overlay
4762 strings from overlays with higher priorities come last.
4764 Value is analogous to strcmp. */
4768 compare_overlay_entries (e1
, e2
)
4771 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4772 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4775 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4777 /* Let after-strings appear in front of before-strings if
4778 they come from different overlays. */
4779 if (EQ (entry1
->overlay
, entry2
->overlay
))
4780 result
= entry1
->after_string_p
? 1 : -1;
4782 result
= entry1
->after_string_p
? -1 : 1;
4784 else if (entry1
->after_string_p
)
4785 /* After-strings sorted in order of decreasing priority. */
4786 result
= entry2
->priority
- entry1
->priority
;
4788 /* Before-strings sorted in order of increasing priority. */
4789 result
= entry1
->priority
- entry2
->priority
;
4795 /* Load the vector IT->overlay_strings with overlay strings from IT's
4796 current buffer position, or from CHARPOS if that is > 0. Set
4797 IT->n_overlays to the total number of overlay strings found.
4799 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4800 a time. On entry into load_overlay_strings,
4801 IT->current.overlay_string_index gives the number of overlay
4802 strings that have already been loaded by previous calls to this
4805 IT->add_overlay_start contains an additional overlay start
4806 position to consider for taking overlay strings from, if non-zero.
4807 This position comes into play when the overlay has an `invisible'
4808 property, and both before and after-strings. When we've skipped to
4809 the end of the overlay, because of its `invisible' property, we
4810 nevertheless want its before-string to appear.
4811 IT->add_overlay_start will contain the overlay start position
4814 Overlay strings are sorted so that after-string strings come in
4815 front of before-string strings. Within before and after-strings,
4816 strings are sorted by overlay priority. See also function
4817 compare_overlay_entries. */
4820 load_overlay_strings (it
, charpos
)
4824 extern Lisp_Object Qwindow
, Qpriority
;
4825 Lisp_Object overlay
, window
, str
, invisible
;
4826 struct Lisp_Overlay
*ov
;
4829 int n
= 0, i
, j
, invis_p
;
4830 struct overlay_entry
*entries
4831 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4834 charpos
= IT_CHARPOS (*it
);
4836 /* Append the overlay string STRING of overlay OVERLAY to vector
4837 `entries' which has size `size' and currently contains `n'
4838 elements. AFTER_P non-zero means STRING is an after-string of
4840 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4843 Lisp_Object priority; \
4847 int new_size = 2 * size; \
4848 struct overlay_entry *old = entries; \
4850 (struct overlay_entry *) alloca (new_size \
4851 * sizeof *entries); \
4852 bcopy (old, entries, size * sizeof *entries); \
4856 entries[n].string = (STRING); \
4857 entries[n].overlay = (OVERLAY); \
4858 priority = Foverlay_get ((OVERLAY), Qpriority); \
4859 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4860 entries[n].after_string_p = (AFTER_P); \
4865 /* Process overlay before the overlay center. */
4866 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4868 XSETMISC (overlay
, ov
);
4869 xassert (OVERLAYP (overlay
));
4870 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4871 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4876 /* Skip this overlay if it doesn't start or end at IT's current
4878 if (end
!= charpos
&& start
!= charpos
)
4881 /* Skip this overlay if it doesn't apply to IT->w. */
4882 window
= Foverlay_get (overlay
, Qwindow
);
4883 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4886 /* If the text ``under'' the overlay is invisible, both before-
4887 and after-strings from this overlay are visible; start and
4888 end position are indistinguishable. */
4889 invisible
= Foverlay_get (overlay
, Qinvisible
);
4890 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4892 /* If overlay has a non-empty before-string, record it. */
4893 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4894 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4896 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4898 /* If overlay has a non-empty after-string, record it. */
4899 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4900 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4902 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4905 /* Process overlays after the overlay center. */
4906 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4908 XSETMISC (overlay
, ov
);
4909 xassert (OVERLAYP (overlay
));
4910 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4911 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4913 if (start
> charpos
)
4916 /* Skip this overlay if it doesn't start or end at IT's current
4918 if (end
!= charpos
&& start
!= charpos
)
4921 /* Skip this overlay if it doesn't apply to IT->w. */
4922 window
= Foverlay_get (overlay
, Qwindow
);
4923 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4926 /* If the text ``under'' the overlay is invisible, it has a zero
4927 dimension, and both before- and after-strings apply. */
4928 invisible
= Foverlay_get (overlay
, Qinvisible
);
4929 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4931 /* If overlay has a non-empty before-string, record it. */
4932 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4933 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4935 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4937 /* If overlay has a non-empty after-string, record it. */
4938 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4939 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4941 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4944 #undef RECORD_OVERLAY_STRING
4948 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4950 /* Record number of overlay strings, and where we computed it. */
4951 it
->n_overlay_strings
= n
;
4952 it
->overlay_strings_charpos
= charpos
;
4954 /* IT->current.overlay_string_index is the number of overlay strings
4955 that have already been consumed by IT. Copy some of the
4956 remaining overlay strings to IT->overlay_strings. */
4958 j
= it
->current
.overlay_string_index
;
4959 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4961 it
->overlay_strings
[i
] = entries
[j
].string
;
4962 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4969 /* Get the first chunk of overlay strings at IT's current buffer
4970 position, or at CHARPOS if that is > 0. Value is non-zero if at
4971 least one overlay string was found. */
4974 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4979 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4980 process. This fills IT->overlay_strings with strings, and sets
4981 IT->n_overlay_strings to the total number of strings to process.
4982 IT->pos.overlay_string_index has to be set temporarily to zero
4983 because load_overlay_strings needs this; it must be set to -1
4984 when no overlay strings are found because a zero value would
4985 indicate a position in the first overlay string. */
4986 it
->current
.overlay_string_index
= 0;
4987 load_overlay_strings (it
, charpos
);
4989 /* If we found overlay strings, set up IT to deliver display
4990 elements from the first one. Otherwise set up IT to deliver
4991 from current_buffer. */
4992 if (it
->n_overlay_strings
)
4994 /* Make sure we know settings in current_buffer, so that we can
4995 restore meaningful values when we're done with the overlay
4998 compute_stop_pos (it
);
4999 xassert (it
->face_id
>= 0);
5001 /* Save IT's settings. They are restored after all overlay
5002 strings have been processed. */
5003 xassert (!compute_stop_p
|| it
->sp
== 0);
5005 /* When called from handle_stop, there might be an empty display
5006 string loaded. In that case, don't bother saving it. */
5007 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5010 /* Set up IT to deliver display elements from the first overlay
5012 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5013 it
->string
= it
->overlay_strings
[0];
5014 it
->from_overlay
= Qnil
;
5015 it
->stop_charpos
= 0;
5016 xassert (STRINGP (it
->string
));
5017 it
->end_charpos
= SCHARS (it
->string
);
5018 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5019 it
->method
= GET_FROM_STRING
;
5023 it
->current
.overlay_string_index
= -1;
5028 get_overlay_strings (it
, charpos
)
5033 it
->method
= GET_FROM_BUFFER
;
5035 (void) get_overlay_strings_1 (it
, charpos
, 1);
5039 /* Value is non-zero if we found at least one overlay string. */
5040 return STRINGP (it
->string
);
5045 /***********************************************************************
5046 Saving and restoring state
5047 ***********************************************************************/
5049 /* Save current settings of IT on IT->stack. Called, for example,
5050 before setting up IT for an overlay string, to be able to restore
5051 IT's settings to what they were after the overlay string has been
5058 struct iterator_stack_entry
*p
;
5060 xassert (it
->sp
< IT_STACK_SIZE
);
5061 p
= it
->stack
+ it
->sp
;
5063 p
->stop_charpos
= it
->stop_charpos
;
5064 p
->cmp_it
= it
->cmp_it
;
5065 xassert (it
->face_id
>= 0);
5066 p
->face_id
= it
->face_id
;
5067 p
->string
= it
->string
;
5068 p
->method
= it
->method
;
5069 p
->from_overlay
= it
->from_overlay
;
5072 case GET_FROM_IMAGE
:
5073 p
->u
.image
.object
= it
->object
;
5074 p
->u
.image
.image_id
= it
->image_id
;
5075 p
->u
.image
.slice
= it
->slice
;
5077 case GET_FROM_STRETCH
:
5078 p
->u
.stretch
.object
= it
->object
;
5081 p
->position
= it
->position
;
5082 p
->current
= it
->current
;
5083 p
->end_charpos
= it
->end_charpos
;
5084 p
->string_nchars
= it
->string_nchars
;
5086 p
->multibyte_p
= it
->multibyte_p
;
5087 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5088 p
->space_width
= it
->space_width
;
5089 p
->font_height
= it
->font_height
;
5090 p
->voffset
= it
->voffset
;
5091 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5092 p
->display_ellipsis_p
= 0;
5093 p
->line_wrap
= it
->line_wrap
;
5098 /* Restore IT's settings from IT->stack. Called, for example, when no
5099 more overlay strings must be processed, and we return to delivering
5100 display elements from a buffer, or when the end of a string from a
5101 `display' property is reached and we return to delivering display
5102 elements from an overlay string, or from a buffer. */
5108 struct iterator_stack_entry
*p
;
5110 xassert (it
->sp
> 0);
5112 p
= it
->stack
+ it
->sp
;
5113 it
->stop_charpos
= p
->stop_charpos
;
5114 it
->cmp_it
= p
->cmp_it
;
5115 it
->face_id
= p
->face_id
;
5116 it
->current
= p
->current
;
5117 it
->position
= p
->position
;
5118 it
->string
= p
->string
;
5119 it
->from_overlay
= p
->from_overlay
;
5120 if (NILP (it
->string
))
5121 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5122 it
->method
= p
->method
;
5125 case GET_FROM_IMAGE
:
5126 it
->image_id
= p
->u
.image
.image_id
;
5127 it
->object
= p
->u
.image
.object
;
5128 it
->slice
= p
->u
.image
.slice
;
5130 case GET_FROM_STRETCH
:
5131 it
->object
= p
->u
.comp
.object
;
5133 case GET_FROM_BUFFER
:
5134 it
->object
= it
->w
->buffer
;
5136 case GET_FROM_STRING
:
5137 it
->object
= it
->string
;
5139 case GET_FROM_DISPLAY_VECTOR
:
5141 it
->method
= GET_FROM_C_STRING
;
5142 else if (STRINGP (it
->string
))
5143 it
->method
= GET_FROM_STRING
;
5146 it
->method
= GET_FROM_BUFFER
;
5147 it
->object
= it
->w
->buffer
;
5150 it
->end_charpos
= p
->end_charpos
;
5151 it
->string_nchars
= p
->string_nchars
;
5153 it
->multibyte_p
= p
->multibyte_p
;
5154 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5155 it
->space_width
= p
->space_width
;
5156 it
->font_height
= p
->font_height
;
5157 it
->voffset
= p
->voffset
;
5158 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5159 it
->line_wrap
= p
->line_wrap
;
5164 /***********************************************************************
5166 ***********************************************************************/
5168 /* Set IT's current position to the previous line start. */
5171 back_to_previous_line_start (it
)
5174 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5175 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5179 /* Move IT to the next line start.
5181 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5182 we skipped over part of the text (as opposed to moving the iterator
5183 continuously over the text). Otherwise, don't change the value
5186 Newlines may come from buffer text, overlay strings, or strings
5187 displayed via the `display' property. That's the reason we can't
5188 simply use find_next_newline_no_quit.
5190 Note that this function may not skip over invisible text that is so
5191 because of text properties and immediately follows a newline. If
5192 it would, function reseat_at_next_visible_line_start, when called
5193 from set_iterator_to_next, would effectively make invisible
5194 characters following a newline part of the wrong glyph row, which
5195 leads to wrong cursor motion. */
5198 forward_to_next_line_start (it
, skipped_p
)
5202 int old_selective
, newline_found_p
, n
;
5203 const int MAX_NEWLINE_DISTANCE
= 500;
5205 /* If already on a newline, just consume it to avoid unintended
5206 skipping over invisible text below. */
5207 if (it
->what
== IT_CHARACTER
5209 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5211 set_iterator_to_next (it
, 0);
5216 /* Don't handle selective display in the following. It's (a)
5217 unnecessary because it's done by the caller, and (b) leads to an
5218 infinite recursion because next_element_from_ellipsis indirectly
5219 calls this function. */
5220 old_selective
= it
->selective
;
5223 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5224 from buffer text. */
5225 for (n
= newline_found_p
= 0;
5226 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5227 n
+= STRINGP (it
->string
) ? 0 : 1)
5229 if (!get_next_display_element (it
))
5231 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5232 set_iterator_to_next (it
, 0);
5235 /* If we didn't find a newline near enough, see if we can use a
5237 if (!newline_found_p
)
5239 int start
= IT_CHARPOS (*it
);
5240 int limit
= find_next_newline_no_quit (start
, 1);
5243 xassert (!STRINGP (it
->string
));
5245 /* If there isn't any `display' property in sight, and no
5246 overlays, we can just use the position of the newline in
5248 if (it
->stop_charpos
>= limit
5249 || ((pos
= Fnext_single_property_change (make_number (start
),
5251 Qnil
, make_number (limit
)),
5253 && next_overlay_change (start
) == ZV
))
5255 IT_CHARPOS (*it
) = limit
;
5256 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5257 *skipped_p
= newline_found_p
= 1;
5261 while (get_next_display_element (it
)
5262 && !newline_found_p
)
5264 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5265 set_iterator_to_next (it
, 0);
5270 it
->selective
= old_selective
;
5271 return newline_found_p
;
5275 /* Set IT's current position to the previous visible line start. Skip
5276 invisible text that is so either due to text properties or due to
5277 selective display. Caution: this does not change IT->current_x and
5281 back_to_previous_visible_line_start (it
)
5284 while (IT_CHARPOS (*it
) > BEGV
)
5286 back_to_previous_line_start (it
);
5288 if (IT_CHARPOS (*it
) <= BEGV
)
5291 /* If selective > 0, then lines indented more than that values
5293 if (it
->selective
> 0
5294 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5295 (double) it
->selective
)) /* iftc */
5298 /* Check the newline before point for invisibility. */
5301 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5302 Qinvisible
, it
->window
);
5303 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5307 if (IT_CHARPOS (*it
) <= BEGV
)
5314 Lisp_Object val
, overlay
;
5316 /* If newline is part of a composition, continue from start of composition */
5317 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5318 && beg
< IT_CHARPOS (*it
))
5321 /* If newline is replaced by a display property, find start of overlay
5322 or interval and continue search from that point. */
5324 pos
= --IT_CHARPOS (it2
);
5327 it2
.string_from_display_prop_p
= 0;
5328 if (handle_display_prop (&it2
) == HANDLED_RETURN
5329 && !NILP (val
= get_char_property_and_overlay
5330 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5331 && (OVERLAYP (overlay
)
5332 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5333 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5336 /* Newline is not replaced by anything -- so we are done. */
5342 IT_CHARPOS (*it
) = beg
;
5343 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5347 it
->continuation_lines_width
= 0;
5349 xassert (IT_CHARPOS (*it
) >= BEGV
);
5350 xassert (IT_CHARPOS (*it
) == BEGV
5351 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5356 /* Reseat iterator IT at the previous visible line start. Skip
5357 invisible text that is so either due to text properties or due to
5358 selective display. At the end, update IT's overlay information,
5359 face information etc. */
5362 reseat_at_previous_visible_line_start (it
)
5365 back_to_previous_visible_line_start (it
);
5366 reseat (it
, it
->current
.pos
, 1);
5371 /* Reseat iterator IT on the next visible line start in the current
5372 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5373 preceding the line start. Skip over invisible text that is so
5374 because of selective display. Compute faces, overlays etc at the
5375 new position. Note that this function does not skip over text that
5376 is invisible because of text properties. */
5379 reseat_at_next_visible_line_start (it
, on_newline_p
)
5383 int newline_found_p
, skipped_p
= 0;
5385 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5387 /* Skip over lines that are invisible because they are indented
5388 more than the value of IT->selective. */
5389 if (it
->selective
> 0)
5390 while (IT_CHARPOS (*it
) < ZV
5391 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5392 (double) it
->selective
)) /* iftc */
5394 xassert (IT_BYTEPOS (*it
) == BEGV
5395 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5396 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5399 /* Position on the newline if that's what's requested. */
5400 if (on_newline_p
&& newline_found_p
)
5402 if (STRINGP (it
->string
))
5404 if (IT_STRING_CHARPOS (*it
) > 0)
5406 --IT_STRING_CHARPOS (*it
);
5407 --IT_STRING_BYTEPOS (*it
);
5410 else if (IT_CHARPOS (*it
) > BEGV
)
5414 reseat (it
, it
->current
.pos
, 0);
5418 reseat (it
, it
->current
.pos
, 0);
5425 /***********************************************************************
5426 Changing an iterator's position
5427 ***********************************************************************/
5429 /* Change IT's current position to POS in current_buffer. If FORCE_P
5430 is non-zero, always check for text properties at the new position.
5431 Otherwise, text properties are only looked up if POS >=
5432 IT->check_charpos of a property. */
5435 reseat (it
, pos
, force_p
)
5437 struct text_pos pos
;
5440 int original_pos
= IT_CHARPOS (*it
);
5442 reseat_1 (it
, pos
, 0);
5444 /* Determine where to check text properties. Avoid doing it
5445 where possible because text property lookup is very expensive. */
5447 || CHARPOS (pos
) > it
->stop_charpos
5448 || CHARPOS (pos
) < original_pos
)
5455 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5456 IT->stop_pos to POS, also. */
5459 reseat_1 (it
, pos
, set_stop_p
)
5461 struct text_pos pos
;
5464 /* Don't call this function when scanning a C string. */
5465 xassert (it
->s
== NULL
);
5467 /* POS must be a reasonable value. */
5468 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5470 it
->current
.pos
= it
->position
= pos
;
5471 it
->end_charpos
= ZV
;
5473 it
->current
.dpvec_index
= -1;
5474 it
->current
.overlay_string_index
= -1;
5475 IT_STRING_CHARPOS (*it
) = -1;
5476 IT_STRING_BYTEPOS (*it
) = -1;
5478 it
->string_from_display_prop_p
= 0;
5479 it
->method
= GET_FROM_BUFFER
;
5480 it
->object
= it
->w
->buffer
;
5481 it
->area
= TEXT_AREA
;
5482 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5484 it
->string_from_display_prop_p
= 0;
5485 it
->face_before_selective_p
= 0;
5488 it
->stop_charpos
= CHARPOS (pos
);
5492 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5493 If S is non-null, it is a C string to iterate over. Otherwise,
5494 STRING gives a Lisp string to iterate over.
5496 If PRECISION > 0, don't return more then PRECISION number of
5497 characters from the string.
5499 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5500 characters have been returned. FIELD_WIDTH < 0 means an infinite
5503 MULTIBYTE = 0 means disable processing of multibyte characters,
5504 MULTIBYTE > 0 means enable it,
5505 MULTIBYTE < 0 means use IT->multibyte_p.
5507 IT must be initialized via a prior call to init_iterator before
5508 calling this function. */
5511 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5516 int precision
, field_width
, multibyte
;
5518 /* No region in strings. */
5519 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5521 /* No text property checks performed by default, but see below. */
5522 it
->stop_charpos
= -1;
5524 /* Set iterator position and end position. */
5525 bzero (&it
->current
, sizeof it
->current
);
5526 it
->current
.overlay_string_index
= -1;
5527 it
->current
.dpvec_index
= -1;
5528 xassert (charpos
>= 0);
5530 /* If STRING is specified, use its multibyteness, otherwise use the
5531 setting of MULTIBYTE, if specified. */
5533 it
->multibyte_p
= multibyte
> 0;
5537 xassert (STRINGP (string
));
5538 it
->string
= string
;
5540 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5541 it
->method
= GET_FROM_STRING
;
5542 it
->current
.string_pos
= string_pos (charpos
, string
);
5549 /* Note that we use IT->current.pos, not it->current.string_pos,
5550 for displaying C strings. */
5551 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5552 if (it
->multibyte_p
)
5554 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5555 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5559 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5560 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5563 it
->method
= GET_FROM_C_STRING
;
5566 /* PRECISION > 0 means don't return more than PRECISION characters
5568 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5569 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5571 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5572 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5573 FIELD_WIDTH < 0 means infinite field width. This is useful for
5574 padding with `-' at the end of a mode line. */
5575 if (field_width
< 0)
5576 field_width
= INFINITY
;
5577 if (field_width
> it
->end_charpos
- charpos
)
5578 it
->end_charpos
= charpos
+ field_width
;
5580 /* Use the standard display table for displaying strings. */
5581 if (DISP_TABLE_P (Vstandard_display_table
))
5582 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5584 it
->stop_charpos
= charpos
;
5585 if (s
== NULL
&& it
->multibyte_p
)
5587 EMACS_INT endpos
= SCHARS (it
->string
);
5588 if (endpos
> it
->end_charpos
)
5589 endpos
= it
->end_charpos
;
5590 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5598 /***********************************************************************
5600 ***********************************************************************/
5602 /* Map enum it_method value to corresponding next_element_from_* function. */
5604 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5606 next_element_from_buffer
,
5607 next_element_from_display_vector
,
5608 next_element_from_string
,
5609 next_element_from_c_string
,
5610 next_element_from_image
,
5611 next_element_from_stretch
5614 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5617 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5618 (possibly with the following characters). */
5620 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5621 ((IT)->cmp_it.id >= 0 \
5622 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5623 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5624 END_CHARPOS, (IT)->w, \
5625 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5629 /* Load IT's display element fields with information about the next
5630 display element from the current position of IT. Value is zero if
5631 end of buffer (or C string) is reached. */
5633 static struct frame
*last_escape_glyph_frame
= NULL
;
5634 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5635 static int last_escape_glyph_merged_face_id
= 0;
5638 get_next_display_element (it
)
5641 /* Non-zero means that we found a display element. Zero means that
5642 we hit the end of what we iterate over. Performance note: the
5643 function pointer `method' used here turns out to be faster than
5644 using a sequence of if-statements. */
5648 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5650 if (it
->what
== IT_CHARACTER
)
5652 /* Map via display table or translate control characters.
5653 IT->c, IT->len etc. have been set to the next character by
5654 the function call above. If we have a display table, and it
5655 contains an entry for IT->c, translate it. Don't do this if
5656 IT->c itself comes from a display table, otherwise we could
5657 end up in an infinite recursion. (An alternative could be to
5658 count the recursion depth of this function and signal an
5659 error when a certain maximum depth is reached.) Is it worth
5661 if (success_p
&& it
->dpvec
== NULL
)
5664 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5665 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5666 nbsp_or_shy
= char_is_other
;
5667 int c
= it
->c
; /* This is the character to display. */
5669 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5671 xassert (SINGLE_BYTE_CHAR_P (c
));
5672 if (unibyte_display_via_language_environment
)
5674 c
= DECODE_CHAR (unibyte
, c
);
5676 c
= BYTE8_TO_CHAR (it
->c
);
5679 c
= BYTE8_TO_CHAR (it
->c
);
5683 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5686 struct Lisp_Vector
*v
= XVECTOR (dv
);
5688 /* Return the first character from the display table
5689 entry, if not empty. If empty, don't display the
5690 current character. */
5693 it
->dpvec_char_len
= it
->len
;
5694 it
->dpvec
= v
->contents
;
5695 it
->dpend
= v
->contents
+ v
->size
;
5696 it
->current
.dpvec_index
= 0;
5697 it
->dpvec_face_id
= -1;
5698 it
->saved_face_id
= it
->face_id
;
5699 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5704 set_iterator_to_next (it
, 0);
5709 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5710 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5711 : c
== 0xAD ? char_is_soft_hyphen
5714 /* Translate control characters into `\003' or `^C' form.
5715 Control characters coming from a display table entry are
5716 currently not translated because we use IT->dpvec to hold
5717 the translation. This could easily be changed but I
5718 don't believe that it is worth doing.
5720 NBSP and SOFT-HYPEN are property translated too.
5722 Non-printable characters and raw-byte characters are also
5723 translated to octal form. */
5724 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5725 ? (it
->area
!= TEXT_AREA
5726 /* In mode line, treat \n, \t like other crl chars. */
5729 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5730 || (c
!= '\n' && c
!= '\t'))
5733 || ! CHAR_PRINTABLE_P (c
))))
5735 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5736 or a non-printable character which must be displayed
5737 either as '\003' or as `^C' where the '\\' and '^'
5738 can be defined in the display table. Fill
5739 IT->ctl_chars with glyphs for what we have to
5740 display. Then, set IT->dpvec to these glyphs. */
5743 int face_id
, lface_id
= 0 ;
5746 /* Handle control characters with ^. */
5748 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5752 g
= '^'; /* default glyph for Control */
5753 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5755 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5756 && GLYPH_CODE_CHAR_VALID_P (gc
))
5758 g
= GLYPH_CODE_CHAR (gc
);
5759 lface_id
= GLYPH_CODE_FACE (gc
);
5763 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5765 else if (it
->f
== last_escape_glyph_frame
5766 && it
->face_id
== last_escape_glyph_face_id
)
5768 face_id
= last_escape_glyph_merged_face_id
;
5772 /* Merge the escape-glyph face into the current face. */
5773 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5775 last_escape_glyph_frame
= it
->f
;
5776 last_escape_glyph_face_id
= it
->face_id
;
5777 last_escape_glyph_merged_face_id
= face_id
;
5780 XSETINT (it
->ctl_chars
[0], g
);
5781 XSETINT (it
->ctl_chars
[1], c
^ 0100);
5783 goto display_control
;
5786 /* Handle non-break space in the mode where it only gets
5789 if (EQ (Vnobreak_char_display
, Qt
)
5790 && nbsp_or_shy
== char_is_nbsp
)
5792 /* Merge the no-break-space face into the current face. */
5793 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5797 XSETINT (it
->ctl_chars
[0], ' ');
5799 goto display_control
;
5802 /* Handle sequences that start with the "escape glyph". */
5804 /* the default escape glyph is \. */
5805 escape_glyph
= '\\';
5808 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5809 && GLYPH_CODE_CHAR_VALID_P (gc
))
5811 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5812 lface_id
= GLYPH_CODE_FACE (gc
);
5816 /* The display table specified a face.
5817 Merge it into face_id and also into escape_glyph. */
5818 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5821 else if (it
->f
== last_escape_glyph_frame
5822 && it
->face_id
== last_escape_glyph_face_id
)
5824 face_id
= last_escape_glyph_merged_face_id
;
5828 /* Merge the escape-glyph face into the current face. */
5829 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5831 last_escape_glyph_frame
= it
->f
;
5832 last_escape_glyph_face_id
= it
->face_id
;
5833 last_escape_glyph_merged_face_id
= face_id
;
5836 /* Handle soft hyphens in the mode where they only get
5839 if (EQ (Vnobreak_char_display
, Qt
)
5840 && nbsp_or_shy
== char_is_soft_hyphen
)
5842 XSETINT (it
->ctl_chars
[0], '-');
5844 goto display_control
;
5847 /* Handle non-break space and soft hyphen
5848 with the escape glyph. */
5852 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5853 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5854 XSETINT (it
->ctl_chars
[1], c
);
5856 goto display_control
;
5863 if (CHAR_BYTE8_P (c
))
5864 /* Display \200 instead of \17777600. */
5865 c
= CHAR_TO_BYTE8 (c
);
5866 len
= sprintf (str
, "%03o", c
);
5868 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5869 for (i
= 0; i
< len
; i
++)
5870 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
5875 /* Set up IT->dpvec and return first character from it. */
5876 it
->dpvec_char_len
= it
->len
;
5877 it
->dpvec
= it
->ctl_chars
;
5878 it
->dpend
= it
->dpvec
+ ctl_len
;
5879 it
->current
.dpvec_index
= 0;
5880 it
->dpvec_face_id
= face_id
;
5881 it
->saved_face_id
= it
->face_id
;
5882 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5886 it
->char_to_display
= c
;
5890 it
->char_to_display
= it
->c
;
5894 #ifdef HAVE_WINDOW_SYSTEM
5895 /* Adjust face id for a multibyte character. There are no multibyte
5896 character in unibyte text. */
5897 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5900 && FRAME_WINDOW_P (it
->f
))
5902 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5904 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5906 /* Automatic composition with glyph-string. */
5907 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5909 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5913 int pos
= (it
->s
? -1
5914 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5915 : IT_CHARPOS (*it
));
5917 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
5923 /* Is this character the last one of a run of characters with
5924 box? If yes, set IT->end_of_box_run_p to 1. */
5928 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5930 int face_id
= underlying_face_id (it
);
5931 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5935 if (face
->box
== FACE_NO_BOX
)
5937 /* If the box comes from face properties in a
5938 display string, check faces in that string. */
5939 int string_face_id
= face_after_it_pos (it
);
5940 it
->end_of_box_run_p
5941 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5944 /* Otherwise, the box comes from the underlying face.
5945 If this is the last string character displayed, check
5946 the next buffer location. */
5947 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
5948 && (it
->current
.overlay_string_index
5949 == it
->n_overlay_strings
- 1))
5953 struct text_pos pos
= it
->current
.pos
;
5954 INC_TEXT_POS (pos
, it
->multibyte_p
);
5956 next_face_id
= face_at_buffer_position
5957 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
5958 it
->region_end_charpos
, &ignore
,
5959 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
5961 it
->end_of_box_run_p
5962 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
5969 int face_id
= face_after_it_pos (it
);
5970 it
->end_of_box_run_p
5971 = (face_id
!= it
->face_id
5972 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
5976 /* Value is 0 if end of buffer or string reached. */
5981 /* Move IT to the next display element.
5983 RESEAT_P non-zero means if called on a newline in buffer text,
5984 skip to the next visible line start.
5986 Functions get_next_display_element and set_iterator_to_next are
5987 separate because I find this arrangement easier to handle than a
5988 get_next_display_element function that also increments IT's
5989 position. The way it is we can first look at an iterator's current
5990 display element, decide whether it fits on a line, and if it does,
5991 increment the iterator position. The other way around we probably
5992 would either need a flag indicating whether the iterator has to be
5993 incremented the next time, or we would have to implement a
5994 decrement position function which would not be easy to write. */
5997 set_iterator_to_next (it
, reseat_p
)
6001 /* Reset flags indicating start and end of a sequence of characters
6002 with box. Reset them at the start of this function because
6003 moving the iterator to a new position might set them. */
6004 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6008 case GET_FROM_BUFFER
:
6009 /* The current display element of IT is a character from
6010 current_buffer. Advance in the buffer, and maybe skip over
6011 invisible lines that are so because of selective display. */
6012 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6013 reseat_at_next_visible_line_start (it
, 0);
6014 else if (it
->cmp_it
.id
>= 0)
6016 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6017 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6018 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6019 it
->cmp_it
.from
= it
->cmp_it
.to
;
6023 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6024 IT_BYTEPOS (*it
), it
->stop_charpos
,
6030 xassert (it
->len
!= 0);
6031 IT_BYTEPOS (*it
) += it
->len
;
6032 IT_CHARPOS (*it
) += 1;
6033 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6037 case GET_FROM_C_STRING
:
6038 /* Current display element of IT is from a C string. */
6039 IT_BYTEPOS (*it
) += it
->len
;
6040 IT_CHARPOS (*it
) += 1;
6043 case GET_FROM_DISPLAY_VECTOR
:
6044 /* Current display element of IT is from a display table entry.
6045 Advance in the display table definition. Reset it to null if
6046 end reached, and continue with characters from buffers/
6048 ++it
->current
.dpvec_index
;
6050 /* Restore face of the iterator to what they were before the
6051 display vector entry (these entries may contain faces). */
6052 it
->face_id
= it
->saved_face_id
;
6054 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6056 int recheck_faces
= it
->ellipsis_p
;
6059 it
->method
= GET_FROM_C_STRING
;
6060 else if (STRINGP (it
->string
))
6061 it
->method
= GET_FROM_STRING
;
6064 it
->method
= GET_FROM_BUFFER
;
6065 it
->object
= it
->w
->buffer
;
6069 it
->current
.dpvec_index
= -1;
6071 /* Skip over characters which were displayed via IT->dpvec. */
6072 if (it
->dpvec_char_len
< 0)
6073 reseat_at_next_visible_line_start (it
, 1);
6074 else if (it
->dpvec_char_len
> 0)
6076 if (it
->method
== GET_FROM_STRING
6077 && it
->n_overlay_strings
> 0)
6078 it
->ignore_overlay_strings_at_pos_p
= 1;
6079 it
->len
= it
->dpvec_char_len
;
6080 set_iterator_to_next (it
, reseat_p
);
6083 /* Maybe recheck faces after display vector */
6085 it
->stop_charpos
= IT_CHARPOS (*it
);
6089 case GET_FROM_STRING
:
6090 /* Current display element is a character from a Lisp string. */
6091 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6092 if (it
->cmp_it
.id
>= 0)
6094 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6095 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6096 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6097 it
->cmp_it
.from
= it
->cmp_it
.to
;
6101 composition_compute_stop_pos (&it
->cmp_it
,
6102 IT_STRING_CHARPOS (*it
),
6103 IT_STRING_BYTEPOS (*it
),
6104 it
->stop_charpos
, it
->string
);
6109 IT_STRING_BYTEPOS (*it
) += it
->len
;
6110 IT_STRING_CHARPOS (*it
) += 1;
6113 consider_string_end
:
6115 if (it
->current
.overlay_string_index
>= 0)
6117 /* IT->string is an overlay string. Advance to the
6118 next, if there is one. */
6119 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6122 next_overlay_string (it
);
6124 setup_for_ellipsis (it
, 0);
6129 /* IT->string is not an overlay string. If we reached
6130 its end, and there is something on IT->stack, proceed
6131 with what is on the stack. This can be either another
6132 string, this time an overlay string, or a buffer. */
6133 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6137 if (it
->method
== GET_FROM_STRING
)
6138 goto consider_string_end
;
6143 case GET_FROM_IMAGE
:
6144 case GET_FROM_STRETCH
:
6145 /* The position etc with which we have to proceed are on
6146 the stack. The position may be at the end of a string,
6147 if the `display' property takes up the whole string. */
6148 xassert (it
->sp
> 0);
6150 if (it
->method
== GET_FROM_STRING
)
6151 goto consider_string_end
;
6155 /* There are no other methods defined, so this should be a bug. */
6159 xassert (it
->method
!= GET_FROM_STRING
6160 || (STRINGP (it
->string
)
6161 && IT_STRING_CHARPOS (*it
) >= 0));
6164 /* Load IT's display element fields with information about the next
6165 display element which comes from a display table entry or from the
6166 result of translating a control character to one of the forms `^C'
6169 IT->dpvec holds the glyphs to return as characters.
6170 IT->saved_face_id holds the face id before the display vector--it
6171 is restored into IT->face_id in set_iterator_to_next. */
6174 next_element_from_display_vector (it
)
6180 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6182 it
->face_id
= it
->saved_face_id
;
6184 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6185 That seemed totally bogus - so I changed it... */
6186 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6188 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6190 it
->c
= GLYPH_CODE_CHAR (gc
);
6191 it
->len
= CHAR_BYTES (it
->c
);
6193 /* The entry may contain a face id to use. Such a face id is
6194 the id of a Lisp face, not a realized face. A face id of
6195 zero means no face is specified. */
6196 if (it
->dpvec_face_id
>= 0)
6197 it
->face_id
= it
->dpvec_face_id
;
6200 int lface_id
= GLYPH_CODE_FACE (gc
);
6202 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6207 /* Display table entry is invalid. Return a space. */
6208 it
->c
= ' ', it
->len
= 1;
6210 /* Don't change position and object of the iterator here. They are
6211 still the values of the character that had this display table
6212 entry or was translated, and that's what we want. */
6213 it
->what
= IT_CHARACTER
;
6218 /* Load IT with the next display element from Lisp string IT->string.
6219 IT->current.string_pos is the current position within the string.
6220 If IT->current.overlay_string_index >= 0, the Lisp string is an
6224 next_element_from_string (it
)
6227 struct text_pos position
;
6229 xassert (STRINGP (it
->string
));
6230 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6231 position
= it
->current
.string_pos
;
6233 /* Time to check for invisible text? */
6234 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6235 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6239 /* Since a handler may have changed IT->method, we must
6241 return GET_NEXT_DISPLAY_ELEMENT (it
);
6244 if (it
->current
.overlay_string_index
>= 0)
6246 /* Get the next character from an overlay string. In overlay
6247 strings, There is no field width or padding with spaces to
6249 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6254 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6255 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6256 && next_element_from_composition (it
))
6260 else if (STRING_MULTIBYTE (it
->string
))
6262 const unsigned char *s
= (SDATA (it
->string
)
6263 + IT_STRING_BYTEPOS (*it
));
6264 it
->c
= string_char_and_length (s
, &it
->len
);
6268 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6274 /* Get the next character from a Lisp string that is not an
6275 overlay string. Such strings come from the mode line, for
6276 example. We may have to pad with spaces, or truncate the
6277 string. See also next_element_from_c_string. */
6278 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6283 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6285 /* Pad with spaces. */
6286 it
->c
= ' ', it
->len
= 1;
6287 CHARPOS (position
) = BYTEPOS (position
) = -1;
6289 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6290 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6291 && next_element_from_composition (it
))
6295 else if (STRING_MULTIBYTE (it
->string
))
6297 const unsigned char *s
= (SDATA (it
->string
)
6298 + IT_STRING_BYTEPOS (*it
));
6299 it
->c
= string_char_and_length (s
, &it
->len
);
6303 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6308 /* Record what we have and where it came from. */
6309 it
->what
= IT_CHARACTER
;
6310 it
->object
= it
->string
;
6311 it
->position
= position
;
6316 /* Load IT with next display element from C string IT->s.
6317 IT->string_nchars is the maximum number of characters to return
6318 from the string. IT->end_charpos may be greater than
6319 IT->string_nchars when this function is called, in which case we
6320 may have to return padding spaces. Value is zero if end of string
6321 reached, including padding spaces. */
6324 next_element_from_c_string (it
)
6330 it
->what
= IT_CHARACTER
;
6331 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6334 /* IT's position can be greater IT->string_nchars in case a field
6335 width or precision has been specified when the iterator was
6337 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6339 /* End of the game. */
6343 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6345 /* Pad with spaces. */
6346 it
->c
= ' ', it
->len
= 1;
6347 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6349 else if (it
->multibyte_p
)
6350 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6352 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6358 /* Set up IT to return characters from an ellipsis, if appropriate.
6359 The definition of the ellipsis glyphs may come from a display table
6360 entry. This function fills IT with the first glyph from the
6361 ellipsis if an ellipsis is to be displayed. */
6364 next_element_from_ellipsis (it
)
6367 if (it
->selective_display_ellipsis_p
)
6368 setup_for_ellipsis (it
, it
->len
);
6371 /* The face at the current position may be different from the
6372 face we find after the invisible text. Remember what it
6373 was in IT->saved_face_id, and signal that it's there by
6374 setting face_before_selective_p. */
6375 it
->saved_face_id
= it
->face_id
;
6376 it
->method
= GET_FROM_BUFFER
;
6377 it
->object
= it
->w
->buffer
;
6378 reseat_at_next_visible_line_start (it
, 1);
6379 it
->face_before_selective_p
= 1;
6382 return GET_NEXT_DISPLAY_ELEMENT (it
);
6386 /* Deliver an image display element. The iterator IT is already
6387 filled with image information (done in handle_display_prop). Value
6392 next_element_from_image (it
)
6395 it
->what
= IT_IMAGE
;
6396 it
->ignore_overlay_strings_at_pos_p
= 0;
6401 /* Fill iterator IT with next display element from a stretch glyph
6402 property. IT->object is the value of the text property. Value is
6406 next_element_from_stretch (it
)
6409 it
->what
= IT_STRETCH
;
6414 /* Load IT with the next display element from current_buffer. Value
6415 is zero if end of buffer reached. IT->stop_charpos is the next
6416 position at which to stop and check for text properties or buffer
6420 next_element_from_buffer (it
)
6425 xassert (IT_CHARPOS (*it
) >= BEGV
);
6427 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6429 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6431 int overlay_strings_follow_p
;
6433 /* End of the game, except when overlay strings follow that
6434 haven't been returned yet. */
6435 if (it
->overlay_strings_at_end_processed_p
)
6436 overlay_strings_follow_p
= 0;
6439 it
->overlay_strings_at_end_processed_p
= 1;
6440 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6443 if (overlay_strings_follow_p
)
6444 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6448 it
->position
= it
->current
.pos
;
6455 return GET_NEXT_DISPLAY_ELEMENT (it
);
6460 /* No face changes, overlays etc. in sight, so just return a
6461 character from current_buffer. */
6464 /* Maybe run the redisplay end trigger hook. Performance note:
6465 This doesn't seem to cost measurable time. */
6466 if (it
->redisplay_end_trigger_charpos
6468 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6469 run_redisplay_end_trigger_hook (it
);
6471 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6473 && next_element_from_composition (it
))
6478 /* Get the next character, maybe multibyte. */
6479 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6480 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6481 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6483 it
->c
= *p
, it
->len
= 1;
6485 /* Record what we have and where it came from. */
6486 it
->what
= IT_CHARACTER
;
6487 it
->object
= it
->w
->buffer
;
6488 it
->position
= it
->current
.pos
;
6490 /* Normally we return the character found above, except when we
6491 really want to return an ellipsis for selective display. */
6496 /* A value of selective > 0 means hide lines indented more
6497 than that number of columns. */
6498 if (it
->selective
> 0
6499 && IT_CHARPOS (*it
) + 1 < ZV
6500 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6501 IT_BYTEPOS (*it
) + 1,
6502 (double) it
->selective
)) /* iftc */
6504 success_p
= next_element_from_ellipsis (it
);
6505 it
->dpvec_char_len
= -1;
6508 else if (it
->c
== '\r' && it
->selective
== -1)
6510 /* A value of selective == -1 means that everything from the
6511 CR to the end of the line is invisible, with maybe an
6512 ellipsis displayed for it. */
6513 success_p
= next_element_from_ellipsis (it
);
6514 it
->dpvec_char_len
= -1;
6519 /* Value is zero if end of buffer reached. */
6520 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6525 /* Run the redisplay end trigger hook for IT. */
6528 run_redisplay_end_trigger_hook (it
)
6531 Lisp_Object args
[3];
6533 /* IT->glyph_row should be non-null, i.e. we should be actually
6534 displaying something, or otherwise we should not run the hook. */
6535 xassert (it
->glyph_row
);
6537 /* Set up hook arguments. */
6538 args
[0] = Qredisplay_end_trigger_functions
;
6539 args
[1] = it
->window
;
6540 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6541 it
->redisplay_end_trigger_charpos
= 0;
6543 /* Since we are *trying* to run these functions, don't try to run
6544 them again, even if they get an error. */
6545 it
->w
->redisplay_end_trigger
= Qnil
;
6546 Frun_hook_with_args (3, args
);
6548 /* Notice if it changed the face of the character we are on. */
6549 handle_face_prop (it
);
6553 /* Deliver a composition display element. Unlike the other
6554 next_element_from_XXX, this function is not registered in the array
6555 get_next_element[]. It is called from next_element_from_buffer and
6556 next_element_from_string when necessary. */
6559 next_element_from_composition (it
)
6562 it
->what
= IT_COMPOSITION
;
6563 it
->len
= it
->cmp_it
.nbytes
;
6564 if (STRINGP (it
->string
))
6568 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6569 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6572 it
->position
= it
->current
.string_pos
;
6573 it
->object
= it
->string
;
6574 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6575 IT_STRING_BYTEPOS (*it
), it
->string
);
6581 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6582 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6585 it
->position
= it
->current
.pos
;
6586 it
->object
= it
->w
->buffer
;
6587 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6588 IT_BYTEPOS (*it
), Qnil
);
6595 /***********************************************************************
6596 Moving an iterator without producing glyphs
6597 ***********************************************************************/
6599 /* Check if iterator is at a position corresponding to a valid buffer
6600 position after some move_it_ call. */
6602 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6603 ((it)->method == GET_FROM_STRING \
6604 ? IT_STRING_CHARPOS (*it) == 0 \
6608 /* Move iterator IT to a specified buffer or X position within one
6609 line on the display without producing glyphs.
6611 OP should be a bit mask including some or all of these bits:
6612 MOVE_TO_X: Stop on reaching x-position TO_X.
6613 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6614 Regardless of OP's value, stop in reaching the end of the display line.
6616 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6617 This means, in particular, that TO_X includes window's horizontal
6620 The return value has several possible values that
6621 say what condition caused the scan to stop:
6623 MOVE_POS_MATCH_OR_ZV
6624 - when TO_POS or ZV was reached.
6627 -when TO_X was reached before TO_POS or ZV were reached.
6630 - when we reached the end of the display area and the line must
6634 - when we reached the end of the display area and the line is
6638 - when we stopped at a line end, i.e. a newline or a CR and selective
6641 static enum move_it_result
6642 move_it_in_display_line_to (struct it
*it
,
6643 EMACS_INT to_charpos
, int to_x
,
6644 enum move_operation_enum op
)
6646 enum move_it_result result
= MOVE_UNDEFINED
;
6647 struct glyph_row
*saved_glyph_row
;
6648 struct it wrap_it
, atpos_it
, atx_it
;
6651 /* Don't produce glyphs in produce_glyphs. */
6652 saved_glyph_row
= it
->glyph_row
;
6653 it
->glyph_row
= NULL
;
6655 /* Use wrap_it to save a copy of IT wherever a word wrap could
6656 occur. Use atpos_it to save a copy of IT at the desired buffer
6657 position, if found, so that we can scan ahead and check if the
6658 word later overshoots the window edge. Use atx_it similarly, for
6664 #define BUFFER_POS_REACHED_P() \
6665 ((op & MOVE_TO_POS) != 0 \
6666 && BUFFERP (it->object) \
6667 && IT_CHARPOS (*it) >= to_charpos \
6668 && (it->method == GET_FROM_BUFFER \
6669 || (it->method == GET_FROM_DISPLAY_VECTOR \
6670 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6672 /* If there's a line-/wrap-prefix, handle it. */
6673 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6674 && it
->current_y
< it
->last_visible_y
)
6675 handle_line_prefix (it
);
6679 int x
, i
, ascent
= 0, descent
= 0;
6681 /* Utility macro to reset an iterator with x, ascent, and descent. */
6682 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6683 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6684 (IT)->max_descent = descent)
6686 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6688 if ((op
& MOVE_TO_POS
) != 0
6689 && BUFFERP (it
->object
)
6690 && it
->method
== GET_FROM_BUFFER
6691 && IT_CHARPOS (*it
) > to_charpos
)
6693 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6695 result
= MOVE_POS_MATCH_OR_ZV
;
6698 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6699 /* If wrap_it is valid, the current position might be in a
6700 word that is wrapped. So, save the iterator in
6701 atpos_it and continue to see if wrapping happens. */
6705 /* Stop when ZV reached.
6706 We used to stop here when TO_CHARPOS reached as well, but that is
6707 too soon if this glyph does not fit on this line. So we handle it
6708 explicitly below. */
6709 if (!get_next_display_element (it
))
6711 result
= MOVE_POS_MATCH_OR_ZV
;
6715 if (it
->line_wrap
== TRUNCATE
)
6717 if (BUFFER_POS_REACHED_P ())
6719 result
= MOVE_POS_MATCH_OR_ZV
;
6725 if (it
->line_wrap
== WORD_WRAP
)
6727 if (IT_DISPLAYING_WHITESPACE (it
))
6731 /* We have reached a glyph that follows one or more
6732 whitespace characters. If the position is
6733 already found, we are done. */
6734 if (atpos_it
.sp
>= 0)
6737 result
= MOVE_POS_MATCH_OR_ZV
;
6743 result
= MOVE_X_REACHED
;
6746 /* Otherwise, we can wrap here. */
6753 /* Remember the line height for the current line, in case
6754 the next element doesn't fit on the line. */
6755 ascent
= it
->max_ascent
;
6756 descent
= it
->max_descent
;
6758 /* The call to produce_glyphs will get the metrics of the
6759 display element IT is loaded with. Record the x-position
6760 before this display element, in case it doesn't fit on the
6764 PRODUCE_GLYPHS (it
);
6766 if (it
->area
!= TEXT_AREA
)
6768 set_iterator_to_next (it
, 1);
6772 /* The number of glyphs we get back in IT->nglyphs will normally
6773 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6774 character on a terminal frame, or (iii) a line end. For the
6775 second case, IT->nglyphs - 1 padding glyphs will be present.
6776 (On X frames, there is only one glyph produced for a
6777 composite character.)
6779 The behavior implemented below means, for continuation lines,
6780 that as many spaces of a TAB as fit on the current line are
6781 displayed there. For terminal frames, as many glyphs of a
6782 multi-glyph character are displayed in the current line, too.
6783 This is what the old redisplay code did, and we keep it that
6784 way. Under X, the whole shape of a complex character must
6785 fit on the line or it will be completely displayed in the
6788 Note that both for tabs and padding glyphs, all glyphs have
6792 /* More than one glyph or glyph doesn't fit on line. All
6793 glyphs have the same width. */
6794 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6796 int x_before_this_char
= x
;
6797 int hpos_before_this_char
= it
->hpos
;
6799 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6801 new_x
= x
+ single_glyph_width
;
6803 /* We want to leave anything reaching TO_X to the caller. */
6804 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6806 if (BUFFER_POS_REACHED_P ())
6808 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6809 goto buffer_pos_reached
;
6810 if (atpos_it
.sp
< 0)
6813 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6818 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6821 result
= MOVE_X_REACHED
;
6827 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6832 if (/* Lines are continued. */
6833 it
->line_wrap
!= TRUNCATE
6834 && (/* And glyph doesn't fit on the line. */
6835 new_x
> it
->last_visible_x
6836 /* Or it fits exactly and we're on a window
6838 || (new_x
== it
->last_visible_x
6839 && FRAME_WINDOW_P (it
->f
))))
6841 if (/* IT->hpos == 0 means the very first glyph
6842 doesn't fit on the line, e.g. a wide image. */
6844 || (new_x
== it
->last_visible_x
6845 && FRAME_WINDOW_P (it
->f
)))
6848 it
->current_x
= new_x
;
6850 /* The character's last glyph just barely fits
6852 if (i
== it
->nglyphs
- 1)
6854 /* If this is the destination position,
6855 return a position *before* it in this row,
6856 now that we know it fits in this row. */
6857 if (BUFFER_POS_REACHED_P ())
6859 if (it
->line_wrap
!= WORD_WRAP
6862 it
->hpos
= hpos_before_this_char
;
6863 it
->current_x
= x_before_this_char
;
6864 result
= MOVE_POS_MATCH_OR_ZV
;
6867 if (it
->line_wrap
== WORD_WRAP
6871 atpos_it
.current_x
= x_before_this_char
;
6872 atpos_it
.hpos
= hpos_before_this_char
;
6876 set_iterator_to_next (it
, 1);
6877 /* On graphical terminals, newlines may
6878 "overflow" into the fringe if
6879 overflow-newline-into-fringe is non-nil.
6880 On text-only terminals, newlines may
6881 overflow into the last glyph on the
6883 if (!FRAME_WINDOW_P (it
->f
)
6884 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6886 if (!get_next_display_element (it
))
6888 result
= MOVE_POS_MATCH_OR_ZV
;
6891 if (BUFFER_POS_REACHED_P ())
6893 if (ITERATOR_AT_END_OF_LINE_P (it
))
6894 result
= MOVE_POS_MATCH_OR_ZV
;
6896 result
= MOVE_LINE_CONTINUED
;
6899 if (ITERATOR_AT_END_OF_LINE_P (it
))
6901 result
= MOVE_NEWLINE_OR_CR
;
6908 IT_RESET_X_ASCENT_DESCENT (it
);
6910 if (wrap_it
.sp
>= 0)
6917 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6919 result
= MOVE_LINE_CONTINUED
;
6923 if (BUFFER_POS_REACHED_P ())
6925 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6926 goto buffer_pos_reached
;
6927 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6930 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6934 if (new_x
> it
->first_visible_x
)
6936 /* Glyph is visible. Increment number of glyphs that
6937 would be displayed. */
6942 if (result
!= MOVE_UNDEFINED
)
6945 else if (BUFFER_POS_REACHED_P ())
6948 IT_RESET_X_ASCENT_DESCENT (it
);
6949 result
= MOVE_POS_MATCH_OR_ZV
;
6952 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6954 /* Stop when TO_X specified and reached. This check is
6955 necessary here because of lines consisting of a line end,
6956 only. The line end will not produce any glyphs and we
6957 would never get MOVE_X_REACHED. */
6958 xassert (it
->nglyphs
== 0);
6959 result
= MOVE_X_REACHED
;
6963 /* Is this a line end? If yes, we're done. */
6964 if (ITERATOR_AT_END_OF_LINE_P (it
))
6966 result
= MOVE_NEWLINE_OR_CR
;
6970 /* The current display element has been consumed. Advance
6972 set_iterator_to_next (it
, 1);
6974 /* Stop if lines are truncated and IT's current x-position is
6975 past the right edge of the window now. */
6976 if (it
->line_wrap
== TRUNCATE
6977 && it
->current_x
>= it
->last_visible_x
)
6979 if (!FRAME_WINDOW_P (it
->f
)
6980 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6982 if (!get_next_display_element (it
)
6983 || BUFFER_POS_REACHED_P ())
6985 result
= MOVE_POS_MATCH_OR_ZV
;
6988 if (ITERATOR_AT_END_OF_LINE_P (it
))
6990 result
= MOVE_NEWLINE_OR_CR
;
6994 result
= MOVE_LINE_TRUNCATED
;
6997 #undef IT_RESET_X_ASCENT_DESCENT
7000 #undef BUFFER_POS_REACHED_P
7002 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7003 restore the saved iterator. */
7004 if (atpos_it
.sp
>= 0)
7006 else if (atx_it
.sp
>= 0)
7011 /* Restore the iterator settings altered at the beginning of this
7013 it
->glyph_row
= saved_glyph_row
;
7017 /* For external use. */
7019 move_it_in_display_line (struct it
*it
,
7020 EMACS_INT to_charpos
, int to_x
,
7021 enum move_operation_enum op
)
7023 if (it
->line_wrap
== WORD_WRAP
7024 && (op
& MOVE_TO_X
))
7026 struct it save_it
= *it
;
7027 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7028 /* When word-wrap is on, TO_X may lie past the end
7029 of a wrapped line. Then it->current is the
7030 character on the next line, so backtrack to the
7031 space before the wrap point. */
7032 if (skip
== MOVE_LINE_CONTINUED
)
7034 int prev_x
= max (it
->current_x
- 1, 0);
7036 move_it_in_display_line_to
7037 (it
, -1, prev_x
, MOVE_TO_X
);
7041 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7045 /* Move IT forward until it satisfies one or more of the criteria in
7046 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7048 OP is a bit-mask that specifies where to stop, and in particular,
7049 which of those four position arguments makes a difference. See the
7050 description of enum move_operation_enum.
7052 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7053 screen line, this function will set IT to the next position >
7057 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7059 int to_charpos
, to_x
, to_y
, to_vpos
;
7062 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7063 int line_height
, line_start_x
= 0, reached
= 0;
7067 if (op
& MOVE_TO_VPOS
)
7069 /* If no TO_CHARPOS and no TO_X specified, stop at the
7070 start of the line TO_VPOS. */
7071 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7073 if (it
->vpos
== to_vpos
)
7079 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7083 /* TO_VPOS >= 0 means stop at TO_X in the line at
7084 TO_VPOS, or at TO_POS, whichever comes first. */
7085 if (it
->vpos
== to_vpos
)
7091 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7093 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7098 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7100 /* We have reached TO_X but not in the line we want. */
7101 skip
= move_it_in_display_line_to (it
, to_charpos
,
7103 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7111 else if (op
& MOVE_TO_Y
)
7113 struct it it_backup
;
7115 if (it
->line_wrap
== WORD_WRAP
)
7118 /* TO_Y specified means stop at TO_X in the line containing
7119 TO_Y---or at TO_CHARPOS if this is reached first. The
7120 problem is that we can't really tell whether the line
7121 contains TO_Y before we have completely scanned it, and
7122 this may skip past TO_X. What we do is to first scan to
7125 If TO_X is not specified, use a TO_X of zero. The reason
7126 is to make the outcome of this function more predictable.
7127 If we didn't use TO_X == 0, we would stop at the end of
7128 the line which is probably not what a caller would expect
7130 skip
= move_it_in_display_line_to
7131 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7132 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7134 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7135 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7137 else if (skip
== MOVE_X_REACHED
)
7139 /* If TO_X was reached, we want to know whether TO_Y is
7140 in the line. We know this is the case if the already
7141 scanned glyphs make the line tall enough. Otherwise,
7142 we must check by scanning the rest of the line. */
7143 line_height
= it
->max_ascent
+ it
->max_descent
;
7144 if (to_y
>= it
->current_y
7145 && to_y
< it
->current_y
+ line_height
)
7151 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7152 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7154 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7155 line_height
= it
->max_ascent
+ it
->max_descent
;
7156 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7158 if (to_y
>= it
->current_y
7159 && to_y
< it
->current_y
+ line_height
)
7161 /* If TO_Y is in this line and TO_X was reached
7162 above, we scanned too far. We have to restore
7163 IT's settings to the ones before skipping. */
7170 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7176 /* Check whether TO_Y is in this line. */
7177 line_height
= it
->max_ascent
+ it
->max_descent
;
7178 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7180 if (to_y
>= it
->current_y
7181 && to_y
< it
->current_y
+ line_height
)
7183 /* When word-wrap is on, TO_X may lie past the end
7184 of a wrapped line. Then it->current is the
7185 character on the next line, so backtrack to the
7186 space before the wrap point. */
7187 if (skip
== MOVE_LINE_CONTINUED
7188 && it
->line_wrap
== WORD_WRAP
)
7190 int prev_x
= max (it
->current_x
- 1, 0);
7192 skip
= move_it_in_display_line_to
7193 (it
, -1, prev_x
, MOVE_TO_X
);
7202 else if (BUFFERP (it
->object
)
7203 && (it
->method
== GET_FROM_BUFFER
7204 || it
->method
== GET_FROM_STRETCH
)
7205 && IT_CHARPOS (*it
) >= to_charpos
)
7206 skip
= MOVE_POS_MATCH_OR_ZV
;
7208 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7212 case MOVE_POS_MATCH_OR_ZV
:
7216 case MOVE_NEWLINE_OR_CR
:
7217 set_iterator_to_next (it
, 1);
7218 it
->continuation_lines_width
= 0;
7221 case MOVE_LINE_TRUNCATED
:
7222 it
->continuation_lines_width
= 0;
7223 reseat_at_next_visible_line_start (it
, 0);
7224 if ((op
& MOVE_TO_POS
) != 0
7225 && IT_CHARPOS (*it
) > to_charpos
)
7232 case MOVE_LINE_CONTINUED
:
7233 /* For continued lines ending in a tab, some of the glyphs
7234 associated with the tab are displayed on the current
7235 line. Since it->current_x does not include these glyphs,
7236 we use it->last_visible_x instead. */
7239 it
->continuation_lines_width
+= it
->last_visible_x
;
7240 /* When moving by vpos, ensure that the iterator really
7241 advances to the next line (bug#847, bug#969). Fixme:
7242 do we need to do this in other circumstances? */
7243 if (it
->current_x
!= it
->last_visible_x
7244 && (op
& MOVE_TO_VPOS
)
7245 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7247 line_start_x
= it
->current_x
+ it
->pixel_width
7248 - it
->last_visible_x
;
7249 set_iterator_to_next (it
, 0);
7253 it
->continuation_lines_width
+= it
->current_x
;
7260 /* Reset/increment for the next run. */
7261 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7262 it
->current_x
= line_start_x
;
7265 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7267 last_height
= it
->max_ascent
+ it
->max_descent
;
7268 last_max_ascent
= it
->max_ascent
;
7269 it
->max_ascent
= it
->max_descent
= 0;
7274 /* On text terminals, we may stop at the end of a line in the middle
7275 of a multi-character glyph. If the glyph itself is continued,
7276 i.e. it is actually displayed on the next line, don't treat this
7277 stopping point as valid; move to the next line instead (unless
7278 that brings us offscreen). */
7279 if (!FRAME_WINDOW_P (it
->f
)
7281 && IT_CHARPOS (*it
) == to_charpos
7282 && it
->what
== IT_CHARACTER
7284 && it
->line_wrap
== WINDOW_WRAP
7285 && it
->current_x
== it
->last_visible_x
- 1
7288 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7290 it
->continuation_lines_width
+= it
->current_x
;
7291 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7292 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7294 last_height
= it
->max_ascent
+ it
->max_descent
;
7295 last_max_ascent
= it
->max_ascent
;
7298 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7302 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7304 If DY > 0, move IT backward at least that many pixels. DY = 0
7305 means move IT backward to the preceding line start or BEGV. This
7306 function may move over more than DY pixels if IT->current_y - DY
7307 ends up in the middle of a line; in this case IT->current_y will be
7308 set to the top of the line moved to. */
7311 move_it_vertically_backward (it
, dy
)
7322 start_pos
= IT_CHARPOS (*it
);
7324 /* Estimate how many newlines we must move back. */
7325 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7327 /* Set the iterator's position that many lines back. */
7328 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7329 back_to_previous_visible_line_start (it
);
7331 /* Reseat the iterator here. When moving backward, we don't want
7332 reseat to skip forward over invisible text, set up the iterator
7333 to deliver from overlay strings at the new position etc. So,
7334 use reseat_1 here. */
7335 reseat_1 (it
, it
->current
.pos
, 1);
7337 /* We are now surely at a line start. */
7338 it
->current_x
= it
->hpos
= 0;
7339 it
->continuation_lines_width
= 0;
7341 /* Move forward and see what y-distance we moved. First move to the
7342 start of the next line so that we get its height. We need this
7343 height to be able to tell whether we reached the specified
7346 it2
.max_ascent
= it2
.max_descent
= 0;
7349 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7350 MOVE_TO_POS
| MOVE_TO_VPOS
);
7352 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7353 xassert (IT_CHARPOS (*it
) >= BEGV
);
7356 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7357 xassert (IT_CHARPOS (*it
) >= BEGV
);
7358 /* H is the actual vertical distance from the position in *IT
7359 and the starting position. */
7360 h
= it2
.current_y
- it
->current_y
;
7361 /* NLINES is the distance in number of lines. */
7362 nlines
= it2
.vpos
- it
->vpos
;
7364 /* Correct IT's y and vpos position
7365 so that they are relative to the starting point. */
7371 /* DY == 0 means move to the start of the screen line. The
7372 value of nlines is > 0 if continuation lines were involved. */
7374 move_it_by_lines (it
, nlines
, 1);
7378 /* The y-position we try to reach, relative to *IT.
7379 Note that H has been subtracted in front of the if-statement. */
7380 int target_y
= it
->current_y
+ h
- dy
;
7381 int y0
= it3
.current_y
;
7382 int y1
= line_bottom_y (&it3
);
7383 int line_height
= y1
- y0
;
7385 /* If we did not reach target_y, try to move further backward if
7386 we can. If we moved too far backward, try to move forward. */
7387 if (target_y
< it
->current_y
7388 /* This is heuristic. In a window that's 3 lines high, with
7389 a line height of 13 pixels each, recentering with point
7390 on the bottom line will try to move -39/2 = 19 pixels
7391 backward. Try to avoid moving into the first line. */
7392 && (it
->current_y
- target_y
7393 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7394 && IT_CHARPOS (*it
) > BEGV
)
7396 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7397 target_y
- it
->current_y
));
7398 dy
= it
->current_y
- target_y
;
7399 goto move_further_back
;
7401 else if (target_y
>= it
->current_y
+ line_height
7402 && IT_CHARPOS (*it
) < ZV
)
7404 /* Should move forward by at least one line, maybe more.
7406 Note: Calling move_it_by_lines can be expensive on
7407 terminal frames, where compute_motion is used (via
7408 vmotion) to do the job, when there are very long lines
7409 and truncate-lines is nil. That's the reason for
7410 treating terminal frames specially here. */
7412 if (!FRAME_WINDOW_P (it
->f
))
7413 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7418 move_it_by_lines (it
, 1, 1);
7420 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7427 /* Move IT by a specified amount of pixel lines DY. DY negative means
7428 move backwards. DY = 0 means move to start of screen line. At the
7429 end, IT will be on the start of a screen line. */
7432 move_it_vertically (it
, dy
)
7437 move_it_vertically_backward (it
, -dy
);
7440 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7441 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7442 MOVE_TO_POS
| MOVE_TO_Y
);
7443 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7445 /* If buffer ends in ZV without a newline, move to the start of
7446 the line to satisfy the post-condition. */
7447 if (IT_CHARPOS (*it
) == ZV
7449 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7450 move_it_by_lines (it
, 0, 0);
7455 /* Move iterator IT past the end of the text line it is in. */
7458 move_it_past_eol (it
)
7461 enum move_it_result rc
;
7463 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7464 if (rc
== MOVE_NEWLINE_OR_CR
)
7465 set_iterator_to_next (it
, 0);
7469 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7470 negative means move up. DVPOS == 0 means move to the start of the
7471 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7472 NEED_Y_P is zero, IT->current_y will be left unchanged.
7474 Further optimization ideas: If we would know that IT->f doesn't use
7475 a face with proportional font, we could be faster for
7476 truncate-lines nil. */
7479 move_it_by_lines (it
, dvpos
, need_y_p
)
7481 int dvpos
, need_y_p
;
7483 struct position pos
;
7485 /* The commented-out optimization uses vmotion on terminals. This
7486 gives bad results, because elements like it->what, on which
7487 callers such as pos_visible_p rely, aren't updated. */
7488 /* if (!FRAME_WINDOW_P (it->f))
7490 struct text_pos textpos;
7492 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7493 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7494 reseat (it, textpos, 1);
7495 it->vpos += pos.vpos;
7496 it->current_y += pos.vpos;
7502 /* DVPOS == 0 means move to the start of the screen line. */
7503 move_it_vertically_backward (it
, 0);
7504 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7505 /* Let next call to line_bottom_y calculate real line height */
7510 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7511 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7512 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7517 int start_charpos
, i
;
7519 /* Start at the beginning of the screen line containing IT's
7520 position. This may actually move vertically backwards,
7521 in case of overlays, so adjust dvpos accordingly. */
7523 move_it_vertically_backward (it
, 0);
7526 /* Go back -DVPOS visible lines and reseat the iterator there. */
7527 start_charpos
= IT_CHARPOS (*it
);
7528 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7529 back_to_previous_visible_line_start (it
);
7530 reseat (it
, it
->current
.pos
, 1);
7532 /* Move further back if we end up in a string or an image. */
7533 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7535 /* First try to move to start of display line. */
7537 move_it_vertically_backward (it
, 0);
7539 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7541 /* If start of line is still in string or image,
7542 move further back. */
7543 back_to_previous_visible_line_start (it
);
7544 reseat (it
, it
->current
.pos
, 1);
7548 it
->current_x
= it
->hpos
= 0;
7550 /* Above call may have moved too far if continuation lines
7551 are involved. Scan forward and see if it did. */
7553 it2
.vpos
= it2
.current_y
= 0;
7554 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7555 it
->vpos
-= it2
.vpos
;
7556 it
->current_y
-= it2
.current_y
;
7557 it
->current_x
= it
->hpos
= 0;
7559 /* If we moved too far back, move IT some lines forward. */
7560 if (it2
.vpos
> -dvpos
)
7562 int delta
= it2
.vpos
+ dvpos
;
7564 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7565 /* Move back again if we got too far ahead. */
7566 if (IT_CHARPOS (*it
) >= start_charpos
)
7572 /* Return 1 if IT points into the middle of a display vector. */
7575 in_display_vector_p (it
)
7578 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7579 && it
->current
.dpvec_index
> 0
7580 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7584 /***********************************************************************
7586 ***********************************************************************/
7589 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7593 add_to_log (format
, arg1
, arg2
)
7595 Lisp_Object arg1
, arg2
;
7597 Lisp_Object args
[3];
7598 Lisp_Object msg
, fmt
;
7601 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7604 /* Do nothing if called asynchronously. Inserting text into
7605 a buffer may call after-change-functions and alike and
7606 that would means running Lisp asynchronously. */
7607 if (handling_signal
)
7611 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7613 args
[0] = fmt
= build_string (format
);
7616 msg
= Fformat (3, args
);
7618 len
= SBYTES (msg
) + 1;
7619 SAFE_ALLOCA (buffer
, char *, len
);
7620 bcopy (SDATA (msg
), buffer
, len
);
7622 message_dolog (buffer
, len
- 1, 1, 0);
7629 /* Output a newline in the *Messages* buffer if "needs" one. */
7632 message_log_maybe_newline ()
7634 if (message_log_need_newline
)
7635 message_dolog ("", 0, 1, 0);
7639 /* Add a string M of length NBYTES to the message log, optionally
7640 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7641 nonzero, means interpret the contents of M as multibyte. This
7642 function calls low-level routines in order to bypass text property
7643 hooks, etc. which might not be safe to run.
7645 This may GC (insert may run before/after change hooks),
7646 so the buffer M must NOT point to a Lisp string. */
7649 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7651 int nbytes
, nlflag
, multibyte
;
7653 if (!NILP (Vmemory_full
))
7656 if (!NILP (Vmessage_log_max
))
7658 struct buffer
*oldbuf
;
7659 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7660 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7661 int point_at_end
= 0;
7663 Lisp_Object old_deactivate_mark
, tem
;
7664 struct gcpro gcpro1
;
7666 old_deactivate_mark
= Vdeactivate_mark
;
7667 oldbuf
= current_buffer
;
7668 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7669 current_buffer
->undo_list
= Qt
;
7671 oldpoint
= message_dolog_marker1
;
7672 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7673 oldbegv
= message_dolog_marker2
;
7674 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7675 oldzv
= message_dolog_marker3
;
7676 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7677 GCPRO1 (old_deactivate_mark
);
7685 BEGV_BYTE
= BEG_BYTE
;
7688 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7690 /* Insert the string--maybe converting multibyte to single byte
7691 or vice versa, so that all the text fits the buffer. */
7693 && NILP (current_buffer
->enable_multibyte_characters
))
7695 int i
, c
, char_bytes
;
7696 unsigned char work
[1];
7698 /* Convert a multibyte string to single-byte
7699 for the *Message* buffer. */
7700 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7702 c
= string_char_and_length (m
+ i
, &char_bytes
);
7703 work
[0] = (ASCII_CHAR_P (c
)
7705 : multibyte_char_to_unibyte (c
, Qnil
));
7706 insert_1_both (work
, 1, 1, 1, 0, 0);
7709 else if (! multibyte
7710 && ! NILP (current_buffer
->enable_multibyte_characters
))
7712 int i
, c
, char_bytes
;
7713 unsigned char *msg
= (unsigned char *) m
;
7714 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7715 /* Convert a single-byte string to multibyte
7716 for the *Message* buffer. */
7717 for (i
= 0; i
< nbytes
; i
++)
7720 MAKE_CHAR_MULTIBYTE (c
);
7721 char_bytes
= CHAR_STRING (c
, str
);
7722 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7726 insert_1 (m
, nbytes
, 1, 0, 0);
7730 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7731 insert_1 ("\n", 1, 1, 0, 0);
7733 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7735 this_bol_byte
= PT_BYTE
;
7737 /* See if this line duplicates the previous one.
7738 If so, combine duplicates. */
7741 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7743 prev_bol_byte
= PT_BYTE
;
7745 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7746 this_bol
, this_bol_byte
);
7749 del_range_both (prev_bol
, prev_bol_byte
,
7750 this_bol
, this_bol_byte
, 0);
7756 /* If you change this format, don't forget to also
7757 change message_log_check_duplicate. */
7758 sprintf (dupstr
, " [%d times]", dup
);
7759 duplen
= strlen (dupstr
);
7760 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7761 insert_1 (dupstr
, duplen
, 1, 0, 1);
7766 /* If we have more than the desired maximum number of lines
7767 in the *Messages* buffer now, delete the oldest ones.
7768 This is safe because we don't have undo in this buffer. */
7770 if (NATNUMP (Vmessage_log_max
))
7772 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7773 -XFASTINT (Vmessage_log_max
) - 1, 0);
7774 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7777 BEGV
= XMARKER (oldbegv
)->charpos
;
7778 BEGV_BYTE
= marker_byte_position (oldbegv
);
7787 ZV
= XMARKER (oldzv
)->charpos
;
7788 ZV_BYTE
= marker_byte_position (oldzv
);
7792 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7794 /* We can't do Fgoto_char (oldpoint) because it will run some
7796 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7797 XMARKER (oldpoint
)->bytepos
);
7800 unchain_marker (XMARKER (oldpoint
));
7801 unchain_marker (XMARKER (oldbegv
));
7802 unchain_marker (XMARKER (oldzv
));
7804 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7805 set_buffer_internal (oldbuf
);
7807 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7808 message_log_need_newline
= !nlflag
;
7809 Vdeactivate_mark
= old_deactivate_mark
;
7814 /* We are at the end of the buffer after just having inserted a newline.
7815 (Note: We depend on the fact we won't be crossing the gap.)
7816 Check to see if the most recent message looks a lot like the previous one.
7817 Return 0 if different, 1 if the new one should just replace it, or a
7818 value N > 1 if we should also append " [N times]". */
7821 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7822 int prev_bol
, this_bol
;
7823 int prev_bol_byte
, this_bol_byte
;
7826 int len
= Z_BYTE
- 1 - this_bol_byte
;
7828 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7829 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7831 for (i
= 0; i
< len
; i
++)
7833 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7841 if (*p1
++ == ' ' && *p1
++ == '[')
7844 while (*p1
>= '0' && *p1
<= '9')
7845 n
= n
* 10 + *p1
++ - '0';
7846 if (strncmp (p1
, " times]\n", 8) == 0)
7853 /* Display an echo area message M with a specified length of NBYTES
7854 bytes. The string may include null characters. If M is 0, clear
7855 out any existing message, and let the mini-buffer text show
7858 This may GC, so the buffer M must NOT point to a Lisp string. */
7861 message2 (m
, nbytes
, multibyte
)
7866 /* First flush out any partial line written with print. */
7867 message_log_maybe_newline ();
7869 message_dolog (m
, nbytes
, 1, multibyte
);
7870 message2_nolog (m
, nbytes
, multibyte
);
7874 /* The non-logging counterpart of message2. */
7877 message2_nolog (m
, nbytes
, multibyte
)
7879 int nbytes
, multibyte
;
7881 struct frame
*sf
= SELECTED_FRAME ();
7882 message_enable_multibyte
= multibyte
;
7884 if (FRAME_INITIAL_P (sf
))
7886 if (noninteractive_need_newline
)
7887 putc ('\n', stderr
);
7888 noninteractive_need_newline
= 0;
7890 fwrite (m
, nbytes
, 1, stderr
);
7891 if (cursor_in_echo_area
== 0)
7892 fprintf (stderr
, "\n");
7895 /* A null message buffer means that the frame hasn't really been
7896 initialized yet. Error messages get reported properly by
7897 cmd_error, so this must be just an informative message; toss it. */
7898 else if (INTERACTIVE
7899 && sf
->glyphs_initialized_p
7900 && FRAME_MESSAGE_BUF (sf
))
7902 Lisp_Object mini_window
;
7905 /* Get the frame containing the mini-buffer
7906 that the selected frame is using. */
7907 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7908 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7910 FRAME_SAMPLE_VISIBILITY (f
);
7911 if (FRAME_VISIBLE_P (sf
)
7912 && ! FRAME_VISIBLE_P (f
))
7913 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7917 set_message (m
, Qnil
, nbytes
, multibyte
);
7918 if (minibuffer_auto_raise
)
7919 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7922 clear_message (1, 1);
7924 do_pending_window_change (0);
7925 echo_area_display (1);
7926 do_pending_window_change (0);
7927 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7928 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7933 /* Display an echo area message M with a specified length of NBYTES
7934 bytes. The string may include null characters. If M is not a
7935 string, clear out any existing message, and let the mini-buffer
7938 This function cancels echoing. */
7941 message3 (m
, nbytes
, multibyte
)
7946 struct gcpro gcpro1
;
7949 clear_message (1,1);
7952 /* First flush out any partial line written with print. */
7953 message_log_maybe_newline ();
7959 SAFE_ALLOCA (buffer
, char *, nbytes
);
7960 bcopy (SDATA (m
), buffer
, nbytes
);
7961 message_dolog (buffer
, nbytes
, 1, multibyte
);
7964 message3_nolog (m
, nbytes
, multibyte
);
7970 /* The non-logging version of message3.
7971 This does not cancel echoing, because it is used for echoing.
7972 Perhaps we need to make a separate function for echoing
7973 and make this cancel echoing. */
7976 message3_nolog (m
, nbytes
, multibyte
)
7978 int nbytes
, multibyte
;
7980 struct frame
*sf
= SELECTED_FRAME ();
7981 message_enable_multibyte
= multibyte
;
7983 if (FRAME_INITIAL_P (sf
))
7985 if (noninteractive_need_newline
)
7986 putc ('\n', stderr
);
7987 noninteractive_need_newline
= 0;
7989 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7990 if (cursor_in_echo_area
== 0)
7991 fprintf (stderr
, "\n");
7994 /* A null message buffer means that the frame hasn't really been
7995 initialized yet. Error messages get reported properly by
7996 cmd_error, so this must be just an informative message; toss it. */
7997 else if (INTERACTIVE
7998 && sf
->glyphs_initialized_p
7999 && FRAME_MESSAGE_BUF (sf
))
8001 Lisp_Object mini_window
;
8005 /* Get the frame containing the mini-buffer
8006 that the selected frame is using. */
8007 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8008 frame
= XWINDOW (mini_window
)->frame
;
8011 FRAME_SAMPLE_VISIBILITY (f
);
8012 if (FRAME_VISIBLE_P (sf
)
8013 && !FRAME_VISIBLE_P (f
))
8014 Fmake_frame_visible (frame
);
8016 if (STRINGP (m
) && SCHARS (m
) > 0)
8018 set_message (NULL
, m
, nbytes
, multibyte
);
8019 if (minibuffer_auto_raise
)
8020 Fraise_frame (frame
);
8021 /* Assume we are not echoing.
8022 (If we are, echo_now will override this.) */
8023 echo_message_buffer
= Qnil
;
8026 clear_message (1, 1);
8028 do_pending_window_change (0);
8029 echo_area_display (1);
8030 do_pending_window_change (0);
8031 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8032 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8037 /* Display a null-terminated echo area message M. If M is 0, clear
8038 out any existing message, and let the mini-buffer text show through.
8040 The buffer M must continue to exist until after the echo area gets
8041 cleared or some other message gets displayed there. Do not pass
8042 text that is stored in a Lisp string. Do not pass text in a buffer
8043 that was alloca'd. */
8049 message2 (m
, (m
? strlen (m
) : 0), 0);
8053 /* The non-logging counterpart of message1. */
8059 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8062 /* Display a message M which contains a single %s
8063 which gets replaced with STRING. */
8066 message_with_string (m
, string
, log
)
8071 CHECK_STRING (string
);
8077 if (noninteractive_need_newline
)
8078 putc ('\n', stderr
);
8079 noninteractive_need_newline
= 0;
8080 fprintf (stderr
, m
, SDATA (string
));
8081 if (!cursor_in_echo_area
)
8082 fprintf (stderr
, "\n");
8086 else if (INTERACTIVE
)
8088 /* The frame whose minibuffer we're going to display the message on.
8089 It may be larger than the selected frame, so we need
8090 to use its buffer, not the selected frame's buffer. */
8091 Lisp_Object mini_window
;
8092 struct frame
*f
, *sf
= SELECTED_FRAME ();
8094 /* Get the frame containing the minibuffer
8095 that the selected frame is using. */
8096 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8097 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8099 /* A null message buffer means that the frame hasn't really been
8100 initialized yet. Error messages get reported properly by
8101 cmd_error, so this must be just an informative message; toss it. */
8102 if (FRAME_MESSAGE_BUF (f
))
8104 Lisp_Object args
[2], message
;
8105 struct gcpro gcpro1
, gcpro2
;
8107 args
[0] = build_string (m
);
8108 args
[1] = message
= string
;
8109 GCPRO2 (args
[0], message
);
8112 message
= Fformat (2, args
);
8115 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8117 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8121 /* Print should start at the beginning of the message
8122 buffer next time. */
8123 message_buf_print
= 0;
8129 /* Dump an informative message to the minibuf. If M is 0, clear out
8130 any existing message, and let the mini-buffer text show through. */
8134 message (m
, a1
, a2
, a3
)
8136 EMACS_INT a1
, a2
, a3
;
8142 if (noninteractive_need_newline
)
8143 putc ('\n', stderr
);
8144 noninteractive_need_newline
= 0;
8145 fprintf (stderr
, m
, a1
, a2
, a3
);
8146 if (cursor_in_echo_area
== 0)
8147 fprintf (stderr
, "\n");
8151 else if (INTERACTIVE
)
8153 /* The frame whose mini-buffer we're going to display the message
8154 on. It may be larger than the selected frame, so we need to
8155 use its buffer, not the selected frame's buffer. */
8156 Lisp_Object mini_window
;
8157 struct frame
*f
, *sf
= SELECTED_FRAME ();
8159 /* Get the frame containing the mini-buffer
8160 that the selected frame is using. */
8161 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8162 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8164 /* A null message buffer means that the frame hasn't really been
8165 initialized yet. Error messages get reported properly by
8166 cmd_error, so this must be just an informative message; toss
8168 if (FRAME_MESSAGE_BUF (f
))
8179 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8180 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8182 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8183 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8185 #endif /* NO_ARG_ARRAY */
8187 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8192 /* Print should start at the beginning of the message
8193 buffer next time. */
8194 message_buf_print
= 0;
8200 /* The non-logging version of message. */
8203 message_nolog (m
, a1
, a2
, a3
)
8205 EMACS_INT a1
, a2
, a3
;
8207 Lisp_Object old_log_max
;
8208 old_log_max
= Vmessage_log_max
;
8209 Vmessage_log_max
= Qnil
;
8210 message (m
, a1
, a2
, a3
);
8211 Vmessage_log_max
= old_log_max
;
8215 /* Display the current message in the current mini-buffer. This is
8216 only called from error handlers in process.c, and is not time
8222 if (!NILP (echo_area_buffer
[0]))
8225 string
= Fcurrent_message ();
8226 message3 (string
, SBYTES (string
),
8227 !NILP (current_buffer
->enable_multibyte_characters
));
8232 /* Make sure echo area buffers in `echo_buffers' are live.
8233 If they aren't, make new ones. */
8236 ensure_echo_area_buffers ()
8240 for (i
= 0; i
< 2; ++i
)
8241 if (!BUFFERP (echo_buffer
[i
])
8242 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8245 Lisp_Object old_buffer
;
8248 old_buffer
= echo_buffer
[i
];
8249 sprintf (name
, " *Echo Area %d*", i
);
8250 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8251 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8252 /* to force word wrap in echo area -
8253 it was decided to postpone this*/
8254 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8256 for (j
= 0; j
< 2; ++j
)
8257 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8258 echo_area_buffer
[j
] = echo_buffer
[i
];
8263 /* Call FN with args A1..A4 with either the current or last displayed
8264 echo_area_buffer as current buffer.
8266 WHICH zero means use the current message buffer
8267 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8268 from echo_buffer[] and clear it.
8270 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8271 suitable buffer from echo_buffer[] and clear it.
8273 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8274 that the current message becomes the last displayed one, make
8275 choose a suitable buffer for echo_area_buffer[0], and clear it.
8277 Value is what FN returns. */
8280 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8283 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8289 int this_one
, the_other
, clear_buffer_p
, rc
;
8290 int count
= SPECPDL_INDEX ();
8292 /* If buffers aren't live, make new ones. */
8293 ensure_echo_area_buffers ();
8298 this_one
= 0, the_other
= 1;
8300 this_one
= 1, the_other
= 0;
8303 this_one
= 0, the_other
= 1;
8306 /* We need a fresh one in case the current echo buffer equals
8307 the one containing the last displayed echo area message. */
8308 if (!NILP (echo_area_buffer
[this_one
])
8309 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8310 echo_area_buffer
[this_one
] = Qnil
;
8313 /* Choose a suitable buffer from echo_buffer[] is we don't
8315 if (NILP (echo_area_buffer
[this_one
]))
8317 echo_area_buffer
[this_one
]
8318 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8319 ? echo_buffer
[the_other
]
8320 : echo_buffer
[this_one
]);
8324 buffer
= echo_area_buffer
[this_one
];
8326 /* Don't get confused by reusing the buffer used for echoing
8327 for a different purpose. */
8328 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8331 record_unwind_protect (unwind_with_echo_area_buffer
,
8332 with_echo_area_buffer_unwind_data (w
));
8334 /* Make the echo area buffer current. Note that for display
8335 purposes, it is not necessary that the displayed window's buffer
8336 == current_buffer, except for text property lookup. So, let's
8337 only set that buffer temporarily here without doing a full
8338 Fset_window_buffer. We must also change w->pointm, though,
8339 because otherwise an assertions in unshow_buffer fails, and Emacs
8341 set_buffer_internal_1 (XBUFFER (buffer
));
8345 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8348 current_buffer
->undo_list
= Qt
;
8349 current_buffer
->read_only
= Qnil
;
8350 specbind (Qinhibit_read_only
, Qt
);
8351 specbind (Qinhibit_modification_hooks
, Qt
);
8353 if (clear_buffer_p
&& Z
> BEG
)
8356 xassert (BEGV
>= BEG
);
8357 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8359 rc
= fn (a1
, a2
, a3
, a4
);
8361 xassert (BEGV
>= BEG
);
8362 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8364 unbind_to (count
, Qnil
);
8369 /* Save state that should be preserved around the call to the function
8370 FN called in with_echo_area_buffer. */
8373 with_echo_area_buffer_unwind_data (w
)
8377 Lisp_Object vector
, tmp
;
8379 /* Reduce consing by keeping one vector in
8380 Vwith_echo_area_save_vector. */
8381 vector
= Vwith_echo_area_save_vector
;
8382 Vwith_echo_area_save_vector
= Qnil
;
8385 vector
= Fmake_vector (make_number (7), Qnil
);
8387 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8388 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8389 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8393 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8394 ASET (vector
, i
, w
->buffer
); ++i
;
8395 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8396 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8401 for (; i
< end
; ++i
)
8402 ASET (vector
, i
, Qnil
);
8405 xassert (i
== ASIZE (vector
));
8410 /* Restore global state from VECTOR which was created by
8411 with_echo_area_buffer_unwind_data. */
8414 unwind_with_echo_area_buffer (vector
)
8417 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8418 Vdeactivate_mark
= AREF (vector
, 1);
8419 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8421 if (WINDOWP (AREF (vector
, 3)))
8424 Lisp_Object buffer
, charpos
, bytepos
;
8426 w
= XWINDOW (AREF (vector
, 3));
8427 buffer
= AREF (vector
, 4);
8428 charpos
= AREF (vector
, 5);
8429 bytepos
= AREF (vector
, 6);
8432 set_marker_both (w
->pointm
, buffer
,
8433 XFASTINT (charpos
), XFASTINT (bytepos
));
8436 Vwith_echo_area_save_vector
= vector
;
8441 /* Set up the echo area for use by print functions. MULTIBYTE_P
8442 non-zero means we will print multibyte. */
8445 setup_echo_area_for_printing (multibyte_p
)
8448 /* If we can't find an echo area any more, exit. */
8449 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8452 ensure_echo_area_buffers ();
8454 if (!message_buf_print
)
8456 /* A message has been output since the last time we printed.
8457 Choose a fresh echo area buffer. */
8458 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8459 echo_area_buffer
[0] = echo_buffer
[1];
8461 echo_area_buffer
[0] = echo_buffer
[0];
8463 /* Switch to that buffer and clear it. */
8464 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8465 current_buffer
->truncate_lines
= Qnil
;
8469 int count
= SPECPDL_INDEX ();
8470 specbind (Qinhibit_read_only
, Qt
);
8471 /* Note that undo recording is always disabled. */
8473 unbind_to (count
, Qnil
);
8475 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8477 /* Set up the buffer for the multibyteness we need. */
8479 != !NILP (current_buffer
->enable_multibyte_characters
))
8480 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8482 /* Raise the frame containing the echo area. */
8483 if (minibuffer_auto_raise
)
8485 struct frame
*sf
= SELECTED_FRAME ();
8486 Lisp_Object mini_window
;
8487 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8488 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8491 message_log_maybe_newline ();
8492 message_buf_print
= 1;
8496 if (NILP (echo_area_buffer
[0]))
8498 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8499 echo_area_buffer
[0] = echo_buffer
[1];
8501 echo_area_buffer
[0] = echo_buffer
[0];
8504 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8506 /* Someone switched buffers between print requests. */
8507 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8508 current_buffer
->truncate_lines
= Qnil
;
8514 /* Display an echo area message in window W. Value is non-zero if W's
8515 height is changed. If display_last_displayed_message_p is
8516 non-zero, display the message that was last displayed, otherwise
8517 display the current message. */
8520 display_echo_area (w
)
8523 int i
, no_message_p
, window_height_changed_p
, count
;
8525 /* Temporarily disable garbage collections while displaying the echo
8526 area. This is done because a GC can print a message itself.
8527 That message would modify the echo area buffer's contents while a
8528 redisplay of the buffer is going on, and seriously confuse
8530 count
= inhibit_garbage_collection ();
8532 /* If there is no message, we must call display_echo_area_1
8533 nevertheless because it resizes the window. But we will have to
8534 reset the echo_area_buffer in question to nil at the end because
8535 with_echo_area_buffer will sets it to an empty buffer. */
8536 i
= display_last_displayed_message_p
? 1 : 0;
8537 no_message_p
= NILP (echo_area_buffer
[i
]);
8539 window_height_changed_p
8540 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8541 display_echo_area_1
,
8542 (EMACS_INT
) w
, Qnil
, 0, 0);
8545 echo_area_buffer
[i
] = Qnil
;
8547 unbind_to (count
, Qnil
);
8548 return window_height_changed_p
;
8552 /* Helper for display_echo_area. Display the current buffer which
8553 contains the current echo area message in window W, a mini-window,
8554 a pointer to which is passed in A1. A2..A4 are currently not used.
8555 Change the height of W so that all of the message is displayed.
8556 Value is non-zero if height of W was changed. */
8559 display_echo_area_1 (a1
, a2
, a3
, a4
)
8564 struct window
*w
= (struct window
*) a1
;
8566 struct text_pos start
;
8567 int window_height_changed_p
= 0;
8569 /* Do this before displaying, so that we have a large enough glyph
8570 matrix for the display. If we can't get enough space for the
8571 whole text, display the last N lines. That works by setting w->start. */
8572 window_height_changed_p
= resize_mini_window (w
, 0);
8574 /* Use the starting position chosen by resize_mini_window. */
8575 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8578 clear_glyph_matrix (w
->desired_matrix
);
8579 XSETWINDOW (window
, w
);
8580 try_window (window
, start
, 0);
8582 return window_height_changed_p
;
8586 /* Resize the echo area window to exactly the size needed for the
8587 currently displayed message, if there is one. If a mini-buffer
8588 is active, don't shrink it. */
8591 resize_echo_area_exactly ()
8593 if (BUFFERP (echo_area_buffer
[0])
8594 && WINDOWP (echo_area_window
))
8596 struct window
*w
= XWINDOW (echo_area_window
);
8598 Lisp_Object resize_exactly
;
8600 if (minibuf_level
== 0)
8601 resize_exactly
= Qt
;
8603 resize_exactly
= Qnil
;
8605 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8606 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8609 ++windows_or_buffers_changed
;
8610 ++update_mode_lines
;
8611 redisplay_internal (0);
8617 /* Callback function for with_echo_area_buffer, when used from
8618 resize_echo_area_exactly. A1 contains a pointer to the window to
8619 resize, EXACTLY non-nil means resize the mini-window exactly to the
8620 size of the text displayed. A3 and A4 are not used. Value is what
8621 resize_mini_window returns. */
8624 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8626 Lisp_Object exactly
;
8629 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8633 /* Resize mini-window W to fit the size of its contents. EXACT_P
8634 means size the window exactly to the size needed. Otherwise, it's
8635 only enlarged until W's buffer is empty.
8637 Set W->start to the right place to begin display. If the whole
8638 contents fit, start at the beginning. Otherwise, start so as
8639 to make the end of the contents appear. This is particularly
8640 important for y-or-n-p, but seems desirable generally.
8642 Value is non-zero if the window height has been changed. */
8645 resize_mini_window (w
, exact_p
)
8649 struct frame
*f
= XFRAME (w
->frame
);
8650 int window_height_changed_p
= 0;
8652 xassert (MINI_WINDOW_P (w
));
8654 /* By default, start display at the beginning. */
8655 set_marker_both (w
->start
, w
->buffer
,
8656 BUF_BEGV (XBUFFER (w
->buffer
)),
8657 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8659 /* Don't resize windows while redisplaying a window; it would
8660 confuse redisplay functions when the size of the window they are
8661 displaying changes from under them. Such a resizing can happen,
8662 for instance, when which-func prints a long message while
8663 we are running fontification-functions. We're running these
8664 functions with safe_call which binds inhibit-redisplay to t. */
8665 if (!NILP (Vinhibit_redisplay
))
8668 /* Nil means don't try to resize. */
8669 if (NILP (Vresize_mini_windows
)
8670 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8673 if (!FRAME_MINIBUF_ONLY_P (f
))
8676 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8677 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8678 int height
, max_height
;
8679 int unit
= FRAME_LINE_HEIGHT (f
);
8680 struct text_pos start
;
8681 struct buffer
*old_current_buffer
= NULL
;
8683 if (current_buffer
!= XBUFFER (w
->buffer
))
8685 old_current_buffer
= current_buffer
;
8686 set_buffer_internal (XBUFFER (w
->buffer
));
8689 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8691 /* Compute the max. number of lines specified by the user. */
8692 if (FLOATP (Vmax_mini_window_height
))
8693 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8694 else if (INTEGERP (Vmax_mini_window_height
))
8695 max_height
= XINT (Vmax_mini_window_height
);
8697 max_height
= total_height
/ 4;
8699 /* Correct that max. height if it's bogus. */
8700 max_height
= max (1, max_height
);
8701 max_height
= min (total_height
, max_height
);
8703 /* Find out the height of the text in the window. */
8704 if (it
.line_wrap
== TRUNCATE
)
8709 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8710 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8711 height
= it
.current_y
+ last_height
;
8713 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8714 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8715 height
= (height
+ unit
- 1) / unit
;
8718 /* Compute a suitable window start. */
8719 if (height
> max_height
)
8721 height
= max_height
;
8722 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8723 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8724 start
= it
.current
.pos
;
8727 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8728 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8730 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8732 /* Let it grow only, until we display an empty message, in which
8733 case the window shrinks again. */
8734 if (height
> WINDOW_TOTAL_LINES (w
))
8736 int old_height
= WINDOW_TOTAL_LINES (w
);
8737 freeze_window_starts (f
, 1);
8738 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8739 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8741 else if (height
< WINDOW_TOTAL_LINES (w
)
8742 && (exact_p
|| BEGV
== ZV
))
8744 int old_height
= WINDOW_TOTAL_LINES (w
);
8745 freeze_window_starts (f
, 0);
8746 shrink_mini_window (w
);
8747 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8752 /* Always resize to exact size needed. */
8753 if (height
> WINDOW_TOTAL_LINES (w
))
8755 int old_height
= WINDOW_TOTAL_LINES (w
);
8756 freeze_window_starts (f
, 1);
8757 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8758 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8760 else if (height
< WINDOW_TOTAL_LINES (w
))
8762 int old_height
= WINDOW_TOTAL_LINES (w
);
8763 freeze_window_starts (f
, 0);
8764 shrink_mini_window (w
);
8768 freeze_window_starts (f
, 1);
8769 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8772 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8776 if (old_current_buffer
)
8777 set_buffer_internal (old_current_buffer
);
8780 return window_height_changed_p
;
8784 /* Value is the current message, a string, or nil if there is no
8792 if (!BUFFERP (echo_area_buffer
[0]))
8796 with_echo_area_buffer (0, 0, current_message_1
,
8797 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8799 echo_area_buffer
[0] = Qnil
;
8807 current_message_1 (a1
, a2
, a3
, a4
)
8812 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8815 *msg
= make_buffer_string (BEG
, Z
, 1);
8822 /* Push the current message on Vmessage_stack for later restauration
8823 by restore_message. Value is non-zero if the current message isn't
8824 empty. This is a relatively infrequent operation, so it's not
8825 worth optimizing. */
8831 msg
= current_message ();
8832 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8833 return STRINGP (msg
);
8837 /* Restore message display from the top of Vmessage_stack. */
8844 xassert (CONSP (Vmessage_stack
));
8845 msg
= XCAR (Vmessage_stack
);
8847 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8849 message3_nolog (msg
, 0, 0);
8853 /* Handler for record_unwind_protect calling pop_message. */
8856 pop_message_unwind (dummy
)
8863 /* Pop the top-most entry off Vmessage_stack. */
8868 xassert (CONSP (Vmessage_stack
));
8869 Vmessage_stack
= XCDR (Vmessage_stack
);
8873 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8874 exits. If the stack is not empty, we have a missing pop_message
8878 check_message_stack ()
8880 if (!NILP (Vmessage_stack
))
8885 /* Truncate to NCHARS what will be displayed in the echo area the next
8886 time we display it---but don't redisplay it now. */
8889 truncate_echo_area (nchars
)
8893 echo_area_buffer
[0] = Qnil
;
8894 /* A null message buffer means that the frame hasn't really been
8895 initialized yet. Error messages get reported properly by
8896 cmd_error, so this must be just an informative message; toss it. */
8897 else if (!noninteractive
8899 && !NILP (echo_area_buffer
[0]))
8901 struct frame
*sf
= SELECTED_FRAME ();
8902 if (FRAME_MESSAGE_BUF (sf
))
8903 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8908 /* Helper function for truncate_echo_area. Truncate the current
8909 message to at most NCHARS characters. */
8912 truncate_message_1 (nchars
, a2
, a3
, a4
)
8917 if (BEG
+ nchars
< Z
)
8918 del_range (BEG
+ nchars
, Z
);
8920 echo_area_buffer
[0] = Qnil
;
8925 /* Set the current message to a substring of S or STRING.
8927 If STRING is a Lisp string, set the message to the first NBYTES
8928 bytes from STRING. NBYTES zero means use the whole string. If
8929 STRING is multibyte, the message will be displayed multibyte.
8931 If S is not null, set the message to the first LEN bytes of S. LEN
8932 zero means use the whole string. MULTIBYTE_P non-zero means S is
8933 multibyte. Display the message multibyte in that case.
8935 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8936 to t before calling set_message_1 (which calls insert).
8940 set_message (s
, string
, nbytes
, multibyte_p
)
8943 int nbytes
, multibyte_p
;
8945 message_enable_multibyte
8946 = ((s
&& multibyte_p
)
8947 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8949 with_echo_area_buffer (0, -1, set_message_1
,
8950 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8951 message_buf_print
= 0;
8952 help_echo_showing_p
= 0;
8956 /* Helper function for set_message. Arguments have the same meaning
8957 as there, with A1 corresponding to S and A2 corresponding to STRING
8958 This function is called with the echo area buffer being
8962 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8965 EMACS_INT nbytes
, multibyte_p
;
8967 const char *s
= (const char *) a1
;
8968 Lisp_Object string
= a2
;
8970 /* Change multibyteness of the echo buffer appropriately. */
8971 if (message_enable_multibyte
8972 != !NILP (current_buffer
->enable_multibyte_characters
))
8973 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8975 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8977 /* Insert new message at BEG. */
8978 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8980 if (STRINGP (string
))
8985 nbytes
= SBYTES (string
);
8986 nchars
= string_byte_to_char (string
, nbytes
);
8988 /* This function takes care of single/multibyte conversion. We
8989 just have to ensure that the echo area buffer has the right
8990 setting of enable_multibyte_characters. */
8991 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8996 nbytes
= strlen (s
);
8998 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9000 /* Convert from multi-byte to single-byte. */
9002 unsigned char work
[1];
9004 /* Convert a multibyte string to single-byte. */
9005 for (i
= 0; i
< nbytes
; i
+= n
)
9007 c
= string_char_and_length (s
+ i
, &n
);
9008 work
[0] = (ASCII_CHAR_P (c
)
9010 : multibyte_char_to_unibyte (c
, Qnil
));
9011 insert_1_both (work
, 1, 1, 1, 0, 0);
9014 else if (!multibyte_p
9015 && !NILP (current_buffer
->enable_multibyte_characters
))
9017 /* Convert from single-byte to multi-byte. */
9019 const unsigned char *msg
= (const unsigned char *) s
;
9020 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9022 /* Convert a single-byte string to multibyte. */
9023 for (i
= 0; i
< nbytes
; i
++)
9026 MAKE_CHAR_MULTIBYTE (c
);
9027 n
= CHAR_STRING (c
, str
);
9028 insert_1_both (str
, 1, n
, 1, 0, 0);
9032 insert_1 (s
, nbytes
, 1, 0, 0);
9039 /* Clear messages. CURRENT_P non-zero means clear the current
9040 message. LAST_DISPLAYED_P non-zero means clear the message
9044 clear_message (current_p
, last_displayed_p
)
9045 int current_p
, last_displayed_p
;
9049 echo_area_buffer
[0] = Qnil
;
9050 message_cleared_p
= 1;
9053 if (last_displayed_p
)
9054 echo_area_buffer
[1] = Qnil
;
9056 message_buf_print
= 0;
9059 /* Clear garbaged frames.
9061 This function is used where the old redisplay called
9062 redraw_garbaged_frames which in turn called redraw_frame which in
9063 turn called clear_frame. The call to clear_frame was a source of
9064 flickering. I believe a clear_frame is not necessary. It should
9065 suffice in the new redisplay to invalidate all current matrices,
9066 and ensure a complete redisplay of all windows. */
9069 clear_garbaged_frames ()
9073 Lisp_Object tail
, frame
;
9074 int changed_count
= 0;
9076 FOR_EACH_FRAME (tail
, frame
)
9078 struct frame
*f
= XFRAME (frame
);
9080 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9084 Fredraw_frame (frame
);
9085 f
->force_flush_display_p
= 1;
9087 clear_current_matrices (f
);
9096 ++windows_or_buffers_changed
;
9101 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9102 is non-zero update selected_frame. Value is non-zero if the
9103 mini-windows height has been changed. */
9106 echo_area_display (update_frame_p
)
9109 Lisp_Object mini_window
;
9112 int window_height_changed_p
= 0;
9113 struct frame
*sf
= SELECTED_FRAME ();
9115 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9116 w
= XWINDOW (mini_window
);
9117 f
= XFRAME (WINDOW_FRAME (w
));
9119 /* Don't display if frame is invisible or not yet initialized. */
9120 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9123 #ifdef HAVE_WINDOW_SYSTEM
9124 /* When Emacs starts, selected_frame may be the initial terminal
9125 frame. If we let this through, a message would be displayed on
9127 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9129 #endif /* HAVE_WINDOW_SYSTEM */
9131 /* Redraw garbaged frames. */
9133 clear_garbaged_frames ();
9135 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9137 echo_area_window
= mini_window
;
9138 window_height_changed_p
= display_echo_area (w
);
9139 w
->must_be_updated_p
= 1;
9141 /* Update the display, unless called from redisplay_internal.
9142 Also don't update the screen during redisplay itself. The
9143 update will happen at the end of redisplay, and an update
9144 here could cause confusion. */
9145 if (update_frame_p
&& !redisplaying_p
)
9149 /* If the display update has been interrupted by pending
9150 input, update mode lines in the frame. Due to the
9151 pending input, it might have been that redisplay hasn't
9152 been called, so that mode lines above the echo area are
9153 garbaged. This looks odd, so we prevent it here. */
9154 if (!display_completed
)
9155 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9157 if (window_height_changed_p
9158 /* Don't do this if Emacs is shutting down. Redisplay
9159 needs to run hooks. */
9160 && !NILP (Vrun_hooks
))
9162 /* Must update other windows. Likewise as in other
9163 cases, don't let this update be interrupted by
9165 int count
= SPECPDL_INDEX ();
9166 specbind (Qredisplay_dont_pause
, Qt
);
9167 windows_or_buffers_changed
= 1;
9168 redisplay_internal (0);
9169 unbind_to (count
, Qnil
);
9171 else if (FRAME_WINDOW_P (f
) && n
== 0)
9173 /* Window configuration is the same as before.
9174 Can do with a display update of the echo area,
9175 unless we displayed some mode lines. */
9176 update_single_window (w
, 1);
9177 FRAME_RIF (f
)->flush_display (f
);
9180 update_frame (f
, 1, 1);
9182 /* If cursor is in the echo area, make sure that the next
9183 redisplay displays the minibuffer, so that the cursor will
9184 be replaced with what the minibuffer wants. */
9185 if (cursor_in_echo_area
)
9186 ++windows_or_buffers_changed
;
9189 else if (!EQ (mini_window
, selected_window
))
9190 windows_or_buffers_changed
++;
9192 /* Last displayed message is now the current message. */
9193 echo_area_buffer
[1] = echo_area_buffer
[0];
9194 /* Inform read_char that we're not echoing. */
9195 echo_message_buffer
= Qnil
;
9197 /* Prevent redisplay optimization in redisplay_internal by resetting
9198 this_line_start_pos. This is done because the mini-buffer now
9199 displays the message instead of its buffer text. */
9200 if (EQ (mini_window
, selected_window
))
9201 CHARPOS (this_line_start_pos
) = 0;
9203 return window_height_changed_p
;
9208 /***********************************************************************
9209 Mode Lines and Frame Titles
9210 ***********************************************************************/
9212 /* A buffer for constructing non-propertized mode-line strings and
9213 frame titles in it; allocated from the heap in init_xdisp and
9214 resized as needed in store_mode_line_noprop_char. */
9216 static char *mode_line_noprop_buf
;
9218 /* The buffer's end, and a current output position in it. */
9220 static char *mode_line_noprop_buf_end
;
9221 static char *mode_line_noprop_ptr
;
9223 #define MODE_LINE_NOPROP_LEN(start) \
9224 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9227 MODE_LINE_DISPLAY
= 0,
9233 /* Alist that caches the results of :propertize.
9234 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9235 static Lisp_Object mode_line_proptrans_alist
;
9237 /* List of strings making up the mode-line. */
9238 static Lisp_Object mode_line_string_list
;
9240 /* Base face property when building propertized mode line string. */
9241 static Lisp_Object mode_line_string_face
;
9242 static Lisp_Object mode_line_string_face_prop
;
9245 /* Unwind data for mode line strings */
9247 static Lisp_Object Vmode_line_unwind_vector
;
9250 format_mode_line_unwind_data (struct buffer
*obuf
,
9254 Lisp_Object vector
, tmp
;
9256 /* Reduce consing by keeping one vector in
9257 Vwith_echo_area_save_vector. */
9258 vector
= Vmode_line_unwind_vector
;
9259 Vmode_line_unwind_vector
= Qnil
;
9262 vector
= Fmake_vector (make_number (8), Qnil
);
9264 ASET (vector
, 0, make_number (mode_line_target
));
9265 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9266 ASET (vector
, 2, mode_line_string_list
);
9267 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9268 ASET (vector
, 4, mode_line_string_face
);
9269 ASET (vector
, 5, mode_line_string_face_prop
);
9272 XSETBUFFER (tmp
, obuf
);
9275 ASET (vector
, 6, tmp
);
9276 ASET (vector
, 7, owin
);
9282 unwind_format_mode_line (vector
)
9285 mode_line_target
= XINT (AREF (vector
, 0));
9286 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9287 mode_line_string_list
= AREF (vector
, 2);
9288 if (! EQ (AREF (vector
, 3), Qt
))
9289 mode_line_proptrans_alist
= AREF (vector
, 3);
9290 mode_line_string_face
= AREF (vector
, 4);
9291 mode_line_string_face_prop
= AREF (vector
, 5);
9293 if (!NILP (AREF (vector
, 7)))
9294 /* Select window before buffer, since it may change the buffer. */
9295 Fselect_window (AREF (vector
, 7), Qt
);
9297 if (!NILP (AREF (vector
, 6)))
9299 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9300 ASET (vector
, 6, Qnil
);
9303 Vmode_line_unwind_vector
= vector
;
9308 /* Store a single character C for the frame title in mode_line_noprop_buf.
9309 Re-allocate mode_line_noprop_buf if necessary. */
9313 store_mode_line_noprop_char (char c
)
9315 store_mode_line_noprop_char (c
)
9319 /* If output position has reached the end of the allocated buffer,
9320 double the buffer's size. */
9321 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9323 int len
= MODE_LINE_NOPROP_LEN (0);
9324 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9325 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9326 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9327 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9330 *mode_line_noprop_ptr
++ = c
;
9334 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9335 mode_line_noprop_ptr. STR is the string to store. Do not copy
9336 characters that yield more columns than PRECISION; PRECISION <= 0
9337 means copy the whole string. Pad with spaces until FIELD_WIDTH
9338 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9339 pad. Called from display_mode_element when it is used to build a
9343 store_mode_line_noprop (str
, field_width
, precision
)
9344 const unsigned char *str
;
9345 int field_width
, precision
;
9350 /* Copy at most PRECISION chars from STR. */
9351 nbytes
= strlen (str
);
9352 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9354 store_mode_line_noprop_char (*str
++);
9356 /* Fill up with spaces until FIELD_WIDTH reached. */
9357 while (field_width
> 0
9360 store_mode_line_noprop_char (' ');
9367 /***********************************************************************
9369 ***********************************************************************/
9371 #ifdef HAVE_WINDOW_SYSTEM
9373 /* Set the title of FRAME, if it has changed. The title format is
9374 Vicon_title_format if FRAME is iconified, otherwise it is
9375 frame_title_format. */
9378 x_consider_frame_title (frame
)
9381 struct frame
*f
= XFRAME (frame
);
9383 if (FRAME_WINDOW_P (f
)
9384 || FRAME_MINIBUF_ONLY_P (f
)
9385 || f
->explicit_name
)
9387 /* Do we have more than one visible frame on this X display? */
9394 int count
= SPECPDL_INDEX ();
9396 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9398 Lisp_Object other_frame
= XCAR (tail
);
9399 struct frame
*tf
= XFRAME (other_frame
);
9402 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9403 && !FRAME_MINIBUF_ONLY_P (tf
)
9404 && !EQ (other_frame
, tip_frame
)
9405 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9409 /* Set global variable indicating that multiple frames exist. */
9410 multiple_frames
= CONSP (tail
);
9412 /* Switch to the buffer of selected window of the frame. Set up
9413 mode_line_target so that display_mode_element will output into
9414 mode_line_noprop_buf; then display the title. */
9415 record_unwind_protect (unwind_format_mode_line
,
9416 format_mode_line_unwind_data
9417 (current_buffer
, selected_window
, 0));
9419 Fselect_window (f
->selected_window
, Qt
);
9420 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9421 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9423 mode_line_target
= MODE_LINE_TITLE
;
9424 title_start
= MODE_LINE_NOPROP_LEN (0);
9425 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9426 NULL
, DEFAULT_FACE_ID
);
9427 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9428 len
= MODE_LINE_NOPROP_LEN (title_start
);
9429 title
= mode_line_noprop_buf
+ title_start
;
9430 unbind_to (count
, Qnil
);
9432 /* Set the title only if it's changed. This avoids consing in
9433 the common case where it hasn't. (If it turns out that we've
9434 already wasted too much time by walking through the list with
9435 display_mode_element, then we might need to optimize at a
9436 higher level than this.) */
9437 if (! STRINGP (f
->name
)
9438 || SBYTES (f
->name
) != len
9439 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9440 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9444 #endif /* not HAVE_WINDOW_SYSTEM */
9449 /***********************************************************************
9451 ***********************************************************************/
9454 /* Prepare for redisplay by updating menu-bar item lists when
9455 appropriate. This can call eval. */
9458 prepare_menu_bars ()
9461 struct gcpro gcpro1
, gcpro2
;
9463 Lisp_Object tooltip_frame
;
9465 #ifdef HAVE_WINDOW_SYSTEM
9466 tooltip_frame
= tip_frame
;
9468 tooltip_frame
= Qnil
;
9471 /* Update all frame titles based on their buffer names, etc. We do
9472 this before the menu bars so that the buffer-menu will show the
9473 up-to-date frame titles. */
9474 #ifdef HAVE_WINDOW_SYSTEM
9475 if (windows_or_buffers_changed
|| update_mode_lines
)
9477 Lisp_Object tail
, frame
;
9479 FOR_EACH_FRAME (tail
, frame
)
9482 if (!EQ (frame
, tooltip_frame
)
9483 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9484 x_consider_frame_title (frame
);
9487 #endif /* HAVE_WINDOW_SYSTEM */
9489 /* Update the menu bar item lists, if appropriate. This has to be
9490 done before any actual redisplay or generation of display lines. */
9491 all_windows
= (update_mode_lines
9492 || buffer_shared
> 1
9493 || windows_or_buffers_changed
);
9496 Lisp_Object tail
, frame
;
9497 int count
= SPECPDL_INDEX ();
9498 /* 1 means that update_menu_bar has run its hooks
9499 so any further calls to update_menu_bar shouldn't do so again. */
9500 int menu_bar_hooks_run
= 0;
9502 record_unwind_save_match_data ();
9504 FOR_EACH_FRAME (tail
, frame
)
9508 /* Ignore tooltip frame. */
9509 if (EQ (frame
, tooltip_frame
))
9512 /* If a window on this frame changed size, report that to
9513 the user and clear the size-change flag. */
9514 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9516 Lisp_Object functions
;
9518 /* Clear flag first in case we get an error below. */
9519 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9520 functions
= Vwindow_size_change_functions
;
9521 GCPRO2 (tail
, functions
);
9523 while (CONSP (functions
))
9525 if (!EQ (XCAR (functions
), Qt
))
9526 call1 (XCAR (functions
), frame
);
9527 functions
= XCDR (functions
);
9533 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9534 #ifdef HAVE_WINDOW_SYSTEM
9535 update_tool_bar (f
, 0);
9538 if (windows_or_buffers_changed
9540 ns_set_doc_edited (f
, Fbuffer_modified_p
9541 (XWINDOW (f
->selected_window
)->buffer
));
9546 unbind_to (count
, Qnil
);
9550 struct frame
*sf
= SELECTED_FRAME ();
9551 update_menu_bar (sf
, 1, 0);
9552 #ifdef HAVE_WINDOW_SYSTEM
9553 update_tool_bar (sf
, 1);
9557 /* Motif needs this. See comment in xmenu.c. Turn it off when
9558 pending_menu_activation is not defined. */
9559 #ifdef USE_X_TOOLKIT
9560 pending_menu_activation
= 0;
9565 /* Update the menu bar item list for frame F. This has to be done
9566 before we start to fill in any display lines, because it can call
9569 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9571 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9572 already ran the menu bar hooks for this redisplay, so there
9573 is no need to run them again. The return value is the
9574 updated value of this flag, to pass to the next call. */
9577 update_menu_bar (f
, save_match_data
, hooks_run
)
9579 int save_match_data
;
9583 register struct window
*w
;
9585 /* If called recursively during a menu update, do nothing. This can
9586 happen when, for instance, an activate-menubar-hook causes a
9588 if (inhibit_menubar_update
)
9591 window
= FRAME_SELECTED_WINDOW (f
);
9592 w
= XWINDOW (window
);
9594 if (FRAME_WINDOW_P (f
)
9596 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9597 || defined (HAVE_NS) || defined (USE_GTK)
9598 FRAME_EXTERNAL_MENU_BAR (f
)
9600 FRAME_MENU_BAR_LINES (f
) > 0
9602 : FRAME_MENU_BAR_LINES (f
) > 0)
9604 /* If the user has switched buffers or windows, we need to
9605 recompute to reflect the new bindings. But we'll
9606 recompute when update_mode_lines is set too; that means
9607 that people can use force-mode-line-update to request
9608 that the menu bar be recomputed. The adverse effect on
9609 the rest of the redisplay algorithm is about the same as
9610 windows_or_buffers_changed anyway. */
9611 if (windows_or_buffers_changed
9612 /* This used to test w->update_mode_line, but we believe
9613 there is no need to recompute the menu in that case. */
9614 || update_mode_lines
9615 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9616 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9617 != !NILP (w
->last_had_star
))
9618 || ((!NILP (Vtransient_mark_mode
)
9619 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9620 != !NILP (w
->region_showing
)))
9622 struct buffer
*prev
= current_buffer
;
9623 int count
= SPECPDL_INDEX ();
9625 specbind (Qinhibit_menubar_update
, Qt
);
9627 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9628 if (save_match_data
)
9629 record_unwind_save_match_data ();
9630 if (NILP (Voverriding_local_map_menu_flag
))
9632 specbind (Qoverriding_terminal_local_map
, Qnil
);
9633 specbind (Qoverriding_local_map
, Qnil
);
9638 /* Run the Lucid hook. */
9639 safe_run_hooks (Qactivate_menubar_hook
);
9641 /* If it has changed current-menubar from previous value,
9642 really recompute the menu-bar from the value. */
9643 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9644 call0 (Qrecompute_lucid_menubar
);
9646 safe_run_hooks (Qmenu_bar_update_hook
);
9651 XSETFRAME (Vmenu_updating_frame
, f
);
9652 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9654 /* Redisplay the menu bar in case we changed it. */
9655 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9656 || defined (HAVE_NS) || defined (USE_GTK)
9657 if (FRAME_WINDOW_P (f
))
9659 #if defined (HAVE_NS)
9660 /* All frames on Mac OS share the same menubar. So only
9661 the selected frame should be allowed to set it. */
9662 if (f
== SELECTED_FRAME ())
9664 set_frame_menubar (f
, 0, 0);
9667 /* On a terminal screen, the menu bar is an ordinary screen
9668 line, and this makes it get updated. */
9669 w
->update_mode_line
= Qt
;
9670 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9671 /* In the non-toolkit version, the menu bar is an ordinary screen
9672 line, and this makes it get updated. */
9673 w
->update_mode_line
= Qt
;
9674 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9676 unbind_to (count
, Qnil
);
9677 set_buffer_internal_1 (prev
);
9686 /***********************************************************************
9688 ***********************************************************************/
9690 #ifdef HAVE_WINDOW_SYSTEM
9693 Nominal cursor position -- where to draw output.
9694 HPOS and VPOS are window relative glyph matrix coordinates.
9695 X and Y are window relative pixel coordinates. */
9697 struct cursor_pos output_cursor
;
9701 Set the global variable output_cursor to CURSOR. All cursor
9702 positions are relative to updated_window. */
9705 set_output_cursor (cursor
)
9706 struct cursor_pos
*cursor
;
9708 output_cursor
.hpos
= cursor
->hpos
;
9709 output_cursor
.vpos
= cursor
->vpos
;
9710 output_cursor
.x
= cursor
->x
;
9711 output_cursor
.y
= cursor
->y
;
9716 Set a nominal cursor position.
9718 HPOS and VPOS are column/row positions in a window glyph matrix. X
9719 and Y are window text area relative pixel positions.
9721 If this is done during an update, updated_window will contain the
9722 window that is being updated and the position is the future output
9723 cursor position for that window. If updated_window is null, use
9724 selected_window and display the cursor at the given position. */
9727 x_cursor_to (vpos
, hpos
, y
, x
)
9728 int vpos
, hpos
, y
, x
;
9732 /* If updated_window is not set, work on selected_window. */
9736 w
= XWINDOW (selected_window
);
9738 /* Set the output cursor. */
9739 output_cursor
.hpos
= hpos
;
9740 output_cursor
.vpos
= vpos
;
9741 output_cursor
.x
= x
;
9742 output_cursor
.y
= y
;
9744 /* If not called as part of an update, really display the cursor.
9745 This will also set the cursor position of W. */
9746 if (updated_window
== NULL
)
9749 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9750 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9751 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9756 #endif /* HAVE_WINDOW_SYSTEM */
9759 /***********************************************************************
9761 ***********************************************************************/
9763 #ifdef HAVE_WINDOW_SYSTEM
9765 /* Where the mouse was last time we reported a mouse event. */
9767 FRAME_PTR last_mouse_frame
;
9769 /* Tool-bar item index of the item on which a mouse button was pressed
9772 int last_tool_bar_item
;
9776 update_tool_bar_unwind (frame
)
9779 selected_frame
= frame
;
9783 /* Update the tool-bar item list for frame F. This has to be done
9784 before we start to fill in any display lines. Called from
9785 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9786 and restore it here. */
9789 update_tool_bar (f
, save_match_data
)
9791 int save_match_data
;
9793 #if defined (USE_GTK) || defined (HAVE_NS)
9794 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9796 int do_update
= WINDOWP (f
->tool_bar_window
)
9797 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9805 window
= FRAME_SELECTED_WINDOW (f
);
9806 w
= XWINDOW (window
);
9808 /* If the user has switched buffers or windows, we need to
9809 recompute to reflect the new bindings. But we'll
9810 recompute when update_mode_lines is set too; that means
9811 that people can use force-mode-line-update to request
9812 that the menu bar be recomputed. The adverse effect on
9813 the rest of the redisplay algorithm is about the same as
9814 windows_or_buffers_changed anyway. */
9815 if (windows_or_buffers_changed
9816 || !NILP (w
->update_mode_line
)
9817 || update_mode_lines
9818 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9819 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9820 != !NILP (w
->last_had_star
))
9821 || ((!NILP (Vtransient_mark_mode
)
9822 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9823 != !NILP (w
->region_showing
)))
9825 struct buffer
*prev
= current_buffer
;
9826 int count
= SPECPDL_INDEX ();
9827 Lisp_Object frame
, new_tool_bar
;
9829 struct gcpro gcpro1
;
9831 /* Set current_buffer to the buffer of the selected
9832 window of the frame, so that we get the right local
9834 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9836 /* Save match data, if we must. */
9837 if (save_match_data
)
9838 record_unwind_save_match_data ();
9840 /* Make sure that we don't accidentally use bogus keymaps. */
9841 if (NILP (Voverriding_local_map_menu_flag
))
9843 specbind (Qoverriding_terminal_local_map
, Qnil
);
9844 specbind (Qoverriding_local_map
, Qnil
);
9847 GCPRO1 (new_tool_bar
);
9849 /* We must temporarily set the selected frame to this frame
9850 before calling tool_bar_items, because the calculation of
9851 the tool-bar keymap uses the selected frame (see
9852 `tool-bar-make-keymap' in tool-bar.el). */
9853 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9854 XSETFRAME (frame
, f
);
9855 selected_frame
= frame
;
9857 /* Build desired tool-bar items from keymaps. */
9858 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9861 /* Redisplay the tool-bar if we changed it. */
9862 if (new_n_tool_bar
!= f
->n_tool_bar_items
9863 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9865 /* Redisplay that happens asynchronously due to an expose event
9866 may access f->tool_bar_items. Make sure we update both
9867 variables within BLOCK_INPUT so no such event interrupts. */
9869 f
->tool_bar_items
= new_tool_bar
;
9870 f
->n_tool_bar_items
= new_n_tool_bar
;
9871 w
->update_mode_line
= Qt
;
9877 unbind_to (count
, Qnil
);
9878 set_buffer_internal_1 (prev
);
9884 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9885 F's desired tool-bar contents. F->tool_bar_items must have
9886 been set up previously by calling prepare_menu_bars. */
9889 build_desired_tool_bar_string (f
)
9892 int i
, size
, size_needed
;
9893 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9894 Lisp_Object image
, plist
, props
;
9896 image
= plist
= props
= Qnil
;
9897 GCPRO3 (image
, plist
, props
);
9899 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9900 Otherwise, make a new string. */
9902 /* The size of the string we might be able to reuse. */
9903 size
= (STRINGP (f
->desired_tool_bar_string
)
9904 ? SCHARS (f
->desired_tool_bar_string
)
9907 /* We need one space in the string for each image. */
9908 size_needed
= f
->n_tool_bar_items
;
9910 /* Reuse f->desired_tool_bar_string, if possible. */
9911 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9912 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9916 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9917 Fremove_text_properties (make_number (0), make_number (size
),
9918 props
, f
->desired_tool_bar_string
);
9921 /* Put a `display' property on the string for the images to display,
9922 put a `menu_item' property on tool-bar items with a value that
9923 is the index of the item in F's tool-bar item vector. */
9924 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9926 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9928 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9929 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9930 int hmargin
, vmargin
, relief
, idx
, end
;
9931 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9933 /* If image is a vector, choose the image according to the
9935 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9936 if (VECTORP (image
))
9940 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9941 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9944 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9945 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9947 xassert (ASIZE (image
) >= idx
);
9948 image
= AREF (image
, idx
);
9953 /* Ignore invalid image specifications. */
9954 if (!valid_image_p (image
))
9957 /* Display the tool-bar button pressed, or depressed. */
9958 plist
= Fcopy_sequence (XCDR (image
));
9960 /* Compute margin and relief to draw. */
9961 relief
= (tool_bar_button_relief
>= 0
9962 ? tool_bar_button_relief
9963 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9964 hmargin
= vmargin
= relief
;
9966 if (INTEGERP (Vtool_bar_button_margin
)
9967 && XINT (Vtool_bar_button_margin
) > 0)
9969 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9970 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9972 else if (CONSP (Vtool_bar_button_margin
))
9974 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9975 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9976 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9978 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9979 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9980 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9983 if (auto_raise_tool_bar_buttons_p
)
9985 /* Add a `:relief' property to the image spec if the item is
9989 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9996 /* If image is selected, display it pressed, i.e. with a
9997 negative relief. If it's not selected, display it with a
9999 plist
= Fplist_put (plist
, QCrelief
,
10001 ? make_number (-relief
)
10002 : make_number (relief
)));
10007 /* Put a margin around the image. */
10008 if (hmargin
|| vmargin
)
10010 if (hmargin
== vmargin
)
10011 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10013 plist
= Fplist_put (plist
, QCmargin
,
10014 Fcons (make_number (hmargin
),
10015 make_number (vmargin
)));
10018 /* If button is not enabled, and we don't have special images
10019 for the disabled state, make the image appear disabled by
10020 applying an appropriate algorithm to it. */
10021 if (!enabled_p
&& idx
< 0)
10022 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10024 /* Put a `display' text property on the string for the image to
10025 display. Put a `menu-item' property on the string that gives
10026 the start of this item's properties in the tool-bar items
10028 image
= Fcons (Qimage
, plist
);
10029 props
= list4 (Qdisplay
, image
,
10030 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10032 /* Let the last image hide all remaining spaces in the tool bar
10033 string. The string can be longer than needed when we reuse a
10034 previous string. */
10035 if (i
+ 1 == f
->n_tool_bar_items
)
10036 end
= SCHARS (f
->desired_tool_bar_string
);
10039 Fadd_text_properties (make_number (i
), make_number (end
),
10040 props
, f
->desired_tool_bar_string
);
10048 /* Display one line of the tool-bar of frame IT->f.
10050 HEIGHT specifies the desired height of the tool-bar line.
10051 If the actual height of the glyph row is less than HEIGHT, the
10052 row's height is increased to HEIGHT, and the icons are centered
10053 vertically in the new height.
10055 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10056 count a final empty row in case the tool-bar width exactly matches
10061 display_tool_bar_line (it
, height
)
10065 struct glyph_row
*row
= it
->glyph_row
;
10066 int max_x
= it
->last_visible_x
;
10067 struct glyph
*last
;
10069 prepare_desired_row (row
);
10070 row
->y
= it
->current_y
;
10072 /* Note that this isn't made use of if the face hasn't a box,
10073 so there's no need to check the face here. */
10074 it
->start_of_box_run_p
= 1;
10076 while (it
->current_x
< max_x
)
10078 int x
, n_glyphs_before
, i
, nglyphs
;
10079 struct it it_before
;
10081 /* Get the next display element. */
10082 if (!get_next_display_element (it
))
10084 /* Don't count empty row if we are counting needed tool-bar lines. */
10085 if (height
< 0 && !it
->hpos
)
10090 /* Produce glyphs. */
10091 n_glyphs_before
= row
->used
[TEXT_AREA
];
10094 PRODUCE_GLYPHS (it
);
10096 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10098 x
= it_before
.current_x
;
10099 while (i
< nglyphs
)
10101 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10103 if (x
+ glyph
->pixel_width
> max_x
)
10105 /* Glyph doesn't fit on line. Backtrack. */
10106 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10108 /* If this is the only glyph on this line, it will never fit on the
10109 toolbar, so skip it. But ensure there is at least one glyph,
10110 so we don't accidentally disable the tool-bar. */
10111 if (n_glyphs_before
== 0
10112 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10118 x
+= glyph
->pixel_width
;
10122 /* Stop at line ends. */
10123 if (ITERATOR_AT_END_OF_LINE_P (it
))
10126 set_iterator_to_next (it
, 1);
10131 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10133 /* Use default face for the border below the tool bar.
10135 FIXME: When auto-resize-tool-bars is grow-only, there is
10136 no additional border below the possibly empty tool-bar lines.
10137 So to make the extra empty lines look "normal", we have to
10138 use the tool-bar face for the border too. */
10139 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10140 it
->face_id
= DEFAULT_FACE_ID
;
10142 extend_face_to_end_of_line (it
);
10143 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10144 last
->right_box_line_p
= 1;
10145 if (last
== row
->glyphs
[TEXT_AREA
])
10146 last
->left_box_line_p
= 1;
10148 /* Make line the desired height and center it vertically. */
10149 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10151 /* Don't add more than one line height. */
10152 height
%= FRAME_LINE_HEIGHT (it
->f
);
10153 it
->max_ascent
+= height
/ 2;
10154 it
->max_descent
+= (height
+ 1) / 2;
10157 compute_line_metrics (it
);
10159 /* If line is empty, make it occupy the rest of the tool-bar. */
10160 if (!row
->displays_text_p
)
10162 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10163 row
->visible_height
= row
->height
;
10164 row
->ascent
= row
->phys_ascent
= 0;
10165 row
->extra_line_spacing
= 0;
10168 row
->full_width_p
= 1;
10169 row
->continued_p
= 0;
10170 row
->truncated_on_left_p
= 0;
10171 row
->truncated_on_right_p
= 0;
10173 it
->current_x
= it
->hpos
= 0;
10174 it
->current_y
+= row
->height
;
10180 /* Max tool-bar height. */
10182 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10183 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10185 /* Value is the number of screen lines needed to make all tool-bar
10186 items of frame F visible. The number of actual rows needed is
10187 returned in *N_ROWS if non-NULL. */
10190 tool_bar_lines_needed (f
, n_rows
)
10194 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10196 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10197 the desired matrix, so use (unused) mode-line row as temporary row to
10198 avoid destroying the first tool-bar row. */
10199 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10201 /* Initialize an iterator for iteration over
10202 F->desired_tool_bar_string in the tool-bar window of frame F. */
10203 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10204 it
.first_visible_x
= 0;
10205 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10206 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10208 while (!ITERATOR_AT_END_P (&it
))
10210 clear_glyph_row (temp_row
);
10211 it
.glyph_row
= temp_row
;
10212 display_tool_bar_line (&it
, -1);
10214 clear_glyph_row (temp_row
);
10216 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10218 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10220 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10224 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10226 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10235 frame
= selected_frame
;
10237 CHECK_FRAME (frame
);
10238 f
= XFRAME (frame
);
10240 if (WINDOWP (f
->tool_bar_window
)
10241 || (w
= XWINDOW (f
->tool_bar_window
),
10242 WINDOW_TOTAL_LINES (w
) > 0))
10244 update_tool_bar (f
, 1);
10245 if (f
->n_tool_bar_items
)
10247 build_desired_tool_bar_string (f
);
10248 nlines
= tool_bar_lines_needed (f
, NULL
);
10252 return make_number (nlines
);
10256 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10257 height should be changed. */
10260 redisplay_tool_bar (f
)
10265 struct glyph_row
*row
;
10267 #if defined (USE_GTK) || defined (HAVE_NS)
10268 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10269 update_frame_tool_bar (f
);
10273 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10274 do anything. This means you must start with tool-bar-lines
10275 non-zero to get the auto-sizing effect. Or in other words, you
10276 can turn off tool-bars by specifying tool-bar-lines zero. */
10277 if (!WINDOWP (f
->tool_bar_window
)
10278 || (w
= XWINDOW (f
->tool_bar_window
),
10279 WINDOW_TOTAL_LINES (w
) == 0))
10282 /* Set up an iterator for the tool-bar window. */
10283 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10284 it
.first_visible_x
= 0;
10285 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10286 row
= it
.glyph_row
;
10288 /* Build a string that represents the contents of the tool-bar. */
10289 build_desired_tool_bar_string (f
);
10290 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10292 if (f
->n_tool_bar_rows
== 0)
10296 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10297 nlines
!= WINDOW_TOTAL_LINES (w
)))
10299 extern Lisp_Object Qtool_bar_lines
;
10301 int old_height
= WINDOW_TOTAL_LINES (w
);
10303 XSETFRAME (frame
, f
);
10304 Fmodify_frame_parameters (frame
,
10305 Fcons (Fcons (Qtool_bar_lines
,
10306 make_number (nlines
)),
10308 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10310 clear_glyph_matrix (w
->desired_matrix
);
10311 fonts_changed_p
= 1;
10317 /* Display as many lines as needed to display all tool-bar items. */
10319 if (f
->n_tool_bar_rows
> 0)
10321 int border
, rows
, height
, extra
;
10323 if (INTEGERP (Vtool_bar_border
))
10324 border
= XINT (Vtool_bar_border
);
10325 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10326 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10327 else if (EQ (Vtool_bar_border
, Qborder_width
))
10328 border
= f
->border_width
;
10334 rows
= f
->n_tool_bar_rows
;
10335 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10336 extra
= it
.last_visible_y
- border
- height
* rows
;
10338 while (it
.current_y
< it
.last_visible_y
)
10341 if (extra
> 0 && rows
-- > 0)
10343 h
= (extra
+ rows
- 1) / rows
;
10346 display_tool_bar_line (&it
, height
+ h
);
10351 while (it
.current_y
< it
.last_visible_y
)
10352 display_tool_bar_line (&it
, 0);
10355 /* It doesn't make much sense to try scrolling in the tool-bar
10356 window, so don't do it. */
10357 w
->desired_matrix
->no_scrolling_p
= 1;
10358 w
->must_be_updated_p
= 1;
10360 if (!NILP (Vauto_resize_tool_bars
))
10362 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10363 int change_height_p
= 0;
10365 /* If we couldn't display everything, change the tool-bar's
10366 height if there is room for more. */
10367 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10368 && it
.current_y
< max_tool_bar_height
)
10369 change_height_p
= 1;
10371 row
= it
.glyph_row
- 1;
10373 /* If there are blank lines at the end, except for a partially
10374 visible blank line at the end that is smaller than
10375 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10376 if (!row
->displays_text_p
10377 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10378 change_height_p
= 1;
10380 /* If row displays tool-bar items, but is partially visible,
10381 change the tool-bar's height. */
10382 if (row
->displays_text_p
10383 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10384 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10385 change_height_p
= 1;
10387 /* Resize windows as needed by changing the `tool-bar-lines'
10388 frame parameter. */
10389 if (change_height_p
)
10391 extern Lisp_Object Qtool_bar_lines
;
10393 int old_height
= WINDOW_TOTAL_LINES (w
);
10395 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10397 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10398 && !f
->minimize_tool_bar_window_p
)
10399 ? (nlines
> old_height
)
10400 : (nlines
!= old_height
));
10401 f
->minimize_tool_bar_window_p
= 0;
10403 if (change_height_p
)
10405 XSETFRAME (frame
, f
);
10406 Fmodify_frame_parameters (frame
,
10407 Fcons (Fcons (Qtool_bar_lines
,
10408 make_number (nlines
)),
10410 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10412 clear_glyph_matrix (w
->desired_matrix
);
10413 f
->n_tool_bar_rows
= nrows
;
10414 fonts_changed_p
= 1;
10421 f
->minimize_tool_bar_window_p
= 0;
10426 /* Get information about the tool-bar item which is displayed in GLYPH
10427 on frame F. Return in *PROP_IDX the index where tool-bar item
10428 properties start in F->tool_bar_items. Value is zero if
10429 GLYPH doesn't display a tool-bar item. */
10432 tool_bar_item_info (f
, glyph
, prop_idx
)
10434 struct glyph
*glyph
;
10441 /* This function can be called asynchronously, which means we must
10442 exclude any possibility that Fget_text_property signals an
10444 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10445 charpos
= max (0, charpos
);
10447 /* Get the text property `menu-item' at pos. The value of that
10448 property is the start index of this item's properties in
10449 F->tool_bar_items. */
10450 prop
= Fget_text_property (make_number (charpos
),
10451 Qmenu_item
, f
->current_tool_bar_string
);
10452 if (INTEGERP (prop
))
10454 *prop_idx
= XINT (prop
);
10464 /* Get information about the tool-bar item at position X/Y on frame F.
10465 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10466 the current matrix of the tool-bar window of F, or NULL if not
10467 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10468 item in F->tool_bar_items. Value is
10470 -1 if X/Y is not on a tool-bar item
10471 0 if X/Y is on the same item that was highlighted before.
10475 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10478 struct glyph
**glyph
;
10479 int *hpos
, *vpos
, *prop_idx
;
10481 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10482 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10485 /* Find the glyph under X/Y. */
10486 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10487 if (*glyph
== NULL
)
10490 /* Get the start of this tool-bar item's properties in
10491 f->tool_bar_items. */
10492 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10495 /* Is mouse on the highlighted item? */
10496 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10497 && *vpos
>= dpyinfo
->mouse_face_beg_row
10498 && *vpos
<= dpyinfo
->mouse_face_end_row
10499 && (*vpos
> dpyinfo
->mouse_face_beg_row
10500 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10501 && (*vpos
< dpyinfo
->mouse_face_end_row
10502 || *hpos
< dpyinfo
->mouse_face_end_col
10503 || dpyinfo
->mouse_face_past_end
))
10511 Handle mouse button event on the tool-bar of frame F, at
10512 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10513 0 for button release. MODIFIERS is event modifiers for button
10517 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10520 unsigned int modifiers
;
10522 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10523 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10524 int hpos
, vpos
, prop_idx
;
10525 struct glyph
*glyph
;
10526 Lisp_Object enabled_p
;
10528 /* If not on the highlighted tool-bar item, return. */
10529 frame_to_window_pixel_xy (w
, &x
, &y
);
10530 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10533 /* If item is disabled, do nothing. */
10534 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10535 if (NILP (enabled_p
))
10540 /* Show item in pressed state. */
10541 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10542 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10543 last_tool_bar_item
= prop_idx
;
10547 Lisp_Object key
, frame
;
10548 struct input_event event
;
10549 EVENT_INIT (event
);
10551 /* Show item in released state. */
10552 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10553 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10555 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10557 XSETFRAME (frame
, f
);
10558 event
.kind
= TOOL_BAR_EVENT
;
10559 event
.frame_or_window
= frame
;
10561 kbd_buffer_store_event (&event
);
10563 event
.kind
= TOOL_BAR_EVENT
;
10564 event
.frame_or_window
= frame
;
10566 event
.modifiers
= modifiers
;
10567 kbd_buffer_store_event (&event
);
10568 last_tool_bar_item
= -1;
10573 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10574 tool-bar window-relative coordinates X/Y. Called from
10575 note_mouse_highlight. */
10578 note_tool_bar_highlight (f
, x
, y
)
10582 Lisp_Object window
= f
->tool_bar_window
;
10583 struct window
*w
= XWINDOW (window
);
10584 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10586 struct glyph
*glyph
;
10587 struct glyph_row
*row
;
10589 Lisp_Object enabled_p
;
10591 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10592 int mouse_down_p
, rc
;
10594 /* Function note_mouse_highlight is called with negative x(y
10595 values when mouse moves outside of the frame. */
10596 if (x
<= 0 || y
<= 0)
10598 clear_mouse_face (dpyinfo
);
10602 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10605 /* Not on tool-bar item. */
10606 clear_mouse_face (dpyinfo
);
10610 /* On same tool-bar item as before. */
10611 goto set_help_echo
;
10613 clear_mouse_face (dpyinfo
);
10615 /* Mouse is down, but on different tool-bar item? */
10616 mouse_down_p
= (dpyinfo
->grabbed
10617 && f
== last_mouse_frame
10618 && FRAME_LIVE_P (f
));
10620 && last_tool_bar_item
!= prop_idx
)
10623 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10624 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10626 /* If tool-bar item is not enabled, don't highlight it. */
10627 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10628 if (!NILP (enabled_p
))
10630 /* Compute the x-position of the glyph. In front and past the
10631 image is a space. We include this in the highlighted area. */
10632 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10633 for (i
= x
= 0; i
< hpos
; ++i
)
10634 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10636 /* Record this as the current active region. */
10637 dpyinfo
->mouse_face_beg_col
= hpos
;
10638 dpyinfo
->mouse_face_beg_row
= vpos
;
10639 dpyinfo
->mouse_face_beg_x
= x
;
10640 dpyinfo
->mouse_face_beg_y
= row
->y
;
10641 dpyinfo
->mouse_face_past_end
= 0;
10643 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10644 dpyinfo
->mouse_face_end_row
= vpos
;
10645 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10646 dpyinfo
->mouse_face_end_y
= row
->y
;
10647 dpyinfo
->mouse_face_window
= window
;
10648 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10650 /* Display it as active. */
10651 show_mouse_face (dpyinfo
, draw
);
10652 dpyinfo
->mouse_face_image_state
= draw
;
10657 /* Set help_echo_string to a help string to display for this tool-bar item.
10658 XTread_socket does the rest. */
10659 help_echo_object
= help_echo_window
= Qnil
;
10660 help_echo_pos
= -1;
10661 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10662 if (NILP (help_echo_string
))
10663 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10666 #endif /* HAVE_WINDOW_SYSTEM */
10670 /************************************************************************
10671 Horizontal scrolling
10672 ************************************************************************/
10674 static int hscroll_window_tree
P_ ((Lisp_Object
));
10675 static int hscroll_windows
P_ ((Lisp_Object
));
10677 /* For all leaf windows in the window tree rooted at WINDOW, set their
10678 hscroll value so that PT is (i) visible in the window, and (ii) so
10679 that it is not within a certain margin at the window's left and
10680 right border. Value is non-zero if any window's hscroll has been
10684 hscroll_window_tree (window
)
10685 Lisp_Object window
;
10687 int hscrolled_p
= 0;
10688 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10689 int hscroll_step_abs
= 0;
10690 double hscroll_step_rel
= 0;
10692 if (hscroll_relative_p
)
10694 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10695 if (hscroll_step_rel
< 0)
10697 hscroll_relative_p
= 0;
10698 hscroll_step_abs
= 0;
10701 else if (INTEGERP (Vhscroll_step
))
10703 hscroll_step_abs
= XINT (Vhscroll_step
);
10704 if (hscroll_step_abs
< 0)
10705 hscroll_step_abs
= 0;
10708 hscroll_step_abs
= 0;
10710 while (WINDOWP (window
))
10712 struct window
*w
= XWINDOW (window
);
10714 if (WINDOWP (w
->hchild
))
10715 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10716 else if (WINDOWP (w
->vchild
))
10717 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10718 else if (w
->cursor
.vpos
>= 0)
10721 int text_area_width
;
10722 struct glyph_row
*current_cursor_row
10723 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10724 struct glyph_row
*desired_cursor_row
10725 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10726 struct glyph_row
*cursor_row
10727 = (desired_cursor_row
->enabled_p
10728 ? desired_cursor_row
10729 : current_cursor_row
);
10731 text_area_width
= window_box_width (w
, TEXT_AREA
);
10733 /* Scroll when cursor is inside this scroll margin. */
10734 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10736 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10737 && ((XFASTINT (w
->hscroll
)
10738 && w
->cursor
.x
<= h_margin
)
10739 || (cursor_row
->enabled_p
10740 && cursor_row
->truncated_on_right_p
10741 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10745 struct buffer
*saved_current_buffer
;
10749 /* Find point in a display of infinite width. */
10750 saved_current_buffer
= current_buffer
;
10751 current_buffer
= XBUFFER (w
->buffer
);
10753 if (w
== XWINDOW (selected_window
))
10754 pt
= BUF_PT (current_buffer
);
10757 pt
= marker_position (w
->pointm
);
10758 pt
= max (BEGV
, pt
);
10762 /* Move iterator to pt starting at cursor_row->start in
10763 a line with infinite width. */
10764 init_to_row_start (&it
, w
, cursor_row
);
10765 it
.last_visible_x
= INFINITY
;
10766 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10767 current_buffer
= saved_current_buffer
;
10769 /* Position cursor in window. */
10770 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10771 hscroll
= max (0, (it
.current_x
10772 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10773 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10774 : (text_area_width
/ 2))))
10775 / FRAME_COLUMN_WIDTH (it
.f
);
10776 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10778 if (hscroll_relative_p
)
10779 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10782 wanted_x
= text_area_width
10783 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10786 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10790 if (hscroll_relative_p
)
10791 wanted_x
= text_area_width
* hscroll_step_rel
10794 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10797 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10799 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10801 /* Don't call Fset_window_hscroll if value hasn't
10802 changed because it will prevent redisplay
10804 if (XFASTINT (w
->hscroll
) != hscroll
)
10806 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10807 w
->hscroll
= make_number (hscroll
);
10816 /* Value is non-zero if hscroll of any leaf window has been changed. */
10817 return hscrolled_p
;
10821 /* Set hscroll so that cursor is visible and not inside horizontal
10822 scroll margins for all windows in the tree rooted at WINDOW. See
10823 also hscroll_window_tree above. Value is non-zero if any window's
10824 hscroll has been changed. If it has, desired matrices on the frame
10825 of WINDOW are cleared. */
10828 hscroll_windows (window
)
10829 Lisp_Object window
;
10831 int hscrolled_p
= hscroll_window_tree (window
);
10833 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10834 return hscrolled_p
;
10839 /************************************************************************
10841 ************************************************************************/
10843 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10844 to a non-zero value. This is sometimes handy to have in a debugger
10849 /* First and last unchanged row for try_window_id. */
10851 int debug_first_unchanged_at_end_vpos
;
10852 int debug_last_unchanged_at_beg_vpos
;
10854 /* Delta vpos and y. */
10856 int debug_dvpos
, debug_dy
;
10858 /* Delta in characters and bytes for try_window_id. */
10860 int debug_delta
, debug_delta_bytes
;
10862 /* Values of window_end_pos and window_end_vpos at the end of
10865 EMACS_INT debug_end_pos
, debug_end_vpos
;
10867 /* Append a string to W->desired_matrix->method. FMT is a printf
10868 format string. A1...A9 are a supplement for a variable-length
10869 argument list. If trace_redisplay_p is non-zero also printf the
10870 resulting string to stderr. */
10873 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10876 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10879 char *method
= w
->desired_matrix
->method
;
10880 int len
= strlen (method
);
10881 int size
= sizeof w
->desired_matrix
->method
;
10882 int remaining
= size
- len
- 1;
10884 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10885 if (len
&& remaining
)
10888 --remaining
, ++len
;
10891 strncpy (method
+ len
, buffer
, remaining
);
10893 if (trace_redisplay_p
)
10894 fprintf (stderr
, "%p (%s): %s\n",
10896 ((BUFFERP (w
->buffer
)
10897 && STRINGP (XBUFFER (w
->buffer
)->name
))
10898 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10903 #endif /* GLYPH_DEBUG */
10906 /* Value is non-zero if all changes in window W, which displays
10907 current_buffer, are in the text between START and END. START is a
10908 buffer position, END is given as a distance from Z. Used in
10909 redisplay_internal for display optimization. */
10912 text_outside_line_unchanged_p (w
, start
, end
)
10916 int unchanged_p
= 1;
10918 /* If text or overlays have changed, see where. */
10919 if (XFASTINT (w
->last_modified
) < MODIFF
10920 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10922 /* Gap in the line? */
10923 if (GPT
< start
|| Z
- GPT
< end
)
10926 /* Changes start in front of the line, or end after it? */
10928 && (BEG_UNCHANGED
< start
- 1
10929 || END_UNCHANGED
< end
))
10932 /* If selective display, can't optimize if changes start at the
10933 beginning of the line. */
10935 && INTEGERP (current_buffer
->selective_display
)
10936 && XINT (current_buffer
->selective_display
) > 0
10937 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10940 /* If there are overlays at the start or end of the line, these
10941 may have overlay strings with newlines in them. A change at
10942 START, for instance, may actually concern the display of such
10943 overlay strings as well, and they are displayed on different
10944 lines. So, quickly rule out this case. (For the future, it
10945 might be desirable to implement something more telling than
10946 just BEG/END_UNCHANGED.) */
10949 if (BEG
+ BEG_UNCHANGED
== start
10950 && overlay_touches_p (start
))
10952 if (END_UNCHANGED
== end
10953 && overlay_touches_p (Z
- end
))
10958 return unchanged_p
;
10962 /* Do a frame update, taking possible shortcuts into account. This is
10963 the main external entry point for redisplay.
10965 If the last redisplay displayed an echo area message and that message
10966 is no longer requested, we clear the echo area or bring back the
10967 mini-buffer if that is in use. */
10972 redisplay_internal (0);
10977 overlay_arrow_string_or_property (var
)
10982 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10985 return Voverlay_arrow_string
;
10988 /* Return 1 if there are any overlay-arrows in current_buffer. */
10990 overlay_arrow_in_current_buffer_p ()
10994 for (vlist
= Voverlay_arrow_variable_list
;
10996 vlist
= XCDR (vlist
))
10998 Lisp_Object var
= XCAR (vlist
);
11001 if (!SYMBOLP (var
))
11003 val
= find_symbol_value (var
);
11005 && current_buffer
== XMARKER (val
)->buffer
)
11012 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11016 overlay_arrows_changed_p ()
11020 for (vlist
= Voverlay_arrow_variable_list
;
11022 vlist
= XCDR (vlist
))
11024 Lisp_Object var
= XCAR (vlist
);
11025 Lisp_Object val
, pstr
;
11027 if (!SYMBOLP (var
))
11029 val
= find_symbol_value (var
);
11030 if (!MARKERP (val
))
11032 if (! EQ (COERCE_MARKER (val
),
11033 Fget (var
, Qlast_arrow_position
))
11034 || ! (pstr
= overlay_arrow_string_or_property (var
),
11035 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11041 /* Mark overlay arrows to be updated on next redisplay. */
11044 update_overlay_arrows (up_to_date
)
11049 for (vlist
= Voverlay_arrow_variable_list
;
11051 vlist
= XCDR (vlist
))
11053 Lisp_Object var
= XCAR (vlist
);
11055 if (!SYMBOLP (var
))
11058 if (up_to_date
> 0)
11060 Lisp_Object val
= find_symbol_value (var
);
11061 Fput (var
, Qlast_arrow_position
,
11062 COERCE_MARKER (val
));
11063 Fput (var
, Qlast_arrow_string
,
11064 overlay_arrow_string_or_property (var
));
11066 else if (up_to_date
< 0
11067 || !NILP (Fget (var
, Qlast_arrow_position
)))
11069 Fput (var
, Qlast_arrow_position
, Qt
);
11070 Fput (var
, Qlast_arrow_string
, Qt
);
11076 /* Return overlay arrow string to display at row.
11077 Return integer (bitmap number) for arrow bitmap in left fringe.
11078 Return nil if no overlay arrow. */
11081 overlay_arrow_at_row (it
, row
)
11083 struct glyph_row
*row
;
11087 for (vlist
= Voverlay_arrow_variable_list
;
11089 vlist
= XCDR (vlist
))
11091 Lisp_Object var
= XCAR (vlist
);
11094 if (!SYMBOLP (var
))
11097 val
= find_symbol_value (var
);
11100 && current_buffer
== XMARKER (val
)->buffer
11101 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11103 if (FRAME_WINDOW_P (it
->f
)
11104 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11106 #ifdef HAVE_WINDOW_SYSTEM
11107 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11110 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11111 return make_number (fringe_bitmap
);
11114 return make_number (-1); /* Use default arrow bitmap */
11116 return overlay_arrow_string_or_property (var
);
11123 /* Return 1 if point moved out of or into a composition. Otherwise
11124 return 0. PREV_BUF and PREV_PT are the last point buffer and
11125 position. BUF and PT are the current point buffer and position. */
11128 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11129 struct buffer
*prev_buf
, *buf
;
11132 EMACS_INT start
, end
;
11134 Lisp_Object buffer
;
11136 XSETBUFFER (buffer
, buf
);
11137 /* Check a composition at the last point if point moved within the
11139 if (prev_buf
== buf
)
11142 /* Point didn't move. */
11145 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11146 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11147 && COMPOSITION_VALID_P (start
, end
, prop
)
11148 && start
< prev_pt
&& end
> prev_pt
)
11149 /* The last point was within the composition. Return 1 iff
11150 point moved out of the composition. */
11151 return (pt
<= start
|| pt
>= end
);
11154 /* Check a composition at the current point. */
11155 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11156 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11157 && COMPOSITION_VALID_P (start
, end
, prop
)
11158 && start
< pt
&& end
> pt
);
11162 /* Reconsider the setting of B->clip_changed which is displayed
11166 reconsider_clip_changes (w
, b
)
11170 if (b
->clip_changed
11171 && !NILP (w
->window_end_valid
)
11172 && w
->current_matrix
->buffer
== b
11173 && w
->current_matrix
->zv
== BUF_ZV (b
)
11174 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11175 b
->clip_changed
= 0;
11177 /* If display wasn't paused, and W is not a tool bar window, see if
11178 point has been moved into or out of a composition. In that case,
11179 we set b->clip_changed to 1 to force updating the screen. If
11180 b->clip_changed has already been set to 1, we can skip this
11182 if (!b
->clip_changed
11183 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11187 if (w
== XWINDOW (selected_window
))
11188 pt
= BUF_PT (current_buffer
);
11190 pt
= marker_position (w
->pointm
);
11192 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11193 || pt
!= XINT (w
->last_point
))
11194 && check_point_in_composition (w
->current_matrix
->buffer
,
11195 XINT (w
->last_point
),
11196 XBUFFER (w
->buffer
), pt
))
11197 b
->clip_changed
= 1;
11202 /* Select FRAME to forward the values of frame-local variables into C
11203 variables so that the redisplay routines can access those values
11207 select_frame_for_redisplay (frame
)
11210 Lisp_Object tail
, symbol
, val
;
11211 Lisp_Object old
= selected_frame
;
11212 struct Lisp_Symbol
*sym
;
11214 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11216 selected_frame
= frame
;
11220 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11221 if (CONSP (XCAR (tail
))
11222 && (symbol
= XCAR (XCAR (tail
)),
11224 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11226 (BUFFER_LOCAL_VALUEP (val
)))
11227 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11228 /* Use find_symbol_value rather than Fsymbol_value
11229 to avoid an error if it is void. */
11230 find_symbol_value (symbol
);
11231 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11235 #define STOP_POLLING \
11236 do { if (! polling_stopped_here) stop_polling (); \
11237 polling_stopped_here = 1; } while (0)
11239 #define RESUME_POLLING \
11240 do { if (polling_stopped_here) start_polling (); \
11241 polling_stopped_here = 0; } while (0)
11244 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11245 response to any user action; therefore, we should preserve the echo
11246 area. (Actually, our caller does that job.) Perhaps in the future
11247 avoid recentering windows if it is not necessary; currently that
11248 causes some problems. */
11251 redisplay_internal (preserve_echo_area
)
11252 int preserve_echo_area
;
11254 struct window
*w
= XWINDOW (selected_window
);
11257 int must_finish
= 0;
11258 struct text_pos tlbufpos
, tlendpos
;
11259 int number_of_visible_frames
;
11262 int polling_stopped_here
= 0;
11263 Lisp_Object old_frame
= selected_frame
;
11265 /* Non-zero means redisplay has to consider all windows on all
11266 frames. Zero means, only selected_window is considered. */
11267 int consider_all_windows_p
;
11269 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11271 /* No redisplay if running in batch mode or frame is not yet fully
11272 initialized, or redisplay is explicitly turned off by setting
11273 Vinhibit_redisplay. */
11274 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11275 || !NILP (Vinhibit_redisplay
))
11278 /* Don't examine these until after testing Vinhibit_redisplay.
11279 When Emacs is shutting down, perhaps because its connection to
11280 X has dropped, we should not look at them at all. */
11281 f
= XFRAME (w
->frame
);
11282 sf
= SELECTED_FRAME ();
11284 if (!f
->glyphs_initialized_p
)
11287 /* The flag redisplay_performed_directly_p is set by
11288 direct_output_for_insert when it already did the whole screen
11289 update necessary. */
11290 if (redisplay_performed_directly_p
)
11292 redisplay_performed_directly_p
= 0;
11293 if (!hscroll_windows (selected_window
))
11297 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11298 if (popup_activated ())
11302 /* I don't think this happens but let's be paranoid. */
11303 if (redisplaying_p
)
11306 /* Record a function that resets redisplaying_p to its old value
11307 when we leave this function. */
11308 count
= SPECPDL_INDEX ();
11309 record_unwind_protect (unwind_redisplay
,
11310 Fcons (make_number (redisplaying_p
), selected_frame
));
11312 specbind (Qinhibit_free_realized_faces
, Qnil
);
11315 Lisp_Object tail
, frame
;
11317 FOR_EACH_FRAME (tail
, frame
)
11319 struct frame
*f
= XFRAME (frame
);
11320 f
->already_hscrolled_p
= 0;
11325 if (!EQ (old_frame
, selected_frame
)
11326 && FRAME_LIVE_P (XFRAME (old_frame
)))
11327 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11328 selected_frame and selected_window to be temporarily out-of-sync so
11329 when we come back here via `goto retry', we need to resync because we
11330 may need to run Elisp code (via prepare_menu_bars). */
11331 select_frame_for_redisplay (old_frame
);
11334 reconsider_clip_changes (w
, current_buffer
);
11335 last_escape_glyph_frame
= NULL
;
11336 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11338 /* If new fonts have been loaded that make a glyph matrix adjustment
11339 necessary, do it. */
11340 if (fonts_changed_p
)
11342 adjust_glyphs (NULL
);
11343 ++windows_or_buffers_changed
;
11344 fonts_changed_p
= 0;
11347 /* If face_change_count is non-zero, init_iterator will free all
11348 realized faces, which includes the faces referenced from current
11349 matrices. So, we can't reuse current matrices in this case. */
11350 if (face_change_count
)
11351 ++windows_or_buffers_changed
;
11353 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11354 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11356 /* Since frames on a single ASCII terminal share the same
11357 display area, displaying a different frame means redisplay
11358 the whole thing. */
11359 windows_or_buffers_changed
++;
11360 SET_FRAME_GARBAGED (sf
);
11362 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11364 FRAME_TTY (sf
)->previous_frame
= sf
;
11367 /* Set the visible flags for all frames. Do this before checking
11368 for resized or garbaged frames; they want to know if their frames
11369 are visible. See the comment in frame.h for
11370 FRAME_SAMPLE_VISIBILITY. */
11372 Lisp_Object tail
, frame
;
11374 number_of_visible_frames
= 0;
11376 FOR_EACH_FRAME (tail
, frame
)
11378 struct frame
*f
= XFRAME (frame
);
11380 FRAME_SAMPLE_VISIBILITY (f
);
11381 if (FRAME_VISIBLE_P (f
))
11382 ++number_of_visible_frames
;
11383 clear_desired_matrices (f
);
11387 /* Notice any pending interrupt request to change frame size. */
11388 do_pending_window_change (1);
11390 /* Clear frames marked as garbaged. */
11391 if (frame_garbaged
)
11392 clear_garbaged_frames ();
11394 /* Build menubar and tool-bar items. */
11395 if (NILP (Vmemory_full
))
11396 prepare_menu_bars ();
11398 if (windows_or_buffers_changed
)
11399 update_mode_lines
++;
11401 /* Detect case that we need to write or remove a star in the mode line. */
11402 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11404 w
->update_mode_line
= Qt
;
11405 if (buffer_shared
> 1)
11406 update_mode_lines
++;
11409 /* Avoid invocation of point motion hooks by `current_column' below. */
11410 count1
= SPECPDL_INDEX ();
11411 specbind (Qinhibit_point_motion_hooks
, Qt
);
11413 /* If %c is in the mode line, update it if needed. */
11414 if (!NILP (w
->column_number_displayed
)
11415 /* This alternative quickly identifies a common case
11416 where no change is needed. */
11417 && !(PT
== XFASTINT (w
->last_point
)
11418 && XFASTINT (w
->last_modified
) >= MODIFF
11419 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11420 && (XFASTINT (w
->column_number_displayed
)
11421 != (int) current_column ())) /* iftc */
11422 w
->update_mode_line
= Qt
;
11424 unbind_to (count1
, Qnil
);
11426 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11428 /* The variable buffer_shared is set in redisplay_window and
11429 indicates that we redisplay a buffer in different windows. See
11431 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11432 || cursor_type_changed
);
11434 /* If specs for an arrow have changed, do thorough redisplay
11435 to ensure we remove any arrow that should no longer exist. */
11436 if (overlay_arrows_changed_p ())
11437 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11439 /* Normally the message* functions will have already displayed and
11440 updated the echo area, but the frame may have been trashed, or
11441 the update may have been preempted, so display the echo area
11442 again here. Checking message_cleared_p captures the case that
11443 the echo area should be cleared. */
11444 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11445 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11446 || (message_cleared_p
11447 && minibuf_level
== 0
11448 /* If the mini-window is currently selected, this means the
11449 echo-area doesn't show through. */
11450 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11452 int window_height_changed_p
= echo_area_display (0);
11455 /* If we don't display the current message, don't clear the
11456 message_cleared_p flag, because, if we did, we wouldn't clear
11457 the echo area in the next redisplay which doesn't preserve
11459 if (!display_last_displayed_message_p
)
11460 message_cleared_p
= 0;
11462 if (fonts_changed_p
)
11464 else if (window_height_changed_p
)
11466 consider_all_windows_p
= 1;
11467 ++update_mode_lines
;
11468 ++windows_or_buffers_changed
;
11470 /* If window configuration was changed, frames may have been
11471 marked garbaged. Clear them or we will experience
11472 surprises wrt scrolling. */
11473 if (frame_garbaged
)
11474 clear_garbaged_frames ();
11477 else if (EQ (selected_window
, minibuf_window
)
11478 && (current_buffer
->clip_changed
11479 || XFASTINT (w
->last_modified
) < MODIFF
11480 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11481 && resize_mini_window (w
, 0))
11483 /* Resized active mini-window to fit the size of what it is
11484 showing if its contents might have changed. */
11486 /* FIXME: this causes all frames to be updated, which seems unnecessary
11487 since only the current frame needs to be considered. This function needs
11488 to be rewritten with two variables, consider_all_windows and
11489 consider_all_frames. */
11490 consider_all_windows_p
= 1;
11491 ++windows_or_buffers_changed
;
11492 ++update_mode_lines
;
11494 /* If window configuration was changed, frames may have been
11495 marked garbaged. Clear them or we will experience
11496 surprises wrt scrolling. */
11497 if (frame_garbaged
)
11498 clear_garbaged_frames ();
11502 /* If showing the region, and mark has changed, we must redisplay
11503 the whole window. The assignment to this_line_start_pos prevents
11504 the optimization directly below this if-statement. */
11505 if (((!NILP (Vtransient_mark_mode
)
11506 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11507 != !NILP (w
->region_showing
))
11508 || (!NILP (w
->region_showing
)
11509 && !EQ (w
->region_showing
,
11510 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11511 CHARPOS (this_line_start_pos
) = 0;
11513 /* Optimize the case that only the line containing the cursor in the
11514 selected window has changed. Variables starting with this_ are
11515 set in display_line and record information about the line
11516 containing the cursor. */
11517 tlbufpos
= this_line_start_pos
;
11518 tlendpos
= this_line_end_pos
;
11519 if (!consider_all_windows_p
11520 && CHARPOS (tlbufpos
) > 0
11521 && NILP (w
->update_mode_line
)
11522 && !current_buffer
->clip_changed
11523 && !current_buffer
->prevent_redisplay_optimizations_p
11524 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11525 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11526 /* Make sure recorded data applies to current buffer, etc. */
11527 && this_line_buffer
== current_buffer
11528 && current_buffer
== XBUFFER (w
->buffer
)
11529 && NILP (w
->force_start
)
11530 && NILP (w
->optional_new_start
)
11531 /* Point must be on the line that we have info recorded about. */
11532 && PT
>= CHARPOS (tlbufpos
)
11533 && PT
<= Z
- CHARPOS (tlendpos
)
11534 /* All text outside that line, including its final newline,
11535 must be unchanged. */
11536 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11537 CHARPOS (tlendpos
)))
11539 if (CHARPOS (tlbufpos
) > BEGV
11540 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11541 && (CHARPOS (tlbufpos
) == ZV
11542 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11543 /* Former continuation line has disappeared by becoming empty. */
11545 else if (XFASTINT (w
->last_modified
) < MODIFF
11546 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11547 || MINI_WINDOW_P (w
))
11549 /* We have to handle the case of continuation around a
11550 wide-column character (see the comment in indent.c around
11553 For instance, in the following case:
11555 -------- Insert --------
11556 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11557 J_I_ ==> J_I_ `^^' are cursors.
11561 As we have to redraw the line above, we cannot use this
11565 int line_height_before
= this_line_pixel_height
;
11567 /* Note that start_display will handle the case that the
11568 line starting at tlbufpos is a continuation line. */
11569 start_display (&it
, w
, tlbufpos
);
11571 /* Implementation note: It this still necessary? */
11572 if (it
.current_x
!= this_line_start_x
)
11575 TRACE ((stderr
, "trying display optimization 1\n"));
11576 w
->cursor
.vpos
= -1;
11577 overlay_arrow_seen
= 0;
11578 it
.vpos
= this_line_vpos
;
11579 it
.current_y
= this_line_y
;
11580 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11581 display_line (&it
);
11583 /* If line contains point, is not continued,
11584 and ends at same distance from eob as before, we win. */
11585 if (w
->cursor
.vpos
>= 0
11586 /* Line is not continued, otherwise this_line_start_pos
11587 would have been set to 0 in display_line. */
11588 && CHARPOS (this_line_start_pos
)
11589 /* Line ends as before. */
11590 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11591 /* Line has same height as before. Otherwise other lines
11592 would have to be shifted up or down. */
11593 && this_line_pixel_height
== line_height_before
)
11595 /* If this is not the window's last line, we must adjust
11596 the charstarts of the lines below. */
11597 if (it
.current_y
< it
.last_visible_y
)
11599 struct glyph_row
*row
11600 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11601 int delta
, delta_bytes
;
11603 /* We used to distinguish between two cases here,
11604 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11605 when the line ends in a newline or the end of the
11606 buffer's accessible portion. But both cases did
11607 the same, so they were collapsed. */
11609 - CHARPOS (tlendpos
)
11610 - MATRIX_ROW_START_CHARPOS (row
));
11611 delta_bytes
= (Z_BYTE
11612 - BYTEPOS (tlendpos
)
11613 - MATRIX_ROW_START_BYTEPOS (row
));
11615 increment_matrix_positions (w
->current_matrix
,
11616 this_line_vpos
+ 1,
11617 w
->current_matrix
->nrows
,
11618 delta
, delta_bytes
);
11621 /* If this row displays text now but previously didn't,
11622 or vice versa, w->window_end_vpos may have to be
11624 if ((it
.glyph_row
- 1)->displays_text_p
)
11626 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11627 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11629 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11630 && this_line_vpos
> 0)
11631 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11632 w
->window_end_valid
= Qnil
;
11634 /* Update hint: No need to try to scroll in update_window. */
11635 w
->desired_matrix
->no_scrolling_p
= 1;
11638 *w
->desired_matrix
->method
= 0;
11639 debug_method_add (w
, "optimization 1");
11641 #ifdef HAVE_WINDOW_SYSTEM
11642 update_window_fringes (w
, 0);
11649 else if (/* Cursor position hasn't changed. */
11650 PT
== XFASTINT (w
->last_point
)
11651 /* Make sure the cursor was last displayed
11652 in this window. Otherwise we have to reposition it. */
11653 && 0 <= w
->cursor
.vpos
11654 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11658 do_pending_window_change (1);
11660 /* We used to always goto end_of_redisplay here, but this
11661 isn't enough if we have a blinking cursor. */
11662 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11663 goto end_of_redisplay
;
11667 /* If highlighting the region, or if the cursor is in the echo area,
11668 then we can't just move the cursor. */
11669 else if (! (!NILP (Vtransient_mark_mode
)
11670 && !NILP (current_buffer
->mark_active
))
11671 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11672 || highlight_nonselected_windows
)
11673 && NILP (w
->region_showing
)
11674 && NILP (Vshow_trailing_whitespace
)
11675 && !cursor_in_echo_area
)
11678 struct glyph_row
*row
;
11680 /* Skip from tlbufpos to PT and see where it is. Note that
11681 PT may be in invisible text. If so, we will end at the
11682 next visible position. */
11683 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11684 NULL
, DEFAULT_FACE_ID
);
11685 it
.current_x
= this_line_start_x
;
11686 it
.current_y
= this_line_y
;
11687 it
.vpos
= this_line_vpos
;
11689 /* The call to move_it_to stops in front of PT, but
11690 moves over before-strings. */
11691 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11693 if (it
.vpos
== this_line_vpos
11694 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11697 xassert (this_line_vpos
== it
.vpos
);
11698 xassert (this_line_y
== it
.current_y
);
11699 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11701 *w
->desired_matrix
->method
= 0;
11702 debug_method_add (w
, "optimization 3");
11711 /* Text changed drastically or point moved off of line. */
11712 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11715 CHARPOS (this_line_start_pos
) = 0;
11716 consider_all_windows_p
|= buffer_shared
> 1;
11717 ++clear_face_cache_count
;
11718 #ifdef HAVE_WINDOW_SYSTEM
11719 ++clear_image_cache_count
;
11722 /* Build desired matrices, and update the display. If
11723 consider_all_windows_p is non-zero, do it for all windows on all
11724 frames. Otherwise do it for selected_window, only. */
11726 if (consider_all_windows_p
)
11728 Lisp_Object tail
, frame
;
11730 FOR_EACH_FRAME (tail
, frame
)
11731 XFRAME (frame
)->updated_p
= 0;
11733 /* Recompute # windows showing selected buffer. This will be
11734 incremented each time such a window is displayed. */
11737 FOR_EACH_FRAME (tail
, frame
)
11739 struct frame
*f
= XFRAME (frame
);
11741 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11743 if (! EQ (frame
, selected_frame
))
11744 /* Select the frame, for the sake of frame-local
11746 select_frame_for_redisplay (frame
);
11748 /* Mark all the scroll bars to be removed; we'll redeem
11749 the ones we want when we redisplay their windows. */
11750 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11751 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11753 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11754 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11756 /* The X error handler may have deleted that frame. */
11757 if (!FRAME_LIVE_P (f
))
11760 /* Any scroll bars which redisplay_windows should have
11761 nuked should now go away. */
11762 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11763 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11765 /* If fonts changed, display again. */
11766 /* ??? rms: I suspect it is a mistake to jump all the way
11767 back to retry here. It should just retry this frame. */
11768 if (fonts_changed_p
)
11771 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11773 /* See if we have to hscroll. */
11774 if (!f
->already_hscrolled_p
)
11776 f
->already_hscrolled_p
= 1;
11777 if (hscroll_windows (f
->root_window
))
11781 /* Prevent various kinds of signals during display
11782 update. stdio is not robust about handling
11783 signals, which can cause an apparent I/O
11785 if (interrupt_input
)
11786 unrequest_sigio ();
11789 /* Update the display. */
11790 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11791 pause
|= update_frame (f
, 0, 0);
11797 if (!EQ (old_frame
, selected_frame
)
11798 && FRAME_LIVE_P (XFRAME (old_frame
)))
11799 /* We played a bit fast-and-loose above and allowed selected_frame
11800 and selected_window to be temporarily out-of-sync but let's make
11801 sure this stays contained. */
11802 select_frame_for_redisplay (old_frame
);
11803 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11807 /* Do the mark_window_display_accurate after all windows have
11808 been redisplayed because this call resets flags in buffers
11809 which are needed for proper redisplay. */
11810 FOR_EACH_FRAME (tail
, frame
)
11812 struct frame
*f
= XFRAME (frame
);
11815 mark_window_display_accurate (f
->root_window
, 1);
11816 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11817 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11822 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11824 Lisp_Object mini_window
;
11825 struct frame
*mini_frame
;
11827 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11828 /* Use list_of_error, not Qerror, so that
11829 we catch only errors and don't run the debugger. */
11830 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11832 redisplay_window_error
);
11834 /* Compare desired and current matrices, perform output. */
11837 /* If fonts changed, display again. */
11838 if (fonts_changed_p
)
11841 /* Prevent various kinds of signals during display update.
11842 stdio is not robust about handling signals,
11843 which can cause an apparent I/O error. */
11844 if (interrupt_input
)
11845 unrequest_sigio ();
11848 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11850 if (hscroll_windows (selected_window
))
11853 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11854 pause
= update_frame (sf
, 0, 0);
11857 /* We may have called echo_area_display at the top of this
11858 function. If the echo area is on another frame, that may
11859 have put text on a frame other than the selected one, so the
11860 above call to update_frame would not have caught it. Catch
11862 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11863 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11865 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11867 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11868 pause
|= update_frame (mini_frame
, 0, 0);
11869 if (!pause
&& hscroll_windows (mini_window
))
11874 /* If display was paused because of pending input, make sure we do a
11875 thorough update the next time. */
11878 /* Prevent the optimization at the beginning of
11879 redisplay_internal that tries a single-line update of the
11880 line containing the cursor in the selected window. */
11881 CHARPOS (this_line_start_pos
) = 0;
11883 /* Let the overlay arrow be updated the next time. */
11884 update_overlay_arrows (0);
11886 /* If we pause after scrolling, some rows in the current
11887 matrices of some windows are not valid. */
11888 if (!WINDOW_FULL_WIDTH_P (w
)
11889 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11890 update_mode_lines
= 1;
11894 if (!consider_all_windows_p
)
11896 /* This has already been done above if
11897 consider_all_windows_p is set. */
11898 mark_window_display_accurate_1 (w
, 1);
11900 /* Say overlay arrows are up to date. */
11901 update_overlay_arrows (1);
11903 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11904 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11907 update_mode_lines
= 0;
11908 windows_or_buffers_changed
= 0;
11909 cursor_type_changed
= 0;
11912 /* Start SIGIO interrupts coming again. Having them off during the
11913 code above makes it less likely one will discard output, but not
11914 impossible, since there might be stuff in the system buffer here.
11915 But it is much hairier to try to do anything about that. */
11916 if (interrupt_input
)
11920 /* If a frame has become visible which was not before, redisplay
11921 again, so that we display it. Expose events for such a frame
11922 (which it gets when becoming visible) don't call the parts of
11923 redisplay constructing glyphs, so simply exposing a frame won't
11924 display anything in this case. So, we have to display these
11925 frames here explicitly. */
11928 Lisp_Object tail
, frame
;
11931 FOR_EACH_FRAME (tail
, frame
)
11933 int this_is_visible
= 0;
11935 if (XFRAME (frame
)->visible
)
11936 this_is_visible
= 1;
11937 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11938 if (XFRAME (frame
)->visible
)
11939 this_is_visible
= 1;
11941 if (this_is_visible
)
11945 if (new_count
!= number_of_visible_frames
)
11946 windows_or_buffers_changed
++;
11949 /* Change frame size now if a change is pending. */
11950 do_pending_window_change (1);
11952 /* If we just did a pending size change, or have additional
11953 visible frames, redisplay again. */
11954 if (windows_or_buffers_changed
&& !pause
)
11957 /* Clear the face cache eventually. */
11958 if (consider_all_windows_p
)
11960 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11962 clear_face_cache (0);
11963 clear_face_cache_count
= 0;
11965 #ifdef HAVE_WINDOW_SYSTEM
11966 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11968 clear_image_caches (Qnil
);
11969 clear_image_cache_count
= 0;
11971 #endif /* HAVE_WINDOW_SYSTEM */
11975 unbind_to (count
, Qnil
);
11980 /* Redisplay, but leave alone any recent echo area message unless
11981 another message has been requested in its place.
11983 This is useful in situations where you need to redisplay but no
11984 user action has occurred, making it inappropriate for the message
11985 area to be cleared. See tracking_off and
11986 wait_reading_process_output for examples of these situations.
11988 FROM_WHERE is an integer saying from where this function was
11989 called. This is useful for debugging. */
11992 redisplay_preserve_echo_area (from_where
)
11995 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11997 if (!NILP (echo_area_buffer
[1]))
11999 /* We have a previously displayed message, but no current
12000 message. Redisplay the previous message. */
12001 display_last_displayed_message_p
= 1;
12002 redisplay_internal (1);
12003 display_last_displayed_message_p
= 0;
12006 redisplay_internal (1);
12008 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12009 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12010 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12014 /* Function registered with record_unwind_protect in
12015 redisplay_internal. Reset redisplaying_p to the value it had
12016 before redisplay_internal was called, and clear
12017 prevent_freeing_realized_faces_p. It also selects the previously
12018 selected frame, unless it has been deleted (by an X connection
12019 failure during redisplay, for example). */
12022 unwind_redisplay (val
)
12025 Lisp_Object old_redisplaying_p
, old_frame
;
12027 old_redisplaying_p
= XCAR (val
);
12028 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12029 old_frame
= XCDR (val
);
12030 if (! EQ (old_frame
, selected_frame
)
12031 && FRAME_LIVE_P (XFRAME (old_frame
)))
12032 select_frame_for_redisplay (old_frame
);
12037 /* Mark the display of window W as accurate or inaccurate. If
12038 ACCURATE_P is non-zero mark display of W as accurate. If
12039 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12040 redisplay_internal is called. */
12043 mark_window_display_accurate_1 (w
, accurate_p
)
12047 if (BUFFERP (w
->buffer
))
12049 struct buffer
*b
= XBUFFER (w
->buffer
);
12052 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12053 w
->last_overlay_modified
12054 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12056 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12060 b
->clip_changed
= 0;
12061 b
->prevent_redisplay_optimizations_p
= 0;
12063 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12064 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12065 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12066 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12068 w
->current_matrix
->buffer
= b
;
12069 w
->current_matrix
->begv
= BUF_BEGV (b
);
12070 w
->current_matrix
->zv
= BUF_ZV (b
);
12072 w
->last_cursor
= w
->cursor
;
12073 w
->last_cursor_off_p
= w
->cursor_off_p
;
12075 if (w
== XWINDOW (selected_window
))
12076 w
->last_point
= make_number (BUF_PT (b
));
12078 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12084 w
->window_end_valid
= w
->buffer
;
12085 w
->update_mode_line
= Qnil
;
12090 /* Mark the display of windows in the window tree rooted at WINDOW as
12091 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12092 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12093 be redisplayed the next time redisplay_internal is called. */
12096 mark_window_display_accurate (window
, accurate_p
)
12097 Lisp_Object window
;
12102 for (; !NILP (window
); window
= w
->next
)
12104 w
= XWINDOW (window
);
12105 mark_window_display_accurate_1 (w
, accurate_p
);
12107 if (!NILP (w
->vchild
))
12108 mark_window_display_accurate (w
->vchild
, accurate_p
);
12109 if (!NILP (w
->hchild
))
12110 mark_window_display_accurate (w
->hchild
, accurate_p
);
12115 update_overlay_arrows (1);
12119 /* Force a thorough redisplay the next time by setting
12120 last_arrow_position and last_arrow_string to t, which is
12121 unequal to any useful value of Voverlay_arrow_... */
12122 update_overlay_arrows (-1);
12127 /* Return value in display table DP (Lisp_Char_Table *) for character
12128 C. Since a display table doesn't have any parent, we don't have to
12129 follow parent. Do not call this function directly but use the
12130 macro DISP_CHAR_VECTOR. */
12133 disp_char_vector (dp
, c
)
12134 struct Lisp_Char_Table
*dp
;
12139 if (ASCII_CHAR_P (c
))
12142 if (SUB_CHAR_TABLE_P (val
))
12143 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12149 XSETCHAR_TABLE (table
, dp
);
12150 val
= char_table_ref (table
, c
);
12159 /***********************************************************************
12161 ***********************************************************************/
12163 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12166 redisplay_windows (window
)
12167 Lisp_Object window
;
12169 while (!NILP (window
))
12171 struct window
*w
= XWINDOW (window
);
12173 if (!NILP (w
->hchild
))
12174 redisplay_windows (w
->hchild
);
12175 else if (!NILP (w
->vchild
))
12176 redisplay_windows (w
->vchild
);
12177 else if (!NILP (w
->buffer
))
12179 displayed_buffer
= XBUFFER (w
->buffer
);
12180 /* Use list_of_error, not Qerror, so that
12181 we catch only errors and don't run the debugger. */
12182 internal_condition_case_1 (redisplay_window_0
, window
,
12184 redisplay_window_error
);
12192 redisplay_window_error ()
12194 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12199 redisplay_window_0 (window
)
12200 Lisp_Object window
;
12202 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12203 redisplay_window (window
, 0);
12208 redisplay_window_1 (window
)
12209 Lisp_Object window
;
12211 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12212 redisplay_window (window
, 1);
12217 /* Increment GLYPH until it reaches END or CONDITION fails while
12218 adding (GLYPH)->pixel_width to X. */
12220 #define SKIP_GLYPHS(glyph, end, x, condition) \
12223 (x) += (glyph)->pixel_width; \
12226 while ((glyph) < (end) && (condition))
12229 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12230 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12231 which positions recorded in ROW differ from current buffer
12234 Return 0 if cursor is not on this row, 1 otherwise. */
12237 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12239 struct glyph_row
*row
;
12240 struct glyph_matrix
*matrix
;
12241 int delta
, delta_bytes
, dy
, dvpos
;
12243 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12244 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12245 struct glyph
*cursor
= NULL
;
12246 /* The first glyph that starts a sequence of glyphs from a string
12247 that is a value of a display property. */
12248 struct glyph
*string_start
;
12249 /* The X coordinate of string_start. */
12250 int string_start_x
;
12251 /* The last known character position in row. */
12252 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12253 /* The last known character position before string_start. */
12254 int string_before_pos
;
12257 /* Last buffer position covered by an overlay. */
12258 int cursor_from_overlay_pos
= 0;
12259 int pt_old
= PT
- delta
;
12261 /* Skip over glyphs not having an object at the start of the row.
12262 These are special glyphs like truncation marks on terminal
12264 if (row
->displays_text_p
)
12266 && INTEGERP (glyph
->object
)
12267 && glyph
->charpos
< 0)
12269 x
+= glyph
->pixel_width
;
12273 string_start
= NULL
;
12275 && !INTEGERP (glyph
->object
)
12276 && (!BUFFERP (glyph
->object
)
12277 || (last_pos
= glyph
->charpos
) < pt_old
12278 || glyph
->avoid_cursor_p
))
12280 if (! STRINGP (glyph
->object
))
12282 string_start
= NULL
;
12283 x
+= glyph
->pixel_width
;
12285 /* If we are beyond the cursor position computed from the
12286 last overlay seen, that overlay is not in effect for
12287 current cursor position. Reset the cursor information
12288 computed from that overlay. */
12289 if (cursor_from_overlay_pos
12290 && last_pos
>= cursor_from_overlay_pos
)
12292 cursor_from_overlay_pos
= 0;
12298 if (string_start
== NULL
)
12300 string_before_pos
= last_pos
;
12301 string_start
= glyph
;
12302 string_start_x
= x
;
12304 /* Skip all glyphs from a string. */
12309 if ((cursor
== NULL
|| glyph
> cursor
)
12310 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12311 Qcursor
, (glyph
)->object
),
12313 && (pos
= string_buffer_position (w
, glyph
->object
,
12314 string_before_pos
),
12315 (pos
== 0 /* from overlay */
12316 || pos
== pt_old
)))
12318 /* Compute the first buffer position after the overlay.
12319 If the `cursor' property tells us how many positions
12320 are associated with the overlay, use that. Otherwise,
12321 estimate from the buffer positions of the glyphs
12322 before and after the overlay. */
12323 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12324 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12328 x
+= glyph
->pixel_width
;
12331 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12335 if (cursor
!= NULL
)
12340 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12342 /* Scan back over the ellipsis glyphs, decrementing positions. */
12343 while (glyph
> row
->glyphs
[TEXT_AREA
]
12344 && (glyph
- 1)->charpos
== last_pos
)
12345 glyph
--, x
-= glyph
->pixel_width
;
12346 /* That loop always goes one position too far, including the
12347 glyph before the ellipsis. So scan forward over that one. */
12348 x
+= glyph
->pixel_width
;
12351 else if (string_start
12352 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12354 /* We may have skipped over point because the previous glyphs
12355 are from string. As there's no easy way to know the
12356 character position of the current glyph, find the correct
12357 glyph on point by scanning from string_start again. */
12359 Lisp_Object string
;
12360 struct glyph
*stop
= glyph
;
12363 limit
= make_number (pt_old
+ 1);
12364 glyph
= string_start
;
12365 x
= string_start_x
;
12366 string
= glyph
->object
;
12367 pos
= string_buffer_position (w
, string
, string_before_pos
);
12368 /* If POS == 0, STRING is from overlay. We skip such glyphs
12369 because we always put the cursor after overlay strings. */
12370 while (pos
== 0 && glyph
< stop
)
12372 string
= glyph
->object
;
12373 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12375 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12378 while (glyph
< stop
)
12380 pos
= XINT (Fnext_single_char_property_change
12381 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12384 /* Skip glyphs from the same string. */
12385 string
= glyph
->object
;
12386 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12387 /* Skip glyphs from an overlay. */
12388 while (glyph
< stop
12389 && ! string_buffer_position (w
, glyph
->object
, pos
))
12391 string
= glyph
->object
;
12392 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12396 /* If we reached the end of the line, and END was from a string,
12397 the cursor is not on this line. */
12398 if (glyph
== end
&& row
->continued_p
)
12402 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12404 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12405 w
->cursor
.y
= row
->y
+ dy
;
12407 if (w
== XWINDOW (selected_window
))
12409 if (!row
->continued_p
12410 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12413 this_line_buffer
= XBUFFER (w
->buffer
);
12415 CHARPOS (this_line_start_pos
)
12416 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12417 BYTEPOS (this_line_start_pos
)
12418 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12420 CHARPOS (this_line_end_pos
)
12421 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12422 BYTEPOS (this_line_end_pos
)
12423 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12425 this_line_y
= w
->cursor
.y
;
12426 this_line_pixel_height
= row
->height
;
12427 this_line_vpos
= w
->cursor
.vpos
;
12428 this_line_start_x
= row
->x
;
12431 CHARPOS (this_line_start_pos
) = 0;
12438 /* Run window scroll functions, if any, for WINDOW with new window
12439 start STARTP. Sets the window start of WINDOW to that position.
12441 We assume that the window's buffer is really current. */
12443 static INLINE
struct text_pos
12444 run_window_scroll_functions (window
, startp
)
12445 Lisp_Object window
;
12446 struct text_pos startp
;
12448 struct window
*w
= XWINDOW (window
);
12449 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12451 if (current_buffer
!= XBUFFER (w
->buffer
))
12454 if (!NILP (Vwindow_scroll_functions
))
12456 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12457 make_number (CHARPOS (startp
)));
12458 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12459 /* In case the hook functions switch buffers. */
12460 if (current_buffer
!= XBUFFER (w
->buffer
))
12461 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12468 /* Make sure the line containing the cursor is fully visible.
12469 A value of 1 means there is nothing to be done.
12470 (Either the line is fully visible, or it cannot be made so,
12471 or we cannot tell.)
12473 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12474 is higher than window.
12476 A value of 0 means the caller should do scrolling
12477 as if point had gone off the screen. */
12480 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12483 int current_matrix_p
;
12485 struct glyph_matrix
*matrix
;
12486 struct glyph_row
*row
;
12489 if (!make_cursor_line_fully_visible_p
)
12492 /* It's not always possible to find the cursor, e.g, when a window
12493 is full of overlay strings. Don't do anything in that case. */
12494 if (w
->cursor
.vpos
< 0)
12497 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12498 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12500 /* If the cursor row is not partially visible, there's nothing to do. */
12501 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12504 /* If the row the cursor is in is taller than the window's height,
12505 it's not clear what to do, so do nothing. */
12506 window_height
= window_box_height (w
);
12507 if (row
->height
>= window_height
)
12509 if (!force_p
|| MINI_WINDOW_P (w
)
12510 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12517 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12518 non-zero means only WINDOW is redisplayed in redisplay_internal.
12519 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12520 in redisplay_window to bring a partially visible line into view in
12521 the case that only the cursor has moved.
12523 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12524 last screen line's vertical height extends past the end of the screen.
12528 1 if scrolling succeeded
12530 0 if scrolling didn't find point.
12532 -1 if new fonts have been loaded so that we must interrupt
12533 redisplay, adjust glyph matrices, and try again. */
12539 SCROLLING_NEED_LARGER_MATRICES
12543 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12544 scroll_step
, temp_scroll_step
, last_line_misfit
)
12545 Lisp_Object window
;
12546 int just_this_one_p
;
12547 EMACS_INT scroll_conservatively
, scroll_step
;
12548 int temp_scroll_step
;
12549 int last_line_misfit
;
12551 struct window
*w
= XWINDOW (window
);
12552 struct frame
*f
= XFRAME (w
->frame
);
12553 struct text_pos pos
, startp
;
12555 int this_scroll_margin
, scroll_max
, rc
, height
;
12556 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12557 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12558 Lisp_Object aggressive
;
12559 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12562 debug_method_add (w
, "try_scrolling");
12565 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12567 /* Compute scroll margin height in pixels. We scroll when point is
12568 within this distance from the top or bottom of the window. */
12569 if (scroll_margin
> 0)
12570 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
12571 * FRAME_LINE_HEIGHT (f
);
12573 this_scroll_margin
= 0;
12575 /* Force scroll_conservatively to have a reasonable value, to avoid
12576 overflow while computing how much to scroll. Note that the user
12577 can supply scroll-conservatively equal to `most-positive-fixnum',
12578 which can be larger than INT_MAX. */
12579 if (scroll_conservatively
> scroll_limit
)
12581 scroll_conservatively
= scroll_limit
;
12582 scroll_max
= INT_MAX
;
12584 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12585 /* Compute how much we should try to scroll maximally to bring
12586 point into view. */
12587 scroll_max
= (max (scroll_step
,
12588 max (scroll_conservatively
, temp_scroll_step
))
12589 * FRAME_LINE_HEIGHT (f
));
12590 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12591 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12592 /* We're trying to scroll because of aggressive scrolling but no
12593 scroll_step is set. Choose an arbitrary one. */
12594 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12600 /* Decide whether to scroll down. */
12601 if (PT
> CHARPOS (startp
))
12603 int scroll_margin_y
;
12605 /* Compute the pixel ypos of the scroll margin, then move it to
12606 either that ypos or PT, whichever comes first. */
12607 start_display (&it
, w
, startp
);
12608 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12609 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12610 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12611 (MOVE_TO_POS
| MOVE_TO_Y
));
12613 if (PT
> CHARPOS (it
.current
.pos
))
12615 int y0
= line_bottom_y (&it
);
12617 /* Compute the distance from the scroll margin to PT
12618 (including the height of the cursor line). Moving the
12619 iterator unconditionally to PT can be slow if PT is far
12620 away, so stop 10 lines past the window bottom (is there a
12621 way to do the right thing quickly?). */
12622 move_it_to (&it
, PT
, -1,
12623 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
12624 -1, MOVE_TO_POS
| MOVE_TO_Y
);
12625 dy
= line_bottom_y (&it
) - y0
;
12627 if (dy
> scroll_max
)
12628 return SCROLLING_FAILED
;
12636 /* Point is in or below the bottom scroll margin, so move the
12637 window start down. If scrolling conservatively, move it just
12638 enough down to make point visible. If scroll_step is set,
12639 move it down by scroll_step. */
12640 if (scroll_conservatively
)
12642 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12643 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12644 else if (scroll_step
|| temp_scroll_step
)
12645 amount_to_scroll
= scroll_max
;
12648 aggressive
= current_buffer
->scroll_up_aggressively
;
12649 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12650 if (NUMBERP (aggressive
))
12652 double float_amount
= XFLOATINT (aggressive
) * height
;
12653 amount_to_scroll
= float_amount
;
12654 if (amount_to_scroll
== 0 && float_amount
> 0)
12655 amount_to_scroll
= 1;
12659 if (amount_to_scroll
<= 0)
12660 return SCROLLING_FAILED
;
12662 start_display (&it
, w
, startp
);
12663 move_it_vertically (&it
, amount_to_scroll
);
12665 /* If STARTP is unchanged, move it down another screen line. */
12666 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12667 move_it_by_lines (&it
, 1, 1);
12668 startp
= it
.current
.pos
;
12672 struct text_pos scroll_margin_pos
= startp
;
12674 /* See if point is inside the scroll margin at the top of the
12676 if (this_scroll_margin
)
12678 start_display (&it
, w
, startp
);
12679 move_it_vertically (&it
, this_scroll_margin
);
12680 scroll_margin_pos
= it
.current
.pos
;
12683 if (PT
< CHARPOS (scroll_margin_pos
))
12685 /* Point is in the scroll margin at the top of the window or
12686 above what is displayed in the window. */
12689 /* Compute the vertical distance from PT to the scroll
12690 margin position. Give up if distance is greater than
12692 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12693 start_display (&it
, w
, pos
);
12695 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12696 it
.last_visible_y
, -1,
12697 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12698 dy
= it
.current_y
- y0
;
12699 if (dy
> scroll_max
)
12700 return SCROLLING_FAILED
;
12702 /* Compute new window start. */
12703 start_display (&it
, w
, startp
);
12705 if (scroll_conservatively
)
12707 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12708 else if (scroll_step
|| temp_scroll_step
)
12709 amount_to_scroll
= scroll_max
;
12712 aggressive
= current_buffer
->scroll_down_aggressively
;
12713 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12714 if (NUMBERP (aggressive
))
12716 double float_amount
= XFLOATINT (aggressive
) * height
;
12717 amount_to_scroll
= float_amount
;
12718 if (amount_to_scroll
== 0 && float_amount
> 0)
12719 amount_to_scroll
= 1;
12723 if (amount_to_scroll
<= 0)
12724 return SCROLLING_FAILED
;
12726 move_it_vertically_backward (&it
, amount_to_scroll
);
12727 startp
= it
.current
.pos
;
12731 /* Run window scroll functions. */
12732 startp
= run_window_scroll_functions (window
, startp
);
12734 /* Display the window. Give up if new fonts are loaded, or if point
12736 if (!try_window (window
, startp
, 0))
12737 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12738 else if (w
->cursor
.vpos
< 0)
12740 clear_glyph_matrix (w
->desired_matrix
);
12741 rc
= SCROLLING_FAILED
;
12745 /* Maybe forget recorded base line for line number display. */
12746 if (!just_this_one_p
12747 || current_buffer
->clip_changed
12748 || BEG_UNCHANGED
< CHARPOS (startp
))
12749 w
->base_line_number
= Qnil
;
12751 /* If cursor ends up on a partially visible line,
12752 treat that as being off the bottom of the screen. */
12753 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
12754 /* It's possible that the cursor is on the first line of the
12755 buffer, which is partially obscured due to a vscroll
12756 (Bug#7537). In that case, avoid looping forever . */
12757 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
12759 clear_glyph_matrix (w
->desired_matrix
);
12760 ++extra_scroll_margin_lines
;
12763 rc
= SCROLLING_SUCCESS
;
12770 /* Compute a suitable window start for window W if display of W starts
12771 on a continuation line. Value is non-zero if a new window start
12774 The new window start will be computed, based on W's width, starting
12775 from the start of the continued line. It is the start of the
12776 screen line with the minimum distance from the old start W->start. */
12779 compute_window_start_on_continuation_line (w
)
12782 struct text_pos pos
, start_pos
;
12783 int window_start_changed_p
= 0;
12785 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12787 /* If window start is on a continuation line... Window start may be
12788 < BEGV in case there's invisible text at the start of the
12789 buffer (M-x rmail, for example). */
12790 if (CHARPOS (start_pos
) > BEGV
12791 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12794 struct glyph_row
*row
;
12796 /* Handle the case that the window start is out of range. */
12797 if (CHARPOS (start_pos
) < BEGV
)
12798 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12799 else if (CHARPOS (start_pos
) > ZV
)
12800 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12802 /* Find the start of the continued line. This should be fast
12803 because scan_buffer is fast (newline cache). */
12804 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12805 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12806 row
, DEFAULT_FACE_ID
);
12807 reseat_at_previous_visible_line_start (&it
);
12809 /* If the line start is "too far" away from the window start,
12810 say it takes too much time to compute a new window start. */
12811 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12812 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12814 int min_distance
, distance
;
12816 /* Move forward by display lines to find the new window
12817 start. If window width was enlarged, the new start can
12818 be expected to be > the old start. If window width was
12819 decreased, the new window start will be < the old start.
12820 So, we're looking for the display line start with the
12821 minimum distance from the old window start. */
12822 pos
= it
.current
.pos
;
12823 min_distance
= INFINITY
;
12824 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12825 distance
< min_distance
)
12827 min_distance
= distance
;
12828 pos
= it
.current
.pos
;
12829 move_it_by_lines (&it
, 1, 0);
12832 /* Set the window start there. */
12833 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12834 window_start_changed_p
= 1;
12838 return window_start_changed_p
;
12842 /* Try cursor movement in case text has not changed in window WINDOW,
12843 with window start STARTP. Value is
12845 CURSOR_MOVEMENT_SUCCESS if successful
12847 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12849 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12850 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12851 we want to scroll as if scroll-step were set to 1. See the code.
12853 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12854 which case we have to abort this redisplay, and adjust matrices
12859 CURSOR_MOVEMENT_SUCCESS
,
12860 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12861 CURSOR_MOVEMENT_MUST_SCROLL
,
12862 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12866 try_cursor_movement (window
, startp
, scroll_step
)
12867 Lisp_Object window
;
12868 struct text_pos startp
;
12871 struct window
*w
= XWINDOW (window
);
12872 struct frame
*f
= XFRAME (w
->frame
);
12873 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12876 if (inhibit_try_cursor_movement
)
12880 /* Handle case where text has not changed, only point, and it has
12881 not moved off the frame. */
12882 if (/* Point may be in this window. */
12883 PT
>= CHARPOS (startp
)
12884 /* Selective display hasn't changed. */
12885 && !current_buffer
->clip_changed
12886 /* Function force-mode-line-update is used to force a thorough
12887 redisplay. It sets either windows_or_buffers_changed or
12888 update_mode_lines. So don't take a shortcut here for these
12890 && !update_mode_lines
12891 && !windows_or_buffers_changed
12892 && !cursor_type_changed
12893 /* Can't use this case if highlighting a region. When a
12894 region exists, cursor movement has to do more than just
12896 && !(!NILP (Vtransient_mark_mode
)
12897 && !NILP (current_buffer
->mark_active
))
12898 && NILP (w
->region_showing
)
12899 && NILP (Vshow_trailing_whitespace
)
12900 /* Right after splitting windows, last_point may be nil. */
12901 && INTEGERP (w
->last_point
)
12902 /* This code is not used for mini-buffer for the sake of the case
12903 of redisplaying to replace an echo area message; since in
12904 that case the mini-buffer contents per se are usually
12905 unchanged. This code is of no real use in the mini-buffer
12906 since the handling of this_line_start_pos, etc., in redisplay
12907 handles the same cases. */
12908 && !EQ (window
, minibuf_window
)
12909 /* When splitting windows or for new windows, it happens that
12910 redisplay is called with a nil window_end_vpos or one being
12911 larger than the window. This should really be fixed in
12912 window.c. I don't have this on my list, now, so we do
12913 approximately the same as the old redisplay code. --gerd. */
12914 && INTEGERP (w
->window_end_vpos
)
12915 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12916 && (FRAME_WINDOW_P (f
)
12917 || !overlay_arrow_in_current_buffer_p ()))
12919 int this_scroll_margin
, top_scroll_margin
;
12920 struct glyph_row
*row
= NULL
;
12923 debug_method_add (w
, "cursor movement");
12926 /* Scroll if point within this distance from the top or bottom
12927 of the window. This is a pixel value. */
12928 if (scroll_margin
> 0)
12930 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12931 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12934 this_scroll_margin
= 0;
12936 top_scroll_margin
= this_scroll_margin
;
12937 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12938 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12940 /* Start with the row the cursor was displayed during the last
12941 not paused redisplay. Give up if that row is not valid. */
12942 if (w
->last_cursor
.vpos
< 0
12943 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12944 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12947 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12948 if (row
->mode_line_p
)
12950 if (!row
->enabled_p
)
12951 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12954 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12957 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12959 if (PT
> XFASTINT (w
->last_point
))
12961 /* Point has moved forward. */
12962 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12963 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12965 xassert (row
->enabled_p
);
12969 /* The end position of a row equals the start position
12970 of the next row. If PT is there, we would rather
12971 display it in the next line. */
12972 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12973 && MATRIX_ROW_END_CHARPOS (row
) == PT
12974 && !cursor_row_p (w
, row
))
12977 /* If within the scroll margin, scroll. Note that
12978 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12979 the next line would be drawn, and that
12980 this_scroll_margin can be zero. */
12981 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12982 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12983 /* Line is completely visible last line in window
12984 and PT is to be set in the next line. */
12985 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12986 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12987 && !row
->ends_at_zv_p
12988 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12991 else if (PT
< XFASTINT (w
->last_point
))
12993 /* Cursor has to be moved backward. Note that PT >=
12994 CHARPOS (startp) because of the outer if-statement. */
12995 while (!row
->mode_line_p
12996 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12997 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12998 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12999 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13000 row
> w
->current_matrix
->rows
13001 && (row
-1)->ends_in_newline_from_string_p
))))
13002 && (row
->y
> top_scroll_margin
13003 || CHARPOS (startp
) == BEGV
))
13005 xassert (row
->enabled_p
);
13009 /* Consider the following case: Window starts at BEGV,
13010 there is invisible, intangible text at BEGV, so that
13011 display starts at some point START > BEGV. It can
13012 happen that we are called with PT somewhere between
13013 BEGV and START. Try to handle that case. */
13014 if (row
< w
->current_matrix
->rows
13015 || row
->mode_line_p
)
13017 row
= w
->current_matrix
->rows
;
13018 if (row
->mode_line_p
)
13022 /* Due to newlines in overlay strings, we may have to
13023 skip forward over overlay strings. */
13024 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13025 && MATRIX_ROW_END_CHARPOS (row
) == PT
13026 && !cursor_row_p (w
, row
))
13029 /* If within the scroll margin, scroll. */
13030 if (row
->y
< top_scroll_margin
13031 && CHARPOS (startp
) != BEGV
)
13036 /* Cursor did not move. So don't scroll even if cursor line
13037 is partially visible, as it was so before. */
13038 rc
= CURSOR_MOVEMENT_SUCCESS
;
13041 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13042 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13044 /* if PT is not in the glyph row, give up. */
13045 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13047 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13048 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13049 && make_cursor_line_fully_visible_p
)
13051 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13052 && !row
->ends_at_zv_p
13053 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13054 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13055 else if (row
->height
> window_box_height (w
))
13057 /* If we end up in a partially visible line, let's
13058 make it fully visible, except when it's taller
13059 than the window, in which case we can't do much
13062 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13066 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13067 if (!cursor_row_fully_visible_p (w
, 0, 1))
13068 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13070 rc
= CURSOR_MOVEMENT_SUCCESS
;
13074 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13079 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13081 rc
= CURSOR_MOVEMENT_SUCCESS
;
13086 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13087 && MATRIX_ROW_START_CHARPOS (row
) == PT
13088 && cursor_row_p (w
, row
));
13097 set_vertical_scroll_bar (w
)
13100 int start
, end
, whole
;
13102 /* Calculate the start and end positions for the current window.
13103 At some point, it would be nice to choose between scrollbars
13104 which reflect the whole buffer size, with special markers
13105 indicating narrowing, and scrollbars which reflect only the
13108 Note that mini-buffers sometimes aren't displaying any text. */
13109 if (!MINI_WINDOW_P (w
)
13110 || (w
== XWINDOW (minibuf_window
)
13111 && NILP (echo_area_buffer
[0])))
13113 struct buffer
*buf
= XBUFFER (w
->buffer
);
13114 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13115 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13116 /* I don't think this is guaranteed to be right. For the
13117 moment, we'll pretend it is. */
13118 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13122 if (whole
< (end
- start
))
13123 whole
= end
- start
;
13126 start
= end
= whole
= 0;
13128 /* Indicate what this scroll bar ought to be displaying now. */
13129 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13130 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13131 (w
, end
- start
, whole
, start
);
13135 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13136 selected_window is redisplayed.
13138 We can return without actually redisplaying the window if
13139 fonts_changed_p is nonzero. In that case, redisplay_internal will
13143 redisplay_window (window
, just_this_one_p
)
13144 Lisp_Object window
;
13145 int just_this_one_p
;
13147 struct window
*w
= XWINDOW (window
);
13148 struct frame
*f
= XFRAME (w
->frame
);
13149 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13150 struct buffer
*old
= current_buffer
;
13151 struct text_pos lpoint
, opoint
, startp
;
13152 int update_mode_line
;
13155 /* Record it now because it's overwritten. */
13156 int current_matrix_up_to_date_p
= 0;
13157 int used_current_matrix_p
= 0;
13158 /* This is less strict than current_matrix_up_to_date_p.
13159 It indictes that the buffer contents and narrowing are unchanged. */
13160 int buffer_unchanged_p
= 0;
13161 int temp_scroll_step
= 0;
13162 int count
= SPECPDL_INDEX ();
13164 int centering_position
= -1;
13165 int last_line_misfit
= 0;
13166 int beg_unchanged
, end_unchanged
;
13168 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13171 /* W must be a leaf window here. */
13172 xassert (!NILP (w
->buffer
));
13174 *w
->desired_matrix
->method
= 0;
13178 reconsider_clip_changes (w
, buffer
);
13180 /* Has the mode line to be updated? */
13181 update_mode_line
= (!NILP (w
->update_mode_line
)
13182 || update_mode_lines
13183 || buffer
->clip_changed
13184 || buffer
->prevent_redisplay_optimizations_p
);
13186 if (MINI_WINDOW_P (w
))
13188 if (w
== XWINDOW (echo_area_window
)
13189 && !NILP (echo_area_buffer
[0]))
13191 if (update_mode_line
)
13192 /* We may have to update a tty frame's menu bar or a
13193 tool-bar. Example `M-x C-h C-h C-g'. */
13194 goto finish_menu_bars
;
13196 /* We've already displayed the echo area glyphs in this window. */
13197 goto finish_scroll_bars
;
13199 else if ((w
!= XWINDOW (minibuf_window
)
13200 || minibuf_level
== 0)
13201 /* When buffer is nonempty, redisplay window normally. */
13202 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13203 /* Quail displays non-mini buffers in minibuffer window.
13204 In that case, redisplay the window normally. */
13205 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13207 /* W is a mini-buffer window, but it's not active, so clear
13209 int yb
= window_text_bottom_y (w
);
13210 struct glyph_row
*row
;
13213 for (y
= 0, row
= w
->desired_matrix
->rows
;
13215 y
+= row
->height
, ++row
)
13216 blank_row (w
, row
, y
);
13217 goto finish_scroll_bars
;
13220 clear_glyph_matrix (w
->desired_matrix
);
13223 /* Otherwise set up data on this window; select its buffer and point
13225 /* Really select the buffer, for the sake of buffer-local
13227 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13229 current_matrix_up_to_date_p
13230 = (!NILP (w
->window_end_valid
)
13231 && !current_buffer
->clip_changed
13232 && !current_buffer
->prevent_redisplay_optimizations_p
13233 && XFASTINT (w
->last_modified
) >= MODIFF
13234 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13236 /* Run the window-bottom-change-functions
13237 if it is possible that the text on the screen has changed
13238 (either due to modification of the text, or any other reason). */
13239 if (!current_matrix_up_to_date_p
13240 && !NILP (Vwindow_text_change_functions
))
13242 safe_run_hooks (Qwindow_text_change_functions
);
13246 beg_unchanged
= BEG_UNCHANGED
;
13247 end_unchanged
= END_UNCHANGED
;
13249 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13251 specbind (Qinhibit_point_motion_hooks
, Qt
);
13254 = (!NILP (w
->window_end_valid
)
13255 && !current_buffer
->clip_changed
13256 && XFASTINT (w
->last_modified
) >= MODIFF
13257 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13259 /* When windows_or_buffers_changed is non-zero, we can't rely on
13260 the window end being valid, so set it to nil there. */
13261 if (windows_or_buffers_changed
)
13263 /* If window starts on a continuation line, maybe adjust the
13264 window start in case the window's width changed. */
13265 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13266 compute_window_start_on_continuation_line (w
);
13268 w
->window_end_valid
= Qnil
;
13271 /* Some sanity checks. */
13272 CHECK_WINDOW_END (w
);
13273 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13275 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13278 /* If %c is in mode line, update it if needed. */
13279 if (!NILP (w
->column_number_displayed
)
13280 /* This alternative quickly identifies a common case
13281 where no change is needed. */
13282 && !(PT
== XFASTINT (w
->last_point
)
13283 && XFASTINT (w
->last_modified
) >= MODIFF
13284 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13285 && (XFASTINT (w
->column_number_displayed
)
13286 != (int) current_column ())) /* iftc */
13287 update_mode_line
= 1;
13289 /* Count number of windows showing the selected buffer. An indirect
13290 buffer counts as its base buffer. */
13291 if (!just_this_one_p
)
13293 struct buffer
*current_base
, *window_base
;
13294 current_base
= current_buffer
;
13295 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13296 if (current_base
->base_buffer
)
13297 current_base
= current_base
->base_buffer
;
13298 if (window_base
->base_buffer
)
13299 window_base
= window_base
->base_buffer
;
13300 if (current_base
== window_base
)
13304 /* Point refers normally to the selected window. For any other
13305 window, set up appropriate value. */
13306 if (!EQ (window
, selected_window
))
13308 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13309 int new_pt_byte
= marker_byte_position (w
->pointm
);
13313 new_pt_byte
= BEGV_BYTE
;
13314 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13316 else if (new_pt
> (ZV
- 1))
13319 new_pt_byte
= ZV_BYTE
;
13320 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13323 /* We don't use SET_PT so that the point-motion hooks don't run. */
13324 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13327 /* If any of the character widths specified in the display table
13328 have changed, invalidate the width run cache. It's true that
13329 this may be a bit late to catch such changes, but the rest of
13330 redisplay goes (non-fatally) haywire when the display table is
13331 changed, so why should we worry about doing any better? */
13332 if (current_buffer
->width_run_cache
)
13334 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13336 if (! disptab_matches_widthtab (disptab
,
13337 XVECTOR (current_buffer
->width_table
)))
13339 invalidate_region_cache (current_buffer
,
13340 current_buffer
->width_run_cache
,
13342 recompute_width_table (current_buffer
, disptab
);
13346 /* If window-start is screwed up, choose a new one. */
13347 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13350 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13352 /* If someone specified a new starting point but did not insist,
13353 check whether it can be used. */
13354 if (!NILP (w
->optional_new_start
)
13355 && CHARPOS (startp
) >= BEGV
13356 && CHARPOS (startp
) <= ZV
)
13358 w
->optional_new_start
= Qnil
;
13359 start_display (&it
, w
, startp
);
13360 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13361 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13362 if (IT_CHARPOS (it
) == PT
)
13363 w
->force_start
= Qt
;
13364 /* IT may overshoot PT if text at PT is invisible. */
13365 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13366 w
->force_start
= Qt
;
13371 /* Handle case where place to start displaying has been specified,
13372 unless the specified location is outside the accessible range. */
13373 if (!NILP (w
->force_start
)
13374 || w
->frozen_window_start_p
)
13376 /* We set this later on if we have to adjust point. */
13379 w
->force_start
= Qnil
;
13381 w
->window_end_valid
= Qnil
;
13383 /* Forget any recorded base line for line number display. */
13384 if (!buffer_unchanged_p
)
13385 w
->base_line_number
= Qnil
;
13387 /* Redisplay the mode line. Select the buffer properly for that.
13388 Also, run the hook window-scroll-functions
13389 because we have scrolled. */
13390 /* Note, we do this after clearing force_start because
13391 if there's an error, it is better to forget about force_start
13392 than to get into an infinite loop calling the hook functions
13393 and having them get more errors. */
13394 if (!update_mode_line
13395 || ! NILP (Vwindow_scroll_functions
))
13397 update_mode_line
= 1;
13398 w
->update_mode_line
= Qt
;
13399 startp
= run_window_scroll_functions (window
, startp
);
13402 w
->last_modified
= make_number (0);
13403 w
->last_overlay_modified
= make_number (0);
13404 if (CHARPOS (startp
) < BEGV
)
13405 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13406 else if (CHARPOS (startp
) > ZV
)
13407 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13409 /* Redisplay, then check if cursor has been set during the
13410 redisplay. Give up if new fonts were loaded. */
13411 /* We used to issue a CHECK_MARGINS argument to try_window here,
13412 but this causes scrolling to fail when point begins inside
13413 the scroll margin (bug#148) -- cyd */
13414 if (!try_window (window
, startp
, 0))
13416 w
->force_start
= Qt
;
13417 clear_glyph_matrix (w
->desired_matrix
);
13418 goto need_larger_matrices
;
13421 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13423 /* If point does not appear, try to move point so it does
13424 appear. The desired matrix has been built above, so we
13425 can use it here. */
13426 new_vpos
= window_box_height (w
) / 2;
13429 if (!cursor_row_fully_visible_p (w
, 0, 0))
13431 /* Point does appear, but on a line partly visible at end of window.
13432 Move it back to a fully-visible line. */
13433 new_vpos
= window_box_height (w
);
13436 /* If we need to move point for either of the above reasons,
13437 now actually do it. */
13440 struct glyph_row
*row
;
13442 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13443 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13446 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13447 MATRIX_ROW_START_BYTEPOS (row
));
13449 if (w
!= XWINDOW (selected_window
))
13450 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13451 else if (current_buffer
== old
)
13452 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13454 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13456 /* If we are highlighting the region, then we just changed
13457 the region, so redisplay to show it. */
13458 if (!NILP (Vtransient_mark_mode
)
13459 && !NILP (current_buffer
->mark_active
))
13461 clear_glyph_matrix (w
->desired_matrix
);
13462 if (!try_window (window
, startp
, 0))
13463 goto need_larger_matrices
;
13468 debug_method_add (w
, "forced window start");
13473 /* Handle case where text has not changed, only point, and it has
13474 not moved off the frame, and we are not retrying after hscroll.
13475 (current_matrix_up_to_date_p is nonzero when retrying.) */
13476 if (current_matrix_up_to_date_p
13477 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13478 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13482 case CURSOR_MOVEMENT_SUCCESS
:
13483 used_current_matrix_p
= 1;
13486 case CURSOR_MOVEMENT_MUST_SCROLL
:
13487 goto try_to_scroll
;
13493 /* If current starting point was originally the beginning of a line
13494 but no longer is, find a new starting point. */
13495 else if (!NILP (w
->start_at_line_beg
)
13496 && !(CHARPOS (startp
) <= BEGV
13497 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13500 debug_method_add (w
, "recenter 1");
13505 /* Try scrolling with try_window_id. Value is > 0 if update has
13506 been done, it is -1 if we know that the same window start will
13507 not work. It is 0 if unsuccessful for some other reason. */
13508 else if ((tem
= try_window_id (w
)) != 0)
13511 debug_method_add (w
, "try_window_id %d", tem
);
13514 if (fonts_changed_p
)
13515 goto need_larger_matrices
;
13519 /* Otherwise try_window_id has returned -1 which means that we
13520 don't want the alternative below this comment to execute. */
13522 else if (CHARPOS (startp
) >= BEGV
13523 && CHARPOS (startp
) <= ZV
13524 && PT
>= CHARPOS (startp
)
13525 && (CHARPOS (startp
) < ZV
13526 /* Avoid starting at end of buffer. */
13527 || CHARPOS (startp
) == BEGV
13528 || (XFASTINT (w
->last_modified
) >= MODIFF
13529 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13532 /* If first window line is a continuation line, and window start
13533 is inside the modified region, but the first change is before
13534 current window start, we must select a new window start.
13536 However, if this is the result of a down-mouse event (e.g. by
13537 extending the mouse-drag-overlay), we don't want to select a
13538 new window start, since that would change the position under
13539 the mouse, resulting in an unwanted mouse-movement rather
13540 than a simple mouse-click. */
13541 if (NILP (w
->start_at_line_beg
)
13542 && NILP (do_mouse_tracking
)
13543 && CHARPOS (startp
) > BEGV
13544 && CHARPOS (startp
) > BEG
+ beg_unchanged
13545 && CHARPOS (startp
) <= Z
- end_unchanged
13546 /* Even if w->start_at_line_beg is nil, a new window may
13547 start at a line_beg, since that's how set_buffer_window
13548 sets it. So, we need to check the return value of
13549 compute_window_start_on_continuation_line. (See also
13551 && XMARKER (w
->start
)->buffer
== current_buffer
13552 && compute_window_start_on_continuation_line (w
))
13554 w
->force_start
= Qt
;
13555 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13560 debug_method_add (w
, "same window start");
13563 /* Try to redisplay starting at same place as before.
13564 If point has not moved off frame, accept the results. */
13565 if (!current_matrix_up_to_date_p
13566 /* Don't use try_window_reusing_current_matrix in this case
13567 because a window scroll function can have changed the
13569 || !NILP (Vwindow_scroll_functions
)
13570 || MINI_WINDOW_P (w
)
13571 || !(used_current_matrix_p
13572 = try_window_reusing_current_matrix (w
)))
13574 IF_DEBUG (debug_method_add (w
, "1"));
13575 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
13576 /* -1 means we need to scroll.
13577 0 means we need new matrices, but fonts_changed_p
13578 is set in that case, so we will detect it below. */
13579 goto try_to_scroll
;
13582 if (fonts_changed_p
)
13583 goto need_larger_matrices
;
13585 if (w
->cursor
.vpos
>= 0)
13587 if (!just_this_one_p
13588 || current_buffer
->clip_changed
13589 || BEG_UNCHANGED
< CHARPOS (startp
))
13590 /* Forget any recorded base line for line number display. */
13591 w
->base_line_number
= Qnil
;
13593 if (!cursor_row_fully_visible_p (w
, 1, 0))
13595 clear_glyph_matrix (w
->desired_matrix
);
13596 last_line_misfit
= 1;
13598 /* Drop through and scroll. */
13603 clear_glyph_matrix (w
->desired_matrix
);
13608 w
->last_modified
= make_number (0);
13609 w
->last_overlay_modified
= make_number (0);
13611 /* Redisplay the mode line. Select the buffer properly for that. */
13612 if (!update_mode_line
)
13614 update_mode_line
= 1;
13615 w
->update_mode_line
= Qt
;
13618 /* Try to scroll by specified few lines. */
13619 if ((scroll_conservatively
13621 || temp_scroll_step
13622 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13623 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13624 && !current_buffer
->clip_changed
13625 && CHARPOS (startp
) >= BEGV
13626 && CHARPOS (startp
) <= ZV
)
13628 /* The function returns -1 if new fonts were loaded, 1 if
13629 successful, 0 if not successful. */
13630 int rc
= try_scrolling (window
, just_this_one_p
,
13631 scroll_conservatively
,
13633 temp_scroll_step
, last_line_misfit
);
13636 case SCROLLING_SUCCESS
:
13639 case SCROLLING_NEED_LARGER_MATRICES
:
13640 goto need_larger_matrices
;
13642 case SCROLLING_FAILED
:
13650 /* Finally, just choose place to start which centers point */
13653 if (centering_position
< 0)
13654 centering_position
= window_box_height (w
) / 2;
13657 debug_method_add (w
, "recenter");
13660 /* w->vscroll = 0; */
13662 /* Forget any previously recorded base line for line number display. */
13663 if (!buffer_unchanged_p
)
13664 w
->base_line_number
= Qnil
;
13666 /* Move backward half the height of the window. */
13667 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13668 it
.current_y
= it
.last_visible_y
;
13669 move_it_vertically_backward (&it
, centering_position
);
13670 xassert (IT_CHARPOS (it
) >= BEGV
);
13672 /* The function move_it_vertically_backward may move over more
13673 than the specified y-distance. If it->w is small, e.g. a
13674 mini-buffer window, we may end up in front of the window's
13675 display area. Start displaying at the start of the line
13676 containing PT in this case. */
13677 if (it
.current_y
<= 0)
13679 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13680 move_it_vertically_backward (&it
, 0);
13684 it
.current_x
= it
.hpos
= 0;
13686 /* Set startp here explicitly in case that helps avoid an infinite loop
13687 in case the window-scroll-functions functions get errors. */
13688 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13690 /* Run scroll hooks. */
13691 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13693 /* Redisplay the window. */
13694 if (!current_matrix_up_to_date_p
13695 || windows_or_buffers_changed
13696 || cursor_type_changed
13697 /* Don't use try_window_reusing_current_matrix in this case
13698 because it can have changed the buffer. */
13699 || !NILP (Vwindow_scroll_functions
)
13700 || !just_this_one_p
13701 || MINI_WINDOW_P (w
)
13702 || !(used_current_matrix_p
13703 = try_window_reusing_current_matrix (w
)))
13704 try_window (window
, startp
, 0);
13706 /* If new fonts have been loaded (due to fontsets), give up. We
13707 have to start a new redisplay since we need to re-adjust glyph
13709 if (fonts_changed_p
)
13710 goto need_larger_matrices
;
13712 /* If cursor did not appear assume that the middle of the window is
13713 in the first line of the window. Do it again with the next line.
13714 (Imagine a window of height 100, displaying two lines of height
13715 60. Moving back 50 from it->last_visible_y will end in the first
13717 if (w
->cursor
.vpos
< 0)
13719 if (!NILP (w
->window_end_valid
)
13720 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13722 clear_glyph_matrix (w
->desired_matrix
);
13723 move_it_by_lines (&it
, 1, 0);
13724 try_window (window
, it
.current
.pos
, 0);
13726 else if (PT
< IT_CHARPOS (it
))
13728 clear_glyph_matrix (w
->desired_matrix
);
13729 move_it_by_lines (&it
, -1, 0);
13730 try_window (window
, it
.current
.pos
, 0);
13734 /* Not much we can do about it. */
13738 /* Consider the following case: Window starts at BEGV, there is
13739 invisible, intangible text at BEGV, so that display starts at
13740 some point START > BEGV. It can happen that we are called with
13741 PT somewhere between BEGV and START. Try to handle that case. */
13742 if (w
->cursor
.vpos
< 0)
13744 struct glyph_row
*row
= w
->current_matrix
->rows
;
13745 if (row
->mode_line_p
)
13747 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13750 if (!cursor_row_fully_visible_p (w
, 0, 0))
13752 /* If vscroll is enabled, disable it and try again. */
13756 clear_glyph_matrix (w
->desired_matrix
);
13760 /* If centering point failed to make the whole line visible,
13761 put point at the top instead. That has to make the whole line
13762 visible, if it can be done. */
13763 if (centering_position
== 0)
13766 clear_glyph_matrix (w
->desired_matrix
);
13767 centering_position
= 0;
13773 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13774 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13775 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13778 /* Display the mode line, if we must. */
13779 if ((update_mode_line
13780 /* If window not full width, must redo its mode line
13781 if (a) the window to its side is being redone and
13782 (b) we do a frame-based redisplay. This is a consequence
13783 of how inverted lines are drawn in frame-based redisplay. */
13784 || (!just_this_one_p
13785 && !FRAME_WINDOW_P (f
)
13786 && !WINDOW_FULL_WIDTH_P (w
))
13787 /* Line number to display. */
13788 || INTEGERP (w
->base_line_pos
)
13789 /* Column number is displayed and different from the one displayed. */
13790 || (!NILP (w
->column_number_displayed
)
13791 && (XFASTINT (w
->column_number_displayed
)
13792 != (int) current_column ()))) /* iftc */
13793 /* This means that the window has a mode line. */
13794 && (WINDOW_WANTS_MODELINE_P (w
)
13795 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13797 display_mode_lines (w
);
13799 /* If mode line height has changed, arrange for a thorough
13800 immediate redisplay using the correct mode line height. */
13801 if (WINDOW_WANTS_MODELINE_P (w
)
13802 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13804 fonts_changed_p
= 1;
13805 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13806 = DESIRED_MODE_LINE_HEIGHT (w
);
13809 /* If header line height has changed, arrange for a thorough
13810 immediate redisplay using the correct header line height. */
13811 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13812 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13814 fonts_changed_p
= 1;
13815 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13816 = DESIRED_HEADER_LINE_HEIGHT (w
);
13819 if (fonts_changed_p
)
13820 goto need_larger_matrices
;
13823 if (!line_number_displayed
13824 && !BUFFERP (w
->base_line_pos
))
13826 w
->base_line_pos
= Qnil
;
13827 w
->base_line_number
= Qnil
;
13832 /* When we reach a frame's selected window, redo the frame's menu bar. */
13833 if (update_mode_line
13834 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13836 int redisplay_menu_p
= 0;
13837 int redisplay_tool_bar_p
= 0;
13839 if (FRAME_WINDOW_P (f
))
13841 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13842 || defined (HAVE_NS) || defined (USE_GTK)
13843 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13845 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13849 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13851 if (redisplay_menu_p
)
13852 display_menu_bar (w
);
13854 #ifdef HAVE_WINDOW_SYSTEM
13855 if (FRAME_WINDOW_P (f
))
13857 #if defined (USE_GTK) || defined (HAVE_NS)
13858 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13860 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13861 && (FRAME_TOOL_BAR_LINES (f
) > 0
13862 || !NILP (Vauto_resize_tool_bars
));
13865 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13867 extern int ignore_mouse_drag_p
;
13868 ignore_mouse_drag_p
= 1;
13874 #ifdef HAVE_WINDOW_SYSTEM
13875 if (FRAME_WINDOW_P (f
)
13876 && update_window_fringes (w
, (just_this_one_p
13877 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13878 || w
->pseudo_window_p
)))
13882 if (draw_window_fringes (w
, 1))
13883 x_draw_vertical_border (w
);
13887 #endif /* HAVE_WINDOW_SYSTEM */
13889 /* We go to this label, with fonts_changed_p nonzero,
13890 if it is necessary to try again using larger glyph matrices.
13891 We have to redeem the scroll bar even in this case,
13892 because the loop in redisplay_internal expects that. */
13893 need_larger_matrices
:
13895 finish_scroll_bars
:
13897 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13899 /* Set the thumb's position and size. */
13900 set_vertical_scroll_bar (w
);
13902 /* Note that we actually used the scroll bar attached to this
13903 window, so it shouldn't be deleted at the end of redisplay. */
13904 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13905 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13908 /* Restore current_buffer and value of point in it. The window
13909 update may have changed the buffer, so first make sure `opoint'
13910 is still valid (Bug#6177). */
13911 if (CHARPOS (opoint
) < BEGV
)
13912 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
13913 else if (CHARPOS (opoint
) > ZV
)
13914 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
13916 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13918 set_buffer_internal_1 (old
);
13919 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13920 shorter. This can be caused by log truncation in *Messages*. */
13921 if (CHARPOS (lpoint
) <= ZV
)
13922 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13924 unbind_to (count
, Qnil
);
13928 /* Build the complete desired matrix of WINDOW with a window start
13929 buffer position POS.
13931 Value is 1 if successful. It is zero if fonts were loaded during
13932 redisplay which makes re-adjusting glyph matrices necessary, and -1
13933 if point would appear in the scroll margins.
13934 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
13935 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
13939 try_window (window
, pos
, flags
)
13940 Lisp_Object window
;
13941 struct text_pos pos
;
13944 struct window
*w
= XWINDOW (window
);
13946 struct glyph_row
*last_text_row
= NULL
;
13947 struct frame
*f
= XFRAME (w
->frame
);
13949 /* Make POS the new window start. */
13950 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13952 /* Mark cursor position as unknown. No overlay arrow seen. */
13953 w
->cursor
.vpos
= -1;
13954 overlay_arrow_seen
= 0;
13956 /* Initialize iterator and info to start at POS. */
13957 start_display (&it
, w
, pos
);
13959 /* Display all lines of W. */
13960 while (it
.current_y
< it
.last_visible_y
)
13962 if (display_line (&it
))
13963 last_text_row
= it
.glyph_row
- 1;
13964 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
13968 /* Don't let the cursor end in the scroll margins. */
13969 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
13970 && !MINI_WINDOW_P (w
))
13972 int this_scroll_margin
;
13974 if (scroll_margin
> 0)
13976 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13977 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13980 this_scroll_margin
= 0;
13982 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13983 && w
->cursor
.y
< this_scroll_margin
13984 && CHARPOS (pos
) > BEGV
13985 && IT_CHARPOS (it
) < ZV
)
13986 /* rms: considering make_cursor_line_fully_visible_p here
13987 seems to give wrong results. We don't want to recenter
13988 when the last line is partly visible, we want to allow
13989 that case to be handled in the usual way. */
13990 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
13992 w
->cursor
.vpos
= -1;
13993 clear_glyph_matrix (w
->desired_matrix
);
13998 /* If bottom moved off end of frame, change mode line percentage. */
13999 if (XFASTINT (w
->window_end_pos
) <= 0
14000 && Z
!= IT_CHARPOS (it
))
14001 w
->update_mode_line
= Qt
;
14003 /* Set window_end_pos to the offset of the last character displayed
14004 on the window from the end of current_buffer. Set
14005 window_end_vpos to its row number. */
14008 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14009 w
->window_end_bytepos
14010 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14012 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14014 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14015 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14016 ->displays_text_p
);
14020 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14021 w
->window_end_pos
= make_number (Z
- ZV
);
14022 w
->window_end_vpos
= make_number (0);
14025 /* But that is not valid info until redisplay finishes. */
14026 w
->window_end_valid
= Qnil
;
14032 /************************************************************************
14033 Window redisplay reusing current matrix when buffer has not changed
14034 ************************************************************************/
14036 /* Try redisplay of window W showing an unchanged buffer with a
14037 different window start than the last time it was displayed by
14038 reusing its current matrix. Value is non-zero if successful.
14039 W->start is the new window start. */
14042 try_window_reusing_current_matrix (w
)
14045 struct frame
*f
= XFRAME (w
->frame
);
14046 struct glyph_row
*row
, *bottom_row
;
14049 struct text_pos start
, new_start
;
14050 int nrows_scrolled
, i
;
14051 struct glyph_row
*last_text_row
;
14052 struct glyph_row
*last_reused_text_row
;
14053 struct glyph_row
*start_row
;
14054 int start_vpos
, min_y
, max_y
;
14057 if (inhibit_try_window_reusing
)
14061 if (/* This function doesn't handle terminal frames. */
14062 !FRAME_WINDOW_P (f
)
14063 /* Don't try to reuse the display if windows have been split
14065 || windows_or_buffers_changed
14066 || cursor_type_changed
)
14069 /* Can't do this if region may have changed. */
14070 if ((!NILP (Vtransient_mark_mode
)
14071 && !NILP (current_buffer
->mark_active
))
14072 || !NILP (w
->region_showing
)
14073 || !NILP (Vshow_trailing_whitespace
))
14076 /* If top-line visibility has changed, give up. */
14077 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14078 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14081 /* Give up if old or new display is scrolled vertically. We could
14082 make this function handle this, but right now it doesn't. */
14083 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14084 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14087 /* The variable new_start now holds the new window start. The old
14088 start `start' can be determined from the current matrix. */
14089 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14090 start
= start_row
->start
.pos
;
14091 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14093 /* Clear the desired matrix for the display below. */
14094 clear_glyph_matrix (w
->desired_matrix
);
14096 if (CHARPOS (new_start
) <= CHARPOS (start
))
14100 /* Don't use this method if the display starts with an ellipsis
14101 displayed for invisible text. It's not easy to handle that case
14102 below, and it's certainly not worth the effort since this is
14103 not a frequent case. */
14104 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14107 IF_DEBUG (debug_method_add (w
, "twu1"));
14109 /* Display up to a row that can be reused. The variable
14110 last_text_row is set to the last row displayed that displays
14111 text. Note that it.vpos == 0 if or if not there is a
14112 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14113 start_display (&it
, w
, new_start
);
14114 first_row_y
= it
.current_y
;
14115 w
->cursor
.vpos
= -1;
14116 last_text_row
= last_reused_text_row
= NULL
;
14118 while (it
.current_y
< it
.last_visible_y
14119 && !fonts_changed_p
)
14121 /* If we have reached into the characters in the START row,
14122 that means the line boundaries have changed. So we
14123 can't start copying with the row START. Maybe it will
14124 work to start copying with the following row. */
14125 while (IT_CHARPOS (it
) > CHARPOS (start
))
14127 /* Advance to the next row as the "start". */
14129 start
= start_row
->start
.pos
;
14130 /* If there are no more rows to try, or just one, give up. */
14131 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14132 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14133 || CHARPOS (start
) == ZV
)
14135 clear_glyph_matrix (w
->desired_matrix
);
14139 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14141 /* If we have reached alignment,
14142 we can copy the rest of the rows. */
14143 if (IT_CHARPOS (it
) == CHARPOS (start
))
14146 if (display_line (&it
))
14147 last_text_row
= it
.glyph_row
- 1;
14150 /* A value of current_y < last_visible_y means that we stopped
14151 at the previous window start, which in turn means that we
14152 have at least one reusable row. */
14153 if (it
.current_y
< it
.last_visible_y
)
14155 /* IT.vpos always starts from 0; it counts text lines. */
14156 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14158 /* Find PT if not already found in the lines displayed. */
14159 if (w
->cursor
.vpos
< 0)
14161 int dy
= it
.current_y
- start_row
->y
;
14163 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14164 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14166 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14167 dy
, nrows_scrolled
);
14170 clear_glyph_matrix (w
->desired_matrix
);
14175 /* Scroll the display. Do it before the current matrix is
14176 changed. The problem here is that update has not yet
14177 run, i.e. part of the current matrix is not up to date.
14178 scroll_run_hook will clear the cursor, and use the
14179 current matrix to get the height of the row the cursor is
14181 run
.current_y
= start_row
->y
;
14182 run
.desired_y
= it
.current_y
;
14183 run
.height
= it
.last_visible_y
- it
.current_y
;
14185 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14188 FRAME_RIF (f
)->update_window_begin_hook (w
);
14189 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14190 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14191 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14195 /* Shift current matrix down by nrows_scrolled lines. */
14196 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14197 rotate_matrix (w
->current_matrix
,
14199 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14202 /* Disable lines that must be updated. */
14203 for (i
= 0; i
< nrows_scrolled
; ++i
)
14204 (start_row
+ i
)->enabled_p
= 0;
14206 /* Re-compute Y positions. */
14207 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14208 max_y
= it
.last_visible_y
;
14209 for (row
= start_row
+ nrows_scrolled
;
14213 row
->y
= it
.current_y
;
14214 row
->visible_height
= row
->height
;
14216 if (row
->y
< min_y
)
14217 row
->visible_height
-= min_y
- row
->y
;
14218 if (row
->y
+ row
->height
> max_y
)
14219 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14220 row
->redraw_fringe_bitmaps_p
= 1;
14222 it
.current_y
+= row
->height
;
14224 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14225 last_reused_text_row
= row
;
14226 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14230 /* Disable lines in the current matrix which are now
14231 below the window. */
14232 for (++row
; row
< bottom_row
; ++row
)
14233 row
->enabled_p
= row
->mode_line_p
= 0;
14236 /* Update window_end_pos etc.; last_reused_text_row is the last
14237 reused row from the current matrix containing text, if any.
14238 The value of last_text_row is the last displayed line
14239 containing text. */
14240 if (last_reused_text_row
)
14242 w
->window_end_bytepos
14243 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14245 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14247 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14248 w
->current_matrix
));
14250 else if (last_text_row
)
14252 w
->window_end_bytepos
14253 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14255 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14257 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14261 /* This window must be completely empty. */
14262 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14263 w
->window_end_pos
= make_number (Z
- ZV
);
14264 w
->window_end_vpos
= make_number (0);
14266 w
->window_end_valid
= Qnil
;
14268 /* Update hint: don't try scrolling again in update_window. */
14269 w
->desired_matrix
->no_scrolling_p
= 1;
14272 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14276 else if (CHARPOS (new_start
) > CHARPOS (start
))
14278 struct glyph_row
*pt_row
, *row
;
14279 struct glyph_row
*first_reusable_row
;
14280 struct glyph_row
*first_row_to_display
;
14282 int yb
= window_text_bottom_y (w
);
14284 /* Find the row starting at new_start, if there is one. Don't
14285 reuse a partially visible line at the end. */
14286 first_reusable_row
= start_row
;
14287 while (first_reusable_row
->enabled_p
14288 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14289 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14290 < CHARPOS (new_start
)))
14291 ++first_reusable_row
;
14293 /* Give up if there is no row to reuse. */
14294 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14295 || !first_reusable_row
->enabled_p
14296 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14297 != CHARPOS (new_start
)))
14300 /* We can reuse fully visible rows beginning with
14301 first_reusable_row to the end of the window. Set
14302 first_row_to_display to the first row that cannot be reused.
14303 Set pt_row to the row containing point, if there is any. */
14305 for (first_row_to_display
= first_reusable_row
;
14306 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14307 ++first_row_to_display
)
14309 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14310 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14311 pt_row
= first_row_to_display
;
14314 /* Start displaying at the start of first_row_to_display. */
14315 xassert (first_row_to_display
->y
< yb
);
14316 init_to_row_start (&it
, w
, first_row_to_display
);
14318 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14320 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14322 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14323 + WINDOW_HEADER_LINE_HEIGHT (w
));
14325 /* Display lines beginning with first_row_to_display in the
14326 desired matrix. Set last_text_row to the last row displayed
14327 that displays text. */
14328 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14329 if (pt_row
== NULL
)
14330 w
->cursor
.vpos
= -1;
14331 last_text_row
= NULL
;
14332 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14333 if (display_line (&it
))
14334 last_text_row
= it
.glyph_row
- 1;
14336 /* If point is in a reused row, adjust y and vpos of the cursor
14340 w
->cursor
.vpos
-= nrows_scrolled
;
14341 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14344 /* Give up if point isn't in a row displayed or reused. (This
14345 also handles the case where w->cursor.vpos < nrows_scrolled
14346 after the calls to display_line, which can happen with scroll
14347 margins. See bug#1295.) */
14348 if (w
->cursor
.vpos
< 0)
14350 clear_glyph_matrix (w
->desired_matrix
);
14354 /* Scroll the display. */
14355 run
.current_y
= first_reusable_row
->y
;
14356 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14357 run
.height
= it
.last_visible_y
- run
.current_y
;
14358 dy
= run
.current_y
- run
.desired_y
;
14363 FRAME_RIF (f
)->update_window_begin_hook (w
);
14364 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14365 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14366 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14370 /* Adjust Y positions of reused rows. */
14371 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14372 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14373 max_y
= it
.last_visible_y
;
14374 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14377 row
->visible_height
= row
->height
;
14378 if (row
->y
< min_y
)
14379 row
->visible_height
-= min_y
- row
->y
;
14380 if (row
->y
+ row
->height
> max_y
)
14381 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14382 row
->redraw_fringe_bitmaps_p
= 1;
14385 /* Scroll the current matrix. */
14386 xassert (nrows_scrolled
> 0);
14387 rotate_matrix (w
->current_matrix
,
14389 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14392 /* Disable rows not reused. */
14393 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14394 row
->enabled_p
= 0;
14396 /* Point may have moved to a different line, so we cannot assume that
14397 the previous cursor position is valid; locate the correct row. */
14400 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14401 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14405 w
->cursor
.y
= row
->y
;
14407 if (row
< bottom_row
)
14409 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14410 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14413 && (!BUFFERP (glyph
->object
)
14414 || glyph
->charpos
< PT
);
14418 w
->cursor
.x
+= glyph
->pixel_width
;
14423 /* Adjust window end. A null value of last_text_row means that
14424 the window end is in reused rows which in turn means that
14425 only its vpos can have changed. */
14428 w
->window_end_bytepos
14429 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14431 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14433 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14438 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14441 w
->window_end_valid
= Qnil
;
14442 w
->desired_matrix
->no_scrolling_p
= 1;
14445 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14455 /************************************************************************
14456 Window redisplay reusing current matrix when buffer has changed
14457 ************************************************************************/
14459 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14460 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14462 static struct glyph_row
*
14463 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14464 struct glyph_row
*));
14467 /* Return the last row in MATRIX displaying text. If row START is
14468 non-null, start searching with that row. IT gives the dimensions
14469 of the display. Value is null if matrix is empty; otherwise it is
14470 a pointer to the row found. */
14472 static struct glyph_row
*
14473 find_last_row_displaying_text (matrix
, it
, start
)
14474 struct glyph_matrix
*matrix
;
14476 struct glyph_row
*start
;
14478 struct glyph_row
*row
, *row_found
;
14480 /* Set row_found to the last row in IT->w's current matrix
14481 displaying text. The loop looks funny but think of partially
14484 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14485 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14487 xassert (row
->enabled_p
);
14489 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14498 /* Return the last row in the current matrix of W that is not affected
14499 by changes at the start of current_buffer that occurred since W's
14500 current matrix was built. Value is null if no such row exists.
14502 BEG_UNCHANGED us the number of characters unchanged at the start of
14503 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14504 first changed character in current_buffer. Characters at positions <
14505 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14506 when the current matrix was built. */
14508 static struct glyph_row
*
14509 find_last_unchanged_at_beg_row (w
)
14512 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14513 struct glyph_row
*row
;
14514 struct glyph_row
*row_found
= NULL
;
14515 int yb
= window_text_bottom_y (w
);
14517 /* Find the last row displaying unchanged text. */
14518 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14519 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14520 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14523 if (/* If row ends before first_changed_pos, it is unchanged,
14524 except in some case. */
14525 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14526 /* When row ends in ZV and we write at ZV it is not
14528 && !row
->ends_at_zv_p
14529 /* When first_changed_pos is the end of a continued line,
14530 row is not unchanged because it may be no longer
14532 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14533 && (row
->continued_p
14534 || row
->exact_window_width_line_p
)))
14537 /* Stop if last visible row. */
14538 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14546 /* Find the first glyph row in the current matrix of W that is not
14547 affected by changes at the end of current_buffer since the
14548 time W's current matrix was built.
14550 Return in *DELTA the number of chars by which buffer positions in
14551 unchanged text at the end of current_buffer must be adjusted.
14553 Return in *DELTA_BYTES the corresponding number of bytes.
14555 Value is null if no such row exists, i.e. all rows are affected by
14558 static struct glyph_row
*
14559 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14561 int *delta
, *delta_bytes
;
14563 struct glyph_row
*row
;
14564 struct glyph_row
*row_found
= NULL
;
14566 *delta
= *delta_bytes
= 0;
14568 /* Display must not have been paused, otherwise the current matrix
14569 is not up to date. */
14570 eassert (!NILP (w
->window_end_valid
));
14572 /* A value of window_end_pos >= END_UNCHANGED means that the window
14573 end is in the range of changed text. If so, there is no
14574 unchanged row at the end of W's current matrix. */
14575 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14578 /* Set row to the last row in W's current matrix displaying text. */
14579 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14581 /* If matrix is entirely empty, no unchanged row exists. */
14582 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14584 /* The value of row is the last glyph row in the matrix having a
14585 meaningful buffer position in it. The end position of row
14586 corresponds to window_end_pos. This allows us to translate
14587 buffer positions in the current matrix to current buffer
14588 positions for characters not in changed text. */
14589 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14590 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14591 int last_unchanged_pos
, last_unchanged_pos_old
;
14592 struct glyph_row
*first_text_row
14593 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14595 *delta
= Z
- Z_old
;
14596 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14598 /* Set last_unchanged_pos to the buffer position of the last
14599 character in the buffer that has not been changed. Z is the
14600 index + 1 of the last character in current_buffer, i.e. by
14601 subtracting END_UNCHANGED we get the index of the last
14602 unchanged character, and we have to add BEG to get its buffer
14604 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14605 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14607 /* Search backward from ROW for a row displaying a line that
14608 starts at a minimum position >= last_unchanged_pos_old. */
14609 for (; row
> first_text_row
; --row
)
14611 /* This used to abort, but it can happen.
14612 It is ok to just stop the search instead here. KFS. */
14613 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14616 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14621 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14627 /* Make sure that glyph rows in the current matrix of window W
14628 reference the same glyph memory as corresponding rows in the
14629 frame's frame matrix. This function is called after scrolling W's
14630 current matrix on a terminal frame in try_window_id and
14631 try_window_reusing_current_matrix. */
14634 sync_frame_with_window_matrix_rows (w
)
14637 struct frame
*f
= XFRAME (w
->frame
);
14638 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14640 /* Preconditions: W must be a leaf window and full-width. Its frame
14641 must have a frame matrix. */
14642 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14643 xassert (WINDOW_FULL_WIDTH_P (w
));
14644 xassert (!FRAME_WINDOW_P (f
));
14646 /* If W is a full-width window, glyph pointers in W's current matrix
14647 have, by definition, to be the same as glyph pointers in the
14648 corresponding frame matrix. Note that frame matrices have no
14649 marginal areas (see build_frame_matrix). */
14650 window_row
= w
->current_matrix
->rows
;
14651 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14652 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14653 while (window_row
< window_row_end
)
14655 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14656 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14658 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14659 frame_row
->glyphs
[TEXT_AREA
] = start
;
14660 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14661 frame_row
->glyphs
[LAST_AREA
] = end
;
14663 /* Disable frame rows whose corresponding window rows have
14664 been disabled in try_window_id. */
14665 if (!window_row
->enabled_p
)
14666 frame_row
->enabled_p
= 0;
14668 ++window_row
, ++frame_row
;
14673 /* Find the glyph row in window W containing CHARPOS. Consider all
14674 rows between START and END (not inclusive). END null means search
14675 all rows to the end of the display area of W. Value is the row
14676 containing CHARPOS or null. */
14679 row_containing_pos (w
, charpos
, start
, end
, dy
)
14682 struct glyph_row
*start
, *end
;
14685 struct glyph_row
*row
= start
;
14688 /* If we happen to start on a header-line, skip that. */
14689 if (row
->mode_line_p
)
14692 if ((end
&& row
>= end
) || !row
->enabled_p
)
14695 last_y
= window_text_bottom_y (w
) - dy
;
14699 /* Give up if we have gone too far. */
14700 if (end
&& row
>= end
)
14702 /* This formerly returned if they were equal.
14703 I think that both quantities are of a "last plus one" type;
14704 if so, when they are equal, the row is within the screen. -- rms. */
14705 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14708 /* If it is in this row, return this row. */
14709 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14710 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14711 /* The end position of a row equals the start
14712 position of the next row. If CHARPOS is there, we
14713 would rather display it in the next line, except
14714 when this line ends in ZV. */
14715 && !row
->ends_at_zv_p
14716 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14717 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14724 /* Try to redisplay window W by reusing its existing display. W's
14725 current matrix must be up to date when this function is called,
14726 i.e. window_end_valid must not be nil.
14730 1 if display has been updated
14731 0 if otherwise unsuccessful
14732 -1 if redisplay with same window start is known not to succeed
14734 The following steps are performed:
14736 1. Find the last row in the current matrix of W that is not
14737 affected by changes at the start of current_buffer. If no such row
14740 2. Find the first row in W's current matrix that is not affected by
14741 changes at the end of current_buffer. Maybe there is no such row.
14743 3. Display lines beginning with the row + 1 found in step 1 to the
14744 row found in step 2 or, if step 2 didn't find a row, to the end of
14747 4. If cursor is not known to appear on the window, give up.
14749 5. If display stopped at the row found in step 2, scroll the
14750 display and current matrix as needed.
14752 6. Maybe display some lines at the end of W, if we must. This can
14753 happen under various circumstances, like a partially visible line
14754 becoming fully visible, or because newly displayed lines are displayed
14755 in smaller font sizes.
14757 7. Update W's window end information. */
14763 struct frame
*f
= XFRAME (w
->frame
);
14764 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14765 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14766 struct glyph_row
*last_unchanged_at_beg_row
;
14767 struct glyph_row
*first_unchanged_at_end_row
;
14768 struct glyph_row
*row
;
14769 struct glyph_row
*bottom_row
;
14772 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14773 struct text_pos start_pos
;
14775 int first_unchanged_at_end_vpos
= 0;
14776 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14777 struct text_pos start
;
14778 int first_changed_charpos
, last_changed_charpos
;
14781 if (inhibit_try_window_id
)
14785 /* This is handy for debugging. */
14787 #define GIVE_UP(X) \
14789 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14793 #define GIVE_UP(X) return 0
14796 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14798 /* Don't use this for mini-windows because these can show
14799 messages and mini-buffers, and we don't handle that here. */
14800 if (MINI_WINDOW_P (w
))
14803 /* This flag is used to prevent redisplay optimizations. */
14804 if (windows_or_buffers_changed
|| cursor_type_changed
)
14807 /* Verify that narrowing has not changed.
14808 Also verify that we were not told to prevent redisplay optimizations.
14809 It would be nice to further
14810 reduce the number of cases where this prevents try_window_id. */
14811 if (current_buffer
->clip_changed
14812 || current_buffer
->prevent_redisplay_optimizations_p
)
14815 /* Window must either use window-based redisplay or be full width. */
14816 if (!FRAME_WINDOW_P (f
)
14817 && (!FRAME_LINE_INS_DEL_OK (f
)
14818 || !WINDOW_FULL_WIDTH_P (w
)))
14821 /* Give up if point is known NOT to appear in W. */
14822 if (PT
< CHARPOS (start
))
14825 /* Another way to prevent redisplay optimizations. */
14826 if (XFASTINT (w
->last_modified
) == 0)
14829 /* Verify that window is not hscrolled. */
14830 if (XFASTINT (w
->hscroll
) != 0)
14833 /* Verify that display wasn't paused. */
14834 if (NILP (w
->window_end_valid
))
14837 /* Can't use this if highlighting a region because a cursor movement
14838 will do more than just set the cursor. */
14839 if (!NILP (Vtransient_mark_mode
)
14840 && !NILP (current_buffer
->mark_active
))
14843 /* Likewise if highlighting trailing whitespace. */
14844 if (!NILP (Vshow_trailing_whitespace
))
14847 /* Likewise if showing a region. */
14848 if (!NILP (w
->region_showing
))
14851 /* Can't use this if overlay arrow position and/or string have
14853 if (overlay_arrows_changed_p ())
14856 /* When word-wrap is on, adding a space to the first word of a
14857 wrapped line can change the wrap position, altering the line
14858 above it. It might be worthwhile to handle this more
14859 intelligently, but for now just redisplay from scratch. */
14860 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14863 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14864 only if buffer has really changed. The reason is that the gap is
14865 initially at Z for freshly visited files. The code below would
14866 set end_unchanged to 0 in that case. */
14867 if (MODIFF
> SAVE_MODIFF
14868 /* This seems to happen sometimes after saving a buffer. */
14869 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14871 if (GPT
- BEG
< BEG_UNCHANGED
)
14872 BEG_UNCHANGED
= GPT
- BEG
;
14873 if (Z
- GPT
< END_UNCHANGED
)
14874 END_UNCHANGED
= Z
- GPT
;
14877 /* The position of the first and last character that has been changed. */
14878 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14879 last_changed_charpos
= Z
- END_UNCHANGED
;
14881 /* If window starts after a line end, and the last change is in
14882 front of that newline, then changes don't affect the display.
14883 This case happens with stealth-fontification. Note that although
14884 the display is unchanged, glyph positions in the matrix have to
14885 be adjusted, of course. */
14886 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14887 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14888 && ((last_changed_charpos
< CHARPOS (start
)
14889 && CHARPOS (start
) == BEGV
)
14890 || (last_changed_charpos
< CHARPOS (start
) - 1
14891 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14893 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14894 struct glyph_row
*r0
;
14896 /* Compute how many chars/bytes have been added to or removed
14897 from the buffer. */
14898 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14899 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14901 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14903 /* Give up if PT is not in the window. Note that it already has
14904 been checked at the start of try_window_id that PT is not in
14905 front of the window start. */
14906 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14909 /* If window start is unchanged, we can reuse the whole matrix
14910 as is, after adjusting glyph positions. No need to compute
14911 the window end again, since its offset from Z hasn't changed. */
14912 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14913 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14914 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14915 /* PT must not be in a partially visible line. */
14916 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14917 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14919 /* Adjust positions in the glyph matrix. */
14920 if (delta
|| delta_bytes
)
14922 struct glyph_row
*r1
14923 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14924 increment_matrix_positions (w
->current_matrix
,
14925 MATRIX_ROW_VPOS (r0
, current_matrix
),
14926 MATRIX_ROW_VPOS (r1
, current_matrix
),
14927 delta
, delta_bytes
);
14930 /* Set the cursor. */
14931 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14933 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14940 /* Handle the case that changes are all below what is displayed in
14941 the window, and that PT is in the window. This shortcut cannot
14942 be taken if ZV is visible in the window, and text has been added
14943 there that is visible in the window. */
14944 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14945 /* ZV is not visible in the window, or there are no
14946 changes at ZV, actually. */
14947 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14948 || first_changed_charpos
== last_changed_charpos
))
14950 struct glyph_row
*r0
;
14952 /* Give up if PT is not in the window. Note that it already has
14953 been checked at the start of try_window_id that PT is not in
14954 front of the window start. */
14955 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14958 /* If window start is unchanged, we can reuse the whole matrix
14959 as is, without changing glyph positions since no text has
14960 been added/removed in front of the window end. */
14961 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14962 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14963 /* PT must not be in a partially visible line. */
14964 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14965 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14967 /* We have to compute the window end anew since text
14968 can have been added/removed after it. */
14970 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14971 w
->window_end_bytepos
14972 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14974 /* Set the cursor. */
14975 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14977 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14984 /* Give up if window start is in the changed area.
14986 The condition used to read
14988 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14990 but why that was tested escapes me at the moment. */
14991 if (CHARPOS (start
) >= first_changed_charpos
14992 && CHARPOS (start
) <= last_changed_charpos
)
14995 /* Check that window start agrees with the start of the first glyph
14996 row in its current matrix. Check this after we know the window
14997 start is not in changed text, otherwise positions would not be
14999 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15000 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15003 /* Give up if the window ends in strings. Overlay strings
15004 at the end are difficult to handle, so don't try. */
15005 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15006 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15009 /* Compute the position at which we have to start displaying new
15010 lines. Some of the lines at the top of the window might be
15011 reusable because they are not displaying changed text. Find the
15012 last row in W's current matrix not affected by changes at the
15013 start of current_buffer. Value is null if changes start in the
15014 first line of window. */
15015 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15016 if (last_unchanged_at_beg_row
)
15018 /* Avoid starting to display in the moddle of a character, a TAB
15019 for instance. This is easier than to set up the iterator
15020 exactly, and it's not a frequent case, so the additional
15021 effort wouldn't really pay off. */
15022 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15023 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15024 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15025 --last_unchanged_at_beg_row
;
15027 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15030 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15032 start_pos
= it
.current
.pos
;
15034 /* Start displaying new lines in the desired matrix at the same
15035 vpos we would use in the current matrix, i.e. below
15036 last_unchanged_at_beg_row. */
15037 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15039 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15040 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15042 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15046 /* There are no reusable lines at the start of the window.
15047 Start displaying in the first text line. */
15048 start_display (&it
, w
, start
);
15049 it
.vpos
= it
.first_vpos
;
15050 start_pos
= it
.current
.pos
;
15053 /* Find the first row that is not affected by changes at the end of
15054 the buffer. Value will be null if there is no unchanged row, in
15055 which case we must redisplay to the end of the window. delta
15056 will be set to the value by which buffer positions beginning with
15057 first_unchanged_at_end_row have to be adjusted due to text
15059 first_unchanged_at_end_row
15060 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15061 IF_DEBUG (debug_delta
= delta
);
15062 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15064 /* Set stop_pos to the buffer position up to which we will have to
15065 display new lines. If first_unchanged_at_end_row != NULL, this
15066 is the buffer position of the start of the line displayed in that
15067 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15068 that we don't stop at a buffer position. */
15070 if (first_unchanged_at_end_row
)
15072 xassert (last_unchanged_at_beg_row
== NULL
15073 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15075 /* If this is a continuation line, move forward to the next one
15076 that isn't. Changes in lines above affect this line.
15077 Caution: this may move first_unchanged_at_end_row to a row
15078 not displaying text. */
15079 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15080 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15081 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15082 < it
.last_visible_y
))
15083 ++first_unchanged_at_end_row
;
15085 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15086 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15087 >= it
.last_visible_y
))
15088 first_unchanged_at_end_row
= NULL
;
15091 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15093 first_unchanged_at_end_vpos
15094 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15095 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15098 else if (last_unchanged_at_beg_row
== NULL
)
15104 /* Either there is no unchanged row at the end, or the one we have
15105 now displays text. This is a necessary condition for the window
15106 end pos calculation at the end of this function. */
15107 xassert (first_unchanged_at_end_row
== NULL
15108 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15110 debug_last_unchanged_at_beg_vpos
15111 = (last_unchanged_at_beg_row
15112 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15114 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15116 #endif /* GLYPH_DEBUG != 0 */
15119 /* Display new lines. Set last_text_row to the last new line
15120 displayed which has text on it, i.e. might end up as being the
15121 line where the window_end_vpos is. */
15122 w
->cursor
.vpos
= -1;
15123 last_text_row
= NULL
;
15124 overlay_arrow_seen
= 0;
15125 while (it
.current_y
< it
.last_visible_y
15126 && !fonts_changed_p
15127 && (first_unchanged_at_end_row
== NULL
15128 || IT_CHARPOS (it
) < stop_pos
))
15130 if (display_line (&it
))
15131 last_text_row
= it
.glyph_row
- 1;
15134 if (fonts_changed_p
)
15138 /* Compute differences in buffer positions, y-positions etc. for
15139 lines reused at the bottom of the window. Compute what we can
15141 if (first_unchanged_at_end_row
15142 /* No lines reused because we displayed everything up to the
15143 bottom of the window. */
15144 && it
.current_y
< it
.last_visible_y
)
15147 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15149 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15150 run
.current_y
= first_unchanged_at_end_row
->y
;
15151 run
.desired_y
= run
.current_y
+ dy
;
15152 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15156 delta
= delta_bytes
= dvpos
= dy
15157 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15158 first_unchanged_at_end_row
= NULL
;
15160 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15163 /* Find the cursor if not already found. We have to decide whether
15164 PT will appear on this window (it sometimes doesn't, but this is
15165 not a very frequent case.) This decision has to be made before
15166 the current matrix is altered. A value of cursor.vpos < 0 means
15167 that PT is either in one of the lines beginning at
15168 first_unchanged_at_end_row or below the window. Don't care for
15169 lines that might be displayed later at the window end; as
15170 mentioned, this is not a frequent case. */
15171 if (w
->cursor
.vpos
< 0)
15173 /* Cursor in unchanged rows at the top? */
15174 if (PT
< CHARPOS (start_pos
)
15175 && last_unchanged_at_beg_row
)
15177 row
= row_containing_pos (w
, PT
,
15178 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15179 last_unchanged_at_beg_row
+ 1, 0);
15181 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15184 /* Start from first_unchanged_at_end_row looking for PT. */
15185 else if (first_unchanged_at_end_row
)
15187 row
= row_containing_pos (w
, PT
- delta
,
15188 first_unchanged_at_end_row
, NULL
, 0);
15190 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15191 delta_bytes
, dy
, dvpos
);
15194 /* Give up if cursor was not found. */
15195 if (w
->cursor
.vpos
< 0)
15197 clear_glyph_matrix (w
->desired_matrix
);
15202 /* Don't let the cursor end in the scroll margins. */
15204 int this_scroll_margin
, cursor_height
;
15206 this_scroll_margin
= max (0, scroll_margin
);
15207 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15208 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15209 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15211 if ((w
->cursor
.y
< this_scroll_margin
15212 && CHARPOS (start
) > BEGV
)
15213 /* Old redisplay didn't take scroll margin into account at the bottom,
15214 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15215 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15216 ? cursor_height
+ this_scroll_margin
15217 : 1)) > it
.last_visible_y
)
15219 w
->cursor
.vpos
= -1;
15220 clear_glyph_matrix (w
->desired_matrix
);
15225 /* Scroll the display. Do it before changing the current matrix so
15226 that xterm.c doesn't get confused about where the cursor glyph is
15228 if (dy
&& run
.height
)
15232 if (FRAME_WINDOW_P (f
))
15234 FRAME_RIF (f
)->update_window_begin_hook (w
);
15235 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15236 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15237 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15241 /* Terminal frame. In this case, dvpos gives the number of
15242 lines to scroll by; dvpos < 0 means scroll up. */
15243 int first_unchanged_at_end_vpos
15244 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15245 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15246 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15247 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15248 + window_internal_height (w
));
15250 /* Perform the operation on the screen. */
15253 /* Scroll last_unchanged_at_beg_row to the end of the
15254 window down dvpos lines. */
15255 set_terminal_window (f
, end
);
15257 /* On dumb terminals delete dvpos lines at the end
15258 before inserting dvpos empty lines. */
15259 if (!FRAME_SCROLL_REGION_OK (f
))
15260 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15262 /* Insert dvpos empty lines in front of
15263 last_unchanged_at_beg_row. */
15264 ins_del_lines (f
, from
, dvpos
);
15266 else if (dvpos
< 0)
15268 /* Scroll up last_unchanged_at_beg_vpos to the end of
15269 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15270 set_terminal_window (f
, end
);
15272 /* Delete dvpos lines in front of
15273 last_unchanged_at_beg_vpos. ins_del_lines will set
15274 the cursor to the given vpos and emit |dvpos| delete
15276 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15278 /* On a dumb terminal insert dvpos empty lines at the
15280 if (!FRAME_SCROLL_REGION_OK (f
))
15281 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15284 set_terminal_window (f
, 0);
15290 /* Shift reused rows of the current matrix to the right position.
15291 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15293 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15294 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15297 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15298 bottom_vpos
, dvpos
);
15299 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15302 else if (dvpos
> 0)
15304 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15305 bottom_vpos
, dvpos
);
15306 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15307 first_unchanged_at_end_vpos
+ dvpos
, 0);
15310 /* For frame-based redisplay, make sure that current frame and window
15311 matrix are in sync with respect to glyph memory. */
15312 if (!FRAME_WINDOW_P (f
))
15313 sync_frame_with_window_matrix_rows (w
);
15315 /* Adjust buffer positions in reused rows. */
15316 if (delta
|| delta_bytes
)
15317 increment_matrix_positions (current_matrix
,
15318 first_unchanged_at_end_vpos
+ dvpos
,
15319 bottom_vpos
, delta
, delta_bytes
);
15321 /* Adjust Y positions. */
15323 shift_glyph_matrix (w
, current_matrix
,
15324 first_unchanged_at_end_vpos
+ dvpos
,
15327 if (first_unchanged_at_end_row
)
15329 first_unchanged_at_end_row
+= dvpos
;
15330 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15331 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15332 first_unchanged_at_end_row
= NULL
;
15335 /* If scrolling up, there may be some lines to display at the end of
15337 last_text_row_at_end
= NULL
;
15340 /* Scrolling up can leave for example a partially visible line
15341 at the end of the window to be redisplayed. */
15342 /* Set last_row to the glyph row in the current matrix where the
15343 window end line is found. It has been moved up or down in
15344 the matrix by dvpos. */
15345 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15346 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15348 /* If last_row is the window end line, it should display text. */
15349 xassert (last_row
->displays_text_p
);
15351 /* If window end line was partially visible before, begin
15352 displaying at that line. Otherwise begin displaying with the
15353 line following it. */
15354 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15356 init_to_row_start (&it
, w
, last_row
);
15357 it
.vpos
= last_vpos
;
15358 it
.current_y
= last_row
->y
;
15362 init_to_row_end (&it
, w
, last_row
);
15363 it
.vpos
= 1 + last_vpos
;
15364 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15368 /* We may start in a continuation line. If so, we have to
15369 get the right continuation_lines_width and current_x. */
15370 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15371 it
.hpos
= it
.current_x
= 0;
15373 /* Display the rest of the lines at the window end. */
15374 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15375 while (it
.current_y
< it
.last_visible_y
15376 && !fonts_changed_p
)
15378 /* Is it always sure that the display agrees with lines in
15379 the current matrix? I don't think so, so we mark rows
15380 displayed invalid in the current matrix by setting their
15381 enabled_p flag to zero. */
15382 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15383 if (display_line (&it
))
15384 last_text_row_at_end
= it
.glyph_row
- 1;
15388 /* Update window_end_pos and window_end_vpos. */
15389 if (first_unchanged_at_end_row
15390 && !last_text_row_at_end
)
15392 /* Window end line if one of the preserved rows from the current
15393 matrix. Set row to the last row displaying text in current
15394 matrix starting at first_unchanged_at_end_row, after
15396 xassert (first_unchanged_at_end_row
->displays_text_p
);
15397 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15398 first_unchanged_at_end_row
);
15399 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15401 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15402 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15404 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15405 xassert (w
->window_end_bytepos
>= 0);
15406 IF_DEBUG (debug_method_add (w
, "A"));
15408 else if (last_text_row_at_end
)
15411 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15412 w
->window_end_bytepos
15413 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15415 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15416 xassert (w
->window_end_bytepos
>= 0);
15417 IF_DEBUG (debug_method_add (w
, "B"));
15419 else if (last_text_row
)
15421 /* We have displayed either to the end of the window or at the
15422 end of the window, i.e. the last row with text is to be found
15423 in the desired matrix. */
15425 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15426 w
->window_end_bytepos
15427 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15429 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15430 xassert (w
->window_end_bytepos
>= 0);
15432 else if (first_unchanged_at_end_row
== NULL
15433 && last_text_row
== NULL
15434 && last_text_row_at_end
== NULL
)
15436 /* Displayed to end of window, but no line containing text was
15437 displayed. Lines were deleted at the end of the window. */
15438 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15439 int vpos
= XFASTINT (w
->window_end_vpos
);
15440 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15441 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15444 row
== NULL
&& vpos
>= first_vpos
;
15445 --vpos
, --current_row
, --desired_row
)
15447 if (desired_row
->enabled_p
)
15449 if (desired_row
->displays_text_p
)
15452 else if (current_row
->displays_text_p
)
15456 xassert (row
!= NULL
);
15457 w
->window_end_vpos
= make_number (vpos
+ 1);
15458 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15459 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15460 xassert (w
->window_end_bytepos
>= 0);
15461 IF_DEBUG (debug_method_add (w
, "C"));
15466 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15467 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15469 /* Record that display has not been completed. */
15470 w
->window_end_valid
= Qnil
;
15471 w
->desired_matrix
->no_scrolling_p
= 1;
15479 /***********************************************************************
15480 More debugging support
15481 ***********************************************************************/
15485 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15486 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15487 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15490 /* Dump the contents of glyph matrix MATRIX on stderr.
15492 GLYPHS 0 means don't show glyph contents.
15493 GLYPHS 1 means show glyphs in short form
15494 GLYPHS > 1 means show glyphs in long form. */
15497 dump_glyph_matrix (matrix
, glyphs
)
15498 struct glyph_matrix
*matrix
;
15502 for (i
= 0; i
< matrix
->nrows
; ++i
)
15503 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15507 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15508 the glyph row and area where the glyph comes from. */
15511 dump_glyph (row
, glyph
, area
)
15512 struct glyph_row
*row
;
15513 struct glyph
*glyph
;
15516 if (glyph
->type
== CHAR_GLYPH
)
15519 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15520 glyph
- row
->glyphs
[TEXT_AREA
],
15523 (BUFFERP (glyph
->object
)
15525 : (STRINGP (glyph
->object
)
15528 glyph
->pixel_width
,
15530 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15534 glyph
->left_box_line_p
,
15535 glyph
->right_box_line_p
);
15537 else if (glyph
->type
== STRETCH_GLYPH
)
15540 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15541 glyph
- row
->glyphs
[TEXT_AREA
],
15544 (BUFFERP (glyph
->object
)
15546 : (STRINGP (glyph
->object
)
15549 glyph
->pixel_width
,
15553 glyph
->left_box_line_p
,
15554 glyph
->right_box_line_p
);
15556 else if (glyph
->type
== IMAGE_GLYPH
)
15559 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15560 glyph
- row
->glyphs
[TEXT_AREA
],
15563 (BUFFERP (glyph
->object
)
15565 : (STRINGP (glyph
->object
)
15568 glyph
->pixel_width
,
15572 glyph
->left_box_line_p
,
15573 glyph
->right_box_line_p
);
15575 else if (glyph
->type
== COMPOSITE_GLYPH
)
15578 " %5d %4c %6d %c %3d 0x%05x",
15579 glyph
- row
->glyphs
[TEXT_AREA
],
15582 (BUFFERP (glyph
->object
)
15584 : (STRINGP (glyph
->object
)
15587 glyph
->pixel_width
,
15589 if (glyph
->u
.cmp
.automatic
)
15592 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
15593 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
15595 glyph
->left_box_line_p
,
15596 glyph
->right_box_line_p
);
15601 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15602 GLYPHS 0 means don't show glyph contents.
15603 GLYPHS 1 means show glyphs in short form
15604 GLYPHS > 1 means show glyphs in long form. */
15607 dump_glyph_row (row
, vpos
, glyphs
)
15608 struct glyph_row
*row
;
15613 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15614 fprintf (stderr
, "======================================================================\n");
15616 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15617 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15619 MATRIX_ROW_START_CHARPOS (row
),
15620 MATRIX_ROW_END_CHARPOS (row
),
15621 row
->used
[TEXT_AREA
],
15622 row
->contains_overlapping_glyphs_p
,
15624 row
->truncated_on_left_p
,
15625 row
->truncated_on_right_p
,
15627 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15628 row
->displays_text_p
,
15631 row
->ends_in_middle_of_char_p
,
15632 row
->starts_in_middle_of_char_p
,
15638 row
->visible_height
,
15641 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15642 row
->end
.overlay_string_index
,
15643 row
->continuation_lines_width
);
15644 fprintf (stderr
, "%9d %5d\n",
15645 CHARPOS (row
->start
.string_pos
),
15646 CHARPOS (row
->end
.string_pos
));
15647 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15648 row
->end
.dpvec_index
);
15655 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15657 struct glyph
*glyph
= row
->glyphs
[area
];
15658 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15660 /* Glyph for a line end in text. */
15661 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15664 if (glyph
< glyph_end
)
15665 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15667 for (; glyph
< glyph_end
; ++glyph
)
15668 dump_glyph (row
, glyph
, area
);
15671 else if (glyphs
== 1)
15675 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15677 char *s
= (char *) alloca (row
->used
[area
] + 1);
15680 for (i
= 0; i
< row
->used
[area
]; ++i
)
15682 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15683 if (glyph
->type
== CHAR_GLYPH
15684 && glyph
->u
.ch
< 0x80
15685 && glyph
->u
.ch
>= ' ')
15686 s
[i
] = glyph
->u
.ch
;
15692 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15698 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15699 Sdump_glyph_matrix
, 0, 1, "p",
15700 doc
: /* Dump the current matrix of the selected window to stderr.
15701 Shows contents of glyph row structures. With non-nil
15702 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15703 glyphs in short form, otherwise show glyphs in long form. */)
15705 Lisp_Object glyphs
;
15707 struct window
*w
= XWINDOW (selected_window
);
15708 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15710 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15711 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15712 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15713 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15714 fprintf (stderr
, "=============================================\n");
15715 dump_glyph_matrix (w
->current_matrix
,
15716 NILP (glyphs
) ? 0 : XINT (glyphs
));
15721 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15722 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15725 struct frame
*f
= XFRAME (selected_frame
);
15726 dump_glyph_matrix (f
->current_matrix
, 1);
15731 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15732 doc
: /* Dump glyph row ROW to stderr.
15733 GLYPH 0 means don't dump glyphs.
15734 GLYPH 1 means dump glyphs in short form.
15735 GLYPH > 1 or omitted means dump glyphs in long form. */)
15737 Lisp_Object row
, glyphs
;
15739 struct glyph_matrix
*matrix
;
15742 CHECK_NUMBER (row
);
15743 matrix
= XWINDOW (selected_window
)->current_matrix
;
15745 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15746 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15748 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15753 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15754 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15755 GLYPH 0 means don't dump glyphs.
15756 GLYPH 1 means dump glyphs in short form.
15757 GLYPH > 1 or omitted means dump glyphs in long form. */)
15759 Lisp_Object row
, glyphs
;
15761 struct frame
*sf
= SELECTED_FRAME ();
15762 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15765 CHECK_NUMBER (row
);
15767 if (vpos
>= 0 && vpos
< m
->nrows
)
15768 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15769 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15774 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15775 doc
: /* Toggle tracing of redisplay.
15776 With ARG, turn tracing on if and only if ARG is positive. */)
15781 trace_redisplay_p
= !trace_redisplay_p
;
15784 arg
= Fprefix_numeric_value (arg
);
15785 trace_redisplay_p
= XINT (arg
) > 0;
15792 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15793 doc
: /* Like `format', but print result to stderr.
15794 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15799 Lisp_Object s
= Fformat (nargs
, args
);
15800 fprintf (stderr
, "%s", SDATA (s
));
15804 #endif /* GLYPH_DEBUG */
15808 /***********************************************************************
15809 Building Desired Matrix Rows
15810 ***********************************************************************/
15812 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15813 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15815 static struct glyph_row
*
15816 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15818 Lisp_Object overlay_arrow_string
;
15820 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15821 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15822 struct buffer
*old
= current_buffer
;
15823 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15824 int arrow_len
= SCHARS (overlay_arrow_string
);
15825 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15826 const unsigned char *p
;
15829 int n_glyphs_before
;
15831 set_buffer_temp (buffer
);
15832 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15833 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15834 SET_TEXT_POS (it
.position
, 0, 0);
15836 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15838 while (p
< arrow_end
)
15840 Lisp_Object face
, ilisp
;
15842 /* Get the next character. */
15844 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
15847 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
15848 if (! ASCII_CHAR_P (it
.c
))
15849 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
15853 /* Get its face. */
15854 ilisp
= make_number (p
- arrow_string
);
15855 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15856 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
15858 /* Compute its width, get its glyphs. */
15859 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15860 SET_TEXT_POS (it
.position
, -1, -1);
15861 PRODUCE_GLYPHS (&it
);
15863 /* If this character doesn't fit any more in the line, we have
15864 to remove some glyphs. */
15865 if (it
.current_x
> it
.last_visible_x
)
15867 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15872 set_buffer_temp (old
);
15873 return it
.glyph_row
;
15877 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15878 glyphs are only inserted for terminal frames since we can't really
15879 win with truncation glyphs when partially visible glyphs are
15880 involved. Which glyphs to insert is determined by
15881 produce_special_glyphs. */
15884 insert_left_trunc_glyphs (it
)
15887 struct it truncate_it
;
15888 struct glyph
*from
, *end
, *to
, *toend
;
15890 xassert (!FRAME_WINDOW_P (it
->f
));
15892 /* Get the truncation glyphs. */
15894 truncate_it
.current_x
= 0;
15895 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15896 truncate_it
.glyph_row
= &scratch_glyph_row
;
15897 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15898 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15899 truncate_it
.object
= make_number (0);
15900 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15902 /* Overwrite glyphs from IT with truncation glyphs. */
15903 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15904 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15905 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15906 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15911 /* There may be padding glyphs left over. Overwrite them too. */
15912 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15914 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15920 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15924 /* Compute the pixel height and width of IT->glyph_row.
15926 Most of the time, ascent and height of a display line will be equal
15927 to the max_ascent and max_height values of the display iterator
15928 structure. This is not the case if
15930 1. We hit ZV without displaying anything. In this case, max_ascent
15931 and max_height will be zero.
15933 2. We have some glyphs that don't contribute to the line height.
15934 (The glyph row flag contributes_to_line_height_p is for future
15935 pixmap extensions).
15937 The first case is easily covered by using default values because in
15938 these cases, the line height does not really matter, except that it
15939 must not be zero. */
15942 compute_line_metrics (it
)
15945 struct glyph_row
*row
= it
->glyph_row
;
15948 if (FRAME_WINDOW_P (it
->f
))
15950 int i
, min_y
, max_y
;
15952 /* The line may consist of one space only, that was added to
15953 place the cursor on it. If so, the row's height hasn't been
15955 if (row
->height
== 0)
15957 if (it
->max_ascent
+ it
->max_descent
== 0)
15958 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15959 row
->ascent
= it
->max_ascent
;
15960 row
->height
= it
->max_ascent
+ it
->max_descent
;
15961 row
->phys_ascent
= it
->max_phys_ascent
;
15962 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15963 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15966 /* Compute the width of this line. */
15967 row
->pixel_width
= row
->x
;
15968 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15969 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15971 xassert (row
->pixel_width
>= 0);
15972 xassert (row
->ascent
>= 0 && row
->height
> 0);
15974 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15975 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15977 /* If first line's physical ascent is larger than its logical
15978 ascent, use the physical ascent, and make the row taller.
15979 This makes accented characters fully visible. */
15980 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15981 && row
->phys_ascent
> row
->ascent
)
15983 row
->height
+= row
->phys_ascent
- row
->ascent
;
15984 row
->ascent
= row
->phys_ascent
;
15987 /* Compute how much of the line is visible. */
15988 row
->visible_height
= row
->height
;
15990 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15991 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15993 if (row
->y
< min_y
)
15994 row
->visible_height
-= min_y
- row
->y
;
15995 if (row
->y
+ row
->height
> max_y
)
15996 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16000 row
->pixel_width
= row
->used
[TEXT_AREA
];
16001 if (row
->continued_p
)
16002 row
->pixel_width
-= it
->continuation_pixel_width
;
16003 else if (row
->truncated_on_right_p
)
16004 row
->pixel_width
-= it
->truncation_pixel_width
;
16005 row
->ascent
= row
->phys_ascent
= 0;
16006 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16007 row
->extra_line_spacing
= 0;
16010 /* Compute a hash code for this row. */
16012 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16013 for (i
= 0; i
< row
->used
[area
]; ++i
)
16014 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16015 + row
->glyphs
[area
][i
].u
.val
16016 + row
->glyphs
[area
][i
].face_id
16017 + row
->glyphs
[area
][i
].padding_p
16018 + (row
->glyphs
[area
][i
].type
<< 2));
16020 it
->max_ascent
= it
->max_descent
= 0;
16021 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16025 /* Append one space to the glyph row of iterator IT if doing a
16026 window-based redisplay. The space has the same face as
16027 IT->face_id. Value is non-zero if a space was added.
16029 This function is called to make sure that there is always one glyph
16030 at the end of a glyph row that the cursor can be set on under
16031 window-systems. (If there weren't such a glyph we would not know
16032 how wide and tall a box cursor should be displayed).
16034 At the same time this space let's a nicely handle clearing to the
16035 end of the line if the row ends in italic text. */
16038 append_space_for_newline (it
, default_face_p
)
16040 int default_face_p
;
16042 if (FRAME_WINDOW_P (it
->f
))
16044 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16046 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16047 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16049 /* Save some values that must not be changed.
16050 Must save IT->c and IT->len because otherwise
16051 ITERATOR_AT_END_P wouldn't work anymore after
16052 append_space_for_newline has been called. */
16053 enum display_element_type saved_what
= it
->what
;
16054 int saved_c
= it
->c
, saved_len
= it
->len
;
16055 int saved_char_to_display
= it
->char_to_display
;
16056 int saved_x
= it
->current_x
;
16057 int saved_face_id
= it
->face_id
;
16058 struct text_pos saved_pos
;
16059 Lisp_Object saved_object
;
16062 saved_object
= it
->object
;
16063 saved_pos
= it
->position
;
16065 it
->what
= IT_CHARACTER
;
16066 bzero (&it
->position
, sizeof it
->position
);
16067 it
->object
= make_number (0);
16068 it
->c
= it
->char_to_display
= ' ';
16071 if (default_face_p
)
16072 it
->face_id
= DEFAULT_FACE_ID
;
16073 else if (it
->face_before_selective_p
)
16074 it
->face_id
= it
->saved_face_id
;
16075 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16076 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16078 PRODUCE_GLYPHS (it
);
16080 it
->override_ascent
= -1;
16081 it
->constrain_row_ascent_descent_p
= 0;
16082 it
->current_x
= saved_x
;
16083 it
->object
= saved_object
;
16084 it
->position
= saved_pos
;
16085 it
->what
= saved_what
;
16086 it
->face_id
= saved_face_id
;
16087 it
->len
= saved_len
;
16089 it
->char_to_display
= saved_char_to_display
;
16098 /* Extend the face of the last glyph in the text area of IT->glyph_row
16099 to the end of the display line. Called from display_line.
16100 If the glyph row is empty, add a space glyph to it so that we
16101 know the face to draw. Set the glyph row flag fill_line_p. */
16104 extend_face_to_end_of_line (it
)
16108 struct frame
*f
= it
->f
;
16110 /* If line is already filled, do nothing. */
16111 if (it
->current_x
>= it
->last_visible_x
)
16114 /* Face extension extends the background and box of IT->face_id
16115 to the end of the line. If the background equals the background
16116 of the frame, we don't have to do anything. */
16117 if (it
->face_before_selective_p
)
16118 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16120 face
= FACE_FROM_ID (f
, it
->face_id
);
16122 if (FRAME_WINDOW_P (f
)
16123 && it
->glyph_row
->displays_text_p
16124 && face
->box
== FACE_NO_BOX
16125 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16129 /* Set the glyph row flag indicating that the face of the last glyph
16130 in the text area has to be drawn to the end of the text area. */
16131 it
->glyph_row
->fill_line_p
= 1;
16133 /* If current character of IT is not ASCII, make sure we have the
16134 ASCII face. This will be automatically undone the next time
16135 get_next_display_element returns a multibyte character. Note
16136 that the character will always be single byte in unibyte
16138 if (!ASCII_CHAR_P (it
->c
))
16140 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16143 if (FRAME_WINDOW_P (f
))
16145 /* If the row is empty, add a space with the current face of IT,
16146 so that we know which face to draw. */
16147 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16149 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16150 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16151 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16156 /* Save some values that must not be changed. */
16157 int saved_x
= it
->current_x
;
16158 struct text_pos saved_pos
;
16159 Lisp_Object saved_object
;
16160 enum display_element_type saved_what
= it
->what
;
16161 int saved_face_id
= it
->face_id
;
16163 saved_object
= it
->object
;
16164 saved_pos
= it
->position
;
16166 it
->what
= IT_CHARACTER
;
16167 bzero (&it
->position
, sizeof it
->position
);
16168 it
->object
= make_number (0);
16169 it
->c
= it
->char_to_display
= ' ';
16171 it
->face_id
= face
->id
;
16173 PRODUCE_GLYPHS (it
);
16175 while (it
->current_x
<= it
->last_visible_x
)
16176 PRODUCE_GLYPHS (it
);
16178 /* Don't count these blanks really. It would let us insert a left
16179 truncation glyph below and make us set the cursor on them, maybe. */
16180 it
->current_x
= saved_x
;
16181 it
->object
= saved_object
;
16182 it
->position
= saved_pos
;
16183 it
->what
= saved_what
;
16184 it
->face_id
= saved_face_id
;
16189 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16190 trailing whitespace. */
16193 trailing_whitespace_p (charpos
)
16196 int bytepos
= CHAR_TO_BYTE (charpos
);
16199 while (bytepos
< ZV_BYTE
16200 && (c
= FETCH_CHAR (bytepos
),
16201 c
== ' ' || c
== '\t'))
16204 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16206 if (bytepos
!= PT_BYTE
)
16213 /* Highlight trailing whitespace, if any, in ROW. */
16216 highlight_trailing_whitespace (f
, row
)
16218 struct glyph_row
*row
;
16220 int used
= row
->used
[TEXT_AREA
];
16224 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16225 struct glyph
*glyph
= start
+ used
- 1;
16227 /* Skip over glyphs inserted to display the cursor at the
16228 end of a line, for extending the face of the last glyph
16229 to the end of the line on terminals, and for truncation
16230 and continuation glyphs. */
16231 while (glyph
>= start
16232 && glyph
->type
== CHAR_GLYPH
16233 && INTEGERP (glyph
->object
))
16236 /* If last glyph is a space or stretch, and it's trailing
16237 whitespace, set the face of all trailing whitespace glyphs in
16238 IT->glyph_row to `trailing-whitespace'. */
16240 && BUFFERP (glyph
->object
)
16241 && (glyph
->type
== STRETCH_GLYPH
16242 || (glyph
->type
== CHAR_GLYPH
16243 && glyph
->u
.ch
== ' '))
16244 && trailing_whitespace_p (glyph
->charpos
))
16246 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16250 while (glyph
>= start
16251 && BUFFERP (glyph
->object
)
16252 && (glyph
->type
== STRETCH_GLYPH
16253 || (glyph
->type
== CHAR_GLYPH
16254 && glyph
->u
.ch
== ' ')))
16255 (glyph
--)->face_id
= face_id
;
16261 /* Value is non-zero if glyph row ROW in window W should be
16262 used to hold the cursor. */
16265 cursor_row_p (w
, row
)
16267 struct glyph_row
*row
;
16269 int cursor_row_p
= 1;
16271 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16273 /* Suppose the row ends on a string.
16274 Unless the row is continued, that means it ends on a newline
16275 in the string. If it's anything other than a display string
16276 (e.g. a before-string from an overlay), we don't want the
16277 cursor there. (This heuristic seems to give the optimal
16278 behavior for the various types of multi-line strings.) */
16279 if (CHARPOS (row
->end
.string_pos
) >= 0)
16281 if (row
->continued_p
)
16285 /* Check for `display' property. */
16286 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16287 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16288 struct glyph
*glyph
;
16291 for (glyph
= end
; glyph
>= beg
; --glyph
)
16292 if (STRINGP (glyph
->object
))
16295 = Fget_char_property (make_number (PT
),
16299 && display_prop_string_p (prop
, glyph
->object
));
16304 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16306 /* If the row ends in middle of a real character,
16307 and the line is continued, we want the cursor here.
16308 That's because MATRIX_ROW_END_CHARPOS would equal
16309 PT if PT is before the character. */
16310 if (!row
->ends_in_ellipsis_p
)
16311 cursor_row_p
= row
->continued_p
;
16313 /* If the row ends in an ellipsis, then
16314 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16315 We want that position to be displayed after the ellipsis. */
16318 /* If the row ends at ZV, display the cursor at the end of that
16319 row instead of at the start of the row below. */
16320 else if (row
->ends_at_zv_p
)
16326 return cursor_row_p
;
16331 /* Push the display property PROP so that it will be rendered at the
16332 current position in IT. Return 1 if PROP was successfully pushed,
16336 push_display_prop (struct it
*it
, Lisp_Object prop
)
16340 if (STRINGP (prop
))
16342 if (SCHARS (prop
) == 0)
16349 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16350 it
->current
.overlay_string_index
= -1;
16351 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16352 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16353 it
->method
= GET_FROM_STRING
;
16354 it
->stop_charpos
= 0;
16356 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16358 it
->method
= GET_FROM_STRETCH
;
16361 #ifdef HAVE_WINDOW_SYSTEM
16362 else if (IMAGEP (prop
))
16364 it
->what
= IT_IMAGE
;
16365 it
->image_id
= lookup_image (it
->f
, prop
);
16366 it
->method
= GET_FROM_IMAGE
;
16368 #endif /* HAVE_WINDOW_SYSTEM */
16371 pop_it (it
); /* bogus display property, give up */
16378 /* Return the character-property PROP at the current position in IT. */
16381 get_it_property (it
, prop
)
16385 Lisp_Object position
;
16387 if (STRINGP (it
->object
))
16388 position
= make_number (IT_STRING_CHARPOS (*it
));
16389 else if (BUFFERP (it
->object
))
16390 position
= make_number (IT_CHARPOS (*it
));
16394 return Fget_char_property (position
, prop
, it
->object
);
16397 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16400 handle_line_prefix (struct it
*it
)
16402 Lisp_Object prefix
;
16403 if (it
->continuation_lines_width
> 0)
16405 prefix
= get_it_property (it
, Qwrap_prefix
);
16407 prefix
= Vwrap_prefix
;
16411 prefix
= get_it_property (it
, Qline_prefix
);
16413 prefix
= Vline_prefix
;
16415 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
16417 /* If the prefix is wider than the window, and we try to wrap
16418 it, it would acquire its own wrap prefix, and so on till the
16419 iterator stack overflows. So, don't wrap the prefix. */
16420 it
->line_wrap
= TRUNCATE
;
16421 it
->avoid_cursor_p
= 1;
16427 /* Construct the glyph row IT->glyph_row in the desired matrix of
16428 IT->w from text at the current position of IT. See dispextern.h
16429 for an overview of struct it. Value is non-zero if
16430 IT->glyph_row displays text, as opposed to a line displaying ZV
16437 struct glyph_row
*row
= it
->glyph_row
;
16438 Lisp_Object overlay_arrow_string
;
16440 int may_wrap
= 0, wrap_x
;
16441 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16442 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16443 int wrap_row_extra_line_spacing
;
16445 /* We always start displaying at hpos zero even if hscrolled. */
16446 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16448 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16449 >= it
->w
->desired_matrix
->nrows
)
16451 it
->w
->nrows_scale_factor
++;
16452 fonts_changed_p
= 1;
16456 /* Is IT->w showing the region? */
16457 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16459 /* Clear the result glyph row and enable it. */
16460 prepare_desired_row (row
);
16462 row
->y
= it
->current_y
;
16463 row
->start
= it
->start
;
16464 row
->continuation_lines_width
= it
->continuation_lines_width
;
16465 row
->displays_text_p
= 1;
16466 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16467 it
->starts_in_middle_of_char_p
= 0;
16469 /* Arrange the overlays nicely for our purposes. Usually, we call
16470 display_line on only one line at a time, in which case this
16471 can't really hurt too much, or we call it on lines which appear
16472 one after another in the buffer, in which case all calls to
16473 recenter_overlay_lists but the first will be pretty cheap. */
16474 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16476 /* Move over display elements that are not visible because we are
16477 hscrolled. This may stop at an x-position < IT->first_visible_x
16478 if the first glyph is partially visible or if we hit a line end. */
16479 if (it
->current_x
< it
->first_visible_x
)
16481 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16482 MOVE_TO_POS
| MOVE_TO_X
);
16486 /* We only do this when not calling `move_it_in_display_line_to'
16487 above, because move_it_in_display_line_to calls
16488 handle_line_prefix itself. */
16489 handle_line_prefix (it
);
16492 /* Get the initial row height. This is either the height of the
16493 text hscrolled, if there is any, or zero. */
16494 row
->ascent
= it
->max_ascent
;
16495 row
->height
= it
->max_ascent
+ it
->max_descent
;
16496 row
->phys_ascent
= it
->max_phys_ascent
;
16497 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16498 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16500 /* Loop generating characters. The loop is left with IT on the next
16501 character to display. */
16504 int n_glyphs_before
, hpos_before
, x_before
;
16506 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16508 /* Retrieve the next thing to display. Value is zero if end of
16510 if (!get_next_display_element (it
))
16512 /* Maybe add a space at the end of this line that is used to
16513 display the cursor there under X. Set the charpos of the
16514 first glyph of blank lines not corresponding to any text
16516 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16517 row
->exact_window_width_line_p
= 1;
16518 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16519 || row
->used
[TEXT_AREA
] == 0)
16521 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16522 row
->displays_text_p
= 0;
16524 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16525 && (!MINI_WINDOW_P (it
->w
)
16526 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16527 row
->indicate_empty_line_p
= 1;
16530 it
->continuation_lines_width
= 0;
16531 row
->ends_at_zv_p
= 1;
16535 /* Now, get the metrics of what we want to display. This also
16536 generates glyphs in `row' (which is IT->glyph_row). */
16537 n_glyphs_before
= row
->used
[TEXT_AREA
];
16540 /* Remember the line height so far in case the next element doesn't
16541 fit on the line. */
16542 if (it
->line_wrap
!= TRUNCATE
)
16544 ascent
= it
->max_ascent
;
16545 descent
= it
->max_descent
;
16546 phys_ascent
= it
->max_phys_ascent
;
16547 phys_descent
= it
->max_phys_descent
;
16549 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16551 if (IT_DISPLAYING_WHITESPACE (it
))
16557 wrap_row_used
= row
->used
[TEXT_AREA
];
16558 wrap_row_ascent
= row
->ascent
;
16559 wrap_row_height
= row
->height
;
16560 wrap_row_phys_ascent
= row
->phys_ascent
;
16561 wrap_row_phys_height
= row
->phys_height
;
16562 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16568 PRODUCE_GLYPHS (it
);
16570 /* If this display element was in marginal areas, continue with
16572 if (it
->area
!= TEXT_AREA
)
16574 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16575 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16576 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16577 row
->phys_height
= max (row
->phys_height
,
16578 it
->max_phys_ascent
+ it
->max_phys_descent
);
16579 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16580 it
->max_extra_line_spacing
);
16581 set_iterator_to_next (it
, 1);
16585 /* Does the display element fit on the line? If we truncate
16586 lines, we should draw past the right edge of the window. If
16587 we don't truncate, we want to stop so that we can display the
16588 continuation glyph before the right margin. If lines are
16589 continued, there are two possible strategies for characters
16590 resulting in more than 1 glyph (e.g. tabs): Display as many
16591 glyphs as possible in this line and leave the rest for the
16592 continuation line, or display the whole element in the next
16593 line. Original redisplay did the former, so we do it also. */
16594 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16595 hpos_before
= it
->hpos
;
16598 if (/* Not a newline. */
16600 /* Glyphs produced fit entirely in the line. */
16601 && it
->current_x
< it
->last_visible_x
)
16603 it
->hpos
+= nglyphs
;
16604 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16605 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16606 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16607 row
->phys_height
= max (row
->phys_height
,
16608 it
->max_phys_ascent
+ it
->max_phys_descent
);
16609 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16610 it
->max_extra_line_spacing
);
16611 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16612 row
->x
= x
- it
->first_visible_x
;
16617 struct glyph
*glyph
;
16619 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16621 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16622 new_x
= x
+ glyph
->pixel_width
;
16624 if (/* Lines are continued. */
16625 it
->line_wrap
!= TRUNCATE
16626 && (/* Glyph doesn't fit on the line. */
16627 new_x
> it
->last_visible_x
16628 /* Or it fits exactly on a window system frame. */
16629 || (new_x
== it
->last_visible_x
16630 && FRAME_WINDOW_P (it
->f
))))
16632 /* End of a continued line. */
16635 || (new_x
== it
->last_visible_x
16636 && FRAME_WINDOW_P (it
->f
)))
16638 /* Current glyph is the only one on the line or
16639 fits exactly on the line. We must continue
16640 the line because we can't draw the cursor
16641 after the glyph. */
16642 row
->continued_p
= 1;
16643 it
->current_x
= new_x
;
16644 it
->continuation_lines_width
+= new_x
;
16646 if (i
== nglyphs
- 1)
16648 /* If line-wrap is on, check if a previous
16649 wrap point was found. */
16650 if (wrap_row_used
> 0
16651 /* Even if there is a previous wrap
16652 point, continue the line here as
16653 usual, if (i) the previous character
16654 was a space or tab AND (ii) the
16655 current character is not. */
16657 || IT_DISPLAYING_WHITESPACE (it
)))
16660 set_iterator_to_next (it
, 1);
16661 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16663 if (!get_next_display_element (it
))
16665 row
->exact_window_width_line_p
= 1;
16666 it
->continuation_lines_width
= 0;
16667 row
->continued_p
= 0;
16668 row
->ends_at_zv_p
= 1;
16670 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16672 row
->continued_p
= 0;
16673 row
->exact_window_width_line_p
= 1;
16678 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16679 && !FRAME_WINDOW_P (it
->f
))
16681 /* A padding glyph that doesn't fit on this line.
16682 This means the whole character doesn't fit
16684 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16686 /* Fill the rest of the row with continuation
16687 glyphs like in 20.x. */
16688 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16689 < row
->glyphs
[1 + TEXT_AREA
])
16690 produce_special_glyphs (it
, IT_CONTINUATION
);
16692 row
->continued_p
= 1;
16693 it
->current_x
= x_before
;
16694 it
->continuation_lines_width
+= x_before
;
16696 /* Restore the height to what it was before the
16697 element not fitting on the line. */
16698 it
->max_ascent
= ascent
;
16699 it
->max_descent
= descent
;
16700 it
->max_phys_ascent
= phys_ascent
;
16701 it
->max_phys_descent
= phys_descent
;
16703 else if (wrap_row_used
> 0)
16707 it
->continuation_lines_width
+= wrap_x
;
16708 row
->used
[TEXT_AREA
] = wrap_row_used
;
16709 row
->ascent
= wrap_row_ascent
;
16710 row
->height
= wrap_row_height
;
16711 row
->phys_ascent
= wrap_row_phys_ascent
;
16712 row
->phys_height
= wrap_row_phys_height
;
16713 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16714 row
->continued_p
= 1;
16715 row
->ends_at_zv_p
= 0;
16716 row
->exact_window_width_line_p
= 0;
16717 it
->continuation_lines_width
+= x
;
16719 /* Make sure that a non-default face is extended
16720 up to the right margin of the window. */
16721 extend_face_to_end_of_line (it
);
16723 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16725 /* A TAB that extends past the right edge of the
16726 window. This produces a single glyph on
16727 window system frames. We leave the glyph in
16728 this row and let it fill the row, but don't
16729 consume the TAB. */
16730 it
->continuation_lines_width
+= it
->last_visible_x
;
16731 row
->ends_in_middle_of_char_p
= 1;
16732 row
->continued_p
= 1;
16733 glyph
->pixel_width
= it
->last_visible_x
- x
;
16734 it
->starts_in_middle_of_char_p
= 1;
16738 /* Something other than a TAB that draws past
16739 the right edge of the window. Restore
16740 positions to values before the element. */
16741 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16743 /* Display continuation glyphs. */
16744 if (!FRAME_WINDOW_P (it
->f
))
16745 produce_special_glyphs (it
, IT_CONTINUATION
);
16746 row
->continued_p
= 1;
16748 it
->current_x
= x_before
;
16749 it
->continuation_lines_width
+= x
;
16750 extend_face_to_end_of_line (it
);
16752 if (nglyphs
> 1 && i
> 0)
16754 row
->ends_in_middle_of_char_p
= 1;
16755 it
->starts_in_middle_of_char_p
= 1;
16758 /* Restore the height to what it was before the
16759 element not fitting on the line. */
16760 it
->max_ascent
= ascent
;
16761 it
->max_descent
= descent
;
16762 it
->max_phys_ascent
= phys_ascent
;
16763 it
->max_phys_descent
= phys_descent
;
16768 else if (new_x
> it
->first_visible_x
)
16770 /* Increment number of glyphs actually displayed. */
16773 if (x
< it
->first_visible_x
)
16774 /* Glyph is partially visible, i.e. row starts at
16775 negative X position. */
16776 row
->x
= x
- it
->first_visible_x
;
16780 /* Glyph is completely off the left margin of the
16781 window. This should not happen because of the
16782 move_it_in_display_line at the start of this
16783 function, unless the text display area of the
16784 window is empty. */
16785 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16789 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16790 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16791 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16792 row
->phys_height
= max (row
->phys_height
,
16793 it
->max_phys_ascent
+ it
->max_phys_descent
);
16794 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16795 it
->max_extra_line_spacing
);
16797 /* End of this display line if row is continued. */
16798 if (row
->continued_p
|| row
->ends_at_zv_p
)
16803 /* Is this a line end? If yes, we're also done, after making
16804 sure that a non-default face is extended up to the right
16805 margin of the window. */
16806 if (ITERATOR_AT_END_OF_LINE_P (it
))
16808 int used_before
= row
->used
[TEXT_AREA
];
16810 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16812 /* Add a space at the end of the line that is used to
16813 display the cursor there. */
16814 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16815 append_space_for_newline (it
, 0);
16817 /* Extend the face to the end of the line. */
16818 extend_face_to_end_of_line (it
);
16820 /* Make sure we have the position. */
16821 if (used_before
== 0)
16822 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16824 /* Consume the line end. This skips over invisible lines. */
16825 set_iterator_to_next (it
, 1);
16826 it
->continuation_lines_width
= 0;
16830 /* Proceed with next display element. Note that this skips
16831 over lines invisible because of selective display. */
16832 set_iterator_to_next (it
, 1);
16834 /* If we truncate lines, we are done when the last displayed
16835 glyphs reach past the right margin of the window. */
16836 if (it
->line_wrap
== TRUNCATE
16837 && (FRAME_WINDOW_P (it
->f
)
16838 ? (it
->current_x
>= it
->last_visible_x
)
16839 : (it
->current_x
> it
->last_visible_x
)))
16841 /* Maybe add truncation glyphs. */
16842 if (!FRAME_WINDOW_P (it
->f
))
16846 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16847 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16850 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16852 row
->used
[TEXT_AREA
] = i
;
16853 produce_special_glyphs (it
, IT_TRUNCATION
);
16856 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16858 /* Don't truncate if we can overflow newline into fringe. */
16859 if (!get_next_display_element (it
))
16861 it
->continuation_lines_width
= 0;
16862 row
->ends_at_zv_p
= 1;
16863 row
->exact_window_width_line_p
= 1;
16866 if (ITERATOR_AT_END_OF_LINE_P (it
))
16868 row
->exact_window_width_line_p
= 1;
16869 goto at_end_of_line
;
16873 row
->truncated_on_right_p
= 1;
16874 it
->continuation_lines_width
= 0;
16875 reseat_at_next_visible_line_start (it
, 0);
16876 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16877 it
->hpos
= hpos_before
;
16878 it
->current_x
= x_before
;
16883 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16884 at the left window margin. */
16885 if (it
->first_visible_x
16886 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16888 if (!FRAME_WINDOW_P (it
->f
))
16889 insert_left_trunc_glyphs (it
);
16890 row
->truncated_on_left_p
= 1;
16893 /* If the start of this line is the overlay arrow-position, then
16894 mark this glyph row as the one containing the overlay arrow.
16895 This is clearly a mess with variable size fonts. It would be
16896 better to let it be displayed like cursors under X. */
16897 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16898 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16899 !NILP (overlay_arrow_string
)))
16901 /* Overlay arrow in window redisplay is a fringe bitmap. */
16902 if (STRINGP (overlay_arrow_string
))
16904 struct glyph_row
*arrow_row
16905 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16906 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16907 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16908 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16909 struct glyph
*p2
, *end
;
16911 /* Copy the arrow glyphs. */
16912 while (glyph
< arrow_end
)
16915 /* Throw away padding glyphs. */
16917 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16918 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16924 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16929 xassert (INTEGERP (overlay_arrow_string
));
16930 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16932 overlay_arrow_seen
= 1;
16935 /* Compute pixel dimensions of this line. */
16936 compute_line_metrics (it
);
16938 /* Remember the position at which this line ends. */
16939 row
->end
= it
->current
;
16941 /* Record whether this row ends inside an ellipsis. */
16942 row
->ends_in_ellipsis_p
16943 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16944 && it
->ellipsis_p
);
16946 /* Save fringe bitmaps in this row. */
16947 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16948 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16949 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16950 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16952 it
->left_user_fringe_bitmap
= 0;
16953 it
->left_user_fringe_face_id
= 0;
16954 it
->right_user_fringe_bitmap
= 0;
16955 it
->right_user_fringe_face_id
= 0;
16957 /* Maybe set the cursor. */
16958 if (it
->w
->cursor
.vpos
< 0
16959 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16960 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16961 && cursor_row_p (it
->w
, row
))
16962 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16964 /* Highlight trailing whitespace. */
16965 if (!NILP (Vshow_trailing_whitespace
))
16966 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16968 /* Prepare for the next line. This line starts horizontally at (X
16969 HPOS) = (0 0). Vertical positions are incremented. As a
16970 convenience for the caller, IT->glyph_row is set to the next
16972 it
->current_x
= it
->hpos
= 0;
16973 it
->current_y
+= row
->height
;
16976 it
->start
= it
->current
;
16977 return row
->displays_text_p
;
16982 /***********************************************************************
16984 ***********************************************************************/
16986 /* Redisplay the menu bar in the frame for window W.
16988 The menu bar of X frames that don't have X toolkit support is
16989 displayed in a special window W->frame->menu_bar_window.
16991 The menu bar of terminal frames is treated specially as far as
16992 glyph matrices are concerned. Menu bar lines are not part of
16993 windows, so the update is done directly on the frame matrix rows
16994 for the menu bar. */
16997 display_menu_bar (w
)
17000 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17005 /* Don't do all this for graphical frames. */
17007 if (FRAME_W32_P (f
))
17010 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17016 if (FRAME_NS_P (f
))
17018 #endif /* HAVE_NS */
17020 #ifdef USE_X_TOOLKIT
17021 xassert (!FRAME_WINDOW_P (f
));
17022 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17023 it
.first_visible_x
= 0;
17024 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17025 #else /* not USE_X_TOOLKIT */
17026 if (FRAME_WINDOW_P (f
))
17028 /* Menu bar lines are displayed in the desired matrix of the
17029 dummy window menu_bar_window. */
17030 struct window
*menu_w
;
17031 xassert (WINDOWP (f
->menu_bar_window
));
17032 menu_w
= XWINDOW (f
->menu_bar_window
);
17033 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17035 it
.first_visible_x
= 0;
17036 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17040 /* This is a TTY frame, i.e. character hpos/vpos are used as
17042 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17044 it
.first_visible_x
= 0;
17045 it
.last_visible_x
= FRAME_COLS (f
);
17047 #endif /* not USE_X_TOOLKIT */
17049 if (! mode_line_inverse_video
)
17050 /* Force the menu-bar to be displayed in the default face. */
17051 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17053 /* Clear all rows of the menu bar. */
17054 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17056 struct glyph_row
*row
= it
.glyph_row
+ i
;
17057 clear_glyph_row (row
);
17058 row
->enabled_p
= 1;
17059 row
->full_width_p
= 1;
17062 /* Display all items of the menu bar. */
17063 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17064 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17066 Lisp_Object string
;
17068 /* Stop at nil string. */
17069 string
= AREF (items
, i
+ 1);
17073 /* Remember where item was displayed. */
17074 ASET (items
, i
+ 3, make_number (it
.hpos
));
17076 /* Display the item, pad with one space. */
17077 if (it
.current_x
< it
.last_visible_x
)
17078 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17079 SCHARS (string
) + 1, 0, 0, -1);
17082 /* Fill out the line with spaces. */
17083 if (it
.current_x
< it
.last_visible_x
)
17084 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17086 /* Compute the total height of the lines. */
17087 compute_line_metrics (&it
);
17092 /***********************************************************************
17094 ***********************************************************************/
17096 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17097 FORCE is non-zero, redisplay mode lines unconditionally.
17098 Otherwise, redisplay only mode lines that are garbaged. Value is
17099 the number of windows whose mode lines were redisplayed. */
17102 redisplay_mode_lines (window
, force
)
17103 Lisp_Object window
;
17108 while (!NILP (window
))
17110 struct window
*w
= XWINDOW (window
);
17112 if (WINDOWP (w
->hchild
))
17113 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17114 else if (WINDOWP (w
->vchild
))
17115 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17117 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17118 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17120 struct text_pos lpoint
;
17121 struct buffer
*old
= current_buffer
;
17123 /* Set the window's buffer for the mode line display. */
17124 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17125 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17127 /* Point refers normally to the selected window. For any
17128 other window, set up appropriate value. */
17129 if (!EQ (window
, selected_window
))
17131 struct text_pos pt
;
17133 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17134 if (CHARPOS (pt
) < BEGV
)
17135 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17136 else if (CHARPOS (pt
) > (ZV
- 1))
17137 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17139 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17142 /* Display mode lines. */
17143 clear_glyph_matrix (w
->desired_matrix
);
17144 if (display_mode_lines (w
))
17147 w
->must_be_updated_p
= 1;
17150 /* Restore old settings. */
17151 set_buffer_internal_1 (old
);
17152 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17162 /* Display the mode and/or header line of window W. Value is the
17163 sum number of mode lines and header lines displayed. */
17166 display_mode_lines (w
)
17169 Lisp_Object old_selected_window
, old_selected_frame
;
17172 old_selected_frame
= selected_frame
;
17173 selected_frame
= w
->frame
;
17174 old_selected_window
= selected_window
;
17175 XSETWINDOW (selected_window
, w
);
17177 /* These will be set while the mode line specs are processed. */
17178 line_number_displayed
= 0;
17179 w
->column_number_displayed
= Qnil
;
17181 if (WINDOW_WANTS_MODELINE_P (w
))
17183 struct window
*sel_w
= XWINDOW (old_selected_window
);
17185 /* Select mode line face based on the real selected window. */
17186 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17187 current_buffer
->mode_line_format
);
17191 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17193 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17194 current_buffer
->header_line_format
);
17198 selected_frame
= old_selected_frame
;
17199 selected_window
= old_selected_window
;
17204 /* Display mode or header line of window W. FACE_ID specifies which
17205 line to display; it is either MODE_LINE_FACE_ID or
17206 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
17207 display. Value is the pixel height of the mode/header line
17211 display_mode_line (w
, face_id
, format
)
17213 enum face_id face_id
;
17214 Lisp_Object format
;
17218 int count
= SPECPDL_INDEX ();
17220 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17221 /* Don't extend on a previously drawn mode-line.
17222 This may happen if called from pos_visible_p. */
17223 it
.glyph_row
->enabled_p
= 0;
17224 prepare_desired_row (it
.glyph_row
);
17226 it
.glyph_row
->mode_line_p
= 1;
17228 if (! mode_line_inverse_video
)
17229 /* Force the mode-line to be displayed in the default face. */
17230 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17232 record_unwind_protect (unwind_format_mode_line
,
17233 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17235 mode_line_target
= MODE_LINE_DISPLAY
;
17237 /* Temporarily make frame's keyboard the current kboard so that
17238 kboard-local variables in the mode_line_format will get the right
17240 push_kboard (FRAME_KBOARD (it
.f
));
17241 record_unwind_save_match_data ();
17242 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17245 unbind_to (count
, Qnil
);
17247 /* Fill up with spaces. */
17248 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17250 compute_line_metrics (&it
);
17251 it
.glyph_row
->full_width_p
= 1;
17252 it
.glyph_row
->continued_p
= 0;
17253 it
.glyph_row
->truncated_on_left_p
= 0;
17254 it
.glyph_row
->truncated_on_right_p
= 0;
17256 /* Make a 3D mode-line have a shadow at its right end. */
17257 face
= FACE_FROM_ID (it
.f
, face_id
);
17258 extend_face_to_end_of_line (&it
);
17259 if (face
->box
!= FACE_NO_BOX
)
17261 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17262 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17263 last
->right_box_line_p
= 1;
17266 return it
.glyph_row
->height
;
17269 /* Move element ELT in LIST to the front of LIST.
17270 Return the updated list. */
17273 move_elt_to_front (elt
, list
)
17274 Lisp_Object elt
, list
;
17276 register Lisp_Object tail
, prev
;
17277 register Lisp_Object tem
;
17281 while (CONSP (tail
))
17287 /* Splice out the link TAIL. */
17289 list
= XCDR (tail
);
17291 Fsetcdr (prev
, XCDR (tail
));
17293 /* Now make it the first. */
17294 Fsetcdr (tail
, list
);
17299 tail
= XCDR (tail
);
17303 /* Not found--return unchanged LIST. */
17307 /* Contribute ELT to the mode line for window IT->w. How it
17308 translates into text depends on its data type.
17310 IT describes the display environment in which we display, as usual.
17312 DEPTH is the depth in recursion. It is used to prevent
17313 infinite recursion here.
17315 FIELD_WIDTH is the number of characters the display of ELT should
17316 occupy in the mode line, and PRECISION is the maximum number of
17317 characters to display from ELT's representation. See
17318 display_string for details.
17320 Returns the hpos of the end of the text generated by ELT.
17322 PROPS is a property list to add to any string we encounter.
17324 If RISKY is nonzero, remove (disregard) any properties in any string
17325 we encounter, and ignore :eval and :propertize.
17327 The global variable `mode_line_target' determines whether the
17328 output is passed to `store_mode_line_noprop',
17329 `store_mode_line_string', or `display_string'. */
17332 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17335 int field_width
, precision
;
17336 Lisp_Object elt
, props
;
17339 int n
= 0, field
, prec
;
17344 elt
= build_string ("*too-deep*");
17348 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17352 /* A string: output it and check for %-constructs within it. */
17356 if (SCHARS (elt
) > 0
17357 && (!NILP (props
) || risky
))
17359 Lisp_Object oprops
, aelt
;
17360 oprops
= Ftext_properties_at (make_number (0), elt
);
17362 /* If the starting string's properties are not what
17363 we want, translate the string. Also, if the string
17364 is risky, do that anyway. */
17366 if (NILP (Fequal (props
, oprops
)) || risky
)
17368 /* If the starting string has properties,
17369 merge the specified ones onto the existing ones. */
17370 if (! NILP (oprops
) && !risky
)
17374 oprops
= Fcopy_sequence (oprops
);
17376 while (CONSP (tem
))
17378 oprops
= Fplist_put (oprops
, XCAR (tem
),
17379 XCAR (XCDR (tem
)));
17380 tem
= XCDR (XCDR (tem
));
17385 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17386 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17388 /* AELT is what we want. Move it to the front
17389 without consing. */
17391 mode_line_proptrans_alist
17392 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17398 /* If AELT has the wrong props, it is useless.
17399 so get rid of it. */
17401 mode_line_proptrans_alist
17402 = Fdelq (aelt
, mode_line_proptrans_alist
);
17404 elt
= Fcopy_sequence (elt
);
17405 Fset_text_properties (make_number (0), Flength (elt
),
17407 /* Add this item to mode_line_proptrans_alist. */
17408 mode_line_proptrans_alist
17409 = Fcons (Fcons (elt
, props
),
17410 mode_line_proptrans_alist
);
17411 /* Truncate mode_line_proptrans_alist
17412 to at most 50 elements. */
17413 tem
= Fnthcdr (make_number (50),
17414 mode_line_proptrans_alist
);
17416 XSETCDR (tem
, Qnil
);
17425 prec
= precision
- n
;
17426 switch (mode_line_target
)
17428 case MODE_LINE_NOPROP
:
17429 case MODE_LINE_TITLE
:
17430 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17432 case MODE_LINE_STRING
:
17433 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17435 case MODE_LINE_DISPLAY
:
17436 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17437 0, prec
, 0, STRING_MULTIBYTE (elt
));
17444 /* Handle the non-literal case. */
17446 while ((precision
<= 0 || n
< precision
)
17447 && SREF (elt
, offset
) != 0
17448 && (mode_line_target
!= MODE_LINE_DISPLAY
17449 || it
->current_x
< it
->last_visible_x
))
17451 int last_offset
= offset
;
17453 /* Advance to end of string or next format specifier. */
17454 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17457 if (offset
- 1 != last_offset
)
17459 int nchars
, nbytes
;
17461 /* Output to end of string or up to '%'. Field width
17462 is length of string. Don't output more than
17463 PRECISION allows us. */
17466 prec
= c_string_width (SDATA (elt
) + last_offset
,
17467 offset
- last_offset
, precision
- n
,
17470 switch (mode_line_target
)
17472 case MODE_LINE_NOPROP
:
17473 case MODE_LINE_TITLE
:
17474 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17476 case MODE_LINE_STRING
:
17478 int bytepos
= last_offset
;
17479 int charpos
= string_byte_to_char (elt
, bytepos
);
17480 int endpos
= (precision
<= 0
17481 ? string_byte_to_char (elt
, offset
)
17482 : charpos
+ nchars
);
17484 n
+= store_mode_line_string (NULL
,
17485 Fsubstring (elt
, make_number (charpos
),
17486 make_number (endpos
)),
17490 case MODE_LINE_DISPLAY
:
17492 int bytepos
= last_offset
;
17493 int charpos
= string_byte_to_char (elt
, bytepos
);
17495 if (precision
<= 0)
17496 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17497 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17499 STRING_MULTIBYTE (elt
));
17504 else /* c == '%' */
17506 int percent_position
= offset
;
17508 /* Get the specified minimum width. Zero means
17511 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17512 field
= field
* 10 + c
- '0';
17514 /* Don't pad beyond the total padding allowed. */
17515 if (field_width
- n
> 0 && field
> field_width
- n
)
17516 field
= field_width
- n
;
17518 /* Note that either PRECISION <= 0 or N < PRECISION. */
17519 prec
= precision
- n
;
17522 n
+= display_mode_element (it
, depth
, field
, prec
,
17523 Vglobal_mode_string
, props
,
17528 int bytepos
, charpos
;
17529 unsigned char *spec
;
17530 Lisp_Object string
;
17532 bytepos
= percent_position
;
17533 charpos
= (STRING_MULTIBYTE (elt
)
17534 ? string_byte_to_char (elt
, bytepos
)
17536 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
17537 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
17539 switch (mode_line_target
)
17541 case MODE_LINE_NOPROP
:
17542 case MODE_LINE_TITLE
:
17543 n
+= store_mode_line_noprop (spec
, field
, prec
);
17545 case MODE_LINE_STRING
:
17547 int len
= strlen (spec
);
17548 Lisp_Object tem
= make_string (spec
, len
);
17549 props
= Ftext_properties_at (make_number (charpos
), elt
);
17550 /* Should only keep face property in props */
17551 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17554 case MODE_LINE_DISPLAY
:
17556 int nglyphs_before
, nwritten
;
17558 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17559 nwritten
= display_string (spec
, string
, elt
,
17564 /* Assign to the glyphs written above the
17565 string where the `%x' came from, position
17569 struct glyph
*glyph
17570 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17574 for (i
= 0; i
< nwritten
; ++i
)
17576 glyph
[i
].object
= elt
;
17577 glyph
[i
].charpos
= charpos
;
17594 /* A symbol: process the value of the symbol recursively
17595 as if it appeared here directly. Avoid error if symbol void.
17596 Special case: if value of symbol is a string, output the string
17599 register Lisp_Object tem
;
17601 /* If the variable is not marked as risky to set
17602 then its contents are risky to use. */
17603 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17606 tem
= Fboundp (elt
);
17609 tem
= Fsymbol_value (elt
);
17610 /* If value is a string, output that string literally:
17611 don't check for % within it. */
17615 if (!EQ (tem
, elt
))
17617 /* Give up right away for nil or t. */
17627 register Lisp_Object car
, tem
;
17629 /* A cons cell: five distinct cases.
17630 If first element is :eval or :propertize, do something special.
17631 If first element is a string or a cons, process all the elements
17632 and effectively concatenate them.
17633 If first element is a negative number, truncate displaying cdr to
17634 at most that many characters. If positive, pad (with spaces)
17635 to at least that many characters.
17636 If first element is a symbol, process the cadr or caddr recursively
17637 according to whether the symbol's value is non-nil or nil. */
17639 if (EQ (car
, QCeval
))
17641 /* An element of the form (:eval FORM) means evaluate FORM
17642 and use the result as mode line elements. */
17647 if (CONSP (XCDR (elt
)))
17650 spec
= safe_eval (XCAR (XCDR (elt
)));
17651 n
+= display_mode_element (it
, depth
, field_width
- n
,
17652 precision
- n
, spec
, props
,
17656 else if (EQ (car
, QCpropertize
))
17658 /* An element of the form (:propertize ELT PROPS...)
17659 means display ELT but applying properties PROPS. */
17664 if (CONSP (XCDR (elt
)))
17665 n
+= display_mode_element (it
, depth
, field_width
- n
,
17666 precision
- n
, XCAR (XCDR (elt
)),
17667 XCDR (XCDR (elt
)), risky
);
17669 else if (SYMBOLP (car
))
17671 tem
= Fboundp (car
);
17675 /* elt is now the cdr, and we know it is a cons cell.
17676 Use its car if CAR has a non-nil value. */
17679 tem
= Fsymbol_value (car
);
17686 /* Symbol's value is nil (or symbol is unbound)
17687 Get the cddr of the original list
17688 and if possible find the caddr and use that. */
17692 else if (!CONSP (elt
))
17697 else if (INTEGERP (car
))
17699 register int lim
= XINT (car
);
17703 /* Negative int means reduce maximum width. */
17704 if (precision
<= 0)
17707 precision
= min (precision
, -lim
);
17711 /* Padding specified. Don't let it be more than
17712 current maximum. */
17714 lim
= min (precision
, lim
);
17716 /* If that's more padding than already wanted, queue it.
17717 But don't reduce padding already specified even if
17718 that is beyond the current truncation point. */
17719 field_width
= max (lim
, field_width
);
17723 else if (STRINGP (car
) || CONSP (car
))
17725 Lisp_Object halftail
= elt
;
17729 && (precision
<= 0 || n
< precision
))
17731 n
+= display_mode_element (it
, depth
,
17732 /* Do padding only after the last
17733 element in the list. */
17734 (! CONSP (XCDR (elt
))
17737 precision
- n
, XCAR (elt
),
17741 if ((len
& 1) == 0)
17742 halftail
= XCDR (halftail
);
17743 /* Check for cycle. */
17744 if (EQ (halftail
, elt
))
17753 elt
= build_string ("*invalid*");
17757 /* Pad to FIELD_WIDTH. */
17758 if (field_width
> 0 && n
< field_width
)
17760 switch (mode_line_target
)
17762 case MODE_LINE_NOPROP
:
17763 case MODE_LINE_TITLE
:
17764 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17766 case MODE_LINE_STRING
:
17767 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17769 case MODE_LINE_DISPLAY
:
17770 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17779 /* Store a mode-line string element in mode_line_string_list.
17781 If STRING is non-null, display that C string. Otherwise, the Lisp
17782 string LISP_STRING is displayed.
17784 FIELD_WIDTH is the minimum number of output glyphs to produce.
17785 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17786 with spaces. FIELD_WIDTH <= 0 means don't pad.
17788 PRECISION is the maximum number of characters to output from
17789 STRING. PRECISION <= 0 means don't truncate the string.
17791 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17792 properties to the string.
17794 PROPS are the properties to add to the string.
17795 The mode_line_string_face face property is always added to the string.
17799 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17801 Lisp_Object lisp_string
;
17810 if (string
!= NULL
)
17812 len
= strlen (string
);
17813 if (precision
> 0 && len
> precision
)
17815 lisp_string
= make_string (string
, len
);
17817 props
= mode_line_string_face_prop
;
17818 else if (!NILP (mode_line_string_face
))
17820 Lisp_Object face
= Fplist_get (props
, Qface
);
17821 props
= Fcopy_sequence (props
);
17823 face
= mode_line_string_face
;
17825 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17826 props
= Fplist_put (props
, Qface
, face
);
17828 Fadd_text_properties (make_number (0), make_number (len
),
17829 props
, lisp_string
);
17833 len
= XFASTINT (Flength (lisp_string
));
17834 if (precision
> 0 && len
> precision
)
17837 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17840 if (!NILP (mode_line_string_face
))
17844 props
= Ftext_properties_at (make_number (0), lisp_string
);
17845 face
= Fplist_get (props
, Qface
);
17847 face
= mode_line_string_face
;
17849 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17850 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17852 lisp_string
= Fcopy_sequence (lisp_string
);
17855 Fadd_text_properties (make_number (0), make_number (len
),
17856 props
, lisp_string
);
17861 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17865 if (field_width
> len
)
17867 field_width
-= len
;
17868 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17870 Fadd_text_properties (make_number (0), make_number (field_width
),
17871 props
, lisp_string
);
17872 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17880 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17882 doc
: /* Format a string out of a mode line format specification.
17883 First arg FORMAT specifies the mode line format (see `mode-line-format'
17884 for details) to use.
17886 Optional second arg FACE specifies the face property to put on all
17887 characters for which no face is specified. The value nil means the
17888 default face. The value t means whatever face the window's mode line
17889 currently uses \(either `mode-line' or `mode-line-inactive',
17890 depending). An integer value means the value string has no text
17891 properties. Otherwise, the value should be one of `default',
17892 `mode-line', `mode-line-inactive', `header-line', or `tool-bar'.
17894 Optional third and fourth args WINDOW and BUFFER specify the window
17895 and buffer to use as the context for the formatting (defaults
17896 are the selected window and the window's buffer). */)
17897 (format
, face
, window
, buffer
)
17898 Lisp_Object format
, face
, window
, buffer
;
17903 struct buffer
*old_buffer
= NULL
;
17905 int no_props
= INTEGERP (face
);
17906 int count
= SPECPDL_INDEX ();
17908 int string_start
= 0;
17911 window
= selected_window
;
17912 CHECK_WINDOW (window
);
17913 w
= XWINDOW (window
);
17916 buffer
= w
->buffer
;
17917 CHECK_BUFFER (buffer
);
17919 /* Make formatting the modeline a non-op when noninteractive, otherwise
17920 there will be problems later caused by a partially initialized frame. */
17921 if (NILP (format
) || noninteractive
)
17922 return empty_unibyte_string
;
17927 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
17928 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
17929 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
17930 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
17931 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_FACE_ID
17932 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
17933 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
17936 if (XBUFFER (buffer
) != current_buffer
)
17937 old_buffer
= current_buffer
;
17939 /* Save things including mode_line_proptrans_alist,
17940 and set that to nil so that we don't alter the outer value. */
17941 record_unwind_protect (unwind_format_mode_line
,
17942 format_mode_line_unwind_data
17943 (old_buffer
, selected_window
, 1));
17944 mode_line_proptrans_alist
= Qnil
;
17946 Fselect_window (window
, Qt
);
17948 set_buffer_internal_1 (XBUFFER (buffer
));
17950 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17954 mode_line_target
= MODE_LINE_NOPROP
;
17955 mode_line_string_face_prop
= Qnil
;
17956 mode_line_string_list
= Qnil
;
17957 string_start
= MODE_LINE_NOPROP_LEN (0);
17961 mode_line_target
= MODE_LINE_STRING
;
17962 mode_line_string_list
= Qnil
;
17963 mode_line_string_face
= face
;
17964 mode_line_string_face_prop
17965 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17968 push_kboard (FRAME_KBOARD (it
.f
));
17969 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17974 len
= MODE_LINE_NOPROP_LEN (string_start
);
17975 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17979 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17980 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17981 empty_unibyte_string
);
17984 unbind_to (count
, Qnil
);
17988 /* Write a null-terminated, right justified decimal representation of
17989 the positive integer D to BUF using a minimal field width WIDTH. */
17992 pint2str (buf
, width
, d
)
17993 register char *buf
;
17994 register int width
;
17997 register char *p
= buf
;
18005 *p
++ = d
% 10 + '0';
18010 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18021 /* Write a null-terminated, right justified decimal and "human
18022 readable" representation of the nonnegative integer D to BUF using
18023 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18025 static const char power_letter
[] =
18039 pint2hrstr (buf
, width
, d
)
18044 /* We aim to represent the nonnegative integer D as
18045 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18048 /* -1 means: do not use TENTHS. */
18052 /* Length of QUOTIENT.TENTHS as a string. */
18058 if (1000 <= quotient
)
18060 /* Scale to the appropriate EXPONENT. */
18063 remainder
= quotient
% 1000;
18067 while (1000 <= quotient
);
18069 /* Round to nearest and decide whether to use TENTHS or not. */
18072 tenths
= remainder
/ 100;
18073 if (50 <= remainder
% 100)
18080 if (quotient
== 10)
18088 if (500 <= remainder
)
18090 if (quotient
< 999)
18101 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18102 if (tenths
== -1 && quotient
<= 99)
18109 p
= psuffix
= buf
+ max (width
, length
);
18111 /* Print EXPONENT. */
18113 *psuffix
++ = power_letter
[exponent
];
18116 /* Print TENTHS. */
18119 *--p
= '0' + tenths
;
18123 /* Print QUOTIENT. */
18126 int digit
= quotient
% 10;
18127 *--p
= '0' + digit
;
18129 while ((quotient
/= 10) != 0);
18131 /* Print leading spaces. */
18136 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18137 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18138 type of CODING_SYSTEM. Return updated pointer into BUF. */
18140 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18143 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18144 Lisp_Object coding_system
;
18145 register char *buf
;
18149 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18150 const unsigned char *eol_str
;
18152 /* The EOL conversion we are using. */
18153 Lisp_Object eoltype
;
18155 val
= CODING_SYSTEM_SPEC (coding_system
);
18158 if (!VECTORP (val
)) /* Not yet decided. */
18163 eoltype
= eol_mnemonic_undecided
;
18164 /* Don't mention EOL conversion if it isn't decided. */
18169 Lisp_Object eolvalue
;
18171 attrs
= AREF (val
, 0);
18172 eolvalue
= AREF (val
, 2);
18175 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18179 /* The EOL conversion that is normal on this system. */
18181 if (NILP (eolvalue
)) /* Not yet decided. */
18182 eoltype
= eol_mnemonic_undecided
;
18183 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18184 eoltype
= eol_mnemonic_undecided
;
18185 else /* eolvalue is Qunix, Qdos, or Qmac. */
18186 eoltype
= (EQ (eolvalue
, Qunix
)
18187 ? eol_mnemonic_unix
18188 : (EQ (eolvalue
, Qdos
) == 1
18189 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18195 /* Mention the EOL conversion if it is not the usual one. */
18196 if (STRINGP (eoltype
))
18198 eol_str
= SDATA (eoltype
);
18199 eol_str_len
= SBYTES (eoltype
);
18201 else if (CHARACTERP (eoltype
))
18203 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18204 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18209 eol_str
= invalid_eol_type
;
18210 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18212 bcopy (eol_str
, buf
, eol_str_len
);
18213 buf
+= eol_str_len
;
18219 /* Return a string for the output of a mode line %-spec for window W,
18220 generated by character C. PRECISION >= 0 means don't return a
18221 string longer than that value. FIELD_WIDTH > 0 means pad the
18222 string returned with spaces to that value. Return a Lisp string in
18223 *STRING if the resulting string is taken from that Lisp string.
18225 Note we operate on the current buffer for most purposes,
18226 the exception being w->base_line_pos. */
18228 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18231 decode_mode_spec (w
, c
, field_width
, precision
, string
)
18234 int field_width
, precision
;
18235 Lisp_Object
*string
;
18238 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18239 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18240 struct buffer
*b
= current_buffer
;
18248 if (!NILP (b
->read_only
))
18250 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18255 /* This differs from %* only for a modified read-only buffer. */
18256 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18258 if (!NILP (b
->read_only
))
18263 /* This differs from %* in ignoring read-only-ness. */
18264 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18276 if (command_loop_level
> 5)
18278 p
= decode_mode_spec_buf
;
18279 for (i
= 0; i
< command_loop_level
; i
++)
18282 return decode_mode_spec_buf
;
18290 if (command_loop_level
> 5)
18292 p
= decode_mode_spec_buf
;
18293 for (i
= 0; i
< command_loop_level
; i
++)
18296 return decode_mode_spec_buf
;
18303 /* Let lots_of_dashes be a string of infinite length. */
18304 if (mode_line_target
== MODE_LINE_NOPROP
||
18305 mode_line_target
== MODE_LINE_STRING
)
18307 if (field_width
<= 0
18308 || field_width
> sizeof (lots_of_dashes
))
18310 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18311 decode_mode_spec_buf
[i
] = '-';
18312 decode_mode_spec_buf
[i
] = '\0';
18313 return decode_mode_spec_buf
;
18316 return lots_of_dashes
;
18324 /* %c and %l are ignored in `frame-title-format'.
18325 (In redisplay_internal, the frame title is drawn _before_ the
18326 windows are updated, so the stuff which depends on actual
18327 window contents (such as %l) may fail to render properly, or
18328 even crash emacs.) */
18329 if (mode_line_target
== MODE_LINE_TITLE
)
18333 int col
= (int) current_column (); /* iftc */
18334 w
->column_number_displayed
= make_number (col
);
18335 pint2str (decode_mode_spec_buf
, field_width
, col
);
18336 return decode_mode_spec_buf
;
18340 #ifndef SYSTEM_MALLOC
18342 if (NILP (Vmemory_full
))
18345 return "!MEM FULL! ";
18352 /* %F displays the frame name. */
18353 if (!NILP (f
->title
))
18354 return (char *) SDATA (f
->title
);
18355 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18356 return (char *) SDATA (f
->name
);
18365 int size
= ZV
- BEGV
;
18366 pint2str (decode_mode_spec_buf
, field_width
, size
);
18367 return decode_mode_spec_buf
;
18372 int size
= ZV
- BEGV
;
18373 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18374 return decode_mode_spec_buf
;
18379 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18380 int topline
, nlines
, junk
, height
;
18382 /* %c and %l are ignored in `frame-title-format'. */
18383 if (mode_line_target
== MODE_LINE_TITLE
)
18386 startpos
= XMARKER (w
->start
)->charpos
;
18387 startpos_byte
= marker_byte_position (w
->start
);
18388 height
= WINDOW_TOTAL_LINES (w
);
18390 /* If we decided that this buffer isn't suitable for line numbers,
18391 don't forget that too fast. */
18392 if (EQ (w
->base_line_pos
, w
->buffer
))
18394 /* But do forget it, if the window shows a different buffer now. */
18395 else if (BUFFERP (w
->base_line_pos
))
18396 w
->base_line_pos
= Qnil
;
18398 /* If the buffer is very big, don't waste time. */
18399 if (INTEGERP (Vline_number_display_limit
)
18400 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18402 w
->base_line_pos
= Qnil
;
18403 w
->base_line_number
= Qnil
;
18407 if (INTEGERP (w
->base_line_number
)
18408 && INTEGERP (w
->base_line_pos
)
18409 && XFASTINT (w
->base_line_pos
) <= startpos
)
18411 line
= XFASTINT (w
->base_line_number
);
18412 linepos
= XFASTINT (w
->base_line_pos
);
18413 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18418 linepos
= BUF_BEGV (b
);
18419 linepos_byte
= BUF_BEGV_BYTE (b
);
18422 /* Count lines from base line to window start position. */
18423 nlines
= display_count_lines (linepos
, linepos_byte
,
18427 topline
= nlines
+ line
;
18429 /* Determine a new base line, if the old one is too close
18430 or too far away, or if we did not have one.
18431 "Too close" means it's plausible a scroll-down would
18432 go back past it. */
18433 if (startpos
== BUF_BEGV (b
))
18435 w
->base_line_number
= make_number (topline
);
18436 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18438 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18439 || linepos
== BUF_BEGV (b
))
18441 int limit
= BUF_BEGV (b
);
18442 int limit_byte
= BUF_BEGV_BYTE (b
);
18444 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18446 if (startpos
- distance
> limit
)
18448 limit
= startpos
- distance
;
18449 limit_byte
= CHAR_TO_BYTE (limit
);
18452 nlines
= display_count_lines (startpos
, startpos_byte
,
18454 - (height
* 2 + 30),
18456 /* If we couldn't find the lines we wanted within
18457 line_number_display_limit_width chars per line,
18458 give up on line numbers for this window. */
18459 if (position
== limit_byte
&& limit
== startpos
- distance
)
18461 w
->base_line_pos
= w
->buffer
;
18462 w
->base_line_number
= Qnil
;
18466 w
->base_line_number
= make_number (topline
- nlines
);
18467 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18470 /* Now count lines from the start pos to point. */
18471 nlines
= display_count_lines (startpos
, startpos_byte
,
18472 PT_BYTE
, PT
, &junk
);
18474 /* Record that we did display the line number. */
18475 line_number_displayed
= 1;
18477 /* Make the string to show. */
18478 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18479 return decode_mode_spec_buf
;
18482 char* p
= decode_mode_spec_buf
;
18483 int pad
= field_width
- 2;
18489 return decode_mode_spec_buf
;
18495 obj
= b
->mode_name
;
18499 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18505 int pos
= marker_position (w
->start
);
18506 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18508 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18510 if (pos
<= BUF_BEGV (b
))
18515 else if (pos
<= BUF_BEGV (b
))
18519 if (total
> 1000000)
18520 /* Do it differently for a large value, to avoid overflow. */
18521 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18523 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18524 /* We can't normally display a 3-digit number,
18525 so get us a 2-digit number that is close. */
18528 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18529 return decode_mode_spec_buf
;
18533 /* Display percentage of size above the bottom of the screen. */
18536 int toppos
= marker_position (w
->start
);
18537 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18538 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18540 if (botpos
>= BUF_ZV (b
))
18542 if (toppos
<= BUF_BEGV (b
))
18549 if (total
> 1000000)
18550 /* Do it differently for a large value, to avoid overflow. */
18551 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18553 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18554 /* We can't normally display a 3-digit number,
18555 so get us a 2-digit number that is close. */
18558 if (toppos
<= BUF_BEGV (b
))
18559 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18561 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18562 return decode_mode_spec_buf
;
18567 /* status of process */
18568 obj
= Fget_buffer_process (Fcurrent_buffer ());
18570 return "no process";
18571 #ifdef subprocesses
18572 obj
= Fsymbol_name (Fprocess_status (obj
));
18578 int count
= inhibit_garbage_collection ();
18579 Lisp_Object val
= call1 (intern ("file-remote-p"),
18580 current_buffer
->directory
);
18581 unbind_to (count
, Qnil
);
18589 case 't': /* indicate TEXT or BINARY */
18590 #ifdef MODE_LINE_BINARY_TEXT
18591 return MODE_LINE_BINARY_TEXT (b
);
18597 /* coding-system (not including end-of-line format) */
18599 /* coding-system (including end-of-line type) */
18601 int eol_flag
= (c
== 'Z');
18602 char *p
= decode_mode_spec_buf
;
18604 if (! FRAME_WINDOW_P (f
))
18606 /* No need to mention EOL here--the terminal never needs
18607 to do EOL conversion. */
18608 p
= decode_mode_spec_coding (CODING_ID_NAME
18609 (FRAME_KEYBOARD_CODING (f
)->id
),
18611 p
= decode_mode_spec_coding (CODING_ID_NAME
18612 (FRAME_TERMINAL_CODING (f
)->id
),
18615 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18618 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18619 #ifdef subprocesses
18620 obj
= Fget_buffer_process (Fcurrent_buffer ());
18621 if (PROCESSP (obj
))
18623 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18625 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18628 #endif /* subprocesses */
18631 return decode_mode_spec_buf
;
18638 return (char *) SDATA (obj
);
18645 /* Count up to COUNT lines starting from START / START_BYTE.
18646 But don't go beyond LIMIT_BYTE.
18647 Return the number of lines thus found (always nonnegative).
18649 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18652 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18653 int start
, start_byte
, limit_byte
, count
;
18656 register unsigned char *cursor
;
18657 unsigned char *base
;
18659 register int ceiling
;
18660 register unsigned char *ceiling_addr
;
18661 int orig_count
= count
;
18663 /* If we are not in selective display mode,
18664 check only for newlines. */
18665 int selective_display
= (!NILP (current_buffer
->selective_display
)
18666 && !INTEGERP (current_buffer
->selective_display
));
18670 while (start_byte
< limit_byte
)
18672 ceiling
= BUFFER_CEILING_OF (start_byte
);
18673 ceiling
= min (limit_byte
- 1, ceiling
);
18674 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18675 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18678 if (selective_display
)
18679 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18682 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18685 if (cursor
!= ceiling_addr
)
18689 start_byte
+= cursor
- base
+ 1;
18690 *byte_pos_ptr
= start_byte
;
18694 if (++cursor
== ceiling_addr
)
18700 start_byte
+= cursor
- base
;
18705 while (start_byte
> limit_byte
)
18707 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18708 ceiling
= max (limit_byte
, ceiling
);
18709 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18710 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18713 if (selective_display
)
18714 while (--cursor
!= ceiling_addr
18715 && *cursor
!= '\n' && *cursor
!= 015)
18718 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18721 if (cursor
!= ceiling_addr
)
18725 start_byte
+= cursor
- base
+ 1;
18726 *byte_pos_ptr
= start_byte
;
18727 /* When scanning backwards, we should
18728 not count the newline posterior to which we stop. */
18729 return - orig_count
- 1;
18735 /* Here we add 1 to compensate for the last decrement
18736 of CURSOR, which took it past the valid range. */
18737 start_byte
+= cursor
- base
+ 1;
18741 *byte_pos_ptr
= limit_byte
;
18744 return - orig_count
+ count
;
18745 return orig_count
- count
;
18751 /***********************************************************************
18753 ***********************************************************************/
18755 /* Display a NUL-terminated string, starting with index START.
18757 If STRING is non-null, display that C string. Otherwise, the Lisp
18758 string LISP_STRING is displayed. There's a case that STRING is
18759 non-null and LISP_STRING is not nil. It means STRING is a string
18760 data of LISP_STRING. In that case, we display LISP_STRING while
18761 ignoring its text properties.
18763 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18764 FACE_STRING. Display STRING or LISP_STRING with the face at
18765 FACE_STRING_POS in FACE_STRING:
18767 Display the string in the environment given by IT, but use the
18768 standard display table, temporarily.
18770 FIELD_WIDTH is the minimum number of output glyphs to produce.
18771 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18772 with spaces. If STRING has more characters, more than FIELD_WIDTH
18773 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18775 PRECISION is the maximum number of characters to output from
18776 STRING. PRECISION < 0 means don't truncate the string.
18778 This is roughly equivalent to printf format specifiers:
18780 FIELD_WIDTH PRECISION PRINTF
18781 ----------------------------------------
18787 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18788 display them, and < 0 means obey the current buffer's value of
18789 enable_multibyte_characters.
18791 Value is the number of columns displayed. */
18794 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18795 start
, it
, field_width
, precision
, max_x
, multibyte
)
18796 unsigned char *string
;
18797 Lisp_Object lisp_string
;
18798 Lisp_Object face_string
;
18799 EMACS_INT face_string_pos
;
18802 int field_width
, precision
, max_x
;
18805 int hpos_at_start
= it
->hpos
;
18806 int saved_face_id
= it
->face_id
;
18807 struct glyph_row
*row
= it
->glyph_row
;
18809 /* Initialize the iterator IT for iteration over STRING beginning
18810 with index START. */
18811 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
18812 precision
, field_width
, multibyte
);
18813 if (string
&& STRINGP (lisp_string
))
18814 /* LISP_STRING is the one returned by decode_mode_spec. We should
18815 ignore its text properties. */
18816 it
->stop_charpos
= -1;
18818 /* If displaying STRING, set up the face of the iterator
18819 from LISP_STRING, if that's given. */
18820 if (STRINGP (face_string
))
18826 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18827 0, it
->region_beg_charpos
,
18828 it
->region_end_charpos
,
18829 &endptr
, it
->base_face_id
, 0);
18830 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18831 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18834 /* Set max_x to the maximum allowed X position. Don't let it go
18835 beyond the right edge of the window. */
18837 max_x
= it
->last_visible_x
;
18839 max_x
= min (max_x
, it
->last_visible_x
);
18841 /* Skip over display elements that are not visible. because IT->w is
18843 if (it
->current_x
< it
->first_visible_x
)
18844 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18845 MOVE_TO_POS
| MOVE_TO_X
);
18847 row
->ascent
= it
->max_ascent
;
18848 row
->height
= it
->max_ascent
+ it
->max_descent
;
18849 row
->phys_ascent
= it
->max_phys_ascent
;
18850 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18851 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18853 /* This condition is for the case that we are called with current_x
18854 past last_visible_x. */
18855 while (it
->current_x
< max_x
)
18857 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18859 /* Get the next display element. */
18860 if (!get_next_display_element (it
))
18863 /* Produce glyphs. */
18864 x_before
= it
->current_x
;
18865 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18866 PRODUCE_GLYPHS (it
);
18868 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18871 while (i
< nglyphs
)
18873 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18875 if (it
->line_wrap
!= TRUNCATE
18876 && x
+ glyph
->pixel_width
> max_x
)
18878 /* End of continued line or max_x reached. */
18879 if (CHAR_GLYPH_PADDING_P (*glyph
))
18881 /* A wide character is unbreakable. */
18882 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18883 it
->current_x
= x_before
;
18887 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18892 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18894 /* Glyph is at least partially visible. */
18896 if (x
< it
->first_visible_x
)
18897 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18901 /* Glyph is off the left margin of the display area.
18902 Should not happen. */
18906 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18907 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18908 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18909 row
->phys_height
= max (row
->phys_height
,
18910 it
->max_phys_ascent
+ it
->max_phys_descent
);
18911 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18912 it
->max_extra_line_spacing
);
18913 x
+= glyph
->pixel_width
;
18917 /* Stop if max_x reached. */
18921 /* Stop at line ends. */
18922 if (ITERATOR_AT_END_OF_LINE_P (it
))
18924 it
->continuation_lines_width
= 0;
18928 set_iterator_to_next (it
, 1);
18930 /* Stop if truncating at the right edge. */
18931 if (it
->line_wrap
== TRUNCATE
18932 && it
->current_x
>= it
->last_visible_x
)
18934 /* Add truncation mark, but don't do it if the line is
18935 truncated at a padding space. */
18936 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18938 if (!FRAME_WINDOW_P (it
->f
))
18942 if (it
->current_x
> it
->last_visible_x
)
18944 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18945 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18947 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18949 row
->used
[TEXT_AREA
] = i
;
18950 produce_special_glyphs (it
, IT_TRUNCATION
);
18953 produce_special_glyphs (it
, IT_TRUNCATION
);
18955 it
->glyph_row
->truncated_on_right_p
= 1;
18961 /* Maybe insert a truncation at the left. */
18962 if (it
->first_visible_x
18963 && IT_CHARPOS (*it
) > 0)
18965 if (!FRAME_WINDOW_P (it
->f
))
18966 insert_left_trunc_glyphs (it
);
18967 it
->glyph_row
->truncated_on_left_p
= 1;
18970 it
->face_id
= saved_face_id
;
18972 /* Value is number of columns displayed. */
18973 return it
->hpos
- hpos_at_start
;
18978 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18979 appears as an element of LIST or as the car of an element of LIST.
18980 If PROPVAL is a list, compare each element against LIST in that
18981 way, and return 1/2 if any element of PROPVAL is found in LIST.
18982 Otherwise return 0. This function cannot quit.
18983 The return value is 2 if the text is invisible but with an ellipsis
18984 and 1 if it's invisible and without an ellipsis. */
18987 invisible_p (propval
, list
)
18988 register Lisp_Object propval
;
18991 register Lisp_Object tail
, proptail
;
18993 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18995 register Lisp_Object tem
;
18997 if (EQ (propval
, tem
))
18999 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19000 return NILP (XCDR (tem
)) ? 1 : 2;
19003 if (CONSP (propval
))
19005 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19007 Lisp_Object propelt
;
19008 propelt
= XCAR (proptail
);
19009 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19011 register Lisp_Object tem
;
19013 if (EQ (propelt
, tem
))
19015 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19016 return NILP (XCDR (tem
)) ? 1 : 2;
19024 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19025 doc
: /* Non-nil if the property makes the text invisible.
19026 POS-OR-PROP can be a marker or number, in which case it is taken to be
19027 a position in the current buffer and the value of the `invisible' property
19028 is checked; or it can be some other value, which is then presumed to be the
19029 value of the `invisible' property of the text of interest.
19030 The non-nil value returned can be t for truly invisible text or something
19031 else if the text is replaced by an ellipsis. */)
19033 Lisp_Object pos_or_prop
;
19036 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19037 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19039 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19040 return (invis
== 0 ? Qnil
19042 : make_number (invis
));
19045 /* Calculate a width or height in pixels from a specification using
19046 the following elements:
19049 NUM - a (fractional) multiple of the default font width/height
19050 (NUM) - specifies exactly NUM pixels
19051 UNIT - a fixed number of pixels, see below.
19052 ELEMENT - size of a display element in pixels, see below.
19053 (NUM . SPEC) - equals NUM * SPEC
19054 (+ SPEC SPEC ...) - add pixel values
19055 (- SPEC SPEC ...) - subtract pixel values
19056 (- SPEC) - negate pixel value
19059 INT or FLOAT - a number constant
19060 SYMBOL - use symbol's (buffer local) variable binding.
19063 in - pixels per inch *)
19064 mm - pixels per 1/1000 meter *)
19065 cm - pixels per 1/100 meter *)
19066 width - width of current font in pixels.
19067 height - height of current font in pixels.
19069 *) using the ratio(s) defined in display-pixels-per-inch.
19073 left-fringe - left fringe width in pixels
19074 right-fringe - right fringe width in pixels
19076 left-margin - left margin width in pixels
19077 right-margin - right margin width in pixels
19079 scroll-bar - scroll-bar area width in pixels
19083 Pixels corresponding to 5 inches:
19086 Total width of non-text areas on left side of window (if scroll-bar is on left):
19087 '(space :width (+ left-fringe left-margin scroll-bar))
19089 Align to first text column (in header line):
19090 '(space :align-to 0)
19092 Align to middle of text area minus half the width of variable `my-image'
19093 containing a loaded image:
19094 '(space :align-to (0.5 . (- text my-image)))
19096 Width of left margin minus width of 1 character in the default font:
19097 '(space :width (- left-margin 1))
19099 Width of left margin minus width of 2 characters in the current font:
19100 '(space :width (- left-margin (2 . width)))
19102 Center 1 character over left-margin (in header line):
19103 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19105 Different ways to express width of left fringe plus left margin minus one pixel:
19106 '(space :width (- (+ left-fringe left-margin) (1)))
19107 '(space :width (+ left-fringe left-margin (- (1))))
19108 '(space :width (+ left-fringe left-margin (-1)))
19112 #define NUMVAL(X) \
19113 ((INTEGERP (X) || FLOATP (X)) \
19118 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19123 int width_p
, *align_to
;
19127 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19128 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19131 return OK_PIXELS (0);
19133 xassert (FRAME_LIVE_P (it
->f
));
19135 if (SYMBOLP (prop
))
19137 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19139 char *unit
= SDATA (SYMBOL_NAME (prop
));
19141 if (unit
[0] == 'i' && unit
[1] == 'n')
19143 else if (unit
[0] == 'm' && unit
[1] == 'm')
19145 else if (unit
[0] == 'c' && unit
[1] == 'm')
19152 #ifdef HAVE_WINDOW_SYSTEM
19153 if (FRAME_WINDOW_P (it
->f
)
19155 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19156 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19158 return OK_PIXELS (ppi
/ pixels
);
19161 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19162 || (CONSP (Vdisplay_pixels_per_inch
)
19164 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19165 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19167 return OK_PIXELS (ppi
/ pixels
);
19173 #ifdef HAVE_WINDOW_SYSTEM
19174 if (EQ (prop
, Qheight
))
19175 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19176 if (EQ (prop
, Qwidth
))
19177 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19179 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19180 return OK_PIXELS (1);
19183 if (EQ (prop
, Qtext
))
19184 return OK_PIXELS (width_p
19185 ? window_box_width (it
->w
, TEXT_AREA
)
19186 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19188 if (align_to
&& *align_to
< 0)
19191 if (EQ (prop
, Qleft
))
19192 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19193 if (EQ (prop
, Qright
))
19194 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19195 if (EQ (prop
, Qcenter
))
19196 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19197 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19198 if (EQ (prop
, Qleft_fringe
))
19199 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19200 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19201 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19202 if (EQ (prop
, Qright_fringe
))
19203 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19204 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19205 : window_box_right_offset (it
->w
, TEXT_AREA
));
19206 if (EQ (prop
, Qleft_margin
))
19207 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19208 if (EQ (prop
, Qright_margin
))
19209 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19210 if (EQ (prop
, Qscroll_bar
))
19211 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19213 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19214 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19215 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19220 if (EQ (prop
, Qleft_fringe
))
19221 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19222 if (EQ (prop
, Qright_fringe
))
19223 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19224 if (EQ (prop
, Qleft_margin
))
19225 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19226 if (EQ (prop
, Qright_margin
))
19227 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19228 if (EQ (prop
, Qscroll_bar
))
19229 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19232 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19235 if (INTEGERP (prop
) || FLOATP (prop
))
19237 int base_unit
= (width_p
19238 ? FRAME_COLUMN_WIDTH (it
->f
)
19239 : FRAME_LINE_HEIGHT (it
->f
));
19240 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19245 Lisp_Object car
= XCAR (prop
);
19246 Lisp_Object cdr
= XCDR (prop
);
19250 #ifdef HAVE_WINDOW_SYSTEM
19251 if (FRAME_WINDOW_P (it
->f
)
19252 && valid_image_p (prop
))
19254 int id
= lookup_image (it
->f
, prop
);
19255 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19257 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19260 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19266 while (CONSP (cdr
))
19268 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19269 font
, width_p
, align_to
))
19272 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19277 if (EQ (car
, Qminus
))
19279 return OK_PIXELS (pixels
);
19282 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19285 if (INTEGERP (car
) || FLOATP (car
))
19288 pixels
= XFLOATINT (car
);
19290 return OK_PIXELS (pixels
);
19291 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19292 font
, width_p
, align_to
))
19293 return OK_PIXELS (pixels
* fact
);
19304 /***********************************************************************
19306 ***********************************************************************/
19308 #ifdef HAVE_WINDOW_SYSTEM
19313 dump_glyph_string (s
)
19314 struct glyph_string
*s
;
19316 fprintf (stderr
, "glyph string\n");
19317 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19318 s
->x
, s
->y
, s
->width
, s
->height
);
19319 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19320 fprintf (stderr
, " hl = %d\n", s
->hl
);
19321 fprintf (stderr
, " left overhang = %d, right = %d\n",
19322 s
->left_overhang
, s
->right_overhang
);
19323 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19324 fprintf (stderr
, " extends to end of line = %d\n",
19325 s
->extends_to_end_of_line_p
);
19326 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19327 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19330 #endif /* GLYPH_DEBUG */
19332 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19333 of XChar2b structures for S; it can't be allocated in
19334 init_glyph_string because it must be allocated via `alloca'. W
19335 is the window on which S is drawn. ROW and AREA are the glyph row
19336 and area within the row from which S is constructed. START is the
19337 index of the first glyph structure covered by S. HL is a
19338 face-override for drawing S. */
19341 #define OPTIONAL_HDC(hdc) hdc,
19342 #define DECLARE_HDC(hdc) HDC hdc;
19343 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19344 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19347 #ifndef OPTIONAL_HDC
19348 #define OPTIONAL_HDC(hdc)
19349 #define DECLARE_HDC(hdc)
19350 #define ALLOCATE_HDC(hdc, f)
19351 #define RELEASE_HDC(hdc, f)
19355 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19356 struct glyph_string
*s
;
19360 struct glyph_row
*row
;
19361 enum glyph_row_area area
;
19363 enum draw_glyphs_face hl
;
19365 bzero (s
, sizeof *s
);
19367 s
->f
= XFRAME (w
->frame
);
19371 s
->display
= FRAME_X_DISPLAY (s
->f
);
19372 s
->window
= FRAME_X_WINDOW (s
->f
);
19373 s
->char2b
= char2b
;
19377 s
->first_glyph
= row
->glyphs
[area
] + start
;
19378 s
->height
= row
->height
;
19379 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19380 s
->ybase
= s
->y
+ row
->ascent
;
19384 /* Append the list of glyph strings with head H and tail T to the list
19385 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19388 append_glyph_string_lists (head
, tail
, h
, t
)
19389 struct glyph_string
**head
, **tail
;
19390 struct glyph_string
*h
, *t
;
19404 /* Prepend the list of glyph strings with head H and tail T to the
19405 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19409 prepend_glyph_string_lists (head
, tail
, h
, t
)
19410 struct glyph_string
**head
, **tail
;
19411 struct glyph_string
*h
, *t
;
19425 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19426 Set *HEAD and *TAIL to the resulting list. */
19429 append_glyph_string (head
, tail
, s
)
19430 struct glyph_string
**head
, **tail
;
19431 struct glyph_string
*s
;
19433 s
->next
= s
->prev
= NULL
;
19434 append_glyph_string_lists (head
, tail
, s
, s
);
19438 /* Get face and two-byte form of character C in face FACE_ID on frame
19439 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19440 means we want to display multibyte text. DISPLAY_P non-zero means
19441 make sure that X resources for the face returned are allocated.
19442 Value is a pointer to a realized face that is ready for display if
19443 DISPLAY_P is non-zero. */
19445 static INLINE
struct face
*
19446 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19450 int multibyte_p
, display_p
;
19452 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19456 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19458 if (code
!= FONT_INVALID_CODE
)
19459 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19461 STORE_XCHAR2B (char2b
, 0, 0);
19464 /* Make sure X resources of the face are allocated. */
19465 #ifdef HAVE_X_WINDOWS
19469 xassert (face
!= NULL
);
19470 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19477 /* Get face and two-byte form of character glyph GLYPH on frame F.
19478 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19479 a pointer to a realized face that is ready for display. */
19481 static INLINE
struct face
*
19482 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19484 struct glyph
*glyph
;
19490 xassert (glyph
->type
== CHAR_GLYPH
);
19491 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19500 if (CHAR_BYTE8_P (glyph
->u
.ch
))
19501 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
19503 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19505 if (code
!= FONT_INVALID_CODE
)
19506 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19508 STORE_XCHAR2B (char2b
, 0, 0);
19511 /* Make sure X resources of the face are allocated. */
19512 xassert (face
!= NULL
);
19513 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19518 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
19519 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
19522 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
19526 if (CHAR_BYTE8_P (c
))
19527 code
= CHAR_TO_BYTE8 (c
);
19529 code
= font
->driver
->encode_char (font
, c
);
19531 if (code
== FONT_INVALID_CODE
)
19533 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19538 /* Fill glyph string S with composition components specified by S->cmp.
19540 BASE_FACE is the base face of the composition.
19541 S->cmp_from is the index of the first component for S.
19543 OVERLAPS non-zero means S should draw the foreground only, and use
19544 its physical height for clipping. See also draw_glyphs.
19546 Value is the index of a component not in S. */
19549 fill_composite_glyph_string (s
, base_face
, overlaps
)
19550 struct glyph_string
*s
;
19551 struct face
*base_face
;
19555 /* For all glyphs of this composition, starting at the offset
19556 S->cmp_from, until we reach the end of the definition or encounter a
19557 glyph that requires the different face, add it to S. */
19562 s
->for_overlaps
= overlaps
;
19565 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
19567 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19571 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19574 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19575 s
->char2b
+ i
, 1, 1);
19581 s
->font
= s
->face
->font
;
19583 else if (s
->face
!= face
)
19591 /* All glyph strings for the same composition has the same width,
19592 i.e. the width set for the first component of the composition. */
19593 s
->width
= s
->first_glyph
->pixel_width
;
19595 /* If the specified font could not be loaded, use the frame's
19596 default font, but record the fact that we couldn't load it in
19597 the glyph string so that we can draw rectangles for the
19598 characters of the glyph string. */
19599 if (s
->font
== NULL
)
19601 s
->font_not_found_p
= 1;
19602 s
->font
= FRAME_FONT (s
->f
);
19605 /* Adjust base line for subscript/superscript text. */
19606 s
->ybase
+= s
->first_glyph
->voffset
;
19608 /* This glyph string must always be drawn with 16-bit functions. */
19615 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
19616 struct glyph_string
*s
;
19618 int start
, end
, overlaps
;
19620 struct glyph
*glyph
, *last
;
19621 Lisp_Object lgstring
;
19624 s
->for_overlaps
= overlaps
;
19625 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19626 last
= s
->row
->glyphs
[s
->area
] + end
;
19627 s
->cmp_id
= glyph
->u
.cmp
.id
;
19628 s
->cmp_from
= glyph
->u
.cmp
.from
;
19629 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
19630 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19631 lgstring
= composition_gstring_from_id (s
->cmp_id
);
19632 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
19634 while (glyph
< last
19635 && glyph
->u
.cmp
.automatic
19636 && glyph
->u
.cmp
.id
== s
->cmp_id
19637 && s
->cmp_to
== glyph
->u
.cmp
.from
)
19638 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
19640 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
19642 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
19643 unsigned code
= LGLYPH_CODE (lglyph
);
19645 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
19647 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
19648 return glyph
- s
->row
->glyphs
[s
->area
];
19652 /* Fill glyph string S from a sequence of character glyphs.
19654 FACE_ID is the face id of the string. START is the index of the
19655 first glyph to consider, END is the index of the last + 1.
19656 OVERLAPS non-zero means S should draw the foreground only, and use
19657 its physical height for clipping. See also draw_glyphs.
19659 Value is the index of the first glyph not in S. */
19662 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19663 struct glyph_string
*s
;
19665 int start
, end
, overlaps
;
19667 struct glyph
*glyph
, *last
;
19669 int glyph_not_available_p
;
19671 xassert (s
->f
== XFRAME (s
->w
->frame
));
19672 xassert (s
->nchars
== 0);
19673 xassert (start
>= 0 && end
> start
);
19675 s
->for_overlaps
= overlaps
;
19676 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19677 last
= s
->row
->glyphs
[s
->area
] + end
;
19678 voffset
= glyph
->voffset
;
19679 s
->padding_p
= glyph
->padding_p
;
19680 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19682 while (glyph
< last
19683 && glyph
->type
== CHAR_GLYPH
19684 && glyph
->voffset
== voffset
19685 /* Same face id implies same font, nowadays. */
19686 && glyph
->face_id
== face_id
19687 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19691 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19692 s
->char2b
+ s
->nchars
,
19694 s
->two_byte_p
= two_byte_p
;
19696 xassert (s
->nchars
<= end
- start
);
19697 s
->width
+= glyph
->pixel_width
;
19698 if (glyph
++->padding_p
!= s
->padding_p
)
19702 s
->font
= s
->face
->font
;
19704 /* If the specified font could not be loaded, use the frame's font,
19705 but record the fact that we couldn't load it in
19706 S->font_not_found_p so that we can draw rectangles for the
19707 characters of the glyph string. */
19708 if (s
->font
== NULL
|| glyph_not_available_p
)
19710 s
->font_not_found_p
= 1;
19711 s
->font
= FRAME_FONT (s
->f
);
19714 /* Adjust base line for subscript/superscript text. */
19715 s
->ybase
+= voffset
;
19717 xassert (s
->face
&& s
->face
->gc
);
19718 return glyph
- s
->row
->glyphs
[s
->area
];
19722 /* Fill glyph string S from image glyph S->first_glyph. */
19725 fill_image_glyph_string (s
)
19726 struct glyph_string
*s
;
19728 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19729 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19731 s
->slice
= s
->first_glyph
->slice
;
19732 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19733 s
->font
= s
->face
->font
;
19734 s
->width
= s
->first_glyph
->pixel_width
;
19736 /* Adjust base line for subscript/superscript text. */
19737 s
->ybase
+= s
->first_glyph
->voffset
;
19741 /* Fill glyph string S from a sequence of stretch glyphs.
19743 ROW is the glyph row in which the glyphs are found, AREA is the
19744 area within the row. START is the index of the first glyph to
19745 consider, END is the index of the last + 1.
19747 Value is the index of the first glyph not in S. */
19750 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19751 struct glyph_string
*s
;
19752 struct glyph_row
*row
;
19753 enum glyph_row_area area
;
19756 struct glyph
*glyph
, *last
;
19757 int voffset
, face_id
;
19759 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19761 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19762 last
= s
->row
->glyphs
[s
->area
] + end
;
19763 face_id
= glyph
->face_id
;
19764 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19765 s
->font
= s
->face
->font
;
19766 s
->width
= glyph
->pixel_width
;
19768 voffset
= glyph
->voffset
;
19772 && glyph
->type
== STRETCH_GLYPH
19773 && glyph
->voffset
== voffset
19774 && glyph
->face_id
== face_id
);
19776 s
->width
+= glyph
->pixel_width
;
19778 /* Adjust base line for subscript/superscript text. */
19779 s
->ybase
+= voffset
;
19781 /* The case that face->gc == 0 is handled when drawing the glyph
19782 string by calling PREPARE_FACE_FOR_DISPLAY. */
19784 return glyph
- s
->row
->glyphs
[s
->area
];
19787 static struct font_metrics
*
19788 get_per_char_metric (f
, font
, char2b
)
19793 static struct font_metrics metrics
;
19794 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19796 if (! font
|| code
== FONT_INVALID_CODE
)
19798 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19803 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19804 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19805 assumed to be zero. */
19808 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19809 struct glyph
*glyph
;
19813 *left
= *right
= 0;
19815 if (glyph
->type
== CHAR_GLYPH
)
19819 struct font_metrics
*pcm
;
19821 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19822 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19824 if (pcm
->rbearing
> pcm
->width
)
19825 *right
= pcm
->rbearing
- pcm
->width
;
19826 if (pcm
->lbearing
< 0)
19827 *left
= -pcm
->lbearing
;
19830 else if (glyph
->type
== COMPOSITE_GLYPH
)
19832 if (! glyph
->u
.cmp
.automatic
)
19834 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
19836 if (cmp
->rbearing
> cmp
->pixel_width
)
19837 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19838 if (cmp
->lbearing
< 0)
19839 *left
= - cmp
->lbearing
;
19843 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
19844 struct font_metrics metrics
;
19846 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
19847 glyph
->u
.cmp
.to
+ 1, &metrics
);
19848 if (metrics
.rbearing
> metrics
.width
)
19849 *right
= metrics
.rbearing
- metrics
.width
;
19850 if (metrics
.lbearing
< 0)
19851 *left
= - metrics
.lbearing
;
19857 /* Return the index of the first glyph preceding glyph string S that
19858 is overwritten by S because of S's left overhang. Value is -1
19859 if no glyphs are overwritten. */
19862 left_overwritten (s
)
19863 struct glyph_string
*s
;
19867 if (s
->left_overhang
)
19870 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19871 int first
= s
->first_glyph
- glyphs
;
19873 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19874 x
-= glyphs
[i
].pixel_width
;
19885 /* Return the index of the first glyph preceding glyph string S that
19886 is overwriting S because of its right overhang. Value is -1 if no
19887 glyph in front of S overwrites S. */
19890 left_overwriting (s
)
19891 struct glyph_string
*s
;
19894 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19895 int first
= s
->first_glyph
- glyphs
;
19899 for (i
= first
- 1; i
>= 0; --i
)
19902 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19905 x
-= glyphs
[i
].pixel_width
;
19912 /* Return the index of the last glyph following glyph string S that is
19913 overwritten by S because of S's right overhang. Value is -1 if
19914 no such glyph is found. */
19917 right_overwritten (s
)
19918 struct glyph_string
*s
;
19922 if (s
->right_overhang
)
19925 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19926 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19927 int end
= s
->row
->used
[s
->area
];
19929 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19930 x
+= glyphs
[i
].pixel_width
;
19939 /* Return the index of the last glyph following glyph string S that
19940 overwrites S because of its left overhang. Value is negative
19941 if no such glyph is found. */
19944 right_overwriting (s
)
19945 struct glyph_string
*s
;
19948 int end
= s
->row
->used
[s
->area
];
19949 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19950 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19954 for (i
= first
; i
< end
; ++i
)
19957 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19960 x
+= glyphs
[i
].pixel_width
;
19967 /* Set background width of glyph string S. START is the index of the
19968 first glyph following S. LAST_X is the right-most x-position + 1
19969 in the drawing area. */
19972 set_glyph_string_background_width (s
, start
, last_x
)
19973 struct glyph_string
*s
;
19977 /* If the face of this glyph string has to be drawn to the end of
19978 the drawing area, set S->extends_to_end_of_line_p. */
19980 if (start
== s
->row
->used
[s
->area
]
19981 && s
->area
== TEXT_AREA
19982 && ((s
->row
->fill_line_p
19983 && (s
->hl
== DRAW_NORMAL_TEXT
19984 || s
->hl
== DRAW_IMAGE_RAISED
19985 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19986 || s
->hl
== DRAW_MOUSE_FACE
))
19987 s
->extends_to_end_of_line_p
= 1;
19989 /* If S extends its face to the end of the line, set its
19990 background_width to the distance to the right edge of the drawing
19992 if (s
->extends_to_end_of_line_p
)
19993 s
->background_width
= last_x
- s
->x
+ 1;
19995 s
->background_width
= s
->width
;
19999 /* Compute overhangs and x-positions for glyph string S and its
20000 predecessors, or successors. X is the starting x-position for S.
20001 BACKWARD_P non-zero means process predecessors. */
20004 compute_overhangs_and_x (s
, x
, backward_p
)
20005 struct glyph_string
*s
;
20013 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20014 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20024 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20025 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20035 /* The following macros are only called from draw_glyphs below.
20036 They reference the following parameters of that function directly:
20037 `w', `row', `area', and `overlap_p'
20038 as well as the following local variables:
20039 `s', `f', and `hdc' (in W32) */
20042 /* On W32, silently add local `hdc' variable to argument list of
20043 init_glyph_string. */
20044 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20045 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20047 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20048 init_glyph_string (s, char2b, w, row, area, start, hl)
20051 /* Add a glyph string for a stretch glyph to the list of strings
20052 between HEAD and TAIL. START is the index of the stretch glyph in
20053 row area AREA of glyph row ROW. END is the index of the last glyph
20054 in that glyph row area. X is the current output position assigned
20055 to the new glyph string constructed. HL overrides that face of the
20056 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20057 is the right-most x-position of the drawing area. */
20059 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20060 and below -- keep them on one line. */
20061 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20064 s = (struct glyph_string *) alloca (sizeof *s); \
20065 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20066 START = fill_stretch_glyph_string (s, row, area, START, END); \
20067 append_glyph_string (&HEAD, &TAIL, s); \
20073 /* Add a glyph string for an image glyph to the list of strings
20074 between HEAD and TAIL. START is the index of the image glyph in
20075 row area AREA of glyph row ROW. END is the index of the last glyph
20076 in that glyph row area. X is the current output position assigned
20077 to the new glyph string constructed. HL overrides that face of the
20078 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20079 is the right-most x-position of the drawing area. */
20081 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20084 s = (struct glyph_string *) alloca (sizeof *s); \
20085 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20086 fill_image_glyph_string (s); \
20087 append_glyph_string (&HEAD, &TAIL, s); \
20094 /* Add a glyph string for a sequence of character glyphs to the list
20095 of strings between HEAD and TAIL. START is the index of the first
20096 glyph in row area AREA of glyph row ROW that is part of the new
20097 glyph string. END is the index of the last glyph in that glyph row
20098 area. X is the current output position assigned to the new glyph
20099 string constructed. HL overrides that face of the glyph; e.g. it
20100 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20101 right-most x-position of the drawing area. */
20103 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20109 face_id = (row)->glyphs[area][START].face_id; \
20111 s = (struct glyph_string *) alloca (sizeof *s); \
20112 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20113 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20114 append_glyph_string (&HEAD, &TAIL, s); \
20116 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20121 /* Add a glyph string for a composite sequence to the list of strings
20122 between HEAD and TAIL. START is the index of the first glyph in
20123 row area AREA of glyph row ROW that is part of the new glyph
20124 string. END is the index of the last glyph in that glyph row area.
20125 X is the current output position assigned to the new glyph string
20126 constructed. HL overrides that face of the glyph; e.g. it is
20127 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20128 x-position of the drawing area. */
20130 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20132 int face_id = (row)->glyphs[area][START].face_id; \
20133 struct face *base_face = FACE_FROM_ID (f, face_id); \
20134 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20135 struct composition *cmp = composition_table[cmp_id]; \
20137 struct glyph_string *first_s; \
20140 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20142 /* Make glyph_strings for each glyph sequence that is drawable by \
20143 the same face, and append them to HEAD/TAIL. */ \
20144 for (n = 0; n < cmp->glyph_len;) \
20146 s = (struct glyph_string *) alloca (sizeof *s); \
20147 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20148 append_glyph_string (&(HEAD), &(TAIL), s); \
20154 n = fill_composite_glyph_string (s, base_face, overlaps); \
20162 /* Add a glyph string for a glyph-string sequence to the list of strings
20163 between HEAD and TAIL. */
20165 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20169 Lisp_Object gstring; \
20171 face_id = (row)->glyphs[area][START].face_id; \
20172 gstring = (composition_gstring_from_id \
20173 ((row)->glyphs[area][START].u.cmp.id)); \
20174 s = (struct glyph_string *) alloca (sizeof *s); \
20175 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20176 * LGSTRING_GLYPH_LEN (gstring)); \
20177 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20178 append_glyph_string (&(HEAD), &(TAIL), s); \
20180 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20184 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20185 of AREA of glyph row ROW on window W between indices START and END.
20186 HL overrides the face for drawing glyph strings, e.g. it is
20187 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20188 x-positions of the drawing area.
20190 This is an ugly monster macro construct because we must use alloca
20191 to allocate glyph strings (because draw_glyphs can be called
20192 asynchronously). */
20194 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20197 HEAD = TAIL = NULL; \
20198 while (START < END) \
20200 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20201 switch (first_glyph->type) \
20204 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20208 case COMPOSITE_GLYPH: \
20209 if (first_glyph->u.cmp.automatic) \
20210 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20213 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20217 case STRETCH_GLYPH: \
20218 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20222 case IMAGE_GLYPH: \
20223 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20233 set_glyph_string_background_width (s, START, LAST_X); \
20240 /* Draw glyphs between START and END in AREA of ROW on window W,
20241 starting at x-position X. X is relative to AREA in W. HL is a
20242 face-override with the following meaning:
20244 DRAW_NORMAL_TEXT draw normally
20245 DRAW_CURSOR draw in cursor face
20246 DRAW_MOUSE_FACE draw in mouse face.
20247 DRAW_INVERSE_VIDEO draw in mode line face
20248 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20249 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20251 If OVERLAPS is non-zero, draw only the foreground of characters and
20252 clip to the physical height of ROW. Non-zero value also defines
20253 the overlapping part to be drawn:
20255 OVERLAPS_PRED overlap with preceding rows
20256 OVERLAPS_SUCC overlap with succeeding rows
20257 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20258 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20260 Value is the x-position reached, relative to AREA of W. */
20263 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20266 struct glyph_row
*row
;
20267 enum glyph_row_area area
;
20268 EMACS_INT start
, end
;
20269 enum draw_glyphs_face hl
;
20272 struct glyph_string
*head
, *tail
;
20273 struct glyph_string
*s
;
20274 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20275 int i
, j
, x_reached
, last_x
, area_left
= 0;
20276 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20279 ALLOCATE_HDC (hdc
, f
);
20281 /* Let's rather be paranoid than getting a SEGV. */
20282 end
= min (end
, row
->used
[area
]);
20283 start
= max (0, start
);
20284 start
= min (end
, start
);
20286 /* Translate X to frame coordinates. Set last_x to the right
20287 end of the drawing area. */
20288 if (row
->full_width_p
)
20290 /* X is relative to the left edge of W, without scroll bars
20292 area_left
= WINDOW_LEFT_EDGE_X (w
);
20293 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20297 area_left
= window_box_left (w
, area
);
20298 last_x
= area_left
+ window_box_width (w
, area
);
20302 /* Build a doubly-linked list of glyph_string structures between
20303 head and tail from what we have to draw. Note that the macro
20304 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20305 the reason we use a separate variable `i'. */
20307 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20309 x_reached
= tail
->x
+ tail
->background_width
;
20313 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20314 the row, redraw some glyphs in front or following the glyph
20315 strings built above. */
20316 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20318 struct glyph_string
*h
, *t
;
20319 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20320 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20323 /* If mouse highlighting is on, we may need to draw adjacent
20324 glyphs using mouse-face highlighting. */
20325 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20327 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20329 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20330 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20332 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20334 check_mouse_face
= 1;
20335 mouse_beg_col
= (row
== mouse_beg_row
)
20336 ? dpyinfo
->mouse_face_beg_col
: 0;
20337 mouse_end_col
= (row
== mouse_end_row
)
20338 ? dpyinfo
->mouse_face_end_col
20339 : row
->used
[TEXT_AREA
];
20343 /* Compute overhangs for all glyph strings. */
20344 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20345 for (s
= head
; s
; s
= s
->next
)
20346 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20348 /* Prepend glyph strings for glyphs in front of the first glyph
20349 string that are overwritten because of the first glyph
20350 string's left overhang. The background of all strings
20351 prepended must be drawn because the first glyph string
20353 i
= left_overwritten (head
);
20356 enum draw_glyphs_face overlap_hl
;
20358 /* If this row contains mouse highlighting, attempt to draw
20359 the overlapped glyphs with the correct highlight. This
20360 code fails if the overlap encompasses more than one glyph
20361 and mouse-highlight spans only some of these glyphs.
20362 However, making it work perfectly involves a lot more
20363 code, and I don't know if the pathological case occurs in
20364 practice, so we'll stick to this for now. --- cyd */
20365 if (check_mouse_face
20366 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20367 overlap_hl
= DRAW_MOUSE_FACE
;
20369 overlap_hl
= DRAW_NORMAL_TEXT
;
20372 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20373 overlap_hl
, dummy_x
, last_x
);
20375 compute_overhangs_and_x (t
, head
->x
, 1);
20376 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20380 /* Prepend glyph strings for glyphs in front of the first glyph
20381 string that overwrite that glyph string because of their
20382 right overhang. For these strings, only the foreground must
20383 be drawn, because it draws over the glyph string at `head'.
20384 The background must not be drawn because this would overwrite
20385 right overhangs of preceding glyphs for which no glyph
20387 i
= left_overwriting (head
);
20390 enum draw_glyphs_face overlap_hl
;
20392 if (check_mouse_face
20393 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20394 overlap_hl
= DRAW_MOUSE_FACE
;
20396 overlap_hl
= DRAW_NORMAL_TEXT
;
20399 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20400 overlap_hl
, dummy_x
, last_x
);
20401 for (s
= h
; s
; s
= s
->next
)
20402 s
->background_filled_p
= 1;
20403 compute_overhangs_and_x (t
, head
->x
, 1);
20404 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20407 /* Append glyphs strings for glyphs following the last glyph
20408 string tail that are overwritten by tail. The background of
20409 these strings has to be drawn because tail's foreground draws
20411 i
= right_overwritten (tail
);
20414 enum draw_glyphs_face overlap_hl
;
20416 if (check_mouse_face
20417 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20418 overlap_hl
= DRAW_MOUSE_FACE
;
20420 overlap_hl
= DRAW_NORMAL_TEXT
;
20422 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20423 overlap_hl
, x
, last_x
);
20424 /* Because BUILD_GLYPH_STRINGS updates the first argument,
20425 we don't have `end = i;' here. */
20426 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20427 append_glyph_string_lists (&head
, &tail
, h
, t
);
20431 /* Append glyph strings for glyphs following the last glyph
20432 string tail that overwrite tail. The foreground of such
20433 glyphs has to be drawn because it writes into the background
20434 of tail. The background must not be drawn because it could
20435 paint over the foreground of following glyphs. */
20436 i
= right_overwriting (tail
);
20439 enum draw_glyphs_face overlap_hl
;
20440 if (check_mouse_face
20441 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20442 overlap_hl
= DRAW_MOUSE_FACE
;
20444 overlap_hl
= DRAW_NORMAL_TEXT
;
20447 i
++; /* We must include the Ith glyph. */
20448 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20449 overlap_hl
, x
, last_x
);
20450 for (s
= h
; s
; s
= s
->next
)
20451 s
->background_filled_p
= 1;
20452 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20453 append_glyph_string_lists (&head
, &tail
, h
, t
);
20455 if (clip_head
|| clip_tail
)
20456 for (s
= head
; s
; s
= s
->next
)
20458 s
->clip_head
= clip_head
;
20459 s
->clip_tail
= clip_tail
;
20463 /* Draw all strings. */
20464 for (s
= head
; s
; s
= s
->next
)
20465 FRAME_RIF (f
)->draw_glyph_string (s
);
20468 /* When focus a sole frame and move horizontally, this sets on_p to 0
20469 causing a failure to erase prev cursor position. */
20470 if (area
== TEXT_AREA
20471 && !row
->full_width_p
20472 /* When drawing overlapping rows, only the glyph strings'
20473 foreground is drawn, which doesn't erase a cursor
20477 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20478 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20479 : (tail
? tail
->x
+ tail
->background_width
: x
));
20483 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20484 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20488 /* Value is the x-position up to which drawn, relative to AREA of W.
20489 This doesn't include parts drawn because of overhangs. */
20490 if (row
->full_width_p
)
20491 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20493 x_reached
-= area_left
;
20495 RELEASE_HDC (hdc
, f
);
20500 /* Expand row matrix if too narrow. Don't expand if area
20503 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20505 if (!fonts_changed_p \
20506 && (it->glyph_row->glyphs[area] \
20507 < it->glyph_row->glyphs[area + 1])) \
20509 it->w->ncols_scale_factor++; \
20510 fonts_changed_p = 1; \
20514 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20515 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20521 struct glyph
*glyph
;
20522 enum glyph_row_area area
= it
->area
;
20524 xassert (it
->glyph_row
);
20525 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20527 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20528 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20530 glyph
->charpos
= CHARPOS (it
->position
);
20531 glyph
->object
= it
->object
;
20532 if (it
->pixel_width
> 0)
20534 glyph
->pixel_width
= it
->pixel_width
;
20535 glyph
->padding_p
= 0;
20539 /* Assure at least 1-pixel width. Otherwise, cursor can't
20540 be displayed correctly. */
20541 glyph
->pixel_width
= 1;
20542 glyph
->padding_p
= 1;
20544 glyph
->ascent
= it
->ascent
;
20545 glyph
->descent
= it
->descent
;
20546 glyph
->voffset
= it
->voffset
;
20547 glyph
->type
= CHAR_GLYPH
;
20548 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20549 glyph
->multibyte_p
= it
->multibyte_p
;
20550 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20551 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20552 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20553 || it
->phys_descent
> it
->descent
);
20554 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20555 glyph
->face_id
= it
->face_id
;
20556 glyph
->u
.ch
= it
->char_to_display
;
20557 glyph
->slice
= null_glyph_slice
;
20558 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20559 ++it
->glyph_row
->used
[area
];
20562 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20565 /* Store one glyph for the composition IT->cmp_it.id in
20566 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
20570 append_composite_glyph (it
)
20573 struct glyph
*glyph
;
20574 enum glyph_row_area area
= it
->area
;
20576 xassert (it
->glyph_row
);
20578 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20579 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20581 glyph
->charpos
= CHARPOS (it
->position
);
20582 glyph
->object
= it
->object
;
20583 glyph
->pixel_width
= it
->pixel_width
;
20584 glyph
->ascent
= it
->ascent
;
20585 glyph
->descent
= it
->descent
;
20586 glyph
->voffset
= it
->voffset
;
20587 glyph
->type
= COMPOSITE_GLYPH
;
20588 if (it
->cmp_it
.ch
< 0)
20590 glyph
->u
.cmp
.automatic
= 0;
20591 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20595 glyph
->u
.cmp
.automatic
= 1;
20596 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20597 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
20598 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
20600 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20601 glyph
->multibyte_p
= it
->multibyte_p
;
20602 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20603 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20604 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20605 || it
->phys_descent
> it
->descent
);
20606 glyph
->padding_p
= 0;
20607 glyph
->glyph_not_available_p
= 0;
20608 glyph
->face_id
= it
->face_id
;
20609 glyph
->slice
= null_glyph_slice
;
20610 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20611 ++it
->glyph_row
->used
[area
];
20614 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20618 /* Change IT->ascent and IT->height according to the setting of
20622 take_vertical_position_into_account (it
)
20627 if (it
->voffset
< 0)
20628 /* Increase the ascent so that we can display the text higher
20630 it
->ascent
-= it
->voffset
;
20632 /* Increase the descent so that we can display the text lower
20634 it
->descent
+= it
->voffset
;
20639 /* Produce glyphs/get display metrics for the image IT is loaded with.
20640 See the description of struct display_iterator in dispextern.h for
20641 an overview of struct display_iterator. */
20644 produce_image_glyph (it
)
20649 int glyph_ascent
, crop
;
20650 struct glyph_slice slice
;
20652 xassert (it
->what
== IT_IMAGE
);
20654 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20656 /* Make sure X resources of the face is loaded. */
20657 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20659 if (it
->image_id
< 0)
20661 /* Fringe bitmap. */
20662 it
->ascent
= it
->phys_ascent
= 0;
20663 it
->descent
= it
->phys_descent
= 0;
20664 it
->pixel_width
= 0;
20669 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20671 /* Make sure X resources of the image is loaded. */
20672 prepare_image_for_display (it
->f
, img
);
20674 slice
.x
= slice
.y
= 0;
20675 slice
.width
= img
->width
;
20676 slice
.height
= img
->height
;
20678 if (INTEGERP (it
->slice
.x
))
20679 slice
.x
= XINT (it
->slice
.x
);
20680 else if (FLOATP (it
->slice
.x
))
20681 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20683 if (INTEGERP (it
->slice
.y
))
20684 slice
.y
= XINT (it
->slice
.y
);
20685 else if (FLOATP (it
->slice
.y
))
20686 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20688 if (INTEGERP (it
->slice
.width
))
20689 slice
.width
= XINT (it
->slice
.width
);
20690 else if (FLOATP (it
->slice
.width
))
20691 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20693 if (INTEGERP (it
->slice
.height
))
20694 slice
.height
= XINT (it
->slice
.height
);
20695 else if (FLOATP (it
->slice
.height
))
20696 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20698 if (slice
.x
>= img
->width
)
20699 slice
.x
= img
->width
;
20700 if (slice
.y
>= img
->height
)
20701 slice
.y
= img
->height
;
20702 if (slice
.x
+ slice
.width
>= img
->width
)
20703 slice
.width
= img
->width
- slice
.x
;
20704 if (slice
.y
+ slice
.height
> img
->height
)
20705 slice
.height
= img
->height
- slice
.y
;
20707 if (slice
.width
== 0 || slice
.height
== 0)
20710 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20712 it
->descent
= slice
.height
- glyph_ascent
;
20714 it
->descent
+= img
->vmargin
;
20715 if (slice
.y
+ slice
.height
== img
->height
)
20716 it
->descent
+= img
->vmargin
;
20717 it
->phys_descent
= it
->descent
;
20719 it
->pixel_width
= slice
.width
;
20721 it
->pixel_width
+= img
->hmargin
;
20722 if (slice
.x
+ slice
.width
== img
->width
)
20723 it
->pixel_width
+= img
->hmargin
;
20725 /* It's quite possible for images to have an ascent greater than
20726 their height, so don't get confused in that case. */
20727 if (it
->descent
< 0)
20732 if (face
->box
!= FACE_NO_BOX
)
20734 if (face
->box_line_width
> 0)
20737 it
->ascent
+= face
->box_line_width
;
20738 if (slice
.y
+ slice
.height
== img
->height
)
20739 it
->descent
+= face
->box_line_width
;
20742 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20743 it
->pixel_width
+= eabs (face
->box_line_width
);
20744 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20745 it
->pixel_width
+= eabs (face
->box_line_width
);
20748 take_vertical_position_into_account (it
);
20750 /* Automatically crop wide image glyphs at right edge so we can
20751 draw the cursor on same display row. */
20752 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20753 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20755 it
->pixel_width
-= crop
;
20756 slice
.width
-= crop
;
20761 struct glyph
*glyph
;
20762 enum glyph_row_area area
= it
->area
;
20764 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20765 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20767 glyph
->charpos
= CHARPOS (it
->position
);
20768 glyph
->object
= it
->object
;
20769 glyph
->pixel_width
= it
->pixel_width
;
20770 glyph
->ascent
= glyph_ascent
;
20771 glyph
->descent
= it
->descent
;
20772 glyph
->voffset
= it
->voffset
;
20773 glyph
->type
= IMAGE_GLYPH
;
20774 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20775 glyph
->multibyte_p
= it
->multibyte_p
;
20776 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20777 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20778 glyph
->overlaps_vertically_p
= 0;
20779 glyph
->padding_p
= 0;
20780 glyph
->glyph_not_available_p
= 0;
20781 glyph
->face_id
= it
->face_id
;
20782 glyph
->u
.img_id
= img
->id
;
20783 glyph
->slice
= slice
;
20784 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20785 ++it
->glyph_row
->used
[area
];
20788 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20793 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20794 of the glyph, WIDTH and HEIGHT are the width and height of the
20795 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20798 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20800 Lisp_Object object
;
20804 struct glyph
*glyph
;
20805 enum glyph_row_area area
= it
->area
;
20807 xassert (ascent
>= 0 && ascent
<= height
);
20809 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20810 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20812 glyph
->charpos
= CHARPOS (it
->position
);
20813 glyph
->object
= object
;
20814 glyph
->pixel_width
= width
;
20815 glyph
->ascent
= ascent
;
20816 glyph
->descent
= height
- ascent
;
20817 glyph
->voffset
= it
->voffset
;
20818 glyph
->type
= STRETCH_GLYPH
;
20819 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20820 glyph
->multibyte_p
= it
->multibyte_p
;
20821 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20822 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20823 glyph
->overlaps_vertically_p
= 0;
20824 glyph
->padding_p
= 0;
20825 glyph
->glyph_not_available_p
= 0;
20826 glyph
->face_id
= it
->face_id
;
20827 glyph
->u
.stretch
.ascent
= ascent
;
20828 glyph
->u
.stretch
.height
= height
;
20829 glyph
->slice
= null_glyph_slice
;
20830 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20831 ++it
->glyph_row
->used
[area
];
20834 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20838 /* Produce a stretch glyph for iterator IT. IT->object is the value
20839 of the glyph property displayed. The value must be a list
20840 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20843 1. `:width WIDTH' specifies that the space should be WIDTH *
20844 canonical char width wide. WIDTH may be an integer or floating
20847 2. `:relative-width FACTOR' specifies that the width of the stretch
20848 should be computed from the width of the first character having the
20849 `glyph' property, and should be FACTOR times that width.
20851 3. `:align-to HPOS' specifies that the space should be wide enough
20852 to reach HPOS, a value in canonical character units.
20854 Exactly one of the above pairs must be present.
20856 4. `:height HEIGHT' specifies that the height of the stretch produced
20857 should be HEIGHT, measured in canonical character units.
20859 5. `:relative-height FACTOR' specifies that the height of the
20860 stretch should be FACTOR times the height of the characters having
20861 the glyph property.
20863 Either none or exactly one of 4 or 5 must be present.
20865 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20866 of the stretch should be used for the ascent of the stretch.
20867 ASCENT must be in the range 0 <= ASCENT <= 100. */
20870 produce_stretch_glyph (it
)
20873 /* (space :width WIDTH :height HEIGHT ...) */
20874 Lisp_Object prop
, plist
;
20875 int width
= 0, height
= 0, align_to
= -1;
20876 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20879 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20880 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20882 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20884 /* List should start with `space'. */
20885 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20886 plist
= XCDR (it
->object
);
20888 /* Compute the width of the stretch. */
20889 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20890 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20892 /* Absolute width `:width WIDTH' specified and valid. */
20893 zero_width_ok_p
= 1;
20896 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20899 /* Relative width `:relative-width FACTOR' specified and valid.
20900 Compute the width of the characters having the `glyph'
20903 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20906 if (it
->multibyte_p
)
20907 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
20910 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
20911 if (! ASCII_CHAR_P (it2
.c
))
20912 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
20915 it2
.glyph_row
= NULL
;
20916 it2
.what
= IT_CHARACTER
;
20917 x_produce_glyphs (&it2
);
20918 width
= NUMVAL (prop
) * it2
.pixel_width
;
20920 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20921 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20923 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20924 align_to
= (align_to
< 0
20926 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20927 else if (align_to
< 0)
20928 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20929 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20930 zero_width_ok_p
= 1;
20933 /* Nothing specified -> width defaults to canonical char width. */
20934 width
= FRAME_COLUMN_WIDTH (it
->f
);
20936 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20939 /* Compute height. */
20940 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20941 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20944 zero_height_ok_p
= 1;
20946 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20948 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20950 height
= FONT_HEIGHT (font
);
20952 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20955 /* Compute percentage of height used for ascent. If
20956 `:ascent ASCENT' is present and valid, use that. Otherwise,
20957 derive the ascent from the font in use. */
20958 if (prop
= Fplist_get (plist
, QCascent
),
20959 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20960 ascent
= height
* NUMVAL (prop
) / 100.0;
20961 else if (!NILP (prop
)
20962 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20963 ascent
= min (max (0, (int)tem
), height
);
20965 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20967 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20968 && it
->current_x
+ width
> it
->last_visible_x
)
20969 width
= it
->last_visible_x
- it
->current_x
- 1;
20971 if (width
> 0 && height
> 0 && it
->glyph_row
)
20973 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20974 if (!STRINGP (object
))
20975 object
= it
->w
->buffer
;
20976 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20979 it
->pixel_width
= width
;
20980 it
->ascent
= it
->phys_ascent
= ascent
;
20981 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20982 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20984 take_vertical_position_into_account (it
);
20987 /* Calculate line-height and line-spacing properties.
20988 An integer value specifies explicit pixel value.
20989 A float value specifies relative value to current face height.
20990 A cons (float . face-name) specifies relative value to
20991 height of specified face font.
20993 Returns height in pixels, or nil. */
20997 calc_line_height_property (it
, val
, font
, boff
, override
)
21001 int boff
, override
;
21003 Lisp_Object face_name
= Qnil
;
21004 int ascent
, descent
, height
;
21006 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21011 face_name
= XCAR (val
);
21013 if (!NUMBERP (val
))
21014 val
= make_number (1);
21015 if (NILP (face_name
))
21017 height
= it
->ascent
+ it
->descent
;
21022 if (NILP (face_name
))
21024 font
= FRAME_FONT (it
->f
);
21025 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21027 else if (EQ (face_name
, Qt
))
21036 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21038 return make_number (-1);
21040 face
= FACE_FROM_ID (it
->f
, face_id
);
21043 return make_number (-1);
21044 boff
= font
->baseline_offset
;
21045 if (font
->vertical_centering
)
21046 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21049 ascent
= FONT_BASE (font
) + boff
;
21050 descent
= FONT_DESCENT (font
) - boff
;
21054 it
->override_ascent
= ascent
;
21055 it
->override_descent
= descent
;
21056 it
->override_boff
= boff
;
21059 height
= ascent
+ descent
;
21063 height
= (int)(XFLOAT_DATA (val
) * height
);
21064 else if (INTEGERP (val
))
21065 height
*= XINT (val
);
21067 return make_number (height
);
21072 Produce glyphs/get display metrics for the display element IT is
21073 loaded with. See the description of struct it in dispextern.h
21074 for an overview of struct it. */
21077 x_produce_glyphs (it
)
21080 int extra_line_spacing
= it
->extra_line_spacing
;
21082 it
->glyph_not_available_p
= 0;
21084 if (it
->what
== IT_CHARACTER
)
21087 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21088 struct font
*font
= face
->font
;
21089 int font_not_found_p
= font
== NULL
;
21090 struct font_metrics
*pcm
= NULL
;
21091 int boff
; /* baseline offset */
21093 if (font_not_found_p
)
21095 /* When no suitable font found, display an empty box based
21096 on the metrics of the font of the default face (or what
21098 struct face
*no_font_face
21099 = FACE_FROM_ID (it
->f
,
21100 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21101 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21102 font
= no_font_face
->font
;
21103 boff
= font
->baseline_offset
;
21107 boff
= font
->baseline_offset
;
21108 if (font
->vertical_centering
)
21109 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21112 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
21118 if (it
->override_ascent
>= 0)
21120 it
->ascent
= it
->override_ascent
;
21121 it
->descent
= it
->override_descent
;
21122 boff
= it
->override_boff
;
21126 it
->ascent
= FONT_BASE (font
) + boff
;
21127 it
->descent
= FONT_DESCENT (font
) - boff
;
21130 if (! font_not_found_p
21131 && get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
21133 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21134 if (pcm
->width
== 0
21135 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
21141 it
->phys_ascent
= pcm
->ascent
+ boff
;
21142 it
->phys_descent
= pcm
->descent
- boff
;
21143 it
->pixel_width
= pcm
->width
;
21147 it
->glyph_not_available_p
= 1;
21148 it
->phys_ascent
= it
->ascent
;
21149 it
->phys_descent
= it
->descent
;
21150 it
->pixel_width
= font
->space_width
;
21153 if (it
->constrain_row_ascent_descent_p
)
21155 if (it
->descent
> it
->max_descent
)
21157 it
->ascent
+= it
->descent
- it
->max_descent
;
21158 it
->descent
= it
->max_descent
;
21160 if (it
->ascent
> it
->max_ascent
)
21162 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21163 it
->ascent
= it
->max_ascent
;
21165 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21166 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21167 extra_line_spacing
= 0;
21170 /* If this is a space inside a region of text with
21171 `space-width' property, change its width. */
21172 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21174 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21176 /* If face has a box, add the box thickness to the character
21177 height. If character has a box line to the left and/or
21178 right, add the box line width to the character's width. */
21179 if (face
->box
!= FACE_NO_BOX
)
21181 int thick
= face
->box_line_width
;
21185 it
->ascent
+= thick
;
21186 it
->descent
+= thick
;
21191 if (it
->start_of_box_run_p
)
21192 it
->pixel_width
+= thick
;
21193 if (it
->end_of_box_run_p
)
21194 it
->pixel_width
+= thick
;
21197 /* If face has an overline, add the height of the overline
21198 (1 pixel) and a 1 pixel margin to the character height. */
21199 if (face
->overline_p
)
21200 it
->ascent
+= overline_margin
;
21202 if (it
->constrain_row_ascent_descent_p
)
21204 if (it
->ascent
> it
->max_ascent
)
21205 it
->ascent
= it
->max_ascent
;
21206 if (it
->descent
> it
->max_descent
)
21207 it
->descent
= it
->max_descent
;
21210 take_vertical_position_into_account (it
);
21212 /* If we have to actually produce glyphs, do it. */
21217 /* Translate a space with a `space-width' property
21218 into a stretch glyph. */
21219 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21220 / FONT_HEIGHT (font
));
21221 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21222 it
->ascent
+ it
->descent
, ascent
);
21227 /* If characters with lbearing or rbearing are displayed
21228 in this line, record that fact in a flag of the
21229 glyph row. This is used to optimize X output code. */
21230 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21231 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21233 if (! stretched_p
&& it
->pixel_width
== 0)
21234 /* We assure that all visible glyphs have at least 1-pixel
21236 it
->pixel_width
= 1;
21238 else if (it
->char_to_display
== '\n')
21240 /* A newline has no width, but we need the height of the
21241 line. But if previous part of the line sets a height,
21242 don't increase that height */
21244 Lisp_Object height
;
21245 Lisp_Object total_height
= Qnil
;
21247 it
->override_ascent
= -1;
21248 it
->pixel_width
= 0;
21251 height
= get_it_property(it
, Qline_height
);
21252 /* Split (line-height total-height) list */
21254 && CONSP (XCDR (height
))
21255 && NILP (XCDR (XCDR (height
))))
21257 total_height
= XCAR (XCDR (height
));
21258 height
= XCAR (height
);
21260 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21262 if (it
->override_ascent
>= 0)
21264 it
->ascent
= it
->override_ascent
;
21265 it
->descent
= it
->override_descent
;
21266 boff
= it
->override_boff
;
21270 it
->ascent
= FONT_BASE (font
) + boff
;
21271 it
->descent
= FONT_DESCENT (font
) - boff
;
21274 if (EQ (height
, Qt
))
21276 if (it
->descent
> it
->max_descent
)
21278 it
->ascent
+= it
->descent
- it
->max_descent
;
21279 it
->descent
= it
->max_descent
;
21281 if (it
->ascent
> it
->max_ascent
)
21283 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21284 it
->ascent
= it
->max_ascent
;
21286 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21287 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21288 it
->constrain_row_ascent_descent_p
= 1;
21289 extra_line_spacing
= 0;
21293 Lisp_Object spacing
;
21295 it
->phys_ascent
= it
->ascent
;
21296 it
->phys_descent
= it
->descent
;
21298 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21299 && face
->box
!= FACE_NO_BOX
21300 && face
->box_line_width
> 0)
21302 it
->ascent
+= face
->box_line_width
;
21303 it
->descent
+= face
->box_line_width
;
21306 && XINT (height
) > it
->ascent
+ it
->descent
)
21307 it
->ascent
= XINT (height
) - it
->descent
;
21309 if (!NILP (total_height
))
21310 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21313 spacing
= get_it_property(it
, Qline_spacing
);
21314 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21316 if (INTEGERP (spacing
))
21318 extra_line_spacing
= XINT (spacing
);
21319 if (!NILP (total_height
))
21320 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21324 else /* i.e. (it->char_to_display == '\t') */
21326 if (font
->space_width
> 0)
21328 int tab_width
= it
->tab_width
* font
->space_width
;
21329 int x
= it
->current_x
+ it
->continuation_lines_width
;
21330 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21332 /* If the distance from the current position to the next tab
21333 stop is less than a space character width, use the
21334 tab stop after that. */
21335 if (next_tab_x
- x
< font
->space_width
)
21336 next_tab_x
+= tab_width
;
21338 it
->pixel_width
= next_tab_x
- x
;
21340 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21341 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21345 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21346 it
->ascent
+ it
->descent
, it
->ascent
);
21351 it
->pixel_width
= 0;
21356 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
21358 /* A static composition.
21360 Note: A composition is represented as one glyph in the
21361 glyph matrix. There are no padding glyphs.
21363 Important note: pixel_width, ascent, and descent are the
21364 values of what is drawn by draw_glyphs (i.e. the values of
21365 the overall glyphs composed). */
21366 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21367 int boff
; /* baseline offset */
21368 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
21369 int glyph_len
= cmp
->glyph_len
;
21370 struct font
*font
= face
->font
;
21374 /* If we have not yet calculated pixel size data of glyphs of
21375 the composition for the current face font, calculate them
21376 now. Theoretically, we have to check all fonts for the
21377 glyphs, but that requires much time and memory space. So,
21378 here we check only the font of the first glyph. This may
21379 lead to incorrect display, but it's very rare, and C-l
21380 (recenter-top-bottom) can correct the display anyway. */
21381 if (! cmp
->font
|| cmp
->font
!= font
)
21383 /* Ascent and descent of the font of the first character
21384 of this composition (adjusted by baseline offset).
21385 Ascent and descent of overall glyphs should not be less
21386 than these, respectively. */
21387 int font_ascent
, font_descent
, font_height
;
21388 /* Bounding box of the overall glyphs. */
21389 int leftmost
, rightmost
, lowest
, highest
;
21390 int lbearing
, rbearing
;
21391 int i
, width
, ascent
, descent
;
21392 int left_padded
= 0, right_padded
= 0;
21395 struct font_metrics
*pcm
;
21396 int font_not_found_p
;
21399 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21400 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21402 if (glyph_len
< cmp
->glyph_len
)
21404 for (i
= 0; i
< glyph_len
; i
++)
21406 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21408 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21413 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21414 : IT_CHARPOS (*it
));
21415 /* If no suitable font is found, use the default font. */
21416 font_not_found_p
= font
== NULL
;
21417 if (font_not_found_p
)
21419 face
= face
->ascii_face
;
21422 boff
= font
->baseline_offset
;
21423 if (font
->vertical_centering
)
21424 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21425 font_ascent
= FONT_BASE (font
) + boff
;
21426 font_descent
= FONT_DESCENT (font
) - boff
;
21427 font_height
= FONT_HEIGHT (font
);
21429 cmp
->font
= (void *) font
;
21432 if (! font_not_found_p
)
21434 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21435 &char2b
, it
->multibyte_p
, 0);
21436 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21439 /* Initialize the bounding box. */
21442 width
= pcm
->width
;
21443 ascent
= pcm
->ascent
;
21444 descent
= pcm
->descent
;
21445 lbearing
= pcm
->lbearing
;
21446 rbearing
= pcm
->rbearing
;
21450 width
= font
->space_width
;
21451 ascent
= FONT_BASE (font
);
21452 descent
= FONT_DESCENT (font
);
21459 lowest
= - descent
+ boff
;
21460 highest
= ascent
+ boff
;
21462 if (! font_not_found_p
21463 && font
->default_ascent
21464 && CHAR_TABLE_P (Vuse_default_ascent
)
21465 && !NILP (Faref (Vuse_default_ascent
,
21466 make_number (it
->char_to_display
))))
21467 highest
= font
->default_ascent
+ boff
;
21469 /* Draw the first glyph at the normal position. It may be
21470 shifted to right later if some other glyphs are drawn
21472 cmp
->offsets
[i
* 2] = 0;
21473 cmp
->offsets
[i
* 2 + 1] = boff
;
21474 cmp
->lbearing
= lbearing
;
21475 cmp
->rbearing
= rbearing
;
21477 /* Set cmp->offsets for the remaining glyphs. */
21478 for (i
++; i
< glyph_len
; i
++)
21480 int left
, right
, btm
, top
;
21481 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21483 struct face
*this_face
;
21488 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21489 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21490 font
= this_face
->font
;
21496 this_boff
= font
->baseline_offset
;
21497 if (font
->vertical_centering
)
21498 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21499 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21500 &char2b
, it
->multibyte_p
, 0);
21501 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21504 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21507 width
= pcm
->width
;
21508 ascent
= pcm
->ascent
;
21509 descent
= pcm
->descent
;
21510 lbearing
= pcm
->lbearing
;
21511 rbearing
= pcm
->rbearing
;
21512 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21514 /* Relative composition with or without
21515 alternate chars. */
21516 left
= (leftmost
+ rightmost
- width
) / 2;
21517 btm
= - descent
+ boff
;
21518 if (font
->relative_compose
21519 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21520 || NILP (Faref (Vignore_relative_composition
,
21521 make_number (ch
)))))
21524 if (- descent
>= font
->relative_compose
)
21525 /* One extra pixel between two glyphs. */
21527 else if (ascent
<= 0)
21528 /* One extra pixel between two glyphs. */
21529 btm
= lowest
- 1 - ascent
- descent
;
21534 /* A composition rule is specified by an integer
21535 value that encodes global and new reference
21536 points (GREF and NREF). GREF and NREF are
21537 specified by numbers as below:
21539 0---1---2 -- ascent
21543 9--10--11 -- center
21545 ---3---4---5--- baseline
21547 6---7---8 -- descent
21549 int rule
= COMPOSITION_RULE (cmp
, i
);
21550 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21552 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21553 grefx
= gref
% 3, nrefx
= nref
% 3;
21554 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21556 xoff
= font_height
* (xoff
- 128) / 256;
21558 yoff
= font_height
* (yoff
- 128) / 256;
21561 + grefx
* (rightmost
- leftmost
) / 2
21562 - nrefx
* width
/ 2
21565 btm
= ((grefy
== 0 ? highest
21567 : grefy
== 2 ? lowest
21568 : (highest
+ lowest
) / 2)
21569 - (nrefy
== 0 ? ascent
+ descent
21570 : nrefy
== 1 ? descent
- boff
21572 : (ascent
+ descent
) / 2)
21576 cmp
->offsets
[i
* 2] = left
;
21577 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21579 /* Update the bounding box of the overall glyphs. */
21582 right
= left
+ width
;
21583 if (left
< leftmost
)
21585 if (right
> rightmost
)
21588 top
= btm
+ descent
+ ascent
;
21594 if (cmp
->lbearing
> left
+ lbearing
)
21595 cmp
->lbearing
= left
+ lbearing
;
21596 if (cmp
->rbearing
< left
+ rbearing
)
21597 cmp
->rbearing
= left
+ rbearing
;
21601 /* If there are glyphs whose x-offsets are negative,
21602 shift all glyphs to the right and make all x-offsets
21606 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21607 cmp
->offsets
[i
* 2] -= leftmost
;
21608 rightmost
-= leftmost
;
21609 cmp
->lbearing
-= leftmost
;
21610 cmp
->rbearing
-= leftmost
;
21613 if (left_padded
&& cmp
->lbearing
< 0)
21615 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21616 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21617 rightmost
-= cmp
->lbearing
;
21618 cmp
->rbearing
-= cmp
->lbearing
;
21621 if (right_padded
&& rightmost
< cmp
->rbearing
)
21623 rightmost
= cmp
->rbearing
;
21626 cmp
->pixel_width
= rightmost
;
21627 cmp
->ascent
= highest
;
21628 cmp
->descent
= - lowest
;
21629 if (cmp
->ascent
< font_ascent
)
21630 cmp
->ascent
= font_ascent
;
21631 if (cmp
->descent
< font_descent
)
21632 cmp
->descent
= font_descent
;
21636 && (cmp
->lbearing
< 0
21637 || cmp
->rbearing
> cmp
->pixel_width
))
21638 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21640 it
->pixel_width
= cmp
->pixel_width
;
21641 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21642 it
->descent
= it
->phys_descent
= cmp
->descent
;
21643 if (face
->box
!= FACE_NO_BOX
)
21645 int thick
= face
->box_line_width
;
21649 it
->ascent
+= thick
;
21650 it
->descent
+= thick
;
21655 if (it
->start_of_box_run_p
)
21656 it
->pixel_width
+= thick
;
21657 if (it
->end_of_box_run_p
)
21658 it
->pixel_width
+= thick
;
21661 /* If face has an overline, add the height of the overline
21662 (1 pixel) and a 1 pixel margin to the character height. */
21663 if (face
->overline_p
)
21664 it
->ascent
+= overline_margin
;
21666 take_vertical_position_into_account (it
);
21667 if (it
->ascent
< 0)
21669 if (it
->descent
< 0)
21673 append_composite_glyph (it
);
21675 else if (it
->what
== IT_COMPOSITION
)
21677 /* A dynamic (automatic) composition. */
21678 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21679 Lisp_Object gstring
;
21680 struct font_metrics metrics
;
21682 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
21684 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
21687 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
21688 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21689 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
21690 it
->descent
= it
->phys_descent
= metrics
.descent
;
21691 if (face
->box
!= FACE_NO_BOX
)
21693 int thick
= face
->box_line_width
;
21697 it
->ascent
+= thick
;
21698 it
->descent
+= thick
;
21703 if (it
->start_of_box_run_p
)
21704 it
->pixel_width
+= thick
;
21705 if (it
->end_of_box_run_p
)
21706 it
->pixel_width
+= thick
;
21708 /* If face has an overline, add the height of the overline
21709 (1 pixel) and a 1 pixel margin to the character height. */
21710 if (face
->overline_p
)
21711 it
->ascent
+= overline_margin
;
21712 take_vertical_position_into_account (it
);
21713 if (it
->ascent
< 0)
21715 if (it
->descent
< 0)
21719 append_composite_glyph (it
);
21721 else if (it
->what
== IT_IMAGE
)
21722 produce_image_glyph (it
);
21723 else if (it
->what
== IT_STRETCH
)
21724 produce_stretch_glyph (it
);
21726 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21727 because this isn't true for images with `:ascent 100'. */
21728 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21729 if (it
->area
== TEXT_AREA
)
21730 it
->current_x
+= it
->pixel_width
;
21732 if (extra_line_spacing
> 0)
21734 it
->descent
+= extra_line_spacing
;
21735 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21736 it
->max_extra_line_spacing
= extra_line_spacing
;
21739 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21740 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21741 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21742 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21746 Output LEN glyphs starting at START at the nominal cursor position.
21747 Advance the nominal cursor over the text. The global variable
21748 updated_window contains the window being updated, updated_row is
21749 the glyph row being updated, and updated_area is the area of that
21750 row being updated. */
21753 x_write_glyphs (start
, len
)
21754 struct glyph
*start
;
21759 xassert (updated_window
&& updated_row
);
21762 /* Write glyphs. */
21764 hpos
= start
- updated_row
->glyphs
[updated_area
];
21765 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21766 updated_row
, updated_area
,
21768 DRAW_NORMAL_TEXT
, 0);
21770 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21771 if (updated_area
== TEXT_AREA
21772 && updated_window
->phys_cursor_on_p
21773 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21774 && updated_window
->phys_cursor
.hpos
>= hpos
21775 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21776 updated_window
->phys_cursor_on_p
= 0;
21780 /* Advance the output cursor. */
21781 output_cursor
.hpos
+= len
;
21782 output_cursor
.x
= x
;
21787 Insert LEN glyphs from START at the nominal cursor position. */
21790 x_insert_glyphs (start
, len
)
21791 struct glyph
*start
;
21796 int line_height
, shift_by_width
, shifted_region_width
;
21797 struct glyph_row
*row
;
21798 struct glyph
*glyph
;
21799 int frame_x
, frame_y
;
21802 xassert (updated_window
&& updated_row
);
21804 w
= updated_window
;
21805 f
= XFRAME (WINDOW_FRAME (w
));
21807 /* Get the height of the line we are in. */
21809 line_height
= row
->height
;
21811 /* Get the width of the glyphs to insert. */
21812 shift_by_width
= 0;
21813 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21814 shift_by_width
+= glyph
->pixel_width
;
21816 /* Get the width of the region to shift right. */
21817 shifted_region_width
= (window_box_width (w
, updated_area
)
21822 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21823 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21825 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21826 line_height
, shift_by_width
);
21828 /* Write the glyphs. */
21829 hpos
= start
- row
->glyphs
[updated_area
];
21830 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21832 DRAW_NORMAL_TEXT
, 0);
21834 /* Advance the output cursor. */
21835 output_cursor
.hpos
+= len
;
21836 output_cursor
.x
+= shift_by_width
;
21842 Erase the current text line from the nominal cursor position
21843 (inclusive) to pixel column TO_X (exclusive). The idea is that
21844 everything from TO_X onward is already erased.
21846 TO_X is a pixel position relative to updated_area of
21847 updated_window. TO_X == -1 means clear to the end of this area. */
21850 x_clear_end_of_line (to_x
)
21854 struct window
*w
= updated_window
;
21855 int max_x
, min_y
, max_y
;
21856 int from_x
, from_y
, to_y
;
21858 xassert (updated_window
&& updated_row
);
21859 f
= XFRAME (w
->frame
);
21861 if (updated_row
->full_width_p
)
21862 max_x
= WINDOW_TOTAL_WIDTH (w
);
21864 max_x
= window_box_width (w
, updated_area
);
21865 max_y
= window_text_bottom_y (w
);
21867 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21868 of window. For TO_X > 0, truncate to end of drawing area. */
21874 to_x
= min (to_x
, max_x
);
21876 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21878 /* Notice if the cursor will be cleared by this operation. */
21879 if (!updated_row
->full_width_p
)
21880 notice_overwritten_cursor (w
, updated_area
,
21881 output_cursor
.x
, -1,
21883 MATRIX_ROW_BOTTOM_Y (updated_row
));
21885 from_x
= output_cursor
.x
;
21887 /* Translate to frame coordinates. */
21888 if (updated_row
->full_width_p
)
21890 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21891 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21895 int area_left
= window_box_left (w
, updated_area
);
21896 from_x
+= area_left
;
21900 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21901 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21902 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21904 /* Prevent inadvertently clearing to end of the X window. */
21905 if (to_x
> from_x
&& to_y
> from_y
)
21908 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21909 to_x
- from_x
, to_y
- from_y
);
21914 #endif /* HAVE_WINDOW_SYSTEM */
21918 /***********************************************************************
21920 ***********************************************************************/
21922 /* Value is the internal representation of the specified cursor type
21923 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21924 of the bar cursor. */
21926 static enum text_cursor_kinds
21927 get_specified_cursor_type (arg
, width
)
21931 enum text_cursor_kinds type
;
21936 if (EQ (arg
, Qbox
))
21937 return FILLED_BOX_CURSOR
;
21939 if (EQ (arg
, Qhollow
))
21940 return HOLLOW_BOX_CURSOR
;
21942 if (EQ (arg
, Qbar
))
21949 && EQ (XCAR (arg
), Qbar
)
21950 && INTEGERP (XCDR (arg
))
21951 && XINT (XCDR (arg
)) >= 0)
21953 *width
= XINT (XCDR (arg
));
21957 if (EQ (arg
, Qhbar
))
21960 return HBAR_CURSOR
;
21964 && EQ (XCAR (arg
), Qhbar
)
21965 && INTEGERP (XCDR (arg
))
21966 && XINT (XCDR (arg
)) >= 0)
21968 *width
= XINT (XCDR (arg
));
21969 return HBAR_CURSOR
;
21972 /* Treat anything unknown as "hollow box cursor".
21973 It was bad to signal an error; people have trouble fixing
21974 .Xdefaults with Emacs, when it has something bad in it. */
21975 type
= HOLLOW_BOX_CURSOR
;
21980 /* Set the default cursor types for specified frame. */
21982 set_frame_cursor_types (f
, arg
)
21989 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21990 FRAME_CURSOR_WIDTH (f
) = width
;
21992 /* By default, set up the blink-off state depending on the on-state. */
21994 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21997 FRAME_BLINK_OFF_CURSOR (f
)
21998 = get_specified_cursor_type (XCDR (tem
), &width
);
21999 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22002 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22006 /* Return the cursor we want to be displayed in window W. Return
22007 width of bar/hbar cursor through WIDTH arg. Return with
22008 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22009 (i.e. if the `system caret' should track this cursor).
22011 In a mini-buffer window, we want the cursor only to appear if we
22012 are reading input from this window. For the selected window, we
22013 want the cursor type given by the frame parameter or buffer local
22014 setting of cursor-type. If explicitly marked off, draw no cursor.
22015 In all other cases, we want a hollow box cursor. */
22017 static enum text_cursor_kinds
22018 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22020 struct glyph
*glyph
;
22022 int *active_cursor
;
22024 struct frame
*f
= XFRAME (w
->frame
);
22025 struct buffer
*b
= XBUFFER (w
->buffer
);
22026 int cursor_type
= DEFAULT_CURSOR
;
22027 Lisp_Object alt_cursor
;
22028 int non_selected
= 0;
22030 *active_cursor
= 1;
22033 if (cursor_in_echo_area
22034 && FRAME_HAS_MINIBUF_P (f
)
22035 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22037 if (w
== XWINDOW (echo_area_window
))
22039 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22041 *width
= FRAME_CURSOR_WIDTH (f
);
22042 return FRAME_DESIRED_CURSOR (f
);
22045 return get_specified_cursor_type (b
->cursor_type
, width
);
22048 *active_cursor
= 0;
22052 /* Detect a nonselected window or nonselected frame. */
22053 else if (w
!= XWINDOW (f
->selected_window
)
22054 #ifdef HAVE_WINDOW_SYSTEM
22055 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22059 *active_cursor
= 0;
22061 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22067 /* Never display a cursor in a window in which cursor-type is nil. */
22068 if (NILP (b
->cursor_type
))
22071 /* Get the normal cursor type for this window. */
22072 if (EQ (b
->cursor_type
, Qt
))
22074 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22075 *width
= FRAME_CURSOR_WIDTH (f
);
22078 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22080 /* Use cursor-in-non-selected-windows instead
22081 for non-selected window or frame. */
22084 alt_cursor
= b
->cursor_in_non_selected_windows
;
22085 if (!EQ (Qt
, alt_cursor
))
22086 return get_specified_cursor_type (alt_cursor
, width
);
22087 /* t means modify the normal cursor type. */
22088 if (cursor_type
== FILLED_BOX_CURSOR
)
22089 cursor_type
= HOLLOW_BOX_CURSOR
;
22090 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22092 return cursor_type
;
22095 /* Use normal cursor if not blinked off. */
22096 if (!w
->cursor_off_p
)
22098 #ifdef HAVE_WINDOW_SYSTEM
22099 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22101 if (cursor_type
== FILLED_BOX_CURSOR
)
22103 /* Using a block cursor on large images can be very annoying.
22104 So use a hollow cursor for "large" images.
22105 If image is not transparent (no mask), also use hollow cursor. */
22106 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22107 if (img
!= NULL
&& IMAGEP (img
->spec
))
22109 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22110 where N = size of default frame font size.
22111 This should cover most of the "tiny" icons people may use. */
22113 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22114 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22115 cursor_type
= HOLLOW_BOX_CURSOR
;
22118 else if (cursor_type
!= NO_CURSOR
)
22120 /* Display current only supports BOX and HOLLOW cursors for images.
22121 So for now, unconditionally use a HOLLOW cursor when cursor is
22122 not a solid box cursor. */
22123 cursor_type
= HOLLOW_BOX_CURSOR
;
22127 return cursor_type
;
22130 /* Cursor is blinked off, so determine how to "toggle" it. */
22132 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22133 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22134 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22136 /* Then see if frame has specified a specific blink off cursor type. */
22137 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22139 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22140 return FRAME_BLINK_OFF_CURSOR (f
);
22144 /* Some people liked having a permanently visible blinking cursor,
22145 while others had very strong opinions against it. So it was
22146 decided to remove it. KFS 2003-09-03 */
22148 /* Finally perform built-in cursor blinking:
22149 filled box <-> hollow box
22150 wide [h]bar <-> narrow [h]bar
22151 narrow [h]bar <-> no cursor
22152 other type <-> no cursor */
22154 if (cursor_type
== FILLED_BOX_CURSOR
)
22155 return HOLLOW_BOX_CURSOR
;
22157 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22160 return cursor_type
;
22168 #ifdef HAVE_WINDOW_SYSTEM
22170 /* Notice when the text cursor of window W has been completely
22171 overwritten by a drawing operation that outputs glyphs in AREA
22172 starting at X0 and ending at X1 in the line starting at Y0 and
22173 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22174 the rest of the line after X0 has been written. Y coordinates
22175 are window-relative. */
22178 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22180 enum glyph_row_area area
;
22181 int x0
, y0
, x1
, y1
;
22183 int cx0
, cx1
, cy0
, cy1
;
22184 struct glyph_row
*row
;
22186 if (!w
->phys_cursor_on_p
)
22188 if (area
!= TEXT_AREA
)
22191 if (w
->phys_cursor
.vpos
< 0
22192 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22193 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22194 !(row
->enabled_p
&& row
->displays_text_p
)))
22197 if (row
->cursor_in_fringe_p
)
22199 row
->cursor_in_fringe_p
= 0;
22200 draw_fringe_bitmap (w
, row
, 0);
22201 w
->phys_cursor_on_p
= 0;
22205 cx0
= w
->phys_cursor
.x
;
22206 cx1
= cx0
+ w
->phys_cursor_width
;
22207 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22210 /* The cursor image will be completely removed from the
22211 screen if the output area intersects the cursor area in
22212 y-direction. When we draw in [y0 y1[, and some part of
22213 the cursor is at y < y0, that part must have been drawn
22214 before. When scrolling, the cursor is erased before
22215 actually scrolling, so we don't come here. When not
22216 scrolling, the rows above the old cursor row must have
22217 changed, and in this case these rows must have written
22218 over the cursor image.
22220 Likewise if part of the cursor is below y1, with the
22221 exception of the cursor being in the first blank row at
22222 the buffer and window end because update_text_area
22223 doesn't draw that row. (Except when it does, but
22224 that's handled in update_text_area.) */
22226 cy0
= w
->phys_cursor
.y
;
22227 cy1
= cy0
+ w
->phys_cursor_height
;
22228 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22231 w
->phys_cursor_on_p
= 0;
22234 #endif /* HAVE_WINDOW_SYSTEM */
22237 /************************************************************************
22239 ************************************************************************/
22241 #ifdef HAVE_WINDOW_SYSTEM
22244 Fix the display of area AREA of overlapping row ROW in window W
22245 with respect to the overlapping part OVERLAPS. */
22248 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22250 struct glyph_row
*row
;
22251 enum glyph_row_area area
;
22259 for (i
= 0; i
< row
->used
[area
];)
22261 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22263 int start
= i
, start_x
= x
;
22267 x
+= row
->glyphs
[area
][i
].pixel_width
;
22270 while (i
< row
->used
[area
]
22271 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22273 draw_glyphs (w
, start_x
, row
, area
,
22275 DRAW_NORMAL_TEXT
, overlaps
);
22279 x
+= row
->glyphs
[area
][i
].pixel_width
;
22289 Draw the cursor glyph of window W in glyph row ROW. See the
22290 comment of draw_glyphs for the meaning of HL. */
22293 draw_phys_cursor_glyph (w
, row
, hl
)
22295 struct glyph_row
*row
;
22296 enum draw_glyphs_face hl
;
22298 /* If cursor hpos is out of bounds, don't draw garbage. This can
22299 happen in mini-buffer windows when switching between echo area
22300 glyphs and mini-buffer. */
22301 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22303 int on_p
= w
->phys_cursor_on_p
;
22305 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22306 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22308 w
->phys_cursor_on_p
= on_p
;
22310 if (hl
== DRAW_CURSOR
)
22311 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22312 /* When we erase the cursor, and ROW is overlapped by other
22313 rows, make sure that these overlapping parts of other rows
22315 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22317 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22319 if (row
> w
->current_matrix
->rows
22320 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22321 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22322 OVERLAPS_ERASED_CURSOR
);
22324 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22325 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22326 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22327 OVERLAPS_ERASED_CURSOR
);
22334 Erase the image of a cursor of window W from the screen. */
22337 erase_phys_cursor (w
)
22340 struct frame
*f
= XFRAME (w
->frame
);
22341 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22342 int hpos
= w
->phys_cursor
.hpos
;
22343 int vpos
= w
->phys_cursor
.vpos
;
22344 int mouse_face_here_p
= 0;
22345 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22346 struct glyph_row
*cursor_row
;
22347 struct glyph
*cursor_glyph
;
22348 enum draw_glyphs_face hl
;
22350 /* No cursor displayed or row invalidated => nothing to do on the
22352 if (w
->phys_cursor_type
== NO_CURSOR
)
22353 goto mark_cursor_off
;
22355 /* VPOS >= active_glyphs->nrows means that window has been resized.
22356 Don't bother to erase the cursor. */
22357 if (vpos
>= active_glyphs
->nrows
)
22358 goto mark_cursor_off
;
22360 /* If row containing cursor is marked invalid, there is nothing we
22362 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22363 if (!cursor_row
->enabled_p
)
22364 goto mark_cursor_off
;
22366 /* If line spacing is > 0, old cursor may only be partially visible in
22367 window after split-window. So adjust visible height. */
22368 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22369 window_text_bottom_y (w
) - cursor_row
->y
);
22371 /* If row is completely invisible, don't attempt to delete a cursor which
22372 isn't there. This can happen if cursor is at top of a window, and
22373 we switch to a buffer with a header line in that window. */
22374 if (cursor_row
->visible_height
<= 0)
22375 goto mark_cursor_off
;
22377 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22378 if (cursor_row
->cursor_in_fringe_p
)
22380 cursor_row
->cursor_in_fringe_p
= 0;
22381 draw_fringe_bitmap (w
, cursor_row
, 0);
22382 goto mark_cursor_off
;
22385 /* This can happen when the new row is shorter than the old one.
22386 In this case, either draw_glyphs or clear_end_of_line
22387 should have cleared the cursor. Note that we wouldn't be
22388 able to erase the cursor in this case because we don't have a
22389 cursor glyph at hand. */
22390 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22391 goto mark_cursor_off
;
22393 /* If the cursor is in the mouse face area, redisplay that when
22394 we clear the cursor. */
22395 if (! NILP (dpyinfo
->mouse_face_window
)
22396 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22397 && (vpos
> dpyinfo
->mouse_face_beg_row
22398 || (vpos
== dpyinfo
->mouse_face_beg_row
22399 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22400 && (vpos
< dpyinfo
->mouse_face_end_row
22401 || (vpos
== dpyinfo
->mouse_face_end_row
22402 && hpos
< dpyinfo
->mouse_face_end_col
))
22403 /* Don't redraw the cursor's spot in mouse face if it is at the
22404 end of a line (on a newline). The cursor appears there, but
22405 mouse highlighting does not. */
22406 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22407 mouse_face_here_p
= 1;
22409 /* Maybe clear the display under the cursor. */
22410 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22413 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22416 cursor_glyph
= get_phys_cursor_glyph (w
);
22417 if (cursor_glyph
== NULL
)
22418 goto mark_cursor_off
;
22420 width
= cursor_glyph
->pixel_width
;
22421 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22422 x
= w
->phys_cursor
.x
;
22424 width
-= left_x
- x
;
22425 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22426 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22427 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22430 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22433 /* Erase the cursor by redrawing the character underneath it. */
22434 if (mouse_face_here_p
)
22435 hl
= DRAW_MOUSE_FACE
;
22437 hl
= DRAW_NORMAL_TEXT
;
22438 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22441 w
->phys_cursor_on_p
= 0;
22442 w
->phys_cursor_type
= NO_CURSOR
;
22447 Display or clear cursor of window W. If ON is zero, clear the
22448 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22449 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22452 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22454 int on
, hpos
, vpos
, x
, y
;
22456 struct frame
*f
= XFRAME (w
->frame
);
22457 int new_cursor_type
;
22458 int new_cursor_width
;
22460 struct glyph_row
*glyph_row
;
22461 struct glyph
*glyph
;
22463 /* This is pointless on invisible frames, and dangerous on garbaged
22464 windows and frames; in the latter case, the frame or window may
22465 be in the midst of changing its size, and x and y may be off the
22467 if (! FRAME_VISIBLE_P (f
)
22468 || FRAME_GARBAGED_P (f
)
22469 || vpos
>= w
->current_matrix
->nrows
22470 || hpos
>= w
->current_matrix
->matrix_w
)
22473 /* If cursor is off and we want it off, return quickly. */
22474 if (!on
&& !w
->phys_cursor_on_p
)
22477 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22478 /* If cursor row is not enabled, we don't really know where to
22479 display the cursor. */
22480 if (!glyph_row
->enabled_p
)
22482 w
->phys_cursor_on_p
= 0;
22487 if (!glyph_row
->exact_window_width_line_p
22488 || hpos
< glyph_row
->used
[TEXT_AREA
])
22489 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22491 xassert (interrupt_input_blocked
);
22493 /* Set new_cursor_type to the cursor we want to be displayed. */
22494 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22495 &new_cursor_width
, &active_cursor
);
22497 /* If cursor is currently being shown and we don't want it to be or
22498 it is in the wrong place, or the cursor type is not what we want,
22500 if (w
->phys_cursor_on_p
22502 || w
->phys_cursor
.x
!= x
22503 || w
->phys_cursor
.y
!= y
22504 || new_cursor_type
!= w
->phys_cursor_type
22505 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22506 && new_cursor_width
!= w
->phys_cursor_width
)))
22507 erase_phys_cursor (w
);
22509 /* Don't check phys_cursor_on_p here because that flag is only set
22510 to zero in some cases where we know that the cursor has been
22511 completely erased, to avoid the extra work of erasing the cursor
22512 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22513 still not be visible, or it has only been partly erased. */
22516 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22517 w
->phys_cursor_height
= glyph_row
->height
;
22519 /* Set phys_cursor_.* before x_draw_.* is called because some
22520 of them may need the information. */
22521 w
->phys_cursor
.x
= x
;
22522 w
->phys_cursor
.y
= glyph_row
->y
;
22523 w
->phys_cursor
.hpos
= hpos
;
22524 w
->phys_cursor
.vpos
= vpos
;
22527 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22528 new_cursor_type
, new_cursor_width
,
22529 on
, active_cursor
);
22533 /* Switch the display of W's cursor on or off, according to the value
22537 update_window_cursor (w
, on
)
22541 /* Don't update cursor in windows whose frame is in the process
22542 of being deleted. */
22543 if (w
->current_matrix
)
22546 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22547 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22553 /* Call update_window_cursor with parameter ON_P on all leaf windows
22554 in the window tree rooted at W. */
22557 update_cursor_in_window_tree (w
, on_p
)
22563 if (!NILP (w
->hchild
))
22564 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22565 else if (!NILP (w
->vchild
))
22566 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22568 update_window_cursor (w
, on_p
);
22570 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22576 Display the cursor on window W, or clear it, according to ON_P.
22577 Don't change the cursor's position. */
22580 x_update_cursor (f
, on_p
)
22584 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22589 Clear the cursor of window W to background color, and mark the
22590 cursor as not shown. This is used when the text where the cursor
22591 is about to be rewritten. */
22597 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22598 update_window_cursor (w
, 0);
22603 Display the active region described by mouse_face_* according to DRAW. */
22606 show_mouse_face (dpyinfo
, draw
)
22607 Display_Info
*dpyinfo
;
22608 enum draw_glyphs_face draw
;
22610 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22611 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22613 if (/* If window is in the process of being destroyed, don't bother
22615 w
->current_matrix
!= NULL
22616 /* Don't update mouse highlight if hidden */
22617 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22618 /* Recognize when we are called to operate on rows that don't exist
22619 anymore. This can happen when a window is split. */
22620 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22622 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22623 struct glyph_row
*row
, *first
, *last
;
22625 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22626 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22628 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22630 int start_hpos
, end_hpos
, start_x
;
22632 /* For all but the first row, the highlight starts at column 0. */
22635 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22636 start_x
= dpyinfo
->mouse_face_beg_x
;
22645 end_hpos
= dpyinfo
->mouse_face_end_col
;
22648 end_hpos
= row
->used
[TEXT_AREA
];
22649 if (draw
== DRAW_NORMAL_TEXT
)
22650 row
->fill_line_p
= 1; /* Clear to end of line */
22653 if (end_hpos
> start_hpos
)
22655 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22656 start_hpos
, end_hpos
,
22660 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22664 /* When we've written over the cursor, arrange for it to
22665 be displayed again. */
22666 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22669 display_and_set_cursor (w
, 1,
22670 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22671 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22676 /* Change the mouse cursor. */
22677 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22678 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22679 else if (draw
== DRAW_MOUSE_FACE
)
22680 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22682 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22686 Clear out the mouse-highlighted active region.
22687 Redraw it un-highlighted first. Value is non-zero if mouse
22688 face was actually drawn unhighlighted. */
22691 clear_mouse_face (dpyinfo
)
22692 Display_Info
*dpyinfo
;
22696 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22698 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22702 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22703 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22704 dpyinfo
->mouse_face_window
= Qnil
;
22705 dpyinfo
->mouse_face_overlay
= Qnil
;
22711 Non-zero if physical cursor of window W is within mouse face. */
22714 cursor_in_mouse_face_p (w
)
22717 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22718 int in_mouse_face
= 0;
22720 if (WINDOWP (dpyinfo
->mouse_face_window
)
22721 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22723 int hpos
= w
->phys_cursor
.hpos
;
22724 int vpos
= w
->phys_cursor
.vpos
;
22726 if (vpos
>= dpyinfo
->mouse_face_beg_row
22727 && vpos
<= dpyinfo
->mouse_face_end_row
22728 && (vpos
> dpyinfo
->mouse_face_beg_row
22729 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22730 && (vpos
< dpyinfo
->mouse_face_end_row
22731 || hpos
< dpyinfo
->mouse_face_end_col
22732 || dpyinfo
->mouse_face_past_end
))
22736 return in_mouse_face
;
22742 /* This function sets the mouse_face_* elements of DPYINFO, assuming
22743 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
22744 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
22745 for the overlay or run of text properties specifying the mouse
22746 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
22747 before-string and after-string that must also be highlighted.
22748 DISPLAY_STRING, if non-nil, is a display string that may cover some
22749 or all of the highlighted text. */
22752 mouse_face_from_buffer_pos (Lisp_Object window
,
22753 Display_Info
*dpyinfo
,
22754 EMACS_INT mouse_charpos
,
22755 EMACS_INT start_charpos
,
22756 EMACS_INT end_charpos
,
22757 Lisp_Object before_string
,
22758 Lisp_Object after_string
,
22759 Lisp_Object display_string
)
22761 struct window
*w
= XWINDOW (window
);
22762 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22763 struct glyph_row
*row
;
22764 struct glyph
*glyph
, *end
;
22768 xassert (NILP (display_string
) || STRINGP (display_string
));
22769 xassert (NILP (before_string
) || STRINGP (before_string
));
22770 xassert (NILP (after_string
) || STRINGP (after_string
));
22772 /* Find the first highlighted glyph. */
22773 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
22775 dpyinfo
->mouse_face_beg_col
= 0;
22776 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22777 dpyinfo
->mouse_face_beg_x
= first
->x
;
22778 dpyinfo
->mouse_face_beg_y
= first
->y
;
22782 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
22784 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22786 /* If the before-string or display-string contains newlines,
22787 row_containing_pos skips to its last row. Move back. */
22788 if (!NILP (before_string
) || !NILP (display_string
))
22790 struct glyph_row
*prev
;
22791 while ((prev
= row
- 1, prev
>= first
)
22792 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
22793 && prev
->used
[TEXT_AREA
] > 0)
22795 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22796 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22797 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
22799 || !(EQ (glyph
->object
, before_string
)
22800 || EQ (glyph
->object
, display_string
)))
22806 glyph
= row
->glyphs
[TEXT_AREA
];
22807 end
= glyph
+ row
->used
[TEXT_AREA
];
22809 dpyinfo
->mouse_face_beg_y
= row
->y
;
22810 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22812 /* Skip truncation glyphs at the start of the glyph row. */
22813 if (row
->displays_text_p
)
22815 && INTEGERP (glyph
->object
)
22816 && glyph
->charpos
< 0;
22818 x
+= glyph
->pixel_width
;
22820 /* Scan the glyph row, stopping before BEFORE_STRING or
22821 DISPLAY_STRING or START_CHARPOS. */
22823 && !INTEGERP (glyph
->object
)
22824 && !EQ (glyph
->object
, before_string
)
22825 && !EQ (glyph
->object
, display_string
)
22826 && !(BUFFERP (glyph
->object
)
22827 && glyph
->charpos
>= start_charpos
);
22829 x
+= glyph
->pixel_width
;
22831 dpyinfo
->mouse_face_beg_x
= x
;
22832 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22835 /* Find the last highlighted glyph. */
22836 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
22839 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22840 dpyinfo
->mouse_face_past_end
= 1;
22842 else if (!NILP (after_string
))
22844 /* If the after-string has newlines, advance to its last row. */
22845 struct glyph_row
*next
;
22846 struct glyph_row
*last
22847 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22849 for (next
= row
+ 1;
22851 && next
->used
[TEXT_AREA
] > 0
22852 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
22857 glyph
= row
->glyphs
[TEXT_AREA
];
22858 end
= glyph
+ row
->used
[TEXT_AREA
];
22860 dpyinfo
->mouse_face_end_y
= row
->y
;
22861 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22863 /* Skip truncation glyphs at the start of the row. */
22864 if (row
->displays_text_p
)
22866 && INTEGERP (glyph
->object
)
22867 && glyph
->charpos
< 0;
22869 x
+= glyph
->pixel_width
;
22871 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
22874 && !INTEGERP (glyph
->object
)
22875 && !EQ (glyph
->object
, after_string
)
22876 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
22878 x
+= glyph
->pixel_width
;
22880 /* If we found AFTER_STRING, consume it and stop. */
22881 if (EQ (glyph
->object
, after_string
))
22883 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
22884 x
+= glyph
->pixel_width
;
22888 /* If there's no after-string, we must check if we overshot,
22889 which might be the case if we stopped after a string glyph.
22890 That glyph may belong to a before-string or display-string
22891 associated with the end position, which must not be
22893 Lisp_Object prev_object
;
22896 while (glyph
> row
->glyphs
[TEXT_AREA
])
22898 prev_object
= (glyph
- 1)->object
;
22899 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
22902 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
22903 if (pos
&& pos
< end_charpos
)
22906 for (; glyph
> row
->glyphs
[TEXT_AREA
]
22907 && EQ ((glyph
- 1)->object
, prev_object
);
22909 x
-= (glyph
- 1)->pixel_width
;
22913 dpyinfo
->mouse_face_end_x
= x
;
22914 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22915 dpyinfo
->mouse_face_window
= window
;
22916 dpyinfo
->mouse_face_face_id
22917 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
22919 !dpyinfo
->mouse_face_hidden
, -1);
22920 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22924 /* Find the position of the glyph for position POS in OBJECT in
22925 window W's current matrix, and return in *X, *Y the pixel
22926 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22928 RIGHT_P non-zero means return the position of the right edge of the
22929 glyph, RIGHT_P zero means return the left edge position.
22931 If no glyph for POS exists in the matrix, return the position of
22932 the glyph with the next smaller position that is in the matrix, if
22933 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22934 exists in the matrix, return the position of the glyph with the
22935 next larger position in OBJECT.
22937 Value is non-zero if a glyph was found. */
22940 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22943 Lisp_Object object
;
22944 int *hpos
, *vpos
, *x
, *y
;
22947 int yb
= window_text_bottom_y (w
);
22948 struct glyph_row
*r
;
22949 struct glyph
*best_glyph
= NULL
;
22950 struct glyph_row
*best_row
= NULL
;
22953 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22954 r
->enabled_p
&& r
->y
< yb
;
22957 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22958 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22961 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22962 if (EQ (g
->object
, object
))
22964 if (g
->charpos
== pos
)
22971 else if (best_glyph
== NULL
22972 || ((eabs (g
->charpos
- pos
)
22973 < eabs (best_glyph
->charpos
- pos
))
22976 : g
->charpos
> pos
)))
22990 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22994 *x
+= best_glyph
->pixel_width
;
22999 *vpos
= best_row
- w
->current_matrix
->rows
;
23002 return best_glyph
!= NULL
;
23006 /* See if position X, Y is within a hot-spot of an image. */
23009 on_hot_spot_p (hot_spot
, x
, y
)
23010 Lisp_Object hot_spot
;
23013 if (!CONSP (hot_spot
))
23016 if (EQ (XCAR (hot_spot
), Qrect
))
23018 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23019 Lisp_Object rect
= XCDR (hot_spot
);
23023 if (!CONSP (XCAR (rect
)))
23025 if (!CONSP (XCDR (rect
)))
23027 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23029 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23031 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23033 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23037 else if (EQ (XCAR (hot_spot
), Qcircle
))
23039 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23040 Lisp_Object circ
= XCDR (hot_spot
);
23041 Lisp_Object lr
, lx0
, ly0
;
23043 && CONSP (XCAR (circ
))
23044 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23045 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23046 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23048 double r
= XFLOATINT (lr
);
23049 double dx
= XINT (lx0
) - x
;
23050 double dy
= XINT (ly0
) - y
;
23051 return (dx
* dx
+ dy
* dy
<= r
* r
);
23054 else if (EQ (XCAR (hot_spot
), Qpoly
))
23056 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23057 if (VECTORP (XCDR (hot_spot
)))
23059 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23060 Lisp_Object
*poly
= v
->contents
;
23064 Lisp_Object lx
, ly
;
23067 /* Need an even number of coordinates, and at least 3 edges. */
23068 if (n
< 6 || n
& 1)
23071 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23072 If count is odd, we are inside polygon. Pixels on edges
23073 may or may not be included depending on actual geometry of the
23075 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23076 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23078 x0
= XINT (lx
), y0
= XINT (ly
);
23079 for (i
= 0; i
< n
; i
+= 2)
23081 int x1
= x0
, y1
= y0
;
23082 if ((lx
= poly
[i
], !INTEGERP (lx
))
23083 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23085 x0
= XINT (lx
), y0
= XINT (ly
);
23087 /* Does this segment cross the X line? */
23095 if (y
> y0
&& y
> y1
)
23097 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23107 find_hot_spot (map
, x
, y
)
23111 while (CONSP (map
))
23113 if (CONSP (XCAR (map
))
23114 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23122 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23124 doc
: /* Lookup in image map MAP coordinates X and Y.
23125 An image map is an alist where each element has the format (AREA ID PLIST).
23126 An AREA is specified as either a rectangle, a circle, or a polygon:
23127 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23128 pixel coordinates of the upper left and bottom right corners.
23129 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23130 and the radius of the circle; r may be a float or integer.
23131 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23132 vector describes one corner in the polygon.
23133 Returns the alist element for the first matching AREA in MAP. */)
23144 return find_hot_spot (map
, XINT (x
), XINT (y
));
23148 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23150 define_frame_cursor1 (f
, cursor
, pointer
)
23153 Lisp_Object pointer
;
23155 /* Do not change cursor shape while dragging mouse. */
23156 if (!NILP (do_mouse_tracking
))
23159 if (!NILP (pointer
))
23161 if (EQ (pointer
, Qarrow
))
23162 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23163 else if (EQ (pointer
, Qhand
))
23164 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23165 else if (EQ (pointer
, Qtext
))
23166 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23167 else if (EQ (pointer
, intern ("hdrag")))
23168 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23169 #ifdef HAVE_X_WINDOWS
23170 else if (EQ (pointer
, intern ("vdrag")))
23171 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23173 else if (EQ (pointer
, intern ("hourglass")))
23174 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23175 else if (EQ (pointer
, Qmodeline
))
23176 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23178 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23181 if (cursor
!= No_Cursor
)
23182 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23185 /* Take proper action when mouse has moved to the mode or header line
23186 or marginal area AREA of window W, x-position X and y-position Y.
23187 X is relative to the start of the text display area of W, so the
23188 width of bitmap areas and scroll bars must be subtracted to get a
23189 position relative to the start of the mode line. */
23192 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23193 Lisp_Object window
;
23195 enum window_part area
;
23197 struct window
*w
= XWINDOW (window
);
23198 struct frame
*f
= XFRAME (w
->frame
);
23199 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23200 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23201 Lisp_Object pointer
= Qnil
;
23202 int charpos
, dx
, dy
, width
, height
;
23203 Lisp_Object string
, object
= Qnil
;
23204 Lisp_Object pos
, help
;
23206 Lisp_Object mouse_face
;
23207 int original_x_pixel
= x
;
23208 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23209 struct glyph_row
*row
;
23211 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23216 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23217 &object
, &dx
, &dy
, &width
, &height
);
23219 row
= (area
== ON_MODE_LINE
23220 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23221 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23224 if (row
->mode_line_p
&& row
->enabled_p
)
23226 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23227 end
= glyph
+ row
->used
[TEXT_AREA
];
23229 for (x0
= original_x_pixel
;
23230 glyph
< end
&& x0
>= glyph
->pixel_width
;
23232 x0
-= glyph
->pixel_width
;
23240 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23241 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23242 &object
, &dx
, &dy
, &width
, &height
);
23247 if (IMAGEP (object
))
23249 Lisp_Object image_map
, hotspot
;
23250 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23252 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23254 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23256 Lisp_Object area_id
, plist
;
23258 area_id
= XCAR (hotspot
);
23259 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23260 If so, we could look for mouse-enter, mouse-leave
23261 properties in PLIST (and do something...). */
23262 hotspot
= XCDR (hotspot
);
23263 if (CONSP (hotspot
)
23264 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23266 pointer
= Fplist_get (plist
, Qpointer
);
23267 if (NILP (pointer
))
23269 help
= Fplist_get (plist
, Qhelp_echo
);
23272 help_echo_string
= help
;
23273 /* Is this correct? ++kfs */
23274 XSETWINDOW (help_echo_window
, w
);
23275 help_echo_object
= w
->buffer
;
23276 help_echo_pos
= charpos
;
23280 if (NILP (pointer
))
23281 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23284 if (STRINGP (string
))
23286 pos
= make_number (charpos
);
23287 /* If we're on a string with `help-echo' text property, arrange
23288 for the help to be displayed. This is done by setting the
23289 global variable help_echo_string to the help string. */
23292 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23295 help_echo_string
= help
;
23296 XSETWINDOW (help_echo_window
, w
);
23297 help_echo_object
= string
;
23298 help_echo_pos
= charpos
;
23302 if (NILP (pointer
))
23303 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23305 /* Change the mouse pointer according to what is under X/Y. */
23306 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23309 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23310 if (!KEYMAPP (map
))
23311 map
= Fget_text_property (pos
, Qkeymap
, string
);
23312 if (!KEYMAPP (map
))
23313 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23316 /* Change the mouse face according to what is under X/Y. */
23317 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23318 if (!NILP (mouse_face
)
23319 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23324 struct glyph
* tmp_glyph
;
23328 int total_pixel_width
;
23333 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23334 Qmouse_face
, string
, Qnil
);
23336 b
= make_number (0);
23338 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23340 e
= make_number (SCHARS (string
));
23342 /* Calculate the position(glyph position: GPOS) of GLYPH in
23343 displayed string. GPOS is different from CHARPOS.
23345 CHARPOS is the position of glyph in internal string
23346 object. A mode line string format has structures which
23347 is converted to a flatten by emacs lisp interpreter.
23348 The internal string is an element of the structures.
23349 The displayed string is the flatten string. */
23351 if (glyph
> row_start_glyph
)
23353 tmp_glyph
= glyph
- 1;
23354 while (tmp_glyph
>= row_start_glyph
23355 && tmp_glyph
->charpos
>= XINT (b
)
23356 && EQ (tmp_glyph
->object
, glyph
->object
))
23363 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23364 displayed string holding GLYPH.
23366 GSEQ_LENGTH is different from SCHARS (STRING).
23367 SCHARS (STRING) returns the length of the internal string. */
23368 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23369 tmp_glyph
->charpos
< XINT (e
);
23370 tmp_glyph
++, gseq_length
++)
23372 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23376 total_pixel_width
= 0;
23377 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23378 total_pixel_width
+= tmp_glyph
->pixel_width
;
23380 /* Pre calculation of re-rendering position */
23382 hpos
= (area
== ON_MODE_LINE
23383 ? (w
->current_matrix
)->nrows
- 1
23386 /* If the re-rendering position is included in the last
23387 re-rendering area, we should do nothing. */
23388 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23389 && dpyinfo
->mouse_face_beg_col
<= vpos
23390 && vpos
< dpyinfo
->mouse_face_end_col
23391 && dpyinfo
->mouse_face_beg_row
== hpos
)
23394 if (clear_mouse_face (dpyinfo
))
23395 cursor
= No_Cursor
;
23397 dpyinfo
->mouse_face_beg_col
= vpos
;
23398 dpyinfo
->mouse_face_beg_row
= hpos
;
23400 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23401 dpyinfo
->mouse_face_beg_y
= 0;
23403 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23404 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23406 dpyinfo
->mouse_face_end_x
= 0;
23407 dpyinfo
->mouse_face_end_y
= 0;
23409 dpyinfo
->mouse_face_past_end
= 0;
23410 dpyinfo
->mouse_face_window
= window
;
23412 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23415 glyph
->face_id
, 1);
23416 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23418 if (NILP (pointer
))
23421 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23422 clear_mouse_face (dpyinfo
);
23424 define_frame_cursor1 (f
, cursor
, pointer
);
23429 Take proper action when the mouse has moved to position X, Y on
23430 frame F as regards highlighting characters that have mouse-face
23431 properties. Also de-highlighting chars where the mouse was before.
23432 X and Y can be negative or out of range. */
23435 note_mouse_highlight (f
, x
, y
)
23439 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23440 enum window_part part
;
23441 Lisp_Object window
;
23443 Cursor cursor
= No_Cursor
;
23444 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23447 /* When a menu is active, don't highlight because this looks odd. */
23448 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23449 if (popup_activated ())
23453 if (NILP (Vmouse_highlight
)
23454 || !f
->glyphs_initialized_p
23455 || f
->pointer_invisible
)
23458 dpyinfo
->mouse_face_mouse_x
= x
;
23459 dpyinfo
->mouse_face_mouse_y
= y
;
23460 dpyinfo
->mouse_face_mouse_frame
= f
;
23462 if (dpyinfo
->mouse_face_defer
)
23465 if (gc_in_progress
)
23467 dpyinfo
->mouse_face_deferred_gc
= 1;
23471 /* Which window is that in? */
23472 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23474 /* If we were displaying active text in another window, clear that.
23475 Also clear if we move out of text area in same window. */
23476 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23477 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23478 && !NILP (dpyinfo
->mouse_face_window
)))
23479 clear_mouse_face (dpyinfo
);
23481 /* Not on a window -> return. */
23482 if (!WINDOWP (window
))
23485 /* Reset help_echo_string. It will get recomputed below. */
23486 help_echo_string
= Qnil
;
23488 /* Convert to window-relative pixel coordinates. */
23489 w
= XWINDOW (window
);
23490 frame_to_window_pixel_xy (w
, &x
, &y
);
23492 /* Handle tool-bar window differently since it doesn't display a
23494 if (EQ (window
, f
->tool_bar_window
))
23496 note_tool_bar_highlight (f
, x
, y
);
23500 /* Mouse is on the mode, header line or margin? */
23501 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23502 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23504 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23508 if (part
== ON_VERTICAL_BORDER
)
23510 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23511 help_echo_string
= build_string ("drag-mouse-1: resize");
23513 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23514 || part
== ON_SCROLL_BAR
)
23515 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23517 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23519 /* Are we in a window whose display is up to date?
23520 And verify the buffer's text has not changed. */
23521 b
= XBUFFER (w
->buffer
);
23522 if (part
== ON_TEXT
23523 && EQ (w
->window_end_valid
, w
->buffer
)
23524 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23525 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23527 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23528 struct glyph
*glyph
;
23529 Lisp_Object object
;
23530 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23531 Lisp_Object
*overlay_vec
= NULL
;
23533 struct buffer
*obuf
;
23534 int obegv
, ozv
, same_region
;
23536 /* Find the glyph under X/Y. */
23537 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23539 /* Look for :pointer property on image. */
23540 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23542 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23543 if (img
!= NULL
&& IMAGEP (img
->spec
))
23545 Lisp_Object image_map
, hotspot
;
23546 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23548 && (hotspot
= find_hot_spot (image_map
,
23549 glyph
->slice
.x
+ dx
,
23550 glyph
->slice
.y
+ dy
),
23552 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23554 Lisp_Object area_id
, plist
;
23556 area_id
= XCAR (hotspot
);
23557 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23558 If so, we could look for mouse-enter, mouse-leave
23559 properties in PLIST (and do something...). */
23560 hotspot
= XCDR (hotspot
);
23561 if (CONSP (hotspot
)
23562 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23564 pointer
= Fplist_get (plist
, Qpointer
);
23565 if (NILP (pointer
))
23567 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23568 if (!NILP (help_echo_string
))
23570 help_echo_window
= window
;
23571 help_echo_object
= glyph
->object
;
23572 help_echo_pos
= glyph
->charpos
;
23576 if (NILP (pointer
))
23577 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23581 /* Clear mouse face if X/Y not over text. */
23583 || area
!= TEXT_AREA
23584 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23586 if (clear_mouse_face (dpyinfo
))
23587 cursor
= No_Cursor
;
23588 if (NILP (pointer
))
23590 if (area
!= TEXT_AREA
)
23591 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23593 pointer
= Vvoid_text_area_pointer
;
23598 pos
= glyph
->charpos
;
23599 object
= glyph
->object
;
23600 if (!STRINGP (object
) && !BUFFERP (object
))
23603 /* If we get an out-of-range value, return now; avoid an error. */
23604 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23607 /* Make the window's buffer temporarily current for
23608 overlays_at and compute_char_face. */
23609 obuf
= current_buffer
;
23610 current_buffer
= b
;
23616 /* Is this char mouse-active or does it have help-echo? */
23617 position
= make_number (pos
);
23619 if (BUFFERP (object
))
23621 /* Put all the overlays we want in a vector in overlay_vec. */
23622 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23623 /* Sort overlays into increasing priority order. */
23624 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23629 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23630 && vpos
>= dpyinfo
->mouse_face_beg_row
23631 && vpos
<= dpyinfo
->mouse_face_end_row
23632 && (vpos
> dpyinfo
->mouse_face_beg_row
23633 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23634 && (vpos
< dpyinfo
->mouse_face_end_row
23635 || hpos
< dpyinfo
->mouse_face_end_col
23636 || dpyinfo
->mouse_face_past_end
));
23639 cursor
= No_Cursor
;
23641 /* Check mouse-face highlighting. */
23643 /* If there exists an overlay with mouse-face overlapping
23644 the one we are currently highlighting, we have to
23645 check if we enter the overlapping overlay, and then
23646 highlight only that. */
23647 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23648 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23650 /* Find the highest priority overlay with a mouse-face. */
23652 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23654 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23655 if (!NILP (mouse_face
))
23656 overlay
= overlay_vec
[i
];
23659 /* If we're highlighting the same overlay as before, there's
23660 no need to do that again. */
23661 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23662 goto check_help_echo
;
23663 dpyinfo
->mouse_face_overlay
= overlay
;
23665 /* Clear the display of the old active region, if any. */
23666 if (clear_mouse_face (dpyinfo
))
23667 cursor
= No_Cursor
;
23669 /* If no overlay applies, get a text property. */
23670 if (NILP (overlay
))
23671 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23673 /* Next, compute the bounds of the mouse highlighting and
23675 if (!NILP (mouse_face
) && STRINGP (object
))
23677 /* The mouse-highlighting comes from a display string
23678 with a mouse-face. */
23682 b
= Fprevious_single_property_change
23683 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
23684 e
= Fnext_single_property_change
23685 (position
, Qmouse_face
, object
, Qnil
);
23687 b
= make_number (0);
23689 e
= make_number (SCHARS (object
) - 1);
23691 fast_find_string_pos (w
, XINT (b
), object
,
23692 &dpyinfo
->mouse_face_beg_col
,
23693 &dpyinfo
->mouse_face_beg_row
,
23694 &dpyinfo
->mouse_face_beg_x
,
23695 &dpyinfo
->mouse_face_beg_y
, 0);
23696 fast_find_string_pos (w
, XINT (e
), object
,
23697 &dpyinfo
->mouse_face_end_col
,
23698 &dpyinfo
->mouse_face_end_row
,
23699 &dpyinfo
->mouse_face_end_x
,
23700 &dpyinfo
->mouse_face_end_y
, 1);
23701 dpyinfo
->mouse_face_past_end
= 0;
23702 dpyinfo
->mouse_face_window
= window
;
23703 dpyinfo
->mouse_face_face_id
23704 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23705 glyph
->face_id
, 1);
23706 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23707 cursor
= No_Cursor
;
23711 /* The mouse-highlighting, if any, comes from an overlay
23712 or text property in the buffer. */
23713 Lisp_Object buffer
, display_string
;
23715 if (STRINGP (object
))
23717 /* If we are on a display string with no mouse-face,
23718 check if the text under it has one. */
23719 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23720 int start
= MATRIX_ROW_START_CHARPOS (r
);
23721 pos
= string_buffer_position (w
, object
, start
);
23724 mouse_face
= get_char_property_and_overlay
23725 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
23726 buffer
= w
->buffer
;
23727 display_string
= object
;
23733 display_string
= Qnil
;
23736 if (!NILP (mouse_face
))
23738 Lisp_Object before
, after
;
23739 Lisp_Object before_string
, after_string
;
23741 if (NILP (overlay
))
23743 /* Handle the text property case. */
23744 before
= Fprevious_single_property_change
23745 (make_number (pos
+ 1), Qmouse_face
, buffer
,
23746 Fmarker_position (w
->start
));
23747 after
= Fnext_single_property_change
23748 (make_number (pos
), Qmouse_face
, buffer
,
23749 make_number (BUF_Z (XBUFFER (buffer
))
23750 - XFASTINT (w
->window_end_pos
)));
23751 before_string
= after_string
= Qnil
;
23755 /* Handle the overlay case. */
23756 before
= Foverlay_start (overlay
);
23757 after
= Foverlay_end (overlay
);
23758 before_string
= Foverlay_get (overlay
, Qbefore_string
);
23759 after_string
= Foverlay_get (overlay
, Qafter_string
);
23761 if (!STRINGP (before_string
)) before_string
= Qnil
;
23762 if (!STRINGP (after_string
)) after_string
= Qnil
;
23765 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
23768 before_string
, after_string
,
23770 cursor
= No_Cursor
;
23777 /* Look for a `help-echo' property. */
23778 if (NILP (help_echo_string
)) {
23779 Lisp_Object help
, overlay
;
23781 /* Check overlays first. */
23782 help
= overlay
= Qnil
;
23783 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23785 overlay
= overlay_vec
[i
];
23786 help
= Foverlay_get (overlay
, Qhelp_echo
);
23791 help_echo_string
= help
;
23792 help_echo_window
= window
;
23793 help_echo_object
= overlay
;
23794 help_echo_pos
= pos
;
23798 Lisp_Object object
= glyph
->object
;
23799 int charpos
= glyph
->charpos
;
23801 /* Try text properties. */
23802 if (STRINGP (object
)
23804 && charpos
< SCHARS (object
))
23806 help
= Fget_text_property (make_number (charpos
),
23807 Qhelp_echo
, object
);
23810 /* If the string itself doesn't specify a help-echo,
23811 see if the buffer text ``under'' it does. */
23812 struct glyph_row
*r
23813 = MATRIX_ROW (w
->current_matrix
, vpos
);
23814 int start
= MATRIX_ROW_START_CHARPOS (r
);
23815 int pos
= string_buffer_position (w
, object
, start
);
23818 help
= Fget_char_property (make_number (pos
),
23819 Qhelp_echo
, w
->buffer
);
23823 object
= w
->buffer
;
23828 else if (BUFFERP (object
)
23831 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23836 help_echo_string
= help
;
23837 help_echo_window
= window
;
23838 help_echo_object
= object
;
23839 help_echo_pos
= charpos
;
23844 /* Look for a `pointer' property. */
23845 if (NILP (pointer
))
23847 /* Check overlays first. */
23848 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23849 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23851 if (NILP (pointer
))
23853 Lisp_Object object
= glyph
->object
;
23854 int charpos
= glyph
->charpos
;
23856 /* Try text properties. */
23857 if (STRINGP (object
)
23859 && charpos
< SCHARS (object
))
23861 pointer
= Fget_text_property (make_number (charpos
),
23863 if (NILP (pointer
))
23865 /* If the string itself doesn't specify a pointer,
23866 see if the buffer text ``under'' it does. */
23867 struct glyph_row
*r
23868 = MATRIX_ROW (w
->current_matrix
, vpos
);
23869 int start
= MATRIX_ROW_START_CHARPOS (r
);
23870 int pos
= string_buffer_position (w
, object
, start
);
23872 pointer
= Fget_char_property (make_number (pos
),
23873 Qpointer
, w
->buffer
);
23876 else if (BUFFERP (object
)
23879 pointer
= Fget_text_property (make_number (charpos
),
23886 current_buffer
= obuf
;
23891 define_frame_cursor1 (f
, cursor
, pointer
);
23896 Clear any mouse-face on window W. This function is part of the
23897 redisplay interface, and is called from try_window_id and similar
23898 functions to ensure the mouse-highlight is off. */
23901 x_clear_window_mouse_face (w
)
23904 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23905 Lisp_Object window
;
23908 XSETWINDOW (window
, w
);
23909 if (EQ (window
, dpyinfo
->mouse_face_window
))
23910 clear_mouse_face (dpyinfo
);
23916 Just discard the mouse face information for frame F, if any.
23917 This is used when the size of F is changed. */
23920 cancel_mouse_face (f
)
23923 Lisp_Object window
;
23924 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23926 window
= dpyinfo
->mouse_face_window
;
23927 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23929 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23930 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23931 dpyinfo
->mouse_face_window
= Qnil
;
23936 #endif /* HAVE_WINDOW_SYSTEM */
23939 /***********************************************************************
23941 ***********************************************************************/
23943 #ifdef HAVE_WINDOW_SYSTEM
23945 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23946 which intersects rectangle R. R is in window-relative coordinates. */
23949 expose_area (w
, row
, r
, area
)
23951 struct glyph_row
*row
;
23953 enum glyph_row_area area
;
23955 struct glyph
*first
= row
->glyphs
[area
];
23956 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23957 struct glyph
*last
;
23958 int first_x
, start_x
, x
;
23960 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23961 /* If row extends face to end of line write the whole line. */
23962 draw_glyphs (w
, 0, row
, area
,
23963 0, row
->used
[area
],
23964 DRAW_NORMAL_TEXT
, 0);
23967 /* Set START_X to the window-relative start position for drawing glyphs of
23968 AREA. The first glyph of the text area can be partially visible.
23969 The first glyphs of other areas cannot. */
23970 start_x
= window_box_left_offset (w
, area
);
23972 if (area
== TEXT_AREA
)
23975 /* Find the first glyph that must be redrawn. */
23977 && x
+ first
->pixel_width
< r
->x
)
23979 x
+= first
->pixel_width
;
23983 /* Find the last one. */
23987 && x
< r
->x
+ r
->width
)
23989 x
+= last
->pixel_width
;
23995 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23996 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23997 DRAW_NORMAL_TEXT
, 0);
24002 /* Redraw the parts of the glyph row ROW on window W intersecting
24003 rectangle R. R is in window-relative coordinates. Value is
24004 non-zero if mouse-face was overwritten. */
24007 expose_line (w
, row
, r
)
24009 struct glyph_row
*row
;
24012 xassert (row
->enabled_p
);
24014 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24015 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24016 0, row
->used
[TEXT_AREA
],
24017 DRAW_NORMAL_TEXT
, 0);
24020 if (row
->used
[LEFT_MARGIN_AREA
])
24021 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24022 if (row
->used
[TEXT_AREA
])
24023 expose_area (w
, row
, r
, TEXT_AREA
);
24024 if (row
->used
[RIGHT_MARGIN_AREA
])
24025 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24026 draw_row_fringe_bitmaps (w
, row
);
24029 return row
->mouse_face_p
;
24033 /* Redraw those parts of glyphs rows during expose event handling that
24034 overlap other rows. Redrawing of an exposed line writes over parts
24035 of lines overlapping that exposed line; this function fixes that.
24037 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24038 row in W's current matrix that is exposed and overlaps other rows.
24039 LAST_OVERLAPPING_ROW is the last such row. */
24042 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24044 struct glyph_row
*first_overlapping_row
;
24045 struct glyph_row
*last_overlapping_row
;
24048 struct glyph_row
*row
;
24050 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24051 if (row
->overlapping_p
)
24053 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24056 if (row
->used
[LEFT_MARGIN_AREA
])
24057 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24059 if (row
->used
[TEXT_AREA
])
24060 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24062 if (row
->used
[RIGHT_MARGIN_AREA
])
24063 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24069 /* Return non-zero if W's cursor intersects rectangle R. */
24072 phys_cursor_in_rect_p (w
, r
)
24076 XRectangle cr
, result
;
24077 struct glyph
*cursor_glyph
;
24078 struct glyph_row
*row
;
24080 if (w
->phys_cursor
.vpos
>= 0
24081 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24082 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24084 && row
->cursor_in_fringe_p
)
24086 /* Cursor is in the fringe. */
24087 cr
.x
= window_box_right_offset (w
,
24088 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24089 ? RIGHT_MARGIN_AREA
24092 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24093 cr
.height
= row
->height
;
24094 return x_intersect_rectangles (&cr
, r
, &result
);
24097 cursor_glyph
= get_phys_cursor_glyph (w
);
24100 /* r is relative to W's box, but w->phys_cursor.x is relative
24101 to left edge of W's TEXT area. Adjust it. */
24102 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24103 cr
.y
= w
->phys_cursor
.y
;
24104 cr
.width
= cursor_glyph
->pixel_width
;
24105 cr
.height
= w
->phys_cursor_height
;
24106 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24107 I assume the effect is the same -- and this is portable. */
24108 return x_intersect_rectangles (&cr
, r
, &result
);
24110 /* If we don't understand the format, pretend we're not in the hot-spot. */
24116 Draw a vertical window border to the right of window W if W doesn't
24117 have vertical scroll bars. */
24120 x_draw_vertical_border (w
)
24123 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24125 /* We could do better, if we knew what type of scroll-bar the adjacent
24126 windows (on either side) have... But we don't :-(
24127 However, I think this works ok. ++KFS 2003-04-25 */
24129 /* Redraw borders between horizontally adjacent windows. Don't
24130 do it for frames with vertical scroll bars because either the
24131 right scroll bar of a window, or the left scroll bar of its
24132 neighbor will suffice as a border. */
24133 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24136 if (!WINDOW_RIGHTMOST_P (w
)
24137 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24139 int x0
, x1
, y0
, y1
;
24141 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24144 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24147 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24149 else if (!WINDOW_LEFTMOST_P (w
)
24150 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24152 int x0
, x1
, y0
, y1
;
24154 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24157 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24160 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24165 /* Redraw the part of window W intersection rectangle FR. Pixel
24166 coordinates in FR are frame-relative. Call this function with
24167 input blocked. Value is non-zero if the exposure overwrites
24171 expose_window (w
, fr
)
24175 struct frame
*f
= XFRAME (w
->frame
);
24177 int mouse_face_overwritten_p
= 0;
24179 /* If window is not yet fully initialized, do nothing. This can
24180 happen when toolkit scroll bars are used and a window is split.
24181 Reconfiguring the scroll bar will generate an expose for a newly
24183 if (w
->current_matrix
== NULL
)
24186 /* When we're currently updating the window, display and current
24187 matrix usually don't agree. Arrange for a thorough display
24189 if (w
== updated_window
)
24191 SET_FRAME_GARBAGED (f
);
24195 /* Frame-relative pixel rectangle of W. */
24196 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24197 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24198 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24199 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24201 if (x_intersect_rectangles (fr
, &wr
, &r
))
24203 int yb
= window_text_bottom_y (w
);
24204 struct glyph_row
*row
;
24205 int cursor_cleared_p
;
24206 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24208 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24209 r
.x
, r
.y
, r
.width
, r
.height
));
24211 /* Convert to window coordinates. */
24212 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24213 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24215 /* Turn off the cursor. */
24216 if (!w
->pseudo_window_p
24217 && phys_cursor_in_rect_p (w
, &r
))
24219 x_clear_cursor (w
);
24220 cursor_cleared_p
= 1;
24223 cursor_cleared_p
= 0;
24225 /* Update lines intersecting rectangle R. */
24226 first_overlapping_row
= last_overlapping_row
= NULL
;
24227 for (row
= w
->current_matrix
->rows
;
24232 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24234 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24235 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24236 || (r
.y
>= y0
&& r
.y
< y1
)
24237 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24239 /* A header line may be overlapping, but there is no need
24240 to fix overlapping areas for them. KFS 2005-02-12 */
24241 if (row
->overlapping_p
&& !row
->mode_line_p
)
24243 if (first_overlapping_row
== NULL
)
24244 first_overlapping_row
= row
;
24245 last_overlapping_row
= row
;
24249 if (expose_line (w
, row
, &r
))
24250 mouse_face_overwritten_p
= 1;
24253 else if (row
->overlapping_p
)
24255 /* We must redraw a row overlapping the exposed area. */
24257 ? y0
+ row
->phys_height
> r
.y
24258 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24260 if (first_overlapping_row
== NULL
)
24261 first_overlapping_row
= row
;
24262 last_overlapping_row
= row
;
24270 /* Display the mode line if there is one. */
24271 if (WINDOW_WANTS_MODELINE_P (w
)
24272 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24274 && row
->y
< r
.y
+ r
.height
)
24276 if (expose_line (w
, row
, &r
))
24277 mouse_face_overwritten_p
= 1;
24280 if (!w
->pseudo_window_p
)
24282 /* Fix the display of overlapping rows. */
24283 if (first_overlapping_row
)
24284 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24287 /* Draw border between windows. */
24288 x_draw_vertical_border (w
);
24290 /* Turn the cursor on again. */
24291 if (cursor_cleared_p
)
24292 update_window_cursor (w
, 1);
24296 return mouse_face_overwritten_p
;
24301 /* Redraw (parts) of all windows in the window tree rooted at W that
24302 intersect R. R contains frame pixel coordinates. Value is
24303 non-zero if the exposure overwrites mouse-face. */
24306 expose_window_tree (w
, r
)
24310 struct frame
*f
= XFRAME (w
->frame
);
24311 int mouse_face_overwritten_p
= 0;
24313 while (w
&& !FRAME_GARBAGED_P (f
))
24315 if (!NILP (w
->hchild
))
24316 mouse_face_overwritten_p
24317 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24318 else if (!NILP (w
->vchild
))
24319 mouse_face_overwritten_p
24320 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24322 mouse_face_overwritten_p
|= expose_window (w
, r
);
24324 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24327 return mouse_face_overwritten_p
;
24332 Redisplay an exposed area of frame F. X and Y are the upper-left
24333 corner of the exposed rectangle. W and H are width and height of
24334 the exposed area. All are pixel values. W or H zero means redraw
24335 the entire frame. */
24338 expose_frame (f
, x
, y
, w
, h
)
24343 int mouse_face_overwritten_p
= 0;
24345 TRACE ((stderr
, "expose_frame "));
24347 /* No need to redraw if frame will be redrawn soon. */
24348 if (FRAME_GARBAGED_P (f
))
24350 TRACE ((stderr
, " garbaged\n"));
24354 /* If basic faces haven't been realized yet, there is no point in
24355 trying to redraw anything. This can happen when we get an expose
24356 event while Emacs is starting, e.g. by moving another window. */
24357 if (FRAME_FACE_CACHE (f
) == NULL
24358 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24360 TRACE ((stderr
, " no faces\n"));
24364 if (w
== 0 || h
== 0)
24367 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24368 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24378 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24379 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24381 if (WINDOWP (f
->tool_bar_window
))
24382 mouse_face_overwritten_p
24383 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24385 #ifdef HAVE_X_WINDOWS
24387 #ifndef USE_X_TOOLKIT
24388 if (WINDOWP (f
->menu_bar_window
))
24389 mouse_face_overwritten_p
24390 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24391 #endif /* not USE_X_TOOLKIT */
24395 /* Some window managers support a focus-follows-mouse style with
24396 delayed raising of frames. Imagine a partially obscured frame,
24397 and moving the mouse into partially obscured mouse-face on that
24398 frame. The visible part of the mouse-face will be highlighted,
24399 then the WM raises the obscured frame. With at least one WM, KDE
24400 2.1, Emacs is not getting any event for the raising of the frame
24401 (even tried with SubstructureRedirectMask), only Expose events.
24402 These expose events will draw text normally, i.e. not
24403 highlighted. Which means we must redo the highlight here.
24404 Subsume it under ``we love X''. --gerd 2001-08-15 */
24405 /* Included in Windows version because Windows most likely does not
24406 do the right thing if any third party tool offers
24407 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24408 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24410 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24411 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24413 int x
= dpyinfo
->mouse_face_mouse_x
;
24414 int y
= dpyinfo
->mouse_face_mouse_y
;
24415 clear_mouse_face (dpyinfo
);
24416 note_mouse_highlight (f
, x
, y
);
24423 Determine the intersection of two rectangles R1 and R2. Return
24424 the intersection in *RESULT. Value is non-zero if RESULT is not
24428 x_intersect_rectangles (r1
, r2
, result
)
24429 XRectangle
*r1
, *r2
, *result
;
24431 XRectangle
*left
, *right
;
24432 XRectangle
*upper
, *lower
;
24433 int intersection_p
= 0;
24435 /* Rearrange so that R1 is the left-most rectangle. */
24437 left
= r1
, right
= r2
;
24439 left
= r2
, right
= r1
;
24441 /* X0 of the intersection is right.x0, if this is inside R1,
24442 otherwise there is no intersection. */
24443 if (right
->x
<= left
->x
+ left
->width
)
24445 result
->x
= right
->x
;
24447 /* The right end of the intersection is the minimum of the
24448 the right ends of left and right. */
24449 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24452 /* Same game for Y. */
24454 upper
= r1
, lower
= r2
;
24456 upper
= r2
, lower
= r1
;
24458 /* The upper end of the intersection is lower.y0, if this is inside
24459 of upper. Otherwise, there is no intersection. */
24460 if (lower
->y
<= upper
->y
+ upper
->height
)
24462 result
->y
= lower
->y
;
24464 /* The lower end of the intersection is the minimum of the lower
24465 ends of upper and lower. */
24466 result
->height
= (min (lower
->y
+ lower
->height
,
24467 upper
->y
+ upper
->height
)
24469 intersection_p
= 1;
24473 return intersection_p
;
24476 #endif /* HAVE_WINDOW_SYSTEM */
24479 /***********************************************************************
24481 ***********************************************************************/
24486 Vwith_echo_area_save_vector
= Qnil
;
24487 staticpro (&Vwith_echo_area_save_vector
);
24489 Vmessage_stack
= Qnil
;
24490 staticpro (&Vmessage_stack
);
24492 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
24493 staticpro (&Qinhibit_redisplay
);
24495 message_dolog_marker1
= Fmake_marker ();
24496 staticpro (&message_dolog_marker1
);
24497 message_dolog_marker2
= Fmake_marker ();
24498 staticpro (&message_dolog_marker2
);
24499 message_dolog_marker3
= Fmake_marker ();
24500 staticpro (&message_dolog_marker3
);
24503 defsubr (&Sdump_frame_glyph_matrix
);
24504 defsubr (&Sdump_glyph_matrix
);
24505 defsubr (&Sdump_glyph_row
);
24506 defsubr (&Sdump_tool_bar_row
);
24507 defsubr (&Strace_redisplay
);
24508 defsubr (&Strace_to_stderr
);
24510 #ifdef HAVE_WINDOW_SYSTEM
24511 defsubr (&Stool_bar_lines_needed
);
24512 defsubr (&Slookup_image_map
);
24514 defsubr (&Sformat_mode_line
);
24515 defsubr (&Sinvisible_p
);
24517 staticpro (&Qmenu_bar_update_hook
);
24518 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
24520 staticpro (&Qoverriding_terminal_local_map
);
24521 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
24523 staticpro (&Qoverriding_local_map
);
24524 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
24526 staticpro (&Qwindow_scroll_functions
);
24527 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
24529 staticpro (&Qwindow_text_change_functions
);
24530 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
24532 staticpro (&Qredisplay_end_trigger_functions
);
24533 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
24535 staticpro (&Qinhibit_point_motion_hooks
);
24536 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
24538 Qeval
= intern_c_string ("eval");
24539 staticpro (&Qeval
);
24541 QCdata
= intern_c_string (":data");
24542 staticpro (&QCdata
);
24543 Qdisplay
= intern_c_string ("display");
24544 staticpro (&Qdisplay
);
24545 Qspace_width
= intern_c_string ("space-width");
24546 staticpro (&Qspace_width
);
24547 Qraise
= intern_c_string ("raise");
24548 staticpro (&Qraise
);
24549 Qslice
= intern_c_string ("slice");
24550 staticpro (&Qslice
);
24551 Qspace
= intern_c_string ("space");
24552 staticpro (&Qspace
);
24553 Qmargin
= intern_c_string ("margin");
24554 staticpro (&Qmargin
);
24555 Qpointer
= intern_c_string ("pointer");
24556 staticpro (&Qpointer
);
24557 Qleft_margin
= intern_c_string ("left-margin");
24558 staticpro (&Qleft_margin
);
24559 Qright_margin
= intern_c_string ("right-margin");
24560 staticpro (&Qright_margin
);
24561 Qcenter
= intern_c_string ("center");
24562 staticpro (&Qcenter
);
24563 Qline_height
= intern_c_string ("line-height");
24564 staticpro (&Qline_height
);
24565 QCalign_to
= intern_c_string (":align-to");
24566 staticpro (&QCalign_to
);
24567 QCrelative_width
= intern_c_string (":relative-width");
24568 staticpro (&QCrelative_width
);
24569 QCrelative_height
= intern_c_string (":relative-height");
24570 staticpro (&QCrelative_height
);
24571 QCeval
= intern_c_string (":eval");
24572 staticpro (&QCeval
);
24573 QCpropertize
= intern_c_string (":propertize");
24574 staticpro (&QCpropertize
);
24575 QCfile
= intern_c_string (":file");
24576 staticpro (&QCfile
);
24577 Qfontified
= intern_c_string ("fontified");
24578 staticpro (&Qfontified
);
24579 Qfontification_functions
= intern_c_string ("fontification-functions");
24580 staticpro (&Qfontification_functions
);
24581 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
24582 staticpro (&Qtrailing_whitespace
);
24583 Qescape_glyph
= intern_c_string ("escape-glyph");
24584 staticpro (&Qescape_glyph
);
24585 Qnobreak_space
= intern_c_string ("nobreak-space");
24586 staticpro (&Qnobreak_space
);
24587 Qimage
= intern_c_string ("image");
24588 staticpro (&Qimage
);
24589 QCmap
= intern_c_string (":map");
24590 staticpro (&QCmap
);
24591 QCpointer
= intern_c_string (":pointer");
24592 staticpro (&QCpointer
);
24593 Qrect
= intern_c_string ("rect");
24594 staticpro (&Qrect
);
24595 Qcircle
= intern_c_string ("circle");
24596 staticpro (&Qcircle
);
24597 Qpoly
= intern_c_string ("poly");
24598 staticpro (&Qpoly
);
24599 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
24600 staticpro (&Qmessage_truncate_lines
);
24601 Qgrow_only
= intern_c_string ("grow-only");
24602 staticpro (&Qgrow_only
);
24603 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
24604 staticpro (&Qinhibit_menubar_update
);
24605 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
24606 staticpro (&Qinhibit_eval_during_redisplay
);
24607 Qposition
= intern_c_string ("position");
24608 staticpro (&Qposition
);
24609 Qbuffer_position
= intern_c_string ("buffer-position");
24610 staticpro (&Qbuffer_position
);
24611 Qobject
= intern_c_string ("object");
24612 staticpro (&Qobject
);
24613 Qbar
= intern_c_string ("bar");
24615 Qhbar
= intern_c_string ("hbar");
24616 staticpro (&Qhbar
);
24617 Qbox
= intern_c_string ("box");
24619 Qhollow
= intern_c_string ("hollow");
24620 staticpro (&Qhollow
);
24621 Qhand
= intern_c_string ("hand");
24622 staticpro (&Qhand
);
24623 Qarrow
= intern_c_string ("arrow");
24624 staticpro (&Qarrow
);
24625 Qtext
= intern_c_string ("text");
24626 staticpro (&Qtext
);
24627 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
24628 staticpro (&Qrisky_local_variable
);
24629 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
24630 staticpro (&Qinhibit_free_realized_faces
);
24632 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
24633 Fcons (intern_c_string ("void-variable"), Qnil
)),
24635 staticpro (&list_of_error
);
24637 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
24638 staticpro (&Qlast_arrow_position
);
24639 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
24640 staticpro (&Qlast_arrow_string
);
24642 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
24643 staticpro (&Qoverlay_arrow_string
);
24644 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
24645 staticpro (&Qoverlay_arrow_bitmap
);
24647 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24648 staticpro (&echo_buffer
[0]);
24649 staticpro (&echo_buffer
[1]);
24651 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24652 staticpro (&echo_area_buffer
[0]);
24653 staticpro (&echo_area_buffer
[1]);
24655 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
24656 staticpro (&Vmessages_buffer_name
);
24658 mode_line_proptrans_alist
= Qnil
;
24659 staticpro (&mode_line_proptrans_alist
);
24660 mode_line_string_list
= Qnil
;
24661 staticpro (&mode_line_string_list
);
24662 mode_line_string_face
= Qnil
;
24663 staticpro (&mode_line_string_face
);
24664 mode_line_string_face_prop
= Qnil
;
24665 staticpro (&mode_line_string_face_prop
);
24666 Vmode_line_unwind_vector
= Qnil
;
24667 staticpro (&Vmode_line_unwind_vector
);
24669 help_echo_string
= Qnil
;
24670 staticpro (&help_echo_string
);
24671 help_echo_object
= Qnil
;
24672 staticpro (&help_echo_object
);
24673 help_echo_window
= Qnil
;
24674 staticpro (&help_echo_window
);
24675 previous_help_echo_string
= Qnil
;
24676 staticpro (&previous_help_echo_string
);
24677 help_echo_pos
= -1;
24679 #ifdef HAVE_WINDOW_SYSTEM
24680 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24681 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24682 For example, if a block cursor is over a tab, it will be drawn as
24683 wide as that tab on the display. */);
24684 x_stretch_cursor_p
= 0;
24687 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24688 doc
: /* *Non-nil means highlight trailing whitespace.
24689 The face used for trailing whitespace is `trailing-whitespace'. */);
24690 Vshow_trailing_whitespace
= Qnil
;
24692 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24693 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24694 A value of t means highlight the character itself (for nobreak space,
24695 use face `nobreak-space').
24696 A value of nil means no highlighting.
24697 Other values mean display the escape glyph followed by an ordinary
24698 space or ordinary hyphen. */);
24699 Vnobreak_char_display
= Qt
;
24701 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24702 doc
: /* *The pointer shape to show in void text areas.
24703 A value of nil means to show the text pointer. Other options are `arrow',
24704 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24705 Vvoid_text_area_pointer
= Qarrow
;
24707 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24708 doc
: /* Non-nil means don't actually do any redisplay.
24709 This is used for internal purposes. */);
24710 Vinhibit_redisplay
= Qnil
;
24712 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24713 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24714 Vglobal_mode_string
= Qnil
;
24716 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24717 doc
: /* Marker for where to display an arrow on top of the buffer text.
24718 This must be the beginning of a line in order to work.
24719 See also `overlay-arrow-string'. */);
24720 Voverlay_arrow_position
= Qnil
;
24722 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24723 doc
: /* String to display as an arrow in non-window frames.
24724 See also `overlay-arrow-position'. */);
24725 Voverlay_arrow_string
= make_pure_c_string ("=>");
24727 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24728 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24729 The symbols on this list are examined during redisplay to determine
24730 where to display overlay arrows. */);
24731 Voverlay_arrow_variable_list
24732 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
24734 DEFVAR_INT ("scroll-step", &scroll_step
,
24735 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24736 If that fails to bring point back on frame, point is centered instead.
24737 If this is zero, point is always centered after it moves off frame.
24738 If you want scrolling to always be a line at a time, you should set
24739 `scroll-conservatively' to a large value rather than set this to 1. */);
24741 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24742 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24743 If point moves off-screen, redisplay will scroll by up to
24744 `scroll-conservatively' lines in order to bring point just barely
24745 onto the screen again. If that cannot be done, then redisplay
24746 recenters point as usual.
24748 A value of zero means always recenter point if it moves off screen. */);
24749 scroll_conservatively
= 0;
24751 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24752 doc
: /* *Number of lines of margin at the top and bottom of a window.
24753 Recenter the window whenever point gets within this many lines
24754 of the top or bottom of the window. */);
24757 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24758 doc
: /* Pixels per inch value for non-window system displays.
24759 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24760 Vdisplay_pixels_per_inch
= make_float (72.0);
24763 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24766 DEFVAR_LISP ("truncate-partial-width-windows",
24767 &Vtruncate_partial_width_windows
,
24768 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
24769 For an integer value, truncate lines in each window narrower than the
24770 full frame width, provided the window width is less than that integer;
24771 otherwise, respect the value of `truncate-lines'.
24773 For any other non-nil value, truncate lines in all windows that do
24774 not span the full frame width.
24776 A value of nil means to respect the value of `truncate-lines'.
24778 If `word-wrap' is enabled, you might want to reduce this. */);
24779 Vtruncate_partial_width_windows
= make_number (50);
24781 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24782 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24783 Any other value means to use the appropriate face, `mode-line',
24784 `header-line', or `menu' respectively. */);
24785 mode_line_inverse_video
= 1;
24787 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24788 doc
: /* *Maximum buffer size for which line number should be displayed.
24789 If the buffer is bigger than this, the line number does not appear
24790 in the mode line. A value of nil means no limit. */);
24791 Vline_number_display_limit
= Qnil
;
24793 DEFVAR_INT ("line-number-display-limit-width",
24794 &line_number_display_limit_width
,
24795 doc
: /* *Maximum line width (in characters) for line number display.
24796 If the average length of the lines near point is bigger than this, then the
24797 line number may be omitted from the mode line. */);
24798 line_number_display_limit_width
= 200;
24800 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24801 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24802 highlight_nonselected_windows
= 0;
24804 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24805 doc
: /* Non-nil if more than one frame is visible on this display.
24806 Minibuffer-only frames don't count, but iconified frames do.
24807 This variable is not guaranteed to be accurate except while processing
24808 `frame-title-format' and `icon-title-format'. */);
24810 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24811 doc
: /* Template for displaying the title bar of visible frames.
24812 \(Assuming the window manager supports this feature.)
24814 This variable has the same structure as `mode-line-format', except that
24815 the %c and %l constructs are ignored. It is used only on frames for
24816 which no explicit name has been set \(see `modify-frame-parameters'). */);
24818 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24819 doc
: /* Template for displaying the title bar of an iconified frame.
24820 \(Assuming the window manager supports this feature.)
24821 This variable has the same structure as `mode-line-format' (which see),
24822 and is used only on frames for which no explicit name has been set
24823 \(see `modify-frame-parameters'). */);
24825 = Vframe_title_format
24826 = pure_cons (intern_c_string ("multiple-frames"),
24827 pure_cons (make_pure_c_string ("%b"),
24828 pure_cons (pure_cons (empty_unibyte_string
,
24829 pure_cons (intern_c_string ("invocation-name"),
24830 pure_cons (make_pure_c_string ("@"),
24831 pure_cons (intern_c_string ("system-name"),
24835 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24836 doc
: /* Maximum number of lines to keep in the message log buffer.
24837 If nil, disable message logging. If t, log messages but don't truncate
24838 the buffer when it becomes large. */);
24839 Vmessage_log_max
= make_number (100);
24841 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24842 doc
: /* Functions called before redisplay, if window sizes have changed.
24843 The value should be a list of functions that take one argument.
24844 Just before redisplay, for each frame, if any of its windows have changed
24845 size since the last redisplay, or have been split or deleted,
24846 all the functions in the list are called, with the frame as argument. */);
24847 Vwindow_size_change_functions
= Qnil
;
24849 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24850 doc
: /* List of functions to call before redisplaying a window with scrolling.
24851 Each function is called with two arguments, the window and its new
24852 display-start position. Note that these functions are also called by
24853 `set-window-buffer'. Also note that the value of `window-end' is not
24854 valid when these functions are called. */);
24855 Vwindow_scroll_functions
= Qnil
;
24857 DEFVAR_LISP ("window-text-change-functions",
24858 &Vwindow_text_change_functions
,
24859 doc
: /* Functions to call in redisplay when text in the window might change. */);
24860 Vwindow_text_change_functions
= Qnil
;
24862 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24863 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24864 Each function is called with two arguments, the window and the end trigger value.
24865 See `set-window-redisplay-end-trigger'. */);
24866 Vredisplay_end_trigger_functions
= Qnil
;
24868 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24869 doc
: /* *Non-nil means autoselect window with mouse pointer.
24870 If nil, do not autoselect windows.
24871 A positive number means delay autoselection by that many seconds: a
24872 window is autoselected only after the mouse has remained in that
24873 window for the duration of the delay.
24874 A negative number has a similar effect, but causes windows to be
24875 autoselected only after the mouse has stopped moving. \(Because of
24876 the way Emacs compares mouse events, you will occasionally wait twice
24877 that time before the window gets selected.\)
24878 Any other value means to autoselect window instantaneously when the
24879 mouse pointer enters it.
24881 Autoselection selects the minibuffer only if it is active, and never
24882 unselects the minibuffer if it is active.
24884 When customizing this variable make sure that the actual value of
24885 `focus-follows-mouse' matches the behavior of your window manager. */);
24886 Vmouse_autoselect_window
= Qnil
;
24888 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24889 doc
: /* *Non-nil means automatically resize tool-bars.
24890 This dynamically changes the tool-bar's height to the minimum height
24891 that is needed to make all tool-bar items visible.
24892 If value is `grow-only', the tool-bar's height is only increased
24893 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24894 Vauto_resize_tool_bars
= Qt
;
24896 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24897 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24898 auto_raise_tool_bar_buttons_p
= 1;
24900 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24901 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24902 make_cursor_line_fully_visible_p
= 1;
24904 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24905 doc
: /* *Border below tool-bar in pixels.
24906 If an integer, use it as the height of the border.
24907 If it is one of `internal-border-width' or `border-width', use the
24908 value of the corresponding frame parameter.
24909 Otherwise, no border is added below the tool-bar. */);
24910 Vtool_bar_border
= Qinternal_border_width
;
24912 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24913 doc
: /* *Margin around tool-bar buttons in pixels.
24914 If an integer, use that for both horizontal and vertical margins.
24915 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24916 HORZ specifying the horizontal margin, and VERT specifying the
24917 vertical margin. */);
24918 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24920 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24921 doc
: /* *Relief thickness of tool-bar buttons. */);
24922 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24924 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24925 doc
: /* List of functions to call to fontify regions of text.
24926 Each function is called with one argument POS. Functions must
24927 fontify a region starting at POS in the current buffer, and give
24928 fontified regions the property `fontified'. */);
24929 Vfontification_functions
= Qnil
;
24930 Fmake_variable_buffer_local (Qfontification_functions
);
24932 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24933 &unibyte_display_via_language_environment
,
24934 doc
: /* *Non-nil means display unibyte text according to language environment.
24935 Specifically, this means that raw bytes in the range 160-255 decimal
24936 are displayed by converting them to the equivalent multibyte characters
24937 according to the current language environment. As a result, they are
24938 displayed according to the current fontset.
24940 Note that this variable affects only how these bytes are displayed,
24941 but does not change the fact they are interpreted as raw bytes. */);
24942 unibyte_display_via_language_environment
= 0;
24944 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24945 doc
: /* *Maximum height for resizing mini-windows.
24946 If a float, it specifies a fraction of the mini-window frame's height.
24947 If an integer, it specifies a number of lines. */);
24948 Vmax_mini_window_height
= make_float (0.25);
24950 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24951 doc
: /* *How to resize mini-windows.
24952 A value of nil means don't automatically resize mini-windows.
24953 A value of t means resize them to fit the text displayed in them.
24954 A value of `grow-only', the default, means let mini-windows grow
24955 only, until their display becomes empty, at which point the windows
24956 go back to their normal size. */);
24957 Vresize_mini_windows
= Qgrow_only
;
24959 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24960 doc
: /* Alist specifying how to blink the cursor off.
24961 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24962 `cursor-type' frame-parameter or variable equals ON-STATE,
24963 comparing using `equal', Emacs uses OFF-STATE to specify
24964 how to blink it off. ON-STATE and OFF-STATE are values for
24965 the `cursor-type' frame parameter.
24967 If a frame's ON-STATE has no entry in this list,
24968 the frame's other specifications determine how to blink the cursor off. */);
24969 Vblink_cursor_alist
= Qnil
;
24971 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24972 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24973 automatic_hscrolling_p
= 1;
24974 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
24975 staticpro (&Qauto_hscroll_mode
);
24977 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24978 doc
: /* *How many columns away from the window edge point is allowed to get
24979 before automatic hscrolling will horizontally scroll the window. */);
24980 hscroll_margin
= 5;
24982 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24983 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24984 When point is less than `hscroll-margin' columns from the window
24985 edge, automatic hscrolling will scroll the window by the amount of columns
24986 determined by this variable. If its value is a positive integer, scroll that
24987 many columns. If it's a positive floating-point number, it specifies the
24988 fraction of the window's width to scroll. If it's nil or zero, point will be
24989 centered horizontally after the scroll. Any other value, including negative
24990 numbers, are treated as if the value were zero.
24992 Automatic hscrolling always moves point outside the scroll margin, so if
24993 point was more than scroll step columns inside the margin, the window will
24994 scroll more than the value given by the scroll step.
24996 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24997 and `scroll-right' overrides this variable's effect. */);
24998 Vhscroll_step
= make_number (0);
25000 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25001 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25002 Bind this around calls to `message' to let it take effect. */);
25003 message_truncate_lines
= 0;
25005 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25006 doc
: /* Normal hook run to update the menu bar definitions.
25007 Redisplay runs this hook before it redisplays the menu bar.
25008 This is used to update submenus such as Buffers,
25009 whose contents depend on various data. */);
25010 Vmenu_bar_update_hook
= Qnil
;
25012 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25013 doc
: /* Frame for which we are updating a menu.
25014 The enable predicate for a menu binding should check this variable. */);
25015 Vmenu_updating_frame
= Qnil
;
25017 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25018 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25019 inhibit_menubar_update
= 0;
25021 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25022 doc
: /* Prefix prepended to all continuation lines at display time.
25023 The value may be a string, an image, or a stretch-glyph; it is
25024 interpreted in the same way as the value of a `display' text property.
25026 This variable is overridden by any `wrap-prefix' text or overlay
25029 To add a prefix to non-continuation lines, use `line-prefix'. */);
25030 Vwrap_prefix
= Qnil
;
25031 staticpro (&Qwrap_prefix
);
25032 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25033 Fmake_variable_buffer_local (Qwrap_prefix
);
25035 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25036 doc
: /* Prefix prepended to all non-continuation lines at display time.
25037 The value may be a string, an image, or a stretch-glyph; it is
25038 interpreted in the same way as the value of a `display' text property.
25040 This variable is overridden by any `line-prefix' text or overlay
25043 To add a prefix to continuation lines, use `wrap-prefix'. */);
25044 Vline_prefix
= Qnil
;
25045 staticpro (&Qline_prefix
);
25046 Qline_prefix
= intern_c_string ("line-prefix");
25047 Fmake_variable_buffer_local (Qline_prefix
);
25049 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25050 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25051 inhibit_eval_during_redisplay
= 0;
25053 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25054 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25055 inhibit_free_realized_faces
= 0;
25058 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25059 doc
: /* Inhibit try_window_id display optimization. */);
25060 inhibit_try_window_id
= 0;
25062 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25063 doc
: /* Inhibit try_window_reusing display optimization. */);
25064 inhibit_try_window_reusing
= 0;
25066 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25067 doc
: /* Inhibit try_cursor_movement display optimization. */);
25068 inhibit_try_cursor_movement
= 0;
25069 #endif /* GLYPH_DEBUG */
25071 DEFVAR_INT ("overline-margin", &overline_margin
,
25072 doc
: /* *Space between overline and text, in pixels.
25073 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25074 margin to the caracter height. */);
25075 overline_margin
= 2;
25077 DEFVAR_INT ("underline-minimum-offset",
25078 &underline_minimum_offset
,
25079 doc
: /* Minimum distance between baseline and underline.
25080 This can improve legibility of underlined text at small font sizes,
25081 particularly when using variable `x-use-underline-position-properties'
25082 with fonts that specify an UNDERLINE_POSITION relatively close to the
25083 baseline. The default value is 1. */);
25084 underline_minimum_offset
= 1;
25086 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25087 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25088 display_hourglass_p
= 1;
25090 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25091 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25092 Value must be an integer or float. */);
25093 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25095 hourglass_atimer
= NULL
;
25096 hourglass_shown_p
= 0;
25100 /* Initialize this module when Emacs starts. */
25105 Lisp_Object root_window
;
25106 struct window
*mini_w
;
25108 current_header_line_height
= current_mode_line_height
= -1;
25110 CHARPOS (this_line_start_pos
) = 0;
25112 mini_w
= XWINDOW (minibuf_window
);
25113 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25115 if (!noninteractive
)
25117 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25120 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25121 set_window_height (root_window
,
25122 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25124 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25125 set_window_height (minibuf_window
, 1, 0);
25127 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25128 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25130 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25131 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25132 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25134 /* The default ellipsis glyphs `...'. */
25135 for (i
= 0; i
< 3; ++i
)
25136 default_invis_vector
[i
] = make_number ('.');
25140 /* Allocate the buffer for frame titles.
25141 Also used for `format-mode-line'. */
25143 mode_line_noprop_buf
= (char *) xmalloc (size
);
25144 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25145 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25146 mode_line_target
= MODE_LINE_DISPLAY
;
25149 help_echo_showing_p
= 0;
25152 /* Since w32 does not support atimers, it defines its own implementation of
25153 the following three functions in w32fns.c. */
25156 /* Platform-independent portion of hourglass implementation. */
25158 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25160 hourglass_started ()
25162 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25165 /* Cancel a currently active hourglass timer, and start a new one. */
25169 #if defined (HAVE_WINDOW_SYSTEM)
25171 int secs
, usecs
= 0;
25173 cancel_hourglass ();
25175 if (INTEGERP (Vhourglass_delay
)
25176 && XINT (Vhourglass_delay
) > 0)
25177 secs
= XFASTINT (Vhourglass_delay
);
25178 else if (FLOATP (Vhourglass_delay
)
25179 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25182 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25183 secs
= XFASTINT (tem
);
25184 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25187 secs
= DEFAULT_HOURGLASS_DELAY
;
25189 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25190 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25191 show_hourglass
, NULL
);
25196 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25199 cancel_hourglass ()
25201 #if defined (HAVE_WINDOW_SYSTEM)
25202 if (hourglass_atimer
)
25204 cancel_atimer (hourglass_atimer
);
25205 hourglass_atimer
= NULL
;
25208 if (hourglass_shown_p
)
25212 #endif /* ! WINDOWSNT */
25214 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25215 (do not change this comment) */