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 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
179 #include "character.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
193 #include "blockinput.h"
195 #ifdef HAVE_X_WINDOWS
210 #ifndef FRAME_X_OUTPUT
211 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
214 #define INFINITY 10000000
216 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
217 || defined(HAVE_NS) || defined (USE_GTK)
218 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
219 extern int pending_menu_activation
;
222 extern int interrupt_input
;
223 extern int command_loop_level
;
225 extern Lisp_Object do_mouse_tracking
;
227 extern int minibuffer_auto_raise
;
228 extern Lisp_Object Vminibuffer_list
;
230 extern Lisp_Object Qface
;
231 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
233 extern Lisp_Object Voverriding_local_map
;
234 extern Lisp_Object Voverriding_local_map_menu_flag
;
235 extern Lisp_Object Qmenu_item
;
236 extern Lisp_Object Qwhen
;
237 extern Lisp_Object Qhelp_echo
;
238 extern Lisp_Object Qbefore_string
, Qafter_string
;
240 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
241 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
242 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
243 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
244 Lisp_Object Qinhibit_point_motion_hooks
;
245 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
246 Lisp_Object Qfontified
;
247 Lisp_Object Qgrow_only
;
248 Lisp_Object Qinhibit_eval_during_redisplay
;
249 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
252 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
255 Lisp_Object Qarrow
, Qhand
, Qtext
;
257 Lisp_Object Qrisky_local_variable
;
259 /* Holds the list (error). */
260 Lisp_Object list_of_error
;
262 /* Functions called to fontify regions of text. */
264 Lisp_Object Vfontification_functions
;
265 Lisp_Object Qfontification_functions
;
267 /* Non-nil means automatically select any window when the mouse
268 cursor moves into it. */
269 Lisp_Object Vmouse_autoselect_window
;
271 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
272 Lisp_Object Vline_prefix
, Qline_prefix
;
274 /* Non-zero means draw tool bar buttons raised when the mouse moves
277 int auto_raise_tool_bar_buttons_p
;
279 /* Non-zero means to reposition window if cursor line is only partially visible. */
281 int make_cursor_line_fully_visible_p
;
283 /* Margin below tool bar in pixels. 0 or nil means no margin.
284 If value is `internal-border-width' or `border-width',
285 the corresponding frame parameter is used. */
287 Lisp_Object Vtool_bar_border
;
289 /* Margin around tool bar buttons in pixels. */
291 Lisp_Object Vtool_bar_button_margin
;
293 /* Thickness of shadow to draw around tool bar buttons. */
295 EMACS_INT tool_bar_button_relief
;
297 /* Non-nil means automatically resize tool-bars so that all tool-bar
298 items are visible, and no blank lines remain.
300 If value is `grow-only', only make tool-bar bigger. */
302 Lisp_Object Vauto_resize_tool_bars
;
304 /* Non-zero means draw block and hollow cursor as wide as the glyph
305 under it. For example, if a block cursor is over a tab, it will be
306 drawn as wide as that tab on the display. */
308 int x_stretch_cursor_p
;
310 /* Non-nil means don't actually do any redisplay. */
312 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
314 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
316 int inhibit_eval_during_redisplay
;
318 /* Names of text properties relevant for redisplay. */
320 Lisp_Object Qdisplay
;
321 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
323 /* Symbols used in text property values. */
325 Lisp_Object Vdisplay_pixels_per_inch
;
326 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
327 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
330 Lisp_Object Qmargin
, Qpointer
;
331 Lisp_Object Qline_height
;
332 extern Lisp_Object Qheight
;
333 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
334 extern Lisp_Object Qscroll_bar
;
335 extern Lisp_Object Qcursor
;
337 /* Non-nil means highlight trailing whitespace. */
339 Lisp_Object Vshow_trailing_whitespace
;
341 /* Non-nil means escape non-break space and hyphens. */
343 Lisp_Object Vnobreak_char_display
;
345 #ifdef HAVE_WINDOW_SYSTEM
346 extern Lisp_Object Voverflow_newline_into_fringe
;
348 /* Test if overflow newline into fringe. Called with iterator IT
349 at or past right window margin, and with IT->current_x set. */
351 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
352 (!NILP (Voverflow_newline_into_fringe) \
353 && FRAME_WINDOW_P (it->f) \
354 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
355 && it->current_x == it->last_visible_x \
356 && it->line_wrap != WORD_WRAP)
358 #else /* !HAVE_WINDOW_SYSTEM */
359 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
360 #endif /* HAVE_WINDOW_SYSTEM */
362 /* Test if the display element loaded in IT is a space or tab
363 character. This is used to determine word wrapping. */
365 #define IT_DISPLAYING_WHITESPACE(it) \
366 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
368 /* Non-nil means show the text cursor in void text areas
369 i.e. in blank areas after eol and eob. This used to be
370 the default in 21.3. */
372 Lisp_Object Vvoid_text_area_pointer
;
374 /* Name of the face used to highlight trailing whitespace. */
376 Lisp_Object Qtrailing_whitespace
;
378 /* Name and number of the face used to highlight escape glyphs. */
380 Lisp_Object Qescape_glyph
;
382 /* Name and number of the face used to highlight non-breaking spaces. */
384 Lisp_Object Qnobreak_space
;
386 /* The symbol `image' which is the car of the lists used to represent
391 /* The image map types. */
392 Lisp_Object QCmap
, QCpointer
;
393 Lisp_Object Qrect
, Qcircle
, Qpoly
;
395 /* Non-zero means print newline to stdout before next mini-buffer
398 int noninteractive_need_newline
;
400 /* Non-zero means print newline to message log before next message. */
402 static int message_log_need_newline
;
404 /* Three markers that message_dolog uses.
405 It could allocate them itself, but that causes trouble
406 in handling memory-full errors. */
407 static Lisp_Object message_dolog_marker1
;
408 static Lisp_Object message_dolog_marker2
;
409 static Lisp_Object message_dolog_marker3
;
411 /* The buffer position of the first character appearing entirely or
412 partially on the line of the selected window which contains the
413 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
414 redisplay optimization in redisplay_internal. */
416 static struct text_pos this_line_start_pos
;
418 /* Number of characters past the end of the line above, including the
419 terminating newline. */
421 static struct text_pos this_line_end_pos
;
423 /* The vertical positions and the height of this line. */
425 static int this_line_vpos
;
426 static int this_line_y
;
427 static int this_line_pixel_height
;
429 /* X position at which this display line starts. Usually zero;
430 negative if first character is partially visible. */
432 static int this_line_start_x
;
434 /* Buffer that this_line_.* variables are referring to. */
436 static struct buffer
*this_line_buffer
;
438 /* Nonzero means truncate lines in all windows less wide than the
441 Lisp_Object Vtruncate_partial_width_windows
;
443 /* A flag to control how to display unibyte 8-bit character. */
445 int unibyte_display_via_language_environment
;
447 /* Nonzero means we have more than one non-mini-buffer-only frame.
448 Not guaranteed to be accurate except while parsing
449 frame-title-format. */
453 Lisp_Object Vglobal_mode_string
;
456 /* List of variables (symbols) which hold markers for overlay arrows.
457 The symbols on this list are examined during redisplay to determine
458 where to display overlay arrows. */
460 Lisp_Object Voverlay_arrow_variable_list
;
462 /* Marker for where to display an arrow on top of the buffer text. */
464 Lisp_Object Voverlay_arrow_position
;
466 /* String to display for the arrow. Only used on terminal frames. */
468 Lisp_Object Voverlay_arrow_string
;
470 /* Values of those variables at last redisplay are stored as
471 properties on `overlay-arrow-position' symbol. However, if
472 Voverlay_arrow_position is a marker, last-arrow-position is its
473 numerical position. */
475 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
477 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
478 properties on a symbol in overlay-arrow-variable-list. */
480 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
482 /* Like mode-line-format, but for the title bar on a visible frame. */
484 Lisp_Object Vframe_title_format
;
486 /* Like mode-line-format, but for the title bar on an iconified frame. */
488 Lisp_Object Vicon_title_format
;
490 /* List of functions to call when a window's size changes. These
491 functions get one arg, a frame on which one or more windows' sizes
494 static Lisp_Object Vwindow_size_change_functions
;
496 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
498 /* Nonzero if an overlay arrow has been displayed in this window. */
500 static int overlay_arrow_seen
;
502 /* Nonzero means highlight the region even in nonselected windows. */
504 int highlight_nonselected_windows
;
506 /* If cursor motion alone moves point off frame, try scrolling this
507 many lines up or down if that will bring it back. */
509 static EMACS_INT scroll_step
;
511 /* Nonzero means scroll just far enough to bring point back on the
512 screen, when appropriate. */
514 static EMACS_INT scroll_conservatively
;
516 /* Recenter the window whenever point gets within this many lines of
517 the top or bottom of the window. This value is translated into a
518 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
519 that there is really a fixed pixel height scroll margin. */
521 EMACS_INT scroll_margin
;
523 /* Number of windows showing the buffer of the selected window (or
524 another buffer with the same base buffer). keyboard.c refers to
529 /* Vector containing glyphs for an ellipsis `...'. */
531 static Lisp_Object default_invis_vector
[3];
533 /* Zero means display the mode-line/header-line/menu-bar in the default face
534 (this slightly odd definition is for compatibility with previous versions
535 of emacs), non-zero means display them using their respective faces.
537 This variable is deprecated. */
539 int mode_line_inverse_video
;
541 /* Prompt to display in front of the mini-buffer contents. */
543 Lisp_Object minibuf_prompt
;
545 /* Width of current mini-buffer prompt. Only set after display_line
546 of the line that contains the prompt. */
548 int minibuf_prompt_width
;
550 /* This is the window where the echo area message was displayed. It
551 is always a mini-buffer window, but it may not be the same window
552 currently active as a mini-buffer. */
554 Lisp_Object echo_area_window
;
556 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
557 pushes the current message and the value of
558 message_enable_multibyte on the stack, the function restore_message
559 pops the stack and displays MESSAGE again. */
561 Lisp_Object Vmessage_stack
;
563 /* Nonzero means multibyte characters were enabled when the echo area
564 message was specified. */
566 int message_enable_multibyte
;
568 /* Nonzero if we should redraw the mode lines on the next redisplay. */
570 int update_mode_lines
;
572 /* Nonzero if window sizes or contents have changed since last
573 redisplay that finished. */
575 int windows_or_buffers_changed
;
577 /* Nonzero means a frame's cursor type has been changed. */
579 int cursor_type_changed
;
581 /* Nonzero after display_mode_line if %l was used and it displayed a
584 int line_number_displayed
;
586 /* Maximum buffer size for which to display line numbers. */
588 Lisp_Object Vline_number_display_limit
;
590 /* Line width to consider when repositioning for line number display. */
592 static EMACS_INT line_number_display_limit_width
;
594 /* Number of lines to keep in the message log buffer. t means
595 infinite. nil means don't log at all. */
597 Lisp_Object Vmessage_log_max
;
599 /* The name of the *Messages* buffer, a string. */
601 static Lisp_Object Vmessages_buffer_name
;
603 /* Current, index 0, and last displayed echo area message. Either
604 buffers from echo_buffers, or nil to indicate no message. */
606 Lisp_Object echo_area_buffer
[2];
608 /* The buffers referenced from echo_area_buffer. */
610 static Lisp_Object echo_buffer
[2];
612 /* A vector saved used in with_area_buffer to reduce consing. */
614 static Lisp_Object Vwith_echo_area_save_vector
;
616 /* Non-zero means display_echo_area should display the last echo area
617 message again. Set by redisplay_preserve_echo_area. */
619 static int display_last_displayed_message_p
;
621 /* Nonzero if echo area is being used by print; zero if being used by
624 int message_buf_print
;
626 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
628 Lisp_Object Qinhibit_menubar_update
;
629 int inhibit_menubar_update
;
631 /* When evaluating expressions from menu bar items (enable conditions,
632 for instance), this is the frame they are being processed for. */
634 Lisp_Object Vmenu_updating_frame
;
636 /* Maximum height for resizing mini-windows. Either a float
637 specifying a fraction of the available height, or an integer
638 specifying a number of lines. */
640 Lisp_Object Vmax_mini_window_height
;
642 /* Non-zero means messages should be displayed with truncated
643 lines instead of being continued. */
645 int message_truncate_lines
;
646 Lisp_Object Qmessage_truncate_lines
;
648 /* Set to 1 in clear_message to make redisplay_internal aware
649 of an emptied echo area. */
651 static int message_cleared_p
;
653 /* How to blink the default frame cursor off. */
654 Lisp_Object Vblink_cursor_alist
;
656 /* A scratch glyph row with contents used for generating truncation
657 glyphs. Also used in direct_output_for_insert. */
659 #define MAX_SCRATCH_GLYPHS 100
660 struct glyph_row scratch_glyph_row
;
661 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
663 /* Ascent and height of the last line processed by move_it_to. */
665 static int last_max_ascent
, last_height
;
667 /* Non-zero if there's a help-echo in the echo area. */
669 int help_echo_showing_p
;
671 /* If >= 0, computed, exact values of mode-line and header-line height
672 to use in the macros CURRENT_MODE_LINE_HEIGHT and
673 CURRENT_HEADER_LINE_HEIGHT. */
675 int current_mode_line_height
, current_header_line_height
;
677 /* The maximum distance to look ahead for text properties. Values
678 that are too small let us call compute_char_face and similar
679 functions too often which is expensive. Values that are too large
680 let us call compute_char_face and alike too often because we
681 might not be interested in text properties that far away. */
683 #define TEXT_PROP_DISTANCE_LIMIT 100
687 /* Variables to turn off display optimizations from Lisp. */
689 int inhibit_try_window_id
, inhibit_try_window_reusing
;
690 int inhibit_try_cursor_movement
;
692 /* Non-zero means print traces of redisplay if compiled with
695 int trace_redisplay_p
;
697 #endif /* GLYPH_DEBUG */
699 #ifdef DEBUG_TRACE_MOVE
700 /* Non-zero means trace with TRACE_MOVE to stderr. */
703 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
705 #define TRACE_MOVE(x) (void) 0
708 /* Non-zero means automatically scroll windows horizontally to make
711 int automatic_hscrolling_p
;
712 Lisp_Object Qauto_hscroll_mode
;
714 /* How close to the margin can point get before the window is scrolled
716 EMACS_INT hscroll_margin
;
718 /* How much to scroll horizontally when point is inside the above margin. */
719 Lisp_Object Vhscroll_step
;
721 /* The variable `resize-mini-windows'. If nil, don't resize
722 mini-windows. If t, always resize them to fit the text they
723 display. If `grow-only', let mini-windows grow only until they
726 Lisp_Object Vresize_mini_windows
;
728 /* Buffer being redisplayed -- for redisplay_window_error. */
730 struct buffer
*displayed_buffer
;
732 /* Space between overline and text. */
734 EMACS_INT overline_margin
;
736 /* Require underline to be at least this many screen pixels below baseline
737 This to avoid underline "merging" with the base of letters at small
738 font sizes, particularly when x_use_underline_position_properties is on. */
740 EMACS_INT underline_minimum_offset
;
742 /* Value returned from text property handlers (see below). */
747 HANDLED_RECOMPUTE_PROPS
,
748 HANDLED_OVERLAY_STRING_CONSUMED
,
752 /* A description of text properties that redisplay is interested
757 /* The name of the property. */
760 /* A unique index for the property. */
763 /* A handler function called to set up iterator IT from the property
764 at IT's current position. Value is used to steer handle_stop. */
765 enum prop_handled (*handler
) P_ ((struct it
*it
));
768 static enum prop_handled handle_face_prop
P_ ((struct it
*));
769 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
770 static enum prop_handled handle_display_prop
P_ ((struct it
*));
771 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
772 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
773 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
775 /* Properties handled by iterators. */
777 static struct props it_props
[] =
779 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
780 /* Handle `face' before `display' because some sub-properties of
781 `display' need to know the face. */
782 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
783 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
784 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
785 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
789 /* Value is the position described by X. If X is a marker, value is
790 the marker_position of X. Otherwise, value is X. */
792 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
794 /* Enumeration returned by some move_it_.* functions internally. */
798 /* Not used. Undefined value. */
801 /* Move ended at the requested buffer position or ZV. */
802 MOVE_POS_MATCH_OR_ZV
,
804 /* Move ended at the requested X pixel position. */
807 /* Move within a line ended at the end of a line that must be
811 /* Move within a line ended at the end of a line that would
812 be displayed truncated. */
815 /* Move within a line ended at a line end. */
819 /* This counter is used to clear the face cache every once in a while
820 in redisplay_internal. It is incremented for each redisplay.
821 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
824 #define CLEAR_FACE_CACHE_COUNT 500
825 static int clear_face_cache_count
;
827 /* Similarly for the image cache. */
829 #ifdef HAVE_WINDOW_SYSTEM
830 #define CLEAR_IMAGE_CACHE_COUNT 101
831 static int clear_image_cache_count
;
834 /* Non-zero while redisplay_internal is in progress. */
838 /* Non-zero means don't free realized faces. Bound while freeing
839 realized faces is dangerous because glyph matrices might still
842 int inhibit_free_realized_faces
;
843 Lisp_Object Qinhibit_free_realized_faces
;
845 /* If a string, XTread_socket generates an event to display that string.
846 (The display is done in read_char.) */
848 Lisp_Object help_echo_string
;
849 Lisp_Object help_echo_window
;
850 Lisp_Object help_echo_object
;
853 /* Temporary variable for XTread_socket. */
855 Lisp_Object previous_help_echo_string
;
857 /* Null glyph slice */
859 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
861 /* Platform-independent portion of hourglass implementation. */
863 /* Non-zero means we're allowed to display a hourglass pointer. */
864 int display_hourglass_p
;
866 /* Non-zero means an hourglass cursor is currently shown. */
867 int hourglass_shown_p
;
869 /* If non-null, an asynchronous timer that, when it expires, displays
870 an hourglass cursor on all frames. */
871 struct atimer
*hourglass_atimer
;
873 /* Number of seconds to wait before displaying an hourglass cursor. */
874 Lisp_Object Vhourglass_delay
;
876 /* Default number of seconds to wait before displaying an hourglass
878 #define DEFAULT_HOURGLASS_DELAY 1
881 /* Function prototypes. */
883 static void setup_for_ellipsis
P_ ((struct it
*, int));
884 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
885 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
886 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
887 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
888 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
889 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
891 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
893 static void handle_line_prefix
P_ ((struct it
*));
895 static void pint2str
P_ ((char *, int, int));
896 static void pint2hrstr
P_ ((char *, int, int));
897 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
899 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
900 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
901 static void store_mode_line_noprop_char
P_ ((char));
902 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
903 static void x_consider_frame_title
P_ ((Lisp_Object
));
904 static void handle_stop
P_ ((struct it
*));
905 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
906 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
907 static void ensure_echo_area_buffers
P_ ((void));
908 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
909 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
910 static int with_echo_area_buffer
P_ ((struct window
*, int,
911 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
912 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
913 static void clear_garbaged_frames
P_ ((void));
914 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
915 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
916 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int display_echo_area
P_ ((struct window
*));
918 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
920 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
921 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
922 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
924 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
925 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
926 static void insert_left_trunc_glyphs
P_ ((struct it
*));
927 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
929 static void extend_face_to_end_of_line
P_ ((struct it
*));
930 static int append_space_for_newline
P_ ((struct it
*, int));
931 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
932 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
933 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
934 static int trailing_whitespace_p
P_ ((int));
935 static int message_log_check_duplicate
P_ ((int, int, int, int));
936 static void push_it
P_ ((struct it
*));
937 static void pop_it
P_ ((struct it
*));
938 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
939 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
940 static void redisplay_internal
P_ ((int));
941 static int echo_area_display
P_ ((int));
942 static void redisplay_windows
P_ ((Lisp_Object
));
943 static void redisplay_window
P_ ((Lisp_Object
, int));
944 static Lisp_Object
redisplay_window_error ();
945 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
946 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
947 static int update_menu_bar
P_ ((struct frame
*, int, int));
948 static int try_window_reusing_current_matrix
P_ ((struct window
*));
949 static int try_window_id
P_ ((struct window
*));
950 static int display_line
P_ ((struct it
*));
951 static int display_mode_lines
P_ ((struct window
*));
952 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
953 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
954 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
955 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
956 static void display_menu_bar
P_ ((struct window
*));
957 static int display_count_lines
P_ ((int, int, int, int, int *));
958 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
959 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
960 static void compute_line_metrics
P_ ((struct it
*));
961 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
962 static int get_overlay_strings
P_ ((struct it
*, int));
963 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
964 static void next_overlay_string
P_ ((struct it
*));
965 static void reseat
P_ ((struct it
*, struct text_pos
, int));
966 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
967 static void back_to_previous_visible_line_start
P_ ((struct it
*));
968 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
969 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
970 static int next_element_from_ellipsis
P_ ((struct it
*));
971 static int next_element_from_display_vector
P_ ((struct it
*));
972 static int next_element_from_string
P_ ((struct it
*));
973 static int next_element_from_c_string
P_ ((struct it
*));
974 static int next_element_from_buffer
P_ ((struct it
*));
975 static int next_element_from_composition
P_ ((struct it
*));
976 static int next_element_from_image
P_ ((struct it
*));
977 static int next_element_from_stretch
P_ ((struct it
*));
978 static void load_overlay_strings
P_ ((struct it
*, int));
979 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
980 struct display_pos
*));
981 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
982 Lisp_Object
, int, int, int, int));
983 static enum move_it_result
984 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
985 enum move_operation_enum
);
986 void move_it_vertically_backward
P_ ((struct it
*, int));
987 static void init_to_row_start
P_ ((struct it
*, struct window
*,
988 struct glyph_row
*));
989 static int init_to_row_end
P_ ((struct it
*, struct window
*,
990 struct glyph_row
*));
991 static void back_to_previous_line_start
P_ ((struct it
*));
992 static int forward_to_next_line_start
P_ ((struct it
*, int *));
993 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
995 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
996 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
997 static int number_of_chars
P_ ((unsigned char *, int));
998 static void compute_stop_pos
P_ ((struct it
*));
999 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1001 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1002 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1003 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1004 Lisp_Object
, Lisp_Object
,
1005 struct text_pos
*, int));
1006 static int underlying_face_id
P_ ((struct it
*));
1007 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1010 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1011 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1013 #ifdef HAVE_WINDOW_SYSTEM
1015 static void update_tool_bar
P_ ((struct frame
*, int));
1016 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1017 static int redisplay_tool_bar
P_ ((struct frame
*));
1018 static void display_tool_bar_line
P_ ((struct it
*, int));
1019 static void notice_overwritten_cursor
P_ ((struct window
*,
1020 enum glyph_row_area
,
1021 int, int, int, int));
1025 #endif /* HAVE_WINDOW_SYSTEM */
1028 /***********************************************************************
1029 Window display dimensions
1030 ***********************************************************************/
1032 /* Return the bottom boundary y-position for text lines in window W.
1033 This is the first y position at which a line cannot start.
1034 It is relative to the top of the window.
1036 This is the height of W minus the height of a mode line, if any. */
1039 window_text_bottom_y (w
)
1042 int height
= WINDOW_TOTAL_HEIGHT (w
);
1044 if (WINDOW_WANTS_MODELINE_P (w
))
1045 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1049 /* Return the pixel width of display area AREA of window W. AREA < 0
1050 means return the total width of W, not including fringes to
1051 the left and right of the window. */
1054 window_box_width (w
, area
)
1058 int cols
= XFASTINT (w
->total_cols
);
1061 if (!w
->pseudo_window_p
)
1063 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1065 if (area
== TEXT_AREA
)
1067 if (INTEGERP (w
->left_margin_cols
))
1068 cols
-= XFASTINT (w
->left_margin_cols
);
1069 if (INTEGERP (w
->right_margin_cols
))
1070 cols
-= XFASTINT (w
->right_margin_cols
);
1071 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1073 else if (area
== LEFT_MARGIN_AREA
)
1075 cols
= (INTEGERP (w
->left_margin_cols
)
1076 ? XFASTINT (w
->left_margin_cols
) : 0);
1079 else if (area
== RIGHT_MARGIN_AREA
)
1081 cols
= (INTEGERP (w
->right_margin_cols
)
1082 ? XFASTINT (w
->right_margin_cols
) : 0);
1087 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1091 /* Return the pixel height of the display area of window W, not
1092 including mode lines of W, if any. */
1095 window_box_height (w
)
1098 struct frame
*f
= XFRAME (w
->frame
);
1099 int height
= WINDOW_TOTAL_HEIGHT (w
);
1101 xassert (height
>= 0);
1103 /* Note: the code below that determines the mode-line/header-line
1104 height is essentially the same as that contained in the macro
1105 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1106 the appropriate glyph row has its `mode_line_p' flag set,
1107 and if it doesn't, uses estimate_mode_line_height instead. */
1109 if (WINDOW_WANTS_MODELINE_P (w
))
1111 struct glyph_row
*ml_row
1112 = (w
->current_matrix
&& w
->current_matrix
->rows
1113 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1115 if (ml_row
&& ml_row
->mode_line_p
)
1116 height
-= ml_row
->height
;
1118 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1121 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1123 struct glyph_row
*hl_row
1124 = (w
->current_matrix
&& w
->current_matrix
->rows
1125 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1127 if (hl_row
&& hl_row
->mode_line_p
)
1128 height
-= hl_row
->height
;
1130 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1133 /* With a very small font and a mode-line that's taller than
1134 default, we might end up with a negative height. */
1135 return max (0, height
);
1138 /* Return the window-relative coordinate of the left edge of display
1139 area AREA of window W. AREA < 0 means return the left edge of the
1140 whole window, to the right of the left fringe of W. */
1143 window_box_left_offset (w
, area
)
1149 if (w
->pseudo_window_p
)
1152 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1154 if (area
== TEXT_AREA
)
1155 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1156 + window_box_width (w
, LEFT_MARGIN_AREA
));
1157 else if (area
== RIGHT_MARGIN_AREA
)
1158 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1159 + window_box_width (w
, LEFT_MARGIN_AREA
)
1160 + window_box_width (w
, TEXT_AREA
)
1161 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1163 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1164 else if (area
== LEFT_MARGIN_AREA
1165 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1166 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1172 /* Return the window-relative coordinate of the right edge of display
1173 area AREA of window W. AREA < 0 means return the left edge of the
1174 whole window, to the left of the right fringe of W. */
1177 window_box_right_offset (w
, area
)
1181 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1184 /* Return the frame-relative coordinate of the left edge of display
1185 area AREA of window W. AREA < 0 means return the left edge of the
1186 whole window, to the right of the left fringe of W. */
1189 window_box_left (w
, area
)
1193 struct frame
*f
= XFRAME (w
->frame
);
1196 if (w
->pseudo_window_p
)
1197 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1199 x
= (WINDOW_LEFT_EDGE_X (w
)
1200 + window_box_left_offset (w
, area
));
1206 /* Return the frame-relative coordinate of the right edge of display
1207 area AREA of window W. AREA < 0 means return the left edge of the
1208 whole window, to the left of the right fringe of W. */
1211 window_box_right (w
, area
)
1215 return window_box_left (w
, area
) + window_box_width (w
, area
);
1218 /* Get the bounding box of the display area AREA of window W, without
1219 mode lines, in frame-relative coordinates. AREA < 0 means the
1220 whole window, not including the left and right fringes of
1221 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1222 coordinates of the upper-left corner of the box. Return in
1223 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1226 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1229 int *box_x
, *box_y
, *box_width
, *box_height
;
1232 *box_width
= window_box_width (w
, area
);
1234 *box_height
= window_box_height (w
);
1236 *box_x
= window_box_left (w
, area
);
1239 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1240 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1241 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1246 /* Get the bounding box of the display area AREA of window W, without
1247 mode lines. AREA < 0 means the whole window, not including the
1248 left and right fringe of the window. Return in *TOP_LEFT_X
1249 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1250 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1251 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1255 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1256 bottom_right_x
, bottom_right_y
)
1259 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1261 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1263 *bottom_right_x
+= *top_left_x
;
1264 *bottom_right_y
+= *top_left_y
;
1269 /***********************************************************************
1271 ***********************************************************************/
1273 /* Return the bottom y-position of the line the iterator IT is in.
1274 This can modify IT's settings. */
1280 int line_height
= it
->max_ascent
+ it
->max_descent
;
1281 int line_top_y
= it
->current_y
;
1283 if (line_height
== 0)
1286 line_height
= last_height
;
1287 else if (IT_CHARPOS (*it
) < ZV
)
1289 move_it_by_lines (it
, 1, 1);
1290 line_height
= (it
->max_ascent
|| it
->max_descent
1291 ? it
->max_ascent
+ it
->max_descent
1296 struct glyph_row
*row
= it
->glyph_row
;
1298 /* Use the default character height. */
1299 it
->glyph_row
= NULL
;
1300 it
->what
= IT_CHARACTER
;
1303 PRODUCE_GLYPHS (it
);
1304 line_height
= it
->ascent
+ it
->descent
;
1305 it
->glyph_row
= row
;
1309 return line_top_y
+ line_height
;
1313 /* Return 1 if position CHARPOS is visible in window W.
1314 CHARPOS < 0 means return info about WINDOW_END position.
1315 If visible, set *X and *Y to pixel coordinates of top left corner.
1316 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1317 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1320 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1322 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1325 struct text_pos top
;
1327 struct buffer
*old_buffer
= NULL
;
1329 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1332 if (XBUFFER (w
->buffer
) != current_buffer
)
1334 old_buffer
= current_buffer
;
1335 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1338 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1340 /* Compute exact mode line heights. */
1341 if (WINDOW_WANTS_MODELINE_P (w
))
1342 current_mode_line_height
1343 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1344 current_buffer
->mode_line_format
);
1346 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1347 current_header_line_height
1348 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1349 current_buffer
->header_line_format
);
1351 start_display (&it
, w
, top
);
1352 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1353 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1355 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1357 /* We have reached CHARPOS, or passed it. How the call to
1358 move_it_to can overshoot: (i) If CHARPOS is on invisible
1359 text, move_it_to stops at the end of the invisible text,
1360 after CHARPOS. (ii) If CHARPOS is in a display vector,
1361 move_it_to stops on its last glyph. */
1362 int top_x
= it
.current_x
;
1363 int top_y
= it
.current_y
;
1364 enum it_method it_method
= it
.method
;
1365 /* Calling line_bottom_y may change it.method. */
1366 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1367 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1369 if (top_y
< window_top_y
)
1370 visible_p
= bottom_y
> window_top_y
;
1371 else if (top_y
< it
.last_visible_y
)
1375 if (it_method
== GET_FROM_BUFFER
)
1377 Lisp_Object window
, prop
;
1379 XSETWINDOW (window
, w
);
1380 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1381 Qinvisible
, window
);
1383 /* If charpos coincides with invisible text covered with an
1384 ellipsis, use the first glyph of the ellipsis to compute
1385 the pixel positions. */
1386 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1388 struct glyph_row
*row
= it
.glyph_row
;
1389 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1390 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1394 && (!BUFFERP (glyph
->object
)
1395 || glyph
->charpos
< charpos
);
1397 x
+= glyph
->pixel_width
;
1401 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1403 /* We stopped on the last glyph of a display vector.
1404 Try and recompute. Hack alert! */
1405 if (charpos
< 2 || top
.charpos
>= charpos
)
1406 top_x
= it
.glyph_row
->x
;
1410 start_display (&it2
, w
, top
);
1411 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1412 get_next_display_element (&it2
);
1413 PRODUCE_GLYPHS (&it2
);
1414 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1415 || it2
.current_x
> it2
.last_visible_x
)
1416 top_x
= it
.glyph_row
->x
;
1419 top_x
= it2
.current_x
;
1420 top_y
= it2
.current_y
;
1426 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1427 *rtop
= max (0, window_top_y
- top_y
);
1428 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1429 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1430 - max (top_y
, window_top_y
)));
1439 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1440 move_it_by_lines (&it
, 1, 0);
1441 if (charpos
< IT_CHARPOS (it
)
1442 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1445 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1447 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1448 *rtop
= max (0, -it2
.current_y
);
1449 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1450 - it
.last_visible_y
));
1451 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1453 - max (it2
.current_y
,
1454 WINDOW_HEADER_LINE_HEIGHT (w
))));
1460 set_buffer_internal_1 (old_buffer
);
1462 current_header_line_height
= current_mode_line_height
= -1;
1464 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1465 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1468 /* Debugging code. */
1470 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1471 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1473 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1480 /* Return the next character from STR which is MAXLEN bytes long.
1481 Return in *LEN the length of the character. This is like
1482 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1483 we find one, we return a `?', but with the length of the invalid
1487 string_char_and_length (str
, maxlen
, len
)
1488 const unsigned char *str
;
1493 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1494 if (!CHAR_VALID_P (c
, 1))
1495 /* We may not change the length here because other places in Emacs
1496 don't use this function, i.e. they silently accept invalid
1505 /* Given a position POS containing a valid character and byte position
1506 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1508 static struct text_pos
1509 string_pos_nchars_ahead (pos
, string
, nchars
)
1510 struct text_pos pos
;
1514 xassert (STRINGP (string
) && nchars
>= 0);
1516 if (STRING_MULTIBYTE (string
))
1518 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1519 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1524 string_char_and_length (p
, rest
, &len
);
1525 p
+= len
, rest
-= len
;
1526 xassert (rest
>= 0);
1528 BYTEPOS (pos
) += len
;
1532 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1538 /* Value is the text position, i.e. character and byte position,
1539 for character position CHARPOS in STRING. */
1541 static INLINE
struct text_pos
1542 string_pos (charpos
, string
)
1546 struct text_pos pos
;
1547 xassert (STRINGP (string
));
1548 xassert (charpos
>= 0);
1549 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1554 /* Value is a text position, i.e. character and byte position, for
1555 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1556 means recognize multibyte characters. */
1558 static struct text_pos
1559 c_string_pos (charpos
, s
, multibyte_p
)
1564 struct text_pos pos
;
1566 xassert (s
!= NULL
);
1567 xassert (charpos
>= 0);
1571 int rest
= strlen (s
), len
;
1573 SET_TEXT_POS (pos
, 0, 0);
1576 string_char_and_length (s
, rest
, &len
);
1577 s
+= len
, rest
-= len
;
1578 xassert (rest
>= 0);
1580 BYTEPOS (pos
) += len
;
1584 SET_TEXT_POS (pos
, charpos
, charpos
);
1590 /* Value is the number of characters in C string S. MULTIBYTE_P
1591 non-zero means recognize multibyte characters. */
1594 number_of_chars (s
, multibyte_p
)
1602 int rest
= strlen (s
), len
;
1603 unsigned char *p
= (unsigned char *) s
;
1605 for (nchars
= 0; rest
> 0; ++nchars
)
1607 string_char_and_length (p
, rest
, &len
);
1608 rest
-= len
, p
+= len
;
1612 nchars
= strlen (s
);
1618 /* Compute byte position NEWPOS->bytepos corresponding to
1619 NEWPOS->charpos. POS is a known position in string STRING.
1620 NEWPOS->charpos must be >= POS.charpos. */
1623 compute_string_pos (newpos
, pos
, string
)
1624 struct text_pos
*newpos
, pos
;
1627 xassert (STRINGP (string
));
1628 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1630 if (STRING_MULTIBYTE (string
))
1631 *newpos
= string_pos_nchars_ahead (pos
, string
,
1632 CHARPOS (*newpos
) - CHARPOS (pos
));
1634 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1638 Return an estimation of the pixel height of mode or top lines on
1639 frame F. FACE_ID specifies what line's height to estimate. */
1642 estimate_mode_line_height (f
, face_id
)
1644 enum face_id face_id
;
1646 #ifdef HAVE_WINDOW_SYSTEM
1647 if (FRAME_WINDOW_P (f
))
1649 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1651 /* This function is called so early when Emacs starts that the face
1652 cache and mode line face are not yet initialized. */
1653 if (FRAME_FACE_CACHE (f
))
1655 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1659 height
= FONT_HEIGHT (face
->font
);
1660 if (face
->box_line_width
> 0)
1661 height
+= 2 * face
->box_line_width
;
1672 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1673 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1674 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1675 not force the value into range. */
1678 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1680 register int pix_x
, pix_y
;
1682 NativeRectangle
*bounds
;
1686 #ifdef HAVE_WINDOW_SYSTEM
1687 if (FRAME_WINDOW_P (f
))
1689 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1690 even for negative values. */
1692 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1694 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1696 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1697 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1700 STORE_NATIVE_RECT (*bounds
,
1701 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1702 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1703 FRAME_COLUMN_WIDTH (f
) - 1,
1704 FRAME_LINE_HEIGHT (f
) - 1);
1710 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1711 pix_x
= FRAME_TOTAL_COLS (f
);
1715 else if (pix_y
> FRAME_LINES (f
))
1716 pix_y
= FRAME_LINES (f
);
1726 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1727 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1728 can't tell the positions because W's display is not up to date,
1732 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1735 int *frame_x
, *frame_y
;
1737 #ifdef HAVE_WINDOW_SYSTEM
1738 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1742 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1743 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1745 if (display_completed
)
1747 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1748 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1749 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1755 hpos
+= glyph
->pixel_width
;
1759 /* If first glyph is partially visible, its first visible position is still 0. */
1771 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1772 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1783 #ifdef HAVE_WINDOW_SYSTEM
1785 /* Find the glyph under window-relative coordinates X/Y in window W.
1786 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1787 strings. Return in *HPOS and *VPOS the row and column number of
1788 the glyph found. Return in *AREA the glyph area containing X.
1789 Value is a pointer to the glyph found or null if X/Y is not on
1790 text, or we can't tell because W's current matrix is not up to
1795 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1798 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1800 struct glyph
*glyph
, *end
;
1801 struct glyph_row
*row
= NULL
;
1804 /* Find row containing Y. Give up if some row is not enabled. */
1805 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1807 row
= MATRIX_ROW (w
->current_matrix
, i
);
1808 if (!row
->enabled_p
)
1810 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1817 /* Give up if Y is not in the window. */
1818 if (i
== w
->current_matrix
->nrows
)
1821 /* Get the glyph area containing X. */
1822 if (w
->pseudo_window_p
)
1829 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1831 *area
= LEFT_MARGIN_AREA
;
1832 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1834 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1837 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1841 *area
= RIGHT_MARGIN_AREA
;
1842 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1846 /* Find glyph containing X. */
1847 glyph
= row
->glyphs
[*area
];
1848 end
= glyph
+ row
->used
[*area
];
1850 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1852 x
-= glyph
->pixel_width
;
1862 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1865 *hpos
= glyph
- row
->glyphs
[*area
];
1871 Convert frame-relative x/y to coordinates relative to window W.
1872 Takes pseudo-windows into account. */
1875 frame_to_window_pixel_xy (w
, x
, y
)
1879 if (w
->pseudo_window_p
)
1881 /* A pseudo-window is always full-width, and starts at the
1882 left edge of the frame, plus a frame border. */
1883 struct frame
*f
= XFRAME (w
->frame
);
1884 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1885 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1889 *x
-= WINDOW_LEFT_EDGE_X (w
);
1890 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1895 Return in RECTS[] at most N clipping rectangles for glyph string S.
1896 Return the number of stored rectangles. */
1899 get_glyph_string_clip_rects (s
, rects
, n
)
1900 struct glyph_string
*s
;
1901 NativeRectangle
*rects
;
1909 if (s
->row
->full_width_p
)
1911 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1912 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1913 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1915 /* Unless displaying a mode or menu bar line, which are always
1916 fully visible, clip to the visible part of the row. */
1917 if (s
->w
->pseudo_window_p
)
1918 r
.height
= s
->row
->visible_height
;
1920 r
.height
= s
->height
;
1924 /* This is a text line that may be partially visible. */
1925 r
.x
= window_box_left (s
->w
, s
->area
);
1926 r
.width
= window_box_width (s
->w
, s
->area
);
1927 r
.height
= s
->row
->visible_height
;
1931 if (r
.x
< s
->clip_head
->x
)
1933 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1934 r
.width
-= s
->clip_head
->x
- r
.x
;
1937 r
.x
= s
->clip_head
->x
;
1940 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1942 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1943 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1948 /* If S draws overlapping rows, it's sufficient to use the top and
1949 bottom of the window for clipping because this glyph string
1950 intentionally draws over other lines. */
1951 if (s
->for_overlaps
)
1953 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1954 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1956 /* Alas, the above simple strategy does not work for the
1957 environments with anti-aliased text: if the same text is
1958 drawn onto the same place multiple times, it gets thicker.
1959 If the overlap we are processing is for the erased cursor, we
1960 take the intersection with the rectagle of the cursor. */
1961 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1963 XRectangle rc
, r_save
= r
;
1965 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1966 rc
.y
= s
->w
->phys_cursor
.y
;
1967 rc
.width
= s
->w
->phys_cursor_width
;
1968 rc
.height
= s
->w
->phys_cursor_height
;
1970 x_intersect_rectangles (&r_save
, &rc
, &r
);
1975 /* Don't use S->y for clipping because it doesn't take partially
1976 visible lines into account. For example, it can be negative for
1977 partially visible lines at the top of a window. */
1978 if (!s
->row
->full_width_p
1979 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1980 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1982 r
.y
= max (0, s
->row
->y
);
1984 /* If drawing a tool-bar window, draw it over the internal border
1985 at the top of the window. */
1986 if (WINDOWP (s
->f
->tool_bar_window
)
1987 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1988 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1991 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1993 /* If drawing the cursor, don't let glyph draw outside its
1994 advertised boundaries. Cleartype does this under some circumstances. */
1995 if (s
->hl
== DRAW_CURSOR
)
1997 struct glyph
*glyph
= s
->first_glyph
;
2002 r
.width
-= s
->x
- r
.x
;
2005 r
.width
= min (r
.width
, glyph
->pixel_width
);
2007 /* If r.y is below window bottom, ensure that we still see a cursor. */
2008 height
= min (glyph
->ascent
+ glyph
->descent
,
2009 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2010 max_y
= window_text_bottom_y (s
->w
) - height
;
2011 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2012 if (s
->ybase
- glyph
->ascent
> max_y
)
2019 /* Don't draw cursor glyph taller than our actual glyph. */
2020 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2021 if (height
< r
.height
)
2023 max_y
= r
.y
+ r
.height
;
2024 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2025 r
.height
= min (max_y
- r
.y
, height
);
2032 XRectangle r_save
= r
;
2034 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2038 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2039 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2041 #ifdef CONVERT_FROM_XRECT
2042 CONVERT_FROM_XRECT (r
, *rects
);
2050 /* If we are processing overlapping and allowed to return
2051 multiple clipping rectangles, we exclude the row of the glyph
2052 string from the clipping rectangle. This is to avoid drawing
2053 the same text on the environment with anti-aliasing. */
2054 #ifdef CONVERT_FROM_XRECT
2057 XRectangle
*rs
= rects
;
2059 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2061 if (s
->for_overlaps
& OVERLAPS_PRED
)
2064 if (r
.y
+ r
.height
> row_y
)
2067 rs
[i
].height
= row_y
- r
.y
;
2073 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2076 if (r
.y
< row_y
+ s
->row
->visible_height
)
2078 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2080 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2081 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2090 #ifdef CONVERT_FROM_XRECT
2091 for (i
= 0; i
< n
; i
++)
2092 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2099 Return in *NR the clipping rectangle for glyph string S. */
2102 get_glyph_string_clip_rect (s
, nr
)
2103 struct glyph_string
*s
;
2104 NativeRectangle
*nr
;
2106 get_glyph_string_clip_rects (s
, nr
, 1);
2111 Return the position and height of the phys cursor in window W.
2112 Set w->phys_cursor_width to width of phys cursor.
2116 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2118 struct glyph_row
*row
;
2119 struct glyph
*glyph
;
2120 int *xp
, *yp
, *heightp
;
2122 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2123 int x
, y
, wd
, h
, h0
, y0
;
2125 /* Compute the width of the rectangle to draw. If on a stretch
2126 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2127 rectangle as wide as the glyph, but use a canonical character
2129 wd
= glyph
->pixel_width
- 1;
2130 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2134 x
= w
->phys_cursor
.x
;
2141 if (glyph
->type
== STRETCH_GLYPH
2142 && !x_stretch_cursor_p
)
2143 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2144 w
->phys_cursor_width
= wd
;
2146 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2148 /* If y is below window bottom, ensure that we still see a cursor. */
2149 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2151 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2152 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2154 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2157 h
= max (h
- (y0
- y
) + 1, h0
);
2162 y0
= window_text_bottom_y (w
) - h0
;
2170 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2171 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2176 * Remember which glyph the mouse is over.
2180 remember_mouse_glyph (f
, gx
, gy
, rect
)
2183 NativeRectangle
*rect
;
2187 struct glyph_row
*r
, *gr
, *end_row
;
2188 enum window_part part
;
2189 enum glyph_row_area area
;
2190 int x
, y
, width
, height
;
2192 /* Try to determine frame pixel position and size of the glyph under
2193 frame pixel coordinates X/Y on frame F. */
2195 if (!f
->glyphs_initialized_p
2196 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2199 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2200 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2204 w
= XWINDOW (window
);
2205 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2206 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2208 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2209 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2211 if (w
->pseudo_window_p
)
2214 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2220 case ON_LEFT_MARGIN
:
2221 area
= LEFT_MARGIN_AREA
;
2224 case ON_RIGHT_MARGIN
:
2225 area
= RIGHT_MARGIN_AREA
;
2228 case ON_HEADER_LINE
:
2230 gr
= (part
== ON_HEADER_LINE
2231 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2232 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2235 goto text_glyph_row_found
;
2242 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2243 if (r
->y
+ r
->height
> y
)
2249 text_glyph_row_found
:
2252 struct glyph
*g
= gr
->glyphs
[area
];
2253 struct glyph
*end
= g
+ gr
->used
[area
];
2255 height
= gr
->height
;
2256 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2257 if (gx
+ g
->pixel_width
> x
)
2262 if (g
->type
== IMAGE_GLYPH
)
2264 /* Don't remember when mouse is over image, as
2265 image may have hot-spots. */
2266 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2269 width
= g
->pixel_width
;
2273 /* Use nominal char spacing at end of line. */
2275 gx
+= (x
/ width
) * width
;
2278 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2279 gx
+= window_box_left_offset (w
, area
);
2283 /* Use nominal line height at end of window. */
2284 gx
= (x
/ width
) * width
;
2286 gy
+= (y
/ height
) * height
;
2290 case ON_LEFT_FRINGE
:
2291 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2292 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2293 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2294 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2297 case ON_RIGHT_FRINGE
:
2298 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2299 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2300 : window_box_right_offset (w
, TEXT_AREA
));
2301 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2305 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2307 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2308 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2309 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2311 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2315 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2316 if (r
->y
+ r
->height
> y
)
2323 height
= gr
->height
;
2326 /* Use nominal line height at end of window. */
2328 gy
+= (y
/ height
) * height
;
2335 /* If there is no glyph under the mouse, then we divide the screen
2336 into a grid of the smallest glyph in the frame, and use that
2339 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2340 round down even for negative values. */
2346 gx
= (gx
/ width
) * width
;
2347 gy
= (gy
/ height
) * height
;
2352 gx
+= WINDOW_LEFT_EDGE_X (w
);
2353 gy
+= WINDOW_TOP_EDGE_Y (w
);
2356 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2358 /* Visible feedback for debugging. */
2361 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2362 f
->output_data
.x
->normal_gc
,
2363 gx
, gy
, width
, height
);
2369 #endif /* HAVE_WINDOW_SYSTEM */
2372 /***********************************************************************
2373 Lisp form evaluation
2374 ***********************************************************************/
2376 /* Error handler for safe_eval and safe_call. */
2379 safe_eval_handler (arg
)
2382 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2387 /* Evaluate SEXPR and return the result, or nil if something went
2388 wrong. Prevent redisplay during the evaluation. */
2390 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2391 Return the result, or nil if something went wrong. Prevent
2392 redisplay during the evaluation. */
2395 safe_call (nargs
, args
)
2401 if (inhibit_eval_during_redisplay
)
2405 int count
= SPECPDL_INDEX ();
2406 struct gcpro gcpro1
;
2409 gcpro1
.nvars
= nargs
;
2410 specbind (Qinhibit_redisplay
, Qt
);
2411 /* Use Qt to ensure debugger does not run,
2412 so there is no possibility of wanting to redisplay. */
2413 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2416 val
= unbind_to (count
, val
);
2423 /* Call function FN with one argument ARG.
2424 Return the result, or nil if something went wrong. */
2427 safe_call1 (fn
, arg
)
2428 Lisp_Object fn
, arg
;
2430 Lisp_Object args
[2];
2433 return safe_call (2, args
);
2436 static Lisp_Object Qeval
;
2439 safe_eval (Lisp_Object sexpr
)
2441 return safe_call1 (Qeval
, sexpr
);
2444 /* Call function FN with one argument ARG.
2445 Return the result, or nil if something went wrong. */
2448 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2450 Lisp_Object args
[3];
2454 return safe_call (3, args
);
2459 /***********************************************************************
2461 ***********************************************************************/
2465 /* Define CHECK_IT to perform sanity checks on iterators.
2466 This is for debugging. It is too slow to do unconditionally. */
2472 if (it
->method
== GET_FROM_STRING
)
2474 xassert (STRINGP (it
->string
));
2475 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2479 xassert (IT_STRING_CHARPOS (*it
) < 0);
2480 if (it
->method
== GET_FROM_BUFFER
)
2482 /* Check that character and byte positions agree. */
2483 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2488 xassert (it
->current
.dpvec_index
>= 0);
2490 xassert (it
->current
.dpvec_index
< 0);
2493 #define CHECK_IT(IT) check_it ((IT))
2497 #define CHECK_IT(IT) (void) 0
2504 /* Check that the window end of window W is what we expect it
2505 to be---the last row in the current matrix displaying text. */
2508 check_window_end (w
)
2511 if (!MINI_WINDOW_P (w
)
2512 && !NILP (w
->window_end_valid
))
2514 struct glyph_row
*row
;
2515 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2516 XFASTINT (w
->window_end_vpos
)),
2518 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2519 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2523 #define CHECK_WINDOW_END(W) check_window_end ((W))
2525 #else /* not GLYPH_DEBUG */
2527 #define CHECK_WINDOW_END(W) (void) 0
2529 #endif /* not GLYPH_DEBUG */
2533 /***********************************************************************
2534 Iterator initialization
2535 ***********************************************************************/
2537 /* Initialize IT for displaying current_buffer in window W, starting
2538 at character position CHARPOS. CHARPOS < 0 means that no buffer
2539 position is specified which is useful when the iterator is assigned
2540 a position later. BYTEPOS is the byte position corresponding to
2541 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2543 If ROW is not null, calls to produce_glyphs with IT as parameter
2544 will produce glyphs in that row.
2546 BASE_FACE_ID is the id of a base face to use. It must be one of
2547 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2548 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2549 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2551 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2552 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2553 will be initialized to use the corresponding mode line glyph row of
2554 the desired matrix of W. */
2557 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2560 int charpos
, bytepos
;
2561 struct glyph_row
*row
;
2562 enum face_id base_face_id
;
2564 int highlight_region_p
;
2565 enum face_id remapped_base_face_id
= base_face_id
;
2567 /* Some precondition checks. */
2568 xassert (w
!= NULL
&& it
!= NULL
);
2569 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2572 /* If face attributes have been changed since the last redisplay,
2573 free realized faces now because they depend on face definitions
2574 that might have changed. Don't free faces while there might be
2575 desired matrices pending which reference these faces. */
2576 if (face_change_count
&& !inhibit_free_realized_faces
)
2578 face_change_count
= 0;
2579 free_all_realized_faces (Qnil
);
2582 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2583 if (! NILP (Vface_remapping_alist
))
2584 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2586 /* Use one of the mode line rows of W's desired matrix if
2590 if (base_face_id
== MODE_LINE_FACE_ID
2591 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2592 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2593 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2594 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2598 bzero (it
, sizeof *it
);
2599 it
->current
.overlay_string_index
= -1;
2600 it
->current
.dpvec_index
= -1;
2601 it
->base_face_id
= remapped_base_face_id
;
2603 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2605 /* The window in which we iterate over current_buffer: */
2606 XSETWINDOW (it
->window
, w
);
2608 it
->f
= XFRAME (w
->frame
);
2612 /* Extra space between lines (on window systems only). */
2613 if (base_face_id
== DEFAULT_FACE_ID
2614 && FRAME_WINDOW_P (it
->f
))
2616 if (NATNUMP (current_buffer
->extra_line_spacing
))
2617 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2618 else if (FLOATP (current_buffer
->extra_line_spacing
))
2619 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2620 * FRAME_LINE_HEIGHT (it
->f
));
2621 else if (it
->f
->extra_line_spacing
> 0)
2622 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2623 it
->max_extra_line_spacing
= 0;
2626 /* If realized faces have been removed, e.g. because of face
2627 attribute changes of named faces, recompute them. When running
2628 in batch mode, the face cache of the initial frame is null. If
2629 we happen to get called, make a dummy face cache. */
2630 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2631 init_frame_faces (it
->f
);
2632 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2633 recompute_basic_faces (it
->f
);
2635 /* Current value of the `slice', `space-width', and 'height' properties. */
2636 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2637 it
->space_width
= Qnil
;
2638 it
->font_height
= Qnil
;
2639 it
->override_ascent
= -1;
2641 /* Are control characters displayed as `^C'? */
2642 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2644 /* -1 means everything between a CR and the following line end
2645 is invisible. >0 means lines indented more than this value are
2647 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2648 ? XFASTINT (current_buffer
->selective_display
)
2649 : (!NILP (current_buffer
->selective_display
)
2651 it
->selective_display_ellipsis_p
2652 = !NILP (current_buffer
->selective_display_ellipses
);
2654 /* Display table to use. */
2655 it
->dp
= window_display_table (w
);
2657 /* Are multibyte characters enabled in current_buffer? */
2658 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2660 /* Non-zero if we should highlight the region. */
2662 = (!NILP (Vtransient_mark_mode
)
2663 && !NILP (current_buffer
->mark_active
)
2664 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2666 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2667 start and end of a visible region in window IT->w. Set both to
2668 -1 to indicate no region. */
2669 if (highlight_region_p
2670 /* Maybe highlight only in selected window. */
2671 && (/* Either show region everywhere. */
2672 highlight_nonselected_windows
2673 /* Or show region in the selected window. */
2674 || w
== XWINDOW (selected_window
)
2675 /* Or show the region if we are in the mini-buffer and W is
2676 the window the mini-buffer refers to. */
2677 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2678 && WINDOWP (minibuf_selected_window
)
2679 && w
== XWINDOW (minibuf_selected_window
))))
2681 int charpos
= marker_position (current_buffer
->mark
);
2682 it
->region_beg_charpos
= min (PT
, charpos
);
2683 it
->region_end_charpos
= max (PT
, charpos
);
2686 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2688 /* Get the position at which the redisplay_end_trigger hook should
2689 be run, if it is to be run at all. */
2690 if (MARKERP (w
->redisplay_end_trigger
)
2691 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2692 it
->redisplay_end_trigger_charpos
2693 = marker_position (w
->redisplay_end_trigger
);
2694 else if (INTEGERP (w
->redisplay_end_trigger
))
2695 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2697 /* Correct bogus values of tab_width. */
2698 it
->tab_width
= XINT (current_buffer
->tab_width
);
2699 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2702 /* Are lines in the display truncated? */
2703 if (base_face_id
!= DEFAULT_FACE_ID
2704 || XINT (it
->w
->hscroll
)
2705 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2706 && ((!NILP (Vtruncate_partial_width_windows
)
2707 && !INTEGERP (Vtruncate_partial_width_windows
))
2708 || (INTEGERP (Vtruncate_partial_width_windows
)
2709 && (WINDOW_TOTAL_COLS (it
->w
)
2710 < XINT (Vtruncate_partial_width_windows
))))))
2711 it
->line_wrap
= TRUNCATE
;
2712 else if (NILP (current_buffer
->truncate_lines
))
2713 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2714 ? WINDOW_WRAP
: WORD_WRAP
;
2716 it
->line_wrap
= TRUNCATE
;
2718 /* Get dimensions of truncation and continuation glyphs. These are
2719 displayed as fringe bitmaps under X, so we don't need them for such
2721 if (!FRAME_WINDOW_P (it
->f
))
2723 if (it
->line_wrap
== TRUNCATE
)
2725 /* We will need the truncation glyph. */
2726 xassert (it
->glyph_row
== NULL
);
2727 produce_special_glyphs (it
, IT_TRUNCATION
);
2728 it
->truncation_pixel_width
= it
->pixel_width
;
2732 /* We will need the continuation glyph. */
2733 xassert (it
->glyph_row
== NULL
);
2734 produce_special_glyphs (it
, IT_CONTINUATION
);
2735 it
->continuation_pixel_width
= it
->pixel_width
;
2738 /* Reset these values to zero because the produce_special_glyphs
2739 above has changed them. */
2740 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2741 it
->phys_ascent
= it
->phys_descent
= 0;
2744 /* Set this after getting the dimensions of truncation and
2745 continuation glyphs, so that we don't produce glyphs when calling
2746 produce_special_glyphs, above. */
2747 it
->glyph_row
= row
;
2748 it
->area
= TEXT_AREA
;
2750 /* Get the dimensions of the display area. The display area
2751 consists of the visible window area plus a horizontally scrolled
2752 part to the left of the window. All x-values are relative to the
2753 start of this total display area. */
2754 if (base_face_id
!= DEFAULT_FACE_ID
)
2756 /* Mode lines, menu bar in terminal frames. */
2757 it
->first_visible_x
= 0;
2758 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2763 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2764 it
->last_visible_x
= (it
->first_visible_x
2765 + window_box_width (w
, TEXT_AREA
));
2767 /* If we truncate lines, leave room for the truncator glyph(s) at
2768 the right margin. Otherwise, leave room for the continuation
2769 glyph(s). Truncation and continuation glyphs are not inserted
2770 for window-based redisplay. */
2771 if (!FRAME_WINDOW_P (it
->f
))
2773 if (it
->line_wrap
== TRUNCATE
)
2774 it
->last_visible_x
-= it
->truncation_pixel_width
;
2776 it
->last_visible_x
-= it
->continuation_pixel_width
;
2779 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2780 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2783 /* Leave room for a border glyph. */
2784 if (!FRAME_WINDOW_P (it
->f
)
2785 && !WINDOW_RIGHTMOST_P (it
->w
))
2786 it
->last_visible_x
-= 1;
2788 it
->last_visible_y
= window_text_bottom_y (w
);
2790 /* For mode lines and alike, arrange for the first glyph having a
2791 left box line if the face specifies a box. */
2792 if (base_face_id
!= DEFAULT_FACE_ID
)
2796 it
->face_id
= remapped_base_face_id
;
2798 /* If we have a boxed mode line, make the first character appear
2799 with a left box line. */
2800 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2801 if (face
->box
!= FACE_NO_BOX
)
2802 it
->start_of_box_run_p
= 1;
2805 /* If a buffer position was specified, set the iterator there,
2806 getting overlays and face properties from that position. */
2807 if (charpos
>= BUF_BEG (current_buffer
))
2809 it
->end_charpos
= ZV
;
2811 IT_CHARPOS (*it
) = charpos
;
2813 /* Compute byte position if not specified. */
2814 if (bytepos
< charpos
)
2815 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2817 IT_BYTEPOS (*it
) = bytepos
;
2819 it
->start
= it
->current
;
2821 /* Compute faces etc. */
2822 reseat (it
, it
->current
.pos
, 1);
2829 /* Initialize IT for the display of window W with window start POS. */
2832 start_display (it
, w
, pos
)
2835 struct text_pos pos
;
2837 struct glyph_row
*row
;
2838 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2840 row
= w
->desired_matrix
->rows
+ first_vpos
;
2841 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2842 it
->first_vpos
= first_vpos
;
2844 /* Don't reseat to previous visible line start if current start
2845 position is in a string or image. */
2846 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2848 int start_at_line_beg_p
;
2849 int first_y
= it
->current_y
;
2851 /* If window start is not at a line start, skip forward to POS to
2852 get the correct continuation lines width. */
2853 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2854 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2855 if (!start_at_line_beg_p
)
2859 reseat_at_previous_visible_line_start (it
);
2860 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2862 new_x
= it
->current_x
+ it
->pixel_width
;
2864 /* If lines are continued, this line may end in the middle
2865 of a multi-glyph character (e.g. a control character
2866 displayed as \003, or in the middle of an overlay
2867 string). In this case move_it_to above will not have
2868 taken us to the start of the continuation line but to the
2869 end of the continued line. */
2870 if (it
->current_x
> 0
2871 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2872 && (/* And glyph doesn't fit on the line. */
2873 new_x
> it
->last_visible_x
2874 /* Or it fits exactly and we're on a window
2876 || (new_x
== it
->last_visible_x
2877 && FRAME_WINDOW_P (it
->f
))))
2879 if (it
->current
.dpvec_index
>= 0
2880 || it
->current
.overlay_string_index
>= 0)
2882 set_iterator_to_next (it
, 1);
2883 move_it_in_display_line_to (it
, -1, -1, 0);
2886 it
->continuation_lines_width
+= it
->current_x
;
2889 /* We're starting a new display line, not affected by the
2890 height of the continued line, so clear the appropriate
2891 fields in the iterator structure. */
2892 it
->max_ascent
= it
->max_descent
= 0;
2893 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2895 it
->current_y
= first_y
;
2897 it
->current_x
= it
->hpos
= 0;
2903 /* Return 1 if POS is a position in ellipses displayed for invisible
2904 text. W is the window we display, for text property lookup. */
2907 in_ellipses_for_invisible_text_p (pos
, w
)
2908 struct display_pos
*pos
;
2911 Lisp_Object prop
, window
;
2913 int charpos
= CHARPOS (pos
->pos
);
2915 /* If POS specifies a position in a display vector, this might
2916 be for an ellipsis displayed for invisible text. We won't
2917 get the iterator set up for delivering that ellipsis unless
2918 we make sure that it gets aware of the invisible text. */
2919 if (pos
->dpvec_index
>= 0
2920 && pos
->overlay_string_index
< 0
2921 && CHARPOS (pos
->string_pos
) < 0
2923 && (XSETWINDOW (window
, w
),
2924 prop
= Fget_char_property (make_number (charpos
),
2925 Qinvisible
, window
),
2926 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2928 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2930 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2937 /* Initialize IT for stepping through current_buffer in window W,
2938 starting at position POS that includes overlay string and display
2939 vector/ control character translation position information. Value
2940 is zero if there are overlay strings with newlines at POS. */
2943 init_from_display_pos (it
, w
, pos
)
2946 struct display_pos
*pos
;
2948 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2949 int i
, overlay_strings_with_newlines
= 0;
2951 /* If POS specifies a position in a display vector, this might
2952 be for an ellipsis displayed for invisible text. We won't
2953 get the iterator set up for delivering that ellipsis unless
2954 we make sure that it gets aware of the invisible text. */
2955 if (in_ellipses_for_invisible_text_p (pos
, w
))
2961 /* Keep in mind: the call to reseat in init_iterator skips invisible
2962 text, so we might end up at a position different from POS. This
2963 is only a problem when POS is a row start after a newline and an
2964 overlay starts there with an after-string, and the overlay has an
2965 invisible property. Since we don't skip invisible text in
2966 display_line and elsewhere immediately after consuming the
2967 newline before the row start, such a POS will not be in a string,
2968 but the call to init_iterator below will move us to the
2970 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2972 /* This only scans the current chunk -- it should scan all chunks.
2973 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2974 to 16 in 22.1 to make this a lesser problem. */
2975 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2977 const char *s
= SDATA (it
->overlay_strings
[i
]);
2978 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2980 while (s
< e
&& *s
!= '\n')
2985 overlay_strings_with_newlines
= 1;
2990 /* If position is within an overlay string, set up IT to the right
2992 if (pos
->overlay_string_index
>= 0)
2996 /* If the first overlay string happens to have a `display'
2997 property for an image, the iterator will be set up for that
2998 image, and we have to undo that setup first before we can
2999 correct the overlay string index. */
3000 if (it
->method
== GET_FROM_IMAGE
)
3003 /* We already have the first chunk of overlay strings in
3004 IT->overlay_strings. Load more until the one for
3005 pos->overlay_string_index is in IT->overlay_strings. */
3006 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3008 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3009 it
->current
.overlay_string_index
= 0;
3012 load_overlay_strings (it
, 0);
3013 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3017 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3018 relative_index
= (it
->current
.overlay_string_index
3019 % OVERLAY_STRING_CHUNK_SIZE
);
3020 it
->string
= it
->overlay_strings
[relative_index
];
3021 xassert (STRINGP (it
->string
));
3022 it
->current
.string_pos
= pos
->string_pos
;
3023 it
->method
= GET_FROM_STRING
;
3026 if (CHARPOS (pos
->string_pos
) >= 0)
3028 /* Recorded position is not in an overlay string, but in another
3029 string. This can only be a string from a `display' property.
3030 IT should already be filled with that string. */
3031 it
->current
.string_pos
= pos
->string_pos
;
3032 xassert (STRINGP (it
->string
));
3035 /* Restore position in display vector translations, control
3036 character translations or ellipses. */
3037 if (pos
->dpvec_index
>= 0)
3039 if (it
->dpvec
== NULL
)
3040 get_next_display_element (it
);
3041 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3042 it
->current
.dpvec_index
= pos
->dpvec_index
;
3046 return !overlay_strings_with_newlines
;
3050 /* Initialize IT for stepping through current_buffer in window W
3051 starting at ROW->start. */
3054 init_to_row_start (it
, w
, row
)
3057 struct glyph_row
*row
;
3059 init_from_display_pos (it
, w
, &row
->start
);
3060 it
->start
= row
->start
;
3061 it
->continuation_lines_width
= row
->continuation_lines_width
;
3066 /* Initialize IT for stepping through current_buffer in window W
3067 starting in the line following ROW, i.e. starting at ROW->end.
3068 Value is zero if there are overlay strings with newlines at ROW's
3072 init_to_row_end (it
, w
, row
)
3075 struct glyph_row
*row
;
3079 if (init_from_display_pos (it
, w
, &row
->end
))
3081 if (row
->continued_p
)
3082 it
->continuation_lines_width
3083 = row
->continuation_lines_width
+ row
->pixel_width
;
3094 /***********************************************************************
3096 ***********************************************************************/
3098 /* Called when IT reaches IT->stop_charpos. Handle text property and
3099 overlay changes. Set IT->stop_charpos to the next position where
3106 enum prop_handled handled
;
3107 int handle_overlay_change_p
;
3111 it
->current
.dpvec_index
= -1;
3112 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3113 it
->ignore_overlay_strings_at_pos_p
= 0;
3116 /* Use face of preceding text for ellipsis (if invisible) */
3117 if (it
->selective_display_ellipsis_p
)
3118 it
->saved_face_id
= it
->face_id
;
3122 handled
= HANDLED_NORMALLY
;
3124 /* Call text property handlers. */
3125 for (p
= it_props
; p
->handler
; ++p
)
3127 handled
= p
->handler (it
);
3129 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3131 else if (handled
== HANDLED_RETURN
)
3133 /* We still want to show before and after strings from
3134 overlays even if the actual buffer text is replaced. */
3135 if (!handle_overlay_change_p
3137 || !get_overlay_strings_1 (it
, 0, 0))
3140 setup_for_ellipsis (it
, 0);
3141 /* When handling a display spec, we might load an
3142 empty string. In that case, discard it here. We
3143 used to discard it in handle_single_display_spec,
3144 but that causes get_overlay_strings_1, above, to
3145 ignore overlay strings that we must check. */
3146 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3150 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3154 it
->ignore_overlay_strings_at_pos_p
= 1;
3155 it
->string_from_display_prop_p
= 0;
3156 handle_overlay_change_p
= 0;
3158 handled
= HANDLED_RECOMPUTE_PROPS
;
3161 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3162 handle_overlay_change_p
= 0;
3165 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3167 /* Don't check for overlay strings below when set to deliver
3168 characters from a display vector. */
3169 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3170 handle_overlay_change_p
= 0;
3172 /* Handle overlay changes.
3173 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3174 if it finds overlays. */
3175 if (handle_overlay_change_p
)
3176 handled
= handle_overlay_change (it
);
3181 setup_for_ellipsis (it
, 0);
3185 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3187 /* Determine where to stop next. */
3188 if (handled
== HANDLED_NORMALLY
)
3189 compute_stop_pos (it
);
3193 /* Compute IT->stop_charpos from text property and overlay change
3194 information for IT's current position. */
3197 compute_stop_pos (it
)
3200 register INTERVAL iv
, next_iv
;
3201 Lisp_Object object
, limit
, position
;
3202 EMACS_INT charpos
, bytepos
;
3204 /* If nowhere else, stop at the end. */
3205 it
->stop_charpos
= it
->end_charpos
;
3207 if (STRINGP (it
->string
))
3209 /* Strings are usually short, so don't limit the search for
3211 object
= it
->string
;
3213 charpos
= IT_STRING_CHARPOS (*it
);
3214 bytepos
= IT_STRING_BYTEPOS (*it
);
3220 /* If next overlay change is in front of the current stop pos
3221 (which is IT->end_charpos), stop there. Note: value of
3222 next_overlay_change is point-max if no overlay change
3224 charpos
= IT_CHARPOS (*it
);
3225 bytepos
= IT_BYTEPOS (*it
);
3226 pos
= next_overlay_change (charpos
);
3227 if (pos
< it
->stop_charpos
)
3228 it
->stop_charpos
= pos
;
3230 /* If showing the region, we have to stop at the region
3231 start or end because the face might change there. */
3232 if (it
->region_beg_charpos
> 0)
3234 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3235 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3236 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3237 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3240 /* Set up variables for computing the stop position from text
3241 property changes. */
3242 XSETBUFFER (object
, current_buffer
);
3243 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3246 /* Get the interval containing IT's position. Value is a null
3247 interval if there isn't such an interval. */
3248 position
= make_number (charpos
);
3249 iv
= validate_interval_range (object
, &position
, &position
, 0);
3250 if (!NULL_INTERVAL_P (iv
))
3252 Lisp_Object values_here
[LAST_PROP_IDX
];
3255 /* Get properties here. */
3256 for (p
= it_props
; p
->handler
; ++p
)
3257 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3259 /* Look for an interval following iv that has different
3261 for (next_iv
= next_interval (iv
);
3262 (!NULL_INTERVAL_P (next_iv
)
3264 || XFASTINT (limit
) > next_iv
->position
));
3265 next_iv
= next_interval (next_iv
))
3267 for (p
= it_props
; p
->handler
; ++p
)
3269 Lisp_Object new_value
;
3271 new_value
= textget (next_iv
->plist
, *p
->name
);
3272 if (!EQ (values_here
[p
->idx
], new_value
))
3280 if (!NULL_INTERVAL_P (next_iv
))
3282 if (INTEGERP (limit
)
3283 && next_iv
->position
>= XFASTINT (limit
))
3284 /* No text property change up to limit. */
3285 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3287 /* Text properties change in next_iv. */
3288 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3292 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3293 it
->stop_charpos
, it
->string
);
3295 xassert (STRINGP (it
->string
)
3296 || (it
->stop_charpos
>= BEGV
3297 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3301 /* Return the position of the next overlay change after POS in
3302 current_buffer. Value is point-max if no overlay change
3303 follows. This is like `next-overlay-change' but doesn't use
3307 next_overlay_change (pos
)
3312 Lisp_Object
*overlays
;
3315 /* Get all overlays at the given position. */
3316 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3318 /* If any of these overlays ends before endpos,
3319 use its ending point instead. */
3320 for (i
= 0; i
< noverlays
; ++i
)
3325 oend
= OVERLAY_END (overlays
[i
]);
3326 oendpos
= OVERLAY_POSITION (oend
);
3327 endpos
= min (endpos
, oendpos
);
3335 /***********************************************************************
3337 ***********************************************************************/
3339 /* Handle changes in the `fontified' property of the current buffer by
3340 calling hook functions from Qfontification_functions to fontify
3343 static enum prop_handled
3344 handle_fontified_prop (it
)
3347 Lisp_Object prop
, pos
;
3348 enum prop_handled handled
= HANDLED_NORMALLY
;
3350 if (!NILP (Vmemory_full
))
3353 /* Get the value of the `fontified' property at IT's current buffer
3354 position. (The `fontified' property doesn't have a special
3355 meaning in strings.) If the value is nil, call functions from
3356 Qfontification_functions. */
3357 if (!STRINGP (it
->string
)
3359 && !NILP (Vfontification_functions
)
3360 && !NILP (Vrun_hooks
)
3361 && (pos
= make_number (IT_CHARPOS (*it
)),
3362 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3363 /* Ignore the special cased nil value always present at EOB since
3364 no amount of fontifying will be able to change it. */
3365 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3367 int count
= SPECPDL_INDEX ();
3370 val
= Vfontification_functions
;
3371 specbind (Qfontification_functions
, Qnil
);
3373 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3374 safe_call1 (val
, pos
);
3377 Lisp_Object globals
, fn
;
3378 struct gcpro gcpro1
, gcpro2
;
3381 GCPRO2 (val
, globals
);
3383 for (; CONSP (val
); val
= XCDR (val
))
3389 /* A value of t indicates this hook has a local
3390 binding; it means to run the global binding too.
3391 In a global value, t should not occur. If it
3392 does, we must ignore it to avoid an endless
3394 for (globals
= Fdefault_value (Qfontification_functions
);
3396 globals
= XCDR (globals
))
3398 fn
= XCAR (globals
);
3400 safe_call1 (fn
, pos
);
3404 safe_call1 (fn
, pos
);
3410 unbind_to (count
, Qnil
);
3412 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3413 something. This avoids an endless loop if they failed to
3414 fontify the text for which reason ever. */
3415 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3416 handled
= HANDLED_RECOMPUTE_PROPS
;
3424 /***********************************************************************
3426 ***********************************************************************/
3428 /* Set up iterator IT from face properties at its current position.
3429 Called from handle_stop. */
3431 static enum prop_handled
3432 handle_face_prop (it
)
3436 EMACS_INT next_stop
;
3438 if (!STRINGP (it
->string
))
3441 = face_at_buffer_position (it
->w
,
3443 it
->region_beg_charpos
,
3444 it
->region_end_charpos
,
3447 + TEXT_PROP_DISTANCE_LIMIT
),
3448 0, it
->base_face_id
);
3450 /* Is this a start of a run of characters with box face?
3451 Caveat: this can be called for a freshly initialized
3452 iterator; face_id is -1 in this case. We know that the new
3453 face will not change until limit, i.e. if the new face has a
3454 box, all characters up to limit will have one. But, as
3455 usual, we don't know whether limit is really the end. */
3456 if (new_face_id
!= it
->face_id
)
3458 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3460 /* If new face has a box but old face has not, this is
3461 the start of a run of characters with box, i.e. it has
3462 a shadow on the left side. The value of face_id of the
3463 iterator will be -1 if this is the initial call that gets
3464 the face. In this case, we have to look in front of IT's
3465 position and see whether there is a face != new_face_id. */
3466 it
->start_of_box_run_p
3467 = (new_face
->box
!= FACE_NO_BOX
3468 && (it
->face_id
>= 0
3469 || IT_CHARPOS (*it
) == BEG
3470 || new_face_id
!= face_before_it_pos (it
)));
3471 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3476 int base_face_id
, bufpos
;
3478 Lisp_Object from_overlay
3479 = (it
->current
.overlay_string_index
>= 0
3480 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3483 /* See if we got to this string directly or indirectly from
3484 an overlay property. That includes the before-string or
3485 after-string of an overlay, strings in display properties
3486 provided by an overlay, their text properties, etc.
3488 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3489 if (! NILP (from_overlay
))
3490 for (i
= it
->sp
- 1; i
>= 0; i
--)
3492 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3494 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3495 else if (! NILP (it
->stack
[i
].from_overlay
))
3496 from_overlay
= it
->stack
[i
].from_overlay
;
3498 if (!NILP (from_overlay
))
3502 if (! NILP (from_overlay
))
3504 bufpos
= IT_CHARPOS (*it
);
3505 /* For a string from an overlay, the base face depends
3506 only on text properties and ignores overlays. */
3508 = face_for_overlay_string (it
->w
,
3510 it
->region_beg_charpos
,
3511 it
->region_end_charpos
,
3514 + TEXT_PROP_DISTANCE_LIMIT
),
3522 /* For strings from a `display' property, use the face at
3523 IT's current buffer position as the base face to merge
3524 with, so that overlay strings appear in the same face as
3525 surrounding text, unless they specify their own
3527 base_face_id
= underlying_face_id (it
);
3530 new_face_id
= face_at_string_position (it
->w
,
3532 IT_STRING_CHARPOS (*it
),
3534 it
->region_beg_charpos
,
3535 it
->region_end_charpos
,
3539 /* Is this a start of a run of characters with box? Caveat:
3540 this can be called for a freshly allocated iterator; face_id
3541 is -1 is this case. We know that the new face will not
3542 change until the next check pos, i.e. if the new face has a
3543 box, all characters up to that position will have a
3544 box. But, as usual, we don't know whether that position
3545 is really the end. */
3546 if (new_face_id
!= it
->face_id
)
3548 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3549 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3551 /* If new face has a box but old face hasn't, this is the
3552 start of a run of characters with box, i.e. it has a
3553 shadow on the left side. */
3554 it
->start_of_box_run_p
3555 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3556 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3560 it
->face_id
= new_face_id
;
3561 return HANDLED_NORMALLY
;
3565 /* Return the ID of the face ``underlying'' IT's current position,
3566 which is in a string. If the iterator is associated with a
3567 buffer, return the face at IT's current buffer position.
3568 Otherwise, use the iterator's base_face_id. */
3571 underlying_face_id (it
)
3574 int face_id
= it
->base_face_id
, i
;
3576 xassert (STRINGP (it
->string
));
3578 for (i
= it
->sp
- 1; i
>= 0; --i
)
3579 if (NILP (it
->stack
[i
].string
))
3580 face_id
= it
->stack
[i
].face_id
;
3586 /* Compute the face one character before or after the current position
3587 of IT. BEFORE_P non-zero means get the face in front of IT's
3588 position. Value is the id of the face. */
3591 face_before_or_after_it_pos (it
, before_p
)
3596 EMACS_INT next_check_charpos
;
3597 struct text_pos pos
;
3599 xassert (it
->s
== NULL
);
3601 if (STRINGP (it
->string
))
3603 int bufpos
, base_face_id
;
3605 /* No face change past the end of the string (for the case
3606 we are padding with spaces). No face change before the
3608 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3609 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3612 /* Set pos to the position before or after IT's current position. */
3614 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3616 /* For composition, we must check the character after the
3618 pos
= (it
->what
== IT_COMPOSITION
3619 ? string_pos (IT_STRING_CHARPOS (*it
)
3620 + it
->cmp_it
.nchars
, it
->string
)
3621 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3623 if (it
->current
.overlay_string_index
>= 0)
3624 bufpos
= IT_CHARPOS (*it
);
3628 base_face_id
= underlying_face_id (it
);
3630 /* Get the face for ASCII, or unibyte. */
3631 face_id
= face_at_string_position (it
->w
,
3635 it
->region_beg_charpos
,
3636 it
->region_end_charpos
,
3637 &next_check_charpos
,
3640 /* Correct the face for charsets different from ASCII. Do it
3641 for the multibyte case only. The face returned above is
3642 suitable for unibyte text if IT->string is unibyte. */
3643 if (STRING_MULTIBYTE (it
->string
))
3645 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3646 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3648 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3650 c
= string_char_and_length (p
, rest
, &len
);
3651 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3656 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3657 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3660 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3661 pos
= it
->current
.pos
;
3664 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3667 if (it
->what
== IT_COMPOSITION
)
3668 /* For composition, we must check the position after the
3670 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3672 INC_TEXT_POS (pos
, it
->multibyte_p
);
3675 /* Determine face for CHARSET_ASCII, or unibyte. */
3676 face_id
= face_at_buffer_position (it
->w
,
3678 it
->region_beg_charpos
,
3679 it
->region_end_charpos
,
3680 &next_check_charpos
,
3683 /* Correct the face for charsets different from ASCII. Do it
3684 for the multibyte case only. The face returned above is
3685 suitable for unibyte text if current_buffer is unibyte. */
3686 if (it
->multibyte_p
)
3688 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3689 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3690 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3699 /***********************************************************************
3701 ***********************************************************************/
3703 /* Set up iterator IT from invisible properties at its current
3704 position. Called from handle_stop. */
3706 static enum prop_handled
3707 handle_invisible_prop (it
)
3710 enum prop_handled handled
= HANDLED_NORMALLY
;
3712 if (STRINGP (it
->string
))
3714 extern Lisp_Object Qinvisible
;
3715 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3717 /* Get the value of the invisible text property at the
3718 current position. Value will be nil if there is no such
3720 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3721 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3724 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3726 handled
= HANDLED_RECOMPUTE_PROPS
;
3728 /* Get the position at which the next change of the
3729 invisible text property can be found in IT->string.
3730 Value will be nil if the property value is the same for
3731 all the rest of IT->string. */
3732 XSETINT (limit
, SCHARS (it
->string
));
3733 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3736 /* Text at current position is invisible. The next
3737 change in the property is at position end_charpos.
3738 Move IT's current position to that position. */
3739 if (INTEGERP (end_charpos
)
3740 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3742 struct text_pos old
;
3743 old
= it
->current
.string_pos
;
3744 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3745 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3749 /* The rest of the string is invisible. If this is an
3750 overlay string, proceed with the next overlay string
3751 or whatever comes and return a character from there. */
3752 if (it
->current
.overlay_string_index
>= 0)
3754 next_overlay_string (it
);
3755 /* Don't check for overlay strings when we just
3756 finished processing them. */
3757 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3761 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3762 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3770 EMACS_INT newpos
, next_stop
, start_charpos
;
3771 Lisp_Object pos
, prop
, overlay
;
3773 /* First of all, is there invisible text at this position? */
3774 start_charpos
= IT_CHARPOS (*it
);
3775 pos
= make_number (IT_CHARPOS (*it
));
3776 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3778 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3780 /* If we are on invisible text, skip over it. */
3781 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3783 /* Record whether we have to display an ellipsis for the
3785 int display_ellipsis_p
= invis_p
== 2;
3787 handled
= HANDLED_RECOMPUTE_PROPS
;
3789 /* Loop skipping over invisible text. The loop is left at
3790 ZV or with IT on the first char being visible again. */
3793 /* Try to skip some invisible text. Return value is the
3794 position reached which can be equal to IT's position
3795 if there is nothing invisible here. This skips both
3796 over invisible text properties and overlays with
3797 invisible property. */
3798 newpos
= skip_invisible (IT_CHARPOS (*it
),
3799 &next_stop
, ZV
, it
->window
);
3801 /* If we skipped nothing at all we weren't at invisible
3802 text in the first place. If everything to the end of
3803 the buffer was skipped, end the loop. */
3804 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3808 /* We skipped some characters but not necessarily
3809 all there are. Check if we ended up on visible
3810 text. Fget_char_property returns the property of
3811 the char before the given position, i.e. if we
3812 get invis_p = 0, this means that the char at
3813 newpos is visible. */
3814 pos
= make_number (newpos
);
3815 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3816 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3819 /* If we ended up on invisible text, proceed to
3820 skip starting with next_stop. */
3822 IT_CHARPOS (*it
) = next_stop
;
3824 /* If there are adjacent invisible texts, don't lose the
3825 second one's ellipsis. */
3827 display_ellipsis_p
= 1;
3831 /* The position newpos is now either ZV or on visible text. */
3832 IT_CHARPOS (*it
) = newpos
;
3833 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3835 /* If there are before-strings at the start of invisible
3836 text, and the text is invisible because of a text
3837 property, arrange to show before-strings because 20.x did
3838 it that way. (If the text is invisible because of an
3839 overlay property instead of a text property, this is
3840 already handled in the overlay code.) */
3842 && get_overlay_strings (it
, start_charpos
))
3844 handled
= HANDLED_RECOMPUTE_PROPS
;
3845 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3847 else if (display_ellipsis_p
)
3849 /* Make sure that the glyphs of the ellipsis will get
3850 correct `charpos' values. If we would not update
3851 it->position here, the glyphs would belong to the
3852 last visible character _before_ the invisible
3853 text, which confuses `set_cursor_from_row'.
3855 We use the last invisible position instead of the
3856 first because this way the cursor is always drawn on
3857 the first "." of the ellipsis, whenever PT is inside
3858 the invisible text. Otherwise the cursor would be
3859 placed _after_ the ellipsis when the point is after the
3860 first invisible character. */
3861 if (!STRINGP (it
->object
))
3863 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3864 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3867 /* Let the ellipsis display before
3868 considering any properties of the following char.
3869 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3870 handled
= HANDLED_RETURN
;
3879 /* Make iterator IT return `...' next.
3880 Replaces LEN characters from buffer. */
3883 setup_for_ellipsis (it
, len
)
3887 /* Use the display table definition for `...'. Invalid glyphs
3888 will be handled by the method returning elements from dpvec. */
3889 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3891 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3892 it
->dpvec
= v
->contents
;
3893 it
->dpend
= v
->contents
+ v
->size
;
3897 /* Default `...'. */
3898 it
->dpvec
= default_invis_vector
;
3899 it
->dpend
= default_invis_vector
+ 3;
3902 it
->dpvec_char_len
= len
;
3903 it
->current
.dpvec_index
= 0;
3904 it
->dpvec_face_id
= -1;
3906 /* Remember the current face id in case glyphs specify faces.
3907 IT's face is restored in set_iterator_to_next.
3908 saved_face_id was set to preceding char's face in handle_stop. */
3909 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3910 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3912 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3918 /***********************************************************************
3920 ***********************************************************************/
3922 /* Set up iterator IT from `display' property at its current position.
3923 Called from handle_stop.
3924 We return HANDLED_RETURN if some part of the display property
3925 overrides the display of the buffer text itself.
3926 Otherwise we return HANDLED_NORMALLY. */
3928 static enum prop_handled
3929 handle_display_prop (it
)
3932 Lisp_Object prop
, object
, overlay
;
3933 struct text_pos
*position
;
3934 /* Nonzero if some property replaces the display of the text itself. */
3935 int display_replaced_p
= 0;
3937 if (STRINGP (it
->string
))
3939 object
= it
->string
;
3940 position
= &it
->current
.string_pos
;
3944 XSETWINDOW (object
, it
->w
);
3945 position
= &it
->current
.pos
;
3948 /* Reset those iterator values set from display property values. */
3949 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3950 it
->space_width
= Qnil
;
3951 it
->font_height
= Qnil
;
3954 /* We don't support recursive `display' properties, i.e. string
3955 values that have a string `display' property, that have a string
3956 `display' property etc. */
3957 if (!it
->string_from_display_prop_p
)
3958 it
->area
= TEXT_AREA
;
3960 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3961 Qdisplay
, object
, &overlay
);
3963 return HANDLED_NORMALLY
;
3964 /* Now OVERLAY is the overlay that gave us this property, or nil
3965 if it was a text property. */
3967 if (!STRINGP (it
->string
))
3968 object
= it
->w
->buffer
;
3971 /* Simple properties. */
3972 && !EQ (XCAR (prop
), Qimage
)
3973 && !EQ (XCAR (prop
), Qspace
)
3974 && !EQ (XCAR (prop
), Qwhen
)
3975 && !EQ (XCAR (prop
), Qslice
)
3976 && !EQ (XCAR (prop
), Qspace_width
)
3977 && !EQ (XCAR (prop
), Qheight
)
3978 && !EQ (XCAR (prop
), Qraise
)
3979 /* Marginal area specifications. */
3980 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3981 && !EQ (XCAR (prop
), Qleft_fringe
)
3982 && !EQ (XCAR (prop
), Qright_fringe
)
3983 && !NILP (XCAR (prop
)))
3985 for (; CONSP (prop
); prop
= XCDR (prop
))
3987 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3988 position
, display_replaced_p
))
3990 display_replaced_p
= 1;
3991 /* If some text in a string is replaced, `position' no
3992 longer points to the position of `object'. */
3993 if (STRINGP (object
))
3998 else if (VECTORP (prop
))
4001 for (i
= 0; i
< ASIZE (prop
); ++i
)
4002 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4003 position
, display_replaced_p
))
4005 display_replaced_p
= 1;
4006 /* If some text in a string is replaced, `position' no
4007 longer points to the position of `object'. */
4008 if (STRINGP (object
))
4014 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4016 display_replaced_p
= 1;
4019 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4023 /* Value is the position of the end of the `display' property starting
4024 at START_POS in OBJECT. */
4026 static struct text_pos
4027 display_prop_end (it
, object
, start_pos
)
4030 struct text_pos start_pos
;
4033 struct text_pos end_pos
;
4035 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4036 Qdisplay
, object
, Qnil
);
4037 CHARPOS (end_pos
) = XFASTINT (end
);
4038 if (STRINGP (object
))
4039 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4041 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4047 /* Set up IT from a single `display' specification PROP. OBJECT
4048 is the object in which the `display' property was found. *POSITION
4049 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4050 means that we previously saw a display specification which already
4051 replaced text display with something else, for example an image;
4052 we ignore such properties after the first one has been processed.
4054 OVERLAY is the overlay this `display' property came from,
4055 or nil if it was a text property.
4057 If PROP is a `space' or `image' specification, and in some other
4058 cases too, set *POSITION to the position where the `display'
4061 Value is non-zero if something was found which replaces the display
4062 of buffer or string text. */
4065 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4066 display_replaced_before_p
)
4070 Lisp_Object overlay
;
4071 struct text_pos
*position
;
4072 int display_replaced_before_p
;
4075 Lisp_Object location
, value
;
4076 struct text_pos start_pos
, save_pos
;
4079 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4080 If the result is non-nil, use VALUE instead of SPEC. */
4082 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4091 if (!NILP (form
) && !EQ (form
, Qt
))
4093 int count
= SPECPDL_INDEX ();
4094 struct gcpro gcpro1
;
4096 /* Bind `object' to the object having the `display' property, a
4097 buffer or string. Bind `position' to the position in the
4098 object where the property was found, and `buffer-position'
4099 to the current position in the buffer. */
4100 specbind (Qobject
, object
);
4101 specbind (Qposition
, make_number (CHARPOS (*position
)));
4102 specbind (Qbuffer_position
,
4103 make_number (STRINGP (object
)
4104 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4106 form
= safe_eval (form
);
4108 unbind_to (count
, Qnil
);
4114 /* Handle `(height HEIGHT)' specifications. */
4116 && EQ (XCAR (spec
), Qheight
)
4117 && CONSP (XCDR (spec
)))
4119 if (!FRAME_WINDOW_P (it
->f
))
4122 it
->font_height
= XCAR (XCDR (spec
));
4123 if (!NILP (it
->font_height
))
4125 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4126 int new_height
= -1;
4128 if (CONSP (it
->font_height
)
4129 && (EQ (XCAR (it
->font_height
), Qplus
)
4130 || EQ (XCAR (it
->font_height
), Qminus
))
4131 && CONSP (XCDR (it
->font_height
))
4132 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4134 /* `(+ N)' or `(- N)' where N is an integer. */
4135 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4136 if (EQ (XCAR (it
->font_height
), Qplus
))
4138 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4140 else if (FUNCTIONP (it
->font_height
))
4142 /* Call function with current height as argument.
4143 Value is the new height. */
4145 height
= safe_call1 (it
->font_height
,
4146 face
->lface
[LFACE_HEIGHT_INDEX
]);
4147 if (NUMBERP (height
))
4148 new_height
= XFLOATINT (height
);
4150 else if (NUMBERP (it
->font_height
))
4152 /* Value is a multiple of the canonical char height. */
4155 face
= FACE_FROM_ID (it
->f
,
4156 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4157 new_height
= (XFLOATINT (it
->font_height
)
4158 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4162 /* Evaluate IT->font_height with `height' bound to the
4163 current specified height to get the new height. */
4164 int count
= SPECPDL_INDEX ();
4166 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4167 value
= safe_eval (it
->font_height
);
4168 unbind_to (count
, Qnil
);
4170 if (NUMBERP (value
))
4171 new_height
= XFLOATINT (value
);
4175 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4181 /* Handle `(space-width WIDTH)'. */
4183 && EQ (XCAR (spec
), Qspace_width
)
4184 && CONSP (XCDR (spec
)))
4186 if (!FRAME_WINDOW_P (it
->f
))
4189 value
= XCAR (XCDR (spec
));
4190 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4191 it
->space_width
= value
;
4196 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4198 && EQ (XCAR (spec
), Qslice
))
4202 if (!FRAME_WINDOW_P (it
->f
))
4205 if (tem
= XCDR (spec
), CONSP (tem
))
4207 it
->slice
.x
= XCAR (tem
);
4208 if (tem
= XCDR (tem
), CONSP (tem
))
4210 it
->slice
.y
= XCAR (tem
);
4211 if (tem
= XCDR (tem
), CONSP (tem
))
4213 it
->slice
.width
= XCAR (tem
);
4214 if (tem
= XCDR (tem
), CONSP (tem
))
4215 it
->slice
.height
= XCAR (tem
);
4223 /* Handle `(raise FACTOR)'. */
4225 && EQ (XCAR (spec
), Qraise
)
4226 && CONSP (XCDR (spec
)))
4228 if (!FRAME_WINDOW_P (it
->f
))
4231 #ifdef HAVE_WINDOW_SYSTEM
4232 value
= XCAR (XCDR (spec
));
4233 if (NUMBERP (value
))
4235 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4236 it
->voffset
= - (XFLOATINT (value
)
4237 * (FONT_HEIGHT (face
->font
)));
4239 #endif /* HAVE_WINDOW_SYSTEM */
4244 /* Don't handle the other kinds of display specifications
4245 inside a string that we got from a `display' property. */
4246 if (it
->string_from_display_prop_p
)
4249 /* Characters having this form of property are not displayed, so
4250 we have to find the end of the property. */
4251 start_pos
= *position
;
4252 *position
= display_prop_end (it
, object
, start_pos
);
4255 /* Stop the scan at that end position--we assume that all
4256 text properties change there. */
4257 it
->stop_charpos
= position
->charpos
;
4259 /* Handle `(left-fringe BITMAP [FACE])'
4260 and `(right-fringe BITMAP [FACE])'. */
4262 && (EQ (XCAR (spec
), Qleft_fringe
)
4263 || EQ (XCAR (spec
), Qright_fringe
))
4264 && CONSP (XCDR (spec
)))
4266 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4269 if (!FRAME_WINDOW_P (it
->f
))
4270 /* If we return here, POSITION has been advanced
4271 across the text with this property. */
4274 #ifdef HAVE_WINDOW_SYSTEM
4275 value
= XCAR (XCDR (spec
));
4276 if (!SYMBOLP (value
)
4277 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4278 /* If we return here, POSITION has been advanced
4279 across the text with this property. */
4282 if (CONSP (XCDR (XCDR (spec
))))
4284 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4285 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4291 /* Save current settings of IT so that we can restore them
4292 when we are finished with the glyph property value. */
4294 save_pos
= it
->position
;
4295 it
->position
= *position
;
4297 it
->position
= save_pos
;
4299 it
->area
= TEXT_AREA
;
4300 it
->what
= IT_IMAGE
;
4301 it
->image_id
= -1; /* no image */
4302 it
->position
= start_pos
;
4303 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4304 it
->method
= GET_FROM_IMAGE
;
4305 it
->from_overlay
= Qnil
;
4306 it
->face_id
= face_id
;
4308 /* Say that we haven't consumed the characters with
4309 `display' property yet. The call to pop_it in
4310 set_iterator_to_next will clean this up. */
4311 *position
= start_pos
;
4313 if (EQ (XCAR (spec
), Qleft_fringe
))
4315 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4316 it
->left_user_fringe_face_id
= face_id
;
4320 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4321 it
->right_user_fringe_face_id
= face_id
;
4323 #endif /* HAVE_WINDOW_SYSTEM */
4327 /* Prepare to handle `((margin left-margin) ...)',
4328 `((margin right-margin) ...)' and `((margin nil) ...)'
4329 prefixes for display specifications. */
4330 location
= Qunbound
;
4331 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4335 value
= XCDR (spec
);
4337 value
= XCAR (value
);
4340 if (EQ (XCAR (tem
), Qmargin
)
4341 && (tem
= XCDR (tem
),
4342 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4344 || EQ (tem
, Qleft_margin
)
4345 || EQ (tem
, Qright_margin
))))
4349 if (EQ (location
, Qunbound
))
4355 /* After this point, VALUE is the property after any
4356 margin prefix has been stripped. It must be a string,
4357 an image specification, or `(space ...)'.
4359 LOCATION specifies where to display: `left-margin',
4360 `right-margin' or nil. */
4362 valid_p
= (STRINGP (value
)
4363 #ifdef HAVE_WINDOW_SYSTEM
4364 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4365 #endif /* not HAVE_WINDOW_SYSTEM */
4366 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4368 if (valid_p
&& !display_replaced_before_p
)
4370 /* Save current settings of IT so that we can restore them
4371 when we are finished with the glyph property value. */
4372 save_pos
= it
->position
;
4373 it
->position
= *position
;
4375 it
->position
= save_pos
;
4376 it
->from_overlay
= overlay
;
4378 if (NILP (location
))
4379 it
->area
= TEXT_AREA
;
4380 else if (EQ (location
, Qleft_margin
))
4381 it
->area
= LEFT_MARGIN_AREA
;
4383 it
->area
= RIGHT_MARGIN_AREA
;
4385 if (STRINGP (value
))
4388 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4389 it
->current
.overlay_string_index
= -1;
4390 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4391 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4392 it
->method
= GET_FROM_STRING
;
4393 it
->stop_charpos
= 0;
4394 it
->string_from_display_prop_p
= 1;
4395 /* Say that we haven't consumed the characters with
4396 `display' property yet. The call to pop_it in
4397 set_iterator_to_next will clean this up. */
4398 if (BUFFERP (object
))
4399 *position
= start_pos
;
4401 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4403 it
->method
= GET_FROM_STRETCH
;
4405 *position
= it
->position
= start_pos
;
4407 #ifdef HAVE_WINDOW_SYSTEM
4410 it
->what
= IT_IMAGE
;
4411 it
->image_id
= lookup_image (it
->f
, value
);
4412 it
->position
= start_pos
;
4413 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4414 it
->method
= GET_FROM_IMAGE
;
4416 /* Say that we haven't consumed the characters with
4417 `display' property yet. The call to pop_it in
4418 set_iterator_to_next will clean this up. */
4419 *position
= start_pos
;
4421 #endif /* HAVE_WINDOW_SYSTEM */
4426 /* Invalid property or property not supported. Restore
4427 POSITION to what it was before. */
4428 *position
= start_pos
;
4433 /* Check if SPEC is a display sub-property value whose text should be
4434 treated as intangible. */
4437 single_display_spec_intangible_p (prop
)
4440 /* Skip over `when FORM'. */
4441 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4455 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4456 we don't need to treat text as intangible. */
4457 if (EQ (XCAR (prop
), Qmargin
))
4465 || EQ (XCAR (prop
), Qleft_margin
)
4466 || EQ (XCAR (prop
), Qright_margin
))
4470 return (CONSP (prop
)
4471 && (EQ (XCAR (prop
), Qimage
)
4472 || EQ (XCAR (prop
), Qspace
)));
4476 /* Check if PROP is a display property value whose text should be
4477 treated as intangible. */
4480 display_prop_intangible_p (prop
)
4484 && CONSP (XCAR (prop
))
4485 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4487 /* A list of sub-properties. */
4488 while (CONSP (prop
))
4490 if (single_display_spec_intangible_p (XCAR (prop
)))
4495 else if (VECTORP (prop
))
4497 /* A vector of sub-properties. */
4499 for (i
= 0; i
< ASIZE (prop
); ++i
)
4500 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4504 return single_display_spec_intangible_p (prop
);
4510 /* Return 1 if PROP is a display sub-property value containing STRING. */
4513 single_display_spec_string_p (prop
, string
)
4514 Lisp_Object prop
, string
;
4516 if (EQ (string
, prop
))
4519 /* Skip over `when FORM'. */
4520 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4529 /* Skip over `margin LOCATION'. */
4530 if (EQ (XCAR (prop
), Qmargin
))
4541 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4545 /* Return 1 if STRING appears in the `display' property PROP. */
4548 display_prop_string_p (prop
, string
)
4549 Lisp_Object prop
, string
;
4552 && CONSP (XCAR (prop
))
4553 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4555 /* A list of sub-properties. */
4556 while (CONSP (prop
))
4558 if (single_display_spec_string_p (XCAR (prop
), string
))
4563 else if (VECTORP (prop
))
4565 /* A vector of sub-properties. */
4567 for (i
= 0; i
< ASIZE (prop
); ++i
)
4568 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4572 return single_display_spec_string_p (prop
, string
);
4578 /* Determine from which buffer position in W's buffer STRING comes
4579 from. AROUND_CHARPOS is an approximate position where it could
4580 be from. Value is the buffer position or 0 if it couldn't be
4583 W's buffer must be current.
4585 This function is necessary because we don't record buffer positions
4586 in glyphs generated from strings (to keep struct glyph small).
4587 This function may only use code that doesn't eval because it is
4588 called asynchronously from note_mouse_highlight. */
4591 string_buffer_position (w
, string
, around_charpos
)
4596 Lisp_Object limit
, prop
, pos
;
4597 const int MAX_DISTANCE
= 1000;
4600 pos
= make_number (around_charpos
);
4601 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4602 while (!found
&& !EQ (pos
, limit
))
4604 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4605 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4608 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4613 pos
= make_number (around_charpos
);
4614 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4615 while (!found
&& !EQ (pos
, limit
))
4617 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4618 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4621 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4626 return found
? XINT (pos
) : 0;
4631 /***********************************************************************
4632 `composition' property
4633 ***********************************************************************/
4635 /* Set up iterator IT from `composition' property at its current
4636 position. Called from handle_stop. */
4638 static enum prop_handled
4639 handle_composition_prop (it
)
4642 Lisp_Object prop
, string
;
4643 EMACS_INT pos
, pos_byte
, start
, end
;
4645 if (STRINGP (it
->string
))
4649 pos
= IT_STRING_CHARPOS (*it
);
4650 pos_byte
= IT_STRING_BYTEPOS (*it
);
4651 string
= it
->string
;
4652 s
= SDATA (string
) + pos_byte
;
4653 it
->c
= STRING_CHAR (s
, 0);
4657 pos
= IT_CHARPOS (*it
);
4658 pos_byte
= IT_BYTEPOS (*it
);
4660 it
->c
= FETCH_CHAR (pos_byte
);
4663 /* If there's a valid composition and point is not inside of the
4664 composition (in the case that the composition is from the current
4665 buffer), draw a glyph composed from the composition components. */
4666 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4667 && COMPOSITION_VALID_P (start
, end
, prop
)
4668 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4672 if (STRINGP (it
->string
))
4673 pos_byte
= string_char_to_byte (it
->string
, start
);
4675 pos_byte
= CHAR_TO_BYTE (start
);
4677 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4680 if (it
->cmp_it
.id
>= 0)
4683 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4684 it
->cmp_it
.nglyphs
= -1;
4688 return HANDLED_NORMALLY
;
4693 /***********************************************************************
4695 ***********************************************************************/
4697 /* The following structure is used to record overlay strings for
4698 later sorting in load_overlay_strings. */
4700 struct overlay_entry
4702 Lisp_Object overlay
;
4709 /* Set up iterator IT from overlay strings at its current position.
4710 Called from handle_stop. */
4712 static enum prop_handled
4713 handle_overlay_change (it
)
4716 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4717 return HANDLED_RECOMPUTE_PROPS
;
4719 return HANDLED_NORMALLY
;
4723 /* Set up the next overlay string for delivery by IT, if there is an
4724 overlay string to deliver. Called by set_iterator_to_next when the
4725 end of the current overlay string is reached. If there are more
4726 overlay strings to display, IT->string and
4727 IT->current.overlay_string_index are set appropriately here.
4728 Otherwise IT->string is set to nil. */
4731 next_overlay_string (it
)
4734 ++it
->current
.overlay_string_index
;
4735 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4737 /* No more overlay strings. Restore IT's settings to what
4738 they were before overlay strings were processed, and
4739 continue to deliver from current_buffer. */
4741 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4744 || (NILP (it
->string
)
4745 && it
->method
== GET_FROM_BUFFER
4746 && it
->stop_charpos
>= BEGV
4747 && it
->stop_charpos
<= it
->end_charpos
));
4748 it
->current
.overlay_string_index
= -1;
4749 it
->n_overlay_strings
= 0;
4751 /* If we're at the end of the buffer, record that we have
4752 processed the overlay strings there already, so that
4753 next_element_from_buffer doesn't try it again. */
4754 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4755 it
->overlay_strings_at_end_processed_p
= 1;
4759 /* There are more overlay strings to process. If
4760 IT->current.overlay_string_index has advanced to a position
4761 where we must load IT->overlay_strings with more strings, do
4763 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4765 if (it
->current
.overlay_string_index
&& i
== 0)
4766 load_overlay_strings (it
, 0);
4768 /* Initialize IT to deliver display elements from the overlay
4770 it
->string
= it
->overlay_strings
[i
];
4771 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4772 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4773 it
->method
= GET_FROM_STRING
;
4774 it
->stop_charpos
= 0;
4775 if (it
->cmp_it
.stop_pos
>= 0)
4776 it
->cmp_it
.stop_pos
= 0;
4783 /* Compare two overlay_entry structures E1 and E2. Used as a
4784 comparison function for qsort in load_overlay_strings. Overlay
4785 strings for the same position are sorted so that
4787 1. All after-strings come in front of before-strings, except
4788 when they come from the same overlay.
4790 2. Within after-strings, strings are sorted so that overlay strings
4791 from overlays with higher priorities come first.
4793 2. Within before-strings, strings are sorted so that overlay
4794 strings from overlays with higher priorities come last.
4796 Value is analogous to strcmp. */
4800 compare_overlay_entries (e1
, e2
)
4803 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4804 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4807 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4809 /* Let after-strings appear in front of before-strings if
4810 they come from different overlays. */
4811 if (EQ (entry1
->overlay
, entry2
->overlay
))
4812 result
= entry1
->after_string_p
? 1 : -1;
4814 result
= entry1
->after_string_p
? -1 : 1;
4816 else if (entry1
->after_string_p
)
4817 /* After-strings sorted in order of decreasing priority. */
4818 result
= entry2
->priority
- entry1
->priority
;
4820 /* Before-strings sorted in order of increasing priority. */
4821 result
= entry1
->priority
- entry2
->priority
;
4827 /* Load the vector IT->overlay_strings with overlay strings from IT's
4828 current buffer position, or from CHARPOS if that is > 0. Set
4829 IT->n_overlays to the total number of overlay strings found.
4831 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4832 a time. On entry into load_overlay_strings,
4833 IT->current.overlay_string_index gives the number of overlay
4834 strings that have already been loaded by previous calls to this
4837 IT->add_overlay_start contains an additional overlay start
4838 position to consider for taking overlay strings from, if non-zero.
4839 This position comes into play when the overlay has an `invisible'
4840 property, and both before and after-strings. When we've skipped to
4841 the end of the overlay, because of its `invisible' property, we
4842 nevertheless want its before-string to appear.
4843 IT->add_overlay_start will contain the overlay start position
4846 Overlay strings are sorted so that after-string strings come in
4847 front of before-string strings. Within before and after-strings,
4848 strings are sorted by overlay priority. See also function
4849 compare_overlay_entries. */
4852 load_overlay_strings (it
, charpos
)
4856 extern Lisp_Object Qwindow
, Qpriority
;
4857 Lisp_Object overlay
, window
, str
, invisible
;
4858 struct Lisp_Overlay
*ov
;
4861 int n
= 0, i
, j
, invis_p
;
4862 struct overlay_entry
*entries
4863 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4866 charpos
= IT_CHARPOS (*it
);
4868 /* Append the overlay string STRING of overlay OVERLAY to vector
4869 `entries' which has size `size' and currently contains `n'
4870 elements. AFTER_P non-zero means STRING is an after-string of
4872 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4875 Lisp_Object priority; \
4879 int new_size = 2 * size; \
4880 struct overlay_entry *old = entries; \
4882 (struct overlay_entry *) alloca (new_size \
4883 * sizeof *entries); \
4884 bcopy (old, entries, size * sizeof *entries); \
4888 entries[n].string = (STRING); \
4889 entries[n].overlay = (OVERLAY); \
4890 priority = Foverlay_get ((OVERLAY), Qpriority); \
4891 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4892 entries[n].after_string_p = (AFTER_P); \
4897 /* Process overlay before the overlay center. */
4898 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4900 XSETMISC (overlay
, ov
);
4901 xassert (OVERLAYP (overlay
));
4902 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4903 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4908 /* Skip this overlay if it doesn't start or end at IT's current
4910 if (end
!= charpos
&& start
!= charpos
)
4913 /* Skip this overlay if it doesn't apply to IT->w. */
4914 window
= Foverlay_get (overlay
, Qwindow
);
4915 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4918 /* If the text ``under'' the overlay is invisible, both before-
4919 and after-strings from this overlay are visible; start and
4920 end position are indistinguishable. */
4921 invisible
= Foverlay_get (overlay
, Qinvisible
);
4922 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4924 /* If overlay has a non-empty before-string, record it. */
4925 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4926 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4928 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4930 /* If overlay has a non-empty after-string, record it. */
4931 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4932 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4934 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4937 /* Process overlays after the overlay center. */
4938 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4940 XSETMISC (overlay
, ov
);
4941 xassert (OVERLAYP (overlay
));
4942 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4943 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4945 if (start
> charpos
)
4948 /* Skip this overlay if it doesn't start or end at IT's current
4950 if (end
!= charpos
&& start
!= charpos
)
4953 /* Skip this overlay if it doesn't apply to IT->w. */
4954 window
= Foverlay_get (overlay
, Qwindow
);
4955 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4958 /* If the text ``under'' the overlay is invisible, it has a zero
4959 dimension, and both before- and after-strings apply. */
4960 invisible
= Foverlay_get (overlay
, Qinvisible
);
4961 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4963 /* If overlay has a non-empty before-string, record it. */
4964 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4965 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4967 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4969 /* If overlay has a non-empty after-string, record it. */
4970 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4971 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4973 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4976 #undef RECORD_OVERLAY_STRING
4980 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4982 /* Record the total number of strings to process. */
4983 it
->n_overlay_strings
= n
;
4985 /* IT->current.overlay_string_index is the number of overlay strings
4986 that have already been consumed by IT. Copy some of the
4987 remaining overlay strings to IT->overlay_strings. */
4989 j
= it
->current
.overlay_string_index
;
4990 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4992 it
->overlay_strings
[i
] = entries
[j
].string
;
4993 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5000 /* Get the first chunk of overlay strings at IT's current buffer
5001 position, or at CHARPOS if that is > 0. Value is non-zero if at
5002 least one overlay string was found. */
5005 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5010 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5011 process. This fills IT->overlay_strings with strings, and sets
5012 IT->n_overlay_strings to the total number of strings to process.
5013 IT->pos.overlay_string_index has to be set temporarily to zero
5014 because load_overlay_strings needs this; it must be set to -1
5015 when no overlay strings are found because a zero value would
5016 indicate a position in the first overlay string. */
5017 it
->current
.overlay_string_index
= 0;
5018 load_overlay_strings (it
, charpos
);
5020 /* If we found overlay strings, set up IT to deliver display
5021 elements from the first one. Otherwise set up IT to deliver
5022 from current_buffer. */
5023 if (it
->n_overlay_strings
)
5025 /* Make sure we know settings in current_buffer, so that we can
5026 restore meaningful values when we're done with the overlay
5029 compute_stop_pos (it
);
5030 xassert (it
->face_id
>= 0);
5032 /* Save IT's settings. They are restored after all overlay
5033 strings have been processed. */
5034 xassert (!compute_stop_p
|| it
->sp
== 0);
5036 /* When called from handle_stop, there might be an empty display
5037 string loaded. In that case, don't bother saving it. */
5038 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5041 /* Set up IT to deliver display elements from the first overlay
5043 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5044 it
->string
= it
->overlay_strings
[0];
5045 it
->from_overlay
= Qnil
;
5046 it
->stop_charpos
= 0;
5047 xassert (STRINGP (it
->string
));
5048 it
->end_charpos
= SCHARS (it
->string
);
5049 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5050 it
->method
= GET_FROM_STRING
;
5054 it
->current
.overlay_string_index
= -1;
5059 get_overlay_strings (it
, charpos
)
5064 it
->method
= GET_FROM_BUFFER
;
5066 (void) get_overlay_strings_1 (it
, charpos
, 1);
5070 /* Value is non-zero if we found at least one overlay string. */
5071 return STRINGP (it
->string
);
5076 /***********************************************************************
5077 Saving and restoring state
5078 ***********************************************************************/
5080 /* Save current settings of IT on IT->stack. Called, for example,
5081 before setting up IT for an overlay string, to be able to restore
5082 IT's settings to what they were after the overlay string has been
5089 struct iterator_stack_entry
*p
;
5091 xassert (it
->sp
< IT_STACK_SIZE
);
5092 p
= it
->stack
+ it
->sp
;
5094 p
->stop_charpos
= it
->stop_charpos
;
5095 p
->cmp_it
= it
->cmp_it
;
5096 xassert (it
->face_id
>= 0);
5097 p
->face_id
= it
->face_id
;
5098 p
->string
= it
->string
;
5099 p
->method
= it
->method
;
5100 p
->from_overlay
= it
->from_overlay
;
5103 case GET_FROM_IMAGE
:
5104 p
->u
.image
.object
= it
->object
;
5105 p
->u
.image
.image_id
= it
->image_id
;
5106 p
->u
.image
.slice
= it
->slice
;
5108 case GET_FROM_STRETCH
:
5109 p
->u
.stretch
.object
= it
->object
;
5112 p
->position
= it
->position
;
5113 p
->current
= it
->current
;
5114 p
->end_charpos
= it
->end_charpos
;
5115 p
->string_nchars
= it
->string_nchars
;
5117 p
->multibyte_p
= it
->multibyte_p
;
5118 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5119 p
->space_width
= it
->space_width
;
5120 p
->font_height
= it
->font_height
;
5121 p
->voffset
= it
->voffset
;
5122 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5123 p
->display_ellipsis_p
= 0;
5124 p
->line_wrap
= it
->line_wrap
;
5129 /* Restore IT's settings from IT->stack. Called, for example, when no
5130 more overlay strings must be processed, and we return to delivering
5131 display elements from a buffer, or when the end of a string from a
5132 `display' property is reached and we return to delivering display
5133 elements from an overlay string, or from a buffer. */
5139 struct iterator_stack_entry
*p
;
5141 xassert (it
->sp
> 0);
5143 p
= it
->stack
+ it
->sp
;
5144 it
->stop_charpos
= p
->stop_charpos
;
5145 it
->cmp_it
= p
->cmp_it
;
5146 it
->face_id
= p
->face_id
;
5147 it
->current
= p
->current
;
5148 it
->position
= p
->position
;
5149 it
->string
= p
->string
;
5150 it
->from_overlay
= p
->from_overlay
;
5151 if (NILP (it
->string
))
5152 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5153 it
->method
= p
->method
;
5156 case GET_FROM_IMAGE
:
5157 it
->image_id
= p
->u
.image
.image_id
;
5158 it
->object
= p
->u
.image
.object
;
5159 it
->slice
= p
->u
.image
.slice
;
5161 case GET_FROM_STRETCH
:
5162 it
->object
= p
->u
.comp
.object
;
5164 case GET_FROM_BUFFER
:
5165 it
->object
= it
->w
->buffer
;
5167 case GET_FROM_STRING
:
5168 it
->object
= it
->string
;
5171 it
->end_charpos
= p
->end_charpos
;
5172 it
->string_nchars
= p
->string_nchars
;
5174 it
->multibyte_p
= p
->multibyte_p
;
5175 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5176 it
->space_width
= p
->space_width
;
5177 it
->font_height
= p
->font_height
;
5178 it
->voffset
= p
->voffset
;
5179 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5180 it
->line_wrap
= p
->line_wrap
;
5185 /***********************************************************************
5187 ***********************************************************************/
5189 /* Set IT's current position to the previous line start. */
5192 back_to_previous_line_start (it
)
5195 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5196 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5200 /* Move IT to the next line start.
5202 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5203 we skipped over part of the text (as opposed to moving the iterator
5204 continuously over the text). Otherwise, don't change the value
5207 Newlines may come from buffer text, overlay strings, or strings
5208 displayed via the `display' property. That's the reason we can't
5209 simply use find_next_newline_no_quit.
5211 Note that this function may not skip over invisible text that is so
5212 because of text properties and immediately follows a newline. If
5213 it would, function reseat_at_next_visible_line_start, when called
5214 from set_iterator_to_next, would effectively make invisible
5215 characters following a newline part of the wrong glyph row, which
5216 leads to wrong cursor motion. */
5219 forward_to_next_line_start (it
, skipped_p
)
5223 int old_selective
, newline_found_p
, n
;
5224 const int MAX_NEWLINE_DISTANCE
= 500;
5226 /* If already on a newline, just consume it to avoid unintended
5227 skipping over invisible text below. */
5228 if (it
->what
== IT_CHARACTER
5230 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5232 set_iterator_to_next (it
, 0);
5237 /* Don't handle selective display in the following. It's (a)
5238 unnecessary because it's done by the caller, and (b) leads to an
5239 infinite recursion because next_element_from_ellipsis indirectly
5240 calls this function. */
5241 old_selective
= it
->selective
;
5244 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5245 from buffer text. */
5246 for (n
= newline_found_p
= 0;
5247 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5248 n
+= STRINGP (it
->string
) ? 0 : 1)
5250 if (!get_next_display_element (it
))
5252 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5253 set_iterator_to_next (it
, 0);
5256 /* If we didn't find a newline near enough, see if we can use a
5258 if (!newline_found_p
)
5260 int start
= IT_CHARPOS (*it
);
5261 int limit
= find_next_newline_no_quit (start
, 1);
5264 xassert (!STRINGP (it
->string
));
5266 /* If there isn't any `display' property in sight, and no
5267 overlays, we can just use the position of the newline in
5269 if (it
->stop_charpos
>= limit
5270 || ((pos
= Fnext_single_property_change (make_number (start
),
5272 Qnil
, make_number (limit
)),
5274 && next_overlay_change (start
) == ZV
))
5276 IT_CHARPOS (*it
) = limit
;
5277 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5278 *skipped_p
= newline_found_p
= 1;
5282 while (get_next_display_element (it
)
5283 && !newline_found_p
)
5285 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5286 set_iterator_to_next (it
, 0);
5291 it
->selective
= old_selective
;
5292 return newline_found_p
;
5296 /* Set IT's current position to the previous visible line start. Skip
5297 invisible text that is so either due to text properties or due to
5298 selective display. Caution: this does not change IT->current_x and
5302 back_to_previous_visible_line_start (it
)
5305 while (IT_CHARPOS (*it
) > BEGV
)
5307 back_to_previous_line_start (it
);
5309 if (IT_CHARPOS (*it
) <= BEGV
)
5312 /* If selective > 0, then lines indented more than that values
5314 if (it
->selective
> 0
5315 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5316 (double) it
->selective
)) /* iftc */
5319 /* Check the newline before point for invisibility. */
5322 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5323 Qinvisible
, it
->window
);
5324 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5328 if (IT_CHARPOS (*it
) <= BEGV
)
5335 Lisp_Object val
, overlay
;
5337 /* If newline is part of a composition, continue from start of composition */
5338 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5339 && beg
< IT_CHARPOS (*it
))
5342 /* If newline is replaced by a display property, find start of overlay
5343 or interval and continue search from that point. */
5345 pos
= --IT_CHARPOS (it2
);
5348 it2
.string_from_display_prop_p
= 0;
5349 if (handle_display_prop (&it2
) == HANDLED_RETURN
5350 && !NILP (val
= get_char_property_and_overlay
5351 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5352 && (OVERLAYP (overlay
)
5353 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5354 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5357 /* Newline is not replaced by anything -- so we are done. */
5363 IT_CHARPOS (*it
) = beg
;
5364 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5368 it
->continuation_lines_width
= 0;
5370 xassert (IT_CHARPOS (*it
) >= BEGV
);
5371 xassert (IT_CHARPOS (*it
) == BEGV
5372 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5377 /* Reseat iterator IT at the previous visible line start. Skip
5378 invisible text that is so either due to text properties or due to
5379 selective display. At the end, update IT's overlay information,
5380 face information etc. */
5383 reseat_at_previous_visible_line_start (it
)
5386 back_to_previous_visible_line_start (it
);
5387 reseat (it
, it
->current
.pos
, 1);
5392 /* Reseat iterator IT on the next visible line start in the current
5393 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5394 preceding the line start. Skip over invisible text that is so
5395 because of selective display. Compute faces, overlays etc at the
5396 new position. Note that this function does not skip over text that
5397 is invisible because of text properties. */
5400 reseat_at_next_visible_line_start (it
, on_newline_p
)
5404 int newline_found_p
, skipped_p
= 0;
5406 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5408 /* Skip over lines that are invisible because they are indented
5409 more than the value of IT->selective. */
5410 if (it
->selective
> 0)
5411 while (IT_CHARPOS (*it
) < ZV
5412 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5413 (double) it
->selective
)) /* iftc */
5415 xassert (IT_BYTEPOS (*it
) == BEGV
5416 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5417 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5420 /* Position on the newline if that's what's requested. */
5421 if (on_newline_p
&& newline_found_p
)
5423 if (STRINGP (it
->string
))
5425 if (IT_STRING_CHARPOS (*it
) > 0)
5427 --IT_STRING_CHARPOS (*it
);
5428 --IT_STRING_BYTEPOS (*it
);
5431 else if (IT_CHARPOS (*it
) > BEGV
)
5435 reseat (it
, it
->current
.pos
, 0);
5439 reseat (it
, it
->current
.pos
, 0);
5446 /***********************************************************************
5447 Changing an iterator's position
5448 ***********************************************************************/
5450 /* Change IT's current position to POS in current_buffer. If FORCE_P
5451 is non-zero, always check for text properties at the new position.
5452 Otherwise, text properties are only looked up if POS >=
5453 IT->check_charpos of a property. */
5456 reseat (it
, pos
, force_p
)
5458 struct text_pos pos
;
5461 int original_pos
= IT_CHARPOS (*it
);
5463 reseat_1 (it
, pos
, 0);
5465 /* Determine where to check text properties. Avoid doing it
5466 where possible because text property lookup is very expensive. */
5468 || CHARPOS (pos
) > it
->stop_charpos
5469 || CHARPOS (pos
) < original_pos
)
5476 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5477 IT->stop_pos to POS, also. */
5480 reseat_1 (it
, pos
, set_stop_p
)
5482 struct text_pos pos
;
5485 /* Don't call this function when scanning a C string. */
5486 xassert (it
->s
== NULL
);
5488 /* POS must be a reasonable value. */
5489 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5491 it
->current
.pos
= it
->position
= pos
;
5492 it
->end_charpos
= ZV
;
5494 it
->current
.dpvec_index
= -1;
5495 it
->current
.overlay_string_index
= -1;
5496 IT_STRING_CHARPOS (*it
) = -1;
5497 IT_STRING_BYTEPOS (*it
) = -1;
5499 it
->string_from_display_prop_p
= 0;
5500 it
->method
= GET_FROM_BUFFER
;
5501 it
->object
= it
->w
->buffer
;
5502 it
->area
= TEXT_AREA
;
5503 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5505 it
->string_from_display_prop_p
= 0;
5506 it
->face_before_selective_p
= 0;
5509 it
->stop_charpos
= CHARPOS (pos
);
5513 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5514 If S is non-null, it is a C string to iterate over. Otherwise,
5515 STRING gives a Lisp string to iterate over.
5517 If PRECISION > 0, don't return more then PRECISION number of
5518 characters from the string.
5520 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5521 characters have been returned. FIELD_WIDTH < 0 means an infinite
5524 MULTIBYTE = 0 means disable processing of multibyte characters,
5525 MULTIBYTE > 0 means enable it,
5526 MULTIBYTE < 0 means use IT->multibyte_p.
5528 IT must be initialized via a prior call to init_iterator before
5529 calling this function. */
5532 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5537 int precision
, field_width
, multibyte
;
5539 /* No region in strings. */
5540 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5542 /* No text property checks performed by default, but see below. */
5543 it
->stop_charpos
= -1;
5545 /* Set iterator position and end position. */
5546 bzero (&it
->current
, sizeof it
->current
);
5547 it
->current
.overlay_string_index
= -1;
5548 it
->current
.dpvec_index
= -1;
5549 xassert (charpos
>= 0);
5551 /* If STRING is specified, use its multibyteness, otherwise use the
5552 setting of MULTIBYTE, if specified. */
5554 it
->multibyte_p
= multibyte
> 0;
5558 xassert (STRINGP (string
));
5559 it
->string
= string
;
5561 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5562 it
->method
= GET_FROM_STRING
;
5563 it
->current
.string_pos
= string_pos (charpos
, string
);
5570 /* Note that we use IT->current.pos, not it->current.string_pos,
5571 for displaying C strings. */
5572 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5573 if (it
->multibyte_p
)
5575 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5576 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5580 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5581 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5584 it
->method
= GET_FROM_C_STRING
;
5587 /* PRECISION > 0 means don't return more than PRECISION characters
5589 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5590 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5592 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5593 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5594 FIELD_WIDTH < 0 means infinite field width. This is useful for
5595 padding with `-' at the end of a mode line. */
5596 if (field_width
< 0)
5597 field_width
= INFINITY
;
5598 if (field_width
> it
->end_charpos
- charpos
)
5599 it
->end_charpos
= charpos
+ field_width
;
5601 /* Use the standard display table for displaying strings. */
5602 if (DISP_TABLE_P (Vstandard_display_table
))
5603 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5605 it
->stop_charpos
= charpos
;
5611 /***********************************************************************
5613 ***********************************************************************/
5615 /* Map enum it_method value to corresponding next_element_from_* function. */
5617 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5619 next_element_from_buffer
,
5620 next_element_from_display_vector
,
5621 next_element_from_string
,
5622 next_element_from_c_string
,
5623 next_element_from_image
,
5624 next_element_from_stretch
5627 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5630 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5631 (possibly with the following characters). */
5633 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS) \
5634 ((IT)->cmp_it.id >= 0 \
5635 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5636 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5637 (IT)->end_charpos, (IT)->w, \
5638 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5642 /* Load IT's display element fields with information about the next
5643 display element from the current position of IT. Value is zero if
5644 end of buffer (or C string) is reached. */
5646 static struct frame
*last_escape_glyph_frame
= NULL
;
5647 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5648 static int last_escape_glyph_merged_face_id
= 0;
5651 get_next_display_element (it
)
5654 /* Non-zero means that we found a display element. Zero means that
5655 we hit the end of what we iterate over. Performance note: the
5656 function pointer `method' used here turns out to be faster than
5657 using a sequence of if-statements. */
5661 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5663 if (it
->what
== IT_CHARACTER
)
5665 /* Map via display table or translate control characters.
5666 IT->c, IT->len etc. have been set to the next character by
5667 the function call above. If we have a display table, and it
5668 contains an entry for IT->c, translate it. Don't do this if
5669 IT->c itself comes from a display table, otherwise we could
5670 end up in an infinite recursion. (An alternative could be to
5671 count the recursion depth of this function and signal an
5672 error when a certain maximum depth is reached.) Is it worth
5674 if (success_p
&& it
->dpvec
== NULL
)
5677 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5680 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5683 struct Lisp_Vector
*v
= XVECTOR (dv
);
5685 /* Return the first character from the display table
5686 entry, if not empty. If empty, don't display the
5687 current character. */
5690 it
->dpvec_char_len
= it
->len
;
5691 it
->dpvec
= v
->contents
;
5692 it
->dpend
= v
->contents
+ v
->size
;
5693 it
->current
.dpvec_index
= 0;
5694 it
->dpvec_face_id
= -1;
5695 it
->saved_face_id
= it
->face_id
;
5696 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5701 set_iterator_to_next (it
, 0);
5706 /* Translate control characters into `\003' or `^C' form.
5707 Control characters coming from a display table entry are
5708 currently not translated because we use IT->dpvec to hold
5709 the translation. This could easily be changed but I
5710 don't believe that it is worth doing.
5712 If it->multibyte_p is nonzero, non-printable non-ASCII
5713 characters are also translated to octal form.
5715 If it->multibyte_p is zero, eight-bit characters that
5716 don't have corresponding multibyte char code are also
5717 translated to octal form. */
5718 else if ((it
->c
< ' '
5719 ? (it
->area
!= TEXT_AREA
5720 /* In mode line, treat \n, \t like other crl chars. */
5723 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5724 || (it
->c
!= '\n' && it
->c
!= '\t'))
5726 ? (!CHAR_PRINTABLE_P (it
->c
)
5727 || (!NILP (Vnobreak_char_display
)
5728 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5729 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5731 && (! unibyte_display_via_language_environment
5732 || (DECODE_CHAR (unibyte
, it
->c
) <= 0xA0))))))
5734 /* IT->c is a control character which must be displayed
5735 either as '\003' or as `^C' where the '\\' and '^'
5736 can be defined in the display table. Fill
5737 IT->ctl_chars with glyphs for what we have to
5738 display. Then, set IT->dpvec to these glyphs. */
5741 int face_id
, lface_id
= 0 ;
5744 /* Handle control characters with ^. */
5746 if (it
->c
< 128 && it
->ctl_arrow_p
)
5750 g
= '^'; /* default glyph for Control */
5751 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5753 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5754 && GLYPH_CODE_CHAR_VALID_P (gc
))
5756 g
= GLYPH_CODE_CHAR (gc
);
5757 lface_id
= GLYPH_CODE_FACE (gc
);
5761 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5763 else if (it
->f
== last_escape_glyph_frame
5764 && it
->face_id
== last_escape_glyph_face_id
)
5766 face_id
= last_escape_glyph_merged_face_id
;
5770 /* Merge the escape-glyph face into the current face. */
5771 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5773 last_escape_glyph_frame
= it
->f
;
5774 last_escape_glyph_face_id
= it
->face_id
;
5775 last_escape_glyph_merged_face_id
= face_id
;
5778 XSETINT (it
->ctl_chars
[0], g
);
5779 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5781 goto display_control
;
5784 /* Handle non-break space in the mode where it only gets
5787 if (EQ (Vnobreak_char_display
, Qt
)
5790 /* Merge the no-break-space face into the current face. */
5791 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5795 XSETINT (it
->ctl_chars
[0], ' ');
5797 goto display_control
;
5800 /* Handle sequences that start with the "escape glyph". */
5802 /* the default escape glyph is \. */
5803 escape_glyph
= '\\';
5806 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5807 && GLYPH_CODE_CHAR_VALID_P (gc
))
5809 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5810 lface_id
= GLYPH_CODE_FACE (gc
);
5814 /* The display table specified a face.
5815 Merge it into face_id and also into escape_glyph. */
5816 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5819 else if (it
->f
== last_escape_glyph_frame
5820 && it
->face_id
== last_escape_glyph_face_id
)
5822 face_id
= last_escape_glyph_merged_face_id
;
5826 /* Merge the escape-glyph face into the current face. */
5827 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5829 last_escape_glyph_frame
= it
->f
;
5830 last_escape_glyph_face_id
= it
->face_id
;
5831 last_escape_glyph_merged_face_id
= face_id
;
5834 /* Handle soft hyphens in the mode where they only get
5837 if (EQ (Vnobreak_char_display
, Qt
)
5841 XSETINT (it
->ctl_chars
[0], '-');
5843 goto display_control
;
5846 /* Handle non-break space and soft hyphen
5847 with the escape glyph. */
5849 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5851 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5852 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5853 XSETINT (it
->ctl_chars
[1], it
->c
);
5855 goto display_control
;
5859 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5863 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5864 if (CHAR_BYTE8_P (it
->c
))
5866 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5869 else if (it
->c
< 256)
5876 /* It's an invalid character, which shouldn't
5877 happen actually, but due to bugs it may
5878 happen. Let's print the char as is, there's
5879 not much meaningful we can do with it. */
5881 str
[1] = it
->c
>> 8;
5882 str
[2] = it
->c
>> 16;
5883 str
[3] = it
->c
>> 24;
5887 for (i
= 0; i
< len
; i
++)
5890 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5891 /* Insert three more glyphs into IT->ctl_chars for
5892 the octal display of the character. */
5893 g
= ((str
[i
] >> 6) & 7) + '0';
5894 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5895 g
= ((str
[i
] >> 3) & 7) + '0';
5896 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5897 g
= (str
[i
] & 7) + '0';
5898 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5904 /* Set up IT->dpvec and return first character from it. */
5905 it
->dpvec_char_len
= it
->len
;
5906 it
->dpvec
= it
->ctl_chars
;
5907 it
->dpend
= it
->dpvec
+ ctl_len
;
5908 it
->current
.dpvec_index
= 0;
5909 it
->dpvec_face_id
= face_id
;
5910 it
->saved_face_id
= it
->face_id
;
5911 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5918 #ifdef HAVE_WINDOW_SYSTEM
5919 /* Adjust face id for a multibyte character. There are no multibyte
5920 character in unibyte text. */
5921 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5924 && FRAME_WINDOW_P (it
->f
))
5926 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5928 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5930 /* Automatic composition with glyph-string. */
5931 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5933 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5937 int pos
= (it
->s
? -1
5938 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5939 : IT_CHARPOS (*it
));
5941 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5946 /* Is this character the last one of a run of characters with
5947 box? If yes, set IT->end_of_box_run_p to 1. */
5951 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5953 int face_id
= underlying_face_id (it
);
5954 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5958 if (face
->box
== FACE_NO_BOX
)
5960 /* If the box comes from face properties in a
5961 display string, check faces in that string. */
5962 int string_face_id
= face_after_it_pos (it
);
5963 it
->end_of_box_run_p
5964 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5967 /* Otherwise, the box comes from the underlying face.
5968 If this is the last string character displayed, check
5969 the next buffer location. */
5970 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
5971 && (it
->current
.overlay_string_index
5972 == it
->n_overlay_strings
- 1))
5976 struct text_pos pos
= it
->current
.pos
;
5977 INC_TEXT_POS (pos
, it
->multibyte_p
);
5979 next_face_id
= face_at_buffer_position
5980 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
5981 it
->region_end_charpos
, &ignore
,
5982 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
5984 it
->end_of_box_run_p
5985 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
5992 int face_id
= face_after_it_pos (it
);
5993 it
->end_of_box_run_p
5994 = (face_id
!= it
->face_id
5995 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
5999 /* Value is 0 if end of buffer or string reached. */
6004 /* Move IT to the next display element.
6006 RESEAT_P non-zero means if called on a newline in buffer text,
6007 skip to the next visible line start.
6009 Functions get_next_display_element and set_iterator_to_next are
6010 separate because I find this arrangement easier to handle than a
6011 get_next_display_element function that also increments IT's
6012 position. The way it is we can first look at an iterator's current
6013 display element, decide whether it fits on a line, and if it does,
6014 increment the iterator position. The other way around we probably
6015 would either need a flag indicating whether the iterator has to be
6016 incremented the next time, or we would have to implement a
6017 decrement position function which would not be easy to write. */
6020 set_iterator_to_next (it
, reseat_p
)
6024 /* Reset flags indicating start and end of a sequence of characters
6025 with box. Reset them at the start of this function because
6026 moving the iterator to a new position might set them. */
6027 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6031 case GET_FROM_BUFFER
:
6032 /* The current display element of IT is a character from
6033 current_buffer. Advance in the buffer, and maybe skip over
6034 invisible lines that are so because of selective display. */
6035 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6036 reseat_at_next_visible_line_start (it
, 0);
6037 else if (it
->cmp_it
.id
>= 0)
6039 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6040 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6041 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6042 it
->cmp_it
.from
= it
->cmp_it
.to
;
6046 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6047 IT_BYTEPOS (*it
), it
->stop_charpos
,
6053 xassert (it
->len
!= 0);
6054 IT_BYTEPOS (*it
) += it
->len
;
6055 IT_CHARPOS (*it
) += 1;
6056 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6060 case GET_FROM_C_STRING
:
6061 /* Current display element of IT is from a C string. */
6062 IT_BYTEPOS (*it
) += it
->len
;
6063 IT_CHARPOS (*it
) += 1;
6066 case GET_FROM_DISPLAY_VECTOR
:
6067 /* Current display element of IT is from a display table entry.
6068 Advance in the display table definition. Reset it to null if
6069 end reached, and continue with characters from buffers/
6071 ++it
->current
.dpvec_index
;
6073 /* Restore face of the iterator to what they were before the
6074 display vector entry (these entries may contain faces). */
6075 it
->face_id
= it
->saved_face_id
;
6077 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6079 int recheck_faces
= it
->ellipsis_p
;
6082 it
->method
= GET_FROM_C_STRING
;
6083 else if (STRINGP (it
->string
))
6084 it
->method
= GET_FROM_STRING
;
6087 it
->method
= GET_FROM_BUFFER
;
6088 it
->object
= it
->w
->buffer
;
6092 it
->current
.dpvec_index
= -1;
6094 /* Skip over characters which were displayed via IT->dpvec. */
6095 if (it
->dpvec_char_len
< 0)
6096 reseat_at_next_visible_line_start (it
, 1);
6097 else if (it
->dpvec_char_len
> 0)
6099 if (it
->method
== GET_FROM_STRING
6100 && it
->n_overlay_strings
> 0)
6101 it
->ignore_overlay_strings_at_pos_p
= 1;
6102 it
->len
= it
->dpvec_char_len
;
6103 set_iterator_to_next (it
, reseat_p
);
6106 /* Maybe recheck faces after display vector */
6108 it
->stop_charpos
= IT_CHARPOS (*it
);
6112 case GET_FROM_STRING
:
6113 /* Current display element is a character from a Lisp string. */
6114 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6115 if (it
->cmp_it
.id
>= 0)
6117 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6118 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6119 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6120 it
->cmp_it
.from
= it
->cmp_it
.to
;
6124 composition_compute_stop_pos (&it
->cmp_it
,
6125 IT_STRING_CHARPOS (*it
),
6126 IT_STRING_BYTEPOS (*it
),
6127 it
->stop_charpos
, it
->string
);
6132 IT_STRING_BYTEPOS (*it
) += it
->len
;
6133 IT_STRING_CHARPOS (*it
) += 1;
6136 consider_string_end
:
6138 if (it
->current
.overlay_string_index
>= 0)
6140 /* IT->string is an overlay string. Advance to the
6141 next, if there is one. */
6142 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6145 next_overlay_string (it
);
6147 setup_for_ellipsis (it
, 0);
6152 /* IT->string is not an overlay string. If we reached
6153 its end, and there is something on IT->stack, proceed
6154 with what is on the stack. This can be either another
6155 string, this time an overlay string, or a buffer. */
6156 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6160 if (it
->method
== GET_FROM_STRING
)
6161 goto consider_string_end
;
6166 case GET_FROM_IMAGE
:
6167 case GET_FROM_STRETCH
:
6168 /* The position etc with which we have to proceed are on
6169 the stack. The position may be at the end of a string,
6170 if the `display' property takes up the whole string. */
6171 xassert (it
->sp
> 0);
6173 if (it
->method
== GET_FROM_STRING
)
6174 goto consider_string_end
;
6178 /* There are no other methods defined, so this should be a bug. */
6182 xassert (it
->method
!= GET_FROM_STRING
6183 || (STRINGP (it
->string
)
6184 && IT_STRING_CHARPOS (*it
) >= 0));
6187 /* Load IT's display element fields with information about the next
6188 display element which comes from a display table entry or from the
6189 result of translating a control character to one of the forms `^C'
6192 IT->dpvec holds the glyphs to return as characters.
6193 IT->saved_face_id holds the face id before the display vector--
6194 it is restored into IT->face_idin set_iterator_to_next. */
6197 next_element_from_display_vector (it
)
6203 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6205 it
->face_id
= it
->saved_face_id
;
6207 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6208 That seemed totally bogus - so I changed it... */
6209 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6211 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6213 it
->c
= GLYPH_CODE_CHAR (gc
);
6214 it
->len
= CHAR_BYTES (it
->c
);
6216 /* The entry may contain a face id to use. Such a face id is
6217 the id of a Lisp face, not a realized face. A face id of
6218 zero means no face is specified. */
6219 if (it
->dpvec_face_id
>= 0)
6220 it
->face_id
= it
->dpvec_face_id
;
6223 int lface_id
= GLYPH_CODE_FACE (gc
);
6225 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6230 /* Display table entry is invalid. Return a space. */
6231 it
->c
= ' ', it
->len
= 1;
6233 /* Don't change position and object of the iterator here. They are
6234 still the values of the character that had this display table
6235 entry or was translated, and that's what we want. */
6236 it
->what
= IT_CHARACTER
;
6241 /* Load IT with the next display element from Lisp string IT->string.
6242 IT->current.string_pos is the current position within the string.
6243 If IT->current.overlay_string_index >= 0, the Lisp string is an
6247 next_element_from_string (it
)
6250 struct text_pos position
;
6252 xassert (STRINGP (it
->string
));
6253 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6254 position
= it
->current
.string_pos
;
6256 /* Time to check for invisible text? */
6257 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6258 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6262 /* Since a handler may have changed IT->method, we must
6264 return GET_NEXT_DISPLAY_ELEMENT (it
);
6267 if (it
->current
.overlay_string_index
>= 0)
6269 /* Get the next character from an overlay string. In overlay
6270 strings, There is no field width or padding with spaces to
6272 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6277 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6278 IT_STRING_BYTEPOS (*it
))
6279 && next_element_from_composition (it
))
6283 else if (STRING_MULTIBYTE (it
->string
))
6285 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6286 const unsigned char *s
= (SDATA (it
->string
)
6287 + IT_STRING_BYTEPOS (*it
));
6288 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6292 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6298 /* Get the next character from a Lisp string that is not an
6299 overlay string. Such strings come from the mode line, for
6300 example. We may have to pad with spaces, or truncate the
6301 string. See also next_element_from_c_string. */
6302 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6307 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6309 /* Pad with spaces. */
6310 it
->c
= ' ', it
->len
= 1;
6311 CHARPOS (position
) = BYTEPOS (position
) = -1;
6313 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6314 IT_STRING_BYTEPOS (*it
))
6315 && next_element_from_composition (it
))
6319 else if (STRING_MULTIBYTE (it
->string
))
6321 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6322 const unsigned char *s
= (SDATA (it
->string
)
6323 + IT_STRING_BYTEPOS (*it
));
6324 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6328 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6333 /* Record what we have and where it came from. */
6334 it
->what
= IT_CHARACTER
;
6335 it
->object
= it
->string
;
6336 it
->position
= position
;
6341 /* Load IT with next display element from C string IT->s.
6342 IT->string_nchars is the maximum number of characters to return
6343 from the string. IT->end_charpos may be greater than
6344 IT->string_nchars when this function is called, in which case we
6345 may have to return padding spaces. Value is zero if end of string
6346 reached, including padding spaces. */
6349 next_element_from_c_string (it
)
6355 it
->what
= IT_CHARACTER
;
6356 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6359 /* IT's position can be greater IT->string_nchars in case a field
6360 width or precision has been specified when the iterator was
6362 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6364 /* End of the game. */
6368 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6370 /* Pad with spaces. */
6371 it
->c
= ' ', it
->len
= 1;
6372 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6374 else if (it
->multibyte_p
)
6376 /* Implementation note: The calls to strlen apparently aren't a
6377 performance problem because there is no noticeable performance
6378 difference between Emacs running in unibyte or multibyte mode. */
6379 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6380 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6384 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6390 /* Set up IT to return characters from an ellipsis, if appropriate.
6391 The definition of the ellipsis glyphs may come from a display table
6392 entry. This function Fills IT with the first glyph from the
6393 ellipsis if an ellipsis is to be displayed. */
6396 next_element_from_ellipsis (it
)
6399 if (it
->selective_display_ellipsis_p
)
6400 setup_for_ellipsis (it
, it
->len
);
6403 /* The face at the current position may be different from the
6404 face we find after the invisible text. Remember what it
6405 was in IT->saved_face_id, and signal that it's there by
6406 setting face_before_selective_p. */
6407 it
->saved_face_id
= it
->face_id
;
6408 it
->method
= GET_FROM_BUFFER
;
6409 it
->object
= it
->w
->buffer
;
6410 reseat_at_next_visible_line_start (it
, 1);
6411 it
->face_before_selective_p
= 1;
6414 return GET_NEXT_DISPLAY_ELEMENT (it
);
6418 /* Deliver an image display element. The iterator IT is already
6419 filled with image information (done in handle_display_prop). Value
6424 next_element_from_image (it
)
6427 it
->what
= IT_IMAGE
;
6432 /* Fill iterator IT with next display element from a stretch glyph
6433 property. IT->object is the value of the text property. Value is
6437 next_element_from_stretch (it
)
6440 it
->what
= IT_STRETCH
;
6445 /* Load IT with the next display element from current_buffer. Value
6446 is zero if end of buffer reached. IT->stop_charpos is the next
6447 position at which to stop and check for text properties or buffer
6451 next_element_from_buffer (it
)
6456 xassert (IT_CHARPOS (*it
) >= BEGV
);
6458 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6460 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6462 int overlay_strings_follow_p
;
6464 /* End of the game, except when overlay strings follow that
6465 haven't been returned yet. */
6466 if (it
->overlay_strings_at_end_processed_p
)
6467 overlay_strings_follow_p
= 0;
6470 it
->overlay_strings_at_end_processed_p
= 1;
6471 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6474 if (overlay_strings_follow_p
)
6475 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6479 it
->position
= it
->current
.pos
;
6486 return GET_NEXT_DISPLAY_ELEMENT (it
);
6491 /* No face changes, overlays etc. in sight, so just return a
6492 character from current_buffer. */
6495 /* Maybe run the redisplay end trigger hook. Performance note:
6496 This doesn't seem to cost measurable time. */
6497 if (it
->redisplay_end_trigger_charpos
6499 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6500 run_redisplay_end_trigger_hook (it
);
6502 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
))
6503 && next_element_from_composition (it
))
6508 /* Get the next character, maybe multibyte. */
6509 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6510 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6511 it
->c
= STRING_CHAR_AND_LENGTH (p
, 0, it
->len
);
6513 it
->c
= *p
, it
->len
= 1;
6515 /* Record what we have and where it came from. */
6516 it
->what
= IT_CHARACTER
;
6517 it
->object
= it
->w
->buffer
;
6518 it
->position
= it
->current
.pos
;
6520 /* Normally we return the character found above, except when we
6521 really want to return an ellipsis for selective display. */
6526 /* A value of selective > 0 means hide lines indented more
6527 than that number of columns. */
6528 if (it
->selective
> 0
6529 && IT_CHARPOS (*it
) + 1 < ZV
6530 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6531 IT_BYTEPOS (*it
) + 1,
6532 (double) it
->selective
)) /* iftc */
6534 success_p
= next_element_from_ellipsis (it
);
6535 it
->dpvec_char_len
= -1;
6538 else if (it
->c
== '\r' && it
->selective
== -1)
6540 /* A value of selective == -1 means that everything from the
6541 CR to the end of the line is invisible, with maybe an
6542 ellipsis displayed for it. */
6543 success_p
= next_element_from_ellipsis (it
);
6544 it
->dpvec_char_len
= -1;
6549 /* Value is zero if end of buffer reached. */
6550 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6555 /* Run the redisplay end trigger hook for IT. */
6558 run_redisplay_end_trigger_hook (it
)
6561 Lisp_Object args
[3];
6563 /* IT->glyph_row should be non-null, i.e. we should be actually
6564 displaying something, or otherwise we should not run the hook. */
6565 xassert (it
->glyph_row
);
6567 /* Set up hook arguments. */
6568 args
[0] = Qredisplay_end_trigger_functions
;
6569 args
[1] = it
->window
;
6570 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6571 it
->redisplay_end_trigger_charpos
= 0;
6573 /* Since we are *trying* to run these functions, don't try to run
6574 them again, even if they get an error. */
6575 it
->w
->redisplay_end_trigger
= Qnil
;
6576 Frun_hook_with_args (3, args
);
6578 /* Notice if it changed the face of the character we are on. */
6579 handle_face_prop (it
);
6583 /* Deliver a composition display element. Unlike the other
6584 next_element_from_XXX, this function is not registered in the array
6585 get_next_element[]. It is called from next_element_from_buffer and
6586 next_element_from_string when necessary. */
6589 next_element_from_composition (it
)
6592 it
->what
= IT_COMPOSITION
;
6593 it
->len
= it
->cmp_it
.nbytes
;
6594 if (STRINGP (it
->string
))
6598 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6599 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6602 it
->position
= it
->current
.string_pos
;
6603 it
->object
= it
->string
;
6604 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6605 IT_STRING_BYTEPOS (*it
), it
->string
);
6611 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6612 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6615 it
->position
= it
->current
.pos
;
6616 it
->object
= it
->w
->buffer
;
6617 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6618 IT_BYTEPOS (*it
), Qnil
);
6625 /***********************************************************************
6626 Moving an iterator without producing glyphs
6627 ***********************************************************************/
6629 /* Check if iterator is at a position corresponding to a valid buffer
6630 position after some move_it_ call. */
6632 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6633 ((it)->method == GET_FROM_STRING \
6634 ? IT_STRING_CHARPOS (*it) == 0 \
6638 /* Move iterator IT to a specified buffer or X position within one
6639 line on the display without producing glyphs.
6641 OP should be a bit mask including some or all of these bits:
6642 MOVE_TO_X: Stop on reaching x-position TO_X.
6643 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6644 Regardless of OP's value, stop in reaching the end of the display line.
6646 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6647 This means, in particular, that TO_X includes window's horizontal
6650 The return value has several possible values that
6651 say what condition caused the scan to stop:
6653 MOVE_POS_MATCH_OR_ZV
6654 - when TO_POS or ZV was reached.
6657 -when TO_X was reached before TO_POS or ZV were reached.
6660 - when we reached the end of the display area and the line must
6664 - when we reached the end of the display area and the line is
6668 - when we stopped at a line end, i.e. a newline or a CR and selective
6671 static enum move_it_result
6672 move_it_in_display_line_to (struct it
*it
,
6673 EMACS_INT to_charpos
, int to_x
,
6674 enum move_operation_enum op
)
6676 enum move_it_result result
= MOVE_UNDEFINED
;
6677 struct glyph_row
*saved_glyph_row
;
6678 struct it wrap_it
, atpos_it
, atx_it
;
6681 /* Don't produce glyphs in produce_glyphs. */
6682 saved_glyph_row
= it
->glyph_row
;
6683 it
->glyph_row
= NULL
;
6685 /* Use wrap_it to save a copy of IT wherever a word wrap could
6686 occur. Use atpos_it to save a copy of IT at the desired buffer
6687 position, if found, so that we can scan ahead and check if the
6688 word later overshoots the window edge. Use atx_it similarly, for
6694 #define BUFFER_POS_REACHED_P() \
6695 ((op & MOVE_TO_POS) != 0 \
6696 && BUFFERP (it->object) \
6697 && IT_CHARPOS (*it) >= to_charpos \
6698 && (it->method == GET_FROM_BUFFER \
6699 || (it->method == GET_FROM_DISPLAY_VECTOR \
6700 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6702 /* If there's a line-/wrap-prefix, handle it. */
6703 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6704 && it
->current_y
< it
->last_visible_y
)
6705 handle_line_prefix (it
);
6709 int x
, i
, ascent
= 0, descent
= 0;
6711 /* Utility macro to reset an iterator with x, ascent, and descent. */
6712 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6713 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6714 (IT)->max_descent = descent)
6716 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6718 if ((op
& MOVE_TO_POS
) != 0
6719 && BUFFERP (it
->object
)
6720 && it
->method
== GET_FROM_BUFFER
6721 && IT_CHARPOS (*it
) > to_charpos
)
6723 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6725 result
= MOVE_POS_MATCH_OR_ZV
;
6728 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6729 /* If wrap_it is valid, the current position might be in a
6730 word that is wrapped. So, save the iterator in
6731 atpos_it and continue to see if wrapping happens. */
6735 /* Stop when ZV reached.
6736 We used to stop here when TO_CHARPOS reached as well, but that is
6737 too soon if this glyph does not fit on this line. So we handle it
6738 explicitly below. */
6739 if (!get_next_display_element (it
))
6741 result
= MOVE_POS_MATCH_OR_ZV
;
6745 if (it
->line_wrap
== TRUNCATE
)
6747 if (BUFFER_POS_REACHED_P ())
6749 result
= MOVE_POS_MATCH_OR_ZV
;
6755 if (it
->line_wrap
== WORD_WRAP
)
6757 if (IT_DISPLAYING_WHITESPACE (it
))
6761 /* We have reached a glyph that follows one or more
6762 whitespace characters. If the position is
6763 already found, we are done. */
6764 if (atpos_it
.sp
>= 0)
6767 result
= MOVE_POS_MATCH_OR_ZV
;
6773 result
= MOVE_X_REACHED
;
6776 /* Otherwise, we can wrap here. */
6783 /* Remember the line height for the current line, in case
6784 the next element doesn't fit on the line. */
6785 ascent
= it
->max_ascent
;
6786 descent
= it
->max_descent
;
6788 /* The call to produce_glyphs will get the metrics of the
6789 display element IT is loaded with. Record the x-position
6790 before this display element, in case it doesn't fit on the
6794 PRODUCE_GLYPHS (it
);
6796 if (it
->area
!= TEXT_AREA
)
6798 set_iterator_to_next (it
, 1);
6802 /* The number of glyphs we get back in IT->nglyphs will normally
6803 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6804 character on a terminal frame, or (iii) a line end. For the
6805 second case, IT->nglyphs - 1 padding glyphs will be present
6806 (on X frames, there is only one glyph produced for a
6807 composite character.
6809 The behavior implemented below means, for continuation lines,
6810 that as many spaces of a TAB as fit on the current line are
6811 displayed there. For terminal frames, as many glyphs of a
6812 multi-glyph character are displayed in the current line, too.
6813 This is what the old redisplay code did, and we keep it that
6814 way. Under X, the whole shape of a complex character must
6815 fit on the line or it will be completely displayed in the
6818 Note that both for tabs and padding glyphs, all glyphs have
6822 /* More than one glyph or glyph doesn't fit on line. All
6823 glyphs have the same width. */
6824 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6826 int x_before_this_char
= x
;
6827 int hpos_before_this_char
= it
->hpos
;
6829 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6831 new_x
= x
+ single_glyph_width
;
6833 /* We want to leave anything reaching TO_X to the caller. */
6834 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6836 if (BUFFER_POS_REACHED_P ())
6838 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6839 goto buffer_pos_reached
;
6840 if (atpos_it
.sp
< 0)
6843 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6848 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6851 result
= MOVE_X_REACHED
;
6857 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6862 if (/* Lines are continued. */
6863 it
->line_wrap
!= TRUNCATE
6864 && (/* And glyph doesn't fit on the line. */
6865 new_x
> it
->last_visible_x
6866 /* Or it fits exactly and we're on a window
6868 || (new_x
== it
->last_visible_x
6869 && FRAME_WINDOW_P (it
->f
))))
6871 if (/* IT->hpos == 0 means the very first glyph
6872 doesn't fit on the line, e.g. a wide image. */
6874 || (new_x
== it
->last_visible_x
6875 && FRAME_WINDOW_P (it
->f
)))
6878 it
->current_x
= new_x
;
6880 /* The character's last glyph just barely fits
6882 if (i
== it
->nglyphs
- 1)
6884 /* If this is the destination position,
6885 return a position *before* it in this row,
6886 now that we know it fits in this row. */
6887 if (BUFFER_POS_REACHED_P ())
6889 if (it
->line_wrap
!= WORD_WRAP
6892 it
->hpos
= hpos_before_this_char
;
6893 it
->current_x
= x_before_this_char
;
6894 result
= MOVE_POS_MATCH_OR_ZV
;
6897 if (it
->line_wrap
== WORD_WRAP
6901 atpos_it
.current_x
= x_before_this_char
;
6902 atpos_it
.hpos
= hpos_before_this_char
;
6906 set_iterator_to_next (it
, 1);
6907 /* One graphical terminals, newlines may
6908 "overflow" into the fringe if
6909 overflow-newline-into-fringe is non-nil.
6910 On text-only terminals, newlines may
6911 overflow into the last glyph on the
6913 if (!FRAME_WINDOW_P (it
->f
)
6914 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6916 if (!get_next_display_element (it
))
6918 result
= MOVE_POS_MATCH_OR_ZV
;
6921 if (BUFFER_POS_REACHED_P ())
6923 if (ITERATOR_AT_END_OF_LINE_P (it
))
6924 result
= MOVE_POS_MATCH_OR_ZV
;
6926 result
= MOVE_LINE_CONTINUED
;
6929 if (ITERATOR_AT_END_OF_LINE_P (it
))
6931 result
= MOVE_NEWLINE_OR_CR
;
6938 IT_RESET_X_ASCENT_DESCENT (it
);
6940 if (wrap_it
.sp
>= 0)
6947 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6949 result
= MOVE_LINE_CONTINUED
;
6953 if (BUFFER_POS_REACHED_P ())
6955 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6956 goto buffer_pos_reached
;
6957 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6960 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6964 if (new_x
> it
->first_visible_x
)
6966 /* Glyph is visible. Increment number of glyphs that
6967 would be displayed. */
6972 if (result
!= MOVE_UNDEFINED
)
6975 else if (BUFFER_POS_REACHED_P ())
6978 IT_RESET_X_ASCENT_DESCENT (it
);
6979 result
= MOVE_POS_MATCH_OR_ZV
;
6982 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6984 /* Stop when TO_X specified and reached. This check is
6985 necessary here because of lines consisting of a line end,
6986 only. The line end will not produce any glyphs and we
6987 would never get MOVE_X_REACHED. */
6988 xassert (it
->nglyphs
== 0);
6989 result
= MOVE_X_REACHED
;
6993 /* Is this a line end? If yes, we're done. */
6994 if (ITERATOR_AT_END_OF_LINE_P (it
))
6996 result
= MOVE_NEWLINE_OR_CR
;
7000 /* The current display element has been consumed. Advance
7002 set_iterator_to_next (it
, 1);
7004 /* Stop if lines are truncated and IT's current x-position is
7005 past the right edge of the window now. */
7006 if (it
->line_wrap
== TRUNCATE
7007 && it
->current_x
>= it
->last_visible_x
)
7009 if (!FRAME_WINDOW_P (it
->f
)
7010 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7012 if (!get_next_display_element (it
)
7013 || BUFFER_POS_REACHED_P ())
7015 result
= MOVE_POS_MATCH_OR_ZV
;
7018 if (ITERATOR_AT_END_OF_LINE_P (it
))
7020 result
= MOVE_NEWLINE_OR_CR
;
7024 result
= MOVE_LINE_TRUNCATED
;
7027 #undef IT_RESET_X_ASCENT_DESCENT
7030 #undef BUFFER_POS_REACHED_P
7032 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7033 restore the saved iterator. */
7034 if (atpos_it
.sp
>= 0)
7036 else if (atx_it
.sp
>= 0)
7041 /* Restore the iterator settings altered at the beginning of this
7043 it
->glyph_row
= saved_glyph_row
;
7047 /* For external use. */
7049 move_it_in_display_line (struct it
*it
,
7050 EMACS_INT to_charpos
, int to_x
,
7051 enum move_operation_enum op
)
7053 if (it
->line_wrap
== WORD_WRAP
7054 && (op
& MOVE_TO_X
))
7056 struct it save_it
= *it
;
7057 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7058 /* When word-wrap is on, TO_X may lie past the end
7059 of a wrapped line. Then it->current is the
7060 character on the next line, so backtrack to the
7061 space before the wrap point. */
7062 if (skip
== MOVE_LINE_CONTINUED
)
7064 int prev_x
= max (it
->current_x
- 1, 0);
7066 move_it_in_display_line_to
7067 (it
, -1, prev_x
, MOVE_TO_X
);
7071 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7075 /* Move IT forward until it satisfies one or more of the criteria in
7076 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7078 OP is a bit-mask that specifies where to stop, and in particular,
7079 which of those four position arguments makes a difference. See the
7080 description of enum move_operation_enum.
7082 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7083 screen line, this function will set IT to the next position >
7087 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7089 int to_charpos
, to_x
, to_y
, to_vpos
;
7092 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7093 int line_height
, line_start_x
= 0, reached
= 0;
7097 if (op
& MOVE_TO_VPOS
)
7099 /* If no TO_CHARPOS and no TO_X specified, stop at the
7100 start of the line TO_VPOS. */
7101 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7103 if (it
->vpos
== to_vpos
)
7109 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7113 /* TO_VPOS >= 0 means stop at TO_X in the line at
7114 TO_VPOS, or at TO_POS, whichever comes first. */
7115 if (it
->vpos
== to_vpos
)
7121 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7123 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7128 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7130 /* We have reached TO_X but not in the line we want. */
7131 skip
= move_it_in_display_line_to (it
, to_charpos
,
7133 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7141 else if (op
& MOVE_TO_Y
)
7143 struct it it_backup
;
7145 if (it
->line_wrap
== WORD_WRAP
)
7148 /* TO_Y specified means stop at TO_X in the line containing
7149 TO_Y---or at TO_CHARPOS if this is reached first. The
7150 problem is that we can't really tell whether the line
7151 contains TO_Y before we have completely scanned it, and
7152 this may skip past TO_X. What we do is to first scan to
7155 If TO_X is not specified, use a TO_X of zero. The reason
7156 is to make the outcome of this function more predictable.
7157 If we didn't use TO_X == 0, we would stop at the end of
7158 the line which is probably not what a caller would expect
7160 skip
= move_it_in_display_line_to
7161 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7162 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7164 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7165 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7167 else if (skip
== MOVE_X_REACHED
)
7169 /* If TO_X was reached, we want to know whether TO_Y is
7170 in the line. We know this is the case if the already
7171 scanned glyphs make the line tall enough. Otherwise,
7172 we must check by scanning the rest of the line. */
7173 line_height
= it
->max_ascent
+ it
->max_descent
;
7174 if (to_y
>= it
->current_y
7175 && to_y
< it
->current_y
+ line_height
)
7181 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7182 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7184 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7185 line_height
= it
->max_ascent
+ it
->max_descent
;
7186 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7188 if (to_y
>= it
->current_y
7189 && to_y
< it
->current_y
+ line_height
)
7191 /* If TO_Y is in this line and TO_X was reached
7192 above, we scanned too far. We have to restore
7193 IT's settings to the ones before skipping. */
7200 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7206 /* Check whether TO_Y is in this line. */
7207 line_height
= it
->max_ascent
+ it
->max_descent
;
7208 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7210 if (to_y
>= it
->current_y
7211 && to_y
< it
->current_y
+ line_height
)
7213 /* When word-wrap is on, TO_X may lie past the end
7214 of a wrapped line. Then it->current is the
7215 character on the next line, so backtrack to the
7216 space before the wrap point. */
7217 if (skip
== MOVE_LINE_CONTINUED
7218 && it
->line_wrap
== WORD_WRAP
)
7220 int prev_x
= max (it
->current_x
- 1, 0);
7222 skip
= move_it_in_display_line_to
7223 (it
, -1, prev_x
, MOVE_TO_X
);
7232 else if (BUFFERP (it
->object
)
7233 && (it
->method
== GET_FROM_BUFFER
7234 || it
->method
== GET_FROM_STRETCH
)
7235 && IT_CHARPOS (*it
) >= to_charpos
)
7236 skip
= MOVE_POS_MATCH_OR_ZV
;
7238 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7242 case MOVE_POS_MATCH_OR_ZV
:
7246 case MOVE_NEWLINE_OR_CR
:
7247 set_iterator_to_next (it
, 1);
7248 it
->continuation_lines_width
= 0;
7251 case MOVE_LINE_TRUNCATED
:
7252 it
->continuation_lines_width
= 0;
7253 reseat_at_next_visible_line_start (it
, 0);
7254 if ((op
& MOVE_TO_POS
) != 0
7255 && IT_CHARPOS (*it
) > to_charpos
)
7262 case MOVE_LINE_CONTINUED
:
7263 /* For continued lines ending in a tab, some of the glyphs
7264 associated with the tab are displayed on the current
7265 line. Since it->current_x does not include these glyphs,
7266 we use it->last_visible_x instead. */
7269 it
->continuation_lines_width
+= it
->last_visible_x
;
7270 /* When moving by vpos, ensure that the iterator really
7271 advances to the next line (bug#847, bug#969). Fixme:
7272 do we need to do this in other circumstances? */
7273 if (it
->current_x
!= it
->last_visible_x
7274 && (op
& MOVE_TO_VPOS
)
7275 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7277 line_start_x
= it
->current_x
+ it
->pixel_width
7278 - it
->last_visible_x
;
7279 set_iterator_to_next (it
, 0);
7283 it
->continuation_lines_width
+= it
->current_x
;
7290 /* Reset/increment for the next run. */
7291 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7292 it
->current_x
= line_start_x
;
7295 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7297 last_height
= it
->max_ascent
+ it
->max_descent
;
7298 last_max_ascent
= it
->max_ascent
;
7299 it
->max_ascent
= it
->max_descent
= 0;
7304 /* On text terminals, we may stop at the end of a line in the middle
7305 of a multi-character glyph. If the glyph itself is continued,
7306 i.e. it is actually displayed on the next line, don't treat this
7307 stopping point as valid; move to the next line instead (unless
7308 that brings us offscreen). */
7309 if (!FRAME_WINDOW_P (it
->f
)
7311 && IT_CHARPOS (*it
) == to_charpos
7312 && it
->what
== IT_CHARACTER
7314 && it
->line_wrap
== WINDOW_WRAP
7315 && it
->current_x
== it
->last_visible_x
- 1
7318 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7320 it
->continuation_lines_width
+= it
->current_x
;
7321 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7322 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7324 last_height
= it
->max_ascent
+ it
->max_descent
;
7325 last_max_ascent
= it
->max_ascent
;
7328 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7332 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7334 If DY > 0, move IT backward at least that many pixels. DY = 0
7335 means move IT backward to the preceding line start or BEGV. This
7336 function may move over more than DY pixels if IT->current_y - DY
7337 ends up in the middle of a line; in this case IT->current_y will be
7338 set to the top of the line moved to. */
7341 move_it_vertically_backward (it
, dy
)
7352 start_pos
= IT_CHARPOS (*it
);
7354 /* Estimate how many newlines we must move back. */
7355 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7357 /* Set the iterator's position that many lines back. */
7358 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7359 back_to_previous_visible_line_start (it
);
7361 /* Reseat the iterator here. When moving backward, we don't want
7362 reseat to skip forward over invisible text, set up the iterator
7363 to deliver from overlay strings at the new position etc. So,
7364 use reseat_1 here. */
7365 reseat_1 (it
, it
->current
.pos
, 1);
7367 /* We are now surely at a line start. */
7368 it
->current_x
= it
->hpos
= 0;
7369 it
->continuation_lines_width
= 0;
7371 /* Move forward and see what y-distance we moved. First move to the
7372 start of the next line so that we get its height. We need this
7373 height to be able to tell whether we reached the specified
7376 it2
.max_ascent
= it2
.max_descent
= 0;
7379 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7380 MOVE_TO_POS
| MOVE_TO_VPOS
);
7382 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7383 xassert (IT_CHARPOS (*it
) >= BEGV
);
7386 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7387 xassert (IT_CHARPOS (*it
) >= BEGV
);
7388 /* H is the actual vertical distance from the position in *IT
7389 and the starting position. */
7390 h
= it2
.current_y
- it
->current_y
;
7391 /* NLINES is the distance in number of lines. */
7392 nlines
= it2
.vpos
- it
->vpos
;
7394 /* Correct IT's y and vpos position
7395 so that they are relative to the starting point. */
7401 /* DY == 0 means move to the start of the screen line. The
7402 value of nlines is > 0 if continuation lines were involved. */
7404 move_it_by_lines (it
, nlines
, 1);
7408 /* The y-position we try to reach, relative to *IT.
7409 Note that H has been subtracted in front of the if-statement. */
7410 int target_y
= it
->current_y
+ h
- dy
;
7411 int y0
= it3
.current_y
;
7412 int y1
= line_bottom_y (&it3
);
7413 int line_height
= y1
- y0
;
7415 /* If we did not reach target_y, try to move further backward if
7416 we can. If we moved too far backward, try to move forward. */
7417 if (target_y
< it
->current_y
7418 /* This is heuristic. In a window that's 3 lines high, with
7419 a line height of 13 pixels each, recentering with point
7420 on the bottom line will try to move -39/2 = 19 pixels
7421 backward. Try to avoid moving into the first line. */
7422 && (it
->current_y
- target_y
7423 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7424 && IT_CHARPOS (*it
) > BEGV
)
7426 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7427 target_y
- it
->current_y
));
7428 dy
= it
->current_y
- target_y
;
7429 goto move_further_back
;
7431 else if (target_y
>= it
->current_y
+ line_height
7432 && IT_CHARPOS (*it
) < ZV
)
7434 /* Should move forward by at least one line, maybe more.
7436 Note: Calling move_it_by_lines can be expensive on
7437 terminal frames, where compute_motion is used (via
7438 vmotion) to do the job, when there are very long lines
7439 and truncate-lines is nil. That's the reason for
7440 treating terminal frames specially here. */
7442 if (!FRAME_WINDOW_P (it
->f
))
7443 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7448 move_it_by_lines (it
, 1, 1);
7450 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7457 /* Move IT by a specified amount of pixel lines DY. DY negative means
7458 move backwards. DY = 0 means move to start of screen line. At the
7459 end, IT will be on the start of a screen line. */
7462 move_it_vertically (it
, dy
)
7467 move_it_vertically_backward (it
, -dy
);
7470 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7471 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7472 MOVE_TO_POS
| MOVE_TO_Y
);
7473 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7475 /* If buffer ends in ZV without a newline, move to the start of
7476 the line to satisfy the post-condition. */
7477 if (IT_CHARPOS (*it
) == ZV
7479 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7480 move_it_by_lines (it
, 0, 0);
7485 /* Move iterator IT past the end of the text line it is in. */
7488 move_it_past_eol (it
)
7491 enum move_it_result rc
;
7493 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7494 if (rc
== MOVE_NEWLINE_OR_CR
)
7495 set_iterator_to_next (it
, 0);
7499 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7500 negative means move up. DVPOS == 0 means move to the start of the
7501 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7502 NEED_Y_P is zero, IT->current_y will be left unchanged.
7504 Further optimization ideas: If we would know that IT->f doesn't use
7505 a face with proportional font, we could be faster for
7506 truncate-lines nil. */
7509 move_it_by_lines (it
, dvpos
, need_y_p
)
7511 int dvpos
, need_y_p
;
7513 struct position pos
;
7515 /* The commented-out optimization uses vmotion on terminals. This
7516 gives bad results, because elements like it->what, on which
7517 callers such as pos_visible_p rely, aren't updated. */
7518 /* if (!FRAME_WINDOW_P (it->f))
7520 struct text_pos textpos;
7522 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7523 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7524 reseat (it, textpos, 1);
7525 it->vpos += pos.vpos;
7526 it->current_y += pos.vpos;
7532 /* DVPOS == 0 means move to the start of the screen line. */
7533 move_it_vertically_backward (it
, 0);
7534 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7535 /* Let next call to line_bottom_y calculate real line height */
7540 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7541 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7542 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7547 int start_charpos
, i
;
7549 /* Start at the beginning of the screen line containing IT's
7550 position. This may actually move vertically backwards,
7551 in case of overlays, so adjust dvpos accordingly. */
7553 move_it_vertically_backward (it
, 0);
7556 /* Go back -DVPOS visible lines and reseat the iterator there. */
7557 start_charpos
= IT_CHARPOS (*it
);
7558 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7559 back_to_previous_visible_line_start (it
);
7560 reseat (it
, it
->current
.pos
, 1);
7562 /* Move further back if we end up in a string or an image. */
7563 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7565 /* First try to move to start of display line. */
7567 move_it_vertically_backward (it
, 0);
7569 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7571 /* If start of line is still in string or image,
7572 move further back. */
7573 back_to_previous_visible_line_start (it
);
7574 reseat (it
, it
->current
.pos
, 1);
7578 it
->current_x
= it
->hpos
= 0;
7580 /* Above call may have moved too far if continuation lines
7581 are involved. Scan forward and see if it did. */
7583 it2
.vpos
= it2
.current_y
= 0;
7584 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7585 it
->vpos
-= it2
.vpos
;
7586 it
->current_y
-= it2
.current_y
;
7587 it
->current_x
= it
->hpos
= 0;
7589 /* If we moved too far back, move IT some lines forward. */
7590 if (it2
.vpos
> -dvpos
)
7592 int delta
= it2
.vpos
+ dvpos
;
7594 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7595 /* Move back again if we got too far ahead. */
7596 if (IT_CHARPOS (*it
) >= start_charpos
)
7602 /* Return 1 if IT points into the middle of a display vector. */
7605 in_display_vector_p (it
)
7608 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7609 && it
->current
.dpvec_index
> 0
7610 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7614 /***********************************************************************
7616 ***********************************************************************/
7619 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7623 add_to_log (format
, arg1
, arg2
)
7625 Lisp_Object arg1
, arg2
;
7627 Lisp_Object args
[3];
7628 Lisp_Object msg
, fmt
;
7631 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7634 /* Do nothing if called asynchronously. Inserting text into
7635 a buffer may call after-change-functions and alike and
7636 that would means running Lisp asynchronously. */
7637 if (handling_signal
)
7641 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7643 args
[0] = fmt
= build_string (format
);
7646 msg
= Fformat (3, args
);
7648 len
= SBYTES (msg
) + 1;
7649 SAFE_ALLOCA (buffer
, char *, len
);
7650 bcopy (SDATA (msg
), buffer
, len
);
7652 message_dolog (buffer
, len
- 1, 1, 0);
7659 /* Output a newline in the *Messages* buffer if "needs" one. */
7662 message_log_maybe_newline ()
7664 if (message_log_need_newline
)
7665 message_dolog ("", 0, 1, 0);
7669 /* Add a string M of length NBYTES to the message log, optionally
7670 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7671 nonzero, means interpret the contents of M as multibyte. This
7672 function calls low-level routines in order to bypass text property
7673 hooks, etc. which might not be safe to run.
7675 This may GC (insert may run before/after change hooks),
7676 so the buffer M must NOT point to a Lisp string. */
7679 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7681 int nbytes
, nlflag
, multibyte
;
7683 if (!NILP (Vmemory_full
))
7686 if (!NILP (Vmessage_log_max
))
7688 struct buffer
*oldbuf
;
7689 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7690 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7691 int point_at_end
= 0;
7693 Lisp_Object old_deactivate_mark
, tem
;
7694 struct gcpro gcpro1
;
7696 old_deactivate_mark
= Vdeactivate_mark
;
7697 oldbuf
= current_buffer
;
7698 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7699 current_buffer
->undo_list
= Qt
;
7701 oldpoint
= message_dolog_marker1
;
7702 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7703 oldbegv
= message_dolog_marker2
;
7704 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7705 oldzv
= message_dolog_marker3
;
7706 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7707 GCPRO1 (old_deactivate_mark
);
7715 BEGV_BYTE
= BEG_BYTE
;
7718 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7720 /* Insert the string--maybe converting multibyte to single byte
7721 or vice versa, so that all the text fits the buffer. */
7723 && NILP (current_buffer
->enable_multibyte_characters
))
7725 int i
, c
, char_bytes
;
7726 unsigned char work
[1];
7728 /* Convert a multibyte string to single-byte
7729 for the *Message* buffer. */
7730 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7732 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7733 work
[0] = (ASCII_CHAR_P (c
)
7735 : multibyte_char_to_unibyte (c
, Qnil
));
7736 insert_1_both (work
, 1, 1, 1, 0, 0);
7739 else if (! multibyte
7740 && ! NILP (current_buffer
->enable_multibyte_characters
))
7742 int i
, c
, char_bytes
;
7743 unsigned char *msg
= (unsigned char *) m
;
7744 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7745 /* Convert a single-byte string to multibyte
7746 for the *Message* buffer. */
7747 for (i
= 0; i
< nbytes
; i
++)
7750 c
= unibyte_char_to_multibyte (c
);
7751 char_bytes
= CHAR_STRING (c
, str
);
7752 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7756 insert_1 (m
, nbytes
, 1, 0, 0);
7760 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7761 insert_1 ("\n", 1, 1, 0, 0);
7763 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7765 this_bol_byte
= PT_BYTE
;
7767 /* See if this line duplicates the previous one.
7768 If so, combine duplicates. */
7771 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7773 prev_bol_byte
= PT_BYTE
;
7775 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7776 this_bol
, this_bol_byte
);
7779 del_range_both (prev_bol
, prev_bol_byte
,
7780 this_bol
, this_bol_byte
, 0);
7786 /* If you change this format, don't forget to also
7787 change message_log_check_duplicate. */
7788 sprintf (dupstr
, " [%d times]", dup
);
7789 duplen
= strlen (dupstr
);
7790 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7791 insert_1 (dupstr
, duplen
, 1, 0, 1);
7796 /* If we have more than the desired maximum number of lines
7797 in the *Messages* buffer now, delete the oldest ones.
7798 This is safe because we don't have undo in this buffer. */
7800 if (NATNUMP (Vmessage_log_max
))
7802 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7803 -XFASTINT (Vmessage_log_max
) - 1, 0);
7804 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7807 BEGV
= XMARKER (oldbegv
)->charpos
;
7808 BEGV_BYTE
= marker_byte_position (oldbegv
);
7817 ZV
= XMARKER (oldzv
)->charpos
;
7818 ZV_BYTE
= marker_byte_position (oldzv
);
7822 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7824 /* We can't do Fgoto_char (oldpoint) because it will run some
7826 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7827 XMARKER (oldpoint
)->bytepos
);
7830 unchain_marker (XMARKER (oldpoint
));
7831 unchain_marker (XMARKER (oldbegv
));
7832 unchain_marker (XMARKER (oldzv
));
7834 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7835 set_buffer_internal (oldbuf
);
7837 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7838 message_log_need_newline
= !nlflag
;
7839 Vdeactivate_mark
= old_deactivate_mark
;
7844 /* We are at the end of the buffer after just having inserted a newline.
7845 (Note: We depend on the fact we won't be crossing the gap.)
7846 Check to see if the most recent message looks a lot like the previous one.
7847 Return 0 if different, 1 if the new one should just replace it, or a
7848 value N > 1 if we should also append " [N times]". */
7851 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7852 int prev_bol
, this_bol
;
7853 int prev_bol_byte
, this_bol_byte
;
7856 int len
= Z_BYTE
- 1 - this_bol_byte
;
7858 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7859 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7861 for (i
= 0; i
< len
; i
++)
7863 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7871 if (*p1
++ == ' ' && *p1
++ == '[')
7874 while (*p1
>= '0' && *p1
<= '9')
7875 n
= n
* 10 + *p1
++ - '0';
7876 if (strncmp (p1
, " times]\n", 8) == 0)
7883 /* Display an echo area message M with a specified length of NBYTES
7884 bytes. The string may include null characters. If M is 0, clear
7885 out any existing message, and let the mini-buffer text show
7888 This may GC, so the buffer M must NOT point to a Lisp string. */
7891 message2 (m
, nbytes
, multibyte
)
7896 /* First flush out any partial line written with print. */
7897 message_log_maybe_newline ();
7899 message_dolog (m
, nbytes
, 1, multibyte
);
7900 message2_nolog (m
, nbytes
, multibyte
);
7904 /* The non-logging counterpart of message2. */
7907 message2_nolog (m
, nbytes
, multibyte
)
7909 int nbytes
, multibyte
;
7911 struct frame
*sf
= SELECTED_FRAME ();
7912 message_enable_multibyte
= multibyte
;
7914 if (FRAME_INITIAL_P (sf
))
7916 if (noninteractive_need_newline
)
7917 putc ('\n', stderr
);
7918 noninteractive_need_newline
= 0;
7920 fwrite (m
, nbytes
, 1, stderr
);
7921 if (cursor_in_echo_area
== 0)
7922 fprintf (stderr
, "\n");
7925 /* A null message buffer means that the frame hasn't really been
7926 initialized yet. Error messages get reported properly by
7927 cmd_error, so this must be just an informative message; toss it. */
7928 else if (INTERACTIVE
7929 && sf
->glyphs_initialized_p
7930 && FRAME_MESSAGE_BUF (sf
))
7932 Lisp_Object mini_window
;
7935 /* Get the frame containing the mini-buffer
7936 that the selected frame is using. */
7937 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7938 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7940 FRAME_SAMPLE_VISIBILITY (f
);
7941 if (FRAME_VISIBLE_P (sf
)
7942 && ! FRAME_VISIBLE_P (f
))
7943 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7947 set_message (m
, Qnil
, nbytes
, multibyte
);
7948 if (minibuffer_auto_raise
)
7949 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7952 clear_message (1, 1);
7954 do_pending_window_change (0);
7955 echo_area_display (1);
7956 do_pending_window_change (0);
7957 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7958 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7963 /* Display an echo area message M with a specified length of NBYTES
7964 bytes. The string may include null characters. If M is not a
7965 string, clear out any existing message, and let the mini-buffer
7968 This function cancels echoing. */
7971 message3 (m
, nbytes
, multibyte
)
7976 struct gcpro gcpro1
;
7979 clear_message (1,1);
7982 /* First flush out any partial line written with print. */
7983 message_log_maybe_newline ();
7989 SAFE_ALLOCA (buffer
, char *, nbytes
);
7990 bcopy (SDATA (m
), buffer
, nbytes
);
7991 message_dolog (buffer
, nbytes
, 1, multibyte
);
7994 message3_nolog (m
, nbytes
, multibyte
);
8000 /* The non-logging version of message3.
8001 This does not cancel echoing, because it is used for echoing.
8002 Perhaps we need to make a separate function for echoing
8003 and make this cancel echoing. */
8006 message3_nolog (m
, nbytes
, multibyte
)
8008 int nbytes
, multibyte
;
8010 struct frame
*sf
= SELECTED_FRAME ();
8011 message_enable_multibyte
= multibyte
;
8013 if (FRAME_INITIAL_P (sf
))
8015 if (noninteractive_need_newline
)
8016 putc ('\n', stderr
);
8017 noninteractive_need_newline
= 0;
8019 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8020 if (cursor_in_echo_area
== 0)
8021 fprintf (stderr
, "\n");
8024 /* A null message buffer means that the frame hasn't really been
8025 initialized yet. Error messages get reported properly by
8026 cmd_error, so this must be just an informative message; toss it. */
8027 else if (INTERACTIVE
8028 && sf
->glyphs_initialized_p
8029 && FRAME_MESSAGE_BUF (sf
))
8031 Lisp_Object mini_window
;
8035 /* Get the frame containing the mini-buffer
8036 that the selected frame is using. */
8037 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8038 frame
= XWINDOW (mini_window
)->frame
;
8041 FRAME_SAMPLE_VISIBILITY (f
);
8042 if (FRAME_VISIBLE_P (sf
)
8043 && !FRAME_VISIBLE_P (f
))
8044 Fmake_frame_visible (frame
);
8046 if (STRINGP (m
) && SCHARS (m
) > 0)
8048 set_message (NULL
, m
, nbytes
, multibyte
);
8049 if (minibuffer_auto_raise
)
8050 Fraise_frame (frame
);
8051 /* Assume we are not echoing.
8052 (If we are, echo_now will override this.) */
8053 echo_message_buffer
= Qnil
;
8056 clear_message (1, 1);
8058 do_pending_window_change (0);
8059 echo_area_display (1);
8060 do_pending_window_change (0);
8061 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8062 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8067 /* Display a null-terminated echo area message M. If M is 0, clear
8068 out any existing message, and let the mini-buffer text show through.
8070 The buffer M must continue to exist until after the echo area gets
8071 cleared or some other message gets displayed there. Do not pass
8072 text that is stored in a Lisp string. Do not pass text in a buffer
8073 that was alloca'd. */
8079 message2 (m
, (m
? strlen (m
) : 0), 0);
8083 /* The non-logging counterpart of message1. */
8089 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8092 /* Display a message M which contains a single %s
8093 which gets replaced with STRING. */
8096 message_with_string (m
, string
, log
)
8101 CHECK_STRING (string
);
8107 if (noninteractive_need_newline
)
8108 putc ('\n', stderr
);
8109 noninteractive_need_newline
= 0;
8110 fprintf (stderr
, m
, SDATA (string
));
8111 if (!cursor_in_echo_area
)
8112 fprintf (stderr
, "\n");
8116 else if (INTERACTIVE
)
8118 /* The frame whose minibuffer we're going to display the message on.
8119 It may be larger than the selected frame, so we need
8120 to use its buffer, not the selected frame's buffer. */
8121 Lisp_Object mini_window
;
8122 struct frame
*f
, *sf
= SELECTED_FRAME ();
8124 /* Get the frame containing the minibuffer
8125 that the selected frame is using. */
8126 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8127 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8129 /* A null message buffer means that the frame hasn't really been
8130 initialized yet. Error messages get reported properly by
8131 cmd_error, so this must be just an informative message; toss it. */
8132 if (FRAME_MESSAGE_BUF (f
))
8134 Lisp_Object args
[2], message
;
8135 struct gcpro gcpro1
, gcpro2
;
8137 args
[0] = build_string (m
);
8138 args
[1] = message
= string
;
8139 GCPRO2 (args
[0], message
);
8142 message
= Fformat (2, args
);
8145 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8147 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8151 /* Print should start at the beginning of the message
8152 buffer next time. */
8153 message_buf_print
= 0;
8159 /* Dump an informative message to the minibuf. If M is 0, clear out
8160 any existing message, and let the mini-buffer text show through. */
8164 message (m
, a1
, a2
, a3
)
8166 EMACS_INT a1
, a2
, a3
;
8172 if (noninteractive_need_newline
)
8173 putc ('\n', stderr
);
8174 noninteractive_need_newline
= 0;
8175 fprintf (stderr
, m
, a1
, a2
, a3
);
8176 if (cursor_in_echo_area
== 0)
8177 fprintf (stderr
, "\n");
8181 else if (INTERACTIVE
)
8183 /* The frame whose mini-buffer we're going to display the message
8184 on. It may be larger than the selected frame, so we need to
8185 use its buffer, not the selected frame's buffer. */
8186 Lisp_Object mini_window
;
8187 struct frame
*f
, *sf
= SELECTED_FRAME ();
8189 /* Get the frame containing the mini-buffer
8190 that the selected frame is using. */
8191 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8192 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8194 /* A null message buffer means that the frame hasn't really been
8195 initialized yet. Error messages get reported properly by
8196 cmd_error, so this must be just an informative message; toss
8198 if (FRAME_MESSAGE_BUF (f
))
8209 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8210 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8212 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8213 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8215 #endif /* NO_ARG_ARRAY */
8217 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8222 /* Print should start at the beginning of the message
8223 buffer next time. */
8224 message_buf_print
= 0;
8230 /* The non-logging version of message. */
8233 message_nolog (m
, a1
, a2
, a3
)
8235 EMACS_INT a1
, a2
, a3
;
8237 Lisp_Object old_log_max
;
8238 old_log_max
= Vmessage_log_max
;
8239 Vmessage_log_max
= Qnil
;
8240 message (m
, a1
, a2
, a3
);
8241 Vmessage_log_max
= old_log_max
;
8245 /* Display the current message in the current mini-buffer. This is
8246 only called from error handlers in process.c, and is not time
8252 if (!NILP (echo_area_buffer
[0]))
8255 string
= Fcurrent_message ();
8256 message3 (string
, SBYTES (string
),
8257 !NILP (current_buffer
->enable_multibyte_characters
));
8262 /* Make sure echo area buffers in `echo_buffers' are live.
8263 If they aren't, make new ones. */
8266 ensure_echo_area_buffers ()
8270 for (i
= 0; i
< 2; ++i
)
8271 if (!BUFFERP (echo_buffer
[i
])
8272 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8275 Lisp_Object old_buffer
;
8278 old_buffer
= echo_buffer
[i
];
8279 sprintf (name
, " *Echo Area %d*", i
);
8280 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8281 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8282 /* to force word wrap in echo area -
8283 it was decided to postpone this*/
8284 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8286 for (j
= 0; j
< 2; ++j
)
8287 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8288 echo_area_buffer
[j
] = echo_buffer
[i
];
8293 /* Call FN with args A1..A4 with either the current or last displayed
8294 echo_area_buffer as current buffer.
8296 WHICH zero means use the current message buffer
8297 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8298 from echo_buffer[] and clear it.
8300 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8301 suitable buffer from echo_buffer[] and clear it.
8303 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8304 that the current message becomes the last displayed one, make
8305 choose a suitable buffer for echo_area_buffer[0], and clear it.
8307 Value is what FN returns. */
8310 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8313 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8319 int this_one
, the_other
, clear_buffer_p
, rc
;
8320 int count
= SPECPDL_INDEX ();
8322 /* If buffers aren't live, make new ones. */
8323 ensure_echo_area_buffers ();
8328 this_one
= 0, the_other
= 1;
8330 this_one
= 1, the_other
= 0;
8333 this_one
= 0, the_other
= 1;
8336 /* We need a fresh one in case the current echo buffer equals
8337 the one containing the last displayed echo area message. */
8338 if (!NILP (echo_area_buffer
[this_one
])
8339 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8340 echo_area_buffer
[this_one
] = Qnil
;
8343 /* Choose a suitable buffer from echo_buffer[] is we don't
8345 if (NILP (echo_area_buffer
[this_one
]))
8347 echo_area_buffer
[this_one
]
8348 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8349 ? echo_buffer
[the_other
]
8350 : echo_buffer
[this_one
]);
8354 buffer
= echo_area_buffer
[this_one
];
8356 /* Don't get confused by reusing the buffer used for echoing
8357 for a different purpose. */
8358 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8361 record_unwind_protect (unwind_with_echo_area_buffer
,
8362 with_echo_area_buffer_unwind_data (w
));
8364 /* Make the echo area buffer current. Note that for display
8365 purposes, it is not necessary that the displayed window's buffer
8366 == current_buffer, except for text property lookup. So, let's
8367 only set that buffer temporarily here without doing a full
8368 Fset_window_buffer. We must also change w->pointm, though,
8369 because otherwise an assertions in unshow_buffer fails, and Emacs
8371 set_buffer_internal_1 (XBUFFER (buffer
));
8375 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8378 current_buffer
->undo_list
= Qt
;
8379 current_buffer
->read_only
= Qnil
;
8380 specbind (Qinhibit_read_only
, Qt
);
8381 specbind (Qinhibit_modification_hooks
, Qt
);
8383 if (clear_buffer_p
&& Z
> BEG
)
8386 xassert (BEGV
>= BEG
);
8387 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8389 rc
= fn (a1
, a2
, a3
, a4
);
8391 xassert (BEGV
>= BEG
);
8392 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8394 unbind_to (count
, Qnil
);
8399 /* Save state that should be preserved around the call to the function
8400 FN called in with_echo_area_buffer. */
8403 with_echo_area_buffer_unwind_data (w
)
8407 Lisp_Object vector
, tmp
;
8409 /* Reduce consing by keeping one vector in
8410 Vwith_echo_area_save_vector. */
8411 vector
= Vwith_echo_area_save_vector
;
8412 Vwith_echo_area_save_vector
= Qnil
;
8415 vector
= Fmake_vector (make_number (7), Qnil
);
8417 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8418 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8419 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8423 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8424 ASET (vector
, i
, w
->buffer
); ++i
;
8425 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8426 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8431 for (; i
< end
; ++i
)
8432 ASET (vector
, i
, Qnil
);
8435 xassert (i
== ASIZE (vector
));
8440 /* Restore global state from VECTOR which was created by
8441 with_echo_area_buffer_unwind_data. */
8444 unwind_with_echo_area_buffer (vector
)
8447 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8448 Vdeactivate_mark
= AREF (vector
, 1);
8449 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8451 if (WINDOWP (AREF (vector
, 3)))
8454 Lisp_Object buffer
, charpos
, bytepos
;
8456 w
= XWINDOW (AREF (vector
, 3));
8457 buffer
= AREF (vector
, 4);
8458 charpos
= AREF (vector
, 5);
8459 bytepos
= AREF (vector
, 6);
8462 set_marker_both (w
->pointm
, buffer
,
8463 XFASTINT (charpos
), XFASTINT (bytepos
));
8466 Vwith_echo_area_save_vector
= vector
;
8471 /* Set up the echo area for use by print functions. MULTIBYTE_P
8472 non-zero means we will print multibyte. */
8475 setup_echo_area_for_printing (multibyte_p
)
8478 /* If we can't find an echo area any more, exit. */
8479 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8482 ensure_echo_area_buffers ();
8484 if (!message_buf_print
)
8486 /* A message has been output since the last time we printed.
8487 Choose a fresh echo area buffer. */
8488 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8489 echo_area_buffer
[0] = echo_buffer
[1];
8491 echo_area_buffer
[0] = echo_buffer
[0];
8493 /* Switch to that buffer and clear it. */
8494 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8495 current_buffer
->truncate_lines
= Qnil
;
8499 int count
= SPECPDL_INDEX ();
8500 specbind (Qinhibit_read_only
, Qt
);
8501 /* Note that undo recording is always disabled. */
8503 unbind_to (count
, Qnil
);
8505 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8507 /* Set up the buffer for the multibyteness we need. */
8509 != !NILP (current_buffer
->enable_multibyte_characters
))
8510 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8512 /* Raise the frame containing the echo area. */
8513 if (minibuffer_auto_raise
)
8515 struct frame
*sf
= SELECTED_FRAME ();
8516 Lisp_Object mini_window
;
8517 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8518 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8521 message_log_maybe_newline ();
8522 message_buf_print
= 1;
8526 if (NILP (echo_area_buffer
[0]))
8528 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8529 echo_area_buffer
[0] = echo_buffer
[1];
8531 echo_area_buffer
[0] = echo_buffer
[0];
8534 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8536 /* Someone switched buffers between print requests. */
8537 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8538 current_buffer
->truncate_lines
= Qnil
;
8544 /* Display an echo area message in window W. Value is non-zero if W's
8545 height is changed. If display_last_displayed_message_p is
8546 non-zero, display the message that was last displayed, otherwise
8547 display the current message. */
8550 display_echo_area (w
)
8553 int i
, no_message_p
, window_height_changed_p
, count
;
8555 /* Temporarily disable garbage collections while displaying the echo
8556 area. This is done because a GC can print a message itself.
8557 That message would modify the echo area buffer's contents while a
8558 redisplay of the buffer is going on, and seriously confuse
8560 count
= inhibit_garbage_collection ();
8562 /* If there is no message, we must call display_echo_area_1
8563 nevertheless because it resizes the window. But we will have to
8564 reset the echo_area_buffer in question to nil at the end because
8565 with_echo_area_buffer will sets it to an empty buffer. */
8566 i
= display_last_displayed_message_p
? 1 : 0;
8567 no_message_p
= NILP (echo_area_buffer
[i
]);
8569 window_height_changed_p
8570 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8571 display_echo_area_1
,
8572 (EMACS_INT
) w
, Qnil
, 0, 0);
8575 echo_area_buffer
[i
] = Qnil
;
8577 unbind_to (count
, Qnil
);
8578 return window_height_changed_p
;
8582 /* Helper for display_echo_area. Display the current buffer which
8583 contains the current echo area message in window W, a mini-window,
8584 a pointer to which is passed in A1. A2..A4 are currently not used.
8585 Change the height of W so that all of the message is displayed.
8586 Value is non-zero if height of W was changed. */
8589 display_echo_area_1 (a1
, a2
, a3
, a4
)
8594 struct window
*w
= (struct window
*) a1
;
8596 struct text_pos start
;
8597 int window_height_changed_p
= 0;
8599 /* Do this before displaying, so that we have a large enough glyph
8600 matrix for the display. If we can't get enough space for the
8601 whole text, display the last N lines. That works by setting w->start. */
8602 window_height_changed_p
= resize_mini_window (w
, 0);
8604 /* Use the starting position chosen by resize_mini_window. */
8605 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8608 clear_glyph_matrix (w
->desired_matrix
);
8609 XSETWINDOW (window
, w
);
8610 try_window (window
, start
, 0);
8612 return window_height_changed_p
;
8616 /* Resize the echo area window to exactly the size needed for the
8617 currently displayed message, if there is one. If a mini-buffer
8618 is active, don't shrink it. */
8621 resize_echo_area_exactly ()
8623 if (BUFFERP (echo_area_buffer
[0])
8624 && WINDOWP (echo_area_window
))
8626 struct window
*w
= XWINDOW (echo_area_window
);
8628 Lisp_Object resize_exactly
;
8630 if (minibuf_level
== 0)
8631 resize_exactly
= Qt
;
8633 resize_exactly
= Qnil
;
8635 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8636 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8639 ++windows_or_buffers_changed
;
8640 ++update_mode_lines
;
8641 redisplay_internal (0);
8647 /* Callback function for with_echo_area_buffer, when used from
8648 resize_echo_area_exactly. A1 contains a pointer to the window to
8649 resize, EXACTLY non-nil means resize the mini-window exactly to the
8650 size of the text displayed. A3 and A4 are not used. Value is what
8651 resize_mini_window returns. */
8654 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8656 Lisp_Object exactly
;
8659 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8663 /* Resize mini-window W to fit the size of its contents. EXACT_P
8664 means size the window exactly to the size needed. Otherwise, it's
8665 only enlarged until W's buffer is empty.
8667 Set W->start to the right place to begin display. If the whole
8668 contents fit, start at the beginning. Otherwise, start so as
8669 to make the end of the contents appear. This is particularly
8670 important for y-or-n-p, but seems desirable generally.
8672 Value is non-zero if the window height has been changed. */
8675 resize_mini_window (w
, exact_p
)
8679 struct frame
*f
= XFRAME (w
->frame
);
8680 int window_height_changed_p
= 0;
8682 xassert (MINI_WINDOW_P (w
));
8684 /* By default, start display at the beginning. */
8685 set_marker_both (w
->start
, w
->buffer
,
8686 BUF_BEGV (XBUFFER (w
->buffer
)),
8687 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8689 /* Don't resize windows while redisplaying a window; it would
8690 confuse redisplay functions when the size of the window they are
8691 displaying changes from under them. Such a resizing can happen,
8692 for instance, when which-func prints a long message while
8693 we are running fontification-functions. We're running these
8694 functions with safe_call which binds inhibit-redisplay to t. */
8695 if (!NILP (Vinhibit_redisplay
))
8698 /* Nil means don't try to resize. */
8699 if (NILP (Vresize_mini_windows
)
8700 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8703 if (!FRAME_MINIBUF_ONLY_P (f
))
8706 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8707 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8708 int height
, max_height
;
8709 int unit
= FRAME_LINE_HEIGHT (f
);
8710 struct text_pos start
;
8711 struct buffer
*old_current_buffer
= NULL
;
8713 if (current_buffer
!= XBUFFER (w
->buffer
))
8715 old_current_buffer
= current_buffer
;
8716 set_buffer_internal (XBUFFER (w
->buffer
));
8719 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8721 /* Compute the max. number of lines specified by the user. */
8722 if (FLOATP (Vmax_mini_window_height
))
8723 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8724 else if (INTEGERP (Vmax_mini_window_height
))
8725 max_height
= XINT (Vmax_mini_window_height
);
8727 max_height
= total_height
/ 4;
8729 /* Correct that max. height if it's bogus. */
8730 max_height
= max (1, max_height
);
8731 max_height
= min (total_height
, max_height
);
8733 /* Find out the height of the text in the window. */
8734 if (it
.line_wrap
== TRUNCATE
)
8739 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8740 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8741 height
= it
.current_y
+ last_height
;
8743 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8744 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8745 height
= (height
+ unit
- 1) / unit
;
8748 /* Compute a suitable window start. */
8749 if (height
> max_height
)
8751 height
= max_height
;
8752 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8753 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8754 start
= it
.current
.pos
;
8757 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8758 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8760 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8762 /* Let it grow only, until we display an empty message, in which
8763 case the window shrinks again. */
8764 if (height
> WINDOW_TOTAL_LINES (w
))
8766 int old_height
= WINDOW_TOTAL_LINES (w
);
8767 freeze_window_starts (f
, 1);
8768 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8769 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8771 else if (height
< WINDOW_TOTAL_LINES (w
)
8772 && (exact_p
|| BEGV
== ZV
))
8774 int old_height
= WINDOW_TOTAL_LINES (w
);
8775 freeze_window_starts (f
, 0);
8776 shrink_mini_window (w
);
8777 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8782 /* Always resize to exact size needed. */
8783 if (height
> WINDOW_TOTAL_LINES (w
))
8785 int old_height
= WINDOW_TOTAL_LINES (w
);
8786 freeze_window_starts (f
, 1);
8787 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8788 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8790 else if (height
< WINDOW_TOTAL_LINES (w
))
8792 int old_height
= WINDOW_TOTAL_LINES (w
);
8793 freeze_window_starts (f
, 0);
8794 shrink_mini_window (w
);
8798 freeze_window_starts (f
, 1);
8799 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8802 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8806 if (old_current_buffer
)
8807 set_buffer_internal (old_current_buffer
);
8810 return window_height_changed_p
;
8814 /* Value is the current message, a string, or nil if there is no
8822 if (!BUFFERP (echo_area_buffer
[0]))
8826 with_echo_area_buffer (0, 0, current_message_1
,
8827 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8829 echo_area_buffer
[0] = Qnil
;
8837 current_message_1 (a1
, a2
, a3
, a4
)
8842 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8845 *msg
= make_buffer_string (BEG
, Z
, 1);
8852 /* Push the current message on Vmessage_stack for later restauration
8853 by restore_message. Value is non-zero if the current message isn't
8854 empty. This is a relatively infrequent operation, so it's not
8855 worth optimizing. */
8861 msg
= current_message ();
8862 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8863 return STRINGP (msg
);
8867 /* Restore message display from the top of Vmessage_stack. */
8874 xassert (CONSP (Vmessage_stack
));
8875 msg
= XCAR (Vmessage_stack
);
8877 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8879 message3_nolog (msg
, 0, 0);
8883 /* Handler for record_unwind_protect calling pop_message. */
8886 pop_message_unwind (dummy
)
8893 /* Pop the top-most entry off Vmessage_stack. */
8898 xassert (CONSP (Vmessage_stack
));
8899 Vmessage_stack
= XCDR (Vmessage_stack
);
8903 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8904 exits. If the stack is not empty, we have a missing pop_message
8908 check_message_stack ()
8910 if (!NILP (Vmessage_stack
))
8915 /* Truncate to NCHARS what will be displayed in the echo area the next
8916 time we display it---but don't redisplay it now. */
8919 truncate_echo_area (nchars
)
8923 echo_area_buffer
[0] = Qnil
;
8924 /* A null message buffer means that the frame hasn't really been
8925 initialized yet. Error messages get reported properly by
8926 cmd_error, so this must be just an informative message; toss it. */
8927 else if (!noninteractive
8929 && !NILP (echo_area_buffer
[0]))
8931 struct frame
*sf
= SELECTED_FRAME ();
8932 if (FRAME_MESSAGE_BUF (sf
))
8933 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8938 /* Helper function for truncate_echo_area. Truncate the current
8939 message to at most NCHARS characters. */
8942 truncate_message_1 (nchars
, a2
, a3
, a4
)
8947 if (BEG
+ nchars
< Z
)
8948 del_range (BEG
+ nchars
, Z
);
8950 echo_area_buffer
[0] = Qnil
;
8955 /* Set the current message to a substring of S or STRING.
8957 If STRING is a Lisp string, set the message to the first NBYTES
8958 bytes from STRING. NBYTES zero means use the whole string. If
8959 STRING is multibyte, the message will be displayed multibyte.
8961 If S is not null, set the message to the first LEN bytes of S. LEN
8962 zero means use the whole string. MULTIBYTE_P non-zero means S is
8963 multibyte. Display the message multibyte in that case.
8965 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8966 to t before calling set_message_1 (which calls insert).
8970 set_message (s
, string
, nbytes
, multibyte_p
)
8973 int nbytes
, multibyte_p
;
8975 message_enable_multibyte
8976 = ((s
&& multibyte_p
)
8977 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8979 with_echo_area_buffer (0, -1, set_message_1
,
8980 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8981 message_buf_print
= 0;
8982 help_echo_showing_p
= 0;
8986 /* Helper function for set_message. Arguments have the same meaning
8987 as there, with A1 corresponding to S and A2 corresponding to STRING
8988 This function is called with the echo area buffer being
8992 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8995 EMACS_INT nbytes
, multibyte_p
;
8997 const char *s
= (const char *) a1
;
8998 Lisp_Object string
= a2
;
9000 /* Change multibyteness of the echo buffer appropriately. */
9001 if (message_enable_multibyte
9002 != !NILP (current_buffer
->enable_multibyte_characters
))
9003 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9005 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9007 /* Insert new message at BEG. */
9008 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9010 if (STRINGP (string
))
9015 nbytes
= SBYTES (string
);
9016 nchars
= string_byte_to_char (string
, nbytes
);
9018 /* This function takes care of single/multibyte conversion. We
9019 just have to ensure that the echo area buffer has the right
9020 setting of enable_multibyte_characters. */
9021 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9026 nbytes
= strlen (s
);
9028 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9030 /* Convert from multi-byte to single-byte. */
9032 unsigned char work
[1];
9034 /* Convert a multibyte string to single-byte. */
9035 for (i
= 0; i
< nbytes
; i
+= n
)
9037 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
9038 work
[0] = (ASCII_CHAR_P (c
)
9040 : multibyte_char_to_unibyte (c
, Qnil
));
9041 insert_1_both (work
, 1, 1, 1, 0, 0);
9044 else if (!multibyte_p
9045 && !NILP (current_buffer
->enable_multibyte_characters
))
9047 /* Convert from single-byte to multi-byte. */
9049 const unsigned char *msg
= (const unsigned char *) s
;
9050 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9052 /* Convert a single-byte string to multibyte. */
9053 for (i
= 0; i
< nbytes
; i
++)
9056 c
= unibyte_char_to_multibyte (c
);
9057 n
= CHAR_STRING (c
, str
);
9058 insert_1_both (str
, 1, n
, 1, 0, 0);
9062 insert_1 (s
, nbytes
, 1, 0, 0);
9069 /* Clear messages. CURRENT_P non-zero means clear the current
9070 message. LAST_DISPLAYED_P non-zero means clear the message
9074 clear_message (current_p
, last_displayed_p
)
9075 int current_p
, last_displayed_p
;
9079 echo_area_buffer
[0] = Qnil
;
9080 message_cleared_p
= 1;
9083 if (last_displayed_p
)
9084 echo_area_buffer
[1] = Qnil
;
9086 message_buf_print
= 0;
9089 /* Clear garbaged frames.
9091 This function is used where the old redisplay called
9092 redraw_garbaged_frames which in turn called redraw_frame which in
9093 turn called clear_frame. The call to clear_frame was a source of
9094 flickering. I believe a clear_frame is not necessary. It should
9095 suffice in the new redisplay to invalidate all current matrices,
9096 and ensure a complete redisplay of all windows. */
9099 clear_garbaged_frames ()
9103 Lisp_Object tail
, frame
;
9104 int changed_count
= 0;
9106 FOR_EACH_FRAME (tail
, frame
)
9108 struct frame
*f
= XFRAME (frame
);
9110 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9114 Fredraw_frame (frame
);
9115 f
->force_flush_display_p
= 1;
9117 clear_current_matrices (f
);
9126 ++windows_or_buffers_changed
;
9131 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9132 is non-zero update selected_frame. Value is non-zero if the
9133 mini-windows height has been changed. */
9136 echo_area_display (update_frame_p
)
9139 Lisp_Object mini_window
;
9142 int window_height_changed_p
= 0;
9143 struct frame
*sf
= SELECTED_FRAME ();
9145 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9146 w
= XWINDOW (mini_window
);
9147 f
= XFRAME (WINDOW_FRAME (w
));
9149 /* Don't display if frame is invisible or not yet initialized. */
9150 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9153 #ifdef HAVE_WINDOW_SYSTEM
9154 /* When Emacs starts, selected_frame may be the initial terminal
9155 frame. If we let this through, a message would be displayed on
9157 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9159 #endif /* HAVE_WINDOW_SYSTEM */
9161 /* Redraw garbaged frames. */
9163 clear_garbaged_frames ();
9165 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9167 echo_area_window
= mini_window
;
9168 window_height_changed_p
= display_echo_area (w
);
9169 w
->must_be_updated_p
= 1;
9171 /* Update the display, unless called from redisplay_internal.
9172 Also don't update the screen during redisplay itself. The
9173 update will happen at the end of redisplay, and an update
9174 here could cause confusion. */
9175 if (update_frame_p
&& !redisplaying_p
)
9179 /* If the display update has been interrupted by pending
9180 input, update mode lines in the frame. Due to the
9181 pending input, it might have been that redisplay hasn't
9182 been called, so that mode lines above the echo area are
9183 garbaged. This looks odd, so we prevent it here. */
9184 if (!display_completed
)
9185 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9187 if (window_height_changed_p
9188 /* Don't do this if Emacs is shutting down. Redisplay
9189 needs to run hooks. */
9190 && !NILP (Vrun_hooks
))
9192 /* Must update other windows. Likewise as in other
9193 cases, don't let this update be interrupted by
9195 int count
= SPECPDL_INDEX ();
9196 specbind (Qredisplay_dont_pause
, Qt
);
9197 windows_or_buffers_changed
= 1;
9198 redisplay_internal (0);
9199 unbind_to (count
, Qnil
);
9201 else if (FRAME_WINDOW_P (f
) && n
== 0)
9203 /* Window configuration is the same as before.
9204 Can do with a display update of the echo area,
9205 unless we displayed some mode lines. */
9206 update_single_window (w
, 1);
9207 FRAME_RIF (f
)->flush_display (f
);
9210 update_frame (f
, 1, 1);
9212 /* If cursor is in the echo area, make sure that the next
9213 redisplay displays the minibuffer, so that the cursor will
9214 be replaced with what the minibuffer wants. */
9215 if (cursor_in_echo_area
)
9216 ++windows_or_buffers_changed
;
9219 else if (!EQ (mini_window
, selected_window
))
9220 windows_or_buffers_changed
++;
9222 /* Last displayed message is now the current message. */
9223 echo_area_buffer
[1] = echo_area_buffer
[0];
9224 /* Inform read_char that we're not echoing. */
9225 echo_message_buffer
= Qnil
;
9227 /* Prevent redisplay optimization in redisplay_internal by resetting
9228 this_line_start_pos. This is done because the mini-buffer now
9229 displays the message instead of its buffer text. */
9230 if (EQ (mini_window
, selected_window
))
9231 CHARPOS (this_line_start_pos
) = 0;
9233 return window_height_changed_p
;
9238 /***********************************************************************
9239 Mode Lines and Frame Titles
9240 ***********************************************************************/
9242 /* A buffer for constructing non-propertized mode-line strings and
9243 frame titles in it; allocated from the heap in init_xdisp and
9244 resized as needed in store_mode_line_noprop_char. */
9246 static char *mode_line_noprop_buf
;
9248 /* The buffer's end, and a current output position in it. */
9250 static char *mode_line_noprop_buf_end
;
9251 static char *mode_line_noprop_ptr
;
9253 #define MODE_LINE_NOPROP_LEN(start) \
9254 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9257 MODE_LINE_DISPLAY
= 0,
9263 /* Alist that caches the results of :propertize.
9264 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9265 static Lisp_Object mode_line_proptrans_alist
;
9267 /* List of strings making up the mode-line. */
9268 static Lisp_Object mode_line_string_list
;
9270 /* Base face property when building propertized mode line string. */
9271 static Lisp_Object mode_line_string_face
;
9272 static Lisp_Object mode_line_string_face_prop
;
9275 /* Unwind data for mode line strings */
9277 static Lisp_Object Vmode_line_unwind_vector
;
9280 format_mode_line_unwind_data (struct buffer
*obuf
,
9284 Lisp_Object vector
, tmp
;
9286 /* Reduce consing by keeping one vector in
9287 Vwith_echo_area_save_vector. */
9288 vector
= Vmode_line_unwind_vector
;
9289 Vmode_line_unwind_vector
= Qnil
;
9292 vector
= Fmake_vector (make_number (8), Qnil
);
9294 ASET (vector
, 0, make_number (mode_line_target
));
9295 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9296 ASET (vector
, 2, mode_line_string_list
);
9297 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9298 ASET (vector
, 4, mode_line_string_face
);
9299 ASET (vector
, 5, mode_line_string_face_prop
);
9302 XSETBUFFER (tmp
, obuf
);
9305 ASET (vector
, 6, tmp
);
9306 ASET (vector
, 7, owin
);
9312 unwind_format_mode_line (vector
)
9315 mode_line_target
= XINT (AREF (vector
, 0));
9316 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9317 mode_line_string_list
= AREF (vector
, 2);
9318 if (! EQ (AREF (vector
, 3), Qt
))
9319 mode_line_proptrans_alist
= AREF (vector
, 3);
9320 mode_line_string_face
= AREF (vector
, 4);
9321 mode_line_string_face_prop
= AREF (vector
, 5);
9323 if (!NILP (AREF (vector
, 7)))
9324 /* Select window before buffer, since it may change the buffer. */
9325 Fselect_window (AREF (vector
, 7), Qt
);
9327 if (!NILP (AREF (vector
, 6)))
9329 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9330 ASET (vector
, 6, Qnil
);
9333 Vmode_line_unwind_vector
= vector
;
9338 /* Store a single character C for the frame title in mode_line_noprop_buf.
9339 Re-allocate mode_line_noprop_buf if necessary. */
9343 store_mode_line_noprop_char (char c
)
9345 store_mode_line_noprop_char (c
)
9349 /* If output position has reached the end of the allocated buffer,
9350 double the buffer's size. */
9351 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9353 int len
= MODE_LINE_NOPROP_LEN (0);
9354 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9355 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9356 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9357 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9360 *mode_line_noprop_ptr
++ = c
;
9364 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9365 mode_line_noprop_ptr. STR is the string to store. Do not copy
9366 characters that yield more columns than PRECISION; PRECISION <= 0
9367 means copy the whole string. Pad with spaces until FIELD_WIDTH
9368 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9369 pad. Called from display_mode_element when it is used to build a
9373 store_mode_line_noprop (str
, field_width
, precision
)
9374 const unsigned char *str
;
9375 int field_width
, precision
;
9380 /* Copy at most PRECISION chars from STR. */
9381 nbytes
= strlen (str
);
9382 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9384 store_mode_line_noprop_char (*str
++);
9386 /* Fill up with spaces until FIELD_WIDTH reached. */
9387 while (field_width
> 0
9390 store_mode_line_noprop_char (' ');
9397 /***********************************************************************
9399 ***********************************************************************/
9401 #ifdef HAVE_WINDOW_SYSTEM
9403 /* Set the title of FRAME, if it has changed. The title format is
9404 Vicon_title_format if FRAME is iconified, otherwise it is
9405 frame_title_format. */
9408 x_consider_frame_title (frame
)
9411 struct frame
*f
= XFRAME (frame
);
9413 if (FRAME_WINDOW_P (f
)
9414 || FRAME_MINIBUF_ONLY_P (f
)
9415 || f
->explicit_name
)
9417 /* Do we have more than one visible frame on this X display? */
9424 int count
= SPECPDL_INDEX ();
9426 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9428 Lisp_Object other_frame
= XCAR (tail
);
9429 struct frame
*tf
= XFRAME (other_frame
);
9432 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9433 && !FRAME_MINIBUF_ONLY_P (tf
)
9434 && !EQ (other_frame
, tip_frame
)
9435 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9439 /* Set global variable indicating that multiple frames exist. */
9440 multiple_frames
= CONSP (tail
);
9442 /* Switch to the buffer of selected window of the frame. Set up
9443 mode_line_target so that display_mode_element will output into
9444 mode_line_noprop_buf; then display the title. */
9445 record_unwind_protect (unwind_format_mode_line
,
9446 format_mode_line_unwind_data
9447 (current_buffer
, selected_window
, 0));
9449 Fselect_window (f
->selected_window
, Qt
);
9450 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9451 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9453 mode_line_target
= MODE_LINE_TITLE
;
9454 title_start
= MODE_LINE_NOPROP_LEN (0);
9455 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9456 NULL
, DEFAULT_FACE_ID
);
9457 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9458 len
= MODE_LINE_NOPROP_LEN (title_start
);
9459 title
= mode_line_noprop_buf
+ title_start
;
9460 unbind_to (count
, Qnil
);
9462 /* Set the title only if it's changed. This avoids consing in
9463 the common case where it hasn't. (If it turns out that we've
9464 already wasted too much time by walking through the list with
9465 display_mode_element, then we might need to optimize at a
9466 higher level than this.) */
9467 if (! STRINGP (f
->name
)
9468 || SBYTES (f
->name
) != len
9469 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9474 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9477 ns_set_name_as_filename (f
);
9479 x_implicitly_set_name (f
, make_string(title
, len
),
9485 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9490 /* do this also for frames with explicit names */
9491 ns_implicitly_set_icon_type(f
);
9492 ns_set_doc_edited(f
, Fbuffer_modified_p
9493 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9499 #endif /* not HAVE_WINDOW_SYSTEM */
9504 /***********************************************************************
9506 ***********************************************************************/
9509 /* Prepare for redisplay by updating menu-bar item lists when
9510 appropriate. This can call eval. */
9513 prepare_menu_bars ()
9516 struct gcpro gcpro1
, gcpro2
;
9518 Lisp_Object tooltip_frame
;
9520 #ifdef HAVE_WINDOW_SYSTEM
9521 tooltip_frame
= tip_frame
;
9523 tooltip_frame
= Qnil
;
9526 /* Update all frame titles based on their buffer names, etc. We do
9527 this before the menu bars so that the buffer-menu will show the
9528 up-to-date frame titles. */
9529 #ifdef HAVE_WINDOW_SYSTEM
9530 if (windows_or_buffers_changed
|| update_mode_lines
)
9532 Lisp_Object tail
, frame
;
9534 FOR_EACH_FRAME (tail
, frame
)
9537 if (!EQ (frame
, tooltip_frame
)
9538 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9539 x_consider_frame_title (frame
);
9542 #endif /* HAVE_WINDOW_SYSTEM */
9544 /* Update the menu bar item lists, if appropriate. This has to be
9545 done before any actual redisplay or generation of display lines. */
9546 all_windows
= (update_mode_lines
9547 || buffer_shared
> 1
9548 || windows_or_buffers_changed
);
9551 Lisp_Object tail
, frame
;
9552 int count
= SPECPDL_INDEX ();
9553 /* 1 means that update_menu_bar has run its hooks
9554 so any further calls to update_menu_bar shouldn't do so again. */
9555 int menu_bar_hooks_run
= 0;
9557 record_unwind_save_match_data ();
9559 FOR_EACH_FRAME (tail
, frame
)
9563 /* Ignore tooltip frame. */
9564 if (EQ (frame
, tooltip_frame
))
9567 /* If a window on this frame changed size, report that to
9568 the user and clear the size-change flag. */
9569 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9571 Lisp_Object functions
;
9573 /* Clear flag first in case we get an error below. */
9574 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9575 functions
= Vwindow_size_change_functions
;
9576 GCPRO2 (tail
, functions
);
9578 while (CONSP (functions
))
9580 if (!EQ (XCAR (functions
), Qt
))
9581 call1 (XCAR (functions
), frame
);
9582 functions
= XCDR (functions
);
9588 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9589 #ifdef HAVE_WINDOW_SYSTEM
9590 update_tool_bar (f
, 0);
9595 unbind_to (count
, Qnil
);
9599 struct frame
*sf
= SELECTED_FRAME ();
9600 update_menu_bar (sf
, 1, 0);
9601 #ifdef HAVE_WINDOW_SYSTEM
9602 update_tool_bar (sf
, 1);
9606 /* Motif needs this. See comment in xmenu.c. Turn it off when
9607 pending_menu_activation is not defined. */
9608 #ifdef USE_X_TOOLKIT
9609 pending_menu_activation
= 0;
9614 /* Update the menu bar item list for frame F. This has to be done
9615 before we start to fill in any display lines, because it can call
9618 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9620 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9621 already ran the menu bar hooks for this redisplay, so there
9622 is no need to run them again. The return value is the
9623 updated value of this flag, to pass to the next call. */
9626 update_menu_bar (f
, save_match_data
, hooks_run
)
9628 int save_match_data
;
9632 register struct window
*w
;
9634 /* If called recursively during a menu update, do nothing. This can
9635 happen when, for instance, an activate-menubar-hook causes a
9637 if (inhibit_menubar_update
)
9640 window
= FRAME_SELECTED_WINDOW (f
);
9641 w
= XWINDOW (window
);
9643 if (FRAME_WINDOW_P (f
)
9645 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9646 || defined (HAVE_NS) || defined (USE_GTK)
9647 FRAME_EXTERNAL_MENU_BAR (f
)
9649 FRAME_MENU_BAR_LINES (f
) > 0
9651 : FRAME_MENU_BAR_LINES (f
) > 0)
9653 /* If the user has switched buffers or windows, we need to
9654 recompute to reflect the new bindings. But we'll
9655 recompute when update_mode_lines is set too; that means
9656 that people can use force-mode-line-update to request
9657 that the menu bar be recomputed. The adverse effect on
9658 the rest of the redisplay algorithm is about the same as
9659 windows_or_buffers_changed anyway. */
9660 if (windows_or_buffers_changed
9661 /* This used to test w->update_mode_line, but we believe
9662 there is no need to recompute the menu in that case. */
9663 || update_mode_lines
9664 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9665 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9666 != !NILP (w
->last_had_star
))
9667 || ((!NILP (Vtransient_mark_mode
)
9668 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9669 != !NILP (w
->region_showing
)))
9671 struct buffer
*prev
= current_buffer
;
9672 int count
= SPECPDL_INDEX ();
9674 specbind (Qinhibit_menubar_update
, Qt
);
9676 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9677 if (save_match_data
)
9678 record_unwind_save_match_data ();
9679 if (NILP (Voverriding_local_map_menu_flag
))
9681 specbind (Qoverriding_terminal_local_map
, Qnil
);
9682 specbind (Qoverriding_local_map
, Qnil
);
9687 /* Run the Lucid hook. */
9688 safe_run_hooks (Qactivate_menubar_hook
);
9690 /* If it has changed current-menubar from previous value,
9691 really recompute the menu-bar from the value. */
9692 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9693 call0 (Qrecompute_lucid_menubar
);
9695 safe_run_hooks (Qmenu_bar_update_hook
);
9700 XSETFRAME (Vmenu_updating_frame
, f
);
9701 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9703 /* Redisplay the menu bar in case we changed it. */
9704 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9705 || defined (HAVE_NS) || defined (USE_GTK)
9706 if (FRAME_WINDOW_P (f
))
9708 #if defined (HAVE_NS)
9709 /* All frames on Mac OS share the same menubar. So only
9710 the selected frame should be allowed to set it. */
9711 if (f
== SELECTED_FRAME ())
9713 set_frame_menubar (f
, 0, 0);
9716 /* On a terminal screen, the menu bar is an ordinary screen
9717 line, and this makes it get updated. */
9718 w
->update_mode_line
= Qt
;
9719 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9720 /* In the non-toolkit version, the menu bar is an ordinary screen
9721 line, and this makes it get updated. */
9722 w
->update_mode_line
= Qt
;
9723 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9725 unbind_to (count
, Qnil
);
9726 set_buffer_internal_1 (prev
);
9735 /***********************************************************************
9737 ***********************************************************************/
9739 #ifdef HAVE_WINDOW_SYSTEM
9742 Nominal cursor position -- where to draw output.
9743 HPOS and VPOS are window relative glyph matrix coordinates.
9744 X and Y are window relative pixel coordinates. */
9746 struct cursor_pos output_cursor
;
9750 Set the global variable output_cursor to CURSOR. All cursor
9751 positions are relative to updated_window. */
9754 set_output_cursor (cursor
)
9755 struct cursor_pos
*cursor
;
9757 output_cursor
.hpos
= cursor
->hpos
;
9758 output_cursor
.vpos
= cursor
->vpos
;
9759 output_cursor
.x
= cursor
->x
;
9760 output_cursor
.y
= cursor
->y
;
9765 Set a nominal cursor position.
9767 HPOS and VPOS are column/row positions in a window glyph matrix. X
9768 and Y are window text area relative pixel positions.
9770 If this is done during an update, updated_window will contain the
9771 window that is being updated and the position is the future output
9772 cursor position for that window. If updated_window is null, use
9773 selected_window and display the cursor at the given position. */
9776 x_cursor_to (vpos
, hpos
, y
, x
)
9777 int vpos
, hpos
, y
, x
;
9781 /* If updated_window is not set, work on selected_window. */
9785 w
= XWINDOW (selected_window
);
9787 /* Set the output cursor. */
9788 output_cursor
.hpos
= hpos
;
9789 output_cursor
.vpos
= vpos
;
9790 output_cursor
.x
= x
;
9791 output_cursor
.y
= y
;
9793 /* If not called as part of an update, really display the cursor.
9794 This will also set the cursor position of W. */
9795 if (updated_window
== NULL
)
9798 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9799 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9800 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9805 #endif /* HAVE_WINDOW_SYSTEM */
9808 /***********************************************************************
9810 ***********************************************************************/
9812 #ifdef HAVE_WINDOW_SYSTEM
9814 /* Where the mouse was last time we reported a mouse event. */
9816 FRAME_PTR last_mouse_frame
;
9818 /* Tool-bar item index of the item on which a mouse button was pressed
9821 int last_tool_bar_item
;
9825 update_tool_bar_unwind (frame
)
9828 selected_frame
= frame
;
9832 /* Update the tool-bar item list for frame F. This has to be done
9833 before we start to fill in any display lines. Called from
9834 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9835 and restore it here. */
9838 update_tool_bar (f
, save_match_data
)
9840 int save_match_data
;
9842 #if defined (USE_GTK) || defined (HAVE_NS)
9843 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9845 int do_update
= WINDOWP (f
->tool_bar_window
)
9846 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9854 window
= FRAME_SELECTED_WINDOW (f
);
9855 w
= XWINDOW (window
);
9857 /* If the user has switched buffers or windows, we need to
9858 recompute to reflect the new bindings. But we'll
9859 recompute when update_mode_lines is set too; that means
9860 that people can use force-mode-line-update to request
9861 that the menu bar be recomputed. The adverse effect on
9862 the rest of the redisplay algorithm is about the same as
9863 windows_or_buffers_changed anyway. */
9864 if (windows_or_buffers_changed
9865 || !NILP (w
->update_mode_line
)
9866 || update_mode_lines
9867 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9868 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9869 != !NILP (w
->last_had_star
))
9870 || ((!NILP (Vtransient_mark_mode
)
9871 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9872 != !NILP (w
->region_showing
)))
9874 struct buffer
*prev
= current_buffer
;
9875 int count
= SPECPDL_INDEX ();
9876 Lisp_Object frame
, new_tool_bar
;
9878 struct gcpro gcpro1
;
9880 /* Set current_buffer to the buffer of the selected
9881 window of the frame, so that we get the right local
9883 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9885 /* Save match data, if we must. */
9886 if (save_match_data
)
9887 record_unwind_save_match_data ();
9889 /* Make sure that we don't accidentally use bogus keymaps. */
9890 if (NILP (Voverriding_local_map_menu_flag
))
9892 specbind (Qoverriding_terminal_local_map
, Qnil
);
9893 specbind (Qoverriding_local_map
, Qnil
);
9896 GCPRO1 (new_tool_bar
);
9898 /* We must temporarily set the selected frame to this frame
9899 before calling tool_bar_items, because the calculation of
9900 the tool-bar keymap uses the selected frame (see
9901 `tool-bar-make-keymap' in tool-bar.el). */
9902 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9903 XSETFRAME (frame
, f
);
9904 selected_frame
= frame
;
9906 /* Build desired tool-bar items from keymaps. */
9907 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9910 /* Redisplay the tool-bar if we changed it. */
9911 if (new_n_tool_bar
!= f
->n_tool_bar_items
9912 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9914 /* Redisplay that happens asynchronously due to an expose event
9915 may access f->tool_bar_items. Make sure we update both
9916 variables within BLOCK_INPUT so no such event interrupts. */
9918 f
->tool_bar_items
= new_tool_bar
;
9919 f
->n_tool_bar_items
= new_n_tool_bar
;
9920 w
->update_mode_line
= Qt
;
9926 unbind_to (count
, Qnil
);
9927 set_buffer_internal_1 (prev
);
9933 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9934 F's desired tool-bar contents. F->tool_bar_items must have
9935 been set up previously by calling prepare_menu_bars. */
9938 build_desired_tool_bar_string (f
)
9941 int i
, size
, size_needed
;
9942 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9943 Lisp_Object image
, plist
, props
;
9945 image
= plist
= props
= Qnil
;
9946 GCPRO3 (image
, plist
, props
);
9948 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9949 Otherwise, make a new string. */
9951 /* The size of the string we might be able to reuse. */
9952 size
= (STRINGP (f
->desired_tool_bar_string
)
9953 ? SCHARS (f
->desired_tool_bar_string
)
9956 /* We need one space in the string for each image. */
9957 size_needed
= f
->n_tool_bar_items
;
9959 /* Reuse f->desired_tool_bar_string, if possible. */
9960 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9961 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9965 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9966 Fremove_text_properties (make_number (0), make_number (size
),
9967 props
, f
->desired_tool_bar_string
);
9970 /* Put a `display' property on the string for the images to display,
9971 put a `menu_item' property on tool-bar items with a value that
9972 is the index of the item in F's tool-bar item vector. */
9973 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9975 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9977 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9978 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9979 int hmargin
, vmargin
, relief
, idx
, end
;
9980 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9982 /* If image is a vector, choose the image according to the
9984 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9985 if (VECTORP (image
))
9989 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9990 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9993 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9994 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9996 xassert (ASIZE (image
) >= idx
);
9997 image
= AREF (image
, idx
);
10002 /* Ignore invalid image specifications. */
10003 if (!valid_image_p (image
))
10006 /* Display the tool-bar button pressed, or depressed. */
10007 plist
= Fcopy_sequence (XCDR (image
));
10009 /* Compute margin and relief to draw. */
10010 relief
= (tool_bar_button_relief
>= 0
10011 ? tool_bar_button_relief
10012 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10013 hmargin
= vmargin
= relief
;
10015 if (INTEGERP (Vtool_bar_button_margin
)
10016 && XINT (Vtool_bar_button_margin
) > 0)
10018 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10019 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10021 else if (CONSP (Vtool_bar_button_margin
))
10023 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10024 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10025 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10027 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10028 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10029 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10032 if (auto_raise_tool_bar_buttons_p
)
10034 /* Add a `:relief' property to the image spec if the item is
10038 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10045 /* If image is selected, display it pressed, i.e. with a
10046 negative relief. If it's not selected, display it with a
10048 plist
= Fplist_put (plist
, QCrelief
,
10050 ? make_number (-relief
)
10051 : make_number (relief
)));
10056 /* Put a margin around the image. */
10057 if (hmargin
|| vmargin
)
10059 if (hmargin
== vmargin
)
10060 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10062 plist
= Fplist_put (plist
, QCmargin
,
10063 Fcons (make_number (hmargin
),
10064 make_number (vmargin
)));
10067 /* If button is not enabled, and we don't have special images
10068 for the disabled state, make the image appear disabled by
10069 applying an appropriate algorithm to it. */
10070 if (!enabled_p
&& idx
< 0)
10071 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10073 /* Put a `display' text property on the string for the image to
10074 display. Put a `menu-item' property on the string that gives
10075 the start of this item's properties in the tool-bar items
10077 image
= Fcons (Qimage
, plist
);
10078 props
= list4 (Qdisplay
, image
,
10079 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10081 /* Let the last image hide all remaining spaces in the tool bar
10082 string. The string can be longer than needed when we reuse a
10083 previous string. */
10084 if (i
+ 1 == f
->n_tool_bar_items
)
10085 end
= SCHARS (f
->desired_tool_bar_string
);
10088 Fadd_text_properties (make_number (i
), make_number (end
),
10089 props
, f
->desired_tool_bar_string
);
10097 /* Display one line of the tool-bar of frame IT->f.
10099 HEIGHT specifies the desired height of the tool-bar line.
10100 If the actual height of the glyph row is less than HEIGHT, the
10101 row's height is increased to HEIGHT, and the icons are centered
10102 vertically in the new height.
10104 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10105 count a final empty row in case the tool-bar width exactly matches
10110 display_tool_bar_line (it
, height
)
10114 struct glyph_row
*row
= it
->glyph_row
;
10115 int max_x
= it
->last_visible_x
;
10116 struct glyph
*last
;
10118 prepare_desired_row (row
);
10119 row
->y
= it
->current_y
;
10121 /* Note that this isn't made use of if the face hasn't a box,
10122 so there's no need to check the face here. */
10123 it
->start_of_box_run_p
= 1;
10125 while (it
->current_x
< max_x
)
10127 int x
, n_glyphs_before
, i
, nglyphs
;
10128 struct it it_before
;
10130 /* Get the next display element. */
10131 if (!get_next_display_element (it
))
10133 /* Don't count empty row if we are counting needed tool-bar lines. */
10134 if (height
< 0 && !it
->hpos
)
10139 /* Produce glyphs. */
10140 n_glyphs_before
= row
->used
[TEXT_AREA
];
10143 PRODUCE_GLYPHS (it
);
10145 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10147 x
= it_before
.current_x
;
10148 while (i
< nglyphs
)
10150 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10152 if (x
+ glyph
->pixel_width
> max_x
)
10154 /* Glyph doesn't fit on line. Backtrack. */
10155 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10157 /* If this is the only glyph on this line, it will never fit on the
10158 toolbar, so skip it. But ensure there is at least one glyph,
10159 so we don't accidentally disable the tool-bar. */
10160 if (n_glyphs_before
== 0
10161 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10167 x
+= glyph
->pixel_width
;
10171 /* Stop at line ends. */
10172 if (ITERATOR_AT_END_OF_LINE_P (it
))
10175 set_iterator_to_next (it
, 1);
10180 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10182 /* Use default face for the border below the tool bar.
10184 FIXME: When auto-resize-tool-bars is grow-only, there is
10185 no additional border below the possibly empty tool-bar lines.
10186 So to make the extra empty lines look "normal", we have to
10187 use the tool-bar face for the border too. */
10188 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10189 it
->face_id
= DEFAULT_FACE_ID
;
10191 extend_face_to_end_of_line (it
);
10192 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10193 last
->right_box_line_p
= 1;
10194 if (last
== row
->glyphs
[TEXT_AREA
])
10195 last
->left_box_line_p
= 1;
10197 /* Make line the desired height and center it vertically. */
10198 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10200 /* Don't add more than one line height. */
10201 height
%= FRAME_LINE_HEIGHT (it
->f
);
10202 it
->max_ascent
+= height
/ 2;
10203 it
->max_descent
+= (height
+ 1) / 2;
10206 compute_line_metrics (it
);
10208 /* If line is empty, make it occupy the rest of the tool-bar. */
10209 if (!row
->displays_text_p
)
10211 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10212 row
->visible_height
= row
->height
;
10213 row
->ascent
= row
->phys_ascent
= 0;
10214 row
->extra_line_spacing
= 0;
10217 row
->full_width_p
= 1;
10218 row
->continued_p
= 0;
10219 row
->truncated_on_left_p
= 0;
10220 row
->truncated_on_right_p
= 0;
10222 it
->current_x
= it
->hpos
= 0;
10223 it
->current_y
+= row
->height
;
10229 /* Max tool-bar height. */
10231 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10232 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10234 /* Value is the number of screen lines needed to make all tool-bar
10235 items of frame F visible. The number of actual rows needed is
10236 returned in *N_ROWS if non-NULL. */
10239 tool_bar_lines_needed (f
, n_rows
)
10243 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10245 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10246 the desired matrix, so use (unused) mode-line row as temporary row to
10247 avoid destroying the first tool-bar row. */
10248 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10250 /* Initialize an iterator for iteration over
10251 F->desired_tool_bar_string in the tool-bar window of frame F. */
10252 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10253 it
.first_visible_x
= 0;
10254 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10255 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10257 while (!ITERATOR_AT_END_P (&it
))
10259 clear_glyph_row (temp_row
);
10260 it
.glyph_row
= temp_row
;
10261 display_tool_bar_line (&it
, -1);
10263 clear_glyph_row (temp_row
);
10265 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10267 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10269 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10273 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10275 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10284 frame
= selected_frame
;
10286 CHECK_FRAME (frame
);
10287 f
= XFRAME (frame
);
10289 if (WINDOWP (f
->tool_bar_window
)
10290 || (w
= XWINDOW (f
->tool_bar_window
),
10291 WINDOW_TOTAL_LINES (w
) > 0))
10293 update_tool_bar (f
, 1);
10294 if (f
->n_tool_bar_items
)
10296 build_desired_tool_bar_string (f
);
10297 nlines
= tool_bar_lines_needed (f
, NULL
);
10301 return make_number (nlines
);
10305 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10306 height should be changed. */
10309 redisplay_tool_bar (f
)
10314 struct glyph_row
*row
;
10316 #if defined (USE_GTK) || defined (HAVE_NS)
10317 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10318 update_frame_tool_bar (f
);
10322 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10323 do anything. This means you must start with tool-bar-lines
10324 non-zero to get the auto-sizing effect. Or in other words, you
10325 can turn off tool-bars by specifying tool-bar-lines zero. */
10326 if (!WINDOWP (f
->tool_bar_window
)
10327 || (w
= XWINDOW (f
->tool_bar_window
),
10328 WINDOW_TOTAL_LINES (w
) == 0))
10331 /* Set up an iterator for the tool-bar window. */
10332 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10333 it
.first_visible_x
= 0;
10334 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10335 row
= it
.glyph_row
;
10337 /* Build a string that represents the contents of the tool-bar. */
10338 build_desired_tool_bar_string (f
);
10339 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10341 if (f
->n_tool_bar_rows
== 0)
10345 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10346 nlines
!= WINDOW_TOTAL_LINES (w
)))
10348 extern Lisp_Object Qtool_bar_lines
;
10350 int old_height
= WINDOW_TOTAL_LINES (w
);
10352 XSETFRAME (frame
, f
);
10353 Fmodify_frame_parameters (frame
,
10354 Fcons (Fcons (Qtool_bar_lines
,
10355 make_number (nlines
)),
10357 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10359 clear_glyph_matrix (w
->desired_matrix
);
10360 fonts_changed_p
= 1;
10366 /* Display as many lines as needed to display all tool-bar items. */
10368 if (f
->n_tool_bar_rows
> 0)
10370 int border
, rows
, height
, extra
;
10372 if (INTEGERP (Vtool_bar_border
))
10373 border
= XINT (Vtool_bar_border
);
10374 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10375 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10376 else if (EQ (Vtool_bar_border
, Qborder_width
))
10377 border
= f
->border_width
;
10383 rows
= f
->n_tool_bar_rows
;
10384 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10385 extra
= it
.last_visible_y
- border
- height
* rows
;
10387 while (it
.current_y
< it
.last_visible_y
)
10390 if (extra
> 0 && rows
-- > 0)
10392 h
= (extra
+ rows
- 1) / rows
;
10395 display_tool_bar_line (&it
, height
+ h
);
10400 while (it
.current_y
< it
.last_visible_y
)
10401 display_tool_bar_line (&it
, 0);
10404 /* It doesn't make much sense to try scrolling in the tool-bar
10405 window, so don't do it. */
10406 w
->desired_matrix
->no_scrolling_p
= 1;
10407 w
->must_be_updated_p
= 1;
10409 if (!NILP (Vauto_resize_tool_bars
))
10411 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10412 int change_height_p
= 0;
10414 /* If we couldn't display everything, change the tool-bar's
10415 height if there is room for more. */
10416 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10417 && it
.current_y
< max_tool_bar_height
)
10418 change_height_p
= 1;
10420 row
= it
.glyph_row
- 1;
10422 /* If there are blank lines at the end, except for a partially
10423 visible blank line at the end that is smaller than
10424 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10425 if (!row
->displays_text_p
10426 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10427 change_height_p
= 1;
10429 /* If row displays tool-bar items, but is partially visible,
10430 change the tool-bar's height. */
10431 if (row
->displays_text_p
10432 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10433 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10434 change_height_p
= 1;
10436 /* Resize windows as needed by changing the `tool-bar-lines'
10437 frame parameter. */
10438 if (change_height_p
)
10440 extern Lisp_Object Qtool_bar_lines
;
10442 int old_height
= WINDOW_TOTAL_LINES (w
);
10444 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10446 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10447 && !f
->minimize_tool_bar_window_p
)
10448 ? (nlines
> old_height
)
10449 : (nlines
!= old_height
));
10450 f
->minimize_tool_bar_window_p
= 0;
10452 if (change_height_p
)
10454 XSETFRAME (frame
, f
);
10455 Fmodify_frame_parameters (frame
,
10456 Fcons (Fcons (Qtool_bar_lines
,
10457 make_number (nlines
)),
10459 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10461 clear_glyph_matrix (w
->desired_matrix
);
10462 f
->n_tool_bar_rows
= nrows
;
10463 fonts_changed_p
= 1;
10470 f
->minimize_tool_bar_window_p
= 0;
10475 /* Get information about the tool-bar item which is displayed in GLYPH
10476 on frame F. Return in *PROP_IDX the index where tool-bar item
10477 properties start in F->tool_bar_items. Value is zero if
10478 GLYPH doesn't display a tool-bar item. */
10481 tool_bar_item_info (f
, glyph
, prop_idx
)
10483 struct glyph
*glyph
;
10490 /* This function can be called asynchronously, which means we must
10491 exclude any possibility that Fget_text_property signals an
10493 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10494 charpos
= max (0, charpos
);
10496 /* Get the text property `menu-item' at pos. The value of that
10497 property is the start index of this item's properties in
10498 F->tool_bar_items. */
10499 prop
= Fget_text_property (make_number (charpos
),
10500 Qmenu_item
, f
->current_tool_bar_string
);
10501 if (INTEGERP (prop
))
10503 *prop_idx
= XINT (prop
);
10513 /* Get information about the tool-bar item at position X/Y on frame F.
10514 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10515 the current matrix of the tool-bar window of F, or NULL if not
10516 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10517 item in F->tool_bar_items. Value is
10519 -1 if X/Y is not on a tool-bar item
10520 0 if X/Y is on the same item that was highlighted before.
10524 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10527 struct glyph
**glyph
;
10528 int *hpos
, *vpos
, *prop_idx
;
10530 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10531 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10534 /* Find the glyph under X/Y. */
10535 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10536 if (*glyph
== NULL
)
10539 /* Get the start of this tool-bar item's properties in
10540 f->tool_bar_items. */
10541 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10544 /* Is mouse on the highlighted item? */
10545 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10546 && *vpos
>= dpyinfo
->mouse_face_beg_row
10547 && *vpos
<= dpyinfo
->mouse_face_end_row
10548 && (*vpos
> dpyinfo
->mouse_face_beg_row
10549 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10550 && (*vpos
< dpyinfo
->mouse_face_end_row
10551 || *hpos
< dpyinfo
->mouse_face_end_col
10552 || dpyinfo
->mouse_face_past_end
))
10560 Handle mouse button event on the tool-bar of frame F, at
10561 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10562 0 for button release. MODIFIERS is event modifiers for button
10566 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10569 unsigned int modifiers
;
10571 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10572 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10573 int hpos
, vpos
, prop_idx
;
10574 struct glyph
*glyph
;
10575 Lisp_Object enabled_p
;
10577 /* If not on the highlighted tool-bar item, return. */
10578 frame_to_window_pixel_xy (w
, &x
, &y
);
10579 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10582 /* If item is disabled, do nothing. */
10583 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10584 if (NILP (enabled_p
))
10589 /* Show item in pressed state. */
10590 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10591 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10592 last_tool_bar_item
= prop_idx
;
10596 Lisp_Object key
, frame
;
10597 struct input_event event
;
10598 EVENT_INIT (event
);
10600 /* Show item in released state. */
10601 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10602 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10604 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10606 XSETFRAME (frame
, f
);
10607 event
.kind
= TOOL_BAR_EVENT
;
10608 event
.frame_or_window
= frame
;
10610 kbd_buffer_store_event (&event
);
10612 event
.kind
= TOOL_BAR_EVENT
;
10613 event
.frame_or_window
= frame
;
10615 event
.modifiers
= modifiers
;
10616 kbd_buffer_store_event (&event
);
10617 last_tool_bar_item
= -1;
10622 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10623 tool-bar window-relative coordinates X/Y. Called from
10624 note_mouse_highlight. */
10627 note_tool_bar_highlight (f
, x
, y
)
10631 Lisp_Object window
= f
->tool_bar_window
;
10632 struct window
*w
= XWINDOW (window
);
10633 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10635 struct glyph
*glyph
;
10636 struct glyph_row
*row
;
10638 Lisp_Object enabled_p
;
10640 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10641 int mouse_down_p
, rc
;
10643 /* Function note_mouse_highlight is called with negative x(y
10644 values when mouse moves outside of the frame. */
10645 if (x
<= 0 || y
<= 0)
10647 clear_mouse_face (dpyinfo
);
10651 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10654 /* Not on tool-bar item. */
10655 clear_mouse_face (dpyinfo
);
10659 /* On same tool-bar item as before. */
10660 goto set_help_echo
;
10662 clear_mouse_face (dpyinfo
);
10664 /* Mouse is down, but on different tool-bar item? */
10665 mouse_down_p
= (dpyinfo
->grabbed
10666 && f
== last_mouse_frame
10667 && FRAME_LIVE_P (f
));
10669 && last_tool_bar_item
!= prop_idx
)
10672 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10673 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10675 /* If tool-bar item is not enabled, don't highlight it. */
10676 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10677 if (!NILP (enabled_p
))
10679 /* Compute the x-position of the glyph. In front and past the
10680 image is a space. We include this in the highlighted area. */
10681 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10682 for (i
= x
= 0; i
< hpos
; ++i
)
10683 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10685 /* Record this as the current active region. */
10686 dpyinfo
->mouse_face_beg_col
= hpos
;
10687 dpyinfo
->mouse_face_beg_row
= vpos
;
10688 dpyinfo
->mouse_face_beg_x
= x
;
10689 dpyinfo
->mouse_face_beg_y
= row
->y
;
10690 dpyinfo
->mouse_face_past_end
= 0;
10692 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10693 dpyinfo
->mouse_face_end_row
= vpos
;
10694 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10695 dpyinfo
->mouse_face_end_y
= row
->y
;
10696 dpyinfo
->mouse_face_window
= window
;
10697 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10699 /* Display it as active. */
10700 show_mouse_face (dpyinfo
, draw
);
10701 dpyinfo
->mouse_face_image_state
= draw
;
10706 /* Set help_echo_string to a help string to display for this tool-bar item.
10707 XTread_socket does the rest. */
10708 help_echo_object
= help_echo_window
= Qnil
;
10709 help_echo_pos
= -1;
10710 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10711 if (NILP (help_echo_string
))
10712 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10715 #endif /* HAVE_WINDOW_SYSTEM */
10719 /************************************************************************
10720 Horizontal scrolling
10721 ************************************************************************/
10723 static int hscroll_window_tree
P_ ((Lisp_Object
));
10724 static int hscroll_windows
P_ ((Lisp_Object
));
10726 /* For all leaf windows in the window tree rooted at WINDOW, set their
10727 hscroll value so that PT is (i) visible in the window, and (ii) so
10728 that it is not within a certain margin at the window's left and
10729 right border. Value is non-zero if any window's hscroll has been
10733 hscroll_window_tree (window
)
10734 Lisp_Object window
;
10736 int hscrolled_p
= 0;
10737 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10738 int hscroll_step_abs
= 0;
10739 double hscroll_step_rel
= 0;
10741 if (hscroll_relative_p
)
10743 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10744 if (hscroll_step_rel
< 0)
10746 hscroll_relative_p
= 0;
10747 hscroll_step_abs
= 0;
10750 else if (INTEGERP (Vhscroll_step
))
10752 hscroll_step_abs
= XINT (Vhscroll_step
);
10753 if (hscroll_step_abs
< 0)
10754 hscroll_step_abs
= 0;
10757 hscroll_step_abs
= 0;
10759 while (WINDOWP (window
))
10761 struct window
*w
= XWINDOW (window
);
10763 if (WINDOWP (w
->hchild
))
10764 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10765 else if (WINDOWP (w
->vchild
))
10766 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10767 else if (w
->cursor
.vpos
>= 0)
10770 int text_area_width
;
10771 struct glyph_row
*current_cursor_row
10772 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10773 struct glyph_row
*desired_cursor_row
10774 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10775 struct glyph_row
*cursor_row
10776 = (desired_cursor_row
->enabled_p
10777 ? desired_cursor_row
10778 : current_cursor_row
);
10780 text_area_width
= window_box_width (w
, TEXT_AREA
);
10782 /* Scroll when cursor is inside this scroll margin. */
10783 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10785 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10786 && ((XFASTINT (w
->hscroll
)
10787 && w
->cursor
.x
<= h_margin
)
10788 || (cursor_row
->enabled_p
10789 && cursor_row
->truncated_on_right_p
10790 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10794 struct buffer
*saved_current_buffer
;
10798 /* Find point in a display of infinite width. */
10799 saved_current_buffer
= current_buffer
;
10800 current_buffer
= XBUFFER (w
->buffer
);
10802 if (w
== XWINDOW (selected_window
))
10803 pt
= BUF_PT (current_buffer
);
10806 pt
= marker_position (w
->pointm
);
10807 pt
= max (BEGV
, pt
);
10811 /* Move iterator to pt starting at cursor_row->start in
10812 a line with infinite width. */
10813 init_to_row_start (&it
, w
, cursor_row
);
10814 it
.last_visible_x
= INFINITY
;
10815 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10816 current_buffer
= saved_current_buffer
;
10818 /* Position cursor in window. */
10819 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10820 hscroll
= max (0, (it
.current_x
10821 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10822 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10823 : (text_area_width
/ 2))))
10824 / FRAME_COLUMN_WIDTH (it
.f
);
10825 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10827 if (hscroll_relative_p
)
10828 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10831 wanted_x
= text_area_width
10832 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10835 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10839 if (hscroll_relative_p
)
10840 wanted_x
= text_area_width
* hscroll_step_rel
10843 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10846 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10848 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10850 /* Don't call Fset_window_hscroll if value hasn't
10851 changed because it will prevent redisplay
10853 if (XFASTINT (w
->hscroll
) != hscroll
)
10855 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10856 w
->hscroll
= make_number (hscroll
);
10865 /* Value is non-zero if hscroll of any leaf window has been changed. */
10866 return hscrolled_p
;
10870 /* Set hscroll so that cursor is visible and not inside horizontal
10871 scroll margins for all windows in the tree rooted at WINDOW. See
10872 also hscroll_window_tree above. Value is non-zero if any window's
10873 hscroll has been changed. If it has, desired matrices on the frame
10874 of WINDOW are cleared. */
10877 hscroll_windows (window
)
10878 Lisp_Object window
;
10880 int hscrolled_p
= hscroll_window_tree (window
);
10882 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10883 return hscrolled_p
;
10888 /************************************************************************
10890 ************************************************************************/
10892 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10893 to a non-zero value. This is sometimes handy to have in a debugger
10898 /* First and last unchanged row for try_window_id. */
10900 int debug_first_unchanged_at_end_vpos
;
10901 int debug_last_unchanged_at_beg_vpos
;
10903 /* Delta vpos and y. */
10905 int debug_dvpos
, debug_dy
;
10907 /* Delta in characters and bytes for try_window_id. */
10909 int debug_delta
, debug_delta_bytes
;
10911 /* Values of window_end_pos and window_end_vpos at the end of
10914 EMACS_INT debug_end_pos
, debug_end_vpos
;
10916 /* Append a string to W->desired_matrix->method. FMT is a printf
10917 format string. A1...A9 are a supplement for a variable-length
10918 argument list. If trace_redisplay_p is non-zero also printf the
10919 resulting string to stderr. */
10922 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10925 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10928 char *method
= w
->desired_matrix
->method
;
10929 int len
= strlen (method
);
10930 int size
= sizeof w
->desired_matrix
->method
;
10931 int remaining
= size
- len
- 1;
10933 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10934 if (len
&& remaining
)
10937 --remaining
, ++len
;
10940 strncpy (method
+ len
, buffer
, remaining
);
10942 if (trace_redisplay_p
)
10943 fprintf (stderr
, "%p (%s): %s\n",
10945 ((BUFFERP (w
->buffer
)
10946 && STRINGP (XBUFFER (w
->buffer
)->name
))
10947 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10952 #endif /* GLYPH_DEBUG */
10955 /* Value is non-zero if all changes in window W, which displays
10956 current_buffer, are in the text between START and END. START is a
10957 buffer position, END is given as a distance from Z. Used in
10958 redisplay_internal for display optimization. */
10961 text_outside_line_unchanged_p (w
, start
, end
)
10965 int unchanged_p
= 1;
10967 /* If text or overlays have changed, see where. */
10968 if (XFASTINT (w
->last_modified
) < MODIFF
10969 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10971 /* Gap in the line? */
10972 if (GPT
< start
|| Z
- GPT
< end
)
10975 /* Changes start in front of the line, or end after it? */
10977 && (BEG_UNCHANGED
< start
- 1
10978 || END_UNCHANGED
< end
))
10981 /* If selective display, can't optimize if changes start at the
10982 beginning of the line. */
10984 && INTEGERP (current_buffer
->selective_display
)
10985 && XINT (current_buffer
->selective_display
) > 0
10986 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10989 /* If there are overlays at the start or end of the line, these
10990 may have overlay strings with newlines in them. A change at
10991 START, for instance, may actually concern the display of such
10992 overlay strings as well, and they are displayed on different
10993 lines. So, quickly rule out this case. (For the future, it
10994 might be desirable to implement something more telling than
10995 just BEG/END_UNCHANGED.) */
10998 if (BEG
+ BEG_UNCHANGED
== start
10999 && overlay_touches_p (start
))
11001 if (END_UNCHANGED
== end
11002 && overlay_touches_p (Z
- end
))
11007 return unchanged_p
;
11011 /* Do a frame update, taking possible shortcuts into account. This is
11012 the main external entry point for redisplay.
11014 If the last redisplay displayed an echo area message and that message
11015 is no longer requested, we clear the echo area or bring back the
11016 mini-buffer if that is in use. */
11021 redisplay_internal (0);
11026 overlay_arrow_string_or_property (var
)
11031 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11034 return Voverlay_arrow_string
;
11037 /* Return 1 if there are any overlay-arrows in current_buffer. */
11039 overlay_arrow_in_current_buffer_p ()
11043 for (vlist
= Voverlay_arrow_variable_list
;
11045 vlist
= XCDR (vlist
))
11047 Lisp_Object var
= XCAR (vlist
);
11050 if (!SYMBOLP (var
))
11052 val
= find_symbol_value (var
);
11054 && current_buffer
== XMARKER (val
)->buffer
)
11061 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11065 overlay_arrows_changed_p ()
11069 for (vlist
= Voverlay_arrow_variable_list
;
11071 vlist
= XCDR (vlist
))
11073 Lisp_Object var
= XCAR (vlist
);
11074 Lisp_Object val
, pstr
;
11076 if (!SYMBOLP (var
))
11078 val
= find_symbol_value (var
);
11079 if (!MARKERP (val
))
11081 if (! EQ (COERCE_MARKER (val
),
11082 Fget (var
, Qlast_arrow_position
))
11083 || ! (pstr
= overlay_arrow_string_or_property (var
),
11084 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11090 /* Mark overlay arrows to be updated on next redisplay. */
11093 update_overlay_arrows (up_to_date
)
11098 for (vlist
= Voverlay_arrow_variable_list
;
11100 vlist
= XCDR (vlist
))
11102 Lisp_Object var
= XCAR (vlist
);
11104 if (!SYMBOLP (var
))
11107 if (up_to_date
> 0)
11109 Lisp_Object val
= find_symbol_value (var
);
11110 Fput (var
, Qlast_arrow_position
,
11111 COERCE_MARKER (val
));
11112 Fput (var
, Qlast_arrow_string
,
11113 overlay_arrow_string_or_property (var
));
11115 else if (up_to_date
< 0
11116 || !NILP (Fget (var
, Qlast_arrow_position
)))
11118 Fput (var
, Qlast_arrow_position
, Qt
);
11119 Fput (var
, Qlast_arrow_string
, Qt
);
11125 /* Return overlay arrow string to display at row.
11126 Return integer (bitmap number) for arrow bitmap in left fringe.
11127 Return nil if no overlay arrow. */
11130 overlay_arrow_at_row (it
, row
)
11132 struct glyph_row
*row
;
11136 for (vlist
= Voverlay_arrow_variable_list
;
11138 vlist
= XCDR (vlist
))
11140 Lisp_Object var
= XCAR (vlist
);
11143 if (!SYMBOLP (var
))
11146 val
= find_symbol_value (var
);
11149 && current_buffer
== XMARKER (val
)->buffer
11150 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11152 if (FRAME_WINDOW_P (it
->f
)
11153 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11155 #ifdef HAVE_WINDOW_SYSTEM
11156 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11159 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11160 return make_number (fringe_bitmap
);
11163 return make_number (-1); /* Use default arrow bitmap */
11165 return overlay_arrow_string_or_property (var
);
11172 /* Return 1 if point moved out of or into a composition. Otherwise
11173 return 0. PREV_BUF and PREV_PT are the last point buffer and
11174 position. BUF and PT are the current point buffer and position. */
11177 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11178 struct buffer
*prev_buf
, *buf
;
11181 EMACS_INT start
, end
;
11183 Lisp_Object buffer
;
11185 XSETBUFFER (buffer
, buf
);
11186 /* Check a composition at the last point if point moved within the
11188 if (prev_buf
== buf
)
11191 /* Point didn't move. */
11194 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11195 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11196 && COMPOSITION_VALID_P (start
, end
, prop
)
11197 && start
< prev_pt
&& end
> prev_pt
)
11198 /* The last point was within the composition. Return 1 iff
11199 point moved out of the composition. */
11200 return (pt
<= start
|| pt
>= end
);
11203 /* Check a composition at the current point. */
11204 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11205 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11206 && COMPOSITION_VALID_P (start
, end
, prop
)
11207 && start
< pt
&& end
> pt
);
11211 /* Reconsider the setting of B->clip_changed which is displayed
11215 reconsider_clip_changes (w
, b
)
11219 if (b
->clip_changed
11220 && !NILP (w
->window_end_valid
)
11221 && w
->current_matrix
->buffer
== b
11222 && w
->current_matrix
->zv
== BUF_ZV (b
)
11223 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11224 b
->clip_changed
= 0;
11226 /* If display wasn't paused, and W is not a tool bar window, see if
11227 point has been moved into or out of a composition. In that case,
11228 we set b->clip_changed to 1 to force updating the screen. If
11229 b->clip_changed has already been set to 1, we can skip this
11231 if (!b
->clip_changed
11232 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11236 if (w
== XWINDOW (selected_window
))
11237 pt
= BUF_PT (current_buffer
);
11239 pt
= marker_position (w
->pointm
);
11241 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11242 || pt
!= XINT (w
->last_point
))
11243 && check_point_in_composition (w
->current_matrix
->buffer
,
11244 XINT (w
->last_point
),
11245 XBUFFER (w
->buffer
), pt
))
11246 b
->clip_changed
= 1;
11251 /* Select FRAME to forward the values of frame-local variables into C
11252 variables so that the redisplay routines can access those values
11256 select_frame_for_redisplay (frame
)
11259 Lisp_Object tail
, symbol
, val
;
11260 Lisp_Object old
= selected_frame
;
11261 struct Lisp_Symbol
*sym
;
11263 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11265 selected_frame
= frame
;
11269 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11270 if (CONSP (XCAR (tail
))
11271 && (symbol
= XCAR (XCAR (tail
)),
11273 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11275 (BUFFER_LOCAL_VALUEP (val
)))
11276 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11277 /* Use find_symbol_value rather than Fsymbol_value
11278 to avoid an error if it is void. */
11279 find_symbol_value (symbol
);
11280 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11284 #define STOP_POLLING \
11285 do { if (! polling_stopped_here) stop_polling (); \
11286 polling_stopped_here = 1; } while (0)
11288 #define RESUME_POLLING \
11289 do { if (polling_stopped_here) start_polling (); \
11290 polling_stopped_here = 0; } while (0)
11293 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11294 response to any user action; therefore, we should preserve the echo
11295 area. (Actually, our caller does that job.) Perhaps in the future
11296 avoid recentering windows if it is not necessary; currently that
11297 causes some problems. */
11300 redisplay_internal (preserve_echo_area
)
11301 int preserve_echo_area
;
11303 struct window
*w
= XWINDOW (selected_window
);
11306 int must_finish
= 0;
11307 struct text_pos tlbufpos
, tlendpos
;
11308 int number_of_visible_frames
;
11311 int polling_stopped_here
= 0;
11312 Lisp_Object old_frame
= selected_frame
;
11314 /* Non-zero means redisplay has to consider all windows on all
11315 frames. Zero means, only selected_window is considered. */
11316 int consider_all_windows_p
;
11318 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11320 /* No redisplay if running in batch mode or frame is not yet fully
11321 initialized, or redisplay is explicitly turned off by setting
11322 Vinhibit_redisplay. */
11323 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11324 || !NILP (Vinhibit_redisplay
))
11327 /* Don't examine these until after testing Vinhibit_redisplay.
11328 When Emacs is shutting down, perhaps because its connection to
11329 X has dropped, we should not look at them at all. */
11330 f
= XFRAME (w
->frame
);
11331 sf
= SELECTED_FRAME ();
11333 if (!f
->glyphs_initialized_p
)
11336 /* The flag redisplay_performed_directly_p is set by
11337 direct_output_for_insert when it already did the whole screen
11338 update necessary. */
11339 if (redisplay_performed_directly_p
)
11341 redisplay_performed_directly_p
= 0;
11342 if (!hscroll_windows (selected_window
))
11346 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11347 if (popup_activated ())
11351 /* I don't think this happens but let's be paranoid. */
11352 if (redisplaying_p
)
11355 /* Record a function that resets redisplaying_p to its old value
11356 when we leave this function. */
11357 count
= SPECPDL_INDEX ();
11358 record_unwind_protect (unwind_redisplay
,
11359 Fcons (make_number (redisplaying_p
), selected_frame
));
11361 specbind (Qinhibit_free_realized_faces
, Qnil
);
11364 Lisp_Object tail
, frame
;
11366 FOR_EACH_FRAME (tail
, frame
)
11368 struct frame
*f
= XFRAME (frame
);
11369 f
->already_hscrolled_p
= 0;
11374 if (!EQ (old_frame
, selected_frame
)
11375 && FRAME_LIVE_P (XFRAME (old_frame
)))
11376 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11377 selected_frame and selected_window to be temporarily out-of-sync so
11378 when we come back here via `goto retry', we need to resync because we
11379 may need to run Elisp code (via prepare_menu_bars). */
11380 select_frame_for_redisplay (old_frame
);
11383 reconsider_clip_changes (w
, current_buffer
);
11384 last_escape_glyph_frame
= NULL
;
11385 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11387 /* If new fonts have been loaded that make a glyph matrix adjustment
11388 necessary, do it. */
11389 if (fonts_changed_p
)
11391 adjust_glyphs (NULL
);
11392 ++windows_or_buffers_changed
;
11393 fonts_changed_p
= 0;
11396 /* If face_change_count is non-zero, init_iterator will free all
11397 realized faces, which includes the faces referenced from current
11398 matrices. So, we can't reuse current matrices in this case. */
11399 if (face_change_count
)
11400 ++windows_or_buffers_changed
;
11402 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11403 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11405 /* Since frames on a single ASCII terminal share the same
11406 display area, displaying a different frame means redisplay
11407 the whole thing. */
11408 windows_or_buffers_changed
++;
11409 SET_FRAME_GARBAGED (sf
);
11411 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11413 FRAME_TTY (sf
)->previous_frame
= sf
;
11416 /* Set the visible flags for all frames. Do this before checking
11417 for resized or garbaged frames; they want to know if their frames
11418 are visible. See the comment in frame.h for
11419 FRAME_SAMPLE_VISIBILITY. */
11421 Lisp_Object tail
, frame
;
11423 number_of_visible_frames
= 0;
11425 FOR_EACH_FRAME (tail
, frame
)
11427 struct frame
*f
= XFRAME (frame
);
11429 FRAME_SAMPLE_VISIBILITY (f
);
11430 if (FRAME_VISIBLE_P (f
))
11431 ++number_of_visible_frames
;
11432 clear_desired_matrices (f
);
11436 /* Notice any pending interrupt request to change frame size. */
11437 do_pending_window_change (1);
11439 /* Clear frames marked as garbaged. */
11440 if (frame_garbaged
)
11441 clear_garbaged_frames ();
11443 /* Build menubar and tool-bar items. */
11444 if (NILP (Vmemory_full
))
11445 prepare_menu_bars ();
11447 if (windows_or_buffers_changed
)
11448 update_mode_lines
++;
11450 /* Detect case that we need to write or remove a star in the mode line. */
11451 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11453 w
->update_mode_line
= Qt
;
11454 if (buffer_shared
> 1)
11455 update_mode_lines
++;
11458 /* Avoid invocation of point motion hooks by `current_column' below. */
11459 count1
= SPECPDL_INDEX ();
11460 specbind (Qinhibit_point_motion_hooks
, Qt
);
11462 /* If %c is in the mode line, update it if needed. */
11463 if (!NILP (w
->column_number_displayed
)
11464 /* This alternative quickly identifies a common case
11465 where no change is needed. */
11466 && !(PT
== XFASTINT (w
->last_point
)
11467 && XFASTINT (w
->last_modified
) >= MODIFF
11468 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11469 && (XFASTINT (w
->column_number_displayed
)
11470 != (int) current_column ())) /* iftc */
11471 w
->update_mode_line
= Qt
;
11473 unbind_to (count1
, Qnil
);
11475 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11477 /* The variable buffer_shared is set in redisplay_window and
11478 indicates that we redisplay a buffer in different windows. See
11480 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11481 || cursor_type_changed
);
11483 /* If specs for an arrow have changed, do thorough redisplay
11484 to ensure we remove any arrow that should no longer exist. */
11485 if (overlay_arrows_changed_p ())
11486 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11488 /* Normally the message* functions will have already displayed and
11489 updated the echo area, but the frame may have been trashed, or
11490 the update may have been preempted, so display the echo area
11491 again here. Checking message_cleared_p captures the case that
11492 the echo area should be cleared. */
11493 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11494 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11495 || (message_cleared_p
11496 && minibuf_level
== 0
11497 /* If the mini-window is currently selected, this means the
11498 echo-area doesn't show through. */
11499 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11501 int window_height_changed_p
= echo_area_display (0);
11504 /* If we don't display the current message, don't clear the
11505 message_cleared_p flag, because, if we did, we wouldn't clear
11506 the echo area in the next redisplay which doesn't preserve
11508 if (!display_last_displayed_message_p
)
11509 message_cleared_p
= 0;
11511 if (fonts_changed_p
)
11513 else if (window_height_changed_p
)
11515 consider_all_windows_p
= 1;
11516 ++update_mode_lines
;
11517 ++windows_or_buffers_changed
;
11519 /* If window configuration was changed, frames may have been
11520 marked garbaged. Clear them or we will experience
11521 surprises wrt scrolling. */
11522 if (frame_garbaged
)
11523 clear_garbaged_frames ();
11526 else if (EQ (selected_window
, minibuf_window
)
11527 && (current_buffer
->clip_changed
11528 || XFASTINT (w
->last_modified
) < MODIFF
11529 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11530 && resize_mini_window (w
, 0))
11532 /* Resized active mini-window to fit the size of what it is
11533 showing if its contents might have changed. */
11535 /* FIXME: this causes all frames to be updated, which seems unnecessary
11536 since only the current frame needs to be considered. This function needs
11537 to be rewritten with two variables, consider_all_windows and
11538 consider_all_frames. */
11539 consider_all_windows_p
= 1;
11540 ++windows_or_buffers_changed
;
11541 ++update_mode_lines
;
11543 /* If window configuration was changed, frames may have been
11544 marked garbaged. Clear them or we will experience
11545 surprises wrt scrolling. */
11546 if (frame_garbaged
)
11547 clear_garbaged_frames ();
11551 /* If showing the region, and mark has changed, we must redisplay
11552 the whole window. The assignment to this_line_start_pos prevents
11553 the optimization directly below this if-statement. */
11554 if (((!NILP (Vtransient_mark_mode
)
11555 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11556 != !NILP (w
->region_showing
))
11557 || (!NILP (w
->region_showing
)
11558 && !EQ (w
->region_showing
,
11559 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11560 CHARPOS (this_line_start_pos
) = 0;
11562 /* Optimize the case that only the line containing the cursor in the
11563 selected window has changed. Variables starting with this_ are
11564 set in display_line and record information about the line
11565 containing the cursor. */
11566 tlbufpos
= this_line_start_pos
;
11567 tlendpos
= this_line_end_pos
;
11568 if (!consider_all_windows_p
11569 && CHARPOS (tlbufpos
) > 0
11570 && NILP (w
->update_mode_line
)
11571 && !current_buffer
->clip_changed
11572 && !current_buffer
->prevent_redisplay_optimizations_p
11573 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11574 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11575 /* Make sure recorded data applies to current buffer, etc. */
11576 && this_line_buffer
== current_buffer
11577 && current_buffer
== XBUFFER (w
->buffer
)
11578 && NILP (w
->force_start
)
11579 && NILP (w
->optional_new_start
)
11580 /* Point must be on the line that we have info recorded about. */
11581 && PT
>= CHARPOS (tlbufpos
)
11582 && PT
<= Z
- CHARPOS (tlendpos
)
11583 /* All text outside that line, including its final newline,
11584 must be unchanged */
11585 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11586 CHARPOS (tlendpos
)))
11588 if (CHARPOS (tlbufpos
) > BEGV
11589 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11590 && (CHARPOS (tlbufpos
) == ZV
11591 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11592 /* Former continuation line has disappeared by becoming empty */
11594 else if (XFASTINT (w
->last_modified
) < MODIFF
11595 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11596 || MINI_WINDOW_P (w
))
11598 /* We have to handle the case of continuation around a
11599 wide-column character (See the comment in indent.c around
11602 For instance, in the following case:
11604 -------- Insert --------
11605 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11606 J_I_ ==> J_I_ `^^' are cursors.
11610 As we have to redraw the line above, we should goto cancel. */
11613 int line_height_before
= this_line_pixel_height
;
11615 /* Note that start_display will handle the case that the
11616 line starting at tlbufpos is a continuation lines. */
11617 start_display (&it
, w
, tlbufpos
);
11619 /* Implementation note: It this still necessary? */
11620 if (it
.current_x
!= this_line_start_x
)
11623 TRACE ((stderr
, "trying display optimization 1\n"));
11624 w
->cursor
.vpos
= -1;
11625 overlay_arrow_seen
= 0;
11626 it
.vpos
= this_line_vpos
;
11627 it
.current_y
= this_line_y
;
11628 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11629 display_line (&it
);
11631 /* If line contains point, is not continued,
11632 and ends at same distance from eob as before, we win */
11633 if (w
->cursor
.vpos
>= 0
11634 /* Line is not continued, otherwise this_line_start_pos
11635 would have been set to 0 in display_line. */
11636 && CHARPOS (this_line_start_pos
)
11637 /* Line ends as before. */
11638 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11639 /* Line has same height as before. Otherwise other lines
11640 would have to be shifted up or down. */
11641 && this_line_pixel_height
== line_height_before
)
11643 /* If this is not the window's last line, we must adjust
11644 the charstarts of the lines below. */
11645 if (it
.current_y
< it
.last_visible_y
)
11647 struct glyph_row
*row
11648 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11649 int delta
, delta_bytes
;
11651 if (Z
- CHARPOS (tlendpos
) == ZV
)
11653 /* This line ends at end of (accessible part of)
11654 buffer. There is no newline to count. */
11656 - CHARPOS (tlendpos
)
11657 - MATRIX_ROW_START_CHARPOS (row
));
11658 delta_bytes
= (Z_BYTE
11659 - BYTEPOS (tlendpos
)
11660 - MATRIX_ROW_START_BYTEPOS (row
));
11664 /* This line ends in a newline. Must take
11665 account of the newline and the rest of the
11666 text that follows. */
11668 - CHARPOS (tlendpos
)
11669 - MATRIX_ROW_START_CHARPOS (row
));
11670 delta_bytes
= (Z_BYTE
11671 - BYTEPOS (tlendpos
)
11672 - MATRIX_ROW_START_BYTEPOS (row
));
11675 increment_matrix_positions (w
->current_matrix
,
11676 this_line_vpos
+ 1,
11677 w
->current_matrix
->nrows
,
11678 delta
, delta_bytes
);
11681 /* If this row displays text now but previously didn't,
11682 or vice versa, w->window_end_vpos may have to be
11684 if ((it
.glyph_row
- 1)->displays_text_p
)
11686 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11687 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11689 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11690 && this_line_vpos
> 0)
11691 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11692 w
->window_end_valid
= Qnil
;
11694 /* Update hint: No need to try to scroll in update_window. */
11695 w
->desired_matrix
->no_scrolling_p
= 1;
11698 *w
->desired_matrix
->method
= 0;
11699 debug_method_add (w
, "optimization 1");
11701 #ifdef HAVE_WINDOW_SYSTEM
11702 update_window_fringes (w
, 0);
11709 else if (/* Cursor position hasn't changed. */
11710 PT
== XFASTINT (w
->last_point
)
11711 /* Make sure the cursor was last displayed
11712 in this window. Otherwise we have to reposition it. */
11713 && 0 <= w
->cursor
.vpos
11714 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11718 do_pending_window_change (1);
11720 /* We used to always goto end_of_redisplay here, but this
11721 isn't enough if we have a blinking cursor. */
11722 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11723 goto end_of_redisplay
;
11727 /* If highlighting the region, or if the cursor is in the echo area,
11728 then we can't just move the cursor. */
11729 else if (! (!NILP (Vtransient_mark_mode
)
11730 && !NILP (current_buffer
->mark_active
))
11731 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11732 || highlight_nonselected_windows
)
11733 && NILP (w
->region_showing
)
11734 && NILP (Vshow_trailing_whitespace
)
11735 && !cursor_in_echo_area
)
11738 struct glyph_row
*row
;
11740 /* Skip from tlbufpos to PT and see where it is. Note that
11741 PT may be in invisible text. If so, we will end at the
11742 next visible position. */
11743 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11744 NULL
, DEFAULT_FACE_ID
);
11745 it
.current_x
= this_line_start_x
;
11746 it
.current_y
= this_line_y
;
11747 it
.vpos
= this_line_vpos
;
11749 /* The call to move_it_to stops in front of PT, but
11750 moves over before-strings. */
11751 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11753 if (it
.vpos
== this_line_vpos
11754 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11757 xassert (this_line_vpos
== it
.vpos
);
11758 xassert (this_line_y
== it
.current_y
);
11759 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11761 *w
->desired_matrix
->method
= 0;
11762 debug_method_add (w
, "optimization 3");
11771 /* Text changed drastically or point moved off of line. */
11772 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11775 CHARPOS (this_line_start_pos
) = 0;
11776 consider_all_windows_p
|= buffer_shared
> 1;
11777 ++clear_face_cache_count
;
11778 #ifdef HAVE_WINDOW_SYSTEM
11779 ++clear_image_cache_count
;
11782 /* Build desired matrices, and update the display. If
11783 consider_all_windows_p is non-zero, do it for all windows on all
11784 frames. Otherwise do it for selected_window, only. */
11786 if (consider_all_windows_p
)
11788 Lisp_Object tail
, frame
;
11790 FOR_EACH_FRAME (tail
, frame
)
11791 XFRAME (frame
)->updated_p
= 0;
11793 /* Recompute # windows showing selected buffer. This will be
11794 incremented each time such a window is displayed. */
11797 FOR_EACH_FRAME (tail
, frame
)
11799 struct frame
*f
= XFRAME (frame
);
11801 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11803 if (! EQ (frame
, selected_frame
))
11804 /* Select the frame, for the sake of frame-local
11806 select_frame_for_redisplay (frame
);
11808 /* Mark all the scroll bars to be removed; we'll redeem
11809 the ones we want when we redisplay their windows. */
11810 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11811 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11813 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11814 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11816 /* The X error handler may have deleted that frame. */
11817 if (!FRAME_LIVE_P (f
))
11820 /* Any scroll bars which redisplay_windows should have
11821 nuked should now go away. */
11822 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11823 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11825 /* If fonts changed, display again. */
11826 /* ??? rms: I suspect it is a mistake to jump all the way
11827 back to retry here. It should just retry this frame. */
11828 if (fonts_changed_p
)
11831 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11833 /* See if we have to hscroll. */
11834 if (!f
->already_hscrolled_p
)
11836 f
->already_hscrolled_p
= 1;
11837 if (hscroll_windows (f
->root_window
))
11841 /* Prevent various kinds of signals during display
11842 update. stdio is not robust about handling
11843 signals, which can cause an apparent I/O
11845 if (interrupt_input
)
11846 unrequest_sigio ();
11849 /* Update the display. */
11850 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11851 pause
|= update_frame (f
, 0, 0);
11857 if (!EQ (old_frame
, selected_frame
)
11858 && FRAME_LIVE_P (XFRAME (old_frame
)))
11859 /* We played a bit fast-and-loose above and allowed selected_frame
11860 and selected_window to be temporarily out-of-sync but let's make
11861 sure this stays contained. */
11862 select_frame_for_redisplay (old_frame
);
11863 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11867 /* Do the mark_window_display_accurate after all windows have
11868 been redisplayed because this call resets flags in buffers
11869 which are needed for proper redisplay. */
11870 FOR_EACH_FRAME (tail
, frame
)
11872 struct frame
*f
= XFRAME (frame
);
11875 mark_window_display_accurate (f
->root_window
, 1);
11876 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11877 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11882 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11884 Lisp_Object mini_window
;
11885 struct frame
*mini_frame
;
11887 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11888 /* Use list_of_error, not Qerror, so that
11889 we catch only errors and don't run the debugger. */
11890 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11892 redisplay_window_error
);
11894 /* Compare desired and current matrices, perform output. */
11897 /* If fonts changed, display again. */
11898 if (fonts_changed_p
)
11901 /* Prevent various kinds of signals during display update.
11902 stdio is not robust about handling signals,
11903 which can cause an apparent I/O error. */
11904 if (interrupt_input
)
11905 unrequest_sigio ();
11908 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11910 if (hscroll_windows (selected_window
))
11913 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11914 pause
= update_frame (sf
, 0, 0);
11917 /* We may have called echo_area_display at the top of this
11918 function. If the echo area is on another frame, that may
11919 have put text on a frame other than the selected one, so the
11920 above call to update_frame would not have caught it. Catch
11922 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11923 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11925 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11927 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11928 pause
|= update_frame (mini_frame
, 0, 0);
11929 if (!pause
&& hscroll_windows (mini_window
))
11934 /* If display was paused because of pending input, make sure we do a
11935 thorough update the next time. */
11938 /* Prevent the optimization at the beginning of
11939 redisplay_internal that tries a single-line update of the
11940 line containing the cursor in the selected window. */
11941 CHARPOS (this_line_start_pos
) = 0;
11943 /* Let the overlay arrow be updated the next time. */
11944 update_overlay_arrows (0);
11946 /* If we pause after scrolling, some rows in the current
11947 matrices of some windows are not valid. */
11948 if (!WINDOW_FULL_WIDTH_P (w
)
11949 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11950 update_mode_lines
= 1;
11954 if (!consider_all_windows_p
)
11956 /* This has already been done above if
11957 consider_all_windows_p is set. */
11958 mark_window_display_accurate_1 (w
, 1);
11960 /* Say overlay arrows are up to date. */
11961 update_overlay_arrows (1);
11963 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11964 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11967 update_mode_lines
= 0;
11968 windows_or_buffers_changed
= 0;
11969 cursor_type_changed
= 0;
11972 /* Start SIGIO interrupts coming again. Having them off during the
11973 code above makes it less likely one will discard output, but not
11974 impossible, since there might be stuff in the system buffer here.
11975 But it is much hairier to try to do anything about that. */
11976 if (interrupt_input
)
11980 /* If a frame has become visible which was not before, redisplay
11981 again, so that we display it. Expose events for such a frame
11982 (which it gets when becoming visible) don't call the parts of
11983 redisplay constructing glyphs, so simply exposing a frame won't
11984 display anything in this case. So, we have to display these
11985 frames here explicitly. */
11988 Lisp_Object tail
, frame
;
11991 FOR_EACH_FRAME (tail
, frame
)
11993 int this_is_visible
= 0;
11995 if (XFRAME (frame
)->visible
)
11996 this_is_visible
= 1;
11997 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11998 if (XFRAME (frame
)->visible
)
11999 this_is_visible
= 1;
12001 if (this_is_visible
)
12005 if (new_count
!= number_of_visible_frames
)
12006 windows_or_buffers_changed
++;
12009 /* Change frame size now if a change is pending. */
12010 do_pending_window_change (1);
12012 /* If we just did a pending size change, or have additional
12013 visible frames, redisplay again. */
12014 if (windows_or_buffers_changed
&& !pause
)
12017 /* Clear the face cache eventually. */
12018 if (consider_all_windows_p
)
12020 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12022 clear_face_cache (0);
12023 clear_face_cache_count
= 0;
12025 #ifdef HAVE_WINDOW_SYSTEM
12026 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12028 clear_image_caches (Qnil
);
12029 clear_image_cache_count
= 0;
12031 #endif /* HAVE_WINDOW_SYSTEM */
12035 unbind_to (count
, Qnil
);
12040 /* Redisplay, but leave alone any recent echo area message unless
12041 another message has been requested in its place.
12043 This is useful in situations where you need to redisplay but no
12044 user action has occurred, making it inappropriate for the message
12045 area to be cleared. See tracking_off and
12046 wait_reading_process_output for examples of these situations.
12048 FROM_WHERE is an integer saying from where this function was
12049 called. This is useful for debugging. */
12052 redisplay_preserve_echo_area (from_where
)
12055 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12057 if (!NILP (echo_area_buffer
[1]))
12059 /* We have a previously displayed message, but no current
12060 message. Redisplay the previous message. */
12061 display_last_displayed_message_p
= 1;
12062 redisplay_internal (1);
12063 display_last_displayed_message_p
= 0;
12066 redisplay_internal (1);
12068 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12069 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12070 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12074 /* Function registered with record_unwind_protect in
12075 redisplay_internal. Reset redisplaying_p to the value it had
12076 before redisplay_internal was called, and clear
12077 prevent_freeing_realized_faces_p. It also selects the previously
12078 selected frame, unless it has been deleted (by an X connection
12079 failure during redisplay, for example). */
12082 unwind_redisplay (val
)
12085 Lisp_Object old_redisplaying_p
, old_frame
;
12087 old_redisplaying_p
= XCAR (val
);
12088 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12089 old_frame
= XCDR (val
);
12090 if (! EQ (old_frame
, selected_frame
)
12091 && FRAME_LIVE_P (XFRAME (old_frame
)))
12092 select_frame_for_redisplay (old_frame
);
12097 /* Mark the display of window W as accurate or inaccurate. If
12098 ACCURATE_P is non-zero mark display of W as accurate. If
12099 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12100 redisplay_internal is called. */
12103 mark_window_display_accurate_1 (w
, accurate_p
)
12107 if (BUFFERP (w
->buffer
))
12109 struct buffer
*b
= XBUFFER (w
->buffer
);
12112 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12113 w
->last_overlay_modified
12114 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12116 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12120 b
->clip_changed
= 0;
12121 b
->prevent_redisplay_optimizations_p
= 0;
12123 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12124 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12125 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12126 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12128 w
->current_matrix
->buffer
= b
;
12129 w
->current_matrix
->begv
= BUF_BEGV (b
);
12130 w
->current_matrix
->zv
= BUF_ZV (b
);
12132 w
->last_cursor
= w
->cursor
;
12133 w
->last_cursor_off_p
= w
->cursor_off_p
;
12135 if (w
== XWINDOW (selected_window
))
12136 w
->last_point
= make_number (BUF_PT (b
));
12138 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12144 w
->window_end_valid
= w
->buffer
;
12145 w
->update_mode_line
= Qnil
;
12150 /* Mark the display of windows in the window tree rooted at WINDOW as
12151 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12152 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12153 be redisplayed the next time redisplay_internal is called. */
12156 mark_window_display_accurate (window
, accurate_p
)
12157 Lisp_Object window
;
12162 for (; !NILP (window
); window
= w
->next
)
12164 w
= XWINDOW (window
);
12165 mark_window_display_accurate_1 (w
, accurate_p
);
12167 if (!NILP (w
->vchild
))
12168 mark_window_display_accurate (w
->vchild
, accurate_p
);
12169 if (!NILP (w
->hchild
))
12170 mark_window_display_accurate (w
->hchild
, accurate_p
);
12175 update_overlay_arrows (1);
12179 /* Force a thorough redisplay the next time by setting
12180 last_arrow_position and last_arrow_string to t, which is
12181 unequal to any useful value of Voverlay_arrow_... */
12182 update_overlay_arrows (-1);
12187 /* Return value in display table DP (Lisp_Char_Table *) for character
12188 C. Since a display table doesn't have any parent, we don't have to
12189 follow parent. Do not call this function directly but use the
12190 macro DISP_CHAR_VECTOR. */
12193 disp_char_vector (dp
, c
)
12194 struct Lisp_Char_Table
*dp
;
12199 if (ASCII_CHAR_P (c
))
12202 if (SUB_CHAR_TABLE_P (val
))
12203 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12209 XSETCHAR_TABLE (table
, dp
);
12210 val
= char_table_ref (table
, c
);
12219 /***********************************************************************
12221 ***********************************************************************/
12223 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12226 redisplay_windows (window
)
12227 Lisp_Object window
;
12229 while (!NILP (window
))
12231 struct window
*w
= XWINDOW (window
);
12233 if (!NILP (w
->hchild
))
12234 redisplay_windows (w
->hchild
);
12235 else if (!NILP (w
->vchild
))
12236 redisplay_windows (w
->vchild
);
12237 else if (!NILP (w
->buffer
))
12239 displayed_buffer
= XBUFFER (w
->buffer
);
12240 /* Use list_of_error, not Qerror, so that
12241 we catch only errors and don't run the debugger. */
12242 internal_condition_case_1 (redisplay_window_0
, window
,
12244 redisplay_window_error
);
12252 redisplay_window_error ()
12254 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12259 redisplay_window_0 (window
)
12260 Lisp_Object window
;
12262 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12263 redisplay_window (window
, 0);
12268 redisplay_window_1 (window
)
12269 Lisp_Object window
;
12271 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12272 redisplay_window (window
, 1);
12277 /* Increment GLYPH until it reaches END or CONDITION fails while
12278 adding (GLYPH)->pixel_width to X. */
12280 #define SKIP_GLYPHS(glyph, end, x, condition) \
12283 (x) += (glyph)->pixel_width; \
12286 while ((glyph) < (end) && (condition))
12289 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12290 DELTA is the number of bytes by which positions recorded in ROW
12291 differ from current buffer positions.
12293 Return 0 if cursor is not on this row. 1 otherwise. */
12296 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12298 struct glyph_row
*row
;
12299 struct glyph_matrix
*matrix
;
12300 int delta
, delta_bytes
, dy
, dvpos
;
12302 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12303 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12304 struct glyph
*cursor
= NULL
;
12305 /* The first glyph that starts a sequence of glyphs from string. */
12306 struct glyph
*string_start
;
12307 /* The X coordinate of string_start. */
12308 int string_start_x
;
12309 /* The last known character position. */
12310 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12311 /* The last known character position before string_start. */
12312 int string_before_pos
;
12315 int cursor_from_overlay_pos
= 0;
12316 int pt_old
= PT
- delta
;
12318 /* Skip over glyphs not having an object at the start of the row.
12319 These are special glyphs like truncation marks on terminal
12321 if (row
->displays_text_p
)
12323 && INTEGERP (glyph
->object
)
12324 && glyph
->charpos
< 0)
12326 x
+= glyph
->pixel_width
;
12330 string_start
= NULL
;
12332 && !INTEGERP (glyph
->object
)
12333 && (!BUFFERP (glyph
->object
)
12334 || (last_pos
= glyph
->charpos
) < pt_old
12335 || glyph
->avoid_cursor_p
))
12337 if (! STRINGP (glyph
->object
))
12339 string_start
= NULL
;
12340 x
+= glyph
->pixel_width
;
12342 if (cursor_from_overlay_pos
12343 && last_pos
>= cursor_from_overlay_pos
)
12345 cursor_from_overlay_pos
= 0;
12351 if (string_start
== NULL
)
12353 string_before_pos
= last_pos
;
12354 string_start
= glyph
;
12355 string_start_x
= x
;
12357 /* Skip all glyphs from string. */
12362 if ((cursor
== NULL
|| glyph
> cursor
)
12363 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12364 Qcursor
, (glyph
)->object
),
12366 && (pos
= string_buffer_position (w
, glyph
->object
,
12367 string_before_pos
),
12368 (pos
== 0 /* From overlay */
12369 || pos
== pt_old
)))
12371 /* Estimate overlay buffer position from the buffer
12372 positions of the glyphs before and after the overlay.
12373 Add 1 to last_pos so that if point corresponds to the
12374 glyph right after the overlay, we still use a 'cursor'
12375 property found in that overlay. */
12376 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12377 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12381 x
+= glyph
->pixel_width
;
12384 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12388 if (cursor
!= NULL
)
12393 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12395 /* Scan back over the ellipsis glyphs, decrementing positions. */
12396 while (glyph
> row
->glyphs
[TEXT_AREA
]
12397 && (glyph
- 1)->charpos
== last_pos
)
12398 glyph
--, x
-= glyph
->pixel_width
;
12399 /* That loop always goes one position too far,
12400 including the glyph before the ellipsis.
12401 So scan forward over that one. */
12402 x
+= glyph
->pixel_width
;
12405 else if (string_start
12406 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12408 /* We may have skipped over point because the previous glyphs
12409 are from string. As there's no easy way to know the
12410 character position of the current glyph, find the correct
12411 glyph on point by scanning from string_start again. */
12413 Lisp_Object string
;
12414 struct glyph
*stop
= glyph
;
12417 limit
= make_number (pt_old
+ 1);
12418 glyph
= string_start
;
12419 x
= string_start_x
;
12420 string
= glyph
->object
;
12421 pos
= string_buffer_position (w
, string
, string_before_pos
);
12422 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12423 because we always put cursor after overlay strings. */
12424 while (pos
== 0 && glyph
< stop
)
12426 string
= glyph
->object
;
12427 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12429 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12432 while (glyph
< stop
)
12434 pos
= XINT (Fnext_single_char_property_change
12435 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12438 /* Skip glyphs from the same string. */
12439 string
= glyph
->object
;
12440 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12441 /* Skip glyphs from an overlay. */
12442 while (glyph
< stop
12443 && ! string_buffer_position (w
, glyph
->object
, pos
))
12445 string
= glyph
->object
;
12446 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12450 /* If we reached the end of the line, and end was from a string,
12451 cursor is not on this line. */
12452 if (glyph
== end
&& row
->continued_p
)
12456 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12458 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12459 w
->cursor
.y
= row
->y
+ dy
;
12461 if (w
== XWINDOW (selected_window
))
12463 if (!row
->continued_p
12464 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12467 this_line_buffer
= XBUFFER (w
->buffer
);
12469 CHARPOS (this_line_start_pos
)
12470 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12471 BYTEPOS (this_line_start_pos
)
12472 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12474 CHARPOS (this_line_end_pos
)
12475 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12476 BYTEPOS (this_line_end_pos
)
12477 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12479 this_line_y
= w
->cursor
.y
;
12480 this_line_pixel_height
= row
->height
;
12481 this_line_vpos
= w
->cursor
.vpos
;
12482 this_line_start_x
= row
->x
;
12485 CHARPOS (this_line_start_pos
) = 0;
12492 /* Run window scroll functions, if any, for WINDOW with new window
12493 start STARTP. Sets the window start of WINDOW to that position.
12495 We assume that the window's buffer is really current. */
12497 static INLINE
struct text_pos
12498 run_window_scroll_functions (window
, startp
)
12499 Lisp_Object window
;
12500 struct text_pos startp
;
12502 struct window
*w
= XWINDOW (window
);
12503 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12505 if (current_buffer
!= XBUFFER (w
->buffer
))
12508 if (!NILP (Vwindow_scroll_functions
))
12510 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12511 make_number (CHARPOS (startp
)));
12512 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12513 /* In case the hook functions switch buffers. */
12514 if (current_buffer
!= XBUFFER (w
->buffer
))
12515 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12522 /* Make sure the line containing the cursor is fully visible.
12523 A value of 1 means there is nothing to be done.
12524 (Either the line is fully visible, or it cannot be made so,
12525 or we cannot tell.)
12527 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12528 is higher than window.
12530 A value of 0 means the caller should do scrolling
12531 as if point had gone off the screen. */
12534 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12537 int current_matrix_p
;
12539 struct glyph_matrix
*matrix
;
12540 struct glyph_row
*row
;
12543 if (!make_cursor_line_fully_visible_p
)
12546 /* It's not always possible to find the cursor, e.g, when a window
12547 is full of overlay strings. Don't do anything in that case. */
12548 if (w
->cursor
.vpos
< 0)
12551 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12552 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12554 /* If the cursor row is not partially visible, there's nothing to do. */
12555 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12558 /* If the row the cursor is in is taller than the window's height,
12559 it's not clear what to do, so do nothing. */
12560 window_height
= window_box_height (w
);
12561 if (row
->height
>= window_height
)
12563 if (!force_p
|| MINI_WINDOW_P (w
)
12564 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12571 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12572 non-zero means only WINDOW is redisplayed in redisplay_internal.
12573 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12574 in redisplay_window to bring a partially visible line into view in
12575 the case that only the cursor has moved.
12577 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12578 last screen line's vertical height extends past the end of the screen.
12582 1 if scrolling succeeded
12584 0 if scrolling didn't find point.
12586 -1 if new fonts have been loaded so that we must interrupt
12587 redisplay, adjust glyph matrices, and try again. */
12593 SCROLLING_NEED_LARGER_MATRICES
12597 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12598 scroll_step
, temp_scroll_step
, last_line_misfit
)
12599 Lisp_Object window
;
12600 int just_this_one_p
;
12601 EMACS_INT scroll_conservatively
, scroll_step
;
12602 int temp_scroll_step
;
12603 int last_line_misfit
;
12605 struct window
*w
= XWINDOW (window
);
12606 struct frame
*f
= XFRAME (w
->frame
);
12607 struct text_pos pos
, startp
;
12609 int this_scroll_margin
, scroll_max
, rc
, height
;
12610 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12611 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12612 Lisp_Object aggressive
;
12613 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12616 debug_method_add (w
, "try_scrolling");
12619 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12621 /* Compute scroll margin height in pixels. We scroll when point is
12622 within this distance from the top or bottom of the window. */
12623 if (scroll_margin
> 0)
12624 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
12625 * FRAME_LINE_HEIGHT (f
);
12627 this_scroll_margin
= 0;
12629 /* Force scroll_conservatively to have a reasonable value, to avoid
12630 overflow while computing how much to scroll. Note that the user
12631 can supply scroll-conservatively equal to `most-positive-fixnum',
12632 which can be larger than INT_MAX. */
12633 if (scroll_conservatively
> scroll_limit
)
12635 scroll_conservatively
= scroll_limit
;
12636 scroll_max
= INT_MAX
;
12638 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12639 /* Compute how much we should try to scroll maximally to bring
12640 point into view. */
12641 scroll_max
= (max (scroll_step
,
12642 max (scroll_conservatively
, temp_scroll_step
))
12643 * FRAME_LINE_HEIGHT (f
));
12644 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12645 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12646 /* We're trying to scroll because of aggressive scrolling but no
12647 scroll_step is set. Choose an arbitrary one. */
12648 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12654 /* Decide whether to scroll down. */
12655 if (PT
> CHARPOS (startp
))
12657 int scroll_margin_y
;
12659 /* Compute the pixel ypos of the scroll margin, then move it to
12660 either that ypos or PT, whichever comes first. */
12661 start_display (&it
, w
, startp
);
12662 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12663 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12664 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12665 (MOVE_TO_POS
| MOVE_TO_Y
));
12667 if (PT
> CHARPOS (it
.current
.pos
))
12669 int y0
= line_bottom_y (&it
);
12671 /* Compute the distance from the scroll margin to PT
12672 (including the height of the cursor line). Moving the
12673 iterator unconditionally to PT can be slow if PT is far
12674 away, so stop 10 lines past the window bottom (is there a
12675 way to do the right thing quickly?). */
12676 move_it_to (&it
, PT
, -1,
12677 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
12678 -1, MOVE_TO_POS
| MOVE_TO_Y
);
12679 dy
= line_bottom_y (&it
) - y0
;
12681 if (dy
> scroll_max
)
12682 return SCROLLING_FAILED
;
12690 /* Point is in or below the bottom scroll margin, so move the
12691 window start down. If scrolling conservatively, move it just
12692 enough down to make point visible. If scroll_step is set,
12693 move it down by scroll_step. */
12694 if (scroll_conservatively
)
12696 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12697 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12698 else if (scroll_step
|| temp_scroll_step
)
12699 amount_to_scroll
= scroll_max
;
12702 aggressive
= current_buffer
->scroll_up_aggressively
;
12703 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12704 if (NUMBERP (aggressive
))
12706 double float_amount
= XFLOATINT (aggressive
) * height
;
12707 amount_to_scroll
= float_amount
;
12708 if (amount_to_scroll
== 0 && float_amount
> 0)
12709 amount_to_scroll
= 1;
12713 if (amount_to_scroll
<= 0)
12714 return SCROLLING_FAILED
;
12716 start_display (&it
, w
, startp
);
12717 move_it_vertically (&it
, amount_to_scroll
);
12719 /* If STARTP is unchanged, move it down another screen line. */
12720 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12721 move_it_by_lines (&it
, 1, 1);
12722 startp
= it
.current
.pos
;
12726 struct text_pos scroll_margin_pos
= startp
;
12728 /* See if point is inside the scroll margin at the top of the
12730 if (this_scroll_margin
)
12732 start_display (&it
, w
, startp
);
12733 move_it_vertically (&it
, this_scroll_margin
);
12734 scroll_margin_pos
= it
.current
.pos
;
12737 if (PT
< CHARPOS (scroll_margin_pos
))
12739 /* Point is in the scroll margin at the top of the window or
12740 above what is displayed in the window. */
12743 /* Compute the vertical distance from PT to the scroll
12744 margin position. Give up if distance is greater than
12746 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12747 start_display (&it
, w
, pos
);
12749 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12750 it
.last_visible_y
, -1,
12751 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12752 dy
= it
.current_y
- y0
;
12753 if (dy
> scroll_max
)
12754 return SCROLLING_FAILED
;
12756 /* Compute new window start. */
12757 start_display (&it
, w
, startp
);
12759 if (scroll_conservatively
)
12761 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12762 else if (scroll_step
|| temp_scroll_step
)
12763 amount_to_scroll
= scroll_max
;
12766 aggressive
= current_buffer
->scroll_down_aggressively
;
12767 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12768 if (NUMBERP (aggressive
))
12770 double float_amount
= XFLOATINT (aggressive
) * height
;
12771 amount_to_scroll
= float_amount
;
12772 if (amount_to_scroll
== 0 && float_amount
> 0)
12773 amount_to_scroll
= 1;
12777 if (amount_to_scroll
<= 0)
12778 return SCROLLING_FAILED
;
12780 move_it_vertically_backward (&it
, amount_to_scroll
);
12781 startp
= it
.current
.pos
;
12785 /* Run window scroll functions. */
12786 startp
= run_window_scroll_functions (window
, startp
);
12788 /* Display the window. Give up if new fonts are loaded, or if point
12790 if (!try_window (window
, startp
, 0))
12791 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12792 else if (w
->cursor
.vpos
< 0)
12794 clear_glyph_matrix (w
->desired_matrix
);
12795 rc
= SCROLLING_FAILED
;
12799 /* Maybe forget recorded base line for line number display. */
12800 if (!just_this_one_p
12801 || current_buffer
->clip_changed
12802 || BEG_UNCHANGED
< CHARPOS (startp
))
12803 w
->base_line_number
= Qnil
;
12805 /* If cursor ends up on a partially visible line,
12806 treat that as being off the bottom of the screen. */
12807 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12809 clear_glyph_matrix (w
->desired_matrix
);
12810 ++extra_scroll_margin_lines
;
12813 rc
= SCROLLING_SUCCESS
;
12820 /* Compute a suitable window start for window W if display of W starts
12821 on a continuation line. Value is non-zero if a new window start
12824 The new window start will be computed, based on W's width, starting
12825 from the start of the continued line. It is the start of the
12826 screen line with the minimum distance from the old start W->start. */
12829 compute_window_start_on_continuation_line (w
)
12832 struct text_pos pos
, start_pos
;
12833 int window_start_changed_p
= 0;
12835 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12837 /* If window start is on a continuation line... Window start may be
12838 < BEGV in case there's invisible text at the start of the
12839 buffer (M-x rmail, for example). */
12840 if (CHARPOS (start_pos
) > BEGV
12841 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12844 struct glyph_row
*row
;
12846 /* Handle the case that the window start is out of range. */
12847 if (CHARPOS (start_pos
) < BEGV
)
12848 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12849 else if (CHARPOS (start_pos
) > ZV
)
12850 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12852 /* Find the start of the continued line. This should be fast
12853 because scan_buffer is fast (newline cache). */
12854 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12855 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12856 row
, DEFAULT_FACE_ID
);
12857 reseat_at_previous_visible_line_start (&it
);
12859 /* If the line start is "too far" away from the window start,
12860 say it takes too much time to compute a new window start. */
12861 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12862 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12864 int min_distance
, distance
;
12866 /* Move forward by display lines to find the new window
12867 start. If window width was enlarged, the new start can
12868 be expected to be > the old start. If window width was
12869 decreased, the new window start will be < the old start.
12870 So, we're looking for the display line start with the
12871 minimum distance from the old window start. */
12872 pos
= it
.current
.pos
;
12873 min_distance
= INFINITY
;
12874 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12875 distance
< min_distance
)
12877 min_distance
= distance
;
12878 pos
= it
.current
.pos
;
12879 move_it_by_lines (&it
, 1, 0);
12882 /* Set the window start there. */
12883 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12884 window_start_changed_p
= 1;
12888 return window_start_changed_p
;
12892 /* Try cursor movement in case text has not changed in window WINDOW,
12893 with window start STARTP. Value is
12895 CURSOR_MOVEMENT_SUCCESS if successful
12897 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12899 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12900 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12901 we want to scroll as if scroll-step were set to 1. See the code.
12903 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12904 which case we have to abort this redisplay, and adjust matrices
12909 CURSOR_MOVEMENT_SUCCESS
,
12910 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12911 CURSOR_MOVEMENT_MUST_SCROLL
,
12912 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12916 try_cursor_movement (window
, startp
, scroll_step
)
12917 Lisp_Object window
;
12918 struct text_pos startp
;
12921 struct window
*w
= XWINDOW (window
);
12922 struct frame
*f
= XFRAME (w
->frame
);
12923 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12926 if (inhibit_try_cursor_movement
)
12930 /* Handle case where text has not changed, only point, and it has
12931 not moved off the frame. */
12932 if (/* Point may be in this window. */
12933 PT
>= CHARPOS (startp
)
12934 /* Selective display hasn't changed. */
12935 && !current_buffer
->clip_changed
12936 /* Function force-mode-line-update is used to force a thorough
12937 redisplay. It sets either windows_or_buffers_changed or
12938 update_mode_lines. So don't take a shortcut here for these
12940 && !update_mode_lines
12941 && !windows_or_buffers_changed
12942 && !cursor_type_changed
12943 /* Can't use this case if highlighting a region. When a
12944 region exists, cursor movement has to do more than just
12946 && !(!NILP (Vtransient_mark_mode
)
12947 && !NILP (current_buffer
->mark_active
))
12948 && NILP (w
->region_showing
)
12949 && NILP (Vshow_trailing_whitespace
)
12950 /* Right after splitting windows, last_point may be nil. */
12951 && INTEGERP (w
->last_point
)
12952 /* This code is not used for mini-buffer for the sake of the case
12953 of redisplaying to replace an echo area message; since in
12954 that case the mini-buffer contents per se are usually
12955 unchanged. This code is of no real use in the mini-buffer
12956 since the handling of this_line_start_pos, etc., in redisplay
12957 handles the same cases. */
12958 && !EQ (window
, minibuf_window
)
12959 /* When splitting windows or for new windows, it happens that
12960 redisplay is called with a nil window_end_vpos or one being
12961 larger than the window. This should really be fixed in
12962 window.c. I don't have this on my list, now, so we do
12963 approximately the same as the old redisplay code. --gerd. */
12964 && INTEGERP (w
->window_end_vpos
)
12965 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12966 && (FRAME_WINDOW_P (f
)
12967 || !overlay_arrow_in_current_buffer_p ()))
12969 int this_scroll_margin
, top_scroll_margin
;
12970 struct glyph_row
*row
= NULL
;
12973 debug_method_add (w
, "cursor movement");
12976 /* Scroll if point within this distance from the top or bottom
12977 of the window. This is a pixel value. */
12978 if (scroll_margin
> 0)
12980 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12981 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12984 this_scroll_margin
= 0;
12986 top_scroll_margin
= this_scroll_margin
;
12987 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12988 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12990 /* Start with the row the cursor was displayed during the last
12991 not paused redisplay. Give up if that row is not valid. */
12992 if (w
->last_cursor
.vpos
< 0
12993 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12994 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12997 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12998 if (row
->mode_line_p
)
13000 if (!row
->enabled_p
)
13001 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13004 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13007 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13009 if (PT
> XFASTINT (w
->last_point
))
13011 /* Point has moved forward. */
13012 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13013 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13015 xassert (row
->enabled_p
);
13019 /* The end position of a row equals the start position
13020 of the next row. If PT is there, we would rather
13021 display it in the next line. */
13022 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13023 && MATRIX_ROW_END_CHARPOS (row
) == PT
13024 && !cursor_row_p (w
, row
))
13027 /* If within the scroll margin, scroll. Note that
13028 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13029 the next line would be drawn, and that
13030 this_scroll_margin can be zero. */
13031 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13032 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13033 /* Line is completely visible last line in window
13034 and PT is to be set in the next line. */
13035 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13036 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13037 && !row
->ends_at_zv_p
13038 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13041 else if (PT
< XFASTINT (w
->last_point
))
13043 /* Cursor has to be moved backward. Note that PT >=
13044 CHARPOS (startp) because of the outer if-statement. */
13045 while (!row
->mode_line_p
13046 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13047 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13048 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13049 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13050 row
> w
->current_matrix
->rows
13051 && (row
-1)->ends_in_newline_from_string_p
))))
13052 && (row
->y
> top_scroll_margin
13053 || CHARPOS (startp
) == BEGV
))
13055 xassert (row
->enabled_p
);
13059 /* Consider the following case: Window starts at BEGV,
13060 there is invisible, intangible text at BEGV, so that
13061 display starts at some point START > BEGV. It can
13062 happen that we are called with PT somewhere between
13063 BEGV and START. Try to handle that case. */
13064 if (row
< w
->current_matrix
->rows
13065 || row
->mode_line_p
)
13067 row
= w
->current_matrix
->rows
;
13068 if (row
->mode_line_p
)
13072 /* Due to newlines in overlay strings, we may have to
13073 skip forward over overlay strings. */
13074 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13075 && MATRIX_ROW_END_CHARPOS (row
) == PT
13076 && !cursor_row_p (w
, row
))
13079 /* If within the scroll margin, scroll. */
13080 if (row
->y
< top_scroll_margin
13081 && CHARPOS (startp
) != BEGV
)
13086 /* Cursor did not move. So don't scroll even if cursor line
13087 is partially visible, as it was so before. */
13088 rc
= CURSOR_MOVEMENT_SUCCESS
;
13091 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13092 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13094 /* if PT is not in the glyph row, give up. */
13095 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13097 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13098 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13099 && make_cursor_line_fully_visible_p
)
13101 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13102 && !row
->ends_at_zv_p
13103 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13104 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13105 else if (row
->height
> window_box_height (w
))
13107 /* If we end up in a partially visible line, let's
13108 make it fully visible, except when it's taller
13109 than the window, in which case we can't do much
13112 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13116 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13117 if (!cursor_row_fully_visible_p (w
, 0, 1))
13118 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13120 rc
= CURSOR_MOVEMENT_SUCCESS
;
13124 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13129 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13131 rc
= CURSOR_MOVEMENT_SUCCESS
;
13136 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13137 && MATRIX_ROW_START_CHARPOS (row
) == PT
13138 && cursor_row_p (w
, row
));
13147 set_vertical_scroll_bar (w
)
13150 int start
, end
, whole
;
13152 /* Calculate the start and end positions for the current window.
13153 At some point, it would be nice to choose between scrollbars
13154 which reflect the whole buffer size, with special markers
13155 indicating narrowing, and scrollbars which reflect only the
13158 Note that mini-buffers sometimes aren't displaying any text. */
13159 if (!MINI_WINDOW_P (w
)
13160 || (w
== XWINDOW (minibuf_window
)
13161 && NILP (echo_area_buffer
[0])))
13163 struct buffer
*buf
= XBUFFER (w
->buffer
);
13164 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13165 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13166 /* I don't think this is guaranteed to be right. For the
13167 moment, we'll pretend it is. */
13168 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13172 if (whole
< (end
- start
))
13173 whole
= end
- start
;
13176 start
= end
= whole
= 0;
13178 /* Indicate what this scroll bar ought to be displaying now. */
13179 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13180 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13181 (w
, end
- start
, whole
, start
);
13185 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13186 selected_window is redisplayed.
13188 We can return without actually redisplaying the window if
13189 fonts_changed_p is nonzero. In that case, redisplay_internal will
13193 redisplay_window (window
, just_this_one_p
)
13194 Lisp_Object window
;
13195 int just_this_one_p
;
13197 struct window
*w
= XWINDOW (window
);
13198 struct frame
*f
= XFRAME (w
->frame
);
13199 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13200 struct buffer
*old
= current_buffer
;
13201 struct text_pos lpoint
, opoint
, startp
;
13202 int update_mode_line
;
13205 /* Record it now because it's overwritten. */
13206 int current_matrix_up_to_date_p
= 0;
13207 int used_current_matrix_p
= 0;
13208 /* This is less strict than current_matrix_up_to_date_p.
13209 It indictes that the buffer contents and narrowing are unchanged. */
13210 int buffer_unchanged_p
= 0;
13211 int temp_scroll_step
= 0;
13212 int count
= SPECPDL_INDEX ();
13214 int centering_position
= -1;
13215 int last_line_misfit
= 0;
13216 int beg_unchanged
, end_unchanged
;
13218 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13221 /* W must be a leaf window here. */
13222 xassert (!NILP (w
->buffer
));
13224 *w
->desired_matrix
->method
= 0;
13228 reconsider_clip_changes (w
, buffer
);
13230 /* Has the mode line to be updated? */
13231 update_mode_line
= (!NILP (w
->update_mode_line
)
13232 || update_mode_lines
13233 || buffer
->clip_changed
13234 || buffer
->prevent_redisplay_optimizations_p
);
13236 if (MINI_WINDOW_P (w
))
13238 if (w
== XWINDOW (echo_area_window
)
13239 && !NILP (echo_area_buffer
[0]))
13241 if (update_mode_line
)
13242 /* We may have to update a tty frame's menu bar or a
13243 tool-bar. Example `M-x C-h C-h C-g'. */
13244 goto finish_menu_bars
;
13246 /* We've already displayed the echo area glyphs in this window. */
13247 goto finish_scroll_bars
;
13249 else if ((w
!= XWINDOW (minibuf_window
)
13250 || minibuf_level
== 0)
13251 /* When buffer is nonempty, redisplay window normally. */
13252 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13253 /* Quail displays non-mini buffers in minibuffer window.
13254 In that case, redisplay the window normally. */
13255 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13257 /* W is a mini-buffer window, but it's not active, so clear
13259 int yb
= window_text_bottom_y (w
);
13260 struct glyph_row
*row
;
13263 for (y
= 0, row
= w
->desired_matrix
->rows
;
13265 y
+= row
->height
, ++row
)
13266 blank_row (w
, row
, y
);
13267 goto finish_scroll_bars
;
13270 clear_glyph_matrix (w
->desired_matrix
);
13273 /* Otherwise set up data on this window; select its buffer and point
13275 /* Really select the buffer, for the sake of buffer-local
13277 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13279 current_matrix_up_to_date_p
13280 = (!NILP (w
->window_end_valid
)
13281 && !current_buffer
->clip_changed
13282 && !current_buffer
->prevent_redisplay_optimizations_p
13283 && XFASTINT (w
->last_modified
) >= MODIFF
13284 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13286 /* Run the window-bottom-change-functions
13287 if it is possible that the text on the screen has changed
13288 (either due to modification of the text, or any other reason). */
13289 if (!current_matrix_up_to_date_p
13290 && !NILP (Vwindow_text_change_functions
))
13292 safe_run_hooks (Qwindow_text_change_functions
);
13296 beg_unchanged
= BEG_UNCHANGED
;
13297 end_unchanged
= END_UNCHANGED
;
13299 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13301 specbind (Qinhibit_point_motion_hooks
, Qt
);
13304 = (!NILP (w
->window_end_valid
)
13305 && !current_buffer
->clip_changed
13306 && XFASTINT (w
->last_modified
) >= MODIFF
13307 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13309 /* When windows_or_buffers_changed is non-zero, we can't rely on
13310 the window end being valid, so set it to nil there. */
13311 if (windows_or_buffers_changed
)
13313 /* If window starts on a continuation line, maybe adjust the
13314 window start in case the window's width changed. */
13315 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13316 compute_window_start_on_continuation_line (w
);
13318 w
->window_end_valid
= Qnil
;
13321 /* Some sanity checks. */
13322 CHECK_WINDOW_END (w
);
13323 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13325 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13328 /* If %c is in mode line, update it if needed. */
13329 if (!NILP (w
->column_number_displayed
)
13330 /* This alternative quickly identifies a common case
13331 where no change is needed. */
13332 && !(PT
== XFASTINT (w
->last_point
)
13333 && XFASTINT (w
->last_modified
) >= MODIFF
13334 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13335 && (XFASTINT (w
->column_number_displayed
)
13336 != (int) current_column ())) /* iftc */
13337 update_mode_line
= 1;
13339 /* Count number of windows showing the selected buffer. An indirect
13340 buffer counts as its base buffer. */
13341 if (!just_this_one_p
)
13343 struct buffer
*current_base
, *window_base
;
13344 current_base
= current_buffer
;
13345 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13346 if (current_base
->base_buffer
)
13347 current_base
= current_base
->base_buffer
;
13348 if (window_base
->base_buffer
)
13349 window_base
= window_base
->base_buffer
;
13350 if (current_base
== window_base
)
13354 /* Point refers normally to the selected window. For any other
13355 window, set up appropriate value. */
13356 if (!EQ (window
, selected_window
))
13358 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13359 int new_pt_byte
= marker_byte_position (w
->pointm
);
13363 new_pt_byte
= BEGV_BYTE
;
13364 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13366 else if (new_pt
> (ZV
- 1))
13369 new_pt_byte
= ZV_BYTE
;
13370 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13373 /* We don't use SET_PT so that the point-motion hooks don't run. */
13374 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13377 /* If any of the character widths specified in the display table
13378 have changed, invalidate the width run cache. It's true that
13379 this may be a bit late to catch such changes, but the rest of
13380 redisplay goes (non-fatally) haywire when the display table is
13381 changed, so why should we worry about doing any better? */
13382 if (current_buffer
->width_run_cache
)
13384 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13386 if (! disptab_matches_widthtab (disptab
,
13387 XVECTOR (current_buffer
->width_table
)))
13389 invalidate_region_cache (current_buffer
,
13390 current_buffer
->width_run_cache
,
13392 recompute_width_table (current_buffer
, disptab
);
13396 /* If window-start is screwed up, choose a new one. */
13397 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13400 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13402 /* If someone specified a new starting point but did not insist,
13403 check whether it can be used. */
13404 if (!NILP (w
->optional_new_start
)
13405 && CHARPOS (startp
) >= BEGV
13406 && CHARPOS (startp
) <= ZV
)
13408 w
->optional_new_start
= Qnil
;
13409 start_display (&it
, w
, startp
);
13410 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13411 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13412 if (IT_CHARPOS (it
) == PT
)
13413 w
->force_start
= Qt
;
13414 /* IT may overshoot PT if text at PT is invisible. */
13415 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13416 w
->force_start
= Qt
;
13421 /* Handle case where place to start displaying has been specified,
13422 unless the specified location is outside the accessible range. */
13423 if (!NILP (w
->force_start
)
13424 || w
->frozen_window_start_p
)
13426 /* We set this later on if we have to adjust point. */
13429 w
->force_start
= Qnil
;
13431 w
->window_end_valid
= Qnil
;
13433 /* Forget any recorded base line for line number display. */
13434 if (!buffer_unchanged_p
)
13435 w
->base_line_number
= Qnil
;
13437 /* Redisplay the mode line. Select the buffer properly for that.
13438 Also, run the hook window-scroll-functions
13439 because we have scrolled. */
13440 /* Note, we do this after clearing force_start because
13441 if there's an error, it is better to forget about force_start
13442 than to get into an infinite loop calling the hook functions
13443 and having them get more errors. */
13444 if (!update_mode_line
13445 || ! NILP (Vwindow_scroll_functions
))
13447 update_mode_line
= 1;
13448 w
->update_mode_line
= Qt
;
13449 startp
= run_window_scroll_functions (window
, startp
);
13452 w
->last_modified
= make_number (0);
13453 w
->last_overlay_modified
= make_number (0);
13454 if (CHARPOS (startp
) < BEGV
)
13455 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13456 else if (CHARPOS (startp
) > ZV
)
13457 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13459 /* Redisplay, then check if cursor has been set during the
13460 redisplay. Give up if new fonts were loaded. */
13461 /* We used to issue a CHECK_MARGINS argument to try_window here,
13462 but this causes scrolling to fail when point begins inside
13463 the scroll margin (bug#148) -- cyd */
13464 if (!try_window (window
, startp
, 0))
13466 w
->force_start
= Qt
;
13467 clear_glyph_matrix (w
->desired_matrix
);
13468 goto need_larger_matrices
;
13471 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13473 /* If point does not appear, try to move point so it does
13474 appear. The desired matrix has been built above, so we
13475 can use it here. */
13476 new_vpos
= window_box_height (w
) / 2;
13479 if (!cursor_row_fully_visible_p (w
, 0, 0))
13481 /* Point does appear, but on a line partly visible at end of window.
13482 Move it back to a fully-visible line. */
13483 new_vpos
= window_box_height (w
);
13486 /* If we need to move point for either of the above reasons,
13487 now actually do it. */
13490 struct glyph_row
*row
;
13492 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13493 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13496 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13497 MATRIX_ROW_START_BYTEPOS (row
));
13499 if (w
!= XWINDOW (selected_window
))
13500 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13501 else if (current_buffer
== old
)
13502 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13504 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13506 /* If we are highlighting the region, then we just changed
13507 the region, so redisplay to show it. */
13508 if (!NILP (Vtransient_mark_mode
)
13509 && !NILP (current_buffer
->mark_active
))
13511 clear_glyph_matrix (w
->desired_matrix
);
13512 if (!try_window (window
, startp
, 0))
13513 goto need_larger_matrices
;
13518 debug_method_add (w
, "forced window start");
13523 /* Handle case where text has not changed, only point, and it has
13524 not moved off the frame, and we are not retrying after hscroll.
13525 (current_matrix_up_to_date_p is nonzero when retrying.) */
13526 if (current_matrix_up_to_date_p
13527 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13528 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13532 case CURSOR_MOVEMENT_SUCCESS
:
13533 used_current_matrix_p
= 1;
13536 case CURSOR_MOVEMENT_MUST_SCROLL
:
13537 goto try_to_scroll
;
13543 /* If current starting point was originally the beginning of a line
13544 but no longer is, find a new starting point. */
13545 else if (!NILP (w
->start_at_line_beg
)
13546 && !(CHARPOS (startp
) <= BEGV
13547 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13550 debug_method_add (w
, "recenter 1");
13555 /* Try scrolling with try_window_id. Value is > 0 if update has
13556 been done, it is -1 if we know that the same window start will
13557 not work. It is 0 if unsuccessful for some other reason. */
13558 else if ((tem
= try_window_id (w
)) != 0)
13561 debug_method_add (w
, "try_window_id %d", tem
);
13564 if (fonts_changed_p
)
13565 goto need_larger_matrices
;
13569 /* Otherwise try_window_id has returned -1 which means that we
13570 don't want the alternative below this comment to execute. */
13572 else if (CHARPOS (startp
) >= BEGV
13573 && CHARPOS (startp
) <= ZV
13574 && PT
>= CHARPOS (startp
)
13575 && (CHARPOS (startp
) < ZV
13576 /* Avoid starting at end of buffer. */
13577 || CHARPOS (startp
) == BEGV
13578 || (XFASTINT (w
->last_modified
) >= MODIFF
13579 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13582 /* If first window line is a continuation line, and window start
13583 is inside the modified region, but the first change is before
13584 current window start, we must select a new window start.
13586 However, if this is the result of a down-mouse event (e.g. by
13587 extending the mouse-drag-overlay), we don't want to select a
13588 new window start, since that would change the position under
13589 the mouse, resulting in an unwanted mouse-movement rather
13590 than a simple mouse-click. */
13591 if (NILP (w
->start_at_line_beg
)
13592 && NILP (do_mouse_tracking
)
13593 && CHARPOS (startp
) > BEGV
13594 && CHARPOS (startp
) > BEG
+ beg_unchanged
13595 && CHARPOS (startp
) <= Z
- end_unchanged
13596 /* Even if w->start_at_line_beg is nil, a new window may
13597 start at a line_beg, since that's how set_buffer_window
13598 sets it. So, we need to check the return value of
13599 compute_window_start_on_continuation_line. (See also
13601 && XMARKER (w
->start
)->buffer
== current_buffer
13602 && compute_window_start_on_continuation_line (w
))
13604 w
->force_start
= Qt
;
13605 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13610 debug_method_add (w
, "same window start");
13613 /* Try to redisplay starting at same place as before.
13614 If point has not moved off frame, accept the results. */
13615 if (!current_matrix_up_to_date_p
13616 /* Don't use try_window_reusing_current_matrix in this case
13617 because a window scroll function can have changed the
13619 || !NILP (Vwindow_scroll_functions
)
13620 || MINI_WINDOW_P (w
)
13621 || !(used_current_matrix_p
13622 = try_window_reusing_current_matrix (w
)))
13624 IF_DEBUG (debug_method_add (w
, "1"));
13625 if (try_window (window
, startp
, 1) < 0)
13626 /* -1 means we need to scroll.
13627 0 means we need new matrices, but fonts_changed_p
13628 is set in that case, so we will detect it below. */
13629 goto try_to_scroll
;
13632 if (fonts_changed_p
)
13633 goto need_larger_matrices
;
13635 if (w
->cursor
.vpos
>= 0)
13637 if (!just_this_one_p
13638 || current_buffer
->clip_changed
13639 || BEG_UNCHANGED
< CHARPOS (startp
))
13640 /* Forget any recorded base line for line number display. */
13641 w
->base_line_number
= Qnil
;
13643 if (!cursor_row_fully_visible_p (w
, 1, 0))
13645 clear_glyph_matrix (w
->desired_matrix
);
13646 last_line_misfit
= 1;
13648 /* Drop through and scroll. */
13653 clear_glyph_matrix (w
->desired_matrix
);
13658 w
->last_modified
= make_number (0);
13659 w
->last_overlay_modified
= make_number (0);
13661 /* Redisplay the mode line. Select the buffer properly for that. */
13662 if (!update_mode_line
)
13664 update_mode_line
= 1;
13665 w
->update_mode_line
= Qt
;
13668 /* Try to scroll by specified few lines. */
13669 if ((scroll_conservatively
13671 || temp_scroll_step
13672 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13673 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13674 && !current_buffer
->clip_changed
13675 && CHARPOS (startp
) >= BEGV
13676 && CHARPOS (startp
) <= ZV
)
13678 /* The function returns -1 if new fonts were loaded, 1 if
13679 successful, 0 if not successful. */
13680 int rc
= try_scrolling (window
, just_this_one_p
,
13681 scroll_conservatively
,
13683 temp_scroll_step
, last_line_misfit
);
13686 case SCROLLING_SUCCESS
:
13689 case SCROLLING_NEED_LARGER_MATRICES
:
13690 goto need_larger_matrices
;
13692 case SCROLLING_FAILED
:
13700 /* Finally, just choose place to start which centers point */
13703 if (centering_position
< 0)
13704 centering_position
= window_box_height (w
) / 2;
13707 debug_method_add (w
, "recenter");
13710 /* w->vscroll = 0; */
13712 /* Forget any previously recorded base line for line number display. */
13713 if (!buffer_unchanged_p
)
13714 w
->base_line_number
= Qnil
;
13716 /* Move backward half the height of the window. */
13717 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13718 it
.current_y
= it
.last_visible_y
;
13719 move_it_vertically_backward (&it
, centering_position
);
13720 xassert (IT_CHARPOS (it
) >= BEGV
);
13722 /* The function move_it_vertically_backward may move over more
13723 than the specified y-distance. If it->w is small, e.g. a
13724 mini-buffer window, we may end up in front of the window's
13725 display area. Start displaying at the start of the line
13726 containing PT in this case. */
13727 if (it
.current_y
<= 0)
13729 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13730 move_it_vertically_backward (&it
, 0);
13734 it
.current_x
= it
.hpos
= 0;
13736 /* Set startp here explicitly in case that helps avoid an infinite loop
13737 in case the window-scroll-functions functions get errors. */
13738 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13740 /* Run scroll hooks. */
13741 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13743 /* Redisplay the window. */
13744 if (!current_matrix_up_to_date_p
13745 || windows_or_buffers_changed
13746 || cursor_type_changed
13747 /* Don't use try_window_reusing_current_matrix in this case
13748 because it can have changed the buffer. */
13749 || !NILP (Vwindow_scroll_functions
)
13750 || !just_this_one_p
13751 || MINI_WINDOW_P (w
)
13752 || !(used_current_matrix_p
13753 = try_window_reusing_current_matrix (w
)))
13754 try_window (window
, startp
, 0);
13756 /* If new fonts have been loaded (due to fontsets), give up. We
13757 have to start a new redisplay since we need to re-adjust glyph
13759 if (fonts_changed_p
)
13760 goto need_larger_matrices
;
13762 /* If cursor did not appear assume that the middle of the window is
13763 in the first line of the window. Do it again with the next line.
13764 (Imagine a window of height 100, displaying two lines of height
13765 60. Moving back 50 from it->last_visible_y will end in the first
13767 if (w
->cursor
.vpos
< 0)
13769 if (!NILP (w
->window_end_valid
)
13770 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13772 clear_glyph_matrix (w
->desired_matrix
);
13773 move_it_by_lines (&it
, 1, 0);
13774 try_window (window
, it
.current
.pos
, 0);
13776 else if (PT
< IT_CHARPOS (it
))
13778 clear_glyph_matrix (w
->desired_matrix
);
13779 move_it_by_lines (&it
, -1, 0);
13780 try_window (window
, it
.current
.pos
, 0);
13784 /* Not much we can do about it. */
13788 /* Consider the following case: Window starts at BEGV, there is
13789 invisible, intangible text at BEGV, so that display starts at
13790 some point START > BEGV. It can happen that we are called with
13791 PT somewhere between BEGV and START. Try to handle that case. */
13792 if (w
->cursor
.vpos
< 0)
13794 struct glyph_row
*row
= w
->current_matrix
->rows
;
13795 if (row
->mode_line_p
)
13797 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13800 if (!cursor_row_fully_visible_p (w
, 0, 0))
13802 /* If vscroll is enabled, disable it and try again. */
13806 clear_glyph_matrix (w
->desired_matrix
);
13810 /* If centering point failed to make the whole line visible,
13811 put point at the top instead. That has to make the whole line
13812 visible, if it can be done. */
13813 if (centering_position
== 0)
13816 clear_glyph_matrix (w
->desired_matrix
);
13817 centering_position
= 0;
13823 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13824 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13825 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13828 /* Display the mode line, if we must. */
13829 if ((update_mode_line
13830 /* If window not full width, must redo its mode line
13831 if (a) the window to its side is being redone and
13832 (b) we do a frame-based redisplay. This is a consequence
13833 of how inverted lines are drawn in frame-based redisplay. */
13834 || (!just_this_one_p
13835 && !FRAME_WINDOW_P (f
)
13836 && !WINDOW_FULL_WIDTH_P (w
))
13837 /* Line number to display. */
13838 || INTEGERP (w
->base_line_pos
)
13839 /* Column number is displayed and different from the one displayed. */
13840 || (!NILP (w
->column_number_displayed
)
13841 && (XFASTINT (w
->column_number_displayed
)
13842 != (int) current_column ()))) /* iftc */
13843 /* This means that the window has a mode line. */
13844 && (WINDOW_WANTS_MODELINE_P (w
)
13845 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13847 display_mode_lines (w
);
13849 /* If mode line height has changed, arrange for a thorough
13850 immediate redisplay using the correct mode line height. */
13851 if (WINDOW_WANTS_MODELINE_P (w
)
13852 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13854 fonts_changed_p
= 1;
13855 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13856 = DESIRED_MODE_LINE_HEIGHT (w
);
13859 /* If top line height has changed, arrange for a thorough
13860 immediate redisplay using the correct mode line height. */
13861 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13862 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13864 fonts_changed_p
= 1;
13865 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13866 = DESIRED_HEADER_LINE_HEIGHT (w
);
13869 if (fonts_changed_p
)
13870 goto need_larger_matrices
;
13873 if (!line_number_displayed
13874 && !BUFFERP (w
->base_line_pos
))
13876 w
->base_line_pos
= Qnil
;
13877 w
->base_line_number
= Qnil
;
13882 /* When we reach a frame's selected window, redo the frame's menu bar. */
13883 if (update_mode_line
13884 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13886 int redisplay_menu_p
= 0;
13887 int redisplay_tool_bar_p
= 0;
13889 if (FRAME_WINDOW_P (f
))
13891 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13892 || defined (HAVE_NS) || defined (USE_GTK)
13893 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13895 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13899 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13901 if (redisplay_menu_p
)
13902 display_menu_bar (w
);
13904 #ifdef HAVE_WINDOW_SYSTEM
13905 if (FRAME_WINDOW_P (f
))
13907 #if defined (USE_GTK) || defined (HAVE_NS)
13908 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13910 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13911 && (FRAME_TOOL_BAR_LINES (f
) > 0
13912 || !NILP (Vauto_resize_tool_bars
));
13915 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13917 extern int ignore_mouse_drag_p
;
13918 ignore_mouse_drag_p
= 1;
13924 #ifdef HAVE_WINDOW_SYSTEM
13925 if (FRAME_WINDOW_P (f
)
13926 && update_window_fringes (w
, (just_this_one_p
13927 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13928 || w
->pseudo_window_p
)))
13932 if (draw_window_fringes (w
, 1))
13933 x_draw_vertical_border (w
);
13937 #endif /* HAVE_WINDOW_SYSTEM */
13939 /* We go to this label, with fonts_changed_p nonzero,
13940 if it is necessary to try again using larger glyph matrices.
13941 We have to redeem the scroll bar even in this case,
13942 because the loop in redisplay_internal expects that. */
13943 need_larger_matrices
:
13945 finish_scroll_bars
:
13947 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13949 /* Set the thumb's position and size. */
13950 set_vertical_scroll_bar (w
);
13952 /* Note that we actually used the scroll bar attached to this
13953 window, so it shouldn't be deleted at the end of redisplay. */
13954 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13955 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13958 /* Restore current_buffer and value of point in it. */
13959 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13960 set_buffer_internal_1 (old
);
13961 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13962 shorter. This can be caused by log truncation in *Messages*. */
13963 if (CHARPOS (lpoint
) <= ZV
)
13964 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13966 unbind_to (count
, Qnil
);
13970 /* Build the complete desired matrix of WINDOW with a window start
13971 buffer position POS.
13973 Value is 1 if successful. It is zero if fonts were loaded during
13974 redisplay which makes re-adjusting glyph matrices necessary, and -1
13975 if point would appear in the scroll margins.
13976 (We check that only if CHECK_MARGINS is nonzero. */
13979 try_window (window
, pos
, check_margins
)
13980 Lisp_Object window
;
13981 struct text_pos pos
;
13984 struct window
*w
= XWINDOW (window
);
13986 struct glyph_row
*last_text_row
= NULL
;
13987 struct frame
*f
= XFRAME (w
->frame
);
13989 /* Make POS the new window start. */
13990 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13992 /* Mark cursor position as unknown. No overlay arrow seen. */
13993 w
->cursor
.vpos
= -1;
13994 overlay_arrow_seen
= 0;
13996 /* Initialize iterator and info to start at POS. */
13997 start_display (&it
, w
, pos
);
13999 /* Display all lines of W. */
14000 while (it
.current_y
< it
.last_visible_y
)
14002 if (display_line (&it
))
14003 last_text_row
= it
.glyph_row
- 1;
14004 if (fonts_changed_p
)
14008 /* Don't let the cursor end in the scroll margins. */
14010 && !MINI_WINDOW_P (w
))
14012 int this_scroll_margin
;
14014 if (scroll_margin
> 0)
14016 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14017 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14020 this_scroll_margin
= 0;
14022 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14023 && w
->cursor
.y
< this_scroll_margin
14024 && CHARPOS (pos
) > BEGV
14025 && IT_CHARPOS (it
) < ZV
)
14026 /* rms: considering make_cursor_line_fully_visible_p here
14027 seems to give wrong results. We don't want to recenter
14028 when the last line is partly visible, we want to allow
14029 that case to be handled in the usual way. */
14030 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14032 w
->cursor
.vpos
= -1;
14033 clear_glyph_matrix (w
->desired_matrix
);
14038 /* If bottom moved off end of frame, change mode line percentage. */
14039 if (XFASTINT (w
->window_end_pos
) <= 0
14040 && Z
!= IT_CHARPOS (it
))
14041 w
->update_mode_line
= Qt
;
14043 /* Set window_end_pos to the offset of the last character displayed
14044 on the window from the end of current_buffer. Set
14045 window_end_vpos to its row number. */
14048 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14049 w
->window_end_bytepos
14050 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14052 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14054 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14055 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14056 ->displays_text_p
);
14060 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14061 w
->window_end_pos
= make_number (Z
- ZV
);
14062 w
->window_end_vpos
= make_number (0);
14065 /* But that is not valid info until redisplay finishes. */
14066 w
->window_end_valid
= Qnil
;
14072 /************************************************************************
14073 Window redisplay reusing current matrix when buffer has not changed
14074 ************************************************************************/
14076 /* Try redisplay of window W showing an unchanged buffer with a
14077 different window start than the last time it was displayed by
14078 reusing its current matrix. Value is non-zero if successful.
14079 W->start is the new window start. */
14082 try_window_reusing_current_matrix (w
)
14085 struct frame
*f
= XFRAME (w
->frame
);
14086 struct glyph_row
*row
, *bottom_row
;
14089 struct text_pos start
, new_start
;
14090 int nrows_scrolled
, i
;
14091 struct glyph_row
*last_text_row
;
14092 struct glyph_row
*last_reused_text_row
;
14093 struct glyph_row
*start_row
;
14094 int start_vpos
, min_y
, max_y
;
14097 if (inhibit_try_window_reusing
)
14101 if (/* This function doesn't handle terminal frames. */
14102 !FRAME_WINDOW_P (f
)
14103 /* Don't try to reuse the display if windows have been split
14105 || windows_or_buffers_changed
14106 || cursor_type_changed
)
14109 /* Can't do this if region may have changed. */
14110 if ((!NILP (Vtransient_mark_mode
)
14111 && !NILP (current_buffer
->mark_active
))
14112 || !NILP (w
->region_showing
)
14113 || !NILP (Vshow_trailing_whitespace
))
14116 /* If top-line visibility has changed, give up. */
14117 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14118 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14121 /* Give up if old or new display is scrolled vertically. We could
14122 make this function handle this, but right now it doesn't. */
14123 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14124 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14127 /* The variable new_start now holds the new window start. The old
14128 start `start' can be determined from the current matrix. */
14129 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14130 start
= start_row
->start
.pos
;
14131 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14133 /* Clear the desired matrix for the display below. */
14134 clear_glyph_matrix (w
->desired_matrix
);
14136 if (CHARPOS (new_start
) <= CHARPOS (start
))
14140 /* Don't use this method if the display starts with an ellipsis
14141 displayed for invisible text. It's not easy to handle that case
14142 below, and it's certainly not worth the effort since this is
14143 not a frequent case. */
14144 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14147 IF_DEBUG (debug_method_add (w
, "twu1"));
14149 /* Display up to a row that can be reused. The variable
14150 last_text_row is set to the last row displayed that displays
14151 text. Note that it.vpos == 0 if or if not there is a
14152 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14153 start_display (&it
, w
, new_start
);
14154 first_row_y
= it
.current_y
;
14155 w
->cursor
.vpos
= -1;
14156 last_text_row
= last_reused_text_row
= NULL
;
14158 while (it
.current_y
< it
.last_visible_y
14159 && !fonts_changed_p
)
14161 /* If we have reached into the characters in the START row,
14162 that means the line boundaries have changed. So we
14163 can't start copying with the row START. Maybe it will
14164 work to start copying with the following row. */
14165 while (IT_CHARPOS (it
) > CHARPOS (start
))
14167 /* Advance to the next row as the "start". */
14169 start
= start_row
->start
.pos
;
14170 /* If there are no more rows to try, or just one, give up. */
14171 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14172 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14173 || CHARPOS (start
) == ZV
)
14175 clear_glyph_matrix (w
->desired_matrix
);
14179 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14181 /* If we have reached alignment,
14182 we can copy the rest of the rows. */
14183 if (IT_CHARPOS (it
) == CHARPOS (start
))
14186 if (display_line (&it
))
14187 last_text_row
= it
.glyph_row
- 1;
14190 /* A value of current_y < last_visible_y means that we stopped
14191 at the previous window start, which in turn means that we
14192 have at least one reusable row. */
14193 if (it
.current_y
< it
.last_visible_y
)
14195 /* IT.vpos always starts from 0; it counts text lines. */
14196 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14198 /* Find PT if not already found in the lines displayed. */
14199 if (w
->cursor
.vpos
< 0)
14201 int dy
= it
.current_y
- start_row
->y
;
14203 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14204 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14206 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14207 dy
, nrows_scrolled
);
14210 clear_glyph_matrix (w
->desired_matrix
);
14215 /* Scroll the display. Do it before the current matrix is
14216 changed. The problem here is that update has not yet
14217 run, i.e. part of the current matrix is not up to date.
14218 scroll_run_hook will clear the cursor, and use the
14219 current matrix to get the height of the row the cursor is
14221 run
.current_y
= start_row
->y
;
14222 run
.desired_y
= it
.current_y
;
14223 run
.height
= it
.last_visible_y
- it
.current_y
;
14225 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14228 FRAME_RIF (f
)->update_window_begin_hook (w
);
14229 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14230 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14231 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14235 /* Shift current matrix down by nrows_scrolled lines. */
14236 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14237 rotate_matrix (w
->current_matrix
,
14239 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14242 /* Disable lines that must be updated. */
14243 for (i
= 0; i
< nrows_scrolled
; ++i
)
14244 (start_row
+ i
)->enabled_p
= 0;
14246 /* Re-compute Y positions. */
14247 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14248 max_y
= it
.last_visible_y
;
14249 for (row
= start_row
+ nrows_scrolled
;
14253 row
->y
= it
.current_y
;
14254 row
->visible_height
= row
->height
;
14256 if (row
->y
< min_y
)
14257 row
->visible_height
-= min_y
- row
->y
;
14258 if (row
->y
+ row
->height
> max_y
)
14259 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14260 row
->redraw_fringe_bitmaps_p
= 1;
14262 it
.current_y
+= row
->height
;
14264 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14265 last_reused_text_row
= row
;
14266 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14270 /* Disable lines in the current matrix which are now
14271 below the window. */
14272 for (++row
; row
< bottom_row
; ++row
)
14273 row
->enabled_p
= row
->mode_line_p
= 0;
14276 /* Update window_end_pos etc.; last_reused_text_row is the last
14277 reused row from the current matrix containing text, if any.
14278 The value of last_text_row is the last displayed line
14279 containing text. */
14280 if (last_reused_text_row
)
14282 w
->window_end_bytepos
14283 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14285 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14287 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14288 w
->current_matrix
));
14290 else if (last_text_row
)
14292 w
->window_end_bytepos
14293 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14295 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14297 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14301 /* This window must be completely empty. */
14302 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14303 w
->window_end_pos
= make_number (Z
- ZV
);
14304 w
->window_end_vpos
= make_number (0);
14306 w
->window_end_valid
= Qnil
;
14308 /* Update hint: don't try scrolling again in update_window. */
14309 w
->desired_matrix
->no_scrolling_p
= 1;
14312 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14316 else if (CHARPOS (new_start
) > CHARPOS (start
))
14318 struct glyph_row
*pt_row
, *row
;
14319 struct glyph_row
*first_reusable_row
;
14320 struct glyph_row
*first_row_to_display
;
14322 int yb
= window_text_bottom_y (w
);
14324 /* Find the row starting at new_start, if there is one. Don't
14325 reuse a partially visible line at the end. */
14326 first_reusable_row
= start_row
;
14327 while (first_reusable_row
->enabled_p
14328 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14329 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14330 < CHARPOS (new_start
)))
14331 ++first_reusable_row
;
14333 /* Give up if there is no row to reuse. */
14334 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14335 || !first_reusable_row
->enabled_p
14336 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14337 != CHARPOS (new_start
)))
14340 /* We can reuse fully visible rows beginning with
14341 first_reusable_row to the end of the window. Set
14342 first_row_to_display to the first row that cannot be reused.
14343 Set pt_row to the row containing point, if there is any. */
14345 for (first_row_to_display
= first_reusable_row
;
14346 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14347 ++first_row_to_display
)
14349 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14350 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14351 pt_row
= first_row_to_display
;
14354 /* Start displaying at the start of first_row_to_display. */
14355 xassert (first_row_to_display
->y
< yb
);
14356 init_to_row_start (&it
, w
, first_row_to_display
);
14358 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14360 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14362 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14363 + WINDOW_HEADER_LINE_HEIGHT (w
));
14365 /* Display lines beginning with first_row_to_display in the
14366 desired matrix. Set last_text_row to the last row displayed
14367 that displays text. */
14368 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14369 if (pt_row
== NULL
)
14370 w
->cursor
.vpos
= -1;
14371 last_text_row
= NULL
;
14372 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14373 if (display_line (&it
))
14374 last_text_row
= it
.glyph_row
- 1;
14376 /* If point is in a reused row, adjust y and vpos of the cursor
14380 w
->cursor
.vpos
-= nrows_scrolled
;
14381 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14384 /* Give up if point isn't in a row displayed or reused. (This
14385 also handles the case where w->cursor.vpos < nrows_scrolled
14386 after the calls to display_line, which can happen with scroll
14387 margins. See bug#1295.) */
14388 if (w
->cursor
.vpos
< 0)
14390 clear_glyph_matrix (w
->desired_matrix
);
14394 /* Scroll the display. */
14395 run
.current_y
= first_reusable_row
->y
;
14396 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14397 run
.height
= it
.last_visible_y
- run
.current_y
;
14398 dy
= run
.current_y
- run
.desired_y
;
14403 FRAME_RIF (f
)->update_window_begin_hook (w
);
14404 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14405 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14406 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14410 /* Adjust Y positions of reused rows. */
14411 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14412 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14413 max_y
= it
.last_visible_y
;
14414 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14417 row
->visible_height
= row
->height
;
14418 if (row
->y
< min_y
)
14419 row
->visible_height
-= min_y
- row
->y
;
14420 if (row
->y
+ row
->height
> max_y
)
14421 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14422 row
->redraw_fringe_bitmaps_p
= 1;
14425 /* Scroll the current matrix. */
14426 xassert (nrows_scrolled
> 0);
14427 rotate_matrix (w
->current_matrix
,
14429 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14432 /* Disable rows not reused. */
14433 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14434 row
->enabled_p
= 0;
14436 /* Point may have moved to a different line, so we cannot assume that
14437 the previous cursor position is valid; locate the correct row. */
14440 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14441 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14445 w
->cursor
.y
= row
->y
;
14447 if (row
< bottom_row
)
14449 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14450 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14453 && (!BUFFERP (glyph
->object
)
14454 || glyph
->charpos
< PT
);
14458 w
->cursor
.x
+= glyph
->pixel_width
;
14463 /* Adjust window end. A null value of last_text_row means that
14464 the window end is in reused rows which in turn means that
14465 only its vpos can have changed. */
14468 w
->window_end_bytepos
14469 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14471 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14473 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14478 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14481 w
->window_end_valid
= Qnil
;
14482 w
->desired_matrix
->no_scrolling_p
= 1;
14485 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14495 /************************************************************************
14496 Window redisplay reusing current matrix when buffer has changed
14497 ************************************************************************/
14499 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14500 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14502 static struct glyph_row
*
14503 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14504 struct glyph_row
*));
14507 /* Return the last row in MATRIX displaying text. If row START is
14508 non-null, start searching with that row. IT gives the dimensions
14509 of the display. Value is null if matrix is empty; otherwise it is
14510 a pointer to the row found. */
14512 static struct glyph_row
*
14513 find_last_row_displaying_text (matrix
, it
, start
)
14514 struct glyph_matrix
*matrix
;
14516 struct glyph_row
*start
;
14518 struct glyph_row
*row
, *row_found
;
14520 /* Set row_found to the last row in IT->w's current matrix
14521 displaying text. The loop looks funny but think of partially
14524 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14525 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14527 xassert (row
->enabled_p
);
14529 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14538 /* Return the last row in the current matrix of W that is not affected
14539 by changes at the start of current_buffer that occurred since W's
14540 current matrix was built. Value is null if no such row exists.
14542 BEG_UNCHANGED us the number of characters unchanged at the start of
14543 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14544 first changed character in current_buffer. Characters at positions <
14545 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14546 when the current matrix was built. */
14548 static struct glyph_row
*
14549 find_last_unchanged_at_beg_row (w
)
14552 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14553 struct glyph_row
*row
;
14554 struct glyph_row
*row_found
= NULL
;
14555 int yb
= window_text_bottom_y (w
);
14557 /* Find the last row displaying unchanged text. */
14558 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14559 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14560 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14563 if (/* If row ends before first_changed_pos, it is unchanged,
14564 except in some case. */
14565 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14566 /* When row ends in ZV and we write at ZV it is not
14568 && !row
->ends_at_zv_p
14569 /* When first_changed_pos is the end of a continued line,
14570 row is not unchanged because it may be no longer
14572 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14573 && (row
->continued_p
14574 || row
->exact_window_width_line_p
)))
14577 /* Stop if last visible row. */
14578 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14586 /* Find the first glyph row in the current matrix of W that is not
14587 affected by changes at the end of current_buffer since the
14588 time W's current matrix was built.
14590 Return in *DELTA the number of chars by which buffer positions in
14591 unchanged text at the end of current_buffer must be adjusted.
14593 Return in *DELTA_BYTES the corresponding number of bytes.
14595 Value is null if no such row exists, i.e. all rows are affected by
14598 static struct glyph_row
*
14599 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14601 int *delta
, *delta_bytes
;
14603 struct glyph_row
*row
;
14604 struct glyph_row
*row_found
= NULL
;
14606 *delta
= *delta_bytes
= 0;
14608 /* Display must not have been paused, otherwise the current matrix
14609 is not up to date. */
14610 eassert (!NILP (w
->window_end_valid
));
14612 /* A value of window_end_pos >= END_UNCHANGED means that the window
14613 end is in the range of changed text. If so, there is no
14614 unchanged row at the end of W's current matrix. */
14615 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14618 /* Set row to the last row in W's current matrix displaying text. */
14619 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14621 /* If matrix is entirely empty, no unchanged row exists. */
14622 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14624 /* The value of row is the last glyph row in the matrix having a
14625 meaningful buffer position in it. The end position of row
14626 corresponds to window_end_pos. This allows us to translate
14627 buffer positions in the current matrix to current buffer
14628 positions for characters not in changed text. */
14629 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14630 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14631 int last_unchanged_pos
, last_unchanged_pos_old
;
14632 struct glyph_row
*first_text_row
14633 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14635 *delta
= Z
- Z_old
;
14636 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14638 /* Set last_unchanged_pos to the buffer position of the last
14639 character in the buffer that has not been changed. Z is the
14640 index + 1 of the last character in current_buffer, i.e. by
14641 subtracting END_UNCHANGED we get the index of the last
14642 unchanged character, and we have to add BEG to get its buffer
14644 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14645 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14647 /* Search backward from ROW for a row displaying a line that
14648 starts at a minimum position >= last_unchanged_pos_old. */
14649 for (; row
> first_text_row
; --row
)
14651 /* This used to abort, but it can happen.
14652 It is ok to just stop the search instead here. KFS. */
14653 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14656 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14661 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14667 /* Make sure that glyph rows in the current matrix of window W
14668 reference the same glyph memory as corresponding rows in the
14669 frame's frame matrix. This function is called after scrolling W's
14670 current matrix on a terminal frame in try_window_id and
14671 try_window_reusing_current_matrix. */
14674 sync_frame_with_window_matrix_rows (w
)
14677 struct frame
*f
= XFRAME (w
->frame
);
14678 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14680 /* Preconditions: W must be a leaf window and full-width. Its frame
14681 must have a frame matrix. */
14682 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14683 xassert (WINDOW_FULL_WIDTH_P (w
));
14684 xassert (!FRAME_WINDOW_P (f
));
14686 /* If W is a full-width window, glyph pointers in W's current matrix
14687 have, by definition, to be the same as glyph pointers in the
14688 corresponding frame matrix. Note that frame matrices have no
14689 marginal areas (see build_frame_matrix). */
14690 window_row
= w
->current_matrix
->rows
;
14691 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14692 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14693 while (window_row
< window_row_end
)
14695 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14696 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14698 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14699 frame_row
->glyphs
[TEXT_AREA
] = start
;
14700 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14701 frame_row
->glyphs
[LAST_AREA
] = end
;
14703 /* Disable frame rows whose corresponding window rows have
14704 been disabled in try_window_id. */
14705 if (!window_row
->enabled_p
)
14706 frame_row
->enabled_p
= 0;
14708 ++window_row
, ++frame_row
;
14713 /* Find the glyph row in window W containing CHARPOS. Consider all
14714 rows between START and END (not inclusive). END null means search
14715 all rows to the end of the display area of W. Value is the row
14716 containing CHARPOS or null. */
14719 row_containing_pos (w
, charpos
, start
, end
, dy
)
14722 struct glyph_row
*start
, *end
;
14725 struct glyph_row
*row
= start
;
14728 /* If we happen to start on a header-line, skip that. */
14729 if (row
->mode_line_p
)
14732 if ((end
&& row
>= end
) || !row
->enabled_p
)
14735 last_y
= window_text_bottom_y (w
) - dy
;
14739 /* Give up if we have gone too far. */
14740 if (end
&& row
>= end
)
14742 /* This formerly returned if they were equal.
14743 I think that both quantities are of a "last plus one" type;
14744 if so, when they are equal, the row is within the screen. -- rms. */
14745 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14748 /* If it is in this row, return this row. */
14749 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14750 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14751 /* The end position of a row equals the start
14752 position of the next row. If CHARPOS is there, we
14753 would rather display it in the next line, except
14754 when this line ends in ZV. */
14755 && !row
->ends_at_zv_p
14756 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14757 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14764 /* Try to redisplay window W by reusing its existing display. W's
14765 current matrix must be up to date when this function is called,
14766 i.e. window_end_valid must not be nil.
14770 1 if display has been updated
14771 0 if otherwise unsuccessful
14772 -1 if redisplay with same window start is known not to succeed
14774 The following steps are performed:
14776 1. Find the last row in the current matrix of W that is not
14777 affected by changes at the start of current_buffer. If no such row
14780 2. Find the first row in W's current matrix that is not affected by
14781 changes at the end of current_buffer. Maybe there is no such row.
14783 3. Display lines beginning with the row + 1 found in step 1 to the
14784 row found in step 2 or, if step 2 didn't find a row, to the end of
14787 4. If cursor is not known to appear on the window, give up.
14789 5. If display stopped at the row found in step 2, scroll the
14790 display and current matrix as needed.
14792 6. Maybe display some lines at the end of W, if we must. This can
14793 happen under various circumstances, like a partially visible line
14794 becoming fully visible, or because newly displayed lines are displayed
14795 in smaller font sizes.
14797 7. Update W's window end information. */
14803 struct frame
*f
= XFRAME (w
->frame
);
14804 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14805 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14806 struct glyph_row
*last_unchanged_at_beg_row
;
14807 struct glyph_row
*first_unchanged_at_end_row
;
14808 struct glyph_row
*row
;
14809 struct glyph_row
*bottom_row
;
14812 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14813 struct text_pos start_pos
;
14815 int first_unchanged_at_end_vpos
= 0;
14816 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14817 struct text_pos start
;
14818 int first_changed_charpos
, last_changed_charpos
;
14821 if (inhibit_try_window_id
)
14825 /* This is handy for debugging. */
14827 #define GIVE_UP(X) \
14829 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14833 #define GIVE_UP(X) return 0
14836 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14838 /* Don't use this for mini-windows because these can show
14839 messages and mini-buffers, and we don't handle that here. */
14840 if (MINI_WINDOW_P (w
))
14843 /* This flag is used to prevent redisplay optimizations. */
14844 if (windows_or_buffers_changed
|| cursor_type_changed
)
14847 /* Verify that narrowing has not changed.
14848 Also verify that we were not told to prevent redisplay optimizations.
14849 It would be nice to further
14850 reduce the number of cases where this prevents try_window_id. */
14851 if (current_buffer
->clip_changed
14852 || current_buffer
->prevent_redisplay_optimizations_p
)
14855 /* Window must either use window-based redisplay or be full width. */
14856 if (!FRAME_WINDOW_P (f
)
14857 && (!FRAME_LINE_INS_DEL_OK (f
)
14858 || !WINDOW_FULL_WIDTH_P (w
)))
14861 /* Give up if point is not known NOT to appear in W. */
14862 if (PT
< CHARPOS (start
))
14865 /* Another way to prevent redisplay optimizations. */
14866 if (XFASTINT (w
->last_modified
) == 0)
14869 /* Verify that window is not hscrolled. */
14870 if (XFASTINT (w
->hscroll
) != 0)
14873 /* Verify that display wasn't paused. */
14874 if (NILP (w
->window_end_valid
))
14877 /* Can't use this if highlighting a region because a cursor movement
14878 will do more than just set the cursor. */
14879 if (!NILP (Vtransient_mark_mode
)
14880 && !NILP (current_buffer
->mark_active
))
14883 /* Likewise if highlighting trailing whitespace. */
14884 if (!NILP (Vshow_trailing_whitespace
))
14887 /* Likewise if showing a region. */
14888 if (!NILP (w
->region_showing
))
14891 /* Can use this if overlay arrow position and or string have changed. */
14892 if (overlay_arrows_changed_p ())
14895 /* When word-wrap is on, adding a space to the first word of a
14896 wrapped line can change the wrap position, altering the line
14897 above it. It might be worthwhile to handle this more
14898 intelligently, but for now just redisplay from scratch. */
14899 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14902 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14903 only if buffer has really changed. The reason is that the gap is
14904 initially at Z for freshly visited files. The code below would
14905 set end_unchanged to 0 in that case. */
14906 if (MODIFF
> SAVE_MODIFF
14907 /* This seems to happen sometimes after saving a buffer. */
14908 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14910 if (GPT
- BEG
< BEG_UNCHANGED
)
14911 BEG_UNCHANGED
= GPT
- BEG
;
14912 if (Z
- GPT
< END_UNCHANGED
)
14913 END_UNCHANGED
= Z
- GPT
;
14916 /* The position of the first and last character that has been changed. */
14917 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14918 last_changed_charpos
= Z
- END_UNCHANGED
;
14920 /* If window starts after a line end, and the last change is in
14921 front of that newline, then changes don't affect the display.
14922 This case happens with stealth-fontification. Note that although
14923 the display is unchanged, glyph positions in the matrix have to
14924 be adjusted, of course. */
14925 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14926 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14927 && ((last_changed_charpos
< CHARPOS (start
)
14928 && CHARPOS (start
) == BEGV
)
14929 || (last_changed_charpos
< CHARPOS (start
) - 1
14930 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14932 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14933 struct glyph_row
*r0
;
14935 /* Compute how many chars/bytes have been added to or removed
14936 from the buffer. */
14937 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14938 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14940 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14942 /* Give up if PT is not in the window. Note that it already has
14943 been checked at the start of try_window_id that PT is not in
14944 front of the window start. */
14945 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14948 /* If window start is unchanged, we can reuse the whole matrix
14949 as is, after adjusting glyph positions. No need to compute
14950 the window end again, since its offset from Z hasn't changed. */
14951 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14952 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14953 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14954 /* PT must not be in a partially visible line. */
14955 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14956 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14958 /* Adjust positions in the glyph matrix. */
14959 if (delta
|| delta_bytes
)
14961 struct glyph_row
*r1
14962 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14963 increment_matrix_positions (w
->current_matrix
,
14964 MATRIX_ROW_VPOS (r0
, current_matrix
),
14965 MATRIX_ROW_VPOS (r1
, current_matrix
),
14966 delta
, delta_bytes
);
14969 /* Set the cursor. */
14970 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14972 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14979 /* Handle the case that changes are all below what is displayed in
14980 the window, and that PT is in the window. This shortcut cannot
14981 be taken if ZV is visible in the window, and text has been added
14982 there that is visible in the window. */
14983 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14984 /* ZV is not visible in the window, or there are no
14985 changes at ZV, actually. */
14986 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14987 || first_changed_charpos
== last_changed_charpos
))
14989 struct glyph_row
*r0
;
14991 /* Give up if PT is not in the window. Note that it already has
14992 been checked at the start of try_window_id that PT is not in
14993 front of the window start. */
14994 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14997 /* If window start is unchanged, we can reuse the whole matrix
14998 as is, without changing glyph positions since no text has
14999 been added/removed in front of the window end. */
15000 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15001 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15002 /* PT must not be in a partially visible line. */
15003 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15004 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15006 /* We have to compute the window end anew since text
15007 can have been added/removed after it. */
15009 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15010 w
->window_end_bytepos
15011 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15013 /* Set the cursor. */
15014 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15016 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15023 /* Give up if window start is in the changed area.
15025 The condition used to read
15027 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15029 but why that was tested escapes me at the moment. */
15030 if (CHARPOS (start
) >= first_changed_charpos
15031 && CHARPOS (start
) <= last_changed_charpos
)
15034 /* Check that window start agrees with the start of the first glyph
15035 row in its current matrix. Check this after we know the window
15036 start is not in changed text, otherwise positions would not be
15038 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15039 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15042 /* Give up if the window ends in strings. Overlay strings
15043 at the end are difficult to handle, so don't try. */
15044 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15045 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15048 /* Compute the position at which we have to start displaying new
15049 lines. Some of the lines at the top of the window might be
15050 reusable because they are not displaying changed text. Find the
15051 last row in W's current matrix not affected by changes at the
15052 start of current_buffer. Value is null if changes start in the
15053 first line of window. */
15054 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15055 if (last_unchanged_at_beg_row
)
15057 /* Avoid starting to display in the moddle of a character, a TAB
15058 for instance. This is easier than to set up the iterator
15059 exactly, and it's not a frequent case, so the additional
15060 effort wouldn't really pay off. */
15061 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15062 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15063 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15064 --last_unchanged_at_beg_row
;
15066 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15069 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15071 start_pos
= it
.current
.pos
;
15073 /* Start displaying new lines in the desired matrix at the same
15074 vpos we would use in the current matrix, i.e. below
15075 last_unchanged_at_beg_row. */
15076 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15078 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15079 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15081 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15085 /* There are no reusable lines at the start of the window.
15086 Start displaying in the first text line. */
15087 start_display (&it
, w
, start
);
15088 it
.vpos
= it
.first_vpos
;
15089 start_pos
= it
.current
.pos
;
15092 /* Find the first row that is not affected by changes at the end of
15093 the buffer. Value will be null if there is no unchanged row, in
15094 which case we must redisplay to the end of the window. delta
15095 will be set to the value by which buffer positions beginning with
15096 first_unchanged_at_end_row have to be adjusted due to text
15098 first_unchanged_at_end_row
15099 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15100 IF_DEBUG (debug_delta
= delta
);
15101 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15103 /* Set stop_pos to the buffer position up to which we will have to
15104 display new lines. If first_unchanged_at_end_row != NULL, this
15105 is the buffer position of the start of the line displayed in that
15106 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15107 that we don't stop at a buffer position. */
15109 if (first_unchanged_at_end_row
)
15111 xassert (last_unchanged_at_beg_row
== NULL
15112 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15114 /* If this is a continuation line, move forward to the next one
15115 that isn't. Changes in lines above affect this line.
15116 Caution: this may move first_unchanged_at_end_row to a row
15117 not displaying text. */
15118 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15119 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15120 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15121 < it
.last_visible_y
))
15122 ++first_unchanged_at_end_row
;
15124 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15125 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15126 >= it
.last_visible_y
))
15127 first_unchanged_at_end_row
= NULL
;
15130 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15132 first_unchanged_at_end_vpos
15133 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15134 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15137 else if (last_unchanged_at_beg_row
== NULL
)
15143 /* Either there is no unchanged row at the end, or the one we have
15144 now displays text. This is a necessary condition for the window
15145 end pos calculation at the end of this function. */
15146 xassert (first_unchanged_at_end_row
== NULL
15147 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15149 debug_last_unchanged_at_beg_vpos
15150 = (last_unchanged_at_beg_row
15151 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15153 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15155 #endif /* GLYPH_DEBUG != 0 */
15158 /* Display new lines. Set last_text_row to the last new line
15159 displayed which has text on it, i.e. might end up as being the
15160 line where the window_end_vpos is. */
15161 w
->cursor
.vpos
= -1;
15162 last_text_row
= NULL
;
15163 overlay_arrow_seen
= 0;
15164 while (it
.current_y
< it
.last_visible_y
15165 && !fonts_changed_p
15166 && (first_unchanged_at_end_row
== NULL
15167 || IT_CHARPOS (it
) < stop_pos
))
15169 if (display_line (&it
))
15170 last_text_row
= it
.glyph_row
- 1;
15173 if (fonts_changed_p
)
15177 /* Compute differences in buffer positions, y-positions etc. for
15178 lines reused at the bottom of the window. Compute what we can
15180 if (first_unchanged_at_end_row
15181 /* No lines reused because we displayed everything up to the
15182 bottom of the window. */
15183 && it
.current_y
< it
.last_visible_y
)
15186 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15188 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15189 run
.current_y
= first_unchanged_at_end_row
->y
;
15190 run
.desired_y
= run
.current_y
+ dy
;
15191 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15195 delta
= delta_bytes
= dvpos
= dy
15196 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15197 first_unchanged_at_end_row
= NULL
;
15199 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15202 /* Find the cursor if not already found. We have to decide whether
15203 PT will appear on this window (it sometimes doesn't, but this is
15204 not a very frequent case.) This decision has to be made before
15205 the current matrix is altered. A value of cursor.vpos < 0 means
15206 that PT is either in one of the lines beginning at
15207 first_unchanged_at_end_row or below the window. Don't care for
15208 lines that might be displayed later at the window end; as
15209 mentioned, this is not a frequent case. */
15210 if (w
->cursor
.vpos
< 0)
15212 /* Cursor in unchanged rows at the top? */
15213 if (PT
< CHARPOS (start_pos
)
15214 && last_unchanged_at_beg_row
)
15216 row
= row_containing_pos (w
, PT
,
15217 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15218 last_unchanged_at_beg_row
+ 1, 0);
15220 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15223 /* Start from first_unchanged_at_end_row looking for PT. */
15224 else if (first_unchanged_at_end_row
)
15226 row
= row_containing_pos (w
, PT
- delta
,
15227 first_unchanged_at_end_row
, NULL
, 0);
15229 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15230 delta_bytes
, dy
, dvpos
);
15233 /* Give up if cursor was not found. */
15234 if (w
->cursor
.vpos
< 0)
15236 clear_glyph_matrix (w
->desired_matrix
);
15241 /* Don't let the cursor end in the scroll margins. */
15243 int this_scroll_margin
, cursor_height
;
15245 this_scroll_margin
= max (0, scroll_margin
);
15246 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15247 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15248 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15250 if ((w
->cursor
.y
< this_scroll_margin
15251 && CHARPOS (start
) > BEGV
)
15252 /* Old redisplay didn't take scroll margin into account at the bottom,
15253 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15254 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15255 ? cursor_height
+ this_scroll_margin
15256 : 1)) > it
.last_visible_y
)
15258 w
->cursor
.vpos
= -1;
15259 clear_glyph_matrix (w
->desired_matrix
);
15264 /* Scroll the display. Do it before changing the current matrix so
15265 that xterm.c doesn't get confused about where the cursor glyph is
15267 if (dy
&& run
.height
)
15271 if (FRAME_WINDOW_P (f
))
15273 FRAME_RIF (f
)->update_window_begin_hook (w
);
15274 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15275 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15276 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15280 /* Terminal frame. In this case, dvpos gives the number of
15281 lines to scroll by; dvpos < 0 means scroll up. */
15282 int first_unchanged_at_end_vpos
15283 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15284 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15285 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15286 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15287 + window_internal_height (w
));
15289 /* Perform the operation on the screen. */
15292 /* Scroll last_unchanged_at_beg_row to the end of the
15293 window down dvpos lines. */
15294 set_terminal_window (f
, end
);
15296 /* On dumb terminals delete dvpos lines at the end
15297 before inserting dvpos empty lines. */
15298 if (!FRAME_SCROLL_REGION_OK (f
))
15299 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15301 /* Insert dvpos empty lines in front of
15302 last_unchanged_at_beg_row. */
15303 ins_del_lines (f
, from
, dvpos
);
15305 else if (dvpos
< 0)
15307 /* Scroll up last_unchanged_at_beg_vpos to the end of
15308 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15309 set_terminal_window (f
, end
);
15311 /* Delete dvpos lines in front of
15312 last_unchanged_at_beg_vpos. ins_del_lines will set
15313 the cursor to the given vpos and emit |dvpos| delete
15315 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15317 /* On a dumb terminal insert dvpos empty lines at the
15319 if (!FRAME_SCROLL_REGION_OK (f
))
15320 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15323 set_terminal_window (f
, 0);
15329 /* Shift reused rows of the current matrix to the right position.
15330 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15332 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15333 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15336 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15337 bottom_vpos
, dvpos
);
15338 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15341 else if (dvpos
> 0)
15343 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15344 bottom_vpos
, dvpos
);
15345 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15346 first_unchanged_at_end_vpos
+ dvpos
, 0);
15349 /* For frame-based redisplay, make sure that current frame and window
15350 matrix are in sync with respect to glyph memory. */
15351 if (!FRAME_WINDOW_P (f
))
15352 sync_frame_with_window_matrix_rows (w
);
15354 /* Adjust buffer positions in reused rows. */
15355 if (delta
|| delta_bytes
)
15356 increment_matrix_positions (current_matrix
,
15357 first_unchanged_at_end_vpos
+ dvpos
,
15358 bottom_vpos
, delta
, delta_bytes
);
15360 /* Adjust Y positions. */
15362 shift_glyph_matrix (w
, current_matrix
,
15363 first_unchanged_at_end_vpos
+ dvpos
,
15366 if (first_unchanged_at_end_row
)
15368 first_unchanged_at_end_row
+= dvpos
;
15369 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15370 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15371 first_unchanged_at_end_row
= NULL
;
15374 /* If scrolling up, there may be some lines to display at the end of
15376 last_text_row_at_end
= NULL
;
15379 /* Scrolling up can leave for example a partially visible line
15380 at the end of the window to be redisplayed. */
15381 /* Set last_row to the glyph row in the current matrix where the
15382 window end line is found. It has been moved up or down in
15383 the matrix by dvpos. */
15384 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15385 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15387 /* If last_row is the window end line, it should display text. */
15388 xassert (last_row
->displays_text_p
);
15390 /* If window end line was partially visible before, begin
15391 displaying at that line. Otherwise begin displaying with the
15392 line following it. */
15393 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15395 init_to_row_start (&it
, w
, last_row
);
15396 it
.vpos
= last_vpos
;
15397 it
.current_y
= last_row
->y
;
15401 init_to_row_end (&it
, w
, last_row
);
15402 it
.vpos
= 1 + last_vpos
;
15403 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15407 /* We may start in a continuation line. If so, we have to
15408 get the right continuation_lines_width and current_x. */
15409 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15410 it
.hpos
= it
.current_x
= 0;
15412 /* Display the rest of the lines at the window end. */
15413 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15414 while (it
.current_y
< it
.last_visible_y
15415 && !fonts_changed_p
)
15417 /* Is it always sure that the display agrees with lines in
15418 the current matrix? I don't think so, so we mark rows
15419 displayed invalid in the current matrix by setting their
15420 enabled_p flag to zero. */
15421 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15422 if (display_line (&it
))
15423 last_text_row_at_end
= it
.glyph_row
- 1;
15427 /* Update window_end_pos and window_end_vpos. */
15428 if (first_unchanged_at_end_row
15429 && !last_text_row_at_end
)
15431 /* Window end line if one of the preserved rows from the current
15432 matrix. Set row to the last row displaying text in current
15433 matrix starting at first_unchanged_at_end_row, after
15435 xassert (first_unchanged_at_end_row
->displays_text_p
);
15436 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15437 first_unchanged_at_end_row
);
15438 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15440 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15441 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15443 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15444 xassert (w
->window_end_bytepos
>= 0);
15445 IF_DEBUG (debug_method_add (w
, "A"));
15447 else if (last_text_row_at_end
)
15450 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15451 w
->window_end_bytepos
15452 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15454 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15455 xassert (w
->window_end_bytepos
>= 0);
15456 IF_DEBUG (debug_method_add (w
, "B"));
15458 else if (last_text_row
)
15460 /* We have displayed either to the end of the window or at the
15461 end of the window, i.e. the last row with text is to be found
15462 in the desired matrix. */
15464 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15465 w
->window_end_bytepos
15466 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15468 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15469 xassert (w
->window_end_bytepos
>= 0);
15471 else if (first_unchanged_at_end_row
== NULL
15472 && last_text_row
== NULL
15473 && last_text_row_at_end
== NULL
)
15475 /* Displayed to end of window, but no line containing text was
15476 displayed. Lines were deleted at the end of the window. */
15477 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15478 int vpos
= XFASTINT (w
->window_end_vpos
);
15479 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15480 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15483 row
== NULL
&& vpos
>= first_vpos
;
15484 --vpos
, --current_row
, --desired_row
)
15486 if (desired_row
->enabled_p
)
15488 if (desired_row
->displays_text_p
)
15491 else if (current_row
->displays_text_p
)
15495 xassert (row
!= NULL
);
15496 w
->window_end_vpos
= make_number (vpos
+ 1);
15497 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15498 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15499 xassert (w
->window_end_bytepos
>= 0);
15500 IF_DEBUG (debug_method_add (w
, "C"));
15505 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15506 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15508 /* Record that display has not been completed. */
15509 w
->window_end_valid
= Qnil
;
15510 w
->desired_matrix
->no_scrolling_p
= 1;
15518 /***********************************************************************
15519 More debugging support
15520 ***********************************************************************/
15524 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15525 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15526 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15529 /* Dump the contents of glyph matrix MATRIX on stderr.
15531 GLYPHS 0 means don't show glyph contents.
15532 GLYPHS 1 means show glyphs in short form
15533 GLYPHS > 1 means show glyphs in long form. */
15536 dump_glyph_matrix (matrix
, glyphs
)
15537 struct glyph_matrix
*matrix
;
15541 for (i
= 0; i
< matrix
->nrows
; ++i
)
15542 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15546 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15547 the glyph row and area where the glyph comes from. */
15550 dump_glyph (row
, glyph
, area
)
15551 struct glyph_row
*row
;
15552 struct glyph
*glyph
;
15555 if (glyph
->type
== CHAR_GLYPH
)
15558 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15559 glyph
- row
->glyphs
[TEXT_AREA
],
15562 (BUFFERP (glyph
->object
)
15564 : (STRINGP (glyph
->object
)
15567 glyph
->pixel_width
,
15569 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15573 glyph
->left_box_line_p
,
15574 glyph
->right_box_line_p
);
15576 else if (glyph
->type
== STRETCH_GLYPH
)
15579 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15580 glyph
- row
->glyphs
[TEXT_AREA
],
15583 (BUFFERP (glyph
->object
)
15585 : (STRINGP (glyph
->object
)
15588 glyph
->pixel_width
,
15592 glyph
->left_box_line_p
,
15593 glyph
->right_box_line_p
);
15595 else if (glyph
->type
== IMAGE_GLYPH
)
15598 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15599 glyph
- row
->glyphs
[TEXT_AREA
],
15602 (BUFFERP (glyph
->object
)
15604 : (STRINGP (glyph
->object
)
15607 glyph
->pixel_width
,
15611 glyph
->left_box_line_p
,
15612 glyph
->right_box_line_p
);
15614 else if (glyph
->type
== COMPOSITE_GLYPH
)
15617 " %5d %4c %6d %c %3d 0x%05x",
15618 glyph
- row
->glyphs
[TEXT_AREA
],
15621 (BUFFERP (glyph
->object
)
15623 : (STRINGP (glyph
->object
)
15626 glyph
->pixel_width
,
15628 if (glyph
->u
.cmp
.automatic
)
15631 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
15632 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
15634 glyph
->left_box_line_p
,
15635 glyph
->right_box_line_p
);
15640 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15641 GLYPHS 0 means don't show glyph contents.
15642 GLYPHS 1 means show glyphs in short form
15643 GLYPHS > 1 means show glyphs in long form. */
15646 dump_glyph_row (row
, vpos
, glyphs
)
15647 struct glyph_row
*row
;
15652 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15653 fprintf (stderr
, "======================================================================\n");
15655 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15656 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15658 MATRIX_ROW_START_CHARPOS (row
),
15659 MATRIX_ROW_END_CHARPOS (row
),
15660 row
->used
[TEXT_AREA
],
15661 row
->contains_overlapping_glyphs_p
,
15663 row
->truncated_on_left_p
,
15664 row
->truncated_on_right_p
,
15666 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15667 row
->displays_text_p
,
15670 row
->ends_in_middle_of_char_p
,
15671 row
->starts_in_middle_of_char_p
,
15677 row
->visible_height
,
15680 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15681 row
->end
.overlay_string_index
,
15682 row
->continuation_lines_width
);
15683 fprintf (stderr
, "%9d %5d\n",
15684 CHARPOS (row
->start
.string_pos
),
15685 CHARPOS (row
->end
.string_pos
));
15686 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15687 row
->end
.dpvec_index
);
15694 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15696 struct glyph
*glyph
= row
->glyphs
[area
];
15697 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15699 /* Glyph for a line end in text. */
15700 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15703 if (glyph
< glyph_end
)
15704 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15706 for (; glyph
< glyph_end
; ++glyph
)
15707 dump_glyph (row
, glyph
, area
);
15710 else if (glyphs
== 1)
15714 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15716 char *s
= (char *) alloca (row
->used
[area
] + 1);
15719 for (i
= 0; i
< row
->used
[area
]; ++i
)
15721 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15722 if (glyph
->type
== CHAR_GLYPH
15723 && glyph
->u
.ch
< 0x80
15724 && glyph
->u
.ch
>= ' ')
15725 s
[i
] = glyph
->u
.ch
;
15731 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15737 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15738 Sdump_glyph_matrix
, 0, 1, "p",
15739 doc
: /* Dump the current matrix of the selected window to stderr.
15740 Shows contents of glyph row structures. With non-nil
15741 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15742 glyphs in short form, otherwise show glyphs in long form. */)
15744 Lisp_Object glyphs
;
15746 struct window
*w
= XWINDOW (selected_window
);
15747 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15749 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15750 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15751 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15752 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15753 fprintf (stderr
, "=============================================\n");
15754 dump_glyph_matrix (w
->current_matrix
,
15755 NILP (glyphs
) ? 0 : XINT (glyphs
));
15760 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15761 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15764 struct frame
*f
= XFRAME (selected_frame
);
15765 dump_glyph_matrix (f
->current_matrix
, 1);
15770 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15771 doc
: /* Dump glyph row ROW to stderr.
15772 GLYPH 0 means don't dump glyphs.
15773 GLYPH 1 means dump glyphs in short form.
15774 GLYPH > 1 or omitted means dump glyphs in long form. */)
15776 Lisp_Object row
, glyphs
;
15778 struct glyph_matrix
*matrix
;
15781 CHECK_NUMBER (row
);
15782 matrix
= XWINDOW (selected_window
)->current_matrix
;
15784 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15785 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15787 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15792 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15793 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15794 GLYPH 0 means don't dump glyphs.
15795 GLYPH 1 means dump glyphs in short form.
15796 GLYPH > 1 or omitted means dump glyphs in long form. */)
15798 Lisp_Object row
, glyphs
;
15800 struct frame
*sf
= SELECTED_FRAME ();
15801 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15804 CHECK_NUMBER (row
);
15806 if (vpos
>= 0 && vpos
< m
->nrows
)
15807 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15808 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15813 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15814 doc
: /* Toggle tracing of redisplay.
15815 With ARG, turn tracing on if and only if ARG is positive. */)
15820 trace_redisplay_p
= !trace_redisplay_p
;
15823 arg
= Fprefix_numeric_value (arg
);
15824 trace_redisplay_p
= XINT (arg
) > 0;
15831 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15832 doc
: /* Like `format', but print result to stderr.
15833 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15838 Lisp_Object s
= Fformat (nargs
, args
);
15839 fprintf (stderr
, "%s", SDATA (s
));
15843 #endif /* GLYPH_DEBUG */
15847 /***********************************************************************
15848 Building Desired Matrix Rows
15849 ***********************************************************************/
15851 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15852 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15854 static struct glyph_row
*
15855 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15857 Lisp_Object overlay_arrow_string
;
15859 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15860 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15861 struct buffer
*old
= current_buffer
;
15862 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15863 int arrow_len
= SCHARS (overlay_arrow_string
);
15864 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15865 const unsigned char *p
;
15868 int n_glyphs_before
;
15870 set_buffer_temp (buffer
);
15871 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15872 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15873 SET_TEXT_POS (it
.position
, 0, 0);
15875 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15877 while (p
< arrow_end
)
15879 Lisp_Object face
, ilisp
;
15881 /* Get the next character. */
15883 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15885 it
.c
= *p
, it
.len
= 1;
15888 /* Get its face. */
15889 ilisp
= make_number (p
- arrow_string
);
15890 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15891 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15893 /* Compute its width, get its glyphs. */
15894 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15895 SET_TEXT_POS (it
.position
, -1, -1);
15896 PRODUCE_GLYPHS (&it
);
15898 /* If this character doesn't fit any more in the line, we have
15899 to remove some glyphs. */
15900 if (it
.current_x
> it
.last_visible_x
)
15902 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15907 set_buffer_temp (old
);
15908 return it
.glyph_row
;
15912 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15913 glyphs are only inserted for terminal frames since we can't really
15914 win with truncation glyphs when partially visible glyphs are
15915 involved. Which glyphs to insert is determined by
15916 produce_special_glyphs. */
15919 insert_left_trunc_glyphs (it
)
15922 struct it truncate_it
;
15923 struct glyph
*from
, *end
, *to
, *toend
;
15925 xassert (!FRAME_WINDOW_P (it
->f
));
15927 /* Get the truncation glyphs. */
15929 truncate_it
.current_x
= 0;
15930 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15931 truncate_it
.glyph_row
= &scratch_glyph_row
;
15932 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15933 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15934 truncate_it
.object
= make_number (0);
15935 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15937 /* Overwrite glyphs from IT with truncation glyphs. */
15938 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15939 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15940 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15941 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15946 /* There may be padding glyphs left over. Overwrite them too. */
15947 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15949 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15955 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15959 /* Compute the pixel height and width of IT->glyph_row.
15961 Most of the time, ascent and height of a display line will be equal
15962 to the max_ascent and max_height values of the display iterator
15963 structure. This is not the case if
15965 1. We hit ZV without displaying anything. In this case, max_ascent
15966 and max_height will be zero.
15968 2. We have some glyphs that don't contribute to the line height.
15969 (The glyph row flag contributes_to_line_height_p is for future
15970 pixmap extensions).
15972 The first case is easily covered by using default values because in
15973 these cases, the line height does not really matter, except that it
15974 must not be zero. */
15977 compute_line_metrics (it
)
15980 struct glyph_row
*row
= it
->glyph_row
;
15983 if (FRAME_WINDOW_P (it
->f
))
15985 int i
, min_y
, max_y
;
15987 /* The line may consist of one space only, that was added to
15988 place the cursor on it. If so, the row's height hasn't been
15990 if (row
->height
== 0)
15992 if (it
->max_ascent
+ it
->max_descent
== 0)
15993 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15994 row
->ascent
= it
->max_ascent
;
15995 row
->height
= it
->max_ascent
+ it
->max_descent
;
15996 row
->phys_ascent
= it
->max_phys_ascent
;
15997 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15998 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16001 /* Compute the width of this line. */
16002 row
->pixel_width
= row
->x
;
16003 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16004 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16006 xassert (row
->pixel_width
>= 0);
16007 xassert (row
->ascent
>= 0 && row
->height
> 0);
16009 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16010 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16012 /* If first line's physical ascent is larger than its logical
16013 ascent, use the physical ascent, and make the row taller.
16014 This makes accented characters fully visible. */
16015 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16016 && row
->phys_ascent
> row
->ascent
)
16018 row
->height
+= row
->phys_ascent
- row
->ascent
;
16019 row
->ascent
= row
->phys_ascent
;
16022 /* Compute how much of the line is visible. */
16023 row
->visible_height
= row
->height
;
16025 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16026 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16028 if (row
->y
< min_y
)
16029 row
->visible_height
-= min_y
- row
->y
;
16030 if (row
->y
+ row
->height
> max_y
)
16031 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16035 row
->pixel_width
= row
->used
[TEXT_AREA
];
16036 if (row
->continued_p
)
16037 row
->pixel_width
-= it
->continuation_pixel_width
;
16038 else if (row
->truncated_on_right_p
)
16039 row
->pixel_width
-= it
->truncation_pixel_width
;
16040 row
->ascent
= row
->phys_ascent
= 0;
16041 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16042 row
->extra_line_spacing
= 0;
16045 /* Compute a hash code for this row. */
16047 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16048 for (i
= 0; i
< row
->used
[area
]; ++i
)
16049 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16050 + row
->glyphs
[area
][i
].u
.val
16051 + row
->glyphs
[area
][i
].face_id
16052 + row
->glyphs
[area
][i
].padding_p
16053 + (row
->glyphs
[area
][i
].type
<< 2));
16055 it
->max_ascent
= it
->max_descent
= 0;
16056 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16060 /* Append one space to the glyph row of iterator IT if doing a
16061 window-based redisplay. The space has the same face as
16062 IT->face_id. Value is non-zero if a space was added.
16064 This function is called to make sure that there is always one glyph
16065 at the end of a glyph row that the cursor can be set on under
16066 window-systems. (If there weren't such a glyph we would not know
16067 how wide and tall a box cursor should be displayed).
16069 At the same time this space let's a nicely handle clearing to the
16070 end of the line if the row ends in italic text. */
16073 append_space_for_newline (it
, default_face_p
)
16075 int default_face_p
;
16077 if (FRAME_WINDOW_P (it
->f
))
16079 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16081 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16082 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16084 /* Save some values that must not be changed.
16085 Must save IT->c and IT->len because otherwise
16086 ITERATOR_AT_END_P wouldn't work anymore after
16087 append_space_for_newline has been called. */
16088 enum display_element_type saved_what
= it
->what
;
16089 int saved_c
= it
->c
, saved_len
= it
->len
;
16090 int saved_x
= it
->current_x
;
16091 int saved_face_id
= it
->face_id
;
16092 struct text_pos saved_pos
;
16093 Lisp_Object saved_object
;
16096 saved_object
= it
->object
;
16097 saved_pos
= it
->position
;
16099 it
->what
= IT_CHARACTER
;
16100 bzero (&it
->position
, sizeof it
->position
);
16101 it
->object
= make_number (0);
16105 if (default_face_p
)
16106 it
->face_id
= DEFAULT_FACE_ID
;
16107 else if (it
->face_before_selective_p
)
16108 it
->face_id
= it
->saved_face_id
;
16109 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16110 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16112 PRODUCE_GLYPHS (it
);
16114 it
->override_ascent
= -1;
16115 it
->constrain_row_ascent_descent_p
= 0;
16116 it
->current_x
= saved_x
;
16117 it
->object
= saved_object
;
16118 it
->position
= saved_pos
;
16119 it
->what
= saved_what
;
16120 it
->face_id
= saved_face_id
;
16121 it
->len
= saved_len
;
16131 /* Extend the face of the last glyph in the text area of IT->glyph_row
16132 to the end of the display line. Called from display_line.
16133 If the glyph row is empty, add a space glyph to it so that we
16134 know the face to draw. Set the glyph row flag fill_line_p. */
16137 extend_face_to_end_of_line (it
)
16141 struct frame
*f
= it
->f
;
16143 /* If line is already filled, do nothing. */
16144 if (it
->current_x
>= it
->last_visible_x
)
16147 /* Face extension extends the background and box of IT->face_id
16148 to the end of the line. If the background equals the background
16149 of the frame, we don't have to do anything. */
16150 if (it
->face_before_selective_p
)
16151 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16153 face
= FACE_FROM_ID (f
, it
->face_id
);
16155 if (FRAME_WINDOW_P (f
)
16156 && it
->glyph_row
->displays_text_p
16157 && face
->box
== FACE_NO_BOX
16158 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16162 /* Set the glyph row flag indicating that the face of the last glyph
16163 in the text area has to be drawn to the end of the text area. */
16164 it
->glyph_row
->fill_line_p
= 1;
16166 /* If current character of IT is not ASCII, make sure we have the
16167 ASCII face. This will be automatically undone the next time
16168 get_next_display_element returns a multibyte character. Note
16169 that the character will always be single byte in unibyte text. */
16170 if (!ASCII_CHAR_P (it
->c
))
16172 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16175 if (FRAME_WINDOW_P (f
))
16177 /* If the row is empty, add a space with the current face of IT,
16178 so that we know which face to draw. */
16179 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16181 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16182 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16183 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16188 /* Save some values that must not be changed. */
16189 int saved_x
= it
->current_x
;
16190 struct text_pos saved_pos
;
16191 Lisp_Object saved_object
;
16192 enum display_element_type saved_what
= it
->what
;
16193 int saved_face_id
= it
->face_id
;
16195 saved_object
= it
->object
;
16196 saved_pos
= it
->position
;
16198 it
->what
= IT_CHARACTER
;
16199 bzero (&it
->position
, sizeof it
->position
);
16200 it
->object
= make_number (0);
16203 it
->face_id
= face
->id
;
16205 PRODUCE_GLYPHS (it
);
16207 while (it
->current_x
<= it
->last_visible_x
)
16208 PRODUCE_GLYPHS (it
);
16210 /* Don't count these blanks really. It would let us insert a left
16211 truncation glyph below and make us set the cursor on them, maybe. */
16212 it
->current_x
= saved_x
;
16213 it
->object
= saved_object
;
16214 it
->position
= saved_pos
;
16215 it
->what
= saved_what
;
16216 it
->face_id
= saved_face_id
;
16221 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16222 trailing whitespace. */
16225 trailing_whitespace_p (charpos
)
16228 int bytepos
= CHAR_TO_BYTE (charpos
);
16231 while (bytepos
< ZV_BYTE
16232 && (c
= FETCH_CHAR (bytepos
),
16233 c
== ' ' || c
== '\t'))
16236 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16238 if (bytepos
!= PT_BYTE
)
16245 /* Highlight trailing whitespace, if any, in ROW. */
16248 highlight_trailing_whitespace (f
, row
)
16250 struct glyph_row
*row
;
16252 int used
= row
->used
[TEXT_AREA
];
16256 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16257 struct glyph
*glyph
= start
+ used
- 1;
16259 /* Skip over glyphs inserted to display the cursor at the
16260 end of a line, for extending the face of the last glyph
16261 to the end of the line on terminals, and for truncation
16262 and continuation glyphs. */
16263 while (glyph
>= start
16264 && glyph
->type
== CHAR_GLYPH
16265 && INTEGERP (glyph
->object
))
16268 /* If last glyph is a space or stretch, and it's trailing
16269 whitespace, set the face of all trailing whitespace glyphs in
16270 IT->glyph_row to `trailing-whitespace'. */
16272 && BUFFERP (glyph
->object
)
16273 && (glyph
->type
== STRETCH_GLYPH
16274 || (glyph
->type
== CHAR_GLYPH
16275 && glyph
->u
.ch
== ' '))
16276 && trailing_whitespace_p (glyph
->charpos
))
16278 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16282 while (glyph
>= start
16283 && BUFFERP (glyph
->object
)
16284 && (glyph
->type
== STRETCH_GLYPH
16285 || (glyph
->type
== CHAR_GLYPH
16286 && glyph
->u
.ch
== ' ')))
16287 (glyph
--)->face_id
= face_id
;
16293 /* Value is non-zero if glyph row ROW in window W should be
16294 used to hold the cursor. */
16297 cursor_row_p (w
, row
)
16299 struct glyph_row
*row
;
16301 int cursor_row_p
= 1;
16303 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16305 /* Suppose the row ends on a string.
16306 Unless the row is continued, that means it ends on a newline
16307 in the string. If it's anything other than a display string
16308 (e.g. a before-string from an overlay), we don't want the
16309 cursor there. (This heuristic seems to give the optimal
16310 behavior for the various types of multi-line strings.) */
16311 if (CHARPOS (row
->end
.string_pos
) >= 0)
16313 if (row
->continued_p
)
16317 /* Check for `display' property. */
16318 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16319 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16320 struct glyph
*glyph
;
16323 for (glyph
= end
; glyph
>= beg
; --glyph
)
16324 if (STRINGP (glyph
->object
))
16327 = Fget_char_property (make_number (PT
),
16331 && display_prop_string_p (prop
, glyph
->object
));
16336 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16338 /* If the row ends in middle of a real character,
16339 and the line is continued, we want the cursor here.
16340 That's because MATRIX_ROW_END_CHARPOS would equal
16341 PT if PT is before the character. */
16342 if (!row
->ends_in_ellipsis_p
)
16343 cursor_row_p
= row
->continued_p
;
16345 /* If the row ends in an ellipsis, then
16346 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16347 We want that position to be displayed after the ellipsis. */
16350 /* If the row ends at ZV, display the cursor at the end of that
16351 row instead of at the start of the row below. */
16352 else if (row
->ends_at_zv_p
)
16358 return cursor_row_p
;
16363 /* Push the display property PROP so that it will be rendered at the
16364 current position in IT. */
16367 push_display_prop (struct it
*it
, Lisp_Object prop
)
16371 /* Never display a cursor on the prefix. */
16372 it
->avoid_cursor_p
= 1;
16374 if (STRINGP (prop
))
16376 if (SCHARS (prop
) == 0)
16383 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16384 it
->current
.overlay_string_index
= -1;
16385 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16386 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16387 it
->method
= GET_FROM_STRING
;
16388 it
->stop_charpos
= 0;
16390 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16392 it
->method
= GET_FROM_STRETCH
;
16395 #ifdef HAVE_WINDOW_SYSTEM
16396 else if (IMAGEP (prop
))
16398 it
->what
= IT_IMAGE
;
16399 it
->image_id
= lookup_image (it
->f
, prop
);
16400 it
->method
= GET_FROM_IMAGE
;
16402 #endif /* HAVE_WINDOW_SYSTEM */
16405 pop_it (it
); /* bogus display property, give up */
16410 /* Return the character-property PROP at the current position in IT. */
16413 get_it_property (it
, prop
)
16417 Lisp_Object position
;
16419 if (STRINGP (it
->object
))
16420 position
= make_number (IT_STRING_CHARPOS (*it
));
16421 else if (BUFFERP (it
->object
))
16422 position
= make_number (IT_CHARPOS (*it
));
16426 return Fget_char_property (position
, prop
, it
->object
);
16429 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16432 handle_line_prefix (struct it
*it
)
16434 Lisp_Object prefix
;
16435 if (it
->continuation_lines_width
> 0)
16437 prefix
= get_it_property (it
, Qwrap_prefix
);
16439 prefix
= Vwrap_prefix
;
16443 prefix
= get_it_property (it
, Qline_prefix
);
16445 prefix
= Vline_prefix
;
16447 if (! NILP (prefix
))
16449 push_display_prop (it
, prefix
);
16450 /* If the prefix is wider than the window, and we try to wrap
16451 it, it would acquire its own wrap prefix, and so on till the
16452 iterator stack overflows. So, don't wrap the prefix. */
16453 it
->line_wrap
= TRUNCATE
;
16459 /* Construct the glyph row IT->glyph_row in the desired matrix of
16460 IT->w from text at the current position of IT. See dispextern.h
16461 for an overview of struct it. Value is non-zero if
16462 IT->glyph_row displays text, as opposed to a line displaying ZV
16469 struct glyph_row
*row
= it
->glyph_row
;
16470 Lisp_Object overlay_arrow_string
;
16472 int may_wrap
= 0, wrap_x
;
16473 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16474 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16475 int wrap_row_extra_line_spacing
;
16477 /* We always start displaying at hpos zero even if hscrolled. */
16478 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16480 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16481 >= it
->w
->desired_matrix
->nrows
)
16483 it
->w
->nrows_scale_factor
++;
16484 fonts_changed_p
= 1;
16488 /* Is IT->w showing the region? */
16489 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16491 /* Clear the result glyph row and enable it. */
16492 prepare_desired_row (row
);
16494 row
->y
= it
->current_y
;
16495 row
->start
= it
->start
;
16496 row
->continuation_lines_width
= it
->continuation_lines_width
;
16497 row
->displays_text_p
= 1;
16498 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16499 it
->starts_in_middle_of_char_p
= 0;
16501 /* Arrange the overlays nicely for our purposes. Usually, we call
16502 display_line on only one line at a time, in which case this
16503 can't really hurt too much, or we call it on lines which appear
16504 one after another in the buffer, in which case all calls to
16505 recenter_overlay_lists but the first will be pretty cheap. */
16506 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16508 /* Move over display elements that are not visible because we are
16509 hscrolled. This may stop at an x-position < IT->first_visible_x
16510 if the first glyph is partially visible or if we hit a line end. */
16511 if (it
->current_x
< it
->first_visible_x
)
16513 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16514 MOVE_TO_POS
| MOVE_TO_X
);
16518 /* We only do this when not calling `move_it_in_display_line_to'
16519 above, because move_it_in_display_line_to calls
16520 handle_line_prefix itself. */
16521 handle_line_prefix (it
);
16524 /* Get the initial row height. This is either the height of the
16525 text hscrolled, if there is any, or zero. */
16526 row
->ascent
= it
->max_ascent
;
16527 row
->height
= it
->max_ascent
+ it
->max_descent
;
16528 row
->phys_ascent
= it
->max_phys_ascent
;
16529 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16530 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16532 /* Loop generating characters. The loop is left with IT on the next
16533 character to display. */
16536 int n_glyphs_before
, hpos_before
, x_before
;
16538 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16540 /* Retrieve the next thing to display. Value is zero if end of
16542 if (!get_next_display_element (it
))
16544 /* Maybe add a space at the end of this line that is used to
16545 display the cursor there under X. Set the charpos of the
16546 first glyph of blank lines not corresponding to any text
16548 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16549 row
->exact_window_width_line_p
= 1;
16550 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16551 || row
->used
[TEXT_AREA
] == 0)
16553 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16554 row
->displays_text_p
= 0;
16556 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16557 && (!MINI_WINDOW_P (it
->w
)
16558 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16559 row
->indicate_empty_line_p
= 1;
16562 it
->continuation_lines_width
= 0;
16563 row
->ends_at_zv_p
= 1;
16567 /* Now, get the metrics of what we want to display. This also
16568 generates glyphs in `row' (which is IT->glyph_row). */
16569 n_glyphs_before
= row
->used
[TEXT_AREA
];
16572 /* Remember the line height so far in case the next element doesn't
16573 fit on the line. */
16574 if (it
->line_wrap
!= TRUNCATE
)
16576 ascent
= it
->max_ascent
;
16577 descent
= it
->max_descent
;
16578 phys_ascent
= it
->max_phys_ascent
;
16579 phys_descent
= it
->max_phys_descent
;
16581 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16583 if (IT_DISPLAYING_WHITESPACE (it
))
16589 wrap_row_used
= row
->used
[TEXT_AREA
];
16590 wrap_row_ascent
= row
->ascent
;
16591 wrap_row_height
= row
->height
;
16592 wrap_row_phys_ascent
= row
->phys_ascent
;
16593 wrap_row_phys_height
= row
->phys_height
;
16594 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16600 PRODUCE_GLYPHS (it
);
16602 /* If this display element was in marginal areas, continue with
16604 if (it
->area
!= TEXT_AREA
)
16606 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16607 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16608 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16609 row
->phys_height
= max (row
->phys_height
,
16610 it
->max_phys_ascent
+ it
->max_phys_descent
);
16611 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16612 it
->max_extra_line_spacing
);
16613 set_iterator_to_next (it
, 1);
16617 /* Does the display element fit on the line? If we truncate
16618 lines, we should draw past the right edge of the window. If
16619 we don't truncate, we want to stop so that we can display the
16620 continuation glyph before the right margin. If lines are
16621 continued, there are two possible strategies for characters
16622 resulting in more than 1 glyph (e.g. tabs): Display as many
16623 glyphs as possible in this line and leave the rest for the
16624 continuation line, or display the whole element in the next
16625 line. Original redisplay did the former, so we do it also. */
16626 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16627 hpos_before
= it
->hpos
;
16630 if (/* Not a newline. */
16632 /* Glyphs produced fit entirely in the line. */
16633 && it
->current_x
< it
->last_visible_x
)
16635 it
->hpos
+= nglyphs
;
16636 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16637 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16638 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16639 row
->phys_height
= max (row
->phys_height
,
16640 it
->max_phys_ascent
+ it
->max_phys_descent
);
16641 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16642 it
->max_extra_line_spacing
);
16643 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16644 row
->x
= x
- it
->first_visible_x
;
16649 struct glyph
*glyph
;
16651 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16653 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16654 new_x
= x
+ glyph
->pixel_width
;
16656 if (/* Lines are continued. */
16657 it
->line_wrap
!= TRUNCATE
16658 && (/* Glyph doesn't fit on the line. */
16659 new_x
> it
->last_visible_x
16660 /* Or it fits exactly on a window system frame. */
16661 || (new_x
== it
->last_visible_x
16662 && FRAME_WINDOW_P (it
->f
))))
16664 /* End of a continued line. */
16667 || (new_x
== it
->last_visible_x
16668 && FRAME_WINDOW_P (it
->f
)))
16670 /* Current glyph is the only one on the line or
16671 fits exactly on the line. We must continue
16672 the line because we can't draw the cursor
16673 after the glyph. */
16674 row
->continued_p
= 1;
16675 it
->current_x
= new_x
;
16676 it
->continuation_lines_width
+= new_x
;
16678 if (i
== nglyphs
- 1)
16680 /* If line-wrap is on, check if a previous
16681 wrap point was found. */
16682 if (wrap_row_used
> 0
16683 /* Even if there is a previous wrap
16684 point, continue the line here as
16685 usual, if (i) the previous character
16686 was a space or tab AND (ii) the
16687 current character is not. */
16689 || IT_DISPLAYING_WHITESPACE (it
)))
16692 set_iterator_to_next (it
, 1);
16693 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16695 if (!get_next_display_element (it
))
16697 row
->exact_window_width_line_p
= 1;
16698 it
->continuation_lines_width
= 0;
16699 row
->continued_p
= 0;
16700 row
->ends_at_zv_p
= 1;
16702 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16704 row
->continued_p
= 0;
16705 row
->exact_window_width_line_p
= 1;
16710 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16711 && !FRAME_WINDOW_P (it
->f
))
16713 /* A padding glyph that doesn't fit on this line.
16714 This means the whole character doesn't fit
16716 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16718 /* Fill the rest of the row with continuation
16719 glyphs like in 20.x. */
16720 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16721 < row
->glyphs
[1 + TEXT_AREA
])
16722 produce_special_glyphs (it
, IT_CONTINUATION
);
16724 row
->continued_p
= 1;
16725 it
->current_x
= x_before
;
16726 it
->continuation_lines_width
+= x_before
;
16728 /* Restore the height to what it was before the
16729 element not fitting on the line. */
16730 it
->max_ascent
= ascent
;
16731 it
->max_descent
= descent
;
16732 it
->max_phys_ascent
= phys_ascent
;
16733 it
->max_phys_descent
= phys_descent
;
16735 else if (wrap_row_used
> 0)
16739 it
->continuation_lines_width
+= wrap_x
;
16740 row
->used
[TEXT_AREA
] = wrap_row_used
;
16741 row
->ascent
= wrap_row_ascent
;
16742 row
->height
= wrap_row_height
;
16743 row
->phys_ascent
= wrap_row_phys_ascent
;
16744 row
->phys_height
= wrap_row_phys_height
;
16745 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16746 row
->continued_p
= 1;
16747 row
->ends_at_zv_p
= 0;
16748 row
->exact_window_width_line_p
= 0;
16749 it
->continuation_lines_width
+= x
;
16751 /* Make sure that a non-default face is extended
16752 up to the right margin of the window. */
16753 extend_face_to_end_of_line (it
);
16755 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16757 /* A TAB that extends past the right edge of the
16758 window. This produces a single glyph on
16759 window system frames. We leave the glyph in
16760 this row and let it fill the row, but don't
16761 consume the TAB. */
16762 it
->continuation_lines_width
+= it
->last_visible_x
;
16763 row
->ends_in_middle_of_char_p
= 1;
16764 row
->continued_p
= 1;
16765 glyph
->pixel_width
= it
->last_visible_x
- x
;
16766 it
->starts_in_middle_of_char_p
= 1;
16770 /* Something other than a TAB that draws past
16771 the right edge of the window. Restore
16772 positions to values before the element. */
16773 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16775 /* Display continuation glyphs. */
16776 if (!FRAME_WINDOW_P (it
->f
))
16777 produce_special_glyphs (it
, IT_CONTINUATION
);
16778 row
->continued_p
= 1;
16780 it
->current_x
= x_before
;
16781 it
->continuation_lines_width
+= x
;
16782 extend_face_to_end_of_line (it
);
16784 if (nglyphs
> 1 && i
> 0)
16786 row
->ends_in_middle_of_char_p
= 1;
16787 it
->starts_in_middle_of_char_p
= 1;
16790 /* Restore the height to what it was before the
16791 element not fitting on the line. */
16792 it
->max_ascent
= ascent
;
16793 it
->max_descent
= descent
;
16794 it
->max_phys_ascent
= phys_ascent
;
16795 it
->max_phys_descent
= phys_descent
;
16800 else if (new_x
> it
->first_visible_x
)
16802 /* Increment number of glyphs actually displayed. */
16805 if (x
< it
->first_visible_x
)
16806 /* Glyph is partially visible, i.e. row starts at
16807 negative X position. */
16808 row
->x
= x
- it
->first_visible_x
;
16812 /* Glyph is completely off the left margin of the
16813 window. This should not happen because of the
16814 move_it_in_display_line at the start of this
16815 function, unless the text display area of the
16816 window is empty. */
16817 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16821 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16822 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16823 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16824 row
->phys_height
= max (row
->phys_height
,
16825 it
->max_phys_ascent
+ it
->max_phys_descent
);
16826 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16827 it
->max_extra_line_spacing
);
16829 /* End of this display line if row is continued. */
16830 if (row
->continued_p
|| row
->ends_at_zv_p
)
16835 /* Is this a line end? If yes, we're also done, after making
16836 sure that a non-default face is extended up to the right
16837 margin of the window. */
16838 if (ITERATOR_AT_END_OF_LINE_P (it
))
16840 int used_before
= row
->used
[TEXT_AREA
];
16842 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16844 /* Add a space at the end of the line that is used to
16845 display the cursor there. */
16846 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16847 append_space_for_newline (it
, 0);
16849 /* Extend the face to the end of the line. */
16850 extend_face_to_end_of_line (it
);
16852 /* Make sure we have the position. */
16853 if (used_before
== 0)
16854 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16856 /* Consume the line end. This skips over invisible lines. */
16857 set_iterator_to_next (it
, 1);
16858 it
->continuation_lines_width
= 0;
16862 /* Proceed with next display element. Note that this skips
16863 over lines invisible because of selective display. */
16864 set_iterator_to_next (it
, 1);
16866 /* If we truncate lines, we are done when the last displayed
16867 glyphs reach past the right margin of the window. */
16868 if (it
->line_wrap
== TRUNCATE
16869 && (FRAME_WINDOW_P (it
->f
)
16870 ? (it
->current_x
>= it
->last_visible_x
)
16871 : (it
->current_x
> it
->last_visible_x
)))
16873 /* Maybe add truncation glyphs. */
16874 if (!FRAME_WINDOW_P (it
->f
))
16878 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16879 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16882 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16884 row
->used
[TEXT_AREA
] = i
;
16885 produce_special_glyphs (it
, IT_TRUNCATION
);
16888 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16890 /* Don't truncate if we can overflow newline into fringe. */
16891 if (!get_next_display_element (it
))
16893 it
->continuation_lines_width
= 0;
16894 row
->ends_at_zv_p
= 1;
16895 row
->exact_window_width_line_p
= 1;
16898 if (ITERATOR_AT_END_OF_LINE_P (it
))
16900 row
->exact_window_width_line_p
= 1;
16901 goto at_end_of_line
;
16905 row
->truncated_on_right_p
= 1;
16906 it
->continuation_lines_width
= 0;
16907 reseat_at_next_visible_line_start (it
, 0);
16908 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16909 it
->hpos
= hpos_before
;
16910 it
->current_x
= x_before
;
16915 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16916 at the left window margin. */
16917 if (it
->first_visible_x
16918 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16920 if (!FRAME_WINDOW_P (it
->f
))
16921 insert_left_trunc_glyphs (it
);
16922 row
->truncated_on_left_p
= 1;
16925 /* If the start of this line is the overlay arrow-position, then
16926 mark this glyph row as the one containing the overlay arrow.
16927 This is clearly a mess with variable size fonts. It would be
16928 better to let it be displayed like cursors under X. */
16929 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16930 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16931 !NILP (overlay_arrow_string
)))
16933 /* Overlay arrow in window redisplay is a fringe bitmap. */
16934 if (STRINGP (overlay_arrow_string
))
16936 struct glyph_row
*arrow_row
16937 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16938 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16939 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16940 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16941 struct glyph
*p2
, *end
;
16943 /* Copy the arrow glyphs. */
16944 while (glyph
< arrow_end
)
16947 /* Throw away padding glyphs. */
16949 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16950 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16956 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16961 xassert (INTEGERP (overlay_arrow_string
));
16962 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16964 overlay_arrow_seen
= 1;
16967 /* Compute pixel dimensions of this line. */
16968 compute_line_metrics (it
);
16970 /* Remember the position at which this line ends. */
16971 row
->end
= it
->current
;
16973 /* Record whether this row ends inside an ellipsis. */
16974 row
->ends_in_ellipsis_p
16975 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16976 && it
->ellipsis_p
);
16978 /* Save fringe bitmaps in this row. */
16979 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16980 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16981 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16982 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16984 it
->left_user_fringe_bitmap
= 0;
16985 it
->left_user_fringe_face_id
= 0;
16986 it
->right_user_fringe_bitmap
= 0;
16987 it
->right_user_fringe_face_id
= 0;
16989 /* Maybe set the cursor. */
16990 if (it
->w
->cursor
.vpos
< 0
16991 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16992 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16993 && cursor_row_p (it
->w
, row
))
16994 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16996 /* Highlight trailing whitespace. */
16997 if (!NILP (Vshow_trailing_whitespace
))
16998 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17000 /* Prepare for the next line. This line starts horizontally at (X
17001 HPOS) = (0 0). Vertical positions are incremented. As a
17002 convenience for the caller, IT->glyph_row is set to the next
17004 it
->current_x
= it
->hpos
= 0;
17005 it
->current_y
+= row
->height
;
17008 it
->start
= it
->current
;
17009 return row
->displays_text_p
;
17014 /***********************************************************************
17016 ***********************************************************************/
17018 /* Redisplay the menu bar in the frame for window W.
17020 The menu bar of X frames that don't have X toolkit support is
17021 displayed in a special window W->frame->menu_bar_window.
17023 The menu bar of terminal frames is treated specially as far as
17024 glyph matrices are concerned. Menu bar lines are not part of
17025 windows, so the update is done directly on the frame matrix rows
17026 for the menu bar. */
17029 display_menu_bar (w
)
17032 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17037 /* Don't do all this for graphical frames. */
17039 if (FRAME_W32_P (f
))
17042 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17048 if (FRAME_NS_P (f
))
17050 #endif /* HAVE_NS */
17052 #ifdef USE_X_TOOLKIT
17053 xassert (!FRAME_WINDOW_P (f
));
17054 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17055 it
.first_visible_x
= 0;
17056 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17057 #else /* not USE_X_TOOLKIT */
17058 if (FRAME_WINDOW_P (f
))
17060 /* Menu bar lines are displayed in the desired matrix of the
17061 dummy window menu_bar_window. */
17062 struct window
*menu_w
;
17063 xassert (WINDOWP (f
->menu_bar_window
));
17064 menu_w
= XWINDOW (f
->menu_bar_window
);
17065 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17067 it
.first_visible_x
= 0;
17068 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17072 /* This is a TTY frame, i.e. character hpos/vpos are used as
17074 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17076 it
.first_visible_x
= 0;
17077 it
.last_visible_x
= FRAME_COLS (f
);
17079 #endif /* not USE_X_TOOLKIT */
17081 if (! mode_line_inverse_video
)
17082 /* Force the menu-bar to be displayed in the default face. */
17083 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17085 /* Clear all rows of the menu bar. */
17086 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17088 struct glyph_row
*row
= it
.glyph_row
+ i
;
17089 clear_glyph_row (row
);
17090 row
->enabled_p
= 1;
17091 row
->full_width_p
= 1;
17094 /* Display all items of the menu bar. */
17095 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17096 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17098 Lisp_Object string
;
17100 /* Stop at nil string. */
17101 string
= AREF (items
, i
+ 1);
17105 /* Remember where item was displayed. */
17106 ASET (items
, i
+ 3, make_number (it
.hpos
));
17108 /* Display the item, pad with one space. */
17109 if (it
.current_x
< it
.last_visible_x
)
17110 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17111 SCHARS (string
) + 1, 0, 0, -1);
17114 /* Fill out the line with spaces. */
17115 if (it
.current_x
< it
.last_visible_x
)
17116 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17118 /* Compute the total height of the lines. */
17119 compute_line_metrics (&it
);
17124 /***********************************************************************
17126 ***********************************************************************/
17128 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17129 FORCE is non-zero, redisplay mode lines unconditionally.
17130 Otherwise, redisplay only mode lines that are garbaged. Value is
17131 the number of windows whose mode lines were redisplayed. */
17134 redisplay_mode_lines (window
, force
)
17135 Lisp_Object window
;
17140 while (!NILP (window
))
17142 struct window
*w
= XWINDOW (window
);
17144 if (WINDOWP (w
->hchild
))
17145 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17146 else if (WINDOWP (w
->vchild
))
17147 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17149 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17150 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17152 struct text_pos lpoint
;
17153 struct buffer
*old
= current_buffer
;
17155 /* Set the window's buffer for the mode line display. */
17156 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17157 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17159 /* Point refers normally to the selected window. For any
17160 other window, set up appropriate value. */
17161 if (!EQ (window
, selected_window
))
17163 struct text_pos pt
;
17165 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17166 if (CHARPOS (pt
) < BEGV
)
17167 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17168 else if (CHARPOS (pt
) > (ZV
- 1))
17169 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17171 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17174 /* Display mode lines. */
17175 clear_glyph_matrix (w
->desired_matrix
);
17176 if (display_mode_lines (w
))
17179 w
->must_be_updated_p
= 1;
17182 /* Restore old settings. */
17183 set_buffer_internal_1 (old
);
17184 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17194 /* Display the mode and/or top line of window W. Value is the number
17195 of mode lines displayed. */
17198 display_mode_lines (w
)
17201 Lisp_Object old_selected_window
, old_selected_frame
;
17204 old_selected_frame
= selected_frame
;
17205 selected_frame
= w
->frame
;
17206 old_selected_window
= selected_window
;
17207 XSETWINDOW (selected_window
, w
);
17209 /* These will be set while the mode line specs are processed. */
17210 line_number_displayed
= 0;
17211 w
->column_number_displayed
= Qnil
;
17213 if (WINDOW_WANTS_MODELINE_P (w
))
17215 struct window
*sel_w
= XWINDOW (old_selected_window
);
17217 /* Select mode line face based on the real selected window. */
17218 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17219 current_buffer
->mode_line_format
);
17223 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17225 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17226 current_buffer
->header_line_format
);
17230 selected_frame
= old_selected_frame
;
17231 selected_window
= old_selected_window
;
17236 /* Display mode or top line of window W. FACE_ID specifies which line
17237 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
17238 FORMAT is the mode line format to display. Value is the pixel
17239 height of the mode line displayed. */
17242 display_mode_line (w
, face_id
, format
)
17244 enum face_id face_id
;
17245 Lisp_Object format
;
17249 int count
= SPECPDL_INDEX ();
17251 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17252 /* Don't extend on a previously drawn mode-line.
17253 This may happen if called from pos_visible_p. */
17254 it
.glyph_row
->enabled_p
= 0;
17255 prepare_desired_row (it
.glyph_row
);
17257 it
.glyph_row
->mode_line_p
= 1;
17259 if (! mode_line_inverse_video
)
17260 /* Force the mode-line to be displayed in the default face. */
17261 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17263 record_unwind_protect (unwind_format_mode_line
,
17264 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17266 mode_line_target
= MODE_LINE_DISPLAY
;
17268 /* Temporarily make frame's keyboard the current kboard so that
17269 kboard-local variables in the mode_line_format will get the right
17271 push_kboard (FRAME_KBOARD (it
.f
));
17272 record_unwind_save_match_data ();
17273 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17276 unbind_to (count
, Qnil
);
17278 /* Fill up with spaces. */
17279 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17281 compute_line_metrics (&it
);
17282 it
.glyph_row
->full_width_p
= 1;
17283 it
.glyph_row
->continued_p
= 0;
17284 it
.glyph_row
->truncated_on_left_p
= 0;
17285 it
.glyph_row
->truncated_on_right_p
= 0;
17287 /* Make a 3D mode-line have a shadow at its right end. */
17288 face
= FACE_FROM_ID (it
.f
, face_id
);
17289 extend_face_to_end_of_line (&it
);
17290 if (face
->box
!= FACE_NO_BOX
)
17292 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17293 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17294 last
->right_box_line_p
= 1;
17297 return it
.glyph_row
->height
;
17300 /* Move element ELT in LIST to the front of LIST.
17301 Return the updated list. */
17304 move_elt_to_front (elt
, list
)
17305 Lisp_Object elt
, list
;
17307 register Lisp_Object tail
, prev
;
17308 register Lisp_Object tem
;
17312 while (CONSP (tail
))
17318 /* Splice out the link TAIL. */
17320 list
= XCDR (tail
);
17322 Fsetcdr (prev
, XCDR (tail
));
17324 /* Now make it the first. */
17325 Fsetcdr (tail
, list
);
17330 tail
= XCDR (tail
);
17334 /* Not found--return unchanged LIST. */
17338 /* Contribute ELT to the mode line for window IT->w. How it
17339 translates into text depends on its data type.
17341 IT describes the display environment in which we display, as usual.
17343 DEPTH is the depth in recursion. It is used to prevent
17344 infinite recursion here.
17346 FIELD_WIDTH is the number of characters the display of ELT should
17347 occupy in the mode line, and PRECISION is the maximum number of
17348 characters to display from ELT's representation. See
17349 display_string for details.
17351 Returns the hpos of the end of the text generated by ELT.
17353 PROPS is a property list to add to any string we encounter.
17355 If RISKY is nonzero, remove (disregard) any properties in any string
17356 we encounter, and ignore :eval and :propertize.
17358 The global variable `mode_line_target' determines whether the
17359 output is passed to `store_mode_line_noprop',
17360 `store_mode_line_string', or `display_string'. */
17363 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17366 int field_width
, precision
;
17367 Lisp_Object elt
, props
;
17370 int n
= 0, field
, prec
;
17375 elt
= build_string ("*too-deep*");
17379 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17383 /* A string: output it and check for %-constructs within it. */
17387 if (SCHARS (elt
) > 0
17388 && (!NILP (props
) || risky
))
17390 Lisp_Object oprops
, aelt
;
17391 oprops
= Ftext_properties_at (make_number (0), elt
);
17393 /* If the starting string's properties are not what
17394 we want, translate the string. Also, if the string
17395 is risky, do that anyway. */
17397 if (NILP (Fequal (props
, oprops
)) || risky
)
17399 /* If the starting string has properties,
17400 merge the specified ones onto the existing ones. */
17401 if (! NILP (oprops
) && !risky
)
17405 oprops
= Fcopy_sequence (oprops
);
17407 while (CONSP (tem
))
17409 oprops
= Fplist_put (oprops
, XCAR (tem
),
17410 XCAR (XCDR (tem
)));
17411 tem
= XCDR (XCDR (tem
));
17416 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17417 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17419 /* AELT is what we want. Move it to the front
17420 without consing. */
17422 mode_line_proptrans_alist
17423 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17429 /* If AELT has the wrong props, it is useless.
17430 so get rid of it. */
17432 mode_line_proptrans_alist
17433 = Fdelq (aelt
, mode_line_proptrans_alist
);
17435 elt
= Fcopy_sequence (elt
);
17436 Fset_text_properties (make_number (0), Flength (elt
),
17438 /* Add this item to mode_line_proptrans_alist. */
17439 mode_line_proptrans_alist
17440 = Fcons (Fcons (elt
, props
),
17441 mode_line_proptrans_alist
);
17442 /* Truncate mode_line_proptrans_alist
17443 to at most 50 elements. */
17444 tem
= Fnthcdr (make_number (50),
17445 mode_line_proptrans_alist
);
17447 XSETCDR (tem
, Qnil
);
17456 prec
= precision
- n
;
17457 switch (mode_line_target
)
17459 case MODE_LINE_NOPROP
:
17460 case MODE_LINE_TITLE
:
17461 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17463 case MODE_LINE_STRING
:
17464 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17466 case MODE_LINE_DISPLAY
:
17467 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17468 0, prec
, 0, STRING_MULTIBYTE (elt
));
17475 /* Handle the non-literal case. */
17477 while ((precision
<= 0 || n
< precision
)
17478 && SREF (elt
, offset
) != 0
17479 && (mode_line_target
!= MODE_LINE_DISPLAY
17480 || it
->current_x
< it
->last_visible_x
))
17482 int last_offset
= offset
;
17484 /* Advance to end of string or next format specifier. */
17485 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17488 if (offset
- 1 != last_offset
)
17490 int nchars
, nbytes
;
17492 /* Output to end of string or up to '%'. Field width
17493 is length of string. Don't output more than
17494 PRECISION allows us. */
17497 prec
= c_string_width (SDATA (elt
) + last_offset
,
17498 offset
- last_offset
, precision
- n
,
17501 switch (mode_line_target
)
17503 case MODE_LINE_NOPROP
:
17504 case MODE_LINE_TITLE
:
17505 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17507 case MODE_LINE_STRING
:
17509 int bytepos
= last_offset
;
17510 int charpos
= string_byte_to_char (elt
, bytepos
);
17511 int endpos
= (precision
<= 0
17512 ? string_byte_to_char (elt
, offset
)
17513 : charpos
+ nchars
);
17515 n
+= store_mode_line_string (NULL
,
17516 Fsubstring (elt
, make_number (charpos
),
17517 make_number (endpos
)),
17521 case MODE_LINE_DISPLAY
:
17523 int bytepos
= last_offset
;
17524 int charpos
= string_byte_to_char (elt
, bytepos
);
17526 if (precision
<= 0)
17527 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17528 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17530 STRING_MULTIBYTE (elt
));
17535 else /* c == '%' */
17537 int percent_position
= offset
;
17539 /* Get the specified minimum width. Zero means
17542 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17543 field
= field
* 10 + c
- '0';
17545 /* Don't pad beyond the total padding allowed. */
17546 if (field_width
- n
> 0 && field
> field_width
- n
)
17547 field
= field_width
- n
;
17549 /* Note that either PRECISION <= 0 or N < PRECISION. */
17550 prec
= precision
- n
;
17553 n
+= display_mode_element (it
, depth
, field
, prec
,
17554 Vglobal_mode_string
, props
,
17559 int bytepos
, charpos
;
17560 unsigned char *spec
;
17562 bytepos
= percent_position
;
17563 charpos
= (STRING_MULTIBYTE (elt
)
17564 ? string_byte_to_char (elt
, bytepos
)
17567 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17569 switch (mode_line_target
)
17571 case MODE_LINE_NOPROP
:
17572 case MODE_LINE_TITLE
:
17573 n
+= store_mode_line_noprop (spec
, field
, prec
);
17575 case MODE_LINE_STRING
:
17577 int len
= strlen (spec
);
17578 Lisp_Object tem
= make_string (spec
, len
);
17579 props
= Ftext_properties_at (make_number (charpos
), elt
);
17580 /* Should only keep face property in props */
17581 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17584 case MODE_LINE_DISPLAY
:
17586 int nglyphs_before
, nwritten
;
17588 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17589 nwritten
= display_string (spec
, Qnil
, elt
,
17594 /* Assign to the glyphs written above the
17595 string where the `%x' came from, position
17599 struct glyph
*glyph
17600 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17604 for (i
= 0; i
< nwritten
; ++i
)
17606 glyph
[i
].object
= elt
;
17607 glyph
[i
].charpos
= charpos
;
17624 /* A symbol: process the value of the symbol recursively
17625 as if it appeared here directly. Avoid error if symbol void.
17626 Special case: if value of symbol is a string, output the string
17629 register Lisp_Object tem
;
17631 /* If the variable is not marked as risky to set
17632 then its contents are risky to use. */
17633 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17636 tem
= Fboundp (elt
);
17639 tem
= Fsymbol_value (elt
);
17640 /* If value is a string, output that string literally:
17641 don't check for % within it. */
17645 if (!EQ (tem
, elt
))
17647 /* Give up right away for nil or t. */
17657 register Lisp_Object car
, tem
;
17659 /* A cons cell: five distinct cases.
17660 If first element is :eval or :propertize, do something special.
17661 If first element is a string or a cons, process all the elements
17662 and effectively concatenate them.
17663 If first element is a negative number, truncate displaying cdr to
17664 at most that many characters. If positive, pad (with spaces)
17665 to at least that many characters.
17666 If first element is a symbol, process the cadr or caddr recursively
17667 according to whether the symbol's value is non-nil or nil. */
17669 if (EQ (car
, QCeval
))
17671 /* An element of the form (:eval FORM) means evaluate FORM
17672 and use the result as mode line elements. */
17677 if (CONSP (XCDR (elt
)))
17680 spec
= safe_eval (XCAR (XCDR (elt
)));
17681 n
+= display_mode_element (it
, depth
, field_width
- n
,
17682 precision
- n
, spec
, props
,
17686 else if (EQ (car
, QCpropertize
))
17688 /* An element of the form (:propertize ELT PROPS...)
17689 means display ELT but applying properties PROPS. */
17694 if (CONSP (XCDR (elt
)))
17695 n
+= display_mode_element (it
, depth
, field_width
- n
,
17696 precision
- n
, XCAR (XCDR (elt
)),
17697 XCDR (XCDR (elt
)), risky
);
17699 else if (SYMBOLP (car
))
17701 tem
= Fboundp (car
);
17705 /* elt is now the cdr, and we know it is a cons cell.
17706 Use its car if CAR has a non-nil value. */
17709 tem
= Fsymbol_value (car
);
17716 /* Symbol's value is nil (or symbol is unbound)
17717 Get the cddr of the original list
17718 and if possible find the caddr and use that. */
17722 else if (!CONSP (elt
))
17727 else if (INTEGERP (car
))
17729 register int lim
= XINT (car
);
17733 /* Negative int means reduce maximum width. */
17734 if (precision
<= 0)
17737 precision
= min (precision
, -lim
);
17741 /* Padding specified. Don't let it be more than
17742 current maximum. */
17744 lim
= min (precision
, lim
);
17746 /* If that's more padding than already wanted, queue it.
17747 But don't reduce padding already specified even if
17748 that is beyond the current truncation point. */
17749 field_width
= max (lim
, field_width
);
17753 else if (STRINGP (car
) || CONSP (car
))
17755 register int limit
= 50;
17756 /* Limit is to protect against circular lists. */
17759 && (precision
<= 0 || n
< precision
))
17761 n
+= display_mode_element (it
, depth
,
17762 /* Do padding only after the last
17763 element in the list. */
17764 (! CONSP (XCDR (elt
))
17767 precision
- n
, XCAR (elt
),
17777 elt
= build_string ("*invalid*");
17781 /* Pad to FIELD_WIDTH. */
17782 if (field_width
> 0 && n
< field_width
)
17784 switch (mode_line_target
)
17786 case MODE_LINE_NOPROP
:
17787 case MODE_LINE_TITLE
:
17788 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17790 case MODE_LINE_STRING
:
17791 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17793 case MODE_LINE_DISPLAY
:
17794 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17803 /* Store a mode-line string element in mode_line_string_list.
17805 If STRING is non-null, display that C string. Otherwise, the Lisp
17806 string LISP_STRING is displayed.
17808 FIELD_WIDTH is the minimum number of output glyphs to produce.
17809 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17810 with spaces. FIELD_WIDTH <= 0 means don't pad.
17812 PRECISION is the maximum number of characters to output from
17813 STRING. PRECISION <= 0 means don't truncate the string.
17815 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17816 properties to the string.
17818 PROPS are the properties to add to the string.
17819 The mode_line_string_face face property is always added to the string.
17823 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17825 Lisp_Object lisp_string
;
17834 if (string
!= NULL
)
17836 len
= strlen (string
);
17837 if (precision
> 0 && len
> precision
)
17839 lisp_string
= make_string (string
, len
);
17841 props
= mode_line_string_face_prop
;
17842 else if (!NILP (mode_line_string_face
))
17844 Lisp_Object face
= Fplist_get (props
, Qface
);
17845 props
= Fcopy_sequence (props
);
17847 face
= mode_line_string_face
;
17849 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17850 props
= Fplist_put (props
, Qface
, face
);
17852 Fadd_text_properties (make_number (0), make_number (len
),
17853 props
, lisp_string
);
17857 len
= XFASTINT (Flength (lisp_string
));
17858 if (precision
> 0 && len
> precision
)
17861 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17864 if (!NILP (mode_line_string_face
))
17868 props
= Ftext_properties_at (make_number (0), lisp_string
);
17869 face
= Fplist_get (props
, Qface
);
17871 face
= mode_line_string_face
;
17873 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17874 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17876 lisp_string
= Fcopy_sequence (lisp_string
);
17879 Fadd_text_properties (make_number (0), make_number (len
),
17880 props
, lisp_string
);
17885 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17889 if (field_width
> len
)
17891 field_width
-= len
;
17892 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17894 Fadd_text_properties (make_number (0), make_number (field_width
),
17895 props
, lisp_string
);
17896 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17904 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17906 doc
: /* Format a string out of a mode line format specification.
17907 First arg FORMAT specifies the mode line format (see `mode-line-format'
17908 for details) to use.
17910 Optional second arg FACE specifies the face property to put
17911 on all characters for which no face is specified.
17912 The value t means whatever face the window's mode line currently uses
17913 \(either `mode-line' or `mode-line-inactive', depending).
17914 A value of nil means the default is no face property.
17915 If FACE is an integer, the value string has no text properties.
17917 Optional third and fourth args WINDOW and BUFFER specify the window
17918 and buffer to use as the context for the formatting (defaults
17919 are the selected window and the window's buffer). */)
17920 (format
, face
, window
, buffer
)
17921 Lisp_Object format
, face
, window
, buffer
;
17926 struct buffer
*old_buffer
= NULL
;
17928 int no_props
= INTEGERP (face
);
17929 int count
= SPECPDL_INDEX ();
17931 int string_start
= 0;
17934 window
= selected_window
;
17935 CHECK_WINDOW (window
);
17936 w
= XWINDOW (window
);
17939 buffer
= w
->buffer
;
17940 CHECK_BUFFER (buffer
);
17942 /* Make formatting the modeline a non-op when noninteractive, otherwise
17943 there will be problems later caused by a partially initialized frame. */
17944 if (NILP (format
) || noninteractive
)
17945 return empty_unibyte_string
;
17953 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17954 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17958 face_id
= DEFAULT_FACE_ID
;
17960 if (XBUFFER (buffer
) != current_buffer
)
17961 old_buffer
= current_buffer
;
17963 /* Save things including mode_line_proptrans_alist,
17964 and set that to nil so that we don't alter the outer value. */
17965 record_unwind_protect (unwind_format_mode_line
,
17966 format_mode_line_unwind_data
17967 (old_buffer
, selected_window
, 1));
17968 mode_line_proptrans_alist
= Qnil
;
17970 Fselect_window (window
, Qt
);
17972 set_buffer_internal_1 (XBUFFER (buffer
));
17974 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17978 mode_line_target
= MODE_LINE_NOPROP
;
17979 mode_line_string_face_prop
= Qnil
;
17980 mode_line_string_list
= Qnil
;
17981 string_start
= MODE_LINE_NOPROP_LEN (0);
17985 mode_line_target
= MODE_LINE_STRING
;
17986 mode_line_string_list
= Qnil
;
17987 mode_line_string_face
= face
;
17988 mode_line_string_face_prop
17989 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17992 push_kboard (FRAME_KBOARD (it
.f
));
17993 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17998 len
= MODE_LINE_NOPROP_LEN (string_start
);
17999 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18003 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18004 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18005 empty_unibyte_string
);
18008 unbind_to (count
, Qnil
);
18012 /* Write a null-terminated, right justified decimal representation of
18013 the positive integer D to BUF using a minimal field width WIDTH. */
18016 pint2str (buf
, width
, d
)
18017 register char *buf
;
18018 register int width
;
18021 register char *p
= buf
;
18029 *p
++ = d
% 10 + '0';
18034 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18045 /* Write a null-terminated, right justified decimal and "human
18046 readable" representation of the nonnegative integer D to BUF using
18047 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18049 static const char power_letter
[] =
18063 pint2hrstr (buf
, width
, d
)
18068 /* We aim to represent the nonnegative integer D as
18069 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18072 /* -1 means: do not use TENTHS. */
18076 /* Length of QUOTIENT.TENTHS as a string. */
18082 if (1000 <= quotient
)
18084 /* Scale to the appropriate EXPONENT. */
18087 remainder
= quotient
% 1000;
18091 while (1000 <= quotient
);
18093 /* Round to nearest and decide whether to use TENTHS or not. */
18096 tenths
= remainder
/ 100;
18097 if (50 <= remainder
% 100)
18104 if (quotient
== 10)
18112 if (500 <= remainder
)
18114 if (quotient
< 999)
18125 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18126 if (tenths
== -1 && quotient
<= 99)
18133 p
= psuffix
= buf
+ max (width
, length
);
18135 /* Print EXPONENT. */
18137 *psuffix
++ = power_letter
[exponent
];
18140 /* Print TENTHS. */
18143 *--p
= '0' + tenths
;
18147 /* Print QUOTIENT. */
18150 int digit
= quotient
% 10;
18151 *--p
= '0' + digit
;
18153 while ((quotient
/= 10) != 0);
18155 /* Print leading spaces. */
18160 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18161 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18162 type of CODING_SYSTEM. Return updated pointer into BUF. */
18164 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18167 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18168 Lisp_Object coding_system
;
18169 register char *buf
;
18173 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18174 const unsigned char *eol_str
;
18176 /* The EOL conversion we are using. */
18177 Lisp_Object eoltype
;
18179 val
= CODING_SYSTEM_SPEC (coding_system
);
18182 if (!VECTORP (val
)) /* Not yet decided. */
18187 eoltype
= eol_mnemonic_undecided
;
18188 /* Don't mention EOL conversion if it isn't decided. */
18193 Lisp_Object eolvalue
;
18195 attrs
= AREF (val
, 0);
18196 eolvalue
= AREF (val
, 2);
18199 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18203 /* The EOL conversion that is normal on this system. */
18205 if (NILP (eolvalue
)) /* Not yet decided. */
18206 eoltype
= eol_mnemonic_undecided
;
18207 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18208 eoltype
= eol_mnemonic_undecided
;
18209 else /* eolvalue is Qunix, Qdos, or Qmac. */
18210 eoltype
= (EQ (eolvalue
, Qunix
)
18211 ? eol_mnemonic_unix
18212 : (EQ (eolvalue
, Qdos
) == 1
18213 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18219 /* Mention the EOL conversion if it is not the usual one. */
18220 if (STRINGP (eoltype
))
18222 eol_str
= SDATA (eoltype
);
18223 eol_str_len
= SBYTES (eoltype
);
18225 else if (CHARACTERP (eoltype
))
18227 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18228 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18233 eol_str
= invalid_eol_type
;
18234 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18236 bcopy (eol_str
, buf
, eol_str_len
);
18237 buf
+= eol_str_len
;
18243 /* Return a string for the output of a mode line %-spec for window W,
18244 generated by character C. PRECISION >= 0 means don't return a
18245 string longer than that value. FIELD_WIDTH > 0 means pad the
18246 string returned with spaces to that value. Return 1 in *MULTIBYTE
18247 if the result is multibyte text.
18249 Note we operate on the current buffer for most purposes,
18250 the exception being w->base_line_pos. */
18252 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18255 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18258 int field_width
, precision
;
18262 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18263 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18264 struct buffer
*b
= current_buffer
;
18272 if (!NILP (b
->read_only
))
18274 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18279 /* This differs from %* only for a modified read-only buffer. */
18280 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18282 if (!NILP (b
->read_only
))
18287 /* This differs from %* in ignoring read-only-ness. */
18288 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18300 if (command_loop_level
> 5)
18302 p
= decode_mode_spec_buf
;
18303 for (i
= 0; i
< command_loop_level
; i
++)
18306 return decode_mode_spec_buf
;
18314 if (command_loop_level
> 5)
18316 p
= decode_mode_spec_buf
;
18317 for (i
= 0; i
< command_loop_level
; i
++)
18320 return decode_mode_spec_buf
;
18327 /* Let lots_of_dashes be a string of infinite length. */
18328 if (mode_line_target
== MODE_LINE_NOPROP
||
18329 mode_line_target
== MODE_LINE_STRING
)
18331 if (field_width
<= 0
18332 || field_width
> sizeof (lots_of_dashes
))
18334 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18335 decode_mode_spec_buf
[i
] = '-';
18336 decode_mode_spec_buf
[i
] = '\0';
18337 return decode_mode_spec_buf
;
18340 return lots_of_dashes
;
18348 /* %c and %l are ignored in `frame-title-format'.
18349 (In redisplay_internal, the frame title is drawn _before_ the
18350 windows are updated, so the stuff which depends on actual
18351 window contents (such as %l) may fail to render properly, or
18352 even crash emacs.) */
18353 if (mode_line_target
== MODE_LINE_TITLE
)
18357 int col
= (int) current_column (); /* iftc */
18358 w
->column_number_displayed
= make_number (col
);
18359 pint2str (decode_mode_spec_buf
, field_width
, col
);
18360 return decode_mode_spec_buf
;
18364 #ifndef SYSTEM_MALLOC
18366 if (NILP (Vmemory_full
))
18369 return "!MEM FULL! ";
18376 /* %F displays the frame name. */
18377 if (!NILP (f
->title
))
18378 return (char *) SDATA (f
->title
);
18379 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18380 return (char *) SDATA (f
->name
);
18389 int size
= ZV
- BEGV
;
18390 pint2str (decode_mode_spec_buf
, field_width
, size
);
18391 return decode_mode_spec_buf
;
18396 int size
= ZV
- BEGV
;
18397 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18398 return decode_mode_spec_buf
;
18403 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18404 int topline
, nlines
, junk
, height
;
18406 /* %c and %l are ignored in `frame-title-format'. */
18407 if (mode_line_target
== MODE_LINE_TITLE
)
18410 startpos
= XMARKER (w
->start
)->charpos
;
18411 startpos_byte
= marker_byte_position (w
->start
);
18412 height
= WINDOW_TOTAL_LINES (w
);
18414 /* If we decided that this buffer isn't suitable for line numbers,
18415 don't forget that too fast. */
18416 if (EQ (w
->base_line_pos
, w
->buffer
))
18418 /* But do forget it, if the window shows a different buffer now. */
18419 else if (BUFFERP (w
->base_line_pos
))
18420 w
->base_line_pos
= Qnil
;
18422 /* If the buffer is very big, don't waste time. */
18423 if (INTEGERP (Vline_number_display_limit
)
18424 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18426 w
->base_line_pos
= Qnil
;
18427 w
->base_line_number
= Qnil
;
18431 if (INTEGERP (w
->base_line_number
)
18432 && INTEGERP (w
->base_line_pos
)
18433 && XFASTINT (w
->base_line_pos
) <= startpos
)
18435 line
= XFASTINT (w
->base_line_number
);
18436 linepos
= XFASTINT (w
->base_line_pos
);
18437 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18442 linepos
= BUF_BEGV (b
);
18443 linepos_byte
= BUF_BEGV_BYTE (b
);
18446 /* Count lines from base line to window start position. */
18447 nlines
= display_count_lines (linepos
, linepos_byte
,
18451 topline
= nlines
+ line
;
18453 /* Determine a new base line, if the old one is too close
18454 or too far away, or if we did not have one.
18455 "Too close" means it's plausible a scroll-down would
18456 go back past it. */
18457 if (startpos
== BUF_BEGV (b
))
18459 w
->base_line_number
= make_number (topline
);
18460 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18462 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18463 || linepos
== BUF_BEGV (b
))
18465 int limit
= BUF_BEGV (b
);
18466 int limit_byte
= BUF_BEGV_BYTE (b
);
18468 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18470 if (startpos
- distance
> limit
)
18472 limit
= startpos
- distance
;
18473 limit_byte
= CHAR_TO_BYTE (limit
);
18476 nlines
= display_count_lines (startpos
, startpos_byte
,
18478 - (height
* 2 + 30),
18480 /* If we couldn't find the lines we wanted within
18481 line_number_display_limit_width chars per line,
18482 give up on line numbers for this window. */
18483 if (position
== limit_byte
&& limit
== startpos
- distance
)
18485 w
->base_line_pos
= w
->buffer
;
18486 w
->base_line_number
= Qnil
;
18490 w
->base_line_number
= make_number (topline
- nlines
);
18491 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18494 /* Now count lines from the start pos to point. */
18495 nlines
= display_count_lines (startpos
, startpos_byte
,
18496 PT_BYTE
, PT
, &junk
);
18498 /* Record that we did display the line number. */
18499 line_number_displayed
= 1;
18501 /* Make the string to show. */
18502 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18503 return decode_mode_spec_buf
;
18506 char* p
= decode_mode_spec_buf
;
18507 int pad
= field_width
- 2;
18513 return decode_mode_spec_buf
;
18519 obj
= b
->mode_name
;
18523 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18529 int pos
= marker_position (w
->start
);
18530 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18532 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18534 if (pos
<= BUF_BEGV (b
))
18539 else if (pos
<= BUF_BEGV (b
))
18543 if (total
> 1000000)
18544 /* Do it differently for a large value, to avoid overflow. */
18545 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18547 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18548 /* We can't normally display a 3-digit number,
18549 so get us a 2-digit number that is close. */
18552 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18553 return decode_mode_spec_buf
;
18557 /* Display percentage of size above the bottom of the screen. */
18560 int toppos
= marker_position (w
->start
);
18561 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18562 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18564 if (botpos
>= BUF_ZV (b
))
18566 if (toppos
<= BUF_BEGV (b
))
18573 if (total
> 1000000)
18574 /* Do it differently for a large value, to avoid overflow. */
18575 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18577 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18578 /* We can't normally display a 3-digit number,
18579 so get us a 2-digit number that is close. */
18582 if (toppos
<= BUF_BEGV (b
))
18583 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18585 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18586 return decode_mode_spec_buf
;
18591 /* status of process */
18592 obj
= Fget_buffer_process (Fcurrent_buffer ());
18594 return "no process";
18595 #ifdef subprocesses
18596 obj
= Fsymbol_name (Fprocess_status (obj
));
18603 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18610 case 't': /* indicate TEXT or BINARY */
18611 #ifdef MODE_LINE_BINARY_TEXT
18612 return MODE_LINE_BINARY_TEXT (b
);
18618 /* coding-system (not including end-of-line format) */
18620 /* coding-system (including end-of-line type) */
18622 int eol_flag
= (c
== 'Z');
18623 char *p
= decode_mode_spec_buf
;
18625 if (! FRAME_WINDOW_P (f
))
18627 /* No need to mention EOL here--the terminal never needs
18628 to do EOL conversion. */
18629 p
= decode_mode_spec_coding (CODING_ID_NAME
18630 (FRAME_KEYBOARD_CODING (f
)->id
),
18632 p
= decode_mode_spec_coding (CODING_ID_NAME
18633 (FRAME_TERMINAL_CODING (f
)->id
),
18636 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18639 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18640 #ifdef subprocesses
18641 obj
= Fget_buffer_process (Fcurrent_buffer ());
18642 if (PROCESSP (obj
))
18644 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18646 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18649 #endif /* subprocesses */
18652 return decode_mode_spec_buf
;
18658 *multibyte
= STRING_MULTIBYTE (obj
);
18659 return (char *) SDATA (obj
);
18666 /* Count up to COUNT lines starting from START / START_BYTE.
18667 But don't go beyond LIMIT_BYTE.
18668 Return the number of lines thus found (always nonnegative).
18670 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18673 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18674 int start
, start_byte
, limit_byte
, count
;
18677 register unsigned char *cursor
;
18678 unsigned char *base
;
18680 register int ceiling
;
18681 register unsigned char *ceiling_addr
;
18682 int orig_count
= count
;
18684 /* If we are not in selective display mode,
18685 check only for newlines. */
18686 int selective_display
= (!NILP (current_buffer
->selective_display
)
18687 && !INTEGERP (current_buffer
->selective_display
));
18691 while (start_byte
< limit_byte
)
18693 ceiling
= BUFFER_CEILING_OF (start_byte
);
18694 ceiling
= min (limit_byte
- 1, ceiling
);
18695 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18696 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18699 if (selective_display
)
18700 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18703 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18706 if (cursor
!= ceiling_addr
)
18710 start_byte
+= cursor
- base
+ 1;
18711 *byte_pos_ptr
= start_byte
;
18715 if (++cursor
== ceiling_addr
)
18721 start_byte
+= cursor
- base
;
18726 while (start_byte
> limit_byte
)
18728 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18729 ceiling
= max (limit_byte
, ceiling
);
18730 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18731 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18734 if (selective_display
)
18735 while (--cursor
!= ceiling_addr
18736 && *cursor
!= '\n' && *cursor
!= 015)
18739 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18742 if (cursor
!= ceiling_addr
)
18746 start_byte
+= cursor
- base
+ 1;
18747 *byte_pos_ptr
= start_byte
;
18748 /* When scanning backwards, we should
18749 not count the newline posterior to which we stop. */
18750 return - orig_count
- 1;
18756 /* Here we add 1 to compensate for the last decrement
18757 of CURSOR, which took it past the valid range. */
18758 start_byte
+= cursor
- base
+ 1;
18762 *byte_pos_ptr
= limit_byte
;
18765 return - orig_count
+ count
;
18766 return orig_count
- count
;
18772 /***********************************************************************
18774 ***********************************************************************/
18776 /* Display a NUL-terminated string, starting with index START.
18778 If STRING is non-null, display that C string. Otherwise, the Lisp
18779 string LISP_STRING is displayed.
18781 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18782 FACE_STRING. Display STRING or LISP_STRING with the face at
18783 FACE_STRING_POS in FACE_STRING:
18785 Display the string in the environment given by IT, but use the
18786 standard display table, temporarily.
18788 FIELD_WIDTH is the minimum number of output glyphs to produce.
18789 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18790 with spaces. If STRING has more characters, more than FIELD_WIDTH
18791 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18793 PRECISION is the maximum number of characters to output from
18794 STRING. PRECISION < 0 means don't truncate the string.
18796 This is roughly equivalent to printf format specifiers:
18798 FIELD_WIDTH PRECISION PRINTF
18799 ----------------------------------------
18805 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18806 display them, and < 0 means obey the current buffer's value of
18807 enable_multibyte_characters.
18809 Value is the number of columns displayed. */
18812 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18813 start
, it
, field_width
, precision
, max_x
, multibyte
)
18814 unsigned char *string
;
18815 Lisp_Object lisp_string
;
18816 Lisp_Object face_string
;
18817 EMACS_INT face_string_pos
;
18820 int field_width
, precision
, max_x
;
18823 int hpos_at_start
= it
->hpos
;
18824 int saved_face_id
= it
->face_id
;
18825 struct glyph_row
*row
= it
->glyph_row
;
18827 /* Initialize the iterator IT for iteration over STRING beginning
18828 with index START. */
18829 reseat_to_string (it
, string
, lisp_string
, start
,
18830 precision
, field_width
, multibyte
);
18832 /* If displaying STRING, set up the face of the iterator
18833 from LISP_STRING, if that's given. */
18834 if (STRINGP (face_string
))
18840 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18841 0, it
->region_beg_charpos
,
18842 it
->region_end_charpos
,
18843 &endptr
, it
->base_face_id
, 0);
18844 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18845 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18848 /* Set max_x to the maximum allowed X position. Don't let it go
18849 beyond the right edge of the window. */
18851 max_x
= it
->last_visible_x
;
18853 max_x
= min (max_x
, it
->last_visible_x
);
18855 /* Skip over display elements that are not visible. because IT->w is
18857 if (it
->current_x
< it
->first_visible_x
)
18858 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18859 MOVE_TO_POS
| MOVE_TO_X
);
18861 row
->ascent
= it
->max_ascent
;
18862 row
->height
= it
->max_ascent
+ it
->max_descent
;
18863 row
->phys_ascent
= it
->max_phys_ascent
;
18864 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18865 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18867 /* This condition is for the case that we are called with current_x
18868 past last_visible_x. */
18869 while (it
->current_x
< max_x
)
18871 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18873 /* Get the next display element. */
18874 if (!get_next_display_element (it
))
18877 /* Produce glyphs. */
18878 x_before
= it
->current_x
;
18879 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18880 PRODUCE_GLYPHS (it
);
18882 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18885 while (i
< nglyphs
)
18887 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18889 if (it
->line_wrap
!= TRUNCATE
18890 && x
+ glyph
->pixel_width
> max_x
)
18892 /* End of continued line or max_x reached. */
18893 if (CHAR_GLYPH_PADDING_P (*glyph
))
18895 /* A wide character is unbreakable. */
18896 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18897 it
->current_x
= x_before
;
18901 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18906 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18908 /* Glyph is at least partially visible. */
18910 if (x
< it
->first_visible_x
)
18911 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18915 /* Glyph is off the left margin of the display area.
18916 Should not happen. */
18920 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18921 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18922 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18923 row
->phys_height
= max (row
->phys_height
,
18924 it
->max_phys_ascent
+ it
->max_phys_descent
);
18925 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18926 it
->max_extra_line_spacing
);
18927 x
+= glyph
->pixel_width
;
18931 /* Stop if max_x reached. */
18935 /* Stop at line ends. */
18936 if (ITERATOR_AT_END_OF_LINE_P (it
))
18938 it
->continuation_lines_width
= 0;
18942 set_iterator_to_next (it
, 1);
18944 /* Stop if truncating at the right edge. */
18945 if (it
->line_wrap
== TRUNCATE
18946 && it
->current_x
>= it
->last_visible_x
)
18948 /* Add truncation mark, but don't do it if the line is
18949 truncated at a padding space. */
18950 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18952 if (!FRAME_WINDOW_P (it
->f
))
18956 if (it
->current_x
> it
->last_visible_x
)
18958 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18959 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18961 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18963 row
->used
[TEXT_AREA
] = i
;
18964 produce_special_glyphs (it
, IT_TRUNCATION
);
18967 produce_special_glyphs (it
, IT_TRUNCATION
);
18969 it
->glyph_row
->truncated_on_right_p
= 1;
18975 /* Maybe insert a truncation at the left. */
18976 if (it
->first_visible_x
18977 && IT_CHARPOS (*it
) > 0)
18979 if (!FRAME_WINDOW_P (it
->f
))
18980 insert_left_trunc_glyphs (it
);
18981 it
->glyph_row
->truncated_on_left_p
= 1;
18984 it
->face_id
= saved_face_id
;
18986 /* Value is number of columns displayed. */
18987 return it
->hpos
- hpos_at_start
;
18992 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18993 appears as an element of LIST or as the car of an element of LIST.
18994 If PROPVAL is a list, compare each element against LIST in that
18995 way, and return 1/2 if any element of PROPVAL is found in LIST.
18996 Otherwise return 0. This function cannot quit.
18997 The return value is 2 if the text is invisible but with an ellipsis
18998 and 1 if it's invisible and without an ellipsis. */
19001 invisible_p (propval
, list
)
19002 register Lisp_Object propval
;
19005 register Lisp_Object tail
, proptail
;
19007 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19009 register Lisp_Object tem
;
19011 if (EQ (propval
, tem
))
19013 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19014 return NILP (XCDR (tem
)) ? 1 : 2;
19017 if (CONSP (propval
))
19019 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19021 Lisp_Object propelt
;
19022 propelt
= XCAR (proptail
);
19023 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19025 register Lisp_Object tem
;
19027 if (EQ (propelt
, tem
))
19029 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19030 return NILP (XCDR (tem
)) ? 1 : 2;
19038 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19039 doc
: /* Non-nil if the property makes the text invisible.
19040 POS-OR-PROP can be a marker or number, in which case it is taken to be
19041 a position in the current buffer and the value of the `invisible' property
19042 is checked; or it can be some other value, which is then presumed to be the
19043 value of the `invisible' property of the text of interest.
19044 The non-nil value returned can be t for truly invisible text or something
19045 else if the text is replaced by an ellipsis. */)
19047 Lisp_Object pos_or_prop
;
19050 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19051 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19053 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19054 return (invis
== 0 ? Qnil
19056 : make_number (invis
));
19059 /* Calculate a width or height in pixels from a specification using
19060 the following elements:
19063 NUM - a (fractional) multiple of the default font width/height
19064 (NUM) - specifies exactly NUM pixels
19065 UNIT - a fixed number of pixels, see below.
19066 ELEMENT - size of a display element in pixels, see below.
19067 (NUM . SPEC) - equals NUM * SPEC
19068 (+ SPEC SPEC ...) - add pixel values
19069 (- SPEC SPEC ...) - subtract pixel values
19070 (- SPEC) - negate pixel value
19073 INT or FLOAT - a number constant
19074 SYMBOL - use symbol's (buffer local) variable binding.
19077 in - pixels per inch *)
19078 mm - pixels per 1/1000 meter *)
19079 cm - pixels per 1/100 meter *)
19080 width - width of current font in pixels.
19081 height - height of current font in pixels.
19083 *) using the ratio(s) defined in display-pixels-per-inch.
19087 left-fringe - left fringe width in pixels
19088 right-fringe - right fringe width in pixels
19090 left-margin - left margin width in pixels
19091 right-margin - right margin width in pixels
19093 scroll-bar - scroll-bar area width in pixels
19097 Pixels corresponding to 5 inches:
19100 Total width of non-text areas on left side of window (if scroll-bar is on left):
19101 '(space :width (+ left-fringe left-margin scroll-bar))
19103 Align to first text column (in header line):
19104 '(space :align-to 0)
19106 Align to middle of text area minus half the width of variable `my-image'
19107 containing a loaded image:
19108 '(space :align-to (0.5 . (- text my-image)))
19110 Width of left margin minus width of 1 character in the default font:
19111 '(space :width (- left-margin 1))
19113 Width of left margin minus width of 2 characters in the current font:
19114 '(space :width (- left-margin (2 . width)))
19116 Center 1 character over left-margin (in header line):
19117 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19119 Different ways to express width of left fringe plus left margin minus one pixel:
19120 '(space :width (- (+ left-fringe left-margin) (1)))
19121 '(space :width (+ left-fringe left-margin (- (1))))
19122 '(space :width (+ left-fringe left-margin (-1)))
19126 #define NUMVAL(X) \
19127 ((INTEGERP (X) || FLOATP (X)) \
19132 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19137 int width_p
, *align_to
;
19141 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19142 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19145 return OK_PIXELS (0);
19147 xassert (FRAME_LIVE_P (it
->f
));
19149 if (SYMBOLP (prop
))
19151 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19153 char *unit
= SDATA (SYMBOL_NAME (prop
));
19155 if (unit
[0] == 'i' && unit
[1] == 'n')
19157 else if (unit
[0] == 'm' && unit
[1] == 'm')
19159 else if (unit
[0] == 'c' && unit
[1] == 'm')
19166 #ifdef HAVE_WINDOW_SYSTEM
19167 if (FRAME_WINDOW_P (it
->f
)
19169 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19170 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19172 return OK_PIXELS (ppi
/ pixels
);
19175 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19176 || (CONSP (Vdisplay_pixels_per_inch
)
19178 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19179 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19181 return OK_PIXELS (ppi
/ pixels
);
19187 #ifdef HAVE_WINDOW_SYSTEM
19188 if (EQ (prop
, Qheight
))
19189 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19190 if (EQ (prop
, Qwidth
))
19191 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19193 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19194 return OK_PIXELS (1);
19197 if (EQ (prop
, Qtext
))
19198 return OK_PIXELS (width_p
19199 ? window_box_width (it
->w
, TEXT_AREA
)
19200 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19202 if (align_to
&& *align_to
< 0)
19205 if (EQ (prop
, Qleft
))
19206 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19207 if (EQ (prop
, Qright
))
19208 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19209 if (EQ (prop
, Qcenter
))
19210 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19211 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19212 if (EQ (prop
, Qleft_fringe
))
19213 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19214 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19215 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19216 if (EQ (prop
, Qright_fringe
))
19217 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19218 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19219 : window_box_right_offset (it
->w
, TEXT_AREA
));
19220 if (EQ (prop
, Qleft_margin
))
19221 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19222 if (EQ (prop
, Qright_margin
))
19223 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19224 if (EQ (prop
, Qscroll_bar
))
19225 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19227 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19228 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19229 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19234 if (EQ (prop
, Qleft_fringe
))
19235 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19236 if (EQ (prop
, Qright_fringe
))
19237 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19238 if (EQ (prop
, Qleft_margin
))
19239 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19240 if (EQ (prop
, Qright_margin
))
19241 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19242 if (EQ (prop
, Qscroll_bar
))
19243 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19246 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19249 if (INTEGERP (prop
) || FLOATP (prop
))
19251 int base_unit
= (width_p
19252 ? FRAME_COLUMN_WIDTH (it
->f
)
19253 : FRAME_LINE_HEIGHT (it
->f
));
19254 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19259 Lisp_Object car
= XCAR (prop
);
19260 Lisp_Object cdr
= XCDR (prop
);
19264 #ifdef HAVE_WINDOW_SYSTEM
19265 if (FRAME_WINDOW_P (it
->f
)
19266 && valid_image_p (prop
))
19268 int id
= lookup_image (it
->f
, prop
);
19269 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19271 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19274 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19280 while (CONSP (cdr
))
19282 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19283 font
, width_p
, align_to
))
19286 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19291 if (EQ (car
, Qminus
))
19293 return OK_PIXELS (pixels
);
19296 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19299 if (INTEGERP (car
) || FLOATP (car
))
19302 pixels
= XFLOATINT (car
);
19304 return OK_PIXELS (pixels
);
19305 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19306 font
, width_p
, align_to
))
19307 return OK_PIXELS (pixels
* fact
);
19318 /***********************************************************************
19320 ***********************************************************************/
19322 #ifdef HAVE_WINDOW_SYSTEM
19327 dump_glyph_string (s
)
19328 struct glyph_string
*s
;
19330 fprintf (stderr
, "glyph string\n");
19331 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19332 s
->x
, s
->y
, s
->width
, s
->height
);
19333 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19334 fprintf (stderr
, " hl = %d\n", s
->hl
);
19335 fprintf (stderr
, " left overhang = %d, right = %d\n",
19336 s
->left_overhang
, s
->right_overhang
);
19337 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19338 fprintf (stderr
, " extends to end of line = %d\n",
19339 s
->extends_to_end_of_line_p
);
19340 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19341 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19344 #endif /* GLYPH_DEBUG */
19346 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19347 of XChar2b structures for S; it can't be allocated in
19348 init_glyph_string because it must be allocated via `alloca'. W
19349 is the window on which S is drawn. ROW and AREA are the glyph row
19350 and area within the row from which S is constructed. START is the
19351 index of the first glyph structure covered by S. HL is a
19352 face-override for drawing S. */
19355 #define OPTIONAL_HDC(hdc) hdc,
19356 #define DECLARE_HDC(hdc) HDC hdc;
19357 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19358 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19361 #ifndef OPTIONAL_HDC
19362 #define OPTIONAL_HDC(hdc)
19363 #define DECLARE_HDC(hdc)
19364 #define ALLOCATE_HDC(hdc, f)
19365 #define RELEASE_HDC(hdc, f)
19369 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19370 struct glyph_string
*s
;
19374 struct glyph_row
*row
;
19375 enum glyph_row_area area
;
19377 enum draw_glyphs_face hl
;
19379 bzero (s
, sizeof *s
);
19381 s
->f
= XFRAME (w
->frame
);
19385 s
->display
= FRAME_X_DISPLAY (s
->f
);
19386 s
->window
= FRAME_X_WINDOW (s
->f
);
19387 s
->char2b
= char2b
;
19391 s
->first_glyph
= row
->glyphs
[area
] + start
;
19392 s
->height
= row
->height
;
19393 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19395 /* Display the internal border below the tool-bar window. */
19396 if (WINDOWP (s
->f
->tool_bar_window
)
19397 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19398 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19400 s
->ybase
= s
->y
+ row
->ascent
;
19404 /* Append the list of glyph strings with head H and tail T to the list
19405 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19408 append_glyph_string_lists (head
, tail
, h
, t
)
19409 struct glyph_string
**head
, **tail
;
19410 struct glyph_string
*h
, *t
;
19424 /* Prepend the list of glyph strings with head H and tail T to the
19425 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19429 prepend_glyph_string_lists (head
, tail
, h
, t
)
19430 struct glyph_string
**head
, **tail
;
19431 struct glyph_string
*h
, *t
;
19445 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19446 Set *HEAD and *TAIL to the resulting list. */
19449 append_glyph_string (head
, tail
, s
)
19450 struct glyph_string
**head
, **tail
;
19451 struct glyph_string
*s
;
19453 s
->next
= s
->prev
= NULL
;
19454 append_glyph_string_lists (head
, tail
, s
, s
);
19458 /* Get face and two-byte form of character C in face FACE_ID on frame
19459 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19460 means we want to display multibyte text. DISPLAY_P non-zero means
19461 make sure that X resources for the face returned are allocated.
19462 Value is a pointer to a realized face that is ready for display if
19463 DISPLAY_P is non-zero. */
19465 static INLINE
struct face
*
19466 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19470 int multibyte_p
, display_p
;
19472 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19476 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19478 if (code
!= FONT_INVALID_CODE
)
19479 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19481 STORE_XCHAR2B (char2b
, 0, 0);
19484 /* Make sure X resources of the face are allocated. */
19485 #ifdef HAVE_X_WINDOWS
19489 xassert (face
!= NULL
);
19490 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19497 /* Get face and two-byte form of character glyph GLYPH on frame F.
19498 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19499 a pointer to a realized face that is ready for display. */
19501 static INLINE
struct face
*
19502 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19504 struct glyph
*glyph
;
19510 xassert (glyph
->type
== CHAR_GLYPH
);
19511 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19518 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19520 if (code
!= FONT_INVALID_CODE
)
19521 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19523 STORE_XCHAR2B (char2b
, 0, 0);
19526 /* Make sure X resources of the face are allocated. */
19527 xassert (face
!= NULL
);
19528 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19533 /* Fill glyph string S with composition components specified by S->cmp.
19535 BASE_FACE is the base face of the composition.
19536 S->cmp_from is the index of the first component for S.
19538 OVERLAPS non-zero means S should draw the foreground only, and use
19539 its physical height for clipping. See also draw_glyphs.
19541 Value is the index of a component not in S. */
19544 fill_composite_glyph_string (s
, base_face
, overlaps
)
19545 struct glyph_string
*s
;
19546 struct face
*base_face
;
19550 /* For all glyphs of this composition, starting at the offset
19551 S->cmp_from, until we reach the end of the definition or encounter a
19552 glyph that requires the different face, add it to S. */
19557 s
->for_overlaps
= overlaps
;
19560 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
19562 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19566 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19569 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19570 s
->char2b
+ i
, 1, 1);
19576 s
->font
= s
->face
->font
;
19578 else if (s
->face
!= face
)
19586 /* All glyph strings for the same composition has the same width,
19587 i.e. the width set for the first component of the composition. */
19588 s
->width
= s
->first_glyph
->pixel_width
;
19590 /* If the specified font could not be loaded, use the frame's
19591 default font, but record the fact that we couldn't load it in
19592 the glyph string so that we can draw rectangles for the
19593 characters of the glyph string. */
19594 if (s
->font
== NULL
)
19596 s
->font_not_found_p
= 1;
19597 s
->font
= FRAME_FONT (s
->f
);
19600 /* Adjust base line for subscript/superscript text. */
19601 s
->ybase
+= s
->first_glyph
->voffset
;
19603 /* This glyph string must always be drawn with 16-bit functions. */
19610 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
19611 struct glyph_string
*s
;
19613 int start
, end
, overlaps
;
19615 struct glyph
*glyph
, *last
;
19616 Lisp_Object lgstring
;
19619 s
->for_overlaps
= overlaps
;
19620 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19621 last
= s
->row
->glyphs
[s
->area
] + end
;
19622 s
->cmp_id
= glyph
->u
.cmp
.id
;
19623 s
->cmp_from
= glyph
->u
.cmp
.from
;
19624 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
19625 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19626 lgstring
= composition_gstring_from_id (s
->cmp_id
);
19627 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
19629 while (glyph
< last
19630 && glyph
->u
.cmp
.automatic
19631 && glyph
->u
.cmp
.id
== s
->cmp_id
19632 && s
->cmp_to
== glyph
->u
.cmp
.from
)
19633 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
19635 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
19637 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
19638 unsigned code
= LGLYPH_CODE (lglyph
);
19640 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
19642 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
19643 return glyph
- s
->row
->glyphs
[s
->area
];
19647 /* Fill glyph string S from a sequence of character glyphs.
19649 FACE_ID is the face id of the string. START is the index of the
19650 first glyph to consider, END is the index of the last + 1.
19651 OVERLAPS non-zero means S should draw the foreground only, and use
19652 its physical height for clipping. See also draw_glyphs.
19654 Value is the index of the first glyph not in S. */
19657 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19658 struct glyph_string
*s
;
19660 int start
, end
, overlaps
;
19662 struct glyph
*glyph
, *last
;
19664 int glyph_not_available_p
;
19666 xassert (s
->f
== XFRAME (s
->w
->frame
));
19667 xassert (s
->nchars
== 0);
19668 xassert (start
>= 0 && end
> start
);
19670 s
->for_overlaps
= overlaps
;
19671 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19672 last
= s
->row
->glyphs
[s
->area
] + end
;
19673 voffset
= glyph
->voffset
;
19674 s
->padding_p
= glyph
->padding_p
;
19675 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19677 while (glyph
< last
19678 && glyph
->type
== CHAR_GLYPH
19679 && glyph
->voffset
== voffset
19680 /* Same face id implies same font, nowadays. */
19681 && glyph
->face_id
== face_id
19682 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19686 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19687 s
->char2b
+ s
->nchars
,
19689 s
->two_byte_p
= two_byte_p
;
19691 xassert (s
->nchars
<= end
- start
);
19692 s
->width
+= glyph
->pixel_width
;
19693 if (glyph
++->padding_p
!= s
->padding_p
)
19697 s
->font
= s
->face
->font
;
19699 /* If the specified font could not be loaded, use the frame's font,
19700 but record the fact that we couldn't load it in
19701 S->font_not_found_p so that we can draw rectangles for the
19702 characters of the glyph string. */
19703 if (s
->font
== NULL
|| glyph_not_available_p
)
19705 s
->font_not_found_p
= 1;
19706 s
->font
= FRAME_FONT (s
->f
);
19709 /* Adjust base line for subscript/superscript text. */
19710 s
->ybase
+= voffset
;
19712 xassert (s
->face
&& s
->face
->gc
);
19713 return glyph
- s
->row
->glyphs
[s
->area
];
19717 /* Fill glyph string S from image glyph S->first_glyph. */
19720 fill_image_glyph_string (s
)
19721 struct glyph_string
*s
;
19723 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19724 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19726 s
->slice
= s
->first_glyph
->slice
;
19727 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19728 s
->font
= s
->face
->font
;
19729 s
->width
= s
->first_glyph
->pixel_width
;
19731 /* Adjust base line for subscript/superscript text. */
19732 s
->ybase
+= s
->first_glyph
->voffset
;
19736 /* Fill glyph string S from a sequence of stretch glyphs.
19738 ROW is the glyph row in which the glyphs are found, AREA is the
19739 area within the row. START is the index of the first glyph to
19740 consider, END is the index of the last + 1.
19742 Value is the index of the first glyph not in S. */
19745 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19746 struct glyph_string
*s
;
19747 struct glyph_row
*row
;
19748 enum glyph_row_area area
;
19751 struct glyph
*glyph
, *last
;
19752 int voffset
, face_id
;
19754 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19756 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19757 last
= s
->row
->glyphs
[s
->area
] + end
;
19758 face_id
= glyph
->face_id
;
19759 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19760 s
->font
= s
->face
->font
;
19761 s
->width
= glyph
->pixel_width
;
19763 voffset
= glyph
->voffset
;
19767 && glyph
->type
== STRETCH_GLYPH
19768 && glyph
->voffset
== voffset
19769 && glyph
->face_id
== face_id
);
19771 s
->width
+= glyph
->pixel_width
;
19773 /* Adjust base line for subscript/superscript text. */
19774 s
->ybase
+= voffset
;
19776 /* The case that face->gc == 0 is handled when drawing the glyph
19777 string by calling PREPARE_FACE_FOR_DISPLAY. */
19779 return glyph
- s
->row
->glyphs
[s
->area
];
19782 static struct font_metrics
*
19783 get_per_char_metric (f
, font
, char2b
)
19788 static struct font_metrics metrics
;
19789 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19791 if (! font
|| code
== FONT_INVALID_CODE
)
19793 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19798 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19799 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19800 assumed to be zero. */
19803 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19804 struct glyph
*glyph
;
19808 *left
= *right
= 0;
19810 if (glyph
->type
== CHAR_GLYPH
)
19814 struct font_metrics
*pcm
;
19816 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19817 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19819 if (pcm
->rbearing
> pcm
->width
)
19820 *right
= pcm
->rbearing
- pcm
->width
;
19821 if (pcm
->lbearing
< 0)
19822 *left
= -pcm
->lbearing
;
19825 else if (glyph
->type
== COMPOSITE_GLYPH
)
19827 if (! glyph
->u
.cmp
.automatic
)
19829 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
19831 if (cmp
->rbearing
> cmp
->pixel_width
)
19832 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19833 if (cmp
->lbearing
< 0)
19834 *left
= - cmp
->lbearing
;
19838 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
19839 struct font_metrics metrics
;
19841 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
19842 glyph
->u
.cmp
.to
+ 1, &metrics
);
19843 if (metrics
.rbearing
> metrics
.width
)
19844 *right
= metrics
.rbearing
- metrics
.width
;
19845 if (metrics
.lbearing
< 0)
19846 *left
= - metrics
.lbearing
;
19852 /* Return the index of the first glyph preceding glyph string S that
19853 is overwritten by S because of S's left overhang. Value is -1
19854 if no glyphs are overwritten. */
19857 left_overwritten (s
)
19858 struct glyph_string
*s
;
19862 if (s
->left_overhang
)
19865 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19866 int first
= s
->first_glyph
- glyphs
;
19868 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19869 x
-= glyphs
[i
].pixel_width
;
19880 /* Return the index of the first glyph preceding glyph string S that
19881 is overwriting S because of its right overhang. Value is -1 if no
19882 glyph in front of S overwrites S. */
19885 left_overwriting (s
)
19886 struct glyph_string
*s
;
19889 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19890 int first
= s
->first_glyph
- glyphs
;
19894 for (i
= first
- 1; i
>= 0; --i
)
19897 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19900 x
-= glyphs
[i
].pixel_width
;
19907 /* Return the index of the last glyph following glyph string S that is
19908 overwritten by S because of S's right overhang. Value is -1 if
19909 no such glyph is found. */
19912 right_overwritten (s
)
19913 struct glyph_string
*s
;
19917 if (s
->right_overhang
)
19920 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19921 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19922 int end
= s
->row
->used
[s
->area
];
19924 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19925 x
+= glyphs
[i
].pixel_width
;
19934 /* Return the index of the last glyph following glyph string S that
19935 overwrites S because of its left overhang. Value is negative
19936 if no such glyph is found. */
19939 right_overwriting (s
)
19940 struct glyph_string
*s
;
19943 int end
= s
->row
->used
[s
->area
];
19944 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19945 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19949 for (i
= first
; i
< end
; ++i
)
19952 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19955 x
+= glyphs
[i
].pixel_width
;
19962 /* Set background width of glyph string S. START is the index of the
19963 first glyph following S. LAST_X is the right-most x-position + 1
19964 in the drawing area. */
19967 set_glyph_string_background_width (s
, start
, last_x
)
19968 struct glyph_string
*s
;
19972 /* If the face of this glyph string has to be drawn to the end of
19973 the drawing area, set S->extends_to_end_of_line_p. */
19975 if (start
== s
->row
->used
[s
->area
]
19976 && s
->area
== TEXT_AREA
19977 && ((s
->row
->fill_line_p
19978 && (s
->hl
== DRAW_NORMAL_TEXT
19979 || s
->hl
== DRAW_IMAGE_RAISED
19980 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19981 || s
->hl
== DRAW_MOUSE_FACE
))
19982 s
->extends_to_end_of_line_p
= 1;
19984 /* If S extends its face to the end of the line, set its
19985 background_width to the distance to the right edge of the drawing
19987 if (s
->extends_to_end_of_line_p
)
19988 s
->background_width
= last_x
- s
->x
+ 1;
19990 s
->background_width
= s
->width
;
19994 /* Compute overhangs and x-positions for glyph string S and its
19995 predecessors, or successors. X is the starting x-position for S.
19996 BACKWARD_P non-zero means process predecessors. */
19999 compute_overhangs_and_x (s
, x
, backward_p
)
20000 struct glyph_string
*s
;
20008 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20009 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20019 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20020 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20030 /* The following macros are only called from draw_glyphs below.
20031 They reference the following parameters of that function directly:
20032 `w', `row', `area', and `overlap_p'
20033 as well as the following local variables:
20034 `s', `f', and `hdc' (in W32) */
20037 /* On W32, silently add local `hdc' variable to argument list of
20038 init_glyph_string. */
20039 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20040 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20042 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20043 init_glyph_string (s, char2b, w, row, area, start, hl)
20046 /* Add a glyph string for a stretch glyph to the list of strings
20047 between HEAD and TAIL. START is the index of the stretch glyph in
20048 row area AREA of glyph row ROW. END is the index of the last glyph
20049 in that glyph row area. X is the current output position assigned
20050 to the new glyph string constructed. HL overrides that face of the
20051 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20052 is the right-most x-position of the drawing area. */
20054 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20055 and below -- keep them on one line. */
20056 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20059 s = (struct glyph_string *) alloca (sizeof *s); \
20060 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20061 START = fill_stretch_glyph_string (s, row, area, START, END); \
20062 append_glyph_string (&HEAD, &TAIL, s); \
20068 /* Add a glyph string for an image glyph to the list of strings
20069 between HEAD and TAIL. START is the index of the image glyph in
20070 row area AREA of glyph row ROW. END is the index of the last glyph
20071 in that glyph row area. X is the current output position assigned
20072 to the new glyph string constructed. HL overrides that face of the
20073 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20074 is the right-most x-position of the drawing area. */
20076 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20079 s = (struct glyph_string *) alloca (sizeof *s); \
20080 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20081 fill_image_glyph_string (s); \
20082 append_glyph_string (&HEAD, &TAIL, s); \
20089 /* Add a glyph string for a sequence of character glyphs to the list
20090 of strings between HEAD and TAIL. START is the index of the first
20091 glyph in row area AREA of glyph row ROW that is part of the new
20092 glyph string. END is the index of the last glyph in that glyph row
20093 area. X is the current output position assigned to the new glyph
20094 string constructed. HL overrides that face of the glyph; e.g. it
20095 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20096 right-most x-position of the drawing area. */
20098 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20104 face_id = (row)->glyphs[area][START].face_id; \
20106 s = (struct glyph_string *) alloca (sizeof *s); \
20107 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20108 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20109 append_glyph_string (&HEAD, &TAIL, s); \
20111 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20116 /* Add a glyph string for a composite sequence to the list of strings
20117 between HEAD and TAIL. START is the index of the first glyph in
20118 row area AREA of glyph row ROW that is part of the new glyph
20119 string. END is the index of the last glyph in that glyph row area.
20120 X is the current output position assigned to the new glyph string
20121 constructed. HL overrides that face of the glyph; e.g. it is
20122 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20123 x-position of the drawing area. */
20125 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20127 int face_id = (row)->glyphs[area][START].face_id; \
20128 struct face *base_face = FACE_FROM_ID (f, face_id); \
20129 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20130 struct composition *cmp = composition_table[cmp_id]; \
20132 struct glyph_string *first_s; \
20135 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20137 /* Make glyph_strings for each glyph sequence that is drawable by \
20138 the same face, and append them to HEAD/TAIL. */ \
20139 for (n = 0; n < cmp->glyph_len;) \
20141 s = (struct glyph_string *) alloca (sizeof *s); \
20142 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20143 append_glyph_string (&(HEAD), &(TAIL), s); \
20149 n = fill_composite_glyph_string (s, base_face, overlaps); \
20157 /* Add a glyph string for a glyph-string sequence to the list of strings
20158 between HEAD and TAIL. */
20160 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20164 Lisp_Object gstring; \
20166 face_id = (row)->glyphs[area][START].face_id; \
20167 gstring = (composition_gstring_from_id \
20168 ((row)->glyphs[area][START].u.cmp.id)); \
20169 s = (struct glyph_string *) alloca (sizeof *s); \
20170 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20171 * LGSTRING_GLYPH_LEN (gstring)); \
20172 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20173 append_glyph_string (&(HEAD), &(TAIL), s); \
20175 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20179 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20180 of AREA of glyph row ROW on window W between indices START and END.
20181 HL overrides the face for drawing glyph strings, e.g. it is
20182 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20183 x-positions of the drawing area.
20185 This is an ugly monster macro construct because we must use alloca
20186 to allocate glyph strings (because draw_glyphs can be called
20187 asynchronously). */
20189 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20192 HEAD = TAIL = NULL; \
20193 while (START < END) \
20195 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20196 switch (first_glyph->type) \
20199 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20203 case COMPOSITE_GLYPH: \
20204 if (first_glyph->u.cmp.automatic) \
20205 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20208 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20212 case STRETCH_GLYPH: \
20213 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20217 case IMAGE_GLYPH: \
20218 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20228 set_glyph_string_background_width (s, START, LAST_X); \
20235 /* Draw glyphs between START and END in AREA of ROW on window W,
20236 starting at x-position X. X is relative to AREA in W. HL is a
20237 face-override with the following meaning:
20239 DRAW_NORMAL_TEXT draw normally
20240 DRAW_CURSOR draw in cursor face
20241 DRAW_MOUSE_FACE draw in mouse face.
20242 DRAW_INVERSE_VIDEO draw in mode line face
20243 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20244 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20246 If OVERLAPS is non-zero, draw only the foreground of characters and
20247 clip to the physical height of ROW. Non-zero value also defines
20248 the overlapping part to be drawn:
20250 OVERLAPS_PRED overlap with preceding rows
20251 OVERLAPS_SUCC overlap with succeeding rows
20252 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20253 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20255 Value is the x-position reached, relative to AREA of W. */
20258 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20261 struct glyph_row
*row
;
20262 enum glyph_row_area area
;
20263 EMACS_INT start
, end
;
20264 enum draw_glyphs_face hl
;
20267 struct glyph_string
*head
, *tail
;
20268 struct glyph_string
*s
;
20269 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20270 int i
, j
, x_reached
, last_x
, area_left
= 0;
20271 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20274 ALLOCATE_HDC (hdc
, f
);
20276 /* Let's rather be paranoid than getting a SEGV. */
20277 end
= min (end
, row
->used
[area
]);
20278 start
= max (0, start
);
20279 start
= min (end
, start
);
20281 /* Translate X to frame coordinates. Set last_x to the right
20282 end of the drawing area. */
20283 if (row
->full_width_p
)
20285 /* X is relative to the left edge of W, without scroll bars
20287 area_left
= WINDOW_LEFT_EDGE_X (w
);
20288 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20292 area_left
= window_box_left (w
, area
);
20293 last_x
= area_left
+ window_box_width (w
, area
);
20297 /* Build a doubly-linked list of glyph_string structures between
20298 head and tail from what we have to draw. Note that the macro
20299 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20300 the reason we use a separate variable `i'. */
20302 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20304 x_reached
= tail
->x
+ tail
->background_width
;
20308 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20309 the row, redraw some glyphs in front or following the glyph
20310 strings built above. */
20311 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20313 struct glyph_string
*h
, *t
;
20314 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20315 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20318 /* If mouse highlighting is on, we may need to draw adjacent
20319 glyphs using mouse-face highlighting. */
20320 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20322 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20324 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20325 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20327 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20329 check_mouse_face
= 1;
20330 mouse_beg_col
= (row
== mouse_beg_row
)
20331 ? dpyinfo
->mouse_face_beg_col
: 0;
20332 mouse_end_col
= (row
== mouse_end_row
)
20333 ? dpyinfo
->mouse_face_end_col
20334 : row
->used
[TEXT_AREA
];
20338 /* Compute overhangs for all glyph strings. */
20339 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20340 for (s
= head
; s
; s
= s
->next
)
20341 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20343 /* Prepend glyph strings for glyphs in front of the first glyph
20344 string that are overwritten because of the first glyph
20345 string's left overhang. The background of all strings
20346 prepended must be drawn because the first glyph string
20348 i
= left_overwritten (head
);
20351 enum draw_glyphs_face overlap_hl
;
20353 /* If this row contains mouse highlighting, attempt to draw
20354 the overlapped glyphs with the correct highlight. This
20355 code fails if the overlap encompasses more than one glyph
20356 and mouse-highlight spans only some of these glyphs.
20357 However, making it work perfectly involves a lot more
20358 code, and I don't know if the pathological case occurs in
20359 practice, so we'll stick to this for now. --- cyd */
20360 if (check_mouse_face
20361 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20362 overlap_hl
= DRAW_MOUSE_FACE
;
20364 overlap_hl
= DRAW_NORMAL_TEXT
;
20367 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20368 overlap_hl
, dummy_x
, last_x
);
20369 compute_overhangs_and_x (t
, head
->x
, 1);
20370 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20374 /* Prepend glyph strings for glyphs in front of the first glyph
20375 string that overwrite that glyph string because of their
20376 right overhang. For these strings, only the foreground must
20377 be drawn, because it draws over the glyph string at `head'.
20378 The background must not be drawn because this would overwrite
20379 right overhangs of preceding glyphs for which no glyph
20381 i
= left_overwriting (head
);
20384 enum draw_glyphs_face overlap_hl
;
20386 if (check_mouse_face
20387 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20388 overlap_hl
= DRAW_MOUSE_FACE
;
20390 overlap_hl
= DRAW_NORMAL_TEXT
;
20393 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20394 overlap_hl
, dummy_x
, last_x
);
20395 for (s
= h
; s
; s
= s
->next
)
20396 s
->background_filled_p
= 1;
20397 compute_overhangs_and_x (t
, head
->x
, 1);
20398 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20401 /* Append glyphs strings for glyphs following the last glyph
20402 string tail that are overwritten by tail. The background of
20403 these strings has to be drawn because tail's foreground draws
20405 i
= right_overwritten (tail
);
20408 enum draw_glyphs_face overlap_hl
;
20410 if (check_mouse_face
20411 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20412 overlap_hl
= DRAW_MOUSE_FACE
;
20414 overlap_hl
= DRAW_NORMAL_TEXT
;
20416 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20417 overlap_hl
, x
, last_x
);
20418 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20419 append_glyph_string_lists (&head
, &tail
, h
, t
);
20423 /* Append glyph strings for glyphs following the last glyph
20424 string tail that overwrite tail. The foreground of such
20425 glyphs has to be drawn because it writes into the background
20426 of tail. The background must not be drawn because it could
20427 paint over the foreground of following glyphs. */
20428 i
= right_overwriting (tail
);
20431 enum draw_glyphs_face overlap_hl
;
20432 if (check_mouse_face
20433 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20434 overlap_hl
= DRAW_MOUSE_FACE
;
20436 overlap_hl
= DRAW_NORMAL_TEXT
;
20439 i
++; /* We must include the Ith glyph. */
20440 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20441 overlap_hl
, x
, last_x
);
20442 for (s
= h
; s
; s
= s
->next
)
20443 s
->background_filled_p
= 1;
20444 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20445 append_glyph_string_lists (&head
, &tail
, h
, t
);
20447 if (clip_head
|| clip_tail
)
20448 for (s
= head
; s
; s
= s
->next
)
20450 s
->clip_head
= clip_head
;
20451 s
->clip_tail
= clip_tail
;
20455 /* Draw all strings. */
20456 for (s
= head
; s
; s
= s
->next
)
20457 FRAME_RIF (f
)->draw_glyph_string (s
);
20460 /* When focus a sole frame and move horizontally, this sets on_p to 0
20461 causing a failure to erase prev cursor position. */
20462 if (area
== TEXT_AREA
20463 && !row
->full_width_p
20464 /* When drawing overlapping rows, only the glyph strings'
20465 foreground is drawn, which doesn't erase a cursor
20469 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20470 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20471 : (tail
? tail
->x
+ tail
->background_width
: x
));
20475 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20476 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20480 /* Value is the x-position up to which drawn, relative to AREA of W.
20481 This doesn't include parts drawn because of overhangs. */
20482 if (row
->full_width_p
)
20483 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20485 x_reached
-= area_left
;
20487 RELEASE_HDC (hdc
, f
);
20492 /* Expand row matrix if too narrow. Don't expand if area
20495 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20497 if (!fonts_changed_p \
20498 && (it->glyph_row->glyphs[area] \
20499 < it->glyph_row->glyphs[area + 1])) \
20501 it->w->ncols_scale_factor++; \
20502 fonts_changed_p = 1; \
20506 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20507 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20513 struct glyph
*glyph
;
20514 enum glyph_row_area area
= it
->area
;
20516 xassert (it
->glyph_row
);
20517 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20519 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20520 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20522 glyph
->charpos
= CHARPOS (it
->position
);
20523 glyph
->object
= it
->object
;
20524 if (it
->pixel_width
> 0)
20526 glyph
->pixel_width
= it
->pixel_width
;
20527 glyph
->padding_p
= 0;
20531 /* Assure at least 1-pixel width. Otherwise, cursor can't
20532 be displayed correctly. */
20533 glyph
->pixel_width
= 1;
20534 glyph
->padding_p
= 1;
20536 glyph
->ascent
= it
->ascent
;
20537 glyph
->descent
= it
->descent
;
20538 glyph
->voffset
= it
->voffset
;
20539 glyph
->type
= CHAR_GLYPH
;
20540 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20541 glyph
->multibyte_p
= it
->multibyte_p
;
20542 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20543 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20544 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20545 || it
->phys_descent
> it
->descent
);
20546 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20547 glyph
->face_id
= it
->face_id
;
20548 glyph
->u
.ch
= it
->char_to_display
;
20549 glyph
->slice
= null_glyph_slice
;
20550 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20551 ++it
->glyph_row
->used
[area
];
20554 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20557 /* Store one glyph for the composition IT->cmp_it.id in
20558 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
20562 append_composite_glyph (it
)
20565 struct glyph
*glyph
;
20566 enum glyph_row_area area
= it
->area
;
20568 xassert (it
->glyph_row
);
20570 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20571 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20573 glyph
->charpos
= CHARPOS (it
->position
);
20574 glyph
->object
= it
->object
;
20575 glyph
->pixel_width
= it
->pixel_width
;
20576 glyph
->ascent
= it
->ascent
;
20577 glyph
->descent
= it
->descent
;
20578 glyph
->voffset
= it
->voffset
;
20579 glyph
->type
= COMPOSITE_GLYPH
;
20580 if (it
->cmp_it
.ch
< 0)
20582 glyph
->u
.cmp
.automatic
= 0;
20583 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20587 glyph
->u
.cmp
.automatic
= 1;
20588 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20589 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
20590 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
20592 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20593 glyph
->multibyte_p
= it
->multibyte_p
;
20594 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20595 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20596 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20597 || it
->phys_descent
> it
->descent
);
20598 glyph
->padding_p
= 0;
20599 glyph
->glyph_not_available_p
= 0;
20600 glyph
->face_id
= it
->face_id
;
20601 glyph
->slice
= null_glyph_slice
;
20602 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20603 ++it
->glyph_row
->used
[area
];
20606 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20610 /* Change IT->ascent and IT->height according to the setting of
20614 take_vertical_position_into_account (it
)
20619 if (it
->voffset
< 0)
20620 /* Increase the ascent so that we can display the text higher
20622 it
->ascent
-= it
->voffset
;
20624 /* Increase the descent so that we can display the text lower
20626 it
->descent
+= it
->voffset
;
20631 /* Produce glyphs/get display metrics for the image IT is loaded with.
20632 See the description of struct display_iterator in dispextern.h for
20633 an overview of struct display_iterator. */
20636 produce_image_glyph (it
)
20641 int glyph_ascent
, crop
;
20642 struct glyph_slice slice
;
20644 xassert (it
->what
== IT_IMAGE
);
20646 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20648 /* Make sure X resources of the face is loaded. */
20649 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20651 if (it
->image_id
< 0)
20653 /* Fringe bitmap. */
20654 it
->ascent
= it
->phys_ascent
= 0;
20655 it
->descent
= it
->phys_descent
= 0;
20656 it
->pixel_width
= 0;
20661 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20663 /* Make sure X resources of the image is loaded. */
20664 prepare_image_for_display (it
->f
, img
);
20666 slice
.x
= slice
.y
= 0;
20667 slice
.width
= img
->width
;
20668 slice
.height
= img
->height
;
20670 if (INTEGERP (it
->slice
.x
))
20671 slice
.x
= XINT (it
->slice
.x
);
20672 else if (FLOATP (it
->slice
.x
))
20673 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20675 if (INTEGERP (it
->slice
.y
))
20676 slice
.y
= XINT (it
->slice
.y
);
20677 else if (FLOATP (it
->slice
.y
))
20678 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20680 if (INTEGERP (it
->slice
.width
))
20681 slice
.width
= XINT (it
->slice
.width
);
20682 else if (FLOATP (it
->slice
.width
))
20683 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20685 if (INTEGERP (it
->slice
.height
))
20686 slice
.height
= XINT (it
->slice
.height
);
20687 else if (FLOATP (it
->slice
.height
))
20688 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20690 if (slice
.x
>= img
->width
)
20691 slice
.x
= img
->width
;
20692 if (slice
.y
>= img
->height
)
20693 slice
.y
= img
->height
;
20694 if (slice
.x
+ slice
.width
>= img
->width
)
20695 slice
.width
= img
->width
- slice
.x
;
20696 if (slice
.y
+ slice
.height
> img
->height
)
20697 slice
.height
= img
->height
- slice
.y
;
20699 if (slice
.width
== 0 || slice
.height
== 0)
20702 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20704 it
->descent
= slice
.height
- glyph_ascent
;
20706 it
->descent
+= img
->vmargin
;
20707 if (slice
.y
+ slice
.height
== img
->height
)
20708 it
->descent
+= img
->vmargin
;
20709 it
->phys_descent
= it
->descent
;
20711 it
->pixel_width
= slice
.width
;
20713 it
->pixel_width
+= img
->hmargin
;
20714 if (slice
.x
+ slice
.width
== img
->width
)
20715 it
->pixel_width
+= img
->hmargin
;
20717 /* It's quite possible for images to have an ascent greater than
20718 their height, so don't get confused in that case. */
20719 if (it
->descent
< 0)
20724 if (face
->box
!= FACE_NO_BOX
)
20726 if (face
->box_line_width
> 0)
20729 it
->ascent
+= face
->box_line_width
;
20730 if (slice
.y
+ slice
.height
== img
->height
)
20731 it
->descent
+= face
->box_line_width
;
20734 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20735 it
->pixel_width
+= eabs (face
->box_line_width
);
20736 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20737 it
->pixel_width
+= eabs (face
->box_line_width
);
20740 take_vertical_position_into_account (it
);
20742 /* Automatically crop wide image glyphs at right edge so we can
20743 draw the cursor on same display row. */
20744 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20745 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20747 it
->pixel_width
-= crop
;
20748 slice
.width
-= crop
;
20753 struct glyph
*glyph
;
20754 enum glyph_row_area area
= it
->area
;
20756 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20757 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20759 glyph
->charpos
= CHARPOS (it
->position
);
20760 glyph
->object
= it
->object
;
20761 glyph
->pixel_width
= it
->pixel_width
;
20762 glyph
->ascent
= glyph_ascent
;
20763 glyph
->descent
= it
->descent
;
20764 glyph
->voffset
= it
->voffset
;
20765 glyph
->type
= IMAGE_GLYPH
;
20766 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20767 glyph
->multibyte_p
= it
->multibyte_p
;
20768 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20769 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20770 glyph
->overlaps_vertically_p
= 0;
20771 glyph
->padding_p
= 0;
20772 glyph
->glyph_not_available_p
= 0;
20773 glyph
->face_id
= it
->face_id
;
20774 glyph
->u
.img_id
= img
->id
;
20775 glyph
->slice
= slice
;
20776 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20777 ++it
->glyph_row
->used
[area
];
20780 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20785 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20786 of the glyph, WIDTH and HEIGHT are the width and height of the
20787 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20790 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20792 Lisp_Object object
;
20796 struct glyph
*glyph
;
20797 enum glyph_row_area area
= it
->area
;
20799 xassert (ascent
>= 0 && ascent
<= height
);
20801 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20802 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20804 glyph
->charpos
= CHARPOS (it
->position
);
20805 glyph
->object
= object
;
20806 glyph
->pixel_width
= width
;
20807 glyph
->ascent
= ascent
;
20808 glyph
->descent
= height
- ascent
;
20809 glyph
->voffset
= it
->voffset
;
20810 glyph
->type
= STRETCH_GLYPH
;
20811 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20812 glyph
->multibyte_p
= it
->multibyte_p
;
20813 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20814 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20815 glyph
->overlaps_vertically_p
= 0;
20816 glyph
->padding_p
= 0;
20817 glyph
->glyph_not_available_p
= 0;
20818 glyph
->face_id
= it
->face_id
;
20819 glyph
->u
.stretch
.ascent
= ascent
;
20820 glyph
->u
.stretch
.height
= height
;
20821 glyph
->slice
= null_glyph_slice
;
20822 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20823 ++it
->glyph_row
->used
[area
];
20826 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20830 /* Produce a stretch glyph for iterator IT. IT->object is the value
20831 of the glyph property displayed. The value must be a list
20832 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20835 1. `:width WIDTH' specifies that the space should be WIDTH *
20836 canonical char width wide. WIDTH may be an integer or floating
20839 2. `:relative-width FACTOR' specifies that the width of the stretch
20840 should be computed from the width of the first character having the
20841 `glyph' property, and should be FACTOR times that width.
20843 3. `:align-to HPOS' specifies that the space should be wide enough
20844 to reach HPOS, a value in canonical character units.
20846 Exactly one of the above pairs must be present.
20848 4. `:height HEIGHT' specifies that the height of the stretch produced
20849 should be HEIGHT, measured in canonical character units.
20851 5. `:relative-height FACTOR' specifies that the height of the
20852 stretch should be FACTOR times the height of the characters having
20853 the glyph property.
20855 Either none or exactly one of 4 or 5 must be present.
20857 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20858 of the stretch should be used for the ascent of the stretch.
20859 ASCENT must be in the range 0 <= ASCENT <= 100. */
20862 produce_stretch_glyph (it
)
20865 /* (space :width WIDTH :height HEIGHT ...) */
20866 Lisp_Object prop
, plist
;
20867 int width
= 0, height
= 0, align_to
= -1;
20868 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20871 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20872 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20874 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20876 /* List should start with `space'. */
20877 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20878 plist
= XCDR (it
->object
);
20880 /* Compute the width of the stretch. */
20881 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20882 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20884 /* Absolute width `:width WIDTH' specified and valid. */
20885 zero_width_ok_p
= 1;
20888 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20891 /* Relative width `:relative-width FACTOR' specified and valid.
20892 Compute the width of the characters having the `glyph'
20895 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20898 if (it
->multibyte_p
)
20900 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20901 - IT_BYTEPOS (*it
));
20902 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20905 it2
.c
= *p
, it2
.len
= 1;
20907 it2
.glyph_row
= NULL
;
20908 it2
.what
= IT_CHARACTER
;
20909 x_produce_glyphs (&it2
);
20910 width
= NUMVAL (prop
) * it2
.pixel_width
;
20912 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20913 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20915 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20916 align_to
= (align_to
< 0
20918 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20919 else if (align_to
< 0)
20920 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20921 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20922 zero_width_ok_p
= 1;
20925 /* Nothing specified -> width defaults to canonical char width. */
20926 width
= FRAME_COLUMN_WIDTH (it
->f
);
20928 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20931 /* Compute height. */
20932 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20933 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20936 zero_height_ok_p
= 1;
20938 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20940 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20942 height
= FONT_HEIGHT (font
);
20944 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20947 /* Compute percentage of height used for ascent. If
20948 `:ascent ASCENT' is present and valid, use that. Otherwise,
20949 derive the ascent from the font in use. */
20950 if (prop
= Fplist_get (plist
, QCascent
),
20951 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20952 ascent
= height
* NUMVAL (prop
) / 100.0;
20953 else if (!NILP (prop
)
20954 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20955 ascent
= min (max (0, (int)tem
), height
);
20957 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20959 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20960 && it
->current_x
+ width
> it
->last_visible_x
)
20961 width
= it
->last_visible_x
- it
->current_x
- 1;
20963 if (width
> 0 && height
> 0 && it
->glyph_row
)
20965 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20966 if (!STRINGP (object
))
20967 object
= it
->w
->buffer
;
20968 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20971 it
->pixel_width
= width
;
20972 it
->ascent
= it
->phys_ascent
= ascent
;
20973 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20974 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20976 take_vertical_position_into_account (it
);
20979 /* Calculate line-height and line-spacing properties.
20980 An integer value specifies explicit pixel value.
20981 A float value specifies relative value to current face height.
20982 A cons (float . face-name) specifies relative value to
20983 height of specified face font.
20985 Returns height in pixels, or nil. */
20989 calc_line_height_property (it
, val
, font
, boff
, override
)
20993 int boff
, override
;
20995 Lisp_Object face_name
= Qnil
;
20996 int ascent
, descent
, height
;
20998 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21003 face_name
= XCAR (val
);
21005 if (!NUMBERP (val
))
21006 val
= make_number (1);
21007 if (NILP (face_name
))
21009 height
= it
->ascent
+ it
->descent
;
21014 if (NILP (face_name
))
21016 font
= FRAME_FONT (it
->f
);
21017 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21019 else if (EQ (face_name
, Qt
))
21028 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21030 return make_number (-1);
21032 face
= FACE_FROM_ID (it
->f
, face_id
);
21035 return make_number (-1);
21036 boff
= font
->baseline_offset
;
21037 if (font
->vertical_centering
)
21038 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21041 ascent
= FONT_BASE (font
) + boff
;
21042 descent
= FONT_DESCENT (font
) - boff
;
21046 it
->override_ascent
= ascent
;
21047 it
->override_descent
= descent
;
21048 it
->override_boff
= boff
;
21051 height
= ascent
+ descent
;
21055 height
= (int)(XFLOAT_DATA (val
) * height
);
21056 else if (INTEGERP (val
))
21057 height
*= XINT (val
);
21059 return make_number (height
);
21064 Produce glyphs/get display metrics for the display element IT is
21065 loaded with. See the description of struct it in dispextern.h
21066 for an overview of struct it. */
21069 x_produce_glyphs (it
)
21072 int extra_line_spacing
= it
->extra_line_spacing
;
21074 it
->glyph_not_available_p
= 0;
21076 if (it
->what
== IT_CHARACTER
)
21080 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21081 struct font_metrics
*pcm
;
21082 int font_not_found_p
;
21083 int boff
; /* baseline offset */
21084 /* We may change it->multibyte_p upon unibyte<->multibyte
21085 conversion. So, save the current value now and restore it
21088 Note: It seems that we don't have to record multibyte_p in
21089 struct glyph because the character code itself tells if or
21090 not the character is multibyte. Thus, in the future, we must
21091 consider eliminating the field `multibyte_p' in the struct
21093 int saved_multibyte_p
= it
->multibyte_p
;
21095 /* Maybe translate single-byte characters to multibyte, or the
21097 it
->char_to_display
= it
->c
;
21098 if (!ASCII_BYTE_P (it
->c
)
21099 && ! it
->multibyte_p
)
21101 if (SINGLE_BYTE_CHAR_P (it
->c
)
21102 && unibyte_display_via_language_environment
)
21104 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21106 /* get_next_display_element assures that this decoding
21108 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21109 it
->multibyte_p
= 1;
21110 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21112 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21116 /* Get font to use. Encode IT->char_to_display. */
21117 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21118 &char2b
, it
->multibyte_p
, 0);
21121 /* When no suitable font found, use the default font. */
21122 font_not_found_p
= font
== NULL
;
21123 if (font_not_found_p
)
21125 font
= FRAME_FONT (it
->f
);
21126 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21130 boff
= font
->baseline_offset
;
21131 if (font
->vertical_centering
)
21132 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21135 if (it
->char_to_display
>= ' '
21136 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21138 /* Either unibyte or ASCII. */
21143 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21145 if (it
->override_ascent
>= 0)
21147 it
->ascent
= it
->override_ascent
;
21148 it
->descent
= it
->override_descent
;
21149 boff
= it
->override_boff
;
21153 it
->ascent
= FONT_BASE (font
) + boff
;
21154 it
->descent
= FONT_DESCENT (font
) - boff
;
21159 it
->phys_ascent
= pcm
->ascent
+ boff
;
21160 it
->phys_descent
= pcm
->descent
- boff
;
21161 it
->pixel_width
= pcm
->width
;
21165 it
->glyph_not_available_p
= 1;
21166 it
->phys_ascent
= it
->ascent
;
21167 it
->phys_descent
= it
->descent
;
21168 it
->pixel_width
= FONT_WIDTH (font
);
21171 if (it
->constrain_row_ascent_descent_p
)
21173 if (it
->descent
> it
->max_descent
)
21175 it
->ascent
+= it
->descent
- it
->max_descent
;
21176 it
->descent
= it
->max_descent
;
21178 if (it
->ascent
> it
->max_ascent
)
21180 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21181 it
->ascent
= it
->max_ascent
;
21183 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21184 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21185 extra_line_spacing
= 0;
21188 /* If this is a space inside a region of text with
21189 `space-width' property, change its width. */
21190 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21192 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21194 /* If face has a box, add the box thickness to the character
21195 height. If character has a box line to the left and/or
21196 right, add the box line width to the character's width. */
21197 if (face
->box
!= FACE_NO_BOX
)
21199 int thick
= face
->box_line_width
;
21203 it
->ascent
+= thick
;
21204 it
->descent
+= thick
;
21209 if (it
->start_of_box_run_p
)
21210 it
->pixel_width
+= thick
;
21211 if (it
->end_of_box_run_p
)
21212 it
->pixel_width
+= thick
;
21215 /* If face has an overline, add the height of the overline
21216 (1 pixel) and a 1 pixel margin to the character height. */
21217 if (face
->overline_p
)
21218 it
->ascent
+= overline_margin
;
21220 if (it
->constrain_row_ascent_descent_p
)
21222 if (it
->ascent
> it
->max_ascent
)
21223 it
->ascent
= it
->max_ascent
;
21224 if (it
->descent
> it
->max_descent
)
21225 it
->descent
= it
->max_descent
;
21228 take_vertical_position_into_account (it
);
21230 /* If we have to actually produce glyphs, do it. */
21235 /* Translate a space with a `space-width' property
21236 into a stretch glyph. */
21237 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21238 / FONT_HEIGHT (font
));
21239 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21240 it
->ascent
+ it
->descent
, ascent
);
21245 /* If characters with lbearing or rbearing are displayed
21246 in this line, record that fact in a flag of the
21247 glyph row. This is used to optimize X output code. */
21248 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21249 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21251 if (! stretched_p
&& it
->pixel_width
== 0)
21252 /* We assure that all visible glyphs have at least 1-pixel
21254 it
->pixel_width
= 1;
21256 else if (it
->char_to_display
== '\n')
21258 /* A newline has no width but we need the height of the line.
21259 But if previous part of the line set a height, don't
21260 increase that height */
21262 Lisp_Object height
;
21263 Lisp_Object total_height
= Qnil
;
21265 it
->override_ascent
= -1;
21266 it
->pixel_width
= 0;
21269 height
= get_it_property(it
, Qline_height
);
21270 /* Split (line-height total-height) list */
21272 && CONSP (XCDR (height
))
21273 && NILP (XCDR (XCDR (height
))))
21275 total_height
= XCAR (XCDR (height
));
21276 height
= XCAR (height
);
21278 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21280 if (it
->override_ascent
>= 0)
21282 it
->ascent
= it
->override_ascent
;
21283 it
->descent
= it
->override_descent
;
21284 boff
= it
->override_boff
;
21288 it
->ascent
= FONT_BASE (font
) + boff
;
21289 it
->descent
= FONT_DESCENT (font
) - boff
;
21292 if (EQ (height
, Qt
))
21294 if (it
->descent
> it
->max_descent
)
21296 it
->ascent
+= it
->descent
- it
->max_descent
;
21297 it
->descent
= it
->max_descent
;
21299 if (it
->ascent
> it
->max_ascent
)
21301 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21302 it
->ascent
= it
->max_ascent
;
21304 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21305 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21306 it
->constrain_row_ascent_descent_p
= 1;
21307 extra_line_spacing
= 0;
21311 Lisp_Object spacing
;
21313 it
->phys_ascent
= it
->ascent
;
21314 it
->phys_descent
= it
->descent
;
21316 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21317 && face
->box
!= FACE_NO_BOX
21318 && face
->box_line_width
> 0)
21320 it
->ascent
+= face
->box_line_width
;
21321 it
->descent
+= face
->box_line_width
;
21324 && XINT (height
) > it
->ascent
+ it
->descent
)
21325 it
->ascent
= XINT (height
) - it
->descent
;
21327 if (!NILP (total_height
))
21328 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21331 spacing
= get_it_property(it
, Qline_spacing
);
21332 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21334 if (INTEGERP (spacing
))
21336 extra_line_spacing
= XINT (spacing
);
21337 if (!NILP (total_height
))
21338 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21342 else if (it
->char_to_display
== '\t')
21344 if (font
->space_width
> 0)
21346 int tab_width
= it
->tab_width
* font
->space_width
;
21347 int x
= it
->current_x
+ it
->continuation_lines_width
;
21348 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21350 /* If the distance from the current position to the next tab
21351 stop is less than a space character width, use the
21352 tab stop after that. */
21353 if (next_tab_x
- x
< font
->space_width
)
21354 next_tab_x
+= tab_width
;
21356 it
->pixel_width
= next_tab_x
- x
;
21358 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21359 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21363 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21364 it
->ascent
+ it
->descent
, it
->ascent
);
21369 it
->pixel_width
= 0;
21375 /* A multi-byte character. Assume that the display width of the
21376 character is the width of the character multiplied by the
21377 width of the font. */
21379 /* If we found a font, this font should give us the right
21380 metrics. If we didn't find a font, use the frame's
21381 default font and calculate the width of the character by
21382 multiplying the width of font by the width of the
21385 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21387 if (font_not_found_p
|| !pcm
)
21389 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21391 if (char_width
== 0)
21392 /* This is a non spacing character. But, as we are
21393 going to display an empty box, the box must occupy
21394 at least one column. */
21396 it
->glyph_not_available_p
= 1;
21397 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
21398 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21399 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21403 it
->pixel_width
= pcm
->width
;
21404 it
->phys_ascent
= pcm
->ascent
+ boff
;
21405 it
->phys_descent
= pcm
->descent
- boff
;
21407 && (pcm
->lbearing
< 0
21408 || pcm
->rbearing
> pcm
->width
))
21409 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21412 it
->ascent
= FONT_BASE (font
) + boff
;
21413 it
->descent
= FONT_DESCENT (font
) - boff
;
21414 if (face
->box
!= FACE_NO_BOX
)
21416 int thick
= face
->box_line_width
;
21420 it
->ascent
+= thick
;
21421 it
->descent
+= thick
;
21426 if (it
->start_of_box_run_p
)
21427 it
->pixel_width
+= thick
;
21428 if (it
->end_of_box_run_p
)
21429 it
->pixel_width
+= thick
;
21432 /* If face has an overline, add the height of the overline
21433 (1 pixel) and a 1 pixel margin to the character height. */
21434 if (face
->overline_p
)
21435 it
->ascent
+= overline_margin
;
21437 take_vertical_position_into_account (it
);
21439 if (it
->ascent
< 0)
21441 if (it
->descent
< 0)
21446 if (it
->pixel_width
== 0)
21447 /* We assure that all visible glyphs have at least 1-pixel
21449 it
->pixel_width
= 1;
21451 it
->multibyte_p
= saved_multibyte_p
;
21453 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
21455 /* A static compositoin.
21457 Note: A composition is represented as one glyph in the
21458 glyph matrix. There are no padding glyphs.
21460 Important is that pixel_width, ascent, and descent are the
21461 values of what is drawn by draw_glyphs (i.e. the values of
21462 the overall glyphs composed). */
21463 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21464 int boff
; /* baseline offset */
21465 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
21466 int glyph_len
= cmp
->glyph_len
;
21467 struct font
*font
= face
->font
;
21471 /* If we have not yet calculated pixel size data of glyphs of
21472 the composition for the current face font, calculate them
21473 now. Theoretically, we have to check all fonts for the
21474 glyphs, but that requires much time and memory space. So,
21475 here we check only the font of the first glyph. This leads
21476 to incorrect display, but it's very rare, and C-l (recenter)
21477 can correct the display anyway. */
21478 if (! cmp
->font
|| cmp
->font
!= font
)
21480 /* Ascent and descent of the font of the first character
21481 of this composition (adjusted by baseline offset).
21482 Ascent and descent of overall glyphs should not be less
21483 than them respectively. */
21484 int font_ascent
, font_descent
, font_height
;
21485 /* Bounding box of the overall glyphs. */
21486 int leftmost
, rightmost
, lowest
, highest
;
21487 int lbearing
, rbearing
;
21488 int i
, width
, ascent
, descent
;
21489 int left_padded
= 0, right_padded
= 0;
21492 struct font_metrics
*pcm
;
21493 int font_not_found_p
;
21496 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21497 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21499 if (glyph_len
< cmp
->glyph_len
)
21501 for (i
= 0; i
< glyph_len
; i
++)
21503 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21505 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21510 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21511 : IT_CHARPOS (*it
));
21512 /* When no suitable font found, use the default font. */
21513 font_not_found_p
= font
== NULL
;
21514 if (font_not_found_p
)
21516 face
= face
->ascii_face
;
21519 boff
= font
->baseline_offset
;
21520 if (font
->vertical_centering
)
21521 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21522 font_ascent
= FONT_BASE (font
) + boff
;
21523 font_descent
= FONT_DESCENT (font
) - boff
;
21524 font_height
= FONT_HEIGHT (font
);
21526 cmp
->font
= (void *) font
;
21529 if (! font_not_found_p
)
21531 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21532 &char2b
, it
->multibyte_p
, 0);
21533 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21536 /* Initialize the bounding box. */
21539 width
= pcm
->width
;
21540 ascent
= pcm
->ascent
;
21541 descent
= pcm
->descent
;
21542 lbearing
= pcm
->lbearing
;
21543 rbearing
= pcm
->rbearing
;
21547 width
= FONT_WIDTH (font
);
21548 ascent
= FONT_BASE (font
);
21549 descent
= FONT_DESCENT (font
);
21556 lowest
= - descent
+ boff
;
21557 highest
= ascent
+ boff
;
21559 if (! font_not_found_p
21560 && font
->default_ascent
21561 && CHAR_TABLE_P (Vuse_default_ascent
)
21562 && !NILP (Faref (Vuse_default_ascent
,
21563 make_number (it
->char_to_display
))))
21564 highest
= font
->default_ascent
+ boff
;
21566 /* Draw the first glyph at the normal position. It may be
21567 shifted to right later if some other glyphs are drawn
21569 cmp
->offsets
[i
* 2] = 0;
21570 cmp
->offsets
[i
* 2 + 1] = boff
;
21571 cmp
->lbearing
= lbearing
;
21572 cmp
->rbearing
= rbearing
;
21574 /* Set cmp->offsets for the remaining glyphs. */
21575 for (i
++; i
< glyph_len
; i
++)
21577 int left
, right
, btm
, top
;
21578 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21580 struct face
*this_face
;
21585 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21586 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21587 font
= this_face
->font
;
21593 this_boff
= font
->baseline_offset
;
21594 if (font
->vertical_centering
)
21595 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21596 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21597 &char2b
, it
->multibyte_p
, 0);
21598 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21601 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21604 width
= pcm
->width
;
21605 ascent
= pcm
->ascent
;
21606 descent
= pcm
->descent
;
21607 lbearing
= pcm
->lbearing
;
21608 rbearing
= pcm
->rbearing
;
21609 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21611 /* Relative composition with or without
21612 alternate chars. */
21613 left
= (leftmost
+ rightmost
- width
) / 2;
21614 btm
= - descent
+ boff
;
21615 if (font
->relative_compose
21616 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21617 || NILP (Faref (Vignore_relative_composition
,
21618 make_number (ch
)))))
21621 if (- descent
>= font
->relative_compose
)
21622 /* One extra pixel between two glyphs. */
21624 else if (ascent
<= 0)
21625 /* One extra pixel between two glyphs. */
21626 btm
= lowest
- 1 - ascent
- descent
;
21631 /* A composition rule is specified by an integer
21632 value that encodes global and new reference
21633 points (GREF and NREF). GREF and NREF are
21634 specified by numbers as below:
21636 0---1---2 -- ascent
21640 9--10--11 -- center
21642 ---3---4---5--- baseline
21644 6---7---8 -- descent
21646 int rule
= COMPOSITION_RULE (cmp
, i
);
21647 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21649 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21650 grefx
= gref
% 3, nrefx
= nref
% 3;
21651 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21653 xoff
= font_height
* (xoff
- 128) / 256;
21655 yoff
= font_height
* (yoff
- 128) / 256;
21658 + grefx
* (rightmost
- leftmost
) / 2
21659 - nrefx
* width
/ 2
21662 btm
= ((grefy
== 0 ? highest
21664 : grefy
== 2 ? lowest
21665 : (highest
+ lowest
) / 2)
21666 - (nrefy
== 0 ? ascent
+ descent
21667 : nrefy
== 1 ? descent
- boff
21669 : (ascent
+ descent
) / 2)
21673 cmp
->offsets
[i
* 2] = left
;
21674 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21676 /* Update the bounding box of the overall glyphs. */
21679 right
= left
+ width
;
21680 if (left
< leftmost
)
21682 if (right
> rightmost
)
21685 top
= btm
+ descent
+ ascent
;
21691 if (cmp
->lbearing
> left
+ lbearing
)
21692 cmp
->lbearing
= left
+ lbearing
;
21693 if (cmp
->rbearing
< left
+ rbearing
)
21694 cmp
->rbearing
= left
+ rbearing
;
21698 /* If there are glyphs whose x-offsets are negative,
21699 shift all glyphs to the right and make all x-offsets
21703 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21704 cmp
->offsets
[i
* 2] -= leftmost
;
21705 rightmost
-= leftmost
;
21706 cmp
->lbearing
-= leftmost
;
21707 cmp
->rbearing
-= leftmost
;
21710 if (left_padded
&& cmp
->lbearing
< 0)
21712 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21713 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21714 rightmost
-= cmp
->lbearing
;
21715 cmp
->rbearing
-= cmp
->lbearing
;
21718 if (right_padded
&& rightmost
< cmp
->rbearing
)
21720 rightmost
= cmp
->rbearing
;
21723 cmp
->pixel_width
= rightmost
;
21724 cmp
->ascent
= highest
;
21725 cmp
->descent
= - lowest
;
21726 if (cmp
->ascent
< font_ascent
)
21727 cmp
->ascent
= font_ascent
;
21728 if (cmp
->descent
< font_descent
)
21729 cmp
->descent
= font_descent
;
21733 && (cmp
->lbearing
< 0
21734 || cmp
->rbearing
> cmp
->pixel_width
))
21735 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21737 it
->pixel_width
= cmp
->pixel_width
;
21738 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21739 it
->descent
= it
->phys_descent
= cmp
->descent
;
21740 if (face
->box
!= FACE_NO_BOX
)
21742 int thick
= face
->box_line_width
;
21746 it
->ascent
+= thick
;
21747 it
->descent
+= thick
;
21752 if (it
->start_of_box_run_p
)
21753 it
->pixel_width
+= thick
;
21754 if (it
->end_of_box_run_p
)
21755 it
->pixel_width
+= thick
;
21758 /* If face has an overline, add the height of the overline
21759 (1 pixel) and a 1 pixel margin to the character height. */
21760 if (face
->overline_p
)
21761 it
->ascent
+= overline_margin
;
21763 take_vertical_position_into_account (it
);
21764 if (it
->ascent
< 0)
21766 if (it
->descent
< 0)
21770 append_composite_glyph (it
);
21772 else if (it
->what
== IT_COMPOSITION
)
21774 /* A dynamic (automatic) composition. */
21775 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21776 Lisp_Object gstring
;
21777 struct font_metrics metrics
;
21779 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
21781 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
21784 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
21785 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21786 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
21787 it
->descent
= it
->phys_descent
= metrics
.descent
;
21788 if (face
->box
!= FACE_NO_BOX
)
21790 int thick
= face
->box_line_width
;
21794 it
->ascent
+= thick
;
21795 it
->descent
+= thick
;
21800 if (it
->start_of_box_run_p
)
21801 it
->pixel_width
+= thick
;
21802 if (it
->end_of_box_run_p
)
21803 it
->pixel_width
+= thick
;
21805 /* If face has an overline, add the height of the overline
21806 (1 pixel) and a 1 pixel margin to the character height. */
21807 if (face
->overline_p
)
21808 it
->ascent
+= overline_margin
;
21809 take_vertical_position_into_account (it
);
21810 if (it
->ascent
< 0)
21812 if (it
->descent
< 0)
21816 append_composite_glyph (it
);
21818 else if (it
->what
== IT_IMAGE
)
21819 produce_image_glyph (it
);
21820 else if (it
->what
== IT_STRETCH
)
21821 produce_stretch_glyph (it
);
21823 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21824 because this isn't true for images with `:ascent 100'. */
21825 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21826 if (it
->area
== TEXT_AREA
)
21827 it
->current_x
+= it
->pixel_width
;
21829 if (extra_line_spacing
> 0)
21831 it
->descent
+= extra_line_spacing
;
21832 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21833 it
->max_extra_line_spacing
= extra_line_spacing
;
21836 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21837 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21838 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21839 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21843 Output LEN glyphs starting at START at the nominal cursor position.
21844 Advance the nominal cursor over the text. The global variable
21845 updated_window contains the window being updated, updated_row is
21846 the glyph row being updated, and updated_area is the area of that
21847 row being updated. */
21850 x_write_glyphs (start
, len
)
21851 struct glyph
*start
;
21856 xassert (updated_window
&& updated_row
);
21859 /* Write glyphs. */
21861 hpos
= start
- updated_row
->glyphs
[updated_area
];
21862 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21863 updated_row
, updated_area
,
21865 DRAW_NORMAL_TEXT
, 0);
21867 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21868 if (updated_area
== TEXT_AREA
21869 && updated_window
->phys_cursor_on_p
21870 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21871 && updated_window
->phys_cursor
.hpos
>= hpos
21872 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21873 updated_window
->phys_cursor_on_p
= 0;
21877 /* Advance the output cursor. */
21878 output_cursor
.hpos
+= len
;
21879 output_cursor
.x
= x
;
21884 Insert LEN glyphs from START at the nominal cursor position. */
21887 x_insert_glyphs (start
, len
)
21888 struct glyph
*start
;
21893 int line_height
, shift_by_width
, shifted_region_width
;
21894 struct glyph_row
*row
;
21895 struct glyph
*glyph
;
21896 int frame_x
, frame_y
;
21899 xassert (updated_window
&& updated_row
);
21901 w
= updated_window
;
21902 f
= XFRAME (WINDOW_FRAME (w
));
21904 /* Get the height of the line we are in. */
21906 line_height
= row
->height
;
21908 /* Get the width of the glyphs to insert. */
21909 shift_by_width
= 0;
21910 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21911 shift_by_width
+= glyph
->pixel_width
;
21913 /* Get the width of the region to shift right. */
21914 shifted_region_width
= (window_box_width (w
, updated_area
)
21919 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21920 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21922 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21923 line_height
, shift_by_width
);
21925 /* Write the glyphs. */
21926 hpos
= start
- row
->glyphs
[updated_area
];
21927 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21929 DRAW_NORMAL_TEXT
, 0);
21931 /* Advance the output cursor. */
21932 output_cursor
.hpos
+= len
;
21933 output_cursor
.x
+= shift_by_width
;
21939 Erase the current text line from the nominal cursor position
21940 (inclusive) to pixel column TO_X (exclusive). The idea is that
21941 everything from TO_X onward is already erased.
21943 TO_X is a pixel position relative to updated_area of
21944 updated_window. TO_X == -1 means clear to the end of this area. */
21947 x_clear_end_of_line (to_x
)
21951 struct window
*w
= updated_window
;
21952 int max_x
, min_y
, max_y
;
21953 int from_x
, from_y
, to_y
;
21955 xassert (updated_window
&& updated_row
);
21956 f
= XFRAME (w
->frame
);
21958 if (updated_row
->full_width_p
)
21959 max_x
= WINDOW_TOTAL_WIDTH (w
);
21961 max_x
= window_box_width (w
, updated_area
);
21962 max_y
= window_text_bottom_y (w
);
21964 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21965 of window. For TO_X > 0, truncate to end of drawing area. */
21971 to_x
= min (to_x
, max_x
);
21973 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21975 /* Notice if the cursor will be cleared by this operation. */
21976 if (!updated_row
->full_width_p
)
21977 notice_overwritten_cursor (w
, updated_area
,
21978 output_cursor
.x
, -1,
21980 MATRIX_ROW_BOTTOM_Y (updated_row
));
21982 from_x
= output_cursor
.x
;
21984 /* Translate to frame coordinates. */
21985 if (updated_row
->full_width_p
)
21987 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21988 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21992 int area_left
= window_box_left (w
, updated_area
);
21993 from_x
+= area_left
;
21997 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21998 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21999 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22001 /* Prevent inadvertently clearing to end of the X window. */
22002 if (to_x
> from_x
&& to_y
> from_y
)
22005 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22006 to_x
- from_x
, to_y
- from_y
);
22011 #endif /* HAVE_WINDOW_SYSTEM */
22015 /***********************************************************************
22017 ***********************************************************************/
22019 /* Value is the internal representation of the specified cursor type
22020 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22021 of the bar cursor. */
22023 static enum text_cursor_kinds
22024 get_specified_cursor_type (arg
, width
)
22028 enum text_cursor_kinds type
;
22033 if (EQ (arg
, Qbox
))
22034 return FILLED_BOX_CURSOR
;
22036 if (EQ (arg
, Qhollow
))
22037 return HOLLOW_BOX_CURSOR
;
22039 if (EQ (arg
, Qbar
))
22046 && EQ (XCAR (arg
), Qbar
)
22047 && INTEGERP (XCDR (arg
))
22048 && XINT (XCDR (arg
)) >= 0)
22050 *width
= XINT (XCDR (arg
));
22054 if (EQ (arg
, Qhbar
))
22057 return HBAR_CURSOR
;
22061 && EQ (XCAR (arg
), Qhbar
)
22062 && INTEGERP (XCDR (arg
))
22063 && XINT (XCDR (arg
)) >= 0)
22065 *width
= XINT (XCDR (arg
));
22066 return HBAR_CURSOR
;
22069 /* Treat anything unknown as "hollow box cursor".
22070 It was bad to signal an error; people have trouble fixing
22071 .Xdefaults with Emacs, when it has something bad in it. */
22072 type
= HOLLOW_BOX_CURSOR
;
22077 /* Set the default cursor types for specified frame. */
22079 set_frame_cursor_types (f
, arg
)
22086 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22087 FRAME_CURSOR_WIDTH (f
) = width
;
22089 /* By default, set up the blink-off state depending on the on-state. */
22091 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22094 FRAME_BLINK_OFF_CURSOR (f
)
22095 = get_specified_cursor_type (XCDR (tem
), &width
);
22096 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22099 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22103 /* Return the cursor we want to be displayed in window W. Return
22104 width of bar/hbar cursor through WIDTH arg. Return with
22105 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22106 (i.e. if the `system caret' should track this cursor).
22108 In a mini-buffer window, we want the cursor only to appear if we
22109 are reading input from this window. For the selected window, we
22110 want the cursor type given by the frame parameter or buffer local
22111 setting of cursor-type. If explicitly marked off, draw no cursor.
22112 In all other cases, we want a hollow box cursor. */
22114 static enum text_cursor_kinds
22115 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22117 struct glyph
*glyph
;
22119 int *active_cursor
;
22121 struct frame
*f
= XFRAME (w
->frame
);
22122 struct buffer
*b
= XBUFFER (w
->buffer
);
22123 int cursor_type
= DEFAULT_CURSOR
;
22124 Lisp_Object alt_cursor
;
22125 int non_selected
= 0;
22127 *active_cursor
= 1;
22130 if (cursor_in_echo_area
22131 && FRAME_HAS_MINIBUF_P (f
)
22132 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22134 if (w
== XWINDOW (echo_area_window
))
22136 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22138 *width
= FRAME_CURSOR_WIDTH (f
);
22139 return FRAME_DESIRED_CURSOR (f
);
22142 return get_specified_cursor_type (b
->cursor_type
, width
);
22145 *active_cursor
= 0;
22149 /* Detect a nonselected window or nonselected frame. */
22150 else if (w
!= XWINDOW (f
->selected_window
)
22151 #ifdef HAVE_WINDOW_SYSTEM
22152 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22156 *active_cursor
= 0;
22158 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22164 /* Never display a cursor in a window in which cursor-type is nil. */
22165 if (NILP (b
->cursor_type
))
22168 /* Get the normal cursor type for this window. */
22169 if (EQ (b
->cursor_type
, Qt
))
22171 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22172 *width
= FRAME_CURSOR_WIDTH (f
);
22175 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22177 /* Use cursor-in-non-selected-windows instead
22178 for non-selected window or frame. */
22181 alt_cursor
= b
->cursor_in_non_selected_windows
;
22182 if (!EQ (Qt
, alt_cursor
))
22183 return get_specified_cursor_type (alt_cursor
, width
);
22184 /* t means modify the normal cursor type. */
22185 if (cursor_type
== FILLED_BOX_CURSOR
)
22186 cursor_type
= HOLLOW_BOX_CURSOR
;
22187 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22189 return cursor_type
;
22192 /* Use normal cursor if not blinked off. */
22193 if (!w
->cursor_off_p
)
22195 #ifdef HAVE_WINDOW_SYSTEM
22196 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22198 if (cursor_type
== FILLED_BOX_CURSOR
)
22200 /* Using a block cursor on large images can be very annoying.
22201 So use a hollow cursor for "large" images.
22202 If image is not transparent (no mask), also use hollow cursor. */
22203 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22204 if (img
!= NULL
&& IMAGEP (img
->spec
))
22206 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22207 where N = size of default frame font size.
22208 This should cover most of the "tiny" icons people may use. */
22210 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22211 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22212 cursor_type
= HOLLOW_BOX_CURSOR
;
22215 else if (cursor_type
!= NO_CURSOR
)
22217 /* Display current only supports BOX and HOLLOW cursors for images.
22218 So for now, unconditionally use a HOLLOW cursor when cursor is
22219 not a solid box cursor. */
22220 cursor_type
= HOLLOW_BOX_CURSOR
;
22224 return cursor_type
;
22227 /* Cursor is blinked off, so determine how to "toggle" it. */
22229 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22230 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22231 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22233 /* Then see if frame has specified a specific blink off cursor type. */
22234 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22236 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22237 return FRAME_BLINK_OFF_CURSOR (f
);
22241 /* Some people liked having a permanently visible blinking cursor,
22242 while others had very strong opinions against it. So it was
22243 decided to remove it. KFS 2003-09-03 */
22245 /* Finally perform built-in cursor blinking:
22246 filled box <-> hollow box
22247 wide [h]bar <-> narrow [h]bar
22248 narrow [h]bar <-> no cursor
22249 other type <-> no cursor */
22251 if (cursor_type
== FILLED_BOX_CURSOR
)
22252 return HOLLOW_BOX_CURSOR
;
22254 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22257 return cursor_type
;
22265 #ifdef HAVE_WINDOW_SYSTEM
22267 /* Notice when the text cursor of window W has been completely
22268 overwritten by a drawing operation that outputs glyphs in AREA
22269 starting at X0 and ending at X1 in the line starting at Y0 and
22270 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22271 the rest of the line after X0 has been written. Y coordinates
22272 are window-relative. */
22275 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22277 enum glyph_row_area area
;
22278 int x0
, y0
, x1
, y1
;
22280 int cx0
, cx1
, cy0
, cy1
;
22281 struct glyph_row
*row
;
22283 if (!w
->phys_cursor_on_p
)
22285 if (area
!= TEXT_AREA
)
22288 if (w
->phys_cursor
.vpos
< 0
22289 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22290 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22291 !(row
->enabled_p
&& row
->displays_text_p
)))
22294 if (row
->cursor_in_fringe_p
)
22296 row
->cursor_in_fringe_p
= 0;
22297 draw_fringe_bitmap (w
, row
, 0);
22298 w
->phys_cursor_on_p
= 0;
22302 cx0
= w
->phys_cursor
.x
;
22303 cx1
= cx0
+ w
->phys_cursor_width
;
22304 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22307 /* The cursor image will be completely removed from the
22308 screen if the output area intersects the cursor area in
22309 y-direction. When we draw in [y0 y1[, and some part of
22310 the cursor is at y < y0, that part must have been drawn
22311 before. When scrolling, the cursor is erased before
22312 actually scrolling, so we don't come here. When not
22313 scrolling, the rows above the old cursor row must have
22314 changed, and in this case these rows must have written
22315 over the cursor image.
22317 Likewise if part of the cursor is below y1, with the
22318 exception of the cursor being in the first blank row at
22319 the buffer and window end because update_text_area
22320 doesn't draw that row. (Except when it does, but
22321 that's handled in update_text_area.) */
22323 cy0
= w
->phys_cursor
.y
;
22324 cy1
= cy0
+ w
->phys_cursor_height
;
22325 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22328 w
->phys_cursor_on_p
= 0;
22331 #endif /* HAVE_WINDOW_SYSTEM */
22334 /************************************************************************
22336 ************************************************************************/
22338 #ifdef HAVE_WINDOW_SYSTEM
22341 Fix the display of area AREA of overlapping row ROW in window W
22342 with respect to the overlapping part OVERLAPS. */
22345 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22347 struct glyph_row
*row
;
22348 enum glyph_row_area area
;
22356 for (i
= 0; i
< row
->used
[area
];)
22358 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22360 int start
= i
, start_x
= x
;
22364 x
+= row
->glyphs
[area
][i
].pixel_width
;
22367 while (i
< row
->used
[area
]
22368 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22370 draw_glyphs (w
, start_x
, row
, area
,
22372 DRAW_NORMAL_TEXT
, overlaps
);
22376 x
+= row
->glyphs
[area
][i
].pixel_width
;
22386 Draw the cursor glyph of window W in glyph row ROW. See the
22387 comment of draw_glyphs for the meaning of HL. */
22390 draw_phys_cursor_glyph (w
, row
, hl
)
22392 struct glyph_row
*row
;
22393 enum draw_glyphs_face hl
;
22395 /* If cursor hpos is out of bounds, don't draw garbage. This can
22396 happen in mini-buffer windows when switching between echo area
22397 glyphs and mini-buffer. */
22398 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22400 int on_p
= w
->phys_cursor_on_p
;
22402 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22403 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22405 w
->phys_cursor_on_p
= on_p
;
22407 if (hl
== DRAW_CURSOR
)
22408 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22409 /* When we erase the cursor, and ROW is overlapped by other
22410 rows, make sure that these overlapping parts of other rows
22412 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22414 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22416 if (row
> w
->current_matrix
->rows
22417 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22418 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22419 OVERLAPS_ERASED_CURSOR
);
22421 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22422 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22423 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22424 OVERLAPS_ERASED_CURSOR
);
22431 Erase the image of a cursor of window W from the screen. */
22434 erase_phys_cursor (w
)
22437 struct frame
*f
= XFRAME (w
->frame
);
22438 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22439 int hpos
= w
->phys_cursor
.hpos
;
22440 int vpos
= w
->phys_cursor
.vpos
;
22441 int mouse_face_here_p
= 0;
22442 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22443 struct glyph_row
*cursor_row
;
22444 struct glyph
*cursor_glyph
;
22445 enum draw_glyphs_face hl
;
22447 /* No cursor displayed or row invalidated => nothing to do on the
22449 if (w
->phys_cursor_type
== NO_CURSOR
)
22450 goto mark_cursor_off
;
22452 /* VPOS >= active_glyphs->nrows means that window has been resized.
22453 Don't bother to erase the cursor. */
22454 if (vpos
>= active_glyphs
->nrows
)
22455 goto mark_cursor_off
;
22457 /* If row containing cursor is marked invalid, there is nothing we
22459 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22460 if (!cursor_row
->enabled_p
)
22461 goto mark_cursor_off
;
22463 /* If line spacing is > 0, old cursor may only be partially visible in
22464 window after split-window. So adjust visible height. */
22465 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22466 window_text_bottom_y (w
) - cursor_row
->y
);
22468 /* If row is completely invisible, don't attempt to delete a cursor which
22469 isn't there. This can happen if cursor is at top of a window, and
22470 we switch to a buffer with a header line in that window. */
22471 if (cursor_row
->visible_height
<= 0)
22472 goto mark_cursor_off
;
22474 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22475 if (cursor_row
->cursor_in_fringe_p
)
22477 cursor_row
->cursor_in_fringe_p
= 0;
22478 draw_fringe_bitmap (w
, cursor_row
, 0);
22479 goto mark_cursor_off
;
22482 /* This can happen when the new row is shorter than the old one.
22483 In this case, either draw_glyphs or clear_end_of_line
22484 should have cleared the cursor. Note that we wouldn't be
22485 able to erase the cursor in this case because we don't have a
22486 cursor glyph at hand. */
22487 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22488 goto mark_cursor_off
;
22490 /* If the cursor is in the mouse face area, redisplay that when
22491 we clear the cursor. */
22492 if (! NILP (dpyinfo
->mouse_face_window
)
22493 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22494 && (vpos
> dpyinfo
->mouse_face_beg_row
22495 || (vpos
== dpyinfo
->mouse_face_beg_row
22496 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22497 && (vpos
< dpyinfo
->mouse_face_end_row
22498 || (vpos
== dpyinfo
->mouse_face_end_row
22499 && hpos
< dpyinfo
->mouse_face_end_col
))
22500 /* Don't redraw the cursor's spot in mouse face if it is at the
22501 end of a line (on a newline). The cursor appears there, but
22502 mouse highlighting does not. */
22503 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22504 mouse_face_here_p
= 1;
22506 /* Maybe clear the display under the cursor. */
22507 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22510 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22513 cursor_glyph
= get_phys_cursor_glyph (w
);
22514 if (cursor_glyph
== NULL
)
22515 goto mark_cursor_off
;
22517 width
= cursor_glyph
->pixel_width
;
22518 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22519 x
= w
->phys_cursor
.x
;
22521 width
-= left_x
- x
;
22522 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22523 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22524 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22527 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22530 /* Erase the cursor by redrawing the character underneath it. */
22531 if (mouse_face_here_p
)
22532 hl
= DRAW_MOUSE_FACE
;
22534 hl
= DRAW_NORMAL_TEXT
;
22535 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22538 w
->phys_cursor_on_p
= 0;
22539 w
->phys_cursor_type
= NO_CURSOR
;
22544 Display or clear cursor of window W. If ON is zero, clear the
22545 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22546 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22549 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22551 int on
, hpos
, vpos
, x
, y
;
22553 struct frame
*f
= XFRAME (w
->frame
);
22554 int new_cursor_type
;
22555 int new_cursor_width
;
22557 struct glyph_row
*glyph_row
;
22558 struct glyph
*glyph
;
22560 /* This is pointless on invisible frames, and dangerous on garbaged
22561 windows and frames; in the latter case, the frame or window may
22562 be in the midst of changing its size, and x and y may be off the
22564 if (! FRAME_VISIBLE_P (f
)
22565 || FRAME_GARBAGED_P (f
)
22566 || vpos
>= w
->current_matrix
->nrows
22567 || hpos
>= w
->current_matrix
->matrix_w
)
22570 /* If cursor is off and we want it off, return quickly. */
22571 if (!on
&& !w
->phys_cursor_on_p
)
22574 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22575 /* If cursor row is not enabled, we don't really know where to
22576 display the cursor. */
22577 if (!glyph_row
->enabled_p
)
22579 w
->phys_cursor_on_p
= 0;
22584 if (!glyph_row
->exact_window_width_line_p
22585 || hpos
< glyph_row
->used
[TEXT_AREA
])
22586 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22588 xassert (interrupt_input_blocked
);
22590 /* Set new_cursor_type to the cursor we want to be displayed. */
22591 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22592 &new_cursor_width
, &active_cursor
);
22594 /* If cursor is currently being shown and we don't want it to be or
22595 it is in the wrong place, or the cursor type is not what we want,
22597 if (w
->phys_cursor_on_p
22599 || w
->phys_cursor
.x
!= x
22600 || w
->phys_cursor
.y
!= y
22601 || new_cursor_type
!= w
->phys_cursor_type
22602 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22603 && new_cursor_width
!= w
->phys_cursor_width
)))
22604 erase_phys_cursor (w
);
22606 /* Don't check phys_cursor_on_p here because that flag is only set
22607 to zero in some cases where we know that the cursor has been
22608 completely erased, to avoid the extra work of erasing the cursor
22609 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22610 still not be visible, or it has only been partly erased. */
22613 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22614 w
->phys_cursor_height
= glyph_row
->height
;
22616 /* Set phys_cursor_.* before x_draw_.* is called because some
22617 of them may need the information. */
22618 w
->phys_cursor
.x
= x
;
22619 w
->phys_cursor
.y
= glyph_row
->y
;
22620 w
->phys_cursor
.hpos
= hpos
;
22621 w
->phys_cursor
.vpos
= vpos
;
22624 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22625 new_cursor_type
, new_cursor_width
,
22626 on
, active_cursor
);
22630 /* Switch the display of W's cursor on or off, according to the value
22637 update_window_cursor (w
, on
)
22641 /* Don't update cursor in windows whose frame is in the process
22642 of being deleted. */
22643 if (w
->current_matrix
)
22646 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22647 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22653 /* Call update_window_cursor with parameter ON_P on all leaf windows
22654 in the window tree rooted at W. */
22657 update_cursor_in_window_tree (w
, on_p
)
22663 if (!NILP (w
->hchild
))
22664 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22665 else if (!NILP (w
->vchild
))
22666 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22668 update_window_cursor (w
, on_p
);
22670 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22676 Display the cursor on window W, or clear it, according to ON_P.
22677 Don't change the cursor's position. */
22680 x_update_cursor (f
, on_p
)
22684 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22689 Clear the cursor of window W to background color, and mark the
22690 cursor as not shown. This is used when the text where the cursor
22691 is is about to be rewritten. */
22697 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22698 update_window_cursor (w
, 0);
22703 Display the active region described by mouse_face_* according to DRAW. */
22706 show_mouse_face (dpyinfo
, draw
)
22707 Display_Info
*dpyinfo
;
22708 enum draw_glyphs_face draw
;
22710 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22711 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22713 if (/* If window is in the process of being destroyed, don't bother
22715 w
->current_matrix
!= NULL
22716 /* Don't update mouse highlight if hidden */
22717 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22718 /* Recognize when we are called to operate on rows that don't exist
22719 anymore. This can happen when a window is split. */
22720 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22722 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22723 struct glyph_row
*row
, *first
, *last
;
22725 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22726 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22728 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22730 int start_hpos
, end_hpos
, start_x
;
22732 /* For all but the first row, the highlight starts at column 0. */
22735 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22736 start_x
= dpyinfo
->mouse_face_beg_x
;
22745 end_hpos
= dpyinfo
->mouse_face_end_col
;
22748 end_hpos
= row
->used
[TEXT_AREA
];
22749 if (draw
== DRAW_NORMAL_TEXT
)
22750 row
->fill_line_p
= 1; /* Clear to end of line */
22753 if (end_hpos
> start_hpos
)
22755 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22756 start_hpos
, end_hpos
,
22760 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22764 /* When we've written over the cursor, arrange for it to
22765 be displayed again. */
22766 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22769 display_and_set_cursor (w
, 1,
22770 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22771 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22776 /* Change the mouse cursor. */
22777 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22778 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22779 else if (draw
== DRAW_MOUSE_FACE
)
22780 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22782 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22786 Clear out the mouse-highlighted active region.
22787 Redraw it un-highlighted first. Value is non-zero if mouse
22788 face was actually drawn unhighlighted. */
22791 clear_mouse_face (dpyinfo
)
22792 Display_Info
*dpyinfo
;
22796 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22798 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22802 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22803 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22804 dpyinfo
->mouse_face_window
= Qnil
;
22805 dpyinfo
->mouse_face_overlay
= Qnil
;
22811 Non-zero if physical cursor of window W is within mouse face. */
22814 cursor_in_mouse_face_p (w
)
22817 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22818 int in_mouse_face
= 0;
22820 if (WINDOWP (dpyinfo
->mouse_face_window
)
22821 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22823 int hpos
= w
->phys_cursor
.hpos
;
22824 int vpos
= w
->phys_cursor
.vpos
;
22826 if (vpos
>= dpyinfo
->mouse_face_beg_row
22827 && vpos
<= dpyinfo
->mouse_face_end_row
22828 && (vpos
> dpyinfo
->mouse_face_beg_row
22829 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22830 && (vpos
< dpyinfo
->mouse_face_end_row
22831 || hpos
< dpyinfo
->mouse_face_end_col
22832 || dpyinfo
->mouse_face_past_end
))
22836 return in_mouse_face
;
22842 /* This function sets the mouse_face_* elements of DPYINFO, assuming
22843 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
22844 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
22845 for the overlay or run of text properties specifying the mouse
22846 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
22847 before-string and after-string that must also be highlighted.
22848 DISPLAY_STRING, if non-nil, is a display string that may cover some
22849 or all of the highlighted text. */
22852 mouse_face_from_buffer_pos (Lisp_Object window
,
22853 Display_Info
*dpyinfo
,
22854 EMACS_INT mouse_charpos
,
22855 EMACS_INT start_charpos
,
22856 EMACS_INT end_charpos
,
22857 Lisp_Object before_string
,
22858 Lisp_Object after_string
,
22859 Lisp_Object display_string
)
22861 struct window
*w
= XWINDOW (window
);
22862 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22863 struct glyph_row
*row
;
22864 struct glyph
*glyph
, *end
;
22868 xassert (NILP (display_string
) || STRINGP (display_string
));
22869 xassert (NILP (before_string
) || STRINGP (before_string
));
22870 xassert (NILP (after_string
) || STRINGP (after_string
));
22872 /* Find the first highlighted glyph. */
22873 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
22875 dpyinfo
->mouse_face_beg_col
= 0;
22876 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22877 dpyinfo
->mouse_face_beg_x
= first
->x
;
22878 dpyinfo
->mouse_face_beg_y
= first
->y
;
22882 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
22884 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22886 /* If the before-string or display-string contains newlines,
22887 row_containing_pos skips to its last row. Move back. */
22888 if (!NILP (before_string
) || !NILP (display_string
))
22890 struct glyph_row
*prev
;
22891 while ((prev
= row
- 1, prev
>= first
)
22892 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
22893 && prev
->used
[TEXT_AREA
] > 0)
22895 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22896 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22897 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
22899 || !(EQ (glyph
->object
, before_string
)
22900 || EQ (glyph
->object
, display_string
)))
22906 glyph
= row
->glyphs
[TEXT_AREA
];
22907 end
= glyph
+ row
->used
[TEXT_AREA
];
22909 dpyinfo
->mouse_face_beg_y
= row
->y
;
22910 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22912 /* Skip truncation glyphs at the start of the glyph row. */
22913 if (row
->displays_text_p
)
22915 && INTEGERP (glyph
->object
)
22916 && glyph
->charpos
< 0;
22918 x
+= glyph
->pixel_width
;
22920 /* Scan the glyph row, stopping before BEFORE_STRING or
22921 DISPLAY_STRING or START_CHARPOS. */
22923 && !INTEGERP (glyph
->object
)
22924 && !EQ (glyph
->object
, before_string
)
22925 && !EQ (glyph
->object
, display_string
)
22926 && !(BUFFERP (glyph
->object
)
22927 && glyph
->charpos
>= start_charpos
);
22929 x
+= glyph
->pixel_width
;
22931 dpyinfo
->mouse_face_beg_x
= x
;
22932 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22935 /* Find the last highlighted glyph. */
22936 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
22939 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22940 dpyinfo
->mouse_face_past_end
= 1;
22942 else if (!NILP (after_string
))
22944 /* If the after-string has newlines, advance to its last row. */
22945 struct glyph_row
*next
;
22946 struct glyph_row
*last
22947 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22949 for (next
= row
+ 1;
22951 && next
->used
[TEXT_AREA
] > 0
22952 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
22957 glyph
= row
->glyphs
[TEXT_AREA
];
22958 end
= glyph
+ row
->used
[TEXT_AREA
];
22960 dpyinfo
->mouse_face_end_y
= row
->y
;
22961 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22963 /* Skip truncation glyphs at the start of the row. */
22964 if (row
->displays_text_p
)
22966 && INTEGERP (glyph
->object
)
22967 && glyph
->charpos
< 0;
22969 x
+= glyph
->pixel_width
;
22971 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
22974 && !INTEGERP (glyph
->object
)
22975 && !EQ (glyph
->object
, after_string
)
22976 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
22978 x
+= glyph
->pixel_width
;
22980 /* If we found AFTER_STRING, consume it and stop. */
22981 if (EQ (glyph
->object
, after_string
))
22983 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
22984 x
+= glyph
->pixel_width
;
22988 /* If there's no after-string, we must check if we overshot,
22989 which might be the case if we stopped after a string glyph.
22990 That glyph may belong to a before-string or display-string
22991 associated with the end position, which must not be
22993 Lisp_Object prev_object
;
22996 while (glyph
> row
->glyphs
[TEXT_AREA
])
22998 prev_object
= (glyph
- 1)->object
;
22999 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23002 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23003 if (pos
&& pos
< end_charpos
)
23006 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23007 && EQ ((glyph
- 1)->object
, prev_object
);
23009 x
-= (glyph
- 1)->pixel_width
;
23013 dpyinfo
->mouse_face_end_x
= x
;
23014 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23015 dpyinfo
->mouse_face_window
= window
;
23016 dpyinfo
->mouse_face_face_id
23017 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23019 !dpyinfo
->mouse_face_hidden
, -1);
23020 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23024 /* Find the position of the glyph for position POS in OBJECT in
23025 window W's current matrix, and return in *X, *Y the pixel
23026 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23028 RIGHT_P non-zero means return the position of the right edge of the
23029 glyph, RIGHT_P zero means return the left edge position.
23031 If no glyph for POS exists in the matrix, return the position of
23032 the glyph with the next smaller position that is in the matrix, if
23033 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23034 exists in the matrix, return the position of the glyph with the
23035 next larger position in OBJECT.
23037 Value is non-zero if a glyph was found. */
23040 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23043 Lisp_Object object
;
23044 int *hpos
, *vpos
, *x
, *y
;
23047 int yb
= window_text_bottom_y (w
);
23048 struct glyph_row
*r
;
23049 struct glyph
*best_glyph
= NULL
;
23050 struct glyph_row
*best_row
= NULL
;
23053 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23054 r
->enabled_p
&& r
->y
< yb
;
23057 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23058 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23061 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23062 if (EQ (g
->object
, object
))
23064 if (g
->charpos
== pos
)
23071 else if (best_glyph
== NULL
23072 || ((eabs (g
->charpos
- pos
)
23073 < eabs (best_glyph
->charpos
- pos
))
23076 : g
->charpos
> pos
)))
23090 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23094 *x
+= best_glyph
->pixel_width
;
23099 *vpos
= best_row
- w
->current_matrix
->rows
;
23102 return best_glyph
!= NULL
;
23106 /* See if position X, Y is within a hot-spot of an image. */
23109 on_hot_spot_p (hot_spot
, x
, y
)
23110 Lisp_Object hot_spot
;
23113 if (!CONSP (hot_spot
))
23116 if (EQ (XCAR (hot_spot
), Qrect
))
23118 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23119 Lisp_Object rect
= XCDR (hot_spot
);
23123 if (!CONSP (XCAR (rect
)))
23125 if (!CONSP (XCDR (rect
)))
23127 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23129 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23131 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23133 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23137 else if (EQ (XCAR (hot_spot
), Qcircle
))
23139 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23140 Lisp_Object circ
= XCDR (hot_spot
);
23141 Lisp_Object lr
, lx0
, ly0
;
23143 && CONSP (XCAR (circ
))
23144 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23145 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23146 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23148 double r
= XFLOATINT (lr
);
23149 double dx
= XINT (lx0
) - x
;
23150 double dy
= XINT (ly0
) - y
;
23151 return (dx
* dx
+ dy
* dy
<= r
* r
);
23154 else if (EQ (XCAR (hot_spot
), Qpoly
))
23156 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23157 if (VECTORP (XCDR (hot_spot
)))
23159 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23160 Lisp_Object
*poly
= v
->contents
;
23164 Lisp_Object lx
, ly
;
23167 /* Need an even number of coordinates, and at least 3 edges. */
23168 if (n
< 6 || n
& 1)
23171 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23172 If count is odd, we are inside polygon. Pixels on edges
23173 may or may not be included depending on actual geometry of the
23175 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23176 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23178 x0
= XINT (lx
), y0
= XINT (ly
);
23179 for (i
= 0; i
< n
; i
+= 2)
23181 int x1
= x0
, y1
= y0
;
23182 if ((lx
= poly
[i
], !INTEGERP (lx
))
23183 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23185 x0
= XINT (lx
), y0
= XINT (ly
);
23187 /* Does this segment cross the X line? */
23195 if (y
> y0
&& y
> y1
)
23197 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23207 find_hot_spot (map
, x
, y
)
23211 while (CONSP (map
))
23213 if (CONSP (XCAR (map
))
23214 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23222 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23224 doc
: /* Lookup in image map MAP coordinates X and Y.
23225 An image map is an alist where each element has the format (AREA ID PLIST).
23226 An AREA is specified as either a rectangle, a circle, or a polygon:
23227 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23228 pixel coordinates of the upper left and bottom right corners.
23229 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23230 and the radius of the circle; r may be a float or integer.
23231 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23232 vector describes one corner in the polygon.
23233 Returns the alist element for the first matching AREA in MAP. */)
23244 return find_hot_spot (map
, XINT (x
), XINT (y
));
23248 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23250 define_frame_cursor1 (f
, cursor
, pointer
)
23253 Lisp_Object pointer
;
23255 /* Do not change cursor shape while dragging mouse. */
23256 if (!NILP (do_mouse_tracking
))
23259 if (!NILP (pointer
))
23261 if (EQ (pointer
, Qarrow
))
23262 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23263 else if (EQ (pointer
, Qhand
))
23264 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23265 else if (EQ (pointer
, Qtext
))
23266 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23267 else if (EQ (pointer
, intern ("hdrag")))
23268 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23269 #ifdef HAVE_X_WINDOWS
23270 else if (EQ (pointer
, intern ("vdrag")))
23271 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23273 else if (EQ (pointer
, intern ("hourglass")))
23274 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23275 else if (EQ (pointer
, Qmodeline
))
23276 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23278 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23281 if (cursor
!= No_Cursor
)
23282 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23285 /* Take proper action when mouse has moved to the mode or header line
23286 or marginal area AREA of window W, x-position X and y-position Y.
23287 X is relative to the start of the text display area of W, so the
23288 width of bitmap areas and scroll bars must be subtracted to get a
23289 position relative to the start of the mode line. */
23292 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23293 Lisp_Object window
;
23295 enum window_part area
;
23297 struct window
*w
= XWINDOW (window
);
23298 struct frame
*f
= XFRAME (w
->frame
);
23299 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23300 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23301 Lisp_Object pointer
= Qnil
;
23302 int charpos
, dx
, dy
, width
, height
;
23303 Lisp_Object string
, object
= Qnil
;
23304 Lisp_Object pos
, help
;
23306 Lisp_Object mouse_face
;
23307 int original_x_pixel
= x
;
23308 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23309 struct glyph_row
*row
;
23311 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23316 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23317 &object
, &dx
, &dy
, &width
, &height
);
23319 row
= (area
== ON_MODE_LINE
23320 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23321 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23324 if (row
->mode_line_p
&& row
->enabled_p
)
23326 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23327 end
= glyph
+ row
->used
[TEXT_AREA
];
23329 for (x0
= original_x_pixel
;
23330 glyph
< end
&& x0
>= glyph
->pixel_width
;
23332 x0
-= glyph
->pixel_width
;
23340 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23341 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23342 &object
, &dx
, &dy
, &width
, &height
);
23347 if (IMAGEP (object
))
23349 Lisp_Object image_map
, hotspot
;
23350 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23352 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23354 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23356 Lisp_Object area_id
, plist
;
23358 area_id
= XCAR (hotspot
);
23359 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23360 If so, we could look for mouse-enter, mouse-leave
23361 properties in PLIST (and do something...). */
23362 hotspot
= XCDR (hotspot
);
23363 if (CONSP (hotspot
)
23364 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23366 pointer
= Fplist_get (plist
, Qpointer
);
23367 if (NILP (pointer
))
23369 help
= Fplist_get (plist
, Qhelp_echo
);
23372 help_echo_string
= help
;
23373 /* Is this correct? ++kfs */
23374 XSETWINDOW (help_echo_window
, w
);
23375 help_echo_object
= w
->buffer
;
23376 help_echo_pos
= charpos
;
23380 if (NILP (pointer
))
23381 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23384 if (STRINGP (string
))
23386 pos
= make_number (charpos
);
23387 /* If we're on a string with `help-echo' text property, arrange
23388 for the help to be displayed. This is done by setting the
23389 global variable help_echo_string to the help string. */
23392 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23395 help_echo_string
= help
;
23396 XSETWINDOW (help_echo_window
, w
);
23397 help_echo_object
= string
;
23398 help_echo_pos
= charpos
;
23402 if (NILP (pointer
))
23403 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23405 /* Change the mouse pointer according to what is under X/Y. */
23406 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23409 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23410 if (!KEYMAPP (map
))
23411 map
= Fget_text_property (pos
, Qkeymap
, string
);
23412 if (!KEYMAPP (map
))
23413 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23416 /* Change the mouse face according to what is under X/Y. */
23417 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23418 if (!NILP (mouse_face
)
23419 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23424 struct glyph
* tmp_glyph
;
23428 int total_pixel_width
;
23433 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23434 Qmouse_face
, string
, Qnil
);
23436 b
= make_number (0);
23438 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23440 e
= make_number (SCHARS (string
));
23442 /* Calculate the position(glyph position: GPOS) of GLYPH in
23443 displayed string. GPOS is different from CHARPOS.
23445 CHARPOS is the position of glyph in internal string
23446 object. A mode line string format has structures which
23447 is converted to a flatten by emacs lisp interpreter.
23448 The internal string is an element of the structures.
23449 The displayed string is the flatten string. */
23451 if (glyph
> row_start_glyph
)
23453 tmp_glyph
= glyph
- 1;
23454 while (tmp_glyph
>= row_start_glyph
23455 && tmp_glyph
->charpos
>= XINT (b
)
23456 && EQ (tmp_glyph
->object
, glyph
->object
))
23463 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23464 displayed string holding GLYPH.
23466 GSEQ_LENGTH is different from SCHARS (STRING).
23467 SCHARS (STRING) returns the length of the internal string. */
23468 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23469 tmp_glyph
->charpos
< XINT (e
);
23470 tmp_glyph
++, gseq_length
++)
23472 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23476 total_pixel_width
= 0;
23477 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23478 total_pixel_width
+= tmp_glyph
->pixel_width
;
23480 /* Pre calculation of re-rendering position */
23482 hpos
= (area
== ON_MODE_LINE
23483 ? (w
->current_matrix
)->nrows
- 1
23486 /* If the re-rendering position is included in the last
23487 re-rendering area, we should do nothing. */
23488 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23489 && dpyinfo
->mouse_face_beg_col
<= vpos
23490 && vpos
< dpyinfo
->mouse_face_end_col
23491 && dpyinfo
->mouse_face_beg_row
== hpos
)
23494 if (clear_mouse_face (dpyinfo
))
23495 cursor
= No_Cursor
;
23497 dpyinfo
->mouse_face_beg_col
= vpos
;
23498 dpyinfo
->mouse_face_beg_row
= hpos
;
23500 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23501 dpyinfo
->mouse_face_beg_y
= 0;
23503 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23504 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23506 dpyinfo
->mouse_face_end_x
= 0;
23507 dpyinfo
->mouse_face_end_y
= 0;
23509 dpyinfo
->mouse_face_past_end
= 0;
23510 dpyinfo
->mouse_face_window
= window
;
23512 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23515 glyph
->face_id
, 1);
23516 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23518 if (NILP (pointer
))
23521 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23522 clear_mouse_face (dpyinfo
);
23524 define_frame_cursor1 (f
, cursor
, pointer
);
23529 Take proper action when the mouse has moved to position X, Y on
23530 frame F as regards highlighting characters that have mouse-face
23531 properties. Also de-highlighting chars where the mouse was before.
23532 X and Y can be negative or out of range. */
23535 note_mouse_highlight (f
, x
, y
)
23539 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23540 enum window_part part
;
23541 Lisp_Object window
;
23543 Cursor cursor
= No_Cursor
;
23544 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23547 /* When a menu is active, don't highlight because this looks odd. */
23548 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23549 if (popup_activated ())
23553 if (NILP (Vmouse_highlight
)
23554 || !f
->glyphs_initialized_p
)
23557 dpyinfo
->mouse_face_mouse_x
= x
;
23558 dpyinfo
->mouse_face_mouse_y
= y
;
23559 dpyinfo
->mouse_face_mouse_frame
= f
;
23561 if (dpyinfo
->mouse_face_defer
)
23564 if (gc_in_progress
)
23566 dpyinfo
->mouse_face_deferred_gc
= 1;
23570 /* Which window is that in? */
23571 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23573 /* If we were displaying active text in another window, clear that.
23574 Also clear if we move out of text area in same window. */
23575 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23576 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23577 && !NILP (dpyinfo
->mouse_face_window
)))
23578 clear_mouse_face (dpyinfo
);
23580 /* Not on a window -> return. */
23581 if (!WINDOWP (window
))
23584 /* Reset help_echo_string. It will get recomputed below. */
23585 help_echo_string
= Qnil
;
23587 /* Convert to window-relative pixel coordinates. */
23588 w
= XWINDOW (window
);
23589 frame_to_window_pixel_xy (w
, &x
, &y
);
23591 /* Handle tool-bar window differently since it doesn't display a
23593 if (EQ (window
, f
->tool_bar_window
))
23595 note_tool_bar_highlight (f
, x
, y
);
23599 /* Mouse is on the mode, header line or margin? */
23600 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23601 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23603 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23607 if (part
== ON_VERTICAL_BORDER
)
23609 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23610 help_echo_string
= build_string ("drag-mouse-1: resize");
23612 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23613 || part
== ON_SCROLL_BAR
)
23614 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23616 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23618 /* Are we in a window whose display is up to date?
23619 And verify the buffer's text has not changed. */
23620 b
= XBUFFER (w
->buffer
);
23621 if (part
== ON_TEXT
23622 && EQ (w
->window_end_valid
, w
->buffer
)
23623 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23624 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23626 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23627 struct glyph
*glyph
;
23628 Lisp_Object object
;
23629 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23630 Lisp_Object
*overlay_vec
= NULL
;
23632 struct buffer
*obuf
;
23633 int obegv
, ozv
, same_region
;
23635 /* Find the glyph under X/Y. */
23636 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23638 /* Look for :pointer property on image. */
23639 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23641 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23642 if (img
!= NULL
&& IMAGEP (img
->spec
))
23644 Lisp_Object image_map
, hotspot
;
23645 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23647 && (hotspot
= find_hot_spot (image_map
,
23648 glyph
->slice
.x
+ dx
,
23649 glyph
->slice
.y
+ dy
),
23651 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23653 Lisp_Object area_id
, plist
;
23655 area_id
= XCAR (hotspot
);
23656 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23657 If so, we could look for mouse-enter, mouse-leave
23658 properties in PLIST (and do something...). */
23659 hotspot
= XCDR (hotspot
);
23660 if (CONSP (hotspot
)
23661 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23663 pointer
= Fplist_get (plist
, Qpointer
);
23664 if (NILP (pointer
))
23666 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23667 if (!NILP (help_echo_string
))
23669 help_echo_window
= window
;
23670 help_echo_object
= glyph
->object
;
23671 help_echo_pos
= glyph
->charpos
;
23675 if (NILP (pointer
))
23676 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23680 /* Clear mouse face if X/Y not over text. */
23682 || area
!= TEXT_AREA
23683 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23685 if (clear_mouse_face (dpyinfo
))
23686 cursor
= No_Cursor
;
23687 if (NILP (pointer
))
23689 if (area
!= TEXT_AREA
)
23690 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23692 pointer
= Vvoid_text_area_pointer
;
23697 pos
= glyph
->charpos
;
23698 object
= glyph
->object
;
23699 if (!STRINGP (object
) && !BUFFERP (object
))
23702 /* If we get an out-of-range value, return now; avoid an error. */
23703 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23706 /* Make the window's buffer temporarily current for
23707 overlays_at and compute_char_face. */
23708 obuf
= current_buffer
;
23709 current_buffer
= b
;
23715 /* Is this char mouse-active or does it have help-echo? */
23716 position
= make_number (pos
);
23718 if (BUFFERP (object
))
23720 /* Put all the overlays we want in a vector in overlay_vec. */
23721 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23722 /* Sort overlays into increasing priority order. */
23723 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23728 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23729 && vpos
>= dpyinfo
->mouse_face_beg_row
23730 && vpos
<= dpyinfo
->mouse_face_end_row
23731 && (vpos
> dpyinfo
->mouse_face_beg_row
23732 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23733 && (vpos
< dpyinfo
->mouse_face_end_row
23734 || hpos
< dpyinfo
->mouse_face_end_col
23735 || dpyinfo
->mouse_face_past_end
));
23738 cursor
= No_Cursor
;
23740 /* Check mouse-face highlighting. */
23742 /* If there exists an overlay with mouse-face overlapping
23743 the one we are currently highlighting, we have to
23744 check if we enter the overlapping overlay, and then
23745 highlight only that. */
23746 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23747 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23749 /* Find the highest priority overlay with a mouse-face. */
23751 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23753 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23754 if (!NILP (mouse_face
))
23755 overlay
= overlay_vec
[i
];
23758 /* If we're highlighting the same overlay as before, there's
23759 no need to do that again. */
23760 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23761 goto check_help_echo
;
23762 dpyinfo
->mouse_face_overlay
= overlay
;
23764 /* Clear the display of the old active region, if any. */
23765 if (clear_mouse_face (dpyinfo
))
23766 cursor
= No_Cursor
;
23768 /* If no overlay applies, get a text property. */
23769 if (NILP (overlay
))
23770 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23772 /* Next, compute the bounds of the mouse highlighting and
23774 if (!NILP (mouse_face
) && STRINGP (object
))
23776 /* The mouse-highlighting comes from a display string
23777 with a mouse-face. */
23781 b
= Fprevious_single_property_change
23782 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
23783 e
= Fnext_single_property_change
23784 (position
, Qmouse_face
, object
, Qnil
);
23786 b
= make_number (0);
23788 e
= make_number (SCHARS (object
) - 1);
23790 fast_find_string_pos (w
, XINT (b
), object
,
23791 &dpyinfo
->mouse_face_beg_col
,
23792 &dpyinfo
->mouse_face_beg_row
,
23793 &dpyinfo
->mouse_face_beg_x
,
23794 &dpyinfo
->mouse_face_beg_y
, 0);
23795 fast_find_string_pos (w
, XINT (e
), object
,
23796 &dpyinfo
->mouse_face_end_col
,
23797 &dpyinfo
->mouse_face_end_row
,
23798 &dpyinfo
->mouse_face_end_x
,
23799 &dpyinfo
->mouse_face_end_y
, 1);
23800 dpyinfo
->mouse_face_past_end
= 0;
23801 dpyinfo
->mouse_face_window
= window
;
23802 dpyinfo
->mouse_face_face_id
23803 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23804 glyph
->face_id
, 1);
23805 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23806 cursor
= No_Cursor
;
23810 /* The mouse-highlighting, if any, comes from an overlay
23811 or text property in the buffer. */
23812 Lisp_Object buffer
, display_string
;
23814 if (STRINGP (object
))
23816 /* If we are on a display string with no mouse-face,
23817 check if the text under it has one. */
23818 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23819 int start
= MATRIX_ROW_START_CHARPOS (r
);
23820 pos
= string_buffer_position (w
, object
, start
);
23823 mouse_face
= get_char_property_and_overlay
23824 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
23825 buffer
= w
->buffer
;
23826 display_string
= object
;
23832 display_string
= Qnil
;
23835 if (!NILP (mouse_face
))
23837 Lisp_Object before
, after
;
23838 Lisp_Object before_string
, after_string
;
23840 if (NILP (overlay
))
23842 /* Handle the text property case. */
23843 before
= Fprevious_single_property_change
23844 (make_number (pos
+ 1), Qmouse_face
, buffer
,
23845 Fmarker_position (w
->start
));
23846 after
= Fnext_single_property_change
23847 (make_number (pos
), Qmouse_face
, buffer
,
23848 make_number (BUF_Z (XBUFFER (buffer
))
23849 - XFASTINT (w
->window_end_pos
)));
23850 before_string
= after_string
= Qnil
;
23854 /* Handle the overlay case. */
23855 before
= Foverlay_start (overlay
);
23856 after
= Foverlay_end (overlay
);
23857 before_string
= Foverlay_get (overlay
, Qbefore_string
);
23858 after_string
= Foverlay_get (overlay
, Qafter_string
);
23860 if (!STRINGP (before_string
)) before_string
= Qnil
;
23861 if (!STRINGP (after_string
)) after_string
= Qnil
;
23864 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
23867 before_string
, after_string
,
23869 cursor
= No_Cursor
;
23876 /* Look for a `help-echo' property. */
23877 if (NILP (help_echo_string
)) {
23878 Lisp_Object help
, overlay
;
23880 /* Check overlays first. */
23881 help
= overlay
= Qnil
;
23882 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23884 overlay
= overlay_vec
[i
];
23885 help
= Foverlay_get (overlay
, Qhelp_echo
);
23890 help_echo_string
= help
;
23891 help_echo_window
= window
;
23892 help_echo_object
= overlay
;
23893 help_echo_pos
= pos
;
23897 Lisp_Object object
= glyph
->object
;
23898 int charpos
= glyph
->charpos
;
23900 /* Try text properties. */
23901 if (STRINGP (object
)
23903 && charpos
< SCHARS (object
))
23905 help
= Fget_text_property (make_number (charpos
),
23906 Qhelp_echo
, object
);
23909 /* If the string itself doesn't specify a help-echo,
23910 see if the buffer text ``under'' it does. */
23911 struct glyph_row
*r
23912 = MATRIX_ROW (w
->current_matrix
, vpos
);
23913 int start
= MATRIX_ROW_START_CHARPOS (r
);
23914 int pos
= string_buffer_position (w
, object
, start
);
23917 help
= Fget_char_property (make_number (pos
),
23918 Qhelp_echo
, w
->buffer
);
23922 object
= w
->buffer
;
23927 else if (BUFFERP (object
)
23930 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23935 help_echo_string
= help
;
23936 help_echo_window
= window
;
23937 help_echo_object
= object
;
23938 help_echo_pos
= charpos
;
23943 /* Look for a `pointer' property. */
23944 if (NILP (pointer
))
23946 /* Check overlays first. */
23947 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23948 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23950 if (NILP (pointer
))
23952 Lisp_Object object
= glyph
->object
;
23953 int charpos
= glyph
->charpos
;
23955 /* Try text properties. */
23956 if (STRINGP (object
)
23958 && charpos
< SCHARS (object
))
23960 pointer
= Fget_text_property (make_number (charpos
),
23962 if (NILP (pointer
))
23964 /* If the string itself doesn't specify a pointer,
23965 see if the buffer text ``under'' it does. */
23966 struct glyph_row
*r
23967 = MATRIX_ROW (w
->current_matrix
, vpos
);
23968 int start
= MATRIX_ROW_START_CHARPOS (r
);
23969 int pos
= string_buffer_position (w
, object
, start
);
23971 pointer
= Fget_char_property (make_number (pos
),
23972 Qpointer
, w
->buffer
);
23975 else if (BUFFERP (object
)
23978 pointer
= Fget_text_property (make_number (charpos
),
23985 current_buffer
= obuf
;
23990 define_frame_cursor1 (f
, cursor
, pointer
);
23995 Clear any mouse-face on window W. This function is part of the
23996 redisplay interface, and is called from try_window_id and similar
23997 functions to ensure the mouse-highlight is off. */
24000 x_clear_window_mouse_face (w
)
24003 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24004 Lisp_Object window
;
24007 XSETWINDOW (window
, w
);
24008 if (EQ (window
, dpyinfo
->mouse_face_window
))
24009 clear_mouse_face (dpyinfo
);
24015 Just discard the mouse face information for frame F, if any.
24016 This is used when the size of F is changed. */
24019 cancel_mouse_face (f
)
24022 Lisp_Object window
;
24023 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24025 window
= dpyinfo
->mouse_face_window
;
24026 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24028 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24029 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24030 dpyinfo
->mouse_face_window
= Qnil
;
24035 #endif /* HAVE_WINDOW_SYSTEM */
24038 /***********************************************************************
24040 ***********************************************************************/
24042 #ifdef HAVE_WINDOW_SYSTEM
24044 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24045 which intersects rectangle R. R is in window-relative coordinates. */
24048 expose_area (w
, row
, r
, area
)
24050 struct glyph_row
*row
;
24052 enum glyph_row_area area
;
24054 struct glyph
*first
= row
->glyphs
[area
];
24055 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24056 struct glyph
*last
;
24057 int first_x
, start_x
, x
;
24059 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24060 /* If row extends face to end of line write the whole line. */
24061 draw_glyphs (w
, 0, row
, area
,
24062 0, row
->used
[area
],
24063 DRAW_NORMAL_TEXT
, 0);
24066 /* Set START_X to the window-relative start position for drawing glyphs of
24067 AREA. The first glyph of the text area can be partially visible.
24068 The first glyphs of other areas cannot. */
24069 start_x
= window_box_left_offset (w
, area
);
24071 if (area
== TEXT_AREA
)
24074 /* Find the first glyph that must be redrawn. */
24076 && x
+ first
->pixel_width
< r
->x
)
24078 x
+= first
->pixel_width
;
24082 /* Find the last one. */
24086 && x
< r
->x
+ r
->width
)
24088 x
+= last
->pixel_width
;
24094 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24095 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24096 DRAW_NORMAL_TEXT
, 0);
24101 /* Redraw the parts of the glyph row ROW on window W intersecting
24102 rectangle R. R is in window-relative coordinates. Value is
24103 non-zero if mouse-face was overwritten. */
24106 expose_line (w
, row
, r
)
24108 struct glyph_row
*row
;
24111 xassert (row
->enabled_p
);
24113 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24114 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24115 0, row
->used
[TEXT_AREA
],
24116 DRAW_NORMAL_TEXT
, 0);
24119 if (row
->used
[LEFT_MARGIN_AREA
])
24120 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24121 if (row
->used
[TEXT_AREA
])
24122 expose_area (w
, row
, r
, TEXT_AREA
);
24123 if (row
->used
[RIGHT_MARGIN_AREA
])
24124 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24125 draw_row_fringe_bitmaps (w
, row
);
24128 return row
->mouse_face_p
;
24132 /* Redraw those parts of glyphs rows during expose event handling that
24133 overlap other rows. Redrawing of an exposed line writes over parts
24134 of lines overlapping that exposed line; this function fixes that.
24136 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24137 row in W's current matrix that is exposed and overlaps other rows.
24138 LAST_OVERLAPPING_ROW is the last such row. */
24141 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24143 struct glyph_row
*first_overlapping_row
;
24144 struct glyph_row
*last_overlapping_row
;
24147 struct glyph_row
*row
;
24149 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24150 if (row
->overlapping_p
)
24152 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24155 if (row
->used
[LEFT_MARGIN_AREA
])
24156 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24158 if (row
->used
[TEXT_AREA
])
24159 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24161 if (row
->used
[RIGHT_MARGIN_AREA
])
24162 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24168 /* Return non-zero if W's cursor intersects rectangle R. */
24171 phys_cursor_in_rect_p (w
, r
)
24175 XRectangle cr
, result
;
24176 struct glyph
*cursor_glyph
;
24177 struct glyph_row
*row
;
24179 if (w
->phys_cursor
.vpos
>= 0
24180 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24181 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24183 && row
->cursor_in_fringe_p
)
24185 /* Cursor is in the fringe. */
24186 cr
.x
= window_box_right_offset (w
,
24187 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24188 ? RIGHT_MARGIN_AREA
24191 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24192 cr
.height
= row
->height
;
24193 return x_intersect_rectangles (&cr
, r
, &result
);
24196 cursor_glyph
= get_phys_cursor_glyph (w
);
24199 /* r is relative to W's box, but w->phys_cursor.x is relative
24200 to left edge of W's TEXT area. Adjust it. */
24201 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24202 cr
.y
= w
->phys_cursor
.y
;
24203 cr
.width
= cursor_glyph
->pixel_width
;
24204 cr
.height
= w
->phys_cursor_height
;
24205 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24206 I assume the effect is the same -- and this is portable. */
24207 return x_intersect_rectangles (&cr
, r
, &result
);
24209 /* If we don't understand the format, pretend we're not in the hot-spot. */
24215 Draw a vertical window border to the right of window W if W doesn't
24216 have vertical scroll bars. */
24219 x_draw_vertical_border (w
)
24222 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24224 /* We could do better, if we knew what type of scroll-bar the adjacent
24225 windows (on either side) have... But we don't :-(
24226 However, I think this works ok. ++KFS 2003-04-25 */
24228 /* Redraw borders between horizontally adjacent windows. Don't
24229 do it for frames with vertical scroll bars because either the
24230 right scroll bar of a window, or the left scroll bar of its
24231 neighbor will suffice as a border. */
24232 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24235 if (!WINDOW_RIGHTMOST_P (w
)
24236 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24238 int x0
, x1
, y0
, y1
;
24240 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24243 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24246 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24248 else if (!WINDOW_LEFTMOST_P (w
)
24249 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24251 int x0
, x1
, y0
, y1
;
24253 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24256 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24259 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24264 /* Redraw the part of window W intersection rectangle FR. Pixel
24265 coordinates in FR are frame-relative. Call this function with
24266 input blocked. Value is non-zero if the exposure overwrites
24270 expose_window (w
, fr
)
24274 struct frame
*f
= XFRAME (w
->frame
);
24276 int mouse_face_overwritten_p
= 0;
24278 /* If window is not yet fully initialized, do nothing. This can
24279 happen when toolkit scroll bars are used and a window is split.
24280 Reconfiguring the scroll bar will generate an expose for a newly
24282 if (w
->current_matrix
== NULL
)
24285 /* When we're currently updating the window, display and current
24286 matrix usually don't agree. Arrange for a thorough display
24288 if (w
== updated_window
)
24290 SET_FRAME_GARBAGED (f
);
24294 /* Frame-relative pixel rectangle of W. */
24295 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24296 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24297 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24298 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24300 if (x_intersect_rectangles (fr
, &wr
, &r
))
24302 int yb
= window_text_bottom_y (w
);
24303 struct glyph_row
*row
;
24304 int cursor_cleared_p
;
24305 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24307 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24308 r
.x
, r
.y
, r
.width
, r
.height
));
24310 /* Convert to window coordinates. */
24311 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24312 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24314 /* Turn off the cursor. */
24315 if (!w
->pseudo_window_p
24316 && phys_cursor_in_rect_p (w
, &r
))
24318 x_clear_cursor (w
);
24319 cursor_cleared_p
= 1;
24322 cursor_cleared_p
= 0;
24324 /* Update lines intersecting rectangle R. */
24325 first_overlapping_row
= last_overlapping_row
= NULL
;
24326 for (row
= w
->current_matrix
->rows
;
24331 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24333 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24334 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24335 || (r
.y
>= y0
&& r
.y
< y1
)
24336 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24338 /* A header line may be overlapping, but there is no need
24339 to fix overlapping areas for them. KFS 2005-02-12 */
24340 if (row
->overlapping_p
&& !row
->mode_line_p
)
24342 if (first_overlapping_row
== NULL
)
24343 first_overlapping_row
= row
;
24344 last_overlapping_row
= row
;
24348 if (expose_line (w
, row
, &r
))
24349 mouse_face_overwritten_p
= 1;
24352 else if (row
->overlapping_p
)
24354 /* We must redraw a row overlapping the exposed area. */
24356 ? y0
+ row
->phys_height
> r
.y
24357 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24359 if (first_overlapping_row
== NULL
)
24360 first_overlapping_row
= row
;
24361 last_overlapping_row
= row
;
24369 /* Display the mode line if there is one. */
24370 if (WINDOW_WANTS_MODELINE_P (w
)
24371 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24373 && row
->y
< r
.y
+ r
.height
)
24375 if (expose_line (w
, row
, &r
))
24376 mouse_face_overwritten_p
= 1;
24379 if (!w
->pseudo_window_p
)
24381 /* Fix the display of overlapping rows. */
24382 if (first_overlapping_row
)
24383 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24386 /* Draw border between windows. */
24387 x_draw_vertical_border (w
);
24389 /* Turn the cursor on again. */
24390 if (cursor_cleared_p
)
24391 update_window_cursor (w
, 1);
24395 return mouse_face_overwritten_p
;
24400 /* Redraw (parts) of all windows in the window tree rooted at W that
24401 intersect R. R contains frame pixel coordinates. Value is
24402 non-zero if the exposure overwrites mouse-face. */
24405 expose_window_tree (w
, r
)
24409 struct frame
*f
= XFRAME (w
->frame
);
24410 int mouse_face_overwritten_p
= 0;
24412 while (w
&& !FRAME_GARBAGED_P (f
))
24414 if (!NILP (w
->hchild
))
24415 mouse_face_overwritten_p
24416 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24417 else if (!NILP (w
->vchild
))
24418 mouse_face_overwritten_p
24419 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24421 mouse_face_overwritten_p
|= expose_window (w
, r
);
24423 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24426 return mouse_face_overwritten_p
;
24431 Redisplay an exposed area of frame F. X and Y are the upper-left
24432 corner of the exposed rectangle. W and H are width and height of
24433 the exposed area. All are pixel values. W or H zero means redraw
24434 the entire frame. */
24437 expose_frame (f
, x
, y
, w
, h
)
24442 int mouse_face_overwritten_p
= 0;
24444 TRACE ((stderr
, "expose_frame "));
24446 /* No need to redraw if frame will be redrawn soon. */
24447 if (FRAME_GARBAGED_P (f
))
24449 TRACE ((stderr
, " garbaged\n"));
24453 /* If basic faces haven't been realized yet, there is no point in
24454 trying to redraw anything. This can happen when we get an expose
24455 event while Emacs is starting, e.g. by moving another window. */
24456 if (FRAME_FACE_CACHE (f
) == NULL
24457 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24459 TRACE ((stderr
, " no faces\n"));
24463 if (w
== 0 || h
== 0)
24466 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24467 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24477 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24478 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24480 if (WINDOWP (f
->tool_bar_window
))
24481 mouse_face_overwritten_p
24482 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24484 #ifdef HAVE_X_WINDOWS
24486 #ifndef USE_X_TOOLKIT
24487 if (WINDOWP (f
->menu_bar_window
))
24488 mouse_face_overwritten_p
24489 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24490 #endif /* not USE_X_TOOLKIT */
24494 /* Some window managers support a focus-follows-mouse style with
24495 delayed raising of frames. Imagine a partially obscured frame,
24496 and moving the mouse into partially obscured mouse-face on that
24497 frame. The visible part of the mouse-face will be highlighted,
24498 then the WM raises the obscured frame. With at least one WM, KDE
24499 2.1, Emacs is not getting any event for the raising of the frame
24500 (even tried with SubstructureRedirectMask), only Expose events.
24501 These expose events will draw text normally, i.e. not
24502 highlighted. Which means we must redo the highlight here.
24503 Subsume it under ``we love X''. --gerd 2001-08-15 */
24504 /* Included in Windows version because Windows most likely does not
24505 do the right thing if any third party tool offers
24506 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24507 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24509 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24510 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24512 int x
= dpyinfo
->mouse_face_mouse_x
;
24513 int y
= dpyinfo
->mouse_face_mouse_y
;
24514 clear_mouse_face (dpyinfo
);
24515 note_mouse_highlight (f
, x
, y
);
24522 Determine the intersection of two rectangles R1 and R2. Return
24523 the intersection in *RESULT. Value is non-zero if RESULT is not
24527 x_intersect_rectangles (r1
, r2
, result
)
24528 XRectangle
*r1
, *r2
, *result
;
24530 XRectangle
*left
, *right
;
24531 XRectangle
*upper
, *lower
;
24532 int intersection_p
= 0;
24534 /* Rearrange so that R1 is the left-most rectangle. */
24536 left
= r1
, right
= r2
;
24538 left
= r2
, right
= r1
;
24540 /* X0 of the intersection is right.x0, if this is inside R1,
24541 otherwise there is no intersection. */
24542 if (right
->x
<= left
->x
+ left
->width
)
24544 result
->x
= right
->x
;
24546 /* The right end of the intersection is the minimum of the
24547 the right ends of left and right. */
24548 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24551 /* Same game for Y. */
24553 upper
= r1
, lower
= r2
;
24555 upper
= r2
, lower
= r1
;
24557 /* The upper end of the intersection is lower.y0, if this is inside
24558 of upper. Otherwise, there is no intersection. */
24559 if (lower
->y
<= upper
->y
+ upper
->height
)
24561 result
->y
= lower
->y
;
24563 /* The lower end of the intersection is the minimum of the lower
24564 ends of upper and lower. */
24565 result
->height
= (min (lower
->y
+ lower
->height
,
24566 upper
->y
+ upper
->height
)
24568 intersection_p
= 1;
24572 return intersection_p
;
24575 #endif /* HAVE_WINDOW_SYSTEM */
24578 /***********************************************************************
24580 ***********************************************************************/
24585 Vwith_echo_area_save_vector
= Qnil
;
24586 staticpro (&Vwith_echo_area_save_vector
);
24588 Vmessage_stack
= Qnil
;
24589 staticpro (&Vmessage_stack
);
24591 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24592 staticpro (&Qinhibit_redisplay
);
24594 message_dolog_marker1
= Fmake_marker ();
24595 staticpro (&message_dolog_marker1
);
24596 message_dolog_marker2
= Fmake_marker ();
24597 staticpro (&message_dolog_marker2
);
24598 message_dolog_marker3
= Fmake_marker ();
24599 staticpro (&message_dolog_marker3
);
24602 defsubr (&Sdump_frame_glyph_matrix
);
24603 defsubr (&Sdump_glyph_matrix
);
24604 defsubr (&Sdump_glyph_row
);
24605 defsubr (&Sdump_tool_bar_row
);
24606 defsubr (&Strace_redisplay
);
24607 defsubr (&Strace_to_stderr
);
24609 #ifdef HAVE_WINDOW_SYSTEM
24610 defsubr (&Stool_bar_lines_needed
);
24611 defsubr (&Slookup_image_map
);
24613 defsubr (&Sformat_mode_line
);
24614 defsubr (&Sinvisible_p
);
24616 staticpro (&Qmenu_bar_update_hook
);
24617 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24619 staticpro (&Qoverriding_terminal_local_map
);
24620 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24622 staticpro (&Qoverriding_local_map
);
24623 Qoverriding_local_map
= intern ("overriding-local-map");
24625 staticpro (&Qwindow_scroll_functions
);
24626 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24628 staticpro (&Qwindow_text_change_functions
);
24629 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24631 staticpro (&Qredisplay_end_trigger_functions
);
24632 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24634 staticpro (&Qinhibit_point_motion_hooks
);
24635 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24637 Qeval
= intern ("eval");
24638 staticpro (&Qeval
);
24640 QCdata
= intern (":data");
24641 staticpro (&QCdata
);
24642 Qdisplay
= intern ("display");
24643 staticpro (&Qdisplay
);
24644 Qspace_width
= intern ("space-width");
24645 staticpro (&Qspace_width
);
24646 Qraise
= intern ("raise");
24647 staticpro (&Qraise
);
24648 Qslice
= intern ("slice");
24649 staticpro (&Qslice
);
24650 Qspace
= intern ("space");
24651 staticpro (&Qspace
);
24652 Qmargin
= intern ("margin");
24653 staticpro (&Qmargin
);
24654 Qpointer
= intern ("pointer");
24655 staticpro (&Qpointer
);
24656 Qleft_margin
= intern ("left-margin");
24657 staticpro (&Qleft_margin
);
24658 Qright_margin
= intern ("right-margin");
24659 staticpro (&Qright_margin
);
24660 Qcenter
= intern ("center");
24661 staticpro (&Qcenter
);
24662 Qline_height
= intern ("line-height");
24663 staticpro (&Qline_height
);
24664 QCalign_to
= intern (":align-to");
24665 staticpro (&QCalign_to
);
24666 QCrelative_width
= intern (":relative-width");
24667 staticpro (&QCrelative_width
);
24668 QCrelative_height
= intern (":relative-height");
24669 staticpro (&QCrelative_height
);
24670 QCeval
= intern (":eval");
24671 staticpro (&QCeval
);
24672 QCpropertize
= intern (":propertize");
24673 staticpro (&QCpropertize
);
24674 QCfile
= intern (":file");
24675 staticpro (&QCfile
);
24676 Qfontified
= intern ("fontified");
24677 staticpro (&Qfontified
);
24678 Qfontification_functions
= intern ("fontification-functions");
24679 staticpro (&Qfontification_functions
);
24680 Qtrailing_whitespace
= intern ("trailing-whitespace");
24681 staticpro (&Qtrailing_whitespace
);
24682 Qescape_glyph
= intern ("escape-glyph");
24683 staticpro (&Qescape_glyph
);
24684 Qnobreak_space
= intern ("nobreak-space");
24685 staticpro (&Qnobreak_space
);
24686 Qimage
= intern ("image");
24687 staticpro (&Qimage
);
24688 QCmap
= intern (":map");
24689 staticpro (&QCmap
);
24690 QCpointer
= intern (":pointer");
24691 staticpro (&QCpointer
);
24692 Qrect
= intern ("rect");
24693 staticpro (&Qrect
);
24694 Qcircle
= intern ("circle");
24695 staticpro (&Qcircle
);
24696 Qpoly
= intern ("poly");
24697 staticpro (&Qpoly
);
24698 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24699 staticpro (&Qmessage_truncate_lines
);
24700 Qgrow_only
= intern ("grow-only");
24701 staticpro (&Qgrow_only
);
24702 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24703 staticpro (&Qinhibit_menubar_update
);
24704 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24705 staticpro (&Qinhibit_eval_during_redisplay
);
24706 Qposition
= intern ("position");
24707 staticpro (&Qposition
);
24708 Qbuffer_position
= intern ("buffer-position");
24709 staticpro (&Qbuffer_position
);
24710 Qobject
= intern ("object");
24711 staticpro (&Qobject
);
24712 Qbar
= intern ("bar");
24714 Qhbar
= intern ("hbar");
24715 staticpro (&Qhbar
);
24716 Qbox
= intern ("box");
24718 Qhollow
= intern ("hollow");
24719 staticpro (&Qhollow
);
24720 Qhand
= intern ("hand");
24721 staticpro (&Qhand
);
24722 Qarrow
= intern ("arrow");
24723 staticpro (&Qarrow
);
24724 Qtext
= intern ("text");
24725 staticpro (&Qtext
);
24726 Qrisky_local_variable
= intern ("risky-local-variable");
24727 staticpro (&Qrisky_local_variable
);
24728 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24729 staticpro (&Qinhibit_free_realized_faces
);
24731 list_of_error
= Fcons (Fcons (intern ("error"),
24732 Fcons (intern ("void-variable"), Qnil
)),
24734 staticpro (&list_of_error
);
24736 Qlast_arrow_position
= intern ("last-arrow-position");
24737 staticpro (&Qlast_arrow_position
);
24738 Qlast_arrow_string
= intern ("last-arrow-string");
24739 staticpro (&Qlast_arrow_string
);
24741 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24742 staticpro (&Qoverlay_arrow_string
);
24743 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24744 staticpro (&Qoverlay_arrow_bitmap
);
24746 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24747 staticpro (&echo_buffer
[0]);
24748 staticpro (&echo_buffer
[1]);
24750 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24751 staticpro (&echo_area_buffer
[0]);
24752 staticpro (&echo_area_buffer
[1]);
24754 Vmessages_buffer_name
= build_string ("*Messages*");
24755 staticpro (&Vmessages_buffer_name
);
24757 mode_line_proptrans_alist
= Qnil
;
24758 staticpro (&mode_line_proptrans_alist
);
24759 mode_line_string_list
= Qnil
;
24760 staticpro (&mode_line_string_list
);
24761 mode_line_string_face
= Qnil
;
24762 staticpro (&mode_line_string_face
);
24763 mode_line_string_face_prop
= Qnil
;
24764 staticpro (&mode_line_string_face_prop
);
24765 Vmode_line_unwind_vector
= Qnil
;
24766 staticpro (&Vmode_line_unwind_vector
);
24768 help_echo_string
= Qnil
;
24769 staticpro (&help_echo_string
);
24770 help_echo_object
= Qnil
;
24771 staticpro (&help_echo_object
);
24772 help_echo_window
= Qnil
;
24773 staticpro (&help_echo_window
);
24774 previous_help_echo_string
= Qnil
;
24775 staticpro (&previous_help_echo_string
);
24776 help_echo_pos
= -1;
24778 #ifdef HAVE_WINDOW_SYSTEM
24779 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24780 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24781 For example, if a block cursor is over a tab, it will be drawn as
24782 wide as that tab on the display. */);
24783 x_stretch_cursor_p
= 0;
24786 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24787 doc
: /* *Non-nil means highlight trailing whitespace.
24788 The face used for trailing whitespace is `trailing-whitespace'. */);
24789 Vshow_trailing_whitespace
= Qnil
;
24791 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24792 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24793 A value of t means highlight the character itself (for nobreak space,
24794 use face `nobreak-space').
24795 A value of nil means no highlighting.
24796 Other values mean display the escape glyph followed by an ordinary
24797 space or ordinary hyphen. */);
24798 Vnobreak_char_display
= Qt
;
24800 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24801 doc
: /* *The pointer shape to show in void text areas.
24802 A value of nil means to show the text pointer. Other options are `arrow',
24803 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24804 Vvoid_text_area_pointer
= Qarrow
;
24806 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24807 doc
: /* Non-nil means don't actually do any redisplay.
24808 This is used for internal purposes. */);
24809 Vinhibit_redisplay
= Qnil
;
24811 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24812 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24813 Vglobal_mode_string
= Qnil
;
24815 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24816 doc
: /* Marker for where to display an arrow on top of the buffer text.
24817 This must be the beginning of a line in order to work.
24818 See also `overlay-arrow-string'. */);
24819 Voverlay_arrow_position
= Qnil
;
24821 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24822 doc
: /* String to display as an arrow in non-window frames.
24823 See also `overlay-arrow-position'. */);
24824 Voverlay_arrow_string
= build_string ("=>");
24826 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24827 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24828 The symbols on this list are examined during redisplay to determine
24829 where to display overlay arrows. */);
24830 Voverlay_arrow_variable_list
24831 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24833 DEFVAR_INT ("scroll-step", &scroll_step
,
24834 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24835 If that fails to bring point back on frame, point is centered instead.
24836 If this is zero, point is always centered after it moves off frame.
24837 If you want scrolling to always be a line at a time, you should set
24838 `scroll-conservatively' to a large value rather than set this to 1. */);
24840 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24841 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24842 If point moves off-screen, redisplay will scroll by up to
24843 `scroll-conservatively' lines in order to bring point just barely
24844 onto the screen again. If that cannot be done, then redisplay
24845 recenters point as usual.
24847 A value of zero means always recenter point if it moves off screen. */);
24848 scroll_conservatively
= 0;
24850 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24851 doc
: /* *Number of lines of margin at the top and bottom of a window.
24852 Recenter the window whenever point gets within this many lines
24853 of the top or bottom of the window. */);
24856 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24857 doc
: /* Pixels per inch value for non-window system displays.
24858 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24859 Vdisplay_pixels_per_inch
= make_float (72.0);
24862 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24865 DEFVAR_LISP ("truncate-partial-width-windows",
24866 &Vtruncate_partial_width_windows
,
24867 doc
: /* Non-nil means truncate lines in windows with less than the frame width.
24868 For an integer value, truncate lines in each window with less than the
24869 full frame width, provided the window width is less than that integer;
24870 otherwise, respect the value of `truncate-lines'.
24872 For any other non-nil value, truncate lines in all windows with
24873 less than the full frame width.
24875 A value of nil means to respect the value of `truncate-lines'.
24877 If `word-wrap' is enabled, you might want to reduce this. */);
24878 Vtruncate_partial_width_windows
= make_number (50);
24880 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24881 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24882 Any other value means to use the appropriate face, `mode-line',
24883 `header-line', or `menu' respectively. */);
24884 mode_line_inverse_video
= 1;
24886 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24887 doc
: /* *Maximum buffer size for which line number should be displayed.
24888 If the buffer is bigger than this, the line number does not appear
24889 in the mode line. A value of nil means no limit. */);
24890 Vline_number_display_limit
= Qnil
;
24892 DEFVAR_INT ("line-number-display-limit-width",
24893 &line_number_display_limit_width
,
24894 doc
: /* *Maximum line width (in characters) for line number display.
24895 If the average length of the lines near point is bigger than this, then the
24896 line number may be omitted from the mode line. */);
24897 line_number_display_limit_width
= 200;
24899 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24900 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24901 highlight_nonselected_windows
= 0;
24903 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24904 doc
: /* Non-nil if more than one frame is visible on this display.
24905 Minibuffer-only frames don't count, but iconified frames do.
24906 This variable is not guaranteed to be accurate except while processing
24907 `frame-title-format' and `icon-title-format'. */);
24909 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24910 doc
: /* Template for displaying the title bar of visible frames.
24911 \(Assuming the window manager supports this feature.)
24913 This variable has the same structure as `mode-line-format', except that
24914 the %c and %l constructs are ignored. It is used only on frames for
24915 which no explicit name has been set \(see `modify-frame-parameters'). */);
24917 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24918 doc
: /* Template for displaying the title bar of an iconified frame.
24919 \(Assuming the window manager supports this feature.)
24920 This variable has the same structure as `mode-line-format' (which see),
24921 and is used only on frames for which no explicit name has been set
24922 \(see `modify-frame-parameters'). */);
24924 = Vframe_title_format
24925 = Fcons (intern ("multiple-frames"),
24926 Fcons (build_string ("%b"),
24927 Fcons (Fcons (empty_unibyte_string
,
24928 Fcons (intern ("invocation-name"),
24929 Fcons (build_string ("@"),
24930 Fcons (intern ("system-name"),
24934 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24935 doc
: /* Maximum number of lines to keep in the message log buffer.
24936 If nil, disable message logging. If t, log messages but don't truncate
24937 the buffer when it becomes large. */);
24938 Vmessage_log_max
= make_number (100);
24940 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24941 doc
: /* Functions called before redisplay, if window sizes have changed.
24942 The value should be a list of functions that take one argument.
24943 Just before redisplay, for each frame, if any of its windows have changed
24944 size since the last redisplay, or have been split or deleted,
24945 all the functions in the list are called, with the frame as argument. */);
24946 Vwindow_size_change_functions
= Qnil
;
24948 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24949 doc
: /* List of functions to call before redisplaying a window with scrolling.
24950 Each function is called with two arguments, the window and its new
24951 display-start position. Note that these functions are also called by
24952 `set-window-buffer'. Also note that the value of `window-end' is not
24953 valid when these functions are called. */);
24954 Vwindow_scroll_functions
= Qnil
;
24956 DEFVAR_LISP ("window-text-change-functions",
24957 &Vwindow_text_change_functions
,
24958 doc
: /* Functions to call in redisplay when text in the window might change. */);
24959 Vwindow_text_change_functions
= Qnil
;
24961 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24962 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24963 Each function is called with two arguments, the window and the end trigger value.
24964 See `set-window-redisplay-end-trigger'. */);
24965 Vredisplay_end_trigger_functions
= Qnil
;
24967 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24968 doc
: /* *Non-nil means autoselect window with mouse pointer.
24969 If nil, do not autoselect windows.
24970 A positive number means delay autoselection by that many seconds: a
24971 window is autoselected only after the mouse has remained in that
24972 window for the duration of the delay.
24973 A negative number has a similar effect, but causes windows to be
24974 autoselected only after the mouse has stopped moving. \(Because of
24975 the way Emacs compares mouse events, you will occasionally wait twice
24976 that time before the window gets selected.\)
24977 Any other value means to autoselect window instantaneously when the
24978 mouse pointer enters it.
24980 Autoselection selects the minibuffer only if it is active, and never
24981 unselects the minibuffer if it is active.
24983 When customizing this variable make sure that the actual value of
24984 `focus-follows-mouse' matches the behavior of your window manager. */);
24985 Vmouse_autoselect_window
= Qnil
;
24987 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24988 doc
: /* *Non-nil means automatically resize tool-bars.
24989 This dynamically changes the tool-bar's height to the minimum height
24990 that is needed to make all tool-bar items visible.
24991 If value is `grow-only', the tool-bar's height is only increased
24992 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24993 Vauto_resize_tool_bars
= Qt
;
24995 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24996 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24997 auto_raise_tool_bar_buttons_p
= 1;
24999 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25000 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25001 make_cursor_line_fully_visible_p
= 1;
25003 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25004 doc
: /* *Border below tool-bar in pixels.
25005 If an integer, use it as the height of the border.
25006 If it is one of `internal-border-width' or `border-width', use the
25007 value of the corresponding frame parameter.
25008 Otherwise, no border is added below the tool-bar. */);
25009 Vtool_bar_border
= Qinternal_border_width
;
25011 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25012 doc
: /* *Margin around tool-bar buttons in pixels.
25013 If an integer, use that for both horizontal and vertical margins.
25014 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25015 HORZ specifying the horizontal margin, and VERT specifying the
25016 vertical margin. */);
25017 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25019 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25020 doc
: /* *Relief thickness of tool-bar buttons. */);
25021 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25023 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25024 doc
: /* List of functions to call to fontify regions of text.
25025 Each function is called with one argument POS. Functions must
25026 fontify a region starting at POS in the current buffer, and give
25027 fontified regions the property `fontified'. */);
25028 Vfontification_functions
= Qnil
;
25029 Fmake_variable_buffer_local (Qfontification_functions
);
25031 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25032 &unibyte_display_via_language_environment
,
25033 doc
: /* *Non-nil means display unibyte text according to language environment.
25034 Specifically this means that unibyte non-ASCII characters
25035 are displayed by converting them to the equivalent multibyte characters
25036 according to the current language environment. As a result, they are
25037 displayed according to the current fontset. */);
25038 unibyte_display_via_language_environment
= 0;
25040 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25041 doc
: /* *Maximum height for resizing mini-windows.
25042 If a float, it specifies a fraction of the mini-window frame's height.
25043 If an integer, it specifies a number of lines. */);
25044 Vmax_mini_window_height
= make_float (0.25);
25046 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25047 doc
: /* *How to resize mini-windows.
25048 A value of nil means don't automatically resize mini-windows.
25049 A value of t means resize them to fit the text displayed in them.
25050 A value of `grow-only', the default, means let mini-windows grow
25051 only, until their display becomes empty, at which point the windows
25052 go back to their normal size. */);
25053 Vresize_mini_windows
= Qgrow_only
;
25055 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25056 doc
: /* Alist specifying how to blink the cursor off.
25057 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25058 `cursor-type' frame-parameter or variable equals ON-STATE,
25059 comparing using `equal', Emacs uses OFF-STATE to specify
25060 how to blink it off. ON-STATE and OFF-STATE are values for
25061 the `cursor-type' frame parameter.
25063 If a frame's ON-STATE has no entry in this list,
25064 the frame's other specifications determine how to blink the cursor off. */);
25065 Vblink_cursor_alist
= Qnil
;
25067 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25068 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25069 automatic_hscrolling_p
= 1;
25070 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
25071 staticpro (&Qauto_hscroll_mode
);
25073 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25074 doc
: /* *How many columns away from the window edge point is allowed to get
25075 before automatic hscrolling will horizontally scroll the window. */);
25076 hscroll_margin
= 5;
25078 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25079 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25080 When point is less than `hscroll-margin' columns from the window
25081 edge, automatic hscrolling will scroll the window by the amount of columns
25082 determined by this variable. If its value is a positive integer, scroll that
25083 many columns. If it's a positive floating-point number, it specifies the
25084 fraction of the window's width to scroll. If it's nil or zero, point will be
25085 centered horizontally after the scroll. Any other value, including negative
25086 numbers, are treated as if the value were zero.
25088 Automatic hscrolling always moves point outside the scroll margin, so if
25089 point was more than scroll step columns inside the margin, the window will
25090 scroll more than the value given by the scroll step.
25092 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25093 and `scroll-right' overrides this variable's effect. */);
25094 Vhscroll_step
= make_number (0);
25096 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25097 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25098 Bind this around calls to `message' to let it take effect. */);
25099 message_truncate_lines
= 0;
25101 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25102 doc
: /* Normal hook run to update the menu bar definitions.
25103 Redisplay runs this hook before it redisplays the menu bar.
25104 This is used to update submenus such as Buffers,
25105 whose contents depend on various data. */);
25106 Vmenu_bar_update_hook
= Qnil
;
25108 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25109 doc
: /* Frame for which we are updating a menu.
25110 The enable predicate for a menu binding should check this variable. */);
25111 Vmenu_updating_frame
= Qnil
;
25113 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25114 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25115 inhibit_menubar_update
= 0;
25117 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25118 doc
: /* Prefix prepended to all continuation lines at display time.
25119 The value may be a string, an image, or a stretch-glyph; it is
25120 interpreted in the same way as the value of a `display' text property.
25122 This variable is overridden by any `wrap-prefix' text or overlay
25125 To add a prefix to non-continuation lines, use `line-prefix'. */);
25126 Vwrap_prefix
= Qnil
;
25127 staticpro (&Qwrap_prefix
);
25128 Qwrap_prefix
= intern ("wrap-prefix");
25129 Fmake_variable_buffer_local (Qwrap_prefix
);
25131 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25132 doc
: /* Prefix prepended to all non-continuation lines at display time.
25133 The value may be a string, an image, or a stretch-glyph; it is
25134 interpreted in the same way as the value of a `display' text property.
25136 This variable is overridden by any `line-prefix' text or overlay
25139 To add a prefix to continuation lines, use `wrap-prefix'. */);
25140 Vline_prefix
= Qnil
;
25141 staticpro (&Qline_prefix
);
25142 Qline_prefix
= intern ("line-prefix");
25143 Fmake_variable_buffer_local (Qline_prefix
);
25145 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25146 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25147 inhibit_eval_during_redisplay
= 0;
25149 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25150 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25151 inhibit_free_realized_faces
= 0;
25154 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25155 doc
: /* Inhibit try_window_id display optimization. */);
25156 inhibit_try_window_id
= 0;
25158 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25159 doc
: /* Inhibit try_window_reusing display optimization. */);
25160 inhibit_try_window_reusing
= 0;
25162 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25163 doc
: /* Inhibit try_cursor_movement display optimization. */);
25164 inhibit_try_cursor_movement
= 0;
25165 #endif /* GLYPH_DEBUG */
25167 DEFVAR_INT ("overline-margin", &overline_margin
,
25168 doc
: /* *Space between overline and text, in pixels.
25169 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25170 margin to the caracter height. */);
25171 overline_margin
= 2;
25173 DEFVAR_INT ("underline-minimum-offset",
25174 &underline_minimum_offset
,
25175 doc
: /* Minimum distance between baseline and underline.
25176 This can improve legibility of underlined text at small font sizes,
25177 particularly when using variable `x-use-underline-position-properties'
25178 with fonts that specify an UNDERLINE_POSITION relatively close to the
25179 baseline. The default value is 1. */);
25180 underline_minimum_offset
= 1;
25182 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25183 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25184 display_hourglass_p
= 1;
25186 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25187 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25188 Value must be an integer or float. */);
25189 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25191 hourglass_atimer
= NULL
;
25192 hourglass_shown_p
= 0;
25196 /* Initialize this module when Emacs starts. */
25201 Lisp_Object root_window
;
25202 struct window
*mini_w
;
25204 current_header_line_height
= current_mode_line_height
= -1;
25206 CHARPOS (this_line_start_pos
) = 0;
25208 mini_w
= XWINDOW (minibuf_window
);
25209 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25211 if (!noninteractive
)
25213 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25216 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25217 set_window_height (root_window
,
25218 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25220 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25221 set_window_height (minibuf_window
, 1, 0);
25223 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25224 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25226 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25227 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25228 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25230 /* The default ellipsis glyphs `...'. */
25231 for (i
= 0; i
< 3; ++i
)
25232 default_invis_vector
[i
] = make_number ('.');
25236 /* Allocate the buffer for frame titles.
25237 Also used for `format-mode-line'. */
25239 mode_line_noprop_buf
= (char *) xmalloc (size
);
25240 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25241 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25242 mode_line_target
= MODE_LINE_DISPLAY
;
25245 help_echo_showing_p
= 0;
25248 /* Since w32 does not support atimers, it defines its own implementation of
25249 the following three functions in w32fns.c. */
25252 /* Platform-independent portion of hourglass implementation. */
25254 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25256 hourglass_started ()
25258 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25261 /* Cancel a currently active hourglass timer, and start a new one. */
25265 #if defined (HAVE_WINDOW_SYSTEM)
25267 int secs
, usecs
= 0;
25269 cancel_hourglass ();
25271 if (INTEGERP (Vhourglass_delay
)
25272 && XINT (Vhourglass_delay
) > 0)
25273 secs
= XFASTINT (Vhourglass_delay
);
25274 else if (FLOATP (Vhourglass_delay
)
25275 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25278 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25279 secs
= XFASTINT (tem
);
25280 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25283 secs
= DEFAULT_HOURGLASS_DELAY
;
25285 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25286 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25287 show_hourglass
, NULL
);
25292 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25295 cancel_hourglass ()
25297 #if defined (HAVE_WINDOW_SYSTEM)
25298 if (hourglass_atimer
)
25300 cancel_atimer (hourglass_atimer
);
25301 hourglass_atimer
= NULL
;
25304 if (hourglass_shown_p
)
25308 #endif /* ! WINDOWSNT */
25310 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25311 (do not change this comment) */