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
;
5170 case GET_FROM_DISPLAY_VECTOR
:
5172 it
->method
= GET_FROM_C_STRING
;
5173 else if (STRINGP (it
->string
))
5174 it
->method
= GET_FROM_STRING
;
5177 it
->method
= GET_FROM_BUFFER
;
5178 it
->object
= it
->w
->buffer
;
5181 it
->end_charpos
= p
->end_charpos
;
5182 it
->string_nchars
= p
->string_nchars
;
5184 it
->multibyte_p
= p
->multibyte_p
;
5185 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5186 it
->space_width
= p
->space_width
;
5187 it
->font_height
= p
->font_height
;
5188 it
->voffset
= p
->voffset
;
5189 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5190 it
->line_wrap
= p
->line_wrap
;
5195 /***********************************************************************
5197 ***********************************************************************/
5199 /* Set IT's current position to the previous line start. */
5202 back_to_previous_line_start (it
)
5205 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5206 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5210 /* Move IT to the next line start.
5212 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5213 we skipped over part of the text (as opposed to moving the iterator
5214 continuously over the text). Otherwise, don't change the value
5217 Newlines may come from buffer text, overlay strings, or strings
5218 displayed via the `display' property. That's the reason we can't
5219 simply use find_next_newline_no_quit.
5221 Note that this function may not skip over invisible text that is so
5222 because of text properties and immediately follows a newline. If
5223 it would, function reseat_at_next_visible_line_start, when called
5224 from set_iterator_to_next, would effectively make invisible
5225 characters following a newline part of the wrong glyph row, which
5226 leads to wrong cursor motion. */
5229 forward_to_next_line_start (it
, skipped_p
)
5233 int old_selective
, newline_found_p
, n
;
5234 const int MAX_NEWLINE_DISTANCE
= 500;
5236 /* If already on a newline, just consume it to avoid unintended
5237 skipping over invisible text below. */
5238 if (it
->what
== IT_CHARACTER
5240 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5242 set_iterator_to_next (it
, 0);
5247 /* Don't handle selective display in the following. It's (a)
5248 unnecessary because it's done by the caller, and (b) leads to an
5249 infinite recursion because next_element_from_ellipsis indirectly
5250 calls this function. */
5251 old_selective
= it
->selective
;
5254 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5255 from buffer text. */
5256 for (n
= newline_found_p
= 0;
5257 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5258 n
+= STRINGP (it
->string
) ? 0 : 1)
5260 if (!get_next_display_element (it
))
5262 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5263 set_iterator_to_next (it
, 0);
5266 /* If we didn't find a newline near enough, see if we can use a
5268 if (!newline_found_p
)
5270 int start
= IT_CHARPOS (*it
);
5271 int limit
= find_next_newline_no_quit (start
, 1);
5274 xassert (!STRINGP (it
->string
));
5276 /* If there isn't any `display' property in sight, and no
5277 overlays, we can just use the position of the newline in
5279 if (it
->stop_charpos
>= limit
5280 || ((pos
= Fnext_single_property_change (make_number (start
),
5282 Qnil
, make_number (limit
)),
5284 && next_overlay_change (start
) == ZV
))
5286 IT_CHARPOS (*it
) = limit
;
5287 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5288 *skipped_p
= newline_found_p
= 1;
5292 while (get_next_display_element (it
)
5293 && !newline_found_p
)
5295 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5296 set_iterator_to_next (it
, 0);
5301 it
->selective
= old_selective
;
5302 return newline_found_p
;
5306 /* Set IT's current position to the previous visible line start. Skip
5307 invisible text that is so either due to text properties or due to
5308 selective display. Caution: this does not change IT->current_x and
5312 back_to_previous_visible_line_start (it
)
5315 while (IT_CHARPOS (*it
) > BEGV
)
5317 back_to_previous_line_start (it
);
5319 if (IT_CHARPOS (*it
) <= BEGV
)
5322 /* If selective > 0, then lines indented more than that values
5324 if (it
->selective
> 0
5325 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5326 (double) it
->selective
)) /* iftc */
5329 /* Check the newline before point for invisibility. */
5332 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5333 Qinvisible
, it
->window
);
5334 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5338 if (IT_CHARPOS (*it
) <= BEGV
)
5345 Lisp_Object val
, overlay
;
5347 /* If newline is part of a composition, continue from start of composition */
5348 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5349 && beg
< IT_CHARPOS (*it
))
5352 /* If newline is replaced by a display property, find start of overlay
5353 or interval and continue search from that point. */
5355 pos
= --IT_CHARPOS (it2
);
5358 it2
.string_from_display_prop_p
= 0;
5359 if (handle_display_prop (&it2
) == HANDLED_RETURN
5360 && !NILP (val
= get_char_property_and_overlay
5361 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5362 && (OVERLAYP (overlay
)
5363 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5364 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5367 /* Newline is not replaced by anything -- so we are done. */
5373 IT_CHARPOS (*it
) = beg
;
5374 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5378 it
->continuation_lines_width
= 0;
5380 xassert (IT_CHARPOS (*it
) >= BEGV
);
5381 xassert (IT_CHARPOS (*it
) == BEGV
5382 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5387 /* Reseat iterator IT at the previous visible line start. Skip
5388 invisible text that is so either due to text properties or due to
5389 selective display. At the end, update IT's overlay information,
5390 face information etc. */
5393 reseat_at_previous_visible_line_start (it
)
5396 back_to_previous_visible_line_start (it
);
5397 reseat (it
, it
->current
.pos
, 1);
5402 /* Reseat iterator IT on the next visible line start in the current
5403 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5404 preceding the line start. Skip over invisible text that is so
5405 because of selective display. Compute faces, overlays etc at the
5406 new position. Note that this function does not skip over text that
5407 is invisible because of text properties. */
5410 reseat_at_next_visible_line_start (it
, on_newline_p
)
5414 int newline_found_p
, skipped_p
= 0;
5416 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5418 /* Skip over lines that are invisible because they are indented
5419 more than the value of IT->selective. */
5420 if (it
->selective
> 0)
5421 while (IT_CHARPOS (*it
) < ZV
5422 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5423 (double) it
->selective
)) /* iftc */
5425 xassert (IT_BYTEPOS (*it
) == BEGV
5426 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5427 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5430 /* Position on the newline if that's what's requested. */
5431 if (on_newline_p
&& newline_found_p
)
5433 if (STRINGP (it
->string
))
5435 if (IT_STRING_CHARPOS (*it
) > 0)
5437 --IT_STRING_CHARPOS (*it
);
5438 --IT_STRING_BYTEPOS (*it
);
5441 else if (IT_CHARPOS (*it
) > BEGV
)
5445 reseat (it
, it
->current
.pos
, 0);
5449 reseat (it
, it
->current
.pos
, 0);
5456 /***********************************************************************
5457 Changing an iterator's position
5458 ***********************************************************************/
5460 /* Change IT's current position to POS in current_buffer. If FORCE_P
5461 is non-zero, always check for text properties at the new position.
5462 Otherwise, text properties are only looked up if POS >=
5463 IT->check_charpos of a property. */
5466 reseat (it
, pos
, force_p
)
5468 struct text_pos pos
;
5471 int original_pos
= IT_CHARPOS (*it
);
5473 reseat_1 (it
, pos
, 0);
5475 /* Determine where to check text properties. Avoid doing it
5476 where possible because text property lookup is very expensive. */
5478 || CHARPOS (pos
) > it
->stop_charpos
5479 || CHARPOS (pos
) < original_pos
)
5486 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5487 IT->stop_pos to POS, also. */
5490 reseat_1 (it
, pos
, set_stop_p
)
5492 struct text_pos pos
;
5495 /* Don't call this function when scanning a C string. */
5496 xassert (it
->s
== NULL
);
5498 /* POS must be a reasonable value. */
5499 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5501 it
->current
.pos
= it
->position
= pos
;
5502 it
->end_charpos
= ZV
;
5504 it
->current
.dpvec_index
= -1;
5505 it
->current
.overlay_string_index
= -1;
5506 IT_STRING_CHARPOS (*it
) = -1;
5507 IT_STRING_BYTEPOS (*it
) = -1;
5509 it
->string_from_display_prop_p
= 0;
5510 it
->method
= GET_FROM_BUFFER
;
5511 it
->object
= it
->w
->buffer
;
5512 it
->area
= TEXT_AREA
;
5513 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5515 it
->string_from_display_prop_p
= 0;
5516 it
->face_before_selective_p
= 0;
5519 it
->stop_charpos
= CHARPOS (pos
);
5523 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5524 If S is non-null, it is a C string to iterate over. Otherwise,
5525 STRING gives a Lisp string to iterate over.
5527 If PRECISION > 0, don't return more then PRECISION number of
5528 characters from the string.
5530 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5531 characters have been returned. FIELD_WIDTH < 0 means an infinite
5534 MULTIBYTE = 0 means disable processing of multibyte characters,
5535 MULTIBYTE > 0 means enable it,
5536 MULTIBYTE < 0 means use IT->multibyte_p.
5538 IT must be initialized via a prior call to init_iterator before
5539 calling this function. */
5542 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5547 int precision
, field_width
, multibyte
;
5549 /* No region in strings. */
5550 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5552 /* No text property checks performed by default, but see below. */
5553 it
->stop_charpos
= -1;
5555 /* Set iterator position and end position. */
5556 bzero (&it
->current
, sizeof it
->current
);
5557 it
->current
.overlay_string_index
= -1;
5558 it
->current
.dpvec_index
= -1;
5559 xassert (charpos
>= 0);
5561 /* If STRING is specified, use its multibyteness, otherwise use the
5562 setting of MULTIBYTE, if specified. */
5564 it
->multibyte_p
= multibyte
> 0;
5568 xassert (STRINGP (string
));
5569 it
->string
= string
;
5571 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5572 it
->method
= GET_FROM_STRING
;
5573 it
->current
.string_pos
= string_pos (charpos
, string
);
5580 /* Note that we use IT->current.pos, not it->current.string_pos,
5581 for displaying C strings. */
5582 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5583 if (it
->multibyte_p
)
5585 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5586 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5590 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5591 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5594 it
->method
= GET_FROM_C_STRING
;
5597 /* PRECISION > 0 means don't return more than PRECISION characters
5599 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5600 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5602 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5603 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5604 FIELD_WIDTH < 0 means infinite field width. This is useful for
5605 padding with `-' at the end of a mode line. */
5606 if (field_width
< 0)
5607 field_width
= INFINITY
;
5608 if (field_width
> it
->end_charpos
- charpos
)
5609 it
->end_charpos
= charpos
+ field_width
;
5611 /* Use the standard display table for displaying strings. */
5612 if (DISP_TABLE_P (Vstandard_display_table
))
5613 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5615 it
->stop_charpos
= charpos
;
5621 /***********************************************************************
5623 ***********************************************************************/
5625 /* Map enum it_method value to corresponding next_element_from_* function. */
5627 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5629 next_element_from_buffer
,
5630 next_element_from_display_vector
,
5631 next_element_from_string
,
5632 next_element_from_c_string
,
5633 next_element_from_image
,
5634 next_element_from_stretch
5637 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5640 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5641 (possibly with the following characters). */
5643 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS) \
5644 ((IT)->cmp_it.id >= 0 \
5645 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5646 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5647 (IT)->end_charpos, (IT)->w, \
5648 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5652 /* Load IT's display element fields with information about the next
5653 display element from the current position of IT. Value is zero if
5654 end of buffer (or C string) is reached. */
5656 static struct frame
*last_escape_glyph_frame
= NULL
;
5657 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5658 static int last_escape_glyph_merged_face_id
= 0;
5661 get_next_display_element (it
)
5664 /* Non-zero means that we found a display element. Zero means that
5665 we hit the end of what we iterate over. Performance note: the
5666 function pointer `method' used here turns out to be faster than
5667 using a sequence of if-statements. */
5671 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5673 if (it
->what
== IT_CHARACTER
)
5675 /* Map via display table or translate control characters.
5676 IT->c, IT->len etc. have been set to the next character by
5677 the function call above. If we have a display table, and it
5678 contains an entry for IT->c, translate it. Don't do this if
5679 IT->c itself comes from a display table, otherwise we could
5680 end up in an infinite recursion. (An alternative could be to
5681 count the recursion depth of this function and signal an
5682 error when a certain maximum depth is reached.) Is it worth
5684 if (success_p
&& it
->dpvec
== NULL
)
5687 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5690 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5693 struct Lisp_Vector
*v
= XVECTOR (dv
);
5695 /* Return the first character from the display table
5696 entry, if not empty. If empty, don't display the
5697 current character. */
5700 it
->dpvec_char_len
= it
->len
;
5701 it
->dpvec
= v
->contents
;
5702 it
->dpend
= v
->contents
+ v
->size
;
5703 it
->current
.dpvec_index
= 0;
5704 it
->dpvec_face_id
= -1;
5705 it
->saved_face_id
= it
->face_id
;
5706 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5711 set_iterator_to_next (it
, 0);
5716 /* Translate control characters into `\003' or `^C' form.
5717 Control characters coming from a display table entry are
5718 currently not translated because we use IT->dpvec to hold
5719 the translation. This could easily be changed but I
5720 don't believe that it is worth doing.
5722 If it->multibyte_p is nonzero, non-printable non-ASCII
5723 characters are also translated to octal form.
5725 If it->multibyte_p is zero, eight-bit characters that
5726 don't have corresponding multibyte char code are also
5727 translated to octal form. */
5728 else if ((it
->c
< ' '
5729 ? (it
->area
!= TEXT_AREA
5730 /* In mode line, treat \n, \t like other crl chars. */
5733 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5734 || (it
->c
!= '\n' && it
->c
!= '\t'))
5736 ? (!CHAR_PRINTABLE_P (it
->c
)
5737 || (!NILP (Vnobreak_char_display
)
5738 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5739 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5741 && (! unibyte_display_via_language_environment
5742 || (DECODE_CHAR (unibyte
, it
->c
) <= 0xA0))))))
5744 /* IT->c is a control character which must be displayed
5745 either as '\003' or as `^C' where the '\\' and '^'
5746 can be defined in the display table. Fill
5747 IT->ctl_chars with glyphs for what we have to
5748 display. Then, set IT->dpvec to these glyphs. */
5751 int face_id
, lface_id
= 0 ;
5754 /* Handle control characters with ^. */
5756 if (it
->c
< 128 && it
->ctl_arrow_p
)
5760 g
= '^'; /* default glyph for Control */
5761 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5763 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5764 && GLYPH_CODE_CHAR_VALID_P (gc
))
5766 g
= GLYPH_CODE_CHAR (gc
);
5767 lface_id
= GLYPH_CODE_FACE (gc
);
5771 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5773 else if (it
->f
== last_escape_glyph_frame
5774 && it
->face_id
== last_escape_glyph_face_id
)
5776 face_id
= last_escape_glyph_merged_face_id
;
5780 /* Merge the escape-glyph face into the current face. */
5781 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5783 last_escape_glyph_frame
= it
->f
;
5784 last_escape_glyph_face_id
= it
->face_id
;
5785 last_escape_glyph_merged_face_id
= face_id
;
5788 XSETINT (it
->ctl_chars
[0], g
);
5789 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5791 goto display_control
;
5794 /* Handle non-break space in the mode where it only gets
5797 if (EQ (Vnobreak_char_display
, Qt
)
5800 /* Merge the no-break-space face into the current face. */
5801 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5805 XSETINT (it
->ctl_chars
[0], ' ');
5807 goto display_control
;
5810 /* Handle sequences that start with the "escape glyph". */
5812 /* the default escape glyph is \. */
5813 escape_glyph
= '\\';
5816 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5817 && GLYPH_CODE_CHAR_VALID_P (gc
))
5819 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5820 lface_id
= GLYPH_CODE_FACE (gc
);
5824 /* The display table specified a face.
5825 Merge it into face_id and also into escape_glyph. */
5826 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5829 else if (it
->f
== last_escape_glyph_frame
5830 && it
->face_id
== last_escape_glyph_face_id
)
5832 face_id
= last_escape_glyph_merged_face_id
;
5836 /* Merge the escape-glyph face into the current face. */
5837 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5839 last_escape_glyph_frame
= it
->f
;
5840 last_escape_glyph_face_id
= it
->face_id
;
5841 last_escape_glyph_merged_face_id
= face_id
;
5844 /* Handle soft hyphens in the mode where they only get
5847 if (EQ (Vnobreak_char_display
, Qt
)
5851 XSETINT (it
->ctl_chars
[0], '-');
5853 goto display_control
;
5856 /* Handle non-break space and soft hyphen
5857 with the escape glyph. */
5859 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5861 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5862 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5863 XSETINT (it
->ctl_chars
[1], it
->c
);
5865 goto display_control
;
5869 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5873 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5874 if (CHAR_BYTE8_P (it
->c
))
5876 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5879 else if (it
->c
< 256)
5886 /* It's an invalid character, which shouldn't
5887 happen actually, but due to bugs it may
5888 happen. Let's print the char as is, there's
5889 not much meaningful we can do with it. */
5891 str
[1] = it
->c
>> 8;
5892 str
[2] = it
->c
>> 16;
5893 str
[3] = it
->c
>> 24;
5897 for (i
= 0; i
< len
; i
++)
5900 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5901 /* Insert three more glyphs into IT->ctl_chars for
5902 the octal display of the character. */
5903 g
= ((str
[i
] >> 6) & 7) + '0';
5904 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5905 g
= ((str
[i
] >> 3) & 7) + '0';
5906 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5907 g
= (str
[i
] & 7) + '0';
5908 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5914 /* Set up IT->dpvec and return first character from it. */
5915 it
->dpvec_char_len
= it
->len
;
5916 it
->dpvec
= it
->ctl_chars
;
5917 it
->dpend
= it
->dpvec
+ ctl_len
;
5918 it
->current
.dpvec_index
= 0;
5919 it
->dpvec_face_id
= face_id
;
5920 it
->saved_face_id
= it
->face_id
;
5921 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5928 #ifdef HAVE_WINDOW_SYSTEM
5929 /* Adjust face id for a multibyte character. There are no multibyte
5930 character in unibyte text. */
5931 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5934 && FRAME_WINDOW_P (it
->f
))
5936 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5938 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5940 /* Automatic composition with glyph-string. */
5941 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5943 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5947 int pos
= (it
->s
? -1
5948 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5949 : IT_CHARPOS (*it
));
5951 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5956 /* Is this character the last one of a run of characters with
5957 box? If yes, set IT->end_of_box_run_p to 1. */
5961 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5963 int face_id
= underlying_face_id (it
);
5964 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5968 if (face
->box
== FACE_NO_BOX
)
5970 /* If the box comes from face properties in a
5971 display string, check faces in that string. */
5972 int string_face_id
= face_after_it_pos (it
);
5973 it
->end_of_box_run_p
5974 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5977 /* Otherwise, the box comes from the underlying face.
5978 If this is the last string character displayed, check
5979 the next buffer location. */
5980 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
5981 && (it
->current
.overlay_string_index
5982 == it
->n_overlay_strings
- 1))
5986 struct text_pos pos
= it
->current
.pos
;
5987 INC_TEXT_POS (pos
, it
->multibyte_p
);
5989 next_face_id
= face_at_buffer_position
5990 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
5991 it
->region_end_charpos
, &ignore
,
5992 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
5994 it
->end_of_box_run_p
5995 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6002 int face_id
= face_after_it_pos (it
);
6003 it
->end_of_box_run_p
6004 = (face_id
!= it
->face_id
6005 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6009 /* Value is 0 if end of buffer or string reached. */
6014 /* Move IT to the next display element.
6016 RESEAT_P non-zero means if called on a newline in buffer text,
6017 skip to the next visible line start.
6019 Functions get_next_display_element and set_iterator_to_next are
6020 separate because I find this arrangement easier to handle than a
6021 get_next_display_element function that also increments IT's
6022 position. The way it is we can first look at an iterator's current
6023 display element, decide whether it fits on a line, and if it does,
6024 increment the iterator position. The other way around we probably
6025 would either need a flag indicating whether the iterator has to be
6026 incremented the next time, or we would have to implement a
6027 decrement position function which would not be easy to write. */
6030 set_iterator_to_next (it
, reseat_p
)
6034 /* Reset flags indicating start and end of a sequence of characters
6035 with box. Reset them at the start of this function because
6036 moving the iterator to a new position might set them. */
6037 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6041 case GET_FROM_BUFFER
:
6042 /* The current display element of IT is a character from
6043 current_buffer. Advance in the buffer, and maybe skip over
6044 invisible lines that are so because of selective display. */
6045 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6046 reseat_at_next_visible_line_start (it
, 0);
6047 else if (it
->cmp_it
.id
>= 0)
6049 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6050 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6051 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6052 it
->cmp_it
.from
= it
->cmp_it
.to
;
6056 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6057 IT_BYTEPOS (*it
), it
->stop_charpos
,
6063 xassert (it
->len
!= 0);
6064 IT_BYTEPOS (*it
) += it
->len
;
6065 IT_CHARPOS (*it
) += 1;
6066 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6070 case GET_FROM_C_STRING
:
6071 /* Current display element of IT is from a C string. */
6072 IT_BYTEPOS (*it
) += it
->len
;
6073 IT_CHARPOS (*it
) += 1;
6076 case GET_FROM_DISPLAY_VECTOR
:
6077 /* Current display element of IT is from a display table entry.
6078 Advance in the display table definition. Reset it to null if
6079 end reached, and continue with characters from buffers/
6081 ++it
->current
.dpvec_index
;
6083 /* Restore face of the iterator to what they were before the
6084 display vector entry (these entries may contain faces). */
6085 it
->face_id
= it
->saved_face_id
;
6087 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6089 int recheck_faces
= it
->ellipsis_p
;
6092 it
->method
= GET_FROM_C_STRING
;
6093 else if (STRINGP (it
->string
))
6094 it
->method
= GET_FROM_STRING
;
6097 it
->method
= GET_FROM_BUFFER
;
6098 it
->object
= it
->w
->buffer
;
6102 it
->current
.dpvec_index
= -1;
6104 /* Skip over characters which were displayed via IT->dpvec. */
6105 if (it
->dpvec_char_len
< 0)
6106 reseat_at_next_visible_line_start (it
, 1);
6107 else if (it
->dpvec_char_len
> 0)
6109 if (it
->method
== GET_FROM_STRING
6110 && it
->n_overlay_strings
> 0)
6111 it
->ignore_overlay_strings_at_pos_p
= 1;
6112 it
->len
= it
->dpvec_char_len
;
6113 set_iterator_to_next (it
, reseat_p
);
6116 /* Maybe recheck faces after display vector */
6118 it
->stop_charpos
= IT_CHARPOS (*it
);
6122 case GET_FROM_STRING
:
6123 /* Current display element is a character from a Lisp string. */
6124 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6125 if (it
->cmp_it
.id
>= 0)
6127 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6128 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6129 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6130 it
->cmp_it
.from
= it
->cmp_it
.to
;
6134 composition_compute_stop_pos (&it
->cmp_it
,
6135 IT_STRING_CHARPOS (*it
),
6136 IT_STRING_BYTEPOS (*it
),
6137 it
->stop_charpos
, it
->string
);
6142 IT_STRING_BYTEPOS (*it
) += it
->len
;
6143 IT_STRING_CHARPOS (*it
) += 1;
6146 consider_string_end
:
6148 if (it
->current
.overlay_string_index
>= 0)
6150 /* IT->string is an overlay string. Advance to the
6151 next, if there is one. */
6152 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6155 next_overlay_string (it
);
6157 setup_for_ellipsis (it
, 0);
6162 /* IT->string is not an overlay string. If we reached
6163 its end, and there is something on IT->stack, proceed
6164 with what is on the stack. This can be either another
6165 string, this time an overlay string, or a buffer. */
6166 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6170 if (it
->method
== GET_FROM_STRING
)
6171 goto consider_string_end
;
6176 case GET_FROM_IMAGE
:
6177 case GET_FROM_STRETCH
:
6178 /* The position etc with which we have to proceed are on
6179 the stack. The position may be at the end of a string,
6180 if the `display' property takes up the whole string. */
6181 xassert (it
->sp
> 0);
6183 if (it
->method
== GET_FROM_STRING
)
6184 goto consider_string_end
;
6188 /* There are no other methods defined, so this should be a bug. */
6192 xassert (it
->method
!= GET_FROM_STRING
6193 || (STRINGP (it
->string
)
6194 && IT_STRING_CHARPOS (*it
) >= 0));
6197 /* Load IT's display element fields with information about the next
6198 display element which comes from a display table entry or from the
6199 result of translating a control character to one of the forms `^C'
6202 IT->dpvec holds the glyphs to return as characters.
6203 IT->saved_face_id holds the face id before the display vector--
6204 it is restored into IT->face_idin set_iterator_to_next. */
6207 next_element_from_display_vector (it
)
6213 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6215 it
->face_id
= it
->saved_face_id
;
6217 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6218 That seemed totally bogus - so I changed it... */
6219 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6221 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6223 it
->c
= GLYPH_CODE_CHAR (gc
);
6224 it
->len
= CHAR_BYTES (it
->c
);
6226 /* The entry may contain a face id to use. Such a face id is
6227 the id of a Lisp face, not a realized face. A face id of
6228 zero means no face is specified. */
6229 if (it
->dpvec_face_id
>= 0)
6230 it
->face_id
= it
->dpvec_face_id
;
6233 int lface_id
= GLYPH_CODE_FACE (gc
);
6235 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6240 /* Display table entry is invalid. Return a space. */
6241 it
->c
= ' ', it
->len
= 1;
6243 /* Don't change position and object of the iterator here. They are
6244 still the values of the character that had this display table
6245 entry or was translated, and that's what we want. */
6246 it
->what
= IT_CHARACTER
;
6251 /* Load IT with the next display element from Lisp string IT->string.
6252 IT->current.string_pos is the current position within the string.
6253 If IT->current.overlay_string_index >= 0, the Lisp string is an
6257 next_element_from_string (it
)
6260 struct text_pos position
;
6262 xassert (STRINGP (it
->string
));
6263 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6264 position
= it
->current
.string_pos
;
6266 /* Time to check for invisible text? */
6267 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6268 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6272 /* Since a handler may have changed IT->method, we must
6274 return GET_NEXT_DISPLAY_ELEMENT (it
);
6277 if (it
->current
.overlay_string_index
>= 0)
6279 /* Get the next character from an overlay string. In overlay
6280 strings, There is no field width or padding with spaces to
6282 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6287 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6288 IT_STRING_BYTEPOS (*it
))
6289 && next_element_from_composition (it
))
6293 else if (STRING_MULTIBYTE (it
->string
))
6295 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6296 const unsigned char *s
= (SDATA (it
->string
)
6297 + IT_STRING_BYTEPOS (*it
));
6298 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6302 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6308 /* Get the next character from a Lisp string that is not an
6309 overlay string. Such strings come from the mode line, for
6310 example. We may have to pad with spaces, or truncate the
6311 string. See also next_element_from_c_string. */
6312 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6317 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6319 /* Pad with spaces. */
6320 it
->c
= ' ', it
->len
= 1;
6321 CHARPOS (position
) = BYTEPOS (position
) = -1;
6323 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6324 IT_STRING_BYTEPOS (*it
))
6325 && next_element_from_composition (it
))
6329 else if (STRING_MULTIBYTE (it
->string
))
6331 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6332 const unsigned char *s
= (SDATA (it
->string
)
6333 + IT_STRING_BYTEPOS (*it
));
6334 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6338 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6343 /* Record what we have and where it came from. */
6344 it
->what
= IT_CHARACTER
;
6345 it
->object
= it
->string
;
6346 it
->position
= position
;
6351 /* Load IT with next display element from C string IT->s.
6352 IT->string_nchars is the maximum number of characters to return
6353 from the string. IT->end_charpos may be greater than
6354 IT->string_nchars when this function is called, in which case we
6355 may have to return padding spaces. Value is zero if end of string
6356 reached, including padding spaces. */
6359 next_element_from_c_string (it
)
6365 it
->what
= IT_CHARACTER
;
6366 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6369 /* IT's position can be greater IT->string_nchars in case a field
6370 width or precision has been specified when the iterator was
6372 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6374 /* End of the game. */
6378 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6380 /* Pad with spaces. */
6381 it
->c
= ' ', it
->len
= 1;
6382 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6384 else if (it
->multibyte_p
)
6386 /* Implementation note: The calls to strlen apparently aren't a
6387 performance problem because there is no noticeable performance
6388 difference between Emacs running in unibyte or multibyte mode. */
6389 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6390 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6394 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6400 /* Set up IT to return characters from an ellipsis, if appropriate.
6401 The definition of the ellipsis glyphs may come from a display table
6402 entry. This function Fills IT with the first glyph from the
6403 ellipsis if an ellipsis is to be displayed. */
6406 next_element_from_ellipsis (it
)
6409 if (it
->selective_display_ellipsis_p
)
6410 setup_for_ellipsis (it
, it
->len
);
6413 /* The face at the current position may be different from the
6414 face we find after the invisible text. Remember what it
6415 was in IT->saved_face_id, and signal that it's there by
6416 setting face_before_selective_p. */
6417 it
->saved_face_id
= it
->face_id
;
6418 it
->method
= GET_FROM_BUFFER
;
6419 it
->object
= it
->w
->buffer
;
6420 reseat_at_next_visible_line_start (it
, 1);
6421 it
->face_before_selective_p
= 1;
6424 return GET_NEXT_DISPLAY_ELEMENT (it
);
6428 /* Deliver an image display element. The iterator IT is already
6429 filled with image information (done in handle_display_prop). Value
6434 next_element_from_image (it
)
6437 it
->what
= IT_IMAGE
;
6442 /* Fill iterator IT with next display element from a stretch glyph
6443 property. IT->object is the value of the text property. Value is
6447 next_element_from_stretch (it
)
6450 it
->what
= IT_STRETCH
;
6455 /* Load IT with the next display element from current_buffer. Value
6456 is zero if end of buffer reached. IT->stop_charpos is the next
6457 position at which to stop and check for text properties or buffer
6461 next_element_from_buffer (it
)
6466 xassert (IT_CHARPOS (*it
) >= BEGV
);
6468 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6470 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6472 int overlay_strings_follow_p
;
6474 /* End of the game, except when overlay strings follow that
6475 haven't been returned yet. */
6476 if (it
->overlay_strings_at_end_processed_p
)
6477 overlay_strings_follow_p
= 0;
6480 it
->overlay_strings_at_end_processed_p
= 1;
6481 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6484 if (overlay_strings_follow_p
)
6485 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6489 it
->position
= it
->current
.pos
;
6496 return GET_NEXT_DISPLAY_ELEMENT (it
);
6501 /* No face changes, overlays etc. in sight, so just return a
6502 character from current_buffer. */
6505 /* Maybe run the redisplay end trigger hook. Performance note:
6506 This doesn't seem to cost measurable time. */
6507 if (it
->redisplay_end_trigger_charpos
6509 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6510 run_redisplay_end_trigger_hook (it
);
6512 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
))
6513 && next_element_from_composition (it
))
6518 /* Get the next character, maybe multibyte. */
6519 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6520 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6521 it
->c
= STRING_CHAR_AND_LENGTH (p
, 0, it
->len
);
6523 it
->c
= *p
, it
->len
= 1;
6525 /* Record what we have and where it came from. */
6526 it
->what
= IT_CHARACTER
;
6527 it
->object
= it
->w
->buffer
;
6528 it
->position
= it
->current
.pos
;
6530 /* Normally we return the character found above, except when we
6531 really want to return an ellipsis for selective display. */
6536 /* A value of selective > 0 means hide lines indented more
6537 than that number of columns. */
6538 if (it
->selective
> 0
6539 && IT_CHARPOS (*it
) + 1 < ZV
6540 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6541 IT_BYTEPOS (*it
) + 1,
6542 (double) it
->selective
)) /* iftc */
6544 success_p
= next_element_from_ellipsis (it
);
6545 it
->dpvec_char_len
= -1;
6548 else if (it
->c
== '\r' && it
->selective
== -1)
6550 /* A value of selective == -1 means that everything from the
6551 CR to the end of the line is invisible, with maybe an
6552 ellipsis displayed for it. */
6553 success_p
= next_element_from_ellipsis (it
);
6554 it
->dpvec_char_len
= -1;
6559 /* Value is zero if end of buffer reached. */
6560 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6565 /* Run the redisplay end trigger hook for IT. */
6568 run_redisplay_end_trigger_hook (it
)
6571 Lisp_Object args
[3];
6573 /* IT->glyph_row should be non-null, i.e. we should be actually
6574 displaying something, or otherwise we should not run the hook. */
6575 xassert (it
->glyph_row
);
6577 /* Set up hook arguments. */
6578 args
[0] = Qredisplay_end_trigger_functions
;
6579 args
[1] = it
->window
;
6580 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6581 it
->redisplay_end_trigger_charpos
= 0;
6583 /* Since we are *trying* to run these functions, don't try to run
6584 them again, even if they get an error. */
6585 it
->w
->redisplay_end_trigger
= Qnil
;
6586 Frun_hook_with_args (3, args
);
6588 /* Notice if it changed the face of the character we are on. */
6589 handle_face_prop (it
);
6593 /* Deliver a composition display element. Unlike the other
6594 next_element_from_XXX, this function is not registered in the array
6595 get_next_element[]. It is called from next_element_from_buffer and
6596 next_element_from_string when necessary. */
6599 next_element_from_composition (it
)
6602 it
->what
= IT_COMPOSITION
;
6603 it
->len
= it
->cmp_it
.nbytes
;
6604 if (STRINGP (it
->string
))
6608 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6609 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6612 it
->position
= it
->current
.string_pos
;
6613 it
->object
= it
->string
;
6614 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6615 IT_STRING_BYTEPOS (*it
), it
->string
);
6621 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6622 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6625 it
->position
= it
->current
.pos
;
6626 it
->object
= it
->w
->buffer
;
6627 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6628 IT_BYTEPOS (*it
), Qnil
);
6635 /***********************************************************************
6636 Moving an iterator without producing glyphs
6637 ***********************************************************************/
6639 /* Check if iterator is at a position corresponding to a valid buffer
6640 position after some move_it_ call. */
6642 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6643 ((it)->method == GET_FROM_STRING \
6644 ? IT_STRING_CHARPOS (*it) == 0 \
6648 /* Move iterator IT to a specified buffer or X position within one
6649 line on the display without producing glyphs.
6651 OP should be a bit mask including some or all of these bits:
6652 MOVE_TO_X: Stop on reaching x-position TO_X.
6653 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6654 Regardless of OP's value, stop in reaching the end of the display line.
6656 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6657 This means, in particular, that TO_X includes window's horizontal
6660 The return value has several possible values that
6661 say what condition caused the scan to stop:
6663 MOVE_POS_MATCH_OR_ZV
6664 - when TO_POS or ZV was reached.
6667 -when TO_X was reached before TO_POS or ZV were reached.
6670 - when we reached the end of the display area and the line must
6674 - when we reached the end of the display area and the line is
6678 - when we stopped at a line end, i.e. a newline or a CR and selective
6681 static enum move_it_result
6682 move_it_in_display_line_to (struct it
*it
,
6683 EMACS_INT to_charpos
, int to_x
,
6684 enum move_operation_enum op
)
6686 enum move_it_result result
= MOVE_UNDEFINED
;
6687 struct glyph_row
*saved_glyph_row
;
6688 struct it wrap_it
, atpos_it
, atx_it
;
6691 /* Don't produce glyphs in produce_glyphs. */
6692 saved_glyph_row
= it
->glyph_row
;
6693 it
->glyph_row
= NULL
;
6695 /* Use wrap_it to save a copy of IT wherever a word wrap could
6696 occur. Use atpos_it to save a copy of IT at the desired buffer
6697 position, if found, so that we can scan ahead and check if the
6698 word later overshoots the window edge. Use atx_it similarly, for
6704 #define BUFFER_POS_REACHED_P() \
6705 ((op & MOVE_TO_POS) != 0 \
6706 && BUFFERP (it->object) \
6707 && IT_CHARPOS (*it) >= to_charpos \
6708 && (it->method == GET_FROM_BUFFER \
6709 || (it->method == GET_FROM_DISPLAY_VECTOR \
6710 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6712 /* If there's a line-/wrap-prefix, handle it. */
6713 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6714 && it
->current_y
< it
->last_visible_y
)
6715 handle_line_prefix (it
);
6719 int x
, i
, ascent
= 0, descent
= 0;
6721 /* Utility macro to reset an iterator with x, ascent, and descent. */
6722 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6723 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6724 (IT)->max_descent = descent)
6726 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6728 if ((op
& MOVE_TO_POS
) != 0
6729 && BUFFERP (it
->object
)
6730 && it
->method
== GET_FROM_BUFFER
6731 && IT_CHARPOS (*it
) > to_charpos
)
6733 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6735 result
= MOVE_POS_MATCH_OR_ZV
;
6738 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6739 /* If wrap_it is valid, the current position might be in a
6740 word that is wrapped. So, save the iterator in
6741 atpos_it and continue to see if wrapping happens. */
6745 /* Stop when ZV reached.
6746 We used to stop here when TO_CHARPOS reached as well, but that is
6747 too soon if this glyph does not fit on this line. So we handle it
6748 explicitly below. */
6749 if (!get_next_display_element (it
))
6751 result
= MOVE_POS_MATCH_OR_ZV
;
6755 if (it
->line_wrap
== TRUNCATE
)
6757 if (BUFFER_POS_REACHED_P ())
6759 result
= MOVE_POS_MATCH_OR_ZV
;
6765 if (it
->line_wrap
== WORD_WRAP
)
6767 if (IT_DISPLAYING_WHITESPACE (it
))
6771 /* We have reached a glyph that follows one or more
6772 whitespace characters. If the position is
6773 already found, we are done. */
6774 if (atpos_it
.sp
>= 0)
6777 result
= MOVE_POS_MATCH_OR_ZV
;
6783 result
= MOVE_X_REACHED
;
6786 /* Otherwise, we can wrap here. */
6793 /* Remember the line height for the current line, in case
6794 the next element doesn't fit on the line. */
6795 ascent
= it
->max_ascent
;
6796 descent
= it
->max_descent
;
6798 /* The call to produce_glyphs will get the metrics of the
6799 display element IT is loaded with. Record the x-position
6800 before this display element, in case it doesn't fit on the
6804 PRODUCE_GLYPHS (it
);
6806 if (it
->area
!= TEXT_AREA
)
6808 set_iterator_to_next (it
, 1);
6812 /* The number of glyphs we get back in IT->nglyphs will normally
6813 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6814 character on a terminal frame, or (iii) a line end. For the
6815 second case, IT->nglyphs - 1 padding glyphs will be present
6816 (on X frames, there is only one glyph produced for a
6817 composite character.
6819 The behavior implemented below means, for continuation lines,
6820 that as many spaces of a TAB as fit on the current line are
6821 displayed there. For terminal frames, as many glyphs of a
6822 multi-glyph character are displayed in the current line, too.
6823 This is what the old redisplay code did, and we keep it that
6824 way. Under X, the whole shape of a complex character must
6825 fit on the line or it will be completely displayed in the
6828 Note that both for tabs and padding glyphs, all glyphs have
6832 /* More than one glyph or glyph doesn't fit on line. All
6833 glyphs have the same width. */
6834 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6836 int x_before_this_char
= x
;
6837 int hpos_before_this_char
= it
->hpos
;
6839 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6841 new_x
= x
+ single_glyph_width
;
6843 /* We want to leave anything reaching TO_X to the caller. */
6844 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6846 if (BUFFER_POS_REACHED_P ())
6848 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6849 goto buffer_pos_reached
;
6850 if (atpos_it
.sp
< 0)
6853 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6858 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6861 result
= MOVE_X_REACHED
;
6867 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6872 if (/* Lines are continued. */
6873 it
->line_wrap
!= TRUNCATE
6874 && (/* And glyph doesn't fit on the line. */
6875 new_x
> it
->last_visible_x
6876 /* Or it fits exactly and we're on a window
6878 || (new_x
== it
->last_visible_x
6879 && FRAME_WINDOW_P (it
->f
))))
6881 if (/* IT->hpos == 0 means the very first glyph
6882 doesn't fit on the line, e.g. a wide image. */
6884 || (new_x
== it
->last_visible_x
6885 && FRAME_WINDOW_P (it
->f
)))
6888 it
->current_x
= new_x
;
6890 /* The character's last glyph just barely fits
6892 if (i
== it
->nglyphs
- 1)
6894 /* If this is the destination position,
6895 return a position *before* it in this row,
6896 now that we know it fits in this row. */
6897 if (BUFFER_POS_REACHED_P ())
6899 if (it
->line_wrap
!= WORD_WRAP
6902 it
->hpos
= hpos_before_this_char
;
6903 it
->current_x
= x_before_this_char
;
6904 result
= MOVE_POS_MATCH_OR_ZV
;
6907 if (it
->line_wrap
== WORD_WRAP
6911 atpos_it
.current_x
= x_before_this_char
;
6912 atpos_it
.hpos
= hpos_before_this_char
;
6916 set_iterator_to_next (it
, 1);
6917 /* One graphical terminals, newlines may
6918 "overflow" into the fringe if
6919 overflow-newline-into-fringe is non-nil.
6920 On text-only terminals, newlines may
6921 overflow into the last glyph on the
6923 if (!FRAME_WINDOW_P (it
->f
)
6924 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6926 if (!get_next_display_element (it
))
6928 result
= MOVE_POS_MATCH_OR_ZV
;
6931 if (BUFFER_POS_REACHED_P ())
6933 if (ITERATOR_AT_END_OF_LINE_P (it
))
6934 result
= MOVE_POS_MATCH_OR_ZV
;
6936 result
= MOVE_LINE_CONTINUED
;
6939 if (ITERATOR_AT_END_OF_LINE_P (it
))
6941 result
= MOVE_NEWLINE_OR_CR
;
6948 IT_RESET_X_ASCENT_DESCENT (it
);
6950 if (wrap_it
.sp
>= 0)
6957 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6959 result
= MOVE_LINE_CONTINUED
;
6963 if (BUFFER_POS_REACHED_P ())
6965 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6966 goto buffer_pos_reached
;
6967 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6970 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6974 if (new_x
> it
->first_visible_x
)
6976 /* Glyph is visible. Increment number of glyphs that
6977 would be displayed. */
6982 if (result
!= MOVE_UNDEFINED
)
6985 else if (BUFFER_POS_REACHED_P ())
6988 IT_RESET_X_ASCENT_DESCENT (it
);
6989 result
= MOVE_POS_MATCH_OR_ZV
;
6992 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6994 /* Stop when TO_X specified and reached. This check is
6995 necessary here because of lines consisting of a line end,
6996 only. The line end will not produce any glyphs and we
6997 would never get MOVE_X_REACHED. */
6998 xassert (it
->nglyphs
== 0);
6999 result
= MOVE_X_REACHED
;
7003 /* Is this a line end? If yes, we're done. */
7004 if (ITERATOR_AT_END_OF_LINE_P (it
))
7006 result
= MOVE_NEWLINE_OR_CR
;
7010 /* The current display element has been consumed. Advance
7012 set_iterator_to_next (it
, 1);
7014 /* Stop if lines are truncated and IT's current x-position is
7015 past the right edge of the window now. */
7016 if (it
->line_wrap
== TRUNCATE
7017 && it
->current_x
>= it
->last_visible_x
)
7019 if (!FRAME_WINDOW_P (it
->f
)
7020 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7022 if (!get_next_display_element (it
)
7023 || BUFFER_POS_REACHED_P ())
7025 result
= MOVE_POS_MATCH_OR_ZV
;
7028 if (ITERATOR_AT_END_OF_LINE_P (it
))
7030 result
= MOVE_NEWLINE_OR_CR
;
7034 result
= MOVE_LINE_TRUNCATED
;
7037 #undef IT_RESET_X_ASCENT_DESCENT
7040 #undef BUFFER_POS_REACHED_P
7042 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7043 restore the saved iterator. */
7044 if (atpos_it
.sp
>= 0)
7046 else if (atx_it
.sp
>= 0)
7051 /* Restore the iterator settings altered at the beginning of this
7053 it
->glyph_row
= saved_glyph_row
;
7057 /* For external use. */
7059 move_it_in_display_line (struct it
*it
,
7060 EMACS_INT to_charpos
, int to_x
,
7061 enum move_operation_enum op
)
7063 if (it
->line_wrap
== WORD_WRAP
7064 && (op
& MOVE_TO_X
))
7066 struct it save_it
= *it
;
7067 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7068 /* When word-wrap is on, TO_X may lie past the end
7069 of a wrapped line. Then it->current is the
7070 character on the next line, so backtrack to the
7071 space before the wrap point. */
7072 if (skip
== MOVE_LINE_CONTINUED
)
7074 int prev_x
= max (it
->current_x
- 1, 0);
7076 move_it_in_display_line_to
7077 (it
, -1, prev_x
, MOVE_TO_X
);
7081 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7085 /* Move IT forward until it satisfies one or more of the criteria in
7086 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7088 OP is a bit-mask that specifies where to stop, and in particular,
7089 which of those four position arguments makes a difference. See the
7090 description of enum move_operation_enum.
7092 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7093 screen line, this function will set IT to the next position >
7097 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7099 int to_charpos
, to_x
, to_y
, to_vpos
;
7102 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7103 int line_height
, line_start_x
= 0, reached
= 0;
7107 if (op
& MOVE_TO_VPOS
)
7109 /* If no TO_CHARPOS and no TO_X specified, stop at the
7110 start of the line TO_VPOS. */
7111 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7113 if (it
->vpos
== to_vpos
)
7119 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7123 /* TO_VPOS >= 0 means stop at TO_X in the line at
7124 TO_VPOS, or at TO_POS, whichever comes first. */
7125 if (it
->vpos
== to_vpos
)
7131 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7133 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7138 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7140 /* We have reached TO_X but not in the line we want. */
7141 skip
= move_it_in_display_line_to (it
, to_charpos
,
7143 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7151 else if (op
& MOVE_TO_Y
)
7153 struct it it_backup
;
7155 if (it
->line_wrap
== WORD_WRAP
)
7158 /* TO_Y specified means stop at TO_X in the line containing
7159 TO_Y---or at TO_CHARPOS if this is reached first. The
7160 problem is that we can't really tell whether the line
7161 contains TO_Y before we have completely scanned it, and
7162 this may skip past TO_X. What we do is to first scan to
7165 If TO_X is not specified, use a TO_X of zero. The reason
7166 is to make the outcome of this function more predictable.
7167 If we didn't use TO_X == 0, we would stop at the end of
7168 the line which is probably not what a caller would expect
7170 skip
= move_it_in_display_line_to
7171 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7172 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7174 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7175 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7177 else if (skip
== MOVE_X_REACHED
)
7179 /* If TO_X was reached, we want to know whether TO_Y is
7180 in the line. We know this is the case if the already
7181 scanned glyphs make the line tall enough. Otherwise,
7182 we must check by scanning the rest of the line. */
7183 line_height
= it
->max_ascent
+ it
->max_descent
;
7184 if (to_y
>= it
->current_y
7185 && to_y
< it
->current_y
+ line_height
)
7191 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7192 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7194 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7195 line_height
= it
->max_ascent
+ it
->max_descent
;
7196 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7198 if (to_y
>= it
->current_y
7199 && to_y
< it
->current_y
+ line_height
)
7201 /* If TO_Y is in this line and TO_X was reached
7202 above, we scanned too far. We have to restore
7203 IT's settings to the ones before skipping. */
7210 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7216 /* Check whether TO_Y is in this line. */
7217 line_height
= it
->max_ascent
+ it
->max_descent
;
7218 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7220 if (to_y
>= it
->current_y
7221 && to_y
< it
->current_y
+ line_height
)
7223 /* When word-wrap is on, TO_X may lie past the end
7224 of a wrapped line. Then it->current is the
7225 character on the next line, so backtrack to the
7226 space before the wrap point. */
7227 if (skip
== MOVE_LINE_CONTINUED
7228 && it
->line_wrap
== WORD_WRAP
)
7230 int prev_x
= max (it
->current_x
- 1, 0);
7232 skip
= move_it_in_display_line_to
7233 (it
, -1, prev_x
, MOVE_TO_X
);
7242 else if (BUFFERP (it
->object
)
7243 && (it
->method
== GET_FROM_BUFFER
7244 || it
->method
== GET_FROM_STRETCH
)
7245 && IT_CHARPOS (*it
) >= to_charpos
)
7246 skip
= MOVE_POS_MATCH_OR_ZV
;
7248 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7252 case MOVE_POS_MATCH_OR_ZV
:
7256 case MOVE_NEWLINE_OR_CR
:
7257 set_iterator_to_next (it
, 1);
7258 it
->continuation_lines_width
= 0;
7261 case MOVE_LINE_TRUNCATED
:
7262 it
->continuation_lines_width
= 0;
7263 reseat_at_next_visible_line_start (it
, 0);
7264 if ((op
& MOVE_TO_POS
) != 0
7265 && IT_CHARPOS (*it
) > to_charpos
)
7272 case MOVE_LINE_CONTINUED
:
7273 /* For continued lines ending in a tab, some of the glyphs
7274 associated with the tab are displayed on the current
7275 line. Since it->current_x does not include these glyphs,
7276 we use it->last_visible_x instead. */
7279 it
->continuation_lines_width
+= it
->last_visible_x
;
7280 /* When moving by vpos, ensure that the iterator really
7281 advances to the next line (bug#847, bug#969). Fixme:
7282 do we need to do this in other circumstances? */
7283 if (it
->current_x
!= it
->last_visible_x
7284 && (op
& MOVE_TO_VPOS
)
7285 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7287 line_start_x
= it
->current_x
+ it
->pixel_width
7288 - it
->last_visible_x
;
7289 set_iterator_to_next (it
, 0);
7293 it
->continuation_lines_width
+= it
->current_x
;
7300 /* Reset/increment for the next run. */
7301 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7302 it
->current_x
= line_start_x
;
7305 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7307 last_height
= it
->max_ascent
+ it
->max_descent
;
7308 last_max_ascent
= it
->max_ascent
;
7309 it
->max_ascent
= it
->max_descent
= 0;
7314 /* On text terminals, we may stop at the end of a line in the middle
7315 of a multi-character glyph. If the glyph itself is continued,
7316 i.e. it is actually displayed on the next line, don't treat this
7317 stopping point as valid; move to the next line instead (unless
7318 that brings us offscreen). */
7319 if (!FRAME_WINDOW_P (it
->f
)
7321 && IT_CHARPOS (*it
) == to_charpos
7322 && it
->what
== IT_CHARACTER
7324 && it
->line_wrap
== WINDOW_WRAP
7325 && it
->current_x
== it
->last_visible_x
- 1
7328 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7330 it
->continuation_lines_width
+= it
->current_x
;
7331 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7332 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7334 last_height
= it
->max_ascent
+ it
->max_descent
;
7335 last_max_ascent
= it
->max_ascent
;
7338 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7342 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7344 If DY > 0, move IT backward at least that many pixels. DY = 0
7345 means move IT backward to the preceding line start or BEGV. This
7346 function may move over more than DY pixels if IT->current_y - DY
7347 ends up in the middle of a line; in this case IT->current_y will be
7348 set to the top of the line moved to. */
7351 move_it_vertically_backward (it
, dy
)
7362 start_pos
= IT_CHARPOS (*it
);
7364 /* Estimate how many newlines we must move back. */
7365 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7367 /* Set the iterator's position that many lines back. */
7368 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7369 back_to_previous_visible_line_start (it
);
7371 /* Reseat the iterator here. When moving backward, we don't want
7372 reseat to skip forward over invisible text, set up the iterator
7373 to deliver from overlay strings at the new position etc. So,
7374 use reseat_1 here. */
7375 reseat_1 (it
, it
->current
.pos
, 1);
7377 /* We are now surely at a line start. */
7378 it
->current_x
= it
->hpos
= 0;
7379 it
->continuation_lines_width
= 0;
7381 /* Move forward and see what y-distance we moved. First move to the
7382 start of the next line so that we get its height. We need this
7383 height to be able to tell whether we reached the specified
7386 it2
.max_ascent
= it2
.max_descent
= 0;
7389 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7390 MOVE_TO_POS
| MOVE_TO_VPOS
);
7392 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7393 xassert (IT_CHARPOS (*it
) >= BEGV
);
7396 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7397 xassert (IT_CHARPOS (*it
) >= BEGV
);
7398 /* H is the actual vertical distance from the position in *IT
7399 and the starting position. */
7400 h
= it2
.current_y
- it
->current_y
;
7401 /* NLINES is the distance in number of lines. */
7402 nlines
= it2
.vpos
- it
->vpos
;
7404 /* Correct IT's y and vpos position
7405 so that they are relative to the starting point. */
7411 /* DY == 0 means move to the start of the screen line. The
7412 value of nlines is > 0 if continuation lines were involved. */
7414 move_it_by_lines (it
, nlines
, 1);
7418 /* The y-position we try to reach, relative to *IT.
7419 Note that H has been subtracted in front of the if-statement. */
7420 int target_y
= it
->current_y
+ h
- dy
;
7421 int y0
= it3
.current_y
;
7422 int y1
= line_bottom_y (&it3
);
7423 int line_height
= y1
- y0
;
7425 /* If we did not reach target_y, try to move further backward if
7426 we can. If we moved too far backward, try to move forward. */
7427 if (target_y
< it
->current_y
7428 /* This is heuristic. In a window that's 3 lines high, with
7429 a line height of 13 pixels each, recentering with point
7430 on the bottom line will try to move -39/2 = 19 pixels
7431 backward. Try to avoid moving into the first line. */
7432 && (it
->current_y
- target_y
7433 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7434 && IT_CHARPOS (*it
) > BEGV
)
7436 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7437 target_y
- it
->current_y
));
7438 dy
= it
->current_y
- target_y
;
7439 goto move_further_back
;
7441 else if (target_y
>= it
->current_y
+ line_height
7442 && IT_CHARPOS (*it
) < ZV
)
7444 /* Should move forward by at least one line, maybe more.
7446 Note: Calling move_it_by_lines can be expensive on
7447 terminal frames, where compute_motion is used (via
7448 vmotion) to do the job, when there are very long lines
7449 and truncate-lines is nil. That's the reason for
7450 treating terminal frames specially here. */
7452 if (!FRAME_WINDOW_P (it
->f
))
7453 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7458 move_it_by_lines (it
, 1, 1);
7460 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7467 /* Move IT by a specified amount of pixel lines DY. DY negative means
7468 move backwards. DY = 0 means move to start of screen line. At the
7469 end, IT will be on the start of a screen line. */
7472 move_it_vertically (it
, dy
)
7477 move_it_vertically_backward (it
, -dy
);
7480 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7481 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7482 MOVE_TO_POS
| MOVE_TO_Y
);
7483 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7485 /* If buffer ends in ZV without a newline, move to the start of
7486 the line to satisfy the post-condition. */
7487 if (IT_CHARPOS (*it
) == ZV
7489 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7490 move_it_by_lines (it
, 0, 0);
7495 /* Move iterator IT past the end of the text line it is in. */
7498 move_it_past_eol (it
)
7501 enum move_it_result rc
;
7503 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7504 if (rc
== MOVE_NEWLINE_OR_CR
)
7505 set_iterator_to_next (it
, 0);
7509 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7510 negative means move up. DVPOS == 0 means move to the start of the
7511 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7512 NEED_Y_P is zero, IT->current_y will be left unchanged.
7514 Further optimization ideas: If we would know that IT->f doesn't use
7515 a face with proportional font, we could be faster for
7516 truncate-lines nil. */
7519 move_it_by_lines (it
, dvpos
, need_y_p
)
7521 int dvpos
, need_y_p
;
7523 struct position pos
;
7525 /* The commented-out optimization uses vmotion on terminals. This
7526 gives bad results, because elements like it->what, on which
7527 callers such as pos_visible_p rely, aren't updated. */
7528 /* if (!FRAME_WINDOW_P (it->f))
7530 struct text_pos textpos;
7532 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7533 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7534 reseat (it, textpos, 1);
7535 it->vpos += pos.vpos;
7536 it->current_y += pos.vpos;
7542 /* DVPOS == 0 means move to the start of the screen line. */
7543 move_it_vertically_backward (it
, 0);
7544 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7545 /* Let next call to line_bottom_y calculate real line height */
7550 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7551 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7552 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7557 int start_charpos
, i
;
7559 /* Start at the beginning of the screen line containing IT's
7560 position. This may actually move vertically backwards,
7561 in case of overlays, so adjust dvpos accordingly. */
7563 move_it_vertically_backward (it
, 0);
7566 /* Go back -DVPOS visible lines and reseat the iterator there. */
7567 start_charpos
= IT_CHARPOS (*it
);
7568 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7569 back_to_previous_visible_line_start (it
);
7570 reseat (it
, it
->current
.pos
, 1);
7572 /* Move further back if we end up in a string or an image. */
7573 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7575 /* First try to move to start of display line. */
7577 move_it_vertically_backward (it
, 0);
7579 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7581 /* If start of line is still in string or image,
7582 move further back. */
7583 back_to_previous_visible_line_start (it
);
7584 reseat (it
, it
->current
.pos
, 1);
7588 it
->current_x
= it
->hpos
= 0;
7590 /* Above call may have moved too far if continuation lines
7591 are involved. Scan forward and see if it did. */
7593 it2
.vpos
= it2
.current_y
= 0;
7594 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7595 it
->vpos
-= it2
.vpos
;
7596 it
->current_y
-= it2
.current_y
;
7597 it
->current_x
= it
->hpos
= 0;
7599 /* If we moved too far back, move IT some lines forward. */
7600 if (it2
.vpos
> -dvpos
)
7602 int delta
= it2
.vpos
+ dvpos
;
7604 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7605 /* Move back again if we got too far ahead. */
7606 if (IT_CHARPOS (*it
) >= start_charpos
)
7612 /* Return 1 if IT points into the middle of a display vector. */
7615 in_display_vector_p (it
)
7618 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7619 && it
->current
.dpvec_index
> 0
7620 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7624 /***********************************************************************
7626 ***********************************************************************/
7629 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7633 add_to_log (format
, arg1
, arg2
)
7635 Lisp_Object arg1
, arg2
;
7637 Lisp_Object args
[3];
7638 Lisp_Object msg
, fmt
;
7641 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7644 /* Do nothing if called asynchronously. Inserting text into
7645 a buffer may call after-change-functions and alike and
7646 that would means running Lisp asynchronously. */
7647 if (handling_signal
)
7651 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7653 args
[0] = fmt
= build_string (format
);
7656 msg
= Fformat (3, args
);
7658 len
= SBYTES (msg
) + 1;
7659 SAFE_ALLOCA (buffer
, char *, len
);
7660 bcopy (SDATA (msg
), buffer
, len
);
7662 message_dolog (buffer
, len
- 1, 1, 0);
7669 /* Output a newline in the *Messages* buffer if "needs" one. */
7672 message_log_maybe_newline ()
7674 if (message_log_need_newline
)
7675 message_dolog ("", 0, 1, 0);
7679 /* Add a string M of length NBYTES to the message log, optionally
7680 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7681 nonzero, means interpret the contents of M as multibyte. This
7682 function calls low-level routines in order to bypass text property
7683 hooks, etc. which might not be safe to run.
7685 This may GC (insert may run before/after change hooks),
7686 so the buffer M must NOT point to a Lisp string. */
7689 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7691 int nbytes
, nlflag
, multibyte
;
7693 if (!NILP (Vmemory_full
))
7696 if (!NILP (Vmessage_log_max
))
7698 struct buffer
*oldbuf
;
7699 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7700 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7701 int point_at_end
= 0;
7703 Lisp_Object old_deactivate_mark
, tem
;
7704 struct gcpro gcpro1
;
7706 old_deactivate_mark
= Vdeactivate_mark
;
7707 oldbuf
= current_buffer
;
7708 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7709 current_buffer
->undo_list
= Qt
;
7711 oldpoint
= message_dolog_marker1
;
7712 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7713 oldbegv
= message_dolog_marker2
;
7714 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7715 oldzv
= message_dolog_marker3
;
7716 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7717 GCPRO1 (old_deactivate_mark
);
7725 BEGV_BYTE
= BEG_BYTE
;
7728 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7730 /* Insert the string--maybe converting multibyte to single byte
7731 or vice versa, so that all the text fits the buffer. */
7733 && NILP (current_buffer
->enable_multibyte_characters
))
7735 int i
, c
, char_bytes
;
7736 unsigned char work
[1];
7738 /* Convert a multibyte string to single-byte
7739 for the *Message* buffer. */
7740 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7742 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7743 work
[0] = (ASCII_CHAR_P (c
)
7745 : multibyte_char_to_unibyte (c
, Qnil
));
7746 insert_1_both (work
, 1, 1, 1, 0, 0);
7749 else if (! multibyte
7750 && ! NILP (current_buffer
->enable_multibyte_characters
))
7752 int i
, c
, char_bytes
;
7753 unsigned char *msg
= (unsigned char *) m
;
7754 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7755 /* Convert a single-byte string to multibyte
7756 for the *Message* buffer. */
7757 for (i
= 0; i
< nbytes
; i
++)
7760 c
= unibyte_char_to_multibyte (c
);
7761 char_bytes
= CHAR_STRING (c
, str
);
7762 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7766 insert_1 (m
, nbytes
, 1, 0, 0);
7770 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7771 insert_1 ("\n", 1, 1, 0, 0);
7773 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7775 this_bol_byte
= PT_BYTE
;
7777 /* See if this line duplicates the previous one.
7778 If so, combine duplicates. */
7781 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7783 prev_bol_byte
= PT_BYTE
;
7785 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7786 this_bol
, this_bol_byte
);
7789 del_range_both (prev_bol
, prev_bol_byte
,
7790 this_bol
, this_bol_byte
, 0);
7796 /* If you change this format, don't forget to also
7797 change message_log_check_duplicate. */
7798 sprintf (dupstr
, " [%d times]", dup
);
7799 duplen
= strlen (dupstr
);
7800 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7801 insert_1 (dupstr
, duplen
, 1, 0, 1);
7806 /* If we have more than the desired maximum number of lines
7807 in the *Messages* buffer now, delete the oldest ones.
7808 This is safe because we don't have undo in this buffer. */
7810 if (NATNUMP (Vmessage_log_max
))
7812 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7813 -XFASTINT (Vmessage_log_max
) - 1, 0);
7814 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7817 BEGV
= XMARKER (oldbegv
)->charpos
;
7818 BEGV_BYTE
= marker_byte_position (oldbegv
);
7827 ZV
= XMARKER (oldzv
)->charpos
;
7828 ZV_BYTE
= marker_byte_position (oldzv
);
7832 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7834 /* We can't do Fgoto_char (oldpoint) because it will run some
7836 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7837 XMARKER (oldpoint
)->bytepos
);
7840 unchain_marker (XMARKER (oldpoint
));
7841 unchain_marker (XMARKER (oldbegv
));
7842 unchain_marker (XMARKER (oldzv
));
7844 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7845 set_buffer_internal (oldbuf
);
7847 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7848 message_log_need_newline
= !nlflag
;
7849 Vdeactivate_mark
= old_deactivate_mark
;
7854 /* We are at the end of the buffer after just having inserted a newline.
7855 (Note: We depend on the fact we won't be crossing the gap.)
7856 Check to see if the most recent message looks a lot like the previous one.
7857 Return 0 if different, 1 if the new one should just replace it, or a
7858 value N > 1 if we should also append " [N times]". */
7861 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7862 int prev_bol
, this_bol
;
7863 int prev_bol_byte
, this_bol_byte
;
7866 int len
= Z_BYTE
- 1 - this_bol_byte
;
7868 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7869 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7871 for (i
= 0; i
< len
; i
++)
7873 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7881 if (*p1
++ == ' ' && *p1
++ == '[')
7884 while (*p1
>= '0' && *p1
<= '9')
7885 n
= n
* 10 + *p1
++ - '0';
7886 if (strncmp (p1
, " times]\n", 8) == 0)
7893 /* Display an echo area message M with a specified length of NBYTES
7894 bytes. The string may include null characters. If M is 0, clear
7895 out any existing message, and let the mini-buffer text show
7898 This may GC, so the buffer M must NOT point to a Lisp string. */
7901 message2 (m
, nbytes
, multibyte
)
7906 /* First flush out any partial line written with print. */
7907 message_log_maybe_newline ();
7909 message_dolog (m
, nbytes
, 1, multibyte
);
7910 message2_nolog (m
, nbytes
, multibyte
);
7914 /* The non-logging counterpart of message2. */
7917 message2_nolog (m
, nbytes
, multibyte
)
7919 int nbytes
, multibyte
;
7921 struct frame
*sf
= SELECTED_FRAME ();
7922 message_enable_multibyte
= multibyte
;
7924 if (FRAME_INITIAL_P (sf
))
7926 if (noninteractive_need_newline
)
7927 putc ('\n', stderr
);
7928 noninteractive_need_newline
= 0;
7930 fwrite (m
, nbytes
, 1, stderr
);
7931 if (cursor_in_echo_area
== 0)
7932 fprintf (stderr
, "\n");
7935 /* A null message buffer means that the frame hasn't really been
7936 initialized yet. Error messages get reported properly by
7937 cmd_error, so this must be just an informative message; toss it. */
7938 else if (INTERACTIVE
7939 && sf
->glyphs_initialized_p
7940 && FRAME_MESSAGE_BUF (sf
))
7942 Lisp_Object mini_window
;
7945 /* Get the frame containing the mini-buffer
7946 that the selected frame is using. */
7947 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7948 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7950 FRAME_SAMPLE_VISIBILITY (f
);
7951 if (FRAME_VISIBLE_P (sf
)
7952 && ! FRAME_VISIBLE_P (f
))
7953 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7957 set_message (m
, Qnil
, nbytes
, multibyte
);
7958 if (minibuffer_auto_raise
)
7959 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7962 clear_message (1, 1);
7964 do_pending_window_change (0);
7965 echo_area_display (1);
7966 do_pending_window_change (0);
7967 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7968 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7973 /* Display an echo area message M with a specified length of NBYTES
7974 bytes. The string may include null characters. If M is not a
7975 string, clear out any existing message, and let the mini-buffer
7978 This function cancels echoing. */
7981 message3 (m
, nbytes
, multibyte
)
7986 struct gcpro gcpro1
;
7989 clear_message (1,1);
7992 /* First flush out any partial line written with print. */
7993 message_log_maybe_newline ();
7999 SAFE_ALLOCA (buffer
, char *, nbytes
);
8000 bcopy (SDATA (m
), buffer
, nbytes
);
8001 message_dolog (buffer
, nbytes
, 1, multibyte
);
8004 message3_nolog (m
, nbytes
, multibyte
);
8010 /* The non-logging version of message3.
8011 This does not cancel echoing, because it is used for echoing.
8012 Perhaps we need to make a separate function for echoing
8013 and make this cancel echoing. */
8016 message3_nolog (m
, nbytes
, multibyte
)
8018 int nbytes
, multibyte
;
8020 struct frame
*sf
= SELECTED_FRAME ();
8021 message_enable_multibyte
= multibyte
;
8023 if (FRAME_INITIAL_P (sf
))
8025 if (noninteractive_need_newline
)
8026 putc ('\n', stderr
);
8027 noninteractive_need_newline
= 0;
8029 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8030 if (cursor_in_echo_area
== 0)
8031 fprintf (stderr
, "\n");
8034 /* A null message buffer means that the frame hasn't really been
8035 initialized yet. Error messages get reported properly by
8036 cmd_error, so this must be just an informative message; toss it. */
8037 else if (INTERACTIVE
8038 && sf
->glyphs_initialized_p
8039 && FRAME_MESSAGE_BUF (sf
))
8041 Lisp_Object mini_window
;
8045 /* Get the frame containing the mini-buffer
8046 that the selected frame is using. */
8047 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8048 frame
= XWINDOW (mini_window
)->frame
;
8051 FRAME_SAMPLE_VISIBILITY (f
);
8052 if (FRAME_VISIBLE_P (sf
)
8053 && !FRAME_VISIBLE_P (f
))
8054 Fmake_frame_visible (frame
);
8056 if (STRINGP (m
) && SCHARS (m
) > 0)
8058 set_message (NULL
, m
, nbytes
, multibyte
);
8059 if (minibuffer_auto_raise
)
8060 Fraise_frame (frame
);
8061 /* Assume we are not echoing.
8062 (If we are, echo_now will override this.) */
8063 echo_message_buffer
= Qnil
;
8066 clear_message (1, 1);
8068 do_pending_window_change (0);
8069 echo_area_display (1);
8070 do_pending_window_change (0);
8071 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8072 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8077 /* Display a null-terminated echo area message M. If M is 0, clear
8078 out any existing message, and let the mini-buffer text show through.
8080 The buffer M must continue to exist until after the echo area gets
8081 cleared or some other message gets displayed there. Do not pass
8082 text that is stored in a Lisp string. Do not pass text in a buffer
8083 that was alloca'd. */
8089 message2 (m
, (m
? strlen (m
) : 0), 0);
8093 /* The non-logging counterpart of message1. */
8099 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8102 /* Display a message M which contains a single %s
8103 which gets replaced with STRING. */
8106 message_with_string (m
, string
, log
)
8111 CHECK_STRING (string
);
8117 if (noninteractive_need_newline
)
8118 putc ('\n', stderr
);
8119 noninteractive_need_newline
= 0;
8120 fprintf (stderr
, m
, SDATA (string
));
8121 if (!cursor_in_echo_area
)
8122 fprintf (stderr
, "\n");
8126 else if (INTERACTIVE
)
8128 /* The frame whose minibuffer we're going to display the message on.
8129 It may be larger than the selected frame, so we need
8130 to use its buffer, not the selected frame's buffer. */
8131 Lisp_Object mini_window
;
8132 struct frame
*f
, *sf
= SELECTED_FRAME ();
8134 /* Get the frame containing the minibuffer
8135 that the selected frame is using. */
8136 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8137 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8139 /* A null message buffer means that the frame hasn't really been
8140 initialized yet. Error messages get reported properly by
8141 cmd_error, so this must be just an informative message; toss it. */
8142 if (FRAME_MESSAGE_BUF (f
))
8144 Lisp_Object args
[2], message
;
8145 struct gcpro gcpro1
, gcpro2
;
8147 args
[0] = build_string (m
);
8148 args
[1] = message
= string
;
8149 GCPRO2 (args
[0], message
);
8152 message
= Fformat (2, args
);
8155 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8157 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8161 /* Print should start at the beginning of the message
8162 buffer next time. */
8163 message_buf_print
= 0;
8169 /* Dump an informative message to the minibuf. If M is 0, clear out
8170 any existing message, and let the mini-buffer text show through. */
8174 message (m
, a1
, a2
, a3
)
8176 EMACS_INT a1
, a2
, a3
;
8182 if (noninteractive_need_newline
)
8183 putc ('\n', stderr
);
8184 noninteractive_need_newline
= 0;
8185 fprintf (stderr
, m
, a1
, a2
, a3
);
8186 if (cursor_in_echo_area
== 0)
8187 fprintf (stderr
, "\n");
8191 else if (INTERACTIVE
)
8193 /* The frame whose mini-buffer we're going to display the message
8194 on. It may be larger than the selected frame, so we need to
8195 use its buffer, not the selected frame's buffer. */
8196 Lisp_Object mini_window
;
8197 struct frame
*f
, *sf
= SELECTED_FRAME ();
8199 /* Get the frame containing the mini-buffer
8200 that the selected frame is using. */
8201 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8202 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8204 /* A null message buffer means that the frame hasn't really been
8205 initialized yet. Error messages get reported properly by
8206 cmd_error, so this must be just an informative message; toss
8208 if (FRAME_MESSAGE_BUF (f
))
8219 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8220 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8222 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8223 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8225 #endif /* NO_ARG_ARRAY */
8227 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8232 /* Print should start at the beginning of the message
8233 buffer next time. */
8234 message_buf_print
= 0;
8240 /* The non-logging version of message. */
8243 message_nolog (m
, a1
, a2
, a3
)
8245 EMACS_INT a1
, a2
, a3
;
8247 Lisp_Object old_log_max
;
8248 old_log_max
= Vmessage_log_max
;
8249 Vmessage_log_max
= Qnil
;
8250 message (m
, a1
, a2
, a3
);
8251 Vmessage_log_max
= old_log_max
;
8255 /* Display the current message in the current mini-buffer. This is
8256 only called from error handlers in process.c, and is not time
8262 if (!NILP (echo_area_buffer
[0]))
8265 string
= Fcurrent_message ();
8266 message3 (string
, SBYTES (string
),
8267 !NILP (current_buffer
->enable_multibyte_characters
));
8272 /* Make sure echo area buffers in `echo_buffers' are live.
8273 If they aren't, make new ones. */
8276 ensure_echo_area_buffers ()
8280 for (i
= 0; i
< 2; ++i
)
8281 if (!BUFFERP (echo_buffer
[i
])
8282 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8285 Lisp_Object old_buffer
;
8288 old_buffer
= echo_buffer
[i
];
8289 sprintf (name
, " *Echo Area %d*", i
);
8290 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8291 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8292 /* to force word wrap in echo area -
8293 it was decided to postpone this*/
8294 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8296 for (j
= 0; j
< 2; ++j
)
8297 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8298 echo_area_buffer
[j
] = echo_buffer
[i
];
8303 /* Call FN with args A1..A4 with either the current or last displayed
8304 echo_area_buffer as current buffer.
8306 WHICH zero means use the current message buffer
8307 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8308 from echo_buffer[] and clear it.
8310 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8311 suitable buffer from echo_buffer[] and clear it.
8313 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8314 that the current message becomes the last displayed one, make
8315 choose a suitable buffer for echo_area_buffer[0], and clear it.
8317 Value is what FN returns. */
8320 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8323 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8329 int this_one
, the_other
, clear_buffer_p
, rc
;
8330 int count
= SPECPDL_INDEX ();
8332 /* If buffers aren't live, make new ones. */
8333 ensure_echo_area_buffers ();
8338 this_one
= 0, the_other
= 1;
8340 this_one
= 1, the_other
= 0;
8343 this_one
= 0, the_other
= 1;
8346 /* We need a fresh one in case the current echo buffer equals
8347 the one containing the last displayed echo area message. */
8348 if (!NILP (echo_area_buffer
[this_one
])
8349 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8350 echo_area_buffer
[this_one
] = Qnil
;
8353 /* Choose a suitable buffer from echo_buffer[] is we don't
8355 if (NILP (echo_area_buffer
[this_one
]))
8357 echo_area_buffer
[this_one
]
8358 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8359 ? echo_buffer
[the_other
]
8360 : echo_buffer
[this_one
]);
8364 buffer
= echo_area_buffer
[this_one
];
8366 /* Don't get confused by reusing the buffer used for echoing
8367 for a different purpose. */
8368 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8371 record_unwind_protect (unwind_with_echo_area_buffer
,
8372 with_echo_area_buffer_unwind_data (w
));
8374 /* Make the echo area buffer current. Note that for display
8375 purposes, it is not necessary that the displayed window's buffer
8376 == current_buffer, except for text property lookup. So, let's
8377 only set that buffer temporarily here without doing a full
8378 Fset_window_buffer. We must also change w->pointm, though,
8379 because otherwise an assertions in unshow_buffer fails, and Emacs
8381 set_buffer_internal_1 (XBUFFER (buffer
));
8385 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8388 current_buffer
->undo_list
= Qt
;
8389 current_buffer
->read_only
= Qnil
;
8390 specbind (Qinhibit_read_only
, Qt
);
8391 specbind (Qinhibit_modification_hooks
, Qt
);
8393 if (clear_buffer_p
&& Z
> BEG
)
8396 xassert (BEGV
>= BEG
);
8397 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8399 rc
= fn (a1
, a2
, a3
, a4
);
8401 xassert (BEGV
>= BEG
);
8402 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8404 unbind_to (count
, Qnil
);
8409 /* Save state that should be preserved around the call to the function
8410 FN called in with_echo_area_buffer. */
8413 with_echo_area_buffer_unwind_data (w
)
8417 Lisp_Object vector
, tmp
;
8419 /* Reduce consing by keeping one vector in
8420 Vwith_echo_area_save_vector. */
8421 vector
= Vwith_echo_area_save_vector
;
8422 Vwith_echo_area_save_vector
= Qnil
;
8425 vector
= Fmake_vector (make_number (7), Qnil
);
8427 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8428 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8429 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8433 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8434 ASET (vector
, i
, w
->buffer
); ++i
;
8435 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8436 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8441 for (; i
< end
; ++i
)
8442 ASET (vector
, i
, Qnil
);
8445 xassert (i
== ASIZE (vector
));
8450 /* Restore global state from VECTOR which was created by
8451 with_echo_area_buffer_unwind_data. */
8454 unwind_with_echo_area_buffer (vector
)
8457 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8458 Vdeactivate_mark
= AREF (vector
, 1);
8459 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8461 if (WINDOWP (AREF (vector
, 3)))
8464 Lisp_Object buffer
, charpos
, bytepos
;
8466 w
= XWINDOW (AREF (vector
, 3));
8467 buffer
= AREF (vector
, 4);
8468 charpos
= AREF (vector
, 5);
8469 bytepos
= AREF (vector
, 6);
8472 set_marker_both (w
->pointm
, buffer
,
8473 XFASTINT (charpos
), XFASTINT (bytepos
));
8476 Vwith_echo_area_save_vector
= vector
;
8481 /* Set up the echo area for use by print functions. MULTIBYTE_P
8482 non-zero means we will print multibyte. */
8485 setup_echo_area_for_printing (multibyte_p
)
8488 /* If we can't find an echo area any more, exit. */
8489 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8492 ensure_echo_area_buffers ();
8494 if (!message_buf_print
)
8496 /* A message has been output since the last time we printed.
8497 Choose a fresh echo area buffer. */
8498 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8499 echo_area_buffer
[0] = echo_buffer
[1];
8501 echo_area_buffer
[0] = echo_buffer
[0];
8503 /* Switch to that buffer and clear it. */
8504 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8505 current_buffer
->truncate_lines
= Qnil
;
8509 int count
= SPECPDL_INDEX ();
8510 specbind (Qinhibit_read_only
, Qt
);
8511 /* Note that undo recording is always disabled. */
8513 unbind_to (count
, Qnil
);
8515 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8517 /* Set up the buffer for the multibyteness we need. */
8519 != !NILP (current_buffer
->enable_multibyte_characters
))
8520 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8522 /* Raise the frame containing the echo area. */
8523 if (minibuffer_auto_raise
)
8525 struct frame
*sf
= SELECTED_FRAME ();
8526 Lisp_Object mini_window
;
8527 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8528 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8531 message_log_maybe_newline ();
8532 message_buf_print
= 1;
8536 if (NILP (echo_area_buffer
[0]))
8538 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8539 echo_area_buffer
[0] = echo_buffer
[1];
8541 echo_area_buffer
[0] = echo_buffer
[0];
8544 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8546 /* Someone switched buffers between print requests. */
8547 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8548 current_buffer
->truncate_lines
= Qnil
;
8554 /* Display an echo area message in window W. Value is non-zero if W's
8555 height is changed. If display_last_displayed_message_p is
8556 non-zero, display the message that was last displayed, otherwise
8557 display the current message. */
8560 display_echo_area (w
)
8563 int i
, no_message_p
, window_height_changed_p
, count
;
8565 /* Temporarily disable garbage collections while displaying the echo
8566 area. This is done because a GC can print a message itself.
8567 That message would modify the echo area buffer's contents while a
8568 redisplay of the buffer is going on, and seriously confuse
8570 count
= inhibit_garbage_collection ();
8572 /* If there is no message, we must call display_echo_area_1
8573 nevertheless because it resizes the window. But we will have to
8574 reset the echo_area_buffer in question to nil at the end because
8575 with_echo_area_buffer will sets it to an empty buffer. */
8576 i
= display_last_displayed_message_p
? 1 : 0;
8577 no_message_p
= NILP (echo_area_buffer
[i
]);
8579 window_height_changed_p
8580 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8581 display_echo_area_1
,
8582 (EMACS_INT
) w
, Qnil
, 0, 0);
8585 echo_area_buffer
[i
] = Qnil
;
8587 unbind_to (count
, Qnil
);
8588 return window_height_changed_p
;
8592 /* Helper for display_echo_area. Display the current buffer which
8593 contains the current echo area message in window W, a mini-window,
8594 a pointer to which is passed in A1. A2..A4 are currently not used.
8595 Change the height of W so that all of the message is displayed.
8596 Value is non-zero if height of W was changed. */
8599 display_echo_area_1 (a1
, a2
, a3
, a4
)
8604 struct window
*w
= (struct window
*) a1
;
8606 struct text_pos start
;
8607 int window_height_changed_p
= 0;
8609 /* Do this before displaying, so that we have a large enough glyph
8610 matrix for the display. If we can't get enough space for the
8611 whole text, display the last N lines. That works by setting w->start. */
8612 window_height_changed_p
= resize_mini_window (w
, 0);
8614 /* Use the starting position chosen by resize_mini_window. */
8615 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8618 clear_glyph_matrix (w
->desired_matrix
);
8619 XSETWINDOW (window
, w
);
8620 try_window (window
, start
, 0);
8622 return window_height_changed_p
;
8626 /* Resize the echo area window to exactly the size needed for the
8627 currently displayed message, if there is one. If a mini-buffer
8628 is active, don't shrink it. */
8631 resize_echo_area_exactly ()
8633 if (BUFFERP (echo_area_buffer
[0])
8634 && WINDOWP (echo_area_window
))
8636 struct window
*w
= XWINDOW (echo_area_window
);
8638 Lisp_Object resize_exactly
;
8640 if (minibuf_level
== 0)
8641 resize_exactly
= Qt
;
8643 resize_exactly
= Qnil
;
8645 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8646 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8649 ++windows_or_buffers_changed
;
8650 ++update_mode_lines
;
8651 redisplay_internal (0);
8657 /* Callback function for with_echo_area_buffer, when used from
8658 resize_echo_area_exactly. A1 contains a pointer to the window to
8659 resize, EXACTLY non-nil means resize the mini-window exactly to the
8660 size of the text displayed. A3 and A4 are not used. Value is what
8661 resize_mini_window returns. */
8664 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8666 Lisp_Object exactly
;
8669 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8673 /* Resize mini-window W to fit the size of its contents. EXACT_P
8674 means size the window exactly to the size needed. Otherwise, it's
8675 only enlarged until W's buffer is empty.
8677 Set W->start to the right place to begin display. If the whole
8678 contents fit, start at the beginning. Otherwise, start so as
8679 to make the end of the contents appear. This is particularly
8680 important for y-or-n-p, but seems desirable generally.
8682 Value is non-zero if the window height has been changed. */
8685 resize_mini_window (w
, exact_p
)
8689 struct frame
*f
= XFRAME (w
->frame
);
8690 int window_height_changed_p
= 0;
8692 xassert (MINI_WINDOW_P (w
));
8694 /* By default, start display at the beginning. */
8695 set_marker_both (w
->start
, w
->buffer
,
8696 BUF_BEGV (XBUFFER (w
->buffer
)),
8697 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8699 /* Don't resize windows while redisplaying a window; it would
8700 confuse redisplay functions when the size of the window they are
8701 displaying changes from under them. Such a resizing can happen,
8702 for instance, when which-func prints a long message while
8703 we are running fontification-functions. We're running these
8704 functions with safe_call which binds inhibit-redisplay to t. */
8705 if (!NILP (Vinhibit_redisplay
))
8708 /* Nil means don't try to resize. */
8709 if (NILP (Vresize_mini_windows
)
8710 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8713 if (!FRAME_MINIBUF_ONLY_P (f
))
8716 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8717 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8718 int height
, max_height
;
8719 int unit
= FRAME_LINE_HEIGHT (f
);
8720 struct text_pos start
;
8721 struct buffer
*old_current_buffer
= NULL
;
8723 if (current_buffer
!= XBUFFER (w
->buffer
))
8725 old_current_buffer
= current_buffer
;
8726 set_buffer_internal (XBUFFER (w
->buffer
));
8729 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8731 /* Compute the max. number of lines specified by the user. */
8732 if (FLOATP (Vmax_mini_window_height
))
8733 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8734 else if (INTEGERP (Vmax_mini_window_height
))
8735 max_height
= XINT (Vmax_mini_window_height
);
8737 max_height
= total_height
/ 4;
8739 /* Correct that max. height if it's bogus. */
8740 max_height
= max (1, max_height
);
8741 max_height
= min (total_height
, max_height
);
8743 /* Find out the height of the text in the window. */
8744 if (it
.line_wrap
== TRUNCATE
)
8749 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8750 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8751 height
= it
.current_y
+ last_height
;
8753 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8754 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8755 height
= (height
+ unit
- 1) / unit
;
8758 /* Compute a suitable window start. */
8759 if (height
> max_height
)
8761 height
= max_height
;
8762 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8763 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8764 start
= it
.current
.pos
;
8767 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8768 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8770 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8772 /* Let it grow only, until we display an empty message, in which
8773 case the window shrinks again. */
8774 if (height
> WINDOW_TOTAL_LINES (w
))
8776 int old_height
= WINDOW_TOTAL_LINES (w
);
8777 freeze_window_starts (f
, 1);
8778 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8779 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8781 else if (height
< WINDOW_TOTAL_LINES (w
)
8782 && (exact_p
|| BEGV
== ZV
))
8784 int old_height
= WINDOW_TOTAL_LINES (w
);
8785 freeze_window_starts (f
, 0);
8786 shrink_mini_window (w
);
8787 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8792 /* Always resize to exact size needed. */
8793 if (height
> WINDOW_TOTAL_LINES (w
))
8795 int old_height
= WINDOW_TOTAL_LINES (w
);
8796 freeze_window_starts (f
, 1);
8797 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8798 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8800 else if (height
< WINDOW_TOTAL_LINES (w
))
8802 int old_height
= WINDOW_TOTAL_LINES (w
);
8803 freeze_window_starts (f
, 0);
8804 shrink_mini_window (w
);
8808 freeze_window_starts (f
, 1);
8809 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8812 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8816 if (old_current_buffer
)
8817 set_buffer_internal (old_current_buffer
);
8820 return window_height_changed_p
;
8824 /* Value is the current message, a string, or nil if there is no
8832 if (!BUFFERP (echo_area_buffer
[0]))
8836 with_echo_area_buffer (0, 0, current_message_1
,
8837 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8839 echo_area_buffer
[0] = Qnil
;
8847 current_message_1 (a1
, a2
, a3
, a4
)
8852 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8855 *msg
= make_buffer_string (BEG
, Z
, 1);
8862 /* Push the current message on Vmessage_stack for later restauration
8863 by restore_message. Value is non-zero if the current message isn't
8864 empty. This is a relatively infrequent operation, so it's not
8865 worth optimizing. */
8871 msg
= current_message ();
8872 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8873 return STRINGP (msg
);
8877 /* Restore message display from the top of Vmessage_stack. */
8884 xassert (CONSP (Vmessage_stack
));
8885 msg
= XCAR (Vmessage_stack
);
8887 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8889 message3_nolog (msg
, 0, 0);
8893 /* Handler for record_unwind_protect calling pop_message. */
8896 pop_message_unwind (dummy
)
8903 /* Pop the top-most entry off Vmessage_stack. */
8908 xassert (CONSP (Vmessage_stack
));
8909 Vmessage_stack
= XCDR (Vmessage_stack
);
8913 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8914 exits. If the stack is not empty, we have a missing pop_message
8918 check_message_stack ()
8920 if (!NILP (Vmessage_stack
))
8925 /* Truncate to NCHARS what will be displayed in the echo area the next
8926 time we display it---but don't redisplay it now. */
8929 truncate_echo_area (nchars
)
8933 echo_area_buffer
[0] = Qnil
;
8934 /* A null message buffer means that the frame hasn't really been
8935 initialized yet. Error messages get reported properly by
8936 cmd_error, so this must be just an informative message; toss it. */
8937 else if (!noninteractive
8939 && !NILP (echo_area_buffer
[0]))
8941 struct frame
*sf
= SELECTED_FRAME ();
8942 if (FRAME_MESSAGE_BUF (sf
))
8943 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8948 /* Helper function for truncate_echo_area. Truncate the current
8949 message to at most NCHARS characters. */
8952 truncate_message_1 (nchars
, a2
, a3
, a4
)
8957 if (BEG
+ nchars
< Z
)
8958 del_range (BEG
+ nchars
, Z
);
8960 echo_area_buffer
[0] = Qnil
;
8965 /* Set the current message to a substring of S or STRING.
8967 If STRING is a Lisp string, set the message to the first NBYTES
8968 bytes from STRING. NBYTES zero means use the whole string. If
8969 STRING is multibyte, the message will be displayed multibyte.
8971 If S is not null, set the message to the first LEN bytes of S. LEN
8972 zero means use the whole string. MULTIBYTE_P non-zero means S is
8973 multibyte. Display the message multibyte in that case.
8975 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8976 to t before calling set_message_1 (which calls insert).
8980 set_message (s
, string
, nbytes
, multibyte_p
)
8983 int nbytes
, multibyte_p
;
8985 message_enable_multibyte
8986 = ((s
&& multibyte_p
)
8987 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8989 with_echo_area_buffer (0, -1, set_message_1
,
8990 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8991 message_buf_print
= 0;
8992 help_echo_showing_p
= 0;
8996 /* Helper function for set_message. Arguments have the same meaning
8997 as there, with A1 corresponding to S and A2 corresponding to STRING
8998 This function is called with the echo area buffer being
9002 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9005 EMACS_INT nbytes
, multibyte_p
;
9007 const char *s
= (const char *) a1
;
9008 Lisp_Object string
= a2
;
9010 /* Change multibyteness of the echo buffer appropriately. */
9011 if (message_enable_multibyte
9012 != !NILP (current_buffer
->enable_multibyte_characters
))
9013 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9015 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9017 /* Insert new message at BEG. */
9018 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9020 if (STRINGP (string
))
9025 nbytes
= SBYTES (string
);
9026 nchars
= string_byte_to_char (string
, nbytes
);
9028 /* This function takes care of single/multibyte conversion. We
9029 just have to ensure that the echo area buffer has the right
9030 setting of enable_multibyte_characters. */
9031 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9036 nbytes
= strlen (s
);
9038 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9040 /* Convert from multi-byte to single-byte. */
9042 unsigned char work
[1];
9044 /* Convert a multibyte string to single-byte. */
9045 for (i
= 0; i
< nbytes
; i
+= n
)
9047 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
9048 work
[0] = (ASCII_CHAR_P (c
)
9050 : multibyte_char_to_unibyte (c
, Qnil
));
9051 insert_1_both (work
, 1, 1, 1, 0, 0);
9054 else if (!multibyte_p
9055 && !NILP (current_buffer
->enable_multibyte_characters
))
9057 /* Convert from single-byte to multi-byte. */
9059 const unsigned char *msg
= (const unsigned char *) s
;
9060 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9062 /* Convert a single-byte string to multibyte. */
9063 for (i
= 0; i
< nbytes
; i
++)
9066 c
= unibyte_char_to_multibyte (c
);
9067 n
= CHAR_STRING (c
, str
);
9068 insert_1_both (str
, 1, n
, 1, 0, 0);
9072 insert_1 (s
, nbytes
, 1, 0, 0);
9079 /* Clear messages. CURRENT_P non-zero means clear the current
9080 message. LAST_DISPLAYED_P non-zero means clear the message
9084 clear_message (current_p
, last_displayed_p
)
9085 int current_p
, last_displayed_p
;
9089 echo_area_buffer
[0] = Qnil
;
9090 message_cleared_p
= 1;
9093 if (last_displayed_p
)
9094 echo_area_buffer
[1] = Qnil
;
9096 message_buf_print
= 0;
9099 /* Clear garbaged frames.
9101 This function is used where the old redisplay called
9102 redraw_garbaged_frames which in turn called redraw_frame which in
9103 turn called clear_frame. The call to clear_frame was a source of
9104 flickering. I believe a clear_frame is not necessary. It should
9105 suffice in the new redisplay to invalidate all current matrices,
9106 and ensure a complete redisplay of all windows. */
9109 clear_garbaged_frames ()
9113 Lisp_Object tail
, frame
;
9114 int changed_count
= 0;
9116 FOR_EACH_FRAME (tail
, frame
)
9118 struct frame
*f
= XFRAME (frame
);
9120 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9124 Fredraw_frame (frame
);
9125 f
->force_flush_display_p
= 1;
9127 clear_current_matrices (f
);
9136 ++windows_or_buffers_changed
;
9141 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9142 is non-zero update selected_frame. Value is non-zero if the
9143 mini-windows height has been changed. */
9146 echo_area_display (update_frame_p
)
9149 Lisp_Object mini_window
;
9152 int window_height_changed_p
= 0;
9153 struct frame
*sf
= SELECTED_FRAME ();
9155 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9156 w
= XWINDOW (mini_window
);
9157 f
= XFRAME (WINDOW_FRAME (w
));
9159 /* Don't display if frame is invisible or not yet initialized. */
9160 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9163 #ifdef HAVE_WINDOW_SYSTEM
9164 /* When Emacs starts, selected_frame may be the initial terminal
9165 frame. If we let this through, a message would be displayed on
9167 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9169 #endif /* HAVE_WINDOW_SYSTEM */
9171 /* Redraw garbaged frames. */
9173 clear_garbaged_frames ();
9175 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9177 echo_area_window
= mini_window
;
9178 window_height_changed_p
= display_echo_area (w
);
9179 w
->must_be_updated_p
= 1;
9181 /* Update the display, unless called from redisplay_internal.
9182 Also don't update the screen during redisplay itself. The
9183 update will happen at the end of redisplay, and an update
9184 here could cause confusion. */
9185 if (update_frame_p
&& !redisplaying_p
)
9189 /* If the display update has been interrupted by pending
9190 input, update mode lines in the frame. Due to the
9191 pending input, it might have been that redisplay hasn't
9192 been called, so that mode lines above the echo area are
9193 garbaged. This looks odd, so we prevent it here. */
9194 if (!display_completed
)
9195 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9197 if (window_height_changed_p
9198 /* Don't do this if Emacs is shutting down. Redisplay
9199 needs to run hooks. */
9200 && !NILP (Vrun_hooks
))
9202 /* Must update other windows. Likewise as in other
9203 cases, don't let this update be interrupted by
9205 int count
= SPECPDL_INDEX ();
9206 specbind (Qredisplay_dont_pause
, Qt
);
9207 windows_or_buffers_changed
= 1;
9208 redisplay_internal (0);
9209 unbind_to (count
, Qnil
);
9211 else if (FRAME_WINDOW_P (f
) && n
== 0)
9213 /* Window configuration is the same as before.
9214 Can do with a display update of the echo area,
9215 unless we displayed some mode lines. */
9216 update_single_window (w
, 1);
9217 FRAME_RIF (f
)->flush_display (f
);
9220 update_frame (f
, 1, 1);
9222 /* If cursor is in the echo area, make sure that the next
9223 redisplay displays the minibuffer, so that the cursor will
9224 be replaced with what the minibuffer wants. */
9225 if (cursor_in_echo_area
)
9226 ++windows_or_buffers_changed
;
9229 else if (!EQ (mini_window
, selected_window
))
9230 windows_or_buffers_changed
++;
9232 /* Last displayed message is now the current message. */
9233 echo_area_buffer
[1] = echo_area_buffer
[0];
9234 /* Inform read_char that we're not echoing. */
9235 echo_message_buffer
= Qnil
;
9237 /* Prevent redisplay optimization in redisplay_internal by resetting
9238 this_line_start_pos. This is done because the mini-buffer now
9239 displays the message instead of its buffer text. */
9240 if (EQ (mini_window
, selected_window
))
9241 CHARPOS (this_line_start_pos
) = 0;
9243 return window_height_changed_p
;
9248 /***********************************************************************
9249 Mode Lines and Frame Titles
9250 ***********************************************************************/
9252 /* A buffer for constructing non-propertized mode-line strings and
9253 frame titles in it; allocated from the heap in init_xdisp and
9254 resized as needed in store_mode_line_noprop_char. */
9256 static char *mode_line_noprop_buf
;
9258 /* The buffer's end, and a current output position in it. */
9260 static char *mode_line_noprop_buf_end
;
9261 static char *mode_line_noprop_ptr
;
9263 #define MODE_LINE_NOPROP_LEN(start) \
9264 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9267 MODE_LINE_DISPLAY
= 0,
9273 /* Alist that caches the results of :propertize.
9274 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9275 static Lisp_Object mode_line_proptrans_alist
;
9277 /* List of strings making up the mode-line. */
9278 static Lisp_Object mode_line_string_list
;
9280 /* Base face property when building propertized mode line string. */
9281 static Lisp_Object mode_line_string_face
;
9282 static Lisp_Object mode_line_string_face_prop
;
9285 /* Unwind data for mode line strings */
9287 static Lisp_Object Vmode_line_unwind_vector
;
9290 format_mode_line_unwind_data (struct buffer
*obuf
,
9294 Lisp_Object vector
, tmp
;
9296 /* Reduce consing by keeping one vector in
9297 Vwith_echo_area_save_vector. */
9298 vector
= Vmode_line_unwind_vector
;
9299 Vmode_line_unwind_vector
= Qnil
;
9302 vector
= Fmake_vector (make_number (8), Qnil
);
9304 ASET (vector
, 0, make_number (mode_line_target
));
9305 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9306 ASET (vector
, 2, mode_line_string_list
);
9307 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9308 ASET (vector
, 4, mode_line_string_face
);
9309 ASET (vector
, 5, mode_line_string_face_prop
);
9312 XSETBUFFER (tmp
, obuf
);
9315 ASET (vector
, 6, tmp
);
9316 ASET (vector
, 7, owin
);
9322 unwind_format_mode_line (vector
)
9325 mode_line_target
= XINT (AREF (vector
, 0));
9326 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9327 mode_line_string_list
= AREF (vector
, 2);
9328 if (! EQ (AREF (vector
, 3), Qt
))
9329 mode_line_proptrans_alist
= AREF (vector
, 3);
9330 mode_line_string_face
= AREF (vector
, 4);
9331 mode_line_string_face_prop
= AREF (vector
, 5);
9333 if (!NILP (AREF (vector
, 7)))
9334 /* Select window before buffer, since it may change the buffer. */
9335 Fselect_window (AREF (vector
, 7), Qt
);
9337 if (!NILP (AREF (vector
, 6)))
9339 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9340 ASET (vector
, 6, Qnil
);
9343 Vmode_line_unwind_vector
= vector
;
9348 /* Store a single character C for the frame title in mode_line_noprop_buf.
9349 Re-allocate mode_line_noprop_buf if necessary. */
9353 store_mode_line_noprop_char (char c
)
9355 store_mode_line_noprop_char (c
)
9359 /* If output position has reached the end of the allocated buffer,
9360 double the buffer's size. */
9361 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9363 int len
= MODE_LINE_NOPROP_LEN (0);
9364 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9365 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9366 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9367 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9370 *mode_line_noprop_ptr
++ = c
;
9374 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9375 mode_line_noprop_ptr. STR is the string to store. Do not copy
9376 characters that yield more columns than PRECISION; PRECISION <= 0
9377 means copy the whole string. Pad with spaces until FIELD_WIDTH
9378 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9379 pad. Called from display_mode_element when it is used to build a
9383 store_mode_line_noprop (str
, field_width
, precision
)
9384 const unsigned char *str
;
9385 int field_width
, precision
;
9390 /* Copy at most PRECISION chars from STR. */
9391 nbytes
= strlen (str
);
9392 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9394 store_mode_line_noprop_char (*str
++);
9396 /* Fill up with spaces until FIELD_WIDTH reached. */
9397 while (field_width
> 0
9400 store_mode_line_noprop_char (' ');
9407 /***********************************************************************
9409 ***********************************************************************/
9411 #ifdef HAVE_WINDOW_SYSTEM
9413 /* Set the title of FRAME, if it has changed. The title format is
9414 Vicon_title_format if FRAME is iconified, otherwise it is
9415 frame_title_format. */
9418 x_consider_frame_title (frame
)
9421 struct frame
*f
= XFRAME (frame
);
9423 if (FRAME_WINDOW_P (f
)
9424 || FRAME_MINIBUF_ONLY_P (f
)
9425 || f
->explicit_name
)
9427 /* Do we have more than one visible frame on this X display? */
9434 int count
= SPECPDL_INDEX ();
9436 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9438 Lisp_Object other_frame
= XCAR (tail
);
9439 struct frame
*tf
= XFRAME (other_frame
);
9442 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9443 && !FRAME_MINIBUF_ONLY_P (tf
)
9444 && !EQ (other_frame
, tip_frame
)
9445 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9449 /* Set global variable indicating that multiple frames exist. */
9450 multiple_frames
= CONSP (tail
);
9452 /* Switch to the buffer of selected window of the frame. Set up
9453 mode_line_target so that display_mode_element will output into
9454 mode_line_noprop_buf; then display the title. */
9455 record_unwind_protect (unwind_format_mode_line
,
9456 format_mode_line_unwind_data
9457 (current_buffer
, selected_window
, 0));
9459 Fselect_window (f
->selected_window
, Qt
);
9460 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9461 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9463 mode_line_target
= MODE_LINE_TITLE
;
9464 title_start
= MODE_LINE_NOPROP_LEN (0);
9465 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9466 NULL
, DEFAULT_FACE_ID
);
9467 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9468 len
= MODE_LINE_NOPROP_LEN (title_start
);
9469 title
= mode_line_noprop_buf
+ title_start
;
9470 unbind_to (count
, Qnil
);
9472 /* Set the title only if it's changed. This avoids consing in
9473 the common case where it hasn't. (If it turns out that we've
9474 already wasted too much time by walking through the list with
9475 display_mode_element, then we might need to optimize at a
9476 higher level than this.) */
9477 if (! STRINGP (f
->name
)
9478 || SBYTES (f
->name
) != len
9479 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9484 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9487 ns_set_name_as_filename (f
);
9489 x_implicitly_set_name (f
, make_string(title
, len
),
9495 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9500 /* do this also for frames with explicit names */
9501 ns_implicitly_set_icon_type(f
);
9502 ns_set_doc_edited(f
, Fbuffer_modified_p
9503 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9509 #endif /* not HAVE_WINDOW_SYSTEM */
9514 /***********************************************************************
9516 ***********************************************************************/
9519 /* Prepare for redisplay by updating menu-bar item lists when
9520 appropriate. This can call eval. */
9523 prepare_menu_bars ()
9526 struct gcpro gcpro1
, gcpro2
;
9528 Lisp_Object tooltip_frame
;
9530 #ifdef HAVE_WINDOW_SYSTEM
9531 tooltip_frame
= tip_frame
;
9533 tooltip_frame
= Qnil
;
9536 /* Update all frame titles based on their buffer names, etc. We do
9537 this before the menu bars so that the buffer-menu will show the
9538 up-to-date frame titles. */
9539 #ifdef HAVE_WINDOW_SYSTEM
9540 if (windows_or_buffers_changed
|| update_mode_lines
)
9542 Lisp_Object tail
, frame
;
9544 FOR_EACH_FRAME (tail
, frame
)
9547 if (!EQ (frame
, tooltip_frame
)
9548 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9549 x_consider_frame_title (frame
);
9552 #endif /* HAVE_WINDOW_SYSTEM */
9554 /* Update the menu bar item lists, if appropriate. This has to be
9555 done before any actual redisplay or generation of display lines. */
9556 all_windows
= (update_mode_lines
9557 || buffer_shared
> 1
9558 || windows_or_buffers_changed
);
9561 Lisp_Object tail
, frame
;
9562 int count
= SPECPDL_INDEX ();
9563 /* 1 means that update_menu_bar has run its hooks
9564 so any further calls to update_menu_bar shouldn't do so again. */
9565 int menu_bar_hooks_run
= 0;
9567 record_unwind_save_match_data ();
9569 FOR_EACH_FRAME (tail
, frame
)
9573 /* Ignore tooltip frame. */
9574 if (EQ (frame
, tooltip_frame
))
9577 /* If a window on this frame changed size, report that to
9578 the user and clear the size-change flag. */
9579 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9581 Lisp_Object functions
;
9583 /* Clear flag first in case we get an error below. */
9584 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9585 functions
= Vwindow_size_change_functions
;
9586 GCPRO2 (tail
, functions
);
9588 while (CONSP (functions
))
9590 if (!EQ (XCAR (functions
), Qt
))
9591 call1 (XCAR (functions
), frame
);
9592 functions
= XCDR (functions
);
9598 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9599 #ifdef HAVE_WINDOW_SYSTEM
9600 update_tool_bar (f
, 0);
9605 unbind_to (count
, Qnil
);
9609 struct frame
*sf
= SELECTED_FRAME ();
9610 update_menu_bar (sf
, 1, 0);
9611 #ifdef HAVE_WINDOW_SYSTEM
9612 update_tool_bar (sf
, 1);
9616 /* Motif needs this. See comment in xmenu.c. Turn it off when
9617 pending_menu_activation is not defined. */
9618 #ifdef USE_X_TOOLKIT
9619 pending_menu_activation
= 0;
9624 /* Update the menu bar item list for frame F. This has to be done
9625 before we start to fill in any display lines, because it can call
9628 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9630 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9631 already ran the menu bar hooks for this redisplay, so there
9632 is no need to run them again. The return value is the
9633 updated value of this flag, to pass to the next call. */
9636 update_menu_bar (f
, save_match_data
, hooks_run
)
9638 int save_match_data
;
9642 register struct window
*w
;
9644 /* If called recursively during a menu update, do nothing. This can
9645 happen when, for instance, an activate-menubar-hook causes a
9647 if (inhibit_menubar_update
)
9650 window
= FRAME_SELECTED_WINDOW (f
);
9651 w
= XWINDOW (window
);
9653 if (FRAME_WINDOW_P (f
)
9655 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9656 || defined (HAVE_NS) || defined (USE_GTK)
9657 FRAME_EXTERNAL_MENU_BAR (f
)
9659 FRAME_MENU_BAR_LINES (f
) > 0
9661 : FRAME_MENU_BAR_LINES (f
) > 0)
9663 /* If the user has switched buffers or windows, we need to
9664 recompute to reflect the new bindings. But we'll
9665 recompute when update_mode_lines is set too; that means
9666 that people can use force-mode-line-update to request
9667 that the menu bar be recomputed. The adverse effect on
9668 the rest of the redisplay algorithm is about the same as
9669 windows_or_buffers_changed anyway. */
9670 if (windows_or_buffers_changed
9671 /* This used to test w->update_mode_line, but we believe
9672 there is no need to recompute the menu in that case. */
9673 || update_mode_lines
9674 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9675 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9676 != !NILP (w
->last_had_star
))
9677 || ((!NILP (Vtransient_mark_mode
)
9678 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9679 != !NILP (w
->region_showing
)))
9681 struct buffer
*prev
= current_buffer
;
9682 int count
= SPECPDL_INDEX ();
9684 specbind (Qinhibit_menubar_update
, Qt
);
9686 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9687 if (save_match_data
)
9688 record_unwind_save_match_data ();
9689 if (NILP (Voverriding_local_map_menu_flag
))
9691 specbind (Qoverriding_terminal_local_map
, Qnil
);
9692 specbind (Qoverriding_local_map
, Qnil
);
9697 /* Run the Lucid hook. */
9698 safe_run_hooks (Qactivate_menubar_hook
);
9700 /* If it has changed current-menubar from previous value,
9701 really recompute the menu-bar from the value. */
9702 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9703 call0 (Qrecompute_lucid_menubar
);
9705 safe_run_hooks (Qmenu_bar_update_hook
);
9710 XSETFRAME (Vmenu_updating_frame
, f
);
9711 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9713 /* Redisplay the menu bar in case we changed it. */
9714 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9715 || defined (HAVE_NS) || defined (USE_GTK)
9716 if (FRAME_WINDOW_P (f
))
9718 #if defined (HAVE_NS)
9719 /* All frames on Mac OS share the same menubar. So only
9720 the selected frame should be allowed to set it. */
9721 if (f
== SELECTED_FRAME ())
9723 set_frame_menubar (f
, 0, 0);
9726 /* On a terminal screen, the menu bar is an ordinary screen
9727 line, and this makes it get updated. */
9728 w
->update_mode_line
= Qt
;
9729 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9730 /* In the non-toolkit version, the menu bar is an ordinary screen
9731 line, and this makes it get updated. */
9732 w
->update_mode_line
= Qt
;
9733 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9735 unbind_to (count
, Qnil
);
9736 set_buffer_internal_1 (prev
);
9745 /***********************************************************************
9747 ***********************************************************************/
9749 #ifdef HAVE_WINDOW_SYSTEM
9752 Nominal cursor position -- where to draw output.
9753 HPOS and VPOS are window relative glyph matrix coordinates.
9754 X and Y are window relative pixel coordinates. */
9756 struct cursor_pos output_cursor
;
9760 Set the global variable output_cursor to CURSOR. All cursor
9761 positions are relative to updated_window. */
9764 set_output_cursor (cursor
)
9765 struct cursor_pos
*cursor
;
9767 output_cursor
.hpos
= cursor
->hpos
;
9768 output_cursor
.vpos
= cursor
->vpos
;
9769 output_cursor
.x
= cursor
->x
;
9770 output_cursor
.y
= cursor
->y
;
9775 Set a nominal cursor position.
9777 HPOS and VPOS are column/row positions in a window glyph matrix. X
9778 and Y are window text area relative pixel positions.
9780 If this is done during an update, updated_window will contain the
9781 window that is being updated and the position is the future output
9782 cursor position for that window. If updated_window is null, use
9783 selected_window and display the cursor at the given position. */
9786 x_cursor_to (vpos
, hpos
, y
, x
)
9787 int vpos
, hpos
, y
, x
;
9791 /* If updated_window is not set, work on selected_window. */
9795 w
= XWINDOW (selected_window
);
9797 /* Set the output cursor. */
9798 output_cursor
.hpos
= hpos
;
9799 output_cursor
.vpos
= vpos
;
9800 output_cursor
.x
= x
;
9801 output_cursor
.y
= y
;
9803 /* If not called as part of an update, really display the cursor.
9804 This will also set the cursor position of W. */
9805 if (updated_window
== NULL
)
9808 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9809 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9810 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9815 #endif /* HAVE_WINDOW_SYSTEM */
9818 /***********************************************************************
9820 ***********************************************************************/
9822 #ifdef HAVE_WINDOW_SYSTEM
9824 /* Where the mouse was last time we reported a mouse event. */
9826 FRAME_PTR last_mouse_frame
;
9828 /* Tool-bar item index of the item on which a mouse button was pressed
9831 int last_tool_bar_item
;
9835 update_tool_bar_unwind (frame
)
9838 selected_frame
= frame
;
9842 /* Update the tool-bar item list for frame F. This has to be done
9843 before we start to fill in any display lines. Called from
9844 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9845 and restore it here. */
9848 update_tool_bar (f
, save_match_data
)
9850 int save_match_data
;
9852 #if defined (USE_GTK) || defined (HAVE_NS)
9853 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9855 int do_update
= WINDOWP (f
->tool_bar_window
)
9856 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9864 window
= FRAME_SELECTED_WINDOW (f
);
9865 w
= XWINDOW (window
);
9867 /* If the user has switched buffers or windows, we need to
9868 recompute to reflect the new bindings. But we'll
9869 recompute when update_mode_lines is set too; that means
9870 that people can use force-mode-line-update to request
9871 that the menu bar be recomputed. The adverse effect on
9872 the rest of the redisplay algorithm is about the same as
9873 windows_or_buffers_changed anyway. */
9874 if (windows_or_buffers_changed
9875 || !NILP (w
->update_mode_line
)
9876 || update_mode_lines
9877 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9878 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9879 != !NILP (w
->last_had_star
))
9880 || ((!NILP (Vtransient_mark_mode
)
9881 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9882 != !NILP (w
->region_showing
)))
9884 struct buffer
*prev
= current_buffer
;
9885 int count
= SPECPDL_INDEX ();
9886 Lisp_Object frame
, new_tool_bar
;
9888 struct gcpro gcpro1
;
9890 /* Set current_buffer to the buffer of the selected
9891 window of the frame, so that we get the right local
9893 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9895 /* Save match data, if we must. */
9896 if (save_match_data
)
9897 record_unwind_save_match_data ();
9899 /* Make sure that we don't accidentally use bogus keymaps. */
9900 if (NILP (Voverriding_local_map_menu_flag
))
9902 specbind (Qoverriding_terminal_local_map
, Qnil
);
9903 specbind (Qoverriding_local_map
, Qnil
);
9906 GCPRO1 (new_tool_bar
);
9908 /* We must temporarily set the selected frame to this frame
9909 before calling tool_bar_items, because the calculation of
9910 the tool-bar keymap uses the selected frame (see
9911 `tool-bar-make-keymap' in tool-bar.el). */
9912 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9913 XSETFRAME (frame
, f
);
9914 selected_frame
= frame
;
9916 /* Build desired tool-bar items from keymaps. */
9917 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9920 /* Redisplay the tool-bar if we changed it. */
9921 if (new_n_tool_bar
!= f
->n_tool_bar_items
9922 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9924 /* Redisplay that happens asynchronously due to an expose event
9925 may access f->tool_bar_items. Make sure we update both
9926 variables within BLOCK_INPUT so no such event interrupts. */
9928 f
->tool_bar_items
= new_tool_bar
;
9929 f
->n_tool_bar_items
= new_n_tool_bar
;
9930 w
->update_mode_line
= Qt
;
9936 unbind_to (count
, Qnil
);
9937 set_buffer_internal_1 (prev
);
9943 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9944 F's desired tool-bar contents. F->tool_bar_items must have
9945 been set up previously by calling prepare_menu_bars. */
9948 build_desired_tool_bar_string (f
)
9951 int i
, size
, size_needed
;
9952 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9953 Lisp_Object image
, plist
, props
;
9955 image
= plist
= props
= Qnil
;
9956 GCPRO3 (image
, plist
, props
);
9958 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9959 Otherwise, make a new string. */
9961 /* The size of the string we might be able to reuse. */
9962 size
= (STRINGP (f
->desired_tool_bar_string
)
9963 ? SCHARS (f
->desired_tool_bar_string
)
9966 /* We need one space in the string for each image. */
9967 size_needed
= f
->n_tool_bar_items
;
9969 /* Reuse f->desired_tool_bar_string, if possible. */
9970 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9971 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9975 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9976 Fremove_text_properties (make_number (0), make_number (size
),
9977 props
, f
->desired_tool_bar_string
);
9980 /* Put a `display' property on the string for the images to display,
9981 put a `menu_item' property on tool-bar items with a value that
9982 is the index of the item in F's tool-bar item vector. */
9983 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9985 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9987 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9988 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9989 int hmargin
, vmargin
, relief
, idx
, end
;
9990 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9992 /* If image is a vector, choose the image according to the
9994 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9995 if (VECTORP (image
))
9999 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10000 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10003 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10004 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10006 xassert (ASIZE (image
) >= idx
);
10007 image
= AREF (image
, idx
);
10012 /* Ignore invalid image specifications. */
10013 if (!valid_image_p (image
))
10016 /* Display the tool-bar button pressed, or depressed. */
10017 plist
= Fcopy_sequence (XCDR (image
));
10019 /* Compute margin and relief to draw. */
10020 relief
= (tool_bar_button_relief
>= 0
10021 ? tool_bar_button_relief
10022 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10023 hmargin
= vmargin
= relief
;
10025 if (INTEGERP (Vtool_bar_button_margin
)
10026 && XINT (Vtool_bar_button_margin
) > 0)
10028 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10029 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10031 else if (CONSP (Vtool_bar_button_margin
))
10033 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10034 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10035 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10037 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10038 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10039 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10042 if (auto_raise_tool_bar_buttons_p
)
10044 /* Add a `:relief' property to the image spec if the item is
10048 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10055 /* If image is selected, display it pressed, i.e. with a
10056 negative relief. If it's not selected, display it with a
10058 plist
= Fplist_put (plist
, QCrelief
,
10060 ? make_number (-relief
)
10061 : make_number (relief
)));
10066 /* Put a margin around the image. */
10067 if (hmargin
|| vmargin
)
10069 if (hmargin
== vmargin
)
10070 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10072 plist
= Fplist_put (plist
, QCmargin
,
10073 Fcons (make_number (hmargin
),
10074 make_number (vmargin
)));
10077 /* If button is not enabled, and we don't have special images
10078 for the disabled state, make the image appear disabled by
10079 applying an appropriate algorithm to it. */
10080 if (!enabled_p
&& idx
< 0)
10081 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10083 /* Put a `display' text property on the string for the image to
10084 display. Put a `menu-item' property on the string that gives
10085 the start of this item's properties in the tool-bar items
10087 image
= Fcons (Qimage
, plist
);
10088 props
= list4 (Qdisplay
, image
,
10089 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10091 /* Let the last image hide all remaining spaces in the tool bar
10092 string. The string can be longer than needed when we reuse a
10093 previous string. */
10094 if (i
+ 1 == f
->n_tool_bar_items
)
10095 end
= SCHARS (f
->desired_tool_bar_string
);
10098 Fadd_text_properties (make_number (i
), make_number (end
),
10099 props
, f
->desired_tool_bar_string
);
10107 /* Display one line of the tool-bar of frame IT->f.
10109 HEIGHT specifies the desired height of the tool-bar line.
10110 If the actual height of the glyph row is less than HEIGHT, the
10111 row's height is increased to HEIGHT, and the icons are centered
10112 vertically in the new height.
10114 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10115 count a final empty row in case the tool-bar width exactly matches
10120 display_tool_bar_line (it
, height
)
10124 struct glyph_row
*row
= it
->glyph_row
;
10125 int max_x
= it
->last_visible_x
;
10126 struct glyph
*last
;
10128 prepare_desired_row (row
);
10129 row
->y
= it
->current_y
;
10131 /* Note that this isn't made use of if the face hasn't a box,
10132 so there's no need to check the face here. */
10133 it
->start_of_box_run_p
= 1;
10135 while (it
->current_x
< max_x
)
10137 int x
, n_glyphs_before
, i
, nglyphs
;
10138 struct it it_before
;
10140 /* Get the next display element. */
10141 if (!get_next_display_element (it
))
10143 /* Don't count empty row if we are counting needed tool-bar lines. */
10144 if (height
< 0 && !it
->hpos
)
10149 /* Produce glyphs. */
10150 n_glyphs_before
= row
->used
[TEXT_AREA
];
10153 PRODUCE_GLYPHS (it
);
10155 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10157 x
= it_before
.current_x
;
10158 while (i
< nglyphs
)
10160 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10162 if (x
+ glyph
->pixel_width
> max_x
)
10164 /* Glyph doesn't fit on line. Backtrack. */
10165 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10167 /* If this is the only glyph on this line, it will never fit on the
10168 toolbar, so skip it. But ensure there is at least one glyph,
10169 so we don't accidentally disable the tool-bar. */
10170 if (n_glyphs_before
== 0
10171 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10177 x
+= glyph
->pixel_width
;
10181 /* Stop at line ends. */
10182 if (ITERATOR_AT_END_OF_LINE_P (it
))
10185 set_iterator_to_next (it
, 1);
10190 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10192 /* Use default face for the border below the tool bar.
10194 FIXME: When auto-resize-tool-bars is grow-only, there is
10195 no additional border below the possibly empty tool-bar lines.
10196 So to make the extra empty lines look "normal", we have to
10197 use the tool-bar face for the border too. */
10198 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10199 it
->face_id
= DEFAULT_FACE_ID
;
10201 extend_face_to_end_of_line (it
);
10202 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10203 last
->right_box_line_p
= 1;
10204 if (last
== row
->glyphs
[TEXT_AREA
])
10205 last
->left_box_line_p
= 1;
10207 /* Make line the desired height and center it vertically. */
10208 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10210 /* Don't add more than one line height. */
10211 height
%= FRAME_LINE_HEIGHT (it
->f
);
10212 it
->max_ascent
+= height
/ 2;
10213 it
->max_descent
+= (height
+ 1) / 2;
10216 compute_line_metrics (it
);
10218 /* If line is empty, make it occupy the rest of the tool-bar. */
10219 if (!row
->displays_text_p
)
10221 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10222 row
->visible_height
= row
->height
;
10223 row
->ascent
= row
->phys_ascent
= 0;
10224 row
->extra_line_spacing
= 0;
10227 row
->full_width_p
= 1;
10228 row
->continued_p
= 0;
10229 row
->truncated_on_left_p
= 0;
10230 row
->truncated_on_right_p
= 0;
10232 it
->current_x
= it
->hpos
= 0;
10233 it
->current_y
+= row
->height
;
10239 /* Max tool-bar height. */
10241 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10242 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10244 /* Value is the number of screen lines needed to make all tool-bar
10245 items of frame F visible. The number of actual rows needed is
10246 returned in *N_ROWS if non-NULL. */
10249 tool_bar_lines_needed (f
, n_rows
)
10253 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10255 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10256 the desired matrix, so use (unused) mode-line row as temporary row to
10257 avoid destroying the first tool-bar row. */
10258 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10260 /* Initialize an iterator for iteration over
10261 F->desired_tool_bar_string in the tool-bar window of frame F. */
10262 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10263 it
.first_visible_x
= 0;
10264 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10265 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10267 while (!ITERATOR_AT_END_P (&it
))
10269 clear_glyph_row (temp_row
);
10270 it
.glyph_row
= temp_row
;
10271 display_tool_bar_line (&it
, -1);
10273 clear_glyph_row (temp_row
);
10275 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10277 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10279 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10283 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10285 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10294 frame
= selected_frame
;
10296 CHECK_FRAME (frame
);
10297 f
= XFRAME (frame
);
10299 if (WINDOWP (f
->tool_bar_window
)
10300 || (w
= XWINDOW (f
->tool_bar_window
),
10301 WINDOW_TOTAL_LINES (w
) > 0))
10303 update_tool_bar (f
, 1);
10304 if (f
->n_tool_bar_items
)
10306 build_desired_tool_bar_string (f
);
10307 nlines
= tool_bar_lines_needed (f
, NULL
);
10311 return make_number (nlines
);
10315 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10316 height should be changed. */
10319 redisplay_tool_bar (f
)
10324 struct glyph_row
*row
;
10326 #if defined (USE_GTK) || defined (HAVE_NS)
10327 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10328 update_frame_tool_bar (f
);
10332 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10333 do anything. This means you must start with tool-bar-lines
10334 non-zero to get the auto-sizing effect. Or in other words, you
10335 can turn off tool-bars by specifying tool-bar-lines zero. */
10336 if (!WINDOWP (f
->tool_bar_window
)
10337 || (w
= XWINDOW (f
->tool_bar_window
),
10338 WINDOW_TOTAL_LINES (w
) == 0))
10341 /* Set up an iterator for the tool-bar window. */
10342 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10343 it
.first_visible_x
= 0;
10344 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10345 row
= it
.glyph_row
;
10347 /* Build a string that represents the contents of the tool-bar. */
10348 build_desired_tool_bar_string (f
);
10349 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10351 if (f
->n_tool_bar_rows
== 0)
10355 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10356 nlines
!= WINDOW_TOTAL_LINES (w
)))
10358 extern Lisp_Object Qtool_bar_lines
;
10360 int old_height
= WINDOW_TOTAL_LINES (w
);
10362 XSETFRAME (frame
, f
);
10363 Fmodify_frame_parameters (frame
,
10364 Fcons (Fcons (Qtool_bar_lines
,
10365 make_number (nlines
)),
10367 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10369 clear_glyph_matrix (w
->desired_matrix
);
10370 fonts_changed_p
= 1;
10376 /* Display as many lines as needed to display all tool-bar items. */
10378 if (f
->n_tool_bar_rows
> 0)
10380 int border
, rows
, height
, extra
;
10382 if (INTEGERP (Vtool_bar_border
))
10383 border
= XINT (Vtool_bar_border
);
10384 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10385 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10386 else if (EQ (Vtool_bar_border
, Qborder_width
))
10387 border
= f
->border_width
;
10393 rows
= f
->n_tool_bar_rows
;
10394 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10395 extra
= it
.last_visible_y
- border
- height
* rows
;
10397 while (it
.current_y
< it
.last_visible_y
)
10400 if (extra
> 0 && rows
-- > 0)
10402 h
= (extra
+ rows
- 1) / rows
;
10405 display_tool_bar_line (&it
, height
+ h
);
10410 while (it
.current_y
< it
.last_visible_y
)
10411 display_tool_bar_line (&it
, 0);
10414 /* It doesn't make much sense to try scrolling in the tool-bar
10415 window, so don't do it. */
10416 w
->desired_matrix
->no_scrolling_p
= 1;
10417 w
->must_be_updated_p
= 1;
10419 if (!NILP (Vauto_resize_tool_bars
))
10421 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10422 int change_height_p
= 0;
10424 /* If we couldn't display everything, change the tool-bar's
10425 height if there is room for more. */
10426 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10427 && it
.current_y
< max_tool_bar_height
)
10428 change_height_p
= 1;
10430 row
= it
.glyph_row
- 1;
10432 /* If there are blank lines at the end, except for a partially
10433 visible blank line at the end that is smaller than
10434 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10435 if (!row
->displays_text_p
10436 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10437 change_height_p
= 1;
10439 /* If row displays tool-bar items, but is partially visible,
10440 change the tool-bar's height. */
10441 if (row
->displays_text_p
10442 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10443 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10444 change_height_p
= 1;
10446 /* Resize windows as needed by changing the `tool-bar-lines'
10447 frame parameter. */
10448 if (change_height_p
)
10450 extern Lisp_Object Qtool_bar_lines
;
10452 int old_height
= WINDOW_TOTAL_LINES (w
);
10454 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10456 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10457 && !f
->minimize_tool_bar_window_p
)
10458 ? (nlines
> old_height
)
10459 : (nlines
!= old_height
));
10460 f
->minimize_tool_bar_window_p
= 0;
10462 if (change_height_p
)
10464 XSETFRAME (frame
, f
);
10465 Fmodify_frame_parameters (frame
,
10466 Fcons (Fcons (Qtool_bar_lines
,
10467 make_number (nlines
)),
10469 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10471 clear_glyph_matrix (w
->desired_matrix
);
10472 f
->n_tool_bar_rows
= nrows
;
10473 fonts_changed_p
= 1;
10480 f
->minimize_tool_bar_window_p
= 0;
10485 /* Get information about the tool-bar item which is displayed in GLYPH
10486 on frame F. Return in *PROP_IDX the index where tool-bar item
10487 properties start in F->tool_bar_items. Value is zero if
10488 GLYPH doesn't display a tool-bar item. */
10491 tool_bar_item_info (f
, glyph
, prop_idx
)
10493 struct glyph
*glyph
;
10500 /* This function can be called asynchronously, which means we must
10501 exclude any possibility that Fget_text_property signals an
10503 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10504 charpos
= max (0, charpos
);
10506 /* Get the text property `menu-item' at pos. The value of that
10507 property is the start index of this item's properties in
10508 F->tool_bar_items. */
10509 prop
= Fget_text_property (make_number (charpos
),
10510 Qmenu_item
, f
->current_tool_bar_string
);
10511 if (INTEGERP (prop
))
10513 *prop_idx
= XINT (prop
);
10523 /* Get information about the tool-bar item at position X/Y on frame F.
10524 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10525 the current matrix of the tool-bar window of F, or NULL if not
10526 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10527 item in F->tool_bar_items. Value is
10529 -1 if X/Y is not on a tool-bar item
10530 0 if X/Y is on the same item that was highlighted before.
10534 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10537 struct glyph
**glyph
;
10538 int *hpos
, *vpos
, *prop_idx
;
10540 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10541 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10544 /* Find the glyph under X/Y. */
10545 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10546 if (*glyph
== NULL
)
10549 /* Get the start of this tool-bar item's properties in
10550 f->tool_bar_items. */
10551 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10554 /* Is mouse on the highlighted item? */
10555 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10556 && *vpos
>= dpyinfo
->mouse_face_beg_row
10557 && *vpos
<= dpyinfo
->mouse_face_end_row
10558 && (*vpos
> dpyinfo
->mouse_face_beg_row
10559 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10560 && (*vpos
< dpyinfo
->mouse_face_end_row
10561 || *hpos
< dpyinfo
->mouse_face_end_col
10562 || dpyinfo
->mouse_face_past_end
))
10570 Handle mouse button event on the tool-bar of frame F, at
10571 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10572 0 for button release. MODIFIERS is event modifiers for button
10576 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10579 unsigned int modifiers
;
10581 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10582 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10583 int hpos
, vpos
, prop_idx
;
10584 struct glyph
*glyph
;
10585 Lisp_Object enabled_p
;
10587 /* If not on the highlighted tool-bar item, return. */
10588 frame_to_window_pixel_xy (w
, &x
, &y
);
10589 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10592 /* If item is disabled, do nothing. */
10593 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10594 if (NILP (enabled_p
))
10599 /* Show item in pressed state. */
10600 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10601 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10602 last_tool_bar_item
= prop_idx
;
10606 Lisp_Object key
, frame
;
10607 struct input_event event
;
10608 EVENT_INIT (event
);
10610 /* Show item in released state. */
10611 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10612 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10614 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10616 XSETFRAME (frame
, f
);
10617 event
.kind
= TOOL_BAR_EVENT
;
10618 event
.frame_or_window
= frame
;
10620 kbd_buffer_store_event (&event
);
10622 event
.kind
= TOOL_BAR_EVENT
;
10623 event
.frame_or_window
= frame
;
10625 event
.modifiers
= modifiers
;
10626 kbd_buffer_store_event (&event
);
10627 last_tool_bar_item
= -1;
10632 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10633 tool-bar window-relative coordinates X/Y. Called from
10634 note_mouse_highlight. */
10637 note_tool_bar_highlight (f
, x
, y
)
10641 Lisp_Object window
= f
->tool_bar_window
;
10642 struct window
*w
= XWINDOW (window
);
10643 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10645 struct glyph
*glyph
;
10646 struct glyph_row
*row
;
10648 Lisp_Object enabled_p
;
10650 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10651 int mouse_down_p
, rc
;
10653 /* Function note_mouse_highlight is called with negative x(y
10654 values when mouse moves outside of the frame. */
10655 if (x
<= 0 || y
<= 0)
10657 clear_mouse_face (dpyinfo
);
10661 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10664 /* Not on tool-bar item. */
10665 clear_mouse_face (dpyinfo
);
10669 /* On same tool-bar item as before. */
10670 goto set_help_echo
;
10672 clear_mouse_face (dpyinfo
);
10674 /* Mouse is down, but on different tool-bar item? */
10675 mouse_down_p
= (dpyinfo
->grabbed
10676 && f
== last_mouse_frame
10677 && FRAME_LIVE_P (f
));
10679 && last_tool_bar_item
!= prop_idx
)
10682 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10683 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10685 /* If tool-bar item is not enabled, don't highlight it. */
10686 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10687 if (!NILP (enabled_p
))
10689 /* Compute the x-position of the glyph. In front and past the
10690 image is a space. We include this in the highlighted area. */
10691 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10692 for (i
= x
= 0; i
< hpos
; ++i
)
10693 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10695 /* Record this as the current active region. */
10696 dpyinfo
->mouse_face_beg_col
= hpos
;
10697 dpyinfo
->mouse_face_beg_row
= vpos
;
10698 dpyinfo
->mouse_face_beg_x
= x
;
10699 dpyinfo
->mouse_face_beg_y
= row
->y
;
10700 dpyinfo
->mouse_face_past_end
= 0;
10702 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10703 dpyinfo
->mouse_face_end_row
= vpos
;
10704 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10705 dpyinfo
->mouse_face_end_y
= row
->y
;
10706 dpyinfo
->mouse_face_window
= window
;
10707 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10709 /* Display it as active. */
10710 show_mouse_face (dpyinfo
, draw
);
10711 dpyinfo
->mouse_face_image_state
= draw
;
10716 /* Set help_echo_string to a help string to display for this tool-bar item.
10717 XTread_socket does the rest. */
10718 help_echo_object
= help_echo_window
= Qnil
;
10719 help_echo_pos
= -1;
10720 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10721 if (NILP (help_echo_string
))
10722 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10725 #endif /* HAVE_WINDOW_SYSTEM */
10729 /************************************************************************
10730 Horizontal scrolling
10731 ************************************************************************/
10733 static int hscroll_window_tree
P_ ((Lisp_Object
));
10734 static int hscroll_windows
P_ ((Lisp_Object
));
10736 /* For all leaf windows in the window tree rooted at WINDOW, set their
10737 hscroll value so that PT is (i) visible in the window, and (ii) so
10738 that it is not within a certain margin at the window's left and
10739 right border. Value is non-zero if any window's hscroll has been
10743 hscroll_window_tree (window
)
10744 Lisp_Object window
;
10746 int hscrolled_p
= 0;
10747 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10748 int hscroll_step_abs
= 0;
10749 double hscroll_step_rel
= 0;
10751 if (hscroll_relative_p
)
10753 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10754 if (hscroll_step_rel
< 0)
10756 hscroll_relative_p
= 0;
10757 hscroll_step_abs
= 0;
10760 else if (INTEGERP (Vhscroll_step
))
10762 hscroll_step_abs
= XINT (Vhscroll_step
);
10763 if (hscroll_step_abs
< 0)
10764 hscroll_step_abs
= 0;
10767 hscroll_step_abs
= 0;
10769 while (WINDOWP (window
))
10771 struct window
*w
= XWINDOW (window
);
10773 if (WINDOWP (w
->hchild
))
10774 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10775 else if (WINDOWP (w
->vchild
))
10776 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10777 else if (w
->cursor
.vpos
>= 0)
10780 int text_area_width
;
10781 struct glyph_row
*current_cursor_row
10782 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10783 struct glyph_row
*desired_cursor_row
10784 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10785 struct glyph_row
*cursor_row
10786 = (desired_cursor_row
->enabled_p
10787 ? desired_cursor_row
10788 : current_cursor_row
);
10790 text_area_width
= window_box_width (w
, TEXT_AREA
);
10792 /* Scroll when cursor is inside this scroll margin. */
10793 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10795 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10796 && ((XFASTINT (w
->hscroll
)
10797 && w
->cursor
.x
<= h_margin
)
10798 || (cursor_row
->enabled_p
10799 && cursor_row
->truncated_on_right_p
10800 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10804 struct buffer
*saved_current_buffer
;
10808 /* Find point in a display of infinite width. */
10809 saved_current_buffer
= current_buffer
;
10810 current_buffer
= XBUFFER (w
->buffer
);
10812 if (w
== XWINDOW (selected_window
))
10813 pt
= BUF_PT (current_buffer
);
10816 pt
= marker_position (w
->pointm
);
10817 pt
= max (BEGV
, pt
);
10821 /* Move iterator to pt starting at cursor_row->start in
10822 a line with infinite width. */
10823 init_to_row_start (&it
, w
, cursor_row
);
10824 it
.last_visible_x
= INFINITY
;
10825 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10826 current_buffer
= saved_current_buffer
;
10828 /* Position cursor in window. */
10829 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10830 hscroll
= max (0, (it
.current_x
10831 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10832 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10833 : (text_area_width
/ 2))))
10834 / FRAME_COLUMN_WIDTH (it
.f
);
10835 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10837 if (hscroll_relative_p
)
10838 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10841 wanted_x
= text_area_width
10842 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10845 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10849 if (hscroll_relative_p
)
10850 wanted_x
= text_area_width
* hscroll_step_rel
10853 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10856 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10858 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10860 /* Don't call Fset_window_hscroll if value hasn't
10861 changed because it will prevent redisplay
10863 if (XFASTINT (w
->hscroll
) != hscroll
)
10865 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10866 w
->hscroll
= make_number (hscroll
);
10875 /* Value is non-zero if hscroll of any leaf window has been changed. */
10876 return hscrolled_p
;
10880 /* Set hscroll so that cursor is visible and not inside horizontal
10881 scroll margins for all windows in the tree rooted at WINDOW. See
10882 also hscroll_window_tree above. Value is non-zero if any window's
10883 hscroll has been changed. If it has, desired matrices on the frame
10884 of WINDOW are cleared. */
10887 hscroll_windows (window
)
10888 Lisp_Object window
;
10890 int hscrolled_p
= hscroll_window_tree (window
);
10892 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10893 return hscrolled_p
;
10898 /************************************************************************
10900 ************************************************************************/
10902 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10903 to a non-zero value. This is sometimes handy to have in a debugger
10908 /* First and last unchanged row for try_window_id. */
10910 int debug_first_unchanged_at_end_vpos
;
10911 int debug_last_unchanged_at_beg_vpos
;
10913 /* Delta vpos and y. */
10915 int debug_dvpos
, debug_dy
;
10917 /* Delta in characters and bytes for try_window_id. */
10919 int debug_delta
, debug_delta_bytes
;
10921 /* Values of window_end_pos and window_end_vpos at the end of
10924 EMACS_INT debug_end_pos
, debug_end_vpos
;
10926 /* Append a string to W->desired_matrix->method. FMT is a printf
10927 format string. A1...A9 are a supplement for a variable-length
10928 argument list. If trace_redisplay_p is non-zero also printf the
10929 resulting string to stderr. */
10932 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10935 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10938 char *method
= w
->desired_matrix
->method
;
10939 int len
= strlen (method
);
10940 int size
= sizeof w
->desired_matrix
->method
;
10941 int remaining
= size
- len
- 1;
10943 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10944 if (len
&& remaining
)
10947 --remaining
, ++len
;
10950 strncpy (method
+ len
, buffer
, remaining
);
10952 if (trace_redisplay_p
)
10953 fprintf (stderr
, "%p (%s): %s\n",
10955 ((BUFFERP (w
->buffer
)
10956 && STRINGP (XBUFFER (w
->buffer
)->name
))
10957 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10962 #endif /* GLYPH_DEBUG */
10965 /* Value is non-zero if all changes in window W, which displays
10966 current_buffer, are in the text between START and END. START is a
10967 buffer position, END is given as a distance from Z. Used in
10968 redisplay_internal for display optimization. */
10971 text_outside_line_unchanged_p (w
, start
, end
)
10975 int unchanged_p
= 1;
10977 /* If text or overlays have changed, see where. */
10978 if (XFASTINT (w
->last_modified
) < MODIFF
10979 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10981 /* Gap in the line? */
10982 if (GPT
< start
|| Z
- GPT
< end
)
10985 /* Changes start in front of the line, or end after it? */
10987 && (BEG_UNCHANGED
< start
- 1
10988 || END_UNCHANGED
< end
))
10991 /* If selective display, can't optimize if changes start at the
10992 beginning of the line. */
10994 && INTEGERP (current_buffer
->selective_display
)
10995 && XINT (current_buffer
->selective_display
) > 0
10996 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10999 /* If there are overlays at the start or end of the line, these
11000 may have overlay strings with newlines in them. A change at
11001 START, for instance, may actually concern the display of such
11002 overlay strings as well, and they are displayed on different
11003 lines. So, quickly rule out this case. (For the future, it
11004 might be desirable to implement something more telling than
11005 just BEG/END_UNCHANGED.) */
11008 if (BEG
+ BEG_UNCHANGED
== start
11009 && overlay_touches_p (start
))
11011 if (END_UNCHANGED
== end
11012 && overlay_touches_p (Z
- end
))
11017 return unchanged_p
;
11021 /* Do a frame update, taking possible shortcuts into account. This is
11022 the main external entry point for redisplay.
11024 If the last redisplay displayed an echo area message and that message
11025 is no longer requested, we clear the echo area or bring back the
11026 mini-buffer if that is in use. */
11031 redisplay_internal (0);
11036 overlay_arrow_string_or_property (var
)
11041 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11044 return Voverlay_arrow_string
;
11047 /* Return 1 if there are any overlay-arrows in current_buffer. */
11049 overlay_arrow_in_current_buffer_p ()
11053 for (vlist
= Voverlay_arrow_variable_list
;
11055 vlist
= XCDR (vlist
))
11057 Lisp_Object var
= XCAR (vlist
);
11060 if (!SYMBOLP (var
))
11062 val
= find_symbol_value (var
);
11064 && current_buffer
== XMARKER (val
)->buffer
)
11071 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11075 overlay_arrows_changed_p ()
11079 for (vlist
= Voverlay_arrow_variable_list
;
11081 vlist
= XCDR (vlist
))
11083 Lisp_Object var
= XCAR (vlist
);
11084 Lisp_Object val
, pstr
;
11086 if (!SYMBOLP (var
))
11088 val
= find_symbol_value (var
);
11089 if (!MARKERP (val
))
11091 if (! EQ (COERCE_MARKER (val
),
11092 Fget (var
, Qlast_arrow_position
))
11093 || ! (pstr
= overlay_arrow_string_or_property (var
),
11094 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11100 /* Mark overlay arrows to be updated on next redisplay. */
11103 update_overlay_arrows (up_to_date
)
11108 for (vlist
= Voverlay_arrow_variable_list
;
11110 vlist
= XCDR (vlist
))
11112 Lisp_Object var
= XCAR (vlist
);
11114 if (!SYMBOLP (var
))
11117 if (up_to_date
> 0)
11119 Lisp_Object val
= find_symbol_value (var
);
11120 Fput (var
, Qlast_arrow_position
,
11121 COERCE_MARKER (val
));
11122 Fput (var
, Qlast_arrow_string
,
11123 overlay_arrow_string_or_property (var
));
11125 else if (up_to_date
< 0
11126 || !NILP (Fget (var
, Qlast_arrow_position
)))
11128 Fput (var
, Qlast_arrow_position
, Qt
);
11129 Fput (var
, Qlast_arrow_string
, Qt
);
11135 /* Return overlay arrow string to display at row.
11136 Return integer (bitmap number) for arrow bitmap in left fringe.
11137 Return nil if no overlay arrow. */
11140 overlay_arrow_at_row (it
, row
)
11142 struct glyph_row
*row
;
11146 for (vlist
= Voverlay_arrow_variable_list
;
11148 vlist
= XCDR (vlist
))
11150 Lisp_Object var
= XCAR (vlist
);
11153 if (!SYMBOLP (var
))
11156 val
= find_symbol_value (var
);
11159 && current_buffer
== XMARKER (val
)->buffer
11160 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11162 if (FRAME_WINDOW_P (it
->f
)
11163 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11165 #ifdef HAVE_WINDOW_SYSTEM
11166 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11169 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11170 return make_number (fringe_bitmap
);
11173 return make_number (-1); /* Use default arrow bitmap */
11175 return overlay_arrow_string_or_property (var
);
11182 /* Return 1 if point moved out of or into a composition. Otherwise
11183 return 0. PREV_BUF and PREV_PT are the last point buffer and
11184 position. BUF and PT are the current point buffer and position. */
11187 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11188 struct buffer
*prev_buf
, *buf
;
11191 EMACS_INT start
, end
;
11193 Lisp_Object buffer
;
11195 XSETBUFFER (buffer
, buf
);
11196 /* Check a composition at the last point if point moved within the
11198 if (prev_buf
== buf
)
11201 /* Point didn't move. */
11204 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11205 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11206 && COMPOSITION_VALID_P (start
, end
, prop
)
11207 && start
< prev_pt
&& end
> prev_pt
)
11208 /* The last point was within the composition. Return 1 iff
11209 point moved out of the composition. */
11210 return (pt
<= start
|| pt
>= end
);
11213 /* Check a composition at the current point. */
11214 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11215 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11216 && COMPOSITION_VALID_P (start
, end
, prop
)
11217 && start
< pt
&& end
> pt
);
11221 /* Reconsider the setting of B->clip_changed which is displayed
11225 reconsider_clip_changes (w
, b
)
11229 if (b
->clip_changed
11230 && !NILP (w
->window_end_valid
)
11231 && w
->current_matrix
->buffer
== b
11232 && w
->current_matrix
->zv
== BUF_ZV (b
)
11233 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11234 b
->clip_changed
= 0;
11236 /* If display wasn't paused, and W is not a tool bar window, see if
11237 point has been moved into or out of a composition. In that case,
11238 we set b->clip_changed to 1 to force updating the screen. If
11239 b->clip_changed has already been set to 1, we can skip this
11241 if (!b
->clip_changed
11242 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11246 if (w
== XWINDOW (selected_window
))
11247 pt
= BUF_PT (current_buffer
);
11249 pt
= marker_position (w
->pointm
);
11251 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11252 || pt
!= XINT (w
->last_point
))
11253 && check_point_in_composition (w
->current_matrix
->buffer
,
11254 XINT (w
->last_point
),
11255 XBUFFER (w
->buffer
), pt
))
11256 b
->clip_changed
= 1;
11261 /* Select FRAME to forward the values of frame-local variables into C
11262 variables so that the redisplay routines can access those values
11266 select_frame_for_redisplay (frame
)
11269 Lisp_Object tail
, symbol
, val
;
11270 Lisp_Object old
= selected_frame
;
11271 struct Lisp_Symbol
*sym
;
11273 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11275 selected_frame
= frame
;
11279 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11280 if (CONSP (XCAR (tail
))
11281 && (symbol
= XCAR (XCAR (tail
)),
11283 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11285 (BUFFER_LOCAL_VALUEP (val
)))
11286 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11287 /* Use find_symbol_value rather than Fsymbol_value
11288 to avoid an error if it is void. */
11289 find_symbol_value (symbol
);
11290 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11294 #define STOP_POLLING \
11295 do { if (! polling_stopped_here) stop_polling (); \
11296 polling_stopped_here = 1; } while (0)
11298 #define RESUME_POLLING \
11299 do { if (polling_stopped_here) start_polling (); \
11300 polling_stopped_here = 0; } while (0)
11303 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11304 response to any user action; therefore, we should preserve the echo
11305 area. (Actually, our caller does that job.) Perhaps in the future
11306 avoid recentering windows if it is not necessary; currently that
11307 causes some problems. */
11310 redisplay_internal (preserve_echo_area
)
11311 int preserve_echo_area
;
11313 struct window
*w
= XWINDOW (selected_window
);
11316 int must_finish
= 0;
11317 struct text_pos tlbufpos
, tlendpos
;
11318 int number_of_visible_frames
;
11321 int polling_stopped_here
= 0;
11322 Lisp_Object old_frame
= selected_frame
;
11324 /* Non-zero means redisplay has to consider all windows on all
11325 frames. Zero means, only selected_window is considered. */
11326 int consider_all_windows_p
;
11328 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11330 /* No redisplay if running in batch mode or frame is not yet fully
11331 initialized, or redisplay is explicitly turned off by setting
11332 Vinhibit_redisplay. */
11333 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11334 || !NILP (Vinhibit_redisplay
))
11337 /* Don't examine these until after testing Vinhibit_redisplay.
11338 When Emacs is shutting down, perhaps because its connection to
11339 X has dropped, we should not look at them at all. */
11340 f
= XFRAME (w
->frame
);
11341 sf
= SELECTED_FRAME ();
11343 if (!f
->glyphs_initialized_p
)
11346 /* The flag redisplay_performed_directly_p is set by
11347 direct_output_for_insert when it already did the whole screen
11348 update necessary. */
11349 if (redisplay_performed_directly_p
)
11351 redisplay_performed_directly_p
= 0;
11352 if (!hscroll_windows (selected_window
))
11356 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11357 if (popup_activated ())
11361 /* I don't think this happens but let's be paranoid. */
11362 if (redisplaying_p
)
11365 /* Record a function that resets redisplaying_p to its old value
11366 when we leave this function. */
11367 count
= SPECPDL_INDEX ();
11368 record_unwind_protect (unwind_redisplay
,
11369 Fcons (make_number (redisplaying_p
), selected_frame
));
11371 specbind (Qinhibit_free_realized_faces
, Qnil
);
11374 Lisp_Object tail
, frame
;
11376 FOR_EACH_FRAME (tail
, frame
)
11378 struct frame
*f
= XFRAME (frame
);
11379 f
->already_hscrolled_p
= 0;
11384 if (!EQ (old_frame
, selected_frame
)
11385 && FRAME_LIVE_P (XFRAME (old_frame
)))
11386 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11387 selected_frame and selected_window to be temporarily out-of-sync so
11388 when we come back here via `goto retry', we need to resync because we
11389 may need to run Elisp code (via prepare_menu_bars). */
11390 select_frame_for_redisplay (old_frame
);
11393 reconsider_clip_changes (w
, current_buffer
);
11394 last_escape_glyph_frame
= NULL
;
11395 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11397 /* If new fonts have been loaded that make a glyph matrix adjustment
11398 necessary, do it. */
11399 if (fonts_changed_p
)
11401 adjust_glyphs (NULL
);
11402 ++windows_or_buffers_changed
;
11403 fonts_changed_p
= 0;
11406 /* If face_change_count is non-zero, init_iterator will free all
11407 realized faces, which includes the faces referenced from current
11408 matrices. So, we can't reuse current matrices in this case. */
11409 if (face_change_count
)
11410 ++windows_or_buffers_changed
;
11412 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11413 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11415 /* Since frames on a single ASCII terminal share the same
11416 display area, displaying a different frame means redisplay
11417 the whole thing. */
11418 windows_or_buffers_changed
++;
11419 SET_FRAME_GARBAGED (sf
);
11421 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11423 FRAME_TTY (sf
)->previous_frame
= sf
;
11426 /* Set the visible flags for all frames. Do this before checking
11427 for resized or garbaged frames; they want to know if their frames
11428 are visible. See the comment in frame.h for
11429 FRAME_SAMPLE_VISIBILITY. */
11431 Lisp_Object tail
, frame
;
11433 number_of_visible_frames
= 0;
11435 FOR_EACH_FRAME (tail
, frame
)
11437 struct frame
*f
= XFRAME (frame
);
11439 FRAME_SAMPLE_VISIBILITY (f
);
11440 if (FRAME_VISIBLE_P (f
))
11441 ++number_of_visible_frames
;
11442 clear_desired_matrices (f
);
11446 /* Notice any pending interrupt request to change frame size. */
11447 do_pending_window_change (1);
11449 /* Clear frames marked as garbaged. */
11450 if (frame_garbaged
)
11451 clear_garbaged_frames ();
11453 /* Build menubar and tool-bar items. */
11454 if (NILP (Vmemory_full
))
11455 prepare_menu_bars ();
11457 if (windows_or_buffers_changed
)
11458 update_mode_lines
++;
11460 /* Detect case that we need to write or remove a star in the mode line. */
11461 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11463 w
->update_mode_line
= Qt
;
11464 if (buffer_shared
> 1)
11465 update_mode_lines
++;
11468 /* Avoid invocation of point motion hooks by `current_column' below. */
11469 count1
= SPECPDL_INDEX ();
11470 specbind (Qinhibit_point_motion_hooks
, Qt
);
11472 /* If %c is in the mode line, update it if needed. */
11473 if (!NILP (w
->column_number_displayed
)
11474 /* This alternative quickly identifies a common case
11475 where no change is needed. */
11476 && !(PT
== XFASTINT (w
->last_point
)
11477 && XFASTINT (w
->last_modified
) >= MODIFF
11478 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11479 && (XFASTINT (w
->column_number_displayed
)
11480 != (int) current_column ())) /* iftc */
11481 w
->update_mode_line
= Qt
;
11483 unbind_to (count1
, Qnil
);
11485 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11487 /* The variable buffer_shared is set in redisplay_window and
11488 indicates that we redisplay a buffer in different windows. See
11490 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11491 || cursor_type_changed
);
11493 /* If specs for an arrow have changed, do thorough redisplay
11494 to ensure we remove any arrow that should no longer exist. */
11495 if (overlay_arrows_changed_p ())
11496 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11498 /* Normally the message* functions will have already displayed and
11499 updated the echo area, but the frame may have been trashed, or
11500 the update may have been preempted, so display the echo area
11501 again here. Checking message_cleared_p captures the case that
11502 the echo area should be cleared. */
11503 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11504 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11505 || (message_cleared_p
11506 && minibuf_level
== 0
11507 /* If the mini-window is currently selected, this means the
11508 echo-area doesn't show through. */
11509 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11511 int window_height_changed_p
= echo_area_display (0);
11514 /* If we don't display the current message, don't clear the
11515 message_cleared_p flag, because, if we did, we wouldn't clear
11516 the echo area in the next redisplay which doesn't preserve
11518 if (!display_last_displayed_message_p
)
11519 message_cleared_p
= 0;
11521 if (fonts_changed_p
)
11523 else if (window_height_changed_p
)
11525 consider_all_windows_p
= 1;
11526 ++update_mode_lines
;
11527 ++windows_or_buffers_changed
;
11529 /* If window configuration was changed, frames may have been
11530 marked garbaged. Clear them or we will experience
11531 surprises wrt scrolling. */
11532 if (frame_garbaged
)
11533 clear_garbaged_frames ();
11536 else if (EQ (selected_window
, minibuf_window
)
11537 && (current_buffer
->clip_changed
11538 || XFASTINT (w
->last_modified
) < MODIFF
11539 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11540 && resize_mini_window (w
, 0))
11542 /* Resized active mini-window to fit the size of what it is
11543 showing if its contents might have changed. */
11545 /* FIXME: this causes all frames to be updated, which seems unnecessary
11546 since only the current frame needs to be considered. This function needs
11547 to be rewritten with two variables, consider_all_windows and
11548 consider_all_frames. */
11549 consider_all_windows_p
= 1;
11550 ++windows_or_buffers_changed
;
11551 ++update_mode_lines
;
11553 /* If window configuration was changed, frames may have been
11554 marked garbaged. Clear them or we will experience
11555 surprises wrt scrolling. */
11556 if (frame_garbaged
)
11557 clear_garbaged_frames ();
11561 /* If showing the region, and mark has changed, we must redisplay
11562 the whole window. The assignment to this_line_start_pos prevents
11563 the optimization directly below this if-statement. */
11564 if (((!NILP (Vtransient_mark_mode
)
11565 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11566 != !NILP (w
->region_showing
))
11567 || (!NILP (w
->region_showing
)
11568 && !EQ (w
->region_showing
,
11569 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11570 CHARPOS (this_line_start_pos
) = 0;
11572 /* Optimize the case that only the line containing the cursor in the
11573 selected window has changed. Variables starting with this_ are
11574 set in display_line and record information about the line
11575 containing the cursor. */
11576 tlbufpos
= this_line_start_pos
;
11577 tlendpos
= this_line_end_pos
;
11578 if (!consider_all_windows_p
11579 && CHARPOS (tlbufpos
) > 0
11580 && NILP (w
->update_mode_line
)
11581 && !current_buffer
->clip_changed
11582 && !current_buffer
->prevent_redisplay_optimizations_p
11583 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11584 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11585 /* Make sure recorded data applies to current buffer, etc. */
11586 && this_line_buffer
== current_buffer
11587 && current_buffer
== XBUFFER (w
->buffer
)
11588 && NILP (w
->force_start
)
11589 && NILP (w
->optional_new_start
)
11590 /* Point must be on the line that we have info recorded about. */
11591 && PT
>= CHARPOS (tlbufpos
)
11592 && PT
<= Z
- CHARPOS (tlendpos
)
11593 /* All text outside that line, including its final newline,
11594 must be unchanged */
11595 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11596 CHARPOS (tlendpos
)))
11598 if (CHARPOS (tlbufpos
) > BEGV
11599 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11600 && (CHARPOS (tlbufpos
) == ZV
11601 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11602 /* Former continuation line has disappeared by becoming empty */
11604 else if (XFASTINT (w
->last_modified
) < MODIFF
11605 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11606 || MINI_WINDOW_P (w
))
11608 /* We have to handle the case of continuation around a
11609 wide-column character (See the comment in indent.c around
11612 For instance, in the following case:
11614 -------- Insert --------
11615 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11616 J_I_ ==> J_I_ `^^' are cursors.
11620 As we have to redraw the line above, we should goto cancel. */
11623 int line_height_before
= this_line_pixel_height
;
11625 /* Note that start_display will handle the case that the
11626 line starting at tlbufpos is a continuation lines. */
11627 start_display (&it
, w
, tlbufpos
);
11629 /* Implementation note: It this still necessary? */
11630 if (it
.current_x
!= this_line_start_x
)
11633 TRACE ((stderr
, "trying display optimization 1\n"));
11634 w
->cursor
.vpos
= -1;
11635 overlay_arrow_seen
= 0;
11636 it
.vpos
= this_line_vpos
;
11637 it
.current_y
= this_line_y
;
11638 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11639 display_line (&it
);
11641 /* If line contains point, is not continued,
11642 and ends at same distance from eob as before, we win */
11643 if (w
->cursor
.vpos
>= 0
11644 /* Line is not continued, otherwise this_line_start_pos
11645 would have been set to 0 in display_line. */
11646 && CHARPOS (this_line_start_pos
)
11647 /* Line ends as before. */
11648 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11649 /* Line has same height as before. Otherwise other lines
11650 would have to be shifted up or down. */
11651 && this_line_pixel_height
== line_height_before
)
11653 /* If this is not the window's last line, we must adjust
11654 the charstarts of the lines below. */
11655 if (it
.current_y
< it
.last_visible_y
)
11657 struct glyph_row
*row
11658 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11659 int delta
, delta_bytes
;
11661 /* We used to distinguish between two cases here,
11662 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11663 when the line ends in a newline or the end of the
11664 buffer's accessible portion. But both cases did
11665 the same, so they were collapsed. */
11667 - CHARPOS (tlendpos
)
11668 - MATRIX_ROW_START_CHARPOS (row
));
11669 delta_bytes
= (Z_BYTE
11670 - BYTEPOS (tlendpos
)
11671 - MATRIX_ROW_START_BYTEPOS (row
));
11673 increment_matrix_positions (w
->current_matrix
,
11674 this_line_vpos
+ 1,
11675 w
->current_matrix
->nrows
,
11676 delta
, delta_bytes
);
11679 /* If this row displays text now but previously didn't,
11680 or vice versa, w->window_end_vpos may have to be
11682 if ((it
.glyph_row
- 1)->displays_text_p
)
11684 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11685 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11687 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11688 && this_line_vpos
> 0)
11689 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11690 w
->window_end_valid
= Qnil
;
11692 /* Update hint: No need to try to scroll in update_window. */
11693 w
->desired_matrix
->no_scrolling_p
= 1;
11696 *w
->desired_matrix
->method
= 0;
11697 debug_method_add (w
, "optimization 1");
11699 #ifdef HAVE_WINDOW_SYSTEM
11700 update_window_fringes (w
, 0);
11707 else if (/* Cursor position hasn't changed. */
11708 PT
== XFASTINT (w
->last_point
)
11709 /* Make sure the cursor was last displayed
11710 in this window. Otherwise we have to reposition it. */
11711 && 0 <= w
->cursor
.vpos
11712 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11716 do_pending_window_change (1);
11718 /* We used to always goto end_of_redisplay here, but this
11719 isn't enough if we have a blinking cursor. */
11720 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11721 goto end_of_redisplay
;
11725 /* If highlighting the region, or if the cursor is in the echo area,
11726 then we can't just move the cursor. */
11727 else if (! (!NILP (Vtransient_mark_mode
)
11728 && !NILP (current_buffer
->mark_active
))
11729 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11730 || highlight_nonselected_windows
)
11731 && NILP (w
->region_showing
)
11732 && NILP (Vshow_trailing_whitespace
)
11733 && !cursor_in_echo_area
)
11736 struct glyph_row
*row
;
11738 /* Skip from tlbufpos to PT and see where it is. Note that
11739 PT may be in invisible text. If so, we will end at the
11740 next visible position. */
11741 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11742 NULL
, DEFAULT_FACE_ID
);
11743 it
.current_x
= this_line_start_x
;
11744 it
.current_y
= this_line_y
;
11745 it
.vpos
= this_line_vpos
;
11747 /* The call to move_it_to stops in front of PT, but
11748 moves over before-strings. */
11749 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11751 if (it
.vpos
== this_line_vpos
11752 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11755 xassert (this_line_vpos
== it
.vpos
);
11756 xassert (this_line_y
== it
.current_y
);
11757 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11759 *w
->desired_matrix
->method
= 0;
11760 debug_method_add (w
, "optimization 3");
11769 /* Text changed drastically or point moved off of line. */
11770 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11773 CHARPOS (this_line_start_pos
) = 0;
11774 consider_all_windows_p
|= buffer_shared
> 1;
11775 ++clear_face_cache_count
;
11776 #ifdef HAVE_WINDOW_SYSTEM
11777 ++clear_image_cache_count
;
11780 /* Build desired matrices, and update the display. If
11781 consider_all_windows_p is non-zero, do it for all windows on all
11782 frames. Otherwise do it for selected_window, only. */
11784 if (consider_all_windows_p
)
11786 Lisp_Object tail
, frame
;
11788 FOR_EACH_FRAME (tail
, frame
)
11789 XFRAME (frame
)->updated_p
= 0;
11791 /* Recompute # windows showing selected buffer. This will be
11792 incremented each time such a window is displayed. */
11795 FOR_EACH_FRAME (tail
, frame
)
11797 struct frame
*f
= XFRAME (frame
);
11799 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11801 if (! EQ (frame
, selected_frame
))
11802 /* Select the frame, for the sake of frame-local
11804 select_frame_for_redisplay (frame
);
11806 /* Mark all the scroll bars to be removed; we'll redeem
11807 the ones we want when we redisplay their windows. */
11808 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11809 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11811 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11812 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11814 /* The X error handler may have deleted that frame. */
11815 if (!FRAME_LIVE_P (f
))
11818 /* Any scroll bars which redisplay_windows should have
11819 nuked should now go away. */
11820 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11821 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11823 /* If fonts changed, display again. */
11824 /* ??? rms: I suspect it is a mistake to jump all the way
11825 back to retry here. It should just retry this frame. */
11826 if (fonts_changed_p
)
11829 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11831 /* See if we have to hscroll. */
11832 if (!f
->already_hscrolled_p
)
11834 f
->already_hscrolled_p
= 1;
11835 if (hscroll_windows (f
->root_window
))
11839 /* Prevent various kinds of signals during display
11840 update. stdio is not robust about handling
11841 signals, which can cause an apparent I/O
11843 if (interrupt_input
)
11844 unrequest_sigio ();
11847 /* Update the display. */
11848 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11849 pause
|= update_frame (f
, 0, 0);
11855 if (!EQ (old_frame
, selected_frame
)
11856 && FRAME_LIVE_P (XFRAME (old_frame
)))
11857 /* We played a bit fast-and-loose above and allowed selected_frame
11858 and selected_window to be temporarily out-of-sync but let's make
11859 sure this stays contained. */
11860 select_frame_for_redisplay (old_frame
);
11861 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11865 /* Do the mark_window_display_accurate after all windows have
11866 been redisplayed because this call resets flags in buffers
11867 which are needed for proper redisplay. */
11868 FOR_EACH_FRAME (tail
, frame
)
11870 struct frame
*f
= XFRAME (frame
);
11873 mark_window_display_accurate (f
->root_window
, 1);
11874 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11875 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11880 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11882 Lisp_Object mini_window
;
11883 struct frame
*mini_frame
;
11885 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11886 /* Use list_of_error, not Qerror, so that
11887 we catch only errors and don't run the debugger. */
11888 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11890 redisplay_window_error
);
11892 /* Compare desired and current matrices, perform output. */
11895 /* If fonts changed, display again. */
11896 if (fonts_changed_p
)
11899 /* Prevent various kinds of signals during display update.
11900 stdio is not robust about handling signals,
11901 which can cause an apparent I/O error. */
11902 if (interrupt_input
)
11903 unrequest_sigio ();
11906 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11908 if (hscroll_windows (selected_window
))
11911 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11912 pause
= update_frame (sf
, 0, 0);
11915 /* We may have called echo_area_display at the top of this
11916 function. If the echo area is on another frame, that may
11917 have put text on a frame other than the selected one, so the
11918 above call to update_frame would not have caught it. Catch
11920 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11921 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11923 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11925 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11926 pause
|= update_frame (mini_frame
, 0, 0);
11927 if (!pause
&& hscroll_windows (mini_window
))
11932 /* If display was paused because of pending input, make sure we do a
11933 thorough update the next time. */
11936 /* Prevent the optimization at the beginning of
11937 redisplay_internal that tries a single-line update of the
11938 line containing the cursor in the selected window. */
11939 CHARPOS (this_line_start_pos
) = 0;
11941 /* Let the overlay arrow be updated the next time. */
11942 update_overlay_arrows (0);
11944 /* If we pause after scrolling, some rows in the current
11945 matrices of some windows are not valid. */
11946 if (!WINDOW_FULL_WIDTH_P (w
)
11947 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11948 update_mode_lines
= 1;
11952 if (!consider_all_windows_p
)
11954 /* This has already been done above if
11955 consider_all_windows_p is set. */
11956 mark_window_display_accurate_1 (w
, 1);
11958 /* Say overlay arrows are up to date. */
11959 update_overlay_arrows (1);
11961 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11962 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11965 update_mode_lines
= 0;
11966 windows_or_buffers_changed
= 0;
11967 cursor_type_changed
= 0;
11970 /* Start SIGIO interrupts coming again. Having them off during the
11971 code above makes it less likely one will discard output, but not
11972 impossible, since there might be stuff in the system buffer here.
11973 But it is much hairier to try to do anything about that. */
11974 if (interrupt_input
)
11978 /* If a frame has become visible which was not before, redisplay
11979 again, so that we display it. Expose events for such a frame
11980 (which it gets when becoming visible) don't call the parts of
11981 redisplay constructing glyphs, so simply exposing a frame won't
11982 display anything in this case. So, we have to display these
11983 frames here explicitly. */
11986 Lisp_Object tail
, frame
;
11989 FOR_EACH_FRAME (tail
, frame
)
11991 int this_is_visible
= 0;
11993 if (XFRAME (frame
)->visible
)
11994 this_is_visible
= 1;
11995 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11996 if (XFRAME (frame
)->visible
)
11997 this_is_visible
= 1;
11999 if (this_is_visible
)
12003 if (new_count
!= number_of_visible_frames
)
12004 windows_or_buffers_changed
++;
12007 /* Change frame size now if a change is pending. */
12008 do_pending_window_change (1);
12010 /* If we just did a pending size change, or have additional
12011 visible frames, redisplay again. */
12012 if (windows_or_buffers_changed
&& !pause
)
12015 /* Clear the face cache eventually. */
12016 if (consider_all_windows_p
)
12018 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12020 clear_face_cache (0);
12021 clear_face_cache_count
= 0;
12023 #ifdef HAVE_WINDOW_SYSTEM
12024 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12026 clear_image_caches (Qnil
);
12027 clear_image_cache_count
= 0;
12029 #endif /* HAVE_WINDOW_SYSTEM */
12033 unbind_to (count
, Qnil
);
12038 /* Redisplay, but leave alone any recent echo area message unless
12039 another message has been requested in its place.
12041 This is useful in situations where you need to redisplay but no
12042 user action has occurred, making it inappropriate for the message
12043 area to be cleared. See tracking_off and
12044 wait_reading_process_output for examples of these situations.
12046 FROM_WHERE is an integer saying from where this function was
12047 called. This is useful for debugging. */
12050 redisplay_preserve_echo_area (from_where
)
12053 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12055 if (!NILP (echo_area_buffer
[1]))
12057 /* We have a previously displayed message, but no current
12058 message. Redisplay the previous message. */
12059 display_last_displayed_message_p
= 1;
12060 redisplay_internal (1);
12061 display_last_displayed_message_p
= 0;
12064 redisplay_internal (1);
12066 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12067 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12068 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12072 /* Function registered with record_unwind_protect in
12073 redisplay_internal. Reset redisplaying_p to the value it had
12074 before redisplay_internal was called, and clear
12075 prevent_freeing_realized_faces_p. It also selects the previously
12076 selected frame, unless it has been deleted (by an X connection
12077 failure during redisplay, for example). */
12080 unwind_redisplay (val
)
12083 Lisp_Object old_redisplaying_p
, old_frame
;
12085 old_redisplaying_p
= XCAR (val
);
12086 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12087 old_frame
= XCDR (val
);
12088 if (! EQ (old_frame
, selected_frame
)
12089 && FRAME_LIVE_P (XFRAME (old_frame
)))
12090 select_frame_for_redisplay (old_frame
);
12095 /* Mark the display of window W as accurate or inaccurate. If
12096 ACCURATE_P is non-zero mark display of W as accurate. If
12097 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12098 redisplay_internal is called. */
12101 mark_window_display_accurate_1 (w
, accurate_p
)
12105 if (BUFFERP (w
->buffer
))
12107 struct buffer
*b
= XBUFFER (w
->buffer
);
12110 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12111 w
->last_overlay_modified
12112 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12114 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12118 b
->clip_changed
= 0;
12119 b
->prevent_redisplay_optimizations_p
= 0;
12121 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12122 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12123 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12124 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12126 w
->current_matrix
->buffer
= b
;
12127 w
->current_matrix
->begv
= BUF_BEGV (b
);
12128 w
->current_matrix
->zv
= BUF_ZV (b
);
12130 w
->last_cursor
= w
->cursor
;
12131 w
->last_cursor_off_p
= w
->cursor_off_p
;
12133 if (w
== XWINDOW (selected_window
))
12134 w
->last_point
= make_number (BUF_PT (b
));
12136 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12142 w
->window_end_valid
= w
->buffer
;
12143 w
->update_mode_line
= Qnil
;
12148 /* Mark the display of windows in the window tree rooted at WINDOW as
12149 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12150 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12151 be redisplayed the next time redisplay_internal is called. */
12154 mark_window_display_accurate (window
, accurate_p
)
12155 Lisp_Object window
;
12160 for (; !NILP (window
); window
= w
->next
)
12162 w
= XWINDOW (window
);
12163 mark_window_display_accurate_1 (w
, accurate_p
);
12165 if (!NILP (w
->vchild
))
12166 mark_window_display_accurate (w
->vchild
, accurate_p
);
12167 if (!NILP (w
->hchild
))
12168 mark_window_display_accurate (w
->hchild
, accurate_p
);
12173 update_overlay_arrows (1);
12177 /* Force a thorough redisplay the next time by setting
12178 last_arrow_position and last_arrow_string to t, which is
12179 unequal to any useful value of Voverlay_arrow_... */
12180 update_overlay_arrows (-1);
12185 /* Return value in display table DP (Lisp_Char_Table *) for character
12186 C. Since a display table doesn't have any parent, we don't have to
12187 follow parent. Do not call this function directly but use the
12188 macro DISP_CHAR_VECTOR. */
12191 disp_char_vector (dp
, c
)
12192 struct Lisp_Char_Table
*dp
;
12197 if (ASCII_CHAR_P (c
))
12200 if (SUB_CHAR_TABLE_P (val
))
12201 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12207 XSETCHAR_TABLE (table
, dp
);
12208 val
= char_table_ref (table
, c
);
12217 /***********************************************************************
12219 ***********************************************************************/
12221 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12224 redisplay_windows (window
)
12225 Lisp_Object window
;
12227 while (!NILP (window
))
12229 struct window
*w
= XWINDOW (window
);
12231 if (!NILP (w
->hchild
))
12232 redisplay_windows (w
->hchild
);
12233 else if (!NILP (w
->vchild
))
12234 redisplay_windows (w
->vchild
);
12235 else if (!NILP (w
->buffer
))
12237 displayed_buffer
= XBUFFER (w
->buffer
);
12238 /* Use list_of_error, not Qerror, so that
12239 we catch only errors and don't run the debugger. */
12240 internal_condition_case_1 (redisplay_window_0
, window
,
12242 redisplay_window_error
);
12250 redisplay_window_error ()
12252 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12257 redisplay_window_0 (window
)
12258 Lisp_Object window
;
12260 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12261 redisplay_window (window
, 0);
12266 redisplay_window_1 (window
)
12267 Lisp_Object window
;
12269 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12270 redisplay_window (window
, 1);
12275 /* Increment GLYPH until it reaches END or CONDITION fails while
12276 adding (GLYPH)->pixel_width to X. */
12278 #define SKIP_GLYPHS(glyph, end, x, condition) \
12281 (x) += (glyph)->pixel_width; \
12284 while ((glyph) < (end) && (condition))
12287 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12288 DELTA is the number of bytes by which positions recorded in ROW
12289 differ from current buffer positions.
12291 Return 0 if cursor is not on this row. 1 otherwise. */
12294 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12296 struct glyph_row
*row
;
12297 struct glyph_matrix
*matrix
;
12298 int delta
, delta_bytes
, dy
, dvpos
;
12300 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12301 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12302 struct glyph
*cursor
= NULL
;
12303 /* The first glyph that starts a sequence of glyphs from string. */
12304 struct glyph
*string_start
;
12305 /* The X coordinate of string_start. */
12306 int string_start_x
;
12307 /* The last known character position. */
12308 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12309 /* The last known character position before string_start. */
12310 int string_before_pos
;
12313 int cursor_from_overlay_pos
= 0;
12314 int pt_old
= PT
- delta
;
12316 /* Skip over glyphs not having an object at the start of the row.
12317 These are special glyphs like truncation marks on terminal
12319 if (row
->displays_text_p
)
12321 && INTEGERP (glyph
->object
)
12322 && glyph
->charpos
< 0)
12324 x
+= glyph
->pixel_width
;
12328 string_start
= NULL
;
12330 && !INTEGERP (glyph
->object
)
12331 && (!BUFFERP (glyph
->object
)
12332 || (last_pos
= glyph
->charpos
) < pt_old
12333 || glyph
->avoid_cursor_p
))
12335 if (! STRINGP (glyph
->object
))
12337 string_start
= NULL
;
12338 x
+= glyph
->pixel_width
;
12340 if (cursor_from_overlay_pos
12341 && last_pos
>= cursor_from_overlay_pos
)
12343 cursor_from_overlay_pos
= 0;
12349 if (string_start
== NULL
)
12351 string_before_pos
= last_pos
;
12352 string_start
= glyph
;
12353 string_start_x
= x
;
12355 /* Skip all glyphs from string. */
12360 if ((cursor
== NULL
|| glyph
> cursor
)
12361 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12362 Qcursor
, (glyph
)->object
),
12364 && (pos
= string_buffer_position (w
, glyph
->object
,
12365 string_before_pos
),
12366 (pos
== 0 /* From overlay */
12367 || pos
== pt_old
)))
12369 /* Estimate overlay buffer position from the buffer
12370 positions of the glyphs before and after the overlay.
12371 Add 1 to last_pos so that if point corresponds to the
12372 glyph right after the overlay, we still use a 'cursor'
12373 property found in that overlay. */
12374 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12375 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12379 x
+= glyph
->pixel_width
;
12382 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12386 if (cursor
!= NULL
)
12391 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12393 /* Scan back over the ellipsis glyphs, decrementing positions. */
12394 while (glyph
> row
->glyphs
[TEXT_AREA
]
12395 && (glyph
- 1)->charpos
== last_pos
)
12396 glyph
--, x
-= glyph
->pixel_width
;
12397 /* That loop always goes one position too far,
12398 including the glyph before the ellipsis.
12399 So scan forward over that one. */
12400 x
+= glyph
->pixel_width
;
12403 else if (string_start
12404 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12406 /* We may have skipped over point because the previous glyphs
12407 are from string. As there's no easy way to know the
12408 character position of the current glyph, find the correct
12409 glyph on point by scanning from string_start again. */
12411 Lisp_Object string
;
12412 struct glyph
*stop
= glyph
;
12415 limit
= make_number (pt_old
+ 1);
12416 glyph
= string_start
;
12417 x
= string_start_x
;
12418 string
= glyph
->object
;
12419 pos
= string_buffer_position (w
, string
, string_before_pos
);
12420 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12421 because we always put cursor after overlay strings. */
12422 while (pos
== 0 && glyph
< stop
)
12424 string
= glyph
->object
;
12425 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12427 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12430 while (glyph
< stop
)
12432 pos
= XINT (Fnext_single_char_property_change
12433 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12436 /* Skip glyphs from the same string. */
12437 string
= glyph
->object
;
12438 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12439 /* Skip glyphs from an overlay. */
12440 while (glyph
< stop
12441 && ! string_buffer_position (w
, glyph
->object
, pos
))
12443 string
= glyph
->object
;
12444 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12448 /* If we reached the end of the line, and end was from a string,
12449 cursor is not on this line. */
12450 if (glyph
== end
&& row
->continued_p
)
12454 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12456 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12457 w
->cursor
.y
= row
->y
+ dy
;
12459 if (w
== XWINDOW (selected_window
))
12461 if (!row
->continued_p
12462 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12465 this_line_buffer
= XBUFFER (w
->buffer
);
12467 CHARPOS (this_line_start_pos
)
12468 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12469 BYTEPOS (this_line_start_pos
)
12470 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12472 CHARPOS (this_line_end_pos
)
12473 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12474 BYTEPOS (this_line_end_pos
)
12475 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12477 this_line_y
= w
->cursor
.y
;
12478 this_line_pixel_height
= row
->height
;
12479 this_line_vpos
= w
->cursor
.vpos
;
12480 this_line_start_x
= row
->x
;
12483 CHARPOS (this_line_start_pos
) = 0;
12490 /* Run window scroll functions, if any, for WINDOW with new window
12491 start STARTP. Sets the window start of WINDOW to that position.
12493 We assume that the window's buffer is really current. */
12495 static INLINE
struct text_pos
12496 run_window_scroll_functions (window
, startp
)
12497 Lisp_Object window
;
12498 struct text_pos startp
;
12500 struct window
*w
= XWINDOW (window
);
12501 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12503 if (current_buffer
!= XBUFFER (w
->buffer
))
12506 if (!NILP (Vwindow_scroll_functions
))
12508 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12509 make_number (CHARPOS (startp
)));
12510 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12511 /* In case the hook functions switch buffers. */
12512 if (current_buffer
!= XBUFFER (w
->buffer
))
12513 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12520 /* Make sure the line containing the cursor is fully visible.
12521 A value of 1 means there is nothing to be done.
12522 (Either the line is fully visible, or it cannot be made so,
12523 or we cannot tell.)
12525 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12526 is higher than window.
12528 A value of 0 means the caller should do scrolling
12529 as if point had gone off the screen. */
12532 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12535 int current_matrix_p
;
12537 struct glyph_matrix
*matrix
;
12538 struct glyph_row
*row
;
12541 if (!make_cursor_line_fully_visible_p
)
12544 /* It's not always possible to find the cursor, e.g, when a window
12545 is full of overlay strings. Don't do anything in that case. */
12546 if (w
->cursor
.vpos
< 0)
12549 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12550 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12552 /* If the cursor row is not partially visible, there's nothing to do. */
12553 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12556 /* If the row the cursor is in is taller than the window's height,
12557 it's not clear what to do, so do nothing. */
12558 window_height
= window_box_height (w
);
12559 if (row
->height
>= window_height
)
12561 if (!force_p
|| MINI_WINDOW_P (w
)
12562 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12569 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12570 non-zero means only WINDOW is redisplayed in redisplay_internal.
12571 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12572 in redisplay_window to bring a partially visible line into view in
12573 the case that only the cursor has moved.
12575 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12576 last screen line's vertical height extends past the end of the screen.
12580 1 if scrolling succeeded
12582 0 if scrolling didn't find point.
12584 -1 if new fonts have been loaded so that we must interrupt
12585 redisplay, adjust glyph matrices, and try again. */
12591 SCROLLING_NEED_LARGER_MATRICES
12595 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12596 scroll_step
, temp_scroll_step
, last_line_misfit
)
12597 Lisp_Object window
;
12598 int just_this_one_p
;
12599 EMACS_INT scroll_conservatively
, scroll_step
;
12600 int temp_scroll_step
;
12601 int last_line_misfit
;
12603 struct window
*w
= XWINDOW (window
);
12604 struct frame
*f
= XFRAME (w
->frame
);
12605 struct text_pos pos
, startp
;
12607 int this_scroll_margin
, scroll_max
, rc
, height
;
12608 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12609 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12610 Lisp_Object aggressive
;
12611 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12614 debug_method_add (w
, "try_scrolling");
12617 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12619 /* Compute scroll margin height in pixels. We scroll when point is
12620 within this distance from the top or bottom of the window. */
12621 if (scroll_margin
> 0)
12622 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
12623 * FRAME_LINE_HEIGHT (f
);
12625 this_scroll_margin
= 0;
12627 /* Force scroll_conservatively to have a reasonable value, to avoid
12628 overflow while computing how much to scroll. Note that the user
12629 can supply scroll-conservatively equal to `most-positive-fixnum',
12630 which can be larger than INT_MAX. */
12631 if (scroll_conservatively
> scroll_limit
)
12633 scroll_conservatively
= scroll_limit
;
12634 scroll_max
= INT_MAX
;
12636 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12637 /* Compute how much we should try to scroll maximally to bring
12638 point into view. */
12639 scroll_max
= (max (scroll_step
,
12640 max (scroll_conservatively
, temp_scroll_step
))
12641 * FRAME_LINE_HEIGHT (f
));
12642 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12643 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12644 /* We're trying to scroll because of aggressive scrolling but no
12645 scroll_step is set. Choose an arbitrary one. */
12646 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12652 /* Decide whether to scroll down. */
12653 if (PT
> CHARPOS (startp
))
12655 int scroll_margin_y
;
12657 /* Compute the pixel ypos of the scroll margin, then move it to
12658 either that ypos or PT, whichever comes first. */
12659 start_display (&it
, w
, startp
);
12660 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12661 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12662 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12663 (MOVE_TO_POS
| MOVE_TO_Y
));
12665 if (PT
> CHARPOS (it
.current
.pos
))
12667 int y0
= line_bottom_y (&it
);
12669 /* Compute the distance from the scroll margin to PT
12670 (including the height of the cursor line). Moving the
12671 iterator unconditionally to PT can be slow if PT is far
12672 away, so stop 10 lines past the window bottom (is there a
12673 way to do the right thing quickly?). */
12674 move_it_to (&it
, PT
, -1,
12675 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
12676 -1, MOVE_TO_POS
| MOVE_TO_Y
);
12677 dy
= line_bottom_y (&it
) - y0
;
12679 if (dy
> scroll_max
)
12680 return SCROLLING_FAILED
;
12688 /* Point is in or below the bottom scroll margin, so move the
12689 window start down. If scrolling conservatively, move it just
12690 enough down to make point visible. If scroll_step is set,
12691 move it down by scroll_step. */
12692 if (scroll_conservatively
)
12694 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12695 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12696 else if (scroll_step
|| temp_scroll_step
)
12697 amount_to_scroll
= scroll_max
;
12700 aggressive
= current_buffer
->scroll_up_aggressively
;
12701 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12702 if (NUMBERP (aggressive
))
12704 double float_amount
= XFLOATINT (aggressive
) * height
;
12705 amount_to_scroll
= float_amount
;
12706 if (amount_to_scroll
== 0 && float_amount
> 0)
12707 amount_to_scroll
= 1;
12711 if (amount_to_scroll
<= 0)
12712 return SCROLLING_FAILED
;
12714 start_display (&it
, w
, startp
);
12715 move_it_vertically (&it
, amount_to_scroll
);
12717 /* If STARTP is unchanged, move it down another screen line. */
12718 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12719 move_it_by_lines (&it
, 1, 1);
12720 startp
= it
.current
.pos
;
12724 struct text_pos scroll_margin_pos
= startp
;
12726 /* See if point is inside the scroll margin at the top of the
12728 if (this_scroll_margin
)
12730 start_display (&it
, w
, startp
);
12731 move_it_vertically (&it
, this_scroll_margin
);
12732 scroll_margin_pos
= it
.current
.pos
;
12735 if (PT
< CHARPOS (scroll_margin_pos
))
12737 /* Point is in the scroll margin at the top of the window or
12738 above what is displayed in the window. */
12741 /* Compute the vertical distance from PT to the scroll
12742 margin position. Give up if distance is greater than
12744 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12745 start_display (&it
, w
, pos
);
12747 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12748 it
.last_visible_y
, -1,
12749 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12750 dy
= it
.current_y
- y0
;
12751 if (dy
> scroll_max
)
12752 return SCROLLING_FAILED
;
12754 /* Compute new window start. */
12755 start_display (&it
, w
, startp
);
12757 if (scroll_conservatively
)
12759 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12760 else if (scroll_step
|| temp_scroll_step
)
12761 amount_to_scroll
= scroll_max
;
12764 aggressive
= current_buffer
->scroll_down_aggressively
;
12765 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12766 if (NUMBERP (aggressive
))
12768 double float_amount
= XFLOATINT (aggressive
) * height
;
12769 amount_to_scroll
= float_amount
;
12770 if (amount_to_scroll
== 0 && float_amount
> 0)
12771 amount_to_scroll
= 1;
12775 if (amount_to_scroll
<= 0)
12776 return SCROLLING_FAILED
;
12778 move_it_vertically_backward (&it
, amount_to_scroll
);
12779 startp
= it
.current
.pos
;
12783 /* Run window scroll functions. */
12784 startp
= run_window_scroll_functions (window
, startp
);
12786 /* Display the window. Give up if new fonts are loaded, or if point
12788 if (!try_window (window
, startp
, 0))
12789 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12790 else if (w
->cursor
.vpos
< 0)
12792 clear_glyph_matrix (w
->desired_matrix
);
12793 rc
= SCROLLING_FAILED
;
12797 /* Maybe forget recorded base line for line number display. */
12798 if (!just_this_one_p
12799 || current_buffer
->clip_changed
12800 || BEG_UNCHANGED
< CHARPOS (startp
))
12801 w
->base_line_number
= Qnil
;
12803 /* If cursor ends up on a partially visible line,
12804 treat that as being off the bottom of the screen. */
12805 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12807 clear_glyph_matrix (w
->desired_matrix
);
12808 ++extra_scroll_margin_lines
;
12811 rc
= SCROLLING_SUCCESS
;
12818 /* Compute a suitable window start for window W if display of W starts
12819 on a continuation line. Value is non-zero if a new window start
12822 The new window start will be computed, based on W's width, starting
12823 from the start of the continued line. It is the start of the
12824 screen line with the minimum distance from the old start W->start. */
12827 compute_window_start_on_continuation_line (w
)
12830 struct text_pos pos
, start_pos
;
12831 int window_start_changed_p
= 0;
12833 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12835 /* If window start is on a continuation line... Window start may be
12836 < BEGV in case there's invisible text at the start of the
12837 buffer (M-x rmail, for example). */
12838 if (CHARPOS (start_pos
) > BEGV
12839 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12842 struct glyph_row
*row
;
12844 /* Handle the case that the window start is out of range. */
12845 if (CHARPOS (start_pos
) < BEGV
)
12846 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12847 else if (CHARPOS (start_pos
) > ZV
)
12848 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12850 /* Find the start of the continued line. This should be fast
12851 because scan_buffer is fast (newline cache). */
12852 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12853 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12854 row
, DEFAULT_FACE_ID
);
12855 reseat_at_previous_visible_line_start (&it
);
12857 /* If the line start is "too far" away from the window start,
12858 say it takes too much time to compute a new window start. */
12859 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12860 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12862 int min_distance
, distance
;
12864 /* Move forward by display lines to find the new window
12865 start. If window width was enlarged, the new start can
12866 be expected to be > the old start. If window width was
12867 decreased, the new window start will be < the old start.
12868 So, we're looking for the display line start with the
12869 minimum distance from the old window start. */
12870 pos
= it
.current
.pos
;
12871 min_distance
= INFINITY
;
12872 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12873 distance
< min_distance
)
12875 min_distance
= distance
;
12876 pos
= it
.current
.pos
;
12877 move_it_by_lines (&it
, 1, 0);
12880 /* Set the window start there. */
12881 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12882 window_start_changed_p
= 1;
12886 return window_start_changed_p
;
12890 /* Try cursor movement in case text has not changed in window WINDOW,
12891 with window start STARTP. Value is
12893 CURSOR_MOVEMENT_SUCCESS if successful
12895 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12897 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12898 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12899 we want to scroll as if scroll-step were set to 1. See the code.
12901 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12902 which case we have to abort this redisplay, and adjust matrices
12907 CURSOR_MOVEMENT_SUCCESS
,
12908 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12909 CURSOR_MOVEMENT_MUST_SCROLL
,
12910 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12914 try_cursor_movement (window
, startp
, scroll_step
)
12915 Lisp_Object window
;
12916 struct text_pos startp
;
12919 struct window
*w
= XWINDOW (window
);
12920 struct frame
*f
= XFRAME (w
->frame
);
12921 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12924 if (inhibit_try_cursor_movement
)
12928 /* Handle case where text has not changed, only point, and it has
12929 not moved off the frame. */
12930 if (/* Point may be in this window. */
12931 PT
>= CHARPOS (startp
)
12932 /* Selective display hasn't changed. */
12933 && !current_buffer
->clip_changed
12934 /* Function force-mode-line-update is used to force a thorough
12935 redisplay. It sets either windows_or_buffers_changed or
12936 update_mode_lines. So don't take a shortcut here for these
12938 && !update_mode_lines
12939 && !windows_or_buffers_changed
12940 && !cursor_type_changed
12941 /* Can't use this case if highlighting a region. When a
12942 region exists, cursor movement has to do more than just
12944 && !(!NILP (Vtransient_mark_mode
)
12945 && !NILP (current_buffer
->mark_active
))
12946 && NILP (w
->region_showing
)
12947 && NILP (Vshow_trailing_whitespace
)
12948 /* Right after splitting windows, last_point may be nil. */
12949 && INTEGERP (w
->last_point
)
12950 /* This code is not used for mini-buffer for the sake of the case
12951 of redisplaying to replace an echo area message; since in
12952 that case the mini-buffer contents per se are usually
12953 unchanged. This code is of no real use in the mini-buffer
12954 since the handling of this_line_start_pos, etc., in redisplay
12955 handles the same cases. */
12956 && !EQ (window
, minibuf_window
)
12957 /* When splitting windows or for new windows, it happens that
12958 redisplay is called with a nil window_end_vpos or one being
12959 larger than the window. This should really be fixed in
12960 window.c. I don't have this on my list, now, so we do
12961 approximately the same as the old redisplay code. --gerd. */
12962 && INTEGERP (w
->window_end_vpos
)
12963 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12964 && (FRAME_WINDOW_P (f
)
12965 || !overlay_arrow_in_current_buffer_p ()))
12967 int this_scroll_margin
, top_scroll_margin
;
12968 struct glyph_row
*row
= NULL
;
12971 debug_method_add (w
, "cursor movement");
12974 /* Scroll if point within this distance from the top or bottom
12975 of the window. This is a pixel value. */
12976 if (scroll_margin
> 0)
12978 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12979 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12982 this_scroll_margin
= 0;
12984 top_scroll_margin
= this_scroll_margin
;
12985 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12986 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12988 /* Start with the row the cursor was displayed during the last
12989 not paused redisplay. Give up if that row is not valid. */
12990 if (w
->last_cursor
.vpos
< 0
12991 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12992 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12995 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12996 if (row
->mode_line_p
)
12998 if (!row
->enabled_p
)
12999 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13002 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13005 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13007 if (PT
> XFASTINT (w
->last_point
))
13009 /* Point has moved forward. */
13010 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13011 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13013 xassert (row
->enabled_p
);
13017 /* The end position of a row equals the start position
13018 of the next row. If PT is there, we would rather
13019 display it in the next line. */
13020 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13021 && MATRIX_ROW_END_CHARPOS (row
) == PT
13022 && !cursor_row_p (w
, row
))
13025 /* If within the scroll margin, scroll. Note that
13026 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13027 the next line would be drawn, and that
13028 this_scroll_margin can be zero. */
13029 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13030 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13031 /* Line is completely visible last line in window
13032 and PT is to be set in the next line. */
13033 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13034 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13035 && !row
->ends_at_zv_p
13036 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13039 else if (PT
< XFASTINT (w
->last_point
))
13041 /* Cursor has to be moved backward. Note that PT >=
13042 CHARPOS (startp) because of the outer if-statement. */
13043 while (!row
->mode_line_p
13044 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13045 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13046 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13047 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13048 row
> w
->current_matrix
->rows
13049 && (row
-1)->ends_in_newline_from_string_p
))))
13050 && (row
->y
> top_scroll_margin
13051 || CHARPOS (startp
) == BEGV
))
13053 xassert (row
->enabled_p
);
13057 /* Consider the following case: Window starts at BEGV,
13058 there is invisible, intangible text at BEGV, so that
13059 display starts at some point START > BEGV. It can
13060 happen that we are called with PT somewhere between
13061 BEGV and START. Try to handle that case. */
13062 if (row
< w
->current_matrix
->rows
13063 || row
->mode_line_p
)
13065 row
= w
->current_matrix
->rows
;
13066 if (row
->mode_line_p
)
13070 /* Due to newlines in overlay strings, we may have to
13071 skip forward over overlay strings. */
13072 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13073 && MATRIX_ROW_END_CHARPOS (row
) == PT
13074 && !cursor_row_p (w
, row
))
13077 /* If within the scroll margin, scroll. */
13078 if (row
->y
< top_scroll_margin
13079 && CHARPOS (startp
) != BEGV
)
13084 /* Cursor did not move. So don't scroll even if cursor line
13085 is partially visible, as it was so before. */
13086 rc
= CURSOR_MOVEMENT_SUCCESS
;
13089 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13090 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13092 /* if PT is not in the glyph row, give up. */
13093 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13095 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13096 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13097 && make_cursor_line_fully_visible_p
)
13099 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13100 && !row
->ends_at_zv_p
13101 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13102 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13103 else if (row
->height
> window_box_height (w
))
13105 /* If we end up in a partially visible line, let's
13106 make it fully visible, except when it's taller
13107 than the window, in which case we can't do much
13110 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13114 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13115 if (!cursor_row_fully_visible_p (w
, 0, 1))
13116 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13118 rc
= CURSOR_MOVEMENT_SUCCESS
;
13122 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13127 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13129 rc
= CURSOR_MOVEMENT_SUCCESS
;
13134 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13135 && MATRIX_ROW_START_CHARPOS (row
) == PT
13136 && cursor_row_p (w
, row
));
13145 set_vertical_scroll_bar (w
)
13148 int start
, end
, whole
;
13150 /* Calculate the start and end positions for the current window.
13151 At some point, it would be nice to choose between scrollbars
13152 which reflect the whole buffer size, with special markers
13153 indicating narrowing, and scrollbars which reflect only the
13156 Note that mini-buffers sometimes aren't displaying any text. */
13157 if (!MINI_WINDOW_P (w
)
13158 || (w
== XWINDOW (minibuf_window
)
13159 && NILP (echo_area_buffer
[0])))
13161 struct buffer
*buf
= XBUFFER (w
->buffer
);
13162 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13163 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13164 /* I don't think this is guaranteed to be right. For the
13165 moment, we'll pretend it is. */
13166 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13170 if (whole
< (end
- start
))
13171 whole
= end
- start
;
13174 start
= end
= whole
= 0;
13176 /* Indicate what this scroll bar ought to be displaying now. */
13177 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13178 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13179 (w
, end
- start
, whole
, start
);
13183 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13184 selected_window is redisplayed.
13186 We can return without actually redisplaying the window if
13187 fonts_changed_p is nonzero. In that case, redisplay_internal will
13191 redisplay_window (window
, just_this_one_p
)
13192 Lisp_Object window
;
13193 int just_this_one_p
;
13195 struct window
*w
= XWINDOW (window
);
13196 struct frame
*f
= XFRAME (w
->frame
);
13197 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13198 struct buffer
*old
= current_buffer
;
13199 struct text_pos lpoint
, opoint
, startp
;
13200 int update_mode_line
;
13203 /* Record it now because it's overwritten. */
13204 int current_matrix_up_to_date_p
= 0;
13205 int used_current_matrix_p
= 0;
13206 /* This is less strict than current_matrix_up_to_date_p.
13207 It indictes that the buffer contents and narrowing are unchanged. */
13208 int buffer_unchanged_p
= 0;
13209 int temp_scroll_step
= 0;
13210 int count
= SPECPDL_INDEX ();
13212 int centering_position
= -1;
13213 int last_line_misfit
= 0;
13214 int beg_unchanged
, end_unchanged
;
13216 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13219 /* W must be a leaf window here. */
13220 xassert (!NILP (w
->buffer
));
13222 *w
->desired_matrix
->method
= 0;
13226 reconsider_clip_changes (w
, buffer
);
13228 /* Has the mode line to be updated? */
13229 update_mode_line
= (!NILP (w
->update_mode_line
)
13230 || update_mode_lines
13231 || buffer
->clip_changed
13232 || buffer
->prevent_redisplay_optimizations_p
);
13234 if (MINI_WINDOW_P (w
))
13236 if (w
== XWINDOW (echo_area_window
)
13237 && !NILP (echo_area_buffer
[0]))
13239 if (update_mode_line
)
13240 /* We may have to update a tty frame's menu bar or a
13241 tool-bar. Example `M-x C-h C-h C-g'. */
13242 goto finish_menu_bars
;
13244 /* We've already displayed the echo area glyphs in this window. */
13245 goto finish_scroll_bars
;
13247 else if ((w
!= XWINDOW (minibuf_window
)
13248 || minibuf_level
== 0)
13249 /* When buffer is nonempty, redisplay window normally. */
13250 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13251 /* Quail displays non-mini buffers in minibuffer window.
13252 In that case, redisplay the window normally. */
13253 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13255 /* W is a mini-buffer window, but it's not active, so clear
13257 int yb
= window_text_bottom_y (w
);
13258 struct glyph_row
*row
;
13261 for (y
= 0, row
= w
->desired_matrix
->rows
;
13263 y
+= row
->height
, ++row
)
13264 blank_row (w
, row
, y
);
13265 goto finish_scroll_bars
;
13268 clear_glyph_matrix (w
->desired_matrix
);
13271 /* Otherwise set up data on this window; select its buffer and point
13273 /* Really select the buffer, for the sake of buffer-local
13275 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13277 current_matrix_up_to_date_p
13278 = (!NILP (w
->window_end_valid
)
13279 && !current_buffer
->clip_changed
13280 && !current_buffer
->prevent_redisplay_optimizations_p
13281 && XFASTINT (w
->last_modified
) >= MODIFF
13282 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13284 /* Run the window-bottom-change-functions
13285 if it is possible that the text on the screen has changed
13286 (either due to modification of the text, or any other reason). */
13287 if (!current_matrix_up_to_date_p
13288 && !NILP (Vwindow_text_change_functions
))
13290 safe_run_hooks (Qwindow_text_change_functions
);
13294 beg_unchanged
= BEG_UNCHANGED
;
13295 end_unchanged
= END_UNCHANGED
;
13297 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13299 specbind (Qinhibit_point_motion_hooks
, Qt
);
13302 = (!NILP (w
->window_end_valid
)
13303 && !current_buffer
->clip_changed
13304 && XFASTINT (w
->last_modified
) >= MODIFF
13305 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13307 /* When windows_or_buffers_changed is non-zero, we can't rely on
13308 the window end being valid, so set it to nil there. */
13309 if (windows_or_buffers_changed
)
13311 /* If window starts on a continuation line, maybe adjust the
13312 window start in case the window's width changed. */
13313 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13314 compute_window_start_on_continuation_line (w
);
13316 w
->window_end_valid
= Qnil
;
13319 /* Some sanity checks. */
13320 CHECK_WINDOW_END (w
);
13321 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13323 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13326 /* If %c is in mode line, update it if needed. */
13327 if (!NILP (w
->column_number_displayed
)
13328 /* This alternative quickly identifies a common case
13329 where no change is needed. */
13330 && !(PT
== XFASTINT (w
->last_point
)
13331 && XFASTINT (w
->last_modified
) >= MODIFF
13332 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13333 && (XFASTINT (w
->column_number_displayed
)
13334 != (int) current_column ())) /* iftc */
13335 update_mode_line
= 1;
13337 /* Count number of windows showing the selected buffer. An indirect
13338 buffer counts as its base buffer. */
13339 if (!just_this_one_p
)
13341 struct buffer
*current_base
, *window_base
;
13342 current_base
= current_buffer
;
13343 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13344 if (current_base
->base_buffer
)
13345 current_base
= current_base
->base_buffer
;
13346 if (window_base
->base_buffer
)
13347 window_base
= window_base
->base_buffer
;
13348 if (current_base
== window_base
)
13352 /* Point refers normally to the selected window. For any other
13353 window, set up appropriate value. */
13354 if (!EQ (window
, selected_window
))
13356 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13357 int new_pt_byte
= marker_byte_position (w
->pointm
);
13361 new_pt_byte
= BEGV_BYTE
;
13362 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13364 else if (new_pt
> (ZV
- 1))
13367 new_pt_byte
= ZV_BYTE
;
13368 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13371 /* We don't use SET_PT so that the point-motion hooks don't run. */
13372 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13375 /* If any of the character widths specified in the display table
13376 have changed, invalidate the width run cache. It's true that
13377 this may be a bit late to catch such changes, but the rest of
13378 redisplay goes (non-fatally) haywire when the display table is
13379 changed, so why should we worry about doing any better? */
13380 if (current_buffer
->width_run_cache
)
13382 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13384 if (! disptab_matches_widthtab (disptab
,
13385 XVECTOR (current_buffer
->width_table
)))
13387 invalidate_region_cache (current_buffer
,
13388 current_buffer
->width_run_cache
,
13390 recompute_width_table (current_buffer
, disptab
);
13394 /* If window-start is screwed up, choose a new one. */
13395 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13398 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13400 /* If someone specified a new starting point but did not insist,
13401 check whether it can be used. */
13402 if (!NILP (w
->optional_new_start
)
13403 && CHARPOS (startp
) >= BEGV
13404 && CHARPOS (startp
) <= ZV
)
13406 w
->optional_new_start
= Qnil
;
13407 start_display (&it
, w
, startp
);
13408 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13409 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13410 if (IT_CHARPOS (it
) == PT
)
13411 w
->force_start
= Qt
;
13412 /* IT may overshoot PT if text at PT is invisible. */
13413 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13414 w
->force_start
= Qt
;
13419 /* Handle case where place to start displaying has been specified,
13420 unless the specified location is outside the accessible range. */
13421 if (!NILP (w
->force_start
)
13422 || w
->frozen_window_start_p
)
13424 /* We set this later on if we have to adjust point. */
13427 w
->force_start
= Qnil
;
13429 w
->window_end_valid
= Qnil
;
13431 /* Forget any recorded base line for line number display. */
13432 if (!buffer_unchanged_p
)
13433 w
->base_line_number
= Qnil
;
13435 /* Redisplay the mode line. Select the buffer properly for that.
13436 Also, run the hook window-scroll-functions
13437 because we have scrolled. */
13438 /* Note, we do this after clearing force_start because
13439 if there's an error, it is better to forget about force_start
13440 than to get into an infinite loop calling the hook functions
13441 and having them get more errors. */
13442 if (!update_mode_line
13443 || ! NILP (Vwindow_scroll_functions
))
13445 update_mode_line
= 1;
13446 w
->update_mode_line
= Qt
;
13447 startp
= run_window_scroll_functions (window
, startp
);
13450 w
->last_modified
= make_number (0);
13451 w
->last_overlay_modified
= make_number (0);
13452 if (CHARPOS (startp
) < BEGV
)
13453 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13454 else if (CHARPOS (startp
) > ZV
)
13455 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13457 /* Redisplay, then check if cursor has been set during the
13458 redisplay. Give up if new fonts were loaded. */
13459 /* We used to issue a CHECK_MARGINS argument to try_window here,
13460 but this causes scrolling to fail when point begins inside
13461 the scroll margin (bug#148) -- cyd */
13462 if (!try_window (window
, startp
, 0))
13464 w
->force_start
= Qt
;
13465 clear_glyph_matrix (w
->desired_matrix
);
13466 goto need_larger_matrices
;
13469 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13471 /* If point does not appear, try to move point so it does
13472 appear. The desired matrix has been built above, so we
13473 can use it here. */
13474 new_vpos
= window_box_height (w
) / 2;
13477 if (!cursor_row_fully_visible_p (w
, 0, 0))
13479 /* Point does appear, but on a line partly visible at end of window.
13480 Move it back to a fully-visible line. */
13481 new_vpos
= window_box_height (w
);
13484 /* If we need to move point for either of the above reasons,
13485 now actually do it. */
13488 struct glyph_row
*row
;
13490 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13491 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13494 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13495 MATRIX_ROW_START_BYTEPOS (row
));
13497 if (w
!= XWINDOW (selected_window
))
13498 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13499 else if (current_buffer
== old
)
13500 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13502 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13504 /* If we are highlighting the region, then we just changed
13505 the region, so redisplay to show it. */
13506 if (!NILP (Vtransient_mark_mode
)
13507 && !NILP (current_buffer
->mark_active
))
13509 clear_glyph_matrix (w
->desired_matrix
);
13510 if (!try_window (window
, startp
, 0))
13511 goto need_larger_matrices
;
13516 debug_method_add (w
, "forced window start");
13521 /* Handle case where text has not changed, only point, and it has
13522 not moved off the frame, and we are not retrying after hscroll.
13523 (current_matrix_up_to_date_p is nonzero when retrying.) */
13524 if (current_matrix_up_to_date_p
13525 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13526 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13530 case CURSOR_MOVEMENT_SUCCESS
:
13531 used_current_matrix_p
= 1;
13534 case CURSOR_MOVEMENT_MUST_SCROLL
:
13535 goto try_to_scroll
;
13541 /* If current starting point was originally the beginning of a line
13542 but no longer is, find a new starting point. */
13543 else if (!NILP (w
->start_at_line_beg
)
13544 && !(CHARPOS (startp
) <= BEGV
13545 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13548 debug_method_add (w
, "recenter 1");
13553 /* Try scrolling with try_window_id. Value is > 0 if update has
13554 been done, it is -1 if we know that the same window start will
13555 not work. It is 0 if unsuccessful for some other reason. */
13556 else if ((tem
= try_window_id (w
)) != 0)
13559 debug_method_add (w
, "try_window_id %d", tem
);
13562 if (fonts_changed_p
)
13563 goto need_larger_matrices
;
13567 /* Otherwise try_window_id has returned -1 which means that we
13568 don't want the alternative below this comment to execute. */
13570 else if (CHARPOS (startp
) >= BEGV
13571 && CHARPOS (startp
) <= ZV
13572 && PT
>= CHARPOS (startp
)
13573 && (CHARPOS (startp
) < ZV
13574 /* Avoid starting at end of buffer. */
13575 || CHARPOS (startp
) == BEGV
13576 || (XFASTINT (w
->last_modified
) >= MODIFF
13577 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13580 /* If first window line is a continuation line, and window start
13581 is inside the modified region, but the first change is before
13582 current window start, we must select a new window start.
13584 However, if this is the result of a down-mouse event (e.g. by
13585 extending the mouse-drag-overlay), we don't want to select a
13586 new window start, since that would change the position under
13587 the mouse, resulting in an unwanted mouse-movement rather
13588 than a simple mouse-click. */
13589 if (NILP (w
->start_at_line_beg
)
13590 && NILP (do_mouse_tracking
)
13591 && CHARPOS (startp
) > BEGV
13592 && CHARPOS (startp
) > BEG
+ beg_unchanged
13593 && CHARPOS (startp
) <= Z
- end_unchanged
13594 /* Even if w->start_at_line_beg is nil, a new window may
13595 start at a line_beg, since that's how set_buffer_window
13596 sets it. So, we need to check the return value of
13597 compute_window_start_on_continuation_line. (See also
13599 && XMARKER (w
->start
)->buffer
== current_buffer
13600 && compute_window_start_on_continuation_line (w
))
13602 w
->force_start
= Qt
;
13603 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13608 debug_method_add (w
, "same window start");
13611 /* Try to redisplay starting at same place as before.
13612 If point has not moved off frame, accept the results. */
13613 if (!current_matrix_up_to_date_p
13614 /* Don't use try_window_reusing_current_matrix in this case
13615 because a window scroll function can have changed the
13617 || !NILP (Vwindow_scroll_functions
)
13618 || MINI_WINDOW_P (w
)
13619 || !(used_current_matrix_p
13620 = try_window_reusing_current_matrix (w
)))
13622 IF_DEBUG (debug_method_add (w
, "1"));
13623 if (try_window (window
, startp
, 1) < 0)
13624 /* -1 means we need to scroll.
13625 0 means we need new matrices, but fonts_changed_p
13626 is set in that case, so we will detect it below. */
13627 goto try_to_scroll
;
13630 if (fonts_changed_p
)
13631 goto need_larger_matrices
;
13633 if (w
->cursor
.vpos
>= 0)
13635 if (!just_this_one_p
13636 || current_buffer
->clip_changed
13637 || BEG_UNCHANGED
< CHARPOS (startp
))
13638 /* Forget any recorded base line for line number display. */
13639 w
->base_line_number
= Qnil
;
13641 if (!cursor_row_fully_visible_p (w
, 1, 0))
13643 clear_glyph_matrix (w
->desired_matrix
);
13644 last_line_misfit
= 1;
13646 /* Drop through and scroll. */
13651 clear_glyph_matrix (w
->desired_matrix
);
13656 w
->last_modified
= make_number (0);
13657 w
->last_overlay_modified
= make_number (0);
13659 /* Redisplay the mode line. Select the buffer properly for that. */
13660 if (!update_mode_line
)
13662 update_mode_line
= 1;
13663 w
->update_mode_line
= Qt
;
13666 /* Try to scroll by specified few lines. */
13667 if ((scroll_conservatively
13669 || temp_scroll_step
13670 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13671 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13672 && !current_buffer
->clip_changed
13673 && CHARPOS (startp
) >= BEGV
13674 && CHARPOS (startp
) <= ZV
)
13676 /* The function returns -1 if new fonts were loaded, 1 if
13677 successful, 0 if not successful. */
13678 int rc
= try_scrolling (window
, just_this_one_p
,
13679 scroll_conservatively
,
13681 temp_scroll_step
, last_line_misfit
);
13684 case SCROLLING_SUCCESS
:
13687 case SCROLLING_NEED_LARGER_MATRICES
:
13688 goto need_larger_matrices
;
13690 case SCROLLING_FAILED
:
13698 /* Finally, just choose place to start which centers point */
13701 if (centering_position
< 0)
13702 centering_position
= window_box_height (w
) / 2;
13705 debug_method_add (w
, "recenter");
13708 /* w->vscroll = 0; */
13710 /* Forget any previously recorded base line for line number display. */
13711 if (!buffer_unchanged_p
)
13712 w
->base_line_number
= Qnil
;
13714 /* Move backward half the height of the window. */
13715 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13716 it
.current_y
= it
.last_visible_y
;
13717 move_it_vertically_backward (&it
, centering_position
);
13718 xassert (IT_CHARPOS (it
) >= BEGV
);
13720 /* The function move_it_vertically_backward may move over more
13721 than the specified y-distance. If it->w is small, e.g. a
13722 mini-buffer window, we may end up in front of the window's
13723 display area. Start displaying at the start of the line
13724 containing PT in this case. */
13725 if (it
.current_y
<= 0)
13727 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13728 move_it_vertically_backward (&it
, 0);
13732 it
.current_x
= it
.hpos
= 0;
13734 /* Set startp here explicitly in case that helps avoid an infinite loop
13735 in case the window-scroll-functions functions get errors. */
13736 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13738 /* Run scroll hooks. */
13739 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13741 /* Redisplay the window. */
13742 if (!current_matrix_up_to_date_p
13743 || windows_or_buffers_changed
13744 || cursor_type_changed
13745 /* Don't use try_window_reusing_current_matrix in this case
13746 because it can have changed the buffer. */
13747 || !NILP (Vwindow_scroll_functions
)
13748 || !just_this_one_p
13749 || MINI_WINDOW_P (w
)
13750 || !(used_current_matrix_p
13751 = try_window_reusing_current_matrix (w
)))
13752 try_window (window
, startp
, 0);
13754 /* If new fonts have been loaded (due to fontsets), give up. We
13755 have to start a new redisplay since we need to re-adjust glyph
13757 if (fonts_changed_p
)
13758 goto need_larger_matrices
;
13760 /* If cursor did not appear assume that the middle of the window is
13761 in the first line of the window. Do it again with the next line.
13762 (Imagine a window of height 100, displaying two lines of height
13763 60. Moving back 50 from it->last_visible_y will end in the first
13765 if (w
->cursor
.vpos
< 0)
13767 if (!NILP (w
->window_end_valid
)
13768 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13770 clear_glyph_matrix (w
->desired_matrix
);
13771 move_it_by_lines (&it
, 1, 0);
13772 try_window (window
, it
.current
.pos
, 0);
13774 else if (PT
< IT_CHARPOS (it
))
13776 clear_glyph_matrix (w
->desired_matrix
);
13777 move_it_by_lines (&it
, -1, 0);
13778 try_window (window
, it
.current
.pos
, 0);
13782 /* Not much we can do about it. */
13786 /* Consider the following case: Window starts at BEGV, there is
13787 invisible, intangible text at BEGV, so that display starts at
13788 some point START > BEGV. It can happen that we are called with
13789 PT somewhere between BEGV and START. Try to handle that case. */
13790 if (w
->cursor
.vpos
< 0)
13792 struct glyph_row
*row
= w
->current_matrix
->rows
;
13793 if (row
->mode_line_p
)
13795 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13798 if (!cursor_row_fully_visible_p (w
, 0, 0))
13800 /* If vscroll is enabled, disable it and try again. */
13804 clear_glyph_matrix (w
->desired_matrix
);
13808 /* If centering point failed to make the whole line visible,
13809 put point at the top instead. That has to make the whole line
13810 visible, if it can be done. */
13811 if (centering_position
== 0)
13814 clear_glyph_matrix (w
->desired_matrix
);
13815 centering_position
= 0;
13821 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13822 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13823 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13826 /* Display the mode line, if we must. */
13827 if ((update_mode_line
13828 /* If window not full width, must redo its mode line
13829 if (a) the window to its side is being redone and
13830 (b) we do a frame-based redisplay. This is a consequence
13831 of how inverted lines are drawn in frame-based redisplay. */
13832 || (!just_this_one_p
13833 && !FRAME_WINDOW_P (f
)
13834 && !WINDOW_FULL_WIDTH_P (w
))
13835 /* Line number to display. */
13836 || INTEGERP (w
->base_line_pos
)
13837 /* Column number is displayed and different from the one displayed. */
13838 || (!NILP (w
->column_number_displayed
)
13839 && (XFASTINT (w
->column_number_displayed
)
13840 != (int) current_column ()))) /* iftc */
13841 /* This means that the window has a mode line. */
13842 && (WINDOW_WANTS_MODELINE_P (w
)
13843 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13845 display_mode_lines (w
);
13847 /* If mode line height has changed, arrange for a thorough
13848 immediate redisplay using the correct mode line height. */
13849 if (WINDOW_WANTS_MODELINE_P (w
)
13850 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13852 fonts_changed_p
= 1;
13853 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13854 = DESIRED_MODE_LINE_HEIGHT (w
);
13857 /* If top line height has changed, arrange for a thorough
13858 immediate redisplay using the correct mode line height. */
13859 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13860 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13862 fonts_changed_p
= 1;
13863 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13864 = DESIRED_HEADER_LINE_HEIGHT (w
);
13867 if (fonts_changed_p
)
13868 goto need_larger_matrices
;
13871 if (!line_number_displayed
13872 && !BUFFERP (w
->base_line_pos
))
13874 w
->base_line_pos
= Qnil
;
13875 w
->base_line_number
= Qnil
;
13880 /* When we reach a frame's selected window, redo the frame's menu bar. */
13881 if (update_mode_line
13882 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13884 int redisplay_menu_p
= 0;
13885 int redisplay_tool_bar_p
= 0;
13887 if (FRAME_WINDOW_P (f
))
13889 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13890 || defined (HAVE_NS) || defined (USE_GTK)
13891 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13893 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13897 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13899 if (redisplay_menu_p
)
13900 display_menu_bar (w
);
13902 #ifdef HAVE_WINDOW_SYSTEM
13903 if (FRAME_WINDOW_P (f
))
13905 #if defined (USE_GTK) || defined (HAVE_NS)
13906 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13908 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13909 && (FRAME_TOOL_BAR_LINES (f
) > 0
13910 || !NILP (Vauto_resize_tool_bars
));
13913 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13915 extern int ignore_mouse_drag_p
;
13916 ignore_mouse_drag_p
= 1;
13922 #ifdef HAVE_WINDOW_SYSTEM
13923 if (FRAME_WINDOW_P (f
)
13924 && update_window_fringes (w
, (just_this_one_p
13925 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13926 || w
->pseudo_window_p
)))
13930 if (draw_window_fringes (w
, 1))
13931 x_draw_vertical_border (w
);
13935 #endif /* HAVE_WINDOW_SYSTEM */
13937 /* We go to this label, with fonts_changed_p nonzero,
13938 if it is necessary to try again using larger glyph matrices.
13939 We have to redeem the scroll bar even in this case,
13940 because the loop in redisplay_internal expects that. */
13941 need_larger_matrices
:
13943 finish_scroll_bars
:
13945 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13947 /* Set the thumb's position and size. */
13948 set_vertical_scroll_bar (w
);
13950 /* Note that we actually used the scroll bar attached to this
13951 window, so it shouldn't be deleted at the end of redisplay. */
13952 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13953 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13956 /* Restore current_buffer and value of point in it. */
13957 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13958 set_buffer_internal_1 (old
);
13959 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13960 shorter. This can be caused by log truncation in *Messages*. */
13961 if (CHARPOS (lpoint
) <= ZV
)
13962 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13964 unbind_to (count
, Qnil
);
13968 /* Build the complete desired matrix of WINDOW with a window start
13969 buffer position POS.
13971 Value is 1 if successful. It is zero if fonts were loaded during
13972 redisplay which makes re-adjusting glyph matrices necessary, and -1
13973 if point would appear in the scroll margins.
13974 (We check that only if CHECK_MARGINS is nonzero. */
13977 try_window (window
, pos
, check_margins
)
13978 Lisp_Object window
;
13979 struct text_pos pos
;
13982 struct window
*w
= XWINDOW (window
);
13984 struct glyph_row
*last_text_row
= NULL
;
13985 struct frame
*f
= XFRAME (w
->frame
);
13987 /* Make POS the new window start. */
13988 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13990 /* Mark cursor position as unknown. No overlay arrow seen. */
13991 w
->cursor
.vpos
= -1;
13992 overlay_arrow_seen
= 0;
13994 /* Initialize iterator and info to start at POS. */
13995 start_display (&it
, w
, pos
);
13997 /* Display all lines of W. */
13998 while (it
.current_y
< it
.last_visible_y
)
14000 if (display_line (&it
))
14001 last_text_row
= it
.glyph_row
- 1;
14002 if (fonts_changed_p
)
14006 /* Don't let the cursor end in the scroll margins. */
14008 && !MINI_WINDOW_P (w
))
14010 int this_scroll_margin
;
14012 if (scroll_margin
> 0)
14014 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14015 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14018 this_scroll_margin
= 0;
14020 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14021 && w
->cursor
.y
< this_scroll_margin
14022 && CHARPOS (pos
) > BEGV
14023 && IT_CHARPOS (it
) < ZV
)
14024 /* rms: considering make_cursor_line_fully_visible_p here
14025 seems to give wrong results. We don't want to recenter
14026 when the last line is partly visible, we want to allow
14027 that case to be handled in the usual way. */
14028 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14030 w
->cursor
.vpos
= -1;
14031 clear_glyph_matrix (w
->desired_matrix
);
14036 /* If bottom moved off end of frame, change mode line percentage. */
14037 if (XFASTINT (w
->window_end_pos
) <= 0
14038 && Z
!= IT_CHARPOS (it
))
14039 w
->update_mode_line
= Qt
;
14041 /* Set window_end_pos to the offset of the last character displayed
14042 on the window from the end of current_buffer. Set
14043 window_end_vpos to its row number. */
14046 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14047 w
->window_end_bytepos
14048 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14050 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14052 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14053 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14054 ->displays_text_p
);
14058 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14059 w
->window_end_pos
= make_number (Z
- ZV
);
14060 w
->window_end_vpos
= make_number (0);
14063 /* But that is not valid info until redisplay finishes. */
14064 w
->window_end_valid
= Qnil
;
14070 /************************************************************************
14071 Window redisplay reusing current matrix when buffer has not changed
14072 ************************************************************************/
14074 /* Try redisplay of window W showing an unchanged buffer with a
14075 different window start than the last time it was displayed by
14076 reusing its current matrix. Value is non-zero if successful.
14077 W->start is the new window start. */
14080 try_window_reusing_current_matrix (w
)
14083 struct frame
*f
= XFRAME (w
->frame
);
14084 struct glyph_row
*row
, *bottom_row
;
14087 struct text_pos start
, new_start
;
14088 int nrows_scrolled
, i
;
14089 struct glyph_row
*last_text_row
;
14090 struct glyph_row
*last_reused_text_row
;
14091 struct glyph_row
*start_row
;
14092 int start_vpos
, min_y
, max_y
;
14095 if (inhibit_try_window_reusing
)
14099 if (/* This function doesn't handle terminal frames. */
14100 !FRAME_WINDOW_P (f
)
14101 /* Don't try to reuse the display if windows have been split
14103 || windows_or_buffers_changed
14104 || cursor_type_changed
)
14107 /* Can't do this if region may have changed. */
14108 if ((!NILP (Vtransient_mark_mode
)
14109 && !NILP (current_buffer
->mark_active
))
14110 || !NILP (w
->region_showing
)
14111 || !NILP (Vshow_trailing_whitespace
))
14114 /* If top-line visibility has changed, give up. */
14115 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14116 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14119 /* Give up if old or new display is scrolled vertically. We could
14120 make this function handle this, but right now it doesn't. */
14121 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14122 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14125 /* The variable new_start now holds the new window start. The old
14126 start `start' can be determined from the current matrix. */
14127 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14128 start
= start_row
->start
.pos
;
14129 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14131 /* Clear the desired matrix for the display below. */
14132 clear_glyph_matrix (w
->desired_matrix
);
14134 if (CHARPOS (new_start
) <= CHARPOS (start
))
14138 /* Don't use this method if the display starts with an ellipsis
14139 displayed for invisible text. It's not easy to handle that case
14140 below, and it's certainly not worth the effort since this is
14141 not a frequent case. */
14142 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14145 IF_DEBUG (debug_method_add (w
, "twu1"));
14147 /* Display up to a row that can be reused. The variable
14148 last_text_row is set to the last row displayed that displays
14149 text. Note that it.vpos == 0 if or if not there is a
14150 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14151 start_display (&it
, w
, new_start
);
14152 first_row_y
= it
.current_y
;
14153 w
->cursor
.vpos
= -1;
14154 last_text_row
= last_reused_text_row
= NULL
;
14156 while (it
.current_y
< it
.last_visible_y
14157 && !fonts_changed_p
)
14159 /* If we have reached into the characters in the START row,
14160 that means the line boundaries have changed. So we
14161 can't start copying with the row START. Maybe it will
14162 work to start copying with the following row. */
14163 while (IT_CHARPOS (it
) > CHARPOS (start
))
14165 /* Advance to the next row as the "start". */
14167 start
= start_row
->start
.pos
;
14168 /* If there are no more rows to try, or just one, give up. */
14169 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14170 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14171 || CHARPOS (start
) == ZV
)
14173 clear_glyph_matrix (w
->desired_matrix
);
14177 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14179 /* If we have reached alignment,
14180 we can copy the rest of the rows. */
14181 if (IT_CHARPOS (it
) == CHARPOS (start
))
14184 if (display_line (&it
))
14185 last_text_row
= it
.glyph_row
- 1;
14188 /* A value of current_y < last_visible_y means that we stopped
14189 at the previous window start, which in turn means that we
14190 have at least one reusable row. */
14191 if (it
.current_y
< it
.last_visible_y
)
14193 /* IT.vpos always starts from 0; it counts text lines. */
14194 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14196 /* Find PT if not already found in the lines displayed. */
14197 if (w
->cursor
.vpos
< 0)
14199 int dy
= it
.current_y
- start_row
->y
;
14201 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14202 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14204 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14205 dy
, nrows_scrolled
);
14208 clear_glyph_matrix (w
->desired_matrix
);
14213 /* Scroll the display. Do it before the current matrix is
14214 changed. The problem here is that update has not yet
14215 run, i.e. part of the current matrix is not up to date.
14216 scroll_run_hook will clear the cursor, and use the
14217 current matrix to get the height of the row the cursor is
14219 run
.current_y
= start_row
->y
;
14220 run
.desired_y
= it
.current_y
;
14221 run
.height
= it
.last_visible_y
- it
.current_y
;
14223 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14226 FRAME_RIF (f
)->update_window_begin_hook (w
);
14227 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14228 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14229 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14233 /* Shift current matrix down by nrows_scrolled lines. */
14234 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14235 rotate_matrix (w
->current_matrix
,
14237 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14240 /* Disable lines that must be updated. */
14241 for (i
= 0; i
< nrows_scrolled
; ++i
)
14242 (start_row
+ i
)->enabled_p
= 0;
14244 /* Re-compute Y positions. */
14245 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14246 max_y
= it
.last_visible_y
;
14247 for (row
= start_row
+ nrows_scrolled
;
14251 row
->y
= it
.current_y
;
14252 row
->visible_height
= row
->height
;
14254 if (row
->y
< min_y
)
14255 row
->visible_height
-= min_y
- row
->y
;
14256 if (row
->y
+ row
->height
> max_y
)
14257 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14258 row
->redraw_fringe_bitmaps_p
= 1;
14260 it
.current_y
+= row
->height
;
14262 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14263 last_reused_text_row
= row
;
14264 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14268 /* Disable lines in the current matrix which are now
14269 below the window. */
14270 for (++row
; row
< bottom_row
; ++row
)
14271 row
->enabled_p
= row
->mode_line_p
= 0;
14274 /* Update window_end_pos etc.; last_reused_text_row is the last
14275 reused row from the current matrix containing text, if any.
14276 The value of last_text_row is the last displayed line
14277 containing text. */
14278 if (last_reused_text_row
)
14280 w
->window_end_bytepos
14281 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14283 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14285 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14286 w
->current_matrix
));
14288 else if (last_text_row
)
14290 w
->window_end_bytepos
14291 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14293 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14295 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14299 /* This window must be completely empty. */
14300 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14301 w
->window_end_pos
= make_number (Z
- ZV
);
14302 w
->window_end_vpos
= make_number (0);
14304 w
->window_end_valid
= Qnil
;
14306 /* Update hint: don't try scrolling again in update_window. */
14307 w
->desired_matrix
->no_scrolling_p
= 1;
14310 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14314 else if (CHARPOS (new_start
) > CHARPOS (start
))
14316 struct glyph_row
*pt_row
, *row
;
14317 struct glyph_row
*first_reusable_row
;
14318 struct glyph_row
*first_row_to_display
;
14320 int yb
= window_text_bottom_y (w
);
14322 /* Find the row starting at new_start, if there is one. Don't
14323 reuse a partially visible line at the end. */
14324 first_reusable_row
= start_row
;
14325 while (first_reusable_row
->enabled_p
14326 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14327 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14328 < CHARPOS (new_start
)))
14329 ++first_reusable_row
;
14331 /* Give up if there is no row to reuse. */
14332 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14333 || !first_reusable_row
->enabled_p
14334 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14335 != CHARPOS (new_start
)))
14338 /* We can reuse fully visible rows beginning with
14339 first_reusable_row to the end of the window. Set
14340 first_row_to_display to the first row that cannot be reused.
14341 Set pt_row to the row containing point, if there is any. */
14343 for (first_row_to_display
= first_reusable_row
;
14344 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14345 ++first_row_to_display
)
14347 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14348 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14349 pt_row
= first_row_to_display
;
14352 /* Start displaying at the start of first_row_to_display. */
14353 xassert (first_row_to_display
->y
< yb
);
14354 init_to_row_start (&it
, w
, first_row_to_display
);
14356 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14358 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14360 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14361 + WINDOW_HEADER_LINE_HEIGHT (w
));
14363 /* Display lines beginning with first_row_to_display in the
14364 desired matrix. Set last_text_row to the last row displayed
14365 that displays text. */
14366 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14367 if (pt_row
== NULL
)
14368 w
->cursor
.vpos
= -1;
14369 last_text_row
= NULL
;
14370 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14371 if (display_line (&it
))
14372 last_text_row
= it
.glyph_row
- 1;
14374 /* If point is in a reused row, adjust y and vpos of the cursor
14378 w
->cursor
.vpos
-= nrows_scrolled
;
14379 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14382 /* Give up if point isn't in a row displayed or reused. (This
14383 also handles the case where w->cursor.vpos < nrows_scrolled
14384 after the calls to display_line, which can happen with scroll
14385 margins. See bug#1295.) */
14386 if (w
->cursor
.vpos
< 0)
14388 clear_glyph_matrix (w
->desired_matrix
);
14392 /* Scroll the display. */
14393 run
.current_y
= first_reusable_row
->y
;
14394 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14395 run
.height
= it
.last_visible_y
- run
.current_y
;
14396 dy
= run
.current_y
- run
.desired_y
;
14401 FRAME_RIF (f
)->update_window_begin_hook (w
);
14402 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14403 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14404 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14408 /* Adjust Y positions of reused rows. */
14409 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14410 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14411 max_y
= it
.last_visible_y
;
14412 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14415 row
->visible_height
= row
->height
;
14416 if (row
->y
< min_y
)
14417 row
->visible_height
-= min_y
- row
->y
;
14418 if (row
->y
+ row
->height
> max_y
)
14419 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14420 row
->redraw_fringe_bitmaps_p
= 1;
14423 /* Scroll the current matrix. */
14424 xassert (nrows_scrolled
> 0);
14425 rotate_matrix (w
->current_matrix
,
14427 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14430 /* Disable rows not reused. */
14431 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14432 row
->enabled_p
= 0;
14434 /* Point may have moved to a different line, so we cannot assume that
14435 the previous cursor position is valid; locate the correct row. */
14438 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14439 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14443 w
->cursor
.y
= row
->y
;
14445 if (row
< bottom_row
)
14447 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14448 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14451 && (!BUFFERP (glyph
->object
)
14452 || glyph
->charpos
< PT
);
14456 w
->cursor
.x
+= glyph
->pixel_width
;
14461 /* Adjust window end. A null value of last_text_row means that
14462 the window end is in reused rows which in turn means that
14463 only its vpos can have changed. */
14466 w
->window_end_bytepos
14467 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14469 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14471 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14476 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14479 w
->window_end_valid
= Qnil
;
14480 w
->desired_matrix
->no_scrolling_p
= 1;
14483 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14493 /************************************************************************
14494 Window redisplay reusing current matrix when buffer has changed
14495 ************************************************************************/
14497 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14498 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14500 static struct glyph_row
*
14501 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14502 struct glyph_row
*));
14505 /* Return the last row in MATRIX displaying text. If row START is
14506 non-null, start searching with that row. IT gives the dimensions
14507 of the display. Value is null if matrix is empty; otherwise it is
14508 a pointer to the row found. */
14510 static struct glyph_row
*
14511 find_last_row_displaying_text (matrix
, it
, start
)
14512 struct glyph_matrix
*matrix
;
14514 struct glyph_row
*start
;
14516 struct glyph_row
*row
, *row_found
;
14518 /* Set row_found to the last row in IT->w's current matrix
14519 displaying text. The loop looks funny but think of partially
14522 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14523 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14525 xassert (row
->enabled_p
);
14527 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14536 /* Return the last row in the current matrix of W that is not affected
14537 by changes at the start of current_buffer that occurred since W's
14538 current matrix was built. Value is null if no such row exists.
14540 BEG_UNCHANGED us the number of characters unchanged at the start of
14541 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14542 first changed character in current_buffer. Characters at positions <
14543 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14544 when the current matrix was built. */
14546 static struct glyph_row
*
14547 find_last_unchanged_at_beg_row (w
)
14550 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14551 struct glyph_row
*row
;
14552 struct glyph_row
*row_found
= NULL
;
14553 int yb
= window_text_bottom_y (w
);
14555 /* Find the last row displaying unchanged text. */
14556 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14557 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14558 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14561 if (/* If row ends before first_changed_pos, it is unchanged,
14562 except in some case. */
14563 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14564 /* When row ends in ZV and we write at ZV it is not
14566 && !row
->ends_at_zv_p
14567 /* When first_changed_pos is the end of a continued line,
14568 row is not unchanged because it may be no longer
14570 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14571 && (row
->continued_p
14572 || row
->exact_window_width_line_p
)))
14575 /* Stop if last visible row. */
14576 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14584 /* Find the first glyph row in the current matrix of W that is not
14585 affected by changes at the end of current_buffer since the
14586 time W's current matrix was built.
14588 Return in *DELTA the number of chars by which buffer positions in
14589 unchanged text at the end of current_buffer must be adjusted.
14591 Return in *DELTA_BYTES the corresponding number of bytes.
14593 Value is null if no such row exists, i.e. all rows are affected by
14596 static struct glyph_row
*
14597 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14599 int *delta
, *delta_bytes
;
14601 struct glyph_row
*row
;
14602 struct glyph_row
*row_found
= NULL
;
14604 *delta
= *delta_bytes
= 0;
14606 /* Display must not have been paused, otherwise the current matrix
14607 is not up to date. */
14608 eassert (!NILP (w
->window_end_valid
));
14610 /* A value of window_end_pos >= END_UNCHANGED means that the window
14611 end is in the range of changed text. If so, there is no
14612 unchanged row at the end of W's current matrix. */
14613 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14616 /* Set row to the last row in W's current matrix displaying text. */
14617 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14619 /* If matrix is entirely empty, no unchanged row exists. */
14620 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14622 /* The value of row is the last glyph row in the matrix having a
14623 meaningful buffer position in it. The end position of row
14624 corresponds to window_end_pos. This allows us to translate
14625 buffer positions in the current matrix to current buffer
14626 positions for characters not in changed text. */
14627 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14628 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14629 int last_unchanged_pos
, last_unchanged_pos_old
;
14630 struct glyph_row
*first_text_row
14631 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14633 *delta
= Z
- Z_old
;
14634 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14636 /* Set last_unchanged_pos to the buffer position of the last
14637 character in the buffer that has not been changed. Z is the
14638 index + 1 of the last character in current_buffer, i.e. by
14639 subtracting END_UNCHANGED we get the index of the last
14640 unchanged character, and we have to add BEG to get its buffer
14642 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14643 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14645 /* Search backward from ROW for a row displaying a line that
14646 starts at a minimum position >= last_unchanged_pos_old. */
14647 for (; row
> first_text_row
; --row
)
14649 /* This used to abort, but it can happen.
14650 It is ok to just stop the search instead here. KFS. */
14651 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14654 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14659 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14665 /* Make sure that glyph rows in the current matrix of window W
14666 reference the same glyph memory as corresponding rows in the
14667 frame's frame matrix. This function is called after scrolling W's
14668 current matrix on a terminal frame in try_window_id and
14669 try_window_reusing_current_matrix. */
14672 sync_frame_with_window_matrix_rows (w
)
14675 struct frame
*f
= XFRAME (w
->frame
);
14676 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14678 /* Preconditions: W must be a leaf window and full-width. Its frame
14679 must have a frame matrix. */
14680 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14681 xassert (WINDOW_FULL_WIDTH_P (w
));
14682 xassert (!FRAME_WINDOW_P (f
));
14684 /* If W is a full-width window, glyph pointers in W's current matrix
14685 have, by definition, to be the same as glyph pointers in the
14686 corresponding frame matrix. Note that frame matrices have no
14687 marginal areas (see build_frame_matrix). */
14688 window_row
= w
->current_matrix
->rows
;
14689 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14690 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14691 while (window_row
< window_row_end
)
14693 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14694 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14696 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14697 frame_row
->glyphs
[TEXT_AREA
] = start
;
14698 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14699 frame_row
->glyphs
[LAST_AREA
] = end
;
14701 /* Disable frame rows whose corresponding window rows have
14702 been disabled in try_window_id. */
14703 if (!window_row
->enabled_p
)
14704 frame_row
->enabled_p
= 0;
14706 ++window_row
, ++frame_row
;
14711 /* Find the glyph row in window W containing CHARPOS. Consider all
14712 rows between START and END (not inclusive). END null means search
14713 all rows to the end of the display area of W. Value is the row
14714 containing CHARPOS or null. */
14717 row_containing_pos (w
, charpos
, start
, end
, dy
)
14720 struct glyph_row
*start
, *end
;
14723 struct glyph_row
*row
= start
;
14726 /* If we happen to start on a header-line, skip that. */
14727 if (row
->mode_line_p
)
14730 if ((end
&& row
>= end
) || !row
->enabled_p
)
14733 last_y
= window_text_bottom_y (w
) - dy
;
14737 /* Give up if we have gone too far. */
14738 if (end
&& row
>= end
)
14740 /* This formerly returned if they were equal.
14741 I think that both quantities are of a "last plus one" type;
14742 if so, when they are equal, the row is within the screen. -- rms. */
14743 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14746 /* If it is in this row, return this row. */
14747 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14748 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14749 /* The end position of a row equals the start
14750 position of the next row. If CHARPOS is there, we
14751 would rather display it in the next line, except
14752 when this line ends in ZV. */
14753 && !row
->ends_at_zv_p
14754 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14755 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14762 /* Try to redisplay window W by reusing its existing display. W's
14763 current matrix must be up to date when this function is called,
14764 i.e. window_end_valid must not be nil.
14768 1 if display has been updated
14769 0 if otherwise unsuccessful
14770 -1 if redisplay with same window start is known not to succeed
14772 The following steps are performed:
14774 1. Find the last row in the current matrix of W that is not
14775 affected by changes at the start of current_buffer. If no such row
14778 2. Find the first row in W's current matrix that is not affected by
14779 changes at the end of current_buffer. Maybe there is no such row.
14781 3. Display lines beginning with the row + 1 found in step 1 to the
14782 row found in step 2 or, if step 2 didn't find a row, to the end of
14785 4. If cursor is not known to appear on the window, give up.
14787 5. If display stopped at the row found in step 2, scroll the
14788 display and current matrix as needed.
14790 6. Maybe display some lines at the end of W, if we must. This can
14791 happen under various circumstances, like a partially visible line
14792 becoming fully visible, or because newly displayed lines are displayed
14793 in smaller font sizes.
14795 7. Update W's window end information. */
14801 struct frame
*f
= XFRAME (w
->frame
);
14802 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14803 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14804 struct glyph_row
*last_unchanged_at_beg_row
;
14805 struct glyph_row
*first_unchanged_at_end_row
;
14806 struct glyph_row
*row
;
14807 struct glyph_row
*bottom_row
;
14810 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14811 struct text_pos start_pos
;
14813 int first_unchanged_at_end_vpos
= 0;
14814 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14815 struct text_pos start
;
14816 int first_changed_charpos
, last_changed_charpos
;
14819 if (inhibit_try_window_id
)
14823 /* This is handy for debugging. */
14825 #define GIVE_UP(X) \
14827 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14831 #define GIVE_UP(X) return 0
14834 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14836 /* Don't use this for mini-windows because these can show
14837 messages and mini-buffers, and we don't handle that here. */
14838 if (MINI_WINDOW_P (w
))
14841 /* This flag is used to prevent redisplay optimizations. */
14842 if (windows_or_buffers_changed
|| cursor_type_changed
)
14845 /* Verify that narrowing has not changed.
14846 Also verify that we were not told to prevent redisplay optimizations.
14847 It would be nice to further
14848 reduce the number of cases where this prevents try_window_id. */
14849 if (current_buffer
->clip_changed
14850 || current_buffer
->prevent_redisplay_optimizations_p
)
14853 /* Window must either use window-based redisplay or be full width. */
14854 if (!FRAME_WINDOW_P (f
)
14855 && (!FRAME_LINE_INS_DEL_OK (f
)
14856 || !WINDOW_FULL_WIDTH_P (w
)))
14859 /* Give up if point is not known NOT to appear in W. */
14860 if (PT
< CHARPOS (start
))
14863 /* Another way to prevent redisplay optimizations. */
14864 if (XFASTINT (w
->last_modified
) == 0)
14867 /* Verify that window is not hscrolled. */
14868 if (XFASTINT (w
->hscroll
) != 0)
14871 /* Verify that display wasn't paused. */
14872 if (NILP (w
->window_end_valid
))
14875 /* Can't use this if highlighting a region because a cursor movement
14876 will do more than just set the cursor. */
14877 if (!NILP (Vtransient_mark_mode
)
14878 && !NILP (current_buffer
->mark_active
))
14881 /* Likewise if highlighting trailing whitespace. */
14882 if (!NILP (Vshow_trailing_whitespace
))
14885 /* Likewise if showing a region. */
14886 if (!NILP (w
->region_showing
))
14889 /* Can use this if overlay arrow position and or string have changed. */
14890 if (overlay_arrows_changed_p ())
14893 /* When word-wrap is on, adding a space to the first word of a
14894 wrapped line can change the wrap position, altering the line
14895 above it. It might be worthwhile to handle this more
14896 intelligently, but for now just redisplay from scratch. */
14897 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14900 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14901 only if buffer has really changed. The reason is that the gap is
14902 initially at Z for freshly visited files. The code below would
14903 set end_unchanged to 0 in that case. */
14904 if (MODIFF
> SAVE_MODIFF
14905 /* This seems to happen sometimes after saving a buffer. */
14906 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14908 if (GPT
- BEG
< BEG_UNCHANGED
)
14909 BEG_UNCHANGED
= GPT
- BEG
;
14910 if (Z
- GPT
< END_UNCHANGED
)
14911 END_UNCHANGED
= Z
- GPT
;
14914 /* The position of the first and last character that has been changed. */
14915 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14916 last_changed_charpos
= Z
- END_UNCHANGED
;
14918 /* If window starts after a line end, and the last change is in
14919 front of that newline, then changes don't affect the display.
14920 This case happens with stealth-fontification. Note that although
14921 the display is unchanged, glyph positions in the matrix have to
14922 be adjusted, of course. */
14923 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14924 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14925 && ((last_changed_charpos
< CHARPOS (start
)
14926 && CHARPOS (start
) == BEGV
)
14927 || (last_changed_charpos
< CHARPOS (start
) - 1
14928 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14930 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14931 struct glyph_row
*r0
;
14933 /* Compute how many chars/bytes have been added to or removed
14934 from the buffer. */
14935 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14936 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14938 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14940 /* Give up if PT is not in the window. Note that it already has
14941 been checked at the start of try_window_id that PT is not in
14942 front of the window start. */
14943 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14946 /* If window start is unchanged, we can reuse the whole matrix
14947 as is, after adjusting glyph positions. No need to compute
14948 the window end again, since its offset from Z hasn't changed. */
14949 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14950 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14951 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14952 /* PT must not be in a partially visible line. */
14953 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14954 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14956 /* Adjust positions in the glyph matrix. */
14957 if (delta
|| delta_bytes
)
14959 struct glyph_row
*r1
14960 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14961 increment_matrix_positions (w
->current_matrix
,
14962 MATRIX_ROW_VPOS (r0
, current_matrix
),
14963 MATRIX_ROW_VPOS (r1
, current_matrix
),
14964 delta
, delta_bytes
);
14967 /* Set the cursor. */
14968 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14970 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14977 /* Handle the case that changes are all below what is displayed in
14978 the window, and that PT is in the window. This shortcut cannot
14979 be taken if ZV is visible in the window, and text has been added
14980 there that is visible in the window. */
14981 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14982 /* ZV is not visible in the window, or there are no
14983 changes at ZV, actually. */
14984 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14985 || first_changed_charpos
== last_changed_charpos
))
14987 struct glyph_row
*r0
;
14989 /* Give up if PT is not in the window. Note that it already has
14990 been checked at the start of try_window_id that PT is not in
14991 front of the window start. */
14992 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14995 /* If window start is unchanged, we can reuse the whole matrix
14996 as is, without changing glyph positions since no text has
14997 been added/removed in front of the window end. */
14998 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14999 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15000 /* PT must not be in a partially visible line. */
15001 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15002 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15004 /* We have to compute the window end anew since text
15005 can have been added/removed after it. */
15007 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15008 w
->window_end_bytepos
15009 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15011 /* Set the cursor. */
15012 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15014 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15021 /* Give up if window start is in the changed area.
15023 The condition used to read
15025 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15027 but why that was tested escapes me at the moment. */
15028 if (CHARPOS (start
) >= first_changed_charpos
15029 && CHARPOS (start
) <= last_changed_charpos
)
15032 /* Check that window start agrees with the start of the first glyph
15033 row in its current matrix. Check this after we know the window
15034 start is not in changed text, otherwise positions would not be
15036 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15037 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15040 /* Give up if the window ends in strings. Overlay strings
15041 at the end are difficult to handle, so don't try. */
15042 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15043 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15046 /* Compute the position at which we have to start displaying new
15047 lines. Some of the lines at the top of the window might be
15048 reusable because they are not displaying changed text. Find the
15049 last row in W's current matrix not affected by changes at the
15050 start of current_buffer. Value is null if changes start in the
15051 first line of window. */
15052 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15053 if (last_unchanged_at_beg_row
)
15055 /* Avoid starting to display in the moddle of a character, a TAB
15056 for instance. This is easier than to set up the iterator
15057 exactly, and it's not a frequent case, so the additional
15058 effort wouldn't really pay off. */
15059 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15060 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15061 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15062 --last_unchanged_at_beg_row
;
15064 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15067 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15069 start_pos
= it
.current
.pos
;
15071 /* Start displaying new lines in the desired matrix at the same
15072 vpos we would use in the current matrix, i.e. below
15073 last_unchanged_at_beg_row. */
15074 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15076 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15077 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15079 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15083 /* There are no reusable lines at the start of the window.
15084 Start displaying in the first text line. */
15085 start_display (&it
, w
, start
);
15086 it
.vpos
= it
.first_vpos
;
15087 start_pos
= it
.current
.pos
;
15090 /* Find the first row that is not affected by changes at the end of
15091 the buffer. Value will be null if there is no unchanged row, in
15092 which case we must redisplay to the end of the window. delta
15093 will be set to the value by which buffer positions beginning with
15094 first_unchanged_at_end_row have to be adjusted due to text
15096 first_unchanged_at_end_row
15097 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15098 IF_DEBUG (debug_delta
= delta
);
15099 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15101 /* Set stop_pos to the buffer position up to which we will have to
15102 display new lines. If first_unchanged_at_end_row != NULL, this
15103 is the buffer position of the start of the line displayed in that
15104 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15105 that we don't stop at a buffer position. */
15107 if (first_unchanged_at_end_row
)
15109 xassert (last_unchanged_at_beg_row
== NULL
15110 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15112 /* If this is a continuation line, move forward to the next one
15113 that isn't. Changes in lines above affect this line.
15114 Caution: this may move first_unchanged_at_end_row to a row
15115 not displaying text. */
15116 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15117 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15118 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15119 < it
.last_visible_y
))
15120 ++first_unchanged_at_end_row
;
15122 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15123 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15124 >= it
.last_visible_y
))
15125 first_unchanged_at_end_row
= NULL
;
15128 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15130 first_unchanged_at_end_vpos
15131 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15132 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15135 else if (last_unchanged_at_beg_row
== NULL
)
15141 /* Either there is no unchanged row at the end, or the one we have
15142 now displays text. This is a necessary condition for the window
15143 end pos calculation at the end of this function. */
15144 xassert (first_unchanged_at_end_row
== NULL
15145 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15147 debug_last_unchanged_at_beg_vpos
15148 = (last_unchanged_at_beg_row
15149 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15151 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15153 #endif /* GLYPH_DEBUG != 0 */
15156 /* Display new lines. Set last_text_row to the last new line
15157 displayed which has text on it, i.e. might end up as being the
15158 line where the window_end_vpos is. */
15159 w
->cursor
.vpos
= -1;
15160 last_text_row
= NULL
;
15161 overlay_arrow_seen
= 0;
15162 while (it
.current_y
< it
.last_visible_y
15163 && !fonts_changed_p
15164 && (first_unchanged_at_end_row
== NULL
15165 || IT_CHARPOS (it
) < stop_pos
))
15167 if (display_line (&it
))
15168 last_text_row
= it
.glyph_row
- 1;
15171 if (fonts_changed_p
)
15175 /* Compute differences in buffer positions, y-positions etc. for
15176 lines reused at the bottom of the window. Compute what we can
15178 if (first_unchanged_at_end_row
15179 /* No lines reused because we displayed everything up to the
15180 bottom of the window. */
15181 && it
.current_y
< it
.last_visible_y
)
15184 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15186 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15187 run
.current_y
= first_unchanged_at_end_row
->y
;
15188 run
.desired_y
= run
.current_y
+ dy
;
15189 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15193 delta
= delta_bytes
= dvpos
= dy
15194 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15195 first_unchanged_at_end_row
= NULL
;
15197 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15200 /* Find the cursor if not already found. We have to decide whether
15201 PT will appear on this window (it sometimes doesn't, but this is
15202 not a very frequent case.) This decision has to be made before
15203 the current matrix is altered. A value of cursor.vpos < 0 means
15204 that PT is either in one of the lines beginning at
15205 first_unchanged_at_end_row or below the window. Don't care for
15206 lines that might be displayed later at the window end; as
15207 mentioned, this is not a frequent case. */
15208 if (w
->cursor
.vpos
< 0)
15210 /* Cursor in unchanged rows at the top? */
15211 if (PT
< CHARPOS (start_pos
)
15212 && last_unchanged_at_beg_row
)
15214 row
= row_containing_pos (w
, PT
,
15215 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15216 last_unchanged_at_beg_row
+ 1, 0);
15218 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15221 /* Start from first_unchanged_at_end_row looking for PT. */
15222 else if (first_unchanged_at_end_row
)
15224 row
= row_containing_pos (w
, PT
- delta
,
15225 first_unchanged_at_end_row
, NULL
, 0);
15227 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15228 delta_bytes
, dy
, dvpos
);
15231 /* Give up if cursor was not found. */
15232 if (w
->cursor
.vpos
< 0)
15234 clear_glyph_matrix (w
->desired_matrix
);
15239 /* Don't let the cursor end in the scroll margins. */
15241 int this_scroll_margin
, cursor_height
;
15243 this_scroll_margin
= max (0, scroll_margin
);
15244 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15245 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15246 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15248 if ((w
->cursor
.y
< this_scroll_margin
15249 && CHARPOS (start
) > BEGV
)
15250 /* Old redisplay didn't take scroll margin into account at the bottom,
15251 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15252 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15253 ? cursor_height
+ this_scroll_margin
15254 : 1)) > it
.last_visible_y
)
15256 w
->cursor
.vpos
= -1;
15257 clear_glyph_matrix (w
->desired_matrix
);
15262 /* Scroll the display. Do it before changing the current matrix so
15263 that xterm.c doesn't get confused about where the cursor glyph is
15265 if (dy
&& run
.height
)
15269 if (FRAME_WINDOW_P (f
))
15271 FRAME_RIF (f
)->update_window_begin_hook (w
);
15272 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15273 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15274 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15278 /* Terminal frame. In this case, dvpos gives the number of
15279 lines to scroll by; dvpos < 0 means scroll up. */
15280 int first_unchanged_at_end_vpos
15281 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15282 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15283 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15284 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15285 + window_internal_height (w
));
15287 /* Perform the operation on the screen. */
15290 /* Scroll last_unchanged_at_beg_row to the end of the
15291 window down dvpos lines. */
15292 set_terminal_window (f
, end
);
15294 /* On dumb terminals delete dvpos lines at the end
15295 before inserting dvpos empty lines. */
15296 if (!FRAME_SCROLL_REGION_OK (f
))
15297 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15299 /* Insert dvpos empty lines in front of
15300 last_unchanged_at_beg_row. */
15301 ins_del_lines (f
, from
, dvpos
);
15303 else if (dvpos
< 0)
15305 /* Scroll up last_unchanged_at_beg_vpos to the end of
15306 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15307 set_terminal_window (f
, end
);
15309 /* Delete dvpos lines in front of
15310 last_unchanged_at_beg_vpos. ins_del_lines will set
15311 the cursor to the given vpos and emit |dvpos| delete
15313 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15315 /* On a dumb terminal insert dvpos empty lines at the
15317 if (!FRAME_SCROLL_REGION_OK (f
))
15318 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15321 set_terminal_window (f
, 0);
15327 /* Shift reused rows of the current matrix to the right position.
15328 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15330 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15331 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15334 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15335 bottom_vpos
, dvpos
);
15336 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15339 else if (dvpos
> 0)
15341 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15342 bottom_vpos
, dvpos
);
15343 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15344 first_unchanged_at_end_vpos
+ dvpos
, 0);
15347 /* For frame-based redisplay, make sure that current frame and window
15348 matrix are in sync with respect to glyph memory. */
15349 if (!FRAME_WINDOW_P (f
))
15350 sync_frame_with_window_matrix_rows (w
);
15352 /* Adjust buffer positions in reused rows. */
15353 if (delta
|| delta_bytes
)
15354 increment_matrix_positions (current_matrix
,
15355 first_unchanged_at_end_vpos
+ dvpos
,
15356 bottom_vpos
, delta
, delta_bytes
);
15358 /* Adjust Y positions. */
15360 shift_glyph_matrix (w
, current_matrix
,
15361 first_unchanged_at_end_vpos
+ dvpos
,
15364 if (first_unchanged_at_end_row
)
15366 first_unchanged_at_end_row
+= dvpos
;
15367 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15368 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15369 first_unchanged_at_end_row
= NULL
;
15372 /* If scrolling up, there may be some lines to display at the end of
15374 last_text_row_at_end
= NULL
;
15377 /* Scrolling up can leave for example a partially visible line
15378 at the end of the window to be redisplayed. */
15379 /* Set last_row to the glyph row in the current matrix where the
15380 window end line is found. It has been moved up or down in
15381 the matrix by dvpos. */
15382 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15383 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15385 /* If last_row is the window end line, it should display text. */
15386 xassert (last_row
->displays_text_p
);
15388 /* If window end line was partially visible before, begin
15389 displaying at that line. Otherwise begin displaying with the
15390 line following it. */
15391 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15393 init_to_row_start (&it
, w
, last_row
);
15394 it
.vpos
= last_vpos
;
15395 it
.current_y
= last_row
->y
;
15399 init_to_row_end (&it
, w
, last_row
);
15400 it
.vpos
= 1 + last_vpos
;
15401 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15405 /* We may start in a continuation line. If so, we have to
15406 get the right continuation_lines_width and current_x. */
15407 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15408 it
.hpos
= it
.current_x
= 0;
15410 /* Display the rest of the lines at the window end. */
15411 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15412 while (it
.current_y
< it
.last_visible_y
15413 && !fonts_changed_p
)
15415 /* Is it always sure that the display agrees with lines in
15416 the current matrix? I don't think so, so we mark rows
15417 displayed invalid in the current matrix by setting their
15418 enabled_p flag to zero. */
15419 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15420 if (display_line (&it
))
15421 last_text_row_at_end
= it
.glyph_row
- 1;
15425 /* Update window_end_pos and window_end_vpos. */
15426 if (first_unchanged_at_end_row
15427 && !last_text_row_at_end
)
15429 /* Window end line if one of the preserved rows from the current
15430 matrix. Set row to the last row displaying text in current
15431 matrix starting at first_unchanged_at_end_row, after
15433 xassert (first_unchanged_at_end_row
->displays_text_p
);
15434 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15435 first_unchanged_at_end_row
);
15436 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15438 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15439 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15441 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15442 xassert (w
->window_end_bytepos
>= 0);
15443 IF_DEBUG (debug_method_add (w
, "A"));
15445 else if (last_text_row_at_end
)
15448 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15449 w
->window_end_bytepos
15450 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15452 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15453 xassert (w
->window_end_bytepos
>= 0);
15454 IF_DEBUG (debug_method_add (w
, "B"));
15456 else if (last_text_row
)
15458 /* We have displayed either to the end of the window or at the
15459 end of the window, i.e. the last row with text is to be found
15460 in the desired matrix. */
15462 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15463 w
->window_end_bytepos
15464 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15466 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15467 xassert (w
->window_end_bytepos
>= 0);
15469 else if (first_unchanged_at_end_row
== NULL
15470 && last_text_row
== NULL
15471 && last_text_row_at_end
== NULL
)
15473 /* Displayed to end of window, but no line containing text was
15474 displayed. Lines were deleted at the end of the window. */
15475 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15476 int vpos
= XFASTINT (w
->window_end_vpos
);
15477 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15478 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15481 row
== NULL
&& vpos
>= first_vpos
;
15482 --vpos
, --current_row
, --desired_row
)
15484 if (desired_row
->enabled_p
)
15486 if (desired_row
->displays_text_p
)
15489 else if (current_row
->displays_text_p
)
15493 xassert (row
!= NULL
);
15494 w
->window_end_vpos
= make_number (vpos
+ 1);
15495 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15496 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15497 xassert (w
->window_end_bytepos
>= 0);
15498 IF_DEBUG (debug_method_add (w
, "C"));
15503 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15504 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15506 /* Record that display has not been completed. */
15507 w
->window_end_valid
= Qnil
;
15508 w
->desired_matrix
->no_scrolling_p
= 1;
15516 /***********************************************************************
15517 More debugging support
15518 ***********************************************************************/
15522 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15523 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15524 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15527 /* Dump the contents of glyph matrix MATRIX on stderr.
15529 GLYPHS 0 means don't show glyph contents.
15530 GLYPHS 1 means show glyphs in short form
15531 GLYPHS > 1 means show glyphs in long form. */
15534 dump_glyph_matrix (matrix
, glyphs
)
15535 struct glyph_matrix
*matrix
;
15539 for (i
= 0; i
< matrix
->nrows
; ++i
)
15540 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15544 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15545 the glyph row and area where the glyph comes from. */
15548 dump_glyph (row
, glyph
, area
)
15549 struct glyph_row
*row
;
15550 struct glyph
*glyph
;
15553 if (glyph
->type
== CHAR_GLYPH
)
15556 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15557 glyph
- row
->glyphs
[TEXT_AREA
],
15560 (BUFFERP (glyph
->object
)
15562 : (STRINGP (glyph
->object
)
15565 glyph
->pixel_width
,
15567 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15571 glyph
->left_box_line_p
,
15572 glyph
->right_box_line_p
);
15574 else if (glyph
->type
== STRETCH_GLYPH
)
15577 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15578 glyph
- row
->glyphs
[TEXT_AREA
],
15581 (BUFFERP (glyph
->object
)
15583 : (STRINGP (glyph
->object
)
15586 glyph
->pixel_width
,
15590 glyph
->left_box_line_p
,
15591 glyph
->right_box_line_p
);
15593 else if (glyph
->type
== IMAGE_GLYPH
)
15596 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15597 glyph
- row
->glyphs
[TEXT_AREA
],
15600 (BUFFERP (glyph
->object
)
15602 : (STRINGP (glyph
->object
)
15605 glyph
->pixel_width
,
15609 glyph
->left_box_line_p
,
15610 glyph
->right_box_line_p
);
15612 else if (glyph
->type
== COMPOSITE_GLYPH
)
15615 " %5d %4c %6d %c %3d 0x%05x",
15616 glyph
- row
->glyphs
[TEXT_AREA
],
15619 (BUFFERP (glyph
->object
)
15621 : (STRINGP (glyph
->object
)
15624 glyph
->pixel_width
,
15626 if (glyph
->u
.cmp
.automatic
)
15629 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
15630 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
15632 glyph
->left_box_line_p
,
15633 glyph
->right_box_line_p
);
15638 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15639 GLYPHS 0 means don't show glyph contents.
15640 GLYPHS 1 means show glyphs in short form
15641 GLYPHS > 1 means show glyphs in long form. */
15644 dump_glyph_row (row
, vpos
, glyphs
)
15645 struct glyph_row
*row
;
15650 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15651 fprintf (stderr
, "======================================================================\n");
15653 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15654 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15656 MATRIX_ROW_START_CHARPOS (row
),
15657 MATRIX_ROW_END_CHARPOS (row
),
15658 row
->used
[TEXT_AREA
],
15659 row
->contains_overlapping_glyphs_p
,
15661 row
->truncated_on_left_p
,
15662 row
->truncated_on_right_p
,
15664 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15665 row
->displays_text_p
,
15668 row
->ends_in_middle_of_char_p
,
15669 row
->starts_in_middle_of_char_p
,
15675 row
->visible_height
,
15678 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15679 row
->end
.overlay_string_index
,
15680 row
->continuation_lines_width
);
15681 fprintf (stderr
, "%9d %5d\n",
15682 CHARPOS (row
->start
.string_pos
),
15683 CHARPOS (row
->end
.string_pos
));
15684 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15685 row
->end
.dpvec_index
);
15692 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15694 struct glyph
*glyph
= row
->glyphs
[area
];
15695 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15697 /* Glyph for a line end in text. */
15698 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15701 if (glyph
< glyph_end
)
15702 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15704 for (; glyph
< glyph_end
; ++glyph
)
15705 dump_glyph (row
, glyph
, area
);
15708 else if (glyphs
== 1)
15712 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15714 char *s
= (char *) alloca (row
->used
[area
] + 1);
15717 for (i
= 0; i
< row
->used
[area
]; ++i
)
15719 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15720 if (glyph
->type
== CHAR_GLYPH
15721 && glyph
->u
.ch
< 0x80
15722 && glyph
->u
.ch
>= ' ')
15723 s
[i
] = glyph
->u
.ch
;
15729 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15735 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15736 Sdump_glyph_matrix
, 0, 1, "p",
15737 doc
: /* Dump the current matrix of the selected window to stderr.
15738 Shows contents of glyph row structures. With non-nil
15739 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15740 glyphs in short form, otherwise show glyphs in long form. */)
15742 Lisp_Object glyphs
;
15744 struct window
*w
= XWINDOW (selected_window
);
15745 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15747 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15748 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15749 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15750 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15751 fprintf (stderr
, "=============================================\n");
15752 dump_glyph_matrix (w
->current_matrix
,
15753 NILP (glyphs
) ? 0 : XINT (glyphs
));
15758 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15759 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15762 struct frame
*f
= XFRAME (selected_frame
);
15763 dump_glyph_matrix (f
->current_matrix
, 1);
15768 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15769 doc
: /* Dump glyph row ROW to stderr.
15770 GLYPH 0 means don't dump glyphs.
15771 GLYPH 1 means dump glyphs in short form.
15772 GLYPH > 1 or omitted means dump glyphs in long form. */)
15774 Lisp_Object row
, glyphs
;
15776 struct glyph_matrix
*matrix
;
15779 CHECK_NUMBER (row
);
15780 matrix
= XWINDOW (selected_window
)->current_matrix
;
15782 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15783 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15785 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15790 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15791 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15792 GLYPH 0 means don't dump glyphs.
15793 GLYPH 1 means dump glyphs in short form.
15794 GLYPH > 1 or omitted means dump glyphs in long form. */)
15796 Lisp_Object row
, glyphs
;
15798 struct frame
*sf
= SELECTED_FRAME ();
15799 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15802 CHECK_NUMBER (row
);
15804 if (vpos
>= 0 && vpos
< m
->nrows
)
15805 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15806 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15811 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15812 doc
: /* Toggle tracing of redisplay.
15813 With ARG, turn tracing on if and only if ARG is positive. */)
15818 trace_redisplay_p
= !trace_redisplay_p
;
15821 arg
= Fprefix_numeric_value (arg
);
15822 trace_redisplay_p
= XINT (arg
) > 0;
15829 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15830 doc
: /* Like `format', but print result to stderr.
15831 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15836 Lisp_Object s
= Fformat (nargs
, args
);
15837 fprintf (stderr
, "%s", SDATA (s
));
15841 #endif /* GLYPH_DEBUG */
15845 /***********************************************************************
15846 Building Desired Matrix Rows
15847 ***********************************************************************/
15849 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15850 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15852 static struct glyph_row
*
15853 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15855 Lisp_Object overlay_arrow_string
;
15857 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15858 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15859 struct buffer
*old
= current_buffer
;
15860 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15861 int arrow_len
= SCHARS (overlay_arrow_string
);
15862 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15863 const unsigned char *p
;
15866 int n_glyphs_before
;
15868 set_buffer_temp (buffer
);
15869 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15870 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15871 SET_TEXT_POS (it
.position
, 0, 0);
15873 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15875 while (p
< arrow_end
)
15877 Lisp_Object face
, ilisp
;
15879 /* Get the next character. */
15881 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15883 it
.c
= *p
, it
.len
= 1;
15886 /* Get its face. */
15887 ilisp
= make_number (p
- arrow_string
);
15888 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15889 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15891 /* Compute its width, get its glyphs. */
15892 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15893 SET_TEXT_POS (it
.position
, -1, -1);
15894 PRODUCE_GLYPHS (&it
);
15896 /* If this character doesn't fit any more in the line, we have
15897 to remove some glyphs. */
15898 if (it
.current_x
> it
.last_visible_x
)
15900 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15905 set_buffer_temp (old
);
15906 return it
.glyph_row
;
15910 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15911 glyphs are only inserted for terminal frames since we can't really
15912 win with truncation glyphs when partially visible glyphs are
15913 involved. Which glyphs to insert is determined by
15914 produce_special_glyphs. */
15917 insert_left_trunc_glyphs (it
)
15920 struct it truncate_it
;
15921 struct glyph
*from
, *end
, *to
, *toend
;
15923 xassert (!FRAME_WINDOW_P (it
->f
));
15925 /* Get the truncation glyphs. */
15927 truncate_it
.current_x
= 0;
15928 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15929 truncate_it
.glyph_row
= &scratch_glyph_row
;
15930 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15931 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15932 truncate_it
.object
= make_number (0);
15933 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15935 /* Overwrite glyphs from IT with truncation glyphs. */
15936 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15937 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15938 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15939 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15944 /* There may be padding glyphs left over. Overwrite them too. */
15945 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15947 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15953 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15957 /* Compute the pixel height and width of IT->glyph_row.
15959 Most of the time, ascent and height of a display line will be equal
15960 to the max_ascent and max_height values of the display iterator
15961 structure. This is not the case if
15963 1. We hit ZV without displaying anything. In this case, max_ascent
15964 and max_height will be zero.
15966 2. We have some glyphs that don't contribute to the line height.
15967 (The glyph row flag contributes_to_line_height_p is for future
15968 pixmap extensions).
15970 The first case is easily covered by using default values because in
15971 these cases, the line height does not really matter, except that it
15972 must not be zero. */
15975 compute_line_metrics (it
)
15978 struct glyph_row
*row
= it
->glyph_row
;
15981 if (FRAME_WINDOW_P (it
->f
))
15983 int i
, min_y
, max_y
;
15985 /* The line may consist of one space only, that was added to
15986 place the cursor on it. If so, the row's height hasn't been
15988 if (row
->height
== 0)
15990 if (it
->max_ascent
+ it
->max_descent
== 0)
15991 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15992 row
->ascent
= it
->max_ascent
;
15993 row
->height
= it
->max_ascent
+ it
->max_descent
;
15994 row
->phys_ascent
= it
->max_phys_ascent
;
15995 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15996 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15999 /* Compute the width of this line. */
16000 row
->pixel_width
= row
->x
;
16001 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16002 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16004 xassert (row
->pixel_width
>= 0);
16005 xassert (row
->ascent
>= 0 && row
->height
> 0);
16007 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16008 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16010 /* If first line's physical ascent is larger than its logical
16011 ascent, use the physical ascent, and make the row taller.
16012 This makes accented characters fully visible. */
16013 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16014 && row
->phys_ascent
> row
->ascent
)
16016 row
->height
+= row
->phys_ascent
- row
->ascent
;
16017 row
->ascent
= row
->phys_ascent
;
16020 /* Compute how much of the line is visible. */
16021 row
->visible_height
= row
->height
;
16023 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16024 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16026 if (row
->y
< min_y
)
16027 row
->visible_height
-= min_y
- row
->y
;
16028 if (row
->y
+ row
->height
> max_y
)
16029 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16033 row
->pixel_width
= row
->used
[TEXT_AREA
];
16034 if (row
->continued_p
)
16035 row
->pixel_width
-= it
->continuation_pixel_width
;
16036 else if (row
->truncated_on_right_p
)
16037 row
->pixel_width
-= it
->truncation_pixel_width
;
16038 row
->ascent
= row
->phys_ascent
= 0;
16039 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16040 row
->extra_line_spacing
= 0;
16043 /* Compute a hash code for this row. */
16045 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16046 for (i
= 0; i
< row
->used
[area
]; ++i
)
16047 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16048 + row
->glyphs
[area
][i
].u
.val
16049 + row
->glyphs
[area
][i
].face_id
16050 + row
->glyphs
[area
][i
].padding_p
16051 + (row
->glyphs
[area
][i
].type
<< 2));
16053 it
->max_ascent
= it
->max_descent
= 0;
16054 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16058 /* Append one space to the glyph row of iterator IT if doing a
16059 window-based redisplay. The space has the same face as
16060 IT->face_id. Value is non-zero if a space was added.
16062 This function is called to make sure that there is always one glyph
16063 at the end of a glyph row that the cursor can be set on under
16064 window-systems. (If there weren't such a glyph we would not know
16065 how wide and tall a box cursor should be displayed).
16067 At the same time this space let's a nicely handle clearing to the
16068 end of the line if the row ends in italic text. */
16071 append_space_for_newline (it
, default_face_p
)
16073 int default_face_p
;
16075 if (FRAME_WINDOW_P (it
->f
))
16077 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16079 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16080 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16082 /* Save some values that must not be changed.
16083 Must save IT->c and IT->len because otherwise
16084 ITERATOR_AT_END_P wouldn't work anymore after
16085 append_space_for_newline has been called. */
16086 enum display_element_type saved_what
= it
->what
;
16087 int saved_c
= it
->c
, saved_len
= it
->len
;
16088 int saved_x
= it
->current_x
;
16089 int saved_face_id
= it
->face_id
;
16090 struct text_pos saved_pos
;
16091 Lisp_Object saved_object
;
16094 saved_object
= it
->object
;
16095 saved_pos
= it
->position
;
16097 it
->what
= IT_CHARACTER
;
16098 bzero (&it
->position
, sizeof it
->position
);
16099 it
->object
= make_number (0);
16103 if (default_face_p
)
16104 it
->face_id
= DEFAULT_FACE_ID
;
16105 else if (it
->face_before_selective_p
)
16106 it
->face_id
= it
->saved_face_id
;
16107 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16108 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16110 PRODUCE_GLYPHS (it
);
16112 it
->override_ascent
= -1;
16113 it
->constrain_row_ascent_descent_p
= 0;
16114 it
->current_x
= saved_x
;
16115 it
->object
= saved_object
;
16116 it
->position
= saved_pos
;
16117 it
->what
= saved_what
;
16118 it
->face_id
= saved_face_id
;
16119 it
->len
= saved_len
;
16129 /* Extend the face of the last glyph in the text area of IT->glyph_row
16130 to the end of the display line. Called from display_line.
16131 If the glyph row is empty, add a space glyph to it so that we
16132 know the face to draw. Set the glyph row flag fill_line_p. */
16135 extend_face_to_end_of_line (it
)
16139 struct frame
*f
= it
->f
;
16141 /* If line is already filled, do nothing. */
16142 if (it
->current_x
>= it
->last_visible_x
)
16145 /* Face extension extends the background and box of IT->face_id
16146 to the end of the line. If the background equals the background
16147 of the frame, we don't have to do anything. */
16148 if (it
->face_before_selective_p
)
16149 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16151 face
= FACE_FROM_ID (f
, it
->face_id
);
16153 if (FRAME_WINDOW_P (f
)
16154 && it
->glyph_row
->displays_text_p
16155 && face
->box
== FACE_NO_BOX
16156 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16160 /* Set the glyph row flag indicating that the face of the last glyph
16161 in the text area has to be drawn to the end of the text area. */
16162 it
->glyph_row
->fill_line_p
= 1;
16164 /* If current character of IT is not ASCII, make sure we have the
16165 ASCII face. This will be automatically undone the next time
16166 get_next_display_element returns a multibyte character. Note
16167 that the character will always be single byte in unibyte text. */
16168 if (!ASCII_CHAR_P (it
->c
))
16170 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16173 if (FRAME_WINDOW_P (f
))
16175 /* If the row is empty, add a space with the current face of IT,
16176 so that we know which face to draw. */
16177 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16179 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16180 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16181 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16186 /* Save some values that must not be changed. */
16187 int saved_x
= it
->current_x
;
16188 struct text_pos saved_pos
;
16189 Lisp_Object saved_object
;
16190 enum display_element_type saved_what
= it
->what
;
16191 int saved_face_id
= it
->face_id
;
16193 saved_object
= it
->object
;
16194 saved_pos
= it
->position
;
16196 it
->what
= IT_CHARACTER
;
16197 bzero (&it
->position
, sizeof it
->position
);
16198 it
->object
= make_number (0);
16201 it
->face_id
= face
->id
;
16203 PRODUCE_GLYPHS (it
);
16205 while (it
->current_x
<= it
->last_visible_x
)
16206 PRODUCE_GLYPHS (it
);
16208 /* Don't count these blanks really. It would let us insert a left
16209 truncation glyph below and make us set the cursor on them, maybe. */
16210 it
->current_x
= saved_x
;
16211 it
->object
= saved_object
;
16212 it
->position
= saved_pos
;
16213 it
->what
= saved_what
;
16214 it
->face_id
= saved_face_id
;
16219 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16220 trailing whitespace. */
16223 trailing_whitespace_p (charpos
)
16226 int bytepos
= CHAR_TO_BYTE (charpos
);
16229 while (bytepos
< ZV_BYTE
16230 && (c
= FETCH_CHAR (bytepos
),
16231 c
== ' ' || c
== '\t'))
16234 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16236 if (bytepos
!= PT_BYTE
)
16243 /* Highlight trailing whitespace, if any, in ROW. */
16246 highlight_trailing_whitespace (f
, row
)
16248 struct glyph_row
*row
;
16250 int used
= row
->used
[TEXT_AREA
];
16254 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16255 struct glyph
*glyph
= start
+ used
- 1;
16257 /* Skip over glyphs inserted to display the cursor at the
16258 end of a line, for extending the face of the last glyph
16259 to the end of the line on terminals, and for truncation
16260 and continuation glyphs. */
16261 while (glyph
>= start
16262 && glyph
->type
== CHAR_GLYPH
16263 && INTEGERP (glyph
->object
))
16266 /* If last glyph is a space or stretch, and it's trailing
16267 whitespace, set the face of all trailing whitespace glyphs in
16268 IT->glyph_row to `trailing-whitespace'. */
16270 && BUFFERP (glyph
->object
)
16271 && (glyph
->type
== STRETCH_GLYPH
16272 || (glyph
->type
== CHAR_GLYPH
16273 && glyph
->u
.ch
== ' '))
16274 && trailing_whitespace_p (glyph
->charpos
))
16276 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16280 while (glyph
>= start
16281 && BUFFERP (glyph
->object
)
16282 && (glyph
->type
== STRETCH_GLYPH
16283 || (glyph
->type
== CHAR_GLYPH
16284 && glyph
->u
.ch
== ' ')))
16285 (glyph
--)->face_id
= face_id
;
16291 /* Value is non-zero if glyph row ROW in window W should be
16292 used to hold the cursor. */
16295 cursor_row_p (w
, row
)
16297 struct glyph_row
*row
;
16299 int cursor_row_p
= 1;
16301 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16303 /* Suppose the row ends on a string.
16304 Unless the row is continued, that means it ends on a newline
16305 in the string. If it's anything other than a display string
16306 (e.g. a before-string from an overlay), we don't want the
16307 cursor there. (This heuristic seems to give the optimal
16308 behavior for the various types of multi-line strings.) */
16309 if (CHARPOS (row
->end
.string_pos
) >= 0)
16311 if (row
->continued_p
)
16315 /* Check for `display' property. */
16316 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16317 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16318 struct glyph
*glyph
;
16321 for (glyph
= end
; glyph
>= beg
; --glyph
)
16322 if (STRINGP (glyph
->object
))
16325 = Fget_char_property (make_number (PT
),
16329 && display_prop_string_p (prop
, glyph
->object
));
16334 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16336 /* If the row ends in middle of a real character,
16337 and the line is continued, we want the cursor here.
16338 That's because MATRIX_ROW_END_CHARPOS would equal
16339 PT if PT is before the character. */
16340 if (!row
->ends_in_ellipsis_p
)
16341 cursor_row_p
= row
->continued_p
;
16343 /* If the row ends in an ellipsis, then
16344 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16345 We want that position to be displayed after the ellipsis. */
16348 /* If the row ends at ZV, display the cursor at the end of that
16349 row instead of at the start of the row below. */
16350 else if (row
->ends_at_zv_p
)
16356 return cursor_row_p
;
16361 /* Push the display property PROP so that it will be rendered at the
16362 current position in IT. */
16365 push_display_prop (struct it
*it
, Lisp_Object prop
)
16369 /* Never display a cursor on the prefix. */
16370 it
->avoid_cursor_p
= 1;
16372 if (STRINGP (prop
))
16374 if (SCHARS (prop
) == 0)
16381 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16382 it
->current
.overlay_string_index
= -1;
16383 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16384 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16385 it
->method
= GET_FROM_STRING
;
16386 it
->stop_charpos
= 0;
16388 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16390 it
->method
= GET_FROM_STRETCH
;
16393 #ifdef HAVE_WINDOW_SYSTEM
16394 else if (IMAGEP (prop
))
16396 it
->what
= IT_IMAGE
;
16397 it
->image_id
= lookup_image (it
->f
, prop
);
16398 it
->method
= GET_FROM_IMAGE
;
16400 #endif /* HAVE_WINDOW_SYSTEM */
16403 pop_it (it
); /* bogus display property, give up */
16408 /* Return the character-property PROP at the current position in IT. */
16411 get_it_property (it
, prop
)
16415 Lisp_Object position
;
16417 if (STRINGP (it
->object
))
16418 position
= make_number (IT_STRING_CHARPOS (*it
));
16419 else if (BUFFERP (it
->object
))
16420 position
= make_number (IT_CHARPOS (*it
));
16424 return Fget_char_property (position
, prop
, it
->object
);
16427 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16430 handle_line_prefix (struct it
*it
)
16432 Lisp_Object prefix
;
16433 if (it
->continuation_lines_width
> 0)
16435 prefix
= get_it_property (it
, Qwrap_prefix
);
16437 prefix
= Vwrap_prefix
;
16441 prefix
= get_it_property (it
, Qline_prefix
);
16443 prefix
= Vline_prefix
;
16445 if (! NILP (prefix
))
16447 push_display_prop (it
, prefix
);
16448 /* If the prefix is wider than the window, and we try to wrap
16449 it, it would acquire its own wrap prefix, and so on till the
16450 iterator stack overflows. So, don't wrap the prefix. */
16451 it
->line_wrap
= TRUNCATE
;
16457 /* Construct the glyph row IT->glyph_row in the desired matrix of
16458 IT->w from text at the current position of IT. See dispextern.h
16459 for an overview of struct it. Value is non-zero if
16460 IT->glyph_row displays text, as opposed to a line displaying ZV
16467 struct glyph_row
*row
= it
->glyph_row
;
16468 Lisp_Object overlay_arrow_string
;
16470 int may_wrap
= 0, wrap_x
;
16471 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16472 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16473 int wrap_row_extra_line_spacing
;
16475 /* We always start displaying at hpos zero even if hscrolled. */
16476 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16478 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16479 >= it
->w
->desired_matrix
->nrows
)
16481 it
->w
->nrows_scale_factor
++;
16482 fonts_changed_p
= 1;
16486 /* Is IT->w showing the region? */
16487 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16489 /* Clear the result glyph row and enable it. */
16490 prepare_desired_row (row
);
16492 row
->y
= it
->current_y
;
16493 row
->start
= it
->start
;
16494 row
->continuation_lines_width
= it
->continuation_lines_width
;
16495 row
->displays_text_p
= 1;
16496 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16497 it
->starts_in_middle_of_char_p
= 0;
16499 /* Arrange the overlays nicely for our purposes. Usually, we call
16500 display_line on only one line at a time, in which case this
16501 can't really hurt too much, or we call it on lines which appear
16502 one after another in the buffer, in which case all calls to
16503 recenter_overlay_lists but the first will be pretty cheap. */
16504 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16506 /* Move over display elements that are not visible because we are
16507 hscrolled. This may stop at an x-position < IT->first_visible_x
16508 if the first glyph is partially visible or if we hit a line end. */
16509 if (it
->current_x
< it
->first_visible_x
)
16511 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16512 MOVE_TO_POS
| MOVE_TO_X
);
16516 /* We only do this when not calling `move_it_in_display_line_to'
16517 above, because move_it_in_display_line_to calls
16518 handle_line_prefix itself. */
16519 handle_line_prefix (it
);
16522 /* Get the initial row height. This is either the height of the
16523 text hscrolled, if there is any, or zero. */
16524 row
->ascent
= it
->max_ascent
;
16525 row
->height
= it
->max_ascent
+ it
->max_descent
;
16526 row
->phys_ascent
= it
->max_phys_ascent
;
16527 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16528 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16530 /* Loop generating characters. The loop is left with IT on the next
16531 character to display. */
16534 int n_glyphs_before
, hpos_before
, x_before
;
16536 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16538 /* Retrieve the next thing to display. Value is zero if end of
16540 if (!get_next_display_element (it
))
16542 /* Maybe add a space at the end of this line that is used to
16543 display the cursor there under X. Set the charpos of the
16544 first glyph of blank lines not corresponding to any text
16546 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16547 row
->exact_window_width_line_p
= 1;
16548 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16549 || row
->used
[TEXT_AREA
] == 0)
16551 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16552 row
->displays_text_p
= 0;
16554 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16555 && (!MINI_WINDOW_P (it
->w
)
16556 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16557 row
->indicate_empty_line_p
= 1;
16560 it
->continuation_lines_width
= 0;
16561 row
->ends_at_zv_p
= 1;
16565 /* Now, get the metrics of what we want to display. This also
16566 generates glyphs in `row' (which is IT->glyph_row). */
16567 n_glyphs_before
= row
->used
[TEXT_AREA
];
16570 /* Remember the line height so far in case the next element doesn't
16571 fit on the line. */
16572 if (it
->line_wrap
!= TRUNCATE
)
16574 ascent
= it
->max_ascent
;
16575 descent
= it
->max_descent
;
16576 phys_ascent
= it
->max_phys_ascent
;
16577 phys_descent
= it
->max_phys_descent
;
16579 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16581 if (IT_DISPLAYING_WHITESPACE (it
))
16587 wrap_row_used
= row
->used
[TEXT_AREA
];
16588 wrap_row_ascent
= row
->ascent
;
16589 wrap_row_height
= row
->height
;
16590 wrap_row_phys_ascent
= row
->phys_ascent
;
16591 wrap_row_phys_height
= row
->phys_height
;
16592 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16598 PRODUCE_GLYPHS (it
);
16600 /* If this display element was in marginal areas, continue with
16602 if (it
->area
!= TEXT_AREA
)
16604 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16605 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16606 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16607 row
->phys_height
= max (row
->phys_height
,
16608 it
->max_phys_ascent
+ it
->max_phys_descent
);
16609 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16610 it
->max_extra_line_spacing
);
16611 set_iterator_to_next (it
, 1);
16615 /* Does the display element fit on the line? If we truncate
16616 lines, we should draw past the right edge of the window. If
16617 we don't truncate, we want to stop so that we can display the
16618 continuation glyph before the right margin. If lines are
16619 continued, there are two possible strategies for characters
16620 resulting in more than 1 glyph (e.g. tabs): Display as many
16621 glyphs as possible in this line and leave the rest for the
16622 continuation line, or display the whole element in the next
16623 line. Original redisplay did the former, so we do it also. */
16624 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16625 hpos_before
= it
->hpos
;
16628 if (/* Not a newline. */
16630 /* Glyphs produced fit entirely in the line. */
16631 && it
->current_x
< it
->last_visible_x
)
16633 it
->hpos
+= nglyphs
;
16634 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16635 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16636 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16637 row
->phys_height
= max (row
->phys_height
,
16638 it
->max_phys_ascent
+ it
->max_phys_descent
);
16639 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16640 it
->max_extra_line_spacing
);
16641 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16642 row
->x
= x
- it
->first_visible_x
;
16647 struct glyph
*glyph
;
16649 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16651 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16652 new_x
= x
+ glyph
->pixel_width
;
16654 if (/* Lines are continued. */
16655 it
->line_wrap
!= TRUNCATE
16656 && (/* Glyph doesn't fit on the line. */
16657 new_x
> it
->last_visible_x
16658 /* Or it fits exactly on a window system frame. */
16659 || (new_x
== it
->last_visible_x
16660 && FRAME_WINDOW_P (it
->f
))))
16662 /* End of a continued line. */
16665 || (new_x
== it
->last_visible_x
16666 && FRAME_WINDOW_P (it
->f
)))
16668 /* Current glyph is the only one on the line or
16669 fits exactly on the line. We must continue
16670 the line because we can't draw the cursor
16671 after the glyph. */
16672 row
->continued_p
= 1;
16673 it
->current_x
= new_x
;
16674 it
->continuation_lines_width
+= new_x
;
16676 if (i
== nglyphs
- 1)
16678 /* If line-wrap is on, check if a previous
16679 wrap point was found. */
16680 if (wrap_row_used
> 0
16681 /* Even if there is a previous wrap
16682 point, continue the line here as
16683 usual, if (i) the previous character
16684 was a space or tab AND (ii) the
16685 current character is not. */
16687 || IT_DISPLAYING_WHITESPACE (it
)))
16690 set_iterator_to_next (it
, 1);
16691 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16693 if (!get_next_display_element (it
))
16695 row
->exact_window_width_line_p
= 1;
16696 it
->continuation_lines_width
= 0;
16697 row
->continued_p
= 0;
16698 row
->ends_at_zv_p
= 1;
16700 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16702 row
->continued_p
= 0;
16703 row
->exact_window_width_line_p
= 1;
16708 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16709 && !FRAME_WINDOW_P (it
->f
))
16711 /* A padding glyph that doesn't fit on this line.
16712 This means the whole character doesn't fit
16714 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16716 /* Fill the rest of the row with continuation
16717 glyphs like in 20.x. */
16718 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16719 < row
->glyphs
[1 + TEXT_AREA
])
16720 produce_special_glyphs (it
, IT_CONTINUATION
);
16722 row
->continued_p
= 1;
16723 it
->current_x
= x_before
;
16724 it
->continuation_lines_width
+= x_before
;
16726 /* Restore the height to what it was before the
16727 element not fitting on the line. */
16728 it
->max_ascent
= ascent
;
16729 it
->max_descent
= descent
;
16730 it
->max_phys_ascent
= phys_ascent
;
16731 it
->max_phys_descent
= phys_descent
;
16733 else if (wrap_row_used
> 0)
16737 it
->continuation_lines_width
+= wrap_x
;
16738 row
->used
[TEXT_AREA
] = wrap_row_used
;
16739 row
->ascent
= wrap_row_ascent
;
16740 row
->height
= wrap_row_height
;
16741 row
->phys_ascent
= wrap_row_phys_ascent
;
16742 row
->phys_height
= wrap_row_phys_height
;
16743 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16744 row
->continued_p
= 1;
16745 row
->ends_at_zv_p
= 0;
16746 row
->exact_window_width_line_p
= 0;
16747 it
->continuation_lines_width
+= x
;
16749 /* Make sure that a non-default face is extended
16750 up to the right margin of the window. */
16751 extend_face_to_end_of_line (it
);
16753 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16755 /* A TAB that extends past the right edge of the
16756 window. This produces a single glyph on
16757 window system frames. We leave the glyph in
16758 this row and let it fill the row, but don't
16759 consume the TAB. */
16760 it
->continuation_lines_width
+= it
->last_visible_x
;
16761 row
->ends_in_middle_of_char_p
= 1;
16762 row
->continued_p
= 1;
16763 glyph
->pixel_width
= it
->last_visible_x
- x
;
16764 it
->starts_in_middle_of_char_p
= 1;
16768 /* Something other than a TAB that draws past
16769 the right edge of the window. Restore
16770 positions to values before the element. */
16771 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16773 /* Display continuation glyphs. */
16774 if (!FRAME_WINDOW_P (it
->f
))
16775 produce_special_glyphs (it
, IT_CONTINUATION
);
16776 row
->continued_p
= 1;
16778 it
->current_x
= x_before
;
16779 it
->continuation_lines_width
+= x
;
16780 extend_face_to_end_of_line (it
);
16782 if (nglyphs
> 1 && i
> 0)
16784 row
->ends_in_middle_of_char_p
= 1;
16785 it
->starts_in_middle_of_char_p
= 1;
16788 /* Restore the height to what it was before the
16789 element not fitting on the line. */
16790 it
->max_ascent
= ascent
;
16791 it
->max_descent
= descent
;
16792 it
->max_phys_ascent
= phys_ascent
;
16793 it
->max_phys_descent
= phys_descent
;
16798 else if (new_x
> it
->first_visible_x
)
16800 /* Increment number of glyphs actually displayed. */
16803 if (x
< it
->first_visible_x
)
16804 /* Glyph is partially visible, i.e. row starts at
16805 negative X position. */
16806 row
->x
= x
- it
->first_visible_x
;
16810 /* Glyph is completely off the left margin of the
16811 window. This should not happen because of the
16812 move_it_in_display_line at the start of this
16813 function, unless the text display area of the
16814 window is empty. */
16815 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16819 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16820 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16821 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16822 row
->phys_height
= max (row
->phys_height
,
16823 it
->max_phys_ascent
+ it
->max_phys_descent
);
16824 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16825 it
->max_extra_line_spacing
);
16827 /* End of this display line if row is continued. */
16828 if (row
->continued_p
|| row
->ends_at_zv_p
)
16833 /* Is this a line end? If yes, we're also done, after making
16834 sure that a non-default face is extended up to the right
16835 margin of the window. */
16836 if (ITERATOR_AT_END_OF_LINE_P (it
))
16838 int used_before
= row
->used
[TEXT_AREA
];
16840 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16842 /* Add a space at the end of the line that is used to
16843 display the cursor there. */
16844 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16845 append_space_for_newline (it
, 0);
16847 /* Extend the face to the end of the line. */
16848 extend_face_to_end_of_line (it
);
16850 /* Make sure we have the position. */
16851 if (used_before
== 0)
16852 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16854 /* Consume the line end. This skips over invisible lines. */
16855 set_iterator_to_next (it
, 1);
16856 it
->continuation_lines_width
= 0;
16860 /* Proceed with next display element. Note that this skips
16861 over lines invisible because of selective display. */
16862 set_iterator_to_next (it
, 1);
16864 /* If we truncate lines, we are done when the last displayed
16865 glyphs reach past the right margin of the window. */
16866 if (it
->line_wrap
== TRUNCATE
16867 && (FRAME_WINDOW_P (it
->f
)
16868 ? (it
->current_x
>= it
->last_visible_x
)
16869 : (it
->current_x
> it
->last_visible_x
)))
16871 /* Maybe add truncation glyphs. */
16872 if (!FRAME_WINDOW_P (it
->f
))
16876 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16877 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16880 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16882 row
->used
[TEXT_AREA
] = i
;
16883 produce_special_glyphs (it
, IT_TRUNCATION
);
16886 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16888 /* Don't truncate if we can overflow newline into fringe. */
16889 if (!get_next_display_element (it
))
16891 it
->continuation_lines_width
= 0;
16892 row
->ends_at_zv_p
= 1;
16893 row
->exact_window_width_line_p
= 1;
16896 if (ITERATOR_AT_END_OF_LINE_P (it
))
16898 row
->exact_window_width_line_p
= 1;
16899 goto at_end_of_line
;
16903 row
->truncated_on_right_p
= 1;
16904 it
->continuation_lines_width
= 0;
16905 reseat_at_next_visible_line_start (it
, 0);
16906 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16907 it
->hpos
= hpos_before
;
16908 it
->current_x
= x_before
;
16913 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16914 at the left window margin. */
16915 if (it
->first_visible_x
16916 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16918 if (!FRAME_WINDOW_P (it
->f
))
16919 insert_left_trunc_glyphs (it
);
16920 row
->truncated_on_left_p
= 1;
16923 /* If the start of this line is the overlay arrow-position, then
16924 mark this glyph row as the one containing the overlay arrow.
16925 This is clearly a mess with variable size fonts. It would be
16926 better to let it be displayed like cursors under X. */
16927 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16928 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16929 !NILP (overlay_arrow_string
)))
16931 /* Overlay arrow in window redisplay is a fringe bitmap. */
16932 if (STRINGP (overlay_arrow_string
))
16934 struct glyph_row
*arrow_row
16935 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16936 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16937 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16938 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16939 struct glyph
*p2
, *end
;
16941 /* Copy the arrow glyphs. */
16942 while (glyph
< arrow_end
)
16945 /* Throw away padding glyphs. */
16947 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16948 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16954 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16959 xassert (INTEGERP (overlay_arrow_string
));
16960 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16962 overlay_arrow_seen
= 1;
16965 /* Compute pixel dimensions of this line. */
16966 compute_line_metrics (it
);
16968 /* Remember the position at which this line ends. */
16969 row
->end
= it
->current
;
16971 /* Record whether this row ends inside an ellipsis. */
16972 row
->ends_in_ellipsis_p
16973 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16974 && it
->ellipsis_p
);
16976 /* Save fringe bitmaps in this row. */
16977 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16978 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16979 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16980 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16982 it
->left_user_fringe_bitmap
= 0;
16983 it
->left_user_fringe_face_id
= 0;
16984 it
->right_user_fringe_bitmap
= 0;
16985 it
->right_user_fringe_face_id
= 0;
16987 /* Maybe set the cursor. */
16988 if (it
->w
->cursor
.vpos
< 0
16989 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16990 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16991 && cursor_row_p (it
->w
, row
))
16992 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16994 /* Highlight trailing whitespace. */
16995 if (!NILP (Vshow_trailing_whitespace
))
16996 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16998 /* Prepare for the next line. This line starts horizontally at (X
16999 HPOS) = (0 0). Vertical positions are incremented. As a
17000 convenience for the caller, IT->glyph_row is set to the next
17002 it
->current_x
= it
->hpos
= 0;
17003 it
->current_y
+= row
->height
;
17006 it
->start
= it
->current
;
17007 return row
->displays_text_p
;
17012 /***********************************************************************
17014 ***********************************************************************/
17016 /* Redisplay the menu bar in the frame for window W.
17018 The menu bar of X frames that don't have X toolkit support is
17019 displayed in a special window W->frame->menu_bar_window.
17021 The menu bar of terminal frames is treated specially as far as
17022 glyph matrices are concerned. Menu bar lines are not part of
17023 windows, so the update is done directly on the frame matrix rows
17024 for the menu bar. */
17027 display_menu_bar (w
)
17030 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17035 /* Don't do all this for graphical frames. */
17037 if (FRAME_W32_P (f
))
17040 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17046 if (FRAME_NS_P (f
))
17048 #endif /* HAVE_NS */
17050 #ifdef USE_X_TOOLKIT
17051 xassert (!FRAME_WINDOW_P (f
));
17052 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17053 it
.first_visible_x
= 0;
17054 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17055 #else /* not USE_X_TOOLKIT */
17056 if (FRAME_WINDOW_P (f
))
17058 /* Menu bar lines are displayed in the desired matrix of the
17059 dummy window menu_bar_window. */
17060 struct window
*menu_w
;
17061 xassert (WINDOWP (f
->menu_bar_window
));
17062 menu_w
= XWINDOW (f
->menu_bar_window
);
17063 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17065 it
.first_visible_x
= 0;
17066 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17070 /* This is a TTY frame, i.e. character hpos/vpos are used as
17072 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17074 it
.first_visible_x
= 0;
17075 it
.last_visible_x
= FRAME_COLS (f
);
17077 #endif /* not USE_X_TOOLKIT */
17079 if (! mode_line_inverse_video
)
17080 /* Force the menu-bar to be displayed in the default face. */
17081 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17083 /* Clear all rows of the menu bar. */
17084 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17086 struct glyph_row
*row
= it
.glyph_row
+ i
;
17087 clear_glyph_row (row
);
17088 row
->enabled_p
= 1;
17089 row
->full_width_p
= 1;
17092 /* Display all items of the menu bar. */
17093 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17094 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17096 Lisp_Object string
;
17098 /* Stop at nil string. */
17099 string
= AREF (items
, i
+ 1);
17103 /* Remember where item was displayed. */
17104 ASET (items
, i
+ 3, make_number (it
.hpos
));
17106 /* Display the item, pad with one space. */
17107 if (it
.current_x
< it
.last_visible_x
)
17108 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17109 SCHARS (string
) + 1, 0, 0, -1);
17112 /* Fill out the line with spaces. */
17113 if (it
.current_x
< it
.last_visible_x
)
17114 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17116 /* Compute the total height of the lines. */
17117 compute_line_metrics (&it
);
17122 /***********************************************************************
17124 ***********************************************************************/
17126 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17127 FORCE is non-zero, redisplay mode lines unconditionally.
17128 Otherwise, redisplay only mode lines that are garbaged. Value is
17129 the number of windows whose mode lines were redisplayed. */
17132 redisplay_mode_lines (window
, force
)
17133 Lisp_Object window
;
17138 while (!NILP (window
))
17140 struct window
*w
= XWINDOW (window
);
17142 if (WINDOWP (w
->hchild
))
17143 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17144 else if (WINDOWP (w
->vchild
))
17145 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17147 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17148 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17150 struct text_pos lpoint
;
17151 struct buffer
*old
= current_buffer
;
17153 /* Set the window's buffer for the mode line display. */
17154 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17155 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17157 /* Point refers normally to the selected window. For any
17158 other window, set up appropriate value. */
17159 if (!EQ (window
, selected_window
))
17161 struct text_pos pt
;
17163 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17164 if (CHARPOS (pt
) < BEGV
)
17165 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17166 else if (CHARPOS (pt
) > (ZV
- 1))
17167 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17169 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17172 /* Display mode lines. */
17173 clear_glyph_matrix (w
->desired_matrix
);
17174 if (display_mode_lines (w
))
17177 w
->must_be_updated_p
= 1;
17180 /* Restore old settings. */
17181 set_buffer_internal_1 (old
);
17182 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17192 /* Display the mode and/or top line of window W. Value is the number
17193 of mode lines displayed. */
17196 display_mode_lines (w
)
17199 Lisp_Object old_selected_window
, old_selected_frame
;
17202 old_selected_frame
= selected_frame
;
17203 selected_frame
= w
->frame
;
17204 old_selected_window
= selected_window
;
17205 XSETWINDOW (selected_window
, w
);
17207 /* These will be set while the mode line specs are processed. */
17208 line_number_displayed
= 0;
17209 w
->column_number_displayed
= Qnil
;
17211 if (WINDOW_WANTS_MODELINE_P (w
))
17213 struct window
*sel_w
= XWINDOW (old_selected_window
);
17215 /* Select mode line face based on the real selected window. */
17216 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17217 current_buffer
->mode_line_format
);
17221 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17223 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17224 current_buffer
->header_line_format
);
17228 selected_frame
= old_selected_frame
;
17229 selected_window
= old_selected_window
;
17234 /* Display mode or top line of window W. FACE_ID specifies which line
17235 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
17236 FORMAT is the mode line format to display. Value is the pixel
17237 height of the mode line displayed. */
17240 display_mode_line (w
, face_id
, format
)
17242 enum face_id face_id
;
17243 Lisp_Object format
;
17247 int count
= SPECPDL_INDEX ();
17249 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17250 /* Don't extend on a previously drawn mode-line.
17251 This may happen if called from pos_visible_p. */
17252 it
.glyph_row
->enabled_p
= 0;
17253 prepare_desired_row (it
.glyph_row
);
17255 it
.glyph_row
->mode_line_p
= 1;
17257 if (! mode_line_inverse_video
)
17258 /* Force the mode-line to be displayed in the default face. */
17259 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17261 record_unwind_protect (unwind_format_mode_line
,
17262 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17264 mode_line_target
= MODE_LINE_DISPLAY
;
17266 /* Temporarily make frame's keyboard the current kboard so that
17267 kboard-local variables in the mode_line_format will get the right
17269 push_kboard (FRAME_KBOARD (it
.f
));
17270 record_unwind_save_match_data ();
17271 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17274 unbind_to (count
, Qnil
);
17276 /* Fill up with spaces. */
17277 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17279 compute_line_metrics (&it
);
17280 it
.glyph_row
->full_width_p
= 1;
17281 it
.glyph_row
->continued_p
= 0;
17282 it
.glyph_row
->truncated_on_left_p
= 0;
17283 it
.glyph_row
->truncated_on_right_p
= 0;
17285 /* Make a 3D mode-line have a shadow at its right end. */
17286 face
= FACE_FROM_ID (it
.f
, face_id
);
17287 extend_face_to_end_of_line (&it
);
17288 if (face
->box
!= FACE_NO_BOX
)
17290 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17291 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17292 last
->right_box_line_p
= 1;
17295 return it
.glyph_row
->height
;
17298 /* Move element ELT in LIST to the front of LIST.
17299 Return the updated list. */
17302 move_elt_to_front (elt
, list
)
17303 Lisp_Object elt
, list
;
17305 register Lisp_Object tail
, prev
;
17306 register Lisp_Object tem
;
17310 while (CONSP (tail
))
17316 /* Splice out the link TAIL. */
17318 list
= XCDR (tail
);
17320 Fsetcdr (prev
, XCDR (tail
));
17322 /* Now make it the first. */
17323 Fsetcdr (tail
, list
);
17328 tail
= XCDR (tail
);
17332 /* Not found--return unchanged LIST. */
17336 /* Contribute ELT to the mode line for window IT->w. How it
17337 translates into text depends on its data type.
17339 IT describes the display environment in which we display, as usual.
17341 DEPTH is the depth in recursion. It is used to prevent
17342 infinite recursion here.
17344 FIELD_WIDTH is the number of characters the display of ELT should
17345 occupy in the mode line, and PRECISION is the maximum number of
17346 characters to display from ELT's representation. See
17347 display_string for details.
17349 Returns the hpos of the end of the text generated by ELT.
17351 PROPS is a property list to add to any string we encounter.
17353 If RISKY is nonzero, remove (disregard) any properties in any string
17354 we encounter, and ignore :eval and :propertize.
17356 The global variable `mode_line_target' determines whether the
17357 output is passed to `store_mode_line_noprop',
17358 `store_mode_line_string', or `display_string'. */
17361 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17364 int field_width
, precision
;
17365 Lisp_Object elt
, props
;
17368 int n
= 0, field
, prec
;
17373 elt
= build_string ("*too-deep*");
17377 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17381 /* A string: output it and check for %-constructs within it. */
17385 if (SCHARS (elt
) > 0
17386 && (!NILP (props
) || risky
))
17388 Lisp_Object oprops
, aelt
;
17389 oprops
= Ftext_properties_at (make_number (0), elt
);
17391 /* If the starting string's properties are not what
17392 we want, translate the string. Also, if the string
17393 is risky, do that anyway. */
17395 if (NILP (Fequal (props
, oprops
)) || risky
)
17397 /* If the starting string has properties,
17398 merge the specified ones onto the existing ones. */
17399 if (! NILP (oprops
) && !risky
)
17403 oprops
= Fcopy_sequence (oprops
);
17405 while (CONSP (tem
))
17407 oprops
= Fplist_put (oprops
, XCAR (tem
),
17408 XCAR (XCDR (tem
)));
17409 tem
= XCDR (XCDR (tem
));
17414 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17415 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17417 /* AELT is what we want. Move it to the front
17418 without consing. */
17420 mode_line_proptrans_alist
17421 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17427 /* If AELT has the wrong props, it is useless.
17428 so get rid of it. */
17430 mode_line_proptrans_alist
17431 = Fdelq (aelt
, mode_line_proptrans_alist
);
17433 elt
= Fcopy_sequence (elt
);
17434 Fset_text_properties (make_number (0), Flength (elt
),
17436 /* Add this item to mode_line_proptrans_alist. */
17437 mode_line_proptrans_alist
17438 = Fcons (Fcons (elt
, props
),
17439 mode_line_proptrans_alist
);
17440 /* Truncate mode_line_proptrans_alist
17441 to at most 50 elements. */
17442 tem
= Fnthcdr (make_number (50),
17443 mode_line_proptrans_alist
);
17445 XSETCDR (tem
, Qnil
);
17454 prec
= precision
- n
;
17455 switch (mode_line_target
)
17457 case MODE_LINE_NOPROP
:
17458 case MODE_LINE_TITLE
:
17459 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17461 case MODE_LINE_STRING
:
17462 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17464 case MODE_LINE_DISPLAY
:
17465 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17466 0, prec
, 0, STRING_MULTIBYTE (elt
));
17473 /* Handle the non-literal case. */
17475 while ((precision
<= 0 || n
< precision
)
17476 && SREF (elt
, offset
) != 0
17477 && (mode_line_target
!= MODE_LINE_DISPLAY
17478 || it
->current_x
< it
->last_visible_x
))
17480 int last_offset
= offset
;
17482 /* Advance to end of string or next format specifier. */
17483 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17486 if (offset
- 1 != last_offset
)
17488 int nchars
, nbytes
;
17490 /* Output to end of string or up to '%'. Field width
17491 is length of string. Don't output more than
17492 PRECISION allows us. */
17495 prec
= c_string_width (SDATA (elt
) + last_offset
,
17496 offset
- last_offset
, precision
- n
,
17499 switch (mode_line_target
)
17501 case MODE_LINE_NOPROP
:
17502 case MODE_LINE_TITLE
:
17503 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17505 case MODE_LINE_STRING
:
17507 int bytepos
= last_offset
;
17508 int charpos
= string_byte_to_char (elt
, bytepos
);
17509 int endpos
= (precision
<= 0
17510 ? string_byte_to_char (elt
, offset
)
17511 : charpos
+ nchars
);
17513 n
+= store_mode_line_string (NULL
,
17514 Fsubstring (elt
, make_number (charpos
),
17515 make_number (endpos
)),
17519 case MODE_LINE_DISPLAY
:
17521 int bytepos
= last_offset
;
17522 int charpos
= string_byte_to_char (elt
, bytepos
);
17524 if (precision
<= 0)
17525 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17526 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17528 STRING_MULTIBYTE (elt
));
17533 else /* c == '%' */
17535 int percent_position
= offset
;
17537 /* Get the specified minimum width. Zero means
17540 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17541 field
= field
* 10 + c
- '0';
17543 /* Don't pad beyond the total padding allowed. */
17544 if (field_width
- n
> 0 && field
> field_width
- n
)
17545 field
= field_width
- n
;
17547 /* Note that either PRECISION <= 0 or N < PRECISION. */
17548 prec
= precision
- n
;
17551 n
+= display_mode_element (it
, depth
, field
, prec
,
17552 Vglobal_mode_string
, props
,
17557 int bytepos
, charpos
;
17558 unsigned char *spec
;
17560 bytepos
= percent_position
;
17561 charpos
= (STRING_MULTIBYTE (elt
)
17562 ? string_byte_to_char (elt
, bytepos
)
17565 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17567 switch (mode_line_target
)
17569 case MODE_LINE_NOPROP
:
17570 case MODE_LINE_TITLE
:
17571 n
+= store_mode_line_noprop (spec
, field
, prec
);
17573 case MODE_LINE_STRING
:
17575 int len
= strlen (spec
);
17576 Lisp_Object tem
= make_string (spec
, len
);
17577 props
= Ftext_properties_at (make_number (charpos
), elt
);
17578 /* Should only keep face property in props */
17579 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17582 case MODE_LINE_DISPLAY
:
17584 int nglyphs_before
, nwritten
;
17586 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17587 nwritten
= display_string (spec
, Qnil
, elt
,
17592 /* Assign to the glyphs written above the
17593 string where the `%x' came from, position
17597 struct glyph
*glyph
17598 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17602 for (i
= 0; i
< nwritten
; ++i
)
17604 glyph
[i
].object
= elt
;
17605 glyph
[i
].charpos
= charpos
;
17622 /* A symbol: process the value of the symbol recursively
17623 as if it appeared here directly. Avoid error if symbol void.
17624 Special case: if value of symbol is a string, output the string
17627 register Lisp_Object tem
;
17629 /* If the variable is not marked as risky to set
17630 then its contents are risky to use. */
17631 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17634 tem
= Fboundp (elt
);
17637 tem
= Fsymbol_value (elt
);
17638 /* If value is a string, output that string literally:
17639 don't check for % within it. */
17643 if (!EQ (tem
, elt
))
17645 /* Give up right away for nil or t. */
17655 register Lisp_Object car
, tem
;
17657 /* A cons cell: five distinct cases.
17658 If first element is :eval or :propertize, do something special.
17659 If first element is a string or a cons, process all the elements
17660 and effectively concatenate them.
17661 If first element is a negative number, truncate displaying cdr to
17662 at most that many characters. If positive, pad (with spaces)
17663 to at least that many characters.
17664 If first element is a symbol, process the cadr or caddr recursively
17665 according to whether the symbol's value is non-nil or nil. */
17667 if (EQ (car
, QCeval
))
17669 /* An element of the form (:eval FORM) means evaluate FORM
17670 and use the result as mode line elements. */
17675 if (CONSP (XCDR (elt
)))
17678 spec
= safe_eval (XCAR (XCDR (elt
)));
17679 n
+= display_mode_element (it
, depth
, field_width
- n
,
17680 precision
- n
, spec
, props
,
17684 else if (EQ (car
, QCpropertize
))
17686 /* An element of the form (:propertize ELT PROPS...)
17687 means display ELT but applying properties PROPS. */
17692 if (CONSP (XCDR (elt
)))
17693 n
+= display_mode_element (it
, depth
, field_width
- n
,
17694 precision
- n
, XCAR (XCDR (elt
)),
17695 XCDR (XCDR (elt
)), risky
);
17697 else if (SYMBOLP (car
))
17699 tem
= Fboundp (car
);
17703 /* elt is now the cdr, and we know it is a cons cell.
17704 Use its car if CAR has a non-nil value. */
17707 tem
= Fsymbol_value (car
);
17714 /* Symbol's value is nil (or symbol is unbound)
17715 Get the cddr of the original list
17716 and if possible find the caddr and use that. */
17720 else if (!CONSP (elt
))
17725 else if (INTEGERP (car
))
17727 register int lim
= XINT (car
);
17731 /* Negative int means reduce maximum width. */
17732 if (precision
<= 0)
17735 precision
= min (precision
, -lim
);
17739 /* Padding specified. Don't let it be more than
17740 current maximum. */
17742 lim
= min (precision
, lim
);
17744 /* If that's more padding than already wanted, queue it.
17745 But don't reduce padding already specified even if
17746 that is beyond the current truncation point. */
17747 field_width
= max (lim
, field_width
);
17751 else if (STRINGP (car
) || CONSP (car
))
17753 Lisp_Object halftail
= elt
;
17757 && (precision
<= 0 || n
< precision
))
17759 n
+= display_mode_element (it
, depth
,
17760 /* Do padding only after the last
17761 element in the list. */
17762 (! CONSP (XCDR (elt
))
17765 precision
- n
, XCAR (elt
),
17769 if ((len
& 1) == 0)
17770 halftail
= XCDR (halftail
);
17771 /* Check for cycle. */
17772 if (EQ (halftail
, elt
))
17781 elt
= build_string ("*invalid*");
17785 /* Pad to FIELD_WIDTH. */
17786 if (field_width
> 0 && n
< field_width
)
17788 switch (mode_line_target
)
17790 case MODE_LINE_NOPROP
:
17791 case MODE_LINE_TITLE
:
17792 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17794 case MODE_LINE_STRING
:
17795 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17797 case MODE_LINE_DISPLAY
:
17798 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17807 /* Store a mode-line string element in mode_line_string_list.
17809 If STRING is non-null, display that C string. Otherwise, the Lisp
17810 string LISP_STRING is displayed.
17812 FIELD_WIDTH is the minimum number of output glyphs to produce.
17813 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17814 with spaces. FIELD_WIDTH <= 0 means don't pad.
17816 PRECISION is the maximum number of characters to output from
17817 STRING. PRECISION <= 0 means don't truncate the string.
17819 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17820 properties to the string.
17822 PROPS are the properties to add to the string.
17823 The mode_line_string_face face property is always added to the string.
17827 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17829 Lisp_Object lisp_string
;
17838 if (string
!= NULL
)
17840 len
= strlen (string
);
17841 if (precision
> 0 && len
> precision
)
17843 lisp_string
= make_string (string
, len
);
17845 props
= mode_line_string_face_prop
;
17846 else if (!NILP (mode_line_string_face
))
17848 Lisp_Object face
= Fplist_get (props
, Qface
);
17849 props
= Fcopy_sequence (props
);
17851 face
= mode_line_string_face
;
17853 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17854 props
= Fplist_put (props
, Qface
, face
);
17856 Fadd_text_properties (make_number (0), make_number (len
),
17857 props
, lisp_string
);
17861 len
= XFASTINT (Flength (lisp_string
));
17862 if (precision
> 0 && len
> precision
)
17865 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17868 if (!NILP (mode_line_string_face
))
17872 props
= Ftext_properties_at (make_number (0), lisp_string
);
17873 face
= Fplist_get (props
, Qface
);
17875 face
= mode_line_string_face
;
17877 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17878 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17880 lisp_string
= Fcopy_sequence (lisp_string
);
17883 Fadd_text_properties (make_number (0), make_number (len
),
17884 props
, lisp_string
);
17889 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17893 if (field_width
> len
)
17895 field_width
-= len
;
17896 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17898 Fadd_text_properties (make_number (0), make_number (field_width
),
17899 props
, lisp_string
);
17900 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17908 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17910 doc
: /* Format a string out of a mode line format specification.
17911 First arg FORMAT specifies the mode line format (see `mode-line-format'
17912 for details) to use.
17914 Optional second arg FACE specifies the face property to put
17915 on all characters for which no face is specified.
17916 The value t means whatever face the window's mode line currently uses
17917 \(either `mode-line' or `mode-line-inactive', depending).
17918 A value of nil means the default is no face property.
17919 If FACE is an integer, the value string has no text properties.
17921 Optional third and fourth args WINDOW and BUFFER specify the window
17922 and buffer to use as the context for the formatting (defaults
17923 are the selected window and the window's buffer). */)
17924 (format
, face
, window
, buffer
)
17925 Lisp_Object format
, face
, window
, buffer
;
17930 struct buffer
*old_buffer
= NULL
;
17932 int no_props
= INTEGERP (face
);
17933 int count
= SPECPDL_INDEX ();
17935 int string_start
= 0;
17938 window
= selected_window
;
17939 CHECK_WINDOW (window
);
17940 w
= XWINDOW (window
);
17943 buffer
= w
->buffer
;
17944 CHECK_BUFFER (buffer
);
17946 /* Make formatting the modeline a non-op when noninteractive, otherwise
17947 there will be problems later caused by a partially initialized frame. */
17948 if (NILP (format
) || noninteractive
)
17949 return empty_unibyte_string
;
17957 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17958 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17962 face_id
= DEFAULT_FACE_ID
;
17964 if (XBUFFER (buffer
) != current_buffer
)
17965 old_buffer
= current_buffer
;
17967 /* Save things including mode_line_proptrans_alist,
17968 and set that to nil so that we don't alter the outer value. */
17969 record_unwind_protect (unwind_format_mode_line
,
17970 format_mode_line_unwind_data
17971 (old_buffer
, selected_window
, 1));
17972 mode_line_proptrans_alist
= Qnil
;
17974 Fselect_window (window
, Qt
);
17976 set_buffer_internal_1 (XBUFFER (buffer
));
17978 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17982 mode_line_target
= MODE_LINE_NOPROP
;
17983 mode_line_string_face_prop
= Qnil
;
17984 mode_line_string_list
= Qnil
;
17985 string_start
= MODE_LINE_NOPROP_LEN (0);
17989 mode_line_target
= MODE_LINE_STRING
;
17990 mode_line_string_list
= Qnil
;
17991 mode_line_string_face
= face
;
17992 mode_line_string_face_prop
17993 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17996 push_kboard (FRAME_KBOARD (it
.f
));
17997 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18002 len
= MODE_LINE_NOPROP_LEN (string_start
);
18003 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18007 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18008 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18009 empty_unibyte_string
);
18012 unbind_to (count
, Qnil
);
18016 /* Write a null-terminated, right justified decimal representation of
18017 the positive integer D to BUF using a minimal field width WIDTH. */
18020 pint2str (buf
, width
, d
)
18021 register char *buf
;
18022 register int width
;
18025 register char *p
= buf
;
18033 *p
++ = d
% 10 + '0';
18038 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18049 /* Write a null-terminated, right justified decimal and "human
18050 readable" representation of the nonnegative integer D to BUF using
18051 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18053 static const char power_letter
[] =
18067 pint2hrstr (buf
, width
, d
)
18072 /* We aim to represent the nonnegative integer D as
18073 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18076 /* -1 means: do not use TENTHS. */
18080 /* Length of QUOTIENT.TENTHS as a string. */
18086 if (1000 <= quotient
)
18088 /* Scale to the appropriate EXPONENT. */
18091 remainder
= quotient
% 1000;
18095 while (1000 <= quotient
);
18097 /* Round to nearest and decide whether to use TENTHS or not. */
18100 tenths
= remainder
/ 100;
18101 if (50 <= remainder
% 100)
18108 if (quotient
== 10)
18116 if (500 <= remainder
)
18118 if (quotient
< 999)
18129 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18130 if (tenths
== -1 && quotient
<= 99)
18137 p
= psuffix
= buf
+ max (width
, length
);
18139 /* Print EXPONENT. */
18141 *psuffix
++ = power_letter
[exponent
];
18144 /* Print TENTHS. */
18147 *--p
= '0' + tenths
;
18151 /* Print QUOTIENT. */
18154 int digit
= quotient
% 10;
18155 *--p
= '0' + digit
;
18157 while ((quotient
/= 10) != 0);
18159 /* Print leading spaces. */
18164 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18165 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18166 type of CODING_SYSTEM. Return updated pointer into BUF. */
18168 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18171 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18172 Lisp_Object coding_system
;
18173 register char *buf
;
18177 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18178 const unsigned char *eol_str
;
18180 /* The EOL conversion we are using. */
18181 Lisp_Object eoltype
;
18183 val
= CODING_SYSTEM_SPEC (coding_system
);
18186 if (!VECTORP (val
)) /* Not yet decided. */
18191 eoltype
= eol_mnemonic_undecided
;
18192 /* Don't mention EOL conversion if it isn't decided. */
18197 Lisp_Object eolvalue
;
18199 attrs
= AREF (val
, 0);
18200 eolvalue
= AREF (val
, 2);
18203 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18207 /* The EOL conversion that is normal on this system. */
18209 if (NILP (eolvalue
)) /* Not yet decided. */
18210 eoltype
= eol_mnemonic_undecided
;
18211 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18212 eoltype
= eol_mnemonic_undecided
;
18213 else /* eolvalue is Qunix, Qdos, or Qmac. */
18214 eoltype
= (EQ (eolvalue
, Qunix
)
18215 ? eol_mnemonic_unix
18216 : (EQ (eolvalue
, Qdos
) == 1
18217 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18223 /* Mention the EOL conversion if it is not the usual one. */
18224 if (STRINGP (eoltype
))
18226 eol_str
= SDATA (eoltype
);
18227 eol_str_len
= SBYTES (eoltype
);
18229 else if (CHARACTERP (eoltype
))
18231 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18232 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18237 eol_str
= invalid_eol_type
;
18238 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18240 bcopy (eol_str
, buf
, eol_str_len
);
18241 buf
+= eol_str_len
;
18247 /* Return a string for the output of a mode line %-spec for window W,
18248 generated by character C. PRECISION >= 0 means don't return a
18249 string longer than that value. FIELD_WIDTH > 0 means pad the
18250 string returned with spaces to that value. Return 1 in *MULTIBYTE
18251 if the result is multibyte text.
18253 Note we operate on the current buffer for most purposes,
18254 the exception being w->base_line_pos. */
18256 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18259 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18262 int field_width
, precision
;
18266 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18267 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18268 struct buffer
*b
= current_buffer
;
18276 if (!NILP (b
->read_only
))
18278 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18283 /* This differs from %* only for a modified read-only buffer. */
18284 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18286 if (!NILP (b
->read_only
))
18291 /* This differs from %* in ignoring read-only-ness. */
18292 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18304 if (command_loop_level
> 5)
18306 p
= decode_mode_spec_buf
;
18307 for (i
= 0; i
< command_loop_level
; i
++)
18310 return decode_mode_spec_buf
;
18318 if (command_loop_level
> 5)
18320 p
= decode_mode_spec_buf
;
18321 for (i
= 0; i
< command_loop_level
; i
++)
18324 return decode_mode_spec_buf
;
18331 /* Let lots_of_dashes be a string of infinite length. */
18332 if (mode_line_target
== MODE_LINE_NOPROP
||
18333 mode_line_target
== MODE_LINE_STRING
)
18335 if (field_width
<= 0
18336 || field_width
> sizeof (lots_of_dashes
))
18338 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18339 decode_mode_spec_buf
[i
] = '-';
18340 decode_mode_spec_buf
[i
] = '\0';
18341 return decode_mode_spec_buf
;
18344 return lots_of_dashes
;
18352 /* %c and %l are ignored in `frame-title-format'.
18353 (In redisplay_internal, the frame title is drawn _before_ the
18354 windows are updated, so the stuff which depends on actual
18355 window contents (such as %l) may fail to render properly, or
18356 even crash emacs.) */
18357 if (mode_line_target
== MODE_LINE_TITLE
)
18361 int col
= (int) current_column (); /* iftc */
18362 w
->column_number_displayed
= make_number (col
);
18363 pint2str (decode_mode_spec_buf
, field_width
, col
);
18364 return decode_mode_spec_buf
;
18368 #ifndef SYSTEM_MALLOC
18370 if (NILP (Vmemory_full
))
18373 return "!MEM FULL! ";
18380 /* %F displays the frame name. */
18381 if (!NILP (f
->title
))
18382 return (char *) SDATA (f
->title
);
18383 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18384 return (char *) SDATA (f
->name
);
18393 int size
= ZV
- BEGV
;
18394 pint2str (decode_mode_spec_buf
, field_width
, size
);
18395 return decode_mode_spec_buf
;
18400 int size
= ZV
- BEGV
;
18401 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18402 return decode_mode_spec_buf
;
18407 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18408 int topline
, nlines
, junk
, height
;
18410 /* %c and %l are ignored in `frame-title-format'. */
18411 if (mode_line_target
== MODE_LINE_TITLE
)
18414 startpos
= XMARKER (w
->start
)->charpos
;
18415 startpos_byte
= marker_byte_position (w
->start
);
18416 height
= WINDOW_TOTAL_LINES (w
);
18418 /* If we decided that this buffer isn't suitable for line numbers,
18419 don't forget that too fast. */
18420 if (EQ (w
->base_line_pos
, w
->buffer
))
18422 /* But do forget it, if the window shows a different buffer now. */
18423 else if (BUFFERP (w
->base_line_pos
))
18424 w
->base_line_pos
= Qnil
;
18426 /* If the buffer is very big, don't waste time. */
18427 if (INTEGERP (Vline_number_display_limit
)
18428 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18430 w
->base_line_pos
= Qnil
;
18431 w
->base_line_number
= Qnil
;
18435 if (INTEGERP (w
->base_line_number
)
18436 && INTEGERP (w
->base_line_pos
)
18437 && XFASTINT (w
->base_line_pos
) <= startpos
)
18439 line
= XFASTINT (w
->base_line_number
);
18440 linepos
= XFASTINT (w
->base_line_pos
);
18441 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18446 linepos
= BUF_BEGV (b
);
18447 linepos_byte
= BUF_BEGV_BYTE (b
);
18450 /* Count lines from base line to window start position. */
18451 nlines
= display_count_lines (linepos
, linepos_byte
,
18455 topline
= nlines
+ line
;
18457 /* Determine a new base line, if the old one is too close
18458 or too far away, or if we did not have one.
18459 "Too close" means it's plausible a scroll-down would
18460 go back past it. */
18461 if (startpos
== BUF_BEGV (b
))
18463 w
->base_line_number
= make_number (topline
);
18464 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18466 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18467 || linepos
== BUF_BEGV (b
))
18469 int limit
= BUF_BEGV (b
);
18470 int limit_byte
= BUF_BEGV_BYTE (b
);
18472 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18474 if (startpos
- distance
> limit
)
18476 limit
= startpos
- distance
;
18477 limit_byte
= CHAR_TO_BYTE (limit
);
18480 nlines
= display_count_lines (startpos
, startpos_byte
,
18482 - (height
* 2 + 30),
18484 /* If we couldn't find the lines we wanted within
18485 line_number_display_limit_width chars per line,
18486 give up on line numbers for this window. */
18487 if (position
== limit_byte
&& limit
== startpos
- distance
)
18489 w
->base_line_pos
= w
->buffer
;
18490 w
->base_line_number
= Qnil
;
18494 w
->base_line_number
= make_number (topline
- nlines
);
18495 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18498 /* Now count lines from the start pos to point. */
18499 nlines
= display_count_lines (startpos
, startpos_byte
,
18500 PT_BYTE
, PT
, &junk
);
18502 /* Record that we did display the line number. */
18503 line_number_displayed
= 1;
18505 /* Make the string to show. */
18506 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18507 return decode_mode_spec_buf
;
18510 char* p
= decode_mode_spec_buf
;
18511 int pad
= field_width
- 2;
18517 return decode_mode_spec_buf
;
18523 obj
= b
->mode_name
;
18527 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18533 int pos
= marker_position (w
->start
);
18534 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18536 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18538 if (pos
<= BUF_BEGV (b
))
18543 else if (pos
<= BUF_BEGV (b
))
18547 if (total
> 1000000)
18548 /* Do it differently for a large value, to avoid overflow. */
18549 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18551 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18552 /* We can't normally display a 3-digit number,
18553 so get us a 2-digit number that is close. */
18556 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18557 return decode_mode_spec_buf
;
18561 /* Display percentage of size above the bottom of the screen. */
18564 int toppos
= marker_position (w
->start
);
18565 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18566 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18568 if (botpos
>= BUF_ZV (b
))
18570 if (toppos
<= BUF_BEGV (b
))
18577 if (total
> 1000000)
18578 /* Do it differently for a large value, to avoid overflow. */
18579 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18581 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18582 /* We can't normally display a 3-digit number,
18583 so get us a 2-digit number that is close. */
18586 if (toppos
<= BUF_BEGV (b
))
18587 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18589 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18590 return decode_mode_spec_buf
;
18595 /* status of process */
18596 obj
= Fget_buffer_process (Fcurrent_buffer ());
18598 return "no process";
18599 #ifdef subprocesses
18600 obj
= Fsymbol_name (Fprocess_status (obj
));
18607 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18614 case 't': /* indicate TEXT or BINARY */
18615 #ifdef MODE_LINE_BINARY_TEXT
18616 return MODE_LINE_BINARY_TEXT (b
);
18622 /* coding-system (not including end-of-line format) */
18624 /* coding-system (including end-of-line type) */
18626 int eol_flag
= (c
== 'Z');
18627 char *p
= decode_mode_spec_buf
;
18629 if (! FRAME_WINDOW_P (f
))
18631 /* No need to mention EOL here--the terminal never needs
18632 to do EOL conversion. */
18633 p
= decode_mode_spec_coding (CODING_ID_NAME
18634 (FRAME_KEYBOARD_CODING (f
)->id
),
18636 p
= decode_mode_spec_coding (CODING_ID_NAME
18637 (FRAME_TERMINAL_CODING (f
)->id
),
18640 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18643 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18644 #ifdef subprocesses
18645 obj
= Fget_buffer_process (Fcurrent_buffer ());
18646 if (PROCESSP (obj
))
18648 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18650 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18653 #endif /* subprocesses */
18656 return decode_mode_spec_buf
;
18662 *multibyte
= STRING_MULTIBYTE (obj
);
18663 return (char *) SDATA (obj
);
18670 /* Count up to COUNT lines starting from START / START_BYTE.
18671 But don't go beyond LIMIT_BYTE.
18672 Return the number of lines thus found (always nonnegative).
18674 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18677 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18678 int start
, start_byte
, limit_byte
, count
;
18681 register unsigned char *cursor
;
18682 unsigned char *base
;
18684 register int ceiling
;
18685 register unsigned char *ceiling_addr
;
18686 int orig_count
= count
;
18688 /* If we are not in selective display mode,
18689 check only for newlines. */
18690 int selective_display
= (!NILP (current_buffer
->selective_display
)
18691 && !INTEGERP (current_buffer
->selective_display
));
18695 while (start_byte
< limit_byte
)
18697 ceiling
= BUFFER_CEILING_OF (start_byte
);
18698 ceiling
= min (limit_byte
- 1, ceiling
);
18699 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18700 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18703 if (selective_display
)
18704 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18707 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18710 if (cursor
!= ceiling_addr
)
18714 start_byte
+= cursor
- base
+ 1;
18715 *byte_pos_ptr
= start_byte
;
18719 if (++cursor
== ceiling_addr
)
18725 start_byte
+= cursor
- base
;
18730 while (start_byte
> limit_byte
)
18732 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18733 ceiling
= max (limit_byte
, ceiling
);
18734 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18735 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18738 if (selective_display
)
18739 while (--cursor
!= ceiling_addr
18740 && *cursor
!= '\n' && *cursor
!= 015)
18743 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18746 if (cursor
!= ceiling_addr
)
18750 start_byte
+= cursor
- base
+ 1;
18751 *byte_pos_ptr
= start_byte
;
18752 /* When scanning backwards, we should
18753 not count the newline posterior to which we stop. */
18754 return - orig_count
- 1;
18760 /* Here we add 1 to compensate for the last decrement
18761 of CURSOR, which took it past the valid range. */
18762 start_byte
+= cursor
- base
+ 1;
18766 *byte_pos_ptr
= limit_byte
;
18769 return - orig_count
+ count
;
18770 return orig_count
- count
;
18776 /***********************************************************************
18778 ***********************************************************************/
18780 /* Display a NUL-terminated string, starting with index START.
18782 If STRING is non-null, display that C string. Otherwise, the Lisp
18783 string LISP_STRING is displayed.
18785 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18786 FACE_STRING. Display STRING or LISP_STRING with the face at
18787 FACE_STRING_POS in FACE_STRING:
18789 Display the string in the environment given by IT, but use the
18790 standard display table, temporarily.
18792 FIELD_WIDTH is the minimum number of output glyphs to produce.
18793 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18794 with spaces. If STRING has more characters, more than FIELD_WIDTH
18795 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18797 PRECISION is the maximum number of characters to output from
18798 STRING. PRECISION < 0 means don't truncate the string.
18800 This is roughly equivalent to printf format specifiers:
18802 FIELD_WIDTH PRECISION PRINTF
18803 ----------------------------------------
18809 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18810 display them, and < 0 means obey the current buffer's value of
18811 enable_multibyte_characters.
18813 Value is the number of columns displayed. */
18816 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18817 start
, it
, field_width
, precision
, max_x
, multibyte
)
18818 unsigned char *string
;
18819 Lisp_Object lisp_string
;
18820 Lisp_Object face_string
;
18821 EMACS_INT face_string_pos
;
18824 int field_width
, precision
, max_x
;
18827 int hpos_at_start
= it
->hpos
;
18828 int saved_face_id
= it
->face_id
;
18829 struct glyph_row
*row
= it
->glyph_row
;
18831 /* Initialize the iterator IT for iteration over STRING beginning
18832 with index START. */
18833 reseat_to_string (it
, string
, lisp_string
, start
,
18834 precision
, field_width
, multibyte
);
18836 /* If displaying STRING, set up the face of the iterator
18837 from LISP_STRING, if that's given. */
18838 if (STRINGP (face_string
))
18844 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18845 0, it
->region_beg_charpos
,
18846 it
->region_end_charpos
,
18847 &endptr
, it
->base_face_id
, 0);
18848 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18849 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18852 /* Set max_x to the maximum allowed X position. Don't let it go
18853 beyond the right edge of the window. */
18855 max_x
= it
->last_visible_x
;
18857 max_x
= min (max_x
, it
->last_visible_x
);
18859 /* Skip over display elements that are not visible. because IT->w is
18861 if (it
->current_x
< it
->first_visible_x
)
18862 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18863 MOVE_TO_POS
| MOVE_TO_X
);
18865 row
->ascent
= it
->max_ascent
;
18866 row
->height
= it
->max_ascent
+ it
->max_descent
;
18867 row
->phys_ascent
= it
->max_phys_ascent
;
18868 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18869 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18871 /* This condition is for the case that we are called with current_x
18872 past last_visible_x. */
18873 while (it
->current_x
< max_x
)
18875 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18877 /* Get the next display element. */
18878 if (!get_next_display_element (it
))
18881 /* Produce glyphs. */
18882 x_before
= it
->current_x
;
18883 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18884 PRODUCE_GLYPHS (it
);
18886 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18889 while (i
< nglyphs
)
18891 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18893 if (it
->line_wrap
!= TRUNCATE
18894 && x
+ glyph
->pixel_width
> max_x
)
18896 /* End of continued line or max_x reached. */
18897 if (CHAR_GLYPH_PADDING_P (*glyph
))
18899 /* A wide character is unbreakable. */
18900 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18901 it
->current_x
= x_before
;
18905 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18910 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18912 /* Glyph is at least partially visible. */
18914 if (x
< it
->first_visible_x
)
18915 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18919 /* Glyph is off the left margin of the display area.
18920 Should not happen. */
18924 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18925 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18926 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18927 row
->phys_height
= max (row
->phys_height
,
18928 it
->max_phys_ascent
+ it
->max_phys_descent
);
18929 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18930 it
->max_extra_line_spacing
);
18931 x
+= glyph
->pixel_width
;
18935 /* Stop if max_x reached. */
18939 /* Stop at line ends. */
18940 if (ITERATOR_AT_END_OF_LINE_P (it
))
18942 it
->continuation_lines_width
= 0;
18946 set_iterator_to_next (it
, 1);
18948 /* Stop if truncating at the right edge. */
18949 if (it
->line_wrap
== TRUNCATE
18950 && it
->current_x
>= it
->last_visible_x
)
18952 /* Add truncation mark, but don't do it if the line is
18953 truncated at a padding space. */
18954 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18956 if (!FRAME_WINDOW_P (it
->f
))
18960 if (it
->current_x
> it
->last_visible_x
)
18962 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18963 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18965 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18967 row
->used
[TEXT_AREA
] = i
;
18968 produce_special_glyphs (it
, IT_TRUNCATION
);
18971 produce_special_glyphs (it
, IT_TRUNCATION
);
18973 it
->glyph_row
->truncated_on_right_p
= 1;
18979 /* Maybe insert a truncation at the left. */
18980 if (it
->first_visible_x
18981 && IT_CHARPOS (*it
) > 0)
18983 if (!FRAME_WINDOW_P (it
->f
))
18984 insert_left_trunc_glyphs (it
);
18985 it
->glyph_row
->truncated_on_left_p
= 1;
18988 it
->face_id
= saved_face_id
;
18990 /* Value is number of columns displayed. */
18991 return it
->hpos
- hpos_at_start
;
18996 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18997 appears as an element of LIST or as the car of an element of LIST.
18998 If PROPVAL is a list, compare each element against LIST in that
18999 way, and return 1/2 if any element of PROPVAL is found in LIST.
19000 Otherwise return 0. This function cannot quit.
19001 The return value is 2 if the text is invisible but with an ellipsis
19002 and 1 if it's invisible and without an ellipsis. */
19005 invisible_p (propval
, list
)
19006 register Lisp_Object propval
;
19009 register Lisp_Object tail
, proptail
;
19011 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19013 register Lisp_Object tem
;
19015 if (EQ (propval
, tem
))
19017 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19018 return NILP (XCDR (tem
)) ? 1 : 2;
19021 if (CONSP (propval
))
19023 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19025 Lisp_Object propelt
;
19026 propelt
= XCAR (proptail
);
19027 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19029 register Lisp_Object tem
;
19031 if (EQ (propelt
, tem
))
19033 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19034 return NILP (XCDR (tem
)) ? 1 : 2;
19042 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19043 doc
: /* Non-nil if the property makes the text invisible.
19044 POS-OR-PROP can be a marker or number, in which case it is taken to be
19045 a position in the current buffer and the value of the `invisible' property
19046 is checked; or it can be some other value, which is then presumed to be the
19047 value of the `invisible' property of the text of interest.
19048 The non-nil value returned can be t for truly invisible text or something
19049 else if the text is replaced by an ellipsis. */)
19051 Lisp_Object pos_or_prop
;
19054 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19055 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19057 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19058 return (invis
== 0 ? Qnil
19060 : make_number (invis
));
19063 /* Calculate a width or height in pixels from a specification using
19064 the following elements:
19067 NUM - a (fractional) multiple of the default font width/height
19068 (NUM) - specifies exactly NUM pixels
19069 UNIT - a fixed number of pixels, see below.
19070 ELEMENT - size of a display element in pixels, see below.
19071 (NUM . SPEC) - equals NUM * SPEC
19072 (+ SPEC SPEC ...) - add pixel values
19073 (- SPEC SPEC ...) - subtract pixel values
19074 (- SPEC) - negate pixel value
19077 INT or FLOAT - a number constant
19078 SYMBOL - use symbol's (buffer local) variable binding.
19081 in - pixels per inch *)
19082 mm - pixels per 1/1000 meter *)
19083 cm - pixels per 1/100 meter *)
19084 width - width of current font in pixels.
19085 height - height of current font in pixels.
19087 *) using the ratio(s) defined in display-pixels-per-inch.
19091 left-fringe - left fringe width in pixels
19092 right-fringe - right fringe width in pixels
19094 left-margin - left margin width in pixels
19095 right-margin - right margin width in pixels
19097 scroll-bar - scroll-bar area width in pixels
19101 Pixels corresponding to 5 inches:
19104 Total width of non-text areas on left side of window (if scroll-bar is on left):
19105 '(space :width (+ left-fringe left-margin scroll-bar))
19107 Align to first text column (in header line):
19108 '(space :align-to 0)
19110 Align to middle of text area minus half the width of variable `my-image'
19111 containing a loaded image:
19112 '(space :align-to (0.5 . (- text my-image)))
19114 Width of left margin minus width of 1 character in the default font:
19115 '(space :width (- left-margin 1))
19117 Width of left margin minus width of 2 characters in the current font:
19118 '(space :width (- left-margin (2 . width)))
19120 Center 1 character over left-margin (in header line):
19121 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19123 Different ways to express width of left fringe plus left margin minus one pixel:
19124 '(space :width (- (+ left-fringe left-margin) (1)))
19125 '(space :width (+ left-fringe left-margin (- (1))))
19126 '(space :width (+ left-fringe left-margin (-1)))
19130 #define NUMVAL(X) \
19131 ((INTEGERP (X) || FLOATP (X)) \
19136 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19141 int width_p
, *align_to
;
19145 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19146 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19149 return OK_PIXELS (0);
19151 xassert (FRAME_LIVE_P (it
->f
));
19153 if (SYMBOLP (prop
))
19155 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19157 char *unit
= SDATA (SYMBOL_NAME (prop
));
19159 if (unit
[0] == 'i' && unit
[1] == 'n')
19161 else if (unit
[0] == 'm' && unit
[1] == 'm')
19163 else if (unit
[0] == 'c' && unit
[1] == 'm')
19170 #ifdef HAVE_WINDOW_SYSTEM
19171 if (FRAME_WINDOW_P (it
->f
)
19173 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19174 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19176 return OK_PIXELS (ppi
/ pixels
);
19179 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19180 || (CONSP (Vdisplay_pixels_per_inch
)
19182 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19183 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19185 return OK_PIXELS (ppi
/ pixels
);
19191 #ifdef HAVE_WINDOW_SYSTEM
19192 if (EQ (prop
, Qheight
))
19193 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19194 if (EQ (prop
, Qwidth
))
19195 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19197 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19198 return OK_PIXELS (1);
19201 if (EQ (prop
, Qtext
))
19202 return OK_PIXELS (width_p
19203 ? window_box_width (it
->w
, TEXT_AREA
)
19204 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19206 if (align_to
&& *align_to
< 0)
19209 if (EQ (prop
, Qleft
))
19210 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19211 if (EQ (prop
, Qright
))
19212 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19213 if (EQ (prop
, Qcenter
))
19214 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19215 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19216 if (EQ (prop
, Qleft_fringe
))
19217 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19218 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19219 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19220 if (EQ (prop
, Qright_fringe
))
19221 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19222 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19223 : window_box_right_offset (it
->w
, TEXT_AREA
));
19224 if (EQ (prop
, Qleft_margin
))
19225 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19226 if (EQ (prop
, Qright_margin
))
19227 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19228 if (EQ (prop
, Qscroll_bar
))
19229 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19231 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19232 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19233 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19238 if (EQ (prop
, Qleft_fringe
))
19239 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19240 if (EQ (prop
, Qright_fringe
))
19241 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19242 if (EQ (prop
, Qleft_margin
))
19243 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19244 if (EQ (prop
, Qright_margin
))
19245 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19246 if (EQ (prop
, Qscroll_bar
))
19247 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19250 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19253 if (INTEGERP (prop
) || FLOATP (prop
))
19255 int base_unit
= (width_p
19256 ? FRAME_COLUMN_WIDTH (it
->f
)
19257 : FRAME_LINE_HEIGHT (it
->f
));
19258 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19263 Lisp_Object car
= XCAR (prop
);
19264 Lisp_Object cdr
= XCDR (prop
);
19268 #ifdef HAVE_WINDOW_SYSTEM
19269 if (FRAME_WINDOW_P (it
->f
)
19270 && valid_image_p (prop
))
19272 int id
= lookup_image (it
->f
, prop
);
19273 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19275 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19278 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19284 while (CONSP (cdr
))
19286 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19287 font
, width_p
, align_to
))
19290 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19295 if (EQ (car
, Qminus
))
19297 return OK_PIXELS (pixels
);
19300 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19303 if (INTEGERP (car
) || FLOATP (car
))
19306 pixels
= XFLOATINT (car
);
19308 return OK_PIXELS (pixels
);
19309 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19310 font
, width_p
, align_to
))
19311 return OK_PIXELS (pixels
* fact
);
19322 /***********************************************************************
19324 ***********************************************************************/
19326 #ifdef HAVE_WINDOW_SYSTEM
19331 dump_glyph_string (s
)
19332 struct glyph_string
*s
;
19334 fprintf (stderr
, "glyph string\n");
19335 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19336 s
->x
, s
->y
, s
->width
, s
->height
);
19337 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19338 fprintf (stderr
, " hl = %d\n", s
->hl
);
19339 fprintf (stderr
, " left overhang = %d, right = %d\n",
19340 s
->left_overhang
, s
->right_overhang
);
19341 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19342 fprintf (stderr
, " extends to end of line = %d\n",
19343 s
->extends_to_end_of_line_p
);
19344 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19345 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19348 #endif /* GLYPH_DEBUG */
19350 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19351 of XChar2b structures for S; it can't be allocated in
19352 init_glyph_string because it must be allocated via `alloca'. W
19353 is the window on which S is drawn. ROW and AREA are the glyph row
19354 and area within the row from which S is constructed. START is the
19355 index of the first glyph structure covered by S. HL is a
19356 face-override for drawing S. */
19359 #define OPTIONAL_HDC(hdc) hdc,
19360 #define DECLARE_HDC(hdc) HDC hdc;
19361 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19362 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19365 #ifndef OPTIONAL_HDC
19366 #define OPTIONAL_HDC(hdc)
19367 #define DECLARE_HDC(hdc)
19368 #define ALLOCATE_HDC(hdc, f)
19369 #define RELEASE_HDC(hdc, f)
19373 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19374 struct glyph_string
*s
;
19378 struct glyph_row
*row
;
19379 enum glyph_row_area area
;
19381 enum draw_glyphs_face hl
;
19383 bzero (s
, sizeof *s
);
19385 s
->f
= XFRAME (w
->frame
);
19389 s
->display
= FRAME_X_DISPLAY (s
->f
);
19390 s
->window
= FRAME_X_WINDOW (s
->f
);
19391 s
->char2b
= char2b
;
19395 s
->first_glyph
= row
->glyphs
[area
] + start
;
19396 s
->height
= row
->height
;
19397 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19399 /* Display the internal border below the tool-bar window. */
19400 if (WINDOWP (s
->f
->tool_bar_window
)
19401 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19402 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19404 s
->ybase
= s
->y
+ row
->ascent
;
19408 /* Append the list of glyph strings with head H and tail T to the list
19409 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19412 append_glyph_string_lists (head
, tail
, h
, t
)
19413 struct glyph_string
**head
, **tail
;
19414 struct glyph_string
*h
, *t
;
19428 /* Prepend the list of glyph strings with head H and tail T to the
19429 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19433 prepend_glyph_string_lists (head
, tail
, h
, t
)
19434 struct glyph_string
**head
, **tail
;
19435 struct glyph_string
*h
, *t
;
19449 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19450 Set *HEAD and *TAIL to the resulting list. */
19453 append_glyph_string (head
, tail
, s
)
19454 struct glyph_string
**head
, **tail
;
19455 struct glyph_string
*s
;
19457 s
->next
= s
->prev
= NULL
;
19458 append_glyph_string_lists (head
, tail
, s
, s
);
19462 /* Get face and two-byte form of character C in face FACE_ID on frame
19463 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19464 means we want to display multibyte text. DISPLAY_P non-zero means
19465 make sure that X resources for the face returned are allocated.
19466 Value is a pointer to a realized face that is ready for display if
19467 DISPLAY_P is non-zero. */
19469 static INLINE
struct face
*
19470 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19474 int multibyte_p
, display_p
;
19476 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19480 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19482 if (code
!= FONT_INVALID_CODE
)
19483 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19485 STORE_XCHAR2B (char2b
, 0, 0);
19488 /* Make sure X resources of the face are allocated. */
19489 #ifdef HAVE_X_WINDOWS
19493 xassert (face
!= NULL
);
19494 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19501 /* Get face and two-byte form of character glyph GLYPH on frame F.
19502 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19503 a pointer to a realized face that is ready for display. */
19505 static INLINE
struct face
*
19506 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19508 struct glyph
*glyph
;
19514 xassert (glyph
->type
== CHAR_GLYPH
);
19515 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19522 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19524 if (code
!= FONT_INVALID_CODE
)
19525 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19527 STORE_XCHAR2B (char2b
, 0, 0);
19530 /* Make sure X resources of the face are allocated. */
19531 xassert (face
!= NULL
);
19532 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19537 /* Fill glyph string S with composition components specified by S->cmp.
19539 BASE_FACE is the base face of the composition.
19540 S->cmp_from is the index of the first component for S.
19542 OVERLAPS non-zero means S should draw the foreground only, and use
19543 its physical height for clipping. See also draw_glyphs.
19545 Value is the index of a component not in S. */
19548 fill_composite_glyph_string (s
, base_face
, overlaps
)
19549 struct glyph_string
*s
;
19550 struct face
*base_face
;
19554 /* For all glyphs of this composition, starting at the offset
19555 S->cmp_from, until we reach the end of the definition or encounter a
19556 glyph that requires the different face, add it to S. */
19561 s
->for_overlaps
= overlaps
;
19564 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
19566 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19570 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19573 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19574 s
->char2b
+ i
, 1, 1);
19580 s
->font
= s
->face
->font
;
19582 else if (s
->face
!= face
)
19590 /* All glyph strings for the same composition has the same width,
19591 i.e. the width set for the first component of the composition. */
19592 s
->width
= s
->first_glyph
->pixel_width
;
19594 /* If the specified font could not be loaded, use the frame's
19595 default font, but record the fact that we couldn't load it in
19596 the glyph string so that we can draw rectangles for the
19597 characters of the glyph string. */
19598 if (s
->font
== NULL
)
19600 s
->font_not_found_p
= 1;
19601 s
->font
= FRAME_FONT (s
->f
);
19604 /* Adjust base line for subscript/superscript text. */
19605 s
->ybase
+= s
->first_glyph
->voffset
;
19607 /* This glyph string must always be drawn with 16-bit functions. */
19614 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
19615 struct glyph_string
*s
;
19617 int start
, end
, overlaps
;
19619 struct glyph
*glyph
, *last
;
19620 Lisp_Object lgstring
;
19623 s
->for_overlaps
= overlaps
;
19624 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19625 last
= s
->row
->glyphs
[s
->area
] + end
;
19626 s
->cmp_id
= glyph
->u
.cmp
.id
;
19627 s
->cmp_from
= glyph
->u
.cmp
.from
;
19628 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
19629 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19630 lgstring
= composition_gstring_from_id (s
->cmp_id
);
19631 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
19633 while (glyph
< last
19634 && glyph
->u
.cmp
.automatic
19635 && glyph
->u
.cmp
.id
== s
->cmp_id
19636 && s
->cmp_to
== glyph
->u
.cmp
.from
)
19637 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
19639 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
19641 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
19642 unsigned code
= LGLYPH_CODE (lglyph
);
19644 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
19646 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
19647 return glyph
- s
->row
->glyphs
[s
->area
];
19651 /* Fill glyph string S from a sequence of character glyphs.
19653 FACE_ID is the face id of the string. START is the index of the
19654 first glyph to consider, END is the index of the last + 1.
19655 OVERLAPS non-zero means S should draw the foreground only, and use
19656 its physical height for clipping. See also draw_glyphs.
19658 Value is the index of the first glyph not in S. */
19661 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19662 struct glyph_string
*s
;
19664 int start
, end
, overlaps
;
19666 struct glyph
*glyph
, *last
;
19668 int glyph_not_available_p
;
19670 xassert (s
->f
== XFRAME (s
->w
->frame
));
19671 xassert (s
->nchars
== 0);
19672 xassert (start
>= 0 && end
> start
);
19674 s
->for_overlaps
= overlaps
;
19675 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19676 last
= s
->row
->glyphs
[s
->area
] + end
;
19677 voffset
= glyph
->voffset
;
19678 s
->padding_p
= glyph
->padding_p
;
19679 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19681 while (glyph
< last
19682 && glyph
->type
== CHAR_GLYPH
19683 && glyph
->voffset
== voffset
19684 /* Same face id implies same font, nowadays. */
19685 && glyph
->face_id
== face_id
19686 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19690 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19691 s
->char2b
+ s
->nchars
,
19693 s
->two_byte_p
= two_byte_p
;
19695 xassert (s
->nchars
<= end
- start
);
19696 s
->width
+= glyph
->pixel_width
;
19697 if (glyph
++->padding_p
!= s
->padding_p
)
19701 s
->font
= s
->face
->font
;
19703 /* If the specified font could not be loaded, use the frame's font,
19704 but record the fact that we couldn't load it in
19705 S->font_not_found_p so that we can draw rectangles for the
19706 characters of the glyph string. */
19707 if (s
->font
== NULL
|| glyph_not_available_p
)
19709 s
->font_not_found_p
= 1;
19710 s
->font
= FRAME_FONT (s
->f
);
19713 /* Adjust base line for subscript/superscript text. */
19714 s
->ybase
+= voffset
;
19716 xassert (s
->face
&& s
->face
->gc
);
19717 return glyph
- s
->row
->glyphs
[s
->area
];
19721 /* Fill glyph string S from image glyph S->first_glyph. */
19724 fill_image_glyph_string (s
)
19725 struct glyph_string
*s
;
19727 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19728 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19730 s
->slice
= s
->first_glyph
->slice
;
19731 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19732 s
->font
= s
->face
->font
;
19733 s
->width
= s
->first_glyph
->pixel_width
;
19735 /* Adjust base line for subscript/superscript text. */
19736 s
->ybase
+= s
->first_glyph
->voffset
;
19740 /* Fill glyph string S from a sequence of stretch glyphs.
19742 ROW is the glyph row in which the glyphs are found, AREA is the
19743 area within the row. START is the index of the first glyph to
19744 consider, END is the index of the last + 1.
19746 Value is the index of the first glyph not in S. */
19749 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19750 struct glyph_string
*s
;
19751 struct glyph_row
*row
;
19752 enum glyph_row_area area
;
19755 struct glyph
*glyph
, *last
;
19756 int voffset
, face_id
;
19758 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19760 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19761 last
= s
->row
->glyphs
[s
->area
] + end
;
19762 face_id
= glyph
->face_id
;
19763 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19764 s
->font
= s
->face
->font
;
19765 s
->width
= glyph
->pixel_width
;
19767 voffset
= glyph
->voffset
;
19771 && glyph
->type
== STRETCH_GLYPH
19772 && glyph
->voffset
== voffset
19773 && glyph
->face_id
== face_id
);
19775 s
->width
+= glyph
->pixel_width
;
19777 /* Adjust base line for subscript/superscript text. */
19778 s
->ybase
+= voffset
;
19780 /* The case that face->gc == 0 is handled when drawing the glyph
19781 string by calling PREPARE_FACE_FOR_DISPLAY. */
19783 return glyph
- s
->row
->glyphs
[s
->area
];
19786 static struct font_metrics
*
19787 get_per_char_metric (f
, font
, char2b
)
19792 static struct font_metrics metrics
;
19793 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19795 if (! font
|| code
== FONT_INVALID_CODE
)
19797 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19802 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19803 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19804 assumed to be zero. */
19807 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19808 struct glyph
*glyph
;
19812 *left
= *right
= 0;
19814 if (glyph
->type
== CHAR_GLYPH
)
19818 struct font_metrics
*pcm
;
19820 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19821 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19823 if (pcm
->rbearing
> pcm
->width
)
19824 *right
= pcm
->rbearing
- pcm
->width
;
19825 if (pcm
->lbearing
< 0)
19826 *left
= -pcm
->lbearing
;
19829 else if (glyph
->type
== COMPOSITE_GLYPH
)
19831 if (! glyph
->u
.cmp
.automatic
)
19833 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
19835 if (cmp
->rbearing
> cmp
->pixel_width
)
19836 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19837 if (cmp
->lbearing
< 0)
19838 *left
= - cmp
->lbearing
;
19842 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
19843 struct font_metrics metrics
;
19845 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
19846 glyph
->u
.cmp
.to
+ 1, &metrics
);
19847 if (metrics
.rbearing
> metrics
.width
)
19848 *right
= metrics
.rbearing
- metrics
.width
;
19849 if (metrics
.lbearing
< 0)
19850 *left
= - metrics
.lbearing
;
19856 /* Return the index of the first glyph preceding glyph string S that
19857 is overwritten by S because of S's left overhang. Value is -1
19858 if no glyphs are overwritten. */
19861 left_overwritten (s
)
19862 struct glyph_string
*s
;
19866 if (s
->left_overhang
)
19869 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19870 int first
= s
->first_glyph
- glyphs
;
19872 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19873 x
-= glyphs
[i
].pixel_width
;
19884 /* Return the index of the first glyph preceding glyph string S that
19885 is overwriting S because of its right overhang. Value is -1 if no
19886 glyph in front of S overwrites S. */
19889 left_overwriting (s
)
19890 struct glyph_string
*s
;
19893 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19894 int first
= s
->first_glyph
- glyphs
;
19898 for (i
= first
- 1; i
>= 0; --i
)
19901 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19904 x
-= glyphs
[i
].pixel_width
;
19911 /* Return the index of the last glyph following glyph string S that is
19912 overwritten by S because of S's right overhang. Value is -1 if
19913 no such glyph is found. */
19916 right_overwritten (s
)
19917 struct glyph_string
*s
;
19921 if (s
->right_overhang
)
19924 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19925 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19926 int end
= s
->row
->used
[s
->area
];
19928 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19929 x
+= glyphs
[i
].pixel_width
;
19938 /* Return the index of the last glyph following glyph string S that
19939 overwrites S because of its left overhang. Value is negative
19940 if no such glyph is found. */
19943 right_overwriting (s
)
19944 struct glyph_string
*s
;
19947 int end
= s
->row
->used
[s
->area
];
19948 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19949 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19953 for (i
= first
; i
< end
; ++i
)
19956 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19959 x
+= glyphs
[i
].pixel_width
;
19966 /* Set background width of glyph string S. START is the index of the
19967 first glyph following S. LAST_X is the right-most x-position + 1
19968 in the drawing area. */
19971 set_glyph_string_background_width (s
, start
, last_x
)
19972 struct glyph_string
*s
;
19976 /* If the face of this glyph string has to be drawn to the end of
19977 the drawing area, set S->extends_to_end_of_line_p. */
19979 if (start
== s
->row
->used
[s
->area
]
19980 && s
->area
== TEXT_AREA
19981 && ((s
->row
->fill_line_p
19982 && (s
->hl
== DRAW_NORMAL_TEXT
19983 || s
->hl
== DRAW_IMAGE_RAISED
19984 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19985 || s
->hl
== DRAW_MOUSE_FACE
))
19986 s
->extends_to_end_of_line_p
= 1;
19988 /* If S extends its face to the end of the line, set its
19989 background_width to the distance to the right edge of the drawing
19991 if (s
->extends_to_end_of_line_p
)
19992 s
->background_width
= last_x
- s
->x
+ 1;
19994 s
->background_width
= s
->width
;
19998 /* Compute overhangs and x-positions for glyph string S and its
19999 predecessors, or successors. X is the starting x-position for S.
20000 BACKWARD_P non-zero means process predecessors. */
20003 compute_overhangs_and_x (s
, x
, backward_p
)
20004 struct glyph_string
*s
;
20012 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20013 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20023 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20024 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20034 /* The following macros are only called from draw_glyphs below.
20035 They reference the following parameters of that function directly:
20036 `w', `row', `area', and `overlap_p'
20037 as well as the following local variables:
20038 `s', `f', and `hdc' (in W32) */
20041 /* On W32, silently add local `hdc' variable to argument list of
20042 init_glyph_string. */
20043 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20044 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20046 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20047 init_glyph_string (s, char2b, w, row, area, start, hl)
20050 /* Add a glyph string for a stretch glyph to the list of strings
20051 between HEAD and TAIL. START is the index of the stretch glyph in
20052 row area AREA of glyph row ROW. END is the index of the last glyph
20053 in that glyph row area. X is the current output position assigned
20054 to the new glyph string constructed. HL overrides that face of the
20055 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20056 is the right-most x-position of the drawing area. */
20058 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20059 and below -- keep them on one line. */
20060 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20063 s = (struct glyph_string *) alloca (sizeof *s); \
20064 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20065 START = fill_stretch_glyph_string (s, row, area, START, END); \
20066 append_glyph_string (&HEAD, &TAIL, s); \
20072 /* Add a glyph string for an image glyph to the list of strings
20073 between HEAD and TAIL. START is the index of the image glyph in
20074 row area AREA of glyph row ROW. END is the index of the last glyph
20075 in that glyph row area. X is the current output position assigned
20076 to the new glyph string constructed. HL overrides that face of the
20077 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20078 is the right-most x-position of the drawing area. */
20080 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20083 s = (struct glyph_string *) alloca (sizeof *s); \
20084 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20085 fill_image_glyph_string (s); \
20086 append_glyph_string (&HEAD, &TAIL, s); \
20093 /* Add a glyph string for a sequence of character glyphs to the list
20094 of strings between HEAD and TAIL. START is the index of the first
20095 glyph in row area AREA of glyph row ROW that is part of the new
20096 glyph string. END is the index of the last glyph in that glyph row
20097 area. X is the current output position assigned to the new glyph
20098 string constructed. HL overrides that face of the glyph; e.g. it
20099 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20100 right-most x-position of the drawing area. */
20102 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20108 face_id = (row)->glyphs[area][START].face_id; \
20110 s = (struct glyph_string *) alloca (sizeof *s); \
20111 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20112 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20113 append_glyph_string (&HEAD, &TAIL, s); \
20115 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20120 /* Add a glyph string for a composite sequence to the list of strings
20121 between HEAD and TAIL. START is the index of the first glyph in
20122 row area AREA of glyph row ROW that is part of the new glyph
20123 string. END is the index of the last glyph in that glyph row area.
20124 X is the current output position assigned to the new glyph string
20125 constructed. HL overrides that face of the glyph; e.g. it is
20126 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20127 x-position of the drawing area. */
20129 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20131 int face_id = (row)->glyphs[area][START].face_id; \
20132 struct face *base_face = FACE_FROM_ID (f, face_id); \
20133 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20134 struct composition *cmp = composition_table[cmp_id]; \
20136 struct glyph_string *first_s; \
20139 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20141 /* Make glyph_strings for each glyph sequence that is drawable by \
20142 the same face, and append them to HEAD/TAIL. */ \
20143 for (n = 0; n < cmp->glyph_len;) \
20145 s = (struct glyph_string *) alloca (sizeof *s); \
20146 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20147 append_glyph_string (&(HEAD), &(TAIL), s); \
20153 n = fill_composite_glyph_string (s, base_face, overlaps); \
20161 /* Add a glyph string for a glyph-string sequence to the list of strings
20162 between HEAD and TAIL. */
20164 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20168 Lisp_Object gstring; \
20170 face_id = (row)->glyphs[area][START].face_id; \
20171 gstring = (composition_gstring_from_id \
20172 ((row)->glyphs[area][START].u.cmp.id)); \
20173 s = (struct glyph_string *) alloca (sizeof *s); \
20174 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20175 * LGSTRING_GLYPH_LEN (gstring)); \
20176 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20177 append_glyph_string (&(HEAD), &(TAIL), s); \
20179 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20183 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20184 of AREA of glyph row ROW on window W between indices START and END.
20185 HL overrides the face for drawing glyph strings, e.g. it is
20186 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20187 x-positions of the drawing area.
20189 This is an ugly monster macro construct because we must use alloca
20190 to allocate glyph strings (because draw_glyphs can be called
20191 asynchronously). */
20193 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20196 HEAD = TAIL = NULL; \
20197 while (START < END) \
20199 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20200 switch (first_glyph->type) \
20203 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20207 case COMPOSITE_GLYPH: \
20208 if (first_glyph->u.cmp.automatic) \
20209 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20212 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20216 case STRETCH_GLYPH: \
20217 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20221 case IMAGE_GLYPH: \
20222 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20232 set_glyph_string_background_width (s, START, LAST_X); \
20239 /* Draw glyphs between START and END in AREA of ROW on window W,
20240 starting at x-position X. X is relative to AREA in W. HL is a
20241 face-override with the following meaning:
20243 DRAW_NORMAL_TEXT draw normally
20244 DRAW_CURSOR draw in cursor face
20245 DRAW_MOUSE_FACE draw in mouse face.
20246 DRAW_INVERSE_VIDEO draw in mode line face
20247 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20248 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20250 If OVERLAPS is non-zero, draw only the foreground of characters and
20251 clip to the physical height of ROW. Non-zero value also defines
20252 the overlapping part to be drawn:
20254 OVERLAPS_PRED overlap with preceding rows
20255 OVERLAPS_SUCC overlap with succeeding rows
20256 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20257 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20259 Value is the x-position reached, relative to AREA of W. */
20262 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20265 struct glyph_row
*row
;
20266 enum glyph_row_area area
;
20267 EMACS_INT start
, end
;
20268 enum draw_glyphs_face hl
;
20271 struct glyph_string
*head
, *tail
;
20272 struct glyph_string
*s
;
20273 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20274 int i
, j
, x_reached
, last_x
, area_left
= 0;
20275 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20278 ALLOCATE_HDC (hdc
, f
);
20280 /* Let's rather be paranoid than getting a SEGV. */
20281 end
= min (end
, row
->used
[area
]);
20282 start
= max (0, start
);
20283 start
= min (end
, start
);
20285 /* Translate X to frame coordinates. Set last_x to the right
20286 end of the drawing area. */
20287 if (row
->full_width_p
)
20289 /* X is relative to the left edge of W, without scroll bars
20291 area_left
= WINDOW_LEFT_EDGE_X (w
);
20292 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20296 area_left
= window_box_left (w
, area
);
20297 last_x
= area_left
+ window_box_width (w
, area
);
20301 /* Build a doubly-linked list of glyph_string structures between
20302 head and tail from what we have to draw. Note that the macro
20303 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20304 the reason we use a separate variable `i'. */
20306 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20308 x_reached
= tail
->x
+ tail
->background_width
;
20312 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20313 the row, redraw some glyphs in front or following the glyph
20314 strings built above. */
20315 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20317 struct glyph_string
*h
, *t
;
20318 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20319 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20322 /* If mouse highlighting is on, we may need to draw adjacent
20323 glyphs using mouse-face highlighting. */
20324 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20326 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20328 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20329 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20331 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20333 check_mouse_face
= 1;
20334 mouse_beg_col
= (row
== mouse_beg_row
)
20335 ? dpyinfo
->mouse_face_beg_col
: 0;
20336 mouse_end_col
= (row
== mouse_end_row
)
20337 ? dpyinfo
->mouse_face_end_col
20338 : row
->used
[TEXT_AREA
];
20342 /* Compute overhangs for all glyph strings. */
20343 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20344 for (s
= head
; s
; s
= s
->next
)
20345 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20347 /* Prepend glyph strings for glyphs in front of the first glyph
20348 string that are overwritten because of the first glyph
20349 string's left overhang. The background of all strings
20350 prepended must be drawn because the first glyph string
20352 i
= left_overwritten (head
);
20355 enum draw_glyphs_face overlap_hl
;
20357 /* If this row contains mouse highlighting, attempt to draw
20358 the overlapped glyphs with the correct highlight. This
20359 code fails if the overlap encompasses more than one glyph
20360 and mouse-highlight spans only some of these glyphs.
20361 However, making it work perfectly involves a lot more
20362 code, and I don't know if the pathological case occurs in
20363 practice, so we'll stick to this for now. --- cyd */
20364 if (check_mouse_face
20365 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20366 overlap_hl
= DRAW_MOUSE_FACE
;
20368 overlap_hl
= DRAW_NORMAL_TEXT
;
20371 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20372 overlap_hl
, dummy_x
, last_x
);
20373 compute_overhangs_and_x (t
, head
->x
, 1);
20374 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20378 /* Prepend glyph strings for glyphs in front of the first glyph
20379 string that overwrite that glyph string because of their
20380 right overhang. For these strings, only the foreground must
20381 be drawn, because it draws over the glyph string at `head'.
20382 The background must not be drawn because this would overwrite
20383 right overhangs of preceding glyphs for which no glyph
20385 i
= left_overwriting (head
);
20388 enum draw_glyphs_face overlap_hl
;
20390 if (check_mouse_face
20391 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20392 overlap_hl
= DRAW_MOUSE_FACE
;
20394 overlap_hl
= DRAW_NORMAL_TEXT
;
20397 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20398 overlap_hl
, dummy_x
, last_x
);
20399 for (s
= h
; s
; s
= s
->next
)
20400 s
->background_filled_p
= 1;
20401 compute_overhangs_and_x (t
, head
->x
, 1);
20402 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20405 /* Append glyphs strings for glyphs following the last glyph
20406 string tail that are overwritten by tail. The background of
20407 these strings has to be drawn because tail's foreground draws
20409 i
= right_overwritten (tail
);
20412 enum draw_glyphs_face overlap_hl
;
20414 if (check_mouse_face
20415 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20416 overlap_hl
= DRAW_MOUSE_FACE
;
20418 overlap_hl
= DRAW_NORMAL_TEXT
;
20420 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20421 overlap_hl
, x
, last_x
);
20422 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20423 append_glyph_string_lists (&head
, &tail
, h
, t
);
20427 /* Append glyph strings for glyphs following the last glyph
20428 string tail that overwrite tail. The foreground of such
20429 glyphs has to be drawn because it writes into the background
20430 of tail. The background must not be drawn because it could
20431 paint over the foreground of following glyphs. */
20432 i
= right_overwriting (tail
);
20435 enum draw_glyphs_face overlap_hl
;
20436 if (check_mouse_face
20437 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20438 overlap_hl
= DRAW_MOUSE_FACE
;
20440 overlap_hl
= DRAW_NORMAL_TEXT
;
20443 i
++; /* We must include the Ith glyph. */
20444 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20445 overlap_hl
, x
, last_x
);
20446 for (s
= h
; s
; s
= s
->next
)
20447 s
->background_filled_p
= 1;
20448 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20449 append_glyph_string_lists (&head
, &tail
, h
, t
);
20451 if (clip_head
|| clip_tail
)
20452 for (s
= head
; s
; s
= s
->next
)
20454 s
->clip_head
= clip_head
;
20455 s
->clip_tail
= clip_tail
;
20459 /* Draw all strings. */
20460 for (s
= head
; s
; s
= s
->next
)
20461 FRAME_RIF (f
)->draw_glyph_string (s
);
20464 /* When focus a sole frame and move horizontally, this sets on_p to 0
20465 causing a failure to erase prev cursor position. */
20466 if (area
== TEXT_AREA
20467 && !row
->full_width_p
20468 /* When drawing overlapping rows, only the glyph strings'
20469 foreground is drawn, which doesn't erase a cursor
20473 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20474 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20475 : (tail
? tail
->x
+ tail
->background_width
: x
));
20479 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20480 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20484 /* Value is the x-position up to which drawn, relative to AREA of W.
20485 This doesn't include parts drawn because of overhangs. */
20486 if (row
->full_width_p
)
20487 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20489 x_reached
-= area_left
;
20491 RELEASE_HDC (hdc
, f
);
20496 /* Expand row matrix if too narrow. Don't expand if area
20499 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20501 if (!fonts_changed_p \
20502 && (it->glyph_row->glyphs[area] \
20503 < it->glyph_row->glyphs[area + 1])) \
20505 it->w->ncols_scale_factor++; \
20506 fonts_changed_p = 1; \
20510 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20511 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20517 struct glyph
*glyph
;
20518 enum glyph_row_area area
= it
->area
;
20520 xassert (it
->glyph_row
);
20521 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20523 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20524 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20526 glyph
->charpos
= CHARPOS (it
->position
);
20527 glyph
->object
= it
->object
;
20528 if (it
->pixel_width
> 0)
20530 glyph
->pixel_width
= it
->pixel_width
;
20531 glyph
->padding_p
= 0;
20535 /* Assure at least 1-pixel width. Otherwise, cursor can't
20536 be displayed correctly. */
20537 glyph
->pixel_width
= 1;
20538 glyph
->padding_p
= 1;
20540 glyph
->ascent
= it
->ascent
;
20541 glyph
->descent
= it
->descent
;
20542 glyph
->voffset
= it
->voffset
;
20543 glyph
->type
= CHAR_GLYPH
;
20544 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20545 glyph
->multibyte_p
= it
->multibyte_p
;
20546 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20547 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20548 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20549 || it
->phys_descent
> it
->descent
);
20550 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20551 glyph
->face_id
= it
->face_id
;
20552 glyph
->u
.ch
= it
->char_to_display
;
20553 glyph
->slice
= null_glyph_slice
;
20554 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20555 ++it
->glyph_row
->used
[area
];
20558 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20561 /* Store one glyph for the composition IT->cmp_it.id in
20562 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
20566 append_composite_glyph (it
)
20569 struct glyph
*glyph
;
20570 enum glyph_row_area area
= it
->area
;
20572 xassert (it
->glyph_row
);
20574 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20575 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20577 glyph
->charpos
= CHARPOS (it
->position
);
20578 glyph
->object
= it
->object
;
20579 glyph
->pixel_width
= it
->pixel_width
;
20580 glyph
->ascent
= it
->ascent
;
20581 glyph
->descent
= it
->descent
;
20582 glyph
->voffset
= it
->voffset
;
20583 glyph
->type
= COMPOSITE_GLYPH
;
20584 if (it
->cmp_it
.ch
< 0)
20586 glyph
->u
.cmp
.automatic
= 0;
20587 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20591 glyph
->u
.cmp
.automatic
= 1;
20592 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20593 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
20594 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
20596 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20597 glyph
->multibyte_p
= it
->multibyte_p
;
20598 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20599 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20600 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20601 || it
->phys_descent
> it
->descent
);
20602 glyph
->padding_p
= 0;
20603 glyph
->glyph_not_available_p
= 0;
20604 glyph
->face_id
= it
->face_id
;
20605 glyph
->slice
= null_glyph_slice
;
20606 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20607 ++it
->glyph_row
->used
[area
];
20610 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20614 /* Change IT->ascent and IT->height according to the setting of
20618 take_vertical_position_into_account (it
)
20623 if (it
->voffset
< 0)
20624 /* Increase the ascent so that we can display the text higher
20626 it
->ascent
-= it
->voffset
;
20628 /* Increase the descent so that we can display the text lower
20630 it
->descent
+= it
->voffset
;
20635 /* Produce glyphs/get display metrics for the image IT is loaded with.
20636 See the description of struct display_iterator in dispextern.h for
20637 an overview of struct display_iterator. */
20640 produce_image_glyph (it
)
20645 int glyph_ascent
, crop
;
20646 struct glyph_slice slice
;
20648 xassert (it
->what
== IT_IMAGE
);
20650 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20652 /* Make sure X resources of the face is loaded. */
20653 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20655 if (it
->image_id
< 0)
20657 /* Fringe bitmap. */
20658 it
->ascent
= it
->phys_ascent
= 0;
20659 it
->descent
= it
->phys_descent
= 0;
20660 it
->pixel_width
= 0;
20665 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20667 /* Make sure X resources of the image is loaded. */
20668 prepare_image_for_display (it
->f
, img
);
20670 slice
.x
= slice
.y
= 0;
20671 slice
.width
= img
->width
;
20672 slice
.height
= img
->height
;
20674 if (INTEGERP (it
->slice
.x
))
20675 slice
.x
= XINT (it
->slice
.x
);
20676 else if (FLOATP (it
->slice
.x
))
20677 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20679 if (INTEGERP (it
->slice
.y
))
20680 slice
.y
= XINT (it
->slice
.y
);
20681 else if (FLOATP (it
->slice
.y
))
20682 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20684 if (INTEGERP (it
->slice
.width
))
20685 slice
.width
= XINT (it
->slice
.width
);
20686 else if (FLOATP (it
->slice
.width
))
20687 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20689 if (INTEGERP (it
->slice
.height
))
20690 slice
.height
= XINT (it
->slice
.height
);
20691 else if (FLOATP (it
->slice
.height
))
20692 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20694 if (slice
.x
>= img
->width
)
20695 slice
.x
= img
->width
;
20696 if (slice
.y
>= img
->height
)
20697 slice
.y
= img
->height
;
20698 if (slice
.x
+ slice
.width
>= img
->width
)
20699 slice
.width
= img
->width
- slice
.x
;
20700 if (slice
.y
+ slice
.height
> img
->height
)
20701 slice
.height
= img
->height
- slice
.y
;
20703 if (slice
.width
== 0 || slice
.height
== 0)
20706 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20708 it
->descent
= slice
.height
- glyph_ascent
;
20710 it
->descent
+= img
->vmargin
;
20711 if (slice
.y
+ slice
.height
== img
->height
)
20712 it
->descent
+= img
->vmargin
;
20713 it
->phys_descent
= it
->descent
;
20715 it
->pixel_width
= slice
.width
;
20717 it
->pixel_width
+= img
->hmargin
;
20718 if (slice
.x
+ slice
.width
== img
->width
)
20719 it
->pixel_width
+= img
->hmargin
;
20721 /* It's quite possible for images to have an ascent greater than
20722 their height, so don't get confused in that case. */
20723 if (it
->descent
< 0)
20728 if (face
->box
!= FACE_NO_BOX
)
20730 if (face
->box_line_width
> 0)
20733 it
->ascent
+= face
->box_line_width
;
20734 if (slice
.y
+ slice
.height
== img
->height
)
20735 it
->descent
+= face
->box_line_width
;
20738 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20739 it
->pixel_width
+= eabs (face
->box_line_width
);
20740 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20741 it
->pixel_width
+= eabs (face
->box_line_width
);
20744 take_vertical_position_into_account (it
);
20746 /* Automatically crop wide image glyphs at right edge so we can
20747 draw the cursor on same display row. */
20748 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20749 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20751 it
->pixel_width
-= crop
;
20752 slice
.width
-= crop
;
20757 struct glyph
*glyph
;
20758 enum glyph_row_area area
= it
->area
;
20760 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20761 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20763 glyph
->charpos
= CHARPOS (it
->position
);
20764 glyph
->object
= it
->object
;
20765 glyph
->pixel_width
= it
->pixel_width
;
20766 glyph
->ascent
= glyph_ascent
;
20767 glyph
->descent
= it
->descent
;
20768 glyph
->voffset
= it
->voffset
;
20769 glyph
->type
= IMAGE_GLYPH
;
20770 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20771 glyph
->multibyte_p
= it
->multibyte_p
;
20772 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20773 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20774 glyph
->overlaps_vertically_p
= 0;
20775 glyph
->padding_p
= 0;
20776 glyph
->glyph_not_available_p
= 0;
20777 glyph
->face_id
= it
->face_id
;
20778 glyph
->u
.img_id
= img
->id
;
20779 glyph
->slice
= slice
;
20780 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20781 ++it
->glyph_row
->used
[area
];
20784 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20789 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20790 of the glyph, WIDTH and HEIGHT are the width and height of the
20791 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20794 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20796 Lisp_Object object
;
20800 struct glyph
*glyph
;
20801 enum glyph_row_area area
= it
->area
;
20803 xassert (ascent
>= 0 && ascent
<= height
);
20805 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20806 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20808 glyph
->charpos
= CHARPOS (it
->position
);
20809 glyph
->object
= object
;
20810 glyph
->pixel_width
= width
;
20811 glyph
->ascent
= ascent
;
20812 glyph
->descent
= height
- ascent
;
20813 glyph
->voffset
= it
->voffset
;
20814 glyph
->type
= STRETCH_GLYPH
;
20815 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20816 glyph
->multibyte_p
= it
->multibyte_p
;
20817 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20818 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20819 glyph
->overlaps_vertically_p
= 0;
20820 glyph
->padding_p
= 0;
20821 glyph
->glyph_not_available_p
= 0;
20822 glyph
->face_id
= it
->face_id
;
20823 glyph
->u
.stretch
.ascent
= ascent
;
20824 glyph
->u
.stretch
.height
= height
;
20825 glyph
->slice
= null_glyph_slice
;
20826 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20827 ++it
->glyph_row
->used
[area
];
20830 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20834 /* Produce a stretch glyph for iterator IT. IT->object is the value
20835 of the glyph property displayed. The value must be a list
20836 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20839 1. `:width WIDTH' specifies that the space should be WIDTH *
20840 canonical char width wide. WIDTH may be an integer or floating
20843 2. `:relative-width FACTOR' specifies that the width of the stretch
20844 should be computed from the width of the first character having the
20845 `glyph' property, and should be FACTOR times that width.
20847 3. `:align-to HPOS' specifies that the space should be wide enough
20848 to reach HPOS, a value in canonical character units.
20850 Exactly one of the above pairs must be present.
20852 4. `:height HEIGHT' specifies that the height of the stretch produced
20853 should be HEIGHT, measured in canonical character units.
20855 5. `:relative-height FACTOR' specifies that the height of the
20856 stretch should be FACTOR times the height of the characters having
20857 the glyph property.
20859 Either none or exactly one of 4 or 5 must be present.
20861 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20862 of the stretch should be used for the ascent of the stretch.
20863 ASCENT must be in the range 0 <= ASCENT <= 100. */
20866 produce_stretch_glyph (it
)
20869 /* (space :width WIDTH :height HEIGHT ...) */
20870 Lisp_Object prop
, plist
;
20871 int width
= 0, height
= 0, align_to
= -1;
20872 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20875 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20876 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20878 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20880 /* List should start with `space'. */
20881 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20882 plist
= XCDR (it
->object
);
20884 /* Compute the width of the stretch. */
20885 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20886 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20888 /* Absolute width `:width WIDTH' specified and valid. */
20889 zero_width_ok_p
= 1;
20892 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20895 /* Relative width `:relative-width FACTOR' specified and valid.
20896 Compute the width of the characters having the `glyph'
20899 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20902 if (it
->multibyte_p
)
20904 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20905 - IT_BYTEPOS (*it
));
20906 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20909 it2
.c
= *p
, it2
.len
= 1;
20911 it2
.glyph_row
= NULL
;
20912 it2
.what
= IT_CHARACTER
;
20913 x_produce_glyphs (&it2
);
20914 width
= NUMVAL (prop
) * it2
.pixel_width
;
20916 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20917 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20919 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20920 align_to
= (align_to
< 0
20922 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20923 else if (align_to
< 0)
20924 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20925 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20926 zero_width_ok_p
= 1;
20929 /* Nothing specified -> width defaults to canonical char width. */
20930 width
= FRAME_COLUMN_WIDTH (it
->f
);
20932 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20935 /* Compute height. */
20936 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20937 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20940 zero_height_ok_p
= 1;
20942 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20944 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20946 height
= FONT_HEIGHT (font
);
20948 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20951 /* Compute percentage of height used for ascent. If
20952 `:ascent ASCENT' is present and valid, use that. Otherwise,
20953 derive the ascent from the font in use. */
20954 if (prop
= Fplist_get (plist
, QCascent
),
20955 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20956 ascent
= height
* NUMVAL (prop
) / 100.0;
20957 else if (!NILP (prop
)
20958 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20959 ascent
= min (max (0, (int)tem
), height
);
20961 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20963 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20964 && it
->current_x
+ width
> it
->last_visible_x
)
20965 width
= it
->last_visible_x
- it
->current_x
- 1;
20967 if (width
> 0 && height
> 0 && it
->glyph_row
)
20969 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20970 if (!STRINGP (object
))
20971 object
= it
->w
->buffer
;
20972 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20975 it
->pixel_width
= width
;
20976 it
->ascent
= it
->phys_ascent
= ascent
;
20977 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20978 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20980 take_vertical_position_into_account (it
);
20983 /* Calculate line-height and line-spacing properties.
20984 An integer value specifies explicit pixel value.
20985 A float value specifies relative value to current face height.
20986 A cons (float . face-name) specifies relative value to
20987 height of specified face font.
20989 Returns height in pixels, or nil. */
20993 calc_line_height_property (it
, val
, font
, boff
, override
)
20997 int boff
, override
;
20999 Lisp_Object face_name
= Qnil
;
21000 int ascent
, descent
, height
;
21002 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21007 face_name
= XCAR (val
);
21009 if (!NUMBERP (val
))
21010 val
= make_number (1);
21011 if (NILP (face_name
))
21013 height
= it
->ascent
+ it
->descent
;
21018 if (NILP (face_name
))
21020 font
= FRAME_FONT (it
->f
);
21021 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21023 else if (EQ (face_name
, Qt
))
21032 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21034 return make_number (-1);
21036 face
= FACE_FROM_ID (it
->f
, face_id
);
21039 return make_number (-1);
21040 boff
= font
->baseline_offset
;
21041 if (font
->vertical_centering
)
21042 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21045 ascent
= FONT_BASE (font
) + boff
;
21046 descent
= FONT_DESCENT (font
) - boff
;
21050 it
->override_ascent
= ascent
;
21051 it
->override_descent
= descent
;
21052 it
->override_boff
= boff
;
21055 height
= ascent
+ descent
;
21059 height
= (int)(XFLOAT_DATA (val
) * height
);
21060 else if (INTEGERP (val
))
21061 height
*= XINT (val
);
21063 return make_number (height
);
21068 Produce glyphs/get display metrics for the display element IT is
21069 loaded with. See the description of struct it in dispextern.h
21070 for an overview of struct it. */
21073 x_produce_glyphs (it
)
21076 int extra_line_spacing
= it
->extra_line_spacing
;
21078 it
->glyph_not_available_p
= 0;
21080 if (it
->what
== IT_CHARACTER
)
21084 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21085 struct font_metrics
*pcm
;
21086 int font_not_found_p
;
21087 int boff
; /* baseline offset */
21088 /* We may change it->multibyte_p upon unibyte<->multibyte
21089 conversion. So, save the current value now and restore it
21092 Note: It seems that we don't have to record multibyte_p in
21093 struct glyph because the character code itself tells if or
21094 not the character is multibyte. Thus, in the future, we must
21095 consider eliminating the field `multibyte_p' in the struct
21097 int saved_multibyte_p
= it
->multibyte_p
;
21099 /* Maybe translate single-byte characters to multibyte, or the
21101 it
->char_to_display
= it
->c
;
21102 if (!ASCII_BYTE_P (it
->c
)
21103 && ! it
->multibyte_p
)
21105 if (SINGLE_BYTE_CHAR_P (it
->c
)
21106 && unibyte_display_via_language_environment
)
21108 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21110 /* get_next_display_element assures that this decoding
21112 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21113 it
->multibyte_p
= 1;
21114 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21116 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21120 /* Get font to use. Encode IT->char_to_display. */
21121 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21122 &char2b
, it
->multibyte_p
, 0);
21125 /* When no suitable font found, use the default font. */
21126 font_not_found_p
= font
== NULL
;
21127 if (font_not_found_p
)
21129 font
= FRAME_FONT (it
->f
);
21130 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21134 boff
= font
->baseline_offset
;
21135 if (font
->vertical_centering
)
21136 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21139 if (it
->char_to_display
>= ' '
21140 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21142 /* Either unibyte or ASCII. */
21147 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21149 if (it
->override_ascent
>= 0)
21151 it
->ascent
= it
->override_ascent
;
21152 it
->descent
= it
->override_descent
;
21153 boff
= it
->override_boff
;
21157 it
->ascent
= FONT_BASE (font
) + boff
;
21158 it
->descent
= FONT_DESCENT (font
) - boff
;
21163 it
->phys_ascent
= pcm
->ascent
+ boff
;
21164 it
->phys_descent
= pcm
->descent
- boff
;
21165 it
->pixel_width
= pcm
->width
;
21169 it
->glyph_not_available_p
= 1;
21170 it
->phys_ascent
= it
->ascent
;
21171 it
->phys_descent
= it
->descent
;
21172 it
->pixel_width
= FONT_WIDTH (font
);
21175 if (it
->constrain_row_ascent_descent_p
)
21177 if (it
->descent
> it
->max_descent
)
21179 it
->ascent
+= it
->descent
- it
->max_descent
;
21180 it
->descent
= it
->max_descent
;
21182 if (it
->ascent
> it
->max_ascent
)
21184 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21185 it
->ascent
= it
->max_ascent
;
21187 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21188 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21189 extra_line_spacing
= 0;
21192 /* If this is a space inside a region of text with
21193 `space-width' property, change its width. */
21194 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21196 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21198 /* If face has a box, add the box thickness to the character
21199 height. If character has a box line to the left and/or
21200 right, add the box line width to the character's width. */
21201 if (face
->box
!= FACE_NO_BOX
)
21203 int thick
= face
->box_line_width
;
21207 it
->ascent
+= thick
;
21208 it
->descent
+= thick
;
21213 if (it
->start_of_box_run_p
)
21214 it
->pixel_width
+= thick
;
21215 if (it
->end_of_box_run_p
)
21216 it
->pixel_width
+= thick
;
21219 /* If face has an overline, add the height of the overline
21220 (1 pixel) and a 1 pixel margin to the character height. */
21221 if (face
->overline_p
)
21222 it
->ascent
+= overline_margin
;
21224 if (it
->constrain_row_ascent_descent_p
)
21226 if (it
->ascent
> it
->max_ascent
)
21227 it
->ascent
= it
->max_ascent
;
21228 if (it
->descent
> it
->max_descent
)
21229 it
->descent
= it
->max_descent
;
21232 take_vertical_position_into_account (it
);
21234 /* If we have to actually produce glyphs, do it. */
21239 /* Translate a space with a `space-width' property
21240 into a stretch glyph. */
21241 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21242 / FONT_HEIGHT (font
));
21243 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21244 it
->ascent
+ it
->descent
, ascent
);
21249 /* If characters with lbearing or rbearing are displayed
21250 in this line, record that fact in a flag of the
21251 glyph row. This is used to optimize X output code. */
21252 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21253 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21255 if (! stretched_p
&& it
->pixel_width
== 0)
21256 /* We assure that all visible glyphs have at least 1-pixel
21258 it
->pixel_width
= 1;
21260 else if (it
->char_to_display
== '\n')
21262 /* A newline has no width but we need the height of the line.
21263 But if previous part of the line set a height, don't
21264 increase that height */
21266 Lisp_Object height
;
21267 Lisp_Object total_height
= Qnil
;
21269 it
->override_ascent
= -1;
21270 it
->pixel_width
= 0;
21273 height
= get_it_property(it
, Qline_height
);
21274 /* Split (line-height total-height) list */
21276 && CONSP (XCDR (height
))
21277 && NILP (XCDR (XCDR (height
))))
21279 total_height
= XCAR (XCDR (height
));
21280 height
= XCAR (height
);
21282 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21284 if (it
->override_ascent
>= 0)
21286 it
->ascent
= it
->override_ascent
;
21287 it
->descent
= it
->override_descent
;
21288 boff
= it
->override_boff
;
21292 it
->ascent
= FONT_BASE (font
) + boff
;
21293 it
->descent
= FONT_DESCENT (font
) - boff
;
21296 if (EQ (height
, Qt
))
21298 if (it
->descent
> it
->max_descent
)
21300 it
->ascent
+= it
->descent
- it
->max_descent
;
21301 it
->descent
= it
->max_descent
;
21303 if (it
->ascent
> it
->max_ascent
)
21305 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21306 it
->ascent
= it
->max_ascent
;
21308 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21309 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21310 it
->constrain_row_ascent_descent_p
= 1;
21311 extra_line_spacing
= 0;
21315 Lisp_Object spacing
;
21317 it
->phys_ascent
= it
->ascent
;
21318 it
->phys_descent
= it
->descent
;
21320 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21321 && face
->box
!= FACE_NO_BOX
21322 && face
->box_line_width
> 0)
21324 it
->ascent
+= face
->box_line_width
;
21325 it
->descent
+= face
->box_line_width
;
21328 && XINT (height
) > it
->ascent
+ it
->descent
)
21329 it
->ascent
= XINT (height
) - it
->descent
;
21331 if (!NILP (total_height
))
21332 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21335 spacing
= get_it_property(it
, Qline_spacing
);
21336 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21338 if (INTEGERP (spacing
))
21340 extra_line_spacing
= XINT (spacing
);
21341 if (!NILP (total_height
))
21342 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21346 else if (it
->char_to_display
== '\t')
21348 if (font
->space_width
> 0)
21350 int tab_width
= it
->tab_width
* font
->space_width
;
21351 int x
= it
->current_x
+ it
->continuation_lines_width
;
21352 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21354 /* If the distance from the current position to the next tab
21355 stop is less than a space character width, use the
21356 tab stop after that. */
21357 if (next_tab_x
- x
< font
->space_width
)
21358 next_tab_x
+= tab_width
;
21360 it
->pixel_width
= next_tab_x
- x
;
21362 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21363 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21367 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21368 it
->ascent
+ it
->descent
, it
->ascent
);
21373 it
->pixel_width
= 0;
21379 /* A multi-byte character. Assume that the display width of the
21380 character is the width of the character multiplied by the
21381 width of the font. */
21383 /* If we found a font, this font should give us the right
21384 metrics. If we didn't find a font, use the frame's
21385 default font and calculate the width of the character by
21386 multiplying the width of font by the width of the
21389 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21391 if (font_not_found_p
|| !pcm
)
21393 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21395 if (char_width
== 0)
21396 /* This is a non spacing character. But, as we are
21397 going to display an empty box, the box must occupy
21398 at least one column. */
21400 it
->glyph_not_available_p
= 1;
21401 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
21402 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21403 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21407 it
->pixel_width
= pcm
->width
;
21408 it
->phys_ascent
= pcm
->ascent
+ boff
;
21409 it
->phys_descent
= pcm
->descent
- boff
;
21411 && (pcm
->lbearing
< 0
21412 || pcm
->rbearing
> pcm
->width
))
21413 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21416 it
->ascent
= FONT_BASE (font
) + boff
;
21417 it
->descent
= FONT_DESCENT (font
) - boff
;
21418 if (face
->box
!= FACE_NO_BOX
)
21420 int thick
= face
->box_line_width
;
21424 it
->ascent
+= thick
;
21425 it
->descent
+= thick
;
21430 if (it
->start_of_box_run_p
)
21431 it
->pixel_width
+= thick
;
21432 if (it
->end_of_box_run_p
)
21433 it
->pixel_width
+= thick
;
21436 /* If face has an overline, add the height of the overline
21437 (1 pixel) and a 1 pixel margin to the character height. */
21438 if (face
->overline_p
)
21439 it
->ascent
+= overline_margin
;
21441 take_vertical_position_into_account (it
);
21443 if (it
->ascent
< 0)
21445 if (it
->descent
< 0)
21450 if (it
->pixel_width
== 0)
21451 /* We assure that all visible glyphs have at least 1-pixel
21453 it
->pixel_width
= 1;
21455 it
->multibyte_p
= saved_multibyte_p
;
21457 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
21459 /* A static compositoin.
21461 Note: A composition is represented as one glyph in the
21462 glyph matrix. There are no padding glyphs.
21464 Important is that pixel_width, ascent, and descent are the
21465 values of what is drawn by draw_glyphs (i.e. the values of
21466 the overall glyphs composed). */
21467 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21468 int boff
; /* baseline offset */
21469 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
21470 int glyph_len
= cmp
->glyph_len
;
21471 struct font
*font
= face
->font
;
21475 /* If we have not yet calculated pixel size data of glyphs of
21476 the composition for the current face font, calculate them
21477 now. Theoretically, we have to check all fonts for the
21478 glyphs, but that requires much time and memory space. So,
21479 here we check only the font of the first glyph. This leads
21480 to incorrect display, but it's very rare, and C-l (recenter)
21481 can correct the display anyway. */
21482 if (! cmp
->font
|| cmp
->font
!= font
)
21484 /* Ascent and descent of the font of the first character
21485 of this composition (adjusted by baseline offset).
21486 Ascent and descent of overall glyphs should not be less
21487 than them respectively. */
21488 int font_ascent
, font_descent
, font_height
;
21489 /* Bounding box of the overall glyphs. */
21490 int leftmost
, rightmost
, lowest
, highest
;
21491 int lbearing
, rbearing
;
21492 int i
, width
, ascent
, descent
;
21493 int left_padded
= 0, right_padded
= 0;
21496 struct font_metrics
*pcm
;
21497 int font_not_found_p
;
21500 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21501 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21503 if (glyph_len
< cmp
->glyph_len
)
21505 for (i
= 0; i
< glyph_len
; i
++)
21507 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21509 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21514 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21515 : IT_CHARPOS (*it
));
21516 /* When no suitable font found, use the default font. */
21517 font_not_found_p
= font
== NULL
;
21518 if (font_not_found_p
)
21520 face
= face
->ascii_face
;
21523 boff
= font
->baseline_offset
;
21524 if (font
->vertical_centering
)
21525 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21526 font_ascent
= FONT_BASE (font
) + boff
;
21527 font_descent
= FONT_DESCENT (font
) - boff
;
21528 font_height
= FONT_HEIGHT (font
);
21530 cmp
->font
= (void *) font
;
21533 if (! font_not_found_p
)
21535 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21536 &char2b
, it
->multibyte_p
, 0);
21537 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21540 /* Initialize the bounding box. */
21543 width
= pcm
->width
;
21544 ascent
= pcm
->ascent
;
21545 descent
= pcm
->descent
;
21546 lbearing
= pcm
->lbearing
;
21547 rbearing
= pcm
->rbearing
;
21551 width
= FONT_WIDTH (font
);
21552 ascent
= FONT_BASE (font
);
21553 descent
= FONT_DESCENT (font
);
21560 lowest
= - descent
+ boff
;
21561 highest
= ascent
+ boff
;
21563 if (! font_not_found_p
21564 && font
->default_ascent
21565 && CHAR_TABLE_P (Vuse_default_ascent
)
21566 && !NILP (Faref (Vuse_default_ascent
,
21567 make_number (it
->char_to_display
))))
21568 highest
= font
->default_ascent
+ boff
;
21570 /* Draw the first glyph at the normal position. It may be
21571 shifted to right later if some other glyphs are drawn
21573 cmp
->offsets
[i
* 2] = 0;
21574 cmp
->offsets
[i
* 2 + 1] = boff
;
21575 cmp
->lbearing
= lbearing
;
21576 cmp
->rbearing
= rbearing
;
21578 /* Set cmp->offsets for the remaining glyphs. */
21579 for (i
++; i
< glyph_len
; i
++)
21581 int left
, right
, btm
, top
;
21582 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21584 struct face
*this_face
;
21589 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21590 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21591 font
= this_face
->font
;
21597 this_boff
= font
->baseline_offset
;
21598 if (font
->vertical_centering
)
21599 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21600 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21601 &char2b
, it
->multibyte_p
, 0);
21602 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21605 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21608 width
= pcm
->width
;
21609 ascent
= pcm
->ascent
;
21610 descent
= pcm
->descent
;
21611 lbearing
= pcm
->lbearing
;
21612 rbearing
= pcm
->rbearing
;
21613 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21615 /* Relative composition with or without
21616 alternate chars. */
21617 left
= (leftmost
+ rightmost
- width
) / 2;
21618 btm
= - descent
+ boff
;
21619 if (font
->relative_compose
21620 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21621 || NILP (Faref (Vignore_relative_composition
,
21622 make_number (ch
)))))
21625 if (- descent
>= font
->relative_compose
)
21626 /* One extra pixel between two glyphs. */
21628 else if (ascent
<= 0)
21629 /* One extra pixel between two glyphs. */
21630 btm
= lowest
- 1 - ascent
- descent
;
21635 /* A composition rule is specified by an integer
21636 value that encodes global and new reference
21637 points (GREF and NREF). GREF and NREF are
21638 specified by numbers as below:
21640 0---1---2 -- ascent
21644 9--10--11 -- center
21646 ---3---4---5--- baseline
21648 6---7---8 -- descent
21650 int rule
= COMPOSITION_RULE (cmp
, i
);
21651 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21653 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21654 grefx
= gref
% 3, nrefx
= nref
% 3;
21655 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21657 xoff
= font_height
* (xoff
- 128) / 256;
21659 yoff
= font_height
* (yoff
- 128) / 256;
21662 + grefx
* (rightmost
- leftmost
) / 2
21663 - nrefx
* width
/ 2
21666 btm
= ((grefy
== 0 ? highest
21668 : grefy
== 2 ? lowest
21669 : (highest
+ lowest
) / 2)
21670 - (nrefy
== 0 ? ascent
+ descent
21671 : nrefy
== 1 ? descent
- boff
21673 : (ascent
+ descent
) / 2)
21677 cmp
->offsets
[i
* 2] = left
;
21678 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21680 /* Update the bounding box of the overall glyphs. */
21683 right
= left
+ width
;
21684 if (left
< leftmost
)
21686 if (right
> rightmost
)
21689 top
= btm
+ descent
+ ascent
;
21695 if (cmp
->lbearing
> left
+ lbearing
)
21696 cmp
->lbearing
= left
+ lbearing
;
21697 if (cmp
->rbearing
< left
+ rbearing
)
21698 cmp
->rbearing
= left
+ rbearing
;
21702 /* If there are glyphs whose x-offsets are negative,
21703 shift all glyphs to the right and make all x-offsets
21707 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21708 cmp
->offsets
[i
* 2] -= leftmost
;
21709 rightmost
-= leftmost
;
21710 cmp
->lbearing
-= leftmost
;
21711 cmp
->rbearing
-= leftmost
;
21714 if (left_padded
&& cmp
->lbearing
< 0)
21716 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21717 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21718 rightmost
-= cmp
->lbearing
;
21719 cmp
->rbearing
-= cmp
->lbearing
;
21722 if (right_padded
&& rightmost
< cmp
->rbearing
)
21724 rightmost
= cmp
->rbearing
;
21727 cmp
->pixel_width
= rightmost
;
21728 cmp
->ascent
= highest
;
21729 cmp
->descent
= - lowest
;
21730 if (cmp
->ascent
< font_ascent
)
21731 cmp
->ascent
= font_ascent
;
21732 if (cmp
->descent
< font_descent
)
21733 cmp
->descent
= font_descent
;
21737 && (cmp
->lbearing
< 0
21738 || cmp
->rbearing
> cmp
->pixel_width
))
21739 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21741 it
->pixel_width
= cmp
->pixel_width
;
21742 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21743 it
->descent
= it
->phys_descent
= cmp
->descent
;
21744 if (face
->box
!= FACE_NO_BOX
)
21746 int thick
= face
->box_line_width
;
21750 it
->ascent
+= thick
;
21751 it
->descent
+= thick
;
21756 if (it
->start_of_box_run_p
)
21757 it
->pixel_width
+= thick
;
21758 if (it
->end_of_box_run_p
)
21759 it
->pixel_width
+= thick
;
21762 /* If face has an overline, add the height of the overline
21763 (1 pixel) and a 1 pixel margin to the character height. */
21764 if (face
->overline_p
)
21765 it
->ascent
+= overline_margin
;
21767 take_vertical_position_into_account (it
);
21768 if (it
->ascent
< 0)
21770 if (it
->descent
< 0)
21774 append_composite_glyph (it
);
21776 else if (it
->what
== IT_COMPOSITION
)
21778 /* A dynamic (automatic) composition. */
21779 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21780 Lisp_Object gstring
;
21781 struct font_metrics metrics
;
21783 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
21785 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
21788 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
21789 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21790 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
21791 it
->descent
= it
->phys_descent
= metrics
.descent
;
21792 if (face
->box
!= FACE_NO_BOX
)
21794 int thick
= face
->box_line_width
;
21798 it
->ascent
+= thick
;
21799 it
->descent
+= thick
;
21804 if (it
->start_of_box_run_p
)
21805 it
->pixel_width
+= thick
;
21806 if (it
->end_of_box_run_p
)
21807 it
->pixel_width
+= thick
;
21809 /* If face has an overline, add the height of the overline
21810 (1 pixel) and a 1 pixel margin to the character height. */
21811 if (face
->overline_p
)
21812 it
->ascent
+= overline_margin
;
21813 take_vertical_position_into_account (it
);
21814 if (it
->ascent
< 0)
21816 if (it
->descent
< 0)
21820 append_composite_glyph (it
);
21822 else if (it
->what
== IT_IMAGE
)
21823 produce_image_glyph (it
);
21824 else if (it
->what
== IT_STRETCH
)
21825 produce_stretch_glyph (it
);
21827 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21828 because this isn't true for images with `:ascent 100'. */
21829 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21830 if (it
->area
== TEXT_AREA
)
21831 it
->current_x
+= it
->pixel_width
;
21833 if (extra_line_spacing
> 0)
21835 it
->descent
+= extra_line_spacing
;
21836 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21837 it
->max_extra_line_spacing
= extra_line_spacing
;
21840 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21841 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21842 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21843 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21847 Output LEN glyphs starting at START at the nominal cursor position.
21848 Advance the nominal cursor over the text. The global variable
21849 updated_window contains the window being updated, updated_row is
21850 the glyph row being updated, and updated_area is the area of that
21851 row being updated. */
21854 x_write_glyphs (start
, len
)
21855 struct glyph
*start
;
21860 xassert (updated_window
&& updated_row
);
21863 /* Write glyphs. */
21865 hpos
= start
- updated_row
->glyphs
[updated_area
];
21866 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21867 updated_row
, updated_area
,
21869 DRAW_NORMAL_TEXT
, 0);
21871 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21872 if (updated_area
== TEXT_AREA
21873 && updated_window
->phys_cursor_on_p
21874 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21875 && updated_window
->phys_cursor
.hpos
>= hpos
21876 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21877 updated_window
->phys_cursor_on_p
= 0;
21881 /* Advance the output cursor. */
21882 output_cursor
.hpos
+= len
;
21883 output_cursor
.x
= x
;
21888 Insert LEN glyphs from START at the nominal cursor position. */
21891 x_insert_glyphs (start
, len
)
21892 struct glyph
*start
;
21897 int line_height
, shift_by_width
, shifted_region_width
;
21898 struct glyph_row
*row
;
21899 struct glyph
*glyph
;
21900 int frame_x
, frame_y
;
21903 xassert (updated_window
&& updated_row
);
21905 w
= updated_window
;
21906 f
= XFRAME (WINDOW_FRAME (w
));
21908 /* Get the height of the line we are in. */
21910 line_height
= row
->height
;
21912 /* Get the width of the glyphs to insert. */
21913 shift_by_width
= 0;
21914 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21915 shift_by_width
+= glyph
->pixel_width
;
21917 /* Get the width of the region to shift right. */
21918 shifted_region_width
= (window_box_width (w
, updated_area
)
21923 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21924 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21926 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21927 line_height
, shift_by_width
);
21929 /* Write the glyphs. */
21930 hpos
= start
- row
->glyphs
[updated_area
];
21931 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21933 DRAW_NORMAL_TEXT
, 0);
21935 /* Advance the output cursor. */
21936 output_cursor
.hpos
+= len
;
21937 output_cursor
.x
+= shift_by_width
;
21943 Erase the current text line from the nominal cursor position
21944 (inclusive) to pixel column TO_X (exclusive). The idea is that
21945 everything from TO_X onward is already erased.
21947 TO_X is a pixel position relative to updated_area of
21948 updated_window. TO_X == -1 means clear to the end of this area. */
21951 x_clear_end_of_line (to_x
)
21955 struct window
*w
= updated_window
;
21956 int max_x
, min_y
, max_y
;
21957 int from_x
, from_y
, to_y
;
21959 xassert (updated_window
&& updated_row
);
21960 f
= XFRAME (w
->frame
);
21962 if (updated_row
->full_width_p
)
21963 max_x
= WINDOW_TOTAL_WIDTH (w
);
21965 max_x
= window_box_width (w
, updated_area
);
21966 max_y
= window_text_bottom_y (w
);
21968 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21969 of window. For TO_X > 0, truncate to end of drawing area. */
21975 to_x
= min (to_x
, max_x
);
21977 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21979 /* Notice if the cursor will be cleared by this operation. */
21980 if (!updated_row
->full_width_p
)
21981 notice_overwritten_cursor (w
, updated_area
,
21982 output_cursor
.x
, -1,
21984 MATRIX_ROW_BOTTOM_Y (updated_row
));
21986 from_x
= output_cursor
.x
;
21988 /* Translate to frame coordinates. */
21989 if (updated_row
->full_width_p
)
21991 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21992 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21996 int area_left
= window_box_left (w
, updated_area
);
21997 from_x
+= area_left
;
22001 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22002 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22003 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22005 /* Prevent inadvertently clearing to end of the X window. */
22006 if (to_x
> from_x
&& to_y
> from_y
)
22009 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22010 to_x
- from_x
, to_y
- from_y
);
22015 #endif /* HAVE_WINDOW_SYSTEM */
22019 /***********************************************************************
22021 ***********************************************************************/
22023 /* Value is the internal representation of the specified cursor type
22024 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22025 of the bar cursor. */
22027 static enum text_cursor_kinds
22028 get_specified_cursor_type (arg
, width
)
22032 enum text_cursor_kinds type
;
22037 if (EQ (arg
, Qbox
))
22038 return FILLED_BOX_CURSOR
;
22040 if (EQ (arg
, Qhollow
))
22041 return HOLLOW_BOX_CURSOR
;
22043 if (EQ (arg
, Qbar
))
22050 && EQ (XCAR (arg
), Qbar
)
22051 && INTEGERP (XCDR (arg
))
22052 && XINT (XCDR (arg
)) >= 0)
22054 *width
= XINT (XCDR (arg
));
22058 if (EQ (arg
, Qhbar
))
22061 return HBAR_CURSOR
;
22065 && EQ (XCAR (arg
), Qhbar
)
22066 && INTEGERP (XCDR (arg
))
22067 && XINT (XCDR (arg
)) >= 0)
22069 *width
= XINT (XCDR (arg
));
22070 return HBAR_CURSOR
;
22073 /* Treat anything unknown as "hollow box cursor".
22074 It was bad to signal an error; people have trouble fixing
22075 .Xdefaults with Emacs, when it has something bad in it. */
22076 type
= HOLLOW_BOX_CURSOR
;
22081 /* Set the default cursor types for specified frame. */
22083 set_frame_cursor_types (f
, arg
)
22090 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22091 FRAME_CURSOR_WIDTH (f
) = width
;
22093 /* By default, set up the blink-off state depending on the on-state. */
22095 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22098 FRAME_BLINK_OFF_CURSOR (f
)
22099 = get_specified_cursor_type (XCDR (tem
), &width
);
22100 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22103 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22107 /* Return the cursor we want to be displayed in window W. Return
22108 width of bar/hbar cursor through WIDTH arg. Return with
22109 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22110 (i.e. if the `system caret' should track this cursor).
22112 In a mini-buffer window, we want the cursor only to appear if we
22113 are reading input from this window. For the selected window, we
22114 want the cursor type given by the frame parameter or buffer local
22115 setting of cursor-type. If explicitly marked off, draw no cursor.
22116 In all other cases, we want a hollow box cursor. */
22118 static enum text_cursor_kinds
22119 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22121 struct glyph
*glyph
;
22123 int *active_cursor
;
22125 struct frame
*f
= XFRAME (w
->frame
);
22126 struct buffer
*b
= XBUFFER (w
->buffer
);
22127 int cursor_type
= DEFAULT_CURSOR
;
22128 Lisp_Object alt_cursor
;
22129 int non_selected
= 0;
22131 *active_cursor
= 1;
22134 if (cursor_in_echo_area
22135 && FRAME_HAS_MINIBUF_P (f
)
22136 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22138 if (w
== XWINDOW (echo_area_window
))
22140 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22142 *width
= FRAME_CURSOR_WIDTH (f
);
22143 return FRAME_DESIRED_CURSOR (f
);
22146 return get_specified_cursor_type (b
->cursor_type
, width
);
22149 *active_cursor
= 0;
22153 /* Detect a nonselected window or nonselected frame. */
22154 else if (w
!= XWINDOW (f
->selected_window
)
22155 #ifdef HAVE_WINDOW_SYSTEM
22156 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22160 *active_cursor
= 0;
22162 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22168 /* Never display a cursor in a window in which cursor-type is nil. */
22169 if (NILP (b
->cursor_type
))
22172 /* Get the normal cursor type for this window. */
22173 if (EQ (b
->cursor_type
, Qt
))
22175 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22176 *width
= FRAME_CURSOR_WIDTH (f
);
22179 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22181 /* Use cursor-in-non-selected-windows instead
22182 for non-selected window or frame. */
22185 alt_cursor
= b
->cursor_in_non_selected_windows
;
22186 if (!EQ (Qt
, alt_cursor
))
22187 return get_specified_cursor_type (alt_cursor
, width
);
22188 /* t means modify the normal cursor type. */
22189 if (cursor_type
== FILLED_BOX_CURSOR
)
22190 cursor_type
= HOLLOW_BOX_CURSOR
;
22191 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22193 return cursor_type
;
22196 /* Use normal cursor if not blinked off. */
22197 if (!w
->cursor_off_p
)
22199 #ifdef HAVE_WINDOW_SYSTEM
22200 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22202 if (cursor_type
== FILLED_BOX_CURSOR
)
22204 /* Using a block cursor on large images can be very annoying.
22205 So use a hollow cursor for "large" images.
22206 If image is not transparent (no mask), also use hollow cursor. */
22207 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22208 if (img
!= NULL
&& IMAGEP (img
->spec
))
22210 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22211 where N = size of default frame font size.
22212 This should cover most of the "tiny" icons people may use. */
22214 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22215 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22216 cursor_type
= HOLLOW_BOX_CURSOR
;
22219 else if (cursor_type
!= NO_CURSOR
)
22221 /* Display current only supports BOX and HOLLOW cursors for images.
22222 So for now, unconditionally use a HOLLOW cursor when cursor is
22223 not a solid box cursor. */
22224 cursor_type
= HOLLOW_BOX_CURSOR
;
22228 return cursor_type
;
22231 /* Cursor is blinked off, so determine how to "toggle" it. */
22233 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22234 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22235 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22237 /* Then see if frame has specified a specific blink off cursor type. */
22238 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22240 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22241 return FRAME_BLINK_OFF_CURSOR (f
);
22245 /* Some people liked having a permanently visible blinking cursor,
22246 while others had very strong opinions against it. So it was
22247 decided to remove it. KFS 2003-09-03 */
22249 /* Finally perform built-in cursor blinking:
22250 filled box <-> hollow box
22251 wide [h]bar <-> narrow [h]bar
22252 narrow [h]bar <-> no cursor
22253 other type <-> no cursor */
22255 if (cursor_type
== FILLED_BOX_CURSOR
)
22256 return HOLLOW_BOX_CURSOR
;
22258 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22261 return cursor_type
;
22269 #ifdef HAVE_WINDOW_SYSTEM
22271 /* Notice when the text cursor of window W has been completely
22272 overwritten by a drawing operation that outputs glyphs in AREA
22273 starting at X0 and ending at X1 in the line starting at Y0 and
22274 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22275 the rest of the line after X0 has been written. Y coordinates
22276 are window-relative. */
22279 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22281 enum glyph_row_area area
;
22282 int x0
, y0
, x1
, y1
;
22284 int cx0
, cx1
, cy0
, cy1
;
22285 struct glyph_row
*row
;
22287 if (!w
->phys_cursor_on_p
)
22289 if (area
!= TEXT_AREA
)
22292 if (w
->phys_cursor
.vpos
< 0
22293 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22294 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22295 !(row
->enabled_p
&& row
->displays_text_p
)))
22298 if (row
->cursor_in_fringe_p
)
22300 row
->cursor_in_fringe_p
= 0;
22301 draw_fringe_bitmap (w
, row
, 0);
22302 w
->phys_cursor_on_p
= 0;
22306 cx0
= w
->phys_cursor
.x
;
22307 cx1
= cx0
+ w
->phys_cursor_width
;
22308 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22311 /* The cursor image will be completely removed from the
22312 screen if the output area intersects the cursor area in
22313 y-direction. When we draw in [y0 y1[, and some part of
22314 the cursor is at y < y0, that part must have been drawn
22315 before. When scrolling, the cursor is erased before
22316 actually scrolling, so we don't come here. When not
22317 scrolling, the rows above the old cursor row must have
22318 changed, and in this case these rows must have written
22319 over the cursor image.
22321 Likewise if part of the cursor is below y1, with the
22322 exception of the cursor being in the first blank row at
22323 the buffer and window end because update_text_area
22324 doesn't draw that row. (Except when it does, but
22325 that's handled in update_text_area.) */
22327 cy0
= w
->phys_cursor
.y
;
22328 cy1
= cy0
+ w
->phys_cursor_height
;
22329 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22332 w
->phys_cursor_on_p
= 0;
22335 #endif /* HAVE_WINDOW_SYSTEM */
22338 /************************************************************************
22340 ************************************************************************/
22342 #ifdef HAVE_WINDOW_SYSTEM
22345 Fix the display of area AREA of overlapping row ROW in window W
22346 with respect to the overlapping part OVERLAPS. */
22349 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22351 struct glyph_row
*row
;
22352 enum glyph_row_area area
;
22360 for (i
= 0; i
< row
->used
[area
];)
22362 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22364 int start
= i
, start_x
= x
;
22368 x
+= row
->glyphs
[area
][i
].pixel_width
;
22371 while (i
< row
->used
[area
]
22372 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22374 draw_glyphs (w
, start_x
, row
, area
,
22376 DRAW_NORMAL_TEXT
, overlaps
);
22380 x
+= row
->glyphs
[area
][i
].pixel_width
;
22390 Draw the cursor glyph of window W in glyph row ROW. See the
22391 comment of draw_glyphs for the meaning of HL. */
22394 draw_phys_cursor_glyph (w
, row
, hl
)
22396 struct glyph_row
*row
;
22397 enum draw_glyphs_face hl
;
22399 /* If cursor hpos is out of bounds, don't draw garbage. This can
22400 happen in mini-buffer windows when switching between echo area
22401 glyphs and mini-buffer. */
22402 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22404 int on_p
= w
->phys_cursor_on_p
;
22406 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22407 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22409 w
->phys_cursor_on_p
= on_p
;
22411 if (hl
== DRAW_CURSOR
)
22412 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22413 /* When we erase the cursor, and ROW is overlapped by other
22414 rows, make sure that these overlapping parts of other rows
22416 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22418 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22420 if (row
> w
->current_matrix
->rows
22421 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22422 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22423 OVERLAPS_ERASED_CURSOR
);
22425 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22426 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22427 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22428 OVERLAPS_ERASED_CURSOR
);
22435 Erase the image of a cursor of window W from the screen. */
22438 erase_phys_cursor (w
)
22441 struct frame
*f
= XFRAME (w
->frame
);
22442 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22443 int hpos
= w
->phys_cursor
.hpos
;
22444 int vpos
= w
->phys_cursor
.vpos
;
22445 int mouse_face_here_p
= 0;
22446 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22447 struct glyph_row
*cursor_row
;
22448 struct glyph
*cursor_glyph
;
22449 enum draw_glyphs_face hl
;
22451 /* No cursor displayed or row invalidated => nothing to do on the
22453 if (w
->phys_cursor_type
== NO_CURSOR
)
22454 goto mark_cursor_off
;
22456 /* VPOS >= active_glyphs->nrows means that window has been resized.
22457 Don't bother to erase the cursor. */
22458 if (vpos
>= active_glyphs
->nrows
)
22459 goto mark_cursor_off
;
22461 /* If row containing cursor is marked invalid, there is nothing we
22463 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22464 if (!cursor_row
->enabled_p
)
22465 goto mark_cursor_off
;
22467 /* If line spacing is > 0, old cursor may only be partially visible in
22468 window after split-window. So adjust visible height. */
22469 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22470 window_text_bottom_y (w
) - cursor_row
->y
);
22472 /* If row is completely invisible, don't attempt to delete a cursor which
22473 isn't there. This can happen if cursor is at top of a window, and
22474 we switch to a buffer with a header line in that window. */
22475 if (cursor_row
->visible_height
<= 0)
22476 goto mark_cursor_off
;
22478 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22479 if (cursor_row
->cursor_in_fringe_p
)
22481 cursor_row
->cursor_in_fringe_p
= 0;
22482 draw_fringe_bitmap (w
, cursor_row
, 0);
22483 goto mark_cursor_off
;
22486 /* This can happen when the new row is shorter than the old one.
22487 In this case, either draw_glyphs or clear_end_of_line
22488 should have cleared the cursor. Note that we wouldn't be
22489 able to erase the cursor in this case because we don't have a
22490 cursor glyph at hand. */
22491 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22492 goto mark_cursor_off
;
22494 /* If the cursor is in the mouse face area, redisplay that when
22495 we clear the cursor. */
22496 if (! NILP (dpyinfo
->mouse_face_window
)
22497 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22498 && (vpos
> dpyinfo
->mouse_face_beg_row
22499 || (vpos
== dpyinfo
->mouse_face_beg_row
22500 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22501 && (vpos
< dpyinfo
->mouse_face_end_row
22502 || (vpos
== dpyinfo
->mouse_face_end_row
22503 && hpos
< dpyinfo
->mouse_face_end_col
))
22504 /* Don't redraw the cursor's spot in mouse face if it is at the
22505 end of a line (on a newline). The cursor appears there, but
22506 mouse highlighting does not. */
22507 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22508 mouse_face_here_p
= 1;
22510 /* Maybe clear the display under the cursor. */
22511 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22514 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22517 cursor_glyph
= get_phys_cursor_glyph (w
);
22518 if (cursor_glyph
== NULL
)
22519 goto mark_cursor_off
;
22521 width
= cursor_glyph
->pixel_width
;
22522 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22523 x
= w
->phys_cursor
.x
;
22525 width
-= left_x
- x
;
22526 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22527 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22528 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22531 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22534 /* Erase the cursor by redrawing the character underneath it. */
22535 if (mouse_face_here_p
)
22536 hl
= DRAW_MOUSE_FACE
;
22538 hl
= DRAW_NORMAL_TEXT
;
22539 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22542 w
->phys_cursor_on_p
= 0;
22543 w
->phys_cursor_type
= NO_CURSOR
;
22548 Display or clear cursor of window W. If ON is zero, clear the
22549 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22550 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22553 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22555 int on
, hpos
, vpos
, x
, y
;
22557 struct frame
*f
= XFRAME (w
->frame
);
22558 int new_cursor_type
;
22559 int new_cursor_width
;
22561 struct glyph_row
*glyph_row
;
22562 struct glyph
*glyph
;
22564 /* This is pointless on invisible frames, and dangerous on garbaged
22565 windows and frames; in the latter case, the frame or window may
22566 be in the midst of changing its size, and x and y may be off the
22568 if (! FRAME_VISIBLE_P (f
)
22569 || FRAME_GARBAGED_P (f
)
22570 || vpos
>= w
->current_matrix
->nrows
22571 || hpos
>= w
->current_matrix
->matrix_w
)
22574 /* If cursor is off and we want it off, return quickly. */
22575 if (!on
&& !w
->phys_cursor_on_p
)
22578 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22579 /* If cursor row is not enabled, we don't really know where to
22580 display the cursor. */
22581 if (!glyph_row
->enabled_p
)
22583 w
->phys_cursor_on_p
= 0;
22588 if (!glyph_row
->exact_window_width_line_p
22589 || hpos
< glyph_row
->used
[TEXT_AREA
])
22590 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22592 xassert (interrupt_input_blocked
);
22594 /* Set new_cursor_type to the cursor we want to be displayed. */
22595 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22596 &new_cursor_width
, &active_cursor
);
22598 /* If cursor is currently being shown and we don't want it to be or
22599 it is in the wrong place, or the cursor type is not what we want,
22601 if (w
->phys_cursor_on_p
22603 || w
->phys_cursor
.x
!= x
22604 || w
->phys_cursor
.y
!= y
22605 || new_cursor_type
!= w
->phys_cursor_type
22606 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22607 && new_cursor_width
!= w
->phys_cursor_width
)))
22608 erase_phys_cursor (w
);
22610 /* Don't check phys_cursor_on_p here because that flag is only set
22611 to zero in some cases where we know that the cursor has been
22612 completely erased, to avoid the extra work of erasing the cursor
22613 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22614 still not be visible, or it has only been partly erased. */
22617 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22618 w
->phys_cursor_height
= glyph_row
->height
;
22620 /* Set phys_cursor_.* before x_draw_.* is called because some
22621 of them may need the information. */
22622 w
->phys_cursor
.x
= x
;
22623 w
->phys_cursor
.y
= glyph_row
->y
;
22624 w
->phys_cursor
.hpos
= hpos
;
22625 w
->phys_cursor
.vpos
= vpos
;
22628 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22629 new_cursor_type
, new_cursor_width
,
22630 on
, active_cursor
);
22634 /* Switch the display of W's cursor on or off, according to the value
22641 update_window_cursor (w
, on
)
22645 /* Don't update cursor in windows whose frame is in the process
22646 of being deleted. */
22647 if (w
->current_matrix
)
22650 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22651 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22657 /* Call update_window_cursor with parameter ON_P on all leaf windows
22658 in the window tree rooted at W. */
22661 update_cursor_in_window_tree (w
, on_p
)
22667 if (!NILP (w
->hchild
))
22668 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22669 else if (!NILP (w
->vchild
))
22670 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22672 update_window_cursor (w
, on_p
);
22674 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22680 Display the cursor on window W, or clear it, according to ON_P.
22681 Don't change the cursor's position. */
22684 x_update_cursor (f
, on_p
)
22688 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22693 Clear the cursor of window W to background color, and mark the
22694 cursor as not shown. This is used when the text where the cursor
22695 is is about to be rewritten. */
22701 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22702 update_window_cursor (w
, 0);
22707 Display the active region described by mouse_face_* according to DRAW. */
22710 show_mouse_face (dpyinfo
, draw
)
22711 Display_Info
*dpyinfo
;
22712 enum draw_glyphs_face draw
;
22714 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22715 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22717 if (/* If window is in the process of being destroyed, don't bother
22719 w
->current_matrix
!= NULL
22720 /* Don't update mouse highlight if hidden */
22721 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22722 /* Recognize when we are called to operate on rows that don't exist
22723 anymore. This can happen when a window is split. */
22724 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22726 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22727 struct glyph_row
*row
, *first
, *last
;
22729 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22730 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22732 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22734 int start_hpos
, end_hpos
, start_x
;
22736 /* For all but the first row, the highlight starts at column 0. */
22739 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22740 start_x
= dpyinfo
->mouse_face_beg_x
;
22749 end_hpos
= dpyinfo
->mouse_face_end_col
;
22752 end_hpos
= row
->used
[TEXT_AREA
];
22753 if (draw
== DRAW_NORMAL_TEXT
)
22754 row
->fill_line_p
= 1; /* Clear to end of line */
22757 if (end_hpos
> start_hpos
)
22759 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22760 start_hpos
, end_hpos
,
22764 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22768 /* When we've written over the cursor, arrange for it to
22769 be displayed again. */
22770 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22773 display_and_set_cursor (w
, 1,
22774 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22775 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22780 /* Change the mouse cursor. */
22781 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22782 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22783 else if (draw
== DRAW_MOUSE_FACE
)
22784 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22786 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22790 Clear out the mouse-highlighted active region.
22791 Redraw it un-highlighted first. Value is non-zero if mouse
22792 face was actually drawn unhighlighted. */
22795 clear_mouse_face (dpyinfo
)
22796 Display_Info
*dpyinfo
;
22800 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22802 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22806 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22807 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22808 dpyinfo
->mouse_face_window
= Qnil
;
22809 dpyinfo
->mouse_face_overlay
= Qnil
;
22815 Non-zero if physical cursor of window W is within mouse face. */
22818 cursor_in_mouse_face_p (w
)
22821 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22822 int in_mouse_face
= 0;
22824 if (WINDOWP (dpyinfo
->mouse_face_window
)
22825 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22827 int hpos
= w
->phys_cursor
.hpos
;
22828 int vpos
= w
->phys_cursor
.vpos
;
22830 if (vpos
>= dpyinfo
->mouse_face_beg_row
22831 && vpos
<= dpyinfo
->mouse_face_end_row
22832 && (vpos
> dpyinfo
->mouse_face_beg_row
22833 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22834 && (vpos
< dpyinfo
->mouse_face_end_row
22835 || hpos
< dpyinfo
->mouse_face_end_col
22836 || dpyinfo
->mouse_face_past_end
))
22840 return in_mouse_face
;
22846 /* This function sets the mouse_face_* elements of DPYINFO, assuming
22847 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
22848 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
22849 for the overlay or run of text properties specifying the mouse
22850 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
22851 before-string and after-string that must also be highlighted.
22852 DISPLAY_STRING, if non-nil, is a display string that may cover some
22853 or all of the highlighted text. */
22856 mouse_face_from_buffer_pos (Lisp_Object window
,
22857 Display_Info
*dpyinfo
,
22858 EMACS_INT mouse_charpos
,
22859 EMACS_INT start_charpos
,
22860 EMACS_INT end_charpos
,
22861 Lisp_Object before_string
,
22862 Lisp_Object after_string
,
22863 Lisp_Object display_string
)
22865 struct window
*w
= XWINDOW (window
);
22866 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22867 struct glyph_row
*row
;
22868 struct glyph
*glyph
, *end
;
22872 xassert (NILP (display_string
) || STRINGP (display_string
));
22873 xassert (NILP (before_string
) || STRINGP (before_string
));
22874 xassert (NILP (after_string
) || STRINGP (after_string
));
22876 /* Find the first highlighted glyph. */
22877 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
22879 dpyinfo
->mouse_face_beg_col
= 0;
22880 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22881 dpyinfo
->mouse_face_beg_x
= first
->x
;
22882 dpyinfo
->mouse_face_beg_y
= first
->y
;
22886 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
22888 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22890 /* If the before-string or display-string contains newlines,
22891 row_containing_pos skips to its last row. Move back. */
22892 if (!NILP (before_string
) || !NILP (display_string
))
22894 struct glyph_row
*prev
;
22895 while ((prev
= row
- 1, prev
>= first
)
22896 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
22897 && prev
->used
[TEXT_AREA
] > 0)
22899 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22900 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22901 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
22903 || !(EQ (glyph
->object
, before_string
)
22904 || EQ (glyph
->object
, display_string
)))
22910 glyph
= row
->glyphs
[TEXT_AREA
];
22911 end
= glyph
+ row
->used
[TEXT_AREA
];
22913 dpyinfo
->mouse_face_beg_y
= row
->y
;
22914 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22916 /* Skip truncation glyphs at the start of the glyph row. */
22917 if (row
->displays_text_p
)
22919 && INTEGERP (glyph
->object
)
22920 && glyph
->charpos
< 0;
22922 x
+= glyph
->pixel_width
;
22924 /* Scan the glyph row, stopping before BEFORE_STRING or
22925 DISPLAY_STRING or START_CHARPOS. */
22927 && !INTEGERP (glyph
->object
)
22928 && !EQ (glyph
->object
, before_string
)
22929 && !EQ (glyph
->object
, display_string
)
22930 && !(BUFFERP (glyph
->object
)
22931 && glyph
->charpos
>= start_charpos
);
22933 x
+= glyph
->pixel_width
;
22935 dpyinfo
->mouse_face_beg_x
= x
;
22936 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22939 /* Find the last highlighted glyph. */
22940 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
22943 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22944 dpyinfo
->mouse_face_past_end
= 1;
22946 else if (!NILP (after_string
))
22948 /* If the after-string has newlines, advance to its last row. */
22949 struct glyph_row
*next
;
22950 struct glyph_row
*last
22951 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22953 for (next
= row
+ 1;
22955 && next
->used
[TEXT_AREA
] > 0
22956 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
22961 glyph
= row
->glyphs
[TEXT_AREA
];
22962 end
= glyph
+ row
->used
[TEXT_AREA
];
22964 dpyinfo
->mouse_face_end_y
= row
->y
;
22965 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22967 /* Skip truncation glyphs at the start of the row. */
22968 if (row
->displays_text_p
)
22970 && INTEGERP (glyph
->object
)
22971 && glyph
->charpos
< 0;
22973 x
+= glyph
->pixel_width
;
22975 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
22978 && !INTEGERP (glyph
->object
)
22979 && !EQ (glyph
->object
, after_string
)
22980 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
22982 x
+= glyph
->pixel_width
;
22984 /* If we found AFTER_STRING, consume it and stop. */
22985 if (EQ (glyph
->object
, after_string
))
22987 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
22988 x
+= glyph
->pixel_width
;
22992 /* If there's no after-string, we must check if we overshot,
22993 which might be the case if we stopped after a string glyph.
22994 That glyph may belong to a before-string or display-string
22995 associated with the end position, which must not be
22997 Lisp_Object prev_object
;
23000 while (glyph
> row
->glyphs
[TEXT_AREA
])
23002 prev_object
= (glyph
- 1)->object
;
23003 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23006 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23007 if (pos
&& pos
< end_charpos
)
23010 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23011 && EQ ((glyph
- 1)->object
, prev_object
);
23013 x
-= (glyph
- 1)->pixel_width
;
23017 dpyinfo
->mouse_face_end_x
= x
;
23018 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23019 dpyinfo
->mouse_face_window
= window
;
23020 dpyinfo
->mouse_face_face_id
23021 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23023 !dpyinfo
->mouse_face_hidden
, -1);
23024 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23028 /* Find the position of the glyph for position POS in OBJECT in
23029 window W's current matrix, and return in *X, *Y the pixel
23030 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23032 RIGHT_P non-zero means return the position of the right edge of the
23033 glyph, RIGHT_P zero means return the left edge position.
23035 If no glyph for POS exists in the matrix, return the position of
23036 the glyph with the next smaller position that is in the matrix, if
23037 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23038 exists in the matrix, return the position of the glyph with the
23039 next larger position in OBJECT.
23041 Value is non-zero if a glyph was found. */
23044 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23047 Lisp_Object object
;
23048 int *hpos
, *vpos
, *x
, *y
;
23051 int yb
= window_text_bottom_y (w
);
23052 struct glyph_row
*r
;
23053 struct glyph
*best_glyph
= NULL
;
23054 struct glyph_row
*best_row
= NULL
;
23057 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23058 r
->enabled_p
&& r
->y
< yb
;
23061 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23062 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23065 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23066 if (EQ (g
->object
, object
))
23068 if (g
->charpos
== pos
)
23075 else if (best_glyph
== NULL
23076 || ((eabs (g
->charpos
- pos
)
23077 < eabs (best_glyph
->charpos
- pos
))
23080 : g
->charpos
> pos
)))
23094 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23098 *x
+= best_glyph
->pixel_width
;
23103 *vpos
= best_row
- w
->current_matrix
->rows
;
23106 return best_glyph
!= NULL
;
23110 /* See if position X, Y is within a hot-spot of an image. */
23113 on_hot_spot_p (hot_spot
, x
, y
)
23114 Lisp_Object hot_spot
;
23117 if (!CONSP (hot_spot
))
23120 if (EQ (XCAR (hot_spot
), Qrect
))
23122 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23123 Lisp_Object rect
= XCDR (hot_spot
);
23127 if (!CONSP (XCAR (rect
)))
23129 if (!CONSP (XCDR (rect
)))
23131 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23133 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23135 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23137 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23141 else if (EQ (XCAR (hot_spot
), Qcircle
))
23143 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23144 Lisp_Object circ
= XCDR (hot_spot
);
23145 Lisp_Object lr
, lx0
, ly0
;
23147 && CONSP (XCAR (circ
))
23148 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23149 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23150 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23152 double r
= XFLOATINT (lr
);
23153 double dx
= XINT (lx0
) - x
;
23154 double dy
= XINT (ly0
) - y
;
23155 return (dx
* dx
+ dy
* dy
<= r
* r
);
23158 else if (EQ (XCAR (hot_spot
), Qpoly
))
23160 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23161 if (VECTORP (XCDR (hot_spot
)))
23163 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23164 Lisp_Object
*poly
= v
->contents
;
23168 Lisp_Object lx
, ly
;
23171 /* Need an even number of coordinates, and at least 3 edges. */
23172 if (n
< 6 || n
& 1)
23175 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23176 If count is odd, we are inside polygon. Pixels on edges
23177 may or may not be included depending on actual geometry of the
23179 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23180 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23182 x0
= XINT (lx
), y0
= XINT (ly
);
23183 for (i
= 0; i
< n
; i
+= 2)
23185 int x1
= x0
, y1
= y0
;
23186 if ((lx
= poly
[i
], !INTEGERP (lx
))
23187 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23189 x0
= XINT (lx
), y0
= XINT (ly
);
23191 /* Does this segment cross the X line? */
23199 if (y
> y0
&& y
> y1
)
23201 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23211 find_hot_spot (map
, x
, y
)
23215 while (CONSP (map
))
23217 if (CONSP (XCAR (map
))
23218 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23226 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23228 doc
: /* Lookup in image map MAP coordinates X and Y.
23229 An image map is an alist where each element has the format (AREA ID PLIST).
23230 An AREA is specified as either a rectangle, a circle, or a polygon:
23231 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23232 pixel coordinates of the upper left and bottom right corners.
23233 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23234 and the radius of the circle; r may be a float or integer.
23235 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23236 vector describes one corner in the polygon.
23237 Returns the alist element for the first matching AREA in MAP. */)
23248 return find_hot_spot (map
, XINT (x
), XINT (y
));
23252 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23254 define_frame_cursor1 (f
, cursor
, pointer
)
23257 Lisp_Object pointer
;
23259 /* Do not change cursor shape while dragging mouse. */
23260 if (!NILP (do_mouse_tracking
))
23263 if (!NILP (pointer
))
23265 if (EQ (pointer
, Qarrow
))
23266 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23267 else if (EQ (pointer
, Qhand
))
23268 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23269 else if (EQ (pointer
, Qtext
))
23270 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23271 else if (EQ (pointer
, intern ("hdrag")))
23272 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23273 #ifdef HAVE_X_WINDOWS
23274 else if (EQ (pointer
, intern ("vdrag")))
23275 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23277 else if (EQ (pointer
, intern ("hourglass")))
23278 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23279 else if (EQ (pointer
, Qmodeline
))
23280 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23282 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23285 if (cursor
!= No_Cursor
)
23286 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23289 /* Take proper action when mouse has moved to the mode or header line
23290 or marginal area AREA of window W, x-position X and y-position Y.
23291 X is relative to the start of the text display area of W, so the
23292 width of bitmap areas and scroll bars must be subtracted to get a
23293 position relative to the start of the mode line. */
23296 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23297 Lisp_Object window
;
23299 enum window_part area
;
23301 struct window
*w
= XWINDOW (window
);
23302 struct frame
*f
= XFRAME (w
->frame
);
23303 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23304 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23305 Lisp_Object pointer
= Qnil
;
23306 int charpos
, dx
, dy
, width
, height
;
23307 Lisp_Object string
, object
= Qnil
;
23308 Lisp_Object pos
, help
;
23310 Lisp_Object mouse_face
;
23311 int original_x_pixel
= x
;
23312 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23313 struct glyph_row
*row
;
23315 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23320 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23321 &object
, &dx
, &dy
, &width
, &height
);
23323 row
= (area
== ON_MODE_LINE
23324 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23325 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23328 if (row
->mode_line_p
&& row
->enabled_p
)
23330 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23331 end
= glyph
+ row
->used
[TEXT_AREA
];
23333 for (x0
= original_x_pixel
;
23334 glyph
< end
&& x0
>= glyph
->pixel_width
;
23336 x0
-= glyph
->pixel_width
;
23344 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23345 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23346 &object
, &dx
, &dy
, &width
, &height
);
23351 if (IMAGEP (object
))
23353 Lisp_Object image_map
, hotspot
;
23354 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23356 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23358 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23360 Lisp_Object area_id
, plist
;
23362 area_id
= XCAR (hotspot
);
23363 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23364 If so, we could look for mouse-enter, mouse-leave
23365 properties in PLIST (and do something...). */
23366 hotspot
= XCDR (hotspot
);
23367 if (CONSP (hotspot
)
23368 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23370 pointer
= Fplist_get (plist
, Qpointer
);
23371 if (NILP (pointer
))
23373 help
= Fplist_get (plist
, Qhelp_echo
);
23376 help_echo_string
= help
;
23377 /* Is this correct? ++kfs */
23378 XSETWINDOW (help_echo_window
, w
);
23379 help_echo_object
= w
->buffer
;
23380 help_echo_pos
= charpos
;
23384 if (NILP (pointer
))
23385 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23388 if (STRINGP (string
))
23390 pos
= make_number (charpos
);
23391 /* If we're on a string with `help-echo' text property, arrange
23392 for the help to be displayed. This is done by setting the
23393 global variable help_echo_string to the help string. */
23396 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23399 help_echo_string
= help
;
23400 XSETWINDOW (help_echo_window
, w
);
23401 help_echo_object
= string
;
23402 help_echo_pos
= charpos
;
23406 if (NILP (pointer
))
23407 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23409 /* Change the mouse pointer according to what is under X/Y. */
23410 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23413 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23414 if (!KEYMAPP (map
))
23415 map
= Fget_text_property (pos
, Qkeymap
, string
);
23416 if (!KEYMAPP (map
))
23417 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23420 /* Change the mouse face according to what is under X/Y. */
23421 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23422 if (!NILP (mouse_face
)
23423 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23428 struct glyph
* tmp_glyph
;
23432 int total_pixel_width
;
23437 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23438 Qmouse_face
, string
, Qnil
);
23440 b
= make_number (0);
23442 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23444 e
= make_number (SCHARS (string
));
23446 /* Calculate the position(glyph position: GPOS) of GLYPH in
23447 displayed string. GPOS is different from CHARPOS.
23449 CHARPOS is the position of glyph in internal string
23450 object. A mode line string format has structures which
23451 is converted to a flatten by emacs lisp interpreter.
23452 The internal string is an element of the structures.
23453 The displayed string is the flatten string. */
23455 if (glyph
> row_start_glyph
)
23457 tmp_glyph
= glyph
- 1;
23458 while (tmp_glyph
>= row_start_glyph
23459 && tmp_glyph
->charpos
>= XINT (b
)
23460 && EQ (tmp_glyph
->object
, glyph
->object
))
23467 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23468 displayed string holding GLYPH.
23470 GSEQ_LENGTH is different from SCHARS (STRING).
23471 SCHARS (STRING) returns the length of the internal string. */
23472 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23473 tmp_glyph
->charpos
< XINT (e
);
23474 tmp_glyph
++, gseq_length
++)
23476 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23480 total_pixel_width
= 0;
23481 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23482 total_pixel_width
+= tmp_glyph
->pixel_width
;
23484 /* Pre calculation of re-rendering position */
23486 hpos
= (area
== ON_MODE_LINE
23487 ? (w
->current_matrix
)->nrows
- 1
23490 /* If the re-rendering position is included in the last
23491 re-rendering area, we should do nothing. */
23492 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23493 && dpyinfo
->mouse_face_beg_col
<= vpos
23494 && vpos
< dpyinfo
->mouse_face_end_col
23495 && dpyinfo
->mouse_face_beg_row
== hpos
)
23498 if (clear_mouse_face (dpyinfo
))
23499 cursor
= No_Cursor
;
23501 dpyinfo
->mouse_face_beg_col
= vpos
;
23502 dpyinfo
->mouse_face_beg_row
= hpos
;
23504 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23505 dpyinfo
->mouse_face_beg_y
= 0;
23507 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23508 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23510 dpyinfo
->mouse_face_end_x
= 0;
23511 dpyinfo
->mouse_face_end_y
= 0;
23513 dpyinfo
->mouse_face_past_end
= 0;
23514 dpyinfo
->mouse_face_window
= window
;
23516 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23519 glyph
->face_id
, 1);
23520 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23522 if (NILP (pointer
))
23525 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23526 clear_mouse_face (dpyinfo
);
23528 define_frame_cursor1 (f
, cursor
, pointer
);
23533 Take proper action when the mouse has moved to position X, Y on
23534 frame F as regards highlighting characters that have mouse-face
23535 properties. Also de-highlighting chars where the mouse was before.
23536 X and Y can be negative or out of range. */
23539 note_mouse_highlight (f
, x
, y
)
23543 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23544 enum window_part part
;
23545 Lisp_Object window
;
23547 Cursor cursor
= No_Cursor
;
23548 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23551 /* When a menu is active, don't highlight because this looks odd. */
23552 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23553 if (popup_activated ())
23557 if (NILP (Vmouse_highlight
)
23558 || !f
->glyphs_initialized_p
)
23561 dpyinfo
->mouse_face_mouse_x
= x
;
23562 dpyinfo
->mouse_face_mouse_y
= y
;
23563 dpyinfo
->mouse_face_mouse_frame
= f
;
23565 if (dpyinfo
->mouse_face_defer
)
23568 if (gc_in_progress
)
23570 dpyinfo
->mouse_face_deferred_gc
= 1;
23574 /* Which window is that in? */
23575 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23577 /* If we were displaying active text in another window, clear that.
23578 Also clear if we move out of text area in same window. */
23579 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23580 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23581 && !NILP (dpyinfo
->mouse_face_window
)))
23582 clear_mouse_face (dpyinfo
);
23584 /* Not on a window -> return. */
23585 if (!WINDOWP (window
))
23588 /* Reset help_echo_string. It will get recomputed below. */
23589 help_echo_string
= Qnil
;
23591 /* Convert to window-relative pixel coordinates. */
23592 w
= XWINDOW (window
);
23593 frame_to_window_pixel_xy (w
, &x
, &y
);
23595 /* Handle tool-bar window differently since it doesn't display a
23597 if (EQ (window
, f
->tool_bar_window
))
23599 note_tool_bar_highlight (f
, x
, y
);
23603 /* Mouse is on the mode, header line or margin? */
23604 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23605 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23607 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23611 if (part
== ON_VERTICAL_BORDER
)
23613 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23614 help_echo_string
= build_string ("drag-mouse-1: resize");
23616 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23617 || part
== ON_SCROLL_BAR
)
23618 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23620 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23622 /* Are we in a window whose display is up to date?
23623 And verify the buffer's text has not changed. */
23624 b
= XBUFFER (w
->buffer
);
23625 if (part
== ON_TEXT
23626 && EQ (w
->window_end_valid
, w
->buffer
)
23627 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23628 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23630 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23631 struct glyph
*glyph
;
23632 Lisp_Object object
;
23633 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23634 Lisp_Object
*overlay_vec
= NULL
;
23636 struct buffer
*obuf
;
23637 int obegv
, ozv
, same_region
;
23639 /* Find the glyph under X/Y. */
23640 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23642 /* Look for :pointer property on image. */
23643 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23645 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23646 if (img
!= NULL
&& IMAGEP (img
->spec
))
23648 Lisp_Object image_map
, hotspot
;
23649 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23651 && (hotspot
= find_hot_spot (image_map
,
23652 glyph
->slice
.x
+ dx
,
23653 glyph
->slice
.y
+ dy
),
23655 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23657 Lisp_Object area_id
, plist
;
23659 area_id
= XCAR (hotspot
);
23660 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23661 If so, we could look for mouse-enter, mouse-leave
23662 properties in PLIST (and do something...). */
23663 hotspot
= XCDR (hotspot
);
23664 if (CONSP (hotspot
)
23665 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23667 pointer
= Fplist_get (plist
, Qpointer
);
23668 if (NILP (pointer
))
23670 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23671 if (!NILP (help_echo_string
))
23673 help_echo_window
= window
;
23674 help_echo_object
= glyph
->object
;
23675 help_echo_pos
= glyph
->charpos
;
23679 if (NILP (pointer
))
23680 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23684 /* Clear mouse face if X/Y not over text. */
23686 || area
!= TEXT_AREA
23687 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23689 if (clear_mouse_face (dpyinfo
))
23690 cursor
= No_Cursor
;
23691 if (NILP (pointer
))
23693 if (area
!= TEXT_AREA
)
23694 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23696 pointer
= Vvoid_text_area_pointer
;
23701 pos
= glyph
->charpos
;
23702 object
= glyph
->object
;
23703 if (!STRINGP (object
) && !BUFFERP (object
))
23706 /* If we get an out-of-range value, return now; avoid an error. */
23707 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23710 /* Make the window's buffer temporarily current for
23711 overlays_at and compute_char_face. */
23712 obuf
= current_buffer
;
23713 current_buffer
= b
;
23719 /* Is this char mouse-active or does it have help-echo? */
23720 position
= make_number (pos
);
23722 if (BUFFERP (object
))
23724 /* Put all the overlays we want in a vector in overlay_vec. */
23725 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23726 /* Sort overlays into increasing priority order. */
23727 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23732 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23733 && vpos
>= dpyinfo
->mouse_face_beg_row
23734 && vpos
<= dpyinfo
->mouse_face_end_row
23735 && (vpos
> dpyinfo
->mouse_face_beg_row
23736 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23737 && (vpos
< dpyinfo
->mouse_face_end_row
23738 || hpos
< dpyinfo
->mouse_face_end_col
23739 || dpyinfo
->mouse_face_past_end
));
23742 cursor
= No_Cursor
;
23744 /* Check mouse-face highlighting. */
23746 /* If there exists an overlay with mouse-face overlapping
23747 the one we are currently highlighting, we have to
23748 check if we enter the overlapping overlay, and then
23749 highlight only that. */
23750 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23751 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23753 /* Find the highest priority overlay with a mouse-face. */
23755 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23757 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23758 if (!NILP (mouse_face
))
23759 overlay
= overlay_vec
[i
];
23762 /* If we're highlighting the same overlay as before, there's
23763 no need to do that again. */
23764 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23765 goto check_help_echo
;
23766 dpyinfo
->mouse_face_overlay
= overlay
;
23768 /* Clear the display of the old active region, if any. */
23769 if (clear_mouse_face (dpyinfo
))
23770 cursor
= No_Cursor
;
23772 /* If no overlay applies, get a text property. */
23773 if (NILP (overlay
))
23774 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23776 /* Next, compute the bounds of the mouse highlighting and
23778 if (!NILP (mouse_face
) && STRINGP (object
))
23780 /* The mouse-highlighting comes from a display string
23781 with a mouse-face. */
23785 b
= Fprevious_single_property_change
23786 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
23787 e
= Fnext_single_property_change
23788 (position
, Qmouse_face
, object
, Qnil
);
23790 b
= make_number (0);
23792 e
= make_number (SCHARS (object
) - 1);
23794 fast_find_string_pos (w
, XINT (b
), object
,
23795 &dpyinfo
->mouse_face_beg_col
,
23796 &dpyinfo
->mouse_face_beg_row
,
23797 &dpyinfo
->mouse_face_beg_x
,
23798 &dpyinfo
->mouse_face_beg_y
, 0);
23799 fast_find_string_pos (w
, XINT (e
), object
,
23800 &dpyinfo
->mouse_face_end_col
,
23801 &dpyinfo
->mouse_face_end_row
,
23802 &dpyinfo
->mouse_face_end_x
,
23803 &dpyinfo
->mouse_face_end_y
, 1);
23804 dpyinfo
->mouse_face_past_end
= 0;
23805 dpyinfo
->mouse_face_window
= window
;
23806 dpyinfo
->mouse_face_face_id
23807 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23808 glyph
->face_id
, 1);
23809 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23810 cursor
= No_Cursor
;
23814 /* The mouse-highlighting, if any, comes from an overlay
23815 or text property in the buffer. */
23816 Lisp_Object buffer
, display_string
;
23818 if (STRINGP (object
))
23820 /* If we are on a display string with no mouse-face,
23821 check if the text under it has one. */
23822 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23823 int start
= MATRIX_ROW_START_CHARPOS (r
);
23824 pos
= string_buffer_position (w
, object
, start
);
23827 mouse_face
= get_char_property_and_overlay
23828 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
23829 buffer
= w
->buffer
;
23830 display_string
= object
;
23836 display_string
= Qnil
;
23839 if (!NILP (mouse_face
))
23841 Lisp_Object before
, after
;
23842 Lisp_Object before_string
, after_string
;
23844 if (NILP (overlay
))
23846 /* Handle the text property case. */
23847 before
= Fprevious_single_property_change
23848 (make_number (pos
+ 1), Qmouse_face
, buffer
,
23849 Fmarker_position (w
->start
));
23850 after
= Fnext_single_property_change
23851 (make_number (pos
), Qmouse_face
, buffer
,
23852 make_number (BUF_Z (XBUFFER (buffer
))
23853 - XFASTINT (w
->window_end_pos
)));
23854 before_string
= after_string
= Qnil
;
23858 /* Handle the overlay case. */
23859 before
= Foverlay_start (overlay
);
23860 after
= Foverlay_end (overlay
);
23861 before_string
= Foverlay_get (overlay
, Qbefore_string
);
23862 after_string
= Foverlay_get (overlay
, Qafter_string
);
23864 if (!STRINGP (before_string
)) before_string
= Qnil
;
23865 if (!STRINGP (after_string
)) after_string
= Qnil
;
23868 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
23871 before_string
, after_string
,
23873 cursor
= No_Cursor
;
23880 /* Look for a `help-echo' property. */
23881 if (NILP (help_echo_string
)) {
23882 Lisp_Object help
, overlay
;
23884 /* Check overlays first. */
23885 help
= overlay
= Qnil
;
23886 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23888 overlay
= overlay_vec
[i
];
23889 help
= Foverlay_get (overlay
, Qhelp_echo
);
23894 help_echo_string
= help
;
23895 help_echo_window
= window
;
23896 help_echo_object
= overlay
;
23897 help_echo_pos
= pos
;
23901 Lisp_Object object
= glyph
->object
;
23902 int charpos
= glyph
->charpos
;
23904 /* Try text properties. */
23905 if (STRINGP (object
)
23907 && charpos
< SCHARS (object
))
23909 help
= Fget_text_property (make_number (charpos
),
23910 Qhelp_echo
, object
);
23913 /* If the string itself doesn't specify a help-echo,
23914 see if the buffer text ``under'' it does. */
23915 struct glyph_row
*r
23916 = MATRIX_ROW (w
->current_matrix
, vpos
);
23917 int start
= MATRIX_ROW_START_CHARPOS (r
);
23918 int pos
= string_buffer_position (w
, object
, start
);
23921 help
= Fget_char_property (make_number (pos
),
23922 Qhelp_echo
, w
->buffer
);
23926 object
= w
->buffer
;
23931 else if (BUFFERP (object
)
23934 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23939 help_echo_string
= help
;
23940 help_echo_window
= window
;
23941 help_echo_object
= object
;
23942 help_echo_pos
= charpos
;
23947 /* Look for a `pointer' property. */
23948 if (NILP (pointer
))
23950 /* Check overlays first. */
23951 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23952 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23954 if (NILP (pointer
))
23956 Lisp_Object object
= glyph
->object
;
23957 int charpos
= glyph
->charpos
;
23959 /* Try text properties. */
23960 if (STRINGP (object
)
23962 && charpos
< SCHARS (object
))
23964 pointer
= Fget_text_property (make_number (charpos
),
23966 if (NILP (pointer
))
23968 /* If the string itself doesn't specify a pointer,
23969 see if the buffer text ``under'' it does. */
23970 struct glyph_row
*r
23971 = MATRIX_ROW (w
->current_matrix
, vpos
);
23972 int start
= MATRIX_ROW_START_CHARPOS (r
);
23973 int pos
= string_buffer_position (w
, object
, start
);
23975 pointer
= Fget_char_property (make_number (pos
),
23976 Qpointer
, w
->buffer
);
23979 else if (BUFFERP (object
)
23982 pointer
= Fget_text_property (make_number (charpos
),
23989 current_buffer
= obuf
;
23994 define_frame_cursor1 (f
, cursor
, pointer
);
23999 Clear any mouse-face on window W. This function is part of the
24000 redisplay interface, and is called from try_window_id and similar
24001 functions to ensure the mouse-highlight is off. */
24004 x_clear_window_mouse_face (w
)
24007 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24008 Lisp_Object window
;
24011 XSETWINDOW (window
, w
);
24012 if (EQ (window
, dpyinfo
->mouse_face_window
))
24013 clear_mouse_face (dpyinfo
);
24019 Just discard the mouse face information for frame F, if any.
24020 This is used when the size of F is changed. */
24023 cancel_mouse_face (f
)
24026 Lisp_Object window
;
24027 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24029 window
= dpyinfo
->mouse_face_window
;
24030 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24032 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24033 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24034 dpyinfo
->mouse_face_window
= Qnil
;
24039 #endif /* HAVE_WINDOW_SYSTEM */
24042 /***********************************************************************
24044 ***********************************************************************/
24046 #ifdef HAVE_WINDOW_SYSTEM
24048 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24049 which intersects rectangle R. R is in window-relative coordinates. */
24052 expose_area (w
, row
, r
, area
)
24054 struct glyph_row
*row
;
24056 enum glyph_row_area area
;
24058 struct glyph
*first
= row
->glyphs
[area
];
24059 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24060 struct glyph
*last
;
24061 int first_x
, start_x
, x
;
24063 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24064 /* If row extends face to end of line write the whole line. */
24065 draw_glyphs (w
, 0, row
, area
,
24066 0, row
->used
[area
],
24067 DRAW_NORMAL_TEXT
, 0);
24070 /* Set START_X to the window-relative start position for drawing glyphs of
24071 AREA. The first glyph of the text area can be partially visible.
24072 The first glyphs of other areas cannot. */
24073 start_x
= window_box_left_offset (w
, area
);
24075 if (area
== TEXT_AREA
)
24078 /* Find the first glyph that must be redrawn. */
24080 && x
+ first
->pixel_width
< r
->x
)
24082 x
+= first
->pixel_width
;
24086 /* Find the last one. */
24090 && x
< r
->x
+ r
->width
)
24092 x
+= last
->pixel_width
;
24098 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24099 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24100 DRAW_NORMAL_TEXT
, 0);
24105 /* Redraw the parts of the glyph row ROW on window W intersecting
24106 rectangle R. R is in window-relative coordinates. Value is
24107 non-zero if mouse-face was overwritten. */
24110 expose_line (w
, row
, r
)
24112 struct glyph_row
*row
;
24115 xassert (row
->enabled_p
);
24117 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24118 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24119 0, row
->used
[TEXT_AREA
],
24120 DRAW_NORMAL_TEXT
, 0);
24123 if (row
->used
[LEFT_MARGIN_AREA
])
24124 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24125 if (row
->used
[TEXT_AREA
])
24126 expose_area (w
, row
, r
, TEXT_AREA
);
24127 if (row
->used
[RIGHT_MARGIN_AREA
])
24128 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24129 draw_row_fringe_bitmaps (w
, row
);
24132 return row
->mouse_face_p
;
24136 /* Redraw those parts of glyphs rows during expose event handling that
24137 overlap other rows. Redrawing of an exposed line writes over parts
24138 of lines overlapping that exposed line; this function fixes that.
24140 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24141 row in W's current matrix that is exposed and overlaps other rows.
24142 LAST_OVERLAPPING_ROW is the last such row. */
24145 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24147 struct glyph_row
*first_overlapping_row
;
24148 struct glyph_row
*last_overlapping_row
;
24151 struct glyph_row
*row
;
24153 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24154 if (row
->overlapping_p
)
24156 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24159 if (row
->used
[LEFT_MARGIN_AREA
])
24160 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24162 if (row
->used
[TEXT_AREA
])
24163 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24165 if (row
->used
[RIGHT_MARGIN_AREA
])
24166 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24172 /* Return non-zero if W's cursor intersects rectangle R. */
24175 phys_cursor_in_rect_p (w
, r
)
24179 XRectangle cr
, result
;
24180 struct glyph
*cursor_glyph
;
24181 struct glyph_row
*row
;
24183 if (w
->phys_cursor
.vpos
>= 0
24184 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24185 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24187 && row
->cursor_in_fringe_p
)
24189 /* Cursor is in the fringe. */
24190 cr
.x
= window_box_right_offset (w
,
24191 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24192 ? RIGHT_MARGIN_AREA
24195 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24196 cr
.height
= row
->height
;
24197 return x_intersect_rectangles (&cr
, r
, &result
);
24200 cursor_glyph
= get_phys_cursor_glyph (w
);
24203 /* r is relative to W's box, but w->phys_cursor.x is relative
24204 to left edge of W's TEXT area. Adjust it. */
24205 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24206 cr
.y
= w
->phys_cursor
.y
;
24207 cr
.width
= cursor_glyph
->pixel_width
;
24208 cr
.height
= w
->phys_cursor_height
;
24209 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24210 I assume the effect is the same -- and this is portable. */
24211 return x_intersect_rectangles (&cr
, r
, &result
);
24213 /* If we don't understand the format, pretend we're not in the hot-spot. */
24219 Draw a vertical window border to the right of window W if W doesn't
24220 have vertical scroll bars. */
24223 x_draw_vertical_border (w
)
24226 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24228 /* We could do better, if we knew what type of scroll-bar the adjacent
24229 windows (on either side) have... But we don't :-(
24230 However, I think this works ok. ++KFS 2003-04-25 */
24232 /* Redraw borders between horizontally adjacent windows. Don't
24233 do it for frames with vertical scroll bars because either the
24234 right scroll bar of a window, or the left scroll bar of its
24235 neighbor will suffice as a border. */
24236 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24239 if (!WINDOW_RIGHTMOST_P (w
)
24240 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24242 int x0
, x1
, y0
, y1
;
24244 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24247 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24250 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24252 else if (!WINDOW_LEFTMOST_P (w
)
24253 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24255 int x0
, x1
, y0
, y1
;
24257 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24260 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24263 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24268 /* Redraw the part of window W intersection rectangle FR. Pixel
24269 coordinates in FR are frame-relative. Call this function with
24270 input blocked. Value is non-zero if the exposure overwrites
24274 expose_window (w
, fr
)
24278 struct frame
*f
= XFRAME (w
->frame
);
24280 int mouse_face_overwritten_p
= 0;
24282 /* If window is not yet fully initialized, do nothing. This can
24283 happen when toolkit scroll bars are used and a window is split.
24284 Reconfiguring the scroll bar will generate an expose for a newly
24286 if (w
->current_matrix
== NULL
)
24289 /* When we're currently updating the window, display and current
24290 matrix usually don't agree. Arrange for a thorough display
24292 if (w
== updated_window
)
24294 SET_FRAME_GARBAGED (f
);
24298 /* Frame-relative pixel rectangle of W. */
24299 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24300 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24301 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24302 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24304 if (x_intersect_rectangles (fr
, &wr
, &r
))
24306 int yb
= window_text_bottom_y (w
);
24307 struct glyph_row
*row
;
24308 int cursor_cleared_p
;
24309 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24311 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24312 r
.x
, r
.y
, r
.width
, r
.height
));
24314 /* Convert to window coordinates. */
24315 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24316 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24318 /* Turn off the cursor. */
24319 if (!w
->pseudo_window_p
24320 && phys_cursor_in_rect_p (w
, &r
))
24322 x_clear_cursor (w
);
24323 cursor_cleared_p
= 1;
24326 cursor_cleared_p
= 0;
24328 /* Update lines intersecting rectangle R. */
24329 first_overlapping_row
= last_overlapping_row
= NULL
;
24330 for (row
= w
->current_matrix
->rows
;
24335 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24337 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24338 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24339 || (r
.y
>= y0
&& r
.y
< y1
)
24340 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24342 /* A header line may be overlapping, but there is no need
24343 to fix overlapping areas for them. KFS 2005-02-12 */
24344 if (row
->overlapping_p
&& !row
->mode_line_p
)
24346 if (first_overlapping_row
== NULL
)
24347 first_overlapping_row
= row
;
24348 last_overlapping_row
= row
;
24352 if (expose_line (w
, row
, &r
))
24353 mouse_face_overwritten_p
= 1;
24356 else if (row
->overlapping_p
)
24358 /* We must redraw a row overlapping the exposed area. */
24360 ? y0
+ row
->phys_height
> r
.y
24361 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24363 if (first_overlapping_row
== NULL
)
24364 first_overlapping_row
= row
;
24365 last_overlapping_row
= row
;
24373 /* Display the mode line if there is one. */
24374 if (WINDOW_WANTS_MODELINE_P (w
)
24375 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24377 && row
->y
< r
.y
+ r
.height
)
24379 if (expose_line (w
, row
, &r
))
24380 mouse_face_overwritten_p
= 1;
24383 if (!w
->pseudo_window_p
)
24385 /* Fix the display of overlapping rows. */
24386 if (first_overlapping_row
)
24387 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24390 /* Draw border between windows. */
24391 x_draw_vertical_border (w
);
24393 /* Turn the cursor on again. */
24394 if (cursor_cleared_p
)
24395 update_window_cursor (w
, 1);
24399 return mouse_face_overwritten_p
;
24404 /* Redraw (parts) of all windows in the window tree rooted at W that
24405 intersect R. R contains frame pixel coordinates. Value is
24406 non-zero if the exposure overwrites mouse-face. */
24409 expose_window_tree (w
, r
)
24413 struct frame
*f
= XFRAME (w
->frame
);
24414 int mouse_face_overwritten_p
= 0;
24416 while (w
&& !FRAME_GARBAGED_P (f
))
24418 if (!NILP (w
->hchild
))
24419 mouse_face_overwritten_p
24420 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24421 else if (!NILP (w
->vchild
))
24422 mouse_face_overwritten_p
24423 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24425 mouse_face_overwritten_p
|= expose_window (w
, r
);
24427 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24430 return mouse_face_overwritten_p
;
24435 Redisplay an exposed area of frame F. X and Y are the upper-left
24436 corner of the exposed rectangle. W and H are width and height of
24437 the exposed area. All are pixel values. W or H zero means redraw
24438 the entire frame. */
24441 expose_frame (f
, x
, y
, w
, h
)
24446 int mouse_face_overwritten_p
= 0;
24448 TRACE ((stderr
, "expose_frame "));
24450 /* No need to redraw if frame will be redrawn soon. */
24451 if (FRAME_GARBAGED_P (f
))
24453 TRACE ((stderr
, " garbaged\n"));
24457 /* If basic faces haven't been realized yet, there is no point in
24458 trying to redraw anything. This can happen when we get an expose
24459 event while Emacs is starting, e.g. by moving another window. */
24460 if (FRAME_FACE_CACHE (f
) == NULL
24461 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24463 TRACE ((stderr
, " no faces\n"));
24467 if (w
== 0 || h
== 0)
24470 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24471 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24481 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24482 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24484 if (WINDOWP (f
->tool_bar_window
))
24485 mouse_face_overwritten_p
24486 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24488 #ifdef HAVE_X_WINDOWS
24490 #ifndef USE_X_TOOLKIT
24491 if (WINDOWP (f
->menu_bar_window
))
24492 mouse_face_overwritten_p
24493 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24494 #endif /* not USE_X_TOOLKIT */
24498 /* Some window managers support a focus-follows-mouse style with
24499 delayed raising of frames. Imagine a partially obscured frame,
24500 and moving the mouse into partially obscured mouse-face on that
24501 frame. The visible part of the mouse-face will be highlighted,
24502 then the WM raises the obscured frame. With at least one WM, KDE
24503 2.1, Emacs is not getting any event for the raising of the frame
24504 (even tried with SubstructureRedirectMask), only Expose events.
24505 These expose events will draw text normally, i.e. not
24506 highlighted. Which means we must redo the highlight here.
24507 Subsume it under ``we love X''. --gerd 2001-08-15 */
24508 /* Included in Windows version because Windows most likely does not
24509 do the right thing if any third party tool offers
24510 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24511 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24513 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24514 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24516 int x
= dpyinfo
->mouse_face_mouse_x
;
24517 int y
= dpyinfo
->mouse_face_mouse_y
;
24518 clear_mouse_face (dpyinfo
);
24519 note_mouse_highlight (f
, x
, y
);
24526 Determine the intersection of two rectangles R1 and R2. Return
24527 the intersection in *RESULT. Value is non-zero if RESULT is not
24531 x_intersect_rectangles (r1
, r2
, result
)
24532 XRectangle
*r1
, *r2
, *result
;
24534 XRectangle
*left
, *right
;
24535 XRectangle
*upper
, *lower
;
24536 int intersection_p
= 0;
24538 /* Rearrange so that R1 is the left-most rectangle. */
24540 left
= r1
, right
= r2
;
24542 left
= r2
, right
= r1
;
24544 /* X0 of the intersection is right.x0, if this is inside R1,
24545 otherwise there is no intersection. */
24546 if (right
->x
<= left
->x
+ left
->width
)
24548 result
->x
= right
->x
;
24550 /* The right end of the intersection is the minimum of the
24551 the right ends of left and right. */
24552 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24555 /* Same game for Y. */
24557 upper
= r1
, lower
= r2
;
24559 upper
= r2
, lower
= r1
;
24561 /* The upper end of the intersection is lower.y0, if this is inside
24562 of upper. Otherwise, there is no intersection. */
24563 if (lower
->y
<= upper
->y
+ upper
->height
)
24565 result
->y
= lower
->y
;
24567 /* The lower end of the intersection is the minimum of the lower
24568 ends of upper and lower. */
24569 result
->height
= (min (lower
->y
+ lower
->height
,
24570 upper
->y
+ upper
->height
)
24572 intersection_p
= 1;
24576 return intersection_p
;
24579 #endif /* HAVE_WINDOW_SYSTEM */
24582 /***********************************************************************
24584 ***********************************************************************/
24589 Vwith_echo_area_save_vector
= Qnil
;
24590 staticpro (&Vwith_echo_area_save_vector
);
24592 Vmessage_stack
= Qnil
;
24593 staticpro (&Vmessage_stack
);
24595 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24596 staticpro (&Qinhibit_redisplay
);
24598 message_dolog_marker1
= Fmake_marker ();
24599 staticpro (&message_dolog_marker1
);
24600 message_dolog_marker2
= Fmake_marker ();
24601 staticpro (&message_dolog_marker2
);
24602 message_dolog_marker3
= Fmake_marker ();
24603 staticpro (&message_dolog_marker3
);
24606 defsubr (&Sdump_frame_glyph_matrix
);
24607 defsubr (&Sdump_glyph_matrix
);
24608 defsubr (&Sdump_glyph_row
);
24609 defsubr (&Sdump_tool_bar_row
);
24610 defsubr (&Strace_redisplay
);
24611 defsubr (&Strace_to_stderr
);
24613 #ifdef HAVE_WINDOW_SYSTEM
24614 defsubr (&Stool_bar_lines_needed
);
24615 defsubr (&Slookup_image_map
);
24617 defsubr (&Sformat_mode_line
);
24618 defsubr (&Sinvisible_p
);
24620 staticpro (&Qmenu_bar_update_hook
);
24621 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24623 staticpro (&Qoverriding_terminal_local_map
);
24624 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24626 staticpro (&Qoverriding_local_map
);
24627 Qoverriding_local_map
= intern ("overriding-local-map");
24629 staticpro (&Qwindow_scroll_functions
);
24630 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24632 staticpro (&Qwindow_text_change_functions
);
24633 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24635 staticpro (&Qredisplay_end_trigger_functions
);
24636 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24638 staticpro (&Qinhibit_point_motion_hooks
);
24639 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24641 Qeval
= intern ("eval");
24642 staticpro (&Qeval
);
24644 QCdata
= intern (":data");
24645 staticpro (&QCdata
);
24646 Qdisplay
= intern ("display");
24647 staticpro (&Qdisplay
);
24648 Qspace_width
= intern ("space-width");
24649 staticpro (&Qspace_width
);
24650 Qraise
= intern ("raise");
24651 staticpro (&Qraise
);
24652 Qslice
= intern ("slice");
24653 staticpro (&Qslice
);
24654 Qspace
= intern ("space");
24655 staticpro (&Qspace
);
24656 Qmargin
= intern ("margin");
24657 staticpro (&Qmargin
);
24658 Qpointer
= intern ("pointer");
24659 staticpro (&Qpointer
);
24660 Qleft_margin
= intern ("left-margin");
24661 staticpro (&Qleft_margin
);
24662 Qright_margin
= intern ("right-margin");
24663 staticpro (&Qright_margin
);
24664 Qcenter
= intern ("center");
24665 staticpro (&Qcenter
);
24666 Qline_height
= intern ("line-height");
24667 staticpro (&Qline_height
);
24668 QCalign_to
= intern (":align-to");
24669 staticpro (&QCalign_to
);
24670 QCrelative_width
= intern (":relative-width");
24671 staticpro (&QCrelative_width
);
24672 QCrelative_height
= intern (":relative-height");
24673 staticpro (&QCrelative_height
);
24674 QCeval
= intern (":eval");
24675 staticpro (&QCeval
);
24676 QCpropertize
= intern (":propertize");
24677 staticpro (&QCpropertize
);
24678 QCfile
= intern (":file");
24679 staticpro (&QCfile
);
24680 Qfontified
= intern ("fontified");
24681 staticpro (&Qfontified
);
24682 Qfontification_functions
= intern ("fontification-functions");
24683 staticpro (&Qfontification_functions
);
24684 Qtrailing_whitespace
= intern ("trailing-whitespace");
24685 staticpro (&Qtrailing_whitespace
);
24686 Qescape_glyph
= intern ("escape-glyph");
24687 staticpro (&Qescape_glyph
);
24688 Qnobreak_space
= intern ("nobreak-space");
24689 staticpro (&Qnobreak_space
);
24690 Qimage
= intern ("image");
24691 staticpro (&Qimage
);
24692 QCmap
= intern (":map");
24693 staticpro (&QCmap
);
24694 QCpointer
= intern (":pointer");
24695 staticpro (&QCpointer
);
24696 Qrect
= intern ("rect");
24697 staticpro (&Qrect
);
24698 Qcircle
= intern ("circle");
24699 staticpro (&Qcircle
);
24700 Qpoly
= intern ("poly");
24701 staticpro (&Qpoly
);
24702 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24703 staticpro (&Qmessage_truncate_lines
);
24704 Qgrow_only
= intern ("grow-only");
24705 staticpro (&Qgrow_only
);
24706 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24707 staticpro (&Qinhibit_menubar_update
);
24708 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24709 staticpro (&Qinhibit_eval_during_redisplay
);
24710 Qposition
= intern ("position");
24711 staticpro (&Qposition
);
24712 Qbuffer_position
= intern ("buffer-position");
24713 staticpro (&Qbuffer_position
);
24714 Qobject
= intern ("object");
24715 staticpro (&Qobject
);
24716 Qbar
= intern ("bar");
24718 Qhbar
= intern ("hbar");
24719 staticpro (&Qhbar
);
24720 Qbox
= intern ("box");
24722 Qhollow
= intern ("hollow");
24723 staticpro (&Qhollow
);
24724 Qhand
= intern ("hand");
24725 staticpro (&Qhand
);
24726 Qarrow
= intern ("arrow");
24727 staticpro (&Qarrow
);
24728 Qtext
= intern ("text");
24729 staticpro (&Qtext
);
24730 Qrisky_local_variable
= intern ("risky-local-variable");
24731 staticpro (&Qrisky_local_variable
);
24732 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24733 staticpro (&Qinhibit_free_realized_faces
);
24735 list_of_error
= Fcons (Fcons (intern ("error"),
24736 Fcons (intern ("void-variable"), Qnil
)),
24738 staticpro (&list_of_error
);
24740 Qlast_arrow_position
= intern ("last-arrow-position");
24741 staticpro (&Qlast_arrow_position
);
24742 Qlast_arrow_string
= intern ("last-arrow-string");
24743 staticpro (&Qlast_arrow_string
);
24745 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24746 staticpro (&Qoverlay_arrow_string
);
24747 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24748 staticpro (&Qoverlay_arrow_bitmap
);
24750 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24751 staticpro (&echo_buffer
[0]);
24752 staticpro (&echo_buffer
[1]);
24754 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24755 staticpro (&echo_area_buffer
[0]);
24756 staticpro (&echo_area_buffer
[1]);
24758 Vmessages_buffer_name
= build_string ("*Messages*");
24759 staticpro (&Vmessages_buffer_name
);
24761 mode_line_proptrans_alist
= Qnil
;
24762 staticpro (&mode_line_proptrans_alist
);
24763 mode_line_string_list
= Qnil
;
24764 staticpro (&mode_line_string_list
);
24765 mode_line_string_face
= Qnil
;
24766 staticpro (&mode_line_string_face
);
24767 mode_line_string_face_prop
= Qnil
;
24768 staticpro (&mode_line_string_face_prop
);
24769 Vmode_line_unwind_vector
= Qnil
;
24770 staticpro (&Vmode_line_unwind_vector
);
24772 help_echo_string
= Qnil
;
24773 staticpro (&help_echo_string
);
24774 help_echo_object
= Qnil
;
24775 staticpro (&help_echo_object
);
24776 help_echo_window
= Qnil
;
24777 staticpro (&help_echo_window
);
24778 previous_help_echo_string
= Qnil
;
24779 staticpro (&previous_help_echo_string
);
24780 help_echo_pos
= -1;
24782 #ifdef HAVE_WINDOW_SYSTEM
24783 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24784 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24785 For example, if a block cursor is over a tab, it will be drawn as
24786 wide as that tab on the display. */);
24787 x_stretch_cursor_p
= 0;
24790 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24791 doc
: /* *Non-nil means highlight trailing whitespace.
24792 The face used for trailing whitespace is `trailing-whitespace'. */);
24793 Vshow_trailing_whitespace
= Qnil
;
24795 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24796 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24797 A value of t means highlight the character itself (for nobreak space,
24798 use face `nobreak-space').
24799 A value of nil means no highlighting.
24800 Other values mean display the escape glyph followed by an ordinary
24801 space or ordinary hyphen. */);
24802 Vnobreak_char_display
= Qt
;
24804 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24805 doc
: /* *The pointer shape to show in void text areas.
24806 A value of nil means to show the text pointer. Other options are `arrow',
24807 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24808 Vvoid_text_area_pointer
= Qarrow
;
24810 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24811 doc
: /* Non-nil means don't actually do any redisplay.
24812 This is used for internal purposes. */);
24813 Vinhibit_redisplay
= Qnil
;
24815 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24816 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24817 Vglobal_mode_string
= Qnil
;
24819 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24820 doc
: /* Marker for where to display an arrow on top of the buffer text.
24821 This must be the beginning of a line in order to work.
24822 See also `overlay-arrow-string'. */);
24823 Voverlay_arrow_position
= Qnil
;
24825 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24826 doc
: /* String to display as an arrow in non-window frames.
24827 See also `overlay-arrow-position'. */);
24828 Voverlay_arrow_string
= build_string ("=>");
24830 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24831 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24832 The symbols on this list are examined during redisplay to determine
24833 where to display overlay arrows. */);
24834 Voverlay_arrow_variable_list
24835 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24837 DEFVAR_INT ("scroll-step", &scroll_step
,
24838 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24839 If that fails to bring point back on frame, point is centered instead.
24840 If this is zero, point is always centered after it moves off frame.
24841 If you want scrolling to always be a line at a time, you should set
24842 `scroll-conservatively' to a large value rather than set this to 1. */);
24844 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24845 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24846 If point moves off-screen, redisplay will scroll by up to
24847 `scroll-conservatively' lines in order to bring point just barely
24848 onto the screen again. If that cannot be done, then redisplay
24849 recenters point as usual.
24851 A value of zero means always recenter point if it moves off screen. */);
24852 scroll_conservatively
= 0;
24854 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24855 doc
: /* *Number of lines of margin at the top and bottom of a window.
24856 Recenter the window whenever point gets within this many lines
24857 of the top or bottom of the window. */);
24860 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24861 doc
: /* Pixels per inch value for non-window system displays.
24862 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24863 Vdisplay_pixels_per_inch
= make_float (72.0);
24866 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24869 DEFVAR_LISP ("truncate-partial-width-windows",
24870 &Vtruncate_partial_width_windows
,
24871 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
24872 For an integer value, truncate lines in each window narrower than the
24873 full frame width, provided the window width is less than that integer;
24874 otherwise, respect the value of `truncate-lines'.
24876 For any other non-nil value, truncate lines in all windows that do
24877 not span the full frame width.
24879 A value of nil means to respect the value of `truncate-lines'.
24881 If `word-wrap' is enabled, you might want to reduce this. */);
24882 Vtruncate_partial_width_windows
= make_number (50);
24884 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24885 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24886 Any other value means to use the appropriate face, `mode-line',
24887 `header-line', or `menu' respectively. */);
24888 mode_line_inverse_video
= 1;
24890 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24891 doc
: /* *Maximum buffer size for which line number should be displayed.
24892 If the buffer is bigger than this, the line number does not appear
24893 in the mode line. A value of nil means no limit. */);
24894 Vline_number_display_limit
= Qnil
;
24896 DEFVAR_INT ("line-number-display-limit-width",
24897 &line_number_display_limit_width
,
24898 doc
: /* *Maximum line width (in characters) for line number display.
24899 If the average length of the lines near point is bigger than this, then the
24900 line number may be omitted from the mode line. */);
24901 line_number_display_limit_width
= 200;
24903 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24904 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24905 highlight_nonselected_windows
= 0;
24907 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24908 doc
: /* Non-nil if more than one frame is visible on this display.
24909 Minibuffer-only frames don't count, but iconified frames do.
24910 This variable is not guaranteed to be accurate except while processing
24911 `frame-title-format' and `icon-title-format'. */);
24913 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24914 doc
: /* Template for displaying the title bar of visible frames.
24915 \(Assuming the window manager supports this feature.)
24917 This variable has the same structure as `mode-line-format', except that
24918 the %c and %l constructs are ignored. It is used only on frames for
24919 which no explicit name has been set \(see `modify-frame-parameters'). */);
24921 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24922 doc
: /* Template for displaying the title bar of an iconified frame.
24923 \(Assuming the window manager supports this feature.)
24924 This variable has the same structure as `mode-line-format' (which see),
24925 and is used only on frames for which no explicit name has been set
24926 \(see `modify-frame-parameters'). */);
24928 = Vframe_title_format
24929 = Fcons (intern ("multiple-frames"),
24930 Fcons (build_string ("%b"),
24931 Fcons (Fcons (empty_unibyte_string
,
24932 Fcons (intern ("invocation-name"),
24933 Fcons (build_string ("@"),
24934 Fcons (intern ("system-name"),
24938 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24939 doc
: /* Maximum number of lines to keep in the message log buffer.
24940 If nil, disable message logging. If t, log messages but don't truncate
24941 the buffer when it becomes large. */);
24942 Vmessage_log_max
= make_number (100);
24944 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24945 doc
: /* Functions called before redisplay, if window sizes have changed.
24946 The value should be a list of functions that take one argument.
24947 Just before redisplay, for each frame, if any of its windows have changed
24948 size since the last redisplay, or have been split or deleted,
24949 all the functions in the list are called, with the frame as argument. */);
24950 Vwindow_size_change_functions
= Qnil
;
24952 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24953 doc
: /* List of functions to call before redisplaying a window with scrolling.
24954 Each function is called with two arguments, the window and its new
24955 display-start position. Note that these functions are also called by
24956 `set-window-buffer'. Also note that the value of `window-end' is not
24957 valid when these functions are called. */);
24958 Vwindow_scroll_functions
= Qnil
;
24960 DEFVAR_LISP ("window-text-change-functions",
24961 &Vwindow_text_change_functions
,
24962 doc
: /* Functions to call in redisplay when text in the window might change. */);
24963 Vwindow_text_change_functions
= Qnil
;
24965 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24966 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24967 Each function is called with two arguments, the window and the end trigger value.
24968 See `set-window-redisplay-end-trigger'. */);
24969 Vredisplay_end_trigger_functions
= Qnil
;
24971 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24972 doc
: /* *Non-nil means autoselect window with mouse pointer.
24973 If nil, do not autoselect windows.
24974 A positive number means delay autoselection by that many seconds: a
24975 window is autoselected only after the mouse has remained in that
24976 window for the duration of the delay.
24977 A negative number has a similar effect, but causes windows to be
24978 autoselected only after the mouse has stopped moving. \(Because of
24979 the way Emacs compares mouse events, you will occasionally wait twice
24980 that time before the window gets selected.\)
24981 Any other value means to autoselect window instantaneously when the
24982 mouse pointer enters it.
24984 Autoselection selects the minibuffer only if it is active, and never
24985 unselects the minibuffer if it is active.
24987 When customizing this variable make sure that the actual value of
24988 `focus-follows-mouse' matches the behavior of your window manager. */);
24989 Vmouse_autoselect_window
= Qnil
;
24991 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24992 doc
: /* *Non-nil means automatically resize tool-bars.
24993 This dynamically changes the tool-bar's height to the minimum height
24994 that is needed to make all tool-bar items visible.
24995 If value is `grow-only', the tool-bar's height is only increased
24996 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24997 Vauto_resize_tool_bars
= Qt
;
24999 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25000 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25001 auto_raise_tool_bar_buttons_p
= 1;
25003 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25004 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25005 make_cursor_line_fully_visible_p
= 1;
25007 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25008 doc
: /* *Border below tool-bar in pixels.
25009 If an integer, use it as the height of the border.
25010 If it is one of `internal-border-width' or `border-width', use the
25011 value of the corresponding frame parameter.
25012 Otherwise, no border is added below the tool-bar. */);
25013 Vtool_bar_border
= Qinternal_border_width
;
25015 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25016 doc
: /* *Margin around tool-bar buttons in pixels.
25017 If an integer, use that for both horizontal and vertical margins.
25018 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25019 HORZ specifying the horizontal margin, and VERT specifying the
25020 vertical margin. */);
25021 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25023 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25024 doc
: /* *Relief thickness of tool-bar buttons. */);
25025 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25027 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25028 doc
: /* List of functions to call to fontify regions of text.
25029 Each function is called with one argument POS. Functions must
25030 fontify a region starting at POS in the current buffer, and give
25031 fontified regions the property `fontified'. */);
25032 Vfontification_functions
= Qnil
;
25033 Fmake_variable_buffer_local (Qfontification_functions
);
25035 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25036 &unibyte_display_via_language_environment
,
25037 doc
: /* *Non-nil means display unibyte text according to language environment.
25038 Specifically this means that unibyte non-ASCII characters
25039 are displayed by converting them to the equivalent multibyte characters
25040 according to the current language environment. As a result, they are
25041 displayed according to the current fontset. */);
25042 unibyte_display_via_language_environment
= 0;
25044 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25045 doc
: /* *Maximum height for resizing mini-windows.
25046 If a float, it specifies a fraction of the mini-window frame's height.
25047 If an integer, it specifies a number of lines. */);
25048 Vmax_mini_window_height
= make_float (0.25);
25050 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25051 doc
: /* *How to resize mini-windows.
25052 A value of nil means don't automatically resize mini-windows.
25053 A value of t means resize them to fit the text displayed in them.
25054 A value of `grow-only', the default, means let mini-windows grow
25055 only, until their display becomes empty, at which point the windows
25056 go back to their normal size. */);
25057 Vresize_mini_windows
= Qgrow_only
;
25059 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25060 doc
: /* Alist specifying how to blink the cursor off.
25061 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25062 `cursor-type' frame-parameter or variable equals ON-STATE,
25063 comparing using `equal', Emacs uses OFF-STATE to specify
25064 how to blink it off. ON-STATE and OFF-STATE are values for
25065 the `cursor-type' frame parameter.
25067 If a frame's ON-STATE has no entry in this list,
25068 the frame's other specifications determine how to blink the cursor off. */);
25069 Vblink_cursor_alist
= Qnil
;
25071 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25072 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25073 automatic_hscrolling_p
= 1;
25074 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
25075 staticpro (&Qauto_hscroll_mode
);
25077 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25078 doc
: /* *How many columns away from the window edge point is allowed to get
25079 before automatic hscrolling will horizontally scroll the window. */);
25080 hscroll_margin
= 5;
25082 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25083 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25084 When point is less than `hscroll-margin' columns from the window
25085 edge, automatic hscrolling will scroll the window by the amount of columns
25086 determined by this variable. If its value is a positive integer, scroll that
25087 many columns. If it's a positive floating-point number, it specifies the
25088 fraction of the window's width to scroll. If it's nil or zero, point will be
25089 centered horizontally after the scroll. Any other value, including negative
25090 numbers, are treated as if the value were zero.
25092 Automatic hscrolling always moves point outside the scroll margin, so if
25093 point was more than scroll step columns inside the margin, the window will
25094 scroll more than the value given by the scroll step.
25096 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25097 and `scroll-right' overrides this variable's effect. */);
25098 Vhscroll_step
= make_number (0);
25100 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25101 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25102 Bind this around calls to `message' to let it take effect. */);
25103 message_truncate_lines
= 0;
25105 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25106 doc
: /* Normal hook run to update the menu bar definitions.
25107 Redisplay runs this hook before it redisplays the menu bar.
25108 This is used to update submenus such as Buffers,
25109 whose contents depend on various data. */);
25110 Vmenu_bar_update_hook
= Qnil
;
25112 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25113 doc
: /* Frame for which we are updating a menu.
25114 The enable predicate for a menu binding should check this variable. */);
25115 Vmenu_updating_frame
= Qnil
;
25117 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25118 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25119 inhibit_menubar_update
= 0;
25121 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25122 doc
: /* Prefix prepended to all continuation lines at display time.
25123 The value may be a string, an image, or a stretch-glyph; it is
25124 interpreted in the same way as the value of a `display' text property.
25126 This variable is overridden by any `wrap-prefix' text or overlay
25129 To add a prefix to non-continuation lines, use `line-prefix'. */);
25130 Vwrap_prefix
= Qnil
;
25131 staticpro (&Qwrap_prefix
);
25132 Qwrap_prefix
= intern ("wrap-prefix");
25133 Fmake_variable_buffer_local (Qwrap_prefix
);
25135 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25136 doc
: /* Prefix prepended to all non-continuation lines at display time.
25137 The value may be a string, an image, or a stretch-glyph; it is
25138 interpreted in the same way as the value of a `display' text property.
25140 This variable is overridden by any `line-prefix' text or overlay
25143 To add a prefix to continuation lines, use `wrap-prefix'. */);
25144 Vline_prefix
= Qnil
;
25145 staticpro (&Qline_prefix
);
25146 Qline_prefix
= intern ("line-prefix");
25147 Fmake_variable_buffer_local (Qline_prefix
);
25149 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25150 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25151 inhibit_eval_during_redisplay
= 0;
25153 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25154 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25155 inhibit_free_realized_faces
= 0;
25158 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25159 doc
: /* Inhibit try_window_id display optimization. */);
25160 inhibit_try_window_id
= 0;
25162 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25163 doc
: /* Inhibit try_window_reusing display optimization. */);
25164 inhibit_try_window_reusing
= 0;
25166 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25167 doc
: /* Inhibit try_cursor_movement display optimization. */);
25168 inhibit_try_cursor_movement
= 0;
25169 #endif /* GLYPH_DEBUG */
25171 DEFVAR_INT ("overline-margin", &overline_margin
,
25172 doc
: /* *Space between overline and text, in pixels.
25173 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25174 margin to the caracter height. */);
25175 overline_margin
= 2;
25177 DEFVAR_INT ("underline-minimum-offset",
25178 &underline_minimum_offset
,
25179 doc
: /* Minimum distance between baseline and underline.
25180 This can improve legibility of underlined text at small font sizes,
25181 particularly when using variable `x-use-underline-position-properties'
25182 with fonts that specify an UNDERLINE_POSITION relatively close to the
25183 baseline. The default value is 1. */);
25184 underline_minimum_offset
= 1;
25186 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25187 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25188 display_hourglass_p
= 1;
25190 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25191 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25192 Value must be an integer or float. */);
25193 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25195 hourglass_atimer
= NULL
;
25196 hourglass_shown_p
= 0;
25200 /* Initialize this module when Emacs starts. */
25205 Lisp_Object root_window
;
25206 struct window
*mini_w
;
25208 current_header_line_height
= current_mode_line_height
= -1;
25210 CHARPOS (this_line_start_pos
) = 0;
25212 mini_w
= XWINDOW (minibuf_window
);
25213 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25215 if (!noninteractive
)
25217 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25220 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25221 set_window_height (root_window
,
25222 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25224 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25225 set_window_height (minibuf_window
, 1, 0);
25227 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25228 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25230 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25231 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25232 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25234 /* The default ellipsis glyphs `...'. */
25235 for (i
= 0; i
< 3; ++i
)
25236 default_invis_vector
[i
] = make_number ('.');
25240 /* Allocate the buffer for frame titles.
25241 Also used for `format-mode-line'. */
25243 mode_line_noprop_buf
= (char *) xmalloc (size
);
25244 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25245 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25246 mode_line_target
= MODE_LINE_DISPLAY
;
25249 help_echo_showing_p
= 0;
25252 /* Since w32 does not support atimers, it defines its own implementation of
25253 the following three functions in w32fns.c. */
25256 /* Platform-independent portion of hourglass implementation. */
25258 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25260 hourglass_started ()
25262 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25265 /* Cancel a currently active hourglass timer, and start a new one. */
25269 #if defined (HAVE_WINDOW_SYSTEM)
25271 int secs
, usecs
= 0;
25273 cancel_hourglass ();
25275 if (INTEGERP (Vhourglass_delay
)
25276 && XINT (Vhourglass_delay
) > 0)
25277 secs
= XFASTINT (Vhourglass_delay
);
25278 else if (FLOATP (Vhourglass_delay
)
25279 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25282 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25283 secs
= XFASTINT (tem
);
25284 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25287 secs
= DEFAULT_HOURGLASS_DELAY
;
25289 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25290 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25291 show_hourglass
, NULL
);
25296 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25299 cancel_hourglass ()
25301 #if defined (HAVE_WINDOW_SYSTEM)
25302 if (hourglass_atimer
)
25304 cancel_atimer (hourglass_atimer
);
25305 hourglass_atimer
= NULL
;
25308 if (hourglass_shown_p
)
25312 #endif /* ! WINDOWSNT */
25314 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25315 (do not change this comment) */