1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
179 #include "character.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
193 #include "blockinput.h"
195 #ifdef HAVE_X_WINDOWS
210 #ifndef FRAME_X_OUTPUT
211 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
214 #define INFINITY 10000000
216 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
217 || defined(HAVE_NS) || defined (USE_GTK)
218 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
219 extern int pending_menu_activation
;
222 extern int interrupt_input
;
223 extern int command_loop_level
;
225 extern Lisp_Object do_mouse_tracking
;
227 extern int minibuffer_auto_raise
;
228 extern Lisp_Object Vminibuffer_list
;
230 extern Lisp_Object Qface
;
231 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
233 extern Lisp_Object Voverriding_local_map
;
234 extern Lisp_Object Voverriding_local_map_menu_flag
;
235 extern Lisp_Object Qmenu_item
;
236 extern Lisp_Object Qwhen
;
237 extern Lisp_Object Qhelp_echo
;
238 extern Lisp_Object Qbefore_string
, Qafter_string
;
240 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
241 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
242 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
243 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
244 Lisp_Object Qinhibit_point_motion_hooks
;
245 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
246 Lisp_Object Qfontified
;
247 Lisp_Object Qgrow_only
;
248 Lisp_Object Qinhibit_eval_during_redisplay
;
249 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
252 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
255 Lisp_Object Qarrow
, Qhand
, Qtext
;
257 Lisp_Object Qrisky_local_variable
;
259 /* Holds the list (error). */
260 Lisp_Object list_of_error
;
262 /* Functions called to fontify regions of text. */
264 Lisp_Object Vfontification_functions
;
265 Lisp_Object Qfontification_functions
;
267 /* Non-nil means automatically select any window when the mouse
268 cursor moves into it. */
269 Lisp_Object Vmouse_autoselect_window
;
271 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
272 Lisp_Object Vline_prefix
, Qline_prefix
;
274 /* Non-zero means draw tool bar buttons raised when the mouse moves
277 int auto_raise_tool_bar_buttons_p
;
279 /* Non-zero means to reposition window if cursor line is only partially visible. */
281 int make_cursor_line_fully_visible_p
;
283 /* Margin below tool bar in pixels. 0 or nil means no margin.
284 If value is `internal-border-width' or `border-width',
285 the corresponding frame parameter is used. */
287 Lisp_Object Vtool_bar_border
;
289 /* Margin around tool bar buttons in pixels. */
291 Lisp_Object Vtool_bar_button_margin
;
293 /* Thickness of shadow to draw around tool bar buttons. */
295 EMACS_INT tool_bar_button_relief
;
297 /* Non-nil means automatically resize tool-bars so that all tool-bar
298 items are visible, and no blank lines remain.
300 If value is `grow-only', only make tool-bar bigger. */
302 Lisp_Object Vauto_resize_tool_bars
;
304 /* Non-zero means draw block and hollow cursor as wide as the glyph
305 under it. For example, if a block cursor is over a tab, it will be
306 drawn as wide as that tab on the display. */
308 int x_stretch_cursor_p
;
310 /* Non-nil means don't actually do any redisplay. */
312 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
314 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
316 int inhibit_eval_during_redisplay
;
318 /* Names of text properties relevant for redisplay. */
320 Lisp_Object Qdisplay
;
321 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
323 /* Symbols used in text property values. */
325 Lisp_Object Vdisplay_pixels_per_inch
;
326 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
327 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
330 Lisp_Object Qmargin
, Qpointer
;
331 Lisp_Object Qline_height
;
332 extern Lisp_Object Qheight
;
333 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
334 extern Lisp_Object Qscroll_bar
;
335 extern Lisp_Object Qcursor
;
337 /* Non-nil means highlight trailing whitespace. */
339 Lisp_Object Vshow_trailing_whitespace
;
341 /* Non-nil means escape non-break space and hyphens. */
343 Lisp_Object Vnobreak_char_display
;
345 #ifdef HAVE_WINDOW_SYSTEM
346 extern Lisp_Object Voverflow_newline_into_fringe
;
348 /* Test if overflow newline into fringe. Called with iterator IT
349 at or past right window margin, and with IT->current_x set. */
351 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
352 (!NILP (Voverflow_newline_into_fringe) \
353 && FRAME_WINDOW_P (it->f) \
354 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
355 && it->current_x == it->last_visible_x \
356 && it->line_wrap != WORD_WRAP)
358 #else /* !HAVE_WINDOW_SYSTEM */
359 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
360 #endif /* HAVE_WINDOW_SYSTEM */
362 /* Test if the display element loaded in IT is a space or tab
363 character. This is used to determine word wrapping. */
365 #define IT_DISPLAYING_WHITESPACE(it) \
366 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
368 /* Non-nil means show the text cursor in void text areas
369 i.e. in blank areas after eol and eob. This used to be
370 the default in 21.3. */
372 Lisp_Object Vvoid_text_area_pointer
;
374 /* Name of the face used to highlight trailing whitespace. */
376 Lisp_Object Qtrailing_whitespace
;
378 /* Name and number of the face used to highlight escape glyphs. */
380 Lisp_Object Qescape_glyph
;
382 /* Name and number of the face used to highlight non-breaking spaces. */
384 Lisp_Object Qnobreak_space
;
386 /* The symbol `image' which is the car of the lists used to represent
391 /* The image map types. */
392 Lisp_Object QCmap
, QCpointer
;
393 Lisp_Object Qrect
, Qcircle
, Qpoly
;
395 /* Non-zero means print newline to stdout before next mini-buffer
398 int noninteractive_need_newline
;
400 /* Non-zero means print newline to message log before next message. */
402 static int message_log_need_newline
;
404 /* Three markers that message_dolog uses.
405 It could allocate them itself, but that causes trouble
406 in handling memory-full errors. */
407 static Lisp_Object message_dolog_marker1
;
408 static Lisp_Object message_dolog_marker2
;
409 static Lisp_Object message_dolog_marker3
;
411 /* The buffer position of the first character appearing entirely or
412 partially on the line of the selected window which contains the
413 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
414 redisplay optimization in redisplay_internal. */
416 static struct text_pos this_line_start_pos
;
418 /* Number of characters past the end of the line above, including the
419 terminating newline. */
421 static struct text_pos this_line_end_pos
;
423 /* The vertical positions and the height of this line. */
425 static int this_line_vpos
;
426 static int this_line_y
;
427 static int this_line_pixel_height
;
429 /* X position at which this display line starts. Usually zero;
430 negative if first character is partially visible. */
432 static int this_line_start_x
;
434 /* Buffer that this_line_.* variables are referring to. */
436 static struct buffer
*this_line_buffer
;
438 /* Nonzero means truncate lines in all windows less wide than the
441 Lisp_Object Vtruncate_partial_width_windows
;
443 /* A flag to control how to display unibyte 8-bit character. */
445 int unibyte_display_via_language_environment
;
447 /* Nonzero means we have more than one non-mini-buffer-only frame.
448 Not guaranteed to be accurate except while parsing
449 frame-title-format. */
453 Lisp_Object Vglobal_mode_string
;
456 /* List of variables (symbols) which hold markers for overlay arrows.
457 The symbols on this list are examined during redisplay to determine
458 where to display overlay arrows. */
460 Lisp_Object Voverlay_arrow_variable_list
;
462 /* Marker for where to display an arrow on top of the buffer text. */
464 Lisp_Object Voverlay_arrow_position
;
466 /* String to display for the arrow. Only used on terminal frames. */
468 Lisp_Object Voverlay_arrow_string
;
470 /* Values of those variables at last redisplay are stored as
471 properties on `overlay-arrow-position' symbol. However, if
472 Voverlay_arrow_position is a marker, last-arrow-position is its
473 numerical position. */
475 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
477 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
478 properties on a symbol in overlay-arrow-variable-list. */
480 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
482 /* Like mode-line-format, but for the title bar on a visible frame. */
484 Lisp_Object Vframe_title_format
;
486 /* Like mode-line-format, but for the title bar on an iconified frame. */
488 Lisp_Object Vicon_title_format
;
490 /* List of functions to call when a window's size changes. These
491 functions get one arg, a frame on which one or more windows' sizes
494 static Lisp_Object Vwindow_size_change_functions
;
496 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
498 /* Nonzero if an overlay arrow has been displayed in this window. */
500 static int overlay_arrow_seen
;
502 /* Nonzero means highlight the region even in nonselected windows. */
504 int highlight_nonselected_windows
;
506 /* If cursor motion alone moves point off frame, try scrolling this
507 many lines up or down if that will bring it back. */
509 static EMACS_INT scroll_step
;
511 /* Nonzero means scroll just far enough to bring point back on the
512 screen, when appropriate. */
514 static EMACS_INT scroll_conservatively
;
516 /* Recenter the window whenever point gets within this many lines of
517 the top or bottom of the window. This value is translated into a
518 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
519 that there is really a fixed pixel height scroll margin. */
521 EMACS_INT scroll_margin
;
523 /* Number of windows showing the buffer of the selected window (or
524 another buffer with the same base buffer). keyboard.c refers to
529 /* Vector containing glyphs for an ellipsis `...'. */
531 static Lisp_Object default_invis_vector
[3];
533 /* Zero means display the mode-line/header-line/menu-bar in the default face
534 (this slightly odd definition is for compatibility with previous versions
535 of emacs), non-zero means display them using their respective faces.
537 This variable is deprecated. */
539 int mode_line_inverse_video
;
541 /* Prompt to display in front of the mini-buffer contents. */
543 Lisp_Object minibuf_prompt
;
545 /* Width of current mini-buffer prompt. Only set after display_line
546 of the line that contains the prompt. */
548 int minibuf_prompt_width
;
550 /* This is the window where the echo area message was displayed. It
551 is always a mini-buffer window, but it may not be the same window
552 currently active as a mini-buffer. */
554 Lisp_Object echo_area_window
;
556 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
557 pushes the current message and the value of
558 message_enable_multibyte on the stack, the function restore_message
559 pops the stack and displays MESSAGE again. */
561 Lisp_Object Vmessage_stack
;
563 /* Nonzero means multibyte characters were enabled when the echo area
564 message was specified. */
566 int message_enable_multibyte
;
568 /* Nonzero if we should redraw the mode lines on the next redisplay. */
570 int update_mode_lines
;
572 /* Nonzero if window sizes or contents have changed since last
573 redisplay that finished. */
575 int windows_or_buffers_changed
;
577 /* Nonzero means a frame's cursor type has been changed. */
579 int cursor_type_changed
;
581 /* Nonzero after display_mode_line if %l was used and it displayed a
584 int line_number_displayed
;
586 /* Maximum buffer size for which to display line numbers. */
588 Lisp_Object Vline_number_display_limit
;
590 /* Line width to consider when repositioning for line number display. */
592 static EMACS_INT line_number_display_limit_width
;
594 /* Number of lines to keep in the message log buffer. t means
595 infinite. nil means don't log at all. */
597 Lisp_Object Vmessage_log_max
;
599 /* The name of the *Messages* buffer, a string. */
601 static Lisp_Object Vmessages_buffer_name
;
603 /* Current, index 0, and last displayed echo area message. Either
604 buffers from echo_buffers, or nil to indicate no message. */
606 Lisp_Object echo_area_buffer
[2];
608 /* The buffers referenced from echo_area_buffer. */
610 static Lisp_Object echo_buffer
[2];
612 /* A vector saved used in with_area_buffer to reduce consing. */
614 static Lisp_Object Vwith_echo_area_save_vector
;
616 /* Non-zero means display_echo_area should display the last echo area
617 message again. Set by redisplay_preserve_echo_area. */
619 static int display_last_displayed_message_p
;
621 /* Nonzero if echo area is being used by print; zero if being used by
624 int message_buf_print
;
626 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
628 Lisp_Object Qinhibit_menubar_update
;
629 int inhibit_menubar_update
;
631 /* When evaluating expressions from menu bar items (enable conditions,
632 for instance), this is the frame they are being processed for. */
634 Lisp_Object Vmenu_updating_frame
;
636 /* Maximum height for resizing mini-windows. Either a float
637 specifying a fraction of the available height, or an integer
638 specifying a number of lines. */
640 Lisp_Object Vmax_mini_window_height
;
642 /* Non-zero means messages should be displayed with truncated
643 lines instead of being continued. */
645 int message_truncate_lines
;
646 Lisp_Object Qmessage_truncate_lines
;
648 /* Set to 1 in clear_message to make redisplay_internal aware
649 of an emptied echo area. */
651 static int message_cleared_p
;
653 /* How to blink the default frame cursor off. */
654 Lisp_Object Vblink_cursor_alist
;
656 /* A scratch glyph row with contents used for generating truncation
657 glyphs. Also used in direct_output_for_insert. */
659 #define MAX_SCRATCH_GLYPHS 100
660 struct glyph_row scratch_glyph_row
;
661 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
663 /* Ascent and height of the last line processed by move_it_to. */
665 static int last_max_ascent
, last_height
;
667 /* Non-zero if there's a help-echo in the echo area. */
669 int help_echo_showing_p
;
671 /* If >= 0, computed, exact values of mode-line and header-line height
672 to use in the macros CURRENT_MODE_LINE_HEIGHT and
673 CURRENT_HEADER_LINE_HEIGHT. */
675 int current_mode_line_height
, current_header_line_height
;
677 /* The maximum distance to look ahead for text properties. Values
678 that are too small let us call compute_char_face and similar
679 functions too often which is expensive. Values that are too large
680 let us call compute_char_face and alike too often because we
681 might not be interested in text properties that far away. */
683 #define TEXT_PROP_DISTANCE_LIMIT 100
687 /* Variables to turn off display optimizations from Lisp. */
689 int inhibit_try_window_id
, inhibit_try_window_reusing
;
690 int inhibit_try_cursor_movement
;
692 /* Non-zero means print traces of redisplay if compiled with
695 int trace_redisplay_p
;
697 #endif /* GLYPH_DEBUG */
699 #ifdef DEBUG_TRACE_MOVE
700 /* Non-zero means trace with TRACE_MOVE to stderr. */
703 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
705 #define TRACE_MOVE(x) (void) 0
708 /* Non-zero means automatically scroll windows horizontally to make
711 int automatic_hscrolling_p
;
712 Lisp_Object Qauto_hscroll_mode
;
714 /* How close to the margin can point get before the window is scrolled
716 EMACS_INT hscroll_margin
;
718 /* How much to scroll horizontally when point is inside the above margin. */
719 Lisp_Object Vhscroll_step
;
721 /* The variable `resize-mini-windows'. If nil, don't resize
722 mini-windows. If t, always resize them to fit the text they
723 display. If `grow-only', let mini-windows grow only until they
726 Lisp_Object Vresize_mini_windows
;
728 /* Buffer being redisplayed -- for redisplay_window_error. */
730 struct buffer
*displayed_buffer
;
732 /* Space between overline and text. */
734 EMACS_INT overline_margin
;
736 /* Require underline to be at least this many screen pixels below baseline
737 This to avoid underline "merging" with the base of letters at small
738 font sizes, particularly when x_use_underline_position_properties is on. */
740 EMACS_INT underline_minimum_offset
;
742 /* Value returned from text property handlers (see below). */
747 HANDLED_RECOMPUTE_PROPS
,
748 HANDLED_OVERLAY_STRING_CONSUMED
,
752 /* A description of text properties that redisplay is interested
757 /* The name of the property. */
760 /* A unique index for the property. */
763 /* A handler function called to set up iterator IT from the property
764 at IT's current position. Value is used to steer handle_stop. */
765 enum prop_handled (*handler
) P_ ((struct it
*it
));
768 static enum prop_handled handle_face_prop
P_ ((struct it
*));
769 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
770 static enum prop_handled handle_display_prop
P_ ((struct it
*));
771 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
772 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
773 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
775 /* Properties handled by iterators. */
777 static struct props it_props
[] =
779 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
780 /* Handle `face' before `display' because some sub-properties of
781 `display' need to know the face. */
782 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
783 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
784 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
785 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
789 /* Value is the position described by X. If X is a marker, value is
790 the marker_position of X. Otherwise, value is X. */
792 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
794 /* Enumeration returned by some move_it_.* functions internally. */
798 /* Not used. Undefined value. */
801 /* Move ended at the requested buffer position or ZV. */
802 MOVE_POS_MATCH_OR_ZV
,
804 /* Move ended at the requested X pixel position. */
807 /* Move within a line ended at the end of a line that must be
811 /* Move within a line ended at the end of a line that would
812 be displayed truncated. */
815 /* Move within a line ended at a line end. */
819 /* This counter is used to clear the face cache every once in a while
820 in redisplay_internal. It is incremented for each redisplay.
821 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
824 #define CLEAR_FACE_CACHE_COUNT 500
825 static int clear_face_cache_count
;
827 /* Similarly for the image cache. */
829 #ifdef HAVE_WINDOW_SYSTEM
830 #define CLEAR_IMAGE_CACHE_COUNT 101
831 static int clear_image_cache_count
;
834 /* Non-zero while redisplay_internal is in progress. */
838 /* Non-zero means don't free realized faces. Bound while freeing
839 realized faces is dangerous because glyph matrices might still
842 int inhibit_free_realized_faces
;
843 Lisp_Object Qinhibit_free_realized_faces
;
845 /* If a string, XTread_socket generates an event to display that string.
846 (The display is done in read_char.) */
848 Lisp_Object help_echo_string
;
849 Lisp_Object help_echo_window
;
850 Lisp_Object help_echo_object
;
853 /* Temporary variable for XTread_socket. */
855 Lisp_Object previous_help_echo_string
;
857 /* Null glyph slice */
859 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
861 /* Platform-independent portion of hourglass implementation. */
863 /* Non-zero means we're allowed to display a hourglass pointer. */
864 int display_hourglass_p
;
866 /* Non-zero means an hourglass cursor is currently shown. */
867 int hourglass_shown_p
;
869 /* If non-null, an asynchronous timer that, when it expires, displays
870 an hourglass cursor on all frames. */
871 struct atimer
*hourglass_atimer
;
873 /* Number of seconds to wait before displaying an hourglass cursor. */
874 Lisp_Object Vhourglass_delay
;
876 /* Default number of seconds to wait before displaying an hourglass
878 #define DEFAULT_HOURGLASS_DELAY 1
881 /* Function prototypes. */
883 static void setup_for_ellipsis
P_ ((struct it
*, int));
884 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
885 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
886 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
887 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
888 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
889 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
891 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
893 static void handle_line_prefix
P_ ((struct it
*));
895 static void pint2str
P_ ((char *, int, int));
896 static void pint2hrstr
P_ ((char *, int, int));
897 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
899 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
900 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
901 static void store_mode_line_noprop_char
P_ ((char));
902 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
903 static void x_consider_frame_title
P_ ((Lisp_Object
));
904 static void handle_stop
P_ ((struct it
*));
905 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
906 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
907 static void ensure_echo_area_buffers
P_ ((void));
908 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
909 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
910 static int with_echo_area_buffer
P_ ((struct window
*, int,
911 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
912 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
913 static void clear_garbaged_frames
P_ ((void));
914 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
915 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
916 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int display_echo_area
P_ ((struct window
*));
918 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
920 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
921 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
922 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
924 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
925 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
926 static void insert_left_trunc_glyphs
P_ ((struct it
*));
927 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
929 static void extend_face_to_end_of_line
P_ ((struct it
*));
930 static int append_space_for_newline
P_ ((struct it
*, int));
931 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
932 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
933 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
934 static int trailing_whitespace_p
P_ ((int));
935 static int message_log_check_duplicate
P_ ((int, int, int, int));
936 static void push_it
P_ ((struct it
*));
937 static void pop_it
P_ ((struct it
*));
938 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
939 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
940 static void redisplay_internal
P_ ((int));
941 static int echo_area_display
P_ ((int));
942 static void redisplay_windows
P_ ((Lisp_Object
));
943 static void redisplay_window
P_ ((Lisp_Object
, int));
944 static Lisp_Object
redisplay_window_error ();
945 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
946 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
947 static int update_menu_bar
P_ ((struct frame
*, int, int));
948 static int try_window_reusing_current_matrix
P_ ((struct window
*));
949 static int try_window_id
P_ ((struct window
*));
950 static int display_line
P_ ((struct it
*));
951 static int display_mode_lines
P_ ((struct window
*));
952 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
953 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
954 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
955 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
956 static void display_menu_bar
P_ ((struct window
*));
957 static int display_count_lines
P_ ((int, int, int, int, int *));
958 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
959 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
960 static void compute_line_metrics
P_ ((struct it
*));
961 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
962 static int get_overlay_strings
P_ ((struct it
*, int));
963 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
964 static void next_overlay_string
P_ ((struct it
*));
965 static void reseat
P_ ((struct it
*, struct text_pos
, int));
966 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
967 static void back_to_previous_visible_line_start
P_ ((struct it
*));
968 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
969 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
970 static int next_element_from_ellipsis
P_ ((struct it
*));
971 static int next_element_from_display_vector
P_ ((struct it
*));
972 static int next_element_from_string
P_ ((struct it
*));
973 static int next_element_from_c_string
P_ ((struct it
*));
974 static int next_element_from_buffer
P_ ((struct it
*));
975 static int next_element_from_composition
P_ ((struct it
*));
976 static int next_element_from_image
P_ ((struct it
*));
977 static int next_element_from_stretch
P_ ((struct it
*));
978 static void load_overlay_strings
P_ ((struct it
*, int));
979 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
980 struct display_pos
*));
981 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
982 Lisp_Object
, int, int, int, int));
983 static enum move_it_result
984 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
985 enum move_operation_enum
);
986 void move_it_vertically_backward
P_ ((struct it
*, int));
987 static void init_to_row_start
P_ ((struct it
*, struct window
*,
988 struct glyph_row
*));
989 static int init_to_row_end
P_ ((struct it
*, struct window
*,
990 struct glyph_row
*));
991 static void back_to_previous_line_start
P_ ((struct it
*));
992 static int forward_to_next_line_start
P_ ((struct it
*, int *));
993 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
995 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
996 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
997 static int number_of_chars
P_ ((unsigned char *, int));
998 static void compute_stop_pos
P_ ((struct it
*));
999 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1001 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1002 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1003 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1004 Lisp_Object
, Lisp_Object
,
1005 struct text_pos
*, int));
1006 static int underlying_face_id
P_ ((struct it
*));
1007 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1010 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1011 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1013 #ifdef HAVE_WINDOW_SYSTEM
1015 static void update_tool_bar
P_ ((struct frame
*, int));
1016 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1017 static int redisplay_tool_bar
P_ ((struct frame
*));
1018 static void display_tool_bar_line
P_ ((struct it
*, int));
1019 static void notice_overwritten_cursor
P_ ((struct window
*,
1020 enum glyph_row_area
,
1021 int, int, int, int));
1025 #endif /* HAVE_WINDOW_SYSTEM */
1028 /***********************************************************************
1029 Window display dimensions
1030 ***********************************************************************/
1032 /* Return the bottom boundary y-position for text lines in window W.
1033 This is the first y position at which a line cannot start.
1034 It is relative to the top of the window.
1036 This is the height of W minus the height of a mode line, if any. */
1039 window_text_bottom_y (w
)
1042 int height
= WINDOW_TOTAL_HEIGHT (w
);
1044 if (WINDOW_WANTS_MODELINE_P (w
))
1045 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1049 /* Return the pixel width of display area AREA of window W. AREA < 0
1050 means return the total width of W, not including fringes to
1051 the left and right of the window. */
1054 window_box_width (w
, area
)
1058 int cols
= XFASTINT (w
->total_cols
);
1061 if (!w
->pseudo_window_p
)
1063 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1065 if (area
== TEXT_AREA
)
1067 if (INTEGERP (w
->left_margin_cols
))
1068 cols
-= XFASTINT (w
->left_margin_cols
);
1069 if (INTEGERP (w
->right_margin_cols
))
1070 cols
-= XFASTINT (w
->right_margin_cols
);
1071 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1073 else if (area
== LEFT_MARGIN_AREA
)
1075 cols
= (INTEGERP (w
->left_margin_cols
)
1076 ? XFASTINT (w
->left_margin_cols
) : 0);
1079 else if (area
== RIGHT_MARGIN_AREA
)
1081 cols
= (INTEGERP (w
->right_margin_cols
)
1082 ? XFASTINT (w
->right_margin_cols
) : 0);
1087 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1091 /* Return the pixel height of the display area of window W, not
1092 including mode lines of W, if any. */
1095 window_box_height (w
)
1098 struct frame
*f
= XFRAME (w
->frame
);
1099 int height
= WINDOW_TOTAL_HEIGHT (w
);
1101 xassert (height
>= 0);
1103 /* Note: the code below that determines the mode-line/header-line
1104 height is essentially the same as that contained in the macro
1105 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1106 the appropriate glyph row has its `mode_line_p' flag set,
1107 and if it doesn't, uses estimate_mode_line_height instead. */
1109 if (WINDOW_WANTS_MODELINE_P (w
))
1111 struct glyph_row
*ml_row
1112 = (w
->current_matrix
&& w
->current_matrix
->rows
1113 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1115 if (ml_row
&& ml_row
->mode_line_p
)
1116 height
-= ml_row
->height
;
1118 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1121 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1123 struct glyph_row
*hl_row
1124 = (w
->current_matrix
&& w
->current_matrix
->rows
1125 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1127 if (hl_row
&& hl_row
->mode_line_p
)
1128 height
-= hl_row
->height
;
1130 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1133 /* With a very small font and a mode-line that's taller than
1134 default, we might end up with a negative height. */
1135 return max (0, height
);
1138 /* Return the window-relative coordinate of the left edge of display
1139 area AREA of window W. AREA < 0 means return the left edge of the
1140 whole window, to the right of the left fringe of W. */
1143 window_box_left_offset (w
, area
)
1149 if (w
->pseudo_window_p
)
1152 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1154 if (area
== TEXT_AREA
)
1155 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1156 + window_box_width (w
, LEFT_MARGIN_AREA
));
1157 else if (area
== RIGHT_MARGIN_AREA
)
1158 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1159 + window_box_width (w
, LEFT_MARGIN_AREA
)
1160 + window_box_width (w
, TEXT_AREA
)
1161 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1163 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1164 else if (area
== LEFT_MARGIN_AREA
1165 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1166 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1172 /* Return the window-relative coordinate of the right edge of display
1173 area AREA of window W. AREA < 0 means return the left edge of the
1174 whole window, to the left of the right fringe of W. */
1177 window_box_right_offset (w
, area
)
1181 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1184 /* Return the frame-relative coordinate of the left edge of display
1185 area AREA of window W. AREA < 0 means return the left edge of the
1186 whole window, to the right of the left fringe of W. */
1189 window_box_left (w
, area
)
1193 struct frame
*f
= XFRAME (w
->frame
);
1196 if (w
->pseudo_window_p
)
1197 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1199 x
= (WINDOW_LEFT_EDGE_X (w
)
1200 + window_box_left_offset (w
, area
));
1206 /* Return the frame-relative coordinate of the right edge of display
1207 area AREA of window W. AREA < 0 means return the left edge of the
1208 whole window, to the left of the right fringe of W. */
1211 window_box_right (w
, area
)
1215 return window_box_left (w
, area
) + window_box_width (w
, area
);
1218 /* Get the bounding box of the display area AREA of window W, without
1219 mode lines, in frame-relative coordinates. AREA < 0 means the
1220 whole window, not including the left and right fringes of
1221 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1222 coordinates of the upper-left corner of the box. Return in
1223 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1226 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1229 int *box_x
, *box_y
, *box_width
, *box_height
;
1232 *box_width
= window_box_width (w
, area
);
1234 *box_height
= window_box_height (w
);
1236 *box_x
= window_box_left (w
, area
);
1239 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1240 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1241 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1246 /* Get the bounding box of the display area AREA of window W, without
1247 mode lines. AREA < 0 means the whole window, not including the
1248 left and right fringe of the window. Return in *TOP_LEFT_X
1249 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1250 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1251 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1255 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1256 bottom_right_x
, bottom_right_y
)
1259 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1261 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1263 *bottom_right_x
+= *top_left_x
;
1264 *bottom_right_y
+= *top_left_y
;
1269 /***********************************************************************
1271 ***********************************************************************/
1273 /* Return the bottom y-position of the line the iterator IT is in.
1274 This can modify IT's settings. */
1280 int line_height
= it
->max_ascent
+ it
->max_descent
;
1281 int line_top_y
= it
->current_y
;
1283 if (line_height
== 0)
1286 line_height
= last_height
;
1287 else if (IT_CHARPOS (*it
) < ZV
)
1289 move_it_by_lines (it
, 1, 1);
1290 line_height
= (it
->max_ascent
|| it
->max_descent
1291 ? it
->max_ascent
+ it
->max_descent
1296 struct glyph_row
*row
= it
->glyph_row
;
1298 /* Use the default character height. */
1299 it
->glyph_row
= NULL
;
1300 it
->what
= IT_CHARACTER
;
1303 PRODUCE_GLYPHS (it
);
1304 line_height
= it
->ascent
+ it
->descent
;
1305 it
->glyph_row
= row
;
1309 return line_top_y
+ line_height
;
1313 /* Return 1 if position CHARPOS is visible in window W.
1314 CHARPOS < 0 means return info about WINDOW_END position.
1315 If visible, set *X and *Y to pixel coordinates of top left corner.
1316 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1317 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1320 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1322 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1325 struct text_pos top
;
1327 struct buffer
*old_buffer
= NULL
;
1329 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1332 if (XBUFFER (w
->buffer
) != current_buffer
)
1334 old_buffer
= current_buffer
;
1335 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1338 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1340 /* Compute exact mode line heights. */
1341 if (WINDOW_WANTS_MODELINE_P (w
))
1342 current_mode_line_height
1343 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1344 current_buffer
->mode_line_format
);
1346 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1347 current_header_line_height
1348 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1349 current_buffer
->header_line_format
);
1351 start_display (&it
, w
, top
);
1352 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1353 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1355 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1357 /* We have reached CHARPOS, or passed it. How the call to
1358 move_it_to can overshoot: (i) If CHARPOS is on invisible
1359 text, move_it_to stops at the end of the invisible text,
1360 after CHARPOS. (ii) If CHARPOS is in a display vector,
1361 move_it_to stops on its last glyph. */
1362 int top_x
= it
.current_x
;
1363 int top_y
= it
.current_y
;
1364 enum it_method it_method
= it
.method
;
1365 /* Calling line_bottom_y may change it.method. */
1366 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1367 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1369 if (top_y
< window_top_y
)
1370 visible_p
= bottom_y
> window_top_y
;
1371 else if (top_y
< it
.last_visible_y
)
1375 if (it_method
== GET_FROM_BUFFER
)
1377 Lisp_Object window
, prop
;
1379 XSETWINDOW (window
, w
);
1380 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1381 Qinvisible
, window
);
1383 /* If charpos coincides with invisible text covered with an
1384 ellipsis, use the first glyph of the ellipsis to compute
1385 the pixel positions. */
1386 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1388 struct glyph_row
*row
= it
.glyph_row
;
1389 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1390 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1394 && (!BUFFERP (glyph
->object
)
1395 || glyph
->charpos
< charpos
);
1397 x
+= glyph
->pixel_width
;
1401 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1403 /* We stopped on the last glyph of a display vector.
1404 Try and recompute. Hack alert! */
1405 if (charpos
< 2 || top
.charpos
>= charpos
)
1406 top_x
= it
.glyph_row
->x
;
1410 start_display (&it2
, w
, top
);
1411 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1412 get_next_display_element (&it2
);
1413 PRODUCE_GLYPHS (&it2
);
1414 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1415 || it2
.current_x
> it2
.last_visible_x
)
1416 top_x
= it
.glyph_row
->x
;
1419 top_x
= it2
.current_x
;
1420 top_y
= it2
.current_y
;
1426 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1427 *rtop
= max (0, window_top_y
- top_y
);
1428 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1429 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1430 - max (top_y
, window_top_y
)));
1439 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1440 move_it_by_lines (&it
, 1, 0);
1441 if (charpos
< IT_CHARPOS (it
)
1442 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1445 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1447 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1448 *rtop
= max (0, -it2
.current_y
);
1449 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1450 - it
.last_visible_y
));
1451 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1453 - max (it2
.current_y
,
1454 WINDOW_HEADER_LINE_HEIGHT (w
))));
1460 set_buffer_internal_1 (old_buffer
);
1462 current_header_line_height
= current_mode_line_height
= -1;
1464 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1465 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1468 /* Debugging code. */
1470 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1471 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1473 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1480 /* Return the next character from STR which is MAXLEN bytes long.
1481 Return in *LEN the length of the character. This is like
1482 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1483 we find one, we return a `?', but with the length of the invalid
1487 string_char_and_length (str
, maxlen
, len
)
1488 const unsigned char *str
;
1493 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1494 if (!CHAR_VALID_P (c
, 1))
1495 /* We may not change the length here because other places in Emacs
1496 don't use this function, i.e. they silently accept invalid
1505 /* Given a position POS containing a valid character and byte position
1506 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1508 static struct text_pos
1509 string_pos_nchars_ahead (pos
, string
, nchars
)
1510 struct text_pos pos
;
1514 xassert (STRINGP (string
) && nchars
>= 0);
1516 if (STRING_MULTIBYTE (string
))
1518 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1519 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1524 string_char_and_length (p
, rest
, &len
);
1525 p
+= len
, rest
-= len
;
1526 xassert (rest
>= 0);
1528 BYTEPOS (pos
) += len
;
1532 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1538 /* Value is the text position, i.e. character and byte position,
1539 for character position CHARPOS in STRING. */
1541 static INLINE
struct text_pos
1542 string_pos (charpos
, string
)
1546 struct text_pos pos
;
1547 xassert (STRINGP (string
));
1548 xassert (charpos
>= 0);
1549 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1554 /* Value is a text position, i.e. character and byte position, for
1555 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1556 means recognize multibyte characters. */
1558 static struct text_pos
1559 c_string_pos (charpos
, s
, multibyte_p
)
1564 struct text_pos pos
;
1566 xassert (s
!= NULL
);
1567 xassert (charpos
>= 0);
1571 int rest
= strlen (s
), len
;
1573 SET_TEXT_POS (pos
, 0, 0);
1576 string_char_and_length (s
, rest
, &len
);
1577 s
+= len
, rest
-= len
;
1578 xassert (rest
>= 0);
1580 BYTEPOS (pos
) += len
;
1584 SET_TEXT_POS (pos
, charpos
, charpos
);
1590 /* Value is the number of characters in C string S. MULTIBYTE_P
1591 non-zero means recognize multibyte characters. */
1594 number_of_chars (s
, multibyte_p
)
1602 int rest
= strlen (s
), len
;
1603 unsigned char *p
= (unsigned char *) s
;
1605 for (nchars
= 0; rest
> 0; ++nchars
)
1607 string_char_and_length (p
, rest
, &len
);
1608 rest
-= len
, p
+= len
;
1612 nchars
= strlen (s
);
1618 /* Compute byte position NEWPOS->bytepos corresponding to
1619 NEWPOS->charpos. POS is a known position in string STRING.
1620 NEWPOS->charpos must be >= POS.charpos. */
1623 compute_string_pos (newpos
, pos
, string
)
1624 struct text_pos
*newpos
, pos
;
1627 xassert (STRINGP (string
));
1628 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1630 if (STRING_MULTIBYTE (string
))
1631 *newpos
= string_pos_nchars_ahead (pos
, string
,
1632 CHARPOS (*newpos
) - CHARPOS (pos
));
1634 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1638 Return an estimation of the pixel height of mode or top lines on
1639 frame F. FACE_ID specifies what line's height to estimate. */
1642 estimate_mode_line_height (f
, face_id
)
1644 enum face_id face_id
;
1646 #ifdef HAVE_WINDOW_SYSTEM
1647 if (FRAME_WINDOW_P (f
))
1649 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1651 /* This function is called so early when Emacs starts that the face
1652 cache and mode line face are not yet initialized. */
1653 if (FRAME_FACE_CACHE (f
))
1655 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1659 height
= FONT_HEIGHT (face
->font
);
1660 if (face
->box_line_width
> 0)
1661 height
+= 2 * face
->box_line_width
;
1672 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1673 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1674 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1675 not force the value into range. */
1678 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1680 register int pix_x
, pix_y
;
1682 NativeRectangle
*bounds
;
1686 #ifdef HAVE_WINDOW_SYSTEM
1687 if (FRAME_WINDOW_P (f
))
1689 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1690 even for negative values. */
1692 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1694 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1696 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1697 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1700 STORE_NATIVE_RECT (*bounds
,
1701 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1702 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1703 FRAME_COLUMN_WIDTH (f
) - 1,
1704 FRAME_LINE_HEIGHT (f
) - 1);
1710 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1711 pix_x
= FRAME_TOTAL_COLS (f
);
1715 else if (pix_y
> FRAME_LINES (f
))
1716 pix_y
= FRAME_LINES (f
);
1726 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1727 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1728 can't tell the positions because W's display is not up to date,
1732 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1735 int *frame_x
, *frame_y
;
1737 #ifdef HAVE_WINDOW_SYSTEM
1738 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1742 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1743 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1745 if (display_completed
)
1747 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1748 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1749 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1755 hpos
+= glyph
->pixel_width
;
1759 /* If first glyph is partially visible, its first visible position is still 0. */
1771 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1772 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1783 #ifdef HAVE_WINDOW_SYSTEM
1785 /* Find the glyph under window-relative coordinates X/Y in window W.
1786 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1787 strings. Return in *HPOS and *VPOS the row and column number of
1788 the glyph found. Return in *AREA the glyph area containing X.
1789 Value is a pointer to the glyph found or null if X/Y is not on
1790 text, or we can't tell because W's current matrix is not up to
1795 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1798 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1800 struct glyph
*glyph
, *end
;
1801 struct glyph_row
*row
= NULL
;
1804 /* Find row containing Y. Give up if some row is not enabled. */
1805 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1807 row
= MATRIX_ROW (w
->current_matrix
, i
);
1808 if (!row
->enabled_p
)
1810 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1817 /* Give up if Y is not in the window. */
1818 if (i
== w
->current_matrix
->nrows
)
1821 /* Get the glyph area containing X. */
1822 if (w
->pseudo_window_p
)
1829 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1831 *area
= LEFT_MARGIN_AREA
;
1832 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1834 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1837 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1841 *area
= RIGHT_MARGIN_AREA
;
1842 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1846 /* Find glyph containing X. */
1847 glyph
= row
->glyphs
[*area
];
1848 end
= glyph
+ row
->used
[*area
];
1850 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1852 x
-= glyph
->pixel_width
;
1862 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1865 *hpos
= glyph
- row
->glyphs
[*area
];
1871 Convert frame-relative x/y to coordinates relative to window W.
1872 Takes pseudo-windows into account. */
1875 frame_to_window_pixel_xy (w
, x
, y
)
1879 if (w
->pseudo_window_p
)
1881 /* A pseudo-window is always full-width, and starts at the
1882 left edge of the frame, plus a frame border. */
1883 struct frame
*f
= XFRAME (w
->frame
);
1884 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1885 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1889 *x
-= WINDOW_LEFT_EDGE_X (w
);
1890 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1895 Return in RECTS[] at most N clipping rectangles for glyph string S.
1896 Return the number of stored rectangles. */
1899 get_glyph_string_clip_rects (s
, rects
, n
)
1900 struct glyph_string
*s
;
1901 NativeRectangle
*rects
;
1909 if (s
->row
->full_width_p
)
1911 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1912 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1913 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1915 /* Unless displaying a mode or menu bar line, which are always
1916 fully visible, clip to the visible part of the row. */
1917 if (s
->w
->pseudo_window_p
)
1918 r
.height
= s
->row
->visible_height
;
1920 r
.height
= s
->height
;
1924 /* This is a text line that may be partially visible. */
1925 r
.x
= window_box_left (s
->w
, s
->area
);
1926 r
.width
= window_box_width (s
->w
, s
->area
);
1927 r
.height
= s
->row
->visible_height
;
1931 if (r
.x
< s
->clip_head
->x
)
1933 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1934 r
.width
-= s
->clip_head
->x
- r
.x
;
1937 r
.x
= s
->clip_head
->x
;
1940 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1942 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1943 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1948 /* If S draws overlapping rows, it's sufficient to use the top and
1949 bottom of the window for clipping because this glyph string
1950 intentionally draws over other lines. */
1951 if (s
->for_overlaps
)
1953 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1954 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1956 /* Alas, the above simple strategy does not work for the
1957 environments with anti-aliased text: if the same text is
1958 drawn onto the same place multiple times, it gets thicker.
1959 If the overlap we are processing is for the erased cursor, we
1960 take the intersection with the rectagle of the cursor. */
1961 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1963 XRectangle rc
, r_save
= r
;
1965 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1966 rc
.y
= s
->w
->phys_cursor
.y
;
1967 rc
.width
= s
->w
->phys_cursor_width
;
1968 rc
.height
= s
->w
->phys_cursor_height
;
1970 x_intersect_rectangles (&r_save
, &rc
, &r
);
1975 /* Don't use S->y for clipping because it doesn't take partially
1976 visible lines into account. For example, it can be negative for
1977 partially visible lines at the top of a window. */
1978 if (!s
->row
->full_width_p
1979 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1980 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1982 r
.y
= max (0, s
->row
->y
);
1984 /* If drawing a tool-bar window, draw it over the internal border
1985 at the top of the window. */
1986 if (WINDOWP (s
->f
->tool_bar_window
)
1987 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1988 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1991 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1993 /* If drawing the cursor, don't let glyph draw outside its
1994 advertised boundaries. Cleartype does this under some circumstances. */
1995 if (s
->hl
== DRAW_CURSOR
)
1997 struct glyph
*glyph
= s
->first_glyph
;
2002 r
.width
-= s
->x
- r
.x
;
2005 r
.width
= min (r
.width
, glyph
->pixel_width
);
2007 /* If r.y is below window bottom, ensure that we still see a cursor. */
2008 height
= min (glyph
->ascent
+ glyph
->descent
,
2009 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2010 max_y
= window_text_bottom_y (s
->w
) - height
;
2011 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2012 if (s
->ybase
- glyph
->ascent
> max_y
)
2019 /* Don't draw cursor glyph taller than our actual glyph. */
2020 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2021 if (height
< r
.height
)
2023 max_y
= r
.y
+ r
.height
;
2024 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2025 r
.height
= min (max_y
- r
.y
, height
);
2032 XRectangle r_save
= r
;
2034 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2038 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2039 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2041 #ifdef CONVERT_FROM_XRECT
2042 CONVERT_FROM_XRECT (r
, *rects
);
2050 /* If we are processing overlapping and allowed to return
2051 multiple clipping rectangles, we exclude the row of the glyph
2052 string from the clipping rectangle. This is to avoid drawing
2053 the same text on the environment with anti-aliasing. */
2054 #ifdef CONVERT_FROM_XRECT
2057 XRectangle
*rs
= rects
;
2059 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2061 if (s
->for_overlaps
& OVERLAPS_PRED
)
2064 if (r
.y
+ r
.height
> row_y
)
2067 rs
[i
].height
= row_y
- r
.y
;
2073 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2076 if (r
.y
< row_y
+ s
->row
->visible_height
)
2078 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2080 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2081 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2090 #ifdef CONVERT_FROM_XRECT
2091 for (i
= 0; i
< n
; i
++)
2092 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2099 Return in *NR the clipping rectangle for glyph string S. */
2102 get_glyph_string_clip_rect (s
, nr
)
2103 struct glyph_string
*s
;
2104 NativeRectangle
*nr
;
2106 get_glyph_string_clip_rects (s
, nr
, 1);
2111 Return the position and height of the phys cursor in window W.
2112 Set w->phys_cursor_width to width of phys cursor.
2116 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2118 struct glyph_row
*row
;
2119 struct glyph
*glyph
;
2120 int *xp
, *yp
, *heightp
;
2122 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2123 int x
, y
, wd
, h
, h0
, y0
;
2125 /* Compute the width of the rectangle to draw. If on a stretch
2126 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2127 rectangle as wide as the glyph, but use a canonical character
2129 wd
= glyph
->pixel_width
- 1;
2130 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2134 x
= w
->phys_cursor
.x
;
2141 if (glyph
->type
== STRETCH_GLYPH
2142 && !x_stretch_cursor_p
)
2143 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2144 w
->phys_cursor_width
= wd
;
2146 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2148 /* If y is below window bottom, ensure that we still see a cursor. */
2149 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2151 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2152 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2154 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2157 h
= max (h
- (y0
- y
) + 1, h0
);
2162 y0
= window_text_bottom_y (w
) - h0
;
2170 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2171 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2176 * Remember which glyph the mouse is over.
2180 remember_mouse_glyph (f
, gx
, gy
, rect
)
2183 NativeRectangle
*rect
;
2187 struct glyph_row
*r
, *gr
, *end_row
;
2188 enum window_part part
;
2189 enum glyph_row_area area
;
2190 int x
, y
, width
, height
;
2192 /* Try to determine frame pixel position and size of the glyph under
2193 frame pixel coordinates X/Y on frame F. */
2195 if (!f
->glyphs_initialized_p
2196 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2199 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2200 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2204 w
= XWINDOW (window
);
2205 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2206 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2208 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2209 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2211 if (w
->pseudo_window_p
)
2214 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2220 case ON_LEFT_MARGIN
:
2221 area
= LEFT_MARGIN_AREA
;
2224 case ON_RIGHT_MARGIN
:
2225 area
= RIGHT_MARGIN_AREA
;
2228 case ON_HEADER_LINE
:
2230 gr
= (part
== ON_HEADER_LINE
2231 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2232 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2235 goto text_glyph_row_found
;
2242 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2243 if (r
->y
+ r
->height
> y
)
2249 text_glyph_row_found
:
2252 struct glyph
*g
= gr
->glyphs
[area
];
2253 struct glyph
*end
= g
+ gr
->used
[area
];
2255 height
= gr
->height
;
2256 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2257 if (gx
+ g
->pixel_width
> x
)
2262 if (g
->type
== IMAGE_GLYPH
)
2264 /* Don't remember when mouse is over image, as
2265 image may have hot-spots. */
2266 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2269 width
= g
->pixel_width
;
2273 /* Use nominal char spacing at end of line. */
2275 gx
+= (x
/ width
) * width
;
2278 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2279 gx
+= window_box_left_offset (w
, area
);
2283 /* Use nominal line height at end of window. */
2284 gx
= (x
/ width
) * width
;
2286 gy
+= (y
/ height
) * height
;
2290 case ON_LEFT_FRINGE
:
2291 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2292 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2293 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2294 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2297 case ON_RIGHT_FRINGE
:
2298 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2299 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2300 : window_box_right_offset (w
, TEXT_AREA
));
2301 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2305 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2307 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2308 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2309 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2311 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2315 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2316 if (r
->y
+ r
->height
> y
)
2323 height
= gr
->height
;
2326 /* Use nominal line height at end of window. */
2328 gy
+= (y
/ height
) * height
;
2335 /* If there is no glyph under the mouse, then we divide the screen
2336 into a grid of the smallest glyph in the frame, and use that
2339 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2340 round down even for negative values. */
2346 gx
= (gx
/ width
) * width
;
2347 gy
= (gy
/ height
) * height
;
2352 gx
+= WINDOW_LEFT_EDGE_X (w
);
2353 gy
+= WINDOW_TOP_EDGE_Y (w
);
2356 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2358 /* Visible feedback for debugging. */
2361 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2362 f
->output_data
.x
->normal_gc
,
2363 gx
, gy
, width
, height
);
2369 #endif /* HAVE_WINDOW_SYSTEM */
2372 /***********************************************************************
2373 Lisp form evaluation
2374 ***********************************************************************/
2376 /* Error handler for safe_eval and safe_call. */
2379 safe_eval_handler (arg
)
2382 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2387 /* Evaluate SEXPR and return the result, or nil if something went
2388 wrong. Prevent redisplay during the evaluation. */
2390 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2391 Return the result, or nil if something went wrong. Prevent
2392 redisplay during the evaluation. */
2395 safe_call (nargs
, args
)
2401 if (inhibit_eval_during_redisplay
)
2405 int count
= SPECPDL_INDEX ();
2406 struct gcpro gcpro1
;
2409 gcpro1
.nvars
= nargs
;
2410 specbind (Qinhibit_redisplay
, Qt
);
2411 /* Use Qt to ensure debugger does not run,
2412 so there is no possibility of wanting to redisplay. */
2413 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2416 val
= unbind_to (count
, val
);
2423 /* Call function FN with one argument ARG.
2424 Return the result, or nil if something went wrong. */
2427 safe_call1 (fn
, arg
)
2428 Lisp_Object fn
, arg
;
2430 Lisp_Object args
[2];
2433 return safe_call (2, args
);
2436 static Lisp_Object Qeval
;
2439 safe_eval (Lisp_Object sexpr
)
2441 return safe_call1 (Qeval
, sexpr
);
2444 /* Call function FN with one argument ARG.
2445 Return the result, or nil if something went wrong. */
2448 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2450 Lisp_Object args
[3];
2454 return safe_call (3, args
);
2459 /***********************************************************************
2461 ***********************************************************************/
2465 /* Define CHECK_IT to perform sanity checks on iterators.
2466 This is for debugging. It is too slow to do unconditionally. */
2472 if (it
->method
== GET_FROM_STRING
)
2474 xassert (STRINGP (it
->string
));
2475 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2479 xassert (IT_STRING_CHARPOS (*it
) < 0);
2480 if (it
->method
== GET_FROM_BUFFER
)
2482 /* Check that character and byte positions agree. */
2483 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2488 xassert (it
->current
.dpvec_index
>= 0);
2490 xassert (it
->current
.dpvec_index
< 0);
2493 #define CHECK_IT(IT) check_it ((IT))
2497 #define CHECK_IT(IT) (void) 0
2504 /* Check that the window end of window W is what we expect it
2505 to be---the last row in the current matrix displaying text. */
2508 check_window_end (w
)
2511 if (!MINI_WINDOW_P (w
)
2512 && !NILP (w
->window_end_valid
))
2514 struct glyph_row
*row
;
2515 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2516 XFASTINT (w
->window_end_vpos
)),
2518 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2519 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2523 #define CHECK_WINDOW_END(W) check_window_end ((W))
2525 #else /* not GLYPH_DEBUG */
2527 #define CHECK_WINDOW_END(W) (void) 0
2529 #endif /* not GLYPH_DEBUG */
2533 /***********************************************************************
2534 Iterator initialization
2535 ***********************************************************************/
2537 /* Initialize IT for displaying current_buffer in window W, starting
2538 at character position CHARPOS. CHARPOS < 0 means that no buffer
2539 position is specified which is useful when the iterator is assigned
2540 a position later. BYTEPOS is the byte position corresponding to
2541 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2543 If ROW is not null, calls to produce_glyphs with IT as parameter
2544 will produce glyphs in that row.
2546 BASE_FACE_ID is the id of a base face to use. It must be one of
2547 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2548 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2549 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2551 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2552 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2553 will be initialized to use the corresponding mode line glyph row of
2554 the desired matrix of W. */
2557 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2560 int charpos
, bytepos
;
2561 struct glyph_row
*row
;
2562 enum face_id base_face_id
;
2564 int highlight_region_p
;
2565 enum face_id remapped_base_face_id
= base_face_id
;
2567 /* Some precondition checks. */
2568 xassert (w
!= NULL
&& it
!= NULL
);
2569 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2572 /* If face attributes have been changed since the last redisplay,
2573 free realized faces now because they depend on face definitions
2574 that might have changed. Don't free faces while there might be
2575 desired matrices pending which reference these faces. */
2576 if (face_change_count
&& !inhibit_free_realized_faces
)
2578 face_change_count
= 0;
2579 free_all_realized_faces (Qnil
);
2582 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2583 if (! NILP (Vface_remapping_alist
))
2584 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2586 /* Use one of the mode line rows of W's desired matrix if
2590 if (base_face_id
== MODE_LINE_FACE_ID
2591 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2592 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2593 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2594 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2598 bzero (it
, sizeof *it
);
2599 it
->current
.overlay_string_index
= -1;
2600 it
->current
.dpvec_index
= -1;
2601 it
->base_face_id
= remapped_base_face_id
;
2603 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2605 /* The window in which we iterate over current_buffer: */
2606 XSETWINDOW (it
->window
, w
);
2608 it
->f
= XFRAME (w
->frame
);
2612 /* Extra space between lines (on window systems only). */
2613 if (base_face_id
== DEFAULT_FACE_ID
2614 && FRAME_WINDOW_P (it
->f
))
2616 if (NATNUMP (current_buffer
->extra_line_spacing
))
2617 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2618 else if (FLOATP (current_buffer
->extra_line_spacing
))
2619 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2620 * FRAME_LINE_HEIGHT (it
->f
));
2621 else if (it
->f
->extra_line_spacing
> 0)
2622 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2623 it
->max_extra_line_spacing
= 0;
2626 /* If realized faces have been removed, e.g. because of face
2627 attribute changes of named faces, recompute them. When running
2628 in batch mode, the face cache of the initial frame is null. If
2629 we happen to get called, make a dummy face cache. */
2630 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2631 init_frame_faces (it
->f
);
2632 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2633 recompute_basic_faces (it
->f
);
2635 /* Current value of the `slice', `space-width', and 'height' properties. */
2636 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2637 it
->space_width
= Qnil
;
2638 it
->font_height
= Qnil
;
2639 it
->override_ascent
= -1;
2641 /* Are control characters displayed as `^C'? */
2642 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2644 /* -1 means everything between a CR and the following line end
2645 is invisible. >0 means lines indented more than this value are
2647 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2648 ? XFASTINT (current_buffer
->selective_display
)
2649 : (!NILP (current_buffer
->selective_display
)
2651 it
->selective_display_ellipsis_p
2652 = !NILP (current_buffer
->selective_display_ellipses
);
2654 /* Display table to use. */
2655 it
->dp
= window_display_table (w
);
2657 /* Are multibyte characters enabled in current_buffer? */
2658 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2660 /* Non-zero if we should highlight the region. */
2662 = (!NILP (Vtransient_mark_mode
)
2663 && !NILP (current_buffer
->mark_active
)
2664 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2666 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2667 start and end of a visible region in window IT->w. Set both to
2668 -1 to indicate no region. */
2669 if (highlight_region_p
2670 /* Maybe highlight only in selected window. */
2671 && (/* Either show region everywhere. */
2672 highlight_nonselected_windows
2673 /* Or show region in the selected window. */
2674 || w
== XWINDOW (selected_window
)
2675 /* Or show the region if we are in the mini-buffer and W is
2676 the window the mini-buffer refers to. */
2677 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2678 && WINDOWP (minibuf_selected_window
)
2679 && w
== XWINDOW (minibuf_selected_window
))))
2681 int charpos
= marker_position (current_buffer
->mark
);
2682 it
->region_beg_charpos
= min (PT
, charpos
);
2683 it
->region_end_charpos
= max (PT
, charpos
);
2686 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2688 /* Get the position at which the redisplay_end_trigger hook should
2689 be run, if it is to be run at all. */
2690 if (MARKERP (w
->redisplay_end_trigger
)
2691 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2692 it
->redisplay_end_trigger_charpos
2693 = marker_position (w
->redisplay_end_trigger
);
2694 else if (INTEGERP (w
->redisplay_end_trigger
))
2695 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2697 /* Correct bogus values of tab_width. */
2698 it
->tab_width
= XINT (current_buffer
->tab_width
);
2699 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2702 /* Are lines in the display truncated? */
2703 if (base_face_id
!= DEFAULT_FACE_ID
2704 || XINT (it
->w
->hscroll
)
2705 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2706 && ((!NILP (Vtruncate_partial_width_windows
)
2707 && !INTEGERP (Vtruncate_partial_width_windows
))
2708 || (INTEGERP (Vtruncate_partial_width_windows
)
2709 && (WINDOW_TOTAL_COLS (it
->w
)
2710 < XINT (Vtruncate_partial_width_windows
))))))
2711 it
->line_wrap
= TRUNCATE
;
2712 else if (NILP (current_buffer
->truncate_lines
))
2713 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2714 ? WINDOW_WRAP
: WORD_WRAP
;
2716 it
->line_wrap
= TRUNCATE
;
2718 /* Get dimensions of truncation and continuation glyphs. These are
2719 displayed as fringe bitmaps under X, so we don't need them for such
2721 if (!FRAME_WINDOW_P (it
->f
))
2723 if (it
->line_wrap
== TRUNCATE
)
2725 /* We will need the truncation glyph. */
2726 xassert (it
->glyph_row
== NULL
);
2727 produce_special_glyphs (it
, IT_TRUNCATION
);
2728 it
->truncation_pixel_width
= it
->pixel_width
;
2732 /* We will need the continuation glyph. */
2733 xassert (it
->glyph_row
== NULL
);
2734 produce_special_glyphs (it
, IT_CONTINUATION
);
2735 it
->continuation_pixel_width
= it
->pixel_width
;
2738 /* Reset these values to zero because the produce_special_glyphs
2739 above has changed them. */
2740 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2741 it
->phys_ascent
= it
->phys_descent
= 0;
2744 /* Set this after getting the dimensions of truncation and
2745 continuation glyphs, so that we don't produce glyphs when calling
2746 produce_special_glyphs, above. */
2747 it
->glyph_row
= row
;
2748 it
->area
= TEXT_AREA
;
2750 /* Get the dimensions of the display area. The display area
2751 consists of the visible window area plus a horizontally scrolled
2752 part to the left of the window. All x-values are relative to the
2753 start of this total display area. */
2754 if (base_face_id
!= DEFAULT_FACE_ID
)
2756 /* Mode lines, menu bar in terminal frames. */
2757 it
->first_visible_x
= 0;
2758 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2763 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2764 it
->last_visible_x
= (it
->first_visible_x
2765 + window_box_width (w
, TEXT_AREA
));
2767 /* If we truncate lines, leave room for the truncator glyph(s) at
2768 the right margin. Otherwise, leave room for the continuation
2769 glyph(s). Truncation and continuation glyphs are not inserted
2770 for window-based redisplay. */
2771 if (!FRAME_WINDOW_P (it
->f
))
2773 if (it
->line_wrap
== TRUNCATE
)
2774 it
->last_visible_x
-= it
->truncation_pixel_width
;
2776 it
->last_visible_x
-= it
->continuation_pixel_width
;
2779 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2780 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2783 /* Leave room for a border glyph. */
2784 if (!FRAME_WINDOW_P (it
->f
)
2785 && !WINDOW_RIGHTMOST_P (it
->w
))
2786 it
->last_visible_x
-= 1;
2788 it
->last_visible_y
= window_text_bottom_y (w
);
2790 /* For mode lines and alike, arrange for the first glyph having a
2791 left box line if the face specifies a box. */
2792 if (base_face_id
!= DEFAULT_FACE_ID
)
2796 it
->face_id
= remapped_base_face_id
;
2798 /* If we have a boxed mode line, make the first character appear
2799 with a left box line. */
2800 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2801 if (face
->box
!= FACE_NO_BOX
)
2802 it
->start_of_box_run_p
= 1;
2805 /* If a buffer position was specified, set the iterator there,
2806 getting overlays and face properties from that position. */
2807 if (charpos
>= BUF_BEG (current_buffer
))
2809 it
->end_charpos
= ZV
;
2811 IT_CHARPOS (*it
) = charpos
;
2813 /* Compute byte position if not specified. */
2814 if (bytepos
< charpos
)
2815 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2817 IT_BYTEPOS (*it
) = bytepos
;
2819 it
->start
= it
->current
;
2821 /* Compute faces etc. */
2822 reseat (it
, it
->current
.pos
, 1);
2829 /* Initialize IT for the display of window W with window start POS. */
2832 start_display (it
, w
, pos
)
2835 struct text_pos pos
;
2837 struct glyph_row
*row
;
2838 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2840 row
= w
->desired_matrix
->rows
+ first_vpos
;
2841 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2842 it
->first_vpos
= first_vpos
;
2844 /* Don't reseat to previous visible line start if current start
2845 position is in a string or image. */
2846 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2848 int start_at_line_beg_p
;
2849 int first_y
= it
->current_y
;
2851 /* If window start is not at a line start, skip forward to POS to
2852 get the correct continuation lines width. */
2853 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2854 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2855 if (!start_at_line_beg_p
)
2859 reseat_at_previous_visible_line_start (it
);
2860 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2862 new_x
= it
->current_x
+ it
->pixel_width
;
2864 /* If lines are continued, this line may end in the middle
2865 of a multi-glyph character (e.g. a control character
2866 displayed as \003, or in the middle of an overlay
2867 string). In this case move_it_to above will not have
2868 taken us to the start of the continuation line but to the
2869 end of the continued line. */
2870 if (it
->current_x
> 0
2871 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2872 && (/* And glyph doesn't fit on the line. */
2873 new_x
> it
->last_visible_x
2874 /* Or it fits exactly and we're on a window
2876 || (new_x
== it
->last_visible_x
2877 && FRAME_WINDOW_P (it
->f
))))
2879 if (it
->current
.dpvec_index
>= 0
2880 || it
->current
.overlay_string_index
>= 0)
2882 set_iterator_to_next (it
, 1);
2883 move_it_in_display_line_to (it
, -1, -1, 0);
2886 it
->continuation_lines_width
+= it
->current_x
;
2889 /* We're starting a new display line, not affected by the
2890 height of the continued line, so clear the appropriate
2891 fields in the iterator structure. */
2892 it
->max_ascent
= it
->max_descent
= 0;
2893 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2895 it
->current_y
= first_y
;
2897 it
->current_x
= it
->hpos
= 0;
2903 /* Return 1 if POS is a position in ellipses displayed for invisible
2904 text. W is the window we display, for text property lookup. */
2907 in_ellipses_for_invisible_text_p (pos
, w
)
2908 struct display_pos
*pos
;
2911 Lisp_Object prop
, window
;
2913 int charpos
= CHARPOS (pos
->pos
);
2915 /* If POS specifies a position in a display vector, this might
2916 be for an ellipsis displayed for invisible text. We won't
2917 get the iterator set up for delivering that ellipsis unless
2918 we make sure that it gets aware of the invisible text. */
2919 if (pos
->dpvec_index
>= 0
2920 && pos
->overlay_string_index
< 0
2921 && CHARPOS (pos
->string_pos
) < 0
2923 && (XSETWINDOW (window
, w
),
2924 prop
= Fget_char_property (make_number (charpos
),
2925 Qinvisible
, window
),
2926 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2928 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2930 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2937 /* Initialize IT for stepping through current_buffer in window W,
2938 starting at position POS that includes overlay string and display
2939 vector/ control character translation position information. Value
2940 is zero if there are overlay strings with newlines at POS. */
2943 init_from_display_pos (it
, w
, pos
)
2946 struct display_pos
*pos
;
2948 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2949 int i
, overlay_strings_with_newlines
= 0;
2951 /* If POS specifies a position in a display vector, this might
2952 be for an ellipsis displayed for invisible text. We won't
2953 get the iterator set up for delivering that ellipsis unless
2954 we make sure that it gets aware of the invisible text. */
2955 if (in_ellipses_for_invisible_text_p (pos
, w
))
2961 /* Keep in mind: the call to reseat in init_iterator skips invisible
2962 text, so we might end up at a position different from POS. This
2963 is only a problem when POS is a row start after a newline and an
2964 overlay starts there with an after-string, and the overlay has an
2965 invisible property. Since we don't skip invisible text in
2966 display_line and elsewhere immediately after consuming the
2967 newline before the row start, such a POS will not be in a string,
2968 but the call to init_iterator below will move us to the
2970 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2972 /* This only scans the current chunk -- it should scan all chunks.
2973 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2974 to 16 in 22.1 to make this a lesser problem. */
2975 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2977 const char *s
= SDATA (it
->overlay_strings
[i
]);
2978 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2980 while (s
< e
&& *s
!= '\n')
2985 overlay_strings_with_newlines
= 1;
2990 /* If position is within an overlay string, set up IT to the right
2992 if (pos
->overlay_string_index
>= 0)
2996 /* If the first overlay string happens to have a `display'
2997 property for an image, the iterator will be set up for that
2998 image, and we have to undo that setup first before we can
2999 correct the overlay string index. */
3000 if (it
->method
== GET_FROM_IMAGE
)
3003 /* We already have the first chunk of overlay strings in
3004 IT->overlay_strings. Load more until the one for
3005 pos->overlay_string_index is in IT->overlay_strings. */
3006 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3008 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3009 it
->current
.overlay_string_index
= 0;
3012 load_overlay_strings (it
, 0);
3013 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3017 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3018 relative_index
= (it
->current
.overlay_string_index
3019 % OVERLAY_STRING_CHUNK_SIZE
);
3020 it
->string
= it
->overlay_strings
[relative_index
];
3021 xassert (STRINGP (it
->string
));
3022 it
->current
.string_pos
= pos
->string_pos
;
3023 it
->method
= GET_FROM_STRING
;
3026 if (CHARPOS (pos
->string_pos
) >= 0)
3028 /* Recorded position is not in an overlay string, but in another
3029 string. This can only be a string from a `display' property.
3030 IT should already be filled with that string. */
3031 it
->current
.string_pos
= pos
->string_pos
;
3032 xassert (STRINGP (it
->string
));
3035 /* Restore position in display vector translations, control
3036 character translations or ellipses. */
3037 if (pos
->dpvec_index
>= 0)
3039 if (it
->dpvec
== NULL
)
3040 get_next_display_element (it
);
3041 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3042 it
->current
.dpvec_index
= pos
->dpvec_index
;
3046 return !overlay_strings_with_newlines
;
3050 /* Initialize IT for stepping through current_buffer in window W
3051 starting at ROW->start. */
3054 init_to_row_start (it
, w
, row
)
3057 struct glyph_row
*row
;
3059 init_from_display_pos (it
, w
, &row
->start
);
3060 it
->start
= row
->start
;
3061 it
->continuation_lines_width
= row
->continuation_lines_width
;
3066 /* Initialize IT for stepping through current_buffer in window W
3067 starting in the line following ROW, i.e. starting at ROW->end.
3068 Value is zero if there are overlay strings with newlines at ROW's
3072 init_to_row_end (it
, w
, row
)
3075 struct glyph_row
*row
;
3079 if (init_from_display_pos (it
, w
, &row
->end
))
3081 if (row
->continued_p
)
3082 it
->continuation_lines_width
3083 = row
->continuation_lines_width
+ row
->pixel_width
;
3094 /***********************************************************************
3096 ***********************************************************************/
3098 /* Called when IT reaches IT->stop_charpos. Handle text property and
3099 overlay changes. Set IT->stop_charpos to the next position where
3106 enum prop_handled handled
;
3107 int handle_overlay_change_p
;
3111 it
->current
.dpvec_index
= -1;
3112 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3113 it
->ignore_overlay_strings_at_pos_p
= 0;
3116 /* Use face of preceding text for ellipsis (if invisible) */
3117 if (it
->selective_display_ellipsis_p
)
3118 it
->saved_face_id
= it
->face_id
;
3122 handled
= HANDLED_NORMALLY
;
3124 /* Call text property handlers. */
3125 for (p
= it_props
; p
->handler
; ++p
)
3127 handled
= p
->handler (it
);
3129 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3131 else if (handled
== HANDLED_RETURN
)
3133 /* We still want to show before and after strings from
3134 overlays even if the actual buffer text is replaced. */
3135 if (!handle_overlay_change_p
3137 || !get_overlay_strings_1 (it
, 0, 0))
3140 setup_for_ellipsis (it
, 0);
3141 /* When handling a display spec, we might load an
3142 empty string. In that case, discard it here. We
3143 used to discard it in handle_single_display_spec,
3144 but that causes get_overlay_strings_1, above, to
3145 ignore overlay strings that we must check. */
3146 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3150 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3154 it
->ignore_overlay_strings_at_pos_p
= 1;
3155 it
->string_from_display_prop_p
= 0;
3156 handle_overlay_change_p
= 0;
3158 handled
= HANDLED_RECOMPUTE_PROPS
;
3161 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3162 handle_overlay_change_p
= 0;
3165 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3167 /* Don't check for overlay strings below when set to deliver
3168 characters from a display vector. */
3169 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3170 handle_overlay_change_p
= 0;
3172 /* Handle overlay changes.
3173 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3174 if it finds overlays. */
3175 if (handle_overlay_change_p
)
3176 handled
= handle_overlay_change (it
);
3181 setup_for_ellipsis (it
, 0);
3185 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3187 /* Determine where to stop next. */
3188 if (handled
== HANDLED_NORMALLY
)
3189 compute_stop_pos (it
);
3193 /* Compute IT->stop_charpos from text property and overlay change
3194 information for IT's current position. */
3197 compute_stop_pos (it
)
3200 register INTERVAL iv
, next_iv
;
3201 Lisp_Object object
, limit
, position
;
3202 EMACS_INT charpos
, bytepos
;
3204 /* If nowhere else, stop at the end. */
3205 it
->stop_charpos
= it
->end_charpos
;
3207 if (STRINGP (it
->string
))
3209 /* Strings are usually short, so don't limit the search for
3211 object
= it
->string
;
3213 charpos
= IT_STRING_CHARPOS (*it
);
3214 bytepos
= IT_STRING_BYTEPOS (*it
);
3220 /* If next overlay change is in front of the current stop pos
3221 (which is IT->end_charpos), stop there. Note: value of
3222 next_overlay_change is point-max if no overlay change
3224 charpos
= IT_CHARPOS (*it
);
3225 bytepos
= IT_BYTEPOS (*it
);
3226 pos
= next_overlay_change (charpos
);
3227 if (pos
< it
->stop_charpos
)
3228 it
->stop_charpos
= pos
;
3230 /* If showing the region, we have to stop at the region
3231 start or end because the face might change there. */
3232 if (it
->region_beg_charpos
> 0)
3234 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3235 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3236 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3237 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3240 /* Set up variables for computing the stop position from text
3241 property changes. */
3242 XSETBUFFER (object
, current_buffer
);
3243 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3246 /* Get the interval containing IT's position. Value is a null
3247 interval if there isn't such an interval. */
3248 position
= make_number (charpos
);
3249 iv
= validate_interval_range (object
, &position
, &position
, 0);
3250 if (!NULL_INTERVAL_P (iv
))
3252 Lisp_Object values_here
[LAST_PROP_IDX
];
3255 /* Get properties here. */
3256 for (p
= it_props
; p
->handler
; ++p
)
3257 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3259 /* Look for an interval following iv that has different
3261 for (next_iv
= next_interval (iv
);
3262 (!NULL_INTERVAL_P (next_iv
)
3264 || XFASTINT (limit
) > next_iv
->position
));
3265 next_iv
= next_interval (next_iv
))
3267 for (p
= it_props
; p
->handler
; ++p
)
3269 Lisp_Object new_value
;
3271 new_value
= textget (next_iv
->plist
, *p
->name
);
3272 if (!EQ (values_here
[p
->idx
], new_value
))
3280 if (!NULL_INTERVAL_P (next_iv
))
3282 if (INTEGERP (limit
)
3283 && next_iv
->position
>= XFASTINT (limit
))
3284 /* No text property change up to limit. */
3285 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3287 /* Text properties change in next_iv. */
3288 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3292 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3293 it
->stop_charpos
, it
->string
);
3295 xassert (STRINGP (it
->string
)
3296 || (it
->stop_charpos
>= BEGV
3297 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3301 /* Return the position of the next overlay change after POS in
3302 current_buffer. Value is point-max if no overlay change
3303 follows. This is like `next-overlay-change' but doesn't use
3307 next_overlay_change (pos
)
3312 Lisp_Object
*overlays
;
3315 /* Get all overlays at the given position. */
3316 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3318 /* If any of these overlays ends before endpos,
3319 use its ending point instead. */
3320 for (i
= 0; i
< noverlays
; ++i
)
3325 oend
= OVERLAY_END (overlays
[i
]);
3326 oendpos
= OVERLAY_POSITION (oend
);
3327 endpos
= min (endpos
, oendpos
);
3335 /***********************************************************************
3337 ***********************************************************************/
3339 /* Handle changes in the `fontified' property of the current buffer by
3340 calling hook functions from Qfontification_functions to fontify
3343 static enum prop_handled
3344 handle_fontified_prop (it
)
3347 Lisp_Object prop
, pos
;
3348 enum prop_handled handled
= HANDLED_NORMALLY
;
3350 if (!NILP (Vmemory_full
))
3353 /* Get the value of the `fontified' property at IT's current buffer
3354 position. (The `fontified' property doesn't have a special
3355 meaning in strings.) If the value is nil, call functions from
3356 Qfontification_functions. */
3357 if (!STRINGP (it
->string
)
3359 && !NILP (Vfontification_functions
)
3360 && !NILP (Vrun_hooks
)
3361 && (pos
= make_number (IT_CHARPOS (*it
)),
3362 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3363 /* Ignore the special cased nil value always present at EOB since
3364 no amount of fontifying will be able to change it. */
3365 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3367 int count
= SPECPDL_INDEX ();
3370 val
= Vfontification_functions
;
3371 specbind (Qfontification_functions
, Qnil
);
3373 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3374 safe_call1 (val
, pos
);
3377 Lisp_Object globals
, fn
;
3378 struct gcpro gcpro1
, gcpro2
;
3381 GCPRO2 (val
, globals
);
3383 for (; CONSP (val
); val
= XCDR (val
))
3389 /* A value of t indicates this hook has a local
3390 binding; it means to run the global binding too.
3391 In a global value, t should not occur. If it
3392 does, we must ignore it to avoid an endless
3394 for (globals
= Fdefault_value (Qfontification_functions
);
3396 globals
= XCDR (globals
))
3398 fn
= XCAR (globals
);
3400 safe_call1 (fn
, pos
);
3404 safe_call1 (fn
, pos
);
3410 unbind_to (count
, Qnil
);
3412 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3413 something. This avoids an endless loop if they failed to
3414 fontify the text for which reason ever. */
3415 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3416 handled
= HANDLED_RECOMPUTE_PROPS
;
3424 /***********************************************************************
3426 ***********************************************************************/
3428 /* Set up iterator IT from face properties at its current position.
3429 Called from handle_stop. */
3431 static enum prop_handled
3432 handle_face_prop (it
)
3436 EMACS_INT next_stop
;
3438 if (!STRINGP (it
->string
))
3441 = face_at_buffer_position (it
->w
,
3443 it
->region_beg_charpos
,
3444 it
->region_end_charpos
,
3447 + TEXT_PROP_DISTANCE_LIMIT
),
3448 0, it
->base_face_id
);
3450 /* Is this a start of a run of characters with box face?
3451 Caveat: this can be called for a freshly initialized
3452 iterator; face_id is -1 in this case. We know that the new
3453 face will not change until limit, i.e. if the new face has a
3454 box, all characters up to limit will have one. But, as
3455 usual, we don't know whether limit is really the end. */
3456 if (new_face_id
!= it
->face_id
)
3458 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3460 /* If new face has a box but old face has not, this is
3461 the start of a run of characters with box, i.e. it has
3462 a shadow on the left side. The value of face_id of the
3463 iterator will be -1 if this is the initial call that gets
3464 the face. In this case, we have to look in front of IT's
3465 position and see whether there is a face != new_face_id. */
3466 it
->start_of_box_run_p
3467 = (new_face
->box
!= FACE_NO_BOX
3468 && (it
->face_id
>= 0
3469 || IT_CHARPOS (*it
) == BEG
3470 || new_face_id
!= face_before_it_pos (it
)));
3471 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3476 int base_face_id
, bufpos
;
3478 Lisp_Object from_overlay
3479 = (it
->current
.overlay_string_index
>= 0
3480 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3483 /* See if we got to this string directly or indirectly from
3484 an overlay property. That includes the before-string or
3485 after-string of an overlay, strings in display properties
3486 provided by an overlay, their text properties, etc.
3488 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3489 if (! NILP (from_overlay
))
3490 for (i
= it
->sp
- 1; i
>= 0; i
--)
3492 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3494 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3495 else if (! NILP (it
->stack
[i
].from_overlay
))
3496 from_overlay
= it
->stack
[i
].from_overlay
;
3498 if (!NILP (from_overlay
))
3502 if (! NILP (from_overlay
))
3504 bufpos
= IT_CHARPOS (*it
);
3505 /* For a string from an overlay, the base face depends
3506 only on text properties and ignores overlays. */
3508 = face_for_overlay_string (it
->w
,
3510 it
->region_beg_charpos
,
3511 it
->region_end_charpos
,
3514 + TEXT_PROP_DISTANCE_LIMIT
),
3522 /* For strings from a `display' property, use the face at
3523 IT's current buffer position as the base face to merge
3524 with, so that overlay strings appear in the same face as
3525 surrounding text, unless they specify their own
3527 base_face_id
= underlying_face_id (it
);
3530 new_face_id
= face_at_string_position (it
->w
,
3532 IT_STRING_CHARPOS (*it
),
3534 it
->region_beg_charpos
,
3535 it
->region_end_charpos
,
3539 /* Is this a start of a run of characters with box? Caveat:
3540 this can be called for a freshly allocated iterator; face_id
3541 is -1 is this case. We know that the new face will not
3542 change until the next check pos, i.e. if the new face has a
3543 box, all characters up to that position will have a
3544 box. But, as usual, we don't know whether that position
3545 is really the end. */
3546 if (new_face_id
!= it
->face_id
)
3548 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3549 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3551 /* If new face has a box but old face hasn't, this is the
3552 start of a run of characters with box, i.e. it has a
3553 shadow on the left side. */
3554 it
->start_of_box_run_p
3555 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3556 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3560 it
->face_id
= new_face_id
;
3561 return HANDLED_NORMALLY
;
3565 /* Return the ID of the face ``underlying'' IT's current position,
3566 which is in a string. If the iterator is associated with a
3567 buffer, return the face at IT's current buffer position.
3568 Otherwise, use the iterator's base_face_id. */
3571 underlying_face_id (it
)
3574 int face_id
= it
->base_face_id
, i
;
3576 xassert (STRINGP (it
->string
));
3578 for (i
= it
->sp
- 1; i
>= 0; --i
)
3579 if (NILP (it
->stack
[i
].string
))
3580 face_id
= it
->stack
[i
].face_id
;
3586 /* Compute the face one character before or after the current position
3587 of IT. BEFORE_P non-zero means get the face in front of IT's
3588 position. Value is the id of the face. */
3591 face_before_or_after_it_pos (it
, before_p
)
3596 EMACS_INT next_check_charpos
;
3597 struct text_pos pos
;
3599 xassert (it
->s
== NULL
);
3601 if (STRINGP (it
->string
))
3603 int bufpos
, base_face_id
;
3605 /* No face change past the end of the string (for the case
3606 we are padding with spaces). No face change before the
3608 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3609 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3612 /* Set pos to the position before or after IT's current position. */
3614 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3616 /* For composition, we must check the character after the
3618 pos
= (it
->what
== IT_COMPOSITION
3619 ? string_pos (IT_STRING_CHARPOS (*it
)
3620 + it
->cmp_it
.nchars
, it
->string
)
3621 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3623 if (it
->current
.overlay_string_index
>= 0)
3624 bufpos
= IT_CHARPOS (*it
);
3628 base_face_id
= underlying_face_id (it
);
3630 /* Get the face for ASCII, or unibyte. */
3631 face_id
= face_at_string_position (it
->w
,
3635 it
->region_beg_charpos
,
3636 it
->region_end_charpos
,
3637 &next_check_charpos
,
3640 /* Correct the face for charsets different from ASCII. Do it
3641 for the multibyte case only. The face returned above is
3642 suitable for unibyte text if IT->string is unibyte. */
3643 if (STRING_MULTIBYTE (it
->string
))
3645 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3646 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3648 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3650 c
= string_char_and_length (p
, rest
, &len
);
3651 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3656 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3657 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3660 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3661 pos
= it
->current
.pos
;
3664 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3667 if (it
->what
== IT_COMPOSITION
)
3668 /* For composition, we must check the position after the
3670 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3672 INC_TEXT_POS (pos
, it
->multibyte_p
);
3675 /* Determine face for CHARSET_ASCII, or unibyte. */
3676 face_id
= face_at_buffer_position (it
->w
,
3678 it
->region_beg_charpos
,
3679 it
->region_end_charpos
,
3680 &next_check_charpos
,
3683 /* Correct the face for charsets different from ASCII. Do it
3684 for the multibyte case only. The face returned above is
3685 suitable for unibyte text if current_buffer is unibyte. */
3686 if (it
->multibyte_p
)
3688 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3689 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3690 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3699 /***********************************************************************
3701 ***********************************************************************/
3703 /* Set up iterator IT from invisible properties at its current
3704 position. Called from handle_stop. */
3706 static enum prop_handled
3707 handle_invisible_prop (it
)
3710 enum prop_handled handled
= HANDLED_NORMALLY
;
3712 if (STRINGP (it
->string
))
3714 extern Lisp_Object Qinvisible
;
3715 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3717 /* Get the value of the invisible text property at the
3718 current position. Value will be nil if there is no such
3720 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3721 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3724 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3726 handled
= HANDLED_RECOMPUTE_PROPS
;
3728 /* Get the position at which the next change of the
3729 invisible text property can be found in IT->string.
3730 Value will be nil if the property value is the same for
3731 all the rest of IT->string. */
3732 XSETINT (limit
, SCHARS (it
->string
));
3733 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3736 /* Text at current position is invisible. The next
3737 change in the property is at position end_charpos.
3738 Move IT's current position to that position. */
3739 if (INTEGERP (end_charpos
)
3740 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3742 struct text_pos old
;
3743 old
= it
->current
.string_pos
;
3744 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3745 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3749 /* The rest of the string is invisible. If this is an
3750 overlay string, proceed with the next overlay string
3751 or whatever comes and return a character from there. */
3752 if (it
->current
.overlay_string_index
>= 0)
3754 next_overlay_string (it
);
3755 /* Don't check for overlay strings when we just
3756 finished processing them. */
3757 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3761 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3762 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3770 EMACS_INT newpos
, next_stop
, start_charpos
;
3771 Lisp_Object pos
, prop
, overlay
;
3773 /* First of all, is there invisible text at this position? */
3774 start_charpos
= IT_CHARPOS (*it
);
3775 pos
= make_number (IT_CHARPOS (*it
));
3776 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3778 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3780 /* If we are on invisible text, skip over it. */
3781 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3783 /* Record whether we have to display an ellipsis for the
3785 int display_ellipsis_p
= invis_p
== 2;
3787 handled
= HANDLED_RECOMPUTE_PROPS
;
3789 /* Loop skipping over invisible text. The loop is left at
3790 ZV or with IT on the first char being visible again. */
3793 /* Try to skip some invisible text. Return value is the
3794 position reached which can be equal to IT's position
3795 if there is nothing invisible here. This skips both
3796 over invisible text properties and overlays with
3797 invisible property. */
3798 newpos
= skip_invisible (IT_CHARPOS (*it
),
3799 &next_stop
, ZV
, it
->window
);
3801 /* If we skipped nothing at all we weren't at invisible
3802 text in the first place. If everything to the end of
3803 the buffer was skipped, end the loop. */
3804 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3808 /* We skipped some characters but not necessarily
3809 all there are. Check if we ended up on visible
3810 text. Fget_char_property returns the property of
3811 the char before the given position, i.e. if we
3812 get invis_p = 0, this means that the char at
3813 newpos is visible. */
3814 pos
= make_number (newpos
);
3815 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3816 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3819 /* If we ended up on invisible text, proceed to
3820 skip starting with next_stop. */
3822 IT_CHARPOS (*it
) = next_stop
;
3824 /* If there are adjacent invisible texts, don't lose the
3825 second one's ellipsis. */
3827 display_ellipsis_p
= 1;
3831 /* The position newpos is now either ZV or on visible text. */
3832 IT_CHARPOS (*it
) = newpos
;
3833 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3835 /* If there are before-strings at the start of invisible
3836 text, and the text is invisible because of a text
3837 property, arrange to show before-strings because 20.x did
3838 it that way. (If the text is invisible because of an
3839 overlay property instead of a text property, this is
3840 already handled in the overlay code.) */
3842 && get_overlay_strings (it
, start_charpos
))
3844 handled
= HANDLED_RECOMPUTE_PROPS
;
3845 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3847 else if (display_ellipsis_p
)
3849 /* Make sure that the glyphs of the ellipsis will get
3850 correct `charpos' values. If we would not update
3851 it->position here, the glyphs would belong to the
3852 last visible character _before_ the invisible
3853 text, which confuses `set_cursor_from_row'.
3855 We use the last invisible position instead of the
3856 first because this way the cursor is always drawn on
3857 the first "." of the ellipsis, whenever PT is inside
3858 the invisible text. Otherwise the cursor would be
3859 placed _after_ the ellipsis when the point is after the
3860 first invisible character. */
3861 if (!STRINGP (it
->object
))
3863 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3864 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3867 /* Let the ellipsis display before
3868 considering any properties of the following char.
3869 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3870 handled
= HANDLED_RETURN
;
3879 /* Make iterator IT return `...' next.
3880 Replaces LEN characters from buffer. */
3883 setup_for_ellipsis (it
, len
)
3887 /* Use the display table definition for `...'. Invalid glyphs
3888 will be handled by the method returning elements from dpvec. */
3889 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3891 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3892 it
->dpvec
= v
->contents
;
3893 it
->dpend
= v
->contents
+ v
->size
;
3897 /* Default `...'. */
3898 it
->dpvec
= default_invis_vector
;
3899 it
->dpend
= default_invis_vector
+ 3;
3902 it
->dpvec_char_len
= len
;
3903 it
->current
.dpvec_index
= 0;
3904 it
->dpvec_face_id
= -1;
3906 /* Remember the current face id in case glyphs specify faces.
3907 IT's face is restored in set_iterator_to_next.
3908 saved_face_id was set to preceding char's face in handle_stop. */
3909 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3910 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3912 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3918 /***********************************************************************
3920 ***********************************************************************/
3922 /* Set up iterator IT from `display' property at its current position.
3923 Called from handle_stop.
3924 We return HANDLED_RETURN if some part of the display property
3925 overrides the display of the buffer text itself.
3926 Otherwise we return HANDLED_NORMALLY. */
3928 static enum prop_handled
3929 handle_display_prop (it
)
3932 Lisp_Object prop
, object
, overlay
;
3933 struct text_pos
*position
;
3934 /* Nonzero if some property replaces the display of the text itself. */
3935 int display_replaced_p
= 0;
3937 if (STRINGP (it
->string
))
3939 object
= it
->string
;
3940 position
= &it
->current
.string_pos
;
3944 XSETWINDOW (object
, it
->w
);
3945 position
= &it
->current
.pos
;
3948 /* Reset those iterator values set from display property values. */
3949 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3950 it
->space_width
= Qnil
;
3951 it
->font_height
= Qnil
;
3954 /* We don't support recursive `display' properties, i.e. string
3955 values that have a string `display' property, that have a string
3956 `display' property etc. */
3957 if (!it
->string_from_display_prop_p
)
3958 it
->area
= TEXT_AREA
;
3960 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3961 Qdisplay
, object
, &overlay
);
3963 return HANDLED_NORMALLY
;
3964 /* Now OVERLAY is the overlay that gave us this property, or nil
3965 if it was a text property. */
3967 if (!STRINGP (it
->string
))
3968 object
= it
->w
->buffer
;
3971 /* Simple properties. */
3972 && !EQ (XCAR (prop
), Qimage
)
3973 && !EQ (XCAR (prop
), Qspace
)
3974 && !EQ (XCAR (prop
), Qwhen
)
3975 && !EQ (XCAR (prop
), Qslice
)
3976 && !EQ (XCAR (prop
), Qspace_width
)
3977 && !EQ (XCAR (prop
), Qheight
)
3978 && !EQ (XCAR (prop
), Qraise
)
3979 /* Marginal area specifications. */
3980 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3981 && !EQ (XCAR (prop
), Qleft_fringe
)
3982 && !EQ (XCAR (prop
), Qright_fringe
)
3983 && !NILP (XCAR (prop
)))
3985 for (; CONSP (prop
); prop
= XCDR (prop
))
3987 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3988 position
, display_replaced_p
))
3990 display_replaced_p
= 1;
3991 /* If some text in a string is replaced, `position' no
3992 longer points to the position of `object'. */
3993 if (STRINGP (object
))
3998 else if (VECTORP (prop
))
4001 for (i
= 0; i
< ASIZE (prop
); ++i
)
4002 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4003 position
, display_replaced_p
))
4005 display_replaced_p
= 1;
4006 /* If some text in a string is replaced, `position' no
4007 longer points to the position of `object'. */
4008 if (STRINGP (object
))
4014 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4016 display_replaced_p
= 1;
4019 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4023 /* Value is the position of the end of the `display' property starting
4024 at START_POS in OBJECT. */
4026 static struct text_pos
4027 display_prop_end (it
, object
, start_pos
)
4030 struct text_pos start_pos
;
4033 struct text_pos end_pos
;
4035 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4036 Qdisplay
, object
, Qnil
);
4037 CHARPOS (end_pos
) = XFASTINT (end
);
4038 if (STRINGP (object
))
4039 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4041 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4047 /* Set up IT from a single `display' specification PROP. OBJECT
4048 is the object in which the `display' property was found. *POSITION
4049 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4050 means that we previously saw a display specification which already
4051 replaced text display with something else, for example an image;
4052 we ignore such properties after the first one has been processed.
4054 OVERLAY is the overlay this `display' property came from,
4055 or nil if it was a text property.
4057 If PROP is a `space' or `image' specification, and in some other
4058 cases too, set *POSITION to the position where the `display'
4061 Value is non-zero if something was found which replaces the display
4062 of buffer or string text. */
4065 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4066 display_replaced_before_p
)
4070 Lisp_Object overlay
;
4071 struct text_pos
*position
;
4072 int display_replaced_before_p
;
4075 Lisp_Object location
, value
;
4076 struct text_pos start_pos
, save_pos
;
4079 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4080 If the result is non-nil, use VALUE instead of SPEC. */
4082 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4091 if (!NILP (form
) && !EQ (form
, Qt
))
4093 int count
= SPECPDL_INDEX ();
4094 struct gcpro gcpro1
;
4096 /* Bind `object' to the object having the `display' property, a
4097 buffer or string. Bind `position' to the position in the
4098 object where the property was found, and `buffer-position'
4099 to the current position in the buffer. */
4100 specbind (Qobject
, object
);
4101 specbind (Qposition
, make_number (CHARPOS (*position
)));
4102 specbind (Qbuffer_position
,
4103 make_number (STRINGP (object
)
4104 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4106 form
= safe_eval (form
);
4108 unbind_to (count
, Qnil
);
4114 /* Handle `(height HEIGHT)' specifications. */
4116 && EQ (XCAR (spec
), Qheight
)
4117 && CONSP (XCDR (spec
)))
4119 if (!FRAME_WINDOW_P (it
->f
))
4122 it
->font_height
= XCAR (XCDR (spec
));
4123 if (!NILP (it
->font_height
))
4125 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4126 int new_height
= -1;
4128 if (CONSP (it
->font_height
)
4129 && (EQ (XCAR (it
->font_height
), Qplus
)
4130 || EQ (XCAR (it
->font_height
), Qminus
))
4131 && CONSP (XCDR (it
->font_height
))
4132 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4134 /* `(+ N)' or `(- N)' where N is an integer. */
4135 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4136 if (EQ (XCAR (it
->font_height
), Qplus
))
4138 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4140 else if (FUNCTIONP (it
->font_height
))
4142 /* Call function with current height as argument.
4143 Value is the new height. */
4145 height
= safe_call1 (it
->font_height
,
4146 face
->lface
[LFACE_HEIGHT_INDEX
]);
4147 if (NUMBERP (height
))
4148 new_height
= XFLOATINT (height
);
4150 else if (NUMBERP (it
->font_height
))
4152 /* Value is a multiple of the canonical char height. */
4155 face
= FACE_FROM_ID (it
->f
,
4156 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4157 new_height
= (XFLOATINT (it
->font_height
)
4158 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4162 /* Evaluate IT->font_height with `height' bound to the
4163 current specified height to get the new height. */
4164 int count
= SPECPDL_INDEX ();
4166 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4167 value
= safe_eval (it
->font_height
);
4168 unbind_to (count
, Qnil
);
4170 if (NUMBERP (value
))
4171 new_height
= XFLOATINT (value
);
4175 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4181 /* Handle `(space-width WIDTH)'. */
4183 && EQ (XCAR (spec
), Qspace_width
)
4184 && CONSP (XCDR (spec
)))
4186 if (!FRAME_WINDOW_P (it
->f
))
4189 value
= XCAR (XCDR (spec
));
4190 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4191 it
->space_width
= value
;
4196 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4198 && EQ (XCAR (spec
), Qslice
))
4202 if (!FRAME_WINDOW_P (it
->f
))
4205 if (tem
= XCDR (spec
), CONSP (tem
))
4207 it
->slice
.x
= XCAR (tem
);
4208 if (tem
= XCDR (tem
), CONSP (tem
))
4210 it
->slice
.y
= XCAR (tem
);
4211 if (tem
= XCDR (tem
), CONSP (tem
))
4213 it
->slice
.width
= XCAR (tem
);
4214 if (tem
= XCDR (tem
), CONSP (tem
))
4215 it
->slice
.height
= XCAR (tem
);
4223 /* Handle `(raise FACTOR)'. */
4225 && EQ (XCAR (spec
), Qraise
)
4226 && CONSP (XCDR (spec
)))
4228 if (!FRAME_WINDOW_P (it
->f
))
4231 #ifdef HAVE_WINDOW_SYSTEM
4232 value
= XCAR (XCDR (spec
));
4233 if (NUMBERP (value
))
4235 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4236 it
->voffset
= - (XFLOATINT (value
)
4237 * (FONT_HEIGHT (face
->font
)));
4239 #endif /* HAVE_WINDOW_SYSTEM */
4244 /* Don't handle the other kinds of display specifications
4245 inside a string that we got from a `display' property. */
4246 if (it
->string_from_display_prop_p
)
4249 /* Characters having this form of property are not displayed, so
4250 we have to find the end of the property. */
4251 start_pos
= *position
;
4252 *position
= display_prop_end (it
, object
, start_pos
);
4255 /* Stop the scan at that end position--we assume that all
4256 text properties change there. */
4257 it
->stop_charpos
= position
->charpos
;
4259 /* Handle `(left-fringe BITMAP [FACE])'
4260 and `(right-fringe BITMAP [FACE])'. */
4262 && (EQ (XCAR (spec
), Qleft_fringe
)
4263 || EQ (XCAR (spec
), Qright_fringe
))
4264 && CONSP (XCDR (spec
)))
4266 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4269 if (!FRAME_WINDOW_P (it
->f
))
4270 /* If we return here, POSITION has been advanced
4271 across the text with this property. */
4274 #ifdef HAVE_WINDOW_SYSTEM
4275 value
= XCAR (XCDR (spec
));
4276 if (!SYMBOLP (value
)
4277 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4278 /* If we return here, POSITION has been advanced
4279 across the text with this property. */
4282 if (CONSP (XCDR (XCDR (spec
))))
4284 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4285 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4291 /* Save current settings of IT so that we can restore them
4292 when we are finished with the glyph property value. */
4294 save_pos
= it
->position
;
4295 it
->position
= *position
;
4297 it
->position
= save_pos
;
4299 it
->area
= TEXT_AREA
;
4300 it
->what
= IT_IMAGE
;
4301 it
->image_id
= -1; /* no image */
4302 it
->position
= start_pos
;
4303 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4304 it
->method
= GET_FROM_IMAGE
;
4305 it
->from_overlay
= Qnil
;
4306 it
->face_id
= face_id
;
4308 /* Say that we haven't consumed the characters with
4309 `display' property yet. The call to pop_it in
4310 set_iterator_to_next will clean this up. */
4311 *position
= start_pos
;
4313 if (EQ (XCAR (spec
), Qleft_fringe
))
4315 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4316 it
->left_user_fringe_face_id
= face_id
;
4320 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4321 it
->right_user_fringe_face_id
= face_id
;
4323 #endif /* HAVE_WINDOW_SYSTEM */
4327 /* Prepare to handle `((margin left-margin) ...)',
4328 `((margin right-margin) ...)' and `((margin nil) ...)'
4329 prefixes for display specifications. */
4330 location
= Qunbound
;
4331 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4335 value
= XCDR (spec
);
4337 value
= XCAR (value
);
4340 if (EQ (XCAR (tem
), Qmargin
)
4341 && (tem
= XCDR (tem
),
4342 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4344 || EQ (tem
, Qleft_margin
)
4345 || EQ (tem
, Qright_margin
))))
4349 if (EQ (location
, Qunbound
))
4355 /* After this point, VALUE is the property after any
4356 margin prefix has been stripped. It must be a string,
4357 an image specification, or `(space ...)'.
4359 LOCATION specifies where to display: `left-margin',
4360 `right-margin' or nil. */
4362 valid_p
= (STRINGP (value
)
4363 #ifdef HAVE_WINDOW_SYSTEM
4364 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4365 #endif /* not HAVE_WINDOW_SYSTEM */
4366 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4368 if (valid_p
&& !display_replaced_before_p
)
4370 /* Save current settings of IT so that we can restore them
4371 when we are finished with the glyph property value. */
4372 save_pos
= it
->position
;
4373 it
->position
= *position
;
4375 it
->position
= save_pos
;
4376 it
->from_overlay
= overlay
;
4378 if (NILP (location
))
4379 it
->area
= TEXT_AREA
;
4380 else if (EQ (location
, Qleft_margin
))
4381 it
->area
= LEFT_MARGIN_AREA
;
4383 it
->area
= RIGHT_MARGIN_AREA
;
4385 if (STRINGP (value
))
4388 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4389 it
->current
.overlay_string_index
= -1;
4390 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4391 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4392 it
->method
= GET_FROM_STRING
;
4393 it
->stop_charpos
= 0;
4394 it
->string_from_display_prop_p
= 1;
4395 /* Say that we haven't consumed the characters with
4396 `display' property yet. The call to pop_it in
4397 set_iterator_to_next will clean this up. */
4398 if (BUFFERP (object
))
4399 *position
= start_pos
;
4401 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4403 it
->method
= GET_FROM_STRETCH
;
4405 *position
= it
->position
= start_pos
;
4407 #ifdef HAVE_WINDOW_SYSTEM
4410 it
->what
= IT_IMAGE
;
4411 it
->image_id
= lookup_image (it
->f
, value
);
4412 it
->position
= start_pos
;
4413 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4414 it
->method
= GET_FROM_IMAGE
;
4416 /* Say that we haven't consumed the characters with
4417 `display' property yet. The call to pop_it in
4418 set_iterator_to_next will clean this up. */
4419 *position
= start_pos
;
4421 #endif /* HAVE_WINDOW_SYSTEM */
4426 /* Invalid property or property not supported. Restore
4427 POSITION to what it was before. */
4428 *position
= start_pos
;
4433 /* Check if SPEC is a display sub-property value whose text should be
4434 treated as intangible. */
4437 single_display_spec_intangible_p (prop
)
4440 /* Skip over `when FORM'. */
4441 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4455 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4456 we don't need to treat text as intangible. */
4457 if (EQ (XCAR (prop
), Qmargin
))
4465 || EQ (XCAR (prop
), Qleft_margin
)
4466 || EQ (XCAR (prop
), Qright_margin
))
4470 return (CONSP (prop
)
4471 && (EQ (XCAR (prop
), Qimage
)
4472 || EQ (XCAR (prop
), Qspace
)));
4476 /* Check if PROP is a display property value whose text should be
4477 treated as intangible. */
4480 display_prop_intangible_p (prop
)
4484 && CONSP (XCAR (prop
))
4485 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4487 /* A list of sub-properties. */
4488 while (CONSP (prop
))
4490 if (single_display_spec_intangible_p (XCAR (prop
)))
4495 else if (VECTORP (prop
))
4497 /* A vector of sub-properties. */
4499 for (i
= 0; i
< ASIZE (prop
); ++i
)
4500 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4504 return single_display_spec_intangible_p (prop
);
4510 /* Return 1 if PROP is a display sub-property value containing STRING. */
4513 single_display_spec_string_p (prop
, string
)
4514 Lisp_Object prop
, string
;
4516 if (EQ (string
, prop
))
4519 /* Skip over `when FORM'. */
4520 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4529 /* Skip over `margin LOCATION'. */
4530 if (EQ (XCAR (prop
), Qmargin
))
4541 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4545 /* Return 1 if STRING appears in the `display' property PROP. */
4548 display_prop_string_p (prop
, string
)
4549 Lisp_Object prop
, string
;
4552 && CONSP (XCAR (prop
))
4553 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4555 /* A list of sub-properties. */
4556 while (CONSP (prop
))
4558 if (single_display_spec_string_p (XCAR (prop
), string
))
4563 else if (VECTORP (prop
))
4565 /* A vector of sub-properties. */
4567 for (i
= 0; i
< ASIZE (prop
); ++i
)
4568 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4572 return single_display_spec_string_p (prop
, string
);
4578 /* Determine from which buffer position in W's buffer STRING comes
4579 from. AROUND_CHARPOS is an approximate position where it could
4580 be from. Value is the buffer position or 0 if it couldn't be
4583 W's buffer must be current.
4585 This function is necessary because we don't record buffer positions
4586 in glyphs generated from strings (to keep struct glyph small).
4587 This function may only use code that doesn't eval because it is
4588 called asynchronously from note_mouse_highlight. */
4591 string_buffer_position (w
, string
, around_charpos
)
4596 Lisp_Object limit
, prop
, pos
;
4597 const int MAX_DISTANCE
= 1000;
4600 pos
= make_number (around_charpos
);
4601 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4602 while (!found
&& !EQ (pos
, limit
))
4604 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4605 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4608 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4613 pos
= make_number (around_charpos
);
4614 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4615 while (!found
&& !EQ (pos
, limit
))
4617 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4618 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4621 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4626 return found
? XINT (pos
) : 0;
4631 /***********************************************************************
4632 `composition' property
4633 ***********************************************************************/
4635 /* Set up iterator IT from `composition' property at its current
4636 position. Called from handle_stop. */
4638 static enum prop_handled
4639 handle_composition_prop (it
)
4642 Lisp_Object prop
, string
;
4643 EMACS_INT pos
, pos_byte
, start
, end
;
4645 if (STRINGP (it
->string
))
4649 pos
= IT_STRING_CHARPOS (*it
);
4650 pos_byte
= IT_STRING_BYTEPOS (*it
);
4651 string
= it
->string
;
4652 s
= SDATA (string
) + pos_byte
;
4653 it
->c
= STRING_CHAR (s
, 0);
4657 pos
= IT_CHARPOS (*it
);
4658 pos_byte
= IT_BYTEPOS (*it
);
4660 it
->c
= FETCH_CHAR (pos_byte
);
4663 /* If there's a valid composition and point is not inside of the
4664 composition (in the case that the composition is from the current
4665 buffer), draw a glyph composed from the composition components. */
4666 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4667 && COMPOSITION_VALID_P (start
, end
, prop
)
4668 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4672 if (STRINGP (it
->string
))
4673 pos_byte
= string_char_to_byte (it
->string
, start
);
4675 pos_byte
= CHAR_TO_BYTE (start
);
4677 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4680 if (it
->cmp_it
.id
>= 0)
4683 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4684 it
->cmp_it
.nglyphs
= -1;
4688 return HANDLED_NORMALLY
;
4693 /***********************************************************************
4695 ***********************************************************************/
4697 /* The following structure is used to record overlay strings for
4698 later sorting in load_overlay_strings. */
4700 struct overlay_entry
4702 Lisp_Object overlay
;
4709 /* Set up iterator IT from overlay strings at its current position.
4710 Called from handle_stop. */
4712 static enum prop_handled
4713 handle_overlay_change (it
)
4716 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4717 return HANDLED_RECOMPUTE_PROPS
;
4719 return HANDLED_NORMALLY
;
4723 /* Set up the next overlay string for delivery by IT, if there is an
4724 overlay string to deliver. Called by set_iterator_to_next when the
4725 end of the current overlay string is reached. If there are more
4726 overlay strings to display, IT->string and
4727 IT->current.overlay_string_index are set appropriately here.
4728 Otherwise IT->string is set to nil. */
4731 next_overlay_string (it
)
4734 ++it
->current
.overlay_string_index
;
4735 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4737 /* No more overlay strings. Restore IT's settings to what
4738 they were before overlay strings were processed, and
4739 continue to deliver from current_buffer. */
4741 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4744 || (NILP (it
->string
)
4745 && it
->method
== GET_FROM_BUFFER
4746 && it
->stop_charpos
>= BEGV
4747 && it
->stop_charpos
<= it
->end_charpos
));
4748 it
->current
.overlay_string_index
= -1;
4749 it
->n_overlay_strings
= 0;
4751 /* If we're at the end of the buffer, record that we have
4752 processed the overlay strings there already, so that
4753 next_element_from_buffer doesn't try it again. */
4754 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4755 it
->overlay_strings_at_end_processed_p
= 1;
4759 /* There are more overlay strings to process. If
4760 IT->current.overlay_string_index has advanced to a position
4761 where we must load IT->overlay_strings with more strings, do
4763 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4765 if (it
->current
.overlay_string_index
&& i
== 0)
4766 load_overlay_strings (it
, 0);
4768 /* Initialize IT to deliver display elements from the overlay
4770 it
->string
= it
->overlay_strings
[i
];
4771 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4772 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4773 it
->method
= GET_FROM_STRING
;
4774 it
->stop_charpos
= 0;
4775 if (it
->cmp_it
.stop_pos
>= 0)
4776 it
->cmp_it
.stop_pos
= 0;
4783 /* Compare two overlay_entry structures E1 and E2. Used as a
4784 comparison function for qsort in load_overlay_strings. Overlay
4785 strings for the same position are sorted so that
4787 1. All after-strings come in front of before-strings, except
4788 when they come from the same overlay.
4790 2. Within after-strings, strings are sorted so that overlay strings
4791 from overlays with higher priorities come first.
4793 2. Within before-strings, strings are sorted so that overlay
4794 strings from overlays with higher priorities come last.
4796 Value is analogous to strcmp. */
4800 compare_overlay_entries (e1
, e2
)
4803 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4804 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4807 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4809 /* Let after-strings appear in front of before-strings if
4810 they come from different overlays. */
4811 if (EQ (entry1
->overlay
, entry2
->overlay
))
4812 result
= entry1
->after_string_p
? 1 : -1;
4814 result
= entry1
->after_string_p
? -1 : 1;
4816 else if (entry1
->after_string_p
)
4817 /* After-strings sorted in order of decreasing priority. */
4818 result
= entry2
->priority
- entry1
->priority
;
4820 /* Before-strings sorted in order of increasing priority. */
4821 result
= entry1
->priority
- entry2
->priority
;
4827 /* Load the vector IT->overlay_strings with overlay strings from IT's
4828 current buffer position, or from CHARPOS if that is > 0. Set
4829 IT->n_overlays to the total number of overlay strings found.
4831 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4832 a time. On entry into load_overlay_strings,
4833 IT->current.overlay_string_index gives the number of overlay
4834 strings that have already been loaded by previous calls to this
4837 IT->add_overlay_start contains an additional overlay start
4838 position to consider for taking overlay strings from, if non-zero.
4839 This position comes into play when the overlay has an `invisible'
4840 property, and both before and after-strings. When we've skipped to
4841 the end of the overlay, because of its `invisible' property, we
4842 nevertheless want its before-string to appear.
4843 IT->add_overlay_start will contain the overlay start position
4846 Overlay strings are sorted so that after-string strings come in
4847 front of before-string strings. Within before and after-strings,
4848 strings are sorted by overlay priority. See also function
4849 compare_overlay_entries. */
4852 load_overlay_strings (it
, charpos
)
4856 extern Lisp_Object Qwindow
, Qpriority
;
4857 Lisp_Object overlay
, window
, str
, invisible
;
4858 struct Lisp_Overlay
*ov
;
4861 int n
= 0, i
, j
, invis_p
;
4862 struct overlay_entry
*entries
4863 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4866 charpos
= IT_CHARPOS (*it
);
4868 /* Append the overlay string STRING of overlay OVERLAY to vector
4869 `entries' which has size `size' and currently contains `n'
4870 elements. AFTER_P non-zero means STRING is an after-string of
4872 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4875 Lisp_Object priority; \
4879 int new_size = 2 * size; \
4880 struct overlay_entry *old = entries; \
4882 (struct overlay_entry *) alloca (new_size \
4883 * sizeof *entries); \
4884 bcopy (old, entries, size * sizeof *entries); \
4888 entries[n].string = (STRING); \
4889 entries[n].overlay = (OVERLAY); \
4890 priority = Foverlay_get ((OVERLAY), Qpriority); \
4891 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4892 entries[n].after_string_p = (AFTER_P); \
4897 /* Process overlay before the overlay center. */
4898 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4900 XSETMISC (overlay
, ov
);
4901 xassert (OVERLAYP (overlay
));
4902 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4903 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4908 /* Skip this overlay if it doesn't start or end at IT's current
4910 if (end
!= charpos
&& start
!= charpos
)
4913 /* Skip this overlay if it doesn't apply to IT->w. */
4914 window
= Foverlay_get (overlay
, Qwindow
);
4915 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4918 /* If the text ``under'' the overlay is invisible, both before-
4919 and after-strings from this overlay are visible; start and
4920 end position are indistinguishable. */
4921 invisible
= Foverlay_get (overlay
, Qinvisible
);
4922 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4924 /* If overlay has a non-empty before-string, record it. */
4925 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4926 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4928 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4930 /* If overlay has a non-empty after-string, record it. */
4931 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4932 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4934 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4937 /* Process overlays after the overlay center. */
4938 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4940 XSETMISC (overlay
, ov
);
4941 xassert (OVERLAYP (overlay
));
4942 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4943 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4945 if (start
> charpos
)
4948 /* Skip this overlay if it doesn't start or end at IT's current
4950 if (end
!= charpos
&& start
!= charpos
)
4953 /* Skip this overlay if it doesn't apply to IT->w. */
4954 window
= Foverlay_get (overlay
, Qwindow
);
4955 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4958 /* If the text ``under'' the overlay is invisible, it has a zero
4959 dimension, and both before- and after-strings apply. */
4960 invisible
= Foverlay_get (overlay
, Qinvisible
);
4961 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4963 /* If overlay has a non-empty before-string, record it. */
4964 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4965 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4967 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4969 /* If overlay has a non-empty after-string, record it. */
4970 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4971 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4973 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4976 #undef RECORD_OVERLAY_STRING
4980 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4982 /* Record the total number of strings to process. */
4983 it
->n_overlay_strings
= n
;
4985 /* IT->current.overlay_string_index is the number of overlay strings
4986 that have already been consumed by IT. Copy some of the
4987 remaining overlay strings to IT->overlay_strings. */
4989 j
= it
->current
.overlay_string_index
;
4990 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4992 it
->overlay_strings
[i
] = entries
[j
].string
;
4993 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5000 /* Get the first chunk of overlay strings at IT's current buffer
5001 position, or at CHARPOS if that is > 0. Value is non-zero if at
5002 least one overlay string was found. */
5005 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5010 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5011 process. This fills IT->overlay_strings with strings, and sets
5012 IT->n_overlay_strings to the total number of strings to process.
5013 IT->pos.overlay_string_index has to be set temporarily to zero
5014 because load_overlay_strings needs this; it must be set to -1
5015 when no overlay strings are found because a zero value would
5016 indicate a position in the first overlay string. */
5017 it
->current
.overlay_string_index
= 0;
5018 load_overlay_strings (it
, charpos
);
5020 /* If we found overlay strings, set up IT to deliver display
5021 elements from the first one. Otherwise set up IT to deliver
5022 from current_buffer. */
5023 if (it
->n_overlay_strings
)
5025 /* Make sure we know settings in current_buffer, so that we can
5026 restore meaningful values when we're done with the overlay
5029 compute_stop_pos (it
);
5030 xassert (it
->face_id
>= 0);
5032 /* Save IT's settings. They are restored after all overlay
5033 strings have been processed. */
5034 xassert (!compute_stop_p
|| it
->sp
== 0);
5036 /* When called from handle_stop, there might be an empty display
5037 string loaded. In that case, don't bother saving it. */
5038 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5041 /* Set up IT to deliver display elements from the first overlay
5043 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5044 it
->string
= it
->overlay_strings
[0];
5045 it
->from_overlay
= Qnil
;
5046 it
->stop_charpos
= 0;
5047 xassert (STRINGP (it
->string
));
5048 it
->end_charpos
= SCHARS (it
->string
);
5049 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5050 it
->method
= GET_FROM_STRING
;
5054 it
->current
.overlay_string_index
= -1;
5059 get_overlay_strings (it
, charpos
)
5064 it
->method
= GET_FROM_BUFFER
;
5066 (void) get_overlay_strings_1 (it
, charpos
, 1);
5070 /* Value is non-zero if we found at least one overlay string. */
5071 return STRINGP (it
->string
);
5076 /***********************************************************************
5077 Saving and restoring state
5078 ***********************************************************************/
5080 /* Save current settings of IT on IT->stack. Called, for example,
5081 before setting up IT for an overlay string, to be able to restore
5082 IT's settings to what they were after the overlay string has been
5089 struct iterator_stack_entry
*p
;
5091 xassert (it
->sp
< IT_STACK_SIZE
);
5092 p
= it
->stack
+ it
->sp
;
5094 p
->stop_charpos
= it
->stop_charpos
;
5095 p
->cmp_it
= it
->cmp_it
;
5096 xassert (it
->face_id
>= 0);
5097 p
->face_id
= it
->face_id
;
5098 p
->string
= it
->string
;
5099 p
->method
= it
->method
;
5100 p
->from_overlay
= it
->from_overlay
;
5103 case GET_FROM_IMAGE
:
5104 p
->u
.image
.object
= it
->object
;
5105 p
->u
.image
.image_id
= it
->image_id
;
5106 p
->u
.image
.slice
= it
->slice
;
5108 case GET_FROM_STRETCH
:
5109 p
->u
.stretch
.object
= it
->object
;
5112 p
->position
= it
->position
;
5113 p
->current
= it
->current
;
5114 p
->end_charpos
= it
->end_charpos
;
5115 p
->string_nchars
= it
->string_nchars
;
5117 p
->multibyte_p
= it
->multibyte_p
;
5118 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5119 p
->space_width
= it
->space_width
;
5120 p
->font_height
= it
->font_height
;
5121 p
->voffset
= it
->voffset
;
5122 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5123 p
->display_ellipsis_p
= 0;
5124 p
->line_wrap
= it
->line_wrap
;
5129 /* Restore IT's settings from IT->stack. Called, for example, when no
5130 more overlay strings must be processed, and we return to delivering
5131 display elements from a buffer, or when the end of a string from a
5132 `display' property is reached and we return to delivering display
5133 elements from an overlay string, or from a buffer. */
5139 struct iterator_stack_entry
*p
;
5141 xassert (it
->sp
> 0);
5143 p
= it
->stack
+ it
->sp
;
5144 it
->stop_charpos
= p
->stop_charpos
;
5145 it
->cmp_it
= p
->cmp_it
;
5146 it
->face_id
= p
->face_id
;
5147 it
->current
= p
->current
;
5148 it
->position
= p
->position
;
5149 it
->string
= p
->string
;
5150 it
->from_overlay
= p
->from_overlay
;
5151 if (NILP (it
->string
))
5152 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5153 it
->method
= p
->method
;
5156 case GET_FROM_IMAGE
:
5157 it
->image_id
= p
->u
.image
.image_id
;
5158 it
->object
= p
->u
.image
.object
;
5159 it
->slice
= p
->u
.image
.slice
;
5161 case GET_FROM_STRETCH
:
5162 it
->object
= p
->u
.comp
.object
;
5164 case GET_FROM_BUFFER
:
5165 it
->object
= it
->w
->buffer
;
5167 case GET_FROM_STRING
:
5168 it
->object
= it
->string
;
5171 it
->end_charpos
= p
->end_charpos
;
5172 it
->string_nchars
= p
->string_nchars
;
5174 it
->multibyte_p
= p
->multibyte_p
;
5175 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5176 it
->space_width
= p
->space_width
;
5177 it
->font_height
= p
->font_height
;
5178 it
->voffset
= p
->voffset
;
5179 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5180 it
->line_wrap
= p
->line_wrap
;
5185 /***********************************************************************
5187 ***********************************************************************/
5189 /* Set IT's current position to the previous line start. */
5192 back_to_previous_line_start (it
)
5195 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5196 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5200 /* Move IT to the next line start.
5202 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5203 we skipped over part of the text (as opposed to moving the iterator
5204 continuously over the text). Otherwise, don't change the value
5207 Newlines may come from buffer text, overlay strings, or strings
5208 displayed via the `display' property. That's the reason we can't
5209 simply use find_next_newline_no_quit.
5211 Note that this function may not skip over invisible text that is so
5212 because of text properties and immediately follows a newline. If
5213 it would, function reseat_at_next_visible_line_start, when called
5214 from set_iterator_to_next, would effectively make invisible
5215 characters following a newline part of the wrong glyph row, which
5216 leads to wrong cursor motion. */
5219 forward_to_next_line_start (it
, skipped_p
)
5223 int old_selective
, newline_found_p
, n
;
5224 const int MAX_NEWLINE_DISTANCE
= 500;
5226 /* If already on a newline, just consume it to avoid unintended
5227 skipping over invisible text below. */
5228 if (it
->what
== IT_CHARACTER
5230 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5232 set_iterator_to_next (it
, 0);
5237 /* Don't handle selective display in the following. It's (a)
5238 unnecessary because it's done by the caller, and (b) leads to an
5239 infinite recursion because next_element_from_ellipsis indirectly
5240 calls this function. */
5241 old_selective
= it
->selective
;
5244 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5245 from buffer text. */
5246 for (n
= newline_found_p
= 0;
5247 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5248 n
+= STRINGP (it
->string
) ? 0 : 1)
5250 if (!get_next_display_element (it
))
5252 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5253 set_iterator_to_next (it
, 0);
5256 /* If we didn't find a newline near enough, see if we can use a
5258 if (!newline_found_p
)
5260 int start
= IT_CHARPOS (*it
);
5261 int limit
= find_next_newline_no_quit (start
, 1);
5264 xassert (!STRINGP (it
->string
));
5266 /* If there isn't any `display' property in sight, and no
5267 overlays, we can just use the position of the newline in
5269 if (it
->stop_charpos
>= limit
5270 || ((pos
= Fnext_single_property_change (make_number (start
),
5272 Qnil
, make_number (limit
)),
5274 && next_overlay_change (start
) == ZV
))
5276 IT_CHARPOS (*it
) = limit
;
5277 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5278 *skipped_p
= newline_found_p
= 1;
5282 while (get_next_display_element (it
)
5283 && !newline_found_p
)
5285 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5286 set_iterator_to_next (it
, 0);
5291 it
->selective
= old_selective
;
5292 return newline_found_p
;
5296 /* Set IT's current position to the previous visible line start. Skip
5297 invisible text that is so either due to text properties or due to
5298 selective display. Caution: this does not change IT->current_x and
5302 back_to_previous_visible_line_start (it
)
5305 while (IT_CHARPOS (*it
) > BEGV
)
5307 back_to_previous_line_start (it
);
5309 if (IT_CHARPOS (*it
) <= BEGV
)
5312 /* If selective > 0, then lines indented more than that values
5314 if (it
->selective
> 0
5315 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5316 (double) it
->selective
)) /* iftc */
5319 /* Check the newline before point for invisibility. */
5322 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5323 Qinvisible
, it
->window
);
5324 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5328 if (IT_CHARPOS (*it
) <= BEGV
)
5335 Lisp_Object val
, overlay
;
5337 /* If newline is part of a composition, continue from start of composition */
5338 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5339 && beg
< IT_CHARPOS (*it
))
5342 /* If newline is replaced by a display property, find start of overlay
5343 or interval and continue search from that point. */
5345 pos
= --IT_CHARPOS (it2
);
5348 it2
.string_from_display_prop_p
= 0;
5349 if (handle_display_prop (&it2
) == HANDLED_RETURN
5350 && !NILP (val
= get_char_property_and_overlay
5351 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5352 && (OVERLAYP (overlay
)
5353 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5354 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5357 /* Newline is not replaced by anything -- so we are done. */
5363 IT_CHARPOS (*it
) = beg
;
5364 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5368 it
->continuation_lines_width
= 0;
5370 xassert (IT_CHARPOS (*it
) >= BEGV
);
5371 xassert (IT_CHARPOS (*it
) == BEGV
5372 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5377 /* Reseat iterator IT at the previous visible line start. Skip
5378 invisible text that is so either due to text properties or due to
5379 selective display. At the end, update IT's overlay information,
5380 face information etc. */
5383 reseat_at_previous_visible_line_start (it
)
5386 back_to_previous_visible_line_start (it
);
5387 reseat (it
, it
->current
.pos
, 1);
5392 /* Reseat iterator IT on the next visible line start in the current
5393 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5394 preceding the line start. Skip over invisible text that is so
5395 because of selective display. Compute faces, overlays etc at the
5396 new position. Note that this function does not skip over text that
5397 is invisible because of text properties. */
5400 reseat_at_next_visible_line_start (it
, on_newline_p
)
5404 int newline_found_p
, skipped_p
= 0;
5406 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5408 /* Skip over lines that are invisible because they are indented
5409 more than the value of IT->selective. */
5410 if (it
->selective
> 0)
5411 while (IT_CHARPOS (*it
) < ZV
5412 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5413 (double) it
->selective
)) /* iftc */
5415 xassert (IT_BYTEPOS (*it
) == BEGV
5416 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5417 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5420 /* Position on the newline if that's what's requested. */
5421 if (on_newline_p
&& newline_found_p
)
5423 if (STRINGP (it
->string
))
5425 if (IT_STRING_CHARPOS (*it
) > 0)
5427 --IT_STRING_CHARPOS (*it
);
5428 --IT_STRING_BYTEPOS (*it
);
5431 else if (IT_CHARPOS (*it
) > BEGV
)
5435 reseat (it
, it
->current
.pos
, 0);
5439 reseat (it
, it
->current
.pos
, 0);
5446 /***********************************************************************
5447 Changing an iterator's position
5448 ***********************************************************************/
5450 /* Change IT's current position to POS in current_buffer. If FORCE_P
5451 is non-zero, always check for text properties at the new position.
5452 Otherwise, text properties are only looked up if POS >=
5453 IT->check_charpos of a property. */
5456 reseat (it
, pos
, force_p
)
5458 struct text_pos pos
;
5461 int original_pos
= IT_CHARPOS (*it
);
5463 reseat_1 (it
, pos
, 0);
5465 /* Determine where to check text properties. Avoid doing it
5466 where possible because text property lookup is very expensive. */
5468 || CHARPOS (pos
) > it
->stop_charpos
5469 || CHARPOS (pos
) < original_pos
)
5476 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5477 IT->stop_pos to POS, also. */
5480 reseat_1 (it
, pos
, set_stop_p
)
5482 struct text_pos pos
;
5485 /* Don't call this function when scanning a C string. */
5486 xassert (it
->s
== NULL
);
5488 /* POS must be a reasonable value. */
5489 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5491 it
->current
.pos
= it
->position
= pos
;
5492 it
->end_charpos
= ZV
;
5494 it
->current
.dpvec_index
= -1;
5495 it
->current
.overlay_string_index
= -1;
5496 IT_STRING_CHARPOS (*it
) = -1;
5497 IT_STRING_BYTEPOS (*it
) = -1;
5499 it
->string_from_display_prop_p
= 0;
5500 it
->method
= GET_FROM_BUFFER
;
5501 it
->object
= it
->w
->buffer
;
5502 it
->area
= TEXT_AREA
;
5503 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5505 it
->string_from_display_prop_p
= 0;
5506 it
->face_before_selective_p
= 0;
5509 it
->stop_charpos
= CHARPOS (pos
);
5513 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5514 If S is non-null, it is a C string to iterate over. Otherwise,
5515 STRING gives a Lisp string to iterate over.
5517 If PRECISION > 0, don't return more then PRECISION number of
5518 characters from the string.
5520 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5521 characters have been returned. FIELD_WIDTH < 0 means an infinite
5524 MULTIBYTE = 0 means disable processing of multibyte characters,
5525 MULTIBYTE > 0 means enable it,
5526 MULTIBYTE < 0 means use IT->multibyte_p.
5528 IT must be initialized via a prior call to init_iterator before
5529 calling this function. */
5532 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5537 int precision
, field_width
, multibyte
;
5539 /* No region in strings. */
5540 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5542 /* No text property checks performed by default, but see below. */
5543 it
->stop_charpos
= -1;
5545 /* Set iterator position and end position. */
5546 bzero (&it
->current
, sizeof it
->current
);
5547 it
->current
.overlay_string_index
= -1;
5548 it
->current
.dpvec_index
= -1;
5549 xassert (charpos
>= 0);
5551 /* If STRING is specified, use its multibyteness, otherwise use the
5552 setting of MULTIBYTE, if specified. */
5554 it
->multibyte_p
= multibyte
> 0;
5558 xassert (STRINGP (string
));
5559 it
->string
= string
;
5561 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5562 it
->method
= GET_FROM_STRING
;
5563 it
->current
.string_pos
= string_pos (charpos
, string
);
5570 /* Note that we use IT->current.pos, not it->current.string_pos,
5571 for displaying C strings. */
5572 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5573 if (it
->multibyte_p
)
5575 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5576 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5580 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5581 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5584 it
->method
= GET_FROM_C_STRING
;
5587 /* PRECISION > 0 means don't return more than PRECISION characters
5589 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5590 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5592 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5593 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5594 FIELD_WIDTH < 0 means infinite field width. This is useful for
5595 padding with `-' at the end of a mode line. */
5596 if (field_width
< 0)
5597 field_width
= INFINITY
;
5598 if (field_width
> it
->end_charpos
- charpos
)
5599 it
->end_charpos
= charpos
+ field_width
;
5601 /* Use the standard display table for displaying strings. */
5602 if (DISP_TABLE_P (Vstandard_display_table
))
5603 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5605 it
->stop_charpos
= charpos
;
5611 /***********************************************************************
5613 ***********************************************************************/
5615 /* Map enum it_method value to corresponding next_element_from_* function. */
5617 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5619 next_element_from_buffer
,
5620 next_element_from_display_vector
,
5621 next_element_from_string
,
5622 next_element_from_c_string
,
5623 next_element_from_image
,
5624 next_element_from_stretch
5627 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5630 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5631 (possibly with the following characters). */
5633 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS) \
5634 ((IT)->cmp_it.id >= 0 \
5635 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5636 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5637 (IT)->end_charpos, (IT)->w, \
5638 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5642 /* Load IT's display element fields with information about the next
5643 display element from the current position of IT. Value is zero if
5644 end of buffer (or C string) is reached. */
5646 static struct frame
*last_escape_glyph_frame
= NULL
;
5647 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5648 static int last_escape_glyph_merged_face_id
= 0;
5651 get_next_display_element (it
)
5654 /* Non-zero means that we found a display element. Zero means that
5655 we hit the end of what we iterate over. Performance note: the
5656 function pointer `method' used here turns out to be faster than
5657 using a sequence of if-statements. */
5661 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5663 if (it
->what
== IT_CHARACTER
)
5665 /* Map via display table or translate control characters.
5666 IT->c, IT->len etc. have been set to the next character by
5667 the function call above. If we have a display table, and it
5668 contains an entry for IT->c, translate it. Don't do this if
5669 IT->c itself comes from a display table, otherwise we could
5670 end up in an infinite recursion. (An alternative could be to
5671 count the recursion depth of this function and signal an
5672 error when a certain maximum depth is reached.) Is it worth
5674 if (success_p
&& it
->dpvec
== NULL
)
5677 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5680 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5683 struct Lisp_Vector
*v
= XVECTOR (dv
);
5685 /* Return the first character from the display table
5686 entry, if not empty. If empty, don't display the
5687 current character. */
5690 it
->dpvec_char_len
= it
->len
;
5691 it
->dpvec
= v
->contents
;
5692 it
->dpend
= v
->contents
+ v
->size
;
5693 it
->current
.dpvec_index
= 0;
5694 it
->dpvec_face_id
= -1;
5695 it
->saved_face_id
= it
->face_id
;
5696 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5701 set_iterator_to_next (it
, 0);
5706 /* Translate control characters into `\003' or `^C' form.
5707 Control characters coming from a display table entry are
5708 currently not translated because we use IT->dpvec to hold
5709 the translation. This could easily be changed but I
5710 don't believe that it is worth doing.
5712 If it->multibyte_p is nonzero, non-printable non-ASCII
5713 characters are also translated to octal form.
5715 If it->multibyte_p is zero, eight-bit characters that
5716 don't have corresponding multibyte char code are also
5717 translated to octal form. */
5718 else if ((it
->c
< ' '
5719 ? (it
->area
!= TEXT_AREA
5720 /* In mode line, treat \n, \t like other crl chars. */
5723 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5724 || (it
->c
!= '\n' && it
->c
!= '\t'))
5726 ? (!CHAR_PRINTABLE_P (it
->c
)
5727 || (!NILP (Vnobreak_char_display
)
5728 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5729 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5731 && (! unibyte_display_via_language_environment
5732 || (DECODE_CHAR (unibyte
, it
->c
) <= 0xA0))))))
5734 /* IT->c is a control character which must be displayed
5735 either as '\003' or as `^C' where the '\\' and '^'
5736 can be defined in the display table. Fill
5737 IT->ctl_chars with glyphs for what we have to
5738 display. Then, set IT->dpvec to these glyphs. */
5741 int face_id
, lface_id
= 0 ;
5744 /* Handle control characters with ^. */
5746 if (it
->c
< 128 && it
->ctl_arrow_p
)
5750 g
= '^'; /* default glyph for Control */
5751 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5753 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5754 && GLYPH_CODE_CHAR_VALID_P (gc
))
5756 g
= GLYPH_CODE_CHAR (gc
);
5757 lface_id
= GLYPH_CODE_FACE (gc
);
5761 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5763 else if (it
->f
== last_escape_glyph_frame
5764 && it
->face_id
== last_escape_glyph_face_id
)
5766 face_id
= last_escape_glyph_merged_face_id
;
5770 /* Merge the escape-glyph face into the current face. */
5771 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5773 last_escape_glyph_frame
= it
->f
;
5774 last_escape_glyph_face_id
= it
->face_id
;
5775 last_escape_glyph_merged_face_id
= face_id
;
5778 XSETINT (it
->ctl_chars
[0], g
);
5779 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5781 goto display_control
;
5784 /* Handle non-break space in the mode where it only gets
5787 if (EQ (Vnobreak_char_display
, Qt
)
5790 /* Merge the no-break-space face into the current face. */
5791 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5795 XSETINT (it
->ctl_chars
[0], ' ');
5797 goto display_control
;
5800 /* Handle sequences that start with the "escape glyph". */
5802 /* the default escape glyph is \. */
5803 escape_glyph
= '\\';
5806 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5807 && GLYPH_CODE_CHAR_VALID_P (gc
))
5809 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5810 lface_id
= GLYPH_CODE_FACE (gc
);
5814 /* The display table specified a face.
5815 Merge it into face_id and also into escape_glyph. */
5816 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5819 else if (it
->f
== last_escape_glyph_frame
5820 && it
->face_id
== last_escape_glyph_face_id
)
5822 face_id
= last_escape_glyph_merged_face_id
;
5826 /* Merge the escape-glyph face into the current face. */
5827 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5829 last_escape_glyph_frame
= it
->f
;
5830 last_escape_glyph_face_id
= it
->face_id
;
5831 last_escape_glyph_merged_face_id
= face_id
;
5834 /* Handle soft hyphens in the mode where they only get
5837 if (EQ (Vnobreak_char_display
, Qt
)
5841 XSETINT (it
->ctl_chars
[0], '-');
5843 goto display_control
;
5846 /* Handle non-break space and soft hyphen
5847 with the escape glyph. */
5849 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5851 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5852 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5853 XSETINT (it
->ctl_chars
[1], it
->c
);
5855 goto display_control
;
5859 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5863 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5864 if (CHAR_BYTE8_P (it
->c
))
5866 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5869 else if (it
->c
< 256)
5876 /* It's an invalid character, which shouldn't
5877 happen actually, but due to bugs it may
5878 happen. Let's print the char as is, there's
5879 not much meaningful we can do with it. */
5881 str
[1] = it
->c
>> 8;
5882 str
[2] = it
->c
>> 16;
5883 str
[3] = it
->c
>> 24;
5887 for (i
= 0; i
< len
; i
++)
5890 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5891 /* Insert three more glyphs into IT->ctl_chars for
5892 the octal display of the character. */
5893 g
= ((str
[i
] >> 6) & 7) + '0';
5894 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5895 g
= ((str
[i
] >> 3) & 7) + '0';
5896 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5897 g
= (str
[i
] & 7) + '0';
5898 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5904 /* Set up IT->dpvec and return first character from it. */
5905 it
->dpvec_char_len
= it
->len
;
5906 it
->dpvec
= it
->ctl_chars
;
5907 it
->dpend
= it
->dpvec
+ ctl_len
;
5908 it
->current
.dpvec_index
= 0;
5909 it
->dpvec_face_id
= face_id
;
5910 it
->saved_face_id
= it
->face_id
;
5911 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5918 #ifdef HAVE_WINDOW_SYSTEM
5919 /* Adjust face id for a multibyte character. There are no multibyte
5920 character in unibyte text. */
5921 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5924 && FRAME_WINDOW_P (it
->f
))
5926 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5928 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5930 /* Automatic composition with glyph-string. */
5931 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5933 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5937 int pos
= (it
->s
? -1
5938 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5939 : IT_CHARPOS (*it
));
5941 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5946 /* Is this character the last one of a run of characters with
5947 box? If yes, set IT->end_of_box_run_p to 1. */
5951 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5953 int face_id
= underlying_face_id (it
);
5954 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5958 if (face
->box
== FACE_NO_BOX
)
5960 /* If the box comes from face properties in a
5961 display string, check faces in that string. */
5962 int string_face_id
= face_after_it_pos (it
);
5963 it
->end_of_box_run_p
5964 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5967 /* Otherwise, the box comes from the underlying face.
5968 If this is the last string character displayed, check
5969 the next buffer location. */
5970 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
5971 && (it
->current
.overlay_string_index
5972 == it
->n_overlay_strings
- 1))
5976 struct text_pos pos
= it
->current
.pos
;
5977 INC_TEXT_POS (pos
, it
->multibyte_p
);
5979 next_face_id
= face_at_buffer_position
5980 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
5981 it
->region_end_charpos
, &ignore
,
5982 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
5984 it
->end_of_box_run_p
5985 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
5992 int face_id
= face_after_it_pos (it
);
5993 it
->end_of_box_run_p
5994 = (face_id
!= it
->face_id
5995 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
5999 /* Value is 0 if end of buffer or string reached. */
6004 /* Move IT to the next display element.
6006 RESEAT_P non-zero means if called on a newline in buffer text,
6007 skip to the next visible line start.
6009 Functions get_next_display_element and set_iterator_to_next are
6010 separate because I find this arrangement easier to handle than a
6011 get_next_display_element function that also increments IT's
6012 position. The way it is we can first look at an iterator's current
6013 display element, decide whether it fits on a line, and if it does,
6014 increment the iterator position. The other way around we probably
6015 would either need a flag indicating whether the iterator has to be
6016 incremented the next time, or we would have to implement a
6017 decrement position function which would not be easy to write. */
6020 set_iterator_to_next (it
, reseat_p
)
6024 /* Reset flags indicating start and end of a sequence of characters
6025 with box. Reset them at the start of this function because
6026 moving the iterator to a new position might set them. */
6027 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6031 case GET_FROM_BUFFER
:
6032 /* The current display element of IT is a character from
6033 current_buffer. Advance in the buffer, and maybe skip over
6034 invisible lines that are so because of selective display. */
6035 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6036 reseat_at_next_visible_line_start (it
, 0);
6037 else if (it
->cmp_it
.id
>= 0)
6039 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6040 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6041 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6042 it
->cmp_it
.from
= it
->cmp_it
.to
;
6046 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6047 IT_BYTEPOS (*it
), it
->stop_charpos
,
6053 xassert (it
->len
!= 0);
6054 IT_BYTEPOS (*it
) += it
->len
;
6055 IT_CHARPOS (*it
) += 1;
6056 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6060 case GET_FROM_C_STRING
:
6061 /* Current display element of IT is from a C string. */
6062 IT_BYTEPOS (*it
) += it
->len
;
6063 IT_CHARPOS (*it
) += 1;
6066 case GET_FROM_DISPLAY_VECTOR
:
6067 /* Current display element of IT is from a display table entry.
6068 Advance in the display table definition. Reset it to null if
6069 end reached, and continue with characters from buffers/
6071 ++it
->current
.dpvec_index
;
6073 /* Restore face of the iterator to what they were before the
6074 display vector entry (these entries may contain faces). */
6075 it
->face_id
= it
->saved_face_id
;
6077 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6079 int recheck_faces
= it
->ellipsis_p
;
6082 it
->method
= GET_FROM_C_STRING
;
6083 else if (STRINGP (it
->string
))
6084 it
->method
= GET_FROM_STRING
;
6087 it
->method
= GET_FROM_BUFFER
;
6088 it
->object
= it
->w
->buffer
;
6092 it
->current
.dpvec_index
= -1;
6094 /* Skip over characters which were displayed via IT->dpvec. */
6095 if (it
->dpvec_char_len
< 0)
6096 reseat_at_next_visible_line_start (it
, 1);
6097 else if (it
->dpvec_char_len
> 0)
6099 if (it
->method
== GET_FROM_STRING
6100 && it
->n_overlay_strings
> 0)
6101 it
->ignore_overlay_strings_at_pos_p
= 1;
6102 it
->len
= it
->dpvec_char_len
;
6103 set_iterator_to_next (it
, reseat_p
);
6106 /* Maybe recheck faces after display vector */
6108 it
->stop_charpos
= IT_CHARPOS (*it
);
6112 case GET_FROM_STRING
:
6113 /* Current display element is a character from a Lisp string. */
6114 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6115 if (it
->cmp_it
.id
>= 0)
6117 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6118 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6119 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6120 it
->cmp_it
.from
= it
->cmp_it
.to
;
6124 composition_compute_stop_pos (&it
->cmp_it
,
6125 IT_STRING_CHARPOS (*it
),
6126 IT_STRING_BYTEPOS (*it
),
6127 it
->stop_charpos
, it
->string
);
6132 IT_STRING_BYTEPOS (*it
) += it
->len
;
6133 IT_STRING_CHARPOS (*it
) += 1;
6136 consider_string_end
:
6138 if (it
->current
.overlay_string_index
>= 0)
6140 /* IT->string is an overlay string. Advance to the
6141 next, if there is one. */
6142 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6145 next_overlay_string (it
);
6147 setup_for_ellipsis (it
, 0);
6152 /* IT->string is not an overlay string. If we reached
6153 its end, and there is something on IT->stack, proceed
6154 with what is on the stack. This can be either another
6155 string, this time an overlay string, or a buffer. */
6156 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6160 if (it
->method
== GET_FROM_STRING
)
6161 goto consider_string_end
;
6166 case GET_FROM_IMAGE
:
6167 case GET_FROM_STRETCH
:
6168 /* The position etc with which we have to proceed are on
6169 the stack. The position may be at the end of a string,
6170 if the `display' property takes up the whole string. */
6171 xassert (it
->sp
> 0);
6173 if (it
->method
== GET_FROM_STRING
)
6174 goto consider_string_end
;
6178 /* There are no other methods defined, so this should be a bug. */
6182 xassert (it
->method
!= GET_FROM_STRING
6183 || (STRINGP (it
->string
)
6184 && IT_STRING_CHARPOS (*it
) >= 0));
6187 /* Load IT's display element fields with information about the next
6188 display element which comes from a display table entry or from the
6189 result of translating a control character to one of the forms `^C'
6192 IT->dpvec holds the glyphs to return as characters.
6193 IT->saved_face_id holds the face id before the display vector--
6194 it is restored into IT->face_idin set_iterator_to_next. */
6197 next_element_from_display_vector (it
)
6203 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6205 it
->face_id
= it
->saved_face_id
;
6207 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6208 That seemed totally bogus - so I changed it... */
6209 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6211 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6213 it
->c
= GLYPH_CODE_CHAR (gc
);
6214 it
->len
= CHAR_BYTES (it
->c
);
6216 /* The entry may contain a face id to use. Such a face id is
6217 the id of a Lisp face, not a realized face. A face id of
6218 zero means no face is specified. */
6219 if (it
->dpvec_face_id
>= 0)
6220 it
->face_id
= it
->dpvec_face_id
;
6223 int lface_id
= GLYPH_CODE_FACE (gc
);
6225 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6230 /* Display table entry is invalid. Return a space. */
6231 it
->c
= ' ', it
->len
= 1;
6233 /* Don't change position and object of the iterator here. They are
6234 still the values of the character that had this display table
6235 entry or was translated, and that's what we want. */
6236 it
->what
= IT_CHARACTER
;
6241 /* Load IT with the next display element from Lisp string IT->string.
6242 IT->current.string_pos is the current position within the string.
6243 If IT->current.overlay_string_index >= 0, the Lisp string is an
6247 next_element_from_string (it
)
6250 struct text_pos position
;
6252 xassert (STRINGP (it
->string
));
6253 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6254 position
= it
->current
.string_pos
;
6256 /* Time to check for invisible text? */
6257 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6258 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6262 /* Since a handler may have changed IT->method, we must
6264 return GET_NEXT_DISPLAY_ELEMENT (it
);
6267 if (it
->current
.overlay_string_index
>= 0)
6269 /* Get the next character from an overlay string. In overlay
6270 strings, There is no field width or padding with spaces to
6272 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6277 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6278 IT_STRING_BYTEPOS (*it
))
6279 && next_element_from_composition (it
))
6283 else if (STRING_MULTIBYTE (it
->string
))
6285 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6286 const unsigned char *s
= (SDATA (it
->string
)
6287 + IT_STRING_BYTEPOS (*it
));
6288 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6292 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6298 /* Get the next character from a Lisp string that is not an
6299 overlay string. Such strings come from the mode line, for
6300 example. We may have to pad with spaces, or truncate the
6301 string. See also next_element_from_c_string. */
6302 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6307 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6309 /* Pad with spaces. */
6310 it
->c
= ' ', it
->len
= 1;
6311 CHARPOS (position
) = BYTEPOS (position
) = -1;
6313 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6314 IT_STRING_BYTEPOS (*it
))
6315 && next_element_from_composition (it
))
6319 else if (STRING_MULTIBYTE (it
->string
))
6321 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6322 const unsigned char *s
= (SDATA (it
->string
)
6323 + IT_STRING_BYTEPOS (*it
));
6324 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6328 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6333 /* Record what we have and where it came from. */
6334 it
->what
= IT_CHARACTER
;
6335 it
->object
= it
->string
;
6336 it
->position
= position
;
6341 /* Load IT with next display element from C string IT->s.
6342 IT->string_nchars is the maximum number of characters to return
6343 from the string. IT->end_charpos may be greater than
6344 IT->string_nchars when this function is called, in which case we
6345 may have to return padding spaces. Value is zero if end of string
6346 reached, including padding spaces. */
6349 next_element_from_c_string (it
)
6355 it
->what
= IT_CHARACTER
;
6356 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6359 /* IT's position can be greater IT->string_nchars in case a field
6360 width or precision has been specified when the iterator was
6362 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6364 /* End of the game. */
6368 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6370 /* Pad with spaces. */
6371 it
->c
= ' ', it
->len
= 1;
6372 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6374 else if (it
->multibyte_p
)
6376 /* Implementation note: The calls to strlen apparently aren't a
6377 performance problem because there is no noticeable performance
6378 difference between Emacs running in unibyte or multibyte mode. */
6379 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6380 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6384 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6390 /* Set up IT to return characters from an ellipsis, if appropriate.
6391 The definition of the ellipsis glyphs may come from a display table
6392 entry. This function Fills IT with the first glyph from the
6393 ellipsis if an ellipsis is to be displayed. */
6396 next_element_from_ellipsis (it
)
6399 if (it
->selective_display_ellipsis_p
)
6400 setup_for_ellipsis (it
, it
->len
);
6403 /* The face at the current position may be different from the
6404 face we find after the invisible text. Remember what it
6405 was in IT->saved_face_id, and signal that it's there by
6406 setting face_before_selective_p. */
6407 it
->saved_face_id
= it
->face_id
;
6408 it
->method
= GET_FROM_BUFFER
;
6409 it
->object
= it
->w
->buffer
;
6410 reseat_at_next_visible_line_start (it
, 1);
6411 it
->face_before_selective_p
= 1;
6414 return GET_NEXT_DISPLAY_ELEMENT (it
);
6418 /* Deliver an image display element. The iterator IT is already
6419 filled with image information (done in handle_display_prop). Value
6424 next_element_from_image (it
)
6427 it
->what
= IT_IMAGE
;
6432 /* Fill iterator IT with next display element from a stretch glyph
6433 property. IT->object is the value of the text property. Value is
6437 next_element_from_stretch (it
)
6440 it
->what
= IT_STRETCH
;
6445 /* Load IT with the next display element from current_buffer. Value
6446 is zero if end of buffer reached. IT->stop_charpos is the next
6447 position at which to stop and check for text properties or buffer
6451 next_element_from_buffer (it
)
6456 xassert (IT_CHARPOS (*it
) >= BEGV
);
6458 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6460 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6462 int overlay_strings_follow_p
;
6464 /* End of the game, except when overlay strings follow that
6465 haven't been returned yet. */
6466 if (it
->overlay_strings_at_end_processed_p
)
6467 overlay_strings_follow_p
= 0;
6470 it
->overlay_strings_at_end_processed_p
= 1;
6471 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6474 if (overlay_strings_follow_p
)
6475 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6479 it
->position
= it
->current
.pos
;
6486 return GET_NEXT_DISPLAY_ELEMENT (it
);
6491 /* No face changes, overlays etc. in sight, so just return a
6492 character from current_buffer. */
6495 /* Maybe run the redisplay end trigger hook. Performance note:
6496 This doesn't seem to cost measurable time. */
6497 if (it
->redisplay_end_trigger_charpos
6499 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6500 run_redisplay_end_trigger_hook (it
);
6502 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
))
6503 && next_element_from_composition (it
))
6508 /* Get the next character, maybe multibyte. */
6509 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6510 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6511 it
->c
= STRING_CHAR_AND_LENGTH (p
, 0, it
->len
);
6513 it
->c
= *p
, it
->len
= 1;
6515 /* Record what we have and where it came from. */
6516 it
->what
= IT_CHARACTER
;
6517 it
->object
= it
->w
->buffer
;
6518 it
->position
= it
->current
.pos
;
6520 /* Normally we return the character found above, except when we
6521 really want to return an ellipsis for selective display. */
6526 /* A value of selective > 0 means hide lines indented more
6527 than that number of columns. */
6528 if (it
->selective
> 0
6529 && IT_CHARPOS (*it
) + 1 < ZV
6530 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6531 IT_BYTEPOS (*it
) + 1,
6532 (double) it
->selective
)) /* iftc */
6534 success_p
= next_element_from_ellipsis (it
);
6535 it
->dpvec_char_len
= -1;
6538 else if (it
->c
== '\r' && it
->selective
== -1)
6540 /* A value of selective == -1 means that everything from the
6541 CR to the end of the line is invisible, with maybe an
6542 ellipsis displayed for it. */
6543 success_p
= next_element_from_ellipsis (it
);
6544 it
->dpvec_char_len
= -1;
6549 /* Value is zero if end of buffer reached. */
6550 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6555 /* Run the redisplay end trigger hook for IT. */
6558 run_redisplay_end_trigger_hook (it
)
6561 Lisp_Object args
[3];
6563 /* IT->glyph_row should be non-null, i.e. we should be actually
6564 displaying something, or otherwise we should not run the hook. */
6565 xassert (it
->glyph_row
);
6567 /* Set up hook arguments. */
6568 args
[0] = Qredisplay_end_trigger_functions
;
6569 args
[1] = it
->window
;
6570 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6571 it
->redisplay_end_trigger_charpos
= 0;
6573 /* Since we are *trying* to run these functions, don't try to run
6574 them again, even if they get an error. */
6575 it
->w
->redisplay_end_trigger
= Qnil
;
6576 Frun_hook_with_args (3, args
);
6578 /* Notice if it changed the face of the character we are on. */
6579 handle_face_prop (it
);
6583 /* Deliver a composition display element. Unlike the other
6584 next_element_from_XXX, this function is not registered in the array
6585 get_next_element[]. It is called from next_element_from_buffer and
6586 next_element_from_string when necessary. */
6589 next_element_from_composition (it
)
6592 it
->what
= IT_COMPOSITION
;
6593 it
->len
= it
->cmp_it
.nbytes
;
6594 if (STRINGP (it
->string
))
6598 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6599 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6602 it
->position
= it
->current
.string_pos
;
6603 it
->object
= it
->string
;
6604 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6605 IT_STRING_BYTEPOS (*it
), it
->string
);
6611 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6612 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6615 it
->position
= it
->current
.pos
;
6616 it
->object
= it
->w
->buffer
;
6617 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6618 IT_BYTEPOS (*it
), Qnil
);
6625 /***********************************************************************
6626 Moving an iterator without producing glyphs
6627 ***********************************************************************/
6629 /* Check if iterator is at a position corresponding to a valid buffer
6630 position after some move_it_ call. */
6632 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6633 ((it)->method == GET_FROM_STRING \
6634 ? IT_STRING_CHARPOS (*it) == 0 \
6638 /* Move iterator IT to a specified buffer or X position within one
6639 line on the display without producing glyphs.
6641 OP should be a bit mask including some or all of these bits:
6642 MOVE_TO_X: Stop on reaching x-position TO_X.
6643 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6644 Regardless of OP's value, stop in reaching the end of the display line.
6646 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6647 This means, in particular, that TO_X includes window's horizontal
6650 The return value has several possible values that
6651 say what condition caused the scan to stop:
6653 MOVE_POS_MATCH_OR_ZV
6654 - when TO_POS or ZV was reached.
6657 -when TO_X was reached before TO_POS or ZV were reached.
6660 - when we reached the end of the display area and the line must
6664 - when we reached the end of the display area and the line is
6668 - when we stopped at a line end, i.e. a newline or a CR and selective
6671 static enum move_it_result
6672 move_it_in_display_line_to (struct it
*it
,
6673 EMACS_INT to_charpos
, int to_x
,
6674 enum move_operation_enum op
)
6676 enum move_it_result result
= MOVE_UNDEFINED
;
6677 struct glyph_row
*saved_glyph_row
;
6678 struct it wrap_it
, atpos_it
, atx_it
;
6681 /* Don't produce glyphs in produce_glyphs. */
6682 saved_glyph_row
= it
->glyph_row
;
6683 it
->glyph_row
= NULL
;
6685 /* Use wrap_it to save a copy of IT wherever a word wrap could
6686 occur. Use atpos_it to save a copy of IT at the desired buffer
6687 position, if found, so that we can scan ahead and check if the
6688 word later overshoots the window edge. Use atx_it similarly, for
6694 #define BUFFER_POS_REACHED_P() \
6695 ((op & MOVE_TO_POS) != 0 \
6696 && BUFFERP (it->object) \
6697 && IT_CHARPOS (*it) >= to_charpos \
6698 && (it->method == GET_FROM_BUFFER \
6699 || (it->method == GET_FROM_DISPLAY_VECTOR \
6700 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6702 /* If there's a line-/wrap-prefix, handle it. */
6703 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6704 && it
->current_y
< it
->last_visible_y
)
6705 handle_line_prefix (it
);
6709 int x
, i
, ascent
= 0, descent
= 0;
6711 /* Utility macro to reset an iterator with x, ascent, and descent. */
6712 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6713 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6714 (IT)->max_descent = descent)
6716 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6718 if ((op
& MOVE_TO_POS
) != 0
6719 && BUFFERP (it
->object
)
6720 && it
->method
== GET_FROM_BUFFER
6721 && IT_CHARPOS (*it
) > to_charpos
)
6723 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6725 result
= MOVE_POS_MATCH_OR_ZV
;
6728 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6729 /* If wrap_it is valid, the current position might be in a
6730 word that is wrapped. So, save the iterator in
6731 atpos_it and continue to see if wrapping happens. */
6735 /* Stop when ZV reached.
6736 We used to stop here when TO_CHARPOS reached as well, but that is
6737 too soon if this glyph does not fit on this line. So we handle it
6738 explicitly below. */
6739 if (!get_next_display_element (it
))
6741 result
= MOVE_POS_MATCH_OR_ZV
;
6745 if (it
->line_wrap
== TRUNCATE
)
6747 if (BUFFER_POS_REACHED_P ())
6749 result
= MOVE_POS_MATCH_OR_ZV
;
6755 if (it
->line_wrap
== WORD_WRAP
)
6757 if (IT_DISPLAYING_WHITESPACE (it
))
6761 /* We have reached a glyph that follows one or more
6762 whitespace characters. If the position is
6763 already found, we are done. */
6764 if (atpos_it
.sp
>= 0)
6767 result
= MOVE_POS_MATCH_OR_ZV
;
6773 result
= MOVE_X_REACHED
;
6776 /* Otherwise, we can wrap here. */
6783 /* Remember the line height for the current line, in case
6784 the next element doesn't fit on the line. */
6785 ascent
= it
->max_ascent
;
6786 descent
= it
->max_descent
;
6788 /* The call to produce_glyphs will get the metrics of the
6789 display element IT is loaded with. Record the x-position
6790 before this display element, in case it doesn't fit on the
6794 PRODUCE_GLYPHS (it
);
6796 if (it
->area
!= TEXT_AREA
)
6798 set_iterator_to_next (it
, 1);
6802 /* The number of glyphs we get back in IT->nglyphs will normally
6803 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6804 character on a terminal frame, or (iii) a line end. For the
6805 second case, IT->nglyphs - 1 padding glyphs will be present
6806 (on X frames, there is only one glyph produced for a
6807 composite character.
6809 The behavior implemented below means, for continuation lines,
6810 that as many spaces of a TAB as fit on the current line are
6811 displayed there. For terminal frames, as many glyphs of a
6812 multi-glyph character are displayed in the current line, too.
6813 This is what the old redisplay code did, and we keep it that
6814 way. Under X, the whole shape of a complex character must
6815 fit on the line or it will be completely displayed in the
6818 Note that both for tabs and padding glyphs, all glyphs have
6822 /* More than one glyph or glyph doesn't fit on line. All
6823 glyphs have the same width. */
6824 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6826 int x_before_this_char
= x
;
6827 int hpos_before_this_char
= it
->hpos
;
6829 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6831 new_x
= x
+ single_glyph_width
;
6833 /* We want to leave anything reaching TO_X to the caller. */
6834 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6836 if (BUFFER_POS_REACHED_P ())
6838 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6839 goto buffer_pos_reached
;
6840 if (atpos_it
.sp
< 0)
6843 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6848 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6851 result
= MOVE_X_REACHED
;
6857 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6862 if (/* Lines are continued. */
6863 it
->line_wrap
!= TRUNCATE
6864 && (/* And glyph doesn't fit on the line. */
6865 new_x
> it
->last_visible_x
6866 /* Or it fits exactly and we're on a window
6868 || (new_x
== it
->last_visible_x
6869 && FRAME_WINDOW_P (it
->f
))))
6871 if (/* IT->hpos == 0 means the very first glyph
6872 doesn't fit on the line, e.g. a wide image. */
6874 || (new_x
== it
->last_visible_x
6875 && FRAME_WINDOW_P (it
->f
)))
6878 it
->current_x
= new_x
;
6880 /* The character's last glyph just barely fits
6882 if (i
== it
->nglyphs
- 1)
6884 /* If this is the destination position,
6885 return a position *before* it in this row,
6886 now that we know it fits in this row. */
6887 if (BUFFER_POS_REACHED_P ())
6889 if (it
->line_wrap
!= WORD_WRAP
6892 it
->hpos
= hpos_before_this_char
;
6893 it
->current_x
= x_before_this_char
;
6894 result
= MOVE_POS_MATCH_OR_ZV
;
6897 if (it
->line_wrap
== WORD_WRAP
6901 atpos_it
.current_x
= x_before_this_char
;
6902 atpos_it
.hpos
= hpos_before_this_char
;
6906 set_iterator_to_next (it
, 1);
6907 /* One graphical terminals, newlines may
6908 "overflow" into the fringe if
6909 overflow-newline-into-fringe is non-nil.
6910 On text-only terminals, newlines may
6911 overflow into the last glyph on the
6913 if (!FRAME_WINDOW_P (it
->f
)
6914 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6916 if (!get_next_display_element (it
))
6918 result
= MOVE_POS_MATCH_OR_ZV
;
6921 if (BUFFER_POS_REACHED_P ())
6923 if (ITERATOR_AT_END_OF_LINE_P (it
))
6924 result
= MOVE_POS_MATCH_OR_ZV
;
6926 result
= MOVE_LINE_CONTINUED
;
6929 if (ITERATOR_AT_END_OF_LINE_P (it
))
6931 result
= MOVE_NEWLINE_OR_CR
;
6938 IT_RESET_X_ASCENT_DESCENT (it
);
6940 if (wrap_it
.sp
>= 0)
6947 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6949 result
= MOVE_LINE_CONTINUED
;
6953 if (BUFFER_POS_REACHED_P ())
6955 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6956 goto buffer_pos_reached
;
6957 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6960 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6964 if (new_x
> it
->first_visible_x
)
6966 /* Glyph is visible. Increment number of glyphs that
6967 would be displayed. */
6972 if (result
!= MOVE_UNDEFINED
)
6975 else if (BUFFER_POS_REACHED_P ())
6978 IT_RESET_X_ASCENT_DESCENT (it
);
6979 result
= MOVE_POS_MATCH_OR_ZV
;
6982 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6984 /* Stop when TO_X specified and reached. This check is
6985 necessary here because of lines consisting of a line end,
6986 only. The line end will not produce any glyphs and we
6987 would never get MOVE_X_REACHED. */
6988 xassert (it
->nglyphs
== 0);
6989 result
= MOVE_X_REACHED
;
6993 /* Is this a line end? If yes, we're done. */
6994 if (ITERATOR_AT_END_OF_LINE_P (it
))
6996 result
= MOVE_NEWLINE_OR_CR
;
7000 /* The current display element has been consumed. Advance
7002 set_iterator_to_next (it
, 1);
7004 /* Stop if lines are truncated and IT's current x-position is
7005 past the right edge of the window now. */
7006 if (it
->line_wrap
== TRUNCATE
7007 && it
->current_x
>= it
->last_visible_x
)
7009 if (!FRAME_WINDOW_P (it
->f
)
7010 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7012 if (!get_next_display_element (it
)
7013 || BUFFER_POS_REACHED_P ())
7015 result
= MOVE_POS_MATCH_OR_ZV
;
7018 if (ITERATOR_AT_END_OF_LINE_P (it
))
7020 result
= MOVE_NEWLINE_OR_CR
;
7024 result
= MOVE_LINE_TRUNCATED
;
7027 #undef IT_RESET_X_ASCENT_DESCENT
7030 #undef BUFFER_POS_REACHED_P
7032 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7033 restore the saved iterator. */
7034 if (atpos_it
.sp
>= 0)
7036 else if (atx_it
.sp
>= 0)
7041 /* Restore the iterator settings altered at the beginning of this
7043 it
->glyph_row
= saved_glyph_row
;
7047 /* For external use. */
7049 move_it_in_display_line (struct it
*it
,
7050 EMACS_INT to_charpos
, int to_x
,
7051 enum move_operation_enum op
)
7053 if (it
->line_wrap
== WORD_WRAP
7054 && (op
& MOVE_TO_X
))
7056 struct it save_it
= *it
;
7057 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7058 /* When word-wrap is on, TO_X may lie past the end
7059 of a wrapped line. Then it->current is the
7060 character on the next line, so backtrack to the
7061 space before the wrap point. */
7062 if (skip
== MOVE_LINE_CONTINUED
)
7064 int prev_x
= max (it
->current_x
- 1, 0);
7066 move_it_in_display_line_to
7067 (it
, -1, prev_x
, MOVE_TO_X
);
7071 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7075 /* Move IT forward until it satisfies one or more of the criteria in
7076 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7078 OP is a bit-mask that specifies where to stop, and in particular,
7079 which of those four position arguments makes a difference. See the
7080 description of enum move_operation_enum.
7082 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7083 screen line, this function will set IT to the next position >
7087 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7089 int to_charpos
, to_x
, to_y
, to_vpos
;
7092 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7098 if (op
& MOVE_TO_VPOS
)
7100 /* If no TO_CHARPOS and no TO_X specified, stop at the
7101 start of the line TO_VPOS. */
7102 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7104 if (it
->vpos
== to_vpos
)
7110 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7114 /* TO_VPOS >= 0 means stop at TO_X in the line at
7115 TO_VPOS, or at TO_POS, whichever comes first. */
7116 if (it
->vpos
== to_vpos
)
7122 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7124 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7129 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7131 /* We have reached TO_X but not in the line we want. */
7132 skip
= move_it_in_display_line_to (it
, to_charpos
,
7134 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7142 else if (op
& MOVE_TO_Y
)
7144 struct it it_backup
;
7146 if (it
->line_wrap
== WORD_WRAP
)
7149 /* TO_Y specified means stop at TO_X in the line containing
7150 TO_Y---or at TO_CHARPOS if this is reached first. The
7151 problem is that we can't really tell whether the line
7152 contains TO_Y before we have completely scanned it, and
7153 this may skip past TO_X. What we do is to first scan to
7156 If TO_X is not specified, use a TO_X of zero. The reason
7157 is to make the outcome of this function more predictable.
7158 If we didn't use TO_X == 0, we would stop at the end of
7159 the line which is probably not what a caller would expect
7161 skip
= move_it_in_display_line_to
7162 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7163 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7165 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7166 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7168 else if (skip
== MOVE_X_REACHED
)
7170 /* If TO_X was reached, we want to know whether TO_Y is
7171 in the line. We know this is the case if the already
7172 scanned glyphs make the line tall enough. Otherwise,
7173 we must check by scanning the rest of the line. */
7174 line_height
= it
->max_ascent
+ it
->max_descent
;
7175 if (to_y
>= it
->current_y
7176 && to_y
< it
->current_y
+ line_height
)
7182 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7183 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7185 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7186 line_height
= it
->max_ascent
+ it
->max_descent
;
7187 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7189 if (to_y
>= it
->current_y
7190 && to_y
< it
->current_y
+ line_height
)
7192 /* If TO_Y is in this line and TO_X was reached
7193 above, we scanned too far. We have to restore
7194 IT's settings to the ones before skipping. */
7201 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7207 /* Check whether TO_Y is in this line. */
7208 line_height
= it
->max_ascent
+ it
->max_descent
;
7209 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7211 if (to_y
>= it
->current_y
7212 && to_y
< it
->current_y
+ line_height
)
7214 /* When word-wrap is on, TO_X may lie past the end
7215 of a wrapped line. Then it->current is the
7216 character on the next line, so backtrack to the
7217 space before the wrap point. */
7218 if (skip
== MOVE_LINE_CONTINUED
7219 && it
->line_wrap
== WORD_WRAP
)
7221 int prev_x
= max (it
->current_x
- 1, 0);
7223 skip
= move_it_in_display_line_to
7224 (it
, -1, prev_x
, MOVE_TO_X
);
7233 else if (BUFFERP (it
->object
)
7234 && (it
->method
== GET_FROM_BUFFER
7235 || it
->method
== GET_FROM_STRETCH
)
7236 && IT_CHARPOS (*it
) >= to_charpos
)
7237 skip
= MOVE_POS_MATCH_OR_ZV
;
7239 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7243 case MOVE_POS_MATCH_OR_ZV
:
7247 case MOVE_NEWLINE_OR_CR
:
7248 set_iterator_to_next (it
, 1);
7249 it
->continuation_lines_width
= 0;
7252 case MOVE_LINE_TRUNCATED
:
7253 it
->continuation_lines_width
= 0;
7254 reseat_at_next_visible_line_start (it
, 0);
7255 if ((op
& MOVE_TO_POS
) != 0
7256 && IT_CHARPOS (*it
) > to_charpos
)
7263 case MOVE_LINE_CONTINUED
:
7264 /* For continued lines ending in a tab, some of the glyphs
7265 associated with the tab are displayed on the current
7266 line. Since it->current_x does not include these glyphs,
7267 we use it->last_visible_x instead. */
7270 it
->continuation_lines_width
+= it
->last_visible_x
;
7271 /* When moving by vpos, ensure that the iterator really
7272 advances to the next line (bug#847, bug#969). Fixme:
7273 do we need to do this in other circumstances? */
7274 if (it
->current_x
!= it
->last_visible_x
7275 && (op
& MOVE_TO_VPOS
)
7276 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7277 set_iterator_to_next (it
, 0);
7280 it
->continuation_lines_width
+= it
->current_x
;
7287 /* Reset/increment for the next run. */
7288 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7289 it
->current_x
= it
->hpos
= 0;
7290 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7292 last_height
= it
->max_ascent
+ it
->max_descent
;
7293 last_max_ascent
= it
->max_ascent
;
7294 it
->max_ascent
= it
->max_descent
= 0;
7299 /* On text terminals, we may stop at the end of a line in the middle
7300 of a multi-character glyph. If the glyph itself is continued,
7301 i.e. it is actually displayed on the next line, don't treat this
7302 stopping point as valid; move to the next line instead (unless
7303 that brings us offscreen). */
7304 if (!FRAME_WINDOW_P (it
->f
)
7306 && IT_CHARPOS (*it
) == to_charpos
7307 && it
->what
== IT_CHARACTER
7309 && it
->line_wrap
== WINDOW_WRAP
7310 && it
->current_x
== it
->last_visible_x
- 1
7313 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7315 it
->continuation_lines_width
+= it
->current_x
;
7316 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7317 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7319 last_height
= it
->max_ascent
+ it
->max_descent
;
7320 last_max_ascent
= it
->max_ascent
;
7323 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7327 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7329 If DY > 0, move IT backward at least that many pixels. DY = 0
7330 means move IT backward to the preceding line start or BEGV. This
7331 function may move over more than DY pixels if IT->current_y - DY
7332 ends up in the middle of a line; in this case IT->current_y will be
7333 set to the top of the line moved to. */
7336 move_it_vertically_backward (it
, dy
)
7347 start_pos
= IT_CHARPOS (*it
);
7349 /* Estimate how many newlines we must move back. */
7350 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7352 /* Set the iterator's position that many lines back. */
7353 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7354 back_to_previous_visible_line_start (it
);
7356 /* Reseat the iterator here. When moving backward, we don't want
7357 reseat to skip forward over invisible text, set up the iterator
7358 to deliver from overlay strings at the new position etc. So,
7359 use reseat_1 here. */
7360 reseat_1 (it
, it
->current
.pos
, 1);
7362 /* We are now surely at a line start. */
7363 it
->current_x
= it
->hpos
= 0;
7364 it
->continuation_lines_width
= 0;
7366 /* Move forward and see what y-distance we moved. First move to the
7367 start of the next line so that we get its height. We need this
7368 height to be able to tell whether we reached the specified
7371 it2
.max_ascent
= it2
.max_descent
= 0;
7374 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7375 MOVE_TO_POS
| MOVE_TO_VPOS
);
7377 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7378 xassert (IT_CHARPOS (*it
) >= BEGV
);
7381 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7382 xassert (IT_CHARPOS (*it
) >= BEGV
);
7383 /* H is the actual vertical distance from the position in *IT
7384 and the starting position. */
7385 h
= it2
.current_y
- it
->current_y
;
7386 /* NLINES is the distance in number of lines. */
7387 nlines
= it2
.vpos
- it
->vpos
;
7389 /* Correct IT's y and vpos position
7390 so that they are relative to the starting point. */
7396 /* DY == 0 means move to the start of the screen line. The
7397 value of nlines is > 0 if continuation lines were involved. */
7399 move_it_by_lines (it
, nlines
, 1);
7403 /* The y-position we try to reach, relative to *IT.
7404 Note that H has been subtracted in front of the if-statement. */
7405 int target_y
= it
->current_y
+ h
- dy
;
7406 int y0
= it3
.current_y
;
7407 int y1
= line_bottom_y (&it3
);
7408 int line_height
= y1
- y0
;
7410 /* If we did not reach target_y, try to move further backward if
7411 we can. If we moved too far backward, try to move forward. */
7412 if (target_y
< it
->current_y
7413 /* This is heuristic. In a window that's 3 lines high, with
7414 a line height of 13 pixels each, recentering with point
7415 on the bottom line will try to move -39/2 = 19 pixels
7416 backward. Try to avoid moving into the first line. */
7417 && (it
->current_y
- target_y
7418 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7419 && IT_CHARPOS (*it
) > BEGV
)
7421 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7422 target_y
- it
->current_y
));
7423 dy
= it
->current_y
- target_y
;
7424 goto move_further_back
;
7426 else if (target_y
>= it
->current_y
+ line_height
7427 && IT_CHARPOS (*it
) < ZV
)
7429 /* Should move forward by at least one line, maybe more.
7431 Note: Calling move_it_by_lines can be expensive on
7432 terminal frames, where compute_motion is used (via
7433 vmotion) to do the job, when there are very long lines
7434 and truncate-lines is nil. That's the reason for
7435 treating terminal frames specially here. */
7437 if (!FRAME_WINDOW_P (it
->f
))
7438 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7443 move_it_by_lines (it
, 1, 1);
7445 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7452 /* Move IT by a specified amount of pixel lines DY. DY negative means
7453 move backwards. DY = 0 means move to start of screen line. At the
7454 end, IT will be on the start of a screen line. */
7457 move_it_vertically (it
, dy
)
7462 move_it_vertically_backward (it
, -dy
);
7465 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7466 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7467 MOVE_TO_POS
| MOVE_TO_Y
);
7468 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7470 /* If buffer ends in ZV without a newline, move to the start of
7471 the line to satisfy the post-condition. */
7472 if (IT_CHARPOS (*it
) == ZV
7474 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7475 move_it_by_lines (it
, 0, 0);
7480 /* Move iterator IT past the end of the text line it is in. */
7483 move_it_past_eol (it
)
7486 enum move_it_result rc
;
7488 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7489 if (rc
== MOVE_NEWLINE_OR_CR
)
7490 set_iterator_to_next (it
, 0);
7494 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7495 negative means move up. DVPOS == 0 means move to the start of the
7496 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7497 NEED_Y_P is zero, IT->current_y will be left unchanged.
7499 Further optimization ideas: If we would know that IT->f doesn't use
7500 a face with proportional font, we could be faster for
7501 truncate-lines nil. */
7504 move_it_by_lines (it
, dvpos
, need_y_p
)
7506 int dvpos
, need_y_p
;
7508 struct position pos
;
7510 /* The commented-out optimization uses vmotion on terminals. This
7511 gives bad results, because elements like it->what, on which
7512 callers such as pos_visible_p rely, aren't updated. */
7513 /* if (!FRAME_WINDOW_P (it->f))
7515 struct text_pos textpos;
7517 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7518 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7519 reseat (it, textpos, 1);
7520 it->vpos += pos.vpos;
7521 it->current_y += pos.vpos;
7527 /* DVPOS == 0 means move to the start of the screen line. */
7528 move_it_vertically_backward (it
, 0);
7529 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7530 /* Let next call to line_bottom_y calculate real line height */
7535 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7536 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7537 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7542 int start_charpos
, i
;
7544 /* Start at the beginning of the screen line containing IT's
7545 position. This may actually move vertically backwards,
7546 in case of overlays, so adjust dvpos accordingly. */
7548 move_it_vertically_backward (it
, 0);
7551 /* Go back -DVPOS visible lines and reseat the iterator there. */
7552 start_charpos
= IT_CHARPOS (*it
);
7553 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7554 back_to_previous_visible_line_start (it
);
7555 reseat (it
, it
->current
.pos
, 1);
7557 /* Move further back if we end up in a string or an image. */
7558 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7560 /* First try to move to start of display line. */
7562 move_it_vertically_backward (it
, 0);
7564 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7566 /* If start of line is still in string or image,
7567 move further back. */
7568 back_to_previous_visible_line_start (it
);
7569 reseat (it
, it
->current
.pos
, 1);
7573 it
->current_x
= it
->hpos
= 0;
7575 /* Above call may have moved too far if continuation lines
7576 are involved. Scan forward and see if it did. */
7578 it2
.vpos
= it2
.current_y
= 0;
7579 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7580 it
->vpos
-= it2
.vpos
;
7581 it
->current_y
-= it2
.current_y
;
7582 it
->current_x
= it
->hpos
= 0;
7584 /* If we moved too far back, move IT some lines forward. */
7585 if (it2
.vpos
> -dvpos
)
7587 int delta
= it2
.vpos
+ dvpos
;
7589 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7590 /* Move back again if we got too far ahead. */
7591 if (IT_CHARPOS (*it
) >= start_charpos
)
7597 /* Return 1 if IT points into the middle of a display vector. */
7600 in_display_vector_p (it
)
7603 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7604 && it
->current
.dpvec_index
> 0
7605 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7609 /***********************************************************************
7611 ***********************************************************************/
7614 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7618 add_to_log (format
, arg1
, arg2
)
7620 Lisp_Object arg1
, arg2
;
7622 Lisp_Object args
[3];
7623 Lisp_Object msg
, fmt
;
7626 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7629 /* Do nothing if called asynchronously. Inserting text into
7630 a buffer may call after-change-functions and alike and
7631 that would means running Lisp asynchronously. */
7632 if (handling_signal
)
7636 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7638 args
[0] = fmt
= build_string (format
);
7641 msg
= Fformat (3, args
);
7643 len
= SBYTES (msg
) + 1;
7644 SAFE_ALLOCA (buffer
, char *, len
);
7645 bcopy (SDATA (msg
), buffer
, len
);
7647 message_dolog (buffer
, len
- 1, 1, 0);
7654 /* Output a newline in the *Messages* buffer if "needs" one. */
7657 message_log_maybe_newline ()
7659 if (message_log_need_newline
)
7660 message_dolog ("", 0, 1, 0);
7664 /* Add a string M of length NBYTES to the message log, optionally
7665 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7666 nonzero, means interpret the contents of M as multibyte. This
7667 function calls low-level routines in order to bypass text property
7668 hooks, etc. which might not be safe to run.
7670 This may GC (insert may run before/after change hooks),
7671 so the buffer M must NOT point to a Lisp string. */
7674 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7676 int nbytes
, nlflag
, multibyte
;
7678 if (!NILP (Vmemory_full
))
7681 if (!NILP (Vmessage_log_max
))
7683 struct buffer
*oldbuf
;
7684 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7685 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7686 int point_at_end
= 0;
7688 Lisp_Object old_deactivate_mark
, tem
;
7689 struct gcpro gcpro1
;
7691 old_deactivate_mark
= Vdeactivate_mark
;
7692 oldbuf
= current_buffer
;
7693 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7694 current_buffer
->undo_list
= Qt
;
7696 oldpoint
= message_dolog_marker1
;
7697 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7698 oldbegv
= message_dolog_marker2
;
7699 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7700 oldzv
= message_dolog_marker3
;
7701 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7702 GCPRO1 (old_deactivate_mark
);
7710 BEGV_BYTE
= BEG_BYTE
;
7713 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7715 /* Insert the string--maybe converting multibyte to single byte
7716 or vice versa, so that all the text fits the buffer. */
7718 && NILP (current_buffer
->enable_multibyte_characters
))
7720 int i
, c
, char_bytes
;
7721 unsigned char work
[1];
7723 /* Convert a multibyte string to single-byte
7724 for the *Message* buffer. */
7725 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7727 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7728 work
[0] = (ASCII_CHAR_P (c
)
7730 : multibyte_char_to_unibyte (c
, Qnil
));
7731 insert_1_both (work
, 1, 1, 1, 0, 0);
7734 else if (! multibyte
7735 && ! NILP (current_buffer
->enable_multibyte_characters
))
7737 int i
, c
, char_bytes
;
7738 unsigned char *msg
= (unsigned char *) m
;
7739 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7740 /* Convert a single-byte string to multibyte
7741 for the *Message* buffer. */
7742 for (i
= 0; i
< nbytes
; i
++)
7745 c
= unibyte_char_to_multibyte (c
);
7746 char_bytes
= CHAR_STRING (c
, str
);
7747 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7751 insert_1 (m
, nbytes
, 1, 0, 0);
7755 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7756 insert_1 ("\n", 1, 1, 0, 0);
7758 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7760 this_bol_byte
= PT_BYTE
;
7762 /* See if this line duplicates the previous one.
7763 If so, combine duplicates. */
7766 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7768 prev_bol_byte
= PT_BYTE
;
7770 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7771 this_bol
, this_bol_byte
);
7774 del_range_both (prev_bol
, prev_bol_byte
,
7775 this_bol
, this_bol_byte
, 0);
7781 /* If you change this format, don't forget to also
7782 change message_log_check_duplicate. */
7783 sprintf (dupstr
, " [%d times]", dup
);
7784 duplen
= strlen (dupstr
);
7785 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7786 insert_1 (dupstr
, duplen
, 1, 0, 1);
7791 /* If we have more than the desired maximum number of lines
7792 in the *Messages* buffer now, delete the oldest ones.
7793 This is safe because we don't have undo in this buffer. */
7795 if (NATNUMP (Vmessage_log_max
))
7797 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7798 -XFASTINT (Vmessage_log_max
) - 1, 0);
7799 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7802 BEGV
= XMARKER (oldbegv
)->charpos
;
7803 BEGV_BYTE
= marker_byte_position (oldbegv
);
7812 ZV
= XMARKER (oldzv
)->charpos
;
7813 ZV_BYTE
= marker_byte_position (oldzv
);
7817 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7819 /* We can't do Fgoto_char (oldpoint) because it will run some
7821 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7822 XMARKER (oldpoint
)->bytepos
);
7825 unchain_marker (XMARKER (oldpoint
));
7826 unchain_marker (XMARKER (oldbegv
));
7827 unchain_marker (XMARKER (oldzv
));
7829 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7830 set_buffer_internal (oldbuf
);
7832 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7833 message_log_need_newline
= !nlflag
;
7834 Vdeactivate_mark
= old_deactivate_mark
;
7839 /* We are at the end of the buffer after just having inserted a newline.
7840 (Note: We depend on the fact we won't be crossing the gap.)
7841 Check to see if the most recent message looks a lot like the previous one.
7842 Return 0 if different, 1 if the new one should just replace it, or a
7843 value N > 1 if we should also append " [N times]". */
7846 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7847 int prev_bol
, this_bol
;
7848 int prev_bol_byte
, this_bol_byte
;
7851 int len
= Z_BYTE
- 1 - this_bol_byte
;
7853 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7854 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7856 for (i
= 0; i
< len
; i
++)
7858 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7866 if (*p1
++ == ' ' && *p1
++ == '[')
7869 while (*p1
>= '0' && *p1
<= '9')
7870 n
= n
* 10 + *p1
++ - '0';
7871 if (strncmp (p1
, " times]\n", 8) == 0)
7878 /* Display an echo area message M with a specified length of NBYTES
7879 bytes. The string may include null characters. If M is 0, clear
7880 out any existing message, and let the mini-buffer text show
7883 This may GC, so the buffer M must NOT point to a Lisp string. */
7886 message2 (m
, nbytes
, multibyte
)
7891 /* First flush out any partial line written with print. */
7892 message_log_maybe_newline ();
7894 message_dolog (m
, nbytes
, 1, multibyte
);
7895 message2_nolog (m
, nbytes
, multibyte
);
7899 /* The non-logging counterpart of message2. */
7902 message2_nolog (m
, nbytes
, multibyte
)
7904 int nbytes
, multibyte
;
7906 struct frame
*sf
= SELECTED_FRAME ();
7907 message_enable_multibyte
= multibyte
;
7909 if (FRAME_INITIAL_P (sf
))
7911 if (noninteractive_need_newline
)
7912 putc ('\n', stderr
);
7913 noninteractive_need_newline
= 0;
7915 fwrite (m
, nbytes
, 1, stderr
);
7916 if (cursor_in_echo_area
== 0)
7917 fprintf (stderr
, "\n");
7920 /* A null message buffer means that the frame hasn't really been
7921 initialized yet. Error messages get reported properly by
7922 cmd_error, so this must be just an informative message; toss it. */
7923 else if (INTERACTIVE
7924 && sf
->glyphs_initialized_p
7925 && FRAME_MESSAGE_BUF (sf
))
7927 Lisp_Object mini_window
;
7930 /* Get the frame containing the mini-buffer
7931 that the selected frame is using. */
7932 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7933 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7935 FRAME_SAMPLE_VISIBILITY (f
);
7936 if (FRAME_VISIBLE_P (sf
)
7937 && ! FRAME_VISIBLE_P (f
))
7938 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7942 set_message (m
, Qnil
, nbytes
, multibyte
);
7943 if (minibuffer_auto_raise
)
7944 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7947 clear_message (1, 1);
7949 do_pending_window_change (0);
7950 echo_area_display (1);
7951 do_pending_window_change (0);
7952 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7953 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7958 /* Display an echo area message M with a specified length of NBYTES
7959 bytes. The string may include null characters. If M is not a
7960 string, clear out any existing message, and let the mini-buffer
7963 This function cancels echoing. */
7966 message3 (m
, nbytes
, multibyte
)
7971 struct gcpro gcpro1
;
7974 clear_message (1,1);
7977 /* First flush out any partial line written with print. */
7978 message_log_maybe_newline ();
7984 SAFE_ALLOCA (buffer
, char *, nbytes
);
7985 bcopy (SDATA (m
), buffer
, nbytes
);
7986 message_dolog (buffer
, nbytes
, 1, multibyte
);
7989 message3_nolog (m
, nbytes
, multibyte
);
7995 /* The non-logging version of message3.
7996 This does not cancel echoing, because it is used for echoing.
7997 Perhaps we need to make a separate function for echoing
7998 and make this cancel echoing. */
8001 message3_nolog (m
, nbytes
, multibyte
)
8003 int nbytes
, multibyte
;
8005 struct frame
*sf
= SELECTED_FRAME ();
8006 message_enable_multibyte
= multibyte
;
8008 if (FRAME_INITIAL_P (sf
))
8010 if (noninteractive_need_newline
)
8011 putc ('\n', stderr
);
8012 noninteractive_need_newline
= 0;
8014 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8015 if (cursor_in_echo_area
== 0)
8016 fprintf (stderr
, "\n");
8019 /* A null message buffer means that the frame hasn't really been
8020 initialized yet. Error messages get reported properly by
8021 cmd_error, so this must be just an informative message; toss it. */
8022 else if (INTERACTIVE
8023 && sf
->glyphs_initialized_p
8024 && FRAME_MESSAGE_BUF (sf
))
8026 Lisp_Object mini_window
;
8030 /* Get the frame containing the mini-buffer
8031 that the selected frame is using. */
8032 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8033 frame
= XWINDOW (mini_window
)->frame
;
8036 FRAME_SAMPLE_VISIBILITY (f
);
8037 if (FRAME_VISIBLE_P (sf
)
8038 && !FRAME_VISIBLE_P (f
))
8039 Fmake_frame_visible (frame
);
8041 if (STRINGP (m
) && SCHARS (m
) > 0)
8043 set_message (NULL
, m
, nbytes
, multibyte
);
8044 if (minibuffer_auto_raise
)
8045 Fraise_frame (frame
);
8046 /* Assume we are not echoing.
8047 (If we are, echo_now will override this.) */
8048 echo_message_buffer
= Qnil
;
8051 clear_message (1, 1);
8053 do_pending_window_change (0);
8054 echo_area_display (1);
8055 do_pending_window_change (0);
8056 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8057 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8062 /* Display a null-terminated echo area message M. If M is 0, clear
8063 out any existing message, and let the mini-buffer text show through.
8065 The buffer M must continue to exist until after the echo area gets
8066 cleared or some other message gets displayed there. Do not pass
8067 text that is stored in a Lisp string. Do not pass text in a buffer
8068 that was alloca'd. */
8074 message2 (m
, (m
? strlen (m
) : 0), 0);
8078 /* The non-logging counterpart of message1. */
8084 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8087 /* Display a message M which contains a single %s
8088 which gets replaced with STRING. */
8091 message_with_string (m
, string
, log
)
8096 CHECK_STRING (string
);
8102 if (noninteractive_need_newline
)
8103 putc ('\n', stderr
);
8104 noninteractive_need_newline
= 0;
8105 fprintf (stderr
, m
, SDATA (string
));
8106 if (!cursor_in_echo_area
)
8107 fprintf (stderr
, "\n");
8111 else if (INTERACTIVE
)
8113 /* The frame whose minibuffer we're going to display the message on.
8114 It may be larger than the selected frame, so we need
8115 to use its buffer, not the selected frame's buffer. */
8116 Lisp_Object mini_window
;
8117 struct frame
*f
, *sf
= SELECTED_FRAME ();
8119 /* Get the frame containing the minibuffer
8120 that the selected frame is using. */
8121 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8122 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8124 /* A null message buffer means that the frame hasn't really been
8125 initialized yet. Error messages get reported properly by
8126 cmd_error, so this must be just an informative message; toss it. */
8127 if (FRAME_MESSAGE_BUF (f
))
8129 Lisp_Object args
[2], message
;
8130 struct gcpro gcpro1
, gcpro2
;
8132 args
[0] = build_string (m
);
8133 args
[1] = message
= string
;
8134 GCPRO2 (args
[0], message
);
8137 message
= Fformat (2, args
);
8140 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8142 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8146 /* Print should start at the beginning of the message
8147 buffer next time. */
8148 message_buf_print
= 0;
8154 /* Dump an informative message to the minibuf. If M is 0, clear out
8155 any existing message, and let the mini-buffer text show through. */
8159 message (m
, a1
, a2
, a3
)
8161 EMACS_INT a1
, a2
, a3
;
8167 if (noninteractive_need_newline
)
8168 putc ('\n', stderr
);
8169 noninteractive_need_newline
= 0;
8170 fprintf (stderr
, m
, a1
, a2
, a3
);
8171 if (cursor_in_echo_area
== 0)
8172 fprintf (stderr
, "\n");
8176 else if (INTERACTIVE
)
8178 /* The frame whose mini-buffer we're going to display the message
8179 on. It may be larger than the selected frame, so we need to
8180 use its buffer, not the selected frame's buffer. */
8181 Lisp_Object mini_window
;
8182 struct frame
*f
, *sf
= SELECTED_FRAME ();
8184 /* Get the frame containing the mini-buffer
8185 that the selected frame is using. */
8186 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8187 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8189 /* A null message buffer means that the frame hasn't really been
8190 initialized yet. Error messages get reported properly by
8191 cmd_error, so this must be just an informative message; toss
8193 if (FRAME_MESSAGE_BUF (f
))
8204 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8205 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8207 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8208 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8210 #endif /* NO_ARG_ARRAY */
8212 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8217 /* Print should start at the beginning of the message
8218 buffer next time. */
8219 message_buf_print
= 0;
8225 /* The non-logging version of message. */
8228 message_nolog (m
, a1
, a2
, a3
)
8230 EMACS_INT a1
, a2
, a3
;
8232 Lisp_Object old_log_max
;
8233 old_log_max
= Vmessage_log_max
;
8234 Vmessage_log_max
= Qnil
;
8235 message (m
, a1
, a2
, a3
);
8236 Vmessage_log_max
= old_log_max
;
8240 /* Display the current message in the current mini-buffer. This is
8241 only called from error handlers in process.c, and is not time
8247 if (!NILP (echo_area_buffer
[0]))
8250 string
= Fcurrent_message ();
8251 message3 (string
, SBYTES (string
),
8252 !NILP (current_buffer
->enable_multibyte_characters
));
8257 /* Make sure echo area buffers in `echo_buffers' are live.
8258 If they aren't, make new ones. */
8261 ensure_echo_area_buffers ()
8265 for (i
= 0; i
< 2; ++i
)
8266 if (!BUFFERP (echo_buffer
[i
])
8267 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8270 Lisp_Object old_buffer
;
8273 old_buffer
= echo_buffer
[i
];
8274 sprintf (name
, " *Echo Area %d*", i
);
8275 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8276 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8277 /* to force word wrap in echo area -
8278 it was decided to postpone this*/
8279 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8281 for (j
= 0; j
< 2; ++j
)
8282 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8283 echo_area_buffer
[j
] = echo_buffer
[i
];
8288 /* Call FN with args A1..A4 with either the current or last displayed
8289 echo_area_buffer as current buffer.
8291 WHICH zero means use the current message buffer
8292 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8293 from echo_buffer[] and clear it.
8295 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8296 suitable buffer from echo_buffer[] and clear it.
8298 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8299 that the current message becomes the last displayed one, make
8300 choose a suitable buffer for echo_area_buffer[0], and clear it.
8302 Value is what FN returns. */
8305 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8308 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8314 int this_one
, the_other
, clear_buffer_p
, rc
;
8315 int count
= SPECPDL_INDEX ();
8317 /* If buffers aren't live, make new ones. */
8318 ensure_echo_area_buffers ();
8323 this_one
= 0, the_other
= 1;
8325 this_one
= 1, the_other
= 0;
8328 this_one
= 0, the_other
= 1;
8331 /* We need a fresh one in case the current echo buffer equals
8332 the one containing the last displayed echo area message. */
8333 if (!NILP (echo_area_buffer
[this_one
])
8334 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8335 echo_area_buffer
[this_one
] = Qnil
;
8338 /* Choose a suitable buffer from echo_buffer[] is we don't
8340 if (NILP (echo_area_buffer
[this_one
]))
8342 echo_area_buffer
[this_one
]
8343 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8344 ? echo_buffer
[the_other
]
8345 : echo_buffer
[this_one
]);
8349 buffer
= echo_area_buffer
[this_one
];
8351 /* Don't get confused by reusing the buffer used for echoing
8352 for a different purpose. */
8353 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8356 record_unwind_protect (unwind_with_echo_area_buffer
,
8357 with_echo_area_buffer_unwind_data (w
));
8359 /* Make the echo area buffer current. Note that for display
8360 purposes, it is not necessary that the displayed window's buffer
8361 == current_buffer, except for text property lookup. So, let's
8362 only set that buffer temporarily here without doing a full
8363 Fset_window_buffer. We must also change w->pointm, though,
8364 because otherwise an assertions in unshow_buffer fails, and Emacs
8366 set_buffer_internal_1 (XBUFFER (buffer
));
8370 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8373 current_buffer
->undo_list
= Qt
;
8374 current_buffer
->read_only
= Qnil
;
8375 specbind (Qinhibit_read_only
, Qt
);
8376 specbind (Qinhibit_modification_hooks
, Qt
);
8378 if (clear_buffer_p
&& Z
> BEG
)
8381 xassert (BEGV
>= BEG
);
8382 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8384 rc
= fn (a1
, a2
, a3
, a4
);
8386 xassert (BEGV
>= BEG
);
8387 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8389 unbind_to (count
, Qnil
);
8394 /* Save state that should be preserved around the call to the function
8395 FN called in with_echo_area_buffer. */
8398 with_echo_area_buffer_unwind_data (w
)
8402 Lisp_Object vector
, tmp
;
8404 /* Reduce consing by keeping one vector in
8405 Vwith_echo_area_save_vector. */
8406 vector
= Vwith_echo_area_save_vector
;
8407 Vwith_echo_area_save_vector
= Qnil
;
8410 vector
= Fmake_vector (make_number (7), Qnil
);
8412 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8413 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8414 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8418 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8419 ASET (vector
, i
, w
->buffer
); ++i
;
8420 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8421 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8426 for (; i
< end
; ++i
)
8427 ASET (vector
, i
, Qnil
);
8430 xassert (i
== ASIZE (vector
));
8435 /* Restore global state from VECTOR which was created by
8436 with_echo_area_buffer_unwind_data. */
8439 unwind_with_echo_area_buffer (vector
)
8442 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8443 Vdeactivate_mark
= AREF (vector
, 1);
8444 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8446 if (WINDOWP (AREF (vector
, 3)))
8449 Lisp_Object buffer
, charpos
, bytepos
;
8451 w
= XWINDOW (AREF (vector
, 3));
8452 buffer
= AREF (vector
, 4);
8453 charpos
= AREF (vector
, 5);
8454 bytepos
= AREF (vector
, 6);
8457 set_marker_both (w
->pointm
, buffer
,
8458 XFASTINT (charpos
), XFASTINT (bytepos
));
8461 Vwith_echo_area_save_vector
= vector
;
8466 /* Set up the echo area for use by print functions. MULTIBYTE_P
8467 non-zero means we will print multibyte. */
8470 setup_echo_area_for_printing (multibyte_p
)
8473 /* If we can't find an echo area any more, exit. */
8474 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8477 ensure_echo_area_buffers ();
8479 if (!message_buf_print
)
8481 /* A message has been output since the last time we printed.
8482 Choose a fresh echo area buffer. */
8483 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8484 echo_area_buffer
[0] = echo_buffer
[1];
8486 echo_area_buffer
[0] = echo_buffer
[0];
8488 /* Switch to that buffer and clear it. */
8489 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8490 current_buffer
->truncate_lines
= Qnil
;
8494 int count
= SPECPDL_INDEX ();
8495 specbind (Qinhibit_read_only
, Qt
);
8496 /* Note that undo recording is always disabled. */
8498 unbind_to (count
, Qnil
);
8500 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8502 /* Set up the buffer for the multibyteness we need. */
8504 != !NILP (current_buffer
->enable_multibyte_characters
))
8505 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8507 /* Raise the frame containing the echo area. */
8508 if (minibuffer_auto_raise
)
8510 struct frame
*sf
= SELECTED_FRAME ();
8511 Lisp_Object mini_window
;
8512 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8513 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8516 message_log_maybe_newline ();
8517 message_buf_print
= 1;
8521 if (NILP (echo_area_buffer
[0]))
8523 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8524 echo_area_buffer
[0] = echo_buffer
[1];
8526 echo_area_buffer
[0] = echo_buffer
[0];
8529 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8531 /* Someone switched buffers between print requests. */
8532 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8533 current_buffer
->truncate_lines
= Qnil
;
8539 /* Display an echo area message in window W. Value is non-zero if W's
8540 height is changed. If display_last_displayed_message_p is
8541 non-zero, display the message that was last displayed, otherwise
8542 display the current message. */
8545 display_echo_area (w
)
8548 int i
, no_message_p
, window_height_changed_p
, count
;
8550 /* Temporarily disable garbage collections while displaying the echo
8551 area. This is done because a GC can print a message itself.
8552 That message would modify the echo area buffer's contents while a
8553 redisplay of the buffer is going on, and seriously confuse
8555 count
= inhibit_garbage_collection ();
8557 /* If there is no message, we must call display_echo_area_1
8558 nevertheless because it resizes the window. But we will have to
8559 reset the echo_area_buffer in question to nil at the end because
8560 with_echo_area_buffer will sets it to an empty buffer. */
8561 i
= display_last_displayed_message_p
? 1 : 0;
8562 no_message_p
= NILP (echo_area_buffer
[i
]);
8564 window_height_changed_p
8565 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8566 display_echo_area_1
,
8567 (EMACS_INT
) w
, Qnil
, 0, 0);
8570 echo_area_buffer
[i
] = Qnil
;
8572 unbind_to (count
, Qnil
);
8573 return window_height_changed_p
;
8577 /* Helper for display_echo_area. Display the current buffer which
8578 contains the current echo area message in window W, a mini-window,
8579 a pointer to which is passed in A1. A2..A4 are currently not used.
8580 Change the height of W so that all of the message is displayed.
8581 Value is non-zero if height of W was changed. */
8584 display_echo_area_1 (a1
, a2
, a3
, a4
)
8589 struct window
*w
= (struct window
*) a1
;
8591 struct text_pos start
;
8592 int window_height_changed_p
= 0;
8594 /* Do this before displaying, so that we have a large enough glyph
8595 matrix for the display. If we can't get enough space for the
8596 whole text, display the last N lines. That works by setting w->start. */
8597 window_height_changed_p
= resize_mini_window (w
, 0);
8599 /* Use the starting position chosen by resize_mini_window. */
8600 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8603 clear_glyph_matrix (w
->desired_matrix
);
8604 XSETWINDOW (window
, w
);
8605 try_window (window
, start
, 0);
8607 return window_height_changed_p
;
8611 /* Resize the echo area window to exactly the size needed for the
8612 currently displayed message, if there is one. If a mini-buffer
8613 is active, don't shrink it. */
8616 resize_echo_area_exactly ()
8618 if (BUFFERP (echo_area_buffer
[0])
8619 && WINDOWP (echo_area_window
))
8621 struct window
*w
= XWINDOW (echo_area_window
);
8623 Lisp_Object resize_exactly
;
8625 if (minibuf_level
== 0)
8626 resize_exactly
= Qt
;
8628 resize_exactly
= Qnil
;
8630 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8631 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8634 ++windows_or_buffers_changed
;
8635 ++update_mode_lines
;
8636 redisplay_internal (0);
8642 /* Callback function for with_echo_area_buffer, when used from
8643 resize_echo_area_exactly. A1 contains a pointer to the window to
8644 resize, EXACTLY non-nil means resize the mini-window exactly to the
8645 size of the text displayed. A3 and A4 are not used. Value is what
8646 resize_mini_window returns. */
8649 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8651 Lisp_Object exactly
;
8654 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8658 /* Resize mini-window W to fit the size of its contents. EXACT_P
8659 means size the window exactly to the size needed. Otherwise, it's
8660 only enlarged until W's buffer is empty.
8662 Set W->start to the right place to begin display. If the whole
8663 contents fit, start at the beginning. Otherwise, start so as
8664 to make the end of the contents appear. This is particularly
8665 important for y-or-n-p, but seems desirable generally.
8667 Value is non-zero if the window height has been changed. */
8670 resize_mini_window (w
, exact_p
)
8674 struct frame
*f
= XFRAME (w
->frame
);
8675 int window_height_changed_p
= 0;
8677 xassert (MINI_WINDOW_P (w
));
8679 /* By default, start display at the beginning. */
8680 set_marker_both (w
->start
, w
->buffer
,
8681 BUF_BEGV (XBUFFER (w
->buffer
)),
8682 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8684 /* Don't resize windows while redisplaying a window; it would
8685 confuse redisplay functions when the size of the window they are
8686 displaying changes from under them. Such a resizing can happen,
8687 for instance, when which-func prints a long message while
8688 we are running fontification-functions. We're running these
8689 functions with safe_call which binds inhibit-redisplay to t. */
8690 if (!NILP (Vinhibit_redisplay
))
8693 /* Nil means don't try to resize. */
8694 if (NILP (Vresize_mini_windows
)
8695 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8698 if (!FRAME_MINIBUF_ONLY_P (f
))
8701 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8702 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8703 int height
, max_height
;
8704 int unit
= FRAME_LINE_HEIGHT (f
);
8705 struct text_pos start
;
8706 struct buffer
*old_current_buffer
= NULL
;
8708 if (current_buffer
!= XBUFFER (w
->buffer
))
8710 old_current_buffer
= current_buffer
;
8711 set_buffer_internal (XBUFFER (w
->buffer
));
8714 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8716 /* Compute the max. number of lines specified by the user. */
8717 if (FLOATP (Vmax_mini_window_height
))
8718 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8719 else if (INTEGERP (Vmax_mini_window_height
))
8720 max_height
= XINT (Vmax_mini_window_height
);
8722 max_height
= total_height
/ 4;
8724 /* Correct that max. height if it's bogus. */
8725 max_height
= max (1, max_height
);
8726 max_height
= min (total_height
, max_height
);
8728 /* Find out the height of the text in the window. */
8729 if (it
.line_wrap
== TRUNCATE
)
8734 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8735 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8736 height
= it
.current_y
+ last_height
;
8738 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8739 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8740 height
= (height
+ unit
- 1) / unit
;
8743 /* Compute a suitable window start. */
8744 if (height
> max_height
)
8746 height
= max_height
;
8747 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8748 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8749 start
= it
.current
.pos
;
8752 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8753 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8755 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8757 /* Let it grow only, until we display an empty message, in which
8758 case the window shrinks again. */
8759 if (height
> WINDOW_TOTAL_LINES (w
))
8761 int old_height
= WINDOW_TOTAL_LINES (w
);
8762 freeze_window_starts (f
, 1);
8763 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8764 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8766 else if (height
< WINDOW_TOTAL_LINES (w
)
8767 && (exact_p
|| BEGV
== ZV
))
8769 int old_height
= WINDOW_TOTAL_LINES (w
);
8770 freeze_window_starts (f
, 0);
8771 shrink_mini_window (w
);
8772 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8777 /* Always resize to exact size needed. */
8778 if (height
> WINDOW_TOTAL_LINES (w
))
8780 int old_height
= WINDOW_TOTAL_LINES (w
);
8781 freeze_window_starts (f
, 1);
8782 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8783 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8785 else if (height
< WINDOW_TOTAL_LINES (w
))
8787 int old_height
= WINDOW_TOTAL_LINES (w
);
8788 freeze_window_starts (f
, 0);
8789 shrink_mini_window (w
);
8793 freeze_window_starts (f
, 1);
8794 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8797 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8801 if (old_current_buffer
)
8802 set_buffer_internal (old_current_buffer
);
8805 return window_height_changed_p
;
8809 /* Value is the current message, a string, or nil if there is no
8817 if (!BUFFERP (echo_area_buffer
[0]))
8821 with_echo_area_buffer (0, 0, current_message_1
,
8822 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8824 echo_area_buffer
[0] = Qnil
;
8832 current_message_1 (a1
, a2
, a3
, a4
)
8837 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8840 *msg
= make_buffer_string (BEG
, Z
, 1);
8847 /* Push the current message on Vmessage_stack for later restauration
8848 by restore_message. Value is non-zero if the current message isn't
8849 empty. This is a relatively infrequent operation, so it's not
8850 worth optimizing. */
8856 msg
= current_message ();
8857 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8858 return STRINGP (msg
);
8862 /* Restore message display from the top of Vmessage_stack. */
8869 xassert (CONSP (Vmessage_stack
));
8870 msg
= XCAR (Vmessage_stack
);
8872 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8874 message3_nolog (msg
, 0, 0);
8878 /* Handler for record_unwind_protect calling pop_message. */
8881 pop_message_unwind (dummy
)
8888 /* Pop the top-most entry off Vmessage_stack. */
8893 xassert (CONSP (Vmessage_stack
));
8894 Vmessage_stack
= XCDR (Vmessage_stack
);
8898 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8899 exits. If the stack is not empty, we have a missing pop_message
8903 check_message_stack ()
8905 if (!NILP (Vmessage_stack
))
8910 /* Truncate to NCHARS what will be displayed in the echo area the next
8911 time we display it---but don't redisplay it now. */
8914 truncate_echo_area (nchars
)
8918 echo_area_buffer
[0] = Qnil
;
8919 /* A null message buffer means that the frame hasn't really been
8920 initialized yet. Error messages get reported properly by
8921 cmd_error, so this must be just an informative message; toss it. */
8922 else if (!noninteractive
8924 && !NILP (echo_area_buffer
[0]))
8926 struct frame
*sf
= SELECTED_FRAME ();
8927 if (FRAME_MESSAGE_BUF (sf
))
8928 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8933 /* Helper function for truncate_echo_area. Truncate the current
8934 message to at most NCHARS characters. */
8937 truncate_message_1 (nchars
, a2
, a3
, a4
)
8942 if (BEG
+ nchars
< Z
)
8943 del_range (BEG
+ nchars
, Z
);
8945 echo_area_buffer
[0] = Qnil
;
8950 /* Set the current message to a substring of S or STRING.
8952 If STRING is a Lisp string, set the message to the first NBYTES
8953 bytes from STRING. NBYTES zero means use the whole string. If
8954 STRING is multibyte, the message will be displayed multibyte.
8956 If S is not null, set the message to the first LEN bytes of S. LEN
8957 zero means use the whole string. MULTIBYTE_P non-zero means S is
8958 multibyte. Display the message multibyte in that case.
8960 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8961 to t before calling set_message_1 (which calls insert).
8965 set_message (s
, string
, nbytes
, multibyte_p
)
8968 int nbytes
, multibyte_p
;
8970 message_enable_multibyte
8971 = ((s
&& multibyte_p
)
8972 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8974 with_echo_area_buffer (0, -1, set_message_1
,
8975 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8976 message_buf_print
= 0;
8977 help_echo_showing_p
= 0;
8981 /* Helper function for set_message. Arguments have the same meaning
8982 as there, with A1 corresponding to S and A2 corresponding to STRING
8983 This function is called with the echo area buffer being
8987 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8990 EMACS_INT nbytes
, multibyte_p
;
8992 const char *s
= (const char *) a1
;
8993 Lisp_Object string
= a2
;
8995 /* Change multibyteness of the echo buffer appropriately. */
8996 if (message_enable_multibyte
8997 != !NILP (current_buffer
->enable_multibyte_characters
))
8998 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9000 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9002 /* Insert new message at BEG. */
9003 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9005 if (STRINGP (string
))
9010 nbytes
= SBYTES (string
);
9011 nchars
= string_byte_to_char (string
, nbytes
);
9013 /* This function takes care of single/multibyte conversion. We
9014 just have to ensure that the echo area buffer has the right
9015 setting of enable_multibyte_characters. */
9016 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9021 nbytes
= strlen (s
);
9023 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9025 /* Convert from multi-byte to single-byte. */
9027 unsigned char work
[1];
9029 /* Convert a multibyte string to single-byte. */
9030 for (i
= 0; i
< nbytes
; i
+= n
)
9032 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
9033 work
[0] = (ASCII_CHAR_P (c
)
9035 : multibyte_char_to_unibyte (c
, Qnil
));
9036 insert_1_both (work
, 1, 1, 1, 0, 0);
9039 else if (!multibyte_p
9040 && !NILP (current_buffer
->enable_multibyte_characters
))
9042 /* Convert from single-byte to multi-byte. */
9044 const unsigned char *msg
= (const unsigned char *) s
;
9045 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9047 /* Convert a single-byte string to multibyte. */
9048 for (i
= 0; i
< nbytes
; i
++)
9051 c
= unibyte_char_to_multibyte (c
);
9052 n
= CHAR_STRING (c
, str
);
9053 insert_1_both (str
, 1, n
, 1, 0, 0);
9057 insert_1 (s
, nbytes
, 1, 0, 0);
9064 /* Clear messages. CURRENT_P non-zero means clear the current
9065 message. LAST_DISPLAYED_P non-zero means clear the message
9069 clear_message (current_p
, last_displayed_p
)
9070 int current_p
, last_displayed_p
;
9074 echo_area_buffer
[0] = Qnil
;
9075 message_cleared_p
= 1;
9078 if (last_displayed_p
)
9079 echo_area_buffer
[1] = Qnil
;
9081 message_buf_print
= 0;
9084 /* Clear garbaged frames.
9086 This function is used where the old redisplay called
9087 redraw_garbaged_frames which in turn called redraw_frame which in
9088 turn called clear_frame. The call to clear_frame was a source of
9089 flickering. I believe a clear_frame is not necessary. It should
9090 suffice in the new redisplay to invalidate all current matrices,
9091 and ensure a complete redisplay of all windows. */
9094 clear_garbaged_frames ()
9098 Lisp_Object tail
, frame
;
9099 int changed_count
= 0;
9101 FOR_EACH_FRAME (tail
, frame
)
9103 struct frame
*f
= XFRAME (frame
);
9105 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9109 Fredraw_frame (frame
);
9110 f
->force_flush_display_p
= 1;
9112 clear_current_matrices (f
);
9121 ++windows_or_buffers_changed
;
9126 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9127 is non-zero update selected_frame. Value is non-zero if the
9128 mini-windows height has been changed. */
9131 echo_area_display (update_frame_p
)
9134 Lisp_Object mini_window
;
9137 int window_height_changed_p
= 0;
9138 struct frame
*sf
= SELECTED_FRAME ();
9140 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9141 w
= XWINDOW (mini_window
);
9142 f
= XFRAME (WINDOW_FRAME (w
));
9144 /* Don't display if frame is invisible or not yet initialized. */
9145 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9148 #ifdef HAVE_WINDOW_SYSTEM
9149 /* When Emacs starts, selected_frame may be the initial terminal
9150 frame. If we let this through, a message would be displayed on
9152 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9154 #endif /* HAVE_WINDOW_SYSTEM */
9156 /* Redraw garbaged frames. */
9158 clear_garbaged_frames ();
9160 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9162 echo_area_window
= mini_window
;
9163 window_height_changed_p
= display_echo_area (w
);
9164 w
->must_be_updated_p
= 1;
9166 /* Update the display, unless called from redisplay_internal.
9167 Also don't update the screen during redisplay itself. The
9168 update will happen at the end of redisplay, and an update
9169 here could cause confusion. */
9170 if (update_frame_p
&& !redisplaying_p
)
9174 /* If the display update has been interrupted by pending
9175 input, update mode lines in the frame. Due to the
9176 pending input, it might have been that redisplay hasn't
9177 been called, so that mode lines above the echo area are
9178 garbaged. This looks odd, so we prevent it here. */
9179 if (!display_completed
)
9180 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9182 if (window_height_changed_p
9183 /* Don't do this if Emacs is shutting down. Redisplay
9184 needs to run hooks. */
9185 && !NILP (Vrun_hooks
))
9187 /* Must update other windows. Likewise as in other
9188 cases, don't let this update be interrupted by
9190 int count
= SPECPDL_INDEX ();
9191 specbind (Qredisplay_dont_pause
, Qt
);
9192 windows_or_buffers_changed
= 1;
9193 redisplay_internal (0);
9194 unbind_to (count
, Qnil
);
9196 else if (FRAME_WINDOW_P (f
) && n
== 0)
9198 /* Window configuration is the same as before.
9199 Can do with a display update of the echo area,
9200 unless we displayed some mode lines. */
9201 update_single_window (w
, 1);
9202 FRAME_RIF (f
)->flush_display (f
);
9205 update_frame (f
, 1, 1);
9207 /* If cursor is in the echo area, make sure that the next
9208 redisplay displays the minibuffer, so that the cursor will
9209 be replaced with what the minibuffer wants. */
9210 if (cursor_in_echo_area
)
9211 ++windows_or_buffers_changed
;
9214 else if (!EQ (mini_window
, selected_window
))
9215 windows_or_buffers_changed
++;
9217 /* Last displayed message is now the current message. */
9218 echo_area_buffer
[1] = echo_area_buffer
[0];
9219 /* Inform read_char that we're not echoing. */
9220 echo_message_buffer
= Qnil
;
9222 /* Prevent redisplay optimization in redisplay_internal by resetting
9223 this_line_start_pos. This is done because the mini-buffer now
9224 displays the message instead of its buffer text. */
9225 if (EQ (mini_window
, selected_window
))
9226 CHARPOS (this_line_start_pos
) = 0;
9228 return window_height_changed_p
;
9233 /***********************************************************************
9234 Mode Lines and Frame Titles
9235 ***********************************************************************/
9237 /* A buffer for constructing non-propertized mode-line strings and
9238 frame titles in it; allocated from the heap in init_xdisp and
9239 resized as needed in store_mode_line_noprop_char. */
9241 static char *mode_line_noprop_buf
;
9243 /* The buffer's end, and a current output position in it. */
9245 static char *mode_line_noprop_buf_end
;
9246 static char *mode_line_noprop_ptr
;
9248 #define MODE_LINE_NOPROP_LEN(start) \
9249 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9252 MODE_LINE_DISPLAY
= 0,
9258 /* Alist that caches the results of :propertize.
9259 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9260 static Lisp_Object mode_line_proptrans_alist
;
9262 /* List of strings making up the mode-line. */
9263 static Lisp_Object mode_line_string_list
;
9265 /* Base face property when building propertized mode line string. */
9266 static Lisp_Object mode_line_string_face
;
9267 static Lisp_Object mode_line_string_face_prop
;
9270 /* Unwind data for mode line strings */
9272 static Lisp_Object Vmode_line_unwind_vector
;
9275 format_mode_line_unwind_data (struct buffer
*obuf
,
9279 Lisp_Object vector
, tmp
;
9281 /* Reduce consing by keeping one vector in
9282 Vwith_echo_area_save_vector. */
9283 vector
= Vmode_line_unwind_vector
;
9284 Vmode_line_unwind_vector
= Qnil
;
9287 vector
= Fmake_vector (make_number (8), Qnil
);
9289 ASET (vector
, 0, make_number (mode_line_target
));
9290 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9291 ASET (vector
, 2, mode_line_string_list
);
9292 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9293 ASET (vector
, 4, mode_line_string_face
);
9294 ASET (vector
, 5, mode_line_string_face_prop
);
9297 XSETBUFFER (tmp
, obuf
);
9300 ASET (vector
, 6, tmp
);
9301 ASET (vector
, 7, owin
);
9307 unwind_format_mode_line (vector
)
9310 mode_line_target
= XINT (AREF (vector
, 0));
9311 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9312 mode_line_string_list
= AREF (vector
, 2);
9313 if (! EQ (AREF (vector
, 3), Qt
))
9314 mode_line_proptrans_alist
= AREF (vector
, 3);
9315 mode_line_string_face
= AREF (vector
, 4);
9316 mode_line_string_face_prop
= AREF (vector
, 5);
9318 if (!NILP (AREF (vector
, 7)))
9319 /* Select window before buffer, since it may change the buffer. */
9320 Fselect_window (AREF (vector
, 7), Qt
);
9322 if (!NILP (AREF (vector
, 6)))
9324 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9325 ASET (vector
, 6, Qnil
);
9328 Vmode_line_unwind_vector
= vector
;
9333 /* Store a single character C for the frame title in mode_line_noprop_buf.
9334 Re-allocate mode_line_noprop_buf if necessary. */
9338 store_mode_line_noprop_char (char c
)
9340 store_mode_line_noprop_char (c
)
9344 /* If output position has reached the end of the allocated buffer,
9345 double the buffer's size. */
9346 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9348 int len
= MODE_LINE_NOPROP_LEN (0);
9349 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9350 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9351 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9352 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9355 *mode_line_noprop_ptr
++ = c
;
9359 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9360 mode_line_noprop_ptr. STR is the string to store. Do not copy
9361 characters that yield more columns than PRECISION; PRECISION <= 0
9362 means copy the whole string. Pad with spaces until FIELD_WIDTH
9363 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9364 pad. Called from display_mode_element when it is used to build a
9368 store_mode_line_noprop (str
, field_width
, precision
)
9369 const unsigned char *str
;
9370 int field_width
, precision
;
9375 /* Copy at most PRECISION chars from STR. */
9376 nbytes
= strlen (str
);
9377 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9379 store_mode_line_noprop_char (*str
++);
9381 /* Fill up with spaces until FIELD_WIDTH reached. */
9382 while (field_width
> 0
9385 store_mode_line_noprop_char (' ');
9392 /***********************************************************************
9394 ***********************************************************************/
9396 #ifdef HAVE_WINDOW_SYSTEM
9398 /* Set the title of FRAME, if it has changed. The title format is
9399 Vicon_title_format if FRAME is iconified, otherwise it is
9400 frame_title_format. */
9403 x_consider_frame_title (frame
)
9406 struct frame
*f
= XFRAME (frame
);
9408 if (FRAME_WINDOW_P (f
)
9409 || FRAME_MINIBUF_ONLY_P (f
)
9410 || f
->explicit_name
)
9412 /* Do we have more than one visible frame on this X display? */
9419 int count
= SPECPDL_INDEX ();
9421 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9423 Lisp_Object other_frame
= XCAR (tail
);
9424 struct frame
*tf
= XFRAME (other_frame
);
9427 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9428 && !FRAME_MINIBUF_ONLY_P (tf
)
9429 && !EQ (other_frame
, tip_frame
)
9430 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9434 /* Set global variable indicating that multiple frames exist. */
9435 multiple_frames
= CONSP (tail
);
9437 /* Switch to the buffer of selected window of the frame. Set up
9438 mode_line_target so that display_mode_element will output into
9439 mode_line_noprop_buf; then display the title. */
9440 record_unwind_protect (unwind_format_mode_line
,
9441 format_mode_line_unwind_data
9442 (current_buffer
, selected_window
, 0));
9444 Fselect_window (f
->selected_window
, Qt
);
9445 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9446 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9448 mode_line_target
= MODE_LINE_TITLE
;
9449 title_start
= MODE_LINE_NOPROP_LEN (0);
9450 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9451 NULL
, DEFAULT_FACE_ID
);
9452 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9453 len
= MODE_LINE_NOPROP_LEN (title_start
);
9454 title
= mode_line_noprop_buf
+ title_start
;
9455 unbind_to (count
, Qnil
);
9457 /* Set the title only if it's changed. This avoids consing in
9458 the common case where it hasn't. (If it turns out that we've
9459 already wasted too much time by walking through the list with
9460 display_mode_element, then we might need to optimize at a
9461 higher level than this.) */
9462 if (! STRINGP (f
->name
)
9463 || SBYTES (f
->name
) != len
9464 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9469 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9472 ns_set_name_as_filename (f
);
9474 x_implicitly_set_name (f
, make_string(title
, len
),
9480 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9485 /* do this also for frames with explicit names */
9486 ns_implicitly_set_icon_type(f
);
9487 ns_set_doc_edited(f
, Fbuffer_modified_p
9488 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9494 #endif /* not HAVE_WINDOW_SYSTEM */
9499 /***********************************************************************
9501 ***********************************************************************/
9504 /* Prepare for redisplay by updating menu-bar item lists when
9505 appropriate. This can call eval. */
9508 prepare_menu_bars ()
9511 struct gcpro gcpro1
, gcpro2
;
9513 Lisp_Object tooltip_frame
;
9515 #ifdef HAVE_WINDOW_SYSTEM
9516 tooltip_frame
= tip_frame
;
9518 tooltip_frame
= Qnil
;
9521 /* Update all frame titles based on their buffer names, etc. We do
9522 this before the menu bars so that the buffer-menu will show the
9523 up-to-date frame titles. */
9524 #ifdef HAVE_WINDOW_SYSTEM
9525 if (windows_or_buffers_changed
|| update_mode_lines
)
9527 Lisp_Object tail
, frame
;
9529 FOR_EACH_FRAME (tail
, frame
)
9532 if (!EQ (frame
, tooltip_frame
)
9533 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9534 x_consider_frame_title (frame
);
9537 #endif /* HAVE_WINDOW_SYSTEM */
9539 /* Update the menu bar item lists, if appropriate. This has to be
9540 done before any actual redisplay or generation of display lines. */
9541 all_windows
= (update_mode_lines
9542 || buffer_shared
> 1
9543 || windows_or_buffers_changed
);
9546 Lisp_Object tail
, frame
;
9547 int count
= SPECPDL_INDEX ();
9548 /* 1 means that update_menu_bar has run its hooks
9549 so any further calls to update_menu_bar shouldn't do so again. */
9550 int menu_bar_hooks_run
= 0;
9552 record_unwind_save_match_data ();
9554 FOR_EACH_FRAME (tail
, frame
)
9558 /* Ignore tooltip frame. */
9559 if (EQ (frame
, tooltip_frame
))
9562 /* If a window on this frame changed size, report that to
9563 the user and clear the size-change flag. */
9564 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9566 Lisp_Object functions
;
9568 /* Clear flag first in case we get an error below. */
9569 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9570 functions
= Vwindow_size_change_functions
;
9571 GCPRO2 (tail
, functions
);
9573 while (CONSP (functions
))
9575 if (!EQ (XCAR (functions
), Qt
))
9576 call1 (XCAR (functions
), frame
);
9577 functions
= XCDR (functions
);
9583 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9584 #ifdef HAVE_WINDOW_SYSTEM
9585 update_tool_bar (f
, 0);
9590 unbind_to (count
, Qnil
);
9594 struct frame
*sf
= SELECTED_FRAME ();
9595 update_menu_bar (sf
, 1, 0);
9596 #ifdef HAVE_WINDOW_SYSTEM
9597 update_tool_bar (sf
, 1);
9601 /* Motif needs this. See comment in xmenu.c. Turn it off when
9602 pending_menu_activation is not defined. */
9603 #ifdef USE_X_TOOLKIT
9604 pending_menu_activation
= 0;
9609 /* Update the menu bar item list for frame F. This has to be done
9610 before we start to fill in any display lines, because it can call
9613 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9615 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9616 already ran the menu bar hooks for this redisplay, so there
9617 is no need to run them again. The return value is the
9618 updated value of this flag, to pass to the next call. */
9621 update_menu_bar (f
, save_match_data
, hooks_run
)
9623 int save_match_data
;
9627 register struct window
*w
;
9629 /* If called recursively during a menu update, do nothing. This can
9630 happen when, for instance, an activate-menubar-hook causes a
9632 if (inhibit_menubar_update
)
9635 window
= FRAME_SELECTED_WINDOW (f
);
9636 w
= XWINDOW (window
);
9638 if (FRAME_WINDOW_P (f
)
9640 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9641 || defined (HAVE_NS) || defined (USE_GTK)
9642 FRAME_EXTERNAL_MENU_BAR (f
)
9644 FRAME_MENU_BAR_LINES (f
) > 0
9646 : FRAME_MENU_BAR_LINES (f
) > 0)
9648 /* If the user has switched buffers or windows, we need to
9649 recompute to reflect the new bindings. But we'll
9650 recompute when update_mode_lines is set too; that means
9651 that people can use force-mode-line-update to request
9652 that the menu bar be recomputed. The adverse effect on
9653 the rest of the redisplay algorithm is about the same as
9654 windows_or_buffers_changed anyway. */
9655 if (windows_or_buffers_changed
9656 /* This used to test w->update_mode_line, but we believe
9657 there is no need to recompute the menu in that case. */
9658 || update_mode_lines
9659 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9660 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9661 != !NILP (w
->last_had_star
))
9662 || ((!NILP (Vtransient_mark_mode
)
9663 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9664 != !NILP (w
->region_showing
)))
9666 struct buffer
*prev
= current_buffer
;
9667 int count
= SPECPDL_INDEX ();
9669 specbind (Qinhibit_menubar_update
, Qt
);
9671 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9672 if (save_match_data
)
9673 record_unwind_save_match_data ();
9674 if (NILP (Voverriding_local_map_menu_flag
))
9676 specbind (Qoverriding_terminal_local_map
, Qnil
);
9677 specbind (Qoverriding_local_map
, Qnil
);
9682 /* Run the Lucid hook. */
9683 safe_run_hooks (Qactivate_menubar_hook
);
9685 /* If it has changed current-menubar from previous value,
9686 really recompute the menu-bar from the value. */
9687 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9688 call0 (Qrecompute_lucid_menubar
);
9690 safe_run_hooks (Qmenu_bar_update_hook
);
9695 XSETFRAME (Vmenu_updating_frame
, f
);
9696 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9698 /* Redisplay the menu bar in case we changed it. */
9699 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9700 || defined (HAVE_NS) || defined (USE_GTK)
9701 if (FRAME_WINDOW_P (f
))
9703 #if defined (HAVE_NS)
9704 /* All frames on Mac OS share the same menubar. So only
9705 the selected frame should be allowed to set it. */
9706 if (f
== SELECTED_FRAME ())
9708 set_frame_menubar (f
, 0, 0);
9711 /* On a terminal screen, the menu bar is an ordinary screen
9712 line, and this makes it get updated. */
9713 w
->update_mode_line
= Qt
;
9714 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9715 /* In the non-toolkit version, the menu bar is an ordinary screen
9716 line, and this makes it get updated. */
9717 w
->update_mode_line
= Qt
;
9718 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9720 unbind_to (count
, Qnil
);
9721 set_buffer_internal_1 (prev
);
9730 /***********************************************************************
9732 ***********************************************************************/
9734 #ifdef HAVE_WINDOW_SYSTEM
9737 Nominal cursor position -- where to draw output.
9738 HPOS and VPOS are window relative glyph matrix coordinates.
9739 X and Y are window relative pixel coordinates. */
9741 struct cursor_pos output_cursor
;
9745 Set the global variable output_cursor to CURSOR. All cursor
9746 positions are relative to updated_window. */
9749 set_output_cursor (cursor
)
9750 struct cursor_pos
*cursor
;
9752 output_cursor
.hpos
= cursor
->hpos
;
9753 output_cursor
.vpos
= cursor
->vpos
;
9754 output_cursor
.x
= cursor
->x
;
9755 output_cursor
.y
= cursor
->y
;
9760 Set a nominal cursor position.
9762 HPOS and VPOS are column/row positions in a window glyph matrix. X
9763 and Y are window text area relative pixel positions.
9765 If this is done during an update, updated_window will contain the
9766 window that is being updated and the position is the future output
9767 cursor position for that window. If updated_window is null, use
9768 selected_window and display the cursor at the given position. */
9771 x_cursor_to (vpos
, hpos
, y
, x
)
9772 int vpos
, hpos
, y
, x
;
9776 /* If updated_window is not set, work on selected_window. */
9780 w
= XWINDOW (selected_window
);
9782 /* Set the output cursor. */
9783 output_cursor
.hpos
= hpos
;
9784 output_cursor
.vpos
= vpos
;
9785 output_cursor
.x
= x
;
9786 output_cursor
.y
= y
;
9788 /* If not called as part of an update, really display the cursor.
9789 This will also set the cursor position of W. */
9790 if (updated_window
== NULL
)
9793 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9794 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9795 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9800 #endif /* HAVE_WINDOW_SYSTEM */
9803 /***********************************************************************
9805 ***********************************************************************/
9807 #ifdef HAVE_WINDOW_SYSTEM
9809 /* Where the mouse was last time we reported a mouse event. */
9811 FRAME_PTR last_mouse_frame
;
9813 /* Tool-bar item index of the item on which a mouse button was pressed
9816 int last_tool_bar_item
;
9820 update_tool_bar_unwind (frame
)
9823 selected_frame
= frame
;
9827 /* Update the tool-bar item list for frame F. This has to be done
9828 before we start to fill in any display lines. Called from
9829 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9830 and restore it here. */
9833 update_tool_bar (f
, save_match_data
)
9835 int save_match_data
;
9837 #if defined (USE_GTK) || defined (HAVE_NS)
9838 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9840 int do_update
= WINDOWP (f
->tool_bar_window
)
9841 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9849 window
= FRAME_SELECTED_WINDOW (f
);
9850 w
= XWINDOW (window
);
9852 /* If the user has switched buffers or windows, we need to
9853 recompute to reflect the new bindings. But we'll
9854 recompute when update_mode_lines is set too; that means
9855 that people can use force-mode-line-update to request
9856 that the menu bar be recomputed. The adverse effect on
9857 the rest of the redisplay algorithm is about the same as
9858 windows_or_buffers_changed anyway. */
9859 if (windows_or_buffers_changed
9860 || !NILP (w
->update_mode_line
)
9861 || update_mode_lines
9862 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9863 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9864 != !NILP (w
->last_had_star
))
9865 || ((!NILP (Vtransient_mark_mode
)
9866 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9867 != !NILP (w
->region_showing
)))
9869 struct buffer
*prev
= current_buffer
;
9870 int count
= SPECPDL_INDEX ();
9871 Lisp_Object frame
, new_tool_bar
;
9873 struct gcpro gcpro1
;
9875 /* Set current_buffer to the buffer of the selected
9876 window of the frame, so that we get the right local
9878 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9880 /* Save match data, if we must. */
9881 if (save_match_data
)
9882 record_unwind_save_match_data ();
9884 /* Make sure that we don't accidentally use bogus keymaps. */
9885 if (NILP (Voverriding_local_map_menu_flag
))
9887 specbind (Qoverriding_terminal_local_map
, Qnil
);
9888 specbind (Qoverriding_local_map
, Qnil
);
9891 GCPRO1 (new_tool_bar
);
9893 /* We must temporarily set the selected frame to this frame
9894 before calling tool_bar_items, because the calculation of
9895 the tool-bar keymap uses the selected frame (see
9896 `tool-bar-make-keymap' in tool-bar.el). */
9897 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9898 XSETFRAME (frame
, f
);
9899 selected_frame
= frame
;
9901 /* Build desired tool-bar items from keymaps. */
9902 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9905 /* Redisplay the tool-bar if we changed it. */
9906 if (new_n_tool_bar
!= f
->n_tool_bar_items
9907 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9909 /* Redisplay that happens asynchronously due to an expose event
9910 may access f->tool_bar_items. Make sure we update both
9911 variables within BLOCK_INPUT so no such event interrupts. */
9913 f
->tool_bar_items
= new_tool_bar
;
9914 f
->n_tool_bar_items
= new_n_tool_bar
;
9915 w
->update_mode_line
= Qt
;
9921 unbind_to (count
, Qnil
);
9922 set_buffer_internal_1 (prev
);
9928 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9929 F's desired tool-bar contents. F->tool_bar_items must have
9930 been set up previously by calling prepare_menu_bars. */
9933 build_desired_tool_bar_string (f
)
9936 int i
, size
, size_needed
;
9937 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9938 Lisp_Object image
, plist
, props
;
9940 image
= plist
= props
= Qnil
;
9941 GCPRO3 (image
, plist
, props
);
9943 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9944 Otherwise, make a new string. */
9946 /* The size of the string we might be able to reuse. */
9947 size
= (STRINGP (f
->desired_tool_bar_string
)
9948 ? SCHARS (f
->desired_tool_bar_string
)
9951 /* We need one space in the string for each image. */
9952 size_needed
= f
->n_tool_bar_items
;
9954 /* Reuse f->desired_tool_bar_string, if possible. */
9955 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9956 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9960 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9961 Fremove_text_properties (make_number (0), make_number (size
),
9962 props
, f
->desired_tool_bar_string
);
9965 /* Put a `display' property on the string for the images to display,
9966 put a `menu_item' property on tool-bar items with a value that
9967 is the index of the item in F's tool-bar item vector. */
9968 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9970 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9972 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9973 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9974 int hmargin
, vmargin
, relief
, idx
, end
;
9975 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9977 /* If image is a vector, choose the image according to the
9979 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9980 if (VECTORP (image
))
9984 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9985 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9988 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9989 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9991 xassert (ASIZE (image
) >= idx
);
9992 image
= AREF (image
, idx
);
9997 /* Ignore invalid image specifications. */
9998 if (!valid_image_p (image
))
10001 /* Display the tool-bar button pressed, or depressed. */
10002 plist
= Fcopy_sequence (XCDR (image
));
10004 /* Compute margin and relief to draw. */
10005 relief
= (tool_bar_button_relief
>= 0
10006 ? tool_bar_button_relief
10007 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10008 hmargin
= vmargin
= relief
;
10010 if (INTEGERP (Vtool_bar_button_margin
)
10011 && XINT (Vtool_bar_button_margin
) > 0)
10013 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10014 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10016 else if (CONSP (Vtool_bar_button_margin
))
10018 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10019 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10020 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10022 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10023 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10024 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10027 if (auto_raise_tool_bar_buttons_p
)
10029 /* Add a `:relief' property to the image spec if the item is
10033 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10040 /* If image is selected, display it pressed, i.e. with a
10041 negative relief. If it's not selected, display it with a
10043 plist
= Fplist_put (plist
, QCrelief
,
10045 ? make_number (-relief
)
10046 : make_number (relief
)));
10051 /* Put a margin around the image. */
10052 if (hmargin
|| vmargin
)
10054 if (hmargin
== vmargin
)
10055 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10057 plist
= Fplist_put (plist
, QCmargin
,
10058 Fcons (make_number (hmargin
),
10059 make_number (vmargin
)));
10062 /* If button is not enabled, and we don't have special images
10063 for the disabled state, make the image appear disabled by
10064 applying an appropriate algorithm to it. */
10065 if (!enabled_p
&& idx
< 0)
10066 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10068 /* Put a `display' text property on the string for the image to
10069 display. Put a `menu-item' property on the string that gives
10070 the start of this item's properties in the tool-bar items
10072 image
= Fcons (Qimage
, plist
);
10073 props
= list4 (Qdisplay
, image
,
10074 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10076 /* Let the last image hide all remaining spaces in the tool bar
10077 string. The string can be longer than needed when we reuse a
10078 previous string. */
10079 if (i
+ 1 == f
->n_tool_bar_items
)
10080 end
= SCHARS (f
->desired_tool_bar_string
);
10083 Fadd_text_properties (make_number (i
), make_number (end
),
10084 props
, f
->desired_tool_bar_string
);
10092 /* Display one line of the tool-bar of frame IT->f.
10094 HEIGHT specifies the desired height of the tool-bar line.
10095 If the actual height of the glyph row is less than HEIGHT, the
10096 row's height is increased to HEIGHT, and the icons are centered
10097 vertically in the new height.
10099 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10100 count a final empty row in case the tool-bar width exactly matches
10105 display_tool_bar_line (it
, height
)
10109 struct glyph_row
*row
= it
->glyph_row
;
10110 int max_x
= it
->last_visible_x
;
10111 struct glyph
*last
;
10113 prepare_desired_row (row
);
10114 row
->y
= it
->current_y
;
10116 /* Note that this isn't made use of if the face hasn't a box,
10117 so there's no need to check the face here. */
10118 it
->start_of_box_run_p
= 1;
10120 while (it
->current_x
< max_x
)
10122 int x
, n_glyphs_before
, i
, nglyphs
;
10123 struct it it_before
;
10125 /* Get the next display element. */
10126 if (!get_next_display_element (it
))
10128 /* Don't count empty row if we are counting needed tool-bar lines. */
10129 if (height
< 0 && !it
->hpos
)
10134 /* Produce glyphs. */
10135 n_glyphs_before
= row
->used
[TEXT_AREA
];
10138 PRODUCE_GLYPHS (it
);
10140 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10142 x
= it_before
.current_x
;
10143 while (i
< nglyphs
)
10145 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10147 if (x
+ glyph
->pixel_width
> max_x
)
10149 /* Glyph doesn't fit on line. Backtrack. */
10150 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10152 /* If this is the only glyph on this line, it will never fit on the
10153 toolbar, so skip it. But ensure there is at least one glyph,
10154 so we don't accidentally disable the tool-bar. */
10155 if (n_glyphs_before
== 0
10156 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10162 x
+= glyph
->pixel_width
;
10166 /* Stop at line ends. */
10167 if (ITERATOR_AT_END_OF_LINE_P (it
))
10170 set_iterator_to_next (it
, 1);
10175 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10177 /* Use default face for the border below the tool bar.
10179 FIXME: When auto-resize-tool-bars is grow-only, there is
10180 no additional border below the possibly empty tool-bar lines.
10181 So to make the extra empty lines look "normal", we have to
10182 use the tool-bar face for the border too. */
10183 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10184 it
->face_id
= DEFAULT_FACE_ID
;
10186 extend_face_to_end_of_line (it
);
10187 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10188 last
->right_box_line_p
= 1;
10189 if (last
== row
->glyphs
[TEXT_AREA
])
10190 last
->left_box_line_p
= 1;
10192 /* Make line the desired height and center it vertically. */
10193 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10195 /* Don't add more than one line height. */
10196 height
%= FRAME_LINE_HEIGHT (it
->f
);
10197 it
->max_ascent
+= height
/ 2;
10198 it
->max_descent
+= (height
+ 1) / 2;
10201 compute_line_metrics (it
);
10203 /* If line is empty, make it occupy the rest of the tool-bar. */
10204 if (!row
->displays_text_p
)
10206 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10207 row
->visible_height
= row
->height
;
10208 row
->ascent
= row
->phys_ascent
= 0;
10209 row
->extra_line_spacing
= 0;
10212 row
->full_width_p
= 1;
10213 row
->continued_p
= 0;
10214 row
->truncated_on_left_p
= 0;
10215 row
->truncated_on_right_p
= 0;
10217 it
->current_x
= it
->hpos
= 0;
10218 it
->current_y
+= row
->height
;
10224 /* Max tool-bar height. */
10226 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10227 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10229 /* Value is the number of screen lines needed to make all tool-bar
10230 items of frame F visible. The number of actual rows needed is
10231 returned in *N_ROWS if non-NULL. */
10234 tool_bar_lines_needed (f
, n_rows
)
10238 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10240 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10241 the desired matrix, so use (unused) mode-line row as temporary row to
10242 avoid destroying the first tool-bar row. */
10243 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10245 /* Initialize an iterator for iteration over
10246 F->desired_tool_bar_string in the tool-bar window of frame F. */
10247 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10248 it
.first_visible_x
= 0;
10249 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10250 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10252 while (!ITERATOR_AT_END_P (&it
))
10254 clear_glyph_row (temp_row
);
10255 it
.glyph_row
= temp_row
;
10256 display_tool_bar_line (&it
, -1);
10258 clear_glyph_row (temp_row
);
10260 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10262 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10264 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10268 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10270 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10279 frame
= selected_frame
;
10281 CHECK_FRAME (frame
);
10282 f
= XFRAME (frame
);
10284 if (WINDOWP (f
->tool_bar_window
)
10285 || (w
= XWINDOW (f
->tool_bar_window
),
10286 WINDOW_TOTAL_LINES (w
) > 0))
10288 update_tool_bar (f
, 1);
10289 if (f
->n_tool_bar_items
)
10291 build_desired_tool_bar_string (f
);
10292 nlines
= tool_bar_lines_needed (f
, NULL
);
10296 return make_number (nlines
);
10300 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10301 height should be changed. */
10304 redisplay_tool_bar (f
)
10309 struct glyph_row
*row
;
10311 #if defined (USE_GTK) || defined (HAVE_NS)
10312 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10313 update_frame_tool_bar (f
);
10317 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10318 do anything. This means you must start with tool-bar-lines
10319 non-zero to get the auto-sizing effect. Or in other words, you
10320 can turn off tool-bars by specifying tool-bar-lines zero. */
10321 if (!WINDOWP (f
->tool_bar_window
)
10322 || (w
= XWINDOW (f
->tool_bar_window
),
10323 WINDOW_TOTAL_LINES (w
) == 0))
10326 /* Set up an iterator for the tool-bar window. */
10327 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10328 it
.first_visible_x
= 0;
10329 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10330 row
= it
.glyph_row
;
10332 /* Build a string that represents the contents of the tool-bar. */
10333 build_desired_tool_bar_string (f
);
10334 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10336 if (f
->n_tool_bar_rows
== 0)
10340 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10341 nlines
!= WINDOW_TOTAL_LINES (w
)))
10343 extern Lisp_Object Qtool_bar_lines
;
10345 int old_height
= WINDOW_TOTAL_LINES (w
);
10347 XSETFRAME (frame
, f
);
10348 Fmodify_frame_parameters (frame
,
10349 Fcons (Fcons (Qtool_bar_lines
,
10350 make_number (nlines
)),
10352 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10354 clear_glyph_matrix (w
->desired_matrix
);
10355 fonts_changed_p
= 1;
10361 /* Display as many lines as needed to display all tool-bar items. */
10363 if (f
->n_tool_bar_rows
> 0)
10365 int border
, rows
, height
, extra
;
10367 if (INTEGERP (Vtool_bar_border
))
10368 border
= XINT (Vtool_bar_border
);
10369 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10370 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10371 else if (EQ (Vtool_bar_border
, Qborder_width
))
10372 border
= f
->border_width
;
10378 rows
= f
->n_tool_bar_rows
;
10379 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10380 extra
= it
.last_visible_y
- border
- height
* rows
;
10382 while (it
.current_y
< it
.last_visible_y
)
10385 if (extra
> 0 && rows
-- > 0)
10387 h
= (extra
+ rows
- 1) / rows
;
10390 display_tool_bar_line (&it
, height
+ h
);
10395 while (it
.current_y
< it
.last_visible_y
)
10396 display_tool_bar_line (&it
, 0);
10399 /* It doesn't make much sense to try scrolling in the tool-bar
10400 window, so don't do it. */
10401 w
->desired_matrix
->no_scrolling_p
= 1;
10402 w
->must_be_updated_p
= 1;
10404 if (!NILP (Vauto_resize_tool_bars
))
10406 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10407 int change_height_p
= 0;
10409 /* If we couldn't display everything, change the tool-bar's
10410 height if there is room for more. */
10411 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10412 && it
.current_y
< max_tool_bar_height
)
10413 change_height_p
= 1;
10415 row
= it
.glyph_row
- 1;
10417 /* If there are blank lines at the end, except for a partially
10418 visible blank line at the end that is smaller than
10419 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10420 if (!row
->displays_text_p
10421 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10422 change_height_p
= 1;
10424 /* If row displays tool-bar items, but is partially visible,
10425 change the tool-bar's height. */
10426 if (row
->displays_text_p
10427 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10428 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10429 change_height_p
= 1;
10431 /* Resize windows as needed by changing the `tool-bar-lines'
10432 frame parameter. */
10433 if (change_height_p
)
10435 extern Lisp_Object Qtool_bar_lines
;
10437 int old_height
= WINDOW_TOTAL_LINES (w
);
10439 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10441 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10442 && !f
->minimize_tool_bar_window_p
)
10443 ? (nlines
> old_height
)
10444 : (nlines
!= old_height
));
10445 f
->minimize_tool_bar_window_p
= 0;
10447 if (change_height_p
)
10449 XSETFRAME (frame
, f
);
10450 Fmodify_frame_parameters (frame
,
10451 Fcons (Fcons (Qtool_bar_lines
,
10452 make_number (nlines
)),
10454 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10456 clear_glyph_matrix (w
->desired_matrix
);
10457 f
->n_tool_bar_rows
= nrows
;
10458 fonts_changed_p
= 1;
10465 f
->minimize_tool_bar_window_p
= 0;
10470 /* Get information about the tool-bar item which is displayed in GLYPH
10471 on frame F. Return in *PROP_IDX the index where tool-bar item
10472 properties start in F->tool_bar_items. Value is zero if
10473 GLYPH doesn't display a tool-bar item. */
10476 tool_bar_item_info (f
, glyph
, prop_idx
)
10478 struct glyph
*glyph
;
10485 /* This function can be called asynchronously, which means we must
10486 exclude any possibility that Fget_text_property signals an
10488 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10489 charpos
= max (0, charpos
);
10491 /* Get the text property `menu-item' at pos. The value of that
10492 property is the start index of this item's properties in
10493 F->tool_bar_items. */
10494 prop
= Fget_text_property (make_number (charpos
),
10495 Qmenu_item
, f
->current_tool_bar_string
);
10496 if (INTEGERP (prop
))
10498 *prop_idx
= XINT (prop
);
10508 /* Get information about the tool-bar item at position X/Y on frame F.
10509 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10510 the current matrix of the tool-bar window of F, or NULL if not
10511 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10512 item in F->tool_bar_items. Value is
10514 -1 if X/Y is not on a tool-bar item
10515 0 if X/Y is on the same item that was highlighted before.
10519 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10522 struct glyph
**glyph
;
10523 int *hpos
, *vpos
, *prop_idx
;
10525 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10526 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10529 /* Find the glyph under X/Y. */
10530 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10531 if (*glyph
== NULL
)
10534 /* Get the start of this tool-bar item's properties in
10535 f->tool_bar_items. */
10536 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10539 /* Is mouse on the highlighted item? */
10540 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10541 && *vpos
>= dpyinfo
->mouse_face_beg_row
10542 && *vpos
<= dpyinfo
->mouse_face_end_row
10543 && (*vpos
> dpyinfo
->mouse_face_beg_row
10544 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10545 && (*vpos
< dpyinfo
->mouse_face_end_row
10546 || *hpos
< dpyinfo
->mouse_face_end_col
10547 || dpyinfo
->mouse_face_past_end
))
10555 Handle mouse button event on the tool-bar of frame F, at
10556 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10557 0 for button release. MODIFIERS is event modifiers for button
10561 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10564 unsigned int modifiers
;
10566 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10567 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10568 int hpos
, vpos
, prop_idx
;
10569 struct glyph
*glyph
;
10570 Lisp_Object enabled_p
;
10572 /* If not on the highlighted tool-bar item, return. */
10573 frame_to_window_pixel_xy (w
, &x
, &y
);
10574 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10577 /* If item is disabled, do nothing. */
10578 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10579 if (NILP (enabled_p
))
10584 /* Show item in pressed state. */
10585 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10586 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10587 last_tool_bar_item
= prop_idx
;
10591 Lisp_Object key
, frame
;
10592 struct input_event event
;
10593 EVENT_INIT (event
);
10595 /* Show item in released state. */
10596 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10597 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10599 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10601 XSETFRAME (frame
, f
);
10602 event
.kind
= TOOL_BAR_EVENT
;
10603 event
.frame_or_window
= frame
;
10605 kbd_buffer_store_event (&event
);
10607 event
.kind
= TOOL_BAR_EVENT
;
10608 event
.frame_or_window
= frame
;
10610 event
.modifiers
= modifiers
;
10611 kbd_buffer_store_event (&event
);
10612 last_tool_bar_item
= -1;
10617 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10618 tool-bar window-relative coordinates X/Y. Called from
10619 note_mouse_highlight. */
10622 note_tool_bar_highlight (f
, x
, y
)
10626 Lisp_Object window
= f
->tool_bar_window
;
10627 struct window
*w
= XWINDOW (window
);
10628 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10630 struct glyph
*glyph
;
10631 struct glyph_row
*row
;
10633 Lisp_Object enabled_p
;
10635 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10636 int mouse_down_p
, rc
;
10638 /* Function note_mouse_highlight is called with negative x(y
10639 values when mouse moves outside of the frame. */
10640 if (x
<= 0 || y
<= 0)
10642 clear_mouse_face (dpyinfo
);
10646 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10649 /* Not on tool-bar item. */
10650 clear_mouse_face (dpyinfo
);
10654 /* On same tool-bar item as before. */
10655 goto set_help_echo
;
10657 clear_mouse_face (dpyinfo
);
10659 /* Mouse is down, but on different tool-bar item? */
10660 mouse_down_p
= (dpyinfo
->grabbed
10661 && f
== last_mouse_frame
10662 && FRAME_LIVE_P (f
));
10664 && last_tool_bar_item
!= prop_idx
)
10667 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10668 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10670 /* If tool-bar item is not enabled, don't highlight it. */
10671 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10672 if (!NILP (enabled_p
))
10674 /* Compute the x-position of the glyph. In front and past the
10675 image is a space. We include this in the highlighted area. */
10676 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10677 for (i
= x
= 0; i
< hpos
; ++i
)
10678 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10680 /* Record this as the current active region. */
10681 dpyinfo
->mouse_face_beg_col
= hpos
;
10682 dpyinfo
->mouse_face_beg_row
= vpos
;
10683 dpyinfo
->mouse_face_beg_x
= x
;
10684 dpyinfo
->mouse_face_beg_y
= row
->y
;
10685 dpyinfo
->mouse_face_past_end
= 0;
10687 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10688 dpyinfo
->mouse_face_end_row
= vpos
;
10689 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10690 dpyinfo
->mouse_face_end_y
= row
->y
;
10691 dpyinfo
->mouse_face_window
= window
;
10692 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10694 /* Display it as active. */
10695 show_mouse_face (dpyinfo
, draw
);
10696 dpyinfo
->mouse_face_image_state
= draw
;
10701 /* Set help_echo_string to a help string to display for this tool-bar item.
10702 XTread_socket does the rest. */
10703 help_echo_object
= help_echo_window
= Qnil
;
10704 help_echo_pos
= -1;
10705 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10706 if (NILP (help_echo_string
))
10707 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10710 #endif /* HAVE_WINDOW_SYSTEM */
10714 /************************************************************************
10715 Horizontal scrolling
10716 ************************************************************************/
10718 static int hscroll_window_tree
P_ ((Lisp_Object
));
10719 static int hscroll_windows
P_ ((Lisp_Object
));
10721 /* For all leaf windows in the window tree rooted at WINDOW, set their
10722 hscroll value so that PT is (i) visible in the window, and (ii) so
10723 that it is not within a certain margin at the window's left and
10724 right border. Value is non-zero if any window's hscroll has been
10728 hscroll_window_tree (window
)
10729 Lisp_Object window
;
10731 int hscrolled_p
= 0;
10732 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10733 int hscroll_step_abs
= 0;
10734 double hscroll_step_rel
= 0;
10736 if (hscroll_relative_p
)
10738 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10739 if (hscroll_step_rel
< 0)
10741 hscroll_relative_p
= 0;
10742 hscroll_step_abs
= 0;
10745 else if (INTEGERP (Vhscroll_step
))
10747 hscroll_step_abs
= XINT (Vhscroll_step
);
10748 if (hscroll_step_abs
< 0)
10749 hscroll_step_abs
= 0;
10752 hscroll_step_abs
= 0;
10754 while (WINDOWP (window
))
10756 struct window
*w
= XWINDOW (window
);
10758 if (WINDOWP (w
->hchild
))
10759 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10760 else if (WINDOWP (w
->vchild
))
10761 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10762 else if (w
->cursor
.vpos
>= 0)
10765 int text_area_width
;
10766 struct glyph_row
*current_cursor_row
10767 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10768 struct glyph_row
*desired_cursor_row
10769 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10770 struct glyph_row
*cursor_row
10771 = (desired_cursor_row
->enabled_p
10772 ? desired_cursor_row
10773 : current_cursor_row
);
10775 text_area_width
= window_box_width (w
, TEXT_AREA
);
10777 /* Scroll when cursor is inside this scroll margin. */
10778 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10780 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10781 && ((XFASTINT (w
->hscroll
)
10782 && w
->cursor
.x
<= h_margin
)
10783 || (cursor_row
->enabled_p
10784 && cursor_row
->truncated_on_right_p
10785 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10789 struct buffer
*saved_current_buffer
;
10793 /* Find point in a display of infinite width. */
10794 saved_current_buffer
= current_buffer
;
10795 current_buffer
= XBUFFER (w
->buffer
);
10797 if (w
== XWINDOW (selected_window
))
10798 pt
= BUF_PT (current_buffer
);
10801 pt
= marker_position (w
->pointm
);
10802 pt
= max (BEGV
, pt
);
10806 /* Move iterator to pt starting at cursor_row->start in
10807 a line with infinite width. */
10808 init_to_row_start (&it
, w
, cursor_row
);
10809 it
.last_visible_x
= INFINITY
;
10810 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10811 current_buffer
= saved_current_buffer
;
10813 /* Position cursor in window. */
10814 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10815 hscroll
= max (0, (it
.current_x
10816 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10817 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10818 : (text_area_width
/ 2))))
10819 / FRAME_COLUMN_WIDTH (it
.f
);
10820 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10822 if (hscroll_relative_p
)
10823 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10826 wanted_x
= text_area_width
10827 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10830 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10834 if (hscroll_relative_p
)
10835 wanted_x
= text_area_width
* hscroll_step_rel
10838 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10841 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10843 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10845 /* Don't call Fset_window_hscroll if value hasn't
10846 changed because it will prevent redisplay
10848 if (XFASTINT (w
->hscroll
) != hscroll
)
10850 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10851 w
->hscroll
= make_number (hscroll
);
10860 /* Value is non-zero if hscroll of any leaf window has been changed. */
10861 return hscrolled_p
;
10865 /* Set hscroll so that cursor is visible and not inside horizontal
10866 scroll margins for all windows in the tree rooted at WINDOW. See
10867 also hscroll_window_tree above. Value is non-zero if any window's
10868 hscroll has been changed. If it has, desired matrices on the frame
10869 of WINDOW are cleared. */
10872 hscroll_windows (window
)
10873 Lisp_Object window
;
10875 int hscrolled_p
= hscroll_window_tree (window
);
10877 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10878 return hscrolled_p
;
10883 /************************************************************************
10885 ************************************************************************/
10887 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10888 to a non-zero value. This is sometimes handy to have in a debugger
10893 /* First and last unchanged row for try_window_id. */
10895 int debug_first_unchanged_at_end_vpos
;
10896 int debug_last_unchanged_at_beg_vpos
;
10898 /* Delta vpos and y. */
10900 int debug_dvpos
, debug_dy
;
10902 /* Delta in characters and bytes for try_window_id. */
10904 int debug_delta
, debug_delta_bytes
;
10906 /* Values of window_end_pos and window_end_vpos at the end of
10909 EMACS_INT debug_end_pos
, debug_end_vpos
;
10911 /* Append a string to W->desired_matrix->method. FMT is a printf
10912 format string. A1...A9 are a supplement for a variable-length
10913 argument list. If trace_redisplay_p is non-zero also printf the
10914 resulting string to stderr. */
10917 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10920 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10923 char *method
= w
->desired_matrix
->method
;
10924 int len
= strlen (method
);
10925 int size
= sizeof w
->desired_matrix
->method
;
10926 int remaining
= size
- len
- 1;
10928 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10929 if (len
&& remaining
)
10932 --remaining
, ++len
;
10935 strncpy (method
+ len
, buffer
, remaining
);
10937 if (trace_redisplay_p
)
10938 fprintf (stderr
, "%p (%s): %s\n",
10940 ((BUFFERP (w
->buffer
)
10941 && STRINGP (XBUFFER (w
->buffer
)->name
))
10942 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10947 #endif /* GLYPH_DEBUG */
10950 /* Value is non-zero if all changes in window W, which displays
10951 current_buffer, are in the text between START and END. START is a
10952 buffer position, END is given as a distance from Z. Used in
10953 redisplay_internal for display optimization. */
10956 text_outside_line_unchanged_p (w
, start
, end
)
10960 int unchanged_p
= 1;
10962 /* If text or overlays have changed, see where. */
10963 if (XFASTINT (w
->last_modified
) < MODIFF
10964 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10966 /* Gap in the line? */
10967 if (GPT
< start
|| Z
- GPT
< end
)
10970 /* Changes start in front of the line, or end after it? */
10972 && (BEG_UNCHANGED
< start
- 1
10973 || END_UNCHANGED
< end
))
10976 /* If selective display, can't optimize if changes start at the
10977 beginning of the line. */
10979 && INTEGERP (current_buffer
->selective_display
)
10980 && XINT (current_buffer
->selective_display
) > 0
10981 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10984 /* If there are overlays at the start or end of the line, these
10985 may have overlay strings with newlines in them. A change at
10986 START, for instance, may actually concern the display of such
10987 overlay strings as well, and they are displayed on different
10988 lines. So, quickly rule out this case. (For the future, it
10989 might be desirable to implement something more telling than
10990 just BEG/END_UNCHANGED.) */
10993 if (BEG
+ BEG_UNCHANGED
== start
10994 && overlay_touches_p (start
))
10996 if (END_UNCHANGED
== end
10997 && overlay_touches_p (Z
- end
))
11002 return unchanged_p
;
11006 /* Do a frame update, taking possible shortcuts into account. This is
11007 the main external entry point for redisplay.
11009 If the last redisplay displayed an echo area message and that message
11010 is no longer requested, we clear the echo area or bring back the
11011 mini-buffer if that is in use. */
11016 redisplay_internal (0);
11021 overlay_arrow_string_or_property (var
)
11026 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11029 return Voverlay_arrow_string
;
11032 /* Return 1 if there are any overlay-arrows in current_buffer. */
11034 overlay_arrow_in_current_buffer_p ()
11038 for (vlist
= Voverlay_arrow_variable_list
;
11040 vlist
= XCDR (vlist
))
11042 Lisp_Object var
= XCAR (vlist
);
11045 if (!SYMBOLP (var
))
11047 val
= find_symbol_value (var
);
11049 && current_buffer
== XMARKER (val
)->buffer
)
11056 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11060 overlay_arrows_changed_p ()
11064 for (vlist
= Voverlay_arrow_variable_list
;
11066 vlist
= XCDR (vlist
))
11068 Lisp_Object var
= XCAR (vlist
);
11069 Lisp_Object val
, pstr
;
11071 if (!SYMBOLP (var
))
11073 val
= find_symbol_value (var
);
11074 if (!MARKERP (val
))
11076 if (! EQ (COERCE_MARKER (val
),
11077 Fget (var
, Qlast_arrow_position
))
11078 || ! (pstr
= overlay_arrow_string_or_property (var
),
11079 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11085 /* Mark overlay arrows to be updated on next redisplay. */
11088 update_overlay_arrows (up_to_date
)
11093 for (vlist
= Voverlay_arrow_variable_list
;
11095 vlist
= XCDR (vlist
))
11097 Lisp_Object var
= XCAR (vlist
);
11099 if (!SYMBOLP (var
))
11102 if (up_to_date
> 0)
11104 Lisp_Object val
= find_symbol_value (var
);
11105 Fput (var
, Qlast_arrow_position
,
11106 COERCE_MARKER (val
));
11107 Fput (var
, Qlast_arrow_string
,
11108 overlay_arrow_string_or_property (var
));
11110 else if (up_to_date
< 0
11111 || !NILP (Fget (var
, Qlast_arrow_position
)))
11113 Fput (var
, Qlast_arrow_position
, Qt
);
11114 Fput (var
, Qlast_arrow_string
, Qt
);
11120 /* Return overlay arrow string to display at row.
11121 Return integer (bitmap number) for arrow bitmap in left fringe.
11122 Return nil if no overlay arrow. */
11125 overlay_arrow_at_row (it
, row
)
11127 struct glyph_row
*row
;
11131 for (vlist
= Voverlay_arrow_variable_list
;
11133 vlist
= XCDR (vlist
))
11135 Lisp_Object var
= XCAR (vlist
);
11138 if (!SYMBOLP (var
))
11141 val
= find_symbol_value (var
);
11144 && current_buffer
== XMARKER (val
)->buffer
11145 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11147 if (FRAME_WINDOW_P (it
->f
)
11148 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11150 #ifdef HAVE_WINDOW_SYSTEM
11151 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11154 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11155 return make_number (fringe_bitmap
);
11158 return make_number (-1); /* Use default arrow bitmap */
11160 return overlay_arrow_string_or_property (var
);
11167 /* Return 1 if point moved out of or into a composition. Otherwise
11168 return 0. PREV_BUF and PREV_PT are the last point buffer and
11169 position. BUF and PT are the current point buffer and position. */
11172 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11173 struct buffer
*prev_buf
, *buf
;
11176 EMACS_INT start
, end
;
11178 Lisp_Object buffer
;
11180 XSETBUFFER (buffer
, buf
);
11181 /* Check a composition at the last point if point moved within the
11183 if (prev_buf
== buf
)
11186 /* Point didn't move. */
11189 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11190 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11191 && COMPOSITION_VALID_P (start
, end
, prop
)
11192 && start
< prev_pt
&& end
> prev_pt
)
11193 /* The last point was within the composition. Return 1 iff
11194 point moved out of the composition. */
11195 return (pt
<= start
|| pt
>= end
);
11198 /* Check a composition at the current point. */
11199 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11200 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11201 && COMPOSITION_VALID_P (start
, end
, prop
)
11202 && start
< pt
&& end
> pt
);
11206 /* Reconsider the setting of B->clip_changed which is displayed
11210 reconsider_clip_changes (w
, b
)
11214 if (b
->clip_changed
11215 && !NILP (w
->window_end_valid
)
11216 && w
->current_matrix
->buffer
== b
11217 && w
->current_matrix
->zv
== BUF_ZV (b
)
11218 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11219 b
->clip_changed
= 0;
11221 /* If display wasn't paused, and W is not a tool bar window, see if
11222 point has been moved into or out of a composition. In that case,
11223 we set b->clip_changed to 1 to force updating the screen. If
11224 b->clip_changed has already been set to 1, we can skip this
11226 if (!b
->clip_changed
11227 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11231 if (w
== XWINDOW (selected_window
))
11232 pt
= BUF_PT (current_buffer
);
11234 pt
= marker_position (w
->pointm
);
11236 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11237 || pt
!= XINT (w
->last_point
))
11238 && check_point_in_composition (w
->current_matrix
->buffer
,
11239 XINT (w
->last_point
),
11240 XBUFFER (w
->buffer
), pt
))
11241 b
->clip_changed
= 1;
11246 /* Select FRAME to forward the values of frame-local variables into C
11247 variables so that the redisplay routines can access those values
11251 select_frame_for_redisplay (frame
)
11254 Lisp_Object tail
, symbol
, val
;
11255 Lisp_Object old
= selected_frame
;
11256 struct Lisp_Symbol
*sym
;
11258 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11260 selected_frame
= frame
;
11264 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11265 if (CONSP (XCAR (tail
))
11266 && (symbol
= XCAR (XCAR (tail
)),
11268 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11270 (BUFFER_LOCAL_VALUEP (val
)))
11271 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11272 /* Use find_symbol_value rather than Fsymbol_value
11273 to avoid an error if it is void. */
11274 find_symbol_value (symbol
);
11275 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11279 #define STOP_POLLING \
11280 do { if (! polling_stopped_here) stop_polling (); \
11281 polling_stopped_here = 1; } while (0)
11283 #define RESUME_POLLING \
11284 do { if (polling_stopped_here) start_polling (); \
11285 polling_stopped_here = 0; } while (0)
11288 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11289 response to any user action; therefore, we should preserve the echo
11290 area. (Actually, our caller does that job.) Perhaps in the future
11291 avoid recentering windows if it is not necessary; currently that
11292 causes some problems. */
11295 redisplay_internal (preserve_echo_area
)
11296 int preserve_echo_area
;
11298 struct window
*w
= XWINDOW (selected_window
);
11301 int must_finish
= 0;
11302 struct text_pos tlbufpos
, tlendpos
;
11303 int number_of_visible_frames
;
11306 int polling_stopped_here
= 0;
11307 Lisp_Object old_frame
= selected_frame
;
11309 /* Non-zero means redisplay has to consider all windows on all
11310 frames. Zero means, only selected_window is considered. */
11311 int consider_all_windows_p
;
11313 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11315 /* No redisplay if running in batch mode or frame is not yet fully
11316 initialized, or redisplay is explicitly turned off by setting
11317 Vinhibit_redisplay. */
11318 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11319 || !NILP (Vinhibit_redisplay
))
11322 /* Don't examine these until after testing Vinhibit_redisplay.
11323 When Emacs is shutting down, perhaps because its connection to
11324 X has dropped, we should not look at them at all. */
11325 f
= XFRAME (w
->frame
);
11326 sf
= SELECTED_FRAME ();
11328 if (!f
->glyphs_initialized_p
)
11331 /* The flag redisplay_performed_directly_p is set by
11332 direct_output_for_insert when it already did the whole screen
11333 update necessary. */
11334 if (redisplay_performed_directly_p
)
11336 redisplay_performed_directly_p
= 0;
11337 if (!hscroll_windows (selected_window
))
11341 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11342 if (popup_activated ())
11346 /* I don't think this happens but let's be paranoid. */
11347 if (redisplaying_p
)
11350 /* Record a function that resets redisplaying_p to its old value
11351 when we leave this function. */
11352 count
= SPECPDL_INDEX ();
11353 record_unwind_protect (unwind_redisplay
,
11354 Fcons (make_number (redisplaying_p
), selected_frame
));
11356 specbind (Qinhibit_free_realized_faces
, Qnil
);
11359 Lisp_Object tail
, frame
;
11361 FOR_EACH_FRAME (tail
, frame
)
11363 struct frame
*f
= XFRAME (frame
);
11364 f
->already_hscrolled_p
= 0;
11369 if (!EQ (old_frame
, selected_frame
)
11370 && FRAME_LIVE_P (XFRAME (old_frame
)))
11371 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11372 selected_frame and selected_window to be temporarily out-of-sync so
11373 when we come back here via `goto retry', we need to resync because we
11374 may need to run Elisp code (via prepare_menu_bars). */
11375 select_frame_for_redisplay (old_frame
);
11378 reconsider_clip_changes (w
, current_buffer
);
11379 last_escape_glyph_frame
= NULL
;
11380 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11382 /* If new fonts have been loaded that make a glyph matrix adjustment
11383 necessary, do it. */
11384 if (fonts_changed_p
)
11386 adjust_glyphs (NULL
);
11387 ++windows_or_buffers_changed
;
11388 fonts_changed_p
= 0;
11391 /* If face_change_count is non-zero, init_iterator will free all
11392 realized faces, which includes the faces referenced from current
11393 matrices. So, we can't reuse current matrices in this case. */
11394 if (face_change_count
)
11395 ++windows_or_buffers_changed
;
11397 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11398 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11400 /* Since frames on a single ASCII terminal share the same
11401 display area, displaying a different frame means redisplay
11402 the whole thing. */
11403 windows_or_buffers_changed
++;
11404 SET_FRAME_GARBAGED (sf
);
11406 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11408 FRAME_TTY (sf
)->previous_frame
= sf
;
11411 /* Set the visible flags for all frames. Do this before checking
11412 for resized or garbaged frames; they want to know if their frames
11413 are visible. See the comment in frame.h for
11414 FRAME_SAMPLE_VISIBILITY. */
11416 Lisp_Object tail
, frame
;
11418 number_of_visible_frames
= 0;
11420 FOR_EACH_FRAME (tail
, frame
)
11422 struct frame
*f
= XFRAME (frame
);
11424 FRAME_SAMPLE_VISIBILITY (f
);
11425 if (FRAME_VISIBLE_P (f
))
11426 ++number_of_visible_frames
;
11427 clear_desired_matrices (f
);
11431 /* Notice any pending interrupt request to change frame size. */
11432 do_pending_window_change (1);
11434 /* Clear frames marked as garbaged. */
11435 if (frame_garbaged
)
11436 clear_garbaged_frames ();
11438 /* Build menubar and tool-bar items. */
11439 if (NILP (Vmemory_full
))
11440 prepare_menu_bars ();
11442 if (windows_or_buffers_changed
)
11443 update_mode_lines
++;
11445 /* Detect case that we need to write or remove a star in the mode line. */
11446 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11448 w
->update_mode_line
= Qt
;
11449 if (buffer_shared
> 1)
11450 update_mode_lines
++;
11453 /* Avoid invocation of point motion hooks by `current_column' below. */
11454 count1
= SPECPDL_INDEX ();
11455 specbind (Qinhibit_point_motion_hooks
, Qt
);
11457 /* If %c is in the mode line, update it if needed. */
11458 if (!NILP (w
->column_number_displayed
)
11459 /* This alternative quickly identifies a common case
11460 where no change is needed. */
11461 && !(PT
== XFASTINT (w
->last_point
)
11462 && XFASTINT (w
->last_modified
) >= MODIFF
11463 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11464 && (XFASTINT (w
->column_number_displayed
)
11465 != (int) current_column ())) /* iftc */
11466 w
->update_mode_line
= Qt
;
11468 unbind_to (count1
, Qnil
);
11470 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11472 /* The variable buffer_shared is set in redisplay_window and
11473 indicates that we redisplay a buffer in different windows. See
11475 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11476 || cursor_type_changed
);
11478 /* If specs for an arrow have changed, do thorough redisplay
11479 to ensure we remove any arrow that should no longer exist. */
11480 if (overlay_arrows_changed_p ())
11481 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11483 /* Normally the message* functions will have already displayed and
11484 updated the echo area, but the frame may have been trashed, or
11485 the update may have been preempted, so display the echo area
11486 again here. Checking message_cleared_p captures the case that
11487 the echo area should be cleared. */
11488 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11489 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11490 || (message_cleared_p
11491 && minibuf_level
== 0
11492 /* If the mini-window is currently selected, this means the
11493 echo-area doesn't show through. */
11494 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11496 int window_height_changed_p
= echo_area_display (0);
11499 /* If we don't display the current message, don't clear the
11500 message_cleared_p flag, because, if we did, we wouldn't clear
11501 the echo area in the next redisplay which doesn't preserve
11503 if (!display_last_displayed_message_p
)
11504 message_cleared_p
= 0;
11506 if (fonts_changed_p
)
11508 else if (window_height_changed_p
)
11510 consider_all_windows_p
= 1;
11511 ++update_mode_lines
;
11512 ++windows_or_buffers_changed
;
11514 /* If window configuration was changed, frames may have been
11515 marked garbaged. Clear them or we will experience
11516 surprises wrt scrolling. */
11517 if (frame_garbaged
)
11518 clear_garbaged_frames ();
11521 else if (EQ (selected_window
, minibuf_window
)
11522 && (current_buffer
->clip_changed
11523 || XFASTINT (w
->last_modified
) < MODIFF
11524 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11525 && resize_mini_window (w
, 0))
11527 /* Resized active mini-window to fit the size of what it is
11528 showing if its contents might have changed. */
11530 /* FIXME: this causes all frames to be updated, which seems unnecessary
11531 since only the current frame needs to be considered. This function needs
11532 to be rewritten with two variables, consider_all_windows and
11533 consider_all_frames. */
11534 consider_all_windows_p
= 1;
11535 ++windows_or_buffers_changed
;
11536 ++update_mode_lines
;
11538 /* If window configuration was changed, frames may have been
11539 marked garbaged. Clear them or we will experience
11540 surprises wrt scrolling. */
11541 if (frame_garbaged
)
11542 clear_garbaged_frames ();
11546 /* If showing the region, and mark has changed, we must redisplay
11547 the whole window. The assignment to this_line_start_pos prevents
11548 the optimization directly below this if-statement. */
11549 if (((!NILP (Vtransient_mark_mode
)
11550 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11551 != !NILP (w
->region_showing
))
11552 || (!NILP (w
->region_showing
)
11553 && !EQ (w
->region_showing
,
11554 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11555 CHARPOS (this_line_start_pos
) = 0;
11557 /* Optimize the case that only the line containing the cursor in the
11558 selected window has changed. Variables starting with this_ are
11559 set in display_line and record information about the line
11560 containing the cursor. */
11561 tlbufpos
= this_line_start_pos
;
11562 tlendpos
= this_line_end_pos
;
11563 if (!consider_all_windows_p
11564 && CHARPOS (tlbufpos
) > 0
11565 && NILP (w
->update_mode_line
)
11566 && !current_buffer
->clip_changed
11567 && !current_buffer
->prevent_redisplay_optimizations_p
11568 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11569 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11570 /* Make sure recorded data applies to current buffer, etc. */
11571 && this_line_buffer
== current_buffer
11572 && current_buffer
== XBUFFER (w
->buffer
)
11573 && NILP (w
->force_start
)
11574 && NILP (w
->optional_new_start
)
11575 /* Point must be on the line that we have info recorded about. */
11576 && PT
>= CHARPOS (tlbufpos
)
11577 && PT
<= Z
- CHARPOS (tlendpos
)
11578 /* All text outside that line, including its final newline,
11579 must be unchanged */
11580 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11581 CHARPOS (tlendpos
)))
11583 if (CHARPOS (tlbufpos
) > BEGV
11584 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11585 && (CHARPOS (tlbufpos
) == ZV
11586 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11587 /* Former continuation line has disappeared by becoming empty */
11589 else if (XFASTINT (w
->last_modified
) < MODIFF
11590 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11591 || MINI_WINDOW_P (w
))
11593 /* We have to handle the case of continuation around a
11594 wide-column character (See the comment in indent.c around
11597 For instance, in the following case:
11599 -------- Insert --------
11600 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11601 J_I_ ==> J_I_ `^^' are cursors.
11605 As we have to redraw the line above, we should goto cancel. */
11608 int line_height_before
= this_line_pixel_height
;
11610 /* Note that start_display will handle the case that the
11611 line starting at tlbufpos is a continuation lines. */
11612 start_display (&it
, w
, tlbufpos
);
11614 /* Implementation note: It this still necessary? */
11615 if (it
.current_x
!= this_line_start_x
)
11618 TRACE ((stderr
, "trying display optimization 1\n"));
11619 w
->cursor
.vpos
= -1;
11620 overlay_arrow_seen
= 0;
11621 it
.vpos
= this_line_vpos
;
11622 it
.current_y
= this_line_y
;
11623 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11624 display_line (&it
);
11626 /* If line contains point, is not continued,
11627 and ends at same distance from eob as before, we win */
11628 if (w
->cursor
.vpos
>= 0
11629 /* Line is not continued, otherwise this_line_start_pos
11630 would have been set to 0 in display_line. */
11631 && CHARPOS (this_line_start_pos
)
11632 /* Line ends as before. */
11633 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11634 /* Line has same height as before. Otherwise other lines
11635 would have to be shifted up or down. */
11636 && this_line_pixel_height
== line_height_before
)
11638 /* If this is not the window's last line, we must adjust
11639 the charstarts of the lines below. */
11640 if (it
.current_y
< it
.last_visible_y
)
11642 struct glyph_row
*row
11643 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11644 int delta
, delta_bytes
;
11646 if (Z
- CHARPOS (tlendpos
) == ZV
)
11648 /* This line ends at end of (accessible part of)
11649 buffer. There is no newline to count. */
11651 - CHARPOS (tlendpos
)
11652 - MATRIX_ROW_START_CHARPOS (row
));
11653 delta_bytes
= (Z_BYTE
11654 - BYTEPOS (tlendpos
)
11655 - MATRIX_ROW_START_BYTEPOS (row
));
11659 /* This line ends in a newline. Must take
11660 account of the newline and the rest of the
11661 text that follows. */
11663 - CHARPOS (tlendpos
)
11664 - MATRIX_ROW_START_CHARPOS (row
));
11665 delta_bytes
= (Z_BYTE
11666 - BYTEPOS (tlendpos
)
11667 - MATRIX_ROW_START_BYTEPOS (row
));
11670 increment_matrix_positions (w
->current_matrix
,
11671 this_line_vpos
+ 1,
11672 w
->current_matrix
->nrows
,
11673 delta
, delta_bytes
);
11676 /* If this row displays text now but previously didn't,
11677 or vice versa, w->window_end_vpos may have to be
11679 if ((it
.glyph_row
- 1)->displays_text_p
)
11681 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11682 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11684 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11685 && this_line_vpos
> 0)
11686 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11687 w
->window_end_valid
= Qnil
;
11689 /* Update hint: No need to try to scroll in update_window. */
11690 w
->desired_matrix
->no_scrolling_p
= 1;
11693 *w
->desired_matrix
->method
= 0;
11694 debug_method_add (w
, "optimization 1");
11696 #ifdef HAVE_WINDOW_SYSTEM
11697 update_window_fringes (w
, 0);
11704 else if (/* Cursor position hasn't changed. */
11705 PT
== XFASTINT (w
->last_point
)
11706 /* Make sure the cursor was last displayed
11707 in this window. Otherwise we have to reposition it. */
11708 && 0 <= w
->cursor
.vpos
11709 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11713 do_pending_window_change (1);
11715 /* We used to always goto end_of_redisplay here, but this
11716 isn't enough if we have a blinking cursor. */
11717 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11718 goto end_of_redisplay
;
11722 /* If highlighting the region, or if the cursor is in the echo area,
11723 then we can't just move the cursor. */
11724 else if (! (!NILP (Vtransient_mark_mode
)
11725 && !NILP (current_buffer
->mark_active
))
11726 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11727 || highlight_nonselected_windows
)
11728 && NILP (w
->region_showing
)
11729 && NILP (Vshow_trailing_whitespace
)
11730 && !cursor_in_echo_area
)
11733 struct glyph_row
*row
;
11735 /* Skip from tlbufpos to PT and see where it is. Note that
11736 PT may be in invisible text. If so, we will end at the
11737 next visible position. */
11738 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11739 NULL
, DEFAULT_FACE_ID
);
11740 it
.current_x
= this_line_start_x
;
11741 it
.current_y
= this_line_y
;
11742 it
.vpos
= this_line_vpos
;
11744 /* The call to move_it_to stops in front of PT, but
11745 moves over before-strings. */
11746 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11748 if (it
.vpos
== this_line_vpos
11749 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11752 xassert (this_line_vpos
== it
.vpos
);
11753 xassert (this_line_y
== it
.current_y
);
11754 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11756 *w
->desired_matrix
->method
= 0;
11757 debug_method_add (w
, "optimization 3");
11766 /* Text changed drastically or point moved off of line. */
11767 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11770 CHARPOS (this_line_start_pos
) = 0;
11771 consider_all_windows_p
|= buffer_shared
> 1;
11772 ++clear_face_cache_count
;
11773 #ifdef HAVE_WINDOW_SYSTEM
11774 ++clear_image_cache_count
;
11777 /* Build desired matrices, and update the display. If
11778 consider_all_windows_p is non-zero, do it for all windows on all
11779 frames. Otherwise do it for selected_window, only. */
11781 if (consider_all_windows_p
)
11783 Lisp_Object tail
, frame
;
11785 FOR_EACH_FRAME (tail
, frame
)
11786 XFRAME (frame
)->updated_p
= 0;
11788 /* Recompute # windows showing selected buffer. This will be
11789 incremented each time such a window is displayed. */
11792 FOR_EACH_FRAME (tail
, frame
)
11794 struct frame
*f
= XFRAME (frame
);
11796 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11798 if (! EQ (frame
, selected_frame
))
11799 /* Select the frame, for the sake of frame-local
11801 select_frame_for_redisplay (frame
);
11803 /* Mark all the scroll bars to be removed; we'll redeem
11804 the ones we want when we redisplay their windows. */
11805 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11806 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11808 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11809 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11811 /* The X error handler may have deleted that frame. */
11812 if (!FRAME_LIVE_P (f
))
11815 /* Any scroll bars which redisplay_windows should have
11816 nuked should now go away. */
11817 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11818 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11820 /* If fonts changed, display again. */
11821 /* ??? rms: I suspect it is a mistake to jump all the way
11822 back to retry here. It should just retry this frame. */
11823 if (fonts_changed_p
)
11826 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11828 /* See if we have to hscroll. */
11829 if (!f
->already_hscrolled_p
)
11831 f
->already_hscrolled_p
= 1;
11832 if (hscroll_windows (f
->root_window
))
11836 /* Prevent various kinds of signals during display
11837 update. stdio is not robust about handling
11838 signals, which can cause an apparent I/O
11840 if (interrupt_input
)
11841 unrequest_sigio ();
11844 /* Update the display. */
11845 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11846 pause
|= update_frame (f
, 0, 0);
11852 if (!EQ (old_frame
, selected_frame
)
11853 && FRAME_LIVE_P (XFRAME (old_frame
)))
11854 /* We played a bit fast-and-loose above and allowed selected_frame
11855 and selected_window to be temporarily out-of-sync but let's make
11856 sure this stays contained. */
11857 select_frame_for_redisplay (old_frame
);
11858 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11862 /* Do the mark_window_display_accurate after all windows have
11863 been redisplayed because this call resets flags in buffers
11864 which are needed for proper redisplay. */
11865 FOR_EACH_FRAME (tail
, frame
)
11867 struct frame
*f
= XFRAME (frame
);
11870 mark_window_display_accurate (f
->root_window
, 1);
11871 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11872 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11877 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11879 Lisp_Object mini_window
;
11880 struct frame
*mini_frame
;
11882 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11883 /* Use list_of_error, not Qerror, so that
11884 we catch only errors and don't run the debugger. */
11885 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11887 redisplay_window_error
);
11889 /* Compare desired and current matrices, perform output. */
11892 /* If fonts changed, display again. */
11893 if (fonts_changed_p
)
11896 /* Prevent various kinds of signals during display update.
11897 stdio is not robust about handling signals,
11898 which can cause an apparent I/O error. */
11899 if (interrupt_input
)
11900 unrequest_sigio ();
11903 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11905 if (hscroll_windows (selected_window
))
11908 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11909 pause
= update_frame (sf
, 0, 0);
11912 /* We may have called echo_area_display at the top of this
11913 function. If the echo area is on another frame, that may
11914 have put text on a frame other than the selected one, so the
11915 above call to update_frame would not have caught it. Catch
11917 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11918 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11920 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11922 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11923 pause
|= update_frame (mini_frame
, 0, 0);
11924 if (!pause
&& hscroll_windows (mini_window
))
11929 /* If display was paused because of pending input, make sure we do a
11930 thorough update the next time. */
11933 /* Prevent the optimization at the beginning of
11934 redisplay_internal that tries a single-line update of the
11935 line containing the cursor in the selected window. */
11936 CHARPOS (this_line_start_pos
) = 0;
11938 /* Let the overlay arrow be updated the next time. */
11939 update_overlay_arrows (0);
11941 /* If we pause after scrolling, some rows in the current
11942 matrices of some windows are not valid. */
11943 if (!WINDOW_FULL_WIDTH_P (w
)
11944 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11945 update_mode_lines
= 1;
11949 if (!consider_all_windows_p
)
11951 /* This has already been done above if
11952 consider_all_windows_p is set. */
11953 mark_window_display_accurate_1 (w
, 1);
11955 /* Say overlay arrows are up to date. */
11956 update_overlay_arrows (1);
11958 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11959 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11962 update_mode_lines
= 0;
11963 windows_or_buffers_changed
= 0;
11964 cursor_type_changed
= 0;
11967 /* Start SIGIO interrupts coming again. Having them off during the
11968 code above makes it less likely one will discard output, but not
11969 impossible, since there might be stuff in the system buffer here.
11970 But it is much hairier to try to do anything about that. */
11971 if (interrupt_input
)
11975 /* If a frame has become visible which was not before, redisplay
11976 again, so that we display it. Expose events for such a frame
11977 (which it gets when becoming visible) don't call the parts of
11978 redisplay constructing glyphs, so simply exposing a frame won't
11979 display anything in this case. So, we have to display these
11980 frames here explicitly. */
11983 Lisp_Object tail
, frame
;
11986 FOR_EACH_FRAME (tail
, frame
)
11988 int this_is_visible
= 0;
11990 if (XFRAME (frame
)->visible
)
11991 this_is_visible
= 1;
11992 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11993 if (XFRAME (frame
)->visible
)
11994 this_is_visible
= 1;
11996 if (this_is_visible
)
12000 if (new_count
!= number_of_visible_frames
)
12001 windows_or_buffers_changed
++;
12004 /* Change frame size now if a change is pending. */
12005 do_pending_window_change (1);
12007 /* If we just did a pending size change, or have additional
12008 visible frames, redisplay again. */
12009 if (windows_or_buffers_changed
&& !pause
)
12012 /* Clear the face cache eventually. */
12013 if (consider_all_windows_p
)
12015 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12017 clear_face_cache (0);
12018 clear_face_cache_count
= 0;
12020 #ifdef HAVE_WINDOW_SYSTEM
12021 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12023 clear_image_caches (Qnil
);
12024 clear_image_cache_count
= 0;
12026 #endif /* HAVE_WINDOW_SYSTEM */
12030 unbind_to (count
, Qnil
);
12035 /* Redisplay, but leave alone any recent echo area message unless
12036 another message has been requested in its place.
12038 This is useful in situations where you need to redisplay but no
12039 user action has occurred, making it inappropriate for the message
12040 area to be cleared. See tracking_off and
12041 wait_reading_process_output for examples of these situations.
12043 FROM_WHERE is an integer saying from where this function was
12044 called. This is useful for debugging. */
12047 redisplay_preserve_echo_area (from_where
)
12050 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12052 if (!NILP (echo_area_buffer
[1]))
12054 /* We have a previously displayed message, but no current
12055 message. Redisplay the previous message. */
12056 display_last_displayed_message_p
= 1;
12057 redisplay_internal (1);
12058 display_last_displayed_message_p
= 0;
12061 redisplay_internal (1);
12063 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12064 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12065 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12069 /* Function registered with record_unwind_protect in
12070 redisplay_internal. Reset redisplaying_p to the value it had
12071 before redisplay_internal was called, and clear
12072 prevent_freeing_realized_faces_p. It also selects the previously
12073 selected frame, unless it has been deleted (by an X connection
12074 failure during redisplay, for example). */
12077 unwind_redisplay (val
)
12080 Lisp_Object old_redisplaying_p
, old_frame
;
12082 old_redisplaying_p
= XCAR (val
);
12083 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12084 old_frame
= XCDR (val
);
12085 if (! EQ (old_frame
, selected_frame
)
12086 && FRAME_LIVE_P (XFRAME (old_frame
)))
12087 select_frame_for_redisplay (old_frame
);
12092 /* Mark the display of window W as accurate or inaccurate. If
12093 ACCURATE_P is non-zero mark display of W as accurate. If
12094 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12095 redisplay_internal is called. */
12098 mark_window_display_accurate_1 (w
, accurate_p
)
12102 if (BUFFERP (w
->buffer
))
12104 struct buffer
*b
= XBUFFER (w
->buffer
);
12107 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12108 w
->last_overlay_modified
12109 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12111 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12115 b
->clip_changed
= 0;
12116 b
->prevent_redisplay_optimizations_p
= 0;
12118 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12119 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12120 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12121 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12123 w
->current_matrix
->buffer
= b
;
12124 w
->current_matrix
->begv
= BUF_BEGV (b
);
12125 w
->current_matrix
->zv
= BUF_ZV (b
);
12127 w
->last_cursor
= w
->cursor
;
12128 w
->last_cursor_off_p
= w
->cursor_off_p
;
12130 if (w
== XWINDOW (selected_window
))
12131 w
->last_point
= make_number (BUF_PT (b
));
12133 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12139 w
->window_end_valid
= w
->buffer
;
12140 w
->update_mode_line
= Qnil
;
12145 /* Mark the display of windows in the window tree rooted at WINDOW as
12146 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12147 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12148 be redisplayed the next time redisplay_internal is called. */
12151 mark_window_display_accurate (window
, accurate_p
)
12152 Lisp_Object window
;
12157 for (; !NILP (window
); window
= w
->next
)
12159 w
= XWINDOW (window
);
12160 mark_window_display_accurate_1 (w
, accurate_p
);
12162 if (!NILP (w
->vchild
))
12163 mark_window_display_accurate (w
->vchild
, accurate_p
);
12164 if (!NILP (w
->hchild
))
12165 mark_window_display_accurate (w
->hchild
, accurate_p
);
12170 update_overlay_arrows (1);
12174 /* Force a thorough redisplay the next time by setting
12175 last_arrow_position and last_arrow_string to t, which is
12176 unequal to any useful value of Voverlay_arrow_... */
12177 update_overlay_arrows (-1);
12182 /* Return value in display table DP (Lisp_Char_Table *) for character
12183 C. Since a display table doesn't have any parent, we don't have to
12184 follow parent. Do not call this function directly but use the
12185 macro DISP_CHAR_VECTOR. */
12188 disp_char_vector (dp
, c
)
12189 struct Lisp_Char_Table
*dp
;
12194 if (ASCII_CHAR_P (c
))
12197 if (SUB_CHAR_TABLE_P (val
))
12198 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12204 XSETCHAR_TABLE (table
, dp
);
12205 val
= char_table_ref (table
, c
);
12214 /***********************************************************************
12216 ***********************************************************************/
12218 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12221 redisplay_windows (window
)
12222 Lisp_Object window
;
12224 while (!NILP (window
))
12226 struct window
*w
= XWINDOW (window
);
12228 if (!NILP (w
->hchild
))
12229 redisplay_windows (w
->hchild
);
12230 else if (!NILP (w
->vchild
))
12231 redisplay_windows (w
->vchild
);
12232 else if (!NILP (w
->buffer
))
12234 displayed_buffer
= XBUFFER (w
->buffer
);
12235 /* Use list_of_error, not Qerror, so that
12236 we catch only errors and don't run the debugger. */
12237 internal_condition_case_1 (redisplay_window_0
, window
,
12239 redisplay_window_error
);
12247 redisplay_window_error ()
12249 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12254 redisplay_window_0 (window
)
12255 Lisp_Object window
;
12257 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12258 redisplay_window (window
, 0);
12263 redisplay_window_1 (window
)
12264 Lisp_Object window
;
12266 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12267 redisplay_window (window
, 1);
12272 /* Increment GLYPH until it reaches END or CONDITION fails while
12273 adding (GLYPH)->pixel_width to X. */
12275 #define SKIP_GLYPHS(glyph, end, x, condition) \
12278 (x) += (glyph)->pixel_width; \
12281 while ((glyph) < (end) && (condition))
12284 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12285 DELTA is the number of bytes by which positions recorded in ROW
12286 differ from current buffer positions.
12288 Return 0 if cursor is not on this row. 1 otherwise. */
12291 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12293 struct glyph_row
*row
;
12294 struct glyph_matrix
*matrix
;
12295 int delta
, delta_bytes
, dy
, dvpos
;
12297 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12298 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12299 struct glyph
*cursor
= NULL
;
12300 /* The first glyph that starts a sequence of glyphs from string. */
12301 struct glyph
*string_start
;
12302 /* The X coordinate of string_start. */
12303 int string_start_x
;
12304 /* The last known character position. */
12305 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12306 /* The last known character position before string_start. */
12307 int string_before_pos
;
12310 int cursor_from_overlay_pos
= 0;
12311 int pt_old
= PT
- delta
;
12313 /* Skip over glyphs not having an object at the start of the row.
12314 These are special glyphs like truncation marks on terminal
12316 if (row
->displays_text_p
)
12318 && INTEGERP (glyph
->object
)
12319 && glyph
->charpos
< 0)
12321 x
+= glyph
->pixel_width
;
12325 string_start
= NULL
;
12327 && !INTEGERP (glyph
->object
)
12328 && (!BUFFERP (glyph
->object
)
12329 || (last_pos
= glyph
->charpos
) < pt_old
12330 || glyph
->avoid_cursor_p
))
12332 if (! STRINGP (glyph
->object
))
12334 string_start
= NULL
;
12335 x
+= glyph
->pixel_width
;
12337 if (cursor_from_overlay_pos
12338 && last_pos
>= cursor_from_overlay_pos
)
12340 cursor_from_overlay_pos
= 0;
12346 if (string_start
== NULL
)
12348 string_before_pos
= last_pos
;
12349 string_start
= glyph
;
12350 string_start_x
= x
;
12352 /* Skip all glyphs from string. */
12357 if ((cursor
== NULL
|| glyph
> cursor
)
12358 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12359 Qcursor
, (glyph
)->object
),
12361 && (pos
= string_buffer_position (w
, glyph
->object
,
12362 string_before_pos
),
12363 (pos
== 0 /* From overlay */
12364 || pos
== pt_old
)))
12366 /* Estimate overlay buffer position from the buffer
12367 positions of the glyphs before and after the overlay.
12368 Add 1 to last_pos so that if point corresponds to the
12369 glyph right after the overlay, we still use a 'cursor'
12370 property found in that overlay. */
12371 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12372 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12376 x
+= glyph
->pixel_width
;
12379 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12383 if (cursor
!= NULL
)
12388 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12390 /* Scan back over the ellipsis glyphs, decrementing positions. */
12391 while (glyph
> row
->glyphs
[TEXT_AREA
]
12392 && (glyph
- 1)->charpos
== last_pos
)
12393 glyph
--, x
-= glyph
->pixel_width
;
12394 /* That loop always goes one position too far,
12395 including the glyph before the ellipsis.
12396 So scan forward over that one. */
12397 x
+= glyph
->pixel_width
;
12400 else if (string_start
12401 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12403 /* We may have skipped over point because the previous glyphs
12404 are from string. As there's no easy way to know the
12405 character position of the current glyph, find the correct
12406 glyph on point by scanning from string_start again. */
12408 Lisp_Object string
;
12409 struct glyph
*stop
= glyph
;
12412 limit
= make_number (pt_old
+ 1);
12413 glyph
= string_start
;
12414 x
= string_start_x
;
12415 string
= glyph
->object
;
12416 pos
= string_buffer_position (w
, string
, string_before_pos
);
12417 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12418 because we always put cursor after overlay strings. */
12419 while (pos
== 0 && glyph
< stop
)
12421 string
= glyph
->object
;
12422 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12424 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12427 while (glyph
< stop
)
12429 pos
= XINT (Fnext_single_char_property_change
12430 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12433 /* Skip glyphs from the same string. */
12434 string
= glyph
->object
;
12435 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12436 /* Skip glyphs from an overlay. */
12437 while (glyph
< stop
12438 && ! string_buffer_position (w
, glyph
->object
, pos
))
12440 string
= glyph
->object
;
12441 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12445 /* If we reached the end of the line, and end was from a string,
12446 cursor is not on this line. */
12447 if (glyph
== end
&& row
->continued_p
)
12451 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12453 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12454 w
->cursor
.y
= row
->y
+ dy
;
12456 if (w
== XWINDOW (selected_window
))
12458 if (!row
->continued_p
12459 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12462 this_line_buffer
= XBUFFER (w
->buffer
);
12464 CHARPOS (this_line_start_pos
)
12465 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12466 BYTEPOS (this_line_start_pos
)
12467 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12469 CHARPOS (this_line_end_pos
)
12470 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12471 BYTEPOS (this_line_end_pos
)
12472 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12474 this_line_y
= w
->cursor
.y
;
12475 this_line_pixel_height
= row
->height
;
12476 this_line_vpos
= w
->cursor
.vpos
;
12477 this_line_start_x
= row
->x
;
12480 CHARPOS (this_line_start_pos
) = 0;
12487 /* Run window scroll functions, if any, for WINDOW with new window
12488 start STARTP. Sets the window start of WINDOW to that position.
12490 We assume that the window's buffer is really current. */
12492 static INLINE
struct text_pos
12493 run_window_scroll_functions (window
, startp
)
12494 Lisp_Object window
;
12495 struct text_pos startp
;
12497 struct window
*w
= XWINDOW (window
);
12498 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12500 if (current_buffer
!= XBUFFER (w
->buffer
))
12503 if (!NILP (Vwindow_scroll_functions
))
12505 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12506 make_number (CHARPOS (startp
)));
12507 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12508 /* In case the hook functions switch buffers. */
12509 if (current_buffer
!= XBUFFER (w
->buffer
))
12510 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12517 /* Make sure the line containing the cursor is fully visible.
12518 A value of 1 means there is nothing to be done.
12519 (Either the line is fully visible, or it cannot be made so,
12520 or we cannot tell.)
12522 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12523 is higher than window.
12525 A value of 0 means the caller should do scrolling
12526 as if point had gone off the screen. */
12529 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12532 int current_matrix_p
;
12534 struct glyph_matrix
*matrix
;
12535 struct glyph_row
*row
;
12538 if (!make_cursor_line_fully_visible_p
)
12541 /* It's not always possible to find the cursor, e.g, when a window
12542 is full of overlay strings. Don't do anything in that case. */
12543 if (w
->cursor
.vpos
< 0)
12546 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12547 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12549 /* If the cursor row is not partially visible, there's nothing to do. */
12550 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12553 /* If the row the cursor is in is taller than the window's height,
12554 it's not clear what to do, so do nothing. */
12555 window_height
= window_box_height (w
);
12556 if (row
->height
>= window_height
)
12558 if (!force_p
|| MINI_WINDOW_P (w
)
12559 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12566 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12567 non-zero means only WINDOW is redisplayed in redisplay_internal.
12568 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12569 in redisplay_window to bring a partially visible line into view in
12570 the case that only the cursor has moved.
12572 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12573 last screen line's vertical height extends past the end of the screen.
12577 1 if scrolling succeeded
12579 0 if scrolling didn't find point.
12581 -1 if new fonts have been loaded so that we must interrupt
12582 redisplay, adjust glyph matrices, and try again. */
12588 SCROLLING_NEED_LARGER_MATRICES
12592 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12593 scroll_step
, temp_scroll_step
, last_line_misfit
)
12594 Lisp_Object window
;
12595 int just_this_one_p
;
12596 EMACS_INT scroll_conservatively
, scroll_step
;
12597 int temp_scroll_step
;
12598 int last_line_misfit
;
12600 struct window
*w
= XWINDOW (window
);
12601 struct frame
*f
= XFRAME (w
->frame
);
12602 struct text_pos pos
, startp
;
12604 int this_scroll_margin
, scroll_max
, rc
, height
;
12605 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12606 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12607 Lisp_Object aggressive
;
12608 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12611 debug_method_add (w
, "try_scrolling");
12614 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12616 /* Compute scroll margin height in pixels. We scroll when point is
12617 within this distance from the top or bottom of the window. */
12618 if (scroll_margin
> 0)
12619 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
12620 * FRAME_LINE_HEIGHT (f
);
12622 this_scroll_margin
= 0;
12624 /* Force scroll_conservatively to have a reasonable value, to avoid
12625 overflow while computing how much to scroll. Note that the user
12626 can supply scroll-conservatively equal to `most-positive-fixnum',
12627 which can be larger than INT_MAX. */
12628 if (scroll_conservatively
> scroll_limit
)
12630 scroll_conservatively
= scroll_limit
;
12631 scroll_max
= INT_MAX
;
12633 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12634 /* Compute how much we should try to scroll maximally to bring
12635 point into view. */
12636 scroll_max
= (max (scroll_step
,
12637 max (scroll_conservatively
, temp_scroll_step
))
12638 * FRAME_LINE_HEIGHT (f
));
12639 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12640 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12641 /* We're trying to scroll because of aggressive scrolling but no
12642 scroll_step is set. Choose an arbitrary one. */
12643 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12649 /* Decide whether to scroll down. */
12650 if (PT
> CHARPOS (startp
))
12652 int scroll_margin_y
;
12654 /* Compute the pixel ypos of the scroll margin, then move it to
12655 either that ypos or PT, whichever comes first. */
12656 start_display (&it
, w
, startp
);
12657 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12658 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12659 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12660 (MOVE_TO_POS
| MOVE_TO_Y
));
12662 if (PT
> CHARPOS (it
.current
.pos
))
12664 int y0
= line_bottom_y (&it
);
12666 /* Compute the distance from the scroll margin to PT
12667 (including the height of the cursor line). Moving the
12668 iterator unconditionally to PT can be slow if PT is far
12669 away, so stop 10 lines past the window bottom (is there a
12670 way to do the right thing quickly?). */
12671 move_it_to (&it
, PT
, -1,
12672 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
12673 -1, MOVE_TO_POS
| MOVE_TO_Y
);
12674 dy
= line_bottom_y (&it
) - y0
;
12676 if (dy
> scroll_max
)
12677 return SCROLLING_FAILED
;
12685 /* Point is in or below the bottom scroll margin, so move the
12686 window start down. If scrolling conservatively, move it just
12687 enough down to make point visible. If scroll_step is set,
12688 move it down by scroll_step. */
12689 if (scroll_conservatively
)
12691 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12692 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12693 else if (scroll_step
|| temp_scroll_step
)
12694 amount_to_scroll
= scroll_max
;
12697 aggressive
= current_buffer
->scroll_up_aggressively
;
12698 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12699 if (NUMBERP (aggressive
))
12701 double float_amount
= XFLOATINT (aggressive
) * height
;
12702 amount_to_scroll
= float_amount
;
12703 if (amount_to_scroll
== 0 && float_amount
> 0)
12704 amount_to_scroll
= 1;
12708 if (amount_to_scroll
<= 0)
12709 return SCROLLING_FAILED
;
12711 start_display (&it
, w
, startp
);
12712 move_it_vertically (&it
, amount_to_scroll
);
12714 /* If STARTP is unchanged, move it down another screen line. */
12715 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12716 move_it_by_lines (&it
, 1, 1);
12717 startp
= it
.current
.pos
;
12721 struct text_pos scroll_margin_pos
= startp
;
12723 /* See if point is inside the scroll margin at the top of the
12725 if (this_scroll_margin
)
12727 start_display (&it
, w
, startp
);
12728 move_it_vertically (&it
, this_scroll_margin
);
12729 scroll_margin_pos
= it
.current
.pos
;
12732 if (PT
< CHARPOS (scroll_margin_pos
))
12734 /* Point is in the scroll margin at the top of the window or
12735 above what is displayed in the window. */
12738 /* Compute the vertical distance from PT to the scroll
12739 margin position. Give up if distance is greater than
12741 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12742 start_display (&it
, w
, pos
);
12744 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12745 it
.last_visible_y
, -1,
12746 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12747 dy
= it
.current_y
- y0
;
12748 if (dy
> scroll_max
)
12749 return SCROLLING_FAILED
;
12751 /* Compute new window start. */
12752 start_display (&it
, w
, startp
);
12754 if (scroll_conservatively
)
12756 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12757 else if (scroll_step
|| temp_scroll_step
)
12758 amount_to_scroll
= scroll_max
;
12761 aggressive
= current_buffer
->scroll_down_aggressively
;
12762 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12763 if (NUMBERP (aggressive
))
12765 double float_amount
= XFLOATINT (aggressive
) * height
;
12766 amount_to_scroll
= float_amount
;
12767 if (amount_to_scroll
== 0 && float_amount
> 0)
12768 amount_to_scroll
= 1;
12772 if (amount_to_scroll
<= 0)
12773 return SCROLLING_FAILED
;
12775 move_it_vertically_backward (&it
, amount_to_scroll
);
12776 startp
= it
.current
.pos
;
12780 /* Run window scroll functions. */
12781 startp
= run_window_scroll_functions (window
, startp
);
12783 /* Display the window. Give up if new fonts are loaded, or if point
12785 if (!try_window (window
, startp
, 0))
12786 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12787 else if (w
->cursor
.vpos
< 0)
12789 clear_glyph_matrix (w
->desired_matrix
);
12790 rc
= SCROLLING_FAILED
;
12794 /* Maybe forget recorded base line for line number display. */
12795 if (!just_this_one_p
12796 || current_buffer
->clip_changed
12797 || BEG_UNCHANGED
< CHARPOS (startp
))
12798 w
->base_line_number
= Qnil
;
12800 /* If cursor ends up on a partially visible line,
12801 treat that as being off the bottom of the screen. */
12802 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12804 clear_glyph_matrix (w
->desired_matrix
);
12805 ++extra_scroll_margin_lines
;
12808 rc
= SCROLLING_SUCCESS
;
12815 /* Compute a suitable window start for window W if display of W starts
12816 on a continuation line. Value is non-zero if a new window start
12819 The new window start will be computed, based on W's width, starting
12820 from the start of the continued line. It is the start of the
12821 screen line with the minimum distance from the old start W->start. */
12824 compute_window_start_on_continuation_line (w
)
12827 struct text_pos pos
, start_pos
;
12828 int window_start_changed_p
= 0;
12830 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12832 /* If window start is on a continuation line... Window start may be
12833 < BEGV in case there's invisible text at the start of the
12834 buffer (M-x rmail, for example). */
12835 if (CHARPOS (start_pos
) > BEGV
12836 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12839 struct glyph_row
*row
;
12841 /* Handle the case that the window start is out of range. */
12842 if (CHARPOS (start_pos
) < BEGV
)
12843 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12844 else if (CHARPOS (start_pos
) > ZV
)
12845 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12847 /* Find the start of the continued line. This should be fast
12848 because scan_buffer is fast (newline cache). */
12849 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12850 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12851 row
, DEFAULT_FACE_ID
);
12852 reseat_at_previous_visible_line_start (&it
);
12854 /* If the line start is "too far" away from the window start,
12855 say it takes too much time to compute a new window start. */
12856 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12857 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12859 int min_distance
, distance
;
12861 /* Move forward by display lines to find the new window
12862 start. If window width was enlarged, the new start can
12863 be expected to be > the old start. If window width was
12864 decreased, the new window start will be < the old start.
12865 So, we're looking for the display line start with the
12866 minimum distance from the old window start. */
12867 pos
= it
.current
.pos
;
12868 min_distance
= INFINITY
;
12869 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12870 distance
< min_distance
)
12872 min_distance
= distance
;
12873 pos
= it
.current
.pos
;
12874 move_it_by_lines (&it
, 1, 0);
12877 /* Set the window start there. */
12878 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12879 window_start_changed_p
= 1;
12883 return window_start_changed_p
;
12887 /* Try cursor movement in case text has not changed in window WINDOW,
12888 with window start STARTP. Value is
12890 CURSOR_MOVEMENT_SUCCESS if successful
12892 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12894 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12895 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12896 we want to scroll as if scroll-step were set to 1. See the code.
12898 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12899 which case we have to abort this redisplay, and adjust matrices
12904 CURSOR_MOVEMENT_SUCCESS
,
12905 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12906 CURSOR_MOVEMENT_MUST_SCROLL
,
12907 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12911 try_cursor_movement (window
, startp
, scroll_step
)
12912 Lisp_Object window
;
12913 struct text_pos startp
;
12916 struct window
*w
= XWINDOW (window
);
12917 struct frame
*f
= XFRAME (w
->frame
);
12918 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12921 if (inhibit_try_cursor_movement
)
12925 /* Handle case where text has not changed, only point, and it has
12926 not moved off the frame. */
12927 if (/* Point may be in this window. */
12928 PT
>= CHARPOS (startp
)
12929 /* Selective display hasn't changed. */
12930 && !current_buffer
->clip_changed
12931 /* Function force-mode-line-update is used to force a thorough
12932 redisplay. It sets either windows_or_buffers_changed or
12933 update_mode_lines. So don't take a shortcut here for these
12935 && !update_mode_lines
12936 && !windows_or_buffers_changed
12937 && !cursor_type_changed
12938 /* Can't use this case if highlighting a region. When a
12939 region exists, cursor movement has to do more than just
12941 && !(!NILP (Vtransient_mark_mode
)
12942 && !NILP (current_buffer
->mark_active
))
12943 && NILP (w
->region_showing
)
12944 && NILP (Vshow_trailing_whitespace
)
12945 /* Right after splitting windows, last_point may be nil. */
12946 && INTEGERP (w
->last_point
)
12947 /* This code is not used for mini-buffer for the sake of the case
12948 of redisplaying to replace an echo area message; since in
12949 that case the mini-buffer contents per se are usually
12950 unchanged. This code is of no real use in the mini-buffer
12951 since the handling of this_line_start_pos, etc., in redisplay
12952 handles the same cases. */
12953 && !EQ (window
, minibuf_window
)
12954 /* When splitting windows or for new windows, it happens that
12955 redisplay is called with a nil window_end_vpos or one being
12956 larger than the window. This should really be fixed in
12957 window.c. I don't have this on my list, now, so we do
12958 approximately the same as the old redisplay code. --gerd. */
12959 && INTEGERP (w
->window_end_vpos
)
12960 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12961 && (FRAME_WINDOW_P (f
)
12962 || !overlay_arrow_in_current_buffer_p ()))
12964 int this_scroll_margin
, top_scroll_margin
;
12965 struct glyph_row
*row
= NULL
;
12968 debug_method_add (w
, "cursor movement");
12971 /* Scroll if point within this distance from the top or bottom
12972 of the window. This is a pixel value. */
12973 if (scroll_margin
> 0)
12975 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12976 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12979 this_scroll_margin
= 0;
12981 top_scroll_margin
= this_scroll_margin
;
12982 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12983 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12985 /* Start with the row the cursor was displayed during the last
12986 not paused redisplay. Give up if that row is not valid. */
12987 if (w
->last_cursor
.vpos
< 0
12988 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12989 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12992 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12993 if (row
->mode_line_p
)
12995 if (!row
->enabled_p
)
12996 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12999 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13002 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13004 if (PT
> XFASTINT (w
->last_point
))
13006 /* Point has moved forward. */
13007 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13008 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13010 xassert (row
->enabled_p
);
13014 /* The end position of a row equals the start position
13015 of the next row. If PT is there, we would rather
13016 display it in the next line. */
13017 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13018 && MATRIX_ROW_END_CHARPOS (row
) == PT
13019 && !cursor_row_p (w
, row
))
13022 /* If within the scroll margin, scroll. Note that
13023 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13024 the next line would be drawn, and that
13025 this_scroll_margin can be zero. */
13026 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13027 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13028 /* Line is completely visible last line in window
13029 and PT is to be set in the next line. */
13030 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13031 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13032 && !row
->ends_at_zv_p
13033 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13036 else if (PT
< XFASTINT (w
->last_point
))
13038 /* Cursor has to be moved backward. Note that PT >=
13039 CHARPOS (startp) because of the outer if-statement. */
13040 while (!row
->mode_line_p
13041 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13042 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13043 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13044 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13045 row
> w
->current_matrix
->rows
13046 && (row
-1)->ends_in_newline_from_string_p
))))
13047 && (row
->y
> top_scroll_margin
13048 || CHARPOS (startp
) == BEGV
))
13050 xassert (row
->enabled_p
);
13054 /* Consider the following case: Window starts at BEGV,
13055 there is invisible, intangible text at BEGV, so that
13056 display starts at some point START > BEGV. It can
13057 happen that we are called with PT somewhere between
13058 BEGV and START. Try to handle that case. */
13059 if (row
< w
->current_matrix
->rows
13060 || row
->mode_line_p
)
13062 row
= w
->current_matrix
->rows
;
13063 if (row
->mode_line_p
)
13067 /* Due to newlines in overlay strings, we may have to
13068 skip forward over overlay strings. */
13069 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13070 && MATRIX_ROW_END_CHARPOS (row
) == PT
13071 && !cursor_row_p (w
, row
))
13074 /* If within the scroll margin, scroll. */
13075 if (row
->y
< top_scroll_margin
13076 && CHARPOS (startp
) != BEGV
)
13081 /* Cursor did not move. So don't scroll even if cursor line
13082 is partially visible, as it was so before. */
13083 rc
= CURSOR_MOVEMENT_SUCCESS
;
13086 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13087 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13089 /* if PT is not in the glyph row, give up. */
13090 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13092 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13093 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13094 && make_cursor_line_fully_visible_p
)
13096 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13097 && !row
->ends_at_zv_p
13098 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13099 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13100 else if (row
->height
> window_box_height (w
))
13102 /* If we end up in a partially visible line, let's
13103 make it fully visible, except when it's taller
13104 than the window, in which case we can't do much
13107 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13111 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13112 if (!cursor_row_fully_visible_p (w
, 0, 1))
13113 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13115 rc
= CURSOR_MOVEMENT_SUCCESS
;
13119 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13124 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13126 rc
= CURSOR_MOVEMENT_SUCCESS
;
13131 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13132 && MATRIX_ROW_START_CHARPOS (row
) == PT
13133 && cursor_row_p (w
, row
));
13142 set_vertical_scroll_bar (w
)
13145 int start
, end
, whole
;
13147 /* Calculate the start and end positions for the current window.
13148 At some point, it would be nice to choose between scrollbars
13149 which reflect the whole buffer size, with special markers
13150 indicating narrowing, and scrollbars which reflect only the
13153 Note that mini-buffers sometimes aren't displaying any text. */
13154 if (!MINI_WINDOW_P (w
)
13155 || (w
== XWINDOW (minibuf_window
)
13156 && NILP (echo_area_buffer
[0])))
13158 struct buffer
*buf
= XBUFFER (w
->buffer
);
13159 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13160 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13161 /* I don't think this is guaranteed to be right. For the
13162 moment, we'll pretend it is. */
13163 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13167 if (whole
< (end
- start
))
13168 whole
= end
- start
;
13171 start
= end
= whole
= 0;
13173 /* Indicate what this scroll bar ought to be displaying now. */
13174 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13175 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13176 (w
, end
- start
, whole
, start
);
13180 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13181 selected_window is redisplayed.
13183 We can return without actually redisplaying the window if
13184 fonts_changed_p is nonzero. In that case, redisplay_internal will
13188 redisplay_window (window
, just_this_one_p
)
13189 Lisp_Object window
;
13190 int just_this_one_p
;
13192 struct window
*w
= XWINDOW (window
);
13193 struct frame
*f
= XFRAME (w
->frame
);
13194 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13195 struct buffer
*old
= current_buffer
;
13196 struct text_pos lpoint
, opoint
, startp
;
13197 int update_mode_line
;
13200 /* Record it now because it's overwritten. */
13201 int current_matrix_up_to_date_p
= 0;
13202 int used_current_matrix_p
= 0;
13203 /* This is less strict than current_matrix_up_to_date_p.
13204 It indictes that the buffer contents and narrowing are unchanged. */
13205 int buffer_unchanged_p
= 0;
13206 int temp_scroll_step
= 0;
13207 int count
= SPECPDL_INDEX ();
13209 int centering_position
= -1;
13210 int last_line_misfit
= 0;
13211 int beg_unchanged
, end_unchanged
;
13213 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13216 /* W must be a leaf window here. */
13217 xassert (!NILP (w
->buffer
));
13219 *w
->desired_matrix
->method
= 0;
13223 reconsider_clip_changes (w
, buffer
);
13225 /* Has the mode line to be updated? */
13226 update_mode_line
= (!NILP (w
->update_mode_line
)
13227 || update_mode_lines
13228 || buffer
->clip_changed
13229 || buffer
->prevent_redisplay_optimizations_p
);
13231 if (MINI_WINDOW_P (w
))
13233 if (w
== XWINDOW (echo_area_window
)
13234 && !NILP (echo_area_buffer
[0]))
13236 if (update_mode_line
)
13237 /* We may have to update a tty frame's menu bar or a
13238 tool-bar. Example `M-x C-h C-h C-g'. */
13239 goto finish_menu_bars
;
13241 /* We've already displayed the echo area glyphs in this window. */
13242 goto finish_scroll_bars
;
13244 else if ((w
!= XWINDOW (minibuf_window
)
13245 || minibuf_level
== 0)
13246 /* When buffer is nonempty, redisplay window normally. */
13247 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13248 /* Quail displays non-mini buffers in minibuffer window.
13249 In that case, redisplay the window normally. */
13250 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13252 /* W is a mini-buffer window, but it's not active, so clear
13254 int yb
= window_text_bottom_y (w
);
13255 struct glyph_row
*row
;
13258 for (y
= 0, row
= w
->desired_matrix
->rows
;
13260 y
+= row
->height
, ++row
)
13261 blank_row (w
, row
, y
);
13262 goto finish_scroll_bars
;
13265 clear_glyph_matrix (w
->desired_matrix
);
13268 /* Otherwise set up data on this window; select its buffer and point
13270 /* Really select the buffer, for the sake of buffer-local
13272 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13274 current_matrix_up_to_date_p
13275 = (!NILP (w
->window_end_valid
)
13276 && !current_buffer
->clip_changed
13277 && !current_buffer
->prevent_redisplay_optimizations_p
13278 && XFASTINT (w
->last_modified
) >= MODIFF
13279 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13281 /* Run the window-bottom-change-functions
13282 if it is possible that the text on the screen has changed
13283 (either due to modification of the text, or any other reason). */
13284 if (!current_matrix_up_to_date_p
13285 && !NILP (Vwindow_text_change_functions
))
13287 safe_run_hooks (Qwindow_text_change_functions
);
13291 beg_unchanged
= BEG_UNCHANGED
;
13292 end_unchanged
= END_UNCHANGED
;
13294 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13296 specbind (Qinhibit_point_motion_hooks
, Qt
);
13299 = (!NILP (w
->window_end_valid
)
13300 && !current_buffer
->clip_changed
13301 && XFASTINT (w
->last_modified
) >= MODIFF
13302 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13304 /* When windows_or_buffers_changed is non-zero, we can't rely on
13305 the window end being valid, so set it to nil there. */
13306 if (windows_or_buffers_changed
)
13308 /* If window starts on a continuation line, maybe adjust the
13309 window start in case the window's width changed. */
13310 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13311 compute_window_start_on_continuation_line (w
);
13313 w
->window_end_valid
= Qnil
;
13316 /* Some sanity checks. */
13317 CHECK_WINDOW_END (w
);
13318 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13320 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13323 /* If %c is in mode line, update it if needed. */
13324 if (!NILP (w
->column_number_displayed
)
13325 /* This alternative quickly identifies a common case
13326 where no change is needed. */
13327 && !(PT
== XFASTINT (w
->last_point
)
13328 && XFASTINT (w
->last_modified
) >= MODIFF
13329 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13330 && (XFASTINT (w
->column_number_displayed
)
13331 != (int) current_column ())) /* iftc */
13332 update_mode_line
= 1;
13334 /* Count number of windows showing the selected buffer. An indirect
13335 buffer counts as its base buffer. */
13336 if (!just_this_one_p
)
13338 struct buffer
*current_base
, *window_base
;
13339 current_base
= current_buffer
;
13340 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13341 if (current_base
->base_buffer
)
13342 current_base
= current_base
->base_buffer
;
13343 if (window_base
->base_buffer
)
13344 window_base
= window_base
->base_buffer
;
13345 if (current_base
== window_base
)
13349 /* Point refers normally to the selected window. For any other
13350 window, set up appropriate value. */
13351 if (!EQ (window
, selected_window
))
13353 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13354 int new_pt_byte
= marker_byte_position (w
->pointm
);
13358 new_pt_byte
= BEGV_BYTE
;
13359 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13361 else if (new_pt
> (ZV
- 1))
13364 new_pt_byte
= ZV_BYTE
;
13365 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13368 /* We don't use SET_PT so that the point-motion hooks don't run. */
13369 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13372 /* If any of the character widths specified in the display table
13373 have changed, invalidate the width run cache. It's true that
13374 this may be a bit late to catch such changes, but the rest of
13375 redisplay goes (non-fatally) haywire when the display table is
13376 changed, so why should we worry about doing any better? */
13377 if (current_buffer
->width_run_cache
)
13379 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13381 if (! disptab_matches_widthtab (disptab
,
13382 XVECTOR (current_buffer
->width_table
)))
13384 invalidate_region_cache (current_buffer
,
13385 current_buffer
->width_run_cache
,
13387 recompute_width_table (current_buffer
, disptab
);
13391 /* If window-start is screwed up, choose a new one. */
13392 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13395 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13397 /* If someone specified a new starting point but did not insist,
13398 check whether it can be used. */
13399 if (!NILP (w
->optional_new_start
)
13400 && CHARPOS (startp
) >= BEGV
13401 && CHARPOS (startp
) <= ZV
)
13403 w
->optional_new_start
= Qnil
;
13404 start_display (&it
, w
, startp
);
13405 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13406 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13407 if (IT_CHARPOS (it
) == PT
)
13408 w
->force_start
= Qt
;
13409 /* IT may overshoot PT if text at PT is invisible. */
13410 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13411 w
->force_start
= Qt
;
13416 /* Handle case where place to start displaying has been specified,
13417 unless the specified location is outside the accessible range. */
13418 if (!NILP (w
->force_start
)
13419 || w
->frozen_window_start_p
)
13421 /* We set this later on if we have to adjust point. */
13424 w
->force_start
= Qnil
;
13426 w
->window_end_valid
= Qnil
;
13428 /* Forget any recorded base line for line number display. */
13429 if (!buffer_unchanged_p
)
13430 w
->base_line_number
= Qnil
;
13432 /* Redisplay the mode line. Select the buffer properly for that.
13433 Also, run the hook window-scroll-functions
13434 because we have scrolled. */
13435 /* Note, we do this after clearing force_start because
13436 if there's an error, it is better to forget about force_start
13437 than to get into an infinite loop calling the hook functions
13438 and having them get more errors. */
13439 if (!update_mode_line
13440 || ! NILP (Vwindow_scroll_functions
))
13442 update_mode_line
= 1;
13443 w
->update_mode_line
= Qt
;
13444 startp
= run_window_scroll_functions (window
, startp
);
13447 w
->last_modified
= make_number (0);
13448 w
->last_overlay_modified
= make_number (0);
13449 if (CHARPOS (startp
) < BEGV
)
13450 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13451 else if (CHARPOS (startp
) > ZV
)
13452 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13454 /* Redisplay, then check if cursor has been set during the
13455 redisplay. Give up if new fonts were loaded. */
13456 /* We used to issue a CHECK_MARGINS argument to try_window here,
13457 but this causes scrolling to fail when point begins inside
13458 the scroll margin (bug#148) -- cyd */
13459 if (!try_window (window
, startp
, 0))
13461 w
->force_start
= Qt
;
13462 clear_glyph_matrix (w
->desired_matrix
);
13463 goto need_larger_matrices
;
13466 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13468 /* If point does not appear, try to move point so it does
13469 appear. The desired matrix has been built above, so we
13470 can use it here. */
13471 new_vpos
= window_box_height (w
) / 2;
13474 if (!cursor_row_fully_visible_p (w
, 0, 0))
13476 /* Point does appear, but on a line partly visible at end of window.
13477 Move it back to a fully-visible line. */
13478 new_vpos
= window_box_height (w
);
13481 /* If we need to move point for either of the above reasons,
13482 now actually do it. */
13485 struct glyph_row
*row
;
13487 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13488 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13491 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13492 MATRIX_ROW_START_BYTEPOS (row
));
13494 if (w
!= XWINDOW (selected_window
))
13495 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13496 else if (current_buffer
== old
)
13497 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13499 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13501 /* If we are highlighting the region, then we just changed
13502 the region, so redisplay to show it. */
13503 if (!NILP (Vtransient_mark_mode
)
13504 && !NILP (current_buffer
->mark_active
))
13506 clear_glyph_matrix (w
->desired_matrix
);
13507 if (!try_window (window
, startp
, 0))
13508 goto need_larger_matrices
;
13513 debug_method_add (w
, "forced window start");
13518 /* Handle case where text has not changed, only point, and it has
13519 not moved off the frame, and we are not retrying after hscroll.
13520 (current_matrix_up_to_date_p is nonzero when retrying.) */
13521 if (current_matrix_up_to_date_p
13522 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13523 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13527 case CURSOR_MOVEMENT_SUCCESS
:
13528 used_current_matrix_p
= 1;
13531 case CURSOR_MOVEMENT_MUST_SCROLL
:
13532 goto try_to_scroll
;
13538 /* If current starting point was originally the beginning of a line
13539 but no longer is, find a new starting point. */
13540 else if (!NILP (w
->start_at_line_beg
)
13541 && !(CHARPOS (startp
) <= BEGV
13542 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13545 debug_method_add (w
, "recenter 1");
13550 /* Try scrolling with try_window_id. Value is > 0 if update has
13551 been done, it is -1 if we know that the same window start will
13552 not work. It is 0 if unsuccessful for some other reason. */
13553 else if ((tem
= try_window_id (w
)) != 0)
13556 debug_method_add (w
, "try_window_id %d", tem
);
13559 if (fonts_changed_p
)
13560 goto need_larger_matrices
;
13564 /* Otherwise try_window_id has returned -1 which means that we
13565 don't want the alternative below this comment to execute. */
13567 else if (CHARPOS (startp
) >= BEGV
13568 && CHARPOS (startp
) <= ZV
13569 && PT
>= CHARPOS (startp
)
13570 && (CHARPOS (startp
) < ZV
13571 /* Avoid starting at end of buffer. */
13572 || CHARPOS (startp
) == BEGV
13573 || (XFASTINT (w
->last_modified
) >= MODIFF
13574 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13577 /* If first window line is a continuation line, and window start
13578 is inside the modified region, but the first change is before
13579 current window start, we must select a new window start.
13581 However, if this is the result of a down-mouse event (e.g. by
13582 extending the mouse-drag-overlay), we don't want to select a
13583 new window start, since that would change the position under
13584 the mouse, resulting in an unwanted mouse-movement rather
13585 than a simple mouse-click. */
13586 if (NILP (w
->start_at_line_beg
)
13587 && NILP (do_mouse_tracking
)
13588 && CHARPOS (startp
) > BEGV
13589 && CHARPOS (startp
) > BEG
+ beg_unchanged
13590 && CHARPOS (startp
) <= Z
- end_unchanged
13591 /* Even if w->start_at_line_beg is nil, a new window may
13592 start at a line_beg, since that's how set_buffer_window
13593 sets it. So, we need to check the return value of
13594 compute_window_start_on_continuation_line. (See also
13596 && XMARKER (w
->start
)->buffer
== current_buffer
13597 && compute_window_start_on_continuation_line (w
))
13599 w
->force_start
= Qt
;
13600 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13605 debug_method_add (w
, "same window start");
13608 /* Try to redisplay starting at same place as before.
13609 If point has not moved off frame, accept the results. */
13610 if (!current_matrix_up_to_date_p
13611 /* Don't use try_window_reusing_current_matrix in this case
13612 because a window scroll function can have changed the
13614 || !NILP (Vwindow_scroll_functions
)
13615 || MINI_WINDOW_P (w
)
13616 || !(used_current_matrix_p
13617 = try_window_reusing_current_matrix (w
)))
13619 IF_DEBUG (debug_method_add (w
, "1"));
13620 if (try_window (window
, startp
, 1) < 0)
13621 /* -1 means we need to scroll.
13622 0 means we need new matrices, but fonts_changed_p
13623 is set in that case, so we will detect it below. */
13624 goto try_to_scroll
;
13627 if (fonts_changed_p
)
13628 goto need_larger_matrices
;
13630 if (w
->cursor
.vpos
>= 0)
13632 if (!just_this_one_p
13633 || current_buffer
->clip_changed
13634 || BEG_UNCHANGED
< CHARPOS (startp
))
13635 /* Forget any recorded base line for line number display. */
13636 w
->base_line_number
= Qnil
;
13638 if (!cursor_row_fully_visible_p (w
, 1, 0))
13640 clear_glyph_matrix (w
->desired_matrix
);
13641 last_line_misfit
= 1;
13643 /* Drop through and scroll. */
13648 clear_glyph_matrix (w
->desired_matrix
);
13653 w
->last_modified
= make_number (0);
13654 w
->last_overlay_modified
= make_number (0);
13656 /* Redisplay the mode line. Select the buffer properly for that. */
13657 if (!update_mode_line
)
13659 update_mode_line
= 1;
13660 w
->update_mode_line
= Qt
;
13663 /* Try to scroll by specified few lines. */
13664 if ((scroll_conservatively
13666 || temp_scroll_step
13667 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13668 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13669 && !current_buffer
->clip_changed
13670 && CHARPOS (startp
) >= BEGV
13671 && CHARPOS (startp
) <= ZV
)
13673 /* The function returns -1 if new fonts were loaded, 1 if
13674 successful, 0 if not successful. */
13675 int rc
= try_scrolling (window
, just_this_one_p
,
13676 scroll_conservatively
,
13678 temp_scroll_step
, last_line_misfit
);
13681 case SCROLLING_SUCCESS
:
13684 case SCROLLING_NEED_LARGER_MATRICES
:
13685 goto need_larger_matrices
;
13687 case SCROLLING_FAILED
:
13695 /* Finally, just choose place to start which centers point */
13698 if (centering_position
< 0)
13699 centering_position
= window_box_height (w
) / 2;
13702 debug_method_add (w
, "recenter");
13705 /* w->vscroll = 0; */
13707 /* Forget any previously recorded base line for line number display. */
13708 if (!buffer_unchanged_p
)
13709 w
->base_line_number
= Qnil
;
13711 /* Move backward half the height of the window. */
13712 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13713 it
.current_y
= it
.last_visible_y
;
13714 move_it_vertically_backward (&it
, centering_position
);
13715 xassert (IT_CHARPOS (it
) >= BEGV
);
13717 /* The function move_it_vertically_backward may move over more
13718 than the specified y-distance. If it->w is small, e.g. a
13719 mini-buffer window, we may end up in front of the window's
13720 display area. Start displaying at the start of the line
13721 containing PT in this case. */
13722 if (it
.current_y
<= 0)
13724 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13725 move_it_vertically_backward (&it
, 0);
13729 it
.current_x
= it
.hpos
= 0;
13731 /* Set startp here explicitly in case that helps avoid an infinite loop
13732 in case the window-scroll-functions functions get errors. */
13733 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13735 /* Run scroll hooks. */
13736 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13738 /* Redisplay the window. */
13739 if (!current_matrix_up_to_date_p
13740 || windows_or_buffers_changed
13741 || cursor_type_changed
13742 /* Don't use try_window_reusing_current_matrix in this case
13743 because it can have changed the buffer. */
13744 || !NILP (Vwindow_scroll_functions
)
13745 || !just_this_one_p
13746 || MINI_WINDOW_P (w
)
13747 || !(used_current_matrix_p
13748 = try_window_reusing_current_matrix (w
)))
13749 try_window (window
, startp
, 0);
13751 /* If new fonts have been loaded (due to fontsets), give up. We
13752 have to start a new redisplay since we need to re-adjust glyph
13754 if (fonts_changed_p
)
13755 goto need_larger_matrices
;
13757 /* If cursor did not appear assume that the middle of the window is
13758 in the first line of the window. Do it again with the next line.
13759 (Imagine a window of height 100, displaying two lines of height
13760 60. Moving back 50 from it->last_visible_y will end in the first
13762 if (w
->cursor
.vpos
< 0)
13764 if (!NILP (w
->window_end_valid
)
13765 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13767 clear_glyph_matrix (w
->desired_matrix
);
13768 move_it_by_lines (&it
, 1, 0);
13769 try_window (window
, it
.current
.pos
, 0);
13771 else if (PT
< IT_CHARPOS (it
))
13773 clear_glyph_matrix (w
->desired_matrix
);
13774 move_it_by_lines (&it
, -1, 0);
13775 try_window (window
, it
.current
.pos
, 0);
13779 /* Not much we can do about it. */
13783 /* Consider the following case: Window starts at BEGV, there is
13784 invisible, intangible text at BEGV, so that display starts at
13785 some point START > BEGV. It can happen that we are called with
13786 PT somewhere between BEGV and START. Try to handle that case. */
13787 if (w
->cursor
.vpos
< 0)
13789 struct glyph_row
*row
= w
->current_matrix
->rows
;
13790 if (row
->mode_line_p
)
13792 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13795 if (!cursor_row_fully_visible_p (w
, 0, 0))
13797 /* If vscroll is enabled, disable it and try again. */
13801 clear_glyph_matrix (w
->desired_matrix
);
13805 /* If centering point failed to make the whole line visible,
13806 put point at the top instead. That has to make the whole line
13807 visible, if it can be done. */
13808 if (centering_position
== 0)
13811 clear_glyph_matrix (w
->desired_matrix
);
13812 centering_position
= 0;
13818 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13819 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13820 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13823 /* Display the mode line, if we must. */
13824 if ((update_mode_line
13825 /* If window not full width, must redo its mode line
13826 if (a) the window to its side is being redone and
13827 (b) we do a frame-based redisplay. This is a consequence
13828 of how inverted lines are drawn in frame-based redisplay. */
13829 || (!just_this_one_p
13830 && !FRAME_WINDOW_P (f
)
13831 && !WINDOW_FULL_WIDTH_P (w
))
13832 /* Line number to display. */
13833 || INTEGERP (w
->base_line_pos
)
13834 /* Column number is displayed and different from the one displayed. */
13835 || (!NILP (w
->column_number_displayed
)
13836 && (XFASTINT (w
->column_number_displayed
)
13837 != (int) current_column ()))) /* iftc */
13838 /* This means that the window has a mode line. */
13839 && (WINDOW_WANTS_MODELINE_P (w
)
13840 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13842 display_mode_lines (w
);
13844 /* If mode line height has changed, arrange for a thorough
13845 immediate redisplay using the correct mode line height. */
13846 if (WINDOW_WANTS_MODELINE_P (w
)
13847 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13849 fonts_changed_p
= 1;
13850 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13851 = DESIRED_MODE_LINE_HEIGHT (w
);
13854 /* If top line height has changed, arrange for a thorough
13855 immediate redisplay using the correct mode line height. */
13856 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13857 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13859 fonts_changed_p
= 1;
13860 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13861 = DESIRED_HEADER_LINE_HEIGHT (w
);
13864 if (fonts_changed_p
)
13865 goto need_larger_matrices
;
13868 if (!line_number_displayed
13869 && !BUFFERP (w
->base_line_pos
))
13871 w
->base_line_pos
= Qnil
;
13872 w
->base_line_number
= Qnil
;
13877 /* When we reach a frame's selected window, redo the frame's menu bar. */
13878 if (update_mode_line
13879 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13881 int redisplay_menu_p
= 0;
13882 int redisplay_tool_bar_p
= 0;
13884 if (FRAME_WINDOW_P (f
))
13886 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13887 || defined (HAVE_NS) || defined (USE_GTK)
13888 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13890 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13894 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13896 if (redisplay_menu_p
)
13897 display_menu_bar (w
);
13899 #ifdef HAVE_WINDOW_SYSTEM
13900 if (FRAME_WINDOW_P (f
))
13902 #if defined (USE_GTK) || defined (HAVE_NS)
13903 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13905 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13906 && (FRAME_TOOL_BAR_LINES (f
) > 0
13907 || !NILP (Vauto_resize_tool_bars
));
13910 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13912 extern int ignore_mouse_drag_p
;
13913 ignore_mouse_drag_p
= 1;
13919 #ifdef HAVE_WINDOW_SYSTEM
13920 if (FRAME_WINDOW_P (f
)
13921 && update_window_fringes (w
, (just_this_one_p
13922 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13923 || w
->pseudo_window_p
)))
13927 if (draw_window_fringes (w
, 1))
13928 x_draw_vertical_border (w
);
13932 #endif /* HAVE_WINDOW_SYSTEM */
13934 /* We go to this label, with fonts_changed_p nonzero,
13935 if it is necessary to try again using larger glyph matrices.
13936 We have to redeem the scroll bar even in this case,
13937 because the loop in redisplay_internal expects that. */
13938 need_larger_matrices
:
13940 finish_scroll_bars
:
13942 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13944 /* Set the thumb's position and size. */
13945 set_vertical_scroll_bar (w
);
13947 /* Note that we actually used the scroll bar attached to this
13948 window, so it shouldn't be deleted at the end of redisplay. */
13949 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13950 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13953 /* Restore current_buffer and value of point in it. */
13954 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13955 set_buffer_internal_1 (old
);
13956 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13957 shorter. This can be caused by log truncation in *Messages*. */
13958 if (CHARPOS (lpoint
) <= ZV
)
13959 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13961 unbind_to (count
, Qnil
);
13965 /* Build the complete desired matrix of WINDOW with a window start
13966 buffer position POS.
13968 Value is 1 if successful. It is zero if fonts were loaded during
13969 redisplay which makes re-adjusting glyph matrices necessary, and -1
13970 if point would appear in the scroll margins.
13971 (We check that only if CHECK_MARGINS is nonzero. */
13974 try_window (window
, pos
, check_margins
)
13975 Lisp_Object window
;
13976 struct text_pos pos
;
13979 struct window
*w
= XWINDOW (window
);
13981 struct glyph_row
*last_text_row
= NULL
;
13982 struct frame
*f
= XFRAME (w
->frame
);
13984 /* Make POS the new window start. */
13985 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13987 /* Mark cursor position as unknown. No overlay arrow seen. */
13988 w
->cursor
.vpos
= -1;
13989 overlay_arrow_seen
= 0;
13991 /* Initialize iterator and info to start at POS. */
13992 start_display (&it
, w
, pos
);
13994 /* Display all lines of W. */
13995 while (it
.current_y
< it
.last_visible_y
)
13997 if (display_line (&it
))
13998 last_text_row
= it
.glyph_row
- 1;
13999 if (fonts_changed_p
)
14003 /* Don't let the cursor end in the scroll margins. */
14005 && !MINI_WINDOW_P (w
))
14007 int this_scroll_margin
;
14009 if (scroll_margin
> 0)
14011 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14012 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14015 this_scroll_margin
= 0;
14017 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14018 && w
->cursor
.y
< this_scroll_margin
14019 && CHARPOS (pos
) > BEGV
14020 && IT_CHARPOS (it
) < ZV
)
14021 /* rms: considering make_cursor_line_fully_visible_p here
14022 seems to give wrong results. We don't want to recenter
14023 when the last line is partly visible, we want to allow
14024 that case to be handled in the usual way. */
14025 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14027 w
->cursor
.vpos
= -1;
14028 clear_glyph_matrix (w
->desired_matrix
);
14033 /* If bottom moved off end of frame, change mode line percentage. */
14034 if (XFASTINT (w
->window_end_pos
) <= 0
14035 && Z
!= IT_CHARPOS (it
))
14036 w
->update_mode_line
= Qt
;
14038 /* Set window_end_pos to the offset of the last character displayed
14039 on the window from the end of current_buffer. Set
14040 window_end_vpos to its row number. */
14043 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14044 w
->window_end_bytepos
14045 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14047 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14049 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14050 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14051 ->displays_text_p
);
14055 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14056 w
->window_end_pos
= make_number (Z
- ZV
);
14057 w
->window_end_vpos
= make_number (0);
14060 /* But that is not valid info until redisplay finishes. */
14061 w
->window_end_valid
= Qnil
;
14067 /************************************************************************
14068 Window redisplay reusing current matrix when buffer has not changed
14069 ************************************************************************/
14071 /* Try redisplay of window W showing an unchanged buffer with a
14072 different window start than the last time it was displayed by
14073 reusing its current matrix. Value is non-zero if successful.
14074 W->start is the new window start. */
14077 try_window_reusing_current_matrix (w
)
14080 struct frame
*f
= XFRAME (w
->frame
);
14081 struct glyph_row
*row
, *bottom_row
;
14084 struct text_pos start
, new_start
;
14085 int nrows_scrolled
, i
;
14086 struct glyph_row
*last_text_row
;
14087 struct glyph_row
*last_reused_text_row
;
14088 struct glyph_row
*start_row
;
14089 int start_vpos
, min_y
, max_y
;
14092 if (inhibit_try_window_reusing
)
14096 if (/* This function doesn't handle terminal frames. */
14097 !FRAME_WINDOW_P (f
)
14098 /* Don't try to reuse the display if windows have been split
14100 || windows_or_buffers_changed
14101 || cursor_type_changed
)
14104 /* Can't do this if region may have changed. */
14105 if ((!NILP (Vtransient_mark_mode
)
14106 && !NILP (current_buffer
->mark_active
))
14107 || !NILP (w
->region_showing
)
14108 || !NILP (Vshow_trailing_whitespace
))
14111 /* If top-line visibility has changed, give up. */
14112 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14113 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14116 /* Give up if old or new display is scrolled vertically. We could
14117 make this function handle this, but right now it doesn't. */
14118 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14119 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14122 /* The variable new_start now holds the new window start. The old
14123 start `start' can be determined from the current matrix. */
14124 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14125 start
= start_row
->start
.pos
;
14126 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14128 /* Clear the desired matrix for the display below. */
14129 clear_glyph_matrix (w
->desired_matrix
);
14131 if (CHARPOS (new_start
) <= CHARPOS (start
))
14135 /* Don't use this method if the display starts with an ellipsis
14136 displayed for invisible text. It's not easy to handle that case
14137 below, and it's certainly not worth the effort since this is
14138 not a frequent case. */
14139 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14142 IF_DEBUG (debug_method_add (w
, "twu1"));
14144 /* Display up to a row that can be reused. The variable
14145 last_text_row is set to the last row displayed that displays
14146 text. Note that it.vpos == 0 if or if not there is a
14147 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14148 start_display (&it
, w
, new_start
);
14149 first_row_y
= it
.current_y
;
14150 w
->cursor
.vpos
= -1;
14151 last_text_row
= last_reused_text_row
= NULL
;
14153 while (it
.current_y
< it
.last_visible_y
14154 && !fonts_changed_p
)
14156 /* If we have reached into the characters in the START row,
14157 that means the line boundaries have changed. So we
14158 can't start copying with the row START. Maybe it will
14159 work to start copying with the following row. */
14160 while (IT_CHARPOS (it
) > CHARPOS (start
))
14162 /* Advance to the next row as the "start". */
14164 start
= start_row
->start
.pos
;
14165 /* If there are no more rows to try, or just one, give up. */
14166 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14167 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14168 || CHARPOS (start
) == ZV
)
14170 clear_glyph_matrix (w
->desired_matrix
);
14174 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14176 /* If we have reached alignment,
14177 we can copy the rest of the rows. */
14178 if (IT_CHARPOS (it
) == CHARPOS (start
))
14181 if (display_line (&it
))
14182 last_text_row
= it
.glyph_row
- 1;
14185 /* A value of current_y < last_visible_y means that we stopped
14186 at the previous window start, which in turn means that we
14187 have at least one reusable row. */
14188 if (it
.current_y
< it
.last_visible_y
)
14190 /* IT.vpos always starts from 0; it counts text lines. */
14191 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14193 /* Find PT if not already found in the lines displayed. */
14194 if (w
->cursor
.vpos
< 0)
14196 int dy
= it
.current_y
- start_row
->y
;
14198 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14199 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14201 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14202 dy
, nrows_scrolled
);
14205 clear_glyph_matrix (w
->desired_matrix
);
14210 /* Scroll the display. Do it before the current matrix is
14211 changed. The problem here is that update has not yet
14212 run, i.e. part of the current matrix is not up to date.
14213 scroll_run_hook will clear the cursor, and use the
14214 current matrix to get the height of the row the cursor is
14216 run
.current_y
= start_row
->y
;
14217 run
.desired_y
= it
.current_y
;
14218 run
.height
= it
.last_visible_y
- it
.current_y
;
14220 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14223 FRAME_RIF (f
)->update_window_begin_hook (w
);
14224 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14225 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14226 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14230 /* Shift current matrix down by nrows_scrolled lines. */
14231 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14232 rotate_matrix (w
->current_matrix
,
14234 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14237 /* Disable lines that must be updated. */
14238 for (i
= 0; i
< nrows_scrolled
; ++i
)
14239 (start_row
+ i
)->enabled_p
= 0;
14241 /* Re-compute Y positions. */
14242 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14243 max_y
= it
.last_visible_y
;
14244 for (row
= start_row
+ nrows_scrolled
;
14248 row
->y
= it
.current_y
;
14249 row
->visible_height
= row
->height
;
14251 if (row
->y
< min_y
)
14252 row
->visible_height
-= min_y
- row
->y
;
14253 if (row
->y
+ row
->height
> max_y
)
14254 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14255 row
->redraw_fringe_bitmaps_p
= 1;
14257 it
.current_y
+= row
->height
;
14259 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14260 last_reused_text_row
= row
;
14261 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14265 /* Disable lines in the current matrix which are now
14266 below the window. */
14267 for (++row
; row
< bottom_row
; ++row
)
14268 row
->enabled_p
= row
->mode_line_p
= 0;
14271 /* Update window_end_pos etc.; last_reused_text_row is the last
14272 reused row from the current matrix containing text, if any.
14273 The value of last_text_row is the last displayed line
14274 containing text. */
14275 if (last_reused_text_row
)
14277 w
->window_end_bytepos
14278 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14280 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14282 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14283 w
->current_matrix
));
14285 else if (last_text_row
)
14287 w
->window_end_bytepos
14288 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14290 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14292 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14296 /* This window must be completely empty. */
14297 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14298 w
->window_end_pos
= make_number (Z
- ZV
);
14299 w
->window_end_vpos
= make_number (0);
14301 w
->window_end_valid
= Qnil
;
14303 /* Update hint: don't try scrolling again in update_window. */
14304 w
->desired_matrix
->no_scrolling_p
= 1;
14307 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14311 else if (CHARPOS (new_start
) > CHARPOS (start
))
14313 struct glyph_row
*pt_row
, *row
;
14314 struct glyph_row
*first_reusable_row
;
14315 struct glyph_row
*first_row_to_display
;
14317 int yb
= window_text_bottom_y (w
);
14319 /* Find the row starting at new_start, if there is one. Don't
14320 reuse a partially visible line at the end. */
14321 first_reusable_row
= start_row
;
14322 while (first_reusable_row
->enabled_p
14323 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14324 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14325 < CHARPOS (new_start
)))
14326 ++first_reusable_row
;
14328 /* Give up if there is no row to reuse. */
14329 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14330 || !first_reusable_row
->enabled_p
14331 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14332 != CHARPOS (new_start
)))
14335 /* We can reuse fully visible rows beginning with
14336 first_reusable_row to the end of the window. Set
14337 first_row_to_display to the first row that cannot be reused.
14338 Set pt_row to the row containing point, if there is any. */
14340 for (first_row_to_display
= first_reusable_row
;
14341 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14342 ++first_row_to_display
)
14344 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14345 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14346 pt_row
= first_row_to_display
;
14349 /* Start displaying at the start of first_row_to_display. */
14350 xassert (first_row_to_display
->y
< yb
);
14351 init_to_row_start (&it
, w
, first_row_to_display
);
14353 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14355 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14357 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14358 + WINDOW_HEADER_LINE_HEIGHT (w
));
14360 /* Display lines beginning with first_row_to_display in the
14361 desired matrix. Set last_text_row to the last row displayed
14362 that displays text. */
14363 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14364 if (pt_row
== NULL
)
14365 w
->cursor
.vpos
= -1;
14366 last_text_row
= NULL
;
14367 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14368 if (display_line (&it
))
14369 last_text_row
= it
.glyph_row
- 1;
14371 /* If point is in a reused row, adjust y and vpos of the cursor
14375 w
->cursor
.vpos
-= nrows_scrolled
;
14376 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14379 /* Give up if point isn't in a row displayed or reused. (This
14380 also handles the case where w->cursor.vpos < nrows_scrolled
14381 after the calls to display_line, which can happen with scroll
14382 margins. See bug#1295.) */
14383 if (w
->cursor
.vpos
< 0)
14385 clear_glyph_matrix (w
->desired_matrix
);
14389 /* Scroll the display. */
14390 run
.current_y
= first_reusable_row
->y
;
14391 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14392 run
.height
= it
.last_visible_y
- run
.current_y
;
14393 dy
= run
.current_y
- run
.desired_y
;
14398 FRAME_RIF (f
)->update_window_begin_hook (w
);
14399 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14400 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14401 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14405 /* Adjust Y positions of reused rows. */
14406 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14407 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14408 max_y
= it
.last_visible_y
;
14409 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14412 row
->visible_height
= row
->height
;
14413 if (row
->y
< min_y
)
14414 row
->visible_height
-= min_y
- row
->y
;
14415 if (row
->y
+ row
->height
> max_y
)
14416 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14417 row
->redraw_fringe_bitmaps_p
= 1;
14420 /* Scroll the current matrix. */
14421 xassert (nrows_scrolled
> 0);
14422 rotate_matrix (w
->current_matrix
,
14424 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14427 /* Disable rows not reused. */
14428 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14429 row
->enabled_p
= 0;
14431 /* Point may have moved to a different line, so we cannot assume that
14432 the previous cursor position is valid; locate the correct row. */
14435 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14436 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14440 w
->cursor
.y
= row
->y
;
14442 if (row
< bottom_row
)
14444 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14445 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14448 && (!BUFFERP (glyph
->object
)
14449 || glyph
->charpos
< PT
);
14453 w
->cursor
.x
+= glyph
->pixel_width
;
14458 /* Adjust window end. A null value of last_text_row means that
14459 the window end is in reused rows which in turn means that
14460 only its vpos can have changed. */
14463 w
->window_end_bytepos
14464 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14466 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14468 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14473 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14476 w
->window_end_valid
= Qnil
;
14477 w
->desired_matrix
->no_scrolling_p
= 1;
14480 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14490 /************************************************************************
14491 Window redisplay reusing current matrix when buffer has changed
14492 ************************************************************************/
14494 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14495 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14497 static struct glyph_row
*
14498 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14499 struct glyph_row
*));
14502 /* Return the last row in MATRIX displaying text. If row START is
14503 non-null, start searching with that row. IT gives the dimensions
14504 of the display. Value is null if matrix is empty; otherwise it is
14505 a pointer to the row found. */
14507 static struct glyph_row
*
14508 find_last_row_displaying_text (matrix
, it
, start
)
14509 struct glyph_matrix
*matrix
;
14511 struct glyph_row
*start
;
14513 struct glyph_row
*row
, *row_found
;
14515 /* Set row_found to the last row in IT->w's current matrix
14516 displaying text. The loop looks funny but think of partially
14519 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14520 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14522 xassert (row
->enabled_p
);
14524 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14533 /* Return the last row in the current matrix of W that is not affected
14534 by changes at the start of current_buffer that occurred since W's
14535 current matrix was built. Value is null if no such row exists.
14537 BEG_UNCHANGED us the number of characters unchanged at the start of
14538 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14539 first changed character in current_buffer. Characters at positions <
14540 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14541 when the current matrix was built. */
14543 static struct glyph_row
*
14544 find_last_unchanged_at_beg_row (w
)
14547 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14548 struct glyph_row
*row
;
14549 struct glyph_row
*row_found
= NULL
;
14550 int yb
= window_text_bottom_y (w
);
14552 /* Find the last row displaying unchanged text. */
14553 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14554 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14555 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14558 if (/* If row ends before first_changed_pos, it is unchanged,
14559 except in some case. */
14560 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14561 /* When row ends in ZV and we write at ZV it is not
14563 && !row
->ends_at_zv_p
14564 /* When first_changed_pos is the end of a continued line,
14565 row is not unchanged because it may be no longer
14567 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14568 && (row
->continued_p
14569 || row
->exact_window_width_line_p
)))
14572 /* Stop if last visible row. */
14573 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14581 /* Find the first glyph row in the current matrix of W that is not
14582 affected by changes at the end of current_buffer since the
14583 time W's current matrix was built.
14585 Return in *DELTA the number of chars by which buffer positions in
14586 unchanged text at the end of current_buffer must be adjusted.
14588 Return in *DELTA_BYTES the corresponding number of bytes.
14590 Value is null if no such row exists, i.e. all rows are affected by
14593 static struct glyph_row
*
14594 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14596 int *delta
, *delta_bytes
;
14598 struct glyph_row
*row
;
14599 struct glyph_row
*row_found
= NULL
;
14601 *delta
= *delta_bytes
= 0;
14603 /* Display must not have been paused, otherwise the current matrix
14604 is not up to date. */
14605 eassert (!NILP (w
->window_end_valid
));
14607 /* A value of window_end_pos >= END_UNCHANGED means that the window
14608 end is in the range of changed text. If so, there is no
14609 unchanged row at the end of W's current matrix. */
14610 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14613 /* Set row to the last row in W's current matrix displaying text. */
14614 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14616 /* If matrix is entirely empty, no unchanged row exists. */
14617 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14619 /* The value of row is the last glyph row in the matrix having a
14620 meaningful buffer position in it. The end position of row
14621 corresponds to window_end_pos. This allows us to translate
14622 buffer positions in the current matrix to current buffer
14623 positions for characters not in changed text. */
14624 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14625 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14626 int last_unchanged_pos
, last_unchanged_pos_old
;
14627 struct glyph_row
*first_text_row
14628 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14630 *delta
= Z
- Z_old
;
14631 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14633 /* Set last_unchanged_pos to the buffer position of the last
14634 character in the buffer that has not been changed. Z is the
14635 index + 1 of the last character in current_buffer, i.e. by
14636 subtracting END_UNCHANGED we get the index of the last
14637 unchanged character, and we have to add BEG to get its buffer
14639 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14640 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14642 /* Search backward from ROW for a row displaying a line that
14643 starts at a minimum position >= last_unchanged_pos_old. */
14644 for (; row
> first_text_row
; --row
)
14646 /* This used to abort, but it can happen.
14647 It is ok to just stop the search instead here. KFS. */
14648 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14651 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14656 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14662 /* Make sure that glyph rows in the current matrix of window W
14663 reference the same glyph memory as corresponding rows in the
14664 frame's frame matrix. This function is called after scrolling W's
14665 current matrix on a terminal frame in try_window_id and
14666 try_window_reusing_current_matrix. */
14669 sync_frame_with_window_matrix_rows (w
)
14672 struct frame
*f
= XFRAME (w
->frame
);
14673 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14675 /* Preconditions: W must be a leaf window and full-width. Its frame
14676 must have a frame matrix. */
14677 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14678 xassert (WINDOW_FULL_WIDTH_P (w
));
14679 xassert (!FRAME_WINDOW_P (f
));
14681 /* If W is a full-width window, glyph pointers in W's current matrix
14682 have, by definition, to be the same as glyph pointers in the
14683 corresponding frame matrix. Note that frame matrices have no
14684 marginal areas (see build_frame_matrix). */
14685 window_row
= w
->current_matrix
->rows
;
14686 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14687 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14688 while (window_row
< window_row_end
)
14690 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14691 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14693 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14694 frame_row
->glyphs
[TEXT_AREA
] = start
;
14695 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14696 frame_row
->glyphs
[LAST_AREA
] = end
;
14698 /* Disable frame rows whose corresponding window rows have
14699 been disabled in try_window_id. */
14700 if (!window_row
->enabled_p
)
14701 frame_row
->enabled_p
= 0;
14703 ++window_row
, ++frame_row
;
14708 /* Find the glyph row in window W containing CHARPOS. Consider all
14709 rows between START and END (not inclusive). END null means search
14710 all rows to the end of the display area of W. Value is the row
14711 containing CHARPOS or null. */
14714 row_containing_pos (w
, charpos
, start
, end
, dy
)
14717 struct glyph_row
*start
, *end
;
14720 struct glyph_row
*row
= start
;
14723 /* If we happen to start on a header-line, skip that. */
14724 if (row
->mode_line_p
)
14727 if ((end
&& row
>= end
) || !row
->enabled_p
)
14730 last_y
= window_text_bottom_y (w
) - dy
;
14734 /* Give up if we have gone too far. */
14735 if (end
&& row
>= end
)
14737 /* This formerly returned if they were equal.
14738 I think that both quantities are of a "last plus one" type;
14739 if so, when they are equal, the row is within the screen. -- rms. */
14740 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14743 /* If it is in this row, return this row. */
14744 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14745 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14746 /* The end position of a row equals the start
14747 position of the next row. If CHARPOS is there, we
14748 would rather display it in the next line, except
14749 when this line ends in ZV. */
14750 && !row
->ends_at_zv_p
14751 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14752 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14759 /* Try to redisplay window W by reusing its existing display. W's
14760 current matrix must be up to date when this function is called,
14761 i.e. window_end_valid must not be nil.
14765 1 if display has been updated
14766 0 if otherwise unsuccessful
14767 -1 if redisplay with same window start is known not to succeed
14769 The following steps are performed:
14771 1. Find the last row in the current matrix of W that is not
14772 affected by changes at the start of current_buffer. If no such row
14775 2. Find the first row in W's current matrix that is not affected by
14776 changes at the end of current_buffer. Maybe there is no such row.
14778 3. Display lines beginning with the row + 1 found in step 1 to the
14779 row found in step 2 or, if step 2 didn't find a row, to the end of
14782 4. If cursor is not known to appear on the window, give up.
14784 5. If display stopped at the row found in step 2, scroll the
14785 display and current matrix as needed.
14787 6. Maybe display some lines at the end of W, if we must. This can
14788 happen under various circumstances, like a partially visible line
14789 becoming fully visible, or because newly displayed lines are displayed
14790 in smaller font sizes.
14792 7. Update W's window end information. */
14798 struct frame
*f
= XFRAME (w
->frame
);
14799 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14800 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14801 struct glyph_row
*last_unchanged_at_beg_row
;
14802 struct glyph_row
*first_unchanged_at_end_row
;
14803 struct glyph_row
*row
;
14804 struct glyph_row
*bottom_row
;
14807 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14808 struct text_pos start_pos
;
14810 int first_unchanged_at_end_vpos
= 0;
14811 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14812 struct text_pos start
;
14813 int first_changed_charpos
, last_changed_charpos
;
14816 if (inhibit_try_window_id
)
14820 /* This is handy for debugging. */
14822 #define GIVE_UP(X) \
14824 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14828 #define GIVE_UP(X) return 0
14831 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14833 /* Don't use this for mini-windows because these can show
14834 messages and mini-buffers, and we don't handle that here. */
14835 if (MINI_WINDOW_P (w
))
14838 /* This flag is used to prevent redisplay optimizations. */
14839 if (windows_or_buffers_changed
|| cursor_type_changed
)
14842 /* Verify that narrowing has not changed.
14843 Also verify that we were not told to prevent redisplay optimizations.
14844 It would be nice to further
14845 reduce the number of cases where this prevents try_window_id. */
14846 if (current_buffer
->clip_changed
14847 || current_buffer
->prevent_redisplay_optimizations_p
)
14850 /* Window must either use window-based redisplay or be full width. */
14851 if (!FRAME_WINDOW_P (f
)
14852 && (!FRAME_LINE_INS_DEL_OK (f
)
14853 || !WINDOW_FULL_WIDTH_P (w
)))
14856 /* Give up if point is not known NOT to appear in W. */
14857 if (PT
< CHARPOS (start
))
14860 /* Another way to prevent redisplay optimizations. */
14861 if (XFASTINT (w
->last_modified
) == 0)
14864 /* Verify that window is not hscrolled. */
14865 if (XFASTINT (w
->hscroll
) != 0)
14868 /* Verify that display wasn't paused. */
14869 if (NILP (w
->window_end_valid
))
14872 /* Can't use this if highlighting a region because a cursor movement
14873 will do more than just set the cursor. */
14874 if (!NILP (Vtransient_mark_mode
)
14875 && !NILP (current_buffer
->mark_active
))
14878 /* Likewise if highlighting trailing whitespace. */
14879 if (!NILP (Vshow_trailing_whitespace
))
14882 /* Likewise if showing a region. */
14883 if (!NILP (w
->region_showing
))
14886 /* Can use this if overlay arrow position and or string have changed. */
14887 if (overlay_arrows_changed_p ())
14890 /* When word-wrap is on, adding a space to the first word of a
14891 wrapped line can change the wrap position, altering the line
14892 above it. It might be worthwhile to handle this more
14893 intelligently, but for now just redisplay from scratch. */
14894 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14897 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14898 only if buffer has really changed. The reason is that the gap is
14899 initially at Z for freshly visited files. The code below would
14900 set end_unchanged to 0 in that case. */
14901 if (MODIFF
> SAVE_MODIFF
14902 /* This seems to happen sometimes after saving a buffer. */
14903 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14905 if (GPT
- BEG
< BEG_UNCHANGED
)
14906 BEG_UNCHANGED
= GPT
- BEG
;
14907 if (Z
- GPT
< END_UNCHANGED
)
14908 END_UNCHANGED
= Z
- GPT
;
14911 /* The position of the first and last character that has been changed. */
14912 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14913 last_changed_charpos
= Z
- END_UNCHANGED
;
14915 /* If window starts after a line end, and the last change is in
14916 front of that newline, then changes don't affect the display.
14917 This case happens with stealth-fontification. Note that although
14918 the display is unchanged, glyph positions in the matrix have to
14919 be adjusted, of course. */
14920 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14921 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14922 && ((last_changed_charpos
< CHARPOS (start
)
14923 && CHARPOS (start
) == BEGV
)
14924 || (last_changed_charpos
< CHARPOS (start
) - 1
14925 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14927 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14928 struct glyph_row
*r0
;
14930 /* Compute how many chars/bytes have been added to or removed
14931 from the buffer. */
14932 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14933 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14935 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14937 /* Give up if PT is not in the window. Note that it already has
14938 been checked at the start of try_window_id that PT is not in
14939 front of the window start. */
14940 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14943 /* If window start is unchanged, we can reuse the whole matrix
14944 as is, after adjusting glyph positions. No need to compute
14945 the window end again, since its offset from Z hasn't changed. */
14946 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14947 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14948 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14949 /* PT must not be in a partially visible line. */
14950 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14951 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14953 /* Adjust positions in the glyph matrix. */
14954 if (delta
|| delta_bytes
)
14956 struct glyph_row
*r1
14957 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14958 increment_matrix_positions (w
->current_matrix
,
14959 MATRIX_ROW_VPOS (r0
, current_matrix
),
14960 MATRIX_ROW_VPOS (r1
, current_matrix
),
14961 delta
, delta_bytes
);
14964 /* Set the cursor. */
14965 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14967 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14974 /* Handle the case that changes are all below what is displayed in
14975 the window, and that PT is in the window. This shortcut cannot
14976 be taken if ZV is visible in the window, and text has been added
14977 there that is visible in the window. */
14978 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14979 /* ZV is not visible in the window, or there are no
14980 changes at ZV, actually. */
14981 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14982 || first_changed_charpos
== last_changed_charpos
))
14984 struct glyph_row
*r0
;
14986 /* Give up if PT is not in the window. Note that it already has
14987 been checked at the start of try_window_id that PT is not in
14988 front of the window start. */
14989 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14992 /* If window start is unchanged, we can reuse the whole matrix
14993 as is, without changing glyph positions since no text has
14994 been added/removed in front of the window end. */
14995 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14996 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14997 /* PT must not be in a partially visible line. */
14998 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14999 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15001 /* We have to compute the window end anew since text
15002 can have been added/removed after it. */
15004 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15005 w
->window_end_bytepos
15006 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15008 /* Set the cursor. */
15009 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15011 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15018 /* Give up if window start is in the changed area.
15020 The condition used to read
15022 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15024 but why that was tested escapes me at the moment. */
15025 if (CHARPOS (start
) >= first_changed_charpos
15026 && CHARPOS (start
) <= last_changed_charpos
)
15029 /* Check that window start agrees with the start of the first glyph
15030 row in its current matrix. Check this after we know the window
15031 start is not in changed text, otherwise positions would not be
15033 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15034 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15037 /* Give up if the window ends in strings. Overlay strings
15038 at the end are difficult to handle, so don't try. */
15039 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15040 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15043 /* Compute the position at which we have to start displaying new
15044 lines. Some of the lines at the top of the window might be
15045 reusable because they are not displaying changed text. Find the
15046 last row in W's current matrix not affected by changes at the
15047 start of current_buffer. Value is null if changes start in the
15048 first line of window. */
15049 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15050 if (last_unchanged_at_beg_row
)
15052 /* Avoid starting to display in the moddle of a character, a TAB
15053 for instance. This is easier than to set up the iterator
15054 exactly, and it's not a frequent case, so the additional
15055 effort wouldn't really pay off. */
15056 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15057 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15058 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15059 --last_unchanged_at_beg_row
;
15061 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15064 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15066 start_pos
= it
.current
.pos
;
15068 /* Start displaying new lines in the desired matrix at the same
15069 vpos we would use in the current matrix, i.e. below
15070 last_unchanged_at_beg_row. */
15071 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15073 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15074 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15076 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15080 /* There are no reusable lines at the start of the window.
15081 Start displaying in the first text line. */
15082 start_display (&it
, w
, start
);
15083 it
.vpos
= it
.first_vpos
;
15084 start_pos
= it
.current
.pos
;
15087 /* Find the first row that is not affected by changes at the end of
15088 the buffer. Value will be null if there is no unchanged row, in
15089 which case we must redisplay to the end of the window. delta
15090 will be set to the value by which buffer positions beginning with
15091 first_unchanged_at_end_row have to be adjusted due to text
15093 first_unchanged_at_end_row
15094 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15095 IF_DEBUG (debug_delta
= delta
);
15096 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15098 /* Set stop_pos to the buffer position up to which we will have to
15099 display new lines. If first_unchanged_at_end_row != NULL, this
15100 is the buffer position of the start of the line displayed in that
15101 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15102 that we don't stop at a buffer position. */
15104 if (first_unchanged_at_end_row
)
15106 xassert (last_unchanged_at_beg_row
== NULL
15107 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15109 /* If this is a continuation line, move forward to the next one
15110 that isn't. Changes in lines above affect this line.
15111 Caution: this may move first_unchanged_at_end_row to a row
15112 not displaying text. */
15113 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15114 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15115 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15116 < it
.last_visible_y
))
15117 ++first_unchanged_at_end_row
;
15119 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15120 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15121 >= it
.last_visible_y
))
15122 first_unchanged_at_end_row
= NULL
;
15125 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15127 first_unchanged_at_end_vpos
15128 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15129 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15132 else if (last_unchanged_at_beg_row
== NULL
)
15138 /* Either there is no unchanged row at the end, or the one we have
15139 now displays text. This is a necessary condition for the window
15140 end pos calculation at the end of this function. */
15141 xassert (first_unchanged_at_end_row
== NULL
15142 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15144 debug_last_unchanged_at_beg_vpos
15145 = (last_unchanged_at_beg_row
15146 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15148 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15150 #endif /* GLYPH_DEBUG != 0 */
15153 /* Display new lines. Set last_text_row to the last new line
15154 displayed which has text on it, i.e. might end up as being the
15155 line where the window_end_vpos is. */
15156 w
->cursor
.vpos
= -1;
15157 last_text_row
= NULL
;
15158 overlay_arrow_seen
= 0;
15159 while (it
.current_y
< it
.last_visible_y
15160 && !fonts_changed_p
15161 && (first_unchanged_at_end_row
== NULL
15162 || IT_CHARPOS (it
) < stop_pos
))
15164 if (display_line (&it
))
15165 last_text_row
= it
.glyph_row
- 1;
15168 if (fonts_changed_p
)
15172 /* Compute differences in buffer positions, y-positions etc. for
15173 lines reused at the bottom of the window. Compute what we can
15175 if (first_unchanged_at_end_row
15176 /* No lines reused because we displayed everything up to the
15177 bottom of the window. */
15178 && it
.current_y
< it
.last_visible_y
)
15181 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15183 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15184 run
.current_y
= first_unchanged_at_end_row
->y
;
15185 run
.desired_y
= run
.current_y
+ dy
;
15186 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15190 delta
= delta_bytes
= dvpos
= dy
15191 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15192 first_unchanged_at_end_row
= NULL
;
15194 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15197 /* Find the cursor if not already found. We have to decide whether
15198 PT will appear on this window (it sometimes doesn't, but this is
15199 not a very frequent case.) This decision has to be made before
15200 the current matrix is altered. A value of cursor.vpos < 0 means
15201 that PT is either in one of the lines beginning at
15202 first_unchanged_at_end_row or below the window. Don't care for
15203 lines that might be displayed later at the window end; as
15204 mentioned, this is not a frequent case. */
15205 if (w
->cursor
.vpos
< 0)
15207 /* Cursor in unchanged rows at the top? */
15208 if (PT
< CHARPOS (start_pos
)
15209 && last_unchanged_at_beg_row
)
15211 row
= row_containing_pos (w
, PT
,
15212 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15213 last_unchanged_at_beg_row
+ 1, 0);
15215 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15218 /* Start from first_unchanged_at_end_row looking for PT. */
15219 else if (first_unchanged_at_end_row
)
15221 row
= row_containing_pos (w
, PT
- delta
,
15222 first_unchanged_at_end_row
, NULL
, 0);
15224 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15225 delta_bytes
, dy
, dvpos
);
15228 /* Give up if cursor was not found. */
15229 if (w
->cursor
.vpos
< 0)
15231 clear_glyph_matrix (w
->desired_matrix
);
15236 /* Don't let the cursor end in the scroll margins. */
15238 int this_scroll_margin
, cursor_height
;
15240 this_scroll_margin
= max (0, scroll_margin
);
15241 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15242 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15243 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15245 if ((w
->cursor
.y
< this_scroll_margin
15246 && CHARPOS (start
) > BEGV
)
15247 /* Old redisplay didn't take scroll margin into account at the bottom,
15248 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15249 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15250 ? cursor_height
+ this_scroll_margin
15251 : 1)) > it
.last_visible_y
)
15253 w
->cursor
.vpos
= -1;
15254 clear_glyph_matrix (w
->desired_matrix
);
15259 /* Scroll the display. Do it before changing the current matrix so
15260 that xterm.c doesn't get confused about where the cursor glyph is
15262 if (dy
&& run
.height
)
15266 if (FRAME_WINDOW_P (f
))
15268 FRAME_RIF (f
)->update_window_begin_hook (w
);
15269 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15270 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15271 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15275 /* Terminal frame. In this case, dvpos gives the number of
15276 lines to scroll by; dvpos < 0 means scroll up. */
15277 int first_unchanged_at_end_vpos
15278 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15279 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15280 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15281 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15282 + window_internal_height (w
));
15284 /* Perform the operation on the screen. */
15287 /* Scroll last_unchanged_at_beg_row to the end of the
15288 window down dvpos lines. */
15289 set_terminal_window (f
, end
);
15291 /* On dumb terminals delete dvpos lines at the end
15292 before inserting dvpos empty lines. */
15293 if (!FRAME_SCROLL_REGION_OK (f
))
15294 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15296 /* Insert dvpos empty lines in front of
15297 last_unchanged_at_beg_row. */
15298 ins_del_lines (f
, from
, dvpos
);
15300 else if (dvpos
< 0)
15302 /* Scroll up last_unchanged_at_beg_vpos to the end of
15303 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15304 set_terminal_window (f
, end
);
15306 /* Delete dvpos lines in front of
15307 last_unchanged_at_beg_vpos. ins_del_lines will set
15308 the cursor to the given vpos and emit |dvpos| delete
15310 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15312 /* On a dumb terminal insert dvpos empty lines at the
15314 if (!FRAME_SCROLL_REGION_OK (f
))
15315 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15318 set_terminal_window (f
, 0);
15324 /* Shift reused rows of the current matrix to the right position.
15325 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15327 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15328 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15331 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15332 bottom_vpos
, dvpos
);
15333 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15336 else if (dvpos
> 0)
15338 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15339 bottom_vpos
, dvpos
);
15340 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15341 first_unchanged_at_end_vpos
+ dvpos
, 0);
15344 /* For frame-based redisplay, make sure that current frame and window
15345 matrix are in sync with respect to glyph memory. */
15346 if (!FRAME_WINDOW_P (f
))
15347 sync_frame_with_window_matrix_rows (w
);
15349 /* Adjust buffer positions in reused rows. */
15350 if (delta
|| delta_bytes
)
15351 increment_matrix_positions (current_matrix
,
15352 first_unchanged_at_end_vpos
+ dvpos
,
15353 bottom_vpos
, delta
, delta_bytes
);
15355 /* Adjust Y positions. */
15357 shift_glyph_matrix (w
, current_matrix
,
15358 first_unchanged_at_end_vpos
+ dvpos
,
15361 if (first_unchanged_at_end_row
)
15363 first_unchanged_at_end_row
+= dvpos
;
15364 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15365 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15366 first_unchanged_at_end_row
= NULL
;
15369 /* If scrolling up, there may be some lines to display at the end of
15371 last_text_row_at_end
= NULL
;
15374 /* Scrolling up can leave for example a partially visible line
15375 at the end of the window to be redisplayed. */
15376 /* Set last_row to the glyph row in the current matrix where the
15377 window end line is found. It has been moved up or down in
15378 the matrix by dvpos. */
15379 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15380 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15382 /* If last_row is the window end line, it should display text. */
15383 xassert (last_row
->displays_text_p
);
15385 /* If window end line was partially visible before, begin
15386 displaying at that line. Otherwise begin displaying with the
15387 line following it. */
15388 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15390 init_to_row_start (&it
, w
, last_row
);
15391 it
.vpos
= last_vpos
;
15392 it
.current_y
= last_row
->y
;
15396 init_to_row_end (&it
, w
, last_row
);
15397 it
.vpos
= 1 + last_vpos
;
15398 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15402 /* We may start in a continuation line. If so, we have to
15403 get the right continuation_lines_width and current_x. */
15404 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15405 it
.hpos
= it
.current_x
= 0;
15407 /* Display the rest of the lines at the window end. */
15408 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15409 while (it
.current_y
< it
.last_visible_y
15410 && !fonts_changed_p
)
15412 /* Is it always sure that the display agrees with lines in
15413 the current matrix? I don't think so, so we mark rows
15414 displayed invalid in the current matrix by setting their
15415 enabled_p flag to zero. */
15416 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15417 if (display_line (&it
))
15418 last_text_row_at_end
= it
.glyph_row
- 1;
15422 /* Update window_end_pos and window_end_vpos. */
15423 if (first_unchanged_at_end_row
15424 && !last_text_row_at_end
)
15426 /* Window end line if one of the preserved rows from the current
15427 matrix. Set row to the last row displaying text in current
15428 matrix starting at first_unchanged_at_end_row, after
15430 xassert (first_unchanged_at_end_row
->displays_text_p
);
15431 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15432 first_unchanged_at_end_row
);
15433 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15435 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15436 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15438 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15439 xassert (w
->window_end_bytepos
>= 0);
15440 IF_DEBUG (debug_method_add (w
, "A"));
15442 else if (last_text_row_at_end
)
15445 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15446 w
->window_end_bytepos
15447 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15449 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15450 xassert (w
->window_end_bytepos
>= 0);
15451 IF_DEBUG (debug_method_add (w
, "B"));
15453 else if (last_text_row
)
15455 /* We have displayed either to the end of the window or at the
15456 end of the window, i.e. the last row with text is to be found
15457 in the desired matrix. */
15459 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15460 w
->window_end_bytepos
15461 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15463 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15464 xassert (w
->window_end_bytepos
>= 0);
15466 else if (first_unchanged_at_end_row
== NULL
15467 && last_text_row
== NULL
15468 && last_text_row_at_end
== NULL
)
15470 /* Displayed to end of window, but no line containing text was
15471 displayed. Lines were deleted at the end of the window. */
15472 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15473 int vpos
= XFASTINT (w
->window_end_vpos
);
15474 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15475 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15478 row
== NULL
&& vpos
>= first_vpos
;
15479 --vpos
, --current_row
, --desired_row
)
15481 if (desired_row
->enabled_p
)
15483 if (desired_row
->displays_text_p
)
15486 else if (current_row
->displays_text_p
)
15490 xassert (row
!= NULL
);
15491 w
->window_end_vpos
= make_number (vpos
+ 1);
15492 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15493 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15494 xassert (w
->window_end_bytepos
>= 0);
15495 IF_DEBUG (debug_method_add (w
, "C"));
15500 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15501 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15503 /* Record that display has not been completed. */
15504 w
->window_end_valid
= Qnil
;
15505 w
->desired_matrix
->no_scrolling_p
= 1;
15513 /***********************************************************************
15514 More debugging support
15515 ***********************************************************************/
15519 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15520 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15521 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15524 /* Dump the contents of glyph matrix MATRIX on stderr.
15526 GLYPHS 0 means don't show glyph contents.
15527 GLYPHS 1 means show glyphs in short form
15528 GLYPHS > 1 means show glyphs in long form. */
15531 dump_glyph_matrix (matrix
, glyphs
)
15532 struct glyph_matrix
*matrix
;
15536 for (i
= 0; i
< matrix
->nrows
; ++i
)
15537 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15541 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15542 the glyph row and area where the glyph comes from. */
15545 dump_glyph (row
, glyph
, area
)
15546 struct glyph_row
*row
;
15547 struct glyph
*glyph
;
15550 if (glyph
->type
== CHAR_GLYPH
)
15553 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15554 glyph
- row
->glyphs
[TEXT_AREA
],
15557 (BUFFERP (glyph
->object
)
15559 : (STRINGP (glyph
->object
)
15562 glyph
->pixel_width
,
15564 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15568 glyph
->left_box_line_p
,
15569 glyph
->right_box_line_p
);
15571 else if (glyph
->type
== STRETCH_GLYPH
)
15574 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15575 glyph
- row
->glyphs
[TEXT_AREA
],
15578 (BUFFERP (glyph
->object
)
15580 : (STRINGP (glyph
->object
)
15583 glyph
->pixel_width
,
15587 glyph
->left_box_line_p
,
15588 glyph
->right_box_line_p
);
15590 else if (glyph
->type
== IMAGE_GLYPH
)
15593 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15594 glyph
- row
->glyphs
[TEXT_AREA
],
15597 (BUFFERP (glyph
->object
)
15599 : (STRINGP (glyph
->object
)
15602 glyph
->pixel_width
,
15606 glyph
->left_box_line_p
,
15607 glyph
->right_box_line_p
);
15609 else if (glyph
->type
== COMPOSITE_GLYPH
)
15612 " %5d %4c %6d %c %3d 0x%05x",
15613 glyph
- row
->glyphs
[TEXT_AREA
],
15616 (BUFFERP (glyph
->object
)
15618 : (STRINGP (glyph
->object
)
15621 glyph
->pixel_width
,
15623 if (glyph
->u
.cmp
.automatic
)
15626 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
15627 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
15629 glyph
->left_box_line_p
,
15630 glyph
->right_box_line_p
);
15635 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15636 GLYPHS 0 means don't show glyph contents.
15637 GLYPHS 1 means show glyphs in short form
15638 GLYPHS > 1 means show glyphs in long form. */
15641 dump_glyph_row (row
, vpos
, glyphs
)
15642 struct glyph_row
*row
;
15647 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15648 fprintf (stderr
, "======================================================================\n");
15650 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15651 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15653 MATRIX_ROW_START_CHARPOS (row
),
15654 MATRIX_ROW_END_CHARPOS (row
),
15655 row
->used
[TEXT_AREA
],
15656 row
->contains_overlapping_glyphs_p
,
15658 row
->truncated_on_left_p
,
15659 row
->truncated_on_right_p
,
15661 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15662 row
->displays_text_p
,
15665 row
->ends_in_middle_of_char_p
,
15666 row
->starts_in_middle_of_char_p
,
15672 row
->visible_height
,
15675 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15676 row
->end
.overlay_string_index
,
15677 row
->continuation_lines_width
);
15678 fprintf (stderr
, "%9d %5d\n",
15679 CHARPOS (row
->start
.string_pos
),
15680 CHARPOS (row
->end
.string_pos
));
15681 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15682 row
->end
.dpvec_index
);
15689 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15691 struct glyph
*glyph
= row
->glyphs
[area
];
15692 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15694 /* Glyph for a line end in text. */
15695 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15698 if (glyph
< glyph_end
)
15699 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15701 for (; glyph
< glyph_end
; ++glyph
)
15702 dump_glyph (row
, glyph
, area
);
15705 else if (glyphs
== 1)
15709 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15711 char *s
= (char *) alloca (row
->used
[area
] + 1);
15714 for (i
= 0; i
< row
->used
[area
]; ++i
)
15716 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15717 if (glyph
->type
== CHAR_GLYPH
15718 && glyph
->u
.ch
< 0x80
15719 && glyph
->u
.ch
>= ' ')
15720 s
[i
] = glyph
->u
.ch
;
15726 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15732 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15733 Sdump_glyph_matrix
, 0, 1, "p",
15734 doc
: /* Dump the current matrix of the selected window to stderr.
15735 Shows contents of glyph row structures. With non-nil
15736 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15737 glyphs in short form, otherwise show glyphs in long form. */)
15739 Lisp_Object glyphs
;
15741 struct window
*w
= XWINDOW (selected_window
);
15742 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15744 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15745 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15746 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15747 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15748 fprintf (stderr
, "=============================================\n");
15749 dump_glyph_matrix (w
->current_matrix
,
15750 NILP (glyphs
) ? 0 : XINT (glyphs
));
15755 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15756 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15759 struct frame
*f
= XFRAME (selected_frame
);
15760 dump_glyph_matrix (f
->current_matrix
, 1);
15765 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15766 doc
: /* Dump glyph row ROW to stderr.
15767 GLYPH 0 means don't dump glyphs.
15768 GLYPH 1 means dump glyphs in short form.
15769 GLYPH > 1 or omitted means dump glyphs in long form. */)
15771 Lisp_Object row
, glyphs
;
15773 struct glyph_matrix
*matrix
;
15776 CHECK_NUMBER (row
);
15777 matrix
= XWINDOW (selected_window
)->current_matrix
;
15779 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15780 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15782 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15787 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15788 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15789 GLYPH 0 means don't dump glyphs.
15790 GLYPH 1 means dump glyphs in short form.
15791 GLYPH > 1 or omitted means dump glyphs in long form. */)
15793 Lisp_Object row
, glyphs
;
15795 struct frame
*sf
= SELECTED_FRAME ();
15796 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15799 CHECK_NUMBER (row
);
15801 if (vpos
>= 0 && vpos
< m
->nrows
)
15802 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15803 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15808 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15809 doc
: /* Toggle tracing of redisplay.
15810 With ARG, turn tracing on if and only if ARG is positive. */)
15815 trace_redisplay_p
= !trace_redisplay_p
;
15818 arg
= Fprefix_numeric_value (arg
);
15819 trace_redisplay_p
= XINT (arg
) > 0;
15826 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15827 doc
: /* Like `format', but print result to stderr.
15828 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15833 Lisp_Object s
= Fformat (nargs
, args
);
15834 fprintf (stderr
, "%s", SDATA (s
));
15838 #endif /* GLYPH_DEBUG */
15842 /***********************************************************************
15843 Building Desired Matrix Rows
15844 ***********************************************************************/
15846 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15847 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15849 static struct glyph_row
*
15850 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15852 Lisp_Object overlay_arrow_string
;
15854 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15855 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15856 struct buffer
*old
= current_buffer
;
15857 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15858 int arrow_len
= SCHARS (overlay_arrow_string
);
15859 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15860 const unsigned char *p
;
15863 int n_glyphs_before
;
15865 set_buffer_temp (buffer
);
15866 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15867 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15868 SET_TEXT_POS (it
.position
, 0, 0);
15870 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15872 while (p
< arrow_end
)
15874 Lisp_Object face
, ilisp
;
15876 /* Get the next character. */
15878 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15880 it
.c
= *p
, it
.len
= 1;
15883 /* Get its face. */
15884 ilisp
= make_number (p
- arrow_string
);
15885 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15886 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15888 /* Compute its width, get its glyphs. */
15889 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15890 SET_TEXT_POS (it
.position
, -1, -1);
15891 PRODUCE_GLYPHS (&it
);
15893 /* If this character doesn't fit any more in the line, we have
15894 to remove some glyphs. */
15895 if (it
.current_x
> it
.last_visible_x
)
15897 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15902 set_buffer_temp (old
);
15903 return it
.glyph_row
;
15907 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15908 glyphs are only inserted for terminal frames since we can't really
15909 win with truncation glyphs when partially visible glyphs are
15910 involved. Which glyphs to insert is determined by
15911 produce_special_glyphs. */
15914 insert_left_trunc_glyphs (it
)
15917 struct it truncate_it
;
15918 struct glyph
*from
, *end
, *to
, *toend
;
15920 xassert (!FRAME_WINDOW_P (it
->f
));
15922 /* Get the truncation glyphs. */
15924 truncate_it
.current_x
= 0;
15925 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15926 truncate_it
.glyph_row
= &scratch_glyph_row
;
15927 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15928 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15929 truncate_it
.object
= make_number (0);
15930 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15932 /* Overwrite glyphs from IT with truncation glyphs. */
15933 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15934 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15935 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15936 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15941 /* There may be padding glyphs left over. Overwrite them too. */
15942 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15944 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15950 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15954 /* Compute the pixel height and width of IT->glyph_row.
15956 Most of the time, ascent and height of a display line will be equal
15957 to the max_ascent and max_height values of the display iterator
15958 structure. This is not the case if
15960 1. We hit ZV without displaying anything. In this case, max_ascent
15961 and max_height will be zero.
15963 2. We have some glyphs that don't contribute to the line height.
15964 (The glyph row flag contributes_to_line_height_p is for future
15965 pixmap extensions).
15967 The first case is easily covered by using default values because in
15968 these cases, the line height does not really matter, except that it
15969 must not be zero. */
15972 compute_line_metrics (it
)
15975 struct glyph_row
*row
= it
->glyph_row
;
15978 if (FRAME_WINDOW_P (it
->f
))
15980 int i
, min_y
, max_y
;
15982 /* The line may consist of one space only, that was added to
15983 place the cursor on it. If so, the row's height hasn't been
15985 if (row
->height
== 0)
15987 if (it
->max_ascent
+ it
->max_descent
== 0)
15988 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15989 row
->ascent
= it
->max_ascent
;
15990 row
->height
= it
->max_ascent
+ it
->max_descent
;
15991 row
->phys_ascent
= it
->max_phys_ascent
;
15992 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15993 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15996 /* Compute the width of this line. */
15997 row
->pixel_width
= row
->x
;
15998 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15999 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16001 xassert (row
->pixel_width
>= 0);
16002 xassert (row
->ascent
>= 0 && row
->height
> 0);
16004 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16005 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16007 /* If first line's physical ascent is larger than its logical
16008 ascent, use the physical ascent, and make the row taller.
16009 This makes accented characters fully visible. */
16010 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16011 && row
->phys_ascent
> row
->ascent
)
16013 row
->height
+= row
->phys_ascent
- row
->ascent
;
16014 row
->ascent
= row
->phys_ascent
;
16017 /* Compute how much of the line is visible. */
16018 row
->visible_height
= row
->height
;
16020 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16021 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16023 if (row
->y
< min_y
)
16024 row
->visible_height
-= min_y
- row
->y
;
16025 if (row
->y
+ row
->height
> max_y
)
16026 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16030 row
->pixel_width
= row
->used
[TEXT_AREA
];
16031 if (row
->continued_p
)
16032 row
->pixel_width
-= it
->continuation_pixel_width
;
16033 else if (row
->truncated_on_right_p
)
16034 row
->pixel_width
-= it
->truncation_pixel_width
;
16035 row
->ascent
= row
->phys_ascent
= 0;
16036 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16037 row
->extra_line_spacing
= 0;
16040 /* Compute a hash code for this row. */
16042 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16043 for (i
= 0; i
< row
->used
[area
]; ++i
)
16044 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16045 + row
->glyphs
[area
][i
].u
.val
16046 + row
->glyphs
[area
][i
].face_id
16047 + row
->glyphs
[area
][i
].padding_p
16048 + (row
->glyphs
[area
][i
].type
<< 2));
16050 it
->max_ascent
= it
->max_descent
= 0;
16051 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16055 /* Append one space to the glyph row of iterator IT if doing a
16056 window-based redisplay. The space has the same face as
16057 IT->face_id. Value is non-zero if a space was added.
16059 This function is called to make sure that there is always one glyph
16060 at the end of a glyph row that the cursor can be set on under
16061 window-systems. (If there weren't such a glyph we would not know
16062 how wide and tall a box cursor should be displayed).
16064 At the same time this space let's a nicely handle clearing to the
16065 end of the line if the row ends in italic text. */
16068 append_space_for_newline (it
, default_face_p
)
16070 int default_face_p
;
16072 if (FRAME_WINDOW_P (it
->f
))
16074 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16076 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16077 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16079 /* Save some values that must not be changed.
16080 Must save IT->c and IT->len because otherwise
16081 ITERATOR_AT_END_P wouldn't work anymore after
16082 append_space_for_newline has been called. */
16083 enum display_element_type saved_what
= it
->what
;
16084 int saved_c
= it
->c
, saved_len
= it
->len
;
16085 int saved_x
= it
->current_x
;
16086 int saved_face_id
= it
->face_id
;
16087 struct text_pos saved_pos
;
16088 Lisp_Object saved_object
;
16091 saved_object
= it
->object
;
16092 saved_pos
= it
->position
;
16094 it
->what
= IT_CHARACTER
;
16095 bzero (&it
->position
, sizeof it
->position
);
16096 it
->object
= make_number (0);
16100 if (default_face_p
)
16101 it
->face_id
= DEFAULT_FACE_ID
;
16102 else if (it
->face_before_selective_p
)
16103 it
->face_id
= it
->saved_face_id
;
16104 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16105 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16107 PRODUCE_GLYPHS (it
);
16109 it
->override_ascent
= -1;
16110 it
->constrain_row_ascent_descent_p
= 0;
16111 it
->current_x
= saved_x
;
16112 it
->object
= saved_object
;
16113 it
->position
= saved_pos
;
16114 it
->what
= saved_what
;
16115 it
->face_id
= saved_face_id
;
16116 it
->len
= saved_len
;
16126 /* Extend the face of the last glyph in the text area of IT->glyph_row
16127 to the end of the display line. Called from display_line.
16128 If the glyph row is empty, add a space glyph to it so that we
16129 know the face to draw. Set the glyph row flag fill_line_p. */
16132 extend_face_to_end_of_line (it
)
16136 struct frame
*f
= it
->f
;
16138 /* If line is already filled, do nothing. */
16139 if (it
->current_x
>= it
->last_visible_x
)
16142 /* Face extension extends the background and box of IT->face_id
16143 to the end of the line. If the background equals the background
16144 of the frame, we don't have to do anything. */
16145 if (it
->face_before_selective_p
)
16146 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16148 face
= FACE_FROM_ID (f
, it
->face_id
);
16150 if (FRAME_WINDOW_P (f
)
16151 && it
->glyph_row
->displays_text_p
16152 && face
->box
== FACE_NO_BOX
16153 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16157 /* Set the glyph row flag indicating that the face of the last glyph
16158 in the text area has to be drawn to the end of the text area. */
16159 it
->glyph_row
->fill_line_p
= 1;
16161 /* If current character of IT is not ASCII, make sure we have the
16162 ASCII face. This will be automatically undone the next time
16163 get_next_display_element returns a multibyte character. Note
16164 that the character will always be single byte in unibyte text. */
16165 if (!ASCII_CHAR_P (it
->c
))
16167 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16170 if (FRAME_WINDOW_P (f
))
16172 /* If the row is empty, add a space with the current face of IT,
16173 so that we know which face to draw. */
16174 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16176 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16177 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16178 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16183 /* Save some values that must not be changed. */
16184 int saved_x
= it
->current_x
;
16185 struct text_pos saved_pos
;
16186 Lisp_Object saved_object
;
16187 enum display_element_type saved_what
= it
->what
;
16188 int saved_face_id
= it
->face_id
;
16190 saved_object
= it
->object
;
16191 saved_pos
= it
->position
;
16193 it
->what
= IT_CHARACTER
;
16194 bzero (&it
->position
, sizeof it
->position
);
16195 it
->object
= make_number (0);
16198 it
->face_id
= face
->id
;
16200 PRODUCE_GLYPHS (it
);
16202 while (it
->current_x
<= it
->last_visible_x
)
16203 PRODUCE_GLYPHS (it
);
16205 /* Don't count these blanks really. It would let us insert a left
16206 truncation glyph below and make us set the cursor on them, maybe. */
16207 it
->current_x
= saved_x
;
16208 it
->object
= saved_object
;
16209 it
->position
= saved_pos
;
16210 it
->what
= saved_what
;
16211 it
->face_id
= saved_face_id
;
16216 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16217 trailing whitespace. */
16220 trailing_whitespace_p (charpos
)
16223 int bytepos
= CHAR_TO_BYTE (charpos
);
16226 while (bytepos
< ZV_BYTE
16227 && (c
= FETCH_CHAR (bytepos
),
16228 c
== ' ' || c
== '\t'))
16231 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16233 if (bytepos
!= PT_BYTE
)
16240 /* Highlight trailing whitespace, if any, in ROW. */
16243 highlight_trailing_whitespace (f
, row
)
16245 struct glyph_row
*row
;
16247 int used
= row
->used
[TEXT_AREA
];
16251 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16252 struct glyph
*glyph
= start
+ used
- 1;
16254 /* Skip over glyphs inserted to display the cursor at the
16255 end of a line, for extending the face of the last glyph
16256 to the end of the line on terminals, and for truncation
16257 and continuation glyphs. */
16258 while (glyph
>= start
16259 && glyph
->type
== CHAR_GLYPH
16260 && INTEGERP (glyph
->object
))
16263 /* If last glyph is a space or stretch, and it's trailing
16264 whitespace, set the face of all trailing whitespace glyphs in
16265 IT->glyph_row to `trailing-whitespace'. */
16267 && BUFFERP (glyph
->object
)
16268 && (glyph
->type
== STRETCH_GLYPH
16269 || (glyph
->type
== CHAR_GLYPH
16270 && glyph
->u
.ch
== ' '))
16271 && trailing_whitespace_p (glyph
->charpos
))
16273 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16277 while (glyph
>= start
16278 && BUFFERP (glyph
->object
)
16279 && (glyph
->type
== STRETCH_GLYPH
16280 || (glyph
->type
== CHAR_GLYPH
16281 && glyph
->u
.ch
== ' ')))
16282 (glyph
--)->face_id
= face_id
;
16288 /* Value is non-zero if glyph row ROW in window W should be
16289 used to hold the cursor. */
16292 cursor_row_p (w
, row
)
16294 struct glyph_row
*row
;
16296 int cursor_row_p
= 1;
16298 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16300 /* Suppose the row ends on a string.
16301 Unless the row is continued, that means it ends on a newline
16302 in the string. If it's anything other than a display string
16303 (e.g. a before-string from an overlay), we don't want the
16304 cursor there. (This heuristic seems to give the optimal
16305 behavior for the various types of multi-line strings.) */
16306 if (CHARPOS (row
->end
.string_pos
) >= 0)
16308 if (row
->continued_p
)
16312 /* Check for `display' property. */
16313 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16314 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16315 struct glyph
*glyph
;
16318 for (glyph
= end
; glyph
>= beg
; --glyph
)
16319 if (STRINGP (glyph
->object
))
16322 = Fget_char_property (make_number (PT
),
16326 && display_prop_string_p (prop
, glyph
->object
));
16331 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16333 /* If the row ends in middle of a real character,
16334 and the line is continued, we want the cursor here.
16335 That's because MATRIX_ROW_END_CHARPOS would equal
16336 PT if PT is before the character. */
16337 if (!row
->ends_in_ellipsis_p
)
16338 cursor_row_p
= row
->continued_p
;
16340 /* If the row ends in an ellipsis, then
16341 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16342 We want that position to be displayed after the ellipsis. */
16345 /* If the row ends at ZV, display the cursor at the end of that
16346 row instead of at the start of the row below. */
16347 else if (row
->ends_at_zv_p
)
16353 return cursor_row_p
;
16358 /* Push the display property PROP so that it will be rendered at the
16359 current position in IT. */
16362 push_display_prop (struct it
*it
, Lisp_Object prop
)
16366 /* Never display a cursor on the prefix. */
16367 it
->avoid_cursor_p
= 1;
16369 if (STRINGP (prop
))
16371 if (SCHARS (prop
) == 0)
16378 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16379 it
->current
.overlay_string_index
= -1;
16380 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16381 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16382 it
->method
= GET_FROM_STRING
;
16383 it
->stop_charpos
= 0;
16385 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16387 it
->method
= GET_FROM_STRETCH
;
16390 #ifdef HAVE_WINDOW_SYSTEM
16391 else if (IMAGEP (prop
))
16393 it
->what
= IT_IMAGE
;
16394 it
->image_id
= lookup_image (it
->f
, prop
);
16395 it
->method
= GET_FROM_IMAGE
;
16397 #endif /* HAVE_WINDOW_SYSTEM */
16400 pop_it (it
); /* bogus display property, give up */
16405 /* Return the character-property PROP at the current position in IT. */
16408 get_it_property (it
, prop
)
16412 Lisp_Object position
;
16414 if (STRINGP (it
->object
))
16415 position
= make_number (IT_STRING_CHARPOS (*it
));
16416 else if (BUFFERP (it
->object
))
16417 position
= make_number (IT_CHARPOS (*it
));
16421 return Fget_char_property (position
, prop
, it
->object
);
16424 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16427 handle_line_prefix (struct it
*it
)
16429 Lisp_Object prefix
;
16430 if (it
->continuation_lines_width
> 0)
16432 prefix
= get_it_property (it
, Qwrap_prefix
);
16434 prefix
= Vwrap_prefix
;
16438 prefix
= get_it_property (it
, Qline_prefix
);
16440 prefix
= Vline_prefix
;
16442 if (! NILP (prefix
))
16444 push_display_prop (it
, prefix
);
16445 /* If the prefix is wider than the window, and we try to wrap
16446 it, it would acquire its own wrap prefix, and so on till the
16447 iterator stack overflows. So, don't wrap the prefix. */
16448 it
->line_wrap
= TRUNCATE
;
16454 /* Construct the glyph row IT->glyph_row in the desired matrix of
16455 IT->w from text at the current position of IT. See dispextern.h
16456 for an overview of struct it. Value is non-zero if
16457 IT->glyph_row displays text, as opposed to a line displaying ZV
16464 struct glyph_row
*row
= it
->glyph_row
;
16465 Lisp_Object overlay_arrow_string
;
16467 int may_wrap
= 0, wrap_x
;
16468 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16469 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16470 int wrap_row_extra_line_spacing
;
16472 /* We always start displaying at hpos zero even if hscrolled. */
16473 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16475 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16476 >= it
->w
->desired_matrix
->nrows
)
16478 it
->w
->nrows_scale_factor
++;
16479 fonts_changed_p
= 1;
16483 /* Is IT->w showing the region? */
16484 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16486 /* Clear the result glyph row and enable it. */
16487 prepare_desired_row (row
);
16489 row
->y
= it
->current_y
;
16490 row
->start
= it
->start
;
16491 row
->continuation_lines_width
= it
->continuation_lines_width
;
16492 row
->displays_text_p
= 1;
16493 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16494 it
->starts_in_middle_of_char_p
= 0;
16496 /* Arrange the overlays nicely for our purposes. Usually, we call
16497 display_line on only one line at a time, in which case this
16498 can't really hurt too much, or we call it on lines which appear
16499 one after another in the buffer, in which case all calls to
16500 recenter_overlay_lists but the first will be pretty cheap. */
16501 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16503 /* Move over display elements that are not visible because we are
16504 hscrolled. This may stop at an x-position < IT->first_visible_x
16505 if the first glyph is partially visible or if we hit a line end. */
16506 if (it
->current_x
< it
->first_visible_x
)
16508 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16509 MOVE_TO_POS
| MOVE_TO_X
);
16513 /* We only do this when not calling `move_it_in_display_line_to'
16514 above, because move_it_in_display_line_to calls
16515 handle_line_prefix itself. */
16516 handle_line_prefix (it
);
16519 /* Get the initial row height. This is either the height of the
16520 text hscrolled, if there is any, or zero. */
16521 row
->ascent
= it
->max_ascent
;
16522 row
->height
= it
->max_ascent
+ it
->max_descent
;
16523 row
->phys_ascent
= it
->max_phys_ascent
;
16524 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16525 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16527 /* Loop generating characters. The loop is left with IT on the next
16528 character to display. */
16531 int n_glyphs_before
, hpos_before
, x_before
;
16533 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16535 /* Retrieve the next thing to display. Value is zero if end of
16537 if (!get_next_display_element (it
))
16539 /* Maybe add a space at the end of this line that is used to
16540 display the cursor there under X. Set the charpos of the
16541 first glyph of blank lines not corresponding to any text
16543 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16544 row
->exact_window_width_line_p
= 1;
16545 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16546 || row
->used
[TEXT_AREA
] == 0)
16548 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16549 row
->displays_text_p
= 0;
16551 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16552 && (!MINI_WINDOW_P (it
->w
)
16553 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16554 row
->indicate_empty_line_p
= 1;
16557 it
->continuation_lines_width
= 0;
16558 row
->ends_at_zv_p
= 1;
16562 /* Now, get the metrics of what we want to display. This also
16563 generates glyphs in `row' (which is IT->glyph_row). */
16564 n_glyphs_before
= row
->used
[TEXT_AREA
];
16567 /* Remember the line height so far in case the next element doesn't
16568 fit on the line. */
16569 if (it
->line_wrap
!= TRUNCATE
)
16571 ascent
= it
->max_ascent
;
16572 descent
= it
->max_descent
;
16573 phys_ascent
= it
->max_phys_ascent
;
16574 phys_descent
= it
->max_phys_descent
;
16576 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16578 if (IT_DISPLAYING_WHITESPACE (it
))
16584 wrap_row_used
= row
->used
[TEXT_AREA
];
16585 wrap_row_ascent
= row
->ascent
;
16586 wrap_row_height
= row
->height
;
16587 wrap_row_phys_ascent
= row
->phys_ascent
;
16588 wrap_row_phys_height
= row
->phys_height
;
16589 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16595 PRODUCE_GLYPHS (it
);
16597 /* If this display element was in marginal areas, continue with
16599 if (it
->area
!= TEXT_AREA
)
16601 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16602 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16603 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16604 row
->phys_height
= max (row
->phys_height
,
16605 it
->max_phys_ascent
+ it
->max_phys_descent
);
16606 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16607 it
->max_extra_line_spacing
);
16608 set_iterator_to_next (it
, 1);
16612 /* Does the display element fit on the line? If we truncate
16613 lines, we should draw past the right edge of the window. If
16614 we don't truncate, we want to stop so that we can display the
16615 continuation glyph before the right margin. If lines are
16616 continued, there are two possible strategies for characters
16617 resulting in more than 1 glyph (e.g. tabs): Display as many
16618 glyphs as possible in this line and leave the rest for the
16619 continuation line, or display the whole element in the next
16620 line. Original redisplay did the former, so we do it also. */
16621 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16622 hpos_before
= it
->hpos
;
16625 if (/* Not a newline. */
16627 /* Glyphs produced fit entirely in the line. */
16628 && it
->current_x
< it
->last_visible_x
)
16630 it
->hpos
+= nglyphs
;
16631 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16632 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16633 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16634 row
->phys_height
= max (row
->phys_height
,
16635 it
->max_phys_ascent
+ it
->max_phys_descent
);
16636 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16637 it
->max_extra_line_spacing
);
16638 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16639 row
->x
= x
- it
->first_visible_x
;
16644 struct glyph
*glyph
;
16646 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16648 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16649 new_x
= x
+ glyph
->pixel_width
;
16651 if (/* Lines are continued. */
16652 it
->line_wrap
!= TRUNCATE
16653 && (/* Glyph doesn't fit on the line. */
16654 new_x
> it
->last_visible_x
16655 /* Or it fits exactly on a window system frame. */
16656 || (new_x
== it
->last_visible_x
16657 && FRAME_WINDOW_P (it
->f
))))
16659 /* End of a continued line. */
16662 || (new_x
== it
->last_visible_x
16663 && FRAME_WINDOW_P (it
->f
)))
16665 /* Current glyph is the only one on the line or
16666 fits exactly on the line. We must continue
16667 the line because we can't draw the cursor
16668 after the glyph. */
16669 row
->continued_p
= 1;
16670 it
->current_x
= new_x
;
16671 it
->continuation_lines_width
+= new_x
;
16673 if (i
== nglyphs
- 1)
16675 /* If line-wrap is on, check if a previous
16676 wrap point was found. */
16677 if (wrap_row_used
> 0
16678 /* Even if there is a previous wrap
16679 point, continue the line here as
16680 usual, if (i) the previous character
16681 was a space or tab AND (ii) the
16682 current character is not. */
16684 || IT_DISPLAYING_WHITESPACE (it
)))
16687 set_iterator_to_next (it
, 1);
16688 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16690 if (!get_next_display_element (it
))
16692 row
->exact_window_width_line_p
= 1;
16693 it
->continuation_lines_width
= 0;
16694 row
->continued_p
= 0;
16695 row
->ends_at_zv_p
= 1;
16697 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16699 row
->continued_p
= 0;
16700 row
->exact_window_width_line_p
= 1;
16705 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16706 && !FRAME_WINDOW_P (it
->f
))
16708 /* A padding glyph that doesn't fit on this line.
16709 This means the whole character doesn't fit
16711 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16713 /* Fill the rest of the row with continuation
16714 glyphs like in 20.x. */
16715 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16716 < row
->glyphs
[1 + TEXT_AREA
])
16717 produce_special_glyphs (it
, IT_CONTINUATION
);
16719 row
->continued_p
= 1;
16720 it
->current_x
= x_before
;
16721 it
->continuation_lines_width
+= x_before
;
16723 /* Restore the height to what it was before the
16724 element not fitting on the line. */
16725 it
->max_ascent
= ascent
;
16726 it
->max_descent
= descent
;
16727 it
->max_phys_ascent
= phys_ascent
;
16728 it
->max_phys_descent
= phys_descent
;
16730 else if (wrap_row_used
> 0)
16734 it
->continuation_lines_width
+= wrap_x
;
16735 row
->used
[TEXT_AREA
] = wrap_row_used
;
16736 row
->ascent
= wrap_row_ascent
;
16737 row
->height
= wrap_row_height
;
16738 row
->phys_ascent
= wrap_row_phys_ascent
;
16739 row
->phys_height
= wrap_row_phys_height
;
16740 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16741 row
->continued_p
= 1;
16742 row
->ends_at_zv_p
= 0;
16743 row
->exact_window_width_line_p
= 0;
16744 it
->continuation_lines_width
+= x
;
16746 /* Make sure that a non-default face is extended
16747 up to the right margin of the window. */
16748 extend_face_to_end_of_line (it
);
16750 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16752 /* A TAB that extends past the right edge of the
16753 window. This produces a single glyph on
16754 window system frames. We leave the glyph in
16755 this row and let it fill the row, but don't
16756 consume the TAB. */
16757 it
->continuation_lines_width
+= it
->last_visible_x
;
16758 row
->ends_in_middle_of_char_p
= 1;
16759 row
->continued_p
= 1;
16760 glyph
->pixel_width
= it
->last_visible_x
- x
;
16761 it
->starts_in_middle_of_char_p
= 1;
16765 /* Something other than a TAB that draws past
16766 the right edge of the window. Restore
16767 positions to values before the element. */
16768 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16770 /* Display continuation glyphs. */
16771 if (!FRAME_WINDOW_P (it
->f
))
16772 produce_special_glyphs (it
, IT_CONTINUATION
);
16773 row
->continued_p
= 1;
16775 it
->current_x
= x_before
;
16776 it
->continuation_lines_width
+= x
;
16777 extend_face_to_end_of_line (it
);
16779 if (nglyphs
> 1 && i
> 0)
16781 row
->ends_in_middle_of_char_p
= 1;
16782 it
->starts_in_middle_of_char_p
= 1;
16785 /* Restore the height to what it was before the
16786 element not fitting on the line. */
16787 it
->max_ascent
= ascent
;
16788 it
->max_descent
= descent
;
16789 it
->max_phys_ascent
= phys_ascent
;
16790 it
->max_phys_descent
= phys_descent
;
16795 else if (new_x
> it
->first_visible_x
)
16797 /* Increment number of glyphs actually displayed. */
16800 if (x
< it
->first_visible_x
)
16801 /* Glyph is partially visible, i.e. row starts at
16802 negative X position. */
16803 row
->x
= x
- it
->first_visible_x
;
16807 /* Glyph is completely off the left margin of the
16808 window. This should not happen because of the
16809 move_it_in_display_line at the start of this
16810 function, unless the text display area of the
16811 window is empty. */
16812 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16816 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16817 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16818 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16819 row
->phys_height
= max (row
->phys_height
,
16820 it
->max_phys_ascent
+ it
->max_phys_descent
);
16821 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16822 it
->max_extra_line_spacing
);
16824 /* End of this display line if row is continued. */
16825 if (row
->continued_p
|| row
->ends_at_zv_p
)
16830 /* Is this a line end? If yes, we're also done, after making
16831 sure that a non-default face is extended up to the right
16832 margin of the window. */
16833 if (ITERATOR_AT_END_OF_LINE_P (it
))
16835 int used_before
= row
->used
[TEXT_AREA
];
16837 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16839 /* Add a space at the end of the line that is used to
16840 display the cursor there. */
16841 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16842 append_space_for_newline (it
, 0);
16844 /* Extend the face to the end of the line. */
16845 extend_face_to_end_of_line (it
);
16847 /* Make sure we have the position. */
16848 if (used_before
== 0)
16849 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16851 /* Consume the line end. This skips over invisible lines. */
16852 set_iterator_to_next (it
, 1);
16853 it
->continuation_lines_width
= 0;
16857 /* Proceed with next display element. Note that this skips
16858 over lines invisible because of selective display. */
16859 set_iterator_to_next (it
, 1);
16861 /* If we truncate lines, we are done when the last displayed
16862 glyphs reach past the right margin of the window. */
16863 if (it
->line_wrap
== TRUNCATE
16864 && (FRAME_WINDOW_P (it
->f
)
16865 ? (it
->current_x
>= it
->last_visible_x
)
16866 : (it
->current_x
> it
->last_visible_x
)))
16868 /* Maybe add truncation glyphs. */
16869 if (!FRAME_WINDOW_P (it
->f
))
16873 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16874 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16877 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16879 row
->used
[TEXT_AREA
] = i
;
16880 produce_special_glyphs (it
, IT_TRUNCATION
);
16883 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16885 /* Don't truncate if we can overflow newline into fringe. */
16886 if (!get_next_display_element (it
))
16888 it
->continuation_lines_width
= 0;
16889 row
->ends_at_zv_p
= 1;
16890 row
->exact_window_width_line_p
= 1;
16893 if (ITERATOR_AT_END_OF_LINE_P (it
))
16895 row
->exact_window_width_line_p
= 1;
16896 goto at_end_of_line
;
16900 row
->truncated_on_right_p
= 1;
16901 it
->continuation_lines_width
= 0;
16902 reseat_at_next_visible_line_start (it
, 0);
16903 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16904 it
->hpos
= hpos_before
;
16905 it
->current_x
= x_before
;
16910 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16911 at the left window margin. */
16912 if (it
->first_visible_x
16913 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16915 if (!FRAME_WINDOW_P (it
->f
))
16916 insert_left_trunc_glyphs (it
);
16917 row
->truncated_on_left_p
= 1;
16920 /* If the start of this line is the overlay arrow-position, then
16921 mark this glyph row as the one containing the overlay arrow.
16922 This is clearly a mess with variable size fonts. It would be
16923 better to let it be displayed like cursors under X. */
16924 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16925 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16926 !NILP (overlay_arrow_string
)))
16928 /* Overlay arrow in window redisplay is a fringe bitmap. */
16929 if (STRINGP (overlay_arrow_string
))
16931 struct glyph_row
*arrow_row
16932 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16933 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16934 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16935 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16936 struct glyph
*p2
, *end
;
16938 /* Copy the arrow glyphs. */
16939 while (glyph
< arrow_end
)
16942 /* Throw away padding glyphs. */
16944 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16945 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16951 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16956 xassert (INTEGERP (overlay_arrow_string
));
16957 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16959 overlay_arrow_seen
= 1;
16962 /* Compute pixel dimensions of this line. */
16963 compute_line_metrics (it
);
16965 /* Remember the position at which this line ends. */
16966 row
->end
= it
->current
;
16968 /* Record whether this row ends inside an ellipsis. */
16969 row
->ends_in_ellipsis_p
16970 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16971 && it
->ellipsis_p
);
16973 /* Save fringe bitmaps in this row. */
16974 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16975 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16976 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16977 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16979 it
->left_user_fringe_bitmap
= 0;
16980 it
->left_user_fringe_face_id
= 0;
16981 it
->right_user_fringe_bitmap
= 0;
16982 it
->right_user_fringe_face_id
= 0;
16984 /* Maybe set the cursor. */
16985 if (it
->w
->cursor
.vpos
< 0
16986 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16987 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16988 && cursor_row_p (it
->w
, row
))
16989 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16991 /* Highlight trailing whitespace. */
16992 if (!NILP (Vshow_trailing_whitespace
))
16993 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16995 /* Prepare for the next line. This line starts horizontally at (X
16996 HPOS) = (0 0). Vertical positions are incremented. As a
16997 convenience for the caller, IT->glyph_row is set to the next
16999 it
->current_x
= it
->hpos
= 0;
17000 it
->current_y
+= row
->height
;
17003 it
->start
= it
->current
;
17004 return row
->displays_text_p
;
17009 /***********************************************************************
17011 ***********************************************************************/
17013 /* Redisplay the menu bar in the frame for window W.
17015 The menu bar of X frames that don't have X toolkit support is
17016 displayed in a special window W->frame->menu_bar_window.
17018 The menu bar of terminal frames is treated specially as far as
17019 glyph matrices are concerned. Menu bar lines are not part of
17020 windows, so the update is done directly on the frame matrix rows
17021 for the menu bar. */
17024 display_menu_bar (w
)
17027 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17032 /* Don't do all this for graphical frames. */
17034 if (FRAME_W32_P (f
))
17037 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17043 if (FRAME_NS_P (f
))
17045 #endif /* HAVE_NS */
17047 #ifdef USE_X_TOOLKIT
17048 xassert (!FRAME_WINDOW_P (f
));
17049 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17050 it
.first_visible_x
= 0;
17051 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17052 #else /* not USE_X_TOOLKIT */
17053 if (FRAME_WINDOW_P (f
))
17055 /* Menu bar lines are displayed in the desired matrix of the
17056 dummy window menu_bar_window. */
17057 struct window
*menu_w
;
17058 xassert (WINDOWP (f
->menu_bar_window
));
17059 menu_w
= XWINDOW (f
->menu_bar_window
);
17060 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17062 it
.first_visible_x
= 0;
17063 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17067 /* This is a TTY frame, i.e. character hpos/vpos are used as
17069 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17071 it
.first_visible_x
= 0;
17072 it
.last_visible_x
= FRAME_COLS (f
);
17074 #endif /* not USE_X_TOOLKIT */
17076 if (! mode_line_inverse_video
)
17077 /* Force the menu-bar to be displayed in the default face. */
17078 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17080 /* Clear all rows of the menu bar. */
17081 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17083 struct glyph_row
*row
= it
.glyph_row
+ i
;
17084 clear_glyph_row (row
);
17085 row
->enabled_p
= 1;
17086 row
->full_width_p
= 1;
17089 /* Display all items of the menu bar. */
17090 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17091 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17093 Lisp_Object string
;
17095 /* Stop at nil string. */
17096 string
= AREF (items
, i
+ 1);
17100 /* Remember where item was displayed. */
17101 ASET (items
, i
+ 3, make_number (it
.hpos
));
17103 /* Display the item, pad with one space. */
17104 if (it
.current_x
< it
.last_visible_x
)
17105 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17106 SCHARS (string
) + 1, 0, 0, -1);
17109 /* Fill out the line with spaces. */
17110 if (it
.current_x
< it
.last_visible_x
)
17111 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17113 /* Compute the total height of the lines. */
17114 compute_line_metrics (&it
);
17119 /***********************************************************************
17121 ***********************************************************************/
17123 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17124 FORCE is non-zero, redisplay mode lines unconditionally.
17125 Otherwise, redisplay only mode lines that are garbaged. Value is
17126 the number of windows whose mode lines were redisplayed. */
17129 redisplay_mode_lines (window
, force
)
17130 Lisp_Object window
;
17135 while (!NILP (window
))
17137 struct window
*w
= XWINDOW (window
);
17139 if (WINDOWP (w
->hchild
))
17140 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17141 else if (WINDOWP (w
->vchild
))
17142 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17144 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17145 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17147 struct text_pos lpoint
;
17148 struct buffer
*old
= current_buffer
;
17150 /* Set the window's buffer for the mode line display. */
17151 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17152 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17154 /* Point refers normally to the selected window. For any
17155 other window, set up appropriate value. */
17156 if (!EQ (window
, selected_window
))
17158 struct text_pos pt
;
17160 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17161 if (CHARPOS (pt
) < BEGV
)
17162 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17163 else if (CHARPOS (pt
) > (ZV
- 1))
17164 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17166 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17169 /* Display mode lines. */
17170 clear_glyph_matrix (w
->desired_matrix
);
17171 if (display_mode_lines (w
))
17174 w
->must_be_updated_p
= 1;
17177 /* Restore old settings. */
17178 set_buffer_internal_1 (old
);
17179 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17189 /* Display the mode and/or top line of window W. Value is the number
17190 of mode lines displayed. */
17193 display_mode_lines (w
)
17196 Lisp_Object old_selected_window
, old_selected_frame
;
17199 old_selected_frame
= selected_frame
;
17200 selected_frame
= w
->frame
;
17201 old_selected_window
= selected_window
;
17202 XSETWINDOW (selected_window
, w
);
17204 /* These will be set while the mode line specs are processed. */
17205 line_number_displayed
= 0;
17206 w
->column_number_displayed
= Qnil
;
17208 if (WINDOW_WANTS_MODELINE_P (w
))
17210 struct window
*sel_w
= XWINDOW (old_selected_window
);
17212 /* Select mode line face based on the real selected window. */
17213 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17214 current_buffer
->mode_line_format
);
17218 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17220 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17221 current_buffer
->header_line_format
);
17225 selected_frame
= old_selected_frame
;
17226 selected_window
= old_selected_window
;
17231 /* Display mode or top line of window W. FACE_ID specifies which line
17232 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
17233 FORMAT is the mode line format to display. Value is the pixel
17234 height of the mode line displayed. */
17237 display_mode_line (w
, face_id
, format
)
17239 enum face_id face_id
;
17240 Lisp_Object format
;
17244 int count
= SPECPDL_INDEX ();
17246 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17247 /* Don't extend on a previously drawn mode-line.
17248 This may happen if called from pos_visible_p. */
17249 it
.glyph_row
->enabled_p
= 0;
17250 prepare_desired_row (it
.glyph_row
);
17252 it
.glyph_row
->mode_line_p
= 1;
17254 if (! mode_line_inverse_video
)
17255 /* Force the mode-line to be displayed in the default face. */
17256 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17258 record_unwind_protect (unwind_format_mode_line
,
17259 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17261 mode_line_target
= MODE_LINE_DISPLAY
;
17263 /* Temporarily make frame's keyboard the current kboard so that
17264 kboard-local variables in the mode_line_format will get the right
17266 push_kboard (FRAME_KBOARD (it
.f
));
17267 record_unwind_save_match_data ();
17268 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17271 unbind_to (count
, Qnil
);
17273 /* Fill up with spaces. */
17274 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17276 compute_line_metrics (&it
);
17277 it
.glyph_row
->full_width_p
= 1;
17278 it
.glyph_row
->continued_p
= 0;
17279 it
.glyph_row
->truncated_on_left_p
= 0;
17280 it
.glyph_row
->truncated_on_right_p
= 0;
17282 /* Make a 3D mode-line have a shadow at its right end. */
17283 face
= FACE_FROM_ID (it
.f
, face_id
);
17284 extend_face_to_end_of_line (&it
);
17285 if (face
->box
!= FACE_NO_BOX
)
17287 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17288 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17289 last
->right_box_line_p
= 1;
17292 return it
.glyph_row
->height
;
17295 /* Move element ELT in LIST to the front of LIST.
17296 Return the updated list. */
17299 move_elt_to_front (elt
, list
)
17300 Lisp_Object elt
, list
;
17302 register Lisp_Object tail
, prev
;
17303 register Lisp_Object tem
;
17307 while (CONSP (tail
))
17313 /* Splice out the link TAIL. */
17315 list
= XCDR (tail
);
17317 Fsetcdr (prev
, XCDR (tail
));
17319 /* Now make it the first. */
17320 Fsetcdr (tail
, list
);
17325 tail
= XCDR (tail
);
17329 /* Not found--return unchanged LIST. */
17333 /* Contribute ELT to the mode line for window IT->w. How it
17334 translates into text depends on its data type.
17336 IT describes the display environment in which we display, as usual.
17338 DEPTH is the depth in recursion. It is used to prevent
17339 infinite recursion here.
17341 FIELD_WIDTH is the number of characters the display of ELT should
17342 occupy in the mode line, and PRECISION is the maximum number of
17343 characters to display from ELT's representation. See
17344 display_string for details.
17346 Returns the hpos of the end of the text generated by ELT.
17348 PROPS is a property list to add to any string we encounter.
17350 If RISKY is nonzero, remove (disregard) any properties in any string
17351 we encounter, and ignore :eval and :propertize.
17353 The global variable `mode_line_target' determines whether the
17354 output is passed to `store_mode_line_noprop',
17355 `store_mode_line_string', or `display_string'. */
17358 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17361 int field_width
, precision
;
17362 Lisp_Object elt
, props
;
17365 int n
= 0, field
, prec
;
17370 elt
= build_string ("*too-deep*");
17374 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17378 /* A string: output it and check for %-constructs within it. */
17382 if (SCHARS (elt
) > 0
17383 && (!NILP (props
) || risky
))
17385 Lisp_Object oprops
, aelt
;
17386 oprops
= Ftext_properties_at (make_number (0), elt
);
17388 /* If the starting string's properties are not what
17389 we want, translate the string. Also, if the string
17390 is risky, do that anyway. */
17392 if (NILP (Fequal (props
, oprops
)) || risky
)
17394 /* If the starting string has properties,
17395 merge the specified ones onto the existing ones. */
17396 if (! NILP (oprops
) && !risky
)
17400 oprops
= Fcopy_sequence (oprops
);
17402 while (CONSP (tem
))
17404 oprops
= Fplist_put (oprops
, XCAR (tem
),
17405 XCAR (XCDR (tem
)));
17406 tem
= XCDR (XCDR (tem
));
17411 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17412 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17414 /* AELT is what we want. Move it to the front
17415 without consing. */
17417 mode_line_proptrans_alist
17418 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17424 /* If AELT has the wrong props, it is useless.
17425 so get rid of it. */
17427 mode_line_proptrans_alist
17428 = Fdelq (aelt
, mode_line_proptrans_alist
);
17430 elt
= Fcopy_sequence (elt
);
17431 Fset_text_properties (make_number (0), Flength (elt
),
17433 /* Add this item to mode_line_proptrans_alist. */
17434 mode_line_proptrans_alist
17435 = Fcons (Fcons (elt
, props
),
17436 mode_line_proptrans_alist
);
17437 /* Truncate mode_line_proptrans_alist
17438 to at most 50 elements. */
17439 tem
= Fnthcdr (make_number (50),
17440 mode_line_proptrans_alist
);
17442 XSETCDR (tem
, Qnil
);
17451 prec
= precision
- n
;
17452 switch (mode_line_target
)
17454 case MODE_LINE_NOPROP
:
17455 case MODE_LINE_TITLE
:
17456 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17458 case MODE_LINE_STRING
:
17459 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17461 case MODE_LINE_DISPLAY
:
17462 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17463 0, prec
, 0, STRING_MULTIBYTE (elt
));
17470 /* Handle the non-literal case. */
17472 while ((precision
<= 0 || n
< precision
)
17473 && SREF (elt
, offset
) != 0
17474 && (mode_line_target
!= MODE_LINE_DISPLAY
17475 || it
->current_x
< it
->last_visible_x
))
17477 int last_offset
= offset
;
17479 /* Advance to end of string or next format specifier. */
17480 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17483 if (offset
- 1 != last_offset
)
17485 int nchars
, nbytes
;
17487 /* Output to end of string or up to '%'. Field width
17488 is length of string. Don't output more than
17489 PRECISION allows us. */
17492 prec
= c_string_width (SDATA (elt
) + last_offset
,
17493 offset
- last_offset
, precision
- n
,
17496 switch (mode_line_target
)
17498 case MODE_LINE_NOPROP
:
17499 case MODE_LINE_TITLE
:
17500 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17502 case MODE_LINE_STRING
:
17504 int bytepos
= last_offset
;
17505 int charpos
= string_byte_to_char (elt
, bytepos
);
17506 int endpos
= (precision
<= 0
17507 ? string_byte_to_char (elt
, offset
)
17508 : charpos
+ nchars
);
17510 n
+= store_mode_line_string (NULL
,
17511 Fsubstring (elt
, make_number (charpos
),
17512 make_number (endpos
)),
17516 case MODE_LINE_DISPLAY
:
17518 int bytepos
= last_offset
;
17519 int charpos
= string_byte_to_char (elt
, bytepos
);
17521 if (precision
<= 0)
17522 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17523 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17525 STRING_MULTIBYTE (elt
));
17530 else /* c == '%' */
17532 int percent_position
= offset
;
17534 /* Get the specified minimum width. Zero means
17537 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17538 field
= field
* 10 + c
- '0';
17540 /* Don't pad beyond the total padding allowed. */
17541 if (field_width
- n
> 0 && field
> field_width
- n
)
17542 field
= field_width
- n
;
17544 /* Note that either PRECISION <= 0 or N < PRECISION. */
17545 prec
= precision
- n
;
17548 n
+= display_mode_element (it
, depth
, field
, prec
,
17549 Vglobal_mode_string
, props
,
17554 int bytepos
, charpos
;
17555 unsigned char *spec
;
17557 bytepos
= percent_position
;
17558 charpos
= (STRING_MULTIBYTE (elt
)
17559 ? string_byte_to_char (elt
, bytepos
)
17562 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17564 switch (mode_line_target
)
17566 case MODE_LINE_NOPROP
:
17567 case MODE_LINE_TITLE
:
17568 n
+= store_mode_line_noprop (spec
, field
, prec
);
17570 case MODE_LINE_STRING
:
17572 int len
= strlen (spec
);
17573 Lisp_Object tem
= make_string (spec
, len
);
17574 props
= Ftext_properties_at (make_number (charpos
), elt
);
17575 /* Should only keep face property in props */
17576 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17579 case MODE_LINE_DISPLAY
:
17581 int nglyphs_before
, nwritten
;
17583 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17584 nwritten
= display_string (spec
, Qnil
, elt
,
17589 /* Assign to the glyphs written above the
17590 string where the `%x' came from, position
17594 struct glyph
*glyph
17595 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17599 for (i
= 0; i
< nwritten
; ++i
)
17601 glyph
[i
].object
= elt
;
17602 glyph
[i
].charpos
= charpos
;
17619 /* A symbol: process the value of the symbol recursively
17620 as if it appeared here directly. Avoid error if symbol void.
17621 Special case: if value of symbol is a string, output the string
17624 register Lisp_Object tem
;
17626 /* If the variable is not marked as risky to set
17627 then its contents are risky to use. */
17628 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17631 tem
= Fboundp (elt
);
17634 tem
= Fsymbol_value (elt
);
17635 /* If value is a string, output that string literally:
17636 don't check for % within it. */
17640 if (!EQ (tem
, elt
))
17642 /* Give up right away for nil or t. */
17652 register Lisp_Object car
, tem
;
17654 /* A cons cell: five distinct cases.
17655 If first element is :eval or :propertize, do something special.
17656 If first element is a string or a cons, process all the elements
17657 and effectively concatenate them.
17658 If first element is a negative number, truncate displaying cdr to
17659 at most that many characters. If positive, pad (with spaces)
17660 to at least that many characters.
17661 If first element is a symbol, process the cadr or caddr recursively
17662 according to whether the symbol's value is non-nil or nil. */
17664 if (EQ (car
, QCeval
))
17666 /* An element of the form (:eval FORM) means evaluate FORM
17667 and use the result as mode line elements. */
17672 if (CONSP (XCDR (elt
)))
17675 spec
= safe_eval (XCAR (XCDR (elt
)));
17676 n
+= display_mode_element (it
, depth
, field_width
- n
,
17677 precision
- n
, spec
, props
,
17681 else if (EQ (car
, QCpropertize
))
17683 /* An element of the form (:propertize ELT PROPS...)
17684 means display ELT but applying properties PROPS. */
17689 if (CONSP (XCDR (elt
)))
17690 n
+= display_mode_element (it
, depth
, field_width
- n
,
17691 precision
- n
, XCAR (XCDR (elt
)),
17692 XCDR (XCDR (elt
)), risky
);
17694 else if (SYMBOLP (car
))
17696 tem
= Fboundp (car
);
17700 /* elt is now the cdr, and we know it is a cons cell.
17701 Use its car if CAR has a non-nil value. */
17704 tem
= Fsymbol_value (car
);
17711 /* Symbol's value is nil (or symbol is unbound)
17712 Get the cddr of the original list
17713 and if possible find the caddr and use that. */
17717 else if (!CONSP (elt
))
17722 else if (INTEGERP (car
))
17724 register int lim
= XINT (car
);
17728 /* Negative int means reduce maximum width. */
17729 if (precision
<= 0)
17732 precision
= min (precision
, -lim
);
17736 /* Padding specified. Don't let it be more than
17737 current maximum. */
17739 lim
= min (precision
, lim
);
17741 /* If that's more padding than already wanted, queue it.
17742 But don't reduce padding already specified even if
17743 that is beyond the current truncation point. */
17744 field_width
= max (lim
, field_width
);
17748 else if (STRINGP (car
) || CONSP (car
))
17750 register int limit
= 50;
17751 /* Limit is to protect against circular lists. */
17754 && (precision
<= 0 || n
< precision
))
17756 n
+= display_mode_element (it
, depth
,
17757 /* Do padding only after the last
17758 element in the list. */
17759 (! CONSP (XCDR (elt
))
17762 precision
- n
, XCAR (elt
),
17772 elt
= build_string ("*invalid*");
17776 /* Pad to FIELD_WIDTH. */
17777 if (field_width
> 0 && n
< field_width
)
17779 switch (mode_line_target
)
17781 case MODE_LINE_NOPROP
:
17782 case MODE_LINE_TITLE
:
17783 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17785 case MODE_LINE_STRING
:
17786 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17788 case MODE_LINE_DISPLAY
:
17789 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17798 /* Store a mode-line string element in mode_line_string_list.
17800 If STRING is non-null, display that C string. Otherwise, the Lisp
17801 string LISP_STRING is displayed.
17803 FIELD_WIDTH is the minimum number of output glyphs to produce.
17804 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17805 with spaces. FIELD_WIDTH <= 0 means don't pad.
17807 PRECISION is the maximum number of characters to output from
17808 STRING. PRECISION <= 0 means don't truncate the string.
17810 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17811 properties to the string.
17813 PROPS are the properties to add to the string.
17814 The mode_line_string_face face property is always added to the string.
17818 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17820 Lisp_Object lisp_string
;
17829 if (string
!= NULL
)
17831 len
= strlen (string
);
17832 if (precision
> 0 && len
> precision
)
17834 lisp_string
= make_string (string
, len
);
17836 props
= mode_line_string_face_prop
;
17837 else if (!NILP (mode_line_string_face
))
17839 Lisp_Object face
= Fplist_get (props
, Qface
);
17840 props
= Fcopy_sequence (props
);
17842 face
= mode_line_string_face
;
17844 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17845 props
= Fplist_put (props
, Qface
, face
);
17847 Fadd_text_properties (make_number (0), make_number (len
),
17848 props
, lisp_string
);
17852 len
= XFASTINT (Flength (lisp_string
));
17853 if (precision
> 0 && len
> precision
)
17856 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17859 if (!NILP (mode_line_string_face
))
17863 props
= Ftext_properties_at (make_number (0), lisp_string
);
17864 face
= Fplist_get (props
, Qface
);
17866 face
= mode_line_string_face
;
17868 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17869 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17871 lisp_string
= Fcopy_sequence (lisp_string
);
17874 Fadd_text_properties (make_number (0), make_number (len
),
17875 props
, lisp_string
);
17880 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17884 if (field_width
> len
)
17886 field_width
-= len
;
17887 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17889 Fadd_text_properties (make_number (0), make_number (field_width
),
17890 props
, lisp_string
);
17891 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17899 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17901 doc
: /* Format a string out of a mode line format specification.
17902 First arg FORMAT specifies the mode line format (see `mode-line-format'
17903 for details) to use.
17905 Optional second arg FACE specifies the face property to put
17906 on all characters for which no face is specified.
17907 The value t means whatever face the window's mode line currently uses
17908 \(either `mode-line' or `mode-line-inactive', depending).
17909 A value of nil means the default is no face property.
17910 If FACE is an integer, the value string has no text properties.
17912 Optional third and fourth args WINDOW and BUFFER specify the window
17913 and buffer to use as the context for the formatting (defaults
17914 are the selected window and the window's buffer). */)
17915 (format
, face
, window
, buffer
)
17916 Lisp_Object format
, face
, window
, buffer
;
17921 struct buffer
*old_buffer
= NULL
;
17923 int no_props
= INTEGERP (face
);
17924 int count
= SPECPDL_INDEX ();
17926 int string_start
= 0;
17929 window
= selected_window
;
17930 CHECK_WINDOW (window
);
17931 w
= XWINDOW (window
);
17934 buffer
= w
->buffer
;
17935 CHECK_BUFFER (buffer
);
17937 /* Make formatting the modeline a non-op when noninteractive, otherwise
17938 there will be problems later caused by a partially initialized frame. */
17939 if (NILP (format
) || noninteractive
)
17940 return empty_unibyte_string
;
17948 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17949 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17953 face_id
= DEFAULT_FACE_ID
;
17955 if (XBUFFER (buffer
) != current_buffer
)
17956 old_buffer
= current_buffer
;
17958 /* Save things including mode_line_proptrans_alist,
17959 and set that to nil so that we don't alter the outer value. */
17960 record_unwind_protect (unwind_format_mode_line
,
17961 format_mode_line_unwind_data
17962 (old_buffer
, selected_window
, 1));
17963 mode_line_proptrans_alist
= Qnil
;
17965 Fselect_window (window
, Qt
);
17967 set_buffer_internal_1 (XBUFFER (buffer
));
17969 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17973 mode_line_target
= MODE_LINE_NOPROP
;
17974 mode_line_string_face_prop
= Qnil
;
17975 mode_line_string_list
= Qnil
;
17976 string_start
= MODE_LINE_NOPROP_LEN (0);
17980 mode_line_target
= MODE_LINE_STRING
;
17981 mode_line_string_list
= Qnil
;
17982 mode_line_string_face
= face
;
17983 mode_line_string_face_prop
17984 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17987 push_kboard (FRAME_KBOARD (it
.f
));
17988 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17993 len
= MODE_LINE_NOPROP_LEN (string_start
);
17994 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17998 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17999 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18000 empty_unibyte_string
);
18003 unbind_to (count
, Qnil
);
18007 /* Write a null-terminated, right justified decimal representation of
18008 the positive integer D to BUF using a minimal field width WIDTH. */
18011 pint2str (buf
, width
, d
)
18012 register char *buf
;
18013 register int width
;
18016 register char *p
= buf
;
18024 *p
++ = d
% 10 + '0';
18029 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18040 /* Write a null-terminated, right justified decimal and "human
18041 readable" representation of the nonnegative integer D to BUF using
18042 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18044 static const char power_letter
[] =
18058 pint2hrstr (buf
, width
, d
)
18063 /* We aim to represent the nonnegative integer D as
18064 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18067 /* -1 means: do not use TENTHS. */
18071 /* Length of QUOTIENT.TENTHS as a string. */
18077 if (1000 <= quotient
)
18079 /* Scale to the appropriate EXPONENT. */
18082 remainder
= quotient
% 1000;
18086 while (1000 <= quotient
);
18088 /* Round to nearest and decide whether to use TENTHS or not. */
18091 tenths
= remainder
/ 100;
18092 if (50 <= remainder
% 100)
18099 if (quotient
== 10)
18107 if (500 <= remainder
)
18109 if (quotient
< 999)
18120 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18121 if (tenths
== -1 && quotient
<= 99)
18128 p
= psuffix
= buf
+ max (width
, length
);
18130 /* Print EXPONENT. */
18132 *psuffix
++ = power_letter
[exponent
];
18135 /* Print TENTHS. */
18138 *--p
= '0' + tenths
;
18142 /* Print QUOTIENT. */
18145 int digit
= quotient
% 10;
18146 *--p
= '0' + digit
;
18148 while ((quotient
/= 10) != 0);
18150 /* Print leading spaces. */
18155 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18156 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18157 type of CODING_SYSTEM. Return updated pointer into BUF. */
18159 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18162 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18163 Lisp_Object coding_system
;
18164 register char *buf
;
18168 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18169 const unsigned char *eol_str
;
18171 /* The EOL conversion we are using. */
18172 Lisp_Object eoltype
;
18174 val
= CODING_SYSTEM_SPEC (coding_system
);
18177 if (!VECTORP (val
)) /* Not yet decided. */
18182 eoltype
= eol_mnemonic_undecided
;
18183 /* Don't mention EOL conversion if it isn't decided. */
18188 Lisp_Object eolvalue
;
18190 attrs
= AREF (val
, 0);
18191 eolvalue
= AREF (val
, 2);
18194 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18198 /* The EOL conversion that is normal on this system. */
18200 if (NILP (eolvalue
)) /* Not yet decided. */
18201 eoltype
= eol_mnemonic_undecided
;
18202 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18203 eoltype
= eol_mnemonic_undecided
;
18204 else /* eolvalue is Qunix, Qdos, or Qmac. */
18205 eoltype
= (EQ (eolvalue
, Qunix
)
18206 ? eol_mnemonic_unix
18207 : (EQ (eolvalue
, Qdos
) == 1
18208 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18214 /* Mention the EOL conversion if it is not the usual one. */
18215 if (STRINGP (eoltype
))
18217 eol_str
= SDATA (eoltype
);
18218 eol_str_len
= SBYTES (eoltype
);
18220 else if (CHARACTERP (eoltype
))
18222 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18223 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18228 eol_str
= invalid_eol_type
;
18229 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18231 bcopy (eol_str
, buf
, eol_str_len
);
18232 buf
+= eol_str_len
;
18238 /* Return a string for the output of a mode line %-spec for window W,
18239 generated by character C. PRECISION >= 0 means don't return a
18240 string longer than that value. FIELD_WIDTH > 0 means pad the
18241 string returned with spaces to that value. Return 1 in *MULTIBYTE
18242 if the result is multibyte text.
18244 Note we operate on the current buffer for most purposes,
18245 the exception being w->base_line_pos. */
18247 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18250 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18253 int field_width
, precision
;
18257 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18258 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18259 struct buffer
*b
= current_buffer
;
18267 if (!NILP (b
->read_only
))
18269 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18274 /* This differs from %* only for a modified read-only buffer. */
18275 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18277 if (!NILP (b
->read_only
))
18282 /* This differs from %* in ignoring read-only-ness. */
18283 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18295 if (command_loop_level
> 5)
18297 p
= decode_mode_spec_buf
;
18298 for (i
= 0; i
< command_loop_level
; i
++)
18301 return decode_mode_spec_buf
;
18309 if (command_loop_level
> 5)
18311 p
= decode_mode_spec_buf
;
18312 for (i
= 0; i
< command_loop_level
; i
++)
18315 return decode_mode_spec_buf
;
18322 /* Let lots_of_dashes be a string of infinite length. */
18323 if (mode_line_target
== MODE_LINE_NOPROP
||
18324 mode_line_target
== MODE_LINE_STRING
)
18326 if (field_width
<= 0
18327 || field_width
> sizeof (lots_of_dashes
))
18329 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18330 decode_mode_spec_buf
[i
] = '-';
18331 decode_mode_spec_buf
[i
] = '\0';
18332 return decode_mode_spec_buf
;
18335 return lots_of_dashes
;
18343 /* %c and %l are ignored in `frame-title-format'.
18344 (In redisplay_internal, the frame title is drawn _before_ the
18345 windows are updated, so the stuff which depends on actual
18346 window contents (such as %l) may fail to render properly, or
18347 even crash emacs.) */
18348 if (mode_line_target
== MODE_LINE_TITLE
)
18352 int col
= (int) current_column (); /* iftc */
18353 w
->column_number_displayed
= make_number (col
);
18354 pint2str (decode_mode_spec_buf
, field_width
, col
);
18355 return decode_mode_spec_buf
;
18359 #ifndef SYSTEM_MALLOC
18361 if (NILP (Vmemory_full
))
18364 return "!MEM FULL! ";
18371 /* %F displays the frame name. */
18372 if (!NILP (f
->title
))
18373 return (char *) SDATA (f
->title
);
18374 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18375 return (char *) SDATA (f
->name
);
18384 int size
= ZV
- BEGV
;
18385 pint2str (decode_mode_spec_buf
, field_width
, size
);
18386 return decode_mode_spec_buf
;
18391 int size
= ZV
- BEGV
;
18392 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18393 return decode_mode_spec_buf
;
18398 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18399 int topline
, nlines
, junk
, height
;
18401 /* %c and %l are ignored in `frame-title-format'. */
18402 if (mode_line_target
== MODE_LINE_TITLE
)
18405 startpos
= XMARKER (w
->start
)->charpos
;
18406 startpos_byte
= marker_byte_position (w
->start
);
18407 height
= WINDOW_TOTAL_LINES (w
);
18409 /* If we decided that this buffer isn't suitable for line numbers,
18410 don't forget that too fast. */
18411 if (EQ (w
->base_line_pos
, w
->buffer
))
18413 /* But do forget it, if the window shows a different buffer now. */
18414 else if (BUFFERP (w
->base_line_pos
))
18415 w
->base_line_pos
= Qnil
;
18417 /* If the buffer is very big, don't waste time. */
18418 if (INTEGERP (Vline_number_display_limit
)
18419 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18421 w
->base_line_pos
= Qnil
;
18422 w
->base_line_number
= Qnil
;
18426 if (INTEGERP (w
->base_line_number
)
18427 && INTEGERP (w
->base_line_pos
)
18428 && XFASTINT (w
->base_line_pos
) <= startpos
)
18430 line
= XFASTINT (w
->base_line_number
);
18431 linepos
= XFASTINT (w
->base_line_pos
);
18432 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18437 linepos
= BUF_BEGV (b
);
18438 linepos_byte
= BUF_BEGV_BYTE (b
);
18441 /* Count lines from base line to window start position. */
18442 nlines
= display_count_lines (linepos
, linepos_byte
,
18446 topline
= nlines
+ line
;
18448 /* Determine a new base line, if the old one is too close
18449 or too far away, or if we did not have one.
18450 "Too close" means it's plausible a scroll-down would
18451 go back past it. */
18452 if (startpos
== BUF_BEGV (b
))
18454 w
->base_line_number
= make_number (topline
);
18455 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18457 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18458 || linepos
== BUF_BEGV (b
))
18460 int limit
= BUF_BEGV (b
);
18461 int limit_byte
= BUF_BEGV_BYTE (b
);
18463 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18465 if (startpos
- distance
> limit
)
18467 limit
= startpos
- distance
;
18468 limit_byte
= CHAR_TO_BYTE (limit
);
18471 nlines
= display_count_lines (startpos
, startpos_byte
,
18473 - (height
* 2 + 30),
18475 /* If we couldn't find the lines we wanted within
18476 line_number_display_limit_width chars per line,
18477 give up on line numbers for this window. */
18478 if (position
== limit_byte
&& limit
== startpos
- distance
)
18480 w
->base_line_pos
= w
->buffer
;
18481 w
->base_line_number
= Qnil
;
18485 w
->base_line_number
= make_number (topline
- nlines
);
18486 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18489 /* Now count lines from the start pos to point. */
18490 nlines
= display_count_lines (startpos
, startpos_byte
,
18491 PT_BYTE
, PT
, &junk
);
18493 /* Record that we did display the line number. */
18494 line_number_displayed
= 1;
18496 /* Make the string to show. */
18497 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18498 return decode_mode_spec_buf
;
18501 char* p
= decode_mode_spec_buf
;
18502 int pad
= field_width
- 2;
18508 return decode_mode_spec_buf
;
18514 obj
= b
->mode_name
;
18518 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18524 int pos
= marker_position (w
->start
);
18525 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18527 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18529 if (pos
<= BUF_BEGV (b
))
18534 else if (pos
<= BUF_BEGV (b
))
18538 if (total
> 1000000)
18539 /* Do it differently for a large value, to avoid overflow. */
18540 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18542 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18543 /* We can't normally display a 3-digit number,
18544 so get us a 2-digit number that is close. */
18547 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18548 return decode_mode_spec_buf
;
18552 /* Display percentage of size above the bottom of the screen. */
18555 int toppos
= marker_position (w
->start
);
18556 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18557 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18559 if (botpos
>= BUF_ZV (b
))
18561 if (toppos
<= BUF_BEGV (b
))
18568 if (total
> 1000000)
18569 /* Do it differently for a large value, to avoid overflow. */
18570 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18572 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18573 /* We can't normally display a 3-digit number,
18574 so get us a 2-digit number that is close. */
18577 if (toppos
<= BUF_BEGV (b
))
18578 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18580 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18581 return decode_mode_spec_buf
;
18586 /* status of process */
18587 obj
= Fget_buffer_process (Fcurrent_buffer ());
18589 return "no process";
18590 #ifdef subprocesses
18591 obj
= Fsymbol_name (Fprocess_status (obj
));
18598 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18605 case 't': /* indicate TEXT or BINARY */
18606 #ifdef MODE_LINE_BINARY_TEXT
18607 return MODE_LINE_BINARY_TEXT (b
);
18613 /* coding-system (not including end-of-line format) */
18615 /* coding-system (including end-of-line type) */
18617 int eol_flag
= (c
== 'Z');
18618 char *p
= decode_mode_spec_buf
;
18620 if (! FRAME_WINDOW_P (f
))
18622 /* No need to mention EOL here--the terminal never needs
18623 to do EOL conversion. */
18624 p
= decode_mode_spec_coding (CODING_ID_NAME
18625 (FRAME_KEYBOARD_CODING (f
)->id
),
18627 p
= decode_mode_spec_coding (CODING_ID_NAME
18628 (FRAME_TERMINAL_CODING (f
)->id
),
18631 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18634 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18635 #ifdef subprocesses
18636 obj
= Fget_buffer_process (Fcurrent_buffer ());
18637 if (PROCESSP (obj
))
18639 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18641 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18644 #endif /* subprocesses */
18647 return decode_mode_spec_buf
;
18653 *multibyte
= STRING_MULTIBYTE (obj
);
18654 return (char *) SDATA (obj
);
18661 /* Count up to COUNT lines starting from START / START_BYTE.
18662 But don't go beyond LIMIT_BYTE.
18663 Return the number of lines thus found (always nonnegative).
18665 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18668 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18669 int start
, start_byte
, limit_byte
, count
;
18672 register unsigned char *cursor
;
18673 unsigned char *base
;
18675 register int ceiling
;
18676 register unsigned char *ceiling_addr
;
18677 int orig_count
= count
;
18679 /* If we are not in selective display mode,
18680 check only for newlines. */
18681 int selective_display
= (!NILP (current_buffer
->selective_display
)
18682 && !INTEGERP (current_buffer
->selective_display
));
18686 while (start_byte
< limit_byte
)
18688 ceiling
= BUFFER_CEILING_OF (start_byte
);
18689 ceiling
= min (limit_byte
- 1, ceiling
);
18690 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18691 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18694 if (selective_display
)
18695 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18698 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18701 if (cursor
!= ceiling_addr
)
18705 start_byte
+= cursor
- base
+ 1;
18706 *byte_pos_ptr
= start_byte
;
18710 if (++cursor
== ceiling_addr
)
18716 start_byte
+= cursor
- base
;
18721 while (start_byte
> limit_byte
)
18723 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18724 ceiling
= max (limit_byte
, ceiling
);
18725 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18726 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18729 if (selective_display
)
18730 while (--cursor
!= ceiling_addr
18731 && *cursor
!= '\n' && *cursor
!= 015)
18734 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18737 if (cursor
!= ceiling_addr
)
18741 start_byte
+= cursor
- base
+ 1;
18742 *byte_pos_ptr
= start_byte
;
18743 /* When scanning backwards, we should
18744 not count the newline posterior to which we stop. */
18745 return - orig_count
- 1;
18751 /* Here we add 1 to compensate for the last decrement
18752 of CURSOR, which took it past the valid range. */
18753 start_byte
+= cursor
- base
+ 1;
18757 *byte_pos_ptr
= limit_byte
;
18760 return - orig_count
+ count
;
18761 return orig_count
- count
;
18767 /***********************************************************************
18769 ***********************************************************************/
18771 /* Display a NUL-terminated string, starting with index START.
18773 If STRING is non-null, display that C string. Otherwise, the Lisp
18774 string LISP_STRING is displayed.
18776 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18777 FACE_STRING. Display STRING or LISP_STRING with the face at
18778 FACE_STRING_POS in FACE_STRING:
18780 Display the string in the environment given by IT, but use the
18781 standard display table, temporarily.
18783 FIELD_WIDTH is the minimum number of output glyphs to produce.
18784 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18785 with spaces. If STRING has more characters, more than FIELD_WIDTH
18786 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18788 PRECISION is the maximum number of characters to output from
18789 STRING. PRECISION < 0 means don't truncate the string.
18791 This is roughly equivalent to printf format specifiers:
18793 FIELD_WIDTH PRECISION PRINTF
18794 ----------------------------------------
18800 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18801 display them, and < 0 means obey the current buffer's value of
18802 enable_multibyte_characters.
18804 Value is the number of columns displayed. */
18807 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18808 start
, it
, field_width
, precision
, max_x
, multibyte
)
18809 unsigned char *string
;
18810 Lisp_Object lisp_string
;
18811 Lisp_Object face_string
;
18812 EMACS_INT face_string_pos
;
18815 int field_width
, precision
, max_x
;
18818 int hpos_at_start
= it
->hpos
;
18819 int saved_face_id
= it
->face_id
;
18820 struct glyph_row
*row
= it
->glyph_row
;
18822 /* Initialize the iterator IT for iteration over STRING beginning
18823 with index START. */
18824 reseat_to_string (it
, string
, lisp_string
, start
,
18825 precision
, field_width
, multibyte
);
18827 /* If displaying STRING, set up the face of the iterator
18828 from LISP_STRING, if that's given. */
18829 if (STRINGP (face_string
))
18835 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18836 0, it
->region_beg_charpos
,
18837 it
->region_end_charpos
,
18838 &endptr
, it
->base_face_id
, 0);
18839 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18840 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18843 /* Set max_x to the maximum allowed X position. Don't let it go
18844 beyond the right edge of the window. */
18846 max_x
= it
->last_visible_x
;
18848 max_x
= min (max_x
, it
->last_visible_x
);
18850 /* Skip over display elements that are not visible. because IT->w is
18852 if (it
->current_x
< it
->first_visible_x
)
18853 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18854 MOVE_TO_POS
| MOVE_TO_X
);
18856 row
->ascent
= it
->max_ascent
;
18857 row
->height
= it
->max_ascent
+ it
->max_descent
;
18858 row
->phys_ascent
= it
->max_phys_ascent
;
18859 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18860 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18862 /* This condition is for the case that we are called with current_x
18863 past last_visible_x. */
18864 while (it
->current_x
< max_x
)
18866 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18868 /* Get the next display element. */
18869 if (!get_next_display_element (it
))
18872 /* Produce glyphs. */
18873 x_before
= it
->current_x
;
18874 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18875 PRODUCE_GLYPHS (it
);
18877 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18880 while (i
< nglyphs
)
18882 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18884 if (it
->line_wrap
!= TRUNCATE
18885 && x
+ glyph
->pixel_width
> max_x
)
18887 /* End of continued line or max_x reached. */
18888 if (CHAR_GLYPH_PADDING_P (*glyph
))
18890 /* A wide character is unbreakable. */
18891 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18892 it
->current_x
= x_before
;
18896 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18901 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18903 /* Glyph is at least partially visible. */
18905 if (x
< it
->first_visible_x
)
18906 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18910 /* Glyph is off the left margin of the display area.
18911 Should not happen. */
18915 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18916 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18917 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18918 row
->phys_height
= max (row
->phys_height
,
18919 it
->max_phys_ascent
+ it
->max_phys_descent
);
18920 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18921 it
->max_extra_line_spacing
);
18922 x
+= glyph
->pixel_width
;
18926 /* Stop if max_x reached. */
18930 /* Stop at line ends. */
18931 if (ITERATOR_AT_END_OF_LINE_P (it
))
18933 it
->continuation_lines_width
= 0;
18937 set_iterator_to_next (it
, 1);
18939 /* Stop if truncating at the right edge. */
18940 if (it
->line_wrap
== TRUNCATE
18941 && it
->current_x
>= it
->last_visible_x
)
18943 /* Add truncation mark, but don't do it if the line is
18944 truncated at a padding space. */
18945 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18947 if (!FRAME_WINDOW_P (it
->f
))
18951 if (it
->current_x
> it
->last_visible_x
)
18953 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18954 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18956 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18958 row
->used
[TEXT_AREA
] = i
;
18959 produce_special_glyphs (it
, IT_TRUNCATION
);
18962 produce_special_glyphs (it
, IT_TRUNCATION
);
18964 it
->glyph_row
->truncated_on_right_p
= 1;
18970 /* Maybe insert a truncation at the left. */
18971 if (it
->first_visible_x
18972 && IT_CHARPOS (*it
) > 0)
18974 if (!FRAME_WINDOW_P (it
->f
))
18975 insert_left_trunc_glyphs (it
);
18976 it
->glyph_row
->truncated_on_left_p
= 1;
18979 it
->face_id
= saved_face_id
;
18981 /* Value is number of columns displayed. */
18982 return it
->hpos
- hpos_at_start
;
18987 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18988 appears as an element of LIST or as the car of an element of LIST.
18989 If PROPVAL is a list, compare each element against LIST in that
18990 way, and return 1/2 if any element of PROPVAL is found in LIST.
18991 Otherwise return 0. This function cannot quit.
18992 The return value is 2 if the text is invisible but with an ellipsis
18993 and 1 if it's invisible and without an ellipsis. */
18996 invisible_p (propval
, list
)
18997 register Lisp_Object propval
;
19000 register Lisp_Object tail
, proptail
;
19002 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19004 register Lisp_Object tem
;
19006 if (EQ (propval
, tem
))
19008 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19009 return NILP (XCDR (tem
)) ? 1 : 2;
19012 if (CONSP (propval
))
19014 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19016 Lisp_Object propelt
;
19017 propelt
= XCAR (proptail
);
19018 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19020 register Lisp_Object tem
;
19022 if (EQ (propelt
, tem
))
19024 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19025 return NILP (XCDR (tem
)) ? 1 : 2;
19033 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19034 doc
: /* Non-nil if the property makes the text invisible.
19035 POS-OR-PROP can be a marker or number, in which case it is taken to be
19036 a position in the current buffer and the value of the `invisible' property
19037 is checked; or it can be some other value, which is then presumed to be the
19038 value of the `invisible' property of the text of interest.
19039 The non-nil value returned can be t for truly invisible text or something
19040 else if the text is replaced by an ellipsis. */)
19042 Lisp_Object pos_or_prop
;
19045 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19046 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19048 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19049 return (invis
== 0 ? Qnil
19051 : make_number (invis
));
19054 /* Calculate a width or height in pixels from a specification using
19055 the following elements:
19058 NUM - a (fractional) multiple of the default font width/height
19059 (NUM) - specifies exactly NUM pixels
19060 UNIT - a fixed number of pixels, see below.
19061 ELEMENT - size of a display element in pixels, see below.
19062 (NUM . SPEC) - equals NUM * SPEC
19063 (+ SPEC SPEC ...) - add pixel values
19064 (- SPEC SPEC ...) - subtract pixel values
19065 (- SPEC) - negate pixel value
19068 INT or FLOAT - a number constant
19069 SYMBOL - use symbol's (buffer local) variable binding.
19072 in - pixels per inch *)
19073 mm - pixels per 1/1000 meter *)
19074 cm - pixels per 1/100 meter *)
19075 width - width of current font in pixels.
19076 height - height of current font in pixels.
19078 *) using the ratio(s) defined in display-pixels-per-inch.
19082 left-fringe - left fringe width in pixels
19083 right-fringe - right fringe width in pixels
19085 left-margin - left margin width in pixels
19086 right-margin - right margin width in pixels
19088 scroll-bar - scroll-bar area width in pixels
19092 Pixels corresponding to 5 inches:
19095 Total width of non-text areas on left side of window (if scroll-bar is on left):
19096 '(space :width (+ left-fringe left-margin scroll-bar))
19098 Align to first text column (in header line):
19099 '(space :align-to 0)
19101 Align to middle of text area minus half the width of variable `my-image'
19102 containing a loaded image:
19103 '(space :align-to (0.5 . (- text my-image)))
19105 Width of left margin minus width of 1 character in the default font:
19106 '(space :width (- left-margin 1))
19108 Width of left margin minus width of 2 characters in the current font:
19109 '(space :width (- left-margin (2 . width)))
19111 Center 1 character over left-margin (in header line):
19112 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19114 Different ways to express width of left fringe plus left margin minus one pixel:
19115 '(space :width (- (+ left-fringe left-margin) (1)))
19116 '(space :width (+ left-fringe left-margin (- (1))))
19117 '(space :width (+ left-fringe left-margin (-1)))
19121 #define NUMVAL(X) \
19122 ((INTEGERP (X) || FLOATP (X)) \
19127 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19132 int width_p
, *align_to
;
19136 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19137 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19140 return OK_PIXELS (0);
19142 xassert (FRAME_LIVE_P (it
->f
));
19144 if (SYMBOLP (prop
))
19146 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19148 char *unit
= SDATA (SYMBOL_NAME (prop
));
19150 if (unit
[0] == 'i' && unit
[1] == 'n')
19152 else if (unit
[0] == 'm' && unit
[1] == 'm')
19154 else if (unit
[0] == 'c' && unit
[1] == 'm')
19161 #ifdef HAVE_WINDOW_SYSTEM
19162 if (FRAME_WINDOW_P (it
->f
)
19164 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19165 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19167 return OK_PIXELS (ppi
/ pixels
);
19170 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19171 || (CONSP (Vdisplay_pixels_per_inch
)
19173 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19174 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19176 return OK_PIXELS (ppi
/ pixels
);
19182 #ifdef HAVE_WINDOW_SYSTEM
19183 if (EQ (prop
, Qheight
))
19184 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19185 if (EQ (prop
, Qwidth
))
19186 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19188 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19189 return OK_PIXELS (1);
19192 if (EQ (prop
, Qtext
))
19193 return OK_PIXELS (width_p
19194 ? window_box_width (it
->w
, TEXT_AREA
)
19195 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19197 if (align_to
&& *align_to
< 0)
19200 if (EQ (prop
, Qleft
))
19201 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19202 if (EQ (prop
, Qright
))
19203 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19204 if (EQ (prop
, Qcenter
))
19205 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19206 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19207 if (EQ (prop
, Qleft_fringe
))
19208 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19209 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19210 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19211 if (EQ (prop
, Qright_fringe
))
19212 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19213 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19214 : window_box_right_offset (it
->w
, TEXT_AREA
));
19215 if (EQ (prop
, Qleft_margin
))
19216 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19217 if (EQ (prop
, Qright_margin
))
19218 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19219 if (EQ (prop
, Qscroll_bar
))
19220 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19222 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19223 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19224 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19229 if (EQ (prop
, Qleft_fringe
))
19230 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19231 if (EQ (prop
, Qright_fringe
))
19232 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19233 if (EQ (prop
, Qleft_margin
))
19234 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19235 if (EQ (prop
, Qright_margin
))
19236 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19237 if (EQ (prop
, Qscroll_bar
))
19238 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19241 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19244 if (INTEGERP (prop
) || FLOATP (prop
))
19246 int base_unit
= (width_p
19247 ? FRAME_COLUMN_WIDTH (it
->f
)
19248 : FRAME_LINE_HEIGHT (it
->f
));
19249 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19254 Lisp_Object car
= XCAR (prop
);
19255 Lisp_Object cdr
= XCDR (prop
);
19259 #ifdef HAVE_WINDOW_SYSTEM
19260 if (FRAME_WINDOW_P (it
->f
)
19261 && valid_image_p (prop
))
19263 int id
= lookup_image (it
->f
, prop
);
19264 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19266 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19269 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19275 while (CONSP (cdr
))
19277 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19278 font
, width_p
, align_to
))
19281 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19286 if (EQ (car
, Qminus
))
19288 return OK_PIXELS (pixels
);
19291 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19294 if (INTEGERP (car
) || FLOATP (car
))
19297 pixels
= XFLOATINT (car
);
19299 return OK_PIXELS (pixels
);
19300 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19301 font
, width_p
, align_to
))
19302 return OK_PIXELS (pixels
* fact
);
19313 /***********************************************************************
19315 ***********************************************************************/
19317 #ifdef HAVE_WINDOW_SYSTEM
19322 dump_glyph_string (s
)
19323 struct glyph_string
*s
;
19325 fprintf (stderr
, "glyph string\n");
19326 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19327 s
->x
, s
->y
, s
->width
, s
->height
);
19328 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19329 fprintf (stderr
, " hl = %d\n", s
->hl
);
19330 fprintf (stderr
, " left overhang = %d, right = %d\n",
19331 s
->left_overhang
, s
->right_overhang
);
19332 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19333 fprintf (stderr
, " extends to end of line = %d\n",
19334 s
->extends_to_end_of_line_p
);
19335 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19336 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19339 #endif /* GLYPH_DEBUG */
19341 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19342 of XChar2b structures for S; it can't be allocated in
19343 init_glyph_string because it must be allocated via `alloca'. W
19344 is the window on which S is drawn. ROW and AREA are the glyph row
19345 and area within the row from which S is constructed. START is the
19346 index of the first glyph structure covered by S. HL is a
19347 face-override for drawing S. */
19350 #define OPTIONAL_HDC(hdc) hdc,
19351 #define DECLARE_HDC(hdc) HDC hdc;
19352 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19353 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19356 #ifndef OPTIONAL_HDC
19357 #define OPTIONAL_HDC(hdc)
19358 #define DECLARE_HDC(hdc)
19359 #define ALLOCATE_HDC(hdc, f)
19360 #define RELEASE_HDC(hdc, f)
19364 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19365 struct glyph_string
*s
;
19369 struct glyph_row
*row
;
19370 enum glyph_row_area area
;
19372 enum draw_glyphs_face hl
;
19374 bzero (s
, sizeof *s
);
19376 s
->f
= XFRAME (w
->frame
);
19380 s
->display
= FRAME_X_DISPLAY (s
->f
);
19381 s
->window
= FRAME_X_WINDOW (s
->f
);
19382 s
->char2b
= char2b
;
19386 s
->first_glyph
= row
->glyphs
[area
] + start
;
19387 s
->height
= row
->height
;
19388 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19390 /* Display the internal border below the tool-bar window. */
19391 if (WINDOWP (s
->f
->tool_bar_window
)
19392 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19393 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19395 s
->ybase
= s
->y
+ row
->ascent
;
19399 /* Append the list of glyph strings with head H and tail T to the list
19400 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19403 append_glyph_string_lists (head
, tail
, h
, t
)
19404 struct glyph_string
**head
, **tail
;
19405 struct glyph_string
*h
, *t
;
19419 /* Prepend the list of glyph strings with head H and tail T to the
19420 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19424 prepend_glyph_string_lists (head
, tail
, h
, t
)
19425 struct glyph_string
**head
, **tail
;
19426 struct glyph_string
*h
, *t
;
19440 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19441 Set *HEAD and *TAIL to the resulting list. */
19444 append_glyph_string (head
, tail
, s
)
19445 struct glyph_string
**head
, **tail
;
19446 struct glyph_string
*s
;
19448 s
->next
= s
->prev
= NULL
;
19449 append_glyph_string_lists (head
, tail
, s
, s
);
19453 /* Get face and two-byte form of character C in face FACE_ID on frame
19454 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19455 means we want to display multibyte text. DISPLAY_P non-zero means
19456 make sure that X resources for the face returned are allocated.
19457 Value is a pointer to a realized face that is ready for display if
19458 DISPLAY_P is non-zero. */
19460 static INLINE
struct face
*
19461 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19465 int multibyte_p
, display_p
;
19467 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19471 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19473 if (code
!= FONT_INVALID_CODE
)
19474 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19476 STORE_XCHAR2B (char2b
, 0, 0);
19479 /* Make sure X resources of the face are allocated. */
19480 #ifdef HAVE_X_WINDOWS
19484 xassert (face
!= NULL
);
19485 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19492 /* Get face and two-byte form of character glyph GLYPH on frame F.
19493 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19494 a pointer to a realized face that is ready for display. */
19496 static INLINE
struct face
*
19497 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19499 struct glyph
*glyph
;
19505 xassert (glyph
->type
== CHAR_GLYPH
);
19506 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19513 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19515 if (code
!= FONT_INVALID_CODE
)
19516 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19518 STORE_XCHAR2B (char2b
, 0, 0);
19521 /* Make sure X resources of the face are allocated. */
19522 xassert (face
!= NULL
);
19523 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19528 /* Fill glyph string S with composition components specified by S->cmp.
19530 BASE_FACE is the base face of the composition.
19531 S->cmp_from is the index of the first component for S.
19533 OVERLAPS non-zero means S should draw the foreground only, and use
19534 its physical height for clipping. See also draw_glyphs.
19536 Value is the index of a component not in S. */
19539 fill_composite_glyph_string (s
, base_face
, overlaps
)
19540 struct glyph_string
*s
;
19541 struct face
*base_face
;
19545 /* For all glyphs of this composition, starting at the offset
19546 S->cmp_from, until we reach the end of the definition or encounter a
19547 glyph that requires the different face, add it to S. */
19552 s
->for_overlaps
= overlaps
;
19555 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
19557 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19561 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19564 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19565 s
->char2b
+ i
, 1, 1);
19571 s
->font
= s
->face
->font
;
19573 else if (s
->face
!= face
)
19581 /* All glyph strings for the same composition has the same width,
19582 i.e. the width set for the first component of the composition. */
19583 s
->width
= s
->first_glyph
->pixel_width
;
19585 /* If the specified font could not be loaded, use the frame's
19586 default font, but record the fact that we couldn't load it in
19587 the glyph string so that we can draw rectangles for the
19588 characters of the glyph string. */
19589 if (s
->font
== NULL
)
19591 s
->font_not_found_p
= 1;
19592 s
->font
= FRAME_FONT (s
->f
);
19595 /* Adjust base line for subscript/superscript text. */
19596 s
->ybase
+= s
->first_glyph
->voffset
;
19598 /* This glyph string must always be drawn with 16-bit functions. */
19605 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
19606 struct glyph_string
*s
;
19608 int start
, end
, overlaps
;
19610 struct glyph
*glyph
, *last
;
19611 Lisp_Object lgstring
;
19614 s
->for_overlaps
= overlaps
;
19615 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19616 last
= s
->row
->glyphs
[s
->area
] + end
;
19617 s
->cmp_id
= glyph
->u
.cmp
.id
;
19618 s
->cmp_from
= glyph
->u
.cmp
.from
;
19619 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
19620 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19621 lgstring
= composition_gstring_from_id (s
->cmp_id
);
19622 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
19624 while (glyph
< last
19625 && glyph
->u
.cmp
.automatic
19626 && glyph
->u
.cmp
.id
== s
->cmp_id
19627 && s
->cmp_to
== glyph
->u
.cmp
.from
)
19628 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
19630 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
19632 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
19633 unsigned code
= LGLYPH_CODE (lglyph
);
19635 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
19637 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
19638 return glyph
- s
->row
->glyphs
[s
->area
];
19642 /* Fill glyph string S from a sequence of character glyphs.
19644 FACE_ID is the face id of the string. START is the index of the
19645 first glyph to consider, END is the index of the last + 1.
19646 OVERLAPS non-zero means S should draw the foreground only, and use
19647 its physical height for clipping. See also draw_glyphs.
19649 Value is the index of the first glyph not in S. */
19652 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19653 struct glyph_string
*s
;
19655 int start
, end
, overlaps
;
19657 struct glyph
*glyph
, *last
;
19659 int glyph_not_available_p
;
19661 xassert (s
->f
== XFRAME (s
->w
->frame
));
19662 xassert (s
->nchars
== 0);
19663 xassert (start
>= 0 && end
> start
);
19665 s
->for_overlaps
= overlaps
;
19666 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19667 last
= s
->row
->glyphs
[s
->area
] + end
;
19668 voffset
= glyph
->voffset
;
19669 s
->padding_p
= glyph
->padding_p
;
19670 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19672 while (glyph
< last
19673 && glyph
->type
== CHAR_GLYPH
19674 && glyph
->voffset
== voffset
19675 /* Same face id implies same font, nowadays. */
19676 && glyph
->face_id
== face_id
19677 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19681 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19682 s
->char2b
+ s
->nchars
,
19684 s
->two_byte_p
= two_byte_p
;
19686 xassert (s
->nchars
<= end
- start
);
19687 s
->width
+= glyph
->pixel_width
;
19688 if (glyph
++->padding_p
!= s
->padding_p
)
19692 s
->font
= s
->face
->font
;
19694 /* If the specified font could not be loaded, use the frame's font,
19695 but record the fact that we couldn't load it in
19696 S->font_not_found_p so that we can draw rectangles for the
19697 characters of the glyph string. */
19698 if (s
->font
== NULL
|| glyph_not_available_p
)
19700 s
->font_not_found_p
= 1;
19701 s
->font
= FRAME_FONT (s
->f
);
19704 /* Adjust base line for subscript/superscript text. */
19705 s
->ybase
+= voffset
;
19707 xassert (s
->face
&& s
->face
->gc
);
19708 return glyph
- s
->row
->glyphs
[s
->area
];
19712 /* Fill glyph string S from image glyph S->first_glyph. */
19715 fill_image_glyph_string (s
)
19716 struct glyph_string
*s
;
19718 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19719 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19721 s
->slice
= s
->first_glyph
->slice
;
19722 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19723 s
->font
= s
->face
->font
;
19724 s
->width
= s
->first_glyph
->pixel_width
;
19726 /* Adjust base line for subscript/superscript text. */
19727 s
->ybase
+= s
->first_glyph
->voffset
;
19731 /* Fill glyph string S from a sequence of stretch glyphs.
19733 ROW is the glyph row in which the glyphs are found, AREA is the
19734 area within the row. START is the index of the first glyph to
19735 consider, END is the index of the last + 1.
19737 Value is the index of the first glyph not in S. */
19740 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19741 struct glyph_string
*s
;
19742 struct glyph_row
*row
;
19743 enum glyph_row_area area
;
19746 struct glyph
*glyph
, *last
;
19747 int voffset
, face_id
;
19749 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19751 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19752 last
= s
->row
->glyphs
[s
->area
] + end
;
19753 face_id
= glyph
->face_id
;
19754 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19755 s
->font
= s
->face
->font
;
19756 s
->width
= glyph
->pixel_width
;
19758 voffset
= glyph
->voffset
;
19762 && glyph
->type
== STRETCH_GLYPH
19763 && glyph
->voffset
== voffset
19764 && glyph
->face_id
== face_id
);
19766 s
->width
+= glyph
->pixel_width
;
19768 /* Adjust base line for subscript/superscript text. */
19769 s
->ybase
+= voffset
;
19771 /* The case that face->gc == 0 is handled when drawing the glyph
19772 string by calling PREPARE_FACE_FOR_DISPLAY. */
19774 return glyph
- s
->row
->glyphs
[s
->area
];
19777 static struct font_metrics
*
19778 get_per_char_metric (f
, font
, char2b
)
19783 static struct font_metrics metrics
;
19784 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19786 if (! font
|| code
== FONT_INVALID_CODE
)
19788 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19793 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19794 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19795 assumed to be zero. */
19798 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19799 struct glyph
*glyph
;
19803 *left
= *right
= 0;
19805 if (glyph
->type
== CHAR_GLYPH
)
19809 struct font_metrics
*pcm
;
19811 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19812 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19814 if (pcm
->rbearing
> pcm
->width
)
19815 *right
= pcm
->rbearing
- pcm
->width
;
19816 if (pcm
->lbearing
< 0)
19817 *left
= -pcm
->lbearing
;
19820 else if (glyph
->type
== COMPOSITE_GLYPH
)
19822 if (! glyph
->u
.cmp
.automatic
)
19824 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
19826 if (cmp
->rbearing
> cmp
->pixel_width
)
19827 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19828 if (cmp
->lbearing
< 0)
19829 *left
= - cmp
->lbearing
;
19833 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
19834 struct font_metrics metrics
;
19836 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
19837 glyph
->u
.cmp
.to
+ 1, &metrics
);
19838 if (metrics
.rbearing
> metrics
.width
)
19839 *right
= metrics
.rbearing
- metrics
.width
;
19840 if (metrics
.lbearing
< 0)
19841 *left
= - metrics
.lbearing
;
19847 /* Return the index of the first glyph preceding glyph string S that
19848 is overwritten by S because of S's left overhang. Value is -1
19849 if no glyphs are overwritten. */
19852 left_overwritten (s
)
19853 struct glyph_string
*s
;
19857 if (s
->left_overhang
)
19860 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19861 int first
= s
->first_glyph
- glyphs
;
19863 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19864 x
-= glyphs
[i
].pixel_width
;
19875 /* Return the index of the first glyph preceding glyph string S that
19876 is overwriting S because of its right overhang. Value is -1 if no
19877 glyph in front of S overwrites S. */
19880 left_overwriting (s
)
19881 struct glyph_string
*s
;
19884 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19885 int first
= s
->first_glyph
- glyphs
;
19889 for (i
= first
- 1; i
>= 0; --i
)
19892 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19895 x
-= glyphs
[i
].pixel_width
;
19902 /* Return the index of the last glyph following glyph string S that is
19903 overwritten by S because of S's right overhang. Value is -1 if
19904 no such glyph is found. */
19907 right_overwritten (s
)
19908 struct glyph_string
*s
;
19912 if (s
->right_overhang
)
19915 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19916 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19917 int end
= s
->row
->used
[s
->area
];
19919 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19920 x
+= glyphs
[i
].pixel_width
;
19929 /* Return the index of the last glyph following glyph string S that
19930 overwrites S because of its left overhang. Value is negative
19931 if no such glyph is found. */
19934 right_overwriting (s
)
19935 struct glyph_string
*s
;
19938 int end
= s
->row
->used
[s
->area
];
19939 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19940 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19944 for (i
= first
; i
< end
; ++i
)
19947 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19950 x
+= glyphs
[i
].pixel_width
;
19957 /* Set background width of glyph string S. START is the index of the
19958 first glyph following S. LAST_X is the right-most x-position + 1
19959 in the drawing area. */
19962 set_glyph_string_background_width (s
, start
, last_x
)
19963 struct glyph_string
*s
;
19967 /* If the face of this glyph string has to be drawn to the end of
19968 the drawing area, set S->extends_to_end_of_line_p. */
19970 if (start
== s
->row
->used
[s
->area
]
19971 && s
->area
== TEXT_AREA
19972 && ((s
->row
->fill_line_p
19973 && (s
->hl
== DRAW_NORMAL_TEXT
19974 || s
->hl
== DRAW_IMAGE_RAISED
19975 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19976 || s
->hl
== DRAW_MOUSE_FACE
))
19977 s
->extends_to_end_of_line_p
= 1;
19979 /* If S extends its face to the end of the line, set its
19980 background_width to the distance to the right edge of the drawing
19982 if (s
->extends_to_end_of_line_p
)
19983 s
->background_width
= last_x
- s
->x
+ 1;
19985 s
->background_width
= s
->width
;
19989 /* Compute overhangs and x-positions for glyph string S and its
19990 predecessors, or successors. X is the starting x-position for S.
19991 BACKWARD_P non-zero means process predecessors. */
19994 compute_overhangs_and_x (s
, x
, backward_p
)
19995 struct glyph_string
*s
;
20003 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20004 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20014 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20015 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20025 /* The following macros are only called from draw_glyphs below.
20026 They reference the following parameters of that function directly:
20027 `w', `row', `area', and `overlap_p'
20028 as well as the following local variables:
20029 `s', `f', and `hdc' (in W32) */
20032 /* On W32, silently add local `hdc' variable to argument list of
20033 init_glyph_string. */
20034 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20035 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20037 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20038 init_glyph_string (s, char2b, w, row, area, start, hl)
20041 /* Add a glyph string for a stretch glyph to the list of strings
20042 between HEAD and TAIL. START is the index of the stretch glyph in
20043 row area AREA of glyph row ROW. END is the index of the last glyph
20044 in that glyph row area. X is the current output position assigned
20045 to the new glyph string constructed. HL overrides that face of the
20046 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20047 is the right-most x-position of the drawing area. */
20049 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20050 and below -- keep them on one line. */
20051 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20054 s = (struct glyph_string *) alloca (sizeof *s); \
20055 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20056 START = fill_stretch_glyph_string (s, row, area, START, END); \
20057 append_glyph_string (&HEAD, &TAIL, s); \
20063 /* Add a glyph string for an image glyph to the list of strings
20064 between HEAD and TAIL. START is the index of the image glyph in
20065 row area AREA of glyph row ROW. END is the index of the last glyph
20066 in that glyph row area. X is the current output position assigned
20067 to the new glyph string constructed. HL overrides that face of the
20068 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20069 is the right-most x-position of the drawing area. */
20071 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20074 s = (struct glyph_string *) alloca (sizeof *s); \
20075 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20076 fill_image_glyph_string (s); \
20077 append_glyph_string (&HEAD, &TAIL, s); \
20084 /* Add a glyph string for a sequence of character glyphs to the list
20085 of strings between HEAD and TAIL. START is the index of the first
20086 glyph in row area AREA of glyph row ROW that is part of the new
20087 glyph string. END is the index of the last glyph in that glyph row
20088 area. X is the current output position assigned to the new glyph
20089 string constructed. HL overrides that face of the glyph; e.g. it
20090 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20091 right-most x-position of the drawing area. */
20093 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20099 face_id = (row)->glyphs[area][START].face_id; \
20101 s = (struct glyph_string *) alloca (sizeof *s); \
20102 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20103 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20104 append_glyph_string (&HEAD, &TAIL, s); \
20106 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20111 /* Add a glyph string for a composite sequence to the list of strings
20112 between HEAD and TAIL. START is the index of the first glyph in
20113 row area AREA of glyph row ROW that is part of the new glyph
20114 string. END is the index of the last glyph in that glyph row area.
20115 X is the current output position assigned to the new glyph string
20116 constructed. HL overrides that face of the glyph; e.g. it is
20117 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20118 x-position of the drawing area. */
20120 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20122 int face_id = (row)->glyphs[area][START].face_id; \
20123 struct face *base_face = FACE_FROM_ID (f, face_id); \
20124 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20125 struct composition *cmp = composition_table[cmp_id]; \
20127 struct glyph_string *first_s; \
20130 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20132 /* Make glyph_strings for each glyph sequence that is drawable by \
20133 the same face, and append them to HEAD/TAIL. */ \
20134 for (n = 0; n < cmp->glyph_len;) \
20136 s = (struct glyph_string *) alloca (sizeof *s); \
20137 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20138 append_glyph_string (&(HEAD), &(TAIL), s); \
20144 n = fill_composite_glyph_string (s, base_face, overlaps); \
20152 /* Add a glyph string for a glyph-string sequence to the list of strings
20153 between HEAD and TAIL. */
20155 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20159 Lisp_Object gstring; \
20161 face_id = (row)->glyphs[area][START].face_id; \
20162 gstring = (composition_gstring_from_id \
20163 ((row)->glyphs[area][START].u.cmp.id)); \
20164 s = (struct glyph_string *) alloca (sizeof *s); \
20165 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20166 * LGSTRING_GLYPH_LEN (gstring)); \
20167 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20168 append_glyph_string (&(HEAD), &(TAIL), s); \
20170 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20174 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20175 of AREA of glyph row ROW on window W between indices START and END.
20176 HL overrides the face for drawing glyph strings, e.g. it is
20177 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20178 x-positions of the drawing area.
20180 This is an ugly monster macro construct because we must use alloca
20181 to allocate glyph strings (because draw_glyphs can be called
20182 asynchronously). */
20184 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20187 HEAD = TAIL = NULL; \
20188 while (START < END) \
20190 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20191 switch (first_glyph->type) \
20194 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20198 case COMPOSITE_GLYPH: \
20199 if (first_glyph->u.cmp.automatic) \
20200 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20203 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20207 case STRETCH_GLYPH: \
20208 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20212 case IMAGE_GLYPH: \
20213 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20223 set_glyph_string_background_width (s, START, LAST_X); \
20230 /* Draw glyphs between START and END in AREA of ROW on window W,
20231 starting at x-position X. X is relative to AREA in W. HL is a
20232 face-override with the following meaning:
20234 DRAW_NORMAL_TEXT draw normally
20235 DRAW_CURSOR draw in cursor face
20236 DRAW_MOUSE_FACE draw in mouse face.
20237 DRAW_INVERSE_VIDEO draw in mode line face
20238 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20239 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20241 If OVERLAPS is non-zero, draw only the foreground of characters and
20242 clip to the physical height of ROW. Non-zero value also defines
20243 the overlapping part to be drawn:
20245 OVERLAPS_PRED overlap with preceding rows
20246 OVERLAPS_SUCC overlap with succeeding rows
20247 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20248 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20250 Value is the x-position reached, relative to AREA of W. */
20253 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20256 struct glyph_row
*row
;
20257 enum glyph_row_area area
;
20258 EMACS_INT start
, end
;
20259 enum draw_glyphs_face hl
;
20262 struct glyph_string
*head
, *tail
;
20263 struct glyph_string
*s
;
20264 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20265 int i
, j
, x_reached
, last_x
, area_left
= 0;
20266 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20269 ALLOCATE_HDC (hdc
, f
);
20271 /* Let's rather be paranoid than getting a SEGV. */
20272 end
= min (end
, row
->used
[area
]);
20273 start
= max (0, start
);
20274 start
= min (end
, start
);
20276 /* Translate X to frame coordinates. Set last_x to the right
20277 end of the drawing area. */
20278 if (row
->full_width_p
)
20280 /* X is relative to the left edge of W, without scroll bars
20282 area_left
= WINDOW_LEFT_EDGE_X (w
);
20283 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20287 area_left
= window_box_left (w
, area
);
20288 last_x
= area_left
+ window_box_width (w
, area
);
20292 /* Build a doubly-linked list of glyph_string structures between
20293 head and tail from what we have to draw. Note that the macro
20294 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20295 the reason we use a separate variable `i'. */
20297 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20299 x_reached
= tail
->x
+ tail
->background_width
;
20303 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20304 the row, redraw some glyphs in front or following the glyph
20305 strings built above. */
20306 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20308 struct glyph_string
*h
, *t
;
20309 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20310 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20313 /* If mouse highlighting is on, we may need to draw adjacent
20314 glyphs using mouse-face highlighting. */
20315 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20317 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20319 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20320 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20322 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20324 check_mouse_face
= 1;
20325 mouse_beg_col
= (row
== mouse_beg_row
)
20326 ? dpyinfo
->mouse_face_beg_col
: 0;
20327 mouse_end_col
= (row
== mouse_end_row
)
20328 ? dpyinfo
->mouse_face_end_col
20329 : row
->used
[TEXT_AREA
];
20333 /* Compute overhangs for all glyph strings. */
20334 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20335 for (s
= head
; s
; s
= s
->next
)
20336 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20338 /* Prepend glyph strings for glyphs in front of the first glyph
20339 string that are overwritten because of the first glyph
20340 string's left overhang. The background of all strings
20341 prepended must be drawn because the first glyph string
20343 i
= left_overwritten (head
);
20346 enum draw_glyphs_face overlap_hl
;
20348 /* If this row contains mouse highlighting, attempt to draw
20349 the overlapped glyphs with the correct highlight. This
20350 code fails if the overlap encompasses more than one glyph
20351 and mouse-highlight spans only some of these glyphs.
20352 However, making it work perfectly involves a lot more
20353 code, and I don't know if the pathological case occurs in
20354 practice, so we'll stick to this for now. --- cyd */
20355 if (check_mouse_face
20356 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20357 overlap_hl
= DRAW_MOUSE_FACE
;
20359 overlap_hl
= DRAW_NORMAL_TEXT
;
20362 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20363 overlap_hl
, dummy_x
, last_x
);
20364 compute_overhangs_and_x (t
, head
->x
, 1);
20365 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20369 /* Prepend glyph strings for glyphs in front of the first glyph
20370 string that overwrite that glyph string because of their
20371 right overhang. For these strings, only the foreground must
20372 be drawn, because it draws over the glyph string at `head'.
20373 The background must not be drawn because this would overwrite
20374 right overhangs of preceding glyphs for which no glyph
20376 i
= left_overwriting (head
);
20379 enum draw_glyphs_face overlap_hl
;
20381 if (check_mouse_face
20382 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20383 overlap_hl
= DRAW_MOUSE_FACE
;
20385 overlap_hl
= DRAW_NORMAL_TEXT
;
20388 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20389 overlap_hl
, dummy_x
, last_x
);
20390 for (s
= h
; s
; s
= s
->next
)
20391 s
->background_filled_p
= 1;
20392 compute_overhangs_and_x (t
, head
->x
, 1);
20393 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20396 /* Append glyphs strings for glyphs following the last glyph
20397 string tail that are overwritten by tail. The background of
20398 these strings has to be drawn because tail's foreground draws
20400 i
= right_overwritten (tail
);
20403 enum draw_glyphs_face overlap_hl
;
20405 if (check_mouse_face
20406 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20407 overlap_hl
= DRAW_MOUSE_FACE
;
20409 overlap_hl
= DRAW_NORMAL_TEXT
;
20411 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20412 overlap_hl
, x
, last_x
);
20413 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20414 append_glyph_string_lists (&head
, &tail
, h
, t
);
20418 /* Append glyph strings for glyphs following the last glyph
20419 string tail that overwrite tail. The foreground of such
20420 glyphs has to be drawn because it writes into the background
20421 of tail. The background must not be drawn because it could
20422 paint over the foreground of following glyphs. */
20423 i
= right_overwriting (tail
);
20426 enum draw_glyphs_face overlap_hl
;
20427 if (check_mouse_face
20428 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20429 overlap_hl
= DRAW_MOUSE_FACE
;
20431 overlap_hl
= DRAW_NORMAL_TEXT
;
20434 i
++; /* We must include the Ith glyph. */
20435 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20436 overlap_hl
, x
, last_x
);
20437 for (s
= h
; s
; s
= s
->next
)
20438 s
->background_filled_p
= 1;
20439 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20440 append_glyph_string_lists (&head
, &tail
, h
, t
);
20442 if (clip_head
|| clip_tail
)
20443 for (s
= head
; s
; s
= s
->next
)
20445 s
->clip_head
= clip_head
;
20446 s
->clip_tail
= clip_tail
;
20450 /* Draw all strings. */
20451 for (s
= head
; s
; s
= s
->next
)
20452 FRAME_RIF (f
)->draw_glyph_string (s
);
20455 /* When focus a sole frame and move horizontally, this sets on_p to 0
20456 causing a failure to erase prev cursor position. */
20457 if (area
== TEXT_AREA
20458 && !row
->full_width_p
20459 /* When drawing overlapping rows, only the glyph strings'
20460 foreground is drawn, which doesn't erase a cursor
20464 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20465 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20466 : (tail
? tail
->x
+ tail
->background_width
: x
));
20470 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20471 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20475 /* Value is the x-position up to which drawn, relative to AREA of W.
20476 This doesn't include parts drawn because of overhangs. */
20477 if (row
->full_width_p
)
20478 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20480 x_reached
-= area_left
;
20482 RELEASE_HDC (hdc
, f
);
20487 /* Expand row matrix if too narrow. Don't expand if area
20490 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20492 if (!fonts_changed_p \
20493 && (it->glyph_row->glyphs[area] \
20494 < it->glyph_row->glyphs[area + 1])) \
20496 it->w->ncols_scale_factor++; \
20497 fonts_changed_p = 1; \
20501 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20502 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20508 struct glyph
*glyph
;
20509 enum glyph_row_area area
= it
->area
;
20511 xassert (it
->glyph_row
);
20512 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20514 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20515 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20517 glyph
->charpos
= CHARPOS (it
->position
);
20518 glyph
->object
= it
->object
;
20519 if (it
->pixel_width
> 0)
20521 glyph
->pixel_width
= it
->pixel_width
;
20522 glyph
->padding_p
= 0;
20526 /* Assure at least 1-pixel width. Otherwise, cursor can't
20527 be displayed correctly. */
20528 glyph
->pixel_width
= 1;
20529 glyph
->padding_p
= 1;
20531 glyph
->ascent
= it
->ascent
;
20532 glyph
->descent
= it
->descent
;
20533 glyph
->voffset
= it
->voffset
;
20534 glyph
->type
= CHAR_GLYPH
;
20535 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20536 glyph
->multibyte_p
= it
->multibyte_p
;
20537 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20538 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20539 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20540 || it
->phys_descent
> it
->descent
);
20541 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20542 glyph
->face_id
= it
->face_id
;
20543 glyph
->u
.ch
= it
->char_to_display
;
20544 glyph
->slice
= null_glyph_slice
;
20545 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20546 ++it
->glyph_row
->used
[area
];
20549 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20552 /* Store one glyph for the composition IT->cmp_it.id in
20553 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
20557 append_composite_glyph (it
)
20560 struct glyph
*glyph
;
20561 enum glyph_row_area area
= it
->area
;
20563 xassert (it
->glyph_row
);
20565 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20566 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20568 glyph
->charpos
= CHARPOS (it
->position
);
20569 glyph
->object
= it
->object
;
20570 glyph
->pixel_width
= it
->pixel_width
;
20571 glyph
->ascent
= it
->ascent
;
20572 glyph
->descent
= it
->descent
;
20573 glyph
->voffset
= it
->voffset
;
20574 glyph
->type
= COMPOSITE_GLYPH
;
20575 if (it
->cmp_it
.ch
< 0)
20577 glyph
->u
.cmp
.automatic
= 0;
20578 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20582 glyph
->u
.cmp
.automatic
= 1;
20583 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20584 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
20585 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
20587 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20588 glyph
->multibyte_p
= it
->multibyte_p
;
20589 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20590 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20591 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20592 || it
->phys_descent
> it
->descent
);
20593 glyph
->padding_p
= 0;
20594 glyph
->glyph_not_available_p
= 0;
20595 glyph
->face_id
= it
->face_id
;
20596 glyph
->slice
= null_glyph_slice
;
20597 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20598 ++it
->glyph_row
->used
[area
];
20601 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20605 /* Change IT->ascent and IT->height according to the setting of
20609 take_vertical_position_into_account (it
)
20614 if (it
->voffset
< 0)
20615 /* Increase the ascent so that we can display the text higher
20617 it
->ascent
-= it
->voffset
;
20619 /* Increase the descent so that we can display the text lower
20621 it
->descent
+= it
->voffset
;
20626 /* Produce glyphs/get display metrics for the image IT is loaded with.
20627 See the description of struct display_iterator in dispextern.h for
20628 an overview of struct display_iterator. */
20631 produce_image_glyph (it
)
20636 int glyph_ascent
, crop
;
20637 struct glyph_slice slice
;
20639 xassert (it
->what
== IT_IMAGE
);
20641 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20643 /* Make sure X resources of the face is loaded. */
20644 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20646 if (it
->image_id
< 0)
20648 /* Fringe bitmap. */
20649 it
->ascent
= it
->phys_ascent
= 0;
20650 it
->descent
= it
->phys_descent
= 0;
20651 it
->pixel_width
= 0;
20656 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20658 /* Make sure X resources of the image is loaded. */
20659 prepare_image_for_display (it
->f
, img
);
20661 slice
.x
= slice
.y
= 0;
20662 slice
.width
= img
->width
;
20663 slice
.height
= img
->height
;
20665 if (INTEGERP (it
->slice
.x
))
20666 slice
.x
= XINT (it
->slice
.x
);
20667 else if (FLOATP (it
->slice
.x
))
20668 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20670 if (INTEGERP (it
->slice
.y
))
20671 slice
.y
= XINT (it
->slice
.y
);
20672 else if (FLOATP (it
->slice
.y
))
20673 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20675 if (INTEGERP (it
->slice
.width
))
20676 slice
.width
= XINT (it
->slice
.width
);
20677 else if (FLOATP (it
->slice
.width
))
20678 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20680 if (INTEGERP (it
->slice
.height
))
20681 slice
.height
= XINT (it
->slice
.height
);
20682 else if (FLOATP (it
->slice
.height
))
20683 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20685 if (slice
.x
>= img
->width
)
20686 slice
.x
= img
->width
;
20687 if (slice
.y
>= img
->height
)
20688 slice
.y
= img
->height
;
20689 if (slice
.x
+ slice
.width
>= img
->width
)
20690 slice
.width
= img
->width
- slice
.x
;
20691 if (slice
.y
+ slice
.height
> img
->height
)
20692 slice
.height
= img
->height
- slice
.y
;
20694 if (slice
.width
== 0 || slice
.height
== 0)
20697 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20699 it
->descent
= slice
.height
- glyph_ascent
;
20701 it
->descent
+= img
->vmargin
;
20702 if (slice
.y
+ slice
.height
== img
->height
)
20703 it
->descent
+= img
->vmargin
;
20704 it
->phys_descent
= it
->descent
;
20706 it
->pixel_width
= slice
.width
;
20708 it
->pixel_width
+= img
->hmargin
;
20709 if (slice
.x
+ slice
.width
== img
->width
)
20710 it
->pixel_width
+= img
->hmargin
;
20712 /* It's quite possible for images to have an ascent greater than
20713 their height, so don't get confused in that case. */
20714 if (it
->descent
< 0)
20719 if (face
->box
!= FACE_NO_BOX
)
20721 if (face
->box_line_width
> 0)
20724 it
->ascent
+= face
->box_line_width
;
20725 if (slice
.y
+ slice
.height
== img
->height
)
20726 it
->descent
+= face
->box_line_width
;
20729 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20730 it
->pixel_width
+= eabs (face
->box_line_width
);
20731 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20732 it
->pixel_width
+= eabs (face
->box_line_width
);
20735 take_vertical_position_into_account (it
);
20737 /* Automatically crop wide image glyphs at right edge so we can
20738 draw the cursor on same display row. */
20739 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20740 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20742 it
->pixel_width
-= crop
;
20743 slice
.width
-= crop
;
20748 struct glyph
*glyph
;
20749 enum glyph_row_area area
= it
->area
;
20751 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20752 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20754 glyph
->charpos
= CHARPOS (it
->position
);
20755 glyph
->object
= it
->object
;
20756 glyph
->pixel_width
= it
->pixel_width
;
20757 glyph
->ascent
= glyph_ascent
;
20758 glyph
->descent
= it
->descent
;
20759 glyph
->voffset
= it
->voffset
;
20760 glyph
->type
= IMAGE_GLYPH
;
20761 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20762 glyph
->multibyte_p
= it
->multibyte_p
;
20763 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20764 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20765 glyph
->overlaps_vertically_p
= 0;
20766 glyph
->padding_p
= 0;
20767 glyph
->glyph_not_available_p
= 0;
20768 glyph
->face_id
= it
->face_id
;
20769 glyph
->u
.img_id
= img
->id
;
20770 glyph
->slice
= slice
;
20771 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20772 ++it
->glyph_row
->used
[area
];
20775 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20780 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20781 of the glyph, WIDTH and HEIGHT are the width and height of the
20782 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20785 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20787 Lisp_Object object
;
20791 struct glyph
*glyph
;
20792 enum glyph_row_area area
= it
->area
;
20794 xassert (ascent
>= 0 && ascent
<= height
);
20796 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20797 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20799 glyph
->charpos
= CHARPOS (it
->position
);
20800 glyph
->object
= object
;
20801 glyph
->pixel_width
= width
;
20802 glyph
->ascent
= ascent
;
20803 glyph
->descent
= height
- ascent
;
20804 glyph
->voffset
= it
->voffset
;
20805 glyph
->type
= STRETCH_GLYPH
;
20806 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20807 glyph
->multibyte_p
= it
->multibyte_p
;
20808 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20809 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20810 glyph
->overlaps_vertically_p
= 0;
20811 glyph
->padding_p
= 0;
20812 glyph
->glyph_not_available_p
= 0;
20813 glyph
->face_id
= it
->face_id
;
20814 glyph
->u
.stretch
.ascent
= ascent
;
20815 glyph
->u
.stretch
.height
= height
;
20816 glyph
->slice
= null_glyph_slice
;
20817 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20818 ++it
->glyph_row
->used
[area
];
20821 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20825 /* Produce a stretch glyph for iterator IT. IT->object is the value
20826 of the glyph property displayed. The value must be a list
20827 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20830 1. `:width WIDTH' specifies that the space should be WIDTH *
20831 canonical char width wide. WIDTH may be an integer or floating
20834 2. `:relative-width FACTOR' specifies that the width of the stretch
20835 should be computed from the width of the first character having the
20836 `glyph' property, and should be FACTOR times that width.
20838 3. `:align-to HPOS' specifies that the space should be wide enough
20839 to reach HPOS, a value in canonical character units.
20841 Exactly one of the above pairs must be present.
20843 4. `:height HEIGHT' specifies that the height of the stretch produced
20844 should be HEIGHT, measured in canonical character units.
20846 5. `:relative-height FACTOR' specifies that the height of the
20847 stretch should be FACTOR times the height of the characters having
20848 the glyph property.
20850 Either none or exactly one of 4 or 5 must be present.
20852 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20853 of the stretch should be used for the ascent of the stretch.
20854 ASCENT must be in the range 0 <= ASCENT <= 100. */
20857 produce_stretch_glyph (it
)
20860 /* (space :width WIDTH :height HEIGHT ...) */
20861 Lisp_Object prop
, plist
;
20862 int width
= 0, height
= 0, align_to
= -1;
20863 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20866 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20867 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20869 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20871 /* List should start with `space'. */
20872 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20873 plist
= XCDR (it
->object
);
20875 /* Compute the width of the stretch. */
20876 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20877 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20879 /* Absolute width `:width WIDTH' specified and valid. */
20880 zero_width_ok_p
= 1;
20883 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20886 /* Relative width `:relative-width FACTOR' specified and valid.
20887 Compute the width of the characters having the `glyph'
20890 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20893 if (it
->multibyte_p
)
20895 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20896 - IT_BYTEPOS (*it
));
20897 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20900 it2
.c
= *p
, it2
.len
= 1;
20902 it2
.glyph_row
= NULL
;
20903 it2
.what
= IT_CHARACTER
;
20904 x_produce_glyphs (&it2
);
20905 width
= NUMVAL (prop
) * it2
.pixel_width
;
20907 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20908 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20910 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20911 align_to
= (align_to
< 0
20913 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20914 else if (align_to
< 0)
20915 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20916 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20917 zero_width_ok_p
= 1;
20920 /* Nothing specified -> width defaults to canonical char width. */
20921 width
= FRAME_COLUMN_WIDTH (it
->f
);
20923 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20926 /* Compute height. */
20927 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20928 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20931 zero_height_ok_p
= 1;
20933 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20935 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20937 height
= FONT_HEIGHT (font
);
20939 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20942 /* Compute percentage of height used for ascent. If
20943 `:ascent ASCENT' is present and valid, use that. Otherwise,
20944 derive the ascent from the font in use. */
20945 if (prop
= Fplist_get (plist
, QCascent
),
20946 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20947 ascent
= height
* NUMVAL (prop
) / 100.0;
20948 else if (!NILP (prop
)
20949 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20950 ascent
= min (max (0, (int)tem
), height
);
20952 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20954 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20955 && it
->current_x
+ width
> it
->last_visible_x
)
20956 width
= it
->last_visible_x
- it
->current_x
- 1;
20958 if (width
> 0 && height
> 0 && it
->glyph_row
)
20960 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20961 if (!STRINGP (object
))
20962 object
= it
->w
->buffer
;
20963 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20966 it
->pixel_width
= width
;
20967 it
->ascent
= it
->phys_ascent
= ascent
;
20968 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20969 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20971 take_vertical_position_into_account (it
);
20974 /* Calculate line-height and line-spacing properties.
20975 An integer value specifies explicit pixel value.
20976 A float value specifies relative value to current face height.
20977 A cons (float . face-name) specifies relative value to
20978 height of specified face font.
20980 Returns height in pixels, or nil. */
20984 calc_line_height_property (it
, val
, font
, boff
, override
)
20988 int boff
, override
;
20990 Lisp_Object face_name
= Qnil
;
20991 int ascent
, descent
, height
;
20993 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20998 face_name
= XCAR (val
);
21000 if (!NUMBERP (val
))
21001 val
= make_number (1);
21002 if (NILP (face_name
))
21004 height
= it
->ascent
+ it
->descent
;
21009 if (NILP (face_name
))
21011 font
= FRAME_FONT (it
->f
);
21012 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21014 else if (EQ (face_name
, Qt
))
21023 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21025 return make_number (-1);
21027 face
= FACE_FROM_ID (it
->f
, face_id
);
21030 return make_number (-1);
21031 boff
= font
->baseline_offset
;
21032 if (font
->vertical_centering
)
21033 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21036 ascent
= FONT_BASE (font
) + boff
;
21037 descent
= FONT_DESCENT (font
) - boff
;
21041 it
->override_ascent
= ascent
;
21042 it
->override_descent
= descent
;
21043 it
->override_boff
= boff
;
21046 height
= ascent
+ descent
;
21050 height
= (int)(XFLOAT_DATA (val
) * height
);
21051 else if (INTEGERP (val
))
21052 height
*= XINT (val
);
21054 return make_number (height
);
21059 Produce glyphs/get display metrics for the display element IT is
21060 loaded with. See the description of struct it in dispextern.h
21061 for an overview of struct it. */
21064 x_produce_glyphs (it
)
21067 int extra_line_spacing
= it
->extra_line_spacing
;
21069 it
->glyph_not_available_p
= 0;
21071 if (it
->what
== IT_CHARACTER
)
21075 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21076 struct font_metrics
*pcm
;
21077 int font_not_found_p
;
21078 int boff
; /* baseline offset */
21079 /* We may change it->multibyte_p upon unibyte<->multibyte
21080 conversion. So, save the current value now and restore it
21083 Note: It seems that we don't have to record multibyte_p in
21084 struct glyph because the character code itself tells if or
21085 not the character is multibyte. Thus, in the future, we must
21086 consider eliminating the field `multibyte_p' in the struct
21088 int saved_multibyte_p
= it
->multibyte_p
;
21090 /* Maybe translate single-byte characters to multibyte, or the
21092 it
->char_to_display
= it
->c
;
21093 if (!ASCII_BYTE_P (it
->c
)
21094 && ! it
->multibyte_p
)
21096 if (SINGLE_BYTE_CHAR_P (it
->c
)
21097 && unibyte_display_via_language_environment
)
21099 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21101 /* get_next_display_element assures that this decoding
21103 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21104 it
->multibyte_p
= 1;
21105 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21107 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21111 /* Get font to use. Encode IT->char_to_display. */
21112 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21113 &char2b
, it
->multibyte_p
, 0);
21116 /* When no suitable font found, use the default font. */
21117 font_not_found_p
= font
== NULL
;
21118 if (font_not_found_p
)
21120 font
= FRAME_FONT (it
->f
);
21121 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21125 boff
= font
->baseline_offset
;
21126 if (font
->vertical_centering
)
21127 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21130 if (it
->char_to_display
>= ' '
21131 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21133 /* Either unibyte or ASCII. */
21138 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21140 if (it
->override_ascent
>= 0)
21142 it
->ascent
= it
->override_ascent
;
21143 it
->descent
= it
->override_descent
;
21144 boff
= it
->override_boff
;
21148 it
->ascent
= FONT_BASE (font
) + boff
;
21149 it
->descent
= FONT_DESCENT (font
) - boff
;
21154 it
->phys_ascent
= pcm
->ascent
+ boff
;
21155 it
->phys_descent
= pcm
->descent
- boff
;
21156 it
->pixel_width
= pcm
->width
;
21160 it
->glyph_not_available_p
= 1;
21161 it
->phys_ascent
= it
->ascent
;
21162 it
->phys_descent
= it
->descent
;
21163 it
->pixel_width
= FONT_WIDTH (font
);
21166 if (it
->constrain_row_ascent_descent_p
)
21168 if (it
->descent
> it
->max_descent
)
21170 it
->ascent
+= it
->descent
- it
->max_descent
;
21171 it
->descent
= it
->max_descent
;
21173 if (it
->ascent
> it
->max_ascent
)
21175 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21176 it
->ascent
= it
->max_ascent
;
21178 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21179 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21180 extra_line_spacing
= 0;
21183 /* If this is a space inside a region of text with
21184 `space-width' property, change its width. */
21185 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21187 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21189 /* If face has a box, add the box thickness to the character
21190 height. If character has a box line to the left and/or
21191 right, add the box line width to the character's width. */
21192 if (face
->box
!= FACE_NO_BOX
)
21194 int thick
= face
->box_line_width
;
21198 it
->ascent
+= thick
;
21199 it
->descent
+= thick
;
21204 if (it
->start_of_box_run_p
)
21205 it
->pixel_width
+= thick
;
21206 if (it
->end_of_box_run_p
)
21207 it
->pixel_width
+= thick
;
21210 /* If face has an overline, add the height of the overline
21211 (1 pixel) and a 1 pixel margin to the character height. */
21212 if (face
->overline_p
)
21213 it
->ascent
+= overline_margin
;
21215 if (it
->constrain_row_ascent_descent_p
)
21217 if (it
->ascent
> it
->max_ascent
)
21218 it
->ascent
= it
->max_ascent
;
21219 if (it
->descent
> it
->max_descent
)
21220 it
->descent
= it
->max_descent
;
21223 take_vertical_position_into_account (it
);
21225 /* If we have to actually produce glyphs, do it. */
21230 /* Translate a space with a `space-width' property
21231 into a stretch glyph. */
21232 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21233 / FONT_HEIGHT (font
));
21234 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21235 it
->ascent
+ it
->descent
, ascent
);
21240 /* If characters with lbearing or rbearing are displayed
21241 in this line, record that fact in a flag of the
21242 glyph row. This is used to optimize X output code. */
21243 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21244 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21246 if (! stretched_p
&& it
->pixel_width
== 0)
21247 /* We assure that all visible glyphs have at least 1-pixel
21249 it
->pixel_width
= 1;
21251 else if (it
->char_to_display
== '\n')
21253 /* A newline has no width but we need the height of the line.
21254 But if previous part of the line set a height, don't
21255 increase that height */
21257 Lisp_Object height
;
21258 Lisp_Object total_height
= Qnil
;
21260 it
->override_ascent
= -1;
21261 it
->pixel_width
= 0;
21264 height
= get_it_property(it
, Qline_height
);
21265 /* Split (line-height total-height) list */
21267 && CONSP (XCDR (height
))
21268 && NILP (XCDR (XCDR (height
))))
21270 total_height
= XCAR (XCDR (height
));
21271 height
= XCAR (height
);
21273 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21275 if (it
->override_ascent
>= 0)
21277 it
->ascent
= it
->override_ascent
;
21278 it
->descent
= it
->override_descent
;
21279 boff
= it
->override_boff
;
21283 it
->ascent
= FONT_BASE (font
) + boff
;
21284 it
->descent
= FONT_DESCENT (font
) - boff
;
21287 if (EQ (height
, Qt
))
21289 if (it
->descent
> it
->max_descent
)
21291 it
->ascent
+= it
->descent
- it
->max_descent
;
21292 it
->descent
= it
->max_descent
;
21294 if (it
->ascent
> it
->max_ascent
)
21296 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21297 it
->ascent
= it
->max_ascent
;
21299 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21300 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21301 it
->constrain_row_ascent_descent_p
= 1;
21302 extra_line_spacing
= 0;
21306 Lisp_Object spacing
;
21308 it
->phys_ascent
= it
->ascent
;
21309 it
->phys_descent
= it
->descent
;
21311 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21312 && face
->box
!= FACE_NO_BOX
21313 && face
->box_line_width
> 0)
21315 it
->ascent
+= face
->box_line_width
;
21316 it
->descent
+= face
->box_line_width
;
21319 && XINT (height
) > it
->ascent
+ it
->descent
)
21320 it
->ascent
= XINT (height
) - it
->descent
;
21322 if (!NILP (total_height
))
21323 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21326 spacing
= get_it_property(it
, Qline_spacing
);
21327 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21329 if (INTEGERP (spacing
))
21331 extra_line_spacing
= XINT (spacing
);
21332 if (!NILP (total_height
))
21333 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21337 else if (it
->char_to_display
== '\t')
21339 if (font
->space_width
> 0)
21341 int tab_width
= it
->tab_width
* font
->space_width
;
21342 int x
= it
->current_x
+ it
->continuation_lines_width
;
21343 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21345 /* If the distance from the current position to the next tab
21346 stop is less than a space character width, use the
21347 tab stop after that. */
21348 if (next_tab_x
- x
< font
->space_width
)
21349 next_tab_x
+= tab_width
;
21351 it
->pixel_width
= next_tab_x
- x
;
21353 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21354 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21358 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21359 it
->ascent
+ it
->descent
, it
->ascent
);
21364 it
->pixel_width
= 0;
21370 /* A multi-byte character. Assume that the display width of the
21371 character is the width of the character multiplied by the
21372 width of the font. */
21374 /* If we found a font, this font should give us the right
21375 metrics. If we didn't find a font, use the frame's
21376 default font and calculate the width of the character by
21377 multiplying the width of font by the width of the
21380 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21382 if (font_not_found_p
|| !pcm
)
21384 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21386 if (char_width
== 0)
21387 /* This is a non spacing character. But, as we are
21388 going to display an empty box, the box must occupy
21389 at least one column. */
21391 it
->glyph_not_available_p
= 1;
21392 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
21393 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21394 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21398 it
->pixel_width
= pcm
->width
;
21399 it
->phys_ascent
= pcm
->ascent
+ boff
;
21400 it
->phys_descent
= pcm
->descent
- boff
;
21402 && (pcm
->lbearing
< 0
21403 || pcm
->rbearing
> pcm
->width
))
21404 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21407 it
->ascent
= FONT_BASE (font
) + boff
;
21408 it
->descent
= FONT_DESCENT (font
) - boff
;
21409 if (face
->box
!= FACE_NO_BOX
)
21411 int thick
= face
->box_line_width
;
21415 it
->ascent
+= thick
;
21416 it
->descent
+= thick
;
21421 if (it
->start_of_box_run_p
)
21422 it
->pixel_width
+= thick
;
21423 if (it
->end_of_box_run_p
)
21424 it
->pixel_width
+= thick
;
21427 /* If face has an overline, add the height of the overline
21428 (1 pixel) and a 1 pixel margin to the character height. */
21429 if (face
->overline_p
)
21430 it
->ascent
+= overline_margin
;
21432 take_vertical_position_into_account (it
);
21434 if (it
->ascent
< 0)
21436 if (it
->descent
< 0)
21441 if (it
->pixel_width
== 0)
21442 /* We assure that all visible glyphs have at least 1-pixel
21444 it
->pixel_width
= 1;
21446 it
->multibyte_p
= saved_multibyte_p
;
21448 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
21450 /* A static compositoin.
21452 Note: A composition is represented as one glyph in the
21453 glyph matrix. There are no padding glyphs.
21455 Important is that pixel_width, ascent, and descent are the
21456 values of what is drawn by draw_glyphs (i.e. the values of
21457 the overall glyphs composed). */
21458 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21459 int boff
; /* baseline offset */
21460 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
21461 int glyph_len
= cmp
->glyph_len
;
21462 struct font
*font
= face
->font
;
21466 /* If we have not yet calculated pixel size data of glyphs of
21467 the composition for the current face font, calculate them
21468 now. Theoretically, we have to check all fonts for the
21469 glyphs, but that requires much time and memory space. So,
21470 here we check only the font of the first glyph. This leads
21471 to incorrect display, but it's very rare, and C-l (recenter)
21472 can correct the display anyway. */
21473 if (! cmp
->font
|| cmp
->font
!= font
)
21475 /* Ascent and descent of the font of the first character
21476 of this composition (adjusted by baseline offset).
21477 Ascent and descent of overall glyphs should not be less
21478 than them respectively. */
21479 int font_ascent
, font_descent
, font_height
;
21480 /* Bounding box of the overall glyphs. */
21481 int leftmost
, rightmost
, lowest
, highest
;
21482 int lbearing
, rbearing
;
21483 int i
, width
, ascent
, descent
;
21484 int left_padded
= 0, right_padded
= 0;
21487 struct font_metrics
*pcm
;
21488 int font_not_found_p
;
21491 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21492 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21494 if (glyph_len
< cmp
->glyph_len
)
21496 for (i
= 0; i
< glyph_len
; i
++)
21498 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21500 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21505 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21506 : IT_CHARPOS (*it
));
21507 /* When no suitable font found, use the default font. */
21508 font_not_found_p
= font
== NULL
;
21509 if (font_not_found_p
)
21511 face
= face
->ascii_face
;
21514 boff
= font
->baseline_offset
;
21515 if (font
->vertical_centering
)
21516 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21517 font_ascent
= FONT_BASE (font
) + boff
;
21518 font_descent
= FONT_DESCENT (font
) - boff
;
21519 font_height
= FONT_HEIGHT (font
);
21521 cmp
->font
= (void *) font
;
21524 if (! font_not_found_p
)
21526 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21527 &char2b
, it
->multibyte_p
, 0);
21528 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21531 /* Initialize the bounding box. */
21534 width
= pcm
->width
;
21535 ascent
= pcm
->ascent
;
21536 descent
= pcm
->descent
;
21537 lbearing
= pcm
->lbearing
;
21538 rbearing
= pcm
->rbearing
;
21542 width
= FONT_WIDTH (font
);
21543 ascent
= FONT_BASE (font
);
21544 descent
= FONT_DESCENT (font
);
21551 lowest
= - descent
+ boff
;
21552 highest
= ascent
+ boff
;
21554 if (! font_not_found_p
21555 && font
->default_ascent
21556 && CHAR_TABLE_P (Vuse_default_ascent
)
21557 && !NILP (Faref (Vuse_default_ascent
,
21558 make_number (it
->char_to_display
))))
21559 highest
= font
->default_ascent
+ boff
;
21561 /* Draw the first glyph at the normal position. It may be
21562 shifted to right later if some other glyphs are drawn
21564 cmp
->offsets
[i
* 2] = 0;
21565 cmp
->offsets
[i
* 2 + 1] = boff
;
21566 cmp
->lbearing
= lbearing
;
21567 cmp
->rbearing
= rbearing
;
21569 /* Set cmp->offsets for the remaining glyphs. */
21570 for (i
++; i
< glyph_len
; i
++)
21572 int left
, right
, btm
, top
;
21573 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21575 struct face
*this_face
;
21580 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21581 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21582 font
= this_face
->font
;
21588 this_boff
= font
->baseline_offset
;
21589 if (font
->vertical_centering
)
21590 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21591 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21592 &char2b
, it
->multibyte_p
, 0);
21593 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21596 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21599 width
= pcm
->width
;
21600 ascent
= pcm
->ascent
;
21601 descent
= pcm
->descent
;
21602 lbearing
= pcm
->lbearing
;
21603 rbearing
= pcm
->rbearing
;
21604 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21606 /* Relative composition with or without
21607 alternate chars. */
21608 left
= (leftmost
+ rightmost
- width
) / 2;
21609 btm
= - descent
+ boff
;
21610 if (font
->relative_compose
21611 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21612 || NILP (Faref (Vignore_relative_composition
,
21613 make_number (ch
)))))
21616 if (- descent
>= font
->relative_compose
)
21617 /* One extra pixel between two glyphs. */
21619 else if (ascent
<= 0)
21620 /* One extra pixel between two glyphs. */
21621 btm
= lowest
- 1 - ascent
- descent
;
21626 /* A composition rule is specified by an integer
21627 value that encodes global and new reference
21628 points (GREF and NREF). GREF and NREF are
21629 specified by numbers as below:
21631 0---1---2 -- ascent
21635 9--10--11 -- center
21637 ---3---4---5--- baseline
21639 6---7---8 -- descent
21641 int rule
= COMPOSITION_RULE (cmp
, i
);
21642 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21644 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21645 grefx
= gref
% 3, nrefx
= nref
% 3;
21646 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21648 xoff
= font_height
* (xoff
- 128) / 256;
21650 yoff
= font_height
* (yoff
- 128) / 256;
21653 + grefx
* (rightmost
- leftmost
) / 2
21654 - nrefx
* width
/ 2
21657 btm
= ((grefy
== 0 ? highest
21659 : grefy
== 2 ? lowest
21660 : (highest
+ lowest
) / 2)
21661 - (nrefy
== 0 ? ascent
+ descent
21662 : nrefy
== 1 ? descent
- boff
21664 : (ascent
+ descent
) / 2)
21668 cmp
->offsets
[i
* 2] = left
;
21669 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21671 /* Update the bounding box of the overall glyphs. */
21674 right
= left
+ width
;
21675 if (left
< leftmost
)
21677 if (right
> rightmost
)
21680 top
= btm
+ descent
+ ascent
;
21686 if (cmp
->lbearing
> left
+ lbearing
)
21687 cmp
->lbearing
= left
+ lbearing
;
21688 if (cmp
->rbearing
< left
+ rbearing
)
21689 cmp
->rbearing
= left
+ rbearing
;
21693 /* If there are glyphs whose x-offsets are negative,
21694 shift all glyphs to the right and make all x-offsets
21698 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21699 cmp
->offsets
[i
* 2] -= leftmost
;
21700 rightmost
-= leftmost
;
21701 cmp
->lbearing
-= leftmost
;
21702 cmp
->rbearing
-= leftmost
;
21705 if (left_padded
&& cmp
->lbearing
< 0)
21707 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21708 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21709 rightmost
-= cmp
->lbearing
;
21710 cmp
->rbearing
-= cmp
->lbearing
;
21713 if (right_padded
&& rightmost
< cmp
->rbearing
)
21715 rightmost
= cmp
->rbearing
;
21718 cmp
->pixel_width
= rightmost
;
21719 cmp
->ascent
= highest
;
21720 cmp
->descent
= - lowest
;
21721 if (cmp
->ascent
< font_ascent
)
21722 cmp
->ascent
= font_ascent
;
21723 if (cmp
->descent
< font_descent
)
21724 cmp
->descent
= font_descent
;
21728 && (cmp
->lbearing
< 0
21729 || cmp
->rbearing
> cmp
->pixel_width
))
21730 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21732 it
->pixel_width
= cmp
->pixel_width
;
21733 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21734 it
->descent
= it
->phys_descent
= cmp
->descent
;
21735 if (face
->box
!= FACE_NO_BOX
)
21737 int thick
= face
->box_line_width
;
21741 it
->ascent
+= thick
;
21742 it
->descent
+= thick
;
21747 if (it
->start_of_box_run_p
)
21748 it
->pixel_width
+= thick
;
21749 if (it
->end_of_box_run_p
)
21750 it
->pixel_width
+= thick
;
21753 /* If face has an overline, add the height of the overline
21754 (1 pixel) and a 1 pixel margin to the character height. */
21755 if (face
->overline_p
)
21756 it
->ascent
+= overline_margin
;
21758 take_vertical_position_into_account (it
);
21759 if (it
->ascent
< 0)
21761 if (it
->descent
< 0)
21765 append_composite_glyph (it
);
21767 else if (it
->what
== IT_COMPOSITION
)
21769 /* A dynamic (automatic) composition. */
21770 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21771 Lisp_Object gstring
;
21772 struct font_metrics metrics
;
21774 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
21776 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
21779 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
21780 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21781 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
21782 it
->descent
= it
->phys_descent
= metrics
.descent
;
21783 if (face
->box
!= FACE_NO_BOX
)
21785 int thick
= face
->box_line_width
;
21789 it
->ascent
+= thick
;
21790 it
->descent
+= thick
;
21795 if (it
->start_of_box_run_p
)
21796 it
->pixel_width
+= thick
;
21797 if (it
->end_of_box_run_p
)
21798 it
->pixel_width
+= thick
;
21800 /* If face has an overline, add the height of the overline
21801 (1 pixel) and a 1 pixel margin to the character height. */
21802 if (face
->overline_p
)
21803 it
->ascent
+= overline_margin
;
21804 take_vertical_position_into_account (it
);
21805 if (it
->ascent
< 0)
21807 if (it
->descent
< 0)
21811 append_composite_glyph (it
);
21813 else if (it
->what
== IT_IMAGE
)
21814 produce_image_glyph (it
);
21815 else if (it
->what
== IT_STRETCH
)
21816 produce_stretch_glyph (it
);
21818 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21819 because this isn't true for images with `:ascent 100'. */
21820 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21821 if (it
->area
== TEXT_AREA
)
21822 it
->current_x
+= it
->pixel_width
;
21824 if (extra_line_spacing
> 0)
21826 it
->descent
+= extra_line_spacing
;
21827 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21828 it
->max_extra_line_spacing
= extra_line_spacing
;
21831 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21832 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21833 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21834 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21838 Output LEN glyphs starting at START at the nominal cursor position.
21839 Advance the nominal cursor over the text. The global variable
21840 updated_window contains the window being updated, updated_row is
21841 the glyph row being updated, and updated_area is the area of that
21842 row being updated. */
21845 x_write_glyphs (start
, len
)
21846 struct glyph
*start
;
21851 xassert (updated_window
&& updated_row
);
21854 /* Write glyphs. */
21856 hpos
= start
- updated_row
->glyphs
[updated_area
];
21857 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21858 updated_row
, updated_area
,
21860 DRAW_NORMAL_TEXT
, 0);
21862 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21863 if (updated_area
== TEXT_AREA
21864 && updated_window
->phys_cursor_on_p
21865 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21866 && updated_window
->phys_cursor
.hpos
>= hpos
21867 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21868 updated_window
->phys_cursor_on_p
= 0;
21872 /* Advance the output cursor. */
21873 output_cursor
.hpos
+= len
;
21874 output_cursor
.x
= x
;
21879 Insert LEN glyphs from START at the nominal cursor position. */
21882 x_insert_glyphs (start
, len
)
21883 struct glyph
*start
;
21888 int line_height
, shift_by_width
, shifted_region_width
;
21889 struct glyph_row
*row
;
21890 struct glyph
*glyph
;
21891 int frame_x
, frame_y
;
21894 xassert (updated_window
&& updated_row
);
21896 w
= updated_window
;
21897 f
= XFRAME (WINDOW_FRAME (w
));
21899 /* Get the height of the line we are in. */
21901 line_height
= row
->height
;
21903 /* Get the width of the glyphs to insert. */
21904 shift_by_width
= 0;
21905 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21906 shift_by_width
+= glyph
->pixel_width
;
21908 /* Get the width of the region to shift right. */
21909 shifted_region_width
= (window_box_width (w
, updated_area
)
21914 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21915 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21917 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21918 line_height
, shift_by_width
);
21920 /* Write the glyphs. */
21921 hpos
= start
- row
->glyphs
[updated_area
];
21922 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21924 DRAW_NORMAL_TEXT
, 0);
21926 /* Advance the output cursor. */
21927 output_cursor
.hpos
+= len
;
21928 output_cursor
.x
+= shift_by_width
;
21934 Erase the current text line from the nominal cursor position
21935 (inclusive) to pixel column TO_X (exclusive). The idea is that
21936 everything from TO_X onward is already erased.
21938 TO_X is a pixel position relative to updated_area of
21939 updated_window. TO_X == -1 means clear to the end of this area. */
21942 x_clear_end_of_line (to_x
)
21946 struct window
*w
= updated_window
;
21947 int max_x
, min_y
, max_y
;
21948 int from_x
, from_y
, to_y
;
21950 xassert (updated_window
&& updated_row
);
21951 f
= XFRAME (w
->frame
);
21953 if (updated_row
->full_width_p
)
21954 max_x
= WINDOW_TOTAL_WIDTH (w
);
21956 max_x
= window_box_width (w
, updated_area
);
21957 max_y
= window_text_bottom_y (w
);
21959 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21960 of window. For TO_X > 0, truncate to end of drawing area. */
21966 to_x
= min (to_x
, max_x
);
21968 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21970 /* Notice if the cursor will be cleared by this operation. */
21971 if (!updated_row
->full_width_p
)
21972 notice_overwritten_cursor (w
, updated_area
,
21973 output_cursor
.x
, -1,
21975 MATRIX_ROW_BOTTOM_Y (updated_row
));
21977 from_x
= output_cursor
.x
;
21979 /* Translate to frame coordinates. */
21980 if (updated_row
->full_width_p
)
21982 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21983 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21987 int area_left
= window_box_left (w
, updated_area
);
21988 from_x
+= area_left
;
21992 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21993 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21994 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21996 /* Prevent inadvertently clearing to end of the X window. */
21997 if (to_x
> from_x
&& to_y
> from_y
)
22000 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22001 to_x
- from_x
, to_y
- from_y
);
22006 #endif /* HAVE_WINDOW_SYSTEM */
22010 /***********************************************************************
22012 ***********************************************************************/
22014 /* Value is the internal representation of the specified cursor type
22015 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22016 of the bar cursor. */
22018 static enum text_cursor_kinds
22019 get_specified_cursor_type (arg
, width
)
22023 enum text_cursor_kinds type
;
22028 if (EQ (arg
, Qbox
))
22029 return FILLED_BOX_CURSOR
;
22031 if (EQ (arg
, Qhollow
))
22032 return HOLLOW_BOX_CURSOR
;
22034 if (EQ (arg
, Qbar
))
22041 && EQ (XCAR (arg
), Qbar
)
22042 && INTEGERP (XCDR (arg
))
22043 && XINT (XCDR (arg
)) >= 0)
22045 *width
= XINT (XCDR (arg
));
22049 if (EQ (arg
, Qhbar
))
22052 return HBAR_CURSOR
;
22056 && EQ (XCAR (arg
), Qhbar
)
22057 && INTEGERP (XCDR (arg
))
22058 && XINT (XCDR (arg
)) >= 0)
22060 *width
= XINT (XCDR (arg
));
22061 return HBAR_CURSOR
;
22064 /* Treat anything unknown as "hollow box cursor".
22065 It was bad to signal an error; people have trouble fixing
22066 .Xdefaults with Emacs, when it has something bad in it. */
22067 type
= HOLLOW_BOX_CURSOR
;
22072 /* Set the default cursor types for specified frame. */
22074 set_frame_cursor_types (f
, arg
)
22081 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22082 FRAME_CURSOR_WIDTH (f
) = width
;
22084 /* By default, set up the blink-off state depending on the on-state. */
22086 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22089 FRAME_BLINK_OFF_CURSOR (f
)
22090 = get_specified_cursor_type (XCDR (tem
), &width
);
22091 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22094 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22098 /* Return the cursor we want to be displayed in window W. Return
22099 width of bar/hbar cursor through WIDTH arg. Return with
22100 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22101 (i.e. if the `system caret' should track this cursor).
22103 In a mini-buffer window, we want the cursor only to appear if we
22104 are reading input from this window. For the selected window, we
22105 want the cursor type given by the frame parameter or buffer local
22106 setting of cursor-type. If explicitly marked off, draw no cursor.
22107 In all other cases, we want a hollow box cursor. */
22109 static enum text_cursor_kinds
22110 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22112 struct glyph
*glyph
;
22114 int *active_cursor
;
22116 struct frame
*f
= XFRAME (w
->frame
);
22117 struct buffer
*b
= XBUFFER (w
->buffer
);
22118 int cursor_type
= DEFAULT_CURSOR
;
22119 Lisp_Object alt_cursor
;
22120 int non_selected
= 0;
22122 *active_cursor
= 1;
22125 if (cursor_in_echo_area
22126 && FRAME_HAS_MINIBUF_P (f
)
22127 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22129 if (w
== XWINDOW (echo_area_window
))
22131 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22133 *width
= FRAME_CURSOR_WIDTH (f
);
22134 return FRAME_DESIRED_CURSOR (f
);
22137 return get_specified_cursor_type (b
->cursor_type
, width
);
22140 *active_cursor
= 0;
22144 /* Detect a nonselected window or nonselected frame. */
22145 else if (w
!= XWINDOW (f
->selected_window
)
22146 #ifdef HAVE_WINDOW_SYSTEM
22147 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22151 *active_cursor
= 0;
22153 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22159 /* Never display a cursor in a window in which cursor-type is nil. */
22160 if (NILP (b
->cursor_type
))
22163 /* Get the normal cursor type for this window. */
22164 if (EQ (b
->cursor_type
, Qt
))
22166 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22167 *width
= FRAME_CURSOR_WIDTH (f
);
22170 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22172 /* Use cursor-in-non-selected-windows instead
22173 for non-selected window or frame. */
22176 alt_cursor
= b
->cursor_in_non_selected_windows
;
22177 if (!EQ (Qt
, alt_cursor
))
22178 return get_specified_cursor_type (alt_cursor
, width
);
22179 /* t means modify the normal cursor type. */
22180 if (cursor_type
== FILLED_BOX_CURSOR
)
22181 cursor_type
= HOLLOW_BOX_CURSOR
;
22182 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22184 return cursor_type
;
22187 /* Use normal cursor if not blinked off. */
22188 if (!w
->cursor_off_p
)
22190 #ifdef HAVE_WINDOW_SYSTEM
22191 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22193 if (cursor_type
== FILLED_BOX_CURSOR
)
22195 /* Using a block cursor on large images can be very annoying.
22196 So use a hollow cursor for "large" images.
22197 If image is not transparent (no mask), also use hollow cursor. */
22198 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22199 if (img
!= NULL
&& IMAGEP (img
->spec
))
22201 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22202 where N = size of default frame font size.
22203 This should cover most of the "tiny" icons people may use. */
22205 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22206 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22207 cursor_type
= HOLLOW_BOX_CURSOR
;
22210 else if (cursor_type
!= NO_CURSOR
)
22212 /* Display current only supports BOX and HOLLOW cursors for images.
22213 So for now, unconditionally use a HOLLOW cursor when cursor is
22214 not a solid box cursor. */
22215 cursor_type
= HOLLOW_BOX_CURSOR
;
22219 return cursor_type
;
22222 /* Cursor is blinked off, so determine how to "toggle" it. */
22224 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22225 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22226 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22228 /* Then see if frame has specified a specific blink off cursor type. */
22229 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22231 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22232 return FRAME_BLINK_OFF_CURSOR (f
);
22236 /* Some people liked having a permanently visible blinking cursor,
22237 while others had very strong opinions against it. So it was
22238 decided to remove it. KFS 2003-09-03 */
22240 /* Finally perform built-in cursor blinking:
22241 filled box <-> hollow box
22242 wide [h]bar <-> narrow [h]bar
22243 narrow [h]bar <-> no cursor
22244 other type <-> no cursor */
22246 if (cursor_type
== FILLED_BOX_CURSOR
)
22247 return HOLLOW_BOX_CURSOR
;
22249 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22252 return cursor_type
;
22260 #ifdef HAVE_WINDOW_SYSTEM
22262 /* Notice when the text cursor of window W has been completely
22263 overwritten by a drawing operation that outputs glyphs in AREA
22264 starting at X0 and ending at X1 in the line starting at Y0 and
22265 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22266 the rest of the line after X0 has been written. Y coordinates
22267 are window-relative. */
22270 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22272 enum glyph_row_area area
;
22273 int x0
, y0
, x1
, y1
;
22275 int cx0
, cx1
, cy0
, cy1
;
22276 struct glyph_row
*row
;
22278 if (!w
->phys_cursor_on_p
)
22280 if (area
!= TEXT_AREA
)
22283 if (w
->phys_cursor
.vpos
< 0
22284 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22285 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22286 !(row
->enabled_p
&& row
->displays_text_p
)))
22289 if (row
->cursor_in_fringe_p
)
22291 row
->cursor_in_fringe_p
= 0;
22292 draw_fringe_bitmap (w
, row
, 0);
22293 w
->phys_cursor_on_p
= 0;
22297 cx0
= w
->phys_cursor
.x
;
22298 cx1
= cx0
+ w
->phys_cursor_width
;
22299 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22302 /* The cursor image will be completely removed from the
22303 screen if the output area intersects the cursor area in
22304 y-direction. When we draw in [y0 y1[, and some part of
22305 the cursor is at y < y0, that part must have been drawn
22306 before. When scrolling, the cursor is erased before
22307 actually scrolling, so we don't come here. When not
22308 scrolling, the rows above the old cursor row must have
22309 changed, and in this case these rows must have written
22310 over the cursor image.
22312 Likewise if part of the cursor is below y1, with the
22313 exception of the cursor being in the first blank row at
22314 the buffer and window end because update_text_area
22315 doesn't draw that row. (Except when it does, but
22316 that's handled in update_text_area.) */
22318 cy0
= w
->phys_cursor
.y
;
22319 cy1
= cy0
+ w
->phys_cursor_height
;
22320 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22323 w
->phys_cursor_on_p
= 0;
22326 #endif /* HAVE_WINDOW_SYSTEM */
22329 /************************************************************************
22331 ************************************************************************/
22333 #ifdef HAVE_WINDOW_SYSTEM
22336 Fix the display of area AREA of overlapping row ROW in window W
22337 with respect to the overlapping part OVERLAPS. */
22340 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22342 struct glyph_row
*row
;
22343 enum glyph_row_area area
;
22351 for (i
= 0; i
< row
->used
[area
];)
22353 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22355 int start
= i
, start_x
= x
;
22359 x
+= row
->glyphs
[area
][i
].pixel_width
;
22362 while (i
< row
->used
[area
]
22363 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22365 draw_glyphs (w
, start_x
, row
, area
,
22367 DRAW_NORMAL_TEXT
, overlaps
);
22371 x
+= row
->glyphs
[area
][i
].pixel_width
;
22381 Draw the cursor glyph of window W in glyph row ROW. See the
22382 comment of draw_glyphs for the meaning of HL. */
22385 draw_phys_cursor_glyph (w
, row
, hl
)
22387 struct glyph_row
*row
;
22388 enum draw_glyphs_face hl
;
22390 /* If cursor hpos is out of bounds, don't draw garbage. This can
22391 happen in mini-buffer windows when switching between echo area
22392 glyphs and mini-buffer. */
22393 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22395 int on_p
= w
->phys_cursor_on_p
;
22397 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22398 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22400 w
->phys_cursor_on_p
= on_p
;
22402 if (hl
== DRAW_CURSOR
)
22403 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22404 /* When we erase the cursor, and ROW is overlapped by other
22405 rows, make sure that these overlapping parts of other rows
22407 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22409 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22411 if (row
> w
->current_matrix
->rows
22412 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22413 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22414 OVERLAPS_ERASED_CURSOR
);
22416 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22417 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22418 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22419 OVERLAPS_ERASED_CURSOR
);
22426 Erase the image of a cursor of window W from the screen. */
22429 erase_phys_cursor (w
)
22432 struct frame
*f
= XFRAME (w
->frame
);
22433 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22434 int hpos
= w
->phys_cursor
.hpos
;
22435 int vpos
= w
->phys_cursor
.vpos
;
22436 int mouse_face_here_p
= 0;
22437 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22438 struct glyph_row
*cursor_row
;
22439 struct glyph
*cursor_glyph
;
22440 enum draw_glyphs_face hl
;
22442 /* No cursor displayed or row invalidated => nothing to do on the
22444 if (w
->phys_cursor_type
== NO_CURSOR
)
22445 goto mark_cursor_off
;
22447 /* VPOS >= active_glyphs->nrows means that window has been resized.
22448 Don't bother to erase the cursor. */
22449 if (vpos
>= active_glyphs
->nrows
)
22450 goto mark_cursor_off
;
22452 /* If row containing cursor is marked invalid, there is nothing we
22454 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22455 if (!cursor_row
->enabled_p
)
22456 goto mark_cursor_off
;
22458 /* If line spacing is > 0, old cursor may only be partially visible in
22459 window after split-window. So adjust visible height. */
22460 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22461 window_text_bottom_y (w
) - cursor_row
->y
);
22463 /* If row is completely invisible, don't attempt to delete a cursor which
22464 isn't there. This can happen if cursor is at top of a window, and
22465 we switch to a buffer with a header line in that window. */
22466 if (cursor_row
->visible_height
<= 0)
22467 goto mark_cursor_off
;
22469 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22470 if (cursor_row
->cursor_in_fringe_p
)
22472 cursor_row
->cursor_in_fringe_p
= 0;
22473 draw_fringe_bitmap (w
, cursor_row
, 0);
22474 goto mark_cursor_off
;
22477 /* This can happen when the new row is shorter than the old one.
22478 In this case, either draw_glyphs or clear_end_of_line
22479 should have cleared the cursor. Note that we wouldn't be
22480 able to erase the cursor in this case because we don't have a
22481 cursor glyph at hand. */
22482 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22483 goto mark_cursor_off
;
22485 /* If the cursor is in the mouse face area, redisplay that when
22486 we clear the cursor. */
22487 if (! NILP (dpyinfo
->mouse_face_window
)
22488 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22489 && (vpos
> dpyinfo
->mouse_face_beg_row
22490 || (vpos
== dpyinfo
->mouse_face_beg_row
22491 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22492 && (vpos
< dpyinfo
->mouse_face_end_row
22493 || (vpos
== dpyinfo
->mouse_face_end_row
22494 && hpos
< dpyinfo
->mouse_face_end_col
))
22495 /* Don't redraw the cursor's spot in mouse face if it is at the
22496 end of a line (on a newline). The cursor appears there, but
22497 mouse highlighting does not. */
22498 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22499 mouse_face_here_p
= 1;
22501 /* Maybe clear the display under the cursor. */
22502 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22505 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22508 cursor_glyph
= get_phys_cursor_glyph (w
);
22509 if (cursor_glyph
== NULL
)
22510 goto mark_cursor_off
;
22512 width
= cursor_glyph
->pixel_width
;
22513 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22514 x
= w
->phys_cursor
.x
;
22516 width
-= left_x
- x
;
22517 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22518 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22519 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22522 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22525 /* Erase the cursor by redrawing the character underneath it. */
22526 if (mouse_face_here_p
)
22527 hl
= DRAW_MOUSE_FACE
;
22529 hl
= DRAW_NORMAL_TEXT
;
22530 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22533 w
->phys_cursor_on_p
= 0;
22534 w
->phys_cursor_type
= NO_CURSOR
;
22539 Display or clear cursor of window W. If ON is zero, clear the
22540 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22541 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22544 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22546 int on
, hpos
, vpos
, x
, y
;
22548 struct frame
*f
= XFRAME (w
->frame
);
22549 int new_cursor_type
;
22550 int new_cursor_width
;
22552 struct glyph_row
*glyph_row
;
22553 struct glyph
*glyph
;
22555 /* This is pointless on invisible frames, and dangerous on garbaged
22556 windows and frames; in the latter case, the frame or window may
22557 be in the midst of changing its size, and x and y may be off the
22559 if (! FRAME_VISIBLE_P (f
)
22560 || FRAME_GARBAGED_P (f
)
22561 || vpos
>= w
->current_matrix
->nrows
22562 || hpos
>= w
->current_matrix
->matrix_w
)
22565 /* If cursor is off and we want it off, return quickly. */
22566 if (!on
&& !w
->phys_cursor_on_p
)
22569 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22570 /* If cursor row is not enabled, we don't really know where to
22571 display the cursor. */
22572 if (!glyph_row
->enabled_p
)
22574 w
->phys_cursor_on_p
= 0;
22579 if (!glyph_row
->exact_window_width_line_p
22580 || hpos
< glyph_row
->used
[TEXT_AREA
])
22581 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22583 xassert (interrupt_input_blocked
);
22585 /* Set new_cursor_type to the cursor we want to be displayed. */
22586 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22587 &new_cursor_width
, &active_cursor
);
22589 /* If cursor is currently being shown and we don't want it to be or
22590 it is in the wrong place, or the cursor type is not what we want,
22592 if (w
->phys_cursor_on_p
22594 || w
->phys_cursor
.x
!= x
22595 || w
->phys_cursor
.y
!= y
22596 || new_cursor_type
!= w
->phys_cursor_type
22597 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22598 && new_cursor_width
!= w
->phys_cursor_width
)))
22599 erase_phys_cursor (w
);
22601 /* Don't check phys_cursor_on_p here because that flag is only set
22602 to zero in some cases where we know that the cursor has been
22603 completely erased, to avoid the extra work of erasing the cursor
22604 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22605 still not be visible, or it has only been partly erased. */
22608 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22609 w
->phys_cursor_height
= glyph_row
->height
;
22611 /* Set phys_cursor_.* before x_draw_.* is called because some
22612 of them may need the information. */
22613 w
->phys_cursor
.x
= x
;
22614 w
->phys_cursor
.y
= glyph_row
->y
;
22615 w
->phys_cursor
.hpos
= hpos
;
22616 w
->phys_cursor
.vpos
= vpos
;
22619 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22620 new_cursor_type
, new_cursor_width
,
22621 on
, active_cursor
);
22625 /* Switch the display of W's cursor on or off, according to the value
22632 update_window_cursor (w
, on
)
22636 /* Don't update cursor in windows whose frame is in the process
22637 of being deleted. */
22638 if (w
->current_matrix
)
22641 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22642 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22648 /* Call update_window_cursor with parameter ON_P on all leaf windows
22649 in the window tree rooted at W. */
22652 update_cursor_in_window_tree (w
, on_p
)
22658 if (!NILP (w
->hchild
))
22659 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22660 else if (!NILP (w
->vchild
))
22661 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22663 update_window_cursor (w
, on_p
);
22665 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22671 Display the cursor on window W, or clear it, according to ON_P.
22672 Don't change the cursor's position. */
22675 x_update_cursor (f
, on_p
)
22679 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22684 Clear the cursor of window W to background color, and mark the
22685 cursor as not shown. This is used when the text where the cursor
22686 is is about to be rewritten. */
22692 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22693 update_window_cursor (w
, 0);
22698 Display the active region described by mouse_face_* according to DRAW. */
22701 show_mouse_face (dpyinfo
, draw
)
22702 Display_Info
*dpyinfo
;
22703 enum draw_glyphs_face draw
;
22705 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22706 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22708 if (/* If window is in the process of being destroyed, don't bother
22710 w
->current_matrix
!= NULL
22711 /* Don't update mouse highlight if hidden */
22712 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22713 /* Recognize when we are called to operate on rows that don't exist
22714 anymore. This can happen when a window is split. */
22715 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22717 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22718 struct glyph_row
*row
, *first
, *last
;
22720 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22721 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22723 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22725 int start_hpos
, end_hpos
, start_x
;
22727 /* For all but the first row, the highlight starts at column 0. */
22730 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22731 start_x
= dpyinfo
->mouse_face_beg_x
;
22740 end_hpos
= dpyinfo
->mouse_face_end_col
;
22743 end_hpos
= row
->used
[TEXT_AREA
];
22744 if (draw
== DRAW_NORMAL_TEXT
)
22745 row
->fill_line_p
= 1; /* Clear to end of line */
22748 if (end_hpos
> start_hpos
)
22750 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22751 start_hpos
, end_hpos
,
22755 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22759 /* When we've written over the cursor, arrange for it to
22760 be displayed again. */
22761 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22764 display_and_set_cursor (w
, 1,
22765 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22766 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22771 /* Change the mouse cursor. */
22772 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22773 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22774 else if (draw
== DRAW_MOUSE_FACE
)
22775 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22777 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22781 Clear out the mouse-highlighted active region.
22782 Redraw it un-highlighted first. Value is non-zero if mouse
22783 face was actually drawn unhighlighted. */
22786 clear_mouse_face (dpyinfo
)
22787 Display_Info
*dpyinfo
;
22791 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22793 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22797 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22798 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22799 dpyinfo
->mouse_face_window
= Qnil
;
22800 dpyinfo
->mouse_face_overlay
= Qnil
;
22806 Non-zero if physical cursor of window W is within mouse face. */
22809 cursor_in_mouse_face_p (w
)
22812 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22813 int in_mouse_face
= 0;
22815 if (WINDOWP (dpyinfo
->mouse_face_window
)
22816 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22818 int hpos
= w
->phys_cursor
.hpos
;
22819 int vpos
= w
->phys_cursor
.vpos
;
22821 if (vpos
>= dpyinfo
->mouse_face_beg_row
22822 && vpos
<= dpyinfo
->mouse_face_end_row
22823 && (vpos
> dpyinfo
->mouse_face_beg_row
22824 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22825 && (vpos
< dpyinfo
->mouse_face_end_row
22826 || hpos
< dpyinfo
->mouse_face_end_col
22827 || dpyinfo
->mouse_face_past_end
))
22831 return in_mouse_face
;
22837 /* This function sets the mouse_face_* elements of DPYINFO, assuming
22838 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
22839 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
22840 for the overlay or run of text properties specifying the mouse
22841 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
22842 before-string and after-string that must also be highlighted.
22843 DISPLAY_STRING, if non-nil, is a display string that may cover some
22844 or all of the highlighted text. */
22847 mouse_face_from_buffer_pos (Lisp_Object window
,
22848 Display_Info
*dpyinfo
,
22849 EMACS_INT mouse_charpos
,
22850 EMACS_INT start_charpos
,
22851 EMACS_INT end_charpos
,
22852 Lisp_Object before_string
,
22853 Lisp_Object after_string
,
22854 Lisp_Object display_string
)
22856 struct window
*w
= XWINDOW (window
);
22857 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22858 struct glyph_row
*row
;
22859 struct glyph
*glyph
, *end
;
22863 xassert (NILP (display_string
) || STRINGP (display_string
));
22864 xassert (NILP (before_string
) || STRINGP (before_string
));
22865 xassert (NILP (after_string
) || STRINGP (after_string
));
22867 /* Find the first highlighted glyph. */
22868 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
22870 dpyinfo
->mouse_face_beg_col
= 0;
22871 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22872 dpyinfo
->mouse_face_beg_x
= first
->x
;
22873 dpyinfo
->mouse_face_beg_y
= first
->y
;
22877 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
22879 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22881 /* If the before-string or display-string contains newlines,
22882 row_containing_pos skips to its last row. Move back. */
22883 if (!NILP (before_string
) || !NILP (display_string
))
22885 struct glyph_row
*prev
;
22886 while ((prev
= row
- 1, prev
>= first
)
22887 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
22888 && prev
->used
[TEXT_AREA
] > 0)
22890 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22891 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22892 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
22894 || !(EQ (glyph
->object
, before_string
)
22895 || EQ (glyph
->object
, display_string
)))
22901 glyph
= row
->glyphs
[TEXT_AREA
];
22902 end
= glyph
+ row
->used
[TEXT_AREA
];
22904 dpyinfo
->mouse_face_beg_y
= row
->y
;
22905 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22907 /* Skip truncation glyphs at the start of the glyph row. */
22908 if (row
->displays_text_p
)
22910 && INTEGERP (glyph
->object
)
22911 && glyph
->charpos
< 0;
22913 x
+= glyph
->pixel_width
;
22915 /* Scan the glyph row, stopping before BEFORE_STRING or
22916 DISPLAY_STRING or START_CHARPOS. */
22918 && !INTEGERP (glyph
->object
)
22919 && !EQ (glyph
->object
, before_string
)
22920 && !EQ (glyph
->object
, display_string
)
22921 && !(BUFFERP (glyph
->object
)
22922 && glyph
->charpos
>= start_charpos
);
22924 x
+= glyph
->pixel_width
;
22926 dpyinfo
->mouse_face_beg_x
= x
;
22927 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22930 /* Find the last highlighted glyph. */
22931 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
22934 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22935 dpyinfo
->mouse_face_past_end
= 1;
22937 else if (!NILP (after_string
))
22939 /* If the after-string has newlines, advance to its last row. */
22940 struct glyph_row
*next
;
22941 struct glyph_row
*last
22942 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22944 for (next
= row
+ 1;
22946 && next
->used
[TEXT_AREA
] > 0
22947 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
22952 glyph
= row
->glyphs
[TEXT_AREA
];
22953 end
= glyph
+ row
->used
[TEXT_AREA
];
22955 dpyinfo
->mouse_face_end_y
= row
->y
;
22956 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22958 /* Skip truncation glyphs at the start of the row. */
22959 if (row
->displays_text_p
)
22961 && INTEGERP (glyph
->object
)
22962 && glyph
->charpos
< 0;
22964 x
+= glyph
->pixel_width
;
22966 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
22969 && !INTEGERP (glyph
->object
)
22970 && !EQ (glyph
->object
, after_string
)
22971 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
22973 x
+= glyph
->pixel_width
;
22975 /* If we found AFTER_STRING, consume it and stop. */
22976 if (EQ (glyph
->object
, after_string
))
22978 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
22979 x
+= glyph
->pixel_width
;
22983 /* If there's no after-string, we must check if we overshot,
22984 which might be the case if we stopped after a string glyph.
22985 That glyph may belong to a before-string or display-string
22986 associated with the end position, which must not be
22988 Lisp_Object prev_object
;
22991 while (glyph
> row
->glyphs
[TEXT_AREA
])
22993 prev_object
= (glyph
- 1)->object
;
22994 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
22997 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
22998 if (pos
&& pos
< end_charpos
)
23001 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23002 && EQ ((glyph
- 1)->object
, prev_object
);
23004 x
-= (glyph
- 1)->pixel_width
;
23008 dpyinfo
->mouse_face_end_x
= x
;
23009 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23010 dpyinfo
->mouse_face_window
= window
;
23011 dpyinfo
->mouse_face_face_id
23012 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23014 !dpyinfo
->mouse_face_hidden
, -1);
23015 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23019 /* Find the position of the glyph for position POS in OBJECT in
23020 window W's current matrix, and return in *X, *Y the pixel
23021 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23023 RIGHT_P non-zero means return the position of the right edge of the
23024 glyph, RIGHT_P zero means return the left edge position.
23026 If no glyph for POS exists in the matrix, return the position of
23027 the glyph with the next smaller position that is in the matrix, if
23028 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23029 exists in the matrix, return the position of the glyph with the
23030 next larger position in OBJECT.
23032 Value is non-zero if a glyph was found. */
23035 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23038 Lisp_Object object
;
23039 int *hpos
, *vpos
, *x
, *y
;
23042 int yb
= window_text_bottom_y (w
);
23043 struct glyph_row
*r
;
23044 struct glyph
*best_glyph
= NULL
;
23045 struct glyph_row
*best_row
= NULL
;
23048 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23049 r
->enabled_p
&& r
->y
< yb
;
23052 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23053 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23056 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23057 if (EQ (g
->object
, object
))
23059 if (g
->charpos
== pos
)
23066 else if (best_glyph
== NULL
23067 || ((eabs (g
->charpos
- pos
)
23068 < eabs (best_glyph
->charpos
- pos
))
23071 : g
->charpos
> pos
)))
23085 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23089 *x
+= best_glyph
->pixel_width
;
23094 *vpos
= best_row
- w
->current_matrix
->rows
;
23097 return best_glyph
!= NULL
;
23101 /* See if position X, Y is within a hot-spot of an image. */
23104 on_hot_spot_p (hot_spot
, x
, y
)
23105 Lisp_Object hot_spot
;
23108 if (!CONSP (hot_spot
))
23111 if (EQ (XCAR (hot_spot
), Qrect
))
23113 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23114 Lisp_Object rect
= XCDR (hot_spot
);
23118 if (!CONSP (XCAR (rect
)))
23120 if (!CONSP (XCDR (rect
)))
23122 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23124 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23126 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23128 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23132 else if (EQ (XCAR (hot_spot
), Qcircle
))
23134 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23135 Lisp_Object circ
= XCDR (hot_spot
);
23136 Lisp_Object lr
, lx0
, ly0
;
23138 && CONSP (XCAR (circ
))
23139 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23140 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23141 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23143 double r
= XFLOATINT (lr
);
23144 double dx
= XINT (lx0
) - x
;
23145 double dy
= XINT (ly0
) - y
;
23146 return (dx
* dx
+ dy
* dy
<= r
* r
);
23149 else if (EQ (XCAR (hot_spot
), Qpoly
))
23151 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23152 if (VECTORP (XCDR (hot_spot
)))
23154 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23155 Lisp_Object
*poly
= v
->contents
;
23159 Lisp_Object lx
, ly
;
23162 /* Need an even number of coordinates, and at least 3 edges. */
23163 if (n
< 6 || n
& 1)
23166 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23167 If count is odd, we are inside polygon. Pixels on edges
23168 may or may not be included depending on actual geometry of the
23170 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23171 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23173 x0
= XINT (lx
), y0
= XINT (ly
);
23174 for (i
= 0; i
< n
; i
+= 2)
23176 int x1
= x0
, y1
= y0
;
23177 if ((lx
= poly
[i
], !INTEGERP (lx
))
23178 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23180 x0
= XINT (lx
), y0
= XINT (ly
);
23182 /* Does this segment cross the X line? */
23190 if (y
> y0
&& y
> y1
)
23192 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23202 find_hot_spot (map
, x
, y
)
23206 while (CONSP (map
))
23208 if (CONSP (XCAR (map
))
23209 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23217 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23219 doc
: /* Lookup in image map MAP coordinates X and Y.
23220 An image map is an alist where each element has the format (AREA ID PLIST).
23221 An AREA is specified as either a rectangle, a circle, or a polygon:
23222 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23223 pixel coordinates of the upper left and bottom right corners.
23224 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23225 and the radius of the circle; r may be a float or integer.
23226 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23227 vector describes one corner in the polygon.
23228 Returns the alist element for the first matching AREA in MAP. */)
23239 return find_hot_spot (map
, XINT (x
), XINT (y
));
23243 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23245 define_frame_cursor1 (f
, cursor
, pointer
)
23248 Lisp_Object pointer
;
23250 /* Do not change cursor shape while dragging mouse. */
23251 if (!NILP (do_mouse_tracking
))
23254 if (!NILP (pointer
))
23256 if (EQ (pointer
, Qarrow
))
23257 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23258 else if (EQ (pointer
, Qhand
))
23259 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23260 else if (EQ (pointer
, Qtext
))
23261 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23262 else if (EQ (pointer
, intern ("hdrag")))
23263 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23264 #ifdef HAVE_X_WINDOWS
23265 else if (EQ (pointer
, intern ("vdrag")))
23266 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23268 else if (EQ (pointer
, intern ("hourglass")))
23269 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23270 else if (EQ (pointer
, Qmodeline
))
23271 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23273 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23276 if (cursor
!= No_Cursor
)
23277 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23280 /* Take proper action when mouse has moved to the mode or header line
23281 or marginal area AREA of window W, x-position X and y-position Y.
23282 X is relative to the start of the text display area of W, so the
23283 width of bitmap areas and scroll bars must be subtracted to get a
23284 position relative to the start of the mode line. */
23287 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23288 Lisp_Object window
;
23290 enum window_part area
;
23292 struct window
*w
= XWINDOW (window
);
23293 struct frame
*f
= XFRAME (w
->frame
);
23294 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23295 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23296 Lisp_Object pointer
= Qnil
;
23297 int charpos
, dx
, dy
, width
, height
;
23298 Lisp_Object string
, object
= Qnil
;
23299 Lisp_Object pos
, help
;
23301 Lisp_Object mouse_face
;
23302 int original_x_pixel
= x
;
23303 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23304 struct glyph_row
*row
;
23306 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23311 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23312 &object
, &dx
, &dy
, &width
, &height
);
23314 row
= (area
== ON_MODE_LINE
23315 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23316 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23319 if (row
->mode_line_p
&& row
->enabled_p
)
23321 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23322 end
= glyph
+ row
->used
[TEXT_AREA
];
23324 for (x0
= original_x_pixel
;
23325 glyph
< end
&& x0
>= glyph
->pixel_width
;
23327 x0
-= glyph
->pixel_width
;
23335 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23336 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23337 &object
, &dx
, &dy
, &width
, &height
);
23342 if (IMAGEP (object
))
23344 Lisp_Object image_map
, hotspot
;
23345 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23347 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23349 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23351 Lisp_Object area_id
, plist
;
23353 area_id
= XCAR (hotspot
);
23354 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23355 If so, we could look for mouse-enter, mouse-leave
23356 properties in PLIST (and do something...). */
23357 hotspot
= XCDR (hotspot
);
23358 if (CONSP (hotspot
)
23359 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23361 pointer
= Fplist_get (plist
, Qpointer
);
23362 if (NILP (pointer
))
23364 help
= Fplist_get (plist
, Qhelp_echo
);
23367 help_echo_string
= help
;
23368 /* Is this correct? ++kfs */
23369 XSETWINDOW (help_echo_window
, w
);
23370 help_echo_object
= w
->buffer
;
23371 help_echo_pos
= charpos
;
23375 if (NILP (pointer
))
23376 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23379 if (STRINGP (string
))
23381 pos
= make_number (charpos
);
23382 /* If we're on a string with `help-echo' text property, arrange
23383 for the help to be displayed. This is done by setting the
23384 global variable help_echo_string to the help string. */
23387 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23390 help_echo_string
= help
;
23391 XSETWINDOW (help_echo_window
, w
);
23392 help_echo_object
= string
;
23393 help_echo_pos
= charpos
;
23397 if (NILP (pointer
))
23398 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23400 /* Change the mouse pointer according to what is under X/Y. */
23401 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23404 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23405 if (!KEYMAPP (map
))
23406 map
= Fget_text_property (pos
, Qkeymap
, string
);
23407 if (!KEYMAPP (map
))
23408 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23411 /* Change the mouse face according to what is under X/Y. */
23412 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23413 if (!NILP (mouse_face
)
23414 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23419 struct glyph
* tmp_glyph
;
23423 int total_pixel_width
;
23428 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23429 Qmouse_face
, string
, Qnil
);
23431 b
= make_number (0);
23433 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23435 e
= make_number (SCHARS (string
));
23437 /* Calculate the position(glyph position: GPOS) of GLYPH in
23438 displayed string. GPOS is different from CHARPOS.
23440 CHARPOS is the position of glyph in internal string
23441 object. A mode line string format has structures which
23442 is converted to a flatten by emacs lisp interpreter.
23443 The internal string is an element of the structures.
23444 The displayed string is the flatten string. */
23446 if (glyph
> row_start_glyph
)
23448 tmp_glyph
= glyph
- 1;
23449 while (tmp_glyph
>= row_start_glyph
23450 && tmp_glyph
->charpos
>= XINT (b
)
23451 && EQ (tmp_glyph
->object
, glyph
->object
))
23458 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23459 displayed string holding GLYPH.
23461 GSEQ_LENGTH is different from SCHARS (STRING).
23462 SCHARS (STRING) returns the length of the internal string. */
23463 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23464 tmp_glyph
->charpos
< XINT (e
);
23465 tmp_glyph
++, gseq_length
++)
23467 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23471 total_pixel_width
= 0;
23472 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23473 total_pixel_width
+= tmp_glyph
->pixel_width
;
23475 /* Pre calculation of re-rendering position */
23477 hpos
= (area
== ON_MODE_LINE
23478 ? (w
->current_matrix
)->nrows
- 1
23481 /* If the re-rendering position is included in the last
23482 re-rendering area, we should do nothing. */
23483 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23484 && dpyinfo
->mouse_face_beg_col
<= vpos
23485 && vpos
< dpyinfo
->mouse_face_end_col
23486 && dpyinfo
->mouse_face_beg_row
== hpos
)
23489 if (clear_mouse_face (dpyinfo
))
23490 cursor
= No_Cursor
;
23492 dpyinfo
->mouse_face_beg_col
= vpos
;
23493 dpyinfo
->mouse_face_beg_row
= hpos
;
23495 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23496 dpyinfo
->mouse_face_beg_y
= 0;
23498 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23499 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23501 dpyinfo
->mouse_face_end_x
= 0;
23502 dpyinfo
->mouse_face_end_y
= 0;
23504 dpyinfo
->mouse_face_past_end
= 0;
23505 dpyinfo
->mouse_face_window
= window
;
23507 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23510 glyph
->face_id
, 1);
23511 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23513 if (NILP (pointer
))
23516 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23517 clear_mouse_face (dpyinfo
);
23519 define_frame_cursor1 (f
, cursor
, pointer
);
23524 Take proper action when the mouse has moved to position X, Y on
23525 frame F as regards highlighting characters that have mouse-face
23526 properties. Also de-highlighting chars where the mouse was before.
23527 X and Y can be negative or out of range. */
23530 note_mouse_highlight (f
, x
, y
)
23534 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23535 enum window_part part
;
23536 Lisp_Object window
;
23538 Cursor cursor
= No_Cursor
;
23539 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23542 /* When a menu is active, don't highlight because this looks odd. */
23543 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23544 if (popup_activated ())
23548 if (NILP (Vmouse_highlight
)
23549 || !f
->glyphs_initialized_p
)
23552 dpyinfo
->mouse_face_mouse_x
= x
;
23553 dpyinfo
->mouse_face_mouse_y
= y
;
23554 dpyinfo
->mouse_face_mouse_frame
= f
;
23556 if (dpyinfo
->mouse_face_defer
)
23559 if (gc_in_progress
)
23561 dpyinfo
->mouse_face_deferred_gc
= 1;
23565 /* Which window is that in? */
23566 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23568 /* If we were displaying active text in another window, clear that.
23569 Also clear if we move out of text area in same window. */
23570 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23571 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23572 && !NILP (dpyinfo
->mouse_face_window
)))
23573 clear_mouse_face (dpyinfo
);
23575 /* Not on a window -> return. */
23576 if (!WINDOWP (window
))
23579 /* Reset help_echo_string. It will get recomputed below. */
23580 help_echo_string
= Qnil
;
23582 /* Convert to window-relative pixel coordinates. */
23583 w
= XWINDOW (window
);
23584 frame_to_window_pixel_xy (w
, &x
, &y
);
23586 /* Handle tool-bar window differently since it doesn't display a
23588 if (EQ (window
, f
->tool_bar_window
))
23590 note_tool_bar_highlight (f
, x
, y
);
23594 /* Mouse is on the mode, header line or margin? */
23595 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23596 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23598 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23602 if (part
== ON_VERTICAL_BORDER
)
23604 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23605 help_echo_string
= build_string ("drag-mouse-1: resize");
23607 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23608 || part
== ON_SCROLL_BAR
)
23609 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23611 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23613 /* Are we in a window whose display is up to date?
23614 And verify the buffer's text has not changed. */
23615 b
= XBUFFER (w
->buffer
);
23616 if (part
== ON_TEXT
23617 && EQ (w
->window_end_valid
, w
->buffer
)
23618 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23619 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23621 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23622 struct glyph
*glyph
;
23623 Lisp_Object object
;
23624 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23625 Lisp_Object
*overlay_vec
= NULL
;
23627 struct buffer
*obuf
;
23628 int obegv
, ozv
, same_region
;
23630 /* Find the glyph under X/Y. */
23631 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23633 /* Look for :pointer property on image. */
23634 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23636 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23637 if (img
!= NULL
&& IMAGEP (img
->spec
))
23639 Lisp_Object image_map
, hotspot
;
23640 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23642 && (hotspot
= find_hot_spot (image_map
,
23643 glyph
->slice
.x
+ dx
,
23644 glyph
->slice
.y
+ dy
),
23646 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23648 Lisp_Object area_id
, plist
;
23650 area_id
= XCAR (hotspot
);
23651 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23652 If so, we could look for mouse-enter, mouse-leave
23653 properties in PLIST (and do something...). */
23654 hotspot
= XCDR (hotspot
);
23655 if (CONSP (hotspot
)
23656 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23658 pointer
= Fplist_get (plist
, Qpointer
);
23659 if (NILP (pointer
))
23661 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23662 if (!NILP (help_echo_string
))
23664 help_echo_window
= window
;
23665 help_echo_object
= glyph
->object
;
23666 help_echo_pos
= glyph
->charpos
;
23670 if (NILP (pointer
))
23671 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23675 /* Clear mouse face if X/Y not over text. */
23677 || area
!= TEXT_AREA
23678 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23680 if (clear_mouse_face (dpyinfo
))
23681 cursor
= No_Cursor
;
23682 if (NILP (pointer
))
23684 if (area
!= TEXT_AREA
)
23685 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23687 pointer
= Vvoid_text_area_pointer
;
23692 pos
= glyph
->charpos
;
23693 object
= glyph
->object
;
23694 if (!STRINGP (object
) && !BUFFERP (object
))
23697 /* If we get an out-of-range value, return now; avoid an error. */
23698 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23701 /* Make the window's buffer temporarily current for
23702 overlays_at and compute_char_face. */
23703 obuf
= current_buffer
;
23704 current_buffer
= b
;
23710 /* Is this char mouse-active or does it have help-echo? */
23711 position
= make_number (pos
);
23713 if (BUFFERP (object
))
23715 /* Put all the overlays we want in a vector in overlay_vec. */
23716 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23717 /* Sort overlays into increasing priority order. */
23718 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23723 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23724 && vpos
>= dpyinfo
->mouse_face_beg_row
23725 && vpos
<= dpyinfo
->mouse_face_end_row
23726 && (vpos
> dpyinfo
->mouse_face_beg_row
23727 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23728 && (vpos
< dpyinfo
->mouse_face_end_row
23729 || hpos
< dpyinfo
->mouse_face_end_col
23730 || dpyinfo
->mouse_face_past_end
));
23733 cursor
= No_Cursor
;
23735 /* Check mouse-face highlighting. */
23737 /* If there exists an overlay with mouse-face overlapping
23738 the one we are currently highlighting, we have to
23739 check if we enter the overlapping overlay, and then
23740 highlight only that. */
23741 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23742 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23744 /* Find the highest priority overlay with a mouse-face. */
23746 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23748 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23749 if (!NILP (mouse_face
))
23750 overlay
= overlay_vec
[i
];
23753 /* If we're highlighting the same overlay as before, there's
23754 no need to do that again. */
23755 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23756 goto check_help_echo
;
23757 dpyinfo
->mouse_face_overlay
= overlay
;
23759 /* Clear the display of the old active region, if any. */
23760 if (clear_mouse_face (dpyinfo
))
23761 cursor
= No_Cursor
;
23763 /* If no overlay applies, get a text property. */
23764 if (NILP (overlay
))
23765 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23767 /* Next, compute the bounds of the mouse highlighting and
23769 if (!NILP (mouse_face
) && STRINGP (object
))
23771 /* The mouse-highlighting comes from a display string
23772 with a mouse-face. */
23776 b
= Fprevious_single_property_change
23777 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
23778 e
= Fnext_single_property_change
23779 (position
, Qmouse_face
, object
, Qnil
);
23781 b
= make_number (0);
23783 e
= make_number (SCHARS (object
) - 1);
23785 fast_find_string_pos (w
, XINT (b
), object
,
23786 &dpyinfo
->mouse_face_beg_col
,
23787 &dpyinfo
->mouse_face_beg_row
,
23788 &dpyinfo
->mouse_face_beg_x
,
23789 &dpyinfo
->mouse_face_beg_y
, 0);
23790 fast_find_string_pos (w
, XINT (e
), object
,
23791 &dpyinfo
->mouse_face_end_col
,
23792 &dpyinfo
->mouse_face_end_row
,
23793 &dpyinfo
->mouse_face_end_x
,
23794 &dpyinfo
->mouse_face_end_y
, 1);
23795 dpyinfo
->mouse_face_past_end
= 0;
23796 dpyinfo
->mouse_face_window
= window
;
23797 dpyinfo
->mouse_face_face_id
23798 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23799 glyph
->face_id
, 1);
23800 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23801 cursor
= No_Cursor
;
23805 /* The mouse-highlighting, if any, comes from an overlay
23806 or text property in the buffer. */
23807 Lisp_Object buffer
, display_string
;
23809 if (STRINGP (object
))
23811 /* If we are on a display string with no mouse-face,
23812 check if the text under it has one. */
23813 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23814 int start
= MATRIX_ROW_START_CHARPOS (r
);
23815 pos
= string_buffer_position (w
, object
, start
);
23818 mouse_face
= get_char_property_and_overlay
23819 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
23820 buffer
= w
->buffer
;
23821 display_string
= object
;
23827 display_string
= Qnil
;
23830 if (!NILP (mouse_face
))
23832 Lisp_Object before
, after
;
23833 Lisp_Object before_string
, after_string
;
23835 if (NILP (overlay
))
23837 /* Handle the text property case. */
23838 before
= Fprevious_single_property_change
23839 (make_number (pos
+ 1), Qmouse_face
, buffer
,
23840 Fmarker_position (w
->start
));
23841 after
= Fnext_single_property_change
23842 (make_number (pos
), Qmouse_face
, buffer
,
23843 make_number (BUF_Z (XBUFFER (buffer
))
23844 - XFASTINT (w
->window_end_pos
)));
23845 before_string
= after_string
= Qnil
;
23849 /* Handle the overlay case. */
23850 before
= Foverlay_start (overlay
);
23851 after
= Foverlay_end (overlay
);
23852 before_string
= Foverlay_get (overlay
, Qbefore_string
);
23853 after_string
= Foverlay_get (overlay
, Qafter_string
);
23855 if (!STRINGP (before_string
)) before_string
= Qnil
;
23856 if (!STRINGP (after_string
)) after_string
= Qnil
;
23859 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
23862 before_string
, after_string
,
23864 cursor
= No_Cursor
;
23871 /* Look for a `help-echo' property. */
23872 if (NILP (help_echo_string
)) {
23873 Lisp_Object help
, overlay
;
23875 /* Check overlays first. */
23876 help
= overlay
= Qnil
;
23877 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23879 overlay
= overlay_vec
[i
];
23880 help
= Foverlay_get (overlay
, Qhelp_echo
);
23885 help_echo_string
= help
;
23886 help_echo_window
= window
;
23887 help_echo_object
= overlay
;
23888 help_echo_pos
= pos
;
23892 Lisp_Object object
= glyph
->object
;
23893 int charpos
= glyph
->charpos
;
23895 /* Try text properties. */
23896 if (STRINGP (object
)
23898 && charpos
< SCHARS (object
))
23900 help
= Fget_text_property (make_number (charpos
),
23901 Qhelp_echo
, object
);
23904 /* If the string itself doesn't specify a help-echo,
23905 see if the buffer text ``under'' it does. */
23906 struct glyph_row
*r
23907 = MATRIX_ROW (w
->current_matrix
, vpos
);
23908 int start
= MATRIX_ROW_START_CHARPOS (r
);
23909 int pos
= string_buffer_position (w
, object
, start
);
23912 help
= Fget_char_property (make_number (pos
),
23913 Qhelp_echo
, w
->buffer
);
23917 object
= w
->buffer
;
23922 else if (BUFFERP (object
)
23925 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23930 help_echo_string
= help
;
23931 help_echo_window
= window
;
23932 help_echo_object
= object
;
23933 help_echo_pos
= charpos
;
23938 /* Look for a `pointer' property. */
23939 if (NILP (pointer
))
23941 /* Check overlays first. */
23942 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23943 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23945 if (NILP (pointer
))
23947 Lisp_Object object
= glyph
->object
;
23948 int charpos
= glyph
->charpos
;
23950 /* Try text properties. */
23951 if (STRINGP (object
)
23953 && charpos
< SCHARS (object
))
23955 pointer
= Fget_text_property (make_number (charpos
),
23957 if (NILP (pointer
))
23959 /* If the string itself doesn't specify a pointer,
23960 see if the buffer text ``under'' it does. */
23961 struct glyph_row
*r
23962 = MATRIX_ROW (w
->current_matrix
, vpos
);
23963 int start
= MATRIX_ROW_START_CHARPOS (r
);
23964 int pos
= string_buffer_position (w
, object
, start
);
23966 pointer
= Fget_char_property (make_number (pos
),
23967 Qpointer
, w
->buffer
);
23970 else if (BUFFERP (object
)
23973 pointer
= Fget_text_property (make_number (charpos
),
23980 current_buffer
= obuf
;
23985 define_frame_cursor1 (f
, cursor
, pointer
);
23990 Clear any mouse-face on window W. This function is part of the
23991 redisplay interface, and is called from try_window_id and similar
23992 functions to ensure the mouse-highlight is off. */
23995 x_clear_window_mouse_face (w
)
23998 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23999 Lisp_Object window
;
24002 XSETWINDOW (window
, w
);
24003 if (EQ (window
, dpyinfo
->mouse_face_window
))
24004 clear_mouse_face (dpyinfo
);
24010 Just discard the mouse face information for frame F, if any.
24011 This is used when the size of F is changed. */
24014 cancel_mouse_face (f
)
24017 Lisp_Object window
;
24018 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24020 window
= dpyinfo
->mouse_face_window
;
24021 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24023 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24024 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24025 dpyinfo
->mouse_face_window
= Qnil
;
24030 #endif /* HAVE_WINDOW_SYSTEM */
24033 /***********************************************************************
24035 ***********************************************************************/
24037 #ifdef HAVE_WINDOW_SYSTEM
24039 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24040 which intersects rectangle R. R is in window-relative coordinates. */
24043 expose_area (w
, row
, r
, area
)
24045 struct glyph_row
*row
;
24047 enum glyph_row_area area
;
24049 struct glyph
*first
= row
->glyphs
[area
];
24050 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24051 struct glyph
*last
;
24052 int first_x
, start_x
, x
;
24054 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24055 /* If row extends face to end of line write the whole line. */
24056 draw_glyphs (w
, 0, row
, area
,
24057 0, row
->used
[area
],
24058 DRAW_NORMAL_TEXT
, 0);
24061 /* Set START_X to the window-relative start position for drawing glyphs of
24062 AREA. The first glyph of the text area can be partially visible.
24063 The first glyphs of other areas cannot. */
24064 start_x
= window_box_left_offset (w
, area
);
24066 if (area
== TEXT_AREA
)
24069 /* Find the first glyph that must be redrawn. */
24071 && x
+ first
->pixel_width
< r
->x
)
24073 x
+= first
->pixel_width
;
24077 /* Find the last one. */
24081 && x
< r
->x
+ r
->width
)
24083 x
+= last
->pixel_width
;
24089 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24090 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24091 DRAW_NORMAL_TEXT
, 0);
24096 /* Redraw the parts of the glyph row ROW on window W intersecting
24097 rectangle R. R is in window-relative coordinates. Value is
24098 non-zero if mouse-face was overwritten. */
24101 expose_line (w
, row
, r
)
24103 struct glyph_row
*row
;
24106 xassert (row
->enabled_p
);
24108 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24109 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24110 0, row
->used
[TEXT_AREA
],
24111 DRAW_NORMAL_TEXT
, 0);
24114 if (row
->used
[LEFT_MARGIN_AREA
])
24115 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24116 if (row
->used
[TEXT_AREA
])
24117 expose_area (w
, row
, r
, TEXT_AREA
);
24118 if (row
->used
[RIGHT_MARGIN_AREA
])
24119 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24120 draw_row_fringe_bitmaps (w
, row
);
24123 return row
->mouse_face_p
;
24127 /* Redraw those parts of glyphs rows during expose event handling that
24128 overlap other rows. Redrawing of an exposed line writes over parts
24129 of lines overlapping that exposed line; this function fixes that.
24131 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24132 row in W's current matrix that is exposed and overlaps other rows.
24133 LAST_OVERLAPPING_ROW is the last such row. */
24136 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24138 struct glyph_row
*first_overlapping_row
;
24139 struct glyph_row
*last_overlapping_row
;
24142 struct glyph_row
*row
;
24144 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24145 if (row
->overlapping_p
)
24147 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24150 if (row
->used
[LEFT_MARGIN_AREA
])
24151 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24153 if (row
->used
[TEXT_AREA
])
24154 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24156 if (row
->used
[RIGHT_MARGIN_AREA
])
24157 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24163 /* Return non-zero if W's cursor intersects rectangle R. */
24166 phys_cursor_in_rect_p (w
, r
)
24170 XRectangle cr
, result
;
24171 struct glyph
*cursor_glyph
;
24172 struct glyph_row
*row
;
24174 if (w
->phys_cursor
.vpos
>= 0
24175 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24176 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24178 && row
->cursor_in_fringe_p
)
24180 /* Cursor is in the fringe. */
24181 cr
.x
= window_box_right_offset (w
,
24182 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24183 ? RIGHT_MARGIN_AREA
24186 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24187 cr
.height
= row
->height
;
24188 return x_intersect_rectangles (&cr
, r
, &result
);
24191 cursor_glyph
= get_phys_cursor_glyph (w
);
24194 /* r is relative to W's box, but w->phys_cursor.x is relative
24195 to left edge of W's TEXT area. Adjust it. */
24196 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24197 cr
.y
= w
->phys_cursor
.y
;
24198 cr
.width
= cursor_glyph
->pixel_width
;
24199 cr
.height
= w
->phys_cursor_height
;
24200 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24201 I assume the effect is the same -- and this is portable. */
24202 return x_intersect_rectangles (&cr
, r
, &result
);
24204 /* If we don't understand the format, pretend we're not in the hot-spot. */
24210 Draw a vertical window border to the right of window W if W doesn't
24211 have vertical scroll bars. */
24214 x_draw_vertical_border (w
)
24217 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24219 /* We could do better, if we knew what type of scroll-bar the adjacent
24220 windows (on either side) have... But we don't :-(
24221 However, I think this works ok. ++KFS 2003-04-25 */
24223 /* Redraw borders between horizontally adjacent windows. Don't
24224 do it for frames with vertical scroll bars because either the
24225 right scroll bar of a window, or the left scroll bar of its
24226 neighbor will suffice as a border. */
24227 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24230 if (!WINDOW_RIGHTMOST_P (w
)
24231 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24233 int x0
, x1
, y0
, y1
;
24235 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24238 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24241 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24243 else if (!WINDOW_LEFTMOST_P (w
)
24244 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24246 int x0
, x1
, y0
, y1
;
24248 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24251 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24254 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24259 /* Redraw the part of window W intersection rectangle FR. Pixel
24260 coordinates in FR are frame-relative. Call this function with
24261 input blocked. Value is non-zero if the exposure overwrites
24265 expose_window (w
, fr
)
24269 struct frame
*f
= XFRAME (w
->frame
);
24271 int mouse_face_overwritten_p
= 0;
24273 /* If window is not yet fully initialized, do nothing. This can
24274 happen when toolkit scroll bars are used and a window is split.
24275 Reconfiguring the scroll bar will generate an expose for a newly
24277 if (w
->current_matrix
== NULL
)
24280 /* When we're currently updating the window, display and current
24281 matrix usually don't agree. Arrange for a thorough display
24283 if (w
== updated_window
)
24285 SET_FRAME_GARBAGED (f
);
24289 /* Frame-relative pixel rectangle of W. */
24290 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24291 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24292 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24293 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24295 if (x_intersect_rectangles (fr
, &wr
, &r
))
24297 int yb
= window_text_bottom_y (w
);
24298 struct glyph_row
*row
;
24299 int cursor_cleared_p
;
24300 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24302 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24303 r
.x
, r
.y
, r
.width
, r
.height
));
24305 /* Convert to window coordinates. */
24306 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24307 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24309 /* Turn off the cursor. */
24310 if (!w
->pseudo_window_p
24311 && phys_cursor_in_rect_p (w
, &r
))
24313 x_clear_cursor (w
);
24314 cursor_cleared_p
= 1;
24317 cursor_cleared_p
= 0;
24319 /* Update lines intersecting rectangle R. */
24320 first_overlapping_row
= last_overlapping_row
= NULL
;
24321 for (row
= w
->current_matrix
->rows
;
24326 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24328 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24329 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24330 || (r
.y
>= y0
&& r
.y
< y1
)
24331 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24333 /* A header line may be overlapping, but there is no need
24334 to fix overlapping areas for them. KFS 2005-02-12 */
24335 if (row
->overlapping_p
&& !row
->mode_line_p
)
24337 if (first_overlapping_row
== NULL
)
24338 first_overlapping_row
= row
;
24339 last_overlapping_row
= row
;
24343 if (expose_line (w
, row
, &r
))
24344 mouse_face_overwritten_p
= 1;
24347 else if (row
->overlapping_p
)
24349 /* We must redraw a row overlapping the exposed area. */
24351 ? y0
+ row
->phys_height
> r
.y
24352 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24354 if (first_overlapping_row
== NULL
)
24355 first_overlapping_row
= row
;
24356 last_overlapping_row
= row
;
24364 /* Display the mode line if there is one. */
24365 if (WINDOW_WANTS_MODELINE_P (w
)
24366 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24368 && row
->y
< r
.y
+ r
.height
)
24370 if (expose_line (w
, row
, &r
))
24371 mouse_face_overwritten_p
= 1;
24374 if (!w
->pseudo_window_p
)
24376 /* Fix the display of overlapping rows. */
24377 if (first_overlapping_row
)
24378 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24381 /* Draw border between windows. */
24382 x_draw_vertical_border (w
);
24384 /* Turn the cursor on again. */
24385 if (cursor_cleared_p
)
24386 update_window_cursor (w
, 1);
24390 return mouse_face_overwritten_p
;
24395 /* Redraw (parts) of all windows in the window tree rooted at W that
24396 intersect R. R contains frame pixel coordinates. Value is
24397 non-zero if the exposure overwrites mouse-face. */
24400 expose_window_tree (w
, r
)
24404 struct frame
*f
= XFRAME (w
->frame
);
24405 int mouse_face_overwritten_p
= 0;
24407 while (w
&& !FRAME_GARBAGED_P (f
))
24409 if (!NILP (w
->hchild
))
24410 mouse_face_overwritten_p
24411 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24412 else if (!NILP (w
->vchild
))
24413 mouse_face_overwritten_p
24414 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24416 mouse_face_overwritten_p
|= expose_window (w
, r
);
24418 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24421 return mouse_face_overwritten_p
;
24426 Redisplay an exposed area of frame F. X and Y are the upper-left
24427 corner of the exposed rectangle. W and H are width and height of
24428 the exposed area. All are pixel values. W or H zero means redraw
24429 the entire frame. */
24432 expose_frame (f
, x
, y
, w
, h
)
24437 int mouse_face_overwritten_p
= 0;
24439 TRACE ((stderr
, "expose_frame "));
24441 /* No need to redraw if frame will be redrawn soon. */
24442 if (FRAME_GARBAGED_P (f
))
24444 TRACE ((stderr
, " garbaged\n"));
24448 /* If basic faces haven't been realized yet, there is no point in
24449 trying to redraw anything. This can happen when we get an expose
24450 event while Emacs is starting, e.g. by moving another window. */
24451 if (FRAME_FACE_CACHE (f
) == NULL
24452 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24454 TRACE ((stderr
, " no faces\n"));
24458 if (w
== 0 || h
== 0)
24461 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24462 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24472 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24473 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24475 if (WINDOWP (f
->tool_bar_window
))
24476 mouse_face_overwritten_p
24477 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24479 #ifdef HAVE_X_WINDOWS
24481 #ifndef USE_X_TOOLKIT
24482 if (WINDOWP (f
->menu_bar_window
))
24483 mouse_face_overwritten_p
24484 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24485 #endif /* not USE_X_TOOLKIT */
24489 /* Some window managers support a focus-follows-mouse style with
24490 delayed raising of frames. Imagine a partially obscured frame,
24491 and moving the mouse into partially obscured mouse-face on that
24492 frame. The visible part of the mouse-face will be highlighted,
24493 then the WM raises the obscured frame. With at least one WM, KDE
24494 2.1, Emacs is not getting any event for the raising of the frame
24495 (even tried with SubstructureRedirectMask), only Expose events.
24496 These expose events will draw text normally, i.e. not
24497 highlighted. Which means we must redo the highlight here.
24498 Subsume it under ``we love X''. --gerd 2001-08-15 */
24499 /* Included in Windows version because Windows most likely does not
24500 do the right thing if any third party tool offers
24501 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24502 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24504 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24505 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24507 int x
= dpyinfo
->mouse_face_mouse_x
;
24508 int y
= dpyinfo
->mouse_face_mouse_y
;
24509 clear_mouse_face (dpyinfo
);
24510 note_mouse_highlight (f
, x
, y
);
24517 Determine the intersection of two rectangles R1 and R2. Return
24518 the intersection in *RESULT. Value is non-zero if RESULT is not
24522 x_intersect_rectangles (r1
, r2
, result
)
24523 XRectangle
*r1
, *r2
, *result
;
24525 XRectangle
*left
, *right
;
24526 XRectangle
*upper
, *lower
;
24527 int intersection_p
= 0;
24529 /* Rearrange so that R1 is the left-most rectangle. */
24531 left
= r1
, right
= r2
;
24533 left
= r2
, right
= r1
;
24535 /* X0 of the intersection is right.x0, if this is inside R1,
24536 otherwise there is no intersection. */
24537 if (right
->x
<= left
->x
+ left
->width
)
24539 result
->x
= right
->x
;
24541 /* The right end of the intersection is the minimum of the
24542 the right ends of left and right. */
24543 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24546 /* Same game for Y. */
24548 upper
= r1
, lower
= r2
;
24550 upper
= r2
, lower
= r1
;
24552 /* The upper end of the intersection is lower.y0, if this is inside
24553 of upper. Otherwise, there is no intersection. */
24554 if (lower
->y
<= upper
->y
+ upper
->height
)
24556 result
->y
= lower
->y
;
24558 /* The lower end of the intersection is the minimum of the lower
24559 ends of upper and lower. */
24560 result
->height
= (min (lower
->y
+ lower
->height
,
24561 upper
->y
+ upper
->height
)
24563 intersection_p
= 1;
24567 return intersection_p
;
24570 #endif /* HAVE_WINDOW_SYSTEM */
24573 /***********************************************************************
24575 ***********************************************************************/
24580 Vwith_echo_area_save_vector
= Qnil
;
24581 staticpro (&Vwith_echo_area_save_vector
);
24583 Vmessage_stack
= Qnil
;
24584 staticpro (&Vmessage_stack
);
24586 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24587 staticpro (&Qinhibit_redisplay
);
24589 message_dolog_marker1
= Fmake_marker ();
24590 staticpro (&message_dolog_marker1
);
24591 message_dolog_marker2
= Fmake_marker ();
24592 staticpro (&message_dolog_marker2
);
24593 message_dolog_marker3
= Fmake_marker ();
24594 staticpro (&message_dolog_marker3
);
24597 defsubr (&Sdump_frame_glyph_matrix
);
24598 defsubr (&Sdump_glyph_matrix
);
24599 defsubr (&Sdump_glyph_row
);
24600 defsubr (&Sdump_tool_bar_row
);
24601 defsubr (&Strace_redisplay
);
24602 defsubr (&Strace_to_stderr
);
24604 #ifdef HAVE_WINDOW_SYSTEM
24605 defsubr (&Stool_bar_lines_needed
);
24606 defsubr (&Slookup_image_map
);
24608 defsubr (&Sformat_mode_line
);
24609 defsubr (&Sinvisible_p
);
24611 staticpro (&Qmenu_bar_update_hook
);
24612 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24614 staticpro (&Qoverriding_terminal_local_map
);
24615 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24617 staticpro (&Qoverriding_local_map
);
24618 Qoverriding_local_map
= intern ("overriding-local-map");
24620 staticpro (&Qwindow_scroll_functions
);
24621 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24623 staticpro (&Qwindow_text_change_functions
);
24624 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24626 staticpro (&Qredisplay_end_trigger_functions
);
24627 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24629 staticpro (&Qinhibit_point_motion_hooks
);
24630 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24632 Qeval
= intern ("eval");
24633 staticpro (&Qeval
);
24635 QCdata
= intern (":data");
24636 staticpro (&QCdata
);
24637 Qdisplay
= intern ("display");
24638 staticpro (&Qdisplay
);
24639 Qspace_width
= intern ("space-width");
24640 staticpro (&Qspace_width
);
24641 Qraise
= intern ("raise");
24642 staticpro (&Qraise
);
24643 Qslice
= intern ("slice");
24644 staticpro (&Qslice
);
24645 Qspace
= intern ("space");
24646 staticpro (&Qspace
);
24647 Qmargin
= intern ("margin");
24648 staticpro (&Qmargin
);
24649 Qpointer
= intern ("pointer");
24650 staticpro (&Qpointer
);
24651 Qleft_margin
= intern ("left-margin");
24652 staticpro (&Qleft_margin
);
24653 Qright_margin
= intern ("right-margin");
24654 staticpro (&Qright_margin
);
24655 Qcenter
= intern ("center");
24656 staticpro (&Qcenter
);
24657 Qline_height
= intern ("line-height");
24658 staticpro (&Qline_height
);
24659 QCalign_to
= intern (":align-to");
24660 staticpro (&QCalign_to
);
24661 QCrelative_width
= intern (":relative-width");
24662 staticpro (&QCrelative_width
);
24663 QCrelative_height
= intern (":relative-height");
24664 staticpro (&QCrelative_height
);
24665 QCeval
= intern (":eval");
24666 staticpro (&QCeval
);
24667 QCpropertize
= intern (":propertize");
24668 staticpro (&QCpropertize
);
24669 QCfile
= intern (":file");
24670 staticpro (&QCfile
);
24671 Qfontified
= intern ("fontified");
24672 staticpro (&Qfontified
);
24673 Qfontification_functions
= intern ("fontification-functions");
24674 staticpro (&Qfontification_functions
);
24675 Qtrailing_whitespace
= intern ("trailing-whitespace");
24676 staticpro (&Qtrailing_whitespace
);
24677 Qescape_glyph
= intern ("escape-glyph");
24678 staticpro (&Qescape_glyph
);
24679 Qnobreak_space
= intern ("nobreak-space");
24680 staticpro (&Qnobreak_space
);
24681 Qimage
= intern ("image");
24682 staticpro (&Qimage
);
24683 QCmap
= intern (":map");
24684 staticpro (&QCmap
);
24685 QCpointer
= intern (":pointer");
24686 staticpro (&QCpointer
);
24687 Qrect
= intern ("rect");
24688 staticpro (&Qrect
);
24689 Qcircle
= intern ("circle");
24690 staticpro (&Qcircle
);
24691 Qpoly
= intern ("poly");
24692 staticpro (&Qpoly
);
24693 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24694 staticpro (&Qmessage_truncate_lines
);
24695 Qgrow_only
= intern ("grow-only");
24696 staticpro (&Qgrow_only
);
24697 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24698 staticpro (&Qinhibit_menubar_update
);
24699 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24700 staticpro (&Qinhibit_eval_during_redisplay
);
24701 Qposition
= intern ("position");
24702 staticpro (&Qposition
);
24703 Qbuffer_position
= intern ("buffer-position");
24704 staticpro (&Qbuffer_position
);
24705 Qobject
= intern ("object");
24706 staticpro (&Qobject
);
24707 Qbar
= intern ("bar");
24709 Qhbar
= intern ("hbar");
24710 staticpro (&Qhbar
);
24711 Qbox
= intern ("box");
24713 Qhollow
= intern ("hollow");
24714 staticpro (&Qhollow
);
24715 Qhand
= intern ("hand");
24716 staticpro (&Qhand
);
24717 Qarrow
= intern ("arrow");
24718 staticpro (&Qarrow
);
24719 Qtext
= intern ("text");
24720 staticpro (&Qtext
);
24721 Qrisky_local_variable
= intern ("risky-local-variable");
24722 staticpro (&Qrisky_local_variable
);
24723 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24724 staticpro (&Qinhibit_free_realized_faces
);
24726 list_of_error
= Fcons (Fcons (intern ("error"),
24727 Fcons (intern ("void-variable"), Qnil
)),
24729 staticpro (&list_of_error
);
24731 Qlast_arrow_position
= intern ("last-arrow-position");
24732 staticpro (&Qlast_arrow_position
);
24733 Qlast_arrow_string
= intern ("last-arrow-string");
24734 staticpro (&Qlast_arrow_string
);
24736 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24737 staticpro (&Qoverlay_arrow_string
);
24738 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24739 staticpro (&Qoverlay_arrow_bitmap
);
24741 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24742 staticpro (&echo_buffer
[0]);
24743 staticpro (&echo_buffer
[1]);
24745 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24746 staticpro (&echo_area_buffer
[0]);
24747 staticpro (&echo_area_buffer
[1]);
24749 Vmessages_buffer_name
= build_string ("*Messages*");
24750 staticpro (&Vmessages_buffer_name
);
24752 mode_line_proptrans_alist
= Qnil
;
24753 staticpro (&mode_line_proptrans_alist
);
24754 mode_line_string_list
= Qnil
;
24755 staticpro (&mode_line_string_list
);
24756 mode_line_string_face
= Qnil
;
24757 staticpro (&mode_line_string_face
);
24758 mode_line_string_face_prop
= Qnil
;
24759 staticpro (&mode_line_string_face_prop
);
24760 Vmode_line_unwind_vector
= Qnil
;
24761 staticpro (&Vmode_line_unwind_vector
);
24763 help_echo_string
= Qnil
;
24764 staticpro (&help_echo_string
);
24765 help_echo_object
= Qnil
;
24766 staticpro (&help_echo_object
);
24767 help_echo_window
= Qnil
;
24768 staticpro (&help_echo_window
);
24769 previous_help_echo_string
= Qnil
;
24770 staticpro (&previous_help_echo_string
);
24771 help_echo_pos
= -1;
24773 #ifdef HAVE_WINDOW_SYSTEM
24774 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24775 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24776 For example, if a block cursor is over a tab, it will be drawn as
24777 wide as that tab on the display. */);
24778 x_stretch_cursor_p
= 0;
24781 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24782 doc
: /* *Non-nil means highlight trailing whitespace.
24783 The face used for trailing whitespace is `trailing-whitespace'. */);
24784 Vshow_trailing_whitespace
= Qnil
;
24786 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24787 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24788 A value of t means highlight the character itself (for nobreak space,
24789 use face `nobreak-space').
24790 A value of nil means no highlighting.
24791 Other values mean display the escape glyph followed by an ordinary
24792 space or ordinary hyphen. */);
24793 Vnobreak_char_display
= Qt
;
24795 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24796 doc
: /* *The pointer shape to show in void text areas.
24797 A value of nil means to show the text pointer. Other options are `arrow',
24798 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24799 Vvoid_text_area_pointer
= Qarrow
;
24801 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24802 doc
: /* Non-nil means don't actually do any redisplay.
24803 This is used for internal purposes. */);
24804 Vinhibit_redisplay
= Qnil
;
24806 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24807 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24808 Vglobal_mode_string
= Qnil
;
24810 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24811 doc
: /* Marker for where to display an arrow on top of the buffer text.
24812 This must be the beginning of a line in order to work.
24813 See also `overlay-arrow-string'. */);
24814 Voverlay_arrow_position
= Qnil
;
24816 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24817 doc
: /* String to display as an arrow in non-window frames.
24818 See also `overlay-arrow-position'. */);
24819 Voverlay_arrow_string
= build_string ("=>");
24821 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24822 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24823 The symbols on this list are examined during redisplay to determine
24824 where to display overlay arrows. */);
24825 Voverlay_arrow_variable_list
24826 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24828 DEFVAR_INT ("scroll-step", &scroll_step
,
24829 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24830 If that fails to bring point back on frame, point is centered instead.
24831 If this is zero, point is always centered after it moves off frame.
24832 If you want scrolling to always be a line at a time, you should set
24833 `scroll-conservatively' to a large value rather than set this to 1. */);
24835 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24836 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24837 If point moves off-screen, redisplay will scroll by up to
24838 `scroll-conservatively' lines in order to bring point just barely
24839 onto the screen again. If that cannot be done, then redisplay
24840 recenters point as usual.
24842 A value of zero means always recenter point if it moves off screen. */);
24843 scroll_conservatively
= 0;
24845 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24846 doc
: /* *Number of lines of margin at the top and bottom of a window.
24847 Recenter the window whenever point gets within this many lines
24848 of the top or bottom of the window. */);
24851 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24852 doc
: /* Pixels per inch value for non-window system displays.
24853 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24854 Vdisplay_pixels_per_inch
= make_float (72.0);
24857 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24860 DEFVAR_LISP ("truncate-partial-width-windows",
24861 &Vtruncate_partial_width_windows
,
24862 doc
: /* Non-nil means truncate lines in windows with less than the frame width.
24863 For an integer value, truncate lines in each window with less than the
24864 full frame width, provided the window width is less than that integer;
24865 otherwise, respect the value of `truncate-lines'.
24867 For any other non-nil value, truncate lines in all windows with
24868 less than the full frame width.
24870 A value of nil means to respect the value of `truncate-lines'.
24872 If `word-wrap' is enabled, you might want to reduce this. */);
24873 Vtruncate_partial_width_windows
= make_number (50);
24875 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24876 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24877 Any other value means to use the appropriate face, `mode-line',
24878 `header-line', or `menu' respectively. */);
24879 mode_line_inverse_video
= 1;
24881 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24882 doc
: /* *Maximum buffer size for which line number should be displayed.
24883 If the buffer is bigger than this, the line number does not appear
24884 in the mode line. A value of nil means no limit. */);
24885 Vline_number_display_limit
= Qnil
;
24887 DEFVAR_INT ("line-number-display-limit-width",
24888 &line_number_display_limit_width
,
24889 doc
: /* *Maximum line width (in characters) for line number display.
24890 If the average length of the lines near point is bigger than this, then the
24891 line number may be omitted from the mode line. */);
24892 line_number_display_limit_width
= 200;
24894 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24895 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24896 highlight_nonselected_windows
= 0;
24898 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24899 doc
: /* Non-nil if more than one frame is visible on this display.
24900 Minibuffer-only frames don't count, but iconified frames do.
24901 This variable is not guaranteed to be accurate except while processing
24902 `frame-title-format' and `icon-title-format'. */);
24904 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24905 doc
: /* Template for displaying the title bar of visible frames.
24906 \(Assuming the window manager supports this feature.)
24908 This variable has the same structure as `mode-line-format', except that
24909 the %c and %l constructs are ignored. It is used only on frames for
24910 which no explicit name has been set \(see `modify-frame-parameters'). */);
24912 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24913 doc
: /* Template for displaying the title bar of an iconified frame.
24914 \(Assuming the window manager supports this feature.)
24915 This variable has the same structure as `mode-line-format' (which see),
24916 and is used only on frames for which no explicit name has been set
24917 \(see `modify-frame-parameters'). */);
24919 = Vframe_title_format
24920 = Fcons (intern ("multiple-frames"),
24921 Fcons (build_string ("%b"),
24922 Fcons (Fcons (empty_unibyte_string
,
24923 Fcons (intern ("invocation-name"),
24924 Fcons (build_string ("@"),
24925 Fcons (intern ("system-name"),
24929 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24930 doc
: /* Maximum number of lines to keep in the message log buffer.
24931 If nil, disable message logging. If t, log messages but don't truncate
24932 the buffer when it becomes large. */);
24933 Vmessage_log_max
= make_number (100);
24935 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24936 doc
: /* Functions called before redisplay, if window sizes have changed.
24937 The value should be a list of functions that take one argument.
24938 Just before redisplay, for each frame, if any of its windows have changed
24939 size since the last redisplay, or have been split or deleted,
24940 all the functions in the list are called, with the frame as argument. */);
24941 Vwindow_size_change_functions
= Qnil
;
24943 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24944 doc
: /* List of functions to call before redisplaying a window with scrolling.
24945 Each function is called with two arguments, the window and its new
24946 display-start position. Note that these functions are also called by
24947 `set-window-buffer'. Also note that the value of `window-end' is not
24948 valid when these functions are called. */);
24949 Vwindow_scroll_functions
= Qnil
;
24951 DEFVAR_LISP ("window-text-change-functions",
24952 &Vwindow_text_change_functions
,
24953 doc
: /* Functions to call in redisplay when text in the window might change. */);
24954 Vwindow_text_change_functions
= Qnil
;
24956 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24957 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24958 Each function is called with two arguments, the window and the end trigger value.
24959 See `set-window-redisplay-end-trigger'. */);
24960 Vredisplay_end_trigger_functions
= Qnil
;
24962 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24963 doc
: /* *Non-nil means autoselect window with mouse pointer.
24964 If nil, do not autoselect windows.
24965 A positive number means delay autoselection by that many seconds: a
24966 window is autoselected only after the mouse has remained in that
24967 window for the duration of the delay.
24968 A negative number has a similar effect, but causes windows to be
24969 autoselected only after the mouse has stopped moving. \(Because of
24970 the way Emacs compares mouse events, you will occasionally wait twice
24971 that time before the window gets selected.\)
24972 Any other value means to autoselect window instantaneously when the
24973 mouse pointer enters it.
24975 Autoselection selects the minibuffer only if it is active, and never
24976 unselects the minibuffer if it is active.
24978 When customizing this variable make sure that the actual value of
24979 `focus-follows-mouse' matches the behavior of your window manager. */);
24980 Vmouse_autoselect_window
= Qnil
;
24982 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24983 doc
: /* *Non-nil means automatically resize tool-bars.
24984 This dynamically changes the tool-bar's height to the minimum height
24985 that is needed to make all tool-bar items visible.
24986 If value is `grow-only', the tool-bar's height is only increased
24987 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24988 Vauto_resize_tool_bars
= Qt
;
24990 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24991 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24992 auto_raise_tool_bar_buttons_p
= 1;
24994 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24995 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24996 make_cursor_line_fully_visible_p
= 1;
24998 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24999 doc
: /* *Border below tool-bar in pixels.
25000 If an integer, use it as the height of the border.
25001 If it is one of `internal-border-width' or `border-width', use the
25002 value of the corresponding frame parameter.
25003 Otherwise, no border is added below the tool-bar. */);
25004 Vtool_bar_border
= Qinternal_border_width
;
25006 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25007 doc
: /* *Margin around tool-bar buttons in pixels.
25008 If an integer, use that for both horizontal and vertical margins.
25009 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25010 HORZ specifying the horizontal margin, and VERT specifying the
25011 vertical margin. */);
25012 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25014 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25015 doc
: /* *Relief thickness of tool-bar buttons. */);
25016 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25018 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25019 doc
: /* List of functions to call to fontify regions of text.
25020 Each function is called with one argument POS. Functions must
25021 fontify a region starting at POS in the current buffer, and give
25022 fontified regions the property `fontified'. */);
25023 Vfontification_functions
= Qnil
;
25024 Fmake_variable_buffer_local (Qfontification_functions
);
25026 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25027 &unibyte_display_via_language_environment
,
25028 doc
: /* *Non-nil means display unibyte text according to language environment.
25029 Specifically this means that unibyte non-ASCII characters
25030 are displayed by converting them to the equivalent multibyte characters
25031 according to the current language environment. As a result, they are
25032 displayed according to the current fontset. */);
25033 unibyte_display_via_language_environment
= 0;
25035 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25036 doc
: /* *Maximum height for resizing mini-windows.
25037 If a float, it specifies a fraction of the mini-window frame's height.
25038 If an integer, it specifies a number of lines. */);
25039 Vmax_mini_window_height
= make_float (0.25);
25041 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25042 doc
: /* *How to resize mini-windows.
25043 A value of nil means don't automatically resize mini-windows.
25044 A value of t means resize them to fit the text displayed in them.
25045 A value of `grow-only', the default, means let mini-windows grow
25046 only, until their display becomes empty, at which point the windows
25047 go back to their normal size. */);
25048 Vresize_mini_windows
= Qgrow_only
;
25050 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25051 doc
: /* Alist specifying how to blink the cursor off.
25052 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25053 `cursor-type' frame-parameter or variable equals ON-STATE,
25054 comparing using `equal', Emacs uses OFF-STATE to specify
25055 how to blink it off. ON-STATE and OFF-STATE are values for
25056 the `cursor-type' frame parameter.
25058 If a frame's ON-STATE has no entry in this list,
25059 the frame's other specifications determine how to blink the cursor off. */);
25060 Vblink_cursor_alist
= Qnil
;
25062 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25063 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25064 automatic_hscrolling_p
= 1;
25065 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
25066 staticpro (&Qauto_hscroll_mode
);
25068 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25069 doc
: /* *How many columns away from the window edge point is allowed to get
25070 before automatic hscrolling will horizontally scroll the window. */);
25071 hscroll_margin
= 5;
25073 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25074 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25075 When point is less than `hscroll-margin' columns from the window
25076 edge, automatic hscrolling will scroll the window by the amount of columns
25077 determined by this variable. If its value is a positive integer, scroll that
25078 many columns. If it's a positive floating-point number, it specifies the
25079 fraction of the window's width to scroll. If it's nil or zero, point will be
25080 centered horizontally after the scroll. Any other value, including negative
25081 numbers, are treated as if the value were zero.
25083 Automatic hscrolling always moves point outside the scroll margin, so if
25084 point was more than scroll step columns inside the margin, the window will
25085 scroll more than the value given by the scroll step.
25087 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25088 and `scroll-right' overrides this variable's effect. */);
25089 Vhscroll_step
= make_number (0);
25091 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25092 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25093 Bind this around calls to `message' to let it take effect. */);
25094 message_truncate_lines
= 0;
25096 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25097 doc
: /* Normal hook run to update the menu bar definitions.
25098 Redisplay runs this hook before it redisplays the menu bar.
25099 This is used to update submenus such as Buffers,
25100 whose contents depend on various data. */);
25101 Vmenu_bar_update_hook
= Qnil
;
25103 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25104 doc
: /* Frame for which we are updating a menu.
25105 The enable predicate for a menu binding should check this variable. */);
25106 Vmenu_updating_frame
= Qnil
;
25108 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25109 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25110 inhibit_menubar_update
= 0;
25112 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25113 doc
: /* Prefix prepended to all continuation lines at display time.
25114 The value may be a string, an image, or a stretch-glyph; it is
25115 interpreted in the same way as the value of a `display' text property.
25117 This variable is overridden by any `wrap-prefix' text or overlay
25120 To add a prefix to non-continuation lines, use `line-prefix'. */);
25121 Vwrap_prefix
= Qnil
;
25122 staticpro (&Qwrap_prefix
);
25123 Qwrap_prefix
= intern ("wrap-prefix");
25124 Fmake_variable_buffer_local (Qwrap_prefix
);
25126 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25127 doc
: /* Prefix prepended to all non-continuation lines at display time.
25128 The value may be a string, an image, or a stretch-glyph; it is
25129 interpreted in the same way as the value of a `display' text property.
25131 This variable is overridden by any `line-prefix' text or overlay
25134 To add a prefix to continuation lines, use `wrap-prefix'. */);
25135 Vline_prefix
= Qnil
;
25136 staticpro (&Qline_prefix
);
25137 Qline_prefix
= intern ("line-prefix");
25138 Fmake_variable_buffer_local (Qline_prefix
);
25140 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25141 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25142 inhibit_eval_during_redisplay
= 0;
25144 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25145 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25146 inhibit_free_realized_faces
= 0;
25149 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25150 doc
: /* Inhibit try_window_id display optimization. */);
25151 inhibit_try_window_id
= 0;
25153 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25154 doc
: /* Inhibit try_window_reusing display optimization. */);
25155 inhibit_try_window_reusing
= 0;
25157 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25158 doc
: /* Inhibit try_cursor_movement display optimization. */);
25159 inhibit_try_cursor_movement
= 0;
25160 #endif /* GLYPH_DEBUG */
25162 DEFVAR_INT ("overline-margin", &overline_margin
,
25163 doc
: /* *Space between overline and text, in pixels.
25164 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25165 margin to the caracter height. */);
25166 overline_margin
= 2;
25168 DEFVAR_INT ("underline-minimum-offset",
25169 &underline_minimum_offset
,
25170 doc
: /* Minimum distance between baseline and underline.
25171 This can improve legibility of underlined text at small font sizes,
25172 particularly when using variable `x-use-underline-position-properties'
25173 with fonts that specify an UNDERLINE_POSITION relatively close to the
25174 baseline. The default value is 1. */);
25175 underline_minimum_offset
= 1;
25177 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25178 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25179 display_hourglass_p
= 1;
25181 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25182 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25183 Value must be an integer or float. */);
25184 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25186 hourglass_atimer
= NULL
;
25187 hourglass_shown_p
= 0;
25191 /* Initialize this module when Emacs starts. */
25196 Lisp_Object root_window
;
25197 struct window
*mini_w
;
25199 current_header_line_height
= current_mode_line_height
= -1;
25201 CHARPOS (this_line_start_pos
) = 0;
25203 mini_w
= XWINDOW (minibuf_window
);
25204 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25206 if (!noninteractive
)
25208 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25211 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25212 set_window_height (root_window
,
25213 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25215 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25216 set_window_height (minibuf_window
, 1, 0);
25218 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25219 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25221 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25222 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25223 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25225 /* The default ellipsis glyphs `...'. */
25226 for (i
= 0; i
< 3; ++i
)
25227 default_invis_vector
[i
] = make_number ('.');
25231 /* Allocate the buffer for frame titles.
25232 Also used for `format-mode-line'. */
25234 mode_line_noprop_buf
= (char *) xmalloc (size
);
25235 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25236 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25237 mode_line_target
= MODE_LINE_DISPLAY
;
25240 help_echo_showing_p
= 0;
25243 /* Since w32 does not support atimers, it defines its own implementation of
25244 the following three functions in w32fns.c. */
25247 /* Platform-independent portion of hourglass implementation. */
25249 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25251 hourglass_started ()
25253 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25256 /* Cancel a currently active hourglass timer, and start a new one. */
25260 #if defined (HAVE_WINDOW_SYSTEM)
25262 int secs
, usecs
= 0;
25264 cancel_hourglass ();
25266 if (INTEGERP (Vhourglass_delay
)
25267 && XINT (Vhourglass_delay
) > 0)
25268 secs
= XFASTINT (Vhourglass_delay
);
25269 else if (FLOATP (Vhourglass_delay
)
25270 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25273 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25274 secs
= XFASTINT (tem
);
25275 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25278 secs
= DEFAULT_HOURGLASS_DELAY
;
25280 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25281 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25282 show_hourglass
, NULL
);
25287 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25290 cancel_hourglass ()
25292 #if defined (HAVE_WINDOW_SYSTEM)
25293 if (hourglass_atimer
)
25295 cancel_atimer (hourglass_atimer
);
25296 hourglass_atimer
= NULL
;
25299 if (hourglass_shown_p
)
25303 #endif /* ! WINDOWSNT */
25305 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25306 (do not change this comment) */