1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
175 #include "keyboard.h"
178 #include "termchar.h"
179 #include "dispextern.h"
181 #include "character.h"
184 #include "commands.h"
188 #include "termhooks.h"
189 #include "intervals.h"
192 #include "region-cache.h"
195 #include "blockinput.h"
197 #ifdef HAVE_X_WINDOWS
212 #ifndef FRAME_X_OUTPUT
213 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
216 #define INFINITY 10000000
218 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
219 || defined(HAVE_NS) || defined (USE_GTK)
220 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
221 extern int pending_menu_activation
;
224 extern int interrupt_input
;
225 extern int command_loop_level
;
227 extern Lisp_Object impl_do_mouse_tracking
;
229 extern int minibuffer_auto_raise
;
230 extern Lisp_Object Vminibuffer_list
;
232 extern Lisp_Object Qface
;
233 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
235 extern Lisp_Object impl_Voverriding_local_map
;
236 extern Lisp_Object impl_Voverriding_local_map_menu_flag
;
237 extern Lisp_Object Qmenu_item
;
238 extern Lisp_Object Qwhen
;
239 extern Lisp_Object Qhelp_echo
;
240 extern Lisp_Object Qbefore_string
, Qafter_string
;
242 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
243 Lisp_Object Qwindow_scroll_functions
, impl_Vwindow_scroll_functions
;
244 Lisp_Object Qwindow_text_change_functions
, impl_Vwindow_text_change_functions
;
245 Lisp_Object Qredisplay_end_trigger_functions
, impl_Vredisplay_end_trigger_functions
;
246 Lisp_Object Qinhibit_point_motion_hooks
;
247 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
248 Lisp_Object Qfontified
;
249 Lisp_Object Qgrow_only
;
250 Lisp_Object Qinhibit_eval_during_redisplay
;
251 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
254 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
257 Lisp_Object Qarrow
, Qhand
, Qtext
;
259 Lisp_Object Qrisky_local_variable
;
261 /* Holds the list (error). */
262 Lisp_Object list_of_error
;
264 /* Functions called to fontify regions of text. */
266 Lisp_Object impl_Vfontification_functions
;
267 Lisp_Object Qfontification_functions
;
269 /* Non-nil means automatically select any window when the mouse
270 cursor moves into it. */
271 Lisp_Object impl_Vmouse_autoselect_window
;
273 Lisp_Object impl_Vwrap_prefix
, Qwrap_prefix
;
274 Lisp_Object impl_Vline_prefix
, Qline_prefix
;
276 /* Non-zero means draw tool bar buttons raised when the mouse moves
279 int auto_raise_tool_bar_buttons_p
;
281 /* Non-zero means to reposition window if cursor line is only partially visible. */
283 int make_cursor_line_fully_visible_p
;
285 /* Margin below tool bar in pixels. 0 or nil means no margin.
286 If value is `internal-border-width' or `border-width',
287 the corresponding frame parameter is used. */
289 Lisp_Object impl_Vtool_bar_border
;
291 /* Margin around tool bar buttons in pixels. */
293 Lisp_Object impl_Vtool_bar_button_margin
;
295 /* Thickness of shadow to draw around tool bar buttons. */
297 EMACS_INT tool_bar_button_relief
;
299 /* Non-nil means automatically resize tool-bars so that all tool-bar
300 items are visible, and no blank lines remain.
302 If value is `grow-only', only make tool-bar bigger. */
304 Lisp_Object impl_Vauto_resize_tool_bars
;
306 /* Non-zero means draw block and hollow cursor as wide as the glyph
307 under it. For example, if a block cursor is over a tab, it will be
308 drawn as wide as that tab on the display. */
310 int x_stretch_cursor_p
;
312 /* Non-nil means don't actually do any redisplay. */
314 Lisp_Object impl_Vinhibit_redisplay
, Qinhibit_redisplay
;
316 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
318 int inhibit_eval_during_redisplay
;
320 /* Names of text properties relevant for redisplay. */
322 Lisp_Object Qdisplay
;
323 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
325 /* Symbols used in text property values. */
327 Lisp_Object impl_Vdisplay_pixels_per_inch
;
328 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
329 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
332 Lisp_Object Qmargin
, Qpointer
;
333 Lisp_Object Qline_height
;
334 extern Lisp_Object Qheight
;
335 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
336 extern Lisp_Object Qscroll_bar
;
337 extern Lisp_Object Qcursor
;
339 /* Non-nil means highlight trailing whitespace. */
341 Lisp_Object impl_Vshow_trailing_whitespace
;
343 /* Non-nil means escape non-break space and hyphens. */
345 Lisp_Object impl_Vnobreak_char_display
;
347 #ifdef HAVE_WINDOW_SYSTEM
348 extern Lisp_Object impl_Voverflow_newline_into_fringe
;
350 /* Test if overflow newline into fringe. Called with iterator IT
351 at or past right window margin, and with IT->current_x set. */
353 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
354 (!NILP (Voverflow_newline_into_fringe) \
355 && FRAME_WINDOW_P (it->f) \
356 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
357 && it->current_x == it->last_visible_x \
358 && it->line_wrap != WORD_WRAP)
360 #else /* !HAVE_WINDOW_SYSTEM */
361 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
362 #endif /* HAVE_WINDOW_SYSTEM */
364 /* Test if the display element loaded in IT is a space or tab
365 character. This is used to determine word wrapping. */
367 #define IT_DISPLAYING_WHITESPACE(it) \
368 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
370 /* Non-nil means show the text cursor in void text areas
371 i.e. in blank areas after eol and eob. This used to be
372 the default in 21.3. */
374 Lisp_Object impl_Vvoid_text_area_pointer
;
376 /* Name of the face used to highlight trailing whitespace. */
378 Lisp_Object Qtrailing_whitespace
;
380 /* Name and number of the face used to highlight escape glyphs. */
382 Lisp_Object Qescape_glyph
;
384 /* Name and number of the face used to highlight non-breaking spaces. */
386 Lisp_Object Qnobreak_space
;
388 /* The symbol `image' which is the car of the lists used to represent
393 /* The image map types. */
394 Lisp_Object QCmap
, QCpointer
;
395 Lisp_Object Qrect
, Qcircle
, Qpoly
;
397 /* Non-zero means print newline to stdout before next mini-buffer
400 int noninteractive_need_newline
;
402 /* Non-zero means print newline to message log before next message. */
404 static int message_log_need_newline
;
406 /* Three markers that message_dolog uses.
407 It could allocate them itself, but that causes trouble
408 in handling memory-full errors. */
409 static Lisp_Object message_dolog_marker1
;
410 static Lisp_Object message_dolog_marker2
;
411 static Lisp_Object message_dolog_marker3
;
413 /* The buffer position of the first character appearing entirely or
414 partially on the line of the selected window which contains the
415 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
416 redisplay optimization in redisplay_internal. */
418 static struct text_pos this_line_start_pos
;
420 /* Number of characters past the end of the line above, including the
421 terminating newline. */
423 static struct text_pos this_line_end_pos
;
425 /* The vertical positions and the height of this line. */
427 static int this_line_vpos
;
428 static int this_line_y
;
429 static int this_line_pixel_height
;
431 /* X position at which this display line starts. Usually zero;
432 negative if first character is partially visible. */
434 static int this_line_start_x
;
436 /* Buffer that this_line_.* variables are referring to. */
438 static struct buffer
*this_line_buffer
;
440 /* Nonzero means truncate lines in all windows less wide than the
443 Lisp_Object impl_Vtruncate_partial_width_windows
;
445 /* A flag to control how to display unibyte 8-bit character. */
447 int unibyte_display_via_language_environment
;
449 /* Nonzero means we have more than one non-mini-buffer-only frame.
450 Not guaranteed to be accurate except while parsing
451 frame-title-format. */
455 Lisp_Object impl_Vglobal_mode_string
;
458 /* List of variables (symbols) which hold markers for overlay arrows.
459 The symbols on this list are examined during redisplay to determine
460 where to display overlay arrows. */
462 Lisp_Object impl_Voverlay_arrow_variable_list
;
464 /* Marker for where to display an arrow on top of the buffer text. */
466 Lisp_Object impl_Voverlay_arrow_position
;
468 /* String to display for the arrow. Only used on terminal frames. */
470 Lisp_Object impl_Voverlay_arrow_string
;
472 /* Values of those variables at last redisplay are stored as
473 properties on `overlay-arrow-position' symbol. However, if
474 Voverlay_arrow_position is a marker, last-arrow-position is its
475 numerical position. */
477 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
479 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
480 properties on a symbol in overlay-arrow-variable-list. */
482 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
484 /* Like mode-line-format, but for the title bar on a visible frame. */
486 Lisp_Object impl_Vframe_title_format
;
488 /* Like mode-line-format, but for the title bar on an iconified frame. */
490 Lisp_Object impl_Vicon_title_format
;
492 /* List of functions to call when a window's size changes. These
493 functions get one arg, a frame on which one or more windows' sizes
496 static Lisp_Object impl_Vwindow_size_change_functions
;
498 Lisp_Object Qmenu_bar_update_hook
, impl_Vmenu_bar_update_hook
;
500 /* Nonzero if an overlay arrow has been displayed in this window. */
502 static int overlay_arrow_seen
;
504 /* Nonzero means highlight the region even in nonselected windows. */
506 int highlight_nonselected_windows
;
508 /* If cursor motion alone moves point off frame, try scrolling this
509 many lines up or down if that will bring it back. */
511 static EMACS_INT scroll_step
;
513 /* Nonzero means scroll just far enough to bring point back on the
514 screen, when appropriate. */
516 static EMACS_INT scroll_conservatively
;
518 /* Recenter the window whenever point gets within this many lines of
519 the top or bottom of the window. This value is translated into a
520 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
521 that there is really a fixed pixel height scroll margin. */
523 EMACS_INT scroll_margin
;
525 /* Number of windows showing the buffer of the selected window (or
526 another buffer with the same base buffer). keyboard.c refers to
531 /* Vector containing glyphs for an ellipsis `...'. */
533 static Lisp_Object default_invis_vector
[3];
535 /* Zero means display the mode-line/header-line/menu-bar in the default face
536 (this slightly odd definition is for compatibility with previous versions
537 of emacs), non-zero means display them using their respective faces.
539 This variable is deprecated. */
541 int mode_line_inverse_video
;
543 /* Prompt to display in front of the mini-buffer contents. */
545 Lisp_Object minibuf_prompt
;
547 /* Width of current mini-buffer prompt. Only set after display_line
548 of the line that contains the prompt. */
550 int minibuf_prompt_width
;
552 /* This is the window where the echo area message was displayed. It
553 is always a mini-buffer window, but it may not be the same window
554 currently active as a mini-buffer. */
556 Lisp_Object echo_area_window
;
558 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
559 pushes the current message and the value of
560 message_enable_multibyte on the stack, the function restore_message
561 pops the stack and displays MESSAGE again. */
563 Lisp_Object Vmessage_stack
;
565 /* Nonzero means multibyte characters were enabled when the echo area
566 message was specified. */
568 int message_enable_multibyte
;
570 /* Nonzero if we should redraw the mode lines on the next redisplay. */
572 int update_mode_lines
;
574 /* Nonzero if window sizes or contents have changed since last
575 redisplay that finished. */
577 int windows_or_buffers_changed
;
579 /* Nonzero means a frame's cursor type has been changed. */
581 int cursor_type_changed
;
583 /* Nonzero after display_mode_line if %l was used and it displayed a
586 int line_number_displayed
;
588 /* Maximum buffer size for which to display line numbers. */
590 Lisp_Object impl_Vline_number_display_limit
;
592 /* Line width to consider when repositioning for line number display. */
594 static EMACS_INT line_number_display_limit_width
;
596 /* Number of lines to keep in the message log buffer. t means
597 infinite. nil means don't log at all. */
599 Lisp_Object impl_Vmessage_log_max
;
601 /* The name of the *Messages* buffer, a string. */
603 static Lisp_Object Vmessages_buffer_name
;
605 /* Current, index 0, and last displayed echo area message. Either
606 buffers from echo_buffers, or nil to indicate no message. */
608 Lisp_Object echo_area_buffer
[2];
610 /* The buffers referenced from echo_area_buffer. */
612 static Lisp_Object echo_buffer
[2];
614 /* A vector saved used in with_area_buffer to reduce consing. */
616 static Lisp_Object Vwith_echo_area_save_vector
;
618 /* Non-zero means display_echo_area should display the last echo area
619 message again. Set by redisplay_preserve_echo_area. */
621 static int display_last_displayed_message_p
;
623 /* Nonzero if echo area is being used by print; zero if being used by
626 int message_buf_print
;
628 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
630 Lisp_Object Qinhibit_menubar_update
;
631 int inhibit_menubar_update
;
633 /* When evaluating expressions from menu bar items (enable conditions,
634 for instance), this is the frame they are being processed for. */
636 Lisp_Object impl_Vmenu_updating_frame
;
638 /* Maximum height for resizing mini-windows. Either a float
639 specifying a fraction of the available height, or an integer
640 specifying a number of lines. */
642 Lisp_Object impl_Vmax_mini_window_height
;
644 /* Non-zero means messages should be displayed with truncated
645 lines instead of being continued. */
647 int message_truncate_lines
;
648 Lisp_Object Qmessage_truncate_lines
;
650 /* Set to 1 in clear_message to make redisplay_internal aware
651 of an emptied echo area. */
653 static int message_cleared_p
;
655 /* How to blink the default frame cursor off. */
656 Lisp_Object impl_Vblink_cursor_alist
;
658 /* A scratch glyph row with contents used for generating truncation
659 glyphs. Also used in direct_output_for_insert. */
661 #define MAX_SCRATCH_GLYPHS 100
662 struct glyph_row scratch_glyph_row
;
663 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
665 /* Ascent and height of the last line processed by move_it_to. */
667 static int last_max_ascent
, last_height
;
669 /* Non-zero if there's a help-echo in the echo area. */
671 int help_echo_showing_p
;
673 /* If >= 0, computed, exact values of mode-line and header-line height
674 to use in the macros CURRENT_MODE_LINE_HEIGHT and
675 CURRENT_HEADER_LINE_HEIGHT. */
677 int current_mode_line_height
, current_header_line_height
;
679 /* The maximum distance to look ahead for text properties. Values
680 that are too small let us call compute_char_face and similar
681 functions too often which is expensive. Values that are too large
682 let us call compute_char_face and alike too often because we
683 might not be interested in text properties that far away. */
685 #define TEXT_PROP_DISTANCE_LIMIT 100
689 /* Variables to turn off display optimizations from Lisp. */
691 int inhibit_try_window_id
, inhibit_try_window_reusing
;
692 int inhibit_try_cursor_movement
;
694 /* Non-zero means print traces of redisplay if compiled with
697 int trace_redisplay_p
;
699 #endif /* GLYPH_DEBUG */
701 #ifdef DEBUG_TRACE_MOVE
702 /* Non-zero means trace with TRACE_MOVE to stderr. */
705 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
707 #define TRACE_MOVE(x) (void) 0
710 /* Non-zero means automatically scroll windows horizontally to make
713 int automatic_hscrolling_p
;
714 Lisp_Object Qauto_hscroll_mode
;
716 /* How close to the margin can point get before the window is scrolled
718 EMACS_INT hscroll_margin
;
720 /* How much to scroll horizontally when point is inside the above margin. */
721 Lisp_Object impl_Vhscroll_step
;
723 /* The variable `resize-mini-windows'. If nil, don't resize
724 mini-windows. If t, always resize them to fit the text they
725 display. If `grow-only', let mini-windows grow only until they
728 Lisp_Object impl_Vresize_mini_windows
;
730 /* Buffer being redisplayed -- for redisplay_window_error. */
732 struct buffer
*displayed_buffer
;
734 /* Space between overline and text. */
736 EMACS_INT overline_margin
;
738 /* Require underline to be at least this many screen pixels below baseline
739 This to avoid underline "merging" with the base of letters at small
740 font sizes, particularly when x_use_underline_position_properties is on. */
742 EMACS_INT underline_minimum_offset
;
744 /* Value returned from text property handlers (see below). */
749 HANDLED_RECOMPUTE_PROPS
,
750 HANDLED_OVERLAY_STRING_CONSUMED
,
754 /* A description of text properties that redisplay is interested
759 /* The name of the property. */
762 /* A unique index for the property. */
765 /* A handler function called to set up iterator IT from the property
766 at IT's current position. Value is used to steer handle_stop. */
767 enum prop_handled (*handler
) P_ ((struct it
*it
));
770 static enum prop_handled handle_face_prop
P_ ((struct it
*));
771 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
772 static enum prop_handled handle_display_prop
P_ ((struct it
*));
773 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
774 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
775 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
777 /* Properties handled by iterators. */
779 static struct props it_props
[] =
781 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
782 /* Handle `face' before `display' because some sub-properties of
783 `display' need to know the face. */
784 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
785 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
786 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
787 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
791 /* Value is the position described by X. If X is a marker, value is
792 the marker_position of X. Otherwise, value is X. */
794 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
796 /* Enumeration returned by some move_it_.* functions internally. */
800 /* Not used. Undefined value. */
803 /* Move ended at the requested buffer position or ZV. */
804 MOVE_POS_MATCH_OR_ZV
,
806 /* Move ended at the requested X pixel position. */
809 /* Move within a line ended at the end of a line that must be
813 /* Move within a line ended at the end of a line that would
814 be displayed truncated. */
817 /* Move within a line ended at a line end. */
821 /* This counter is used to clear the face cache every once in a while
822 in redisplay_internal. It is incremented for each redisplay.
823 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
826 #define CLEAR_FACE_CACHE_COUNT 500
827 static int clear_face_cache_count
;
829 /* Similarly for the image cache. */
831 #ifdef HAVE_WINDOW_SYSTEM
832 #define CLEAR_IMAGE_CACHE_COUNT 101
833 static int clear_image_cache_count
;
836 /* Non-zero while redisplay_internal is in progress. */
840 /* Non-zero means don't free realized faces. Bound while freeing
841 realized faces is dangerous because glyph matrices might still
844 int inhibit_free_realized_faces
;
845 Lisp_Object Qinhibit_free_realized_faces
;
847 /* If a string, XTread_socket generates an event to display that string.
848 (The display is done in read_char.) */
850 Lisp_Object help_echo_string
;
851 Lisp_Object help_echo_window
;
852 Lisp_Object help_echo_object
;
855 /* Temporary variable for XTread_socket. */
857 Lisp_Object previous_help_echo_string
;
859 /* Null glyph slice */
861 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
863 /* Platform-independent portion of hourglass implementation. */
865 /* Non-zero means we're allowed to display a hourglass pointer. */
866 int display_hourglass_p
;
868 /* Non-zero means an hourglass cursor is currently shown. */
869 int hourglass_shown_p
;
871 /* If non-null, an asynchronous timer that, when it expires, displays
872 an hourglass cursor on all frames. */
873 struct atimer
*hourglass_atimer
;
875 /* Number of seconds to wait before displaying an hourglass cursor. */
876 Lisp_Object impl_Vhourglass_delay
;
878 /* Default number of seconds to wait before displaying an hourglass
880 #define DEFAULT_HOURGLASS_DELAY 1
883 /* Function prototypes. */
885 static void setup_for_ellipsis
P_ ((struct it
*, int));
886 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
887 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
888 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
889 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
890 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
891 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
893 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
895 static void handle_line_prefix
P_ ((struct it
*));
897 static void pint2str
P_ ((char *, int, int));
898 static void pint2hrstr
P_ ((char *, int, int));
899 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
901 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
902 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
903 static void store_mode_line_noprop_char
P_ ((char));
904 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
905 static void x_consider_frame_title
P_ ((Lisp_Object
));
906 static void handle_stop
P_ ((struct it
*));
907 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
908 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
909 static void ensure_echo_area_buffers
P_ ((void));
910 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
911 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
912 static int with_echo_area_buffer
P_ ((struct window
*, int,
913 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
914 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
915 static void clear_garbaged_frames
P_ ((void));
916 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
918 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int display_echo_area
P_ ((struct window
*));
920 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
921 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
922 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
923 static int string_char_and_length
P_ ((const unsigned char *, int *));
924 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
926 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
927 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
928 static void insert_left_trunc_glyphs
P_ ((struct it
*));
929 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
931 static void extend_face_to_end_of_line
P_ ((struct it
*));
932 static int append_space_for_newline
P_ ((struct it
*, int));
933 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
934 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
935 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
936 static int trailing_whitespace_p
P_ ((int));
937 static int message_log_check_duplicate
P_ ((int, int, int, int));
938 static void push_it
P_ ((struct it
*));
939 static void pop_it
P_ ((struct it
*));
940 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
941 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
942 static void redisplay_internal
P_ ((int));
943 static int echo_area_display
P_ ((int));
944 static void redisplay_windows
P_ ((Lisp_Object
));
945 static void redisplay_window
P_ ((Lisp_Object
, int));
946 static Lisp_Object
redisplay_window_error ();
947 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
948 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
949 static int update_menu_bar
P_ ((struct frame
*, int, int));
950 static int try_window_reusing_current_matrix
P_ ((struct window
*));
951 static int try_window_id
P_ ((struct window
*));
952 static int display_line
P_ ((struct it
*));
953 static int display_mode_lines
P_ ((struct window
*));
954 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
955 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
956 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
957 static char *decode_mode_spec
P_ ((struct window
*, int, int, int,
959 static void display_menu_bar
P_ ((struct window
*));
960 static int display_count_lines
P_ ((int, int, int, int, int *));
961 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
962 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
963 static void compute_line_metrics
P_ ((struct it
*));
964 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
965 static int get_overlay_strings
P_ ((struct it
*, int));
966 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
967 static void next_overlay_string
P_ ((struct it
*));
968 static void reseat
P_ ((struct it
*, struct text_pos
, int));
969 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
970 static void back_to_previous_visible_line_start
P_ ((struct it
*));
971 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
972 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
973 static int next_element_from_ellipsis
P_ ((struct it
*));
974 static int next_element_from_display_vector
P_ ((struct it
*));
975 static int next_element_from_string
P_ ((struct it
*));
976 static int next_element_from_c_string
P_ ((struct it
*));
977 static int next_element_from_buffer
P_ ((struct it
*));
978 static int next_element_from_composition
P_ ((struct it
*));
979 static int next_element_from_image
P_ ((struct it
*));
980 static int next_element_from_stretch
P_ ((struct it
*));
981 static void load_overlay_strings
P_ ((struct it
*, int));
982 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
983 struct display_pos
*));
984 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
985 Lisp_Object
, int, int, int, int));
986 static enum move_it_result
987 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
988 enum move_operation_enum
);
989 void move_it_vertically_backward
P_ ((struct it
*, int));
990 static void init_to_row_start
P_ ((struct it
*, struct window
*,
991 struct glyph_row
*));
992 static int init_to_row_end
P_ ((struct it
*, struct window
*,
993 struct glyph_row
*));
994 static void back_to_previous_line_start
P_ ((struct it
*));
995 static int forward_to_next_line_start
P_ ((struct it
*, int *));
996 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
998 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
999 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
1000 static int number_of_chars
P_ ((unsigned char *, int));
1001 static void compute_stop_pos
P_ ((struct it
*));
1002 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1004 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1005 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1006 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1007 Lisp_Object
, Lisp_Object
,
1008 struct text_pos
*, int));
1009 static int underlying_face_id
P_ ((struct it
*));
1010 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1013 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1014 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1016 #ifdef HAVE_WINDOW_SYSTEM
1018 static void update_tool_bar
P_ ((struct frame
*, int));
1019 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1020 static int redisplay_tool_bar
P_ ((struct frame
*));
1021 static void display_tool_bar_line
P_ ((struct it
*, int));
1022 static void notice_overwritten_cursor
P_ ((struct window
*,
1023 enum glyph_row_area
,
1024 int, int, int, int));
1028 #endif /* HAVE_WINDOW_SYSTEM */
1031 /***********************************************************************
1032 Window display dimensions
1033 ***********************************************************************/
1035 /* Return the bottom boundary y-position for text lines in window W.
1036 This is the first y position at which a line cannot start.
1037 It is relative to the top of the window.
1039 This is the height of W minus the height of a mode line, if any. */
1042 window_text_bottom_y (w
)
1045 int height
= WINDOW_TOTAL_HEIGHT (w
);
1047 if (WINDOW_WANTS_MODELINE_P (w
))
1048 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1052 /* Return the pixel width of display area AREA of window W. AREA < 0
1053 means return the total width of W, not including fringes to
1054 the left and right of the window. */
1057 window_box_width (w
, area
)
1061 int cols
= XFASTINT (w
->total_cols
);
1064 if (!w
->pseudo_window_p
)
1066 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1068 if (area
== TEXT_AREA
)
1070 if (INTEGERP (w
->left_margin_cols
))
1071 cols
-= XFASTINT (w
->left_margin_cols
);
1072 if (INTEGERP (w
->right_margin_cols
))
1073 cols
-= XFASTINT (w
->right_margin_cols
);
1074 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1076 else if (area
== LEFT_MARGIN_AREA
)
1078 cols
= (INTEGERP (w
->left_margin_cols
)
1079 ? XFASTINT (w
->left_margin_cols
) : 0);
1082 else if (area
== RIGHT_MARGIN_AREA
)
1084 cols
= (INTEGERP (w
->right_margin_cols
)
1085 ? XFASTINT (w
->right_margin_cols
) : 0);
1090 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1094 /* Return the pixel height of the display area of window W, not
1095 including mode lines of W, if any. */
1098 window_box_height (w
)
1101 struct frame
*f
= XFRAME (w
->frame
);
1102 int height
= WINDOW_TOTAL_HEIGHT (w
);
1104 xassert (height
>= 0);
1106 /* Note: the code below that determines the mode-line/header-line
1107 height is essentially the same as that contained in the macro
1108 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1109 the appropriate glyph row has its `mode_line_p' flag set,
1110 and if it doesn't, uses estimate_mode_line_height instead. */
1112 if (WINDOW_WANTS_MODELINE_P (w
))
1114 struct glyph_row
*ml_row
1115 = (w
->current_matrix
&& w
->current_matrix
->rows
1116 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1118 if (ml_row
&& ml_row
->mode_line_p
)
1119 height
-= ml_row
->height
;
1121 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1124 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1126 struct glyph_row
*hl_row
1127 = (w
->current_matrix
&& w
->current_matrix
->rows
1128 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1130 if (hl_row
&& hl_row
->mode_line_p
)
1131 height
-= hl_row
->height
;
1133 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1136 /* With a very small font and a mode-line that's taller than
1137 default, we might end up with a negative height. */
1138 return max (0, height
);
1141 /* Return the window-relative coordinate of the left edge of display
1142 area AREA of window W. AREA < 0 means return the left edge of the
1143 whole window, to the right of the left fringe of W. */
1146 window_box_left_offset (w
, area
)
1152 if (w
->pseudo_window_p
)
1155 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1157 if (area
== TEXT_AREA
)
1158 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1159 + window_box_width (w
, LEFT_MARGIN_AREA
));
1160 else if (area
== RIGHT_MARGIN_AREA
)
1161 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1162 + window_box_width (w
, LEFT_MARGIN_AREA
)
1163 + window_box_width (w
, TEXT_AREA
)
1164 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1166 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1167 else if (area
== LEFT_MARGIN_AREA
1168 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1169 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1175 /* Return the window-relative coordinate of the right edge of display
1176 area AREA of window W. AREA < 0 means return the left edge of the
1177 whole window, to the left of the right fringe of W. */
1180 window_box_right_offset (w
, area
)
1184 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1187 /* Return the frame-relative coordinate of the left edge of display
1188 area AREA of window W. AREA < 0 means return the left edge of the
1189 whole window, to the right of the left fringe of W. */
1192 window_box_left (w
, area
)
1196 struct frame
*f
= XFRAME (w
->frame
);
1199 if (w
->pseudo_window_p
)
1200 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1202 x
= (WINDOW_LEFT_EDGE_X (w
)
1203 + window_box_left_offset (w
, area
));
1209 /* Return the frame-relative coordinate of the right edge of display
1210 area AREA of window W. AREA < 0 means return the left edge of the
1211 whole window, to the left of the right fringe of W. */
1214 window_box_right (w
, area
)
1218 return window_box_left (w
, area
) + window_box_width (w
, area
);
1221 /* Get the bounding box of the display area AREA of window W, without
1222 mode lines, in frame-relative coordinates. AREA < 0 means the
1223 whole window, not including the left and right fringes of
1224 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1225 coordinates of the upper-left corner of the box. Return in
1226 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1229 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1232 int *box_x
, *box_y
, *box_width
, *box_height
;
1235 *box_width
= window_box_width (w
, area
);
1237 *box_height
= window_box_height (w
);
1239 *box_x
= window_box_left (w
, area
);
1242 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1243 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1244 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1249 /* Get the bounding box of the display area AREA of window W, without
1250 mode lines. AREA < 0 means the whole window, not including the
1251 left and right fringe of the window. Return in *TOP_LEFT_X
1252 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1253 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1254 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1258 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1259 bottom_right_x
, bottom_right_y
)
1262 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1264 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1266 *bottom_right_x
+= *top_left_x
;
1267 *bottom_right_y
+= *top_left_y
;
1272 /***********************************************************************
1274 ***********************************************************************/
1276 /* Return the bottom y-position of the line the iterator IT is in.
1277 This can modify IT's settings. */
1283 int line_height
= it
->max_ascent
+ it
->max_descent
;
1284 int line_top_y
= it
->current_y
;
1286 if (line_height
== 0)
1289 line_height
= last_height
;
1290 else if (IT_CHARPOS (*it
) < ZV
)
1292 move_it_by_lines (it
, 1, 1);
1293 line_height
= (it
->max_ascent
|| it
->max_descent
1294 ? it
->max_ascent
+ it
->max_descent
1299 struct glyph_row
*row
= it
->glyph_row
;
1301 /* Use the default character height. */
1302 it
->glyph_row
= NULL
;
1303 it
->what
= IT_CHARACTER
;
1306 PRODUCE_GLYPHS (it
);
1307 line_height
= it
->ascent
+ it
->descent
;
1308 it
->glyph_row
= row
;
1312 return line_top_y
+ line_height
;
1316 /* Return 1 if position CHARPOS is visible in window W.
1317 CHARPOS < 0 means return info about WINDOW_END position.
1318 If visible, set *X and *Y to pixel coordinates of top left corner.
1319 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1320 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1323 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1325 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1328 struct text_pos top
;
1330 struct buffer
*old_buffer
= NULL
;
1332 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1335 if (XBUFFER (w
->buffer
) != current_buffer
)
1337 old_buffer
= current_buffer
;
1338 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1341 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1343 /* Compute exact mode line heights. */
1344 if (WINDOW_WANTS_MODELINE_P (w
))
1345 current_mode_line_height
1346 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1347 current_buffer
->mode_line_format
);
1349 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1350 current_header_line_height
1351 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1352 current_buffer
->header_line_format
);
1354 start_display (&it
, w
, top
);
1355 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1356 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1358 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1360 /* We have reached CHARPOS, or passed it. How the call to
1361 move_it_to can overshoot: (i) If CHARPOS is on invisible
1362 text, move_it_to stops at the end of the invisible text,
1363 after CHARPOS. (ii) If CHARPOS is in a display vector,
1364 move_it_to stops on its last glyph. */
1365 int top_x
= it
.current_x
;
1366 int top_y
= it
.current_y
;
1367 enum it_method it_method
= it
.method
;
1368 /* Calling line_bottom_y may change it.method, it.position, etc. */
1369 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1370 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1372 if (top_y
< window_top_y
)
1373 visible_p
= bottom_y
> window_top_y
;
1374 else if (top_y
< it
.last_visible_y
)
1378 if (it_method
== GET_FROM_BUFFER
)
1380 Lisp_Object window
, prop
;
1382 XSETWINDOW (window
, w
);
1383 prop
= Fget_char_property (make_number (charpos
),
1384 Qinvisible
, window
);
1386 /* If charpos coincides with invisible text covered with an
1387 ellipsis, use the first glyph of the ellipsis to compute
1388 the pixel positions. */
1389 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1391 struct glyph_row
*row
= it
.glyph_row
;
1392 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1393 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1397 && (!BUFFERP (glyph
->object
)
1398 || glyph
->charpos
< charpos
);
1400 x
+= glyph
->pixel_width
;
1404 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1406 /* We stopped on the last glyph of a display vector.
1407 Try and recompute. Hack alert! */
1408 if (charpos
< 2 || top
.charpos
>= charpos
)
1409 top_x
= it
.glyph_row
->x
;
1413 start_display (&it2
, w
, top
);
1414 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1415 get_next_display_element (&it2
);
1416 PRODUCE_GLYPHS (&it2
);
1417 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1418 || it2
.current_x
> it2
.last_visible_x
)
1419 top_x
= it
.glyph_row
->x
;
1422 top_x
= it2
.current_x
;
1423 top_y
= it2
.current_y
;
1429 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1430 *rtop
= max (0, window_top_y
- top_y
);
1431 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1432 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1433 - max (top_y
, window_top_y
)));
1442 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1443 move_it_by_lines (&it
, 1, 0);
1444 if (charpos
< IT_CHARPOS (it
)
1445 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1448 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1450 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1451 *rtop
= max (0, -it2
.current_y
);
1452 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1453 - it
.last_visible_y
));
1454 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1456 - max (it2
.current_y
,
1457 WINDOW_HEADER_LINE_HEIGHT (w
))));
1463 set_buffer_internal_1 (old_buffer
);
1465 current_header_line_height
= current_mode_line_height
= -1;
1467 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1468 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1471 /* Debugging code. */
1473 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1474 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1476 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1483 /* Return the next character from STR which is MAXLEN bytes long.
1484 Return in *LEN the length of the character. This is like
1485 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1486 we find one, we return a `?', but with the length of the invalid
1490 string_char_and_length (str
, len
)
1491 const unsigned char *str
;
1496 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1497 if (!CHAR_VALID_P (c
, 1))
1498 /* We may not change the length here because other places in Emacs
1499 don't use this function, i.e. they silently accept invalid
1508 /* Given a position POS containing a valid character and byte position
1509 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1511 static struct text_pos
1512 string_pos_nchars_ahead (pos
, string
, nchars
)
1513 struct text_pos pos
;
1517 xassert (STRINGP (string
) && nchars
>= 0);
1519 if (STRING_MULTIBYTE (string
))
1521 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1522 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1527 string_char_and_length (p
, &len
);
1528 p
+= len
, rest
-= len
;
1529 xassert (rest
>= 0);
1531 BYTEPOS (pos
) += len
;
1535 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1541 /* Value is the text position, i.e. character and byte position,
1542 for character position CHARPOS in STRING. */
1544 static INLINE
struct text_pos
1545 string_pos (charpos
, string
)
1549 struct text_pos pos
;
1550 xassert (STRINGP (string
));
1551 xassert (charpos
>= 0);
1552 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1557 /* Value is a text position, i.e. character and byte position, for
1558 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1559 means recognize multibyte characters. */
1561 static struct text_pos
1562 c_string_pos (charpos
, s
, multibyte_p
)
1567 struct text_pos pos
;
1569 xassert (s
!= NULL
);
1570 xassert (charpos
>= 0);
1574 int rest
= strlen (s
), len
;
1576 SET_TEXT_POS (pos
, 0, 0);
1579 string_char_and_length (s
, &len
);
1580 s
+= len
, rest
-= len
;
1581 xassert (rest
>= 0);
1583 BYTEPOS (pos
) += len
;
1587 SET_TEXT_POS (pos
, charpos
, charpos
);
1593 /* Value is the number of characters in C string S. MULTIBYTE_P
1594 non-zero means recognize multibyte characters. */
1597 number_of_chars (s
, multibyte_p
)
1605 int rest
= strlen (s
), len
;
1606 unsigned char *p
= (unsigned char *) s
;
1608 for (nchars
= 0; rest
> 0; ++nchars
)
1610 string_char_and_length (p
, &len
);
1611 rest
-= len
, p
+= len
;
1615 nchars
= strlen (s
);
1621 /* Compute byte position NEWPOS->bytepos corresponding to
1622 NEWPOS->charpos. POS is a known position in string STRING.
1623 NEWPOS->charpos must be >= POS.charpos. */
1626 compute_string_pos (newpos
, pos
, string
)
1627 struct text_pos
*newpos
, pos
;
1630 xassert (STRINGP (string
));
1631 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1633 if (STRING_MULTIBYTE (string
))
1634 *newpos
= string_pos_nchars_ahead (pos
, string
,
1635 CHARPOS (*newpos
) - CHARPOS (pos
));
1637 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1641 Return an estimation of the pixel height of mode or header lines on
1642 frame F. FACE_ID specifies what line's height to estimate. */
1645 estimate_mode_line_height (f
, face_id
)
1647 enum face_id face_id
;
1649 #ifdef HAVE_WINDOW_SYSTEM
1650 if (FRAME_WINDOW_P (f
))
1652 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1654 /* This function is called so early when Emacs starts that the face
1655 cache and mode line face are not yet initialized. */
1656 if (FRAME_FACE_CACHE (f
))
1658 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1662 height
= FONT_HEIGHT (face
->font
);
1663 if (face
->box_line_width
> 0)
1664 height
+= 2 * face
->box_line_width
;
1675 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1676 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1677 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1678 not force the value into range. */
1681 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1683 register int pix_x
, pix_y
;
1685 NativeRectangle
*bounds
;
1689 #ifdef HAVE_WINDOW_SYSTEM
1690 if (FRAME_WINDOW_P (f
))
1692 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1693 even for negative values. */
1695 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1697 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1699 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1700 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1703 STORE_NATIVE_RECT (*bounds
,
1704 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1705 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1706 FRAME_COLUMN_WIDTH (f
) - 1,
1707 FRAME_LINE_HEIGHT (f
) - 1);
1713 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1714 pix_x
= FRAME_TOTAL_COLS (f
);
1718 else if (pix_y
> FRAME_LINES (f
))
1719 pix_y
= FRAME_LINES (f
);
1729 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1730 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1731 can't tell the positions because W's display is not up to date,
1735 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1738 int *frame_x
, *frame_y
;
1740 #ifdef HAVE_WINDOW_SYSTEM
1741 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1745 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1746 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1748 if (display_completed
)
1750 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1751 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1752 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1758 hpos
+= glyph
->pixel_width
;
1762 /* If first glyph is partially visible, its first visible position is still 0. */
1774 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1775 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1786 #ifdef HAVE_WINDOW_SYSTEM
1788 /* Find the glyph under window-relative coordinates X/Y in window W.
1789 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1790 strings. Return in *HPOS and *VPOS the row and column number of
1791 the glyph found. Return in *AREA the glyph area containing X.
1792 Value is a pointer to the glyph found or null if X/Y is not on
1793 text, or we can't tell because W's current matrix is not up to
1798 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1801 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1803 struct glyph
*glyph
, *end
;
1804 struct glyph_row
*row
= NULL
;
1807 /* Find row containing Y. Give up if some row is not enabled. */
1808 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1810 row
= MATRIX_ROW (w
->current_matrix
, i
);
1811 if (!row
->enabled_p
)
1813 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1820 /* Give up if Y is not in the window. */
1821 if (i
== w
->current_matrix
->nrows
)
1824 /* Get the glyph area containing X. */
1825 if (w
->pseudo_window_p
)
1832 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1834 *area
= LEFT_MARGIN_AREA
;
1835 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1837 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1840 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1844 *area
= RIGHT_MARGIN_AREA
;
1845 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1849 /* Find glyph containing X. */
1850 glyph
= row
->glyphs
[*area
];
1851 end
= glyph
+ row
->used
[*area
];
1853 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1855 x
-= glyph
->pixel_width
;
1865 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1868 *hpos
= glyph
- row
->glyphs
[*area
];
1874 Convert frame-relative x/y to coordinates relative to window W.
1875 Takes pseudo-windows into account. */
1878 frame_to_window_pixel_xy (w
, x
, y
)
1882 if (w
->pseudo_window_p
)
1884 /* A pseudo-window is always full-width, and starts at the
1885 left edge of the frame, plus a frame border. */
1886 struct frame
*f
= XFRAME (w
->frame
);
1887 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1888 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1892 *x
-= WINDOW_LEFT_EDGE_X (w
);
1893 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1898 Return in RECTS[] at most N clipping rectangles for glyph string S.
1899 Return the number of stored rectangles. */
1902 get_glyph_string_clip_rects (s
, rects
, n
)
1903 struct glyph_string
*s
;
1904 NativeRectangle
*rects
;
1912 if (s
->row
->full_width_p
)
1914 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1915 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1916 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1918 /* Unless displaying a mode or menu bar line, which are always
1919 fully visible, clip to the visible part of the row. */
1920 if (s
->w
->pseudo_window_p
)
1921 r
.height
= s
->row
->visible_height
;
1923 r
.height
= s
->height
;
1927 /* This is a text line that may be partially visible. */
1928 r
.x
= window_box_left (s
->w
, s
->area
);
1929 r
.width
= window_box_width (s
->w
, s
->area
);
1930 r
.height
= s
->row
->visible_height
;
1934 if (r
.x
< s
->clip_head
->x
)
1936 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1937 r
.width
-= s
->clip_head
->x
- r
.x
;
1940 r
.x
= s
->clip_head
->x
;
1943 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1945 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1946 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1951 /* If S draws overlapping rows, it's sufficient to use the top and
1952 bottom of the window for clipping because this glyph string
1953 intentionally draws over other lines. */
1954 if (s
->for_overlaps
)
1956 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1957 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1959 /* Alas, the above simple strategy does not work for the
1960 environments with anti-aliased text: if the same text is
1961 drawn onto the same place multiple times, it gets thicker.
1962 If the overlap we are processing is for the erased cursor, we
1963 take the intersection with the rectagle of the cursor. */
1964 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1966 XRectangle rc
, r_save
= r
;
1968 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1969 rc
.y
= s
->w
->phys_cursor
.y
;
1970 rc
.width
= s
->w
->phys_cursor_width
;
1971 rc
.height
= s
->w
->phys_cursor_height
;
1973 x_intersect_rectangles (&r_save
, &rc
, &r
);
1978 /* Don't use S->y for clipping because it doesn't take partially
1979 visible lines into account. For example, it can be negative for
1980 partially visible lines at the top of a window. */
1981 if (!s
->row
->full_width_p
1982 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1983 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1985 r
.y
= max (0, s
->row
->y
);
1988 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1990 /* If drawing the cursor, don't let glyph draw outside its
1991 advertised boundaries. Cleartype does this under some circumstances. */
1992 if (s
->hl
== DRAW_CURSOR
)
1994 struct glyph
*glyph
= s
->first_glyph
;
1999 r
.width
-= s
->x
- r
.x
;
2002 r
.width
= min (r
.width
, glyph
->pixel_width
);
2004 /* If r.y is below window bottom, ensure that we still see a cursor. */
2005 height
= min (glyph
->ascent
+ glyph
->descent
,
2006 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2007 max_y
= window_text_bottom_y (s
->w
) - height
;
2008 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2009 if (s
->ybase
- glyph
->ascent
> max_y
)
2016 /* Don't draw cursor glyph taller than our actual glyph. */
2017 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2018 if (height
< r
.height
)
2020 max_y
= r
.y
+ r
.height
;
2021 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2022 r
.height
= min (max_y
- r
.y
, height
);
2029 XRectangle r_save
= r
;
2031 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2035 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2036 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2038 #ifdef CONVERT_FROM_XRECT
2039 CONVERT_FROM_XRECT (r
, *rects
);
2047 /* If we are processing overlapping and allowed to return
2048 multiple clipping rectangles, we exclude the row of the glyph
2049 string from the clipping rectangle. This is to avoid drawing
2050 the same text on the environment with anti-aliasing. */
2051 #ifdef CONVERT_FROM_XRECT
2054 XRectangle
*rs
= rects
;
2056 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2058 if (s
->for_overlaps
& OVERLAPS_PRED
)
2061 if (r
.y
+ r
.height
> row_y
)
2064 rs
[i
].height
= row_y
- r
.y
;
2070 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2073 if (r
.y
< row_y
+ s
->row
->visible_height
)
2075 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2077 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2078 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2087 #ifdef CONVERT_FROM_XRECT
2088 for (i
= 0; i
< n
; i
++)
2089 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2096 Return in *NR the clipping rectangle for glyph string S. */
2099 get_glyph_string_clip_rect (s
, nr
)
2100 struct glyph_string
*s
;
2101 NativeRectangle
*nr
;
2103 get_glyph_string_clip_rects (s
, nr
, 1);
2108 Return the position and height of the phys cursor in window W.
2109 Set w->phys_cursor_width to width of phys cursor.
2113 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2115 struct glyph_row
*row
;
2116 struct glyph
*glyph
;
2117 int *xp
, *yp
, *heightp
;
2119 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2120 int x
, y
, wd
, h
, h0
, y0
;
2122 /* Compute the width of the rectangle to draw. If on a stretch
2123 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2124 rectangle as wide as the glyph, but use a canonical character
2126 wd
= glyph
->pixel_width
- 1;
2127 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2131 x
= w
->phys_cursor
.x
;
2138 if (glyph
->type
== STRETCH_GLYPH
2139 && !x_stretch_cursor_p
)
2140 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2141 w
->phys_cursor_width
= wd
;
2143 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2145 /* If y is below window bottom, ensure that we still see a cursor. */
2146 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2148 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2149 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2151 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2154 h
= max (h
- (y0
- y
) + 1, h0
);
2159 y0
= window_text_bottom_y (w
) - h0
;
2167 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2168 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2173 * Remember which glyph the mouse is over.
2177 remember_mouse_glyph (f
, gx
, gy
, rect
)
2180 NativeRectangle
*rect
;
2184 struct glyph_row
*r
, *gr
, *end_row
;
2185 enum window_part part
;
2186 enum glyph_row_area area
;
2187 int x
, y
, width
, height
;
2189 /* Try to determine frame pixel position and size of the glyph under
2190 frame pixel coordinates X/Y on frame F. */
2192 if (!f
->glyphs_initialized_p
2193 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2196 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2197 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2201 w
= XWINDOW (window
);
2202 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2203 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2205 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2206 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2208 if (w
->pseudo_window_p
)
2211 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2217 case ON_LEFT_MARGIN
:
2218 area
= LEFT_MARGIN_AREA
;
2221 case ON_RIGHT_MARGIN
:
2222 area
= RIGHT_MARGIN_AREA
;
2225 case ON_HEADER_LINE
:
2227 gr
= (part
== ON_HEADER_LINE
2228 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2229 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2232 goto text_glyph_row_found
;
2239 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2240 if (r
->y
+ r
->height
> y
)
2246 text_glyph_row_found
:
2249 struct glyph
*g
= gr
->glyphs
[area
];
2250 struct glyph
*end
= g
+ gr
->used
[area
];
2252 height
= gr
->height
;
2253 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2254 if (gx
+ g
->pixel_width
> x
)
2259 if (g
->type
== IMAGE_GLYPH
)
2261 /* Don't remember when mouse is over image, as
2262 image may have hot-spots. */
2263 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2266 width
= g
->pixel_width
;
2270 /* Use nominal char spacing at end of line. */
2272 gx
+= (x
/ width
) * width
;
2275 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2276 gx
+= window_box_left_offset (w
, area
);
2280 /* Use nominal line height at end of window. */
2281 gx
= (x
/ width
) * width
;
2283 gy
+= (y
/ height
) * height
;
2287 case ON_LEFT_FRINGE
:
2288 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2289 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2290 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2291 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2294 case ON_RIGHT_FRINGE
:
2295 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2296 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2297 : window_box_right_offset (w
, TEXT_AREA
));
2298 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2302 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2304 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2305 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2306 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2308 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2312 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2313 if (r
->y
+ r
->height
> y
)
2320 height
= gr
->height
;
2323 /* Use nominal line height at end of window. */
2325 gy
+= (y
/ height
) * height
;
2332 /* If there is no glyph under the mouse, then we divide the screen
2333 into a grid of the smallest glyph in the frame, and use that
2336 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2337 round down even for negative values. */
2343 gx
= (gx
/ width
) * width
;
2344 gy
= (gy
/ height
) * height
;
2349 gx
+= WINDOW_LEFT_EDGE_X (w
);
2350 gy
+= WINDOW_TOP_EDGE_Y (w
);
2353 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2355 /* Visible feedback for debugging. */
2358 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2359 f
->output_data
.x
->normal_gc
,
2360 gx
, gy
, width
, height
);
2366 #endif /* HAVE_WINDOW_SYSTEM */
2369 /***********************************************************************
2370 Lisp form evaluation
2371 ***********************************************************************/
2373 /* Error handler for safe_eval and safe_call. */
2376 safe_eval_handler (arg
)
2379 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2384 /* Evaluate SEXPR and return the result, or nil if something went
2385 wrong. Prevent redisplay during the evaluation. */
2387 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2388 Return the result, or nil if something went wrong. Prevent
2389 redisplay during the evaluation. */
2392 safe_call (nargs
, args
)
2398 if (inhibit_eval_during_redisplay
)
2402 int count
= SPECPDL_INDEX ();
2403 struct gcpro gcpro1
;
2406 gcpro1
.nvars
= nargs
;
2407 specbind (Qinhibit_redisplay
, Qt
);
2408 /* Use Qt to ensure debugger does not run,
2409 so there is no possibility of wanting to redisplay. */
2410 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2413 val
= unbind_to (count
, val
);
2420 /* Call function FN with one argument ARG.
2421 Return the result, or nil if something went wrong. */
2424 safe_call1 (fn
, arg
)
2425 Lisp_Object fn
, arg
;
2427 Lisp_Object args
[2];
2430 return safe_call (2, args
);
2433 static Lisp_Object Qeval
;
2436 safe_eval (Lisp_Object sexpr
)
2438 return safe_call1 (Qeval
, sexpr
);
2441 /* Call function FN with one argument ARG.
2442 Return the result, or nil if something went wrong. */
2445 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2447 Lisp_Object args
[3];
2451 return safe_call (3, args
);
2456 /***********************************************************************
2458 ***********************************************************************/
2462 /* Define CHECK_IT to perform sanity checks on iterators.
2463 This is for debugging. It is too slow to do unconditionally. */
2469 if (it
->method
== GET_FROM_STRING
)
2471 xassert (STRINGP (it
->string
));
2472 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2476 xassert (IT_STRING_CHARPOS (*it
) < 0);
2477 if (it
->method
== GET_FROM_BUFFER
)
2479 /* Check that character and byte positions agree. */
2480 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2485 xassert (it
->current
.dpvec_index
>= 0);
2487 xassert (it
->current
.dpvec_index
< 0);
2490 #define CHECK_IT(IT) check_it ((IT))
2494 #define CHECK_IT(IT) (void) 0
2501 /* Check that the window end of window W is what we expect it
2502 to be---the last row in the current matrix displaying text. */
2505 check_window_end (w
)
2508 if (!MINI_WINDOW_P (w
)
2509 && !NILP (w
->window_end_valid
))
2511 struct glyph_row
*row
;
2512 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2513 XFASTINT (w
->window_end_vpos
)),
2515 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2516 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2520 #define CHECK_WINDOW_END(W) check_window_end ((W))
2522 #else /* not GLYPH_DEBUG */
2524 #define CHECK_WINDOW_END(W) (void) 0
2526 #endif /* not GLYPH_DEBUG */
2530 /***********************************************************************
2531 Iterator initialization
2532 ***********************************************************************/
2534 /* Initialize IT for displaying current_buffer in window W, starting
2535 at character position CHARPOS. CHARPOS < 0 means that no buffer
2536 position is specified which is useful when the iterator is assigned
2537 a position later. BYTEPOS is the byte position corresponding to
2538 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2540 If ROW is not null, calls to produce_glyphs with IT as parameter
2541 will produce glyphs in that row.
2543 BASE_FACE_ID is the id of a base face to use. It must be one of
2544 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2545 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2546 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2548 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2549 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2550 will be initialized to use the corresponding mode line glyph row of
2551 the desired matrix of W. */
2554 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2557 int charpos
, bytepos
;
2558 struct glyph_row
*row
;
2559 enum face_id base_face_id
;
2561 int highlight_region_p
;
2562 enum face_id remapped_base_face_id
= base_face_id
;
2564 /* Some precondition checks. */
2565 xassert (w
!= NULL
&& it
!= NULL
);
2566 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2569 /* If face attributes have been changed since the last redisplay,
2570 free realized faces now because they depend on face definitions
2571 that might have changed. Don't free faces while there might be
2572 desired matrices pending which reference these faces. */
2573 if (face_change_count
&& !inhibit_free_realized_faces
)
2575 face_change_count
= 0;
2576 free_all_realized_faces (Qnil
);
2579 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2580 if (! NILP (Vface_remapping_alist
))
2581 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2583 /* Use one of the mode line rows of W's desired matrix if
2587 if (base_face_id
== MODE_LINE_FACE_ID
2588 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2589 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2590 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2591 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2595 bzero (it
, sizeof *it
);
2596 it
->current
.overlay_string_index
= -1;
2597 it
->current
.dpvec_index
= -1;
2598 it
->base_face_id
= remapped_base_face_id
;
2600 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2602 /* The window in which we iterate over current_buffer: */
2603 XSETWINDOW (it
->window
, w
);
2605 it
->f
= XFRAME (w
->frame
);
2609 /* Extra space between lines (on window systems only). */
2610 if (base_face_id
== DEFAULT_FACE_ID
2611 && FRAME_WINDOW_P (it
->f
))
2613 if (NATNUMP (current_buffer
->extra_line_spacing
))
2614 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2615 else if (FLOATP (current_buffer
->extra_line_spacing
))
2616 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2617 * FRAME_LINE_HEIGHT (it
->f
));
2618 else if (it
->f
->extra_line_spacing
> 0)
2619 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2620 it
->max_extra_line_spacing
= 0;
2623 /* If realized faces have been removed, e.g. because of face
2624 attribute changes of named faces, recompute them. When running
2625 in batch mode, the face cache of the initial frame is null. If
2626 we happen to get called, make a dummy face cache. */
2627 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2628 init_frame_faces (it
->f
);
2629 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2630 recompute_basic_faces (it
->f
);
2632 /* Current value of the `slice', `space-width', and 'height' properties. */
2633 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2634 it
->space_width
= Qnil
;
2635 it
->font_height
= Qnil
;
2636 it
->override_ascent
= -1;
2638 /* Are control characters displayed as `^C'? */
2639 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2641 /* -1 means everything between a CR and the following line end
2642 is invisible. >0 means lines indented more than this value are
2644 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2645 ? XFASTINT (current_buffer
->selective_display
)
2646 : (!NILP (current_buffer
->selective_display
)
2648 it
->selective_display_ellipsis_p
2649 = !NILP (current_buffer
->selective_display_ellipses
);
2651 /* Display table to use. */
2652 it
->dp
= window_display_table (w
);
2654 /* Are multibyte characters enabled in current_buffer? */
2655 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2657 /* Non-zero if we should highlight the region. */
2659 = (!NILP (Vtransient_mark_mode
)
2660 && !NILP (current_buffer
->mark_active
)
2661 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2663 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2664 start and end of a visible region in window IT->w. Set both to
2665 -1 to indicate no region. */
2666 if (highlight_region_p
2667 /* Maybe highlight only in selected window. */
2668 && (/* Either show region everywhere. */
2669 highlight_nonselected_windows
2670 /* Or show region in the selected window. */
2671 || w
== XWINDOW (selected_window
)
2672 /* Or show the region if we are in the mini-buffer and W is
2673 the window the mini-buffer refers to. */
2674 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2675 && WINDOWP (minibuf_selected_window
)
2676 && w
== XWINDOW (minibuf_selected_window
))))
2678 int charpos
= marker_position (current_buffer
->mark
);
2679 it
->region_beg_charpos
= min (PT
, charpos
);
2680 it
->region_end_charpos
= max (PT
, charpos
);
2683 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2685 /* Get the position at which the redisplay_end_trigger hook should
2686 be run, if it is to be run at all. */
2687 if (MARKERP (w
->redisplay_end_trigger
)
2688 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2689 it
->redisplay_end_trigger_charpos
2690 = marker_position (w
->redisplay_end_trigger
);
2691 else if (INTEGERP (w
->redisplay_end_trigger
))
2692 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2694 /* Correct bogus values of tab_width. */
2695 it
->tab_width
= XINT (current_buffer
->tab_width
);
2696 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2699 /* Are lines in the display truncated? */
2700 if (base_face_id
!= DEFAULT_FACE_ID
2701 || XINT (it
->w
->hscroll
)
2702 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2703 && ((!NILP (Vtruncate_partial_width_windows
)
2704 && !INTEGERP (Vtruncate_partial_width_windows
))
2705 || (INTEGERP (Vtruncate_partial_width_windows
)
2706 && (WINDOW_TOTAL_COLS (it
->w
)
2707 < XINT (Vtruncate_partial_width_windows
))))))
2708 it
->line_wrap
= TRUNCATE
;
2709 else if (NILP (current_buffer
->truncate_lines
))
2710 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2711 ? WINDOW_WRAP
: WORD_WRAP
;
2713 it
->line_wrap
= TRUNCATE
;
2715 /* Get dimensions of truncation and continuation glyphs. These are
2716 displayed as fringe bitmaps under X, so we don't need them for such
2718 if (!FRAME_WINDOW_P (it
->f
))
2720 if (it
->line_wrap
== TRUNCATE
)
2722 /* We will need the truncation glyph. */
2723 xassert (it
->glyph_row
== NULL
);
2724 produce_special_glyphs (it
, IT_TRUNCATION
);
2725 it
->truncation_pixel_width
= it
->pixel_width
;
2729 /* We will need the continuation glyph. */
2730 xassert (it
->glyph_row
== NULL
);
2731 produce_special_glyphs (it
, IT_CONTINUATION
);
2732 it
->continuation_pixel_width
= it
->pixel_width
;
2735 /* Reset these values to zero because the produce_special_glyphs
2736 above has changed them. */
2737 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2738 it
->phys_ascent
= it
->phys_descent
= 0;
2741 /* Set this after getting the dimensions of truncation and
2742 continuation glyphs, so that we don't produce glyphs when calling
2743 produce_special_glyphs, above. */
2744 it
->glyph_row
= row
;
2745 it
->area
= TEXT_AREA
;
2747 /* Get the dimensions of the display area. The display area
2748 consists of the visible window area plus a horizontally scrolled
2749 part to the left of the window. All x-values are relative to the
2750 start of this total display area. */
2751 if (base_face_id
!= DEFAULT_FACE_ID
)
2753 /* Mode lines, menu bar in terminal frames. */
2754 it
->first_visible_x
= 0;
2755 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2760 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2761 it
->last_visible_x
= (it
->first_visible_x
2762 + window_box_width (w
, TEXT_AREA
));
2764 /* If we truncate lines, leave room for the truncator glyph(s) at
2765 the right margin. Otherwise, leave room for the continuation
2766 glyph(s). Truncation and continuation glyphs are not inserted
2767 for window-based redisplay. */
2768 if (!FRAME_WINDOW_P (it
->f
))
2770 if (it
->line_wrap
== TRUNCATE
)
2771 it
->last_visible_x
-= it
->truncation_pixel_width
;
2773 it
->last_visible_x
-= it
->continuation_pixel_width
;
2776 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2777 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2780 /* Leave room for a border glyph. */
2781 if (!FRAME_WINDOW_P (it
->f
)
2782 && !WINDOW_RIGHTMOST_P (it
->w
))
2783 it
->last_visible_x
-= 1;
2785 it
->last_visible_y
= window_text_bottom_y (w
);
2787 /* For mode lines and alike, arrange for the first glyph having a
2788 left box line if the face specifies a box. */
2789 if (base_face_id
!= DEFAULT_FACE_ID
)
2793 it
->face_id
= remapped_base_face_id
;
2795 /* If we have a boxed mode line, make the first character appear
2796 with a left box line. */
2797 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2798 if (face
->box
!= FACE_NO_BOX
)
2799 it
->start_of_box_run_p
= 1;
2802 /* If a buffer position was specified, set the iterator there,
2803 getting overlays and face properties from that position. */
2804 if (charpos
>= BUF_BEG (current_buffer
))
2806 it
->end_charpos
= ZV
;
2808 IT_CHARPOS (*it
) = charpos
;
2810 /* Compute byte position if not specified. */
2811 if (bytepos
< charpos
)
2812 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2814 IT_BYTEPOS (*it
) = bytepos
;
2816 it
->start
= it
->current
;
2818 /* Compute faces etc. */
2819 reseat (it
, it
->current
.pos
, 1);
2826 /* Initialize IT for the display of window W with window start POS. */
2829 start_display (it
, w
, pos
)
2832 struct text_pos pos
;
2834 struct glyph_row
*row
;
2835 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2837 row
= w
->desired_matrix
->rows
+ first_vpos
;
2838 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2839 it
->first_vpos
= first_vpos
;
2841 /* Don't reseat to previous visible line start if current start
2842 position is in a string or image. */
2843 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2845 int start_at_line_beg_p
;
2846 int first_y
= it
->current_y
;
2848 /* If window start is not at a line start, skip forward to POS to
2849 get the correct continuation lines width. */
2850 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2851 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2852 if (!start_at_line_beg_p
)
2856 reseat_at_previous_visible_line_start (it
);
2857 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2859 new_x
= it
->current_x
+ it
->pixel_width
;
2861 /* If lines are continued, this line may end in the middle
2862 of a multi-glyph character (e.g. a control character
2863 displayed as \003, or in the middle of an overlay
2864 string). In this case move_it_to above will not have
2865 taken us to the start of the continuation line but to the
2866 end of the continued line. */
2867 if (it
->current_x
> 0
2868 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2869 && (/* And glyph doesn't fit on the line. */
2870 new_x
> it
->last_visible_x
2871 /* Or it fits exactly and we're on a window
2873 || (new_x
== it
->last_visible_x
2874 && FRAME_WINDOW_P (it
->f
))))
2876 if (it
->current
.dpvec_index
>= 0
2877 || it
->current
.overlay_string_index
>= 0)
2879 set_iterator_to_next (it
, 1);
2880 move_it_in_display_line_to (it
, -1, -1, 0);
2883 it
->continuation_lines_width
+= it
->current_x
;
2886 /* We're starting a new display line, not affected by the
2887 height of the continued line, so clear the appropriate
2888 fields in the iterator structure. */
2889 it
->max_ascent
= it
->max_descent
= 0;
2890 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2892 it
->current_y
= first_y
;
2894 it
->current_x
= it
->hpos
= 0;
2900 /* Return 1 if POS is a position in ellipses displayed for invisible
2901 text. W is the window we display, for text property lookup. */
2904 in_ellipses_for_invisible_text_p (pos
, w
)
2905 struct display_pos
*pos
;
2908 Lisp_Object prop
, window
;
2910 int charpos
= CHARPOS (pos
->pos
);
2912 /* If POS specifies a position in a display vector, this might
2913 be for an ellipsis displayed for invisible text. We won't
2914 get the iterator set up for delivering that ellipsis unless
2915 we make sure that it gets aware of the invisible text. */
2916 if (pos
->dpvec_index
>= 0
2917 && pos
->overlay_string_index
< 0
2918 && CHARPOS (pos
->string_pos
) < 0
2920 && (XSETWINDOW (window
, w
),
2921 prop
= Fget_char_property (make_number (charpos
),
2922 Qinvisible
, window
),
2923 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2925 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2927 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2934 /* Initialize IT for stepping through current_buffer in window W,
2935 starting at position POS that includes overlay string and display
2936 vector/ control character translation position information. Value
2937 is zero if there are overlay strings with newlines at POS. */
2940 init_from_display_pos (it
, w
, pos
)
2943 struct display_pos
*pos
;
2945 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2946 int i
, overlay_strings_with_newlines
= 0;
2948 /* If POS specifies a position in a display vector, this might
2949 be for an ellipsis displayed for invisible text. We won't
2950 get the iterator set up for delivering that ellipsis unless
2951 we make sure that it gets aware of the invisible text. */
2952 if (in_ellipses_for_invisible_text_p (pos
, w
))
2958 /* Keep in mind: the call to reseat in init_iterator skips invisible
2959 text, so we might end up at a position different from POS. This
2960 is only a problem when POS is a row start after a newline and an
2961 overlay starts there with an after-string, and the overlay has an
2962 invisible property. Since we don't skip invisible text in
2963 display_line and elsewhere immediately after consuming the
2964 newline before the row start, such a POS will not be in a string,
2965 but the call to init_iterator below will move us to the
2967 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2969 /* This only scans the current chunk -- it should scan all chunks.
2970 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2971 to 16 in 22.1 to make this a lesser problem. */
2972 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2974 const char *s
= SDATA (it
->overlay_strings
[i
]);
2975 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2977 while (s
< e
&& *s
!= '\n')
2982 overlay_strings_with_newlines
= 1;
2987 /* If position is within an overlay string, set up IT to the right
2989 if (pos
->overlay_string_index
>= 0)
2993 /* If the first overlay string happens to have a `display'
2994 property for an image, the iterator will be set up for that
2995 image, and we have to undo that setup first before we can
2996 correct the overlay string index. */
2997 if (it
->method
== GET_FROM_IMAGE
)
3000 /* We already have the first chunk of overlay strings in
3001 IT->overlay_strings. Load more until the one for
3002 pos->overlay_string_index is in IT->overlay_strings. */
3003 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3005 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3006 it
->current
.overlay_string_index
= 0;
3009 load_overlay_strings (it
, 0);
3010 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3014 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3015 relative_index
= (it
->current
.overlay_string_index
3016 % OVERLAY_STRING_CHUNK_SIZE
);
3017 it
->string
= it
->overlay_strings
[relative_index
];
3018 xassert (STRINGP (it
->string
));
3019 it
->current
.string_pos
= pos
->string_pos
;
3020 it
->method
= GET_FROM_STRING
;
3023 if (CHARPOS (pos
->string_pos
) >= 0)
3025 /* Recorded position is not in an overlay string, but in another
3026 string. This can only be a string from a `display' property.
3027 IT should already be filled with that string. */
3028 it
->current
.string_pos
= pos
->string_pos
;
3029 xassert (STRINGP (it
->string
));
3032 /* Restore position in display vector translations, control
3033 character translations or ellipses. */
3034 if (pos
->dpvec_index
>= 0)
3036 if (it
->dpvec
== NULL
)
3037 get_next_display_element (it
);
3038 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3039 it
->current
.dpvec_index
= pos
->dpvec_index
;
3043 return !overlay_strings_with_newlines
;
3047 /* Initialize IT for stepping through current_buffer in window W
3048 starting at ROW->start. */
3051 init_to_row_start (it
, w
, row
)
3054 struct glyph_row
*row
;
3056 init_from_display_pos (it
, w
, &row
->start
);
3057 it
->start
= row
->start
;
3058 it
->continuation_lines_width
= row
->continuation_lines_width
;
3063 /* Initialize IT for stepping through current_buffer in window W
3064 starting in the line following ROW, i.e. starting at ROW->end.
3065 Value is zero if there are overlay strings with newlines at ROW's
3069 init_to_row_end (it
, w
, row
)
3072 struct glyph_row
*row
;
3076 if (init_from_display_pos (it
, w
, &row
->end
))
3078 if (row
->continued_p
)
3079 it
->continuation_lines_width
3080 = row
->continuation_lines_width
+ row
->pixel_width
;
3091 /***********************************************************************
3093 ***********************************************************************/
3095 /* Called when IT reaches IT->stop_charpos. Handle text property and
3096 overlay changes. Set IT->stop_charpos to the next position where
3103 enum prop_handled handled
;
3104 int handle_overlay_change_p
;
3108 it
->current
.dpvec_index
= -1;
3109 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3110 it
->ignore_overlay_strings_at_pos_p
= 0;
3113 /* Use face of preceding text for ellipsis (if invisible) */
3114 if (it
->selective_display_ellipsis_p
)
3115 it
->saved_face_id
= it
->face_id
;
3119 handled
= HANDLED_NORMALLY
;
3121 /* Call text property handlers. */
3122 for (p
= it_props
; p
->handler
; ++p
)
3124 handled
= p
->handler (it
);
3126 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3128 else if (handled
== HANDLED_RETURN
)
3130 /* We still want to show before and after strings from
3131 overlays even if the actual buffer text is replaced. */
3132 if (!handle_overlay_change_p
3134 || !get_overlay_strings_1 (it
, 0, 0))
3137 setup_for_ellipsis (it
, 0);
3138 /* When handling a display spec, we might load an
3139 empty string. In that case, discard it here. We
3140 used to discard it in handle_single_display_spec,
3141 but that causes get_overlay_strings_1, above, to
3142 ignore overlay strings that we must check. */
3143 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3147 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3151 it
->ignore_overlay_strings_at_pos_p
= 1;
3152 it
->string_from_display_prop_p
= 0;
3153 handle_overlay_change_p
= 0;
3155 handled
= HANDLED_RECOMPUTE_PROPS
;
3158 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3159 handle_overlay_change_p
= 0;
3162 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3164 /* Don't check for overlay strings below when set to deliver
3165 characters from a display vector. */
3166 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3167 handle_overlay_change_p
= 0;
3169 /* Handle overlay changes.
3170 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3171 if it finds overlays. */
3172 if (handle_overlay_change_p
)
3173 handled
= handle_overlay_change (it
);
3178 setup_for_ellipsis (it
, 0);
3182 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3184 /* Determine where to stop next. */
3185 if (handled
== HANDLED_NORMALLY
)
3186 compute_stop_pos (it
);
3190 /* Compute IT->stop_charpos from text property and overlay change
3191 information for IT's current position. */
3194 compute_stop_pos (it
)
3197 register INTERVAL iv
, next_iv
;
3198 Lisp_Object object
, limit
, position
;
3199 EMACS_INT charpos
, bytepos
;
3201 /* If nowhere else, stop at the end. */
3202 it
->stop_charpos
= it
->end_charpos
;
3204 if (STRINGP (it
->string
))
3206 /* Strings are usually short, so don't limit the search for
3208 object
= it
->string
;
3210 charpos
= IT_STRING_CHARPOS (*it
);
3211 bytepos
= IT_STRING_BYTEPOS (*it
);
3217 /* If next overlay change is in front of the current stop pos
3218 (which is IT->end_charpos), stop there. Note: value of
3219 next_overlay_change is point-max if no overlay change
3221 charpos
= IT_CHARPOS (*it
);
3222 bytepos
= IT_BYTEPOS (*it
);
3223 pos
= next_overlay_change (charpos
);
3224 if (pos
< it
->stop_charpos
)
3225 it
->stop_charpos
= pos
;
3227 /* If showing the region, we have to stop at the region
3228 start or end because the face might change there. */
3229 if (it
->region_beg_charpos
> 0)
3231 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3232 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3233 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3234 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3237 /* Set up variables for computing the stop position from text
3238 property changes. */
3239 XSETBUFFER (object
, current_buffer
);
3240 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3243 /* Get the interval containing IT's position. Value is a null
3244 interval if there isn't such an interval. */
3245 position
= make_number (charpos
);
3246 iv
= validate_interval_range (object
, &position
, &position
, 0);
3247 if (!NULL_INTERVAL_P (iv
))
3249 Lisp_Object values_here
[LAST_PROP_IDX
];
3252 /* Get properties here. */
3253 for (p
= it_props
; p
->handler
; ++p
)
3254 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3256 /* Look for an interval following iv that has different
3258 for (next_iv
= next_interval (iv
);
3259 (!NULL_INTERVAL_P (next_iv
)
3261 || XFASTINT (limit
) > next_iv
->position
));
3262 next_iv
= next_interval (next_iv
))
3264 for (p
= it_props
; p
->handler
; ++p
)
3266 Lisp_Object new_value
;
3268 new_value
= textget (next_iv
->plist
, *p
->name
);
3269 if (!EQ (values_here
[p
->idx
], new_value
))
3277 if (!NULL_INTERVAL_P (next_iv
))
3279 if (INTEGERP (limit
)
3280 && next_iv
->position
>= XFASTINT (limit
))
3281 /* No text property change up to limit. */
3282 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3284 /* Text properties change in next_iv. */
3285 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3289 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3290 it
->stop_charpos
, it
->string
);
3292 xassert (STRINGP (it
->string
)
3293 || (it
->stop_charpos
>= BEGV
3294 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3298 /* Return the position of the next overlay change after POS in
3299 current_buffer. Value is point-max if no overlay change
3300 follows. This is like `next-overlay-change' but doesn't use
3304 next_overlay_change (pos
)
3309 Lisp_Object
*overlays
;
3312 /* Get all overlays at the given position. */
3313 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3315 /* If any of these overlays ends before endpos,
3316 use its ending point instead. */
3317 for (i
= 0; i
< noverlays
; ++i
)
3322 oend
= OVERLAY_END (overlays
[i
]);
3323 oendpos
= OVERLAY_POSITION (oend
);
3324 endpos
= min (endpos
, oendpos
);
3332 /***********************************************************************
3334 ***********************************************************************/
3336 /* Handle changes in the `fontified' property of the current buffer by
3337 calling hook functions from Qfontification_functions to fontify
3340 static enum prop_handled
3341 handle_fontified_prop (it
)
3344 Lisp_Object prop
, pos
;
3345 enum prop_handled handled
= HANDLED_NORMALLY
;
3347 if (!NILP (Vmemory_full
))
3350 /* Get the value of the `fontified' property at IT's current buffer
3351 position. (The `fontified' property doesn't have a special
3352 meaning in strings.) If the value is nil, call functions from
3353 Qfontification_functions. */
3354 if (!STRINGP (it
->string
)
3356 && !NILP (Vfontification_functions
)
3357 && !NILP (Vrun_hooks
)
3358 && (pos
= make_number (IT_CHARPOS (*it
)),
3359 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3360 /* Ignore the special cased nil value always present at EOB since
3361 no amount of fontifying will be able to change it. */
3362 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3364 int count
= SPECPDL_INDEX ();
3367 val
= Vfontification_functions
;
3368 specbind (Qfontification_functions
, Qnil
);
3370 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3371 safe_call1 (val
, pos
);
3374 Lisp_Object globals
, fn
;
3375 struct gcpro gcpro1
, gcpro2
;
3378 GCPRO2 (val
, globals
);
3380 for (; CONSP (val
); val
= XCDR (val
))
3386 /* A value of t indicates this hook has a local
3387 binding; it means to run the global binding too.
3388 In a global value, t should not occur. If it
3389 does, we must ignore it to avoid an endless
3391 for (globals
= Fdefault_value (Qfontification_functions
);
3393 globals
= XCDR (globals
))
3395 fn
= XCAR (globals
);
3397 safe_call1 (fn
, pos
);
3401 safe_call1 (fn
, pos
);
3407 unbind_to (count
, Qnil
);
3409 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3410 something. This avoids an endless loop if they failed to
3411 fontify the text for which reason ever. */
3412 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3413 handled
= HANDLED_RECOMPUTE_PROPS
;
3421 /***********************************************************************
3423 ***********************************************************************/
3425 /* Set up iterator IT from face properties at its current position.
3426 Called from handle_stop. */
3428 static enum prop_handled
3429 handle_face_prop (it
)
3433 EMACS_INT next_stop
;
3435 if (!STRINGP (it
->string
))
3438 = face_at_buffer_position (it
->w
,
3440 it
->region_beg_charpos
,
3441 it
->region_end_charpos
,
3444 + TEXT_PROP_DISTANCE_LIMIT
),
3445 0, it
->base_face_id
);
3447 /* Is this a start of a run of characters with box face?
3448 Caveat: this can be called for a freshly initialized
3449 iterator; face_id is -1 in this case. We know that the new
3450 face will not change until limit, i.e. if the new face has a
3451 box, all characters up to limit will have one. But, as
3452 usual, we don't know whether limit is really the end. */
3453 if (new_face_id
!= it
->face_id
)
3455 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3457 /* If new face has a box but old face has not, this is
3458 the start of a run of characters with box, i.e. it has
3459 a shadow on the left side. The value of face_id of the
3460 iterator will be -1 if this is the initial call that gets
3461 the face. In this case, we have to look in front of IT's
3462 position and see whether there is a face != new_face_id. */
3463 it
->start_of_box_run_p
3464 = (new_face
->box
!= FACE_NO_BOX
3465 && (it
->face_id
>= 0
3466 || IT_CHARPOS (*it
) == BEG
3467 || new_face_id
!= face_before_it_pos (it
)));
3468 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3473 int base_face_id
, bufpos
;
3475 Lisp_Object from_overlay
3476 = (it
->current
.overlay_string_index
>= 0
3477 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3480 /* See if we got to this string directly or indirectly from
3481 an overlay property. That includes the before-string or
3482 after-string of an overlay, strings in display properties
3483 provided by an overlay, their text properties, etc.
3485 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3486 if (! NILP (from_overlay
))
3487 for (i
= it
->sp
- 1; i
>= 0; i
--)
3489 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3491 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3492 else if (! NILP (it
->stack
[i
].from_overlay
))
3493 from_overlay
= it
->stack
[i
].from_overlay
;
3495 if (!NILP (from_overlay
))
3499 if (! NILP (from_overlay
))
3501 bufpos
= IT_CHARPOS (*it
);
3502 /* For a string from an overlay, the base face depends
3503 only on text properties and ignores overlays. */
3505 = face_for_overlay_string (it
->w
,
3507 it
->region_beg_charpos
,
3508 it
->region_end_charpos
,
3511 + TEXT_PROP_DISTANCE_LIMIT
),
3519 /* For strings from a `display' property, use the face at
3520 IT's current buffer position as the base face to merge
3521 with, so that overlay strings appear in the same face as
3522 surrounding text, unless they specify their own
3524 base_face_id
= underlying_face_id (it
);
3527 new_face_id
= face_at_string_position (it
->w
,
3529 IT_STRING_CHARPOS (*it
),
3531 it
->region_beg_charpos
,
3532 it
->region_end_charpos
,
3536 /* Is this a start of a run of characters with box? Caveat:
3537 this can be called for a freshly allocated iterator; face_id
3538 is -1 is this case. We know that the new face will not
3539 change until the next check pos, i.e. if the new face has a
3540 box, all characters up to that position will have a
3541 box. But, as usual, we don't know whether that position
3542 is really the end. */
3543 if (new_face_id
!= it
->face_id
)
3545 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3546 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3548 /* If new face has a box but old face hasn't, this is the
3549 start of a run of characters with box, i.e. it has a
3550 shadow on the left side. */
3551 it
->start_of_box_run_p
3552 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3553 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3557 it
->face_id
= new_face_id
;
3558 return HANDLED_NORMALLY
;
3562 /* Return the ID of the face ``underlying'' IT's current position,
3563 which is in a string. If the iterator is associated with a
3564 buffer, return the face at IT's current buffer position.
3565 Otherwise, use the iterator's base_face_id. */
3568 underlying_face_id (it
)
3571 int face_id
= it
->base_face_id
, i
;
3573 xassert (STRINGP (it
->string
));
3575 for (i
= it
->sp
- 1; i
>= 0; --i
)
3576 if (NILP (it
->stack
[i
].string
))
3577 face_id
= it
->stack
[i
].face_id
;
3583 /* Compute the face one character before or after the current position
3584 of IT. BEFORE_P non-zero means get the face in front of IT's
3585 position. Value is the id of the face. */
3588 face_before_or_after_it_pos (it
, before_p
)
3593 EMACS_INT next_check_charpos
;
3594 struct text_pos pos
;
3596 xassert (it
->s
== NULL
);
3598 if (STRINGP (it
->string
))
3600 int bufpos
, base_face_id
;
3602 /* No face change past the end of the string (for the case
3603 we are padding with spaces). No face change before the
3605 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3606 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3609 /* Set pos to the position before or after IT's current position. */
3611 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3613 /* For composition, we must check the character after the
3615 pos
= (it
->what
== IT_COMPOSITION
3616 ? string_pos (IT_STRING_CHARPOS (*it
)
3617 + it
->cmp_it
.nchars
, it
->string
)
3618 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3620 if (it
->current
.overlay_string_index
>= 0)
3621 bufpos
= IT_CHARPOS (*it
);
3625 base_face_id
= underlying_face_id (it
);
3627 /* Get the face for ASCII, or unibyte. */
3628 face_id
= face_at_string_position (it
->w
,
3632 it
->region_beg_charpos
,
3633 it
->region_end_charpos
,
3634 &next_check_charpos
,
3637 /* Correct the face for charsets different from ASCII. Do it
3638 for the multibyte case only. The face returned above is
3639 suitable for unibyte text if IT->string is unibyte. */
3640 if (STRING_MULTIBYTE (it
->string
))
3642 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3643 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3645 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3647 c
= string_char_and_length (p
, &len
);
3648 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3653 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3654 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3657 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3658 pos
= it
->current
.pos
;
3661 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3664 if (it
->what
== IT_COMPOSITION
)
3665 /* For composition, we must check the position after the
3667 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3669 INC_TEXT_POS (pos
, it
->multibyte_p
);
3672 /* Determine face for CHARSET_ASCII, or unibyte. */
3673 face_id
= face_at_buffer_position (it
->w
,
3675 it
->region_beg_charpos
,
3676 it
->region_end_charpos
,
3677 &next_check_charpos
,
3680 /* Correct the face for charsets different from ASCII. Do it
3681 for the multibyte case only. The face returned above is
3682 suitable for unibyte text if current_buffer is unibyte. */
3683 if (it
->multibyte_p
)
3685 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3686 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3687 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3696 /***********************************************************************
3698 ***********************************************************************/
3700 /* Set up iterator IT from invisible properties at its current
3701 position. Called from handle_stop. */
3703 static enum prop_handled
3704 handle_invisible_prop (it
)
3707 enum prop_handled handled
= HANDLED_NORMALLY
;
3709 if (STRINGP (it
->string
))
3711 extern Lisp_Object Qinvisible
;
3712 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3714 /* Get the value of the invisible text property at the
3715 current position. Value will be nil if there is no such
3717 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3718 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3721 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3723 handled
= HANDLED_RECOMPUTE_PROPS
;
3725 /* Get the position at which the next change of the
3726 invisible text property can be found in IT->string.
3727 Value will be nil if the property value is the same for
3728 all the rest of IT->string. */
3729 XSETINT (limit
, SCHARS (it
->string
));
3730 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3733 /* Text at current position is invisible. The next
3734 change in the property is at position end_charpos.
3735 Move IT's current position to that position. */
3736 if (INTEGERP (end_charpos
)
3737 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3739 struct text_pos old
;
3740 old
= it
->current
.string_pos
;
3741 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3742 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3746 /* The rest of the string is invisible. If this is an
3747 overlay string, proceed with the next overlay string
3748 or whatever comes and return a character from there. */
3749 if (it
->current
.overlay_string_index
>= 0)
3751 next_overlay_string (it
);
3752 /* Don't check for overlay strings when we just
3753 finished processing them. */
3754 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3758 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3759 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3767 EMACS_INT newpos
, next_stop
, start_charpos
;
3768 Lisp_Object pos
, prop
, overlay
;
3770 /* First of all, is there invisible text at this position? */
3771 start_charpos
= IT_CHARPOS (*it
);
3772 pos
= make_number (IT_CHARPOS (*it
));
3773 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3775 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3777 /* If we are on invisible text, skip over it. */
3778 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3780 /* Record whether we have to display an ellipsis for the
3782 int display_ellipsis_p
= invis_p
== 2;
3784 handled
= HANDLED_RECOMPUTE_PROPS
;
3786 /* Loop skipping over invisible text. The loop is left at
3787 ZV or with IT on the first char being visible again. */
3790 /* Try to skip some invisible text. Return value is the
3791 position reached which can be equal to IT's position
3792 if there is nothing invisible here. This skips both
3793 over invisible text properties and overlays with
3794 invisible property. */
3795 newpos
= skip_invisible (IT_CHARPOS (*it
),
3796 &next_stop
, ZV
, it
->window
);
3798 /* If we skipped nothing at all we weren't at invisible
3799 text in the first place. If everything to the end of
3800 the buffer was skipped, end the loop. */
3801 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3805 /* We skipped some characters but not necessarily
3806 all there are. Check if we ended up on visible
3807 text. Fget_char_property returns the property of
3808 the char before the given position, i.e. if we
3809 get invis_p = 0, this means that the char at
3810 newpos is visible. */
3811 pos
= make_number (newpos
);
3812 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3813 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3816 /* If we ended up on invisible text, proceed to
3817 skip starting with next_stop. */
3819 IT_CHARPOS (*it
) = next_stop
;
3821 /* If there are adjacent invisible texts, don't lose the
3822 second one's ellipsis. */
3824 display_ellipsis_p
= 1;
3828 /* The position newpos is now either ZV or on visible text. */
3829 IT_CHARPOS (*it
) = newpos
;
3830 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3832 /* If there are before-strings at the start of invisible
3833 text, and the text is invisible because of a text
3834 property, arrange to show before-strings because 20.x did
3835 it that way. (If the text is invisible because of an
3836 overlay property instead of a text property, this is
3837 already handled in the overlay code.) */
3839 && get_overlay_strings (it
, start_charpos
))
3841 handled
= HANDLED_RECOMPUTE_PROPS
;
3842 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3844 else if (display_ellipsis_p
)
3846 /* Make sure that the glyphs of the ellipsis will get
3847 correct `charpos' values. If we would not update
3848 it->position here, the glyphs would belong to the
3849 last visible character _before_ the invisible
3850 text, which confuses `set_cursor_from_row'.
3852 We use the last invisible position instead of the
3853 first because this way the cursor is always drawn on
3854 the first "." of the ellipsis, whenever PT is inside
3855 the invisible text. Otherwise the cursor would be
3856 placed _after_ the ellipsis when the point is after the
3857 first invisible character. */
3858 if (!STRINGP (it
->object
))
3860 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3861 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3864 /* Let the ellipsis display before
3865 considering any properties of the following char.
3866 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3867 handled
= HANDLED_RETURN
;
3876 /* Make iterator IT return `...' next.
3877 Replaces LEN characters from buffer. */
3880 setup_for_ellipsis (it
, len
)
3884 /* Use the display table definition for `...'. Invalid glyphs
3885 will be handled by the method returning elements from dpvec. */
3886 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3888 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3889 it
->dpvec
= v
->contents
;
3890 it
->dpend
= v
->contents
+ v
->size
;
3894 /* Default `...'. */
3895 it
->dpvec
= default_invis_vector
;
3896 it
->dpend
= default_invis_vector
+ 3;
3899 it
->dpvec_char_len
= len
;
3900 it
->current
.dpvec_index
= 0;
3901 it
->dpvec_face_id
= -1;
3903 /* Remember the current face id in case glyphs specify faces.
3904 IT's face is restored in set_iterator_to_next.
3905 saved_face_id was set to preceding char's face in handle_stop. */
3906 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3907 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3909 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3915 /***********************************************************************
3917 ***********************************************************************/
3919 /* Set up iterator IT from `display' property at its current position.
3920 Called from handle_stop.
3921 We return HANDLED_RETURN if some part of the display property
3922 overrides the display of the buffer text itself.
3923 Otherwise we return HANDLED_NORMALLY. */
3925 static enum prop_handled
3926 handle_display_prop (it
)
3929 Lisp_Object prop
, object
, overlay
;
3930 struct text_pos
*position
;
3931 /* Nonzero if some property replaces the display of the text itself. */
3932 int display_replaced_p
= 0;
3934 if (STRINGP (it
->string
))
3936 object
= it
->string
;
3937 position
= &it
->current
.string_pos
;
3941 XSETWINDOW (object
, it
->w
);
3942 position
= &it
->current
.pos
;
3945 /* Reset those iterator values set from display property values. */
3946 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3947 it
->space_width
= Qnil
;
3948 it
->font_height
= Qnil
;
3951 /* We don't support recursive `display' properties, i.e. string
3952 values that have a string `display' property, that have a string
3953 `display' property etc. */
3954 if (!it
->string_from_display_prop_p
)
3955 it
->area
= TEXT_AREA
;
3957 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3958 Qdisplay
, object
, &overlay
);
3960 return HANDLED_NORMALLY
;
3961 /* Now OVERLAY is the overlay that gave us this property, or nil
3962 if it was a text property. */
3964 if (!STRINGP (it
->string
))
3965 object
= it
->w
->buffer
;
3968 /* Simple properties. */
3969 && !EQ (XCAR (prop
), Qimage
)
3970 && !EQ (XCAR (prop
), Qspace
)
3971 && !EQ (XCAR (prop
), Qwhen
)
3972 && !EQ (XCAR (prop
), Qslice
)
3973 && !EQ (XCAR (prop
), Qspace_width
)
3974 && !EQ (XCAR (prop
), Qheight
)
3975 && !EQ (XCAR (prop
), Qraise
)
3976 /* Marginal area specifications. */
3977 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3978 && !EQ (XCAR (prop
), Qleft_fringe
)
3979 && !EQ (XCAR (prop
), Qright_fringe
)
3980 && !NILP (XCAR (prop
)))
3982 for (; CONSP (prop
); prop
= XCDR (prop
))
3984 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3985 position
, display_replaced_p
))
3987 display_replaced_p
= 1;
3988 /* If some text in a string is replaced, `position' no
3989 longer points to the position of `object'. */
3990 if (STRINGP (object
))
3995 else if (VECTORP (prop
))
3998 for (i
= 0; i
< ASIZE (prop
); ++i
)
3999 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4000 position
, display_replaced_p
))
4002 display_replaced_p
= 1;
4003 /* If some text in a string is replaced, `position' no
4004 longer points to the position of `object'. */
4005 if (STRINGP (object
))
4011 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4013 display_replaced_p
= 1;
4016 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4020 /* Value is the position of the end of the `display' property starting
4021 at START_POS in OBJECT. */
4023 static struct text_pos
4024 display_prop_end (it
, object
, start_pos
)
4027 struct text_pos start_pos
;
4030 struct text_pos end_pos
;
4032 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4033 Qdisplay
, object
, Qnil
);
4034 CHARPOS (end_pos
) = XFASTINT (end
);
4035 if (STRINGP (object
))
4036 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4038 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4044 /* Set up IT from a single `display' specification PROP. OBJECT
4045 is the object in which the `display' property was found. *POSITION
4046 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4047 means that we previously saw a display specification which already
4048 replaced text display with something else, for example an image;
4049 we ignore such properties after the first one has been processed.
4051 OVERLAY is the overlay this `display' property came from,
4052 or nil if it was a text property.
4054 If PROP is a `space' or `image' specification, and in some other
4055 cases too, set *POSITION to the position where the `display'
4058 Value is non-zero if something was found which replaces the display
4059 of buffer or string text. */
4062 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4063 display_replaced_before_p
)
4067 Lisp_Object overlay
;
4068 struct text_pos
*position
;
4069 int display_replaced_before_p
;
4072 Lisp_Object location
, value
;
4073 struct text_pos start_pos
, save_pos
;
4076 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4077 If the result is non-nil, use VALUE instead of SPEC. */
4079 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4088 if (!NILP (form
) && !EQ (form
, Qt
))
4090 int count
= SPECPDL_INDEX ();
4091 struct gcpro gcpro1
;
4093 /* Bind `object' to the object having the `display' property, a
4094 buffer or string. Bind `position' to the position in the
4095 object where the property was found, and `buffer-position'
4096 to the current position in the buffer. */
4097 specbind (Qobject
, object
);
4098 specbind (Qposition
, make_number (CHARPOS (*position
)));
4099 specbind (Qbuffer_position
,
4100 make_number (STRINGP (object
)
4101 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4103 form
= safe_eval (form
);
4105 unbind_to (count
, Qnil
);
4111 /* Handle `(height HEIGHT)' specifications. */
4113 && EQ (XCAR (spec
), Qheight
)
4114 && CONSP (XCDR (spec
)))
4116 if (!FRAME_WINDOW_P (it
->f
))
4119 it
->font_height
= XCAR (XCDR (spec
));
4120 if (!NILP (it
->font_height
))
4122 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4123 int new_height
= -1;
4125 if (CONSP (it
->font_height
)
4126 && (EQ (XCAR (it
->font_height
), Qplus
)
4127 || EQ (XCAR (it
->font_height
), Qminus
))
4128 && CONSP (XCDR (it
->font_height
))
4129 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4131 /* `(+ N)' or `(- N)' where N is an integer. */
4132 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4133 if (EQ (XCAR (it
->font_height
), Qplus
))
4135 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4137 else if (FUNCTIONP (it
->font_height
))
4139 /* Call function with current height as argument.
4140 Value is the new height. */
4142 height
= safe_call1 (it
->font_height
,
4143 face
->lface
[LFACE_HEIGHT_INDEX
]);
4144 if (NUMBERP (height
))
4145 new_height
= XFLOATINT (height
);
4147 else if (NUMBERP (it
->font_height
))
4149 /* Value is a multiple of the canonical char height. */
4152 face
= FACE_FROM_ID (it
->f
,
4153 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4154 new_height
= (XFLOATINT (it
->font_height
)
4155 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4159 /* Evaluate IT->font_height with `height' bound to the
4160 current specified height to get the new height. */
4161 int count
= SPECPDL_INDEX ();
4163 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4164 value
= safe_eval (it
->font_height
);
4165 unbind_to (count
, Qnil
);
4167 if (NUMBERP (value
))
4168 new_height
= XFLOATINT (value
);
4172 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4178 /* Handle `(space-width WIDTH)'. */
4180 && EQ (XCAR (spec
), Qspace_width
)
4181 && CONSP (XCDR (spec
)))
4183 if (!FRAME_WINDOW_P (it
->f
))
4186 value
= XCAR (XCDR (spec
));
4187 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4188 it
->space_width
= value
;
4193 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4195 && EQ (XCAR (spec
), Qslice
))
4199 if (!FRAME_WINDOW_P (it
->f
))
4202 if (tem
= XCDR (spec
), CONSP (tem
))
4204 it
->slice
.x
= XCAR (tem
);
4205 if (tem
= XCDR (tem
), CONSP (tem
))
4207 it
->slice
.y
= XCAR (tem
);
4208 if (tem
= XCDR (tem
), CONSP (tem
))
4210 it
->slice
.width
= XCAR (tem
);
4211 if (tem
= XCDR (tem
), CONSP (tem
))
4212 it
->slice
.height
= XCAR (tem
);
4220 /* Handle `(raise FACTOR)'. */
4222 && EQ (XCAR (spec
), Qraise
)
4223 && CONSP (XCDR (spec
)))
4225 if (!FRAME_WINDOW_P (it
->f
))
4228 #ifdef HAVE_WINDOW_SYSTEM
4229 value
= XCAR (XCDR (spec
));
4230 if (NUMBERP (value
))
4232 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4233 it
->voffset
= - (XFLOATINT (value
)
4234 * (FONT_HEIGHT (face
->font
)));
4236 #endif /* HAVE_WINDOW_SYSTEM */
4241 /* Don't handle the other kinds of display specifications
4242 inside a string that we got from a `display' property. */
4243 if (it
->string_from_display_prop_p
)
4246 /* Characters having this form of property are not displayed, so
4247 we have to find the end of the property. */
4248 start_pos
= *position
;
4249 *position
= display_prop_end (it
, object
, start_pos
);
4252 /* Stop the scan at that end position--we assume that all
4253 text properties change there. */
4254 it
->stop_charpos
= position
->charpos
;
4256 /* Handle `(left-fringe BITMAP [FACE])'
4257 and `(right-fringe BITMAP [FACE])'. */
4259 && (EQ (XCAR (spec
), Qleft_fringe
)
4260 || EQ (XCAR (spec
), Qright_fringe
))
4261 && CONSP (XCDR (spec
)))
4263 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4266 if (!FRAME_WINDOW_P (it
->f
))
4267 /* If we return here, POSITION has been advanced
4268 across the text with this property. */
4271 #ifdef HAVE_WINDOW_SYSTEM
4272 value
= XCAR (XCDR (spec
));
4273 if (!SYMBOLP (value
)
4274 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4275 /* If we return here, POSITION has been advanced
4276 across the text with this property. */
4279 if (CONSP (XCDR (XCDR (spec
))))
4281 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4282 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4288 /* Save current settings of IT so that we can restore them
4289 when we are finished with the glyph property value. */
4291 save_pos
= it
->position
;
4292 it
->position
= *position
;
4294 it
->position
= save_pos
;
4296 it
->area
= TEXT_AREA
;
4297 it
->what
= IT_IMAGE
;
4298 it
->image_id
= -1; /* no image */
4299 it
->position
= start_pos
;
4300 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4301 it
->method
= GET_FROM_IMAGE
;
4302 it
->from_overlay
= Qnil
;
4303 it
->face_id
= face_id
;
4305 /* Say that we haven't consumed the characters with
4306 `display' property yet. The call to pop_it in
4307 set_iterator_to_next will clean this up. */
4308 *position
= start_pos
;
4310 if (EQ (XCAR (spec
), Qleft_fringe
))
4312 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4313 it
->left_user_fringe_face_id
= face_id
;
4317 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4318 it
->right_user_fringe_face_id
= face_id
;
4320 #endif /* HAVE_WINDOW_SYSTEM */
4324 /* Prepare to handle `((margin left-margin) ...)',
4325 `((margin right-margin) ...)' and `((margin nil) ...)'
4326 prefixes for display specifications. */
4327 location
= Qunbound
;
4328 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4332 value
= XCDR (spec
);
4334 value
= XCAR (value
);
4337 if (EQ (XCAR (tem
), Qmargin
)
4338 && (tem
= XCDR (tem
),
4339 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4341 || EQ (tem
, Qleft_margin
)
4342 || EQ (tem
, Qright_margin
))))
4346 if (EQ (location
, Qunbound
))
4352 /* After this point, VALUE is the property after any
4353 margin prefix has been stripped. It must be a string,
4354 an image specification, or `(space ...)'.
4356 LOCATION specifies where to display: `left-margin',
4357 `right-margin' or nil. */
4359 valid_p
= (STRINGP (value
)
4360 #ifdef HAVE_WINDOW_SYSTEM
4361 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4362 #endif /* not HAVE_WINDOW_SYSTEM */
4363 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4365 if (valid_p
&& !display_replaced_before_p
)
4367 /* Save current settings of IT so that we can restore them
4368 when we are finished with the glyph property value. */
4369 save_pos
= it
->position
;
4370 it
->position
= *position
;
4372 it
->position
= save_pos
;
4373 it
->from_overlay
= overlay
;
4375 if (NILP (location
))
4376 it
->area
= TEXT_AREA
;
4377 else if (EQ (location
, Qleft_margin
))
4378 it
->area
= LEFT_MARGIN_AREA
;
4380 it
->area
= RIGHT_MARGIN_AREA
;
4382 if (STRINGP (value
))
4385 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4386 it
->current
.overlay_string_index
= -1;
4387 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4388 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4389 it
->method
= GET_FROM_STRING
;
4390 it
->stop_charpos
= 0;
4391 it
->string_from_display_prop_p
= 1;
4392 /* Say that we haven't consumed the characters with
4393 `display' property yet. The call to pop_it in
4394 set_iterator_to_next will clean this up. */
4395 if (BUFFERP (object
))
4396 *position
= start_pos
;
4398 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4400 it
->method
= GET_FROM_STRETCH
;
4402 *position
= it
->position
= start_pos
;
4404 #ifdef HAVE_WINDOW_SYSTEM
4407 it
->what
= IT_IMAGE
;
4408 it
->image_id
= lookup_image (it
->f
, value
);
4409 it
->position
= start_pos
;
4410 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4411 it
->method
= GET_FROM_IMAGE
;
4413 /* Say that we haven't consumed the characters with
4414 `display' property yet. The call to pop_it in
4415 set_iterator_to_next will clean this up. */
4416 *position
= start_pos
;
4418 #endif /* HAVE_WINDOW_SYSTEM */
4423 /* Invalid property or property not supported. Restore
4424 POSITION to what it was before. */
4425 *position
= start_pos
;
4430 /* Check if SPEC is a display sub-property value whose text should be
4431 treated as intangible. */
4434 single_display_spec_intangible_p (prop
)
4437 /* Skip over `when FORM'. */
4438 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4452 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4453 we don't need to treat text as intangible. */
4454 if (EQ (XCAR (prop
), Qmargin
))
4462 || EQ (XCAR (prop
), Qleft_margin
)
4463 || EQ (XCAR (prop
), Qright_margin
))
4467 return (CONSP (prop
)
4468 && (EQ (XCAR (prop
), Qimage
)
4469 || EQ (XCAR (prop
), Qspace
)));
4473 /* Check if PROP is a display property value whose text should be
4474 treated as intangible. */
4477 display_prop_intangible_p (prop
)
4481 && CONSP (XCAR (prop
))
4482 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4484 /* A list of sub-properties. */
4485 while (CONSP (prop
))
4487 if (single_display_spec_intangible_p (XCAR (prop
)))
4492 else if (VECTORP (prop
))
4494 /* A vector of sub-properties. */
4496 for (i
= 0; i
< ASIZE (prop
); ++i
)
4497 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4501 return single_display_spec_intangible_p (prop
);
4507 /* Return 1 if PROP is a display sub-property value containing STRING. */
4510 single_display_spec_string_p (prop
, string
)
4511 Lisp_Object prop
, string
;
4513 if (EQ (string
, prop
))
4516 /* Skip over `when FORM'. */
4517 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4526 /* Skip over `margin LOCATION'. */
4527 if (EQ (XCAR (prop
), Qmargin
))
4538 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4542 /* Return 1 if STRING appears in the `display' property PROP. */
4545 display_prop_string_p (prop
, string
)
4546 Lisp_Object prop
, string
;
4549 && CONSP (XCAR (prop
))
4550 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4552 /* A list of sub-properties. */
4553 while (CONSP (prop
))
4555 if (single_display_spec_string_p (XCAR (prop
), string
))
4560 else if (VECTORP (prop
))
4562 /* A vector of sub-properties. */
4564 for (i
= 0; i
< ASIZE (prop
); ++i
)
4565 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4569 return single_display_spec_string_p (prop
, string
);
4575 /* Determine which buffer position in W's buffer STRING comes from.
4576 AROUND_CHARPOS is an approximate position where it could come from.
4577 Value is the buffer position or 0 if it couldn't be determined.
4579 W's buffer must be current.
4581 This function is necessary because we don't record buffer positions
4582 in glyphs generated from strings (to keep struct glyph small).
4583 This function may only use code that doesn't eval because it is
4584 called asynchronously from note_mouse_highlight. */
4587 string_buffer_position (w
, string
, around_charpos
)
4592 Lisp_Object limit
, prop
, pos
;
4593 const int MAX_DISTANCE
= 1000;
4596 pos
= make_number (around_charpos
);
4597 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4598 while (!found
&& !EQ (pos
, limit
))
4600 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4601 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4604 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4609 pos
= make_number (around_charpos
);
4610 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4611 while (!found
&& !EQ (pos
, limit
))
4613 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4614 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4617 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4622 return found
? XINT (pos
) : 0;
4627 /***********************************************************************
4628 `composition' property
4629 ***********************************************************************/
4631 /* Set up iterator IT from `composition' property at its current
4632 position. Called from handle_stop. */
4634 static enum prop_handled
4635 handle_composition_prop (it
)
4638 Lisp_Object prop
, string
;
4639 EMACS_INT pos
, pos_byte
, start
, end
;
4641 if (STRINGP (it
->string
))
4645 pos
= IT_STRING_CHARPOS (*it
);
4646 pos_byte
= IT_STRING_BYTEPOS (*it
);
4647 string
= it
->string
;
4648 s
= SDATA (string
) + pos_byte
;
4649 it
->c
= STRING_CHAR (s
);
4653 pos
= IT_CHARPOS (*it
);
4654 pos_byte
= IT_BYTEPOS (*it
);
4656 it
->c
= FETCH_CHAR (pos_byte
);
4659 /* If there's a valid composition and point is not inside of the
4660 composition (in the case that the composition is from the current
4661 buffer), draw a glyph composed from the composition components. */
4662 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4663 && COMPOSITION_VALID_P (start
, end
, prop
)
4664 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4668 if (STRINGP (it
->string
))
4669 pos_byte
= string_char_to_byte (it
->string
, start
);
4671 pos_byte
= CHAR_TO_BYTE (start
);
4673 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4676 if (it
->cmp_it
.id
>= 0)
4679 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4680 it
->cmp_it
.nglyphs
= -1;
4684 return HANDLED_NORMALLY
;
4689 /***********************************************************************
4691 ***********************************************************************/
4693 /* The following structure is used to record overlay strings for
4694 later sorting in load_overlay_strings. */
4696 struct overlay_entry
4698 Lisp_Object overlay
;
4705 /* Set up iterator IT from overlay strings at its current position.
4706 Called from handle_stop. */
4708 static enum prop_handled
4709 handle_overlay_change (it
)
4712 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4713 return HANDLED_RECOMPUTE_PROPS
;
4715 return HANDLED_NORMALLY
;
4719 /* Set up the next overlay string for delivery by IT, if there is an
4720 overlay string to deliver. Called by set_iterator_to_next when the
4721 end of the current overlay string is reached. If there are more
4722 overlay strings to display, IT->string and
4723 IT->current.overlay_string_index are set appropriately here.
4724 Otherwise IT->string is set to nil. */
4727 next_overlay_string (it
)
4730 ++it
->current
.overlay_string_index
;
4731 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4733 /* No more overlay strings. Restore IT's settings to what
4734 they were before overlay strings were processed, and
4735 continue to deliver from current_buffer. */
4737 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4740 || (NILP (it
->string
)
4741 && it
->method
== GET_FROM_BUFFER
4742 && it
->stop_charpos
>= BEGV
4743 && it
->stop_charpos
<= it
->end_charpos
));
4744 it
->current
.overlay_string_index
= -1;
4745 it
->n_overlay_strings
= 0;
4747 /* If we're at the end of the buffer, record that we have
4748 processed the overlay strings there already, so that
4749 next_element_from_buffer doesn't try it again. */
4750 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4751 it
->overlay_strings_at_end_processed_p
= 1;
4755 /* There are more overlay strings to process. If
4756 IT->current.overlay_string_index has advanced to a position
4757 where we must load IT->overlay_strings with more strings, do
4759 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4761 if (it
->current
.overlay_string_index
&& i
== 0)
4762 load_overlay_strings (it
, 0);
4764 /* Initialize IT to deliver display elements from the overlay
4766 it
->string
= it
->overlay_strings
[i
];
4767 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4768 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4769 it
->method
= GET_FROM_STRING
;
4770 it
->stop_charpos
= 0;
4771 if (it
->cmp_it
.stop_pos
>= 0)
4772 it
->cmp_it
.stop_pos
= 0;
4779 /* Compare two overlay_entry structures E1 and E2. Used as a
4780 comparison function for qsort in load_overlay_strings. Overlay
4781 strings for the same position are sorted so that
4783 1. All after-strings come in front of before-strings, except
4784 when they come from the same overlay.
4786 2. Within after-strings, strings are sorted so that overlay strings
4787 from overlays with higher priorities come first.
4789 2. Within before-strings, strings are sorted so that overlay
4790 strings from overlays with higher priorities come last.
4792 Value is analogous to strcmp. */
4796 compare_overlay_entries (e1
, e2
)
4799 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4800 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4803 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4805 /* Let after-strings appear in front of before-strings if
4806 they come from different overlays. */
4807 if (EQ (entry1
->overlay
, entry2
->overlay
))
4808 result
= entry1
->after_string_p
? 1 : -1;
4810 result
= entry1
->after_string_p
? -1 : 1;
4812 else if (entry1
->after_string_p
)
4813 /* After-strings sorted in order of decreasing priority. */
4814 result
= entry2
->priority
- entry1
->priority
;
4816 /* Before-strings sorted in order of increasing priority. */
4817 result
= entry1
->priority
- entry2
->priority
;
4823 /* Load the vector IT->overlay_strings with overlay strings from IT's
4824 current buffer position, or from CHARPOS if that is > 0. Set
4825 IT->n_overlays to the total number of overlay strings found.
4827 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4828 a time. On entry into load_overlay_strings,
4829 IT->current.overlay_string_index gives the number of overlay
4830 strings that have already been loaded by previous calls to this
4833 IT->add_overlay_start contains an additional overlay start
4834 position to consider for taking overlay strings from, if non-zero.
4835 This position comes into play when the overlay has an `invisible'
4836 property, and both before and after-strings. When we've skipped to
4837 the end of the overlay, because of its `invisible' property, we
4838 nevertheless want its before-string to appear.
4839 IT->add_overlay_start will contain the overlay start position
4842 Overlay strings are sorted so that after-string strings come in
4843 front of before-string strings. Within before and after-strings,
4844 strings are sorted by overlay priority. See also function
4845 compare_overlay_entries. */
4848 load_overlay_strings (it
, charpos
)
4852 extern Lisp_Object Qwindow
, Qpriority
;
4853 Lisp_Object overlay
, window
, str
, invisible
;
4854 struct Lisp_Overlay
*ov
;
4857 int n
= 0, i
, j
, invis_p
;
4858 struct overlay_entry
*entries
4859 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4862 charpos
= IT_CHARPOS (*it
);
4864 /* Append the overlay string STRING of overlay OVERLAY to vector
4865 `entries' which has size `size' and currently contains `n'
4866 elements. AFTER_P non-zero means STRING is an after-string of
4868 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4871 Lisp_Object priority; \
4875 int new_size = 2 * size; \
4876 struct overlay_entry *old = entries; \
4878 (struct overlay_entry *) alloca (new_size \
4879 * sizeof *entries); \
4880 bcopy (old, entries, size * sizeof *entries); \
4884 entries[n].string = (STRING); \
4885 entries[n].overlay = (OVERLAY); \
4886 priority = Foverlay_get ((OVERLAY), Qpriority); \
4887 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4888 entries[n].after_string_p = (AFTER_P); \
4893 /* Process overlay before the overlay center. */
4894 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4896 XSETMISC (overlay
, ov
);
4897 xassert (OVERLAYP (overlay
));
4898 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4899 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4904 /* Skip this overlay if it doesn't start or end at IT's current
4906 if (end
!= charpos
&& start
!= charpos
)
4909 /* Skip this overlay if it doesn't apply to IT->w. */
4910 window
= Foverlay_get (overlay
, Qwindow
);
4911 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4914 /* If the text ``under'' the overlay is invisible, both before-
4915 and after-strings from this overlay are visible; start and
4916 end position are indistinguishable. */
4917 invisible
= Foverlay_get (overlay
, Qinvisible
);
4918 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4920 /* If overlay has a non-empty before-string, record it. */
4921 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4922 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4924 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4926 /* If overlay has a non-empty after-string, record it. */
4927 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4928 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4930 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4933 /* Process overlays after the overlay center. */
4934 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4936 XSETMISC (overlay
, ov
);
4937 xassert (OVERLAYP (overlay
));
4938 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4939 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4941 if (start
> charpos
)
4944 /* Skip this overlay if it doesn't start or end at IT's current
4946 if (end
!= charpos
&& start
!= charpos
)
4949 /* Skip this overlay if it doesn't apply to IT->w. */
4950 window
= Foverlay_get (overlay
, Qwindow
);
4951 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4954 /* If the text ``under'' the overlay is invisible, it has a zero
4955 dimension, and both before- and after-strings apply. */
4956 invisible
= Foverlay_get (overlay
, Qinvisible
);
4957 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4959 /* If overlay has a non-empty before-string, record it. */
4960 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4961 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4963 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4965 /* If overlay has a non-empty after-string, record it. */
4966 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4967 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4969 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4972 #undef RECORD_OVERLAY_STRING
4976 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4978 /* Record the total number of strings to process. */
4979 it
->n_overlay_strings
= n
;
4981 /* IT->current.overlay_string_index is the number of overlay strings
4982 that have already been consumed by IT. Copy some of the
4983 remaining overlay strings to IT->overlay_strings. */
4985 j
= it
->current
.overlay_string_index
;
4986 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4988 it
->overlay_strings
[i
] = entries
[j
].string
;
4989 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4996 /* Get the first chunk of overlay strings at IT's current buffer
4997 position, or at CHARPOS if that is > 0. Value is non-zero if at
4998 least one overlay string was found. */
5001 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5006 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5007 process. This fills IT->overlay_strings with strings, and sets
5008 IT->n_overlay_strings to the total number of strings to process.
5009 IT->pos.overlay_string_index has to be set temporarily to zero
5010 because load_overlay_strings needs this; it must be set to -1
5011 when no overlay strings are found because a zero value would
5012 indicate a position in the first overlay string. */
5013 it
->current
.overlay_string_index
= 0;
5014 load_overlay_strings (it
, charpos
);
5016 /* If we found overlay strings, set up IT to deliver display
5017 elements from the first one. Otherwise set up IT to deliver
5018 from current_buffer. */
5019 if (it
->n_overlay_strings
)
5021 /* Make sure we know settings in current_buffer, so that we can
5022 restore meaningful values when we're done with the overlay
5025 compute_stop_pos (it
);
5026 xassert (it
->face_id
>= 0);
5028 /* Save IT's settings. They are restored after all overlay
5029 strings have been processed. */
5030 xassert (!compute_stop_p
|| it
->sp
== 0);
5032 /* When called from handle_stop, there might be an empty display
5033 string loaded. In that case, don't bother saving it. */
5034 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5037 /* Set up IT to deliver display elements from the first overlay
5039 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5040 it
->string
= it
->overlay_strings
[0];
5041 it
->from_overlay
= Qnil
;
5042 it
->stop_charpos
= 0;
5043 xassert (STRINGP (it
->string
));
5044 it
->end_charpos
= SCHARS (it
->string
);
5045 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5046 it
->method
= GET_FROM_STRING
;
5050 it
->current
.overlay_string_index
= -1;
5055 get_overlay_strings (it
, charpos
)
5060 it
->method
= GET_FROM_BUFFER
;
5062 (void) get_overlay_strings_1 (it
, charpos
, 1);
5066 /* Value is non-zero if we found at least one overlay string. */
5067 return STRINGP (it
->string
);
5072 /***********************************************************************
5073 Saving and restoring state
5074 ***********************************************************************/
5076 /* Save current settings of IT on IT->stack. Called, for example,
5077 before setting up IT for an overlay string, to be able to restore
5078 IT's settings to what they were after the overlay string has been
5085 struct iterator_stack_entry
*p
;
5087 xassert (it
->sp
< IT_STACK_SIZE
);
5088 p
= it
->stack
+ it
->sp
;
5090 p
->stop_charpos
= it
->stop_charpos
;
5091 p
->cmp_it
= it
->cmp_it
;
5092 xassert (it
->face_id
>= 0);
5093 p
->face_id
= it
->face_id
;
5094 p
->string
= it
->string
;
5095 p
->method
= it
->method
;
5096 p
->from_overlay
= it
->from_overlay
;
5099 case GET_FROM_IMAGE
:
5100 p
->u
.image
.object
= it
->object
;
5101 p
->u
.image
.image_id
= it
->image_id
;
5102 p
->u
.image
.slice
= it
->slice
;
5104 case GET_FROM_STRETCH
:
5105 p
->u
.stretch
.object
= it
->object
;
5108 p
->position
= it
->position
;
5109 p
->current
= it
->current
;
5110 p
->end_charpos
= it
->end_charpos
;
5111 p
->string_nchars
= it
->string_nchars
;
5113 p
->multibyte_p
= it
->multibyte_p
;
5114 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5115 p
->space_width
= it
->space_width
;
5116 p
->font_height
= it
->font_height
;
5117 p
->voffset
= it
->voffset
;
5118 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5119 p
->display_ellipsis_p
= 0;
5120 p
->line_wrap
= it
->line_wrap
;
5125 /* Restore IT's settings from IT->stack. Called, for example, when no
5126 more overlay strings must be processed, and we return to delivering
5127 display elements from a buffer, or when the end of a string from a
5128 `display' property is reached and we return to delivering display
5129 elements from an overlay string, or from a buffer. */
5135 struct iterator_stack_entry
*p
;
5137 xassert (it
->sp
> 0);
5139 p
= it
->stack
+ it
->sp
;
5140 it
->stop_charpos
= p
->stop_charpos
;
5141 it
->cmp_it
= p
->cmp_it
;
5142 it
->face_id
= p
->face_id
;
5143 it
->current
= p
->current
;
5144 it
->position
= p
->position
;
5145 it
->string
= p
->string
;
5146 it
->from_overlay
= p
->from_overlay
;
5147 if (NILP (it
->string
))
5148 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5149 it
->method
= p
->method
;
5152 case GET_FROM_IMAGE
:
5153 it
->image_id
= p
->u
.image
.image_id
;
5154 it
->object
= p
->u
.image
.object
;
5155 it
->slice
= p
->u
.image
.slice
;
5157 case GET_FROM_STRETCH
:
5158 it
->object
= p
->u
.comp
.object
;
5160 case GET_FROM_BUFFER
:
5161 it
->object
= it
->w
->buffer
;
5163 case GET_FROM_STRING
:
5164 it
->object
= it
->string
;
5166 case GET_FROM_DISPLAY_VECTOR
:
5168 it
->method
= GET_FROM_C_STRING
;
5169 else if (STRINGP (it
->string
))
5170 it
->method
= GET_FROM_STRING
;
5173 it
->method
= GET_FROM_BUFFER
;
5174 it
->object
= it
->w
->buffer
;
5177 it
->end_charpos
= p
->end_charpos
;
5178 it
->string_nchars
= p
->string_nchars
;
5180 it
->multibyte_p
= p
->multibyte_p
;
5181 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5182 it
->space_width
= p
->space_width
;
5183 it
->font_height
= p
->font_height
;
5184 it
->voffset
= p
->voffset
;
5185 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5186 it
->line_wrap
= p
->line_wrap
;
5191 /***********************************************************************
5193 ***********************************************************************/
5195 /* Set IT's current position to the previous line start. */
5198 back_to_previous_line_start (it
)
5201 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5202 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5206 /* Move IT to the next line start.
5208 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5209 we skipped over part of the text (as opposed to moving the iterator
5210 continuously over the text). Otherwise, don't change the value
5213 Newlines may come from buffer text, overlay strings, or strings
5214 displayed via the `display' property. That's the reason we can't
5215 simply use find_next_newline_no_quit.
5217 Note that this function may not skip over invisible text that is so
5218 because of text properties and immediately follows a newline. If
5219 it would, function reseat_at_next_visible_line_start, when called
5220 from set_iterator_to_next, would effectively make invisible
5221 characters following a newline part of the wrong glyph row, which
5222 leads to wrong cursor motion. */
5225 forward_to_next_line_start (it
, skipped_p
)
5229 int old_selective
, newline_found_p
, n
;
5230 const int MAX_NEWLINE_DISTANCE
= 500;
5232 /* If already on a newline, just consume it to avoid unintended
5233 skipping over invisible text below. */
5234 if (it
->what
== IT_CHARACTER
5236 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5238 set_iterator_to_next (it
, 0);
5243 /* Don't handle selective display in the following. It's (a)
5244 unnecessary because it's done by the caller, and (b) leads to an
5245 infinite recursion because next_element_from_ellipsis indirectly
5246 calls this function. */
5247 old_selective
= it
->selective
;
5250 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5251 from buffer text. */
5252 for (n
= newline_found_p
= 0;
5253 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5254 n
+= STRINGP (it
->string
) ? 0 : 1)
5256 if (!get_next_display_element (it
))
5258 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5259 set_iterator_to_next (it
, 0);
5262 /* If we didn't find a newline near enough, see if we can use a
5264 if (!newline_found_p
)
5266 int start
= IT_CHARPOS (*it
);
5267 int limit
= find_next_newline_no_quit (start
, 1);
5270 xassert (!STRINGP (it
->string
));
5272 /* If there isn't any `display' property in sight, and no
5273 overlays, we can just use the position of the newline in
5275 if (it
->stop_charpos
>= limit
5276 || ((pos
= Fnext_single_property_change (make_number (start
),
5278 Qnil
, make_number (limit
)),
5280 && next_overlay_change (start
) == ZV
))
5282 IT_CHARPOS (*it
) = limit
;
5283 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5284 *skipped_p
= newline_found_p
= 1;
5288 while (get_next_display_element (it
)
5289 && !newline_found_p
)
5291 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5292 set_iterator_to_next (it
, 0);
5297 it
->selective
= old_selective
;
5298 return newline_found_p
;
5302 /* Set IT's current position to the previous visible line start. Skip
5303 invisible text that is so either due to text properties or due to
5304 selective display. Caution: this does not change IT->current_x and
5308 back_to_previous_visible_line_start (it
)
5311 while (IT_CHARPOS (*it
) > BEGV
)
5313 back_to_previous_line_start (it
);
5315 if (IT_CHARPOS (*it
) <= BEGV
)
5318 /* If selective > 0, then lines indented more than that values
5320 if (it
->selective
> 0
5321 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5322 (double) it
->selective
)) /* iftc */
5325 /* Check the newline before point for invisibility. */
5328 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5329 Qinvisible
, it
->window
);
5330 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5334 if (IT_CHARPOS (*it
) <= BEGV
)
5341 Lisp_Object val
, overlay
;
5343 /* If newline is part of a composition, continue from start of composition */
5344 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5345 && beg
< IT_CHARPOS (*it
))
5348 /* If newline is replaced by a display property, find start of overlay
5349 or interval and continue search from that point. */
5351 pos
= --IT_CHARPOS (it2
);
5354 it2
.string_from_display_prop_p
= 0;
5355 if (handle_display_prop (&it2
) == HANDLED_RETURN
5356 && !NILP (val
= get_char_property_and_overlay
5357 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5358 && (OVERLAYP (overlay
)
5359 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5360 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5363 /* Newline is not replaced by anything -- so we are done. */
5369 IT_CHARPOS (*it
) = beg
;
5370 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5374 it
->continuation_lines_width
= 0;
5376 xassert (IT_CHARPOS (*it
) >= BEGV
);
5377 xassert (IT_CHARPOS (*it
) == BEGV
5378 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5383 /* Reseat iterator IT at the previous visible line start. Skip
5384 invisible text that is so either due to text properties or due to
5385 selective display. At the end, update IT's overlay information,
5386 face information etc. */
5389 reseat_at_previous_visible_line_start (it
)
5392 back_to_previous_visible_line_start (it
);
5393 reseat (it
, it
->current
.pos
, 1);
5398 /* Reseat iterator IT on the next visible line start in the current
5399 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5400 preceding the line start. Skip over invisible text that is so
5401 because of selective display. Compute faces, overlays etc at the
5402 new position. Note that this function does not skip over text that
5403 is invisible because of text properties. */
5406 reseat_at_next_visible_line_start (it
, on_newline_p
)
5410 int newline_found_p
, skipped_p
= 0;
5412 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5414 /* Skip over lines that are invisible because they are indented
5415 more than the value of IT->selective. */
5416 if (it
->selective
> 0)
5417 while (IT_CHARPOS (*it
) < ZV
5418 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5419 (double) it
->selective
)) /* iftc */
5421 xassert (IT_BYTEPOS (*it
) == BEGV
5422 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5423 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5426 /* Position on the newline if that's what's requested. */
5427 if (on_newline_p
&& newline_found_p
)
5429 if (STRINGP (it
->string
))
5431 if (IT_STRING_CHARPOS (*it
) > 0)
5433 --IT_STRING_CHARPOS (*it
);
5434 --IT_STRING_BYTEPOS (*it
);
5437 else if (IT_CHARPOS (*it
) > BEGV
)
5441 reseat (it
, it
->current
.pos
, 0);
5445 reseat (it
, it
->current
.pos
, 0);
5452 /***********************************************************************
5453 Changing an iterator's position
5454 ***********************************************************************/
5456 /* Change IT's current position to POS in current_buffer. If FORCE_P
5457 is non-zero, always check for text properties at the new position.
5458 Otherwise, text properties are only looked up if POS >=
5459 IT->check_charpos of a property. */
5462 reseat (it
, pos
, force_p
)
5464 struct text_pos pos
;
5467 int original_pos
= IT_CHARPOS (*it
);
5469 reseat_1 (it
, pos
, 0);
5471 /* Determine where to check text properties. Avoid doing it
5472 where possible because text property lookup is very expensive. */
5474 || CHARPOS (pos
) > it
->stop_charpos
5475 || CHARPOS (pos
) < original_pos
)
5482 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5483 IT->stop_pos to POS, also. */
5486 reseat_1 (it
, pos
, set_stop_p
)
5488 struct text_pos pos
;
5491 /* Don't call this function when scanning a C string. */
5492 xassert (it
->s
== NULL
);
5494 /* POS must be a reasonable value. */
5495 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5497 it
->current
.pos
= it
->position
= pos
;
5498 it
->end_charpos
= ZV
;
5500 it
->current
.dpvec_index
= -1;
5501 it
->current
.overlay_string_index
= -1;
5502 IT_STRING_CHARPOS (*it
) = -1;
5503 IT_STRING_BYTEPOS (*it
) = -1;
5505 it
->string_from_display_prop_p
= 0;
5506 it
->method
= GET_FROM_BUFFER
;
5507 it
->object
= it
->w
->buffer
;
5508 it
->area
= TEXT_AREA
;
5509 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5511 it
->string_from_display_prop_p
= 0;
5512 it
->face_before_selective_p
= 0;
5515 it
->stop_charpos
= CHARPOS (pos
);
5519 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5520 If S is non-null, it is a C string to iterate over. Otherwise,
5521 STRING gives a Lisp string to iterate over.
5523 If PRECISION > 0, don't return more then PRECISION number of
5524 characters from the string.
5526 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5527 characters have been returned. FIELD_WIDTH < 0 means an infinite
5530 MULTIBYTE = 0 means disable processing of multibyte characters,
5531 MULTIBYTE > 0 means enable it,
5532 MULTIBYTE < 0 means use IT->multibyte_p.
5534 IT must be initialized via a prior call to init_iterator before
5535 calling this function. */
5538 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5543 int precision
, field_width
, multibyte
;
5545 /* No region in strings. */
5546 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5548 /* No text property checks performed by default, but see below. */
5549 it
->stop_charpos
= -1;
5551 /* Set iterator position and end position. */
5552 bzero (&it
->current
, sizeof it
->current
);
5553 it
->current
.overlay_string_index
= -1;
5554 it
->current
.dpvec_index
= -1;
5555 xassert (charpos
>= 0);
5557 /* If STRING is specified, use its multibyteness, otherwise use the
5558 setting of MULTIBYTE, if specified. */
5560 it
->multibyte_p
= multibyte
> 0;
5564 xassert (STRINGP (string
));
5565 it
->string
= string
;
5567 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5568 it
->method
= GET_FROM_STRING
;
5569 it
->current
.string_pos
= string_pos (charpos
, string
);
5576 /* Note that we use IT->current.pos, not it->current.string_pos,
5577 for displaying C strings. */
5578 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5579 if (it
->multibyte_p
)
5581 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5582 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5586 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5587 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5590 it
->method
= GET_FROM_C_STRING
;
5593 /* PRECISION > 0 means don't return more than PRECISION characters
5595 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5596 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5598 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5599 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5600 FIELD_WIDTH < 0 means infinite field width. This is useful for
5601 padding with `-' at the end of a mode line. */
5602 if (field_width
< 0)
5603 field_width
= INFINITY
;
5604 if (field_width
> it
->end_charpos
- charpos
)
5605 it
->end_charpos
= charpos
+ field_width
;
5607 /* Use the standard display table for displaying strings. */
5608 if (DISP_TABLE_P (Vstandard_display_table
))
5609 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5611 it
->stop_charpos
= charpos
;
5612 if (s
== NULL
&& it
->multibyte_p
)
5614 EMACS_INT endpos
= SCHARS (it
->string
);
5615 if (endpos
> it
->end_charpos
)
5616 endpos
= it
->end_charpos
;
5617 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5625 /***********************************************************************
5627 ***********************************************************************/
5629 /* Map enum it_method value to corresponding next_element_from_* function. */
5631 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5633 next_element_from_buffer
,
5634 next_element_from_display_vector
,
5635 next_element_from_string
,
5636 next_element_from_c_string
,
5637 next_element_from_image
,
5638 next_element_from_stretch
5641 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5644 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5645 (possibly with the following characters). */
5647 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5648 ((IT)->cmp_it.id >= 0 \
5649 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5650 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5651 END_CHARPOS, (IT)->w, \
5652 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5656 /* Load IT's display element fields with information about the next
5657 display element from the current position of IT. Value is zero if
5658 end of buffer (or C string) is reached. */
5660 static struct frame
*last_escape_glyph_frame
= NULL
;
5661 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5662 static int last_escape_glyph_merged_face_id
= 0;
5665 get_next_display_element (it
)
5668 /* Non-zero means that we found a display element. Zero means that
5669 we hit the end of what we iterate over. Performance note: the
5670 function pointer `method' used here turns out to be faster than
5671 using a sequence of if-statements. */
5675 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5677 if (it
->what
== IT_CHARACTER
)
5679 /* Map via display table or translate control characters.
5680 IT->c, IT->len etc. have been set to the next character by
5681 the function call above. If we have a display table, and it
5682 contains an entry for IT->c, translate it. Don't do this if
5683 IT->c itself comes from a display table, otherwise we could
5684 end up in an infinite recursion. (An alternative could be to
5685 count the recursion depth of this function and signal an
5686 error when a certain maximum depth is reached.) Is it worth
5688 if (success_p
&& it
->dpvec
== NULL
)
5691 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5692 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5693 nbsp_or_shy
= char_is_other
;
5694 int decoded
= it
->c
;
5697 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5700 struct Lisp_Vector
*v
= XVECTOR (dv
);
5702 /* Return the first character from the display table
5703 entry, if not empty. If empty, don't display the
5704 current character. */
5707 it
->dpvec_char_len
= it
->len
;
5708 it
->dpvec
= v
->contents
;
5709 it
->dpend
= v
->contents
+ v
->size
;
5710 it
->current
.dpvec_index
= 0;
5711 it
->dpvec_face_id
= -1;
5712 it
->saved_face_id
= it
->face_id
;
5713 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5718 set_iterator_to_next (it
, 0);
5723 if (unibyte_display_via_language_environment
5724 && !ASCII_CHAR_P (it
->c
))
5725 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5727 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5729 if (it
->multibyte_p
)
5730 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5731 : it
->c
== 0xAD ? char_is_soft_hyphen
5733 else if (unibyte_display_via_language_environment
)
5734 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5735 : decoded
== 0xAD ? char_is_soft_hyphen
5739 /* Translate control characters into `\003' or `^C' form.
5740 Control characters coming from a display table entry are
5741 currently not translated because we use IT->dpvec to hold
5742 the translation. This could easily be changed but I
5743 don't believe that it is worth doing.
5745 If it->multibyte_p is nonzero, non-printable non-ASCII
5746 characters are also translated to octal form.
5748 If it->multibyte_p is zero, eight-bit characters that
5749 don't have corresponding multibyte char code are also
5750 translated to octal form. */
5752 ? (it
->area
!= TEXT_AREA
5753 /* In mode line, treat \n, \t like other crl chars. */
5756 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5757 || (it
->c
!= '\n' && it
->c
!= '\t'))
5760 ? ! CHAR_PRINTABLE_P (it
->c
)
5761 : (! unibyte_display_via_language_environment
5763 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5765 /* IT->c is a control character which must be displayed
5766 either as '\003' or as `^C' where the '\\' and '^'
5767 can be defined in the display table. Fill
5768 IT->ctl_chars with glyphs for what we have to
5769 display. Then, set IT->dpvec to these glyphs. */
5772 int face_id
, lface_id
= 0 ;
5775 /* Handle control characters with ^. */
5777 if (it
->c
< 128 && it
->ctl_arrow_p
)
5781 g
= '^'; /* default glyph for Control */
5782 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5784 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5785 && GLYPH_CODE_CHAR_VALID_P (gc
))
5787 g
= GLYPH_CODE_CHAR (gc
);
5788 lface_id
= GLYPH_CODE_FACE (gc
);
5792 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5794 else if (it
->f
== last_escape_glyph_frame
5795 && it
->face_id
== last_escape_glyph_face_id
)
5797 face_id
= last_escape_glyph_merged_face_id
;
5801 /* Merge the escape-glyph face into the current face. */
5802 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5804 last_escape_glyph_frame
= it
->f
;
5805 last_escape_glyph_face_id
= it
->face_id
;
5806 last_escape_glyph_merged_face_id
= face_id
;
5809 XSETINT (it
->ctl_chars
[0], g
);
5810 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5812 goto display_control
;
5815 /* Handle non-break space in the mode where it only gets
5818 if (EQ (Vnobreak_char_display
, Qt
)
5819 && nbsp_or_shy
== char_is_nbsp
)
5821 /* Merge the no-break-space face into the current face. */
5822 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5826 XSETINT (it
->ctl_chars
[0], ' ');
5828 goto display_control
;
5831 /* Handle sequences that start with the "escape glyph". */
5833 /* the default escape glyph is \. */
5834 escape_glyph
= '\\';
5837 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5838 && GLYPH_CODE_CHAR_VALID_P (gc
))
5840 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5841 lface_id
= GLYPH_CODE_FACE (gc
);
5845 /* The display table specified a face.
5846 Merge it into face_id and also into escape_glyph. */
5847 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5850 else if (it
->f
== last_escape_glyph_frame
5851 && it
->face_id
== last_escape_glyph_face_id
)
5853 face_id
= last_escape_glyph_merged_face_id
;
5857 /* Merge the escape-glyph face into the current face. */
5858 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5860 last_escape_glyph_frame
= it
->f
;
5861 last_escape_glyph_face_id
= it
->face_id
;
5862 last_escape_glyph_merged_face_id
= face_id
;
5865 /* Handle soft hyphens in the mode where they only get
5868 if (EQ (Vnobreak_char_display
, Qt
)
5869 && nbsp_or_shy
== char_is_soft_hyphen
)
5872 XSETINT (it
->ctl_chars
[0], '-');
5874 goto display_control
;
5877 /* Handle non-break space and soft hyphen
5878 with the escape glyph. */
5882 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5883 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5884 XSETINT (it
->ctl_chars
[1], it
->c
);
5886 goto display_control
;
5890 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5894 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5895 if (CHAR_BYTE8_P (it
->c
))
5897 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5900 else if (it
->c
< 256)
5907 /* It's an invalid character, which shouldn't
5908 happen actually, but due to bugs it may
5909 happen. Let's print the char as is, there's
5910 not much meaningful we can do with it. */
5912 str
[1] = it
->c
>> 8;
5913 str
[2] = it
->c
>> 16;
5914 str
[3] = it
->c
>> 24;
5918 for (i
= 0; i
< len
; i
++)
5921 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5922 /* Insert three more glyphs into IT->ctl_chars for
5923 the octal display of the character. */
5924 g
= ((str
[i
] >> 6) & 7) + '0';
5925 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5926 g
= ((str
[i
] >> 3) & 7) + '0';
5927 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5928 g
= (str
[i
] & 7) + '0';
5929 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5935 /* Set up IT->dpvec and return first character from it. */
5936 it
->dpvec_char_len
= it
->len
;
5937 it
->dpvec
= it
->ctl_chars
;
5938 it
->dpend
= it
->dpvec
+ ctl_len
;
5939 it
->current
.dpvec_index
= 0;
5940 it
->dpvec_face_id
= face_id
;
5941 it
->saved_face_id
= it
->face_id
;
5942 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5949 #ifdef HAVE_WINDOW_SYSTEM
5950 /* Adjust face id for a multibyte character. There are no multibyte
5951 character in unibyte text. */
5952 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5955 && FRAME_WINDOW_P (it
->f
))
5957 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5959 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5961 /* Automatic composition with glyph-string. */
5962 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5964 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5968 int pos
= (it
->s
? -1
5969 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5970 : IT_CHARPOS (*it
));
5972 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5977 /* Is this character the last one of a run of characters with
5978 box? If yes, set IT->end_of_box_run_p to 1. */
5982 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5984 int face_id
= underlying_face_id (it
);
5985 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5989 if (face
->box
== FACE_NO_BOX
)
5991 /* If the box comes from face properties in a
5992 display string, check faces in that string. */
5993 int string_face_id
= face_after_it_pos (it
);
5994 it
->end_of_box_run_p
5995 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5998 /* Otherwise, the box comes from the underlying face.
5999 If this is the last string character displayed, check
6000 the next buffer location. */
6001 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6002 && (it
->current
.overlay_string_index
6003 == it
->n_overlay_strings
- 1))
6007 struct text_pos pos
= it
->current
.pos
;
6008 INC_TEXT_POS (pos
, it
->multibyte_p
);
6010 next_face_id
= face_at_buffer_position
6011 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6012 it
->region_end_charpos
, &ignore
,
6013 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6015 it
->end_of_box_run_p
6016 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6023 int face_id
= face_after_it_pos (it
);
6024 it
->end_of_box_run_p
6025 = (face_id
!= it
->face_id
6026 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6030 /* Value is 0 if end of buffer or string reached. */
6035 /* Move IT to the next display element.
6037 RESEAT_P non-zero means if called on a newline in buffer text,
6038 skip to the next visible line start.
6040 Functions get_next_display_element and set_iterator_to_next are
6041 separate because I find this arrangement easier to handle than a
6042 get_next_display_element function that also increments IT's
6043 position. The way it is we can first look at an iterator's current
6044 display element, decide whether it fits on a line, and if it does,
6045 increment the iterator position. The other way around we probably
6046 would either need a flag indicating whether the iterator has to be
6047 incremented the next time, or we would have to implement a
6048 decrement position function which would not be easy to write. */
6051 set_iterator_to_next (it
, reseat_p
)
6055 /* Reset flags indicating start and end of a sequence of characters
6056 with box. Reset them at the start of this function because
6057 moving the iterator to a new position might set them. */
6058 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6062 case GET_FROM_BUFFER
:
6063 /* The current display element of IT is a character from
6064 current_buffer. Advance in the buffer, and maybe skip over
6065 invisible lines that are so because of selective display. */
6066 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6067 reseat_at_next_visible_line_start (it
, 0);
6068 else if (it
->cmp_it
.id
>= 0)
6070 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6071 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6072 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6073 it
->cmp_it
.from
= it
->cmp_it
.to
;
6077 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6078 IT_BYTEPOS (*it
), it
->stop_charpos
,
6084 xassert (it
->len
!= 0);
6085 IT_BYTEPOS (*it
) += it
->len
;
6086 IT_CHARPOS (*it
) += 1;
6087 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6091 case GET_FROM_C_STRING
:
6092 /* Current display element of IT is from a C string. */
6093 IT_BYTEPOS (*it
) += it
->len
;
6094 IT_CHARPOS (*it
) += 1;
6097 case GET_FROM_DISPLAY_VECTOR
:
6098 /* Current display element of IT is from a display table entry.
6099 Advance in the display table definition. Reset it to null if
6100 end reached, and continue with characters from buffers/
6102 ++it
->current
.dpvec_index
;
6104 /* Restore face of the iterator to what they were before the
6105 display vector entry (these entries may contain faces). */
6106 it
->face_id
= it
->saved_face_id
;
6108 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6110 int recheck_faces
= it
->ellipsis_p
;
6113 it
->method
= GET_FROM_C_STRING
;
6114 else if (STRINGP (it
->string
))
6115 it
->method
= GET_FROM_STRING
;
6118 it
->method
= GET_FROM_BUFFER
;
6119 it
->object
= it
->w
->buffer
;
6123 it
->current
.dpvec_index
= -1;
6125 /* Skip over characters which were displayed via IT->dpvec. */
6126 if (it
->dpvec_char_len
< 0)
6127 reseat_at_next_visible_line_start (it
, 1);
6128 else if (it
->dpvec_char_len
> 0)
6130 if (it
->method
== GET_FROM_STRING
6131 && it
->n_overlay_strings
> 0)
6132 it
->ignore_overlay_strings_at_pos_p
= 1;
6133 it
->len
= it
->dpvec_char_len
;
6134 set_iterator_to_next (it
, reseat_p
);
6137 /* Maybe recheck faces after display vector */
6139 it
->stop_charpos
= IT_CHARPOS (*it
);
6143 case GET_FROM_STRING
:
6144 /* Current display element is a character from a Lisp string. */
6145 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6146 if (it
->cmp_it
.id
>= 0)
6148 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6149 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6150 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6151 it
->cmp_it
.from
= it
->cmp_it
.to
;
6155 composition_compute_stop_pos (&it
->cmp_it
,
6156 IT_STRING_CHARPOS (*it
),
6157 IT_STRING_BYTEPOS (*it
),
6158 it
->stop_charpos
, it
->string
);
6163 IT_STRING_BYTEPOS (*it
) += it
->len
;
6164 IT_STRING_CHARPOS (*it
) += 1;
6167 consider_string_end
:
6169 if (it
->current
.overlay_string_index
>= 0)
6171 /* IT->string is an overlay string. Advance to the
6172 next, if there is one. */
6173 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6176 next_overlay_string (it
);
6178 setup_for_ellipsis (it
, 0);
6183 /* IT->string is not an overlay string. If we reached
6184 its end, and there is something on IT->stack, proceed
6185 with what is on the stack. This can be either another
6186 string, this time an overlay string, or a buffer. */
6187 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6191 if (it
->method
== GET_FROM_STRING
)
6192 goto consider_string_end
;
6197 case GET_FROM_IMAGE
:
6198 case GET_FROM_STRETCH
:
6199 /* The position etc with which we have to proceed are on
6200 the stack. The position may be at the end of a string,
6201 if the `display' property takes up the whole string. */
6202 xassert (it
->sp
> 0);
6204 if (it
->method
== GET_FROM_STRING
)
6205 goto consider_string_end
;
6209 /* There are no other methods defined, so this should be a bug. */
6213 xassert (it
->method
!= GET_FROM_STRING
6214 || (STRINGP (it
->string
)
6215 && IT_STRING_CHARPOS (*it
) >= 0));
6218 /* Load IT's display element fields with information about the next
6219 display element which comes from a display table entry or from the
6220 result of translating a control character to one of the forms `^C'
6223 IT->dpvec holds the glyphs to return as characters.
6224 IT->saved_face_id holds the face id before the display vector--it
6225 is restored into IT->face_id in set_iterator_to_next. */
6228 next_element_from_display_vector (it
)
6234 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6236 it
->face_id
= it
->saved_face_id
;
6238 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6239 That seemed totally bogus - so I changed it... */
6240 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6242 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6244 it
->c
= GLYPH_CODE_CHAR (gc
);
6245 it
->len
= CHAR_BYTES (it
->c
);
6247 /* The entry may contain a face id to use. Such a face id is
6248 the id of a Lisp face, not a realized face. A face id of
6249 zero means no face is specified. */
6250 if (it
->dpvec_face_id
>= 0)
6251 it
->face_id
= it
->dpvec_face_id
;
6254 int lface_id
= GLYPH_CODE_FACE (gc
);
6256 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6261 /* Display table entry is invalid. Return a space. */
6262 it
->c
= ' ', it
->len
= 1;
6264 /* Don't change position and object of the iterator here. They are
6265 still the values of the character that had this display table
6266 entry or was translated, and that's what we want. */
6267 it
->what
= IT_CHARACTER
;
6272 /* Load IT with the next display element from Lisp string IT->string.
6273 IT->current.string_pos is the current position within the string.
6274 If IT->current.overlay_string_index >= 0, the Lisp string is an
6278 next_element_from_string (it
)
6281 struct text_pos position
;
6283 xassert (STRINGP (it
->string
));
6284 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6285 position
= it
->current
.string_pos
;
6287 /* Time to check for invisible text? */
6288 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6289 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6293 /* Since a handler may have changed IT->method, we must
6295 return GET_NEXT_DISPLAY_ELEMENT (it
);
6298 if (it
->current
.overlay_string_index
>= 0)
6300 /* Get the next character from an overlay string. In overlay
6301 strings, There is no field width or padding with spaces to
6303 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6308 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6309 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6310 && next_element_from_composition (it
))
6314 else if (STRING_MULTIBYTE (it
->string
))
6316 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6317 const unsigned char *s
= (SDATA (it
->string
)
6318 + IT_STRING_BYTEPOS (*it
));
6319 it
->c
= string_char_and_length (s
, &it
->len
);
6323 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6329 /* Get the next character from a Lisp string that is not an
6330 overlay string. Such strings come from the mode line, for
6331 example. We may have to pad with spaces, or truncate the
6332 string. See also next_element_from_c_string. */
6333 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6338 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6340 /* Pad with spaces. */
6341 it
->c
= ' ', it
->len
= 1;
6342 CHARPOS (position
) = BYTEPOS (position
) = -1;
6344 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6345 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6346 && next_element_from_composition (it
))
6350 else if (STRING_MULTIBYTE (it
->string
))
6352 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6353 const unsigned char *s
= (SDATA (it
->string
)
6354 + IT_STRING_BYTEPOS (*it
));
6355 it
->c
= string_char_and_length (s
, &it
->len
);
6359 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6364 /* Record what we have and where it came from. */
6365 it
->what
= IT_CHARACTER
;
6366 it
->object
= it
->string
;
6367 it
->position
= position
;
6372 /* Load IT with next display element from C string IT->s.
6373 IT->string_nchars is the maximum number of characters to return
6374 from the string. IT->end_charpos may be greater than
6375 IT->string_nchars when this function is called, in which case we
6376 may have to return padding spaces. Value is zero if end of string
6377 reached, including padding spaces. */
6380 next_element_from_c_string (it
)
6386 it
->what
= IT_CHARACTER
;
6387 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6390 /* IT's position can be greater IT->string_nchars in case a field
6391 width or precision has been specified when the iterator was
6393 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6395 /* End of the game. */
6399 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6401 /* Pad with spaces. */
6402 it
->c
= ' ', it
->len
= 1;
6403 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6405 else if (it
->multibyte_p
)
6407 /* Implementation note: The calls to strlen apparently aren't a
6408 performance problem because there is no noticeable performance
6409 difference between Emacs running in unibyte or multibyte mode. */
6410 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6411 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6414 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6420 /* Set up IT to return characters from an ellipsis, if appropriate.
6421 The definition of the ellipsis glyphs may come from a display table
6422 entry. This function fills IT with the first glyph from the
6423 ellipsis if an ellipsis is to be displayed. */
6426 next_element_from_ellipsis (it
)
6429 if (it
->selective_display_ellipsis_p
)
6430 setup_for_ellipsis (it
, it
->len
);
6433 /* The face at the current position may be different from the
6434 face we find after the invisible text. Remember what it
6435 was in IT->saved_face_id, and signal that it's there by
6436 setting face_before_selective_p. */
6437 it
->saved_face_id
= it
->face_id
;
6438 it
->method
= GET_FROM_BUFFER
;
6439 it
->object
= it
->w
->buffer
;
6440 reseat_at_next_visible_line_start (it
, 1);
6441 it
->face_before_selective_p
= 1;
6444 return GET_NEXT_DISPLAY_ELEMENT (it
);
6448 /* Deliver an image display element. The iterator IT is already
6449 filled with image information (done in handle_display_prop). Value
6454 next_element_from_image (it
)
6457 it
->what
= IT_IMAGE
;
6462 /* Fill iterator IT with next display element from a stretch glyph
6463 property. IT->object is the value of the text property. Value is
6467 next_element_from_stretch (it
)
6470 it
->what
= IT_STRETCH
;
6475 /* Load IT with the next display element from current_buffer. Value
6476 is zero if end of buffer reached. IT->stop_charpos is the next
6477 position at which to stop and check for text properties or buffer
6481 next_element_from_buffer (it
)
6486 xassert (IT_CHARPOS (*it
) >= BEGV
);
6488 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6490 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6492 int overlay_strings_follow_p
;
6494 /* End of the game, except when overlay strings follow that
6495 haven't been returned yet. */
6496 if (it
->overlay_strings_at_end_processed_p
)
6497 overlay_strings_follow_p
= 0;
6500 it
->overlay_strings_at_end_processed_p
= 1;
6501 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6504 if (overlay_strings_follow_p
)
6505 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6509 it
->position
= it
->current
.pos
;
6516 return GET_NEXT_DISPLAY_ELEMENT (it
);
6521 /* No face changes, overlays etc. in sight, so just return a
6522 character from current_buffer. */
6525 /* Maybe run the redisplay end trigger hook. Performance note:
6526 This doesn't seem to cost measurable time. */
6527 if (it
->redisplay_end_trigger_charpos
6529 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6530 run_redisplay_end_trigger_hook (it
);
6532 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6534 && next_element_from_composition (it
))
6539 /* Get the next character, maybe multibyte. */
6540 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6541 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6542 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6544 it
->c
= *p
, it
->len
= 1;
6546 /* Record what we have and where it came from. */
6547 it
->what
= IT_CHARACTER
;
6548 it
->object
= it
->w
->buffer
;
6549 it
->position
= it
->current
.pos
;
6551 /* Normally we return the character found above, except when we
6552 really want to return an ellipsis for selective display. */
6557 /* A value of selective > 0 means hide lines indented more
6558 than that number of columns. */
6559 if (it
->selective
> 0
6560 && IT_CHARPOS (*it
) + 1 < ZV
6561 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6562 IT_BYTEPOS (*it
) + 1,
6563 (double) it
->selective
)) /* iftc */
6565 success_p
= next_element_from_ellipsis (it
);
6566 it
->dpvec_char_len
= -1;
6569 else if (it
->c
== '\r' && it
->selective
== -1)
6571 /* A value of selective == -1 means that everything from the
6572 CR to the end of the line is invisible, with maybe an
6573 ellipsis displayed for it. */
6574 success_p
= next_element_from_ellipsis (it
);
6575 it
->dpvec_char_len
= -1;
6580 /* Value is zero if end of buffer reached. */
6581 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6586 /* Run the redisplay end trigger hook for IT. */
6589 run_redisplay_end_trigger_hook (it
)
6592 Lisp_Object args
[3];
6594 /* IT->glyph_row should be non-null, i.e. we should be actually
6595 displaying something, or otherwise we should not run the hook. */
6596 xassert (it
->glyph_row
);
6598 /* Set up hook arguments. */
6599 args
[0] = Qredisplay_end_trigger_functions
;
6600 args
[1] = it
->window
;
6601 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6602 it
->redisplay_end_trigger_charpos
= 0;
6604 /* Since we are *trying* to run these functions, don't try to run
6605 them again, even if they get an error. */
6606 it
->w
->redisplay_end_trigger
= Qnil
;
6607 Frun_hook_with_args (3, args
);
6609 /* Notice if it changed the face of the character we are on. */
6610 handle_face_prop (it
);
6614 /* Deliver a composition display element. Unlike the other
6615 next_element_from_XXX, this function is not registered in the array
6616 get_next_element[]. It is called from next_element_from_buffer and
6617 next_element_from_string when necessary. */
6620 next_element_from_composition (it
)
6623 it
->what
= IT_COMPOSITION
;
6624 it
->len
= it
->cmp_it
.nbytes
;
6625 if (STRINGP (it
->string
))
6629 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6630 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6633 it
->position
= it
->current
.string_pos
;
6634 it
->object
= it
->string
;
6635 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6636 IT_STRING_BYTEPOS (*it
), it
->string
);
6642 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6643 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6646 it
->position
= it
->current
.pos
;
6647 it
->object
= it
->w
->buffer
;
6648 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6649 IT_BYTEPOS (*it
), Qnil
);
6656 /***********************************************************************
6657 Moving an iterator without producing glyphs
6658 ***********************************************************************/
6660 /* Check if iterator is at a position corresponding to a valid buffer
6661 position after some move_it_ call. */
6663 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6664 ((it)->method == GET_FROM_STRING \
6665 ? IT_STRING_CHARPOS (*it) == 0 \
6669 /* Move iterator IT to a specified buffer or X position within one
6670 line on the display without producing glyphs.
6672 OP should be a bit mask including some or all of these bits:
6673 MOVE_TO_X: Stop on reaching x-position TO_X.
6674 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6675 Regardless of OP's value, stop in reaching the end of the display line.
6677 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6678 This means, in particular, that TO_X includes window's horizontal
6681 The return value has several possible values that
6682 say what condition caused the scan to stop:
6684 MOVE_POS_MATCH_OR_ZV
6685 - when TO_POS or ZV was reached.
6688 -when TO_X was reached before TO_POS or ZV were reached.
6691 - when we reached the end of the display area and the line must
6695 - when we reached the end of the display area and the line is
6699 - when we stopped at a line end, i.e. a newline or a CR and selective
6702 static enum move_it_result
6703 move_it_in_display_line_to (struct it
*it
,
6704 EMACS_INT to_charpos
, int to_x
,
6705 enum move_operation_enum op
)
6707 enum move_it_result result
= MOVE_UNDEFINED
;
6708 struct glyph_row
*saved_glyph_row
;
6709 struct it wrap_it
, atpos_it
, atx_it
;
6712 /* Don't produce glyphs in produce_glyphs. */
6713 saved_glyph_row
= it
->glyph_row
;
6714 it
->glyph_row
= NULL
;
6716 /* Use wrap_it to save a copy of IT wherever a word wrap could
6717 occur. Use atpos_it to save a copy of IT at the desired buffer
6718 position, if found, so that we can scan ahead and check if the
6719 word later overshoots the window edge. Use atx_it similarly, for
6725 #define BUFFER_POS_REACHED_P() \
6726 ((op & MOVE_TO_POS) != 0 \
6727 && BUFFERP (it->object) \
6728 && IT_CHARPOS (*it) >= to_charpos \
6729 && (it->method == GET_FROM_BUFFER \
6730 || (it->method == GET_FROM_DISPLAY_VECTOR \
6731 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6733 /* If there's a line-/wrap-prefix, handle it. */
6734 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6735 && it
->current_y
< it
->last_visible_y
)
6736 handle_line_prefix (it
);
6740 int x
, i
, ascent
= 0, descent
= 0;
6742 /* Utility macro to reset an iterator with x, ascent, and descent. */
6743 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6744 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6745 (IT)->max_descent = descent)
6747 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6749 if ((op
& MOVE_TO_POS
) != 0
6750 && BUFFERP (it
->object
)
6751 && it
->method
== GET_FROM_BUFFER
6752 && IT_CHARPOS (*it
) > to_charpos
)
6754 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6756 result
= MOVE_POS_MATCH_OR_ZV
;
6759 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6760 /* If wrap_it is valid, the current position might be in a
6761 word that is wrapped. So, save the iterator in
6762 atpos_it and continue to see if wrapping happens. */
6766 /* Stop when ZV reached.
6767 We used to stop here when TO_CHARPOS reached as well, but that is
6768 too soon if this glyph does not fit on this line. So we handle it
6769 explicitly below. */
6770 if (!get_next_display_element (it
))
6772 result
= MOVE_POS_MATCH_OR_ZV
;
6776 if (it
->line_wrap
== TRUNCATE
)
6778 if (BUFFER_POS_REACHED_P ())
6780 result
= MOVE_POS_MATCH_OR_ZV
;
6786 if (it
->line_wrap
== WORD_WRAP
)
6788 if (IT_DISPLAYING_WHITESPACE (it
))
6792 /* We have reached a glyph that follows one or more
6793 whitespace characters. If the position is
6794 already found, we are done. */
6795 if (atpos_it
.sp
>= 0)
6798 result
= MOVE_POS_MATCH_OR_ZV
;
6804 result
= MOVE_X_REACHED
;
6807 /* Otherwise, we can wrap here. */
6814 /* Remember the line height for the current line, in case
6815 the next element doesn't fit on the line. */
6816 ascent
= it
->max_ascent
;
6817 descent
= it
->max_descent
;
6819 /* The call to produce_glyphs will get the metrics of the
6820 display element IT is loaded with. Record the x-position
6821 before this display element, in case it doesn't fit on the
6825 PRODUCE_GLYPHS (it
);
6827 if (it
->area
!= TEXT_AREA
)
6829 set_iterator_to_next (it
, 1);
6833 /* The number of glyphs we get back in IT->nglyphs will normally
6834 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6835 character on a terminal frame, or (iii) a line end. For the
6836 second case, IT->nglyphs - 1 padding glyphs will be present.
6837 (On X frames, there is only one glyph produced for a
6838 composite character.)
6840 The behavior implemented below means, for continuation lines,
6841 that as many spaces of a TAB as fit on the current line are
6842 displayed there. For terminal frames, as many glyphs of a
6843 multi-glyph character are displayed in the current line, too.
6844 This is what the old redisplay code did, and we keep it that
6845 way. Under X, the whole shape of a complex character must
6846 fit on the line or it will be completely displayed in the
6849 Note that both for tabs and padding glyphs, all glyphs have
6853 /* More than one glyph or glyph doesn't fit on line. All
6854 glyphs have the same width. */
6855 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6857 int x_before_this_char
= x
;
6858 int hpos_before_this_char
= it
->hpos
;
6860 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6862 new_x
= x
+ single_glyph_width
;
6864 /* We want to leave anything reaching TO_X to the caller. */
6865 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6867 if (BUFFER_POS_REACHED_P ())
6869 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6870 goto buffer_pos_reached
;
6871 if (atpos_it
.sp
< 0)
6874 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6879 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6882 result
= MOVE_X_REACHED
;
6888 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6893 if (/* Lines are continued. */
6894 it
->line_wrap
!= TRUNCATE
6895 && (/* And glyph doesn't fit on the line. */
6896 new_x
> it
->last_visible_x
6897 /* Or it fits exactly and we're on a window
6899 || (new_x
== it
->last_visible_x
6900 && FRAME_WINDOW_P (it
->f
))))
6902 if (/* IT->hpos == 0 means the very first glyph
6903 doesn't fit on the line, e.g. a wide image. */
6905 || (new_x
== it
->last_visible_x
6906 && FRAME_WINDOW_P (it
->f
)))
6909 it
->current_x
= new_x
;
6911 /* The character's last glyph just barely fits
6913 if (i
== it
->nglyphs
- 1)
6915 /* If this is the destination position,
6916 return a position *before* it in this row,
6917 now that we know it fits in this row. */
6918 if (BUFFER_POS_REACHED_P ())
6920 if (it
->line_wrap
!= WORD_WRAP
6923 it
->hpos
= hpos_before_this_char
;
6924 it
->current_x
= x_before_this_char
;
6925 result
= MOVE_POS_MATCH_OR_ZV
;
6928 if (it
->line_wrap
== WORD_WRAP
6932 atpos_it
.current_x
= x_before_this_char
;
6933 atpos_it
.hpos
= hpos_before_this_char
;
6937 set_iterator_to_next (it
, 1);
6938 /* On graphical terminals, newlines may
6939 "overflow" into the fringe if
6940 overflow-newline-into-fringe is non-nil.
6941 On text-only terminals, newlines may
6942 overflow into the last glyph on the
6944 if (!FRAME_WINDOW_P (it
->f
)
6945 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6947 if (!get_next_display_element (it
))
6949 result
= MOVE_POS_MATCH_OR_ZV
;
6952 if (BUFFER_POS_REACHED_P ())
6954 if (ITERATOR_AT_END_OF_LINE_P (it
))
6955 result
= MOVE_POS_MATCH_OR_ZV
;
6957 result
= MOVE_LINE_CONTINUED
;
6960 if (ITERATOR_AT_END_OF_LINE_P (it
))
6962 result
= MOVE_NEWLINE_OR_CR
;
6969 IT_RESET_X_ASCENT_DESCENT (it
);
6971 if (wrap_it
.sp
>= 0)
6978 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6980 result
= MOVE_LINE_CONTINUED
;
6984 if (BUFFER_POS_REACHED_P ())
6986 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6987 goto buffer_pos_reached
;
6988 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6991 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6995 if (new_x
> it
->first_visible_x
)
6997 /* Glyph is visible. Increment number of glyphs that
6998 would be displayed. */
7003 if (result
!= MOVE_UNDEFINED
)
7006 else if (BUFFER_POS_REACHED_P ())
7009 IT_RESET_X_ASCENT_DESCENT (it
);
7010 result
= MOVE_POS_MATCH_OR_ZV
;
7013 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7015 /* Stop when TO_X specified and reached. This check is
7016 necessary here because of lines consisting of a line end,
7017 only. The line end will not produce any glyphs and we
7018 would never get MOVE_X_REACHED. */
7019 xassert (it
->nglyphs
== 0);
7020 result
= MOVE_X_REACHED
;
7024 /* Is this a line end? If yes, we're done. */
7025 if (ITERATOR_AT_END_OF_LINE_P (it
))
7027 result
= MOVE_NEWLINE_OR_CR
;
7031 /* The current display element has been consumed. Advance
7033 set_iterator_to_next (it
, 1);
7035 /* Stop if lines are truncated and IT's current x-position is
7036 past the right edge of the window now. */
7037 if (it
->line_wrap
== TRUNCATE
7038 && it
->current_x
>= it
->last_visible_x
)
7040 if (!FRAME_WINDOW_P (it
->f
)
7041 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7043 if (!get_next_display_element (it
)
7044 || BUFFER_POS_REACHED_P ())
7046 result
= MOVE_POS_MATCH_OR_ZV
;
7049 if (ITERATOR_AT_END_OF_LINE_P (it
))
7051 result
= MOVE_NEWLINE_OR_CR
;
7055 result
= MOVE_LINE_TRUNCATED
;
7058 #undef IT_RESET_X_ASCENT_DESCENT
7061 #undef BUFFER_POS_REACHED_P
7063 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7064 restore the saved iterator. */
7065 if (atpos_it
.sp
>= 0)
7067 else if (atx_it
.sp
>= 0)
7072 /* Restore the iterator settings altered at the beginning of this
7074 it
->glyph_row
= saved_glyph_row
;
7078 /* For external use. */
7080 move_it_in_display_line (struct it
*it
,
7081 EMACS_INT to_charpos
, int to_x
,
7082 enum move_operation_enum op
)
7084 if (it
->line_wrap
== WORD_WRAP
7085 && (op
& MOVE_TO_X
))
7087 struct it save_it
= *it
;
7088 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7089 /* When word-wrap is on, TO_X may lie past the end
7090 of a wrapped line. Then it->current is the
7091 character on the next line, so backtrack to the
7092 space before the wrap point. */
7093 if (skip
== MOVE_LINE_CONTINUED
)
7095 int prev_x
= max (it
->current_x
- 1, 0);
7097 move_it_in_display_line_to
7098 (it
, -1, prev_x
, MOVE_TO_X
);
7102 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7106 /* Move IT forward until it satisfies one or more of the criteria in
7107 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7109 OP is a bit-mask that specifies where to stop, and in particular,
7110 which of those four position arguments makes a difference. See the
7111 description of enum move_operation_enum.
7113 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7114 screen line, this function will set IT to the next position >
7118 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7120 int to_charpos
, to_x
, to_y
, to_vpos
;
7123 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7124 int line_height
, line_start_x
= 0, reached
= 0;
7128 if (op
& MOVE_TO_VPOS
)
7130 /* If no TO_CHARPOS and no TO_X specified, stop at the
7131 start of the line TO_VPOS. */
7132 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7134 if (it
->vpos
== to_vpos
)
7140 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7144 /* TO_VPOS >= 0 means stop at TO_X in the line at
7145 TO_VPOS, or at TO_POS, whichever comes first. */
7146 if (it
->vpos
== to_vpos
)
7152 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7154 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7159 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7161 /* We have reached TO_X but not in the line we want. */
7162 skip
= move_it_in_display_line_to (it
, to_charpos
,
7164 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7172 else if (op
& MOVE_TO_Y
)
7174 struct it it_backup
;
7176 if (it
->line_wrap
== WORD_WRAP
)
7179 /* TO_Y specified means stop at TO_X in the line containing
7180 TO_Y---or at TO_CHARPOS if this is reached first. The
7181 problem is that we can't really tell whether the line
7182 contains TO_Y before we have completely scanned it, and
7183 this may skip past TO_X. What we do is to first scan to
7186 If TO_X is not specified, use a TO_X of zero. The reason
7187 is to make the outcome of this function more predictable.
7188 If we didn't use TO_X == 0, we would stop at the end of
7189 the line which is probably not what a caller would expect
7191 skip
= move_it_in_display_line_to
7192 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7193 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7195 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7196 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7198 else if (skip
== MOVE_X_REACHED
)
7200 /* If TO_X was reached, we want to know whether TO_Y is
7201 in the line. We know this is the case if the already
7202 scanned glyphs make the line tall enough. Otherwise,
7203 we must check by scanning the rest of the line. */
7204 line_height
= it
->max_ascent
+ it
->max_descent
;
7205 if (to_y
>= it
->current_y
7206 && to_y
< it
->current_y
+ line_height
)
7212 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7213 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7215 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7216 line_height
= it
->max_ascent
+ it
->max_descent
;
7217 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7219 if (to_y
>= it
->current_y
7220 && to_y
< it
->current_y
+ line_height
)
7222 /* If TO_Y is in this line and TO_X was reached
7223 above, we scanned too far. We have to restore
7224 IT's settings to the ones before skipping. */
7231 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7237 /* Check whether TO_Y is in this line. */
7238 line_height
= it
->max_ascent
+ it
->max_descent
;
7239 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7241 if (to_y
>= it
->current_y
7242 && to_y
< it
->current_y
+ line_height
)
7244 /* When word-wrap is on, TO_X may lie past the end
7245 of a wrapped line. Then it->current is the
7246 character on the next line, so backtrack to the
7247 space before the wrap point. */
7248 if (skip
== MOVE_LINE_CONTINUED
7249 && it
->line_wrap
== WORD_WRAP
)
7251 int prev_x
= max (it
->current_x
- 1, 0);
7253 skip
= move_it_in_display_line_to
7254 (it
, -1, prev_x
, MOVE_TO_X
);
7263 else if (BUFFERP (it
->object
)
7264 && (it
->method
== GET_FROM_BUFFER
7265 || it
->method
== GET_FROM_STRETCH
)
7266 && IT_CHARPOS (*it
) >= to_charpos
)
7267 skip
= MOVE_POS_MATCH_OR_ZV
;
7269 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7273 case MOVE_POS_MATCH_OR_ZV
:
7277 case MOVE_NEWLINE_OR_CR
:
7278 set_iterator_to_next (it
, 1);
7279 it
->continuation_lines_width
= 0;
7282 case MOVE_LINE_TRUNCATED
:
7283 it
->continuation_lines_width
= 0;
7284 reseat_at_next_visible_line_start (it
, 0);
7285 if ((op
& MOVE_TO_POS
) != 0
7286 && IT_CHARPOS (*it
) > to_charpos
)
7293 case MOVE_LINE_CONTINUED
:
7294 /* For continued lines ending in a tab, some of the glyphs
7295 associated with the tab are displayed on the current
7296 line. Since it->current_x does not include these glyphs,
7297 we use it->last_visible_x instead. */
7300 it
->continuation_lines_width
+= it
->last_visible_x
;
7301 /* When moving by vpos, ensure that the iterator really
7302 advances to the next line (bug#847, bug#969). Fixme:
7303 do we need to do this in other circumstances? */
7304 if (it
->current_x
!= it
->last_visible_x
7305 && (op
& MOVE_TO_VPOS
)
7306 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7308 line_start_x
= it
->current_x
+ it
->pixel_width
7309 - it
->last_visible_x
;
7310 set_iterator_to_next (it
, 0);
7314 it
->continuation_lines_width
+= it
->current_x
;
7321 /* Reset/increment for the next run. */
7322 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7323 it
->current_x
= line_start_x
;
7326 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7328 last_height
= it
->max_ascent
+ it
->max_descent
;
7329 last_max_ascent
= it
->max_ascent
;
7330 it
->max_ascent
= it
->max_descent
= 0;
7335 /* On text terminals, we may stop at the end of a line in the middle
7336 of a multi-character glyph. If the glyph itself is continued,
7337 i.e. it is actually displayed on the next line, don't treat this
7338 stopping point as valid; move to the next line instead (unless
7339 that brings us offscreen). */
7340 if (!FRAME_WINDOW_P (it
->f
)
7342 && IT_CHARPOS (*it
) == to_charpos
7343 && it
->what
== IT_CHARACTER
7345 && it
->line_wrap
== WINDOW_WRAP
7346 && it
->current_x
== it
->last_visible_x
- 1
7349 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7351 it
->continuation_lines_width
+= it
->current_x
;
7352 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7353 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7355 last_height
= it
->max_ascent
+ it
->max_descent
;
7356 last_max_ascent
= it
->max_ascent
;
7359 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7363 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7365 If DY > 0, move IT backward at least that many pixels. DY = 0
7366 means move IT backward to the preceding line start or BEGV. This
7367 function may move over more than DY pixels if IT->current_y - DY
7368 ends up in the middle of a line; in this case IT->current_y will be
7369 set to the top of the line moved to. */
7372 move_it_vertically_backward (it
, dy
)
7383 start_pos
= IT_CHARPOS (*it
);
7385 /* Estimate how many newlines we must move back. */
7386 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7388 /* Set the iterator's position that many lines back. */
7389 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7390 back_to_previous_visible_line_start (it
);
7392 /* Reseat the iterator here. When moving backward, we don't want
7393 reseat to skip forward over invisible text, set up the iterator
7394 to deliver from overlay strings at the new position etc. So,
7395 use reseat_1 here. */
7396 reseat_1 (it
, it
->current
.pos
, 1);
7398 /* We are now surely at a line start. */
7399 it
->current_x
= it
->hpos
= 0;
7400 it
->continuation_lines_width
= 0;
7402 /* Move forward and see what y-distance we moved. First move to the
7403 start of the next line so that we get its height. We need this
7404 height to be able to tell whether we reached the specified
7407 it2
.max_ascent
= it2
.max_descent
= 0;
7410 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7411 MOVE_TO_POS
| MOVE_TO_VPOS
);
7413 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7414 xassert (IT_CHARPOS (*it
) >= BEGV
);
7417 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7418 xassert (IT_CHARPOS (*it
) >= BEGV
);
7419 /* H is the actual vertical distance from the position in *IT
7420 and the starting position. */
7421 h
= it2
.current_y
- it
->current_y
;
7422 /* NLINES is the distance in number of lines. */
7423 nlines
= it2
.vpos
- it
->vpos
;
7425 /* Correct IT's y and vpos position
7426 so that they are relative to the starting point. */
7432 /* DY == 0 means move to the start of the screen line. The
7433 value of nlines is > 0 if continuation lines were involved. */
7435 move_it_by_lines (it
, nlines
, 1);
7439 /* The y-position we try to reach, relative to *IT.
7440 Note that H has been subtracted in front of the if-statement. */
7441 int target_y
= it
->current_y
+ h
- dy
;
7442 int y0
= it3
.current_y
;
7443 int y1
= line_bottom_y (&it3
);
7444 int line_height
= y1
- y0
;
7446 /* If we did not reach target_y, try to move further backward if
7447 we can. If we moved too far backward, try to move forward. */
7448 if (target_y
< it
->current_y
7449 /* This is heuristic. In a window that's 3 lines high, with
7450 a line height of 13 pixels each, recentering with point
7451 on the bottom line will try to move -39/2 = 19 pixels
7452 backward. Try to avoid moving into the first line. */
7453 && (it
->current_y
- target_y
7454 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7455 && IT_CHARPOS (*it
) > BEGV
)
7457 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7458 target_y
- it
->current_y
));
7459 dy
= it
->current_y
- target_y
;
7460 goto move_further_back
;
7462 else if (target_y
>= it
->current_y
+ line_height
7463 && IT_CHARPOS (*it
) < ZV
)
7465 /* Should move forward by at least one line, maybe more.
7467 Note: Calling move_it_by_lines can be expensive on
7468 terminal frames, where compute_motion is used (via
7469 vmotion) to do the job, when there are very long lines
7470 and truncate-lines is nil. That's the reason for
7471 treating terminal frames specially here. */
7473 if (!FRAME_WINDOW_P (it
->f
))
7474 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7479 move_it_by_lines (it
, 1, 1);
7481 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7488 /* Move IT by a specified amount of pixel lines DY. DY negative means
7489 move backwards. DY = 0 means move to start of screen line. At the
7490 end, IT will be on the start of a screen line. */
7493 move_it_vertically (it
, dy
)
7498 move_it_vertically_backward (it
, -dy
);
7501 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7502 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7503 MOVE_TO_POS
| MOVE_TO_Y
);
7504 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7506 /* If buffer ends in ZV without a newline, move to the start of
7507 the line to satisfy the post-condition. */
7508 if (IT_CHARPOS (*it
) == ZV
7510 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7511 move_it_by_lines (it
, 0, 0);
7516 /* Move iterator IT past the end of the text line it is in. */
7519 move_it_past_eol (it
)
7522 enum move_it_result rc
;
7524 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7525 if (rc
== MOVE_NEWLINE_OR_CR
)
7526 set_iterator_to_next (it
, 0);
7530 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7531 negative means move up. DVPOS == 0 means move to the start of the
7532 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7533 NEED_Y_P is zero, IT->current_y will be left unchanged.
7535 Further optimization ideas: If we would know that IT->f doesn't use
7536 a face with proportional font, we could be faster for
7537 truncate-lines nil. */
7540 move_it_by_lines (it
, dvpos
, need_y_p
)
7542 int dvpos
, need_y_p
;
7544 struct position pos
;
7546 /* The commented-out optimization uses vmotion on terminals. This
7547 gives bad results, because elements like it->what, on which
7548 callers such as pos_visible_p rely, aren't updated. */
7549 /* if (!FRAME_WINDOW_P (it->f))
7551 struct text_pos textpos;
7553 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7554 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7555 reseat (it, textpos, 1);
7556 it->vpos += pos.vpos;
7557 it->current_y += pos.vpos;
7563 /* DVPOS == 0 means move to the start of the screen line. */
7564 move_it_vertically_backward (it
, 0);
7565 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7566 /* Let next call to line_bottom_y calculate real line height */
7571 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7572 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7573 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7578 int start_charpos
, i
;
7580 /* Start at the beginning of the screen line containing IT's
7581 position. This may actually move vertically backwards,
7582 in case of overlays, so adjust dvpos accordingly. */
7584 move_it_vertically_backward (it
, 0);
7587 /* Go back -DVPOS visible lines and reseat the iterator there. */
7588 start_charpos
= IT_CHARPOS (*it
);
7589 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7590 back_to_previous_visible_line_start (it
);
7591 reseat (it
, it
->current
.pos
, 1);
7593 /* Move further back if we end up in a string or an image. */
7594 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7596 /* First try to move to start of display line. */
7598 move_it_vertically_backward (it
, 0);
7600 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7602 /* If start of line is still in string or image,
7603 move further back. */
7604 back_to_previous_visible_line_start (it
);
7605 reseat (it
, it
->current
.pos
, 1);
7609 it
->current_x
= it
->hpos
= 0;
7611 /* Above call may have moved too far if continuation lines
7612 are involved. Scan forward and see if it did. */
7614 it2
.vpos
= it2
.current_y
= 0;
7615 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7616 it
->vpos
-= it2
.vpos
;
7617 it
->current_y
-= it2
.current_y
;
7618 it
->current_x
= it
->hpos
= 0;
7620 /* If we moved too far back, move IT some lines forward. */
7621 if (it2
.vpos
> -dvpos
)
7623 int delta
= it2
.vpos
+ dvpos
;
7625 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7626 /* Move back again if we got too far ahead. */
7627 if (IT_CHARPOS (*it
) >= start_charpos
)
7633 /* Return 1 if IT points into the middle of a display vector. */
7636 in_display_vector_p (it
)
7639 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7640 && it
->current
.dpvec_index
> 0
7641 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7645 /***********************************************************************
7647 ***********************************************************************/
7650 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7654 add_to_log (format
, arg1
, arg2
)
7656 Lisp_Object arg1
, arg2
;
7658 Lisp_Object args
[3];
7659 Lisp_Object msg
, fmt
;
7662 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7665 /* Do nothing if called asynchronously. Inserting text into
7666 a buffer may call after-change-functions and alike and
7667 that would means running Lisp asynchronously. */
7668 if (handling_signal
)
7672 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7674 args
[0] = fmt
= build_string (format
);
7677 msg
= Fformat (3, args
);
7679 len
= SBYTES (msg
) + 1;
7680 SAFE_ALLOCA (buffer
, char *, len
);
7681 bcopy (SDATA (msg
), buffer
, len
);
7683 message_dolog (buffer
, len
- 1, 1, 0);
7690 /* Output a newline in the *Messages* buffer if "needs" one. */
7693 message_log_maybe_newline ()
7695 if (message_log_need_newline
)
7696 message_dolog ("", 0, 1, 0);
7700 /* Add a string M of length NBYTES to the message log, optionally
7701 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7702 nonzero, means interpret the contents of M as multibyte. This
7703 function calls low-level routines in order to bypass text property
7704 hooks, etc. which might not be safe to run.
7706 This may GC (insert may run before/after change hooks),
7707 so the buffer M must NOT point to a Lisp string. */
7710 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7712 int nbytes
, nlflag
, multibyte
;
7714 if (!NILP (Vmemory_full
))
7717 if (!NILP (Vmessage_log_max
))
7719 struct buffer
*oldbuf
;
7720 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7721 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7722 int point_at_end
= 0;
7724 Lisp_Object old_deactivate_mark
, tem
;
7725 struct gcpro gcpro1
;
7727 old_deactivate_mark
= Vdeactivate_mark
;
7728 oldbuf
= current_buffer
;
7729 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7730 current_buffer
->undo_list
= Qt
;
7732 oldpoint
= message_dolog_marker1
;
7733 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7734 oldbegv
= message_dolog_marker2
;
7735 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7736 oldzv
= message_dolog_marker3
;
7737 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7738 GCPRO1 (old_deactivate_mark
);
7746 BEGV_BYTE
= BEG_BYTE
;
7749 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7751 /* Insert the string--maybe converting multibyte to single byte
7752 or vice versa, so that all the text fits the buffer. */
7754 && NILP (current_buffer
->enable_multibyte_characters
))
7756 int i
, c
, char_bytes
;
7757 unsigned char work
[1];
7759 /* Convert a multibyte string to single-byte
7760 for the *Message* buffer. */
7761 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7763 c
= string_char_and_length (m
+ i
, &char_bytes
);
7764 work
[0] = (ASCII_CHAR_P (c
)
7766 : multibyte_char_to_unibyte (c
, Qnil
));
7767 insert_1_both (work
, 1, 1, 1, 0, 0);
7770 else if (! multibyte
7771 && ! NILP (current_buffer
->enable_multibyte_characters
))
7773 int i
, c
, char_bytes
;
7774 unsigned char *msg
= (unsigned char *) m
;
7775 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7776 /* Convert a single-byte string to multibyte
7777 for the *Message* buffer. */
7778 for (i
= 0; i
< nbytes
; i
++)
7781 MAKE_CHAR_MULTIBYTE (c
);
7782 char_bytes
= CHAR_STRING (c
, str
);
7783 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7787 insert_1 (m
, nbytes
, 1, 0, 0);
7791 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7792 insert_1 ("\n", 1, 1, 0, 0);
7794 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7796 this_bol_byte
= PT_BYTE
;
7798 /* See if this line duplicates the previous one.
7799 If so, combine duplicates. */
7802 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7804 prev_bol_byte
= PT_BYTE
;
7806 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7807 this_bol
, this_bol_byte
);
7810 del_range_both (prev_bol
, prev_bol_byte
,
7811 this_bol
, this_bol_byte
, 0);
7817 /* If you change this format, don't forget to also
7818 change message_log_check_duplicate. */
7819 sprintf (dupstr
, " [%d times]", dup
);
7820 duplen
= strlen (dupstr
);
7821 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7822 insert_1 (dupstr
, duplen
, 1, 0, 1);
7827 /* If we have more than the desired maximum number of lines
7828 in the *Messages* buffer now, delete the oldest ones.
7829 This is safe because we don't have undo in this buffer. */
7831 if (NATNUMP (Vmessage_log_max
))
7833 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7834 -XFASTINT (Vmessage_log_max
) - 1, 0);
7835 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7838 BEGV
= XMARKER (oldbegv
)->charpos
;
7839 BEGV_BYTE
= marker_byte_position (oldbegv
);
7848 ZV
= XMARKER (oldzv
)->charpos
;
7849 ZV_BYTE
= marker_byte_position (oldzv
);
7853 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7855 /* We can't do Fgoto_char (oldpoint) because it will run some
7857 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7858 XMARKER (oldpoint
)->bytepos
);
7861 unchain_marker (XMARKER (oldpoint
));
7862 unchain_marker (XMARKER (oldbegv
));
7863 unchain_marker (XMARKER (oldzv
));
7865 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7866 set_buffer_internal (oldbuf
);
7868 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7869 message_log_need_newline
= !nlflag
;
7870 Vdeactivate_mark
= old_deactivate_mark
;
7875 /* We are at the end of the buffer after just having inserted a newline.
7876 (Note: We depend on the fact we won't be crossing the gap.)
7877 Check to see if the most recent message looks a lot like the previous one.
7878 Return 0 if different, 1 if the new one should just replace it, or a
7879 value N > 1 if we should also append " [N times]". */
7882 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7883 int prev_bol
, this_bol
;
7884 int prev_bol_byte
, this_bol_byte
;
7887 int len
= Z_BYTE
- 1 - this_bol_byte
;
7889 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7890 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7892 for (i
= 0; i
< len
; i
++)
7894 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7902 if (*p1
++ == ' ' && *p1
++ == '[')
7905 while (*p1
>= '0' && *p1
<= '9')
7906 n
= n
* 10 + *p1
++ - '0';
7907 if (strncmp (p1
, " times]\n", 8) == 0)
7914 /* Display an echo area message M with a specified length of NBYTES
7915 bytes. The string may include null characters. If M is 0, clear
7916 out any existing message, and let the mini-buffer text show
7919 This may GC, so the buffer M must NOT point to a Lisp string. */
7922 message2 (m
, nbytes
, multibyte
)
7927 /* First flush out any partial line written with print. */
7928 message_log_maybe_newline ();
7930 message_dolog (m
, nbytes
, 1, multibyte
);
7931 message2_nolog (m
, nbytes
, multibyte
);
7935 /* The non-logging counterpart of message2. */
7938 message2_nolog (m
, nbytes
, multibyte
)
7940 int nbytes
, multibyte
;
7942 struct frame
*sf
= SELECTED_FRAME ();
7943 message_enable_multibyte
= multibyte
;
7945 if (FRAME_INITIAL_P (sf
))
7947 if (noninteractive_need_newline
)
7948 putc ('\n', stderr
);
7949 noninteractive_need_newline
= 0;
7951 fwrite (m
, nbytes
, 1, stderr
);
7952 if (cursor_in_echo_area
== 0)
7953 fprintf (stderr
, "\n");
7956 /* A null message buffer means that the frame hasn't really been
7957 initialized yet. Error messages get reported properly by
7958 cmd_error, so this must be just an informative message; toss it. */
7959 else if (INTERACTIVE
7960 && sf
->glyphs_initialized_p
7961 && FRAME_MESSAGE_BUF (sf
))
7963 Lisp_Object mini_window
;
7966 /* Get the frame containing the mini-buffer
7967 that the selected frame is using. */
7968 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7969 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7971 FRAME_SAMPLE_VISIBILITY (f
);
7972 if (FRAME_VISIBLE_P (sf
)
7973 && ! FRAME_VISIBLE_P (f
))
7974 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7978 set_message (m
, Qnil
, nbytes
, multibyte
);
7979 if (minibuffer_auto_raise
)
7980 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7983 clear_message (1, 1);
7985 do_pending_window_change (0);
7986 echo_area_display (1);
7987 do_pending_window_change (0);
7988 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7989 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7994 /* Display an echo area message M with a specified length of NBYTES
7995 bytes. The string may include null characters. If M is not a
7996 string, clear out any existing message, and let the mini-buffer
7999 This function cancels echoing. */
8002 message3 (m
, nbytes
, multibyte
)
8007 struct gcpro gcpro1
;
8010 clear_message (1,1);
8013 /* First flush out any partial line written with print. */
8014 message_log_maybe_newline ();
8020 SAFE_ALLOCA (buffer
, char *, nbytes
);
8021 bcopy (SDATA (m
), buffer
, nbytes
);
8022 message_dolog (buffer
, nbytes
, 1, multibyte
);
8025 message3_nolog (m
, nbytes
, multibyte
);
8031 /* The non-logging version of message3.
8032 This does not cancel echoing, because it is used for echoing.
8033 Perhaps we need to make a separate function for echoing
8034 and make this cancel echoing. */
8037 message3_nolog (m
, nbytes
, multibyte
)
8039 int nbytes
, multibyte
;
8041 struct frame
*sf
= SELECTED_FRAME ();
8042 message_enable_multibyte
= multibyte
;
8044 if (FRAME_INITIAL_P (sf
))
8046 if (noninteractive_need_newline
)
8047 putc ('\n', stderr
);
8048 noninteractive_need_newline
= 0;
8050 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8051 if (cursor_in_echo_area
== 0)
8052 fprintf (stderr
, "\n");
8055 /* A null message buffer means that the frame hasn't really been
8056 initialized yet. Error messages get reported properly by
8057 cmd_error, so this must be just an informative message; toss it. */
8058 else if (INTERACTIVE
8059 && sf
->glyphs_initialized_p
8060 && FRAME_MESSAGE_BUF (sf
))
8062 Lisp_Object mini_window
;
8066 /* Get the frame containing the mini-buffer
8067 that the selected frame is using. */
8068 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8069 frame
= XWINDOW (mini_window
)->frame
;
8072 FRAME_SAMPLE_VISIBILITY (f
);
8073 if (FRAME_VISIBLE_P (sf
)
8074 && !FRAME_VISIBLE_P (f
))
8075 Fmake_frame_visible (frame
);
8077 if (STRINGP (m
) && SCHARS (m
) > 0)
8079 set_message (NULL
, m
, nbytes
, multibyte
);
8080 if (minibuffer_auto_raise
)
8081 Fraise_frame (frame
);
8082 /* Assume we are not echoing.
8083 (If we are, echo_now will override this.) */
8084 echo_message_buffer
= Qnil
;
8087 clear_message (1, 1);
8089 do_pending_window_change (0);
8090 echo_area_display (1);
8091 do_pending_window_change (0);
8092 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8093 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8098 /* Display a null-terminated echo area message M. If M is 0, clear
8099 out any existing message, and let the mini-buffer text show through.
8101 The buffer M must continue to exist until after the echo area gets
8102 cleared or some other message gets displayed there. Do not pass
8103 text that is stored in a Lisp string. Do not pass text in a buffer
8104 that was alloca'd. */
8110 message2 (m
, (m
? strlen (m
) : 0), 0);
8114 /* The non-logging counterpart of message1. */
8120 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8123 /* Display a message M which contains a single %s
8124 which gets replaced with STRING. */
8127 message_with_string (m
, string
, log
)
8132 CHECK_STRING (string
);
8138 if (noninteractive_need_newline
)
8139 putc ('\n', stderr
);
8140 noninteractive_need_newline
= 0;
8141 fprintf (stderr
, m
, SDATA (string
));
8142 if (!cursor_in_echo_area
)
8143 fprintf (stderr
, "\n");
8147 else if (INTERACTIVE
)
8149 /* The frame whose minibuffer we're going to display the message on.
8150 It may be larger than the selected frame, so we need
8151 to use its buffer, not the selected frame's buffer. */
8152 Lisp_Object mini_window
;
8153 struct frame
*f
, *sf
= SELECTED_FRAME ();
8155 /* Get the frame containing the minibuffer
8156 that the selected frame is using. */
8157 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8158 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8160 /* A null message buffer means that the frame hasn't really been
8161 initialized yet. Error messages get reported properly by
8162 cmd_error, so this must be just an informative message; toss it. */
8163 if (FRAME_MESSAGE_BUF (f
))
8165 Lisp_Object args
[2], message
;
8166 struct gcpro gcpro1
, gcpro2
;
8168 args
[0] = build_string (m
);
8169 args
[1] = message
= string
;
8170 GCPRO2 (args
[0], message
);
8173 message
= Fformat (2, args
);
8176 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8178 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8182 /* Print should start at the beginning of the message
8183 buffer next time. */
8184 message_buf_print
= 0;
8190 /* Dump an informative message to the minibuf. If M is 0, clear out
8191 any existing message, and let the mini-buffer text show through. */
8195 message (m
, a1
, a2
, a3
)
8197 EMACS_INT a1
, a2
, a3
;
8203 if (noninteractive_need_newline
)
8204 putc ('\n', stderr
);
8205 noninteractive_need_newline
= 0;
8206 fprintf (stderr
, m
, a1
, a2
, a3
);
8207 if (cursor_in_echo_area
== 0)
8208 fprintf (stderr
, "\n");
8212 else if (INTERACTIVE
)
8214 /* The frame whose mini-buffer we're going to display the message
8215 on. It may be larger than the selected frame, so we need to
8216 use its buffer, not the selected frame's buffer. */
8217 Lisp_Object mini_window
;
8218 struct frame
*f
, *sf
= SELECTED_FRAME ();
8220 /* Get the frame containing the mini-buffer
8221 that the selected frame is using. */
8222 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8223 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8225 /* A null message buffer means that the frame hasn't really been
8226 initialized yet. Error messages get reported properly by
8227 cmd_error, so this must be just an informative message; toss
8229 if (FRAME_MESSAGE_BUF (f
))
8240 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8241 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8243 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8244 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8246 #endif /* NO_ARG_ARRAY */
8248 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8253 /* Print should start at the beginning of the message
8254 buffer next time. */
8255 message_buf_print
= 0;
8261 /* The non-logging version of message. */
8264 message_nolog (m
, a1
, a2
, a3
)
8266 EMACS_INT a1
, a2
, a3
;
8268 Lisp_Object old_log_max
;
8269 old_log_max
= Vmessage_log_max
;
8270 Vmessage_log_max
= Qnil
;
8271 message (m
, a1
, a2
, a3
);
8272 Vmessage_log_max
= old_log_max
;
8276 /* Display the current message in the current mini-buffer. This is
8277 only called from error handlers in process.c, and is not time
8283 if (!NILP (echo_area_buffer
[0]))
8286 string
= Fcurrent_message ();
8287 message3 (string
, SBYTES (string
),
8288 !NILP (current_buffer
->enable_multibyte_characters
));
8293 /* Make sure echo area buffers in `echo_buffers' are live.
8294 If they aren't, make new ones. */
8297 ensure_echo_area_buffers ()
8301 for (i
= 0; i
< 2; ++i
)
8302 if (!BUFFERP (echo_buffer
[i
])
8303 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8306 Lisp_Object old_buffer
;
8309 old_buffer
= echo_buffer
[i
];
8310 sprintf (name
, " *Echo Area %d*", i
);
8311 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8312 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8313 /* to force word wrap in echo area -
8314 it was decided to postpone this*/
8315 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8317 for (j
= 0; j
< 2; ++j
)
8318 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8319 echo_area_buffer
[j
] = echo_buffer
[i
];
8324 /* Call FN with args A1..A4 with either the current or last displayed
8325 echo_area_buffer as current buffer.
8327 WHICH zero means use the current message buffer
8328 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8329 from echo_buffer[] and clear it.
8331 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8332 suitable buffer from echo_buffer[] and clear it.
8334 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8335 that the current message becomes the last displayed one, make
8336 choose a suitable buffer for echo_area_buffer[0], and clear it.
8338 Value is what FN returns. */
8341 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8344 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8350 int this_one
, the_other
, clear_buffer_p
, rc
;
8351 int count
= SPECPDL_INDEX ();
8353 /* If buffers aren't live, make new ones. */
8354 ensure_echo_area_buffers ();
8359 this_one
= 0, the_other
= 1;
8361 this_one
= 1, the_other
= 0;
8364 this_one
= 0, the_other
= 1;
8367 /* We need a fresh one in case the current echo buffer equals
8368 the one containing the last displayed echo area message. */
8369 if (!NILP (echo_area_buffer
[this_one
])
8370 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8371 echo_area_buffer
[this_one
] = Qnil
;
8374 /* Choose a suitable buffer from echo_buffer[] is we don't
8376 if (NILP (echo_area_buffer
[this_one
]))
8378 echo_area_buffer
[this_one
]
8379 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8380 ? echo_buffer
[the_other
]
8381 : echo_buffer
[this_one
]);
8385 buffer
= echo_area_buffer
[this_one
];
8387 /* Don't get confused by reusing the buffer used for echoing
8388 for a different purpose. */
8389 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8392 record_unwind_protect (unwind_with_echo_area_buffer
,
8393 with_echo_area_buffer_unwind_data (w
));
8395 /* Make the echo area buffer current. Note that for display
8396 purposes, it is not necessary that the displayed window's buffer
8397 == current_buffer, except for text property lookup. So, let's
8398 only set that buffer temporarily here without doing a full
8399 Fset_window_buffer. We must also change w->pointm, though,
8400 because otherwise an assertions in unshow_buffer fails, and Emacs
8402 set_buffer_internal_1 (XBUFFER (buffer
));
8406 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8409 current_buffer
->undo_list
= Qt
;
8410 current_buffer
->read_only
= Qnil
;
8411 specbind (Qinhibit_read_only
, Qt
);
8412 specbind (Qinhibit_modification_hooks
, Qt
);
8414 if (clear_buffer_p
&& Z
> BEG
)
8417 xassert (BEGV
>= BEG
);
8418 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8420 rc
= fn (a1
, a2
, a3
, a4
);
8422 xassert (BEGV
>= BEG
);
8423 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8425 unbind_to (count
, Qnil
);
8430 /* Save state that should be preserved around the call to the function
8431 FN called in with_echo_area_buffer. */
8434 with_echo_area_buffer_unwind_data (w
)
8438 Lisp_Object vector
, tmp
;
8440 /* Reduce consing by keeping one vector in
8441 Vwith_echo_area_save_vector. */
8442 vector
= Vwith_echo_area_save_vector
;
8443 Vwith_echo_area_save_vector
= Qnil
;
8446 vector
= Fmake_vector (make_number (7), Qnil
);
8448 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8449 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8450 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8454 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8455 ASET (vector
, i
, w
->buffer
); ++i
;
8456 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8457 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8462 for (; i
< end
; ++i
)
8463 ASET (vector
, i
, Qnil
);
8466 xassert (i
== ASIZE (vector
));
8471 /* Restore global state from VECTOR which was created by
8472 with_echo_area_buffer_unwind_data. */
8475 unwind_with_echo_area_buffer (vector
)
8478 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8479 Vdeactivate_mark
= AREF (vector
, 1);
8480 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8482 if (WINDOWP (AREF (vector
, 3)))
8485 Lisp_Object buffer
, charpos
, bytepos
;
8487 w
= XWINDOW (AREF (vector
, 3));
8488 buffer
= AREF (vector
, 4);
8489 charpos
= AREF (vector
, 5);
8490 bytepos
= AREF (vector
, 6);
8493 set_marker_both (w
->pointm
, buffer
,
8494 XFASTINT (charpos
), XFASTINT (bytepos
));
8497 Vwith_echo_area_save_vector
= vector
;
8502 /* Set up the echo area for use by print functions. MULTIBYTE_P
8503 non-zero means we will print multibyte. */
8506 setup_echo_area_for_printing (multibyte_p
)
8509 /* If we can't find an echo area any more, exit. */
8510 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8513 ensure_echo_area_buffers ();
8515 if (!message_buf_print
)
8517 /* A message has been output since the last time we printed.
8518 Choose a fresh echo area buffer. */
8519 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8520 echo_area_buffer
[0] = echo_buffer
[1];
8522 echo_area_buffer
[0] = echo_buffer
[0];
8524 /* Switch to that buffer and clear it. */
8525 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8526 current_buffer
->truncate_lines
= Qnil
;
8530 int count
= SPECPDL_INDEX ();
8531 specbind (Qinhibit_read_only
, Qt
);
8532 /* Note that undo recording is always disabled. */
8534 unbind_to (count
, Qnil
);
8536 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8538 /* Set up the buffer for the multibyteness we need. */
8540 != !NILP (current_buffer
->enable_multibyte_characters
))
8541 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8543 /* Raise the frame containing the echo area. */
8544 if (minibuffer_auto_raise
)
8546 struct frame
*sf
= SELECTED_FRAME ();
8547 Lisp_Object mini_window
;
8548 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8549 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8552 message_log_maybe_newline ();
8553 message_buf_print
= 1;
8557 if (NILP (echo_area_buffer
[0]))
8559 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8560 echo_area_buffer
[0] = echo_buffer
[1];
8562 echo_area_buffer
[0] = echo_buffer
[0];
8565 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8567 /* Someone switched buffers between print requests. */
8568 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8569 current_buffer
->truncate_lines
= Qnil
;
8575 /* Display an echo area message in window W. Value is non-zero if W's
8576 height is changed. If display_last_displayed_message_p is
8577 non-zero, display the message that was last displayed, otherwise
8578 display the current message. */
8581 display_echo_area (w
)
8584 int i
, no_message_p
, window_height_changed_p
, count
;
8586 /* Temporarily disable garbage collections while displaying the echo
8587 area. This is done because a GC can print a message itself.
8588 That message would modify the echo area buffer's contents while a
8589 redisplay of the buffer is going on, and seriously confuse
8591 count
= inhibit_garbage_collection ();
8593 /* If there is no message, we must call display_echo_area_1
8594 nevertheless because it resizes the window. But we will have to
8595 reset the echo_area_buffer in question to nil at the end because
8596 with_echo_area_buffer will sets it to an empty buffer. */
8597 i
= display_last_displayed_message_p
? 1 : 0;
8598 no_message_p
= NILP (echo_area_buffer
[i
]);
8600 window_height_changed_p
8601 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8602 display_echo_area_1
,
8603 (EMACS_INT
) w
, Qnil
, 0, 0);
8606 echo_area_buffer
[i
] = Qnil
;
8608 unbind_to (count
, Qnil
);
8609 return window_height_changed_p
;
8613 /* Helper for display_echo_area. Display the current buffer which
8614 contains the current echo area message in window W, a mini-window,
8615 a pointer to which is passed in A1. A2..A4 are currently not used.
8616 Change the height of W so that all of the message is displayed.
8617 Value is non-zero if height of W was changed. */
8620 display_echo_area_1 (a1
, a2
, a3
, a4
)
8625 struct window
*w
= (struct window
*) a1
;
8627 struct text_pos start
;
8628 int window_height_changed_p
= 0;
8630 /* Do this before displaying, so that we have a large enough glyph
8631 matrix for the display. If we can't get enough space for the
8632 whole text, display the last N lines. That works by setting w->start. */
8633 window_height_changed_p
= resize_mini_window (w
, 0);
8635 /* Use the starting position chosen by resize_mini_window. */
8636 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8639 clear_glyph_matrix (w
->desired_matrix
);
8640 XSETWINDOW (window
, w
);
8641 try_window (window
, start
, 0);
8643 return window_height_changed_p
;
8647 /* Resize the echo area window to exactly the size needed for the
8648 currently displayed message, if there is one. If a mini-buffer
8649 is active, don't shrink it. */
8652 resize_echo_area_exactly ()
8654 if (BUFFERP (echo_area_buffer
[0])
8655 && WINDOWP (echo_area_window
))
8657 struct window
*w
= XWINDOW (echo_area_window
);
8659 Lisp_Object resize_exactly
;
8661 if (minibuf_level
== 0)
8662 resize_exactly
= Qt
;
8664 resize_exactly
= Qnil
;
8666 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8667 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8670 ++windows_or_buffers_changed
;
8671 ++update_mode_lines
;
8672 redisplay_internal (0);
8678 /* Callback function for with_echo_area_buffer, when used from
8679 resize_echo_area_exactly. A1 contains a pointer to the window to
8680 resize, EXACTLY non-nil means resize the mini-window exactly to the
8681 size of the text displayed. A3 and A4 are not used. Value is what
8682 resize_mini_window returns. */
8685 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8687 Lisp_Object exactly
;
8690 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8694 /* Resize mini-window W to fit the size of its contents. EXACT_P
8695 means size the window exactly to the size needed. Otherwise, it's
8696 only enlarged until W's buffer is empty.
8698 Set W->start to the right place to begin display. If the whole
8699 contents fit, start at the beginning. Otherwise, start so as
8700 to make the end of the contents appear. This is particularly
8701 important for y-or-n-p, but seems desirable generally.
8703 Value is non-zero if the window height has been changed. */
8706 resize_mini_window (w
, exact_p
)
8710 struct frame
*f
= XFRAME (w
->frame
);
8711 int window_height_changed_p
= 0;
8713 xassert (MINI_WINDOW_P (w
));
8715 /* By default, start display at the beginning. */
8716 set_marker_both (w
->start
, w
->buffer
,
8717 BUF_BEGV (XBUFFER (w
->buffer
)),
8718 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8720 /* Don't resize windows while redisplaying a window; it would
8721 confuse redisplay functions when the size of the window they are
8722 displaying changes from under them. Such a resizing can happen,
8723 for instance, when which-func prints a long message while
8724 we are running fontification-functions. We're running these
8725 functions with safe_call which binds inhibit-redisplay to t. */
8726 if (!NILP (Vinhibit_redisplay
))
8729 /* Nil means don't try to resize. */
8730 if (NILP (Vresize_mini_windows
)
8731 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8734 if (!FRAME_MINIBUF_ONLY_P (f
))
8737 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8738 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8739 int height
, max_height
;
8740 int unit
= FRAME_LINE_HEIGHT (f
);
8741 struct text_pos start
;
8742 struct buffer
*old_current_buffer
= NULL
;
8744 if (current_buffer
!= XBUFFER (w
->buffer
))
8746 old_current_buffer
= current_buffer
;
8747 set_buffer_internal (XBUFFER (w
->buffer
));
8750 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8752 /* Compute the max. number of lines specified by the user. */
8753 if (FLOATP (Vmax_mini_window_height
))
8754 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8755 else if (INTEGERP (Vmax_mini_window_height
))
8756 max_height
= XINT (Vmax_mini_window_height
);
8758 max_height
= total_height
/ 4;
8760 /* Correct that max. height if it's bogus. */
8761 max_height
= max (1, max_height
);
8762 max_height
= min (total_height
, max_height
);
8764 /* Find out the height of the text in the window. */
8765 if (it
.line_wrap
== TRUNCATE
)
8770 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8771 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8772 height
= it
.current_y
+ last_height
;
8774 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8775 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8776 height
= (height
+ unit
- 1) / unit
;
8779 /* Compute a suitable window start. */
8780 if (height
> max_height
)
8782 height
= max_height
;
8783 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8784 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8785 start
= it
.current
.pos
;
8788 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8789 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8791 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8793 /* Let it grow only, until we display an empty message, in which
8794 case the window shrinks again. */
8795 if (height
> WINDOW_TOTAL_LINES (w
))
8797 int old_height
= WINDOW_TOTAL_LINES (w
);
8798 freeze_window_starts (f
, 1);
8799 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8800 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8802 else if (height
< WINDOW_TOTAL_LINES (w
)
8803 && (exact_p
|| BEGV
== ZV
))
8805 int old_height
= WINDOW_TOTAL_LINES (w
);
8806 freeze_window_starts (f
, 0);
8807 shrink_mini_window (w
);
8808 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8813 /* Always resize to exact size needed. */
8814 if (height
> WINDOW_TOTAL_LINES (w
))
8816 int old_height
= WINDOW_TOTAL_LINES (w
);
8817 freeze_window_starts (f
, 1);
8818 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8819 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8821 else if (height
< WINDOW_TOTAL_LINES (w
))
8823 int old_height
= WINDOW_TOTAL_LINES (w
);
8824 freeze_window_starts (f
, 0);
8825 shrink_mini_window (w
);
8829 freeze_window_starts (f
, 1);
8830 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8833 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8837 if (old_current_buffer
)
8838 set_buffer_internal (old_current_buffer
);
8841 return window_height_changed_p
;
8845 /* Value is the current message, a string, or nil if there is no
8853 if (!BUFFERP (echo_area_buffer
[0]))
8857 with_echo_area_buffer (0, 0, current_message_1
,
8858 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8860 echo_area_buffer
[0] = Qnil
;
8868 current_message_1 (a1
, a2
, a3
, a4
)
8873 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8876 *msg
= make_buffer_string (BEG
, Z
, 1);
8883 /* Push the current message on Vmessage_stack for later restauration
8884 by restore_message. Value is non-zero if the current message isn't
8885 empty. This is a relatively infrequent operation, so it's not
8886 worth optimizing. */
8892 msg
= current_message ();
8893 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8894 return STRINGP (msg
);
8898 /* Restore message display from the top of Vmessage_stack. */
8905 xassert (CONSP (Vmessage_stack
));
8906 msg
= XCAR (Vmessage_stack
);
8908 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8910 message3_nolog (msg
, 0, 0);
8914 /* Handler for record_unwind_protect calling pop_message. */
8917 pop_message_unwind (dummy
)
8924 /* Pop the top-most entry off Vmessage_stack. */
8929 xassert (CONSP (Vmessage_stack
));
8930 Vmessage_stack
= XCDR (Vmessage_stack
);
8934 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8935 exits. If the stack is not empty, we have a missing pop_message
8939 check_message_stack ()
8941 if (!NILP (Vmessage_stack
))
8946 /* Truncate to NCHARS what will be displayed in the echo area the next
8947 time we display it---but don't redisplay it now. */
8950 truncate_echo_area (nchars
)
8954 echo_area_buffer
[0] = Qnil
;
8955 /* A null message buffer means that the frame hasn't really been
8956 initialized yet. Error messages get reported properly by
8957 cmd_error, so this must be just an informative message; toss it. */
8958 else if (!noninteractive
8960 && !NILP (echo_area_buffer
[0]))
8962 struct frame
*sf
= SELECTED_FRAME ();
8963 if (FRAME_MESSAGE_BUF (sf
))
8964 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8969 /* Helper function for truncate_echo_area. Truncate the current
8970 message to at most NCHARS characters. */
8973 truncate_message_1 (nchars
, a2
, a3
, a4
)
8978 if (BEG
+ nchars
< Z
)
8979 del_range (BEG
+ nchars
, Z
);
8981 echo_area_buffer
[0] = Qnil
;
8986 /* Set the current message to a substring of S or STRING.
8988 If STRING is a Lisp string, set the message to the first NBYTES
8989 bytes from STRING. NBYTES zero means use the whole string. If
8990 STRING is multibyte, the message will be displayed multibyte.
8992 If S is not null, set the message to the first LEN bytes of S. LEN
8993 zero means use the whole string. MULTIBYTE_P non-zero means S is
8994 multibyte. Display the message multibyte in that case.
8996 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8997 to t before calling set_message_1 (which calls insert).
9001 set_message (s
, string
, nbytes
, multibyte_p
)
9004 int nbytes
, multibyte_p
;
9006 message_enable_multibyte
9007 = ((s
&& multibyte_p
)
9008 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9010 with_echo_area_buffer (0, -1, set_message_1
,
9011 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9012 message_buf_print
= 0;
9013 help_echo_showing_p
= 0;
9017 /* Helper function for set_message. Arguments have the same meaning
9018 as there, with A1 corresponding to S and A2 corresponding to STRING
9019 This function is called with the echo area buffer being
9023 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9026 EMACS_INT nbytes
, multibyte_p
;
9028 const char *s
= (const char *) a1
;
9029 Lisp_Object string
= a2
;
9031 /* Change multibyteness of the echo buffer appropriately. */
9032 if (message_enable_multibyte
9033 != !NILP (current_buffer
->enable_multibyte_characters
))
9034 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9036 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9038 /* Insert new message at BEG. */
9039 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9041 if (STRINGP (string
))
9046 nbytes
= SBYTES (string
);
9047 nchars
= string_byte_to_char (string
, nbytes
);
9049 /* This function takes care of single/multibyte conversion. We
9050 just have to ensure that the echo area buffer has the right
9051 setting of enable_multibyte_characters. */
9052 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9057 nbytes
= strlen (s
);
9059 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9061 /* Convert from multi-byte to single-byte. */
9063 unsigned char work
[1];
9065 /* Convert a multibyte string to single-byte. */
9066 for (i
= 0; i
< nbytes
; i
+= n
)
9068 c
= string_char_and_length (s
+ i
, &n
);
9069 work
[0] = (ASCII_CHAR_P (c
)
9071 : multibyte_char_to_unibyte (c
, Qnil
));
9072 insert_1_both (work
, 1, 1, 1, 0, 0);
9075 else if (!multibyte_p
9076 && !NILP (current_buffer
->enable_multibyte_characters
))
9078 /* Convert from single-byte to multi-byte. */
9080 const unsigned char *msg
= (const unsigned char *) s
;
9081 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9083 /* Convert a single-byte string to multibyte. */
9084 for (i
= 0; i
< nbytes
; i
++)
9087 MAKE_CHAR_MULTIBYTE (c
);
9088 n
= CHAR_STRING (c
, str
);
9089 insert_1_both (str
, 1, n
, 1, 0, 0);
9093 insert_1 (s
, nbytes
, 1, 0, 0);
9100 /* Clear messages. CURRENT_P non-zero means clear the current
9101 message. LAST_DISPLAYED_P non-zero means clear the message
9105 clear_message (current_p
, last_displayed_p
)
9106 int current_p
, last_displayed_p
;
9110 echo_area_buffer
[0] = Qnil
;
9111 message_cleared_p
= 1;
9114 if (last_displayed_p
)
9115 echo_area_buffer
[1] = Qnil
;
9117 message_buf_print
= 0;
9120 /* Clear garbaged frames.
9122 This function is used where the old redisplay called
9123 redraw_garbaged_frames which in turn called redraw_frame which in
9124 turn called clear_frame. The call to clear_frame was a source of
9125 flickering. I believe a clear_frame is not necessary. It should
9126 suffice in the new redisplay to invalidate all current matrices,
9127 and ensure a complete redisplay of all windows. */
9130 clear_garbaged_frames ()
9134 Lisp_Object tail
, frame
;
9135 int changed_count
= 0;
9137 FOR_EACH_FRAME (tail
, frame
)
9139 struct frame
*f
= XFRAME (frame
);
9141 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9145 Fredraw_frame (frame
);
9146 f
->force_flush_display_p
= 1;
9148 clear_current_matrices (f
);
9157 ++windows_or_buffers_changed
;
9162 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9163 is non-zero update selected_frame. Value is non-zero if the
9164 mini-windows height has been changed. */
9167 echo_area_display (update_frame_p
)
9170 Lisp_Object mini_window
;
9173 int window_height_changed_p
= 0;
9174 struct frame
*sf
= SELECTED_FRAME ();
9176 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9177 w
= XWINDOW (mini_window
);
9178 f
= XFRAME (WINDOW_FRAME (w
));
9180 /* Don't display if frame is invisible or not yet initialized. */
9181 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9184 #ifdef HAVE_WINDOW_SYSTEM
9185 /* When Emacs starts, selected_frame may be the initial terminal
9186 frame. If we let this through, a message would be displayed on
9188 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9190 #endif /* HAVE_WINDOW_SYSTEM */
9192 /* Redraw garbaged frames. */
9194 clear_garbaged_frames ();
9196 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9198 echo_area_window
= mini_window
;
9199 window_height_changed_p
= display_echo_area (w
);
9200 w
->must_be_updated_p
= 1;
9202 /* Update the display, unless called from redisplay_internal.
9203 Also don't update the screen during redisplay itself. The
9204 update will happen at the end of redisplay, and an update
9205 here could cause confusion. */
9206 if (update_frame_p
&& !redisplaying_p
)
9210 /* If the display update has been interrupted by pending
9211 input, update mode lines in the frame. Due to the
9212 pending input, it might have been that redisplay hasn't
9213 been called, so that mode lines above the echo area are
9214 garbaged. This looks odd, so we prevent it here. */
9215 if (!display_completed
)
9216 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9218 if (window_height_changed_p
9219 /* Don't do this if Emacs is shutting down. Redisplay
9220 needs to run hooks. */
9221 && !NILP (Vrun_hooks
))
9223 /* Must update other windows. Likewise as in other
9224 cases, don't let this update be interrupted by
9226 int count
= SPECPDL_INDEX ();
9227 specbind (Qredisplay_dont_pause
, Qt
);
9228 windows_or_buffers_changed
= 1;
9229 redisplay_internal (0);
9230 unbind_to (count
, Qnil
);
9232 else if (FRAME_WINDOW_P (f
) && n
== 0)
9234 /* Window configuration is the same as before.
9235 Can do with a display update of the echo area,
9236 unless we displayed some mode lines. */
9237 update_single_window (w
, 1);
9238 FRAME_RIF (f
)->flush_display (f
);
9241 update_frame (f
, 1, 1);
9243 /* If cursor is in the echo area, make sure that the next
9244 redisplay displays the minibuffer, so that the cursor will
9245 be replaced with what the minibuffer wants. */
9246 if (cursor_in_echo_area
)
9247 ++windows_or_buffers_changed
;
9250 else if (!EQ (mini_window
, selected_window
))
9251 windows_or_buffers_changed
++;
9253 /* Last displayed message is now the current message. */
9254 echo_area_buffer
[1] = echo_area_buffer
[0];
9255 /* Inform read_char that we're not echoing. */
9256 echo_message_buffer
= Qnil
;
9258 /* Prevent redisplay optimization in redisplay_internal by resetting
9259 this_line_start_pos. This is done because the mini-buffer now
9260 displays the message instead of its buffer text. */
9261 if (EQ (mini_window
, selected_window
))
9262 CHARPOS (this_line_start_pos
) = 0;
9264 return window_height_changed_p
;
9269 /***********************************************************************
9270 Mode Lines and Frame Titles
9271 ***********************************************************************/
9273 /* A buffer for constructing non-propertized mode-line strings and
9274 frame titles in it; allocated from the heap in init_xdisp and
9275 resized as needed in store_mode_line_noprop_char. */
9277 static char *mode_line_noprop_buf
;
9279 /* The buffer's end, and a current output position in it. */
9281 static char *mode_line_noprop_buf_end
;
9282 static char *mode_line_noprop_ptr
;
9284 #define MODE_LINE_NOPROP_LEN(start) \
9285 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9288 MODE_LINE_DISPLAY
= 0,
9294 /* Alist that caches the results of :propertize.
9295 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9296 static Lisp_Object mode_line_proptrans_alist
;
9298 /* List of strings making up the mode-line. */
9299 static Lisp_Object mode_line_string_list
;
9301 /* Base face property when building propertized mode line string. */
9302 static Lisp_Object mode_line_string_face
;
9303 static Lisp_Object mode_line_string_face_prop
;
9306 /* Unwind data for mode line strings */
9308 static Lisp_Object Vmode_line_unwind_vector
;
9311 format_mode_line_unwind_data (struct buffer
*obuf
,
9315 Lisp_Object vector
, tmp
;
9317 /* Reduce consing by keeping one vector in
9318 Vwith_echo_area_save_vector. */
9319 vector
= Vmode_line_unwind_vector
;
9320 Vmode_line_unwind_vector
= Qnil
;
9323 vector
= Fmake_vector (make_number (8), Qnil
);
9325 ASET (vector
, 0, make_number (mode_line_target
));
9326 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9327 ASET (vector
, 2, mode_line_string_list
);
9328 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9329 ASET (vector
, 4, mode_line_string_face
);
9330 ASET (vector
, 5, mode_line_string_face_prop
);
9333 XSETBUFFER (tmp
, obuf
);
9336 ASET (vector
, 6, tmp
);
9337 ASET (vector
, 7, owin
);
9343 unwind_format_mode_line (vector
)
9346 mode_line_target
= XINT (AREF (vector
, 0));
9347 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9348 mode_line_string_list
= AREF (vector
, 2);
9349 if (! EQ (AREF (vector
, 3), Qt
))
9350 mode_line_proptrans_alist
= AREF (vector
, 3);
9351 mode_line_string_face
= AREF (vector
, 4);
9352 mode_line_string_face_prop
= AREF (vector
, 5);
9354 if (!NILP (AREF (vector
, 7)))
9355 /* Select window before buffer, since it may change the buffer. */
9356 Fselect_window (AREF (vector
, 7), Qt
);
9358 if (!NILP (AREF (vector
, 6)))
9360 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9361 ASET (vector
, 6, Qnil
);
9364 Vmode_line_unwind_vector
= vector
;
9369 /* Store a single character C for the frame title in mode_line_noprop_buf.
9370 Re-allocate mode_line_noprop_buf if necessary. */
9374 store_mode_line_noprop_char (char c
)
9376 store_mode_line_noprop_char (c
)
9380 /* If output position has reached the end of the allocated buffer,
9381 double the buffer's size. */
9382 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9384 int len
= MODE_LINE_NOPROP_LEN (0);
9385 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9386 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9387 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9388 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9391 *mode_line_noprop_ptr
++ = c
;
9395 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9396 mode_line_noprop_ptr. STR is the string to store. Do not copy
9397 characters that yield more columns than PRECISION; PRECISION <= 0
9398 means copy the whole string. Pad with spaces until FIELD_WIDTH
9399 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9400 pad. Called from display_mode_element when it is used to build a
9404 store_mode_line_noprop (str
, field_width
, precision
)
9405 const unsigned char *str
;
9406 int field_width
, precision
;
9411 /* Copy at most PRECISION chars from STR. */
9412 nbytes
= strlen (str
);
9413 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9415 store_mode_line_noprop_char (*str
++);
9417 /* Fill up with spaces until FIELD_WIDTH reached. */
9418 while (field_width
> 0
9421 store_mode_line_noprop_char (' ');
9428 /***********************************************************************
9430 ***********************************************************************/
9432 #ifdef HAVE_WINDOW_SYSTEM
9434 /* Set the title of FRAME, if it has changed. The title format is
9435 Vicon_title_format if FRAME is iconified, otherwise it is
9436 frame_title_format. */
9439 x_consider_frame_title (frame
)
9442 struct frame
*f
= XFRAME (frame
);
9444 if (FRAME_WINDOW_P (f
)
9445 || FRAME_MINIBUF_ONLY_P (f
)
9446 || f
->explicit_name
)
9448 /* Do we have more than one visible frame on this X display? */
9455 int count
= SPECPDL_INDEX ();
9457 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9459 Lisp_Object other_frame
= XCAR (tail
);
9460 struct frame
*tf
= XFRAME (other_frame
);
9463 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9464 && !FRAME_MINIBUF_ONLY_P (tf
)
9465 && !EQ (other_frame
, tip_frame
)
9466 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9470 /* Set global variable indicating that multiple frames exist. */
9471 multiple_frames
= CONSP (tail
);
9473 /* Switch to the buffer of selected window of the frame. Set up
9474 mode_line_target so that display_mode_element will output into
9475 mode_line_noprop_buf; then display the title. */
9476 record_unwind_protect (unwind_format_mode_line
,
9477 format_mode_line_unwind_data
9478 (current_buffer
, selected_window
, 0));
9480 Fselect_window (f
->selected_window
, Qt
);
9481 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9482 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9484 mode_line_target
= MODE_LINE_TITLE
;
9485 title_start
= MODE_LINE_NOPROP_LEN (0);
9486 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9487 NULL
, DEFAULT_FACE_ID
);
9488 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9489 len
= MODE_LINE_NOPROP_LEN (title_start
);
9490 title
= mode_line_noprop_buf
+ title_start
;
9491 unbind_to (count
, Qnil
);
9493 /* Set the title only if it's changed. This avoids consing in
9494 the common case where it hasn't. (If it turns out that we've
9495 already wasted too much time by walking through the list with
9496 display_mode_element, then we might need to optimize at a
9497 higher level than this.) */
9498 if (! STRINGP (f
->name
)
9499 || SBYTES (f
->name
) != len
9500 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9505 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9508 ns_set_name_as_filename (f
);
9510 x_implicitly_set_name (f
, make_string(title
, len
),
9516 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9521 /* do this also for frames with explicit names */
9522 ns_implicitly_set_icon_type(f
);
9523 ns_set_doc_edited(f
, Fbuffer_modified_p
9524 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9530 #endif /* not HAVE_WINDOW_SYSTEM */
9535 /***********************************************************************
9537 ***********************************************************************/
9540 /* Prepare for redisplay by updating menu-bar item lists when
9541 appropriate. This can call eval. */
9544 prepare_menu_bars ()
9547 struct gcpro gcpro1
, gcpro2
;
9549 Lisp_Object tooltip_frame
;
9551 #ifdef HAVE_WINDOW_SYSTEM
9552 tooltip_frame
= tip_frame
;
9554 tooltip_frame
= Qnil
;
9557 /* Update all frame titles based on their buffer names, etc. We do
9558 this before the menu bars so that the buffer-menu will show the
9559 up-to-date frame titles. */
9560 #ifdef HAVE_WINDOW_SYSTEM
9561 if (windows_or_buffers_changed
|| update_mode_lines
)
9563 Lisp_Object tail
, frame
;
9565 FOR_EACH_FRAME (tail
, frame
)
9568 if (!EQ (frame
, tooltip_frame
)
9569 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9570 x_consider_frame_title (frame
);
9573 #endif /* HAVE_WINDOW_SYSTEM */
9575 /* Update the menu bar item lists, if appropriate. This has to be
9576 done before any actual redisplay or generation of display lines. */
9577 all_windows
= (update_mode_lines
9578 || buffer_shared
> 1
9579 || windows_or_buffers_changed
);
9582 Lisp_Object tail
, frame
;
9583 int count
= SPECPDL_INDEX ();
9584 /* 1 means that update_menu_bar has run its hooks
9585 so any further calls to update_menu_bar shouldn't do so again. */
9586 int menu_bar_hooks_run
= 0;
9588 record_unwind_save_match_data ();
9590 FOR_EACH_FRAME (tail
, frame
)
9594 /* Ignore tooltip frame. */
9595 if (EQ (frame
, tooltip_frame
))
9598 /* If a window on this frame changed size, report that to
9599 the user and clear the size-change flag. */
9600 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9602 Lisp_Object functions
;
9604 /* Clear flag first in case we get an error below. */
9605 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9606 functions
= Vwindow_size_change_functions
;
9607 GCPRO2 (tail
, functions
);
9609 while (CONSP (functions
))
9611 if (!EQ (XCAR (functions
), Qt
))
9612 call1 (XCAR (functions
), frame
);
9613 functions
= XCDR (functions
);
9619 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9620 #ifdef HAVE_WINDOW_SYSTEM
9621 update_tool_bar (f
, 0);
9626 unbind_to (count
, Qnil
);
9630 struct frame
*sf
= SELECTED_FRAME ();
9631 update_menu_bar (sf
, 1, 0);
9632 #ifdef HAVE_WINDOW_SYSTEM
9633 update_tool_bar (sf
, 1);
9637 /* Motif needs this. See comment in xmenu.c. Turn it off when
9638 pending_menu_activation is not defined. */
9639 #ifdef USE_X_TOOLKIT
9640 pending_menu_activation
= 0;
9645 /* Update the menu bar item list for frame F. This has to be done
9646 before we start to fill in any display lines, because it can call
9649 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9651 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9652 already ran the menu bar hooks for this redisplay, so there
9653 is no need to run them again. The return value is the
9654 updated value of this flag, to pass to the next call. */
9657 update_menu_bar (f
, save_match_data
, hooks_run
)
9659 int save_match_data
;
9663 register struct window
*w
;
9665 /* If called recursively during a menu update, do nothing. This can
9666 happen when, for instance, an activate-menubar-hook causes a
9668 if (inhibit_menubar_update
)
9671 window
= FRAME_SELECTED_WINDOW (f
);
9672 w
= XWINDOW (window
);
9674 if (FRAME_WINDOW_P (f
)
9676 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9677 || defined (HAVE_NS) || defined (USE_GTK)
9678 FRAME_EXTERNAL_MENU_BAR (f
)
9680 FRAME_MENU_BAR_LINES (f
) > 0
9682 : FRAME_MENU_BAR_LINES (f
) > 0)
9684 /* If the user has switched buffers or windows, we need to
9685 recompute to reflect the new bindings. But we'll
9686 recompute when update_mode_lines is set too; that means
9687 that people can use force-mode-line-update to request
9688 that the menu bar be recomputed. The adverse effect on
9689 the rest of the redisplay algorithm is about the same as
9690 windows_or_buffers_changed anyway. */
9691 if (windows_or_buffers_changed
9692 /* This used to test w->update_mode_line, but we believe
9693 there is no need to recompute the menu in that case. */
9694 || update_mode_lines
9695 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9696 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9697 != !NILP (w
->last_had_star
))
9698 || ((!NILP (Vtransient_mark_mode
)
9699 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9700 != !NILP (w
->region_showing
)))
9702 struct buffer
*prev
= current_buffer
;
9703 int count
= SPECPDL_INDEX ();
9705 specbind (Qinhibit_menubar_update
, Qt
);
9707 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9708 if (save_match_data
)
9709 record_unwind_save_match_data ();
9710 if (NILP (Voverriding_local_map_menu_flag
))
9712 specbind (Qoverriding_terminal_local_map
, Qnil
);
9713 specbind (Qoverriding_local_map
, Qnil
);
9718 /* Run the Lucid hook. */
9719 safe_run_hooks (Qactivate_menubar_hook
);
9721 /* If it has changed current-menubar from previous value,
9722 really recompute the menu-bar from the value. */
9723 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9724 call0 (Qrecompute_lucid_menubar
);
9726 safe_run_hooks (Qmenu_bar_update_hook
);
9731 XSETFRAME (Vmenu_updating_frame
, f
);
9732 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9734 /* Redisplay the menu bar in case we changed it. */
9735 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9736 || defined (HAVE_NS) || defined (USE_GTK)
9737 if (FRAME_WINDOW_P (f
))
9739 #if defined (HAVE_NS)
9740 /* All frames on Mac OS share the same menubar. So only
9741 the selected frame should be allowed to set it. */
9742 if (f
== SELECTED_FRAME ())
9744 set_frame_menubar (f
, 0, 0);
9747 /* On a terminal screen, the menu bar is an ordinary screen
9748 line, and this makes it get updated. */
9749 w
->update_mode_line
= Qt
;
9750 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9751 /* In the non-toolkit version, the menu bar is an ordinary screen
9752 line, and this makes it get updated. */
9753 w
->update_mode_line
= Qt
;
9754 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9756 unbind_to (count
, Qnil
);
9757 set_buffer_internal_1 (prev
);
9766 /***********************************************************************
9768 ***********************************************************************/
9770 #ifdef HAVE_WINDOW_SYSTEM
9773 Nominal cursor position -- where to draw output.
9774 HPOS and VPOS are window relative glyph matrix coordinates.
9775 X and Y are window relative pixel coordinates. */
9777 struct cursor_pos output_cursor
;
9781 Set the global variable output_cursor to CURSOR. All cursor
9782 positions are relative to updated_window. */
9785 set_output_cursor (cursor
)
9786 struct cursor_pos
*cursor
;
9788 output_cursor
.hpos
= cursor
->hpos
;
9789 output_cursor
.vpos
= cursor
->vpos
;
9790 output_cursor
.x
= cursor
->x
;
9791 output_cursor
.y
= cursor
->y
;
9796 Set a nominal cursor position.
9798 HPOS and VPOS are column/row positions in a window glyph matrix. X
9799 and Y are window text area relative pixel positions.
9801 If this is done during an update, updated_window will contain the
9802 window that is being updated and the position is the future output
9803 cursor position for that window. If updated_window is null, use
9804 selected_window and display the cursor at the given position. */
9807 x_cursor_to (vpos
, hpos
, y
, x
)
9808 int vpos
, hpos
, y
, x
;
9812 /* If updated_window is not set, work on selected_window. */
9816 w
= XWINDOW (selected_window
);
9818 /* Set the output cursor. */
9819 output_cursor
.hpos
= hpos
;
9820 output_cursor
.vpos
= vpos
;
9821 output_cursor
.x
= x
;
9822 output_cursor
.y
= y
;
9824 /* If not called as part of an update, really display the cursor.
9825 This will also set the cursor position of W. */
9826 if (updated_window
== NULL
)
9829 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9830 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9831 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9836 #endif /* HAVE_WINDOW_SYSTEM */
9839 /***********************************************************************
9841 ***********************************************************************/
9843 #ifdef HAVE_WINDOW_SYSTEM
9845 /* Where the mouse was last time we reported a mouse event. */
9847 FRAME_PTR last_mouse_frame
;
9849 /* Tool-bar item index of the item on which a mouse button was pressed
9852 int last_tool_bar_item
;
9856 update_tool_bar_unwind (frame
)
9859 selected_frame
= frame
;
9863 /* Update the tool-bar item list for frame F. This has to be done
9864 before we start to fill in any display lines. Called from
9865 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9866 and restore it here. */
9869 update_tool_bar (f
, save_match_data
)
9871 int save_match_data
;
9873 #if defined (USE_GTK) || defined (HAVE_NS)
9874 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9876 int do_update
= WINDOWP (f
->tool_bar_window
)
9877 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9885 window
= FRAME_SELECTED_WINDOW (f
);
9886 w
= XWINDOW (window
);
9888 /* If the user has switched buffers or windows, we need to
9889 recompute to reflect the new bindings. But we'll
9890 recompute when update_mode_lines is set too; that means
9891 that people can use force-mode-line-update to request
9892 that the menu bar be recomputed. The adverse effect on
9893 the rest of the redisplay algorithm is about the same as
9894 windows_or_buffers_changed anyway. */
9895 if (windows_or_buffers_changed
9896 || !NILP (w
->update_mode_line
)
9897 || update_mode_lines
9898 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9899 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9900 != !NILP (w
->last_had_star
))
9901 || ((!NILP (Vtransient_mark_mode
)
9902 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9903 != !NILP (w
->region_showing
)))
9905 struct buffer
*prev
= current_buffer
;
9906 int count
= SPECPDL_INDEX ();
9907 Lisp_Object frame
, new_tool_bar
;
9909 struct gcpro gcpro1
;
9911 /* Set current_buffer to the buffer of the selected
9912 window of the frame, so that we get the right local
9914 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9916 /* Save match data, if we must. */
9917 if (save_match_data
)
9918 record_unwind_save_match_data ();
9920 /* Make sure that we don't accidentally use bogus keymaps. */
9921 if (NILP (Voverriding_local_map_menu_flag
))
9923 specbind (Qoverriding_terminal_local_map
, Qnil
);
9924 specbind (Qoverriding_local_map
, Qnil
);
9927 GCPRO1 (new_tool_bar
);
9929 /* We must temporarily set the selected frame to this frame
9930 before calling tool_bar_items, because the calculation of
9931 the tool-bar keymap uses the selected frame (see
9932 `tool-bar-make-keymap' in tool-bar.el). */
9933 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9934 XSETFRAME (frame
, f
);
9935 selected_frame
= frame
;
9937 /* Build desired tool-bar items from keymaps. */
9938 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9941 /* Redisplay the tool-bar if we changed it. */
9942 if (new_n_tool_bar
!= f
->n_tool_bar_items
9943 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9945 /* Redisplay that happens asynchronously due to an expose event
9946 may access f->tool_bar_items. Make sure we update both
9947 variables within BLOCK_INPUT so no such event interrupts. */
9949 f
->tool_bar_items
= new_tool_bar
;
9950 f
->n_tool_bar_items
= new_n_tool_bar
;
9951 w
->update_mode_line
= Qt
;
9957 unbind_to (count
, Qnil
);
9958 set_buffer_internal_1 (prev
);
9964 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9965 F's desired tool-bar contents. F->tool_bar_items must have
9966 been set up previously by calling prepare_menu_bars. */
9969 build_desired_tool_bar_string (f
)
9972 int i
, size
, size_needed
;
9973 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9974 Lisp_Object image
, plist
, props
;
9976 image
= plist
= props
= Qnil
;
9977 GCPRO3 (image
, plist
, props
);
9979 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9980 Otherwise, make a new string. */
9982 /* The size of the string we might be able to reuse. */
9983 size
= (STRINGP (f
->desired_tool_bar_string
)
9984 ? SCHARS (f
->desired_tool_bar_string
)
9987 /* We need one space in the string for each image. */
9988 size_needed
= f
->n_tool_bar_items
;
9990 /* Reuse f->desired_tool_bar_string, if possible. */
9991 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9992 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9996 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9997 Fremove_text_properties (make_number (0), make_number (size
),
9998 props
, f
->desired_tool_bar_string
);
10001 /* Put a `display' property on the string for the images to display,
10002 put a `menu_item' property on tool-bar items with a value that
10003 is the index of the item in F's tool-bar item vector. */
10004 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10006 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10008 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10009 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10010 int hmargin
, vmargin
, relief
, idx
, end
;
10011 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10013 /* If image is a vector, choose the image according to the
10015 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10016 if (VECTORP (image
))
10020 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10021 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10024 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10025 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10027 xassert (ASIZE (image
) >= idx
);
10028 image
= AREF (image
, idx
);
10033 /* Ignore invalid image specifications. */
10034 if (!valid_image_p (image
))
10037 /* Display the tool-bar button pressed, or depressed. */
10038 plist
= Fcopy_sequence (XCDR (image
));
10040 /* Compute margin and relief to draw. */
10041 relief
= (tool_bar_button_relief
>= 0
10042 ? tool_bar_button_relief
10043 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10044 hmargin
= vmargin
= relief
;
10046 if (INTEGERP (Vtool_bar_button_margin
)
10047 && XINT (Vtool_bar_button_margin
) > 0)
10049 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10050 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10052 else if (CONSP (Vtool_bar_button_margin
))
10054 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10055 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10056 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10058 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10059 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10060 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10063 if (auto_raise_tool_bar_buttons_p
)
10065 /* Add a `:relief' property to the image spec if the item is
10069 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10076 /* If image is selected, display it pressed, i.e. with a
10077 negative relief. If it's not selected, display it with a
10079 plist
= Fplist_put (plist
, QCrelief
,
10081 ? make_number (-relief
)
10082 : make_number (relief
)));
10087 /* Put a margin around the image. */
10088 if (hmargin
|| vmargin
)
10090 if (hmargin
== vmargin
)
10091 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10093 plist
= Fplist_put (plist
, QCmargin
,
10094 Fcons (make_number (hmargin
),
10095 make_number (vmargin
)));
10098 /* If button is not enabled, and we don't have special images
10099 for the disabled state, make the image appear disabled by
10100 applying an appropriate algorithm to it. */
10101 if (!enabled_p
&& idx
< 0)
10102 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10104 /* Put a `display' text property on the string for the image to
10105 display. Put a `menu-item' property on the string that gives
10106 the start of this item's properties in the tool-bar items
10108 image
= Fcons (Qimage
, plist
);
10109 props
= list4 (Qdisplay
, image
,
10110 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10112 /* Let the last image hide all remaining spaces in the tool bar
10113 string. The string can be longer than needed when we reuse a
10114 previous string. */
10115 if (i
+ 1 == f
->n_tool_bar_items
)
10116 end
= SCHARS (f
->desired_tool_bar_string
);
10119 Fadd_text_properties (make_number (i
), make_number (end
),
10120 props
, f
->desired_tool_bar_string
);
10128 /* Display one line of the tool-bar of frame IT->f.
10130 HEIGHT specifies the desired height of the tool-bar line.
10131 If the actual height of the glyph row is less than HEIGHT, the
10132 row's height is increased to HEIGHT, and the icons are centered
10133 vertically in the new height.
10135 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10136 count a final empty row in case the tool-bar width exactly matches
10141 display_tool_bar_line (it
, height
)
10145 struct glyph_row
*row
= it
->glyph_row
;
10146 int max_x
= it
->last_visible_x
;
10147 struct glyph
*last
;
10149 prepare_desired_row (row
);
10150 row
->y
= it
->current_y
;
10152 /* Note that this isn't made use of if the face hasn't a box,
10153 so there's no need to check the face here. */
10154 it
->start_of_box_run_p
= 1;
10156 while (it
->current_x
< max_x
)
10158 int x
, n_glyphs_before
, i
, nglyphs
;
10159 struct it it_before
;
10161 /* Get the next display element. */
10162 if (!get_next_display_element (it
))
10164 /* Don't count empty row if we are counting needed tool-bar lines. */
10165 if (height
< 0 && !it
->hpos
)
10170 /* Produce glyphs. */
10171 n_glyphs_before
= row
->used
[TEXT_AREA
];
10174 PRODUCE_GLYPHS (it
);
10176 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10178 x
= it_before
.current_x
;
10179 while (i
< nglyphs
)
10181 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10183 if (x
+ glyph
->pixel_width
> max_x
)
10185 /* Glyph doesn't fit on line. Backtrack. */
10186 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10188 /* If this is the only glyph on this line, it will never fit on the
10189 toolbar, so skip it. But ensure there is at least one glyph,
10190 so we don't accidentally disable the tool-bar. */
10191 if (n_glyphs_before
== 0
10192 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10198 x
+= glyph
->pixel_width
;
10202 /* Stop at line ends. */
10203 if (ITERATOR_AT_END_OF_LINE_P (it
))
10206 set_iterator_to_next (it
, 1);
10211 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10213 /* Use default face for the border below the tool bar.
10215 FIXME: When auto-resize-tool-bars is grow-only, there is
10216 no additional border below the possibly empty tool-bar lines.
10217 So to make the extra empty lines look "normal", we have to
10218 use the tool-bar face for the border too. */
10219 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10220 it
->face_id
= DEFAULT_FACE_ID
;
10222 extend_face_to_end_of_line (it
);
10223 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10224 last
->right_box_line_p
= 1;
10225 if (last
== row
->glyphs
[TEXT_AREA
])
10226 last
->left_box_line_p
= 1;
10228 /* Make line the desired height and center it vertically. */
10229 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10231 /* Don't add more than one line height. */
10232 height
%= FRAME_LINE_HEIGHT (it
->f
);
10233 it
->max_ascent
+= height
/ 2;
10234 it
->max_descent
+= (height
+ 1) / 2;
10237 compute_line_metrics (it
);
10239 /* If line is empty, make it occupy the rest of the tool-bar. */
10240 if (!row
->displays_text_p
)
10242 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10243 row
->visible_height
= row
->height
;
10244 row
->ascent
= row
->phys_ascent
= 0;
10245 row
->extra_line_spacing
= 0;
10248 row
->full_width_p
= 1;
10249 row
->continued_p
= 0;
10250 row
->truncated_on_left_p
= 0;
10251 row
->truncated_on_right_p
= 0;
10253 it
->current_x
= it
->hpos
= 0;
10254 it
->current_y
+= row
->height
;
10260 /* Max tool-bar height. */
10262 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10263 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10265 /* Value is the number of screen lines needed to make all tool-bar
10266 items of frame F visible. The number of actual rows needed is
10267 returned in *N_ROWS if non-NULL. */
10270 tool_bar_lines_needed (f
, n_rows
)
10274 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10276 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10277 the desired matrix, so use (unused) mode-line row as temporary row to
10278 avoid destroying the first tool-bar row. */
10279 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10281 /* Initialize an iterator for iteration over
10282 F->desired_tool_bar_string in the tool-bar window of frame F. */
10283 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10284 it
.first_visible_x
= 0;
10285 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10286 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10288 while (!ITERATOR_AT_END_P (&it
))
10290 clear_glyph_row (temp_row
);
10291 it
.glyph_row
= temp_row
;
10292 display_tool_bar_line (&it
, -1);
10294 clear_glyph_row (temp_row
);
10296 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10298 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10300 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10304 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10306 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10315 frame
= selected_frame
;
10317 CHECK_FRAME (frame
);
10318 f
= XFRAME (frame
);
10320 if (WINDOWP (f
->tool_bar_window
)
10321 || (w
= XWINDOW (f
->tool_bar_window
),
10322 WINDOW_TOTAL_LINES (w
) > 0))
10324 update_tool_bar (f
, 1);
10325 if (f
->n_tool_bar_items
)
10327 build_desired_tool_bar_string (f
);
10328 nlines
= tool_bar_lines_needed (f
, NULL
);
10332 return make_number (nlines
);
10336 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10337 height should be changed. */
10340 redisplay_tool_bar (f
)
10345 struct glyph_row
*row
;
10347 #if defined (USE_GTK) || defined (HAVE_NS)
10348 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10349 update_frame_tool_bar (f
);
10353 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10354 do anything. This means you must start with tool-bar-lines
10355 non-zero to get the auto-sizing effect. Or in other words, you
10356 can turn off tool-bars by specifying tool-bar-lines zero. */
10357 if (!WINDOWP (f
->tool_bar_window
)
10358 || (w
= XWINDOW (f
->tool_bar_window
),
10359 WINDOW_TOTAL_LINES (w
) == 0))
10362 /* Set up an iterator for the tool-bar window. */
10363 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10364 it
.first_visible_x
= 0;
10365 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10366 row
= it
.glyph_row
;
10368 /* Build a string that represents the contents of the tool-bar. */
10369 build_desired_tool_bar_string (f
);
10370 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10372 if (f
->n_tool_bar_rows
== 0)
10376 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10377 nlines
!= WINDOW_TOTAL_LINES (w
)))
10379 extern Lisp_Object Qtool_bar_lines
;
10381 int old_height
= WINDOW_TOTAL_LINES (w
);
10383 XSETFRAME (frame
, f
);
10384 Fmodify_frame_parameters (frame
,
10385 Fcons (Fcons (Qtool_bar_lines
,
10386 make_number (nlines
)),
10388 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10390 clear_glyph_matrix (w
->desired_matrix
);
10391 fonts_changed_p
= 1;
10397 /* Display as many lines as needed to display all tool-bar items. */
10399 if (f
->n_tool_bar_rows
> 0)
10401 int border
, rows
, height
, extra
;
10403 if (INTEGERP (Vtool_bar_border
))
10404 border
= XINT (Vtool_bar_border
);
10405 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10406 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10407 else if (EQ (Vtool_bar_border
, Qborder_width
))
10408 border
= f
->border_width
;
10414 rows
= f
->n_tool_bar_rows
;
10415 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10416 extra
= it
.last_visible_y
- border
- height
* rows
;
10418 while (it
.current_y
< it
.last_visible_y
)
10421 if (extra
> 0 && rows
-- > 0)
10423 h
= (extra
+ rows
- 1) / rows
;
10426 display_tool_bar_line (&it
, height
+ h
);
10431 while (it
.current_y
< it
.last_visible_y
)
10432 display_tool_bar_line (&it
, 0);
10435 /* It doesn't make much sense to try scrolling in the tool-bar
10436 window, so don't do it. */
10437 w
->desired_matrix
->no_scrolling_p
= 1;
10438 w
->must_be_updated_p
= 1;
10440 if (!NILP (Vauto_resize_tool_bars
))
10442 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10443 int change_height_p
= 0;
10445 /* If we couldn't display everything, change the tool-bar's
10446 height if there is room for more. */
10447 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10448 && it
.current_y
< max_tool_bar_height
)
10449 change_height_p
= 1;
10451 row
= it
.glyph_row
- 1;
10453 /* If there are blank lines at the end, except for a partially
10454 visible blank line at the end that is smaller than
10455 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10456 if (!row
->displays_text_p
10457 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10458 change_height_p
= 1;
10460 /* If row displays tool-bar items, but is partially visible,
10461 change the tool-bar's height. */
10462 if (row
->displays_text_p
10463 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10464 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10465 change_height_p
= 1;
10467 /* Resize windows as needed by changing the `tool-bar-lines'
10468 frame parameter. */
10469 if (change_height_p
)
10471 extern Lisp_Object Qtool_bar_lines
;
10473 int old_height
= WINDOW_TOTAL_LINES (w
);
10475 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10477 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10478 && !f
->minimize_tool_bar_window_p
)
10479 ? (nlines
> old_height
)
10480 : (nlines
!= old_height
));
10481 f
->minimize_tool_bar_window_p
= 0;
10483 if (change_height_p
)
10485 XSETFRAME (frame
, f
);
10486 Fmodify_frame_parameters (frame
,
10487 Fcons (Fcons (Qtool_bar_lines
,
10488 make_number (nlines
)),
10490 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10492 clear_glyph_matrix (w
->desired_matrix
);
10493 f
->n_tool_bar_rows
= nrows
;
10494 fonts_changed_p
= 1;
10501 f
->minimize_tool_bar_window_p
= 0;
10506 /* Get information about the tool-bar item which is displayed in GLYPH
10507 on frame F. Return in *PROP_IDX the index where tool-bar item
10508 properties start in F->tool_bar_items. Value is zero if
10509 GLYPH doesn't display a tool-bar item. */
10512 tool_bar_item_info (f
, glyph
, prop_idx
)
10514 struct glyph
*glyph
;
10521 /* This function can be called asynchronously, which means we must
10522 exclude any possibility that Fget_text_property signals an
10524 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10525 charpos
= max (0, charpos
);
10527 /* Get the text property `menu-item' at pos. The value of that
10528 property is the start index of this item's properties in
10529 F->tool_bar_items. */
10530 prop
= Fget_text_property (make_number (charpos
),
10531 Qmenu_item
, f
->current_tool_bar_string
);
10532 if (INTEGERP (prop
))
10534 *prop_idx
= XINT (prop
);
10544 /* Get information about the tool-bar item at position X/Y on frame F.
10545 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10546 the current matrix of the tool-bar window of F, or NULL if not
10547 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10548 item in F->tool_bar_items. Value is
10550 -1 if X/Y is not on a tool-bar item
10551 0 if X/Y is on the same item that was highlighted before.
10555 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10558 struct glyph
**glyph
;
10559 int *hpos
, *vpos
, *prop_idx
;
10561 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10562 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10565 /* Find the glyph under X/Y. */
10566 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10567 if (*glyph
== NULL
)
10570 /* Get the start of this tool-bar item's properties in
10571 f->tool_bar_items. */
10572 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10575 /* Is mouse on the highlighted item? */
10576 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10577 && *vpos
>= dpyinfo
->mouse_face_beg_row
10578 && *vpos
<= dpyinfo
->mouse_face_end_row
10579 && (*vpos
> dpyinfo
->mouse_face_beg_row
10580 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10581 && (*vpos
< dpyinfo
->mouse_face_end_row
10582 || *hpos
< dpyinfo
->mouse_face_end_col
10583 || dpyinfo
->mouse_face_past_end
))
10591 Handle mouse button event on the tool-bar of frame F, at
10592 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10593 0 for button release. MODIFIERS is event modifiers for button
10597 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10600 unsigned int modifiers
;
10602 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10603 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10604 int hpos
, vpos
, prop_idx
;
10605 struct glyph
*glyph
;
10606 Lisp_Object enabled_p
;
10608 /* If not on the highlighted tool-bar item, return. */
10609 frame_to_window_pixel_xy (w
, &x
, &y
);
10610 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10613 /* If item is disabled, do nothing. */
10614 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10615 if (NILP (enabled_p
))
10620 /* Show item in pressed state. */
10621 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10622 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10623 last_tool_bar_item
= prop_idx
;
10627 Lisp_Object key
, frame
;
10628 struct input_event event
;
10629 EVENT_INIT (event
);
10631 /* Show item in released state. */
10632 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10633 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10635 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10637 XSETFRAME (frame
, f
);
10638 event
.kind
= TOOL_BAR_EVENT
;
10639 event
.frame_or_window
= frame
;
10641 kbd_buffer_store_event (&event
);
10643 event
.kind
= TOOL_BAR_EVENT
;
10644 event
.frame_or_window
= frame
;
10646 event
.modifiers
= modifiers
;
10647 kbd_buffer_store_event (&event
);
10648 last_tool_bar_item
= -1;
10653 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10654 tool-bar window-relative coordinates X/Y. Called from
10655 note_mouse_highlight. */
10658 note_tool_bar_highlight (f
, x
, y
)
10662 Lisp_Object window
= f
->tool_bar_window
;
10663 struct window
*w
= XWINDOW (window
);
10664 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10666 struct glyph
*glyph
;
10667 struct glyph_row
*row
;
10669 Lisp_Object enabled_p
;
10671 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10672 int mouse_down_p
, rc
;
10674 /* Function note_mouse_highlight is called with negative x(y
10675 values when mouse moves outside of the frame. */
10676 if (x
<= 0 || y
<= 0)
10678 clear_mouse_face (dpyinfo
);
10682 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10685 /* Not on tool-bar item. */
10686 clear_mouse_face (dpyinfo
);
10690 /* On same tool-bar item as before. */
10691 goto set_help_echo
;
10693 clear_mouse_face (dpyinfo
);
10695 /* Mouse is down, but on different tool-bar item? */
10696 mouse_down_p
= (dpyinfo
->grabbed
10697 && f
== last_mouse_frame
10698 && FRAME_LIVE_P (f
));
10700 && last_tool_bar_item
!= prop_idx
)
10703 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10704 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10706 /* If tool-bar item is not enabled, don't highlight it. */
10707 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10708 if (!NILP (enabled_p
))
10710 /* Compute the x-position of the glyph. In front and past the
10711 image is a space. We include this in the highlighted area. */
10712 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10713 for (i
= x
= 0; i
< hpos
; ++i
)
10714 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10716 /* Record this as the current active region. */
10717 dpyinfo
->mouse_face_beg_col
= hpos
;
10718 dpyinfo
->mouse_face_beg_row
= vpos
;
10719 dpyinfo
->mouse_face_beg_x
= x
;
10720 dpyinfo
->mouse_face_beg_y
= row
->y
;
10721 dpyinfo
->mouse_face_past_end
= 0;
10723 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10724 dpyinfo
->mouse_face_end_row
= vpos
;
10725 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10726 dpyinfo
->mouse_face_end_y
= row
->y
;
10727 dpyinfo
->mouse_face_window
= window
;
10728 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10730 /* Display it as active. */
10731 show_mouse_face (dpyinfo
, draw
);
10732 dpyinfo
->mouse_face_image_state
= draw
;
10737 /* Set help_echo_string to a help string to display for this tool-bar item.
10738 XTread_socket does the rest. */
10739 help_echo_object
= help_echo_window
= Qnil
;
10740 help_echo_pos
= -1;
10741 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10742 if (NILP (help_echo_string
))
10743 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10746 #endif /* HAVE_WINDOW_SYSTEM */
10750 /************************************************************************
10751 Horizontal scrolling
10752 ************************************************************************/
10754 static int hscroll_window_tree
P_ ((Lisp_Object
));
10755 static int hscroll_windows
P_ ((Lisp_Object
));
10757 /* For all leaf windows in the window tree rooted at WINDOW, set their
10758 hscroll value so that PT is (i) visible in the window, and (ii) so
10759 that it is not within a certain margin at the window's left and
10760 right border. Value is non-zero if any window's hscroll has been
10764 hscroll_window_tree (window
)
10765 Lisp_Object window
;
10767 int hscrolled_p
= 0;
10768 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10769 int hscroll_step_abs
= 0;
10770 double hscroll_step_rel
= 0;
10772 if (hscroll_relative_p
)
10774 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10775 if (hscroll_step_rel
< 0)
10777 hscroll_relative_p
= 0;
10778 hscroll_step_abs
= 0;
10781 else if (INTEGERP (Vhscroll_step
))
10783 hscroll_step_abs
= XINT (Vhscroll_step
);
10784 if (hscroll_step_abs
< 0)
10785 hscroll_step_abs
= 0;
10788 hscroll_step_abs
= 0;
10790 while (WINDOWP (window
))
10792 struct window
*w
= XWINDOW (window
);
10794 if (WINDOWP (w
->hchild
))
10795 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10796 else if (WINDOWP (w
->vchild
))
10797 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10798 else if (w
->cursor
.vpos
>= 0)
10801 int text_area_width
;
10802 struct glyph_row
*current_cursor_row
10803 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10804 struct glyph_row
*desired_cursor_row
10805 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10806 struct glyph_row
*cursor_row
10807 = (desired_cursor_row
->enabled_p
10808 ? desired_cursor_row
10809 : current_cursor_row
);
10811 text_area_width
= window_box_width (w
, TEXT_AREA
);
10813 /* Scroll when cursor is inside this scroll margin. */
10814 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10816 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10817 && ((XFASTINT (w
->hscroll
)
10818 && w
->cursor
.x
<= h_margin
)
10819 || (cursor_row
->enabled_p
10820 && cursor_row
->truncated_on_right_p
10821 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10825 struct buffer
*saved_current_buffer
;
10829 /* Find point in a display of infinite width. */
10830 saved_current_buffer
= current_buffer
;
10831 current_buffer
= XBUFFER (w
->buffer
);
10833 if (w
== XWINDOW (selected_window
))
10834 pt
= BUF_PT (current_buffer
);
10837 pt
= marker_position (w
->pointm
);
10838 pt
= max (BEGV
, pt
);
10842 /* Move iterator to pt starting at cursor_row->start in
10843 a line with infinite width. */
10844 init_to_row_start (&it
, w
, cursor_row
);
10845 it
.last_visible_x
= INFINITY
;
10846 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10847 current_buffer
= saved_current_buffer
;
10849 /* Position cursor in window. */
10850 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10851 hscroll
= max (0, (it
.current_x
10852 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10853 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10854 : (text_area_width
/ 2))))
10855 / FRAME_COLUMN_WIDTH (it
.f
);
10856 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10858 if (hscroll_relative_p
)
10859 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10862 wanted_x
= text_area_width
10863 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10866 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10870 if (hscroll_relative_p
)
10871 wanted_x
= text_area_width
* hscroll_step_rel
10874 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10877 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10879 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10881 /* Don't call Fset_window_hscroll if value hasn't
10882 changed because it will prevent redisplay
10884 if (XFASTINT (w
->hscroll
) != hscroll
)
10886 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10887 w
->hscroll
= make_number (hscroll
);
10896 /* Value is non-zero if hscroll of any leaf window has been changed. */
10897 return hscrolled_p
;
10901 /* Set hscroll so that cursor is visible and not inside horizontal
10902 scroll margins for all windows in the tree rooted at WINDOW. See
10903 also hscroll_window_tree above. Value is non-zero if any window's
10904 hscroll has been changed. If it has, desired matrices on the frame
10905 of WINDOW are cleared. */
10908 hscroll_windows (window
)
10909 Lisp_Object window
;
10911 int hscrolled_p
= hscroll_window_tree (window
);
10913 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10914 return hscrolled_p
;
10919 /************************************************************************
10921 ************************************************************************/
10923 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10924 to a non-zero value. This is sometimes handy to have in a debugger
10929 /* First and last unchanged row for try_window_id. */
10931 int debug_first_unchanged_at_end_vpos
;
10932 int debug_last_unchanged_at_beg_vpos
;
10934 /* Delta vpos and y. */
10936 int debug_dvpos
, debug_dy
;
10938 /* Delta in characters and bytes for try_window_id. */
10940 int debug_delta
, debug_delta_bytes
;
10942 /* Values of window_end_pos and window_end_vpos at the end of
10945 EMACS_INT debug_end_pos
, debug_end_vpos
;
10947 /* Append a string to W->desired_matrix->method. FMT is a printf
10948 format string. A1...A9 are a supplement for a variable-length
10949 argument list. If trace_redisplay_p is non-zero also printf the
10950 resulting string to stderr. */
10953 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10956 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10959 char *method
= w
->desired_matrix
->method
;
10960 int len
= strlen (method
);
10961 int size
= sizeof w
->desired_matrix
->method
;
10962 int remaining
= size
- len
- 1;
10964 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10965 if (len
&& remaining
)
10968 --remaining
, ++len
;
10971 strncpy (method
+ len
, buffer
, remaining
);
10973 if (trace_redisplay_p
)
10974 fprintf (stderr
, "%p (%s): %s\n",
10976 ((BUFFERP (w
->buffer
)
10977 && STRINGP (XBUFFER (w
->buffer
)->name
))
10978 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10983 #endif /* GLYPH_DEBUG */
10986 /* Value is non-zero if all changes in window W, which displays
10987 current_buffer, are in the text between START and END. START is a
10988 buffer position, END is given as a distance from Z. Used in
10989 redisplay_internal for display optimization. */
10992 text_outside_line_unchanged_p (w
, start
, end
)
10996 int unchanged_p
= 1;
10998 /* If text or overlays have changed, see where. */
10999 if (XFASTINT (w
->last_modified
) < MODIFF
11000 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11002 /* Gap in the line? */
11003 if (GPT
< start
|| Z
- GPT
< end
)
11006 /* Changes start in front of the line, or end after it? */
11008 && (BEG_UNCHANGED
< start
- 1
11009 || END_UNCHANGED
< end
))
11012 /* If selective display, can't optimize if changes start at the
11013 beginning of the line. */
11015 && INTEGERP (current_buffer
->selective_display
)
11016 && XINT (current_buffer
->selective_display
) > 0
11017 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11020 /* If there are overlays at the start or end of the line, these
11021 may have overlay strings with newlines in them. A change at
11022 START, for instance, may actually concern the display of such
11023 overlay strings as well, and they are displayed on different
11024 lines. So, quickly rule out this case. (For the future, it
11025 might be desirable to implement something more telling than
11026 just BEG/END_UNCHANGED.) */
11029 if (BEG
+ BEG_UNCHANGED
== start
11030 && overlay_touches_p (start
))
11032 if (END_UNCHANGED
== end
11033 && overlay_touches_p (Z
- end
))
11038 return unchanged_p
;
11042 /* Do a frame update, taking possible shortcuts into account. This is
11043 the main external entry point for redisplay.
11045 If the last redisplay displayed an echo area message and that message
11046 is no longer requested, we clear the echo area or bring back the
11047 mini-buffer if that is in use. */
11052 redisplay_internal (0);
11057 overlay_arrow_string_or_property (var
)
11062 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11065 return Voverlay_arrow_string
;
11068 /* Return 1 if there are any overlay-arrows in current_buffer. */
11070 overlay_arrow_in_current_buffer_p ()
11074 for (vlist
= Voverlay_arrow_variable_list
;
11076 vlist
= XCDR (vlist
))
11078 Lisp_Object var
= XCAR (vlist
);
11081 if (!SYMBOLP (var
))
11083 val
= find_symbol_value (var
);
11085 && current_buffer
== XMARKER (val
)->buffer
)
11092 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11096 overlay_arrows_changed_p ()
11100 for (vlist
= Voverlay_arrow_variable_list
;
11102 vlist
= XCDR (vlist
))
11104 Lisp_Object var
= XCAR (vlist
);
11105 Lisp_Object val
, pstr
;
11107 if (!SYMBOLP (var
))
11109 val
= find_symbol_value (var
);
11110 if (!MARKERP (val
))
11112 if (! EQ (COERCE_MARKER (val
),
11113 Fget (var
, Qlast_arrow_position
))
11114 || ! (pstr
= overlay_arrow_string_or_property (var
),
11115 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11121 /* Mark overlay arrows to be updated on next redisplay. */
11124 update_overlay_arrows (up_to_date
)
11129 for (vlist
= Voverlay_arrow_variable_list
;
11131 vlist
= XCDR (vlist
))
11133 Lisp_Object var
= XCAR (vlist
);
11135 if (!SYMBOLP (var
))
11138 if (up_to_date
> 0)
11140 Lisp_Object val
= find_symbol_value (var
);
11141 Fput (var
, Qlast_arrow_position
,
11142 COERCE_MARKER (val
));
11143 Fput (var
, Qlast_arrow_string
,
11144 overlay_arrow_string_or_property (var
));
11146 else if (up_to_date
< 0
11147 || !NILP (Fget (var
, Qlast_arrow_position
)))
11149 Fput (var
, Qlast_arrow_position
, Qt
);
11150 Fput (var
, Qlast_arrow_string
, Qt
);
11156 /* Return overlay arrow string to display at row.
11157 Return integer (bitmap number) for arrow bitmap in left fringe.
11158 Return nil if no overlay arrow. */
11161 overlay_arrow_at_row (it
, row
)
11163 struct glyph_row
*row
;
11167 for (vlist
= Voverlay_arrow_variable_list
;
11169 vlist
= XCDR (vlist
))
11171 Lisp_Object var
= XCAR (vlist
);
11174 if (!SYMBOLP (var
))
11177 val
= find_symbol_value (var
);
11180 && current_buffer
== XMARKER (val
)->buffer
11181 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11183 if (FRAME_WINDOW_P (it
->f
)
11184 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11186 #ifdef HAVE_WINDOW_SYSTEM
11187 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11190 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11191 return make_number (fringe_bitmap
);
11194 return make_number (-1); /* Use default arrow bitmap */
11196 return overlay_arrow_string_or_property (var
);
11203 /* Return 1 if point moved out of or into a composition. Otherwise
11204 return 0. PREV_BUF and PREV_PT are the last point buffer and
11205 position. BUF and PT are the current point buffer and position. */
11208 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11209 struct buffer
*prev_buf
, *buf
;
11212 EMACS_INT start
, end
;
11214 Lisp_Object buffer
;
11216 XSETBUFFER (buffer
, buf
);
11217 /* Check a composition at the last point if point moved within the
11219 if (prev_buf
== buf
)
11222 /* Point didn't move. */
11225 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11226 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11227 && COMPOSITION_VALID_P (start
, end
, prop
)
11228 && start
< prev_pt
&& end
> prev_pt
)
11229 /* The last point was within the composition. Return 1 iff
11230 point moved out of the composition. */
11231 return (pt
<= start
|| pt
>= end
);
11234 /* Check a composition at the current point. */
11235 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11236 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11237 && COMPOSITION_VALID_P (start
, end
, prop
)
11238 && start
< pt
&& end
> pt
);
11242 /* Reconsider the setting of B->clip_changed which is displayed
11246 reconsider_clip_changes (w
, b
)
11250 if (b
->clip_changed
11251 && !NILP (w
->window_end_valid
)
11252 && w
->current_matrix
->buffer
== b
11253 && w
->current_matrix
->zv
== BUF_ZV (b
)
11254 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11255 b
->clip_changed
= 0;
11257 /* If display wasn't paused, and W is not a tool bar window, see if
11258 point has been moved into or out of a composition. In that case,
11259 we set b->clip_changed to 1 to force updating the screen. If
11260 b->clip_changed has already been set to 1, we can skip this
11262 if (!b
->clip_changed
11263 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11267 if (w
== XWINDOW (selected_window
))
11268 pt
= BUF_PT (current_buffer
);
11270 pt
= marker_position (w
->pointm
);
11272 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11273 || pt
!= XINT (w
->last_point
))
11274 && check_point_in_composition (w
->current_matrix
->buffer
,
11275 XINT (w
->last_point
),
11276 XBUFFER (w
->buffer
), pt
))
11277 b
->clip_changed
= 1;
11282 /* Select FRAME to forward the values of frame-local variables into C
11283 variables so that the redisplay routines can access those values
11287 select_frame_for_redisplay (frame
)
11290 Lisp_Object tail
, symbol
, val
;
11291 Lisp_Object old
= selected_frame
;
11292 struct Lisp_Symbol
*sym
;
11294 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11296 selected_frame
= frame
;
11300 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11301 if (CONSP (XCAR (tail
))
11302 && (symbol
= XCAR (XCAR (tail
)),
11304 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11306 (BUFFER_LOCAL_VALUEP (val
)))
11307 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11308 /* Use find_symbol_value rather than Fsymbol_value
11309 to avoid an error if it is void. */
11310 find_symbol_value (symbol
);
11311 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11315 #define STOP_POLLING \
11316 do { if (! polling_stopped_here) stop_polling (); \
11317 polling_stopped_here = 1; } while (0)
11319 #define RESUME_POLLING \
11320 do { if (polling_stopped_here) start_polling (); \
11321 polling_stopped_here = 0; } while (0)
11324 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11325 response to any user action; therefore, we should preserve the echo
11326 area. (Actually, our caller does that job.) Perhaps in the future
11327 avoid recentering windows if it is not necessary; currently that
11328 causes some problems. */
11331 redisplay_internal (preserve_echo_area
)
11332 int preserve_echo_area
;
11334 struct window
*w
= XWINDOW (selected_window
);
11337 int must_finish
= 0;
11338 struct text_pos tlbufpos
, tlendpos
;
11339 int number_of_visible_frames
;
11342 int polling_stopped_here
= 0;
11343 Lisp_Object old_frame
= selected_frame
;
11345 /* Non-zero means redisplay has to consider all windows on all
11346 frames. Zero means, only selected_window is considered. */
11347 int consider_all_windows_p
;
11349 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11351 /* No redisplay if running in batch mode or frame is not yet fully
11352 initialized, or redisplay is explicitly turned off by setting
11353 Vinhibit_redisplay. */
11354 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11355 || !NILP (Vinhibit_redisplay
))
11358 /* Don't examine these until after testing Vinhibit_redisplay.
11359 When Emacs is shutting down, perhaps because its connection to
11360 X has dropped, we should not look at them at all. */
11361 f
= XFRAME (w
->frame
);
11362 sf
= SELECTED_FRAME ();
11364 if (!f
->glyphs_initialized_p
)
11367 /* The flag redisplay_performed_directly_p is set by
11368 direct_output_for_insert when it already did the whole screen
11369 update necessary. */
11370 if (redisplay_performed_directly_p
)
11372 redisplay_performed_directly_p
= 0;
11373 if (!hscroll_windows (selected_window
))
11377 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11378 if (popup_activated ())
11382 /* I don't think this happens but let's be paranoid. */
11383 if (redisplaying_p
)
11386 /* Record a function that resets redisplaying_p to its old value
11387 when we leave this function. */
11388 count
= SPECPDL_INDEX ();
11389 record_unwind_protect (unwind_redisplay
,
11390 Fcons (make_number (redisplaying_p
), selected_frame
));
11392 specbind (Qinhibit_free_realized_faces
, Qnil
);
11395 Lisp_Object tail
, frame
;
11397 FOR_EACH_FRAME (tail
, frame
)
11399 struct frame
*f
= XFRAME (frame
);
11400 f
->already_hscrolled_p
= 0;
11405 if (!EQ (old_frame
, selected_frame
)
11406 && FRAME_LIVE_P (XFRAME (old_frame
)))
11407 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11408 selected_frame and selected_window to be temporarily out-of-sync so
11409 when we come back here via `goto retry', we need to resync because we
11410 may need to run Elisp code (via prepare_menu_bars). */
11411 select_frame_for_redisplay (old_frame
);
11414 reconsider_clip_changes (w
, current_buffer
);
11415 last_escape_glyph_frame
= NULL
;
11416 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11418 /* If new fonts have been loaded that make a glyph matrix adjustment
11419 necessary, do it. */
11420 if (fonts_changed_p
)
11422 adjust_glyphs (NULL
);
11423 ++windows_or_buffers_changed
;
11424 fonts_changed_p
= 0;
11427 /* If face_change_count is non-zero, init_iterator will free all
11428 realized faces, which includes the faces referenced from current
11429 matrices. So, we can't reuse current matrices in this case. */
11430 if (face_change_count
)
11431 ++windows_or_buffers_changed
;
11433 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11434 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11436 /* Since frames on a single ASCII terminal share the same
11437 display area, displaying a different frame means redisplay
11438 the whole thing. */
11439 windows_or_buffers_changed
++;
11440 SET_FRAME_GARBAGED (sf
);
11442 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11444 FRAME_TTY (sf
)->previous_frame
= sf
;
11447 /* Set the visible flags for all frames. Do this before checking
11448 for resized or garbaged frames; they want to know if their frames
11449 are visible. See the comment in frame.h for
11450 FRAME_SAMPLE_VISIBILITY. */
11452 Lisp_Object tail
, frame
;
11454 number_of_visible_frames
= 0;
11456 FOR_EACH_FRAME (tail
, frame
)
11458 struct frame
*f
= XFRAME (frame
);
11460 FRAME_SAMPLE_VISIBILITY (f
);
11461 if (FRAME_VISIBLE_P (f
))
11462 ++number_of_visible_frames
;
11463 clear_desired_matrices (f
);
11467 /* Notice any pending interrupt request to change frame size. */
11468 do_pending_window_change (1);
11470 /* Clear frames marked as garbaged. */
11471 if (frame_garbaged
)
11472 clear_garbaged_frames ();
11474 /* Build menubar and tool-bar items. */
11475 if (NILP (Vmemory_full
))
11476 prepare_menu_bars ();
11478 if (windows_or_buffers_changed
)
11479 update_mode_lines
++;
11481 /* Detect case that we need to write or remove a star in the mode line. */
11482 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11484 w
->update_mode_line
= Qt
;
11485 if (buffer_shared
> 1)
11486 update_mode_lines
++;
11489 /* Avoid invocation of point motion hooks by `current_column' below. */
11490 count1
= SPECPDL_INDEX ();
11491 specbind (Qinhibit_point_motion_hooks
, Qt
);
11493 /* If %c is in the mode line, update it if needed. */
11494 if (!NILP (w
->column_number_displayed
)
11495 /* This alternative quickly identifies a common case
11496 where no change is needed. */
11497 && !(PT
== XFASTINT (w
->last_point
)
11498 && XFASTINT (w
->last_modified
) >= MODIFF
11499 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11500 && (XFASTINT (w
->column_number_displayed
)
11501 != (int) current_column ())) /* iftc */
11502 w
->update_mode_line
= Qt
;
11504 unbind_to (count1
, Qnil
);
11506 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11508 /* The variable buffer_shared is set in redisplay_window and
11509 indicates that we redisplay a buffer in different windows. See
11511 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11512 || cursor_type_changed
);
11514 /* If specs for an arrow have changed, do thorough redisplay
11515 to ensure we remove any arrow that should no longer exist. */
11516 if (overlay_arrows_changed_p ())
11517 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11519 /* Normally the message* functions will have already displayed and
11520 updated the echo area, but the frame may have been trashed, or
11521 the update may have been preempted, so display the echo area
11522 again here. Checking message_cleared_p captures the case that
11523 the echo area should be cleared. */
11524 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11525 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11526 || (message_cleared_p
11527 && minibuf_level
== 0
11528 /* If the mini-window is currently selected, this means the
11529 echo-area doesn't show through. */
11530 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11532 int window_height_changed_p
= echo_area_display (0);
11535 /* If we don't display the current message, don't clear the
11536 message_cleared_p flag, because, if we did, we wouldn't clear
11537 the echo area in the next redisplay which doesn't preserve
11539 if (!display_last_displayed_message_p
)
11540 message_cleared_p
= 0;
11542 if (fonts_changed_p
)
11544 else if (window_height_changed_p
)
11546 consider_all_windows_p
= 1;
11547 ++update_mode_lines
;
11548 ++windows_or_buffers_changed
;
11550 /* If window configuration was changed, frames may have been
11551 marked garbaged. Clear them or we will experience
11552 surprises wrt scrolling. */
11553 if (frame_garbaged
)
11554 clear_garbaged_frames ();
11557 else if (EQ (selected_window
, minibuf_window
)
11558 && (current_buffer
->clip_changed
11559 || XFASTINT (w
->last_modified
) < MODIFF
11560 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11561 && resize_mini_window (w
, 0))
11563 /* Resized active mini-window to fit the size of what it is
11564 showing if its contents might have changed. */
11566 /* FIXME: this causes all frames to be updated, which seems unnecessary
11567 since only the current frame needs to be considered. This function needs
11568 to be rewritten with two variables, consider_all_windows and
11569 consider_all_frames. */
11570 consider_all_windows_p
= 1;
11571 ++windows_or_buffers_changed
;
11572 ++update_mode_lines
;
11574 /* If window configuration was changed, frames may have been
11575 marked garbaged. Clear them or we will experience
11576 surprises wrt scrolling. */
11577 if (frame_garbaged
)
11578 clear_garbaged_frames ();
11582 /* If showing the region, and mark has changed, we must redisplay
11583 the whole window. The assignment to this_line_start_pos prevents
11584 the optimization directly below this if-statement. */
11585 if (((!NILP (Vtransient_mark_mode
)
11586 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11587 != !NILP (w
->region_showing
))
11588 || (!NILP (w
->region_showing
)
11589 && !EQ (w
->region_showing
,
11590 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11591 CHARPOS (this_line_start_pos
) = 0;
11593 /* Optimize the case that only the line containing the cursor in the
11594 selected window has changed. Variables starting with this_ are
11595 set in display_line and record information about the line
11596 containing the cursor. */
11597 tlbufpos
= this_line_start_pos
;
11598 tlendpos
= this_line_end_pos
;
11599 if (!consider_all_windows_p
11600 && CHARPOS (tlbufpos
) > 0
11601 && NILP (w
->update_mode_line
)
11602 && !current_buffer
->clip_changed
11603 && !current_buffer
->prevent_redisplay_optimizations_p
11604 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11605 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11606 /* Make sure recorded data applies to current buffer, etc. */
11607 && this_line_buffer
== current_buffer
11608 && current_buffer
== XBUFFER (w
->buffer
)
11609 && NILP (w
->force_start
)
11610 && NILP (w
->optional_new_start
)
11611 /* Point must be on the line that we have info recorded about. */
11612 && PT
>= CHARPOS (tlbufpos
)
11613 && PT
<= Z
- CHARPOS (tlendpos
)
11614 /* All text outside that line, including its final newline,
11615 must be unchanged. */
11616 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11617 CHARPOS (tlendpos
)))
11619 if (CHARPOS (tlbufpos
) > BEGV
11620 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11621 && (CHARPOS (tlbufpos
) == ZV
11622 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11623 /* Former continuation line has disappeared by becoming empty. */
11625 else if (XFASTINT (w
->last_modified
) < MODIFF
11626 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11627 || MINI_WINDOW_P (w
))
11629 /* We have to handle the case of continuation around a
11630 wide-column character (see the comment in indent.c around
11633 For instance, in the following case:
11635 -------- Insert --------
11636 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11637 J_I_ ==> J_I_ `^^' are cursors.
11641 As we have to redraw the line above, we cannot use this
11645 int line_height_before
= this_line_pixel_height
;
11647 /* Note that start_display will handle the case that the
11648 line starting at tlbufpos is a continuation line. */
11649 start_display (&it
, w
, tlbufpos
);
11651 /* Implementation note: It this still necessary? */
11652 if (it
.current_x
!= this_line_start_x
)
11655 TRACE ((stderr
, "trying display optimization 1\n"));
11656 w
->cursor
.vpos
= -1;
11657 overlay_arrow_seen
= 0;
11658 it
.vpos
= this_line_vpos
;
11659 it
.current_y
= this_line_y
;
11660 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11661 display_line (&it
);
11663 /* If line contains point, is not continued,
11664 and ends at same distance from eob as before, we win. */
11665 if (w
->cursor
.vpos
>= 0
11666 /* Line is not continued, otherwise this_line_start_pos
11667 would have been set to 0 in display_line. */
11668 && CHARPOS (this_line_start_pos
)
11669 /* Line ends as before. */
11670 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11671 /* Line has same height as before. Otherwise other lines
11672 would have to be shifted up or down. */
11673 && this_line_pixel_height
== line_height_before
)
11675 /* If this is not the window's last line, we must adjust
11676 the charstarts of the lines below. */
11677 if (it
.current_y
< it
.last_visible_y
)
11679 struct glyph_row
*row
11680 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11681 int delta
, delta_bytes
;
11683 /* We used to distinguish between two cases here,
11684 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11685 when the line ends in a newline or the end of the
11686 buffer's accessible portion. But both cases did
11687 the same, so they were collapsed. */
11689 - CHARPOS (tlendpos
)
11690 - MATRIX_ROW_START_CHARPOS (row
));
11691 delta_bytes
= (Z_BYTE
11692 - BYTEPOS (tlendpos
)
11693 - MATRIX_ROW_START_BYTEPOS (row
));
11695 increment_matrix_positions (w
->current_matrix
,
11696 this_line_vpos
+ 1,
11697 w
->current_matrix
->nrows
,
11698 delta
, delta_bytes
);
11701 /* If this row displays text now but previously didn't,
11702 or vice versa, w->window_end_vpos may have to be
11704 if ((it
.glyph_row
- 1)->displays_text_p
)
11706 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11707 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11709 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11710 && this_line_vpos
> 0)
11711 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11712 w
->window_end_valid
= Qnil
;
11714 /* Update hint: No need to try to scroll in update_window. */
11715 w
->desired_matrix
->no_scrolling_p
= 1;
11718 *w
->desired_matrix
->method
= 0;
11719 debug_method_add (w
, "optimization 1");
11721 #ifdef HAVE_WINDOW_SYSTEM
11722 update_window_fringes (w
, 0);
11729 else if (/* Cursor position hasn't changed. */
11730 PT
== XFASTINT (w
->last_point
)
11731 /* Make sure the cursor was last displayed
11732 in this window. Otherwise we have to reposition it. */
11733 && 0 <= w
->cursor
.vpos
11734 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11738 do_pending_window_change (1);
11740 /* We used to always goto end_of_redisplay here, but this
11741 isn't enough if we have a blinking cursor. */
11742 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11743 goto end_of_redisplay
;
11747 /* If highlighting the region, or if the cursor is in the echo area,
11748 then we can't just move the cursor. */
11749 else if (! (!NILP (Vtransient_mark_mode
)
11750 && !NILP (current_buffer
->mark_active
))
11751 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11752 || highlight_nonselected_windows
)
11753 && NILP (w
->region_showing
)
11754 && NILP (Vshow_trailing_whitespace
)
11755 && !cursor_in_echo_area
)
11758 struct glyph_row
*row
;
11760 /* Skip from tlbufpos to PT and see where it is. Note that
11761 PT may be in invisible text. If so, we will end at the
11762 next visible position. */
11763 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11764 NULL
, DEFAULT_FACE_ID
);
11765 it
.current_x
= this_line_start_x
;
11766 it
.current_y
= this_line_y
;
11767 it
.vpos
= this_line_vpos
;
11769 /* The call to move_it_to stops in front of PT, but
11770 moves over before-strings. */
11771 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11773 if (it
.vpos
== this_line_vpos
11774 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11777 xassert (this_line_vpos
== it
.vpos
);
11778 xassert (this_line_y
== it
.current_y
);
11779 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11781 *w
->desired_matrix
->method
= 0;
11782 debug_method_add (w
, "optimization 3");
11791 /* Text changed drastically or point moved off of line. */
11792 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11795 CHARPOS (this_line_start_pos
) = 0;
11796 consider_all_windows_p
|= buffer_shared
> 1;
11797 ++clear_face_cache_count
;
11798 #ifdef HAVE_WINDOW_SYSTEM
11799 ++clear_image_cache_count
;
11802 /* Build desired matrices, and update the display. If
11803 consider_all_windows_p is non-zero, do it for all windows on all
11804 frames. Otherwise do it for selected_window, only. */
11806 if (consider_all_windows_p
)
11808 Lisp_Object tail
, frame
;
11810 FOR_EACH_FRAME (tail
, frame
)
11811 XFRAME (frame
)->updated_p
= 0;
11813 /* Recompute # windows showing selected buffer. This will be
11814 incremented each time such a window is displayed. */
11817 FOR_EACH_FRAME (tail
, frame
)
11819 struct frame
*f
= XFRAME (frame
);
11821 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11823 if (! EQ (frame
, selected_frame
))
11824 /* Select the frame, for the sake of frame-local
11826 select_frame_for_redisplay (frame
);
11828 /* Mark all the scroll bars to be removed; we'll redeem
11829 the ones we want when we redisplay their windows. */
11830 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11831 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11833 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11834 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11836 /* The X error handler may have deleted that frame. */
11837 if (!FRAME_LIVE_P (f
))
11840 /* Any scroll bars which redisplay_windows should have
11841 nuked should now go away. */
11842 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11843 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11845 /* If fonts changed, display again. */
11846 /* ??? rms: I suspect it is a mistake to jump all the way
11847 back to retry here. It should just retry this frame. */
11848 if (fonts_changed_p
)
11851 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11853 /* See if we have to hscroll. */
11854 if (!f
->already_hscrolled_p
)
11856 f
->already_hscrolled_p
= 1;
11857 if (hscroll_windows (f
->root_window
))
11861 /* Prevent various kinds of signals during display
11862 update. stdio is not robust about handling
11863 signals, which can cause an apparent I/O
11865 if (interrupt_input
)
11866 unrequest_sigio ();
11869 /* Update the display. */
11870 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11871 pause
|= update_frame (f
, 0, 0);
11877 if (!EQ (old_frame
, selected_frame
)
11878 && FRAME_LIVE_P (XFRAME (old_frame
)))
11879 /* We played a bit fast-and-loose above and allowed selected_frame
11880 and selected_window to be temporarily out-of-sync but let's make
11881 sure this stays contained. */
11882 select_frame_for_redisplay (old_frame
);
11883 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11887 /* Do the mark_window_display_accurate after all windows have
11888 been redisplayed because this call resets flags in buffers
11889 which are needed for proper redisplay. */
11890 FOR_EACH_FRAME (tail
, frame
)
11892 struct frame
*f
= XFRAME (frame
);
11895 mark_window_display_accurate (f
->root_window
, 1);
11896 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11897 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11902 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11904 Lisp_Object mini_window
;
11905 struct frame
*mini_frame
;
11907 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11908 /* Use list_of_error, not Qerror, so that
11909 we catch only errors and don't run the debugger. */
11910 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11912 redisplay_window_error
);
11914 /* Compare desired and current matrices, perform output. */
11917 /* If fonts changed, display again. */
11918 if (fonts_changed_p
)
11921 /* Prevent various kinds of signals during display update.
11922 stdio is not robust about handling signals,
11923 which can cause an apparent I/O error. */
11924 if (interrupt_input
)
11925 unrequest_sigio ();
11928 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11930 if (hscroll_windows (selected_window
))
11933 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11934 pause
= update_frame (sf
, 0, 0);
11937 /* We may have called echo_area_display at the top of this
11938 function. If the echo area is on another frame, that may
11939 have put text on a frame other than the selected one, so the
11940 above call to update_frame would not have caught it. Catch
11942 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11943 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11945 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11947 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11948 pause
|= update_frame (mini_frame
, 0, 0);
11949 if (!pause
&& hscroll_windows (mini_window
))
11954 /* If display was paused because of pending input, make sure we do a
11955 thorough update the next time. */
11958 /* Prevent the optimization at the beginning of
11959 redisplay_internal that tries a single-line update of the
11960 line containing the cursor in the selected window. */
11961 CHARPOS (this_line_start_pos
) = 0;
11963 /* Let the overlay arrow be updated the next time. */
11964 update_overlay_arrows (0);
11966 /* If we pause after scrolling, some rows in the current
11967 matrices of some windows are not valid. */
11968 if (!WINDOW_FULL_WIDTH_P (w
)
11969 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11970 update_mode_lines
= 1;
11974 if (!consider_all_windows_p
)
11976 /* This has already been done above if
11977 consider_all_windows_p is set. */
11978 mark_window_display_accurate_1 (w
, 1);
11980 /* Say overlay arrows are up to date. */
11981 update_overlay_arrows (1);
11983 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11984 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11987 update_mode_lines
= 0;
11988 windows_or_buffers_changed
= 0;
11989 cursor_type_changed
= 0;
11992 /* Start SIGIO interrupts coming again. Having them off during the
11993 code above makes it less likely one will discard output, but not
11994 impossible, since there might be stuff in the system buffer here.
11995 But it is much hairier to try to do anything about that. */
11996 if (interrupt_input
)
12000 /* If a frame has become visible which was not before, redisplay
12001 again, so that we display it. Expose events for such a frame
12002 (which it gets when becoming visible) don't call the parts of
12003 redisplay constructing glyphs, so simply exposing a frame won't
12004 display anything in this case. So, we have to display these
12005 frames here explicitly. */
12008 Lisp_Object tail
, frame
;
12011 FOR_EACH_FRAME (tail
, frame
)
12013 int this_is_visible
= 0;
12015 if (XFRAME (frame
)->visible
)
12016 this_is_visible
= 1;
12017 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12018 if (XFRAME (frame
)->visible
)
12019 this_is_visible
= 1;
12021 if (this_is_visible
)
12025 if (new_count
!= number_of_visible_frames
)
12026 windows_or_buffers_changed
++;
12029 /* Change frame size now if a change is pending. */
12030 do_pending_window_change (1);
12032 /* If we just did a pending size change, or have additional
12033 visible frames, redisplay again. */
12034 if (windows_or_buffers_changed
&& !pause
)
12037 /* Clear the face cache eventually. */
12038 if (consider_all_windows_p
)
12040 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12042 clear_face_cache (0);
12043 clear_face_cache_count
= 0;
12045 #ifdef HAVE_WINDOW_SYSTEM
12046 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12048 clear_image_caches (Qnil
);
12049 clear_image_cache_count
= 0;
12051 #endif /* HAVE_WINDOW_SYSTEM */
12055 unbind_to (count
, Qnil
);
12060 /* Redisplay, but leave alone any recent echo area message unless
12061 another message has been requested in its place.
12063 This is useful in situations where you need to redisplay but no
12064 user action has occurred, making it inappropriate for the message
12065 area to be cleared. See tracking_off and
12066 wait_reading_process_output for examples of these situations.
12068 FROM_WHERE is an integer saying from where this function was
12069 called. This is useful for debugging. */
12072 redisplay_preserve_echo_area (from_where
)
12075 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12077 if (!NILP (echo_area_buffer
[1]))
12079 /* We have a previously displayed message, but no current
12080 message. Redisplay the previous message. */
12081 display_last_displayed_message_p
= 1;
12082 redisplay_internal (1);
12083 display_last_displayed_message_p
= 0;
12086 redisplay_internal (1);
12088 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12089 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12090 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12094 /* Function registered with record_unwind_protect in
12095 redisplay_internal. Reset redisplaying_p to the value it had
12096 before redisplay_internal was called, and clear
12097 prevent_freeing_realized_faces_p. It also selects the previously
12098 selected frame, unless it has been deleted (by an X connection
12099 failure during redisplay, for example). */
12102 unwind_redisplay (val
)
12105 Lisp_Object old_redisplaying_p
, old_frame
;
12107 old_redisplaying_p
= XCAR (val
);
12108 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12109 old_frame
= XCDR (val
);
12110 if (! EQ (old_frame
, selected_frame
)
12111 && FRAME_LIVE_P (XFRAME (old_frame
)))
12112 select_frame_for_redisplay (old_frame
);
12117 /* Mark the display of window W as accurate or inaccurate. If
12118 ACCURATE_P is non-zero mark display of W as accurate. If
12119 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12120 redisplay_internal is called. */
12123 mark_window_display_accurate_1 (w
, accurate_p
)
12127 if (BUFFERP (w
->buffer
))
12129 struct buffer
*b
= XBUFFER (w
->buffer
);
12132 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12133 w
->last_overlay_modified
12134 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12136 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12140 b
->clip_changed
= 0;
12141 b
->prevent_redisplay_optimizations_p
= 0;
12143 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12144 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12145 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12146 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12148 w
->current_matrix
->buffer
= b
;
12149 w
->current_matrix
->begv
= BUF_BEGV (b
);
12150 w
->current_matrix
->zv
= BUF_ZV (b
);
12152 w
->last_cursor
= w
->cursor
;
12153 w
->last_cursor_off_p
= w
->cursor_off_p
;
12155 if (w
== XWINDOW (selected_window
))
12156 w
->last_point
= make_number (BUF_PT (b
));
12158 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12164 w
->window_end_valid
= w
->buffer
;
12165 w
->update_mode_line
= Qnil
;
12170 /* Mark the display of windows in the window tree rooted at WINDOW as
12171 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12172 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12173 be redisplayed the next time redisplay_internal is called. */
12176 mark_window_display_accurate (window
, accurate_p
)
12177 Lisp_Object window
;
12182 for (; !NILP (window
); window
= w
->next
)
12184 w
= XWINDOW (window
);
12185 mark_window_display_accurate_1 (w
, accurate_p
);
12187 if (!NILP (w
->vchild
))
12188 mark_window_display_accurate (w
->vchild
, accurate_p
);
12189 if (!NILP (w
->hchild
))
12190 mark_window_display_accurate (w
->hchild
, accurate_p
);
12195 update_overlay_arrows (1);
12199 /* Force a thorough redisplay the next time by setting
12200 last_arrow_position and last_arrow_string to t, which is
12201 unequal to any useful value of Voverlay_arrow_... */
12202 update_overlay_arrows (-1);
12207 /* Return value in display table DP (Lisp_Char_Table *) for character
12208 C. Since a display table doesn't have any parent, we don't have to
12209 follow parent. Do not call this function directly but use the
12210 macro DISP_CHAR_VECTOR. */
12213 disp_char_vector (dp
, c
)
12214 struct Lisp_Char_Table
*dp
;
12219 if (ASCII_CHAR_P (c
))
12222 if (SUB_CHAR_TABLE_P (val
))
12223 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12229 XSETCHAR_TABLE (table
, dp
);
12230 val
= char_table_ref (table
, c
);
12239 /***********************************************************************
12241 ***********************************************************************/
12243 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12246 redisplay_windows (window
)
12247 Lisp_Object window
;
12249 while (!NILP (window
))
12251 struct window
*w
= XWINDOW (window
);
12253 if (!NILP (w
->hchild
))
12254 redisplay_windows (w
->hchild
);
12255 else if (!NILP (w
->vchild
))
12256 redisplay_windows (w
->vchild
);
12257 else if (!NILP (w
->buffer
))
12259 displayed_buffer
= XBUFFER (w
->buffer
);
12260 /* Use list_of_error, not Qerror, so that
12261 we catch only errors and don't run the debugger. */
12262 internal_condition_case_1 (redisplay_window_0
, window
,
12264 redisplay_window_error
);
12272 redisplay_window_error ()
12274 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12279 redisplay_window_0 (window
)
12280 Lisp_Object window
;
12282 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12283 redisplay_window (window
, 0);
12288 redisplay_window_1 (window
)
12289 Lisp_Object window
;
12291 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12292 redisplay_window (window
, 1);
12297 /* Increment GLYPH until it reaches END or CONDITION fails while
12298 adding (GLYPH)->pixel_width to X. */
12300 #define SKIP_GLYPHS(glyph, end, x, condition) \
12303 (x) += (glyph)->pixel_width; \
12306 while ((glyph) < (end) && (condition))
12309 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12310 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12311 which positions recorded in ROW differ from current buffer
12314 Return 0 if cursor is not on this row, 1 otherwise. */
12317 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12319 struct glyph_row
*row
;
12320 struct glyph_matrix
*matrix
;
12321 int delta
, delta_bytes
, dy
, dvpos
;
12323 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12324 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12325 struct glyph
*cursor
= NULL
;
12326 /* The first glyph that starts a sequence of glyphs from a string
12327 that is a value of a display property. */
12328 struct glyph
*string_start
;
12329 /* The X coordinate of string_start. */
12330 int string_start_x
;
12331 /* The last known character position in row. */
12332 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12333 /* The last known character position before string_start. */
12334 int string_before_pos
;
12337 /* Last buffer position covered by an overlay. */
12338 int cursor_from_overlay_pos
= 0;
12339 int pt_old
= PT
- delta
;
12341 /* Skip over glyphs not having an object at the start of the row.
12342 These are special glyphs like truncation marks on terminal
12344 if (row
->displays_text_p
)
12346 && INTEGERP (glyph
->object
)
12347 && glyph
->charpos
< 0)
12349 x
+= glyph
->pixel_width
;
12353 string_start
= NULL
;
12355 && !INTEGERP (glyph
->object
)
12356 && (!BUFFERP (glyph
->object
)
12357 || (last_pos
= glyph
->charpos
) < pt_old
12358 || glyph
->avoid_cursor_p
))
12360 if (! STRINGP (glyph
->object
))
12362 string_start
= NULL
;
12363 x
+= glyph
->pixel_width
;
12365 /* If we are beyond the cursor position computed from the
12366 last overlay seen, that overlay is not in effect for
12367 current cursor position. Reset the cursor information
12368 computed from that overlay. */
12369 if (cursor_from_overlay_pos
12370 && last_pos
>= cursor_from_overlay_pos
)
12372 cursor_from_overlay_pos
= 0;
12378 if (string_start
== NULL
)
12380 string_before_pos
= last_pos
;
12381 string_start
= glyph
;
12382 string_start_x
= x
;
12384 /* Skip all glyphs from a string. */
12389 if ((cursor
== NULL
|| glyph
> cursor
)
12390 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12391 Qcursor
, (glyph
)->object
),
12393 && (pos
= string_buffer_position (w
, glyph
->object
,
12394 string_before_pos
),
12395 (pos
== 0 /* from overlay */
12396 || pos
== pt_old
)))
12398 /* Compute the first buffer position after the overlay.
12399 If the `cursor' property tells us how many positions
12400 are associated with the overlay, use that. Otherwise,
12401 estimate from the buffer positions of the glyphs
12402 before and after the overlay. */
12403 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12404 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12408 x
+= glyph
->pixel_width
;
12411 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12415 if (cursor
!= NULL
)
12420 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12422 /* Scan back over the ellipsis glyphs, decrementing positions. */
12423 while (glyph
> row
->glyphs
[TEXT_AREA
]
12424 && (glyph
- 1)->charpos
== last_pos
)
12425 glyph
--, x
-= glyph
->pixel_width
;
12426 /* That loop always goes one position too far, including the
12427 glyph before the ellipsis. So scan forward over that one. */
12428 x
+= glyph
->pixel_width
;
12431 else if (string_start
12432 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12434 /* We may have skipped over point because the previous glyphs
12435 are from string. As there's no easy way to know the
12436 character position of the current glyph, find the correct
12437 glyph on point by scanning from string_start again. */
12439 Lisp_Object string
;
12440 struct glyph
*stop
= glyph
;
12443 limit
= make_number (pt_old
+ 1);
12444 glyph
= string_start
;
12445 x
= string_start_x
;
12446 string
= glyph
->object
;
12447 pos
= string_buffer_position (w
, string
, string_before_pos
);
12448 /* If POS == 0, STRING is from overlay. We skip such glyphs
12449 because we always put the cursor after overlay strings. */
12450 while (pos
== 0 && glyph
< stop
)
12452 string
= glyph
->object
;
12453 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12455 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12458 while (glyph
< stop
)
12460 pos
= XINT (Fnext_single_char_property_change
12461 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12464 /* Skip glyphs from the same string. */
12465 string
= glyph
->object
;
12466 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12467 /* Skip glyphs from an overlay. */
12468 while (glyph
< stop
12469 && ! string_buffer_position (w
, glyph
->object
, pos
))
12471 string
= glyph
->object
;
12472 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12476 /* If we reached the end of the line, and END was from a string,
12477 the cursor is not on this line. */
12478 if (glyph
== end
&& row
->continued_p
)
12482 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12484 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12485 w
->cursor
.y
= row
->y
+ dy
;
12487 if (w
== XWINDOW (selected_window
))
12489 if (!row
->continued_p
12490 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12493 this_line_buffer
= XBUFFER (w
->buffer
);
12495 CHARPOS (this_line_start_pos
)
12496 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12497 BYTEPOS (this_line_start_pos
)
12498 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12500 CHARPOS (this_line_end_pos
)
12501 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12502 BYTEPOS (this_line_end_pos
)
12503 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12505 this_line_y
= w
->cursor
.y
;
12506 this_line_pixel_height
= row
->height
;
12507 this_line_vpos
= w
->cursor
.vpos
;
12508 this_line_start_x
= row
->x
;
12511 CHARPOS (this_line_start_pos
) = 0;
12518 /* Run window scroll functions, if any, for WINDOW with new window
12519 start STARTP. Sets the window start of WINDOW to that position.
12521 We assume that the window's buffer is really current. */
12523 static INLINE
struct text_pos
12524 run_window_scroll_functions (window
, startp
)
12525 Lisp_Object window
;
12526 struct text_pos startp
;
12528 struct window
*w
= XWINDOW (window
);
12529 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12531 if (current_buffer
!= XBUFFER (w
->buffer
))
12534 if (!NILP (Vwindow_scroll_functions
))
12536 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12537 make_number (CHARPOS (startp
)));
12538 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12539 /* In case the hook functions switch buffers. */
12540 if (current_buffer
!= XBUFFER (w
->buffer
))
12541 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12548 /* Make sure the line containing the cursor is fully visible.
12549 A value of 1 means there is nothing to be done.
12550 (Either the line is fully visible, or it cannot be made so,
12551 or we cannot tell.)
12553 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12554 is higher than window.
12556 A value of 0 means the caller should do scrolling
12557 as if point had gone off the screen. */
12560 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12563 int current_matrix_p
;
12565 struct glyph_matrix
*matrix
;
12566 struct glyph_row
*row
;
12569 if (!make_cursor_line_fully_visible_p
)
12572 /* It's not always possible to find the cursor, e.g, when a window
12573 is full of overlay strings. Don't do anything in that case. */
12574 if (w
->cursor
.vpos
< 0)
12577 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12578 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12580 /* If the cursor row is not partially visible, there's nothing to do. */
12581 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12584 /* If the row the cursor is in is taller than the window's height,
12585 it's not clear what to do, so do nothing. */
12586 window_height
= window_box_height (w
);
12587 if (row
->height
>= window_height
)
12589 if (!force_p
|| MINI_WINDOW_P (w
)
12590 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12597 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12598 non-zero means only WINDOW is redisplayed in redisplay_internal.
12599 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12600 in redisplay_window to bring a partially visible line into view in
12601 the case that only the cursor has moved.
12603 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12604 last screen line's vertical height extends past the end of the screen.
12608 1 if scrolling succeeded
12610 0 if scrolling didn't find point.
12612 -1 if new fonts have been loaded so that we must interrupt
12613 redisplay, adjust glyph matrices, and try again. */
12619 SCROLLING_NEED_LARGER_MATRICES
12623 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12624 scroll_step
, temp_scroll_step
, last_line_misfit
)
12625 Lisp_Object window
;
12626 int just_this_one_p
;
12627 EMACS_INT scroll_conservatively
, scroll_step
;
12628 int temp_scroll_step
;
12629 int last_line_misfit
;
12631 struct window
*w
= XWINDOW (window
);
12632 struct frame
*f
= XFRAME (w
->frame
);
12633 struct text_pos pos
, startp
;
12635 int this_scroll_margin
, scroll_max
, rc
, height
;
12636 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12637 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12638 Lisp_Object aggressive
;
12639 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12642 debug_method_add (w
, "try_scrolling");
12645 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12647 /* Compute scroll margin height in pixels. We scroll when point is
12648 within this distance from the top or bottom of the window. */
12649 if (scroll_margin
> 0)
12650 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
12651 * FRAME_LINE_HEIGHT (f
);
12653 this_scroll_margin
= 0;
12655 /* Force scroll_conservatively to have a reasonable value, to avoid
12656 overflow while computing how much to scroll. Note that the user
12657 can supply scroll-conservatively equal to `most-positive-fixnum',
12658 which can be larger than INT_MAX. */
12659 if (scroll_conservatively
> scroll_limit
)
12661 scroll_conservatively
= scroll_limit
;
12662 scroll_max
= INT_MAX
;
12664 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12665 /* Compute how much we should try to scroll maximally to bring
12666 point into view. */
12667 scroll_max
= (max (scroll_step
,
12668 max (scroll_conservatively
, temp_scroll_step
))
12669 * FRAME_LINE_HEIGHT (f
));
12670 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12671 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12672 /* We're trying to scroll because of aggressive scrolling but no
12673 scroll_step is set. Choose an arbitrary one. */
12674 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12680 /* Decide whether to scroll down. */
12681 if (PT
> CHARPOS (startp
))
12683 int scroll_margin_y
;
12685 /* Compute the pixel ypos of the scroll margin, then move it to
12686 either that ypos or PT, whichever comes first. */
12687 start_display (&it
, w
, startp
);
12688 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12689 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12690 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12691 (MOVE_TO_POS
| MOVE_TO_Y
));
12693 if (PT
> CHARPOS (it
.current
.pos
))
12695 int y0
= line_bottom_y (&it
);
12697 /* Compute the distance from the scroll margin to PT
12698 (including the height of the cursor line). Moving the
12699 iterator unconditionally to PT can be slow if PT is far
12700 away, so stop 10 lines past the window bottom (is there a
12701 way to do the right thing quickly?). */
12702 move_it_to (&it
, PT
, -1,
12703 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
12704 -1, MOVE_TO_POS
| MOVE_TO_Y
);
12705 dy
= line_bottom_y (&it
) - y0
;
12707 if (dy
> scroll_max
)
12708 return SCROLLING_FAILED
;
12716 /* Point is in or below the bottom scroll margin, so move the
12717 window start down. If scrolling conservatively, move it just
12718 enough down to make point visible. If scroll_step is set,
12719 move it down by scroll_step. */
12720 if (scroll_conservatively
)
12722 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12723 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12724 else if (scroll_step
|| temp_scroll_step
)
12725 amount_to_scroll
= scroll_max
;
12728 aggressive
= current_buffer
->scroll_up_aggressively
;
12729 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12730 if (NUMBERP (aggressive
))
12732 double float_amount
= XFLOATINT (aggressive
) * height
;
12733 amount_to_scroll
= float_amount
;
12734 if (amount_to_scroll
== 0 && float_amount
> 0)
12735 amount_to_scroll
= 1;
12739 if (amount_to_scroll
<= 0)
12740 return SCROLLING_FAILED
;
12742 start_display (&it
, w
, startp
);
12743 move_it_vertically (&it
, amount_to_scroll
);
12745 /* If STARTP is unchanged, move it down another screen line. */
12746 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12747 move_it_by_lines (&it
, 1, 1);
12748 startp
= it
.current
.pos
;
12752 struct text_pos scroll_margin_pos
= startp
;
12754 /* See if point is inside the scroll margin at the top of the
12756 if (this_scroll_margin
)
12758 start_display (&it
, w
, startp
);
12759 move_it_vertically (&it
, this_scroll_margin
);
12760 scroll_margin_pos
= it
.current
.pos
;
12763 if (PT
< CHARPOS (scroll_margin_pos
))
12765 /* Point is in the scroll margin at the top of the window or
12766 above what is displayed in the window. */
12769 /* Compute the vertical distance from PT to the scroll
12770 margin position. Give up if distance is greater than
12772 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12773 start_display (&it
, w
, pos
);
12775 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12776 it
.last_visible_y
, -1,
12777 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12778 dy
= it
.current_y
- y0
;
12779 if (dy
> scroll_max
)
12780 return SCROLLING_FAILED
;
12782 /* Compute new window start. */
12783 start_display (&it
, w
, startp
);
12785 if (scroll_conservatively
)
12787 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12788 else if (scroll_step
|| temp_scroll_step
)
12789 amount_to_scroll
= scroll_max
;
12792 aggressive
= current_buffer
->scroll_down_aggressively
;
12793 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12794 if (NUMBERP (aggressive
))
12796 double float_amount
= XFLOATINT (aggressive
) * height
;
12797 amount_to_scroll
= float_amount
;
12798 if (amount_to_scroll
== 0 && float_amount
> 0)
12799 amount_to_scroll
= 1;
12803 if (amount_to_scroll
<= 0)
12804 return SCROLLING_FAILED
;
12806 move_it_vertically_backward (&it
, amount_to_scroll
);
12807 startp
= it
.current
.pos
;
12811 /* Run window scroll functions. */
12812 startp
= run_window_scroll_functions (window
, startp
);
12814 /* Display the window. Give up if new fonts are loaded, or if point
12816 if (!try_window (window
, startp
, 0))
12817 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12818 else if (w
->cursor
.vpos
< 0)
12820 clear_glyph_matrix (w
->desired_matrix
);
12821 rc
= SCROLLING_FAILED
;
12825 /* Maybe forget recorded base line for line number display. */
12826 if (!just_this_one_p
12827 || current_buffer
->clip_changed
12828 || BEG_UNCHANGED
< CHARPOS (startp
))
12829 w
->base_line_number
= Qnil
;
12831 /* If cursor ends up on a partially visible line,
12832 treat that as being off the bottom of the screen. */
12833 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12835 clear_glyph_matrix (w
->desired_matrix
);
12836 ++extra_scroll_margin_lines
;
12839 rc
= SCROLLING_SUCCESS
;
12846 /* Compute a suitable window start for window W if display of W starts
12847 on a continuation line. Value is non-zero if a new window start
12850 The new window start will be computed, based on W's width, starting
12851 from the start of the continued line. It is the start of the
12852 screen line with the minimum distance from the old start W->start. */
12855 compute_window_start_on_continuation_line (w
)
12858 struct text_pos pos
, start_pos
;
12859 int window_start_changed_p
= 0;
12861 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12863 /* If window start is on a continuation line... Window start may be
12864 < BEGV in case there's invisible text at the start of the
12865 buffer (M-x rmail, for example). */
12866 if (CHARPOS (start_pos
) > BEGV
12867 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12870 struct glyph_row
*row
;
12872 /* Handle the case that the window start is out of range. */
12873 if (CHARPOS (start_pos
) < BEGV
)
12874 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12875 else if (CHARPOS (start_pos
) > ZV
)
12876 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12878 /* Find the start of the continued line. This should be fast
12879 because scan_buffer is fast (newline cache). */
12880 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12881 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12882 row
, DEFAULT_FACE_ID
);
12883 reseat_at_previous_visible_line_start (&it
);
12885 /* If the line start is "too far" away from the window start,
12886 say it takes too much time to compute a new window start. */
12887 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12888 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12890 int min_distance
, distance
;
12892 /* Move forward by display lines to find the new window
12893 start. If window width was enlarged, the new start can
12894 be expected to be > the old start. If window width was
12895 decreased, the new window start will be < the old start.
12896 So, we're looking for the display line start with the
12897 minimum distance from the old window start. */
12898 pos
= it
.current
.pos
;
12899 min_distance
= INFINITY
;
12900 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12901 distance
< min_distance
)
12903 min_distance
= distance
;
12904 pos
= it
.current
.pos
;
12905 move_it_by_lines (&it
, 1, 0);
12908 /* Set the window start there. */
12909 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12910 window_start_changed_p
= 1;
12914 return window_start_changed_p
;
12918 /* Try cursor movement in case text has not changed in window WINDOW,
12919 with window start STARTP. Value is
12921 CURSOR_MOVEMENT_SUCCESS if successful
12923 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12925 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12926 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12927 we want to scroll as if scroll-step were set to 1. See the code.
12929 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12930 which case we have to abort this redisplay, and adjust matrices
12935 CURSOR_MOVEMENT_SUCCESS
,
12936 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12937 CURSOR_MOVEMENT_MUST_SCROLL
,
12938 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12942 try_cursor_movement (window
, startp
, scroll_step
)
12943 Lisp_Object window
;
12944 struct text_pos startp
;
12947 struct window
*w
= XWINDOW (window
);
12948 struct frame
*f
= XFRAME (w
->frame
);
12949 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12952 if (inhibit_try_cursor_movement
)
12956 /* Handle case where text has not changed, only point, and it has
12957 not moved off the frame. */
12958 if (/* Point may be in this window. */
12959 PT
>= CHARPOS (startp
)
12960 /* Selective display hasn't changed. */
12961 && !current_buffer
->clip_changed
12962 /* Function force-mode-line-update is used to force a thorough
12963 redisplay. It sets either windows_or_buffers_changed or
12964 update_mode_lines. So don't take a shortcut here for these
12966 && !update_mode_lines
12967 && !windows_or_buffers_changed
12968 && !cursor_type_changed
12969 /* Can't use this case if highlighting a region. When a
12970 region exists, cursor movement has to do more than just
12972 && !(!NILP (Vtransient_mark_mode
)
12973 && !NILP (current_buffer
->mark_active
))
12974 && NILP (w
->region_showing
)
12975 && NILP (Vshow_trailing_whitespace
)
12976 /* Right after splitting windows, last_point may be nil. */
12977 && INTEGERP (w
->last_point
)
12978 /* This code is not used for mini-buffer for the sake of the case
12979 of redisplaying to replace an echo area message; since in
12980 that case the mini-buffer contents per se are usually
12981 unchanged. This code is of no real use in the mini-buffer
12982 since the handling of this_line_start_pos, etc., in redisplay
12983 handles the same cases. */
12984 && !EQ (window
, minibuf_window
)
12985 /* When splitting windows or for new windows, it happens that
12986 redisplay is called with a nil window_end_vpos or one being
12987 larger than the window. This should really be fixed in
12988 window.c. I don't have this on my list, now, so we do
12989 approximately the same as the old redisplay code. --gerd. */
12990 && INTEGERP (w
->window_end_vpos
)
12991 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12992 && (FRAME_WINDOW_P (f
)
12993 || !overlay_arrow_in_current_buffer_p ()))
12995 int this_scroll_margin
, top_scroll_margin
;
12996 struct glyph_row
*row
= NULL
;
12999 debug_method_add (w
, "cursor movement");
13002 /* Scroll if point within this distance from the top or bottom
13003 of the window. This is a pixel value. */
13004 if (scroll_margin
> 0)
13006 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13007 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13010 this_scroll_margin
= 0;
13012 top_scroll_margin
= this_scroll_margin
;
13013 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13014 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13016 /* Start with the row the cursor was displayed during the last
13017 not paused redisplay. Give up if that row is not valid. */
13018 if (w
->last_cursor
.vpos
< 0
13019 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13020 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13023 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13024 if (row
->mode_line_p
)
13026 if (!row
->enabled_p
)
13027 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13030 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13033 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13035 if (PT
> XFASTINT (w
->last_point
))
13037 /* Point has moved forward. */
13038 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13039 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13041 xassert (row
->enabled_p
);
13045 /* The end position of a row equals the start position
13046 of the next row. If PT is there, we would rather
13047 display it in the next line. */
13048 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13049 && MATRIX_ROW_END_CHARPOS (row
) == PT
13050 && !cursor_row_p (w
, row
))
13053 /* If within the scroll margin, scroll. Note that
13054 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13055 the next line would be drawn, and that
13056 this_scroll_margin can be zero. */
13057 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13058 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13059 /* Line is completely visible last line in window
13060 and PT is to be set in the next line. */
13061 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13062 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13063 && !row
->ends_at_zv_p
13064 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13067 else if (PT
< XFASTINT (w
->last_point
))
13069 /* Cursor has to be moved backward. Note that PT >=
13070 CHARPOS (startp) because of the outer if-statement. */
13071 while (!row
->mode_line_p
13072 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13073 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13074 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13075 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13076 row
> w
->current_matrix
->rows
13077 && (row
-1)->ends_in_newline_from_string_p
))))
13078 && (row
->y
> top_scroll_margin
13079 || CHARPOS (startp
) == BEGV
))
13081 xassert (row
->enabled_p
);
13085 /* Consider the following case: Window starts at BEGV,
13086 there is invisible, intangible text at BEGV, so that
13087 display starts at some point START > BEGV. It can
13088 happen that we are called with PT somewhere between
13089 BEGV and START. Try to handle that case. */
13090 if (row
< w
->current_matrix
->rows
13091 || row
->mode_line_p
)
13093 row
= w
->current_matrix
->rows
;
13094 if (row
->mode_line_p
)
13098 /* Due to newlines in overlay strings, we may have to
13099 skip forward over overlay strings. */
13100 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13101 && MATRIX_ROW_END_CHARPOS (row
) == PT
13102 && !cursor_row_p (w
, row
))
13105 /* If within the scroll margin, scroll. */
13106 if (row
->y
< top_scroll_margin
13107 && CHARPOS (startp
) != BEGV
)
13112 /* Cursor did not move. So don't scroll even if cursor line
13113 is partially visible, as it was so before. */
13114 rc
= CURSOR_MOVEMENT_SUCCESS
;
13117 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13118 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13120 /* if PT is not in the glyph row, give up. */
13121 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13123 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13124 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13125 && make_cursor_line_fully_visible_p
)
13127 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13128 && !row
->ends_at_zv_p
13129 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13130 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13131 else if (row
->height
> window_box_height (w
))
13133 /* If we end up in a partially visible line, let's
13134 make it fully visible, except when it's taller
13135 than the window, in which case we can't do much
13138 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13142 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13143 if (!cursor_row_fully_visible_p (w
, 0, 1))
13144 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13146 rc
= CURSOR_MOVEMENT_SUCCESS
;
13150 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13155 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13157 rc
= CURSOR_MOVEMENT_SUCCESS
;
13162 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13163 && MATRIX_ROW_START_CHARPOS (row
) == PT
13164 && cursor_row_p (w
, row
));
13173 set_vertical_scroll_bar (w
)
13176 int start
, end
, whole
;
13178 /* Calculate the start and end positions for the current window.
13179 At some point, it would be nice to choose between scrollbars
13180 which reflect the whole buffer size, with special markers
13181 indicating narrowing, and scrollbars which reflect only the
13184 Note that mini-buffers sometimes aren't displaying any text. */
13185 if (!MINI_WINDOW_P (w
)
13186 || (w
== XWINDOW (minibuf_window
)
13187 && NILP (echo_area_buffer
[0])))
13189 struct buffer
*buf
= XBUFFER (w
->buffer
);
13190 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13191 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13192 /* I don't think this is guaranteed to be right. For the
13193 moment, we'll pretend it is. */
13194 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13198 if (whole
< (end
- start
))
13199 whole
= end
- start
;
13202 start
= end
= whole
= 0;
13204 /* Indicate what this scroll bar ought to be displaying now. */
13205 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13206 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13207 (w
, end
- start
, whole
, start
);
13211 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13212 selected_window is redisplayed.
13214 We can return without actually redisplaying the window if
13215 fonts_changed_p is nonzero. In that case, redisplay_internal will
13219 redisplay_window (window
, just_this_one_p
)
13220 Lisp_Object window
;
13221 int just_this_one_p
;
13223 struct window
*w
= XWINDOW (window
);
13224 struct frame
*f
= XFRAME (w
->frame
);
13225 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13226 struct buffer
*old
= current_buffer
;
13227 struct text_pos lpoint
, opoint
, startp
;
13228 int update_mode_line
;
13231 /* Record it now because it's overwritten. */
13232 int current_matrix_up_to_date_p
= 0;
13233 int used_current_matrix_p
= 0;
13234 /* This is less strict than current_matrix_up_to_date_p.
13235 It indictes that the buffer contents and narrowing are unchanged. */
13236 int buffer_unchanged_p
= 0;
13237 int temp_scroll_step
= 0;
13238 int count
= SPECPDL_INDEX ();
13240 int centering_position
= -1;
13241 int last_line_misfit
= 0;
13242 int beg_unchanged
, end_unchanged
;
13244 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13247 /* W must be a leaf window here. */
13248 xassert (!NILP (w
->buffer
));
13250 *w
->desired_matrix
->method
= 0;
13254 reconsider_clip_changes (w
, buffer
);
13256 /* Has the mode line to be updated? */
13257 update_mode_line
= (!NILP (w
->update_mode_line
)
13258 || update_mode_lines
13259 || buffer
->clip_changed
13260 || buffer
->prevent_redisplay_optimizations_p
);
13262 if (MINI_WINDOW_P (w
))
13264 if (w
== XWINDOW (echo_area_window
)
13265 && !NILP (echo_area_buffer
[0]))
13267 if (update_mode_line
)
13268 /* We may have to update a tty frame's menu bar or a
13269 tool-bar. Example `M-x C-h C-h C-g'. */
13270 goto finish_menu_bars
;
13272 /* We've already displayed the echo area glyphs in this window. */
13273 goto finish_scroll_bars
;
13275 else if ((w
!= XWINDOW (minibuf_window
)
13276 || minibuf_level
== 0)
13277 /* When buffer is nonempty, redisplay window normally. */
13278 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13279 /* Quail displays non-mini buffers in minibuffer window.
13280 In that case, redisplay the window normally. */
13281 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13283 /* W is a mini-buffer window, but it's not active, so clear
13285 int yb
= window_text_bottom_y (w
);
13286 struct glyph_row
*row
;
13289 for (y
= 0, row
= w
->desired_matrix
->rows
;
13291 y
+= row
->height
, ++row
)
13292 blank_row (w
, row
, y
);
13293 goto finish_scroll_bars
;
13296 clear_glyph_matrix (w
->desired_matrix
);
13299 /* Otherwise set up data on this window; select its buffer and point
13301 /* Really select the buffer, for the sake of buffer-local
13303 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13305 current_matrix_up_to_date_p
13306 = (!NILP (w
->window_end_valid
)
13307 && !current_buffer
->clip_changed
13308 && !current_buffer
->prevent_redisplay_optimizations_p
13309 && XFASTINT (w
->last_modified
) >= MODIFF
13310 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13312 /* Run the window-bottom-change-functions
13313 if it is possible that the text on the screen has changed
13314 (either due to modification of the text, or any other reason). */
13315 if (!current_matrix_up_to_date_p
13316 && !NILP (Vwindow_text_change_functions
))
13318 safe_run_hooks (Qwindow_text_change_functions
);
13322 beg_unchanged
= BEG_UNCHANGED
;
13323 end_unchanged
= END_UNCHANGED
;
13325 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13327 specbind (Qinhibit_point_motion_hooks
, Qt
);
13330 = (!NILP (w
->window_end_valid
)
13331 && !current_buffer
->clip_changed
13332 && XFASTINT (w
->last_modified
) >= MODIFF
13333 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13335 /* When windows_or_buffers_changed is non-zero, we can't rely on
13336 the window end being valid, so set it to nil there. */
13337 if (windows_or_buffers_changed
)
13339 /* If window starts on a continuation line, maybe adjust the
13340 window start in case the window's width changed. */
13341 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13342 compute_window_start_on_continuation_line (w
);
13344 w
->window_end_valid
= Qnil
;
13347 /* Some sanity checks. */
13348 CHECK_WINDOW_END (w
);
13349 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13351 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13354 /* If %c is in mode line, update it if needed. */
13355 if (!NILP (w
->column_number_displayed
)
13356 /* This alternative quickly identifies a common case
13357 where no change is needed. */
13358 && !(PT
== XFASTINT (w
->last_point
)
13359 && XFASTINT (w
->last_modified
) >= MODIFF
13360 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13361 && (XFASTINT (w
->column_number_displayed
)
13362 != (int) current_column ())) /* iftc */
13363 update_mode_line
= 1;
13365 /* Count number of windows showing the selected buffer. An indirect
13366 buffer counts as its base buffer. */
13367 if (!just_this_one_p
)
13369 struct buffer
*current_base
, *window_base
;
13370 current_base
= current_buffer
;
13371 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13372 if (current_base
->base_buffer
)
13373 current_base
= current_base
->base_buffer
;
13374 if (window_base
->base_buffer
)
13375 window_base
= window_base
->base_buffer
;
13376 if (current_base
== window_base
)
13380 /* Point refers normally to the selected window. For any other
13381 window, set up appropriate value. */
13382 if (!EQ (window
, selected_window
))
13384 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13385 int new_pt_byte
= marker_byte_position (w
->pointm
);
13389 new_pt_byte
= BEGV_BYTE
;
13390 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13392 else if (new_pt
> (ZV
- 1))
13395 new_pt_byte
= ZV_BYTE
;
13396 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13399 /* We don't use SET_PT so that the point-motion hooks don't run. */
13400 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13403 /* If any of the character widths specified in the display table
13404 have changed, invalidate the width run cache. It's true that
13405 this may be a bit late to catch such changes, but the rest of
13406 redisplay goes (non-fatally) haywire when the display table is
13407 changed, so why should we worry about doing any better? */
13408 if (current_buffer
->width_run_cache
)
13410 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13412 if (! disptab_matches_widthtab (disptab
,
13413 XVECTOR (current_buffer
->width_table
)))
13415 invalidate_region_cache (current_buffer
,
13416 current_buffer
->width_run_cache
,
13418 recompute_width_table (current_buffer
, disptab
);
13422 /* If window-start is screwed up, choose a new one. */
13423 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13426 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13428 /* If someone specified a new starting point but did not insist,
13429 check whether it can be used. */
13430 if (!NILP (w
->optional_new_start
)
13431 && CHARPOS (startp
) >= BEGV
13432 && CHARPOS (startp
) <= ZV
)
13434 w
->optional_new_start
= Qnil
;
13435 start_display (&it
, w
, startp
);
13436 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13437 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13438 if (IT_CHARPOS (it
) == PT
)
13439 w
->force_start
= Qt
;
13440 /* IT may overshoot PT if text at PT is invisible. */
13441 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13442 w
->force_start
= Qt
;
13447 /* Handle case where place to start displaying has been specified,
13448 unless the specified location is outside the accessible range. */
13449 if (!NILP (w
->force_start
)
13450 || w
->frozen_window_start_p
)
13452 /* We set this later on if we have to adjust point. */
13455 w
->force_start
= Qnil
;
13457 w
->window_end_valid
= Qnil
;
13459 /* Forget any recorded base line for line number display. */
13460 if (!buffer_unchanged_p
)
13461 w
->base_line_number
= Qnil
;
13463 /* Redisplay the mode line. Select the buffer properly for that.
13464 Also, run the hook window-scroll-functions
13465 because we have scrolled. */
13466 /* Note, we do this after clearing force_start because
13467 if there's an error, it is better to forget about force_start
13468 than to get into an infinite loop calling the hook functions
13469 and having them get more errors. */
13470 if (!update_mode_line
13471 || ! NILP (Vwindow_scroll_functions
))
13473 update_mode_line
= 1;
13474 w
->update_mode_line
= Qt
;
13475 startp
= run_window_scroll_functions (window
, startp
);
13478 w
->last_modified
= make_number (0);
13479 w
->last_overlay_modified
= make_number (0);
13480 if (CHARPOS (startp
) < BEGV
)
13481 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13482 else if (CHARPOS (startp
) > ZV
)
13483 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13485 /* Redisplay, then check if cursor has been set during the
13486 redisplay. Give up if new fonts were loaded. */
13487 /* We used to issue a CHECK_MARGINS argument to try_window here,
13488 but this causes scrolling to fail when point begins inside
13489 the scroll margin (bug#148) -- cyd */
13490 if (!try_window (window
, startp
, 0))
13492 w
->force_start
= Qt
;
13493 clear_glyph_matrix (w
->desired_matrix
);
13494 goto need_larger_matrices
;
13497 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13499 /* If point does not appear, try to move point so it does
13500 appear. The desired matrix has been built above, so we
13501 can use it here. */
13502 new_vpos
= window_box_height (w
) / 2;
13505 if (!cursor_row_fully_visible_p (w
, 0, 0))
13507 /* Point does appear, but on a line partly visible at end of window.
13508 Move it back to a fully-visible line. */
13509 new_vpos
= window_box_height (w
);
13512 /* If we need to move point for either of the above reasons,
13513 now actually do it. */
13516 struct glyph_row
*row
;
13518 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13519 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13522 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13523 MATRIX_ROW_START_BYTEPOS (row
));
13525 if (w
!= XWINDOW (selected_window
))
13526 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13527 else if (current_buffer
== old
)
13528 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13530 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13532 /* If we are highlighting the region, then we just changed
13533 the region, so redisplay to show it. */
13534 if (!NILP (Vtransient_mark_mode
)
13535 && !NILP (current_buffer
->mark_active
))
13537 clear_glyph_matrix (w
->desired_matrix
);
13538 if (!try_window (window
, startp
, 0))
13539 goto need_larger_matrices
;
13544 debug_method_add (w
, "forced window start");
13549 /* Handle case where text has not changed, only point, and it has
13550 not moved off the frame, and we are not retrying after hscroll.
13551 (current_matrix_up_to_date_p is nonzero when retrying.) */
13552 if (current_matrix_up_to_date_p
13553 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13554 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13558 case CURSOR_MOVEMENT_SUCCESS
:
13559 used_current_matrix_p
= 1;
13562 case CURSOR_MOVEMENT_MUST_SCROLL
:
13563 goto try_to_scroll
;
13569 /* If current starting point was originally the beginning of a line
13570 but no longer is, find a new starting point. */
13571 else if (!NILP (w
->start_at_line_beg
)
13572 && !(CHARPOS (startp
) <= BEGV
13573 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13576 debug_method_add (w
, "recenter 1");
13581 /* Try scrolling with try_window_id. Value is > 0 if update has
13582 been done, it is -1 if we know that the same window start will
13583 not work. It is 0 if unsuccessful for some other reason. */
13584 else if ((tem
= try_window_id (w
)) != 0)
13587 debug_method_add (w
, "try_window_id %d", tem
);
13590 if (fonts_changed_p
)
13591 goto need_larger_matrices
;
13595 /* Otherwise try_window_id has returned -1 which means that we
13596 don't want the alternative below this comment to execute. */
13598 else if (CHARPOS (startp
) >= BEGV
13599 && CHARPOS (startp
) <= ZV
13600 && PT
>= CHARPOS (startp
)
13601 && (CHARPOS (startp
) < ZV
13602 /* Avoid starting at end of buffer. */
13603 || CHARPOS (startp
) == BEGV
13604 || (XFASTINT (w
->last_modified
) >= MODIFF
13605 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13608 /* If first window line is a continuation line, and window start
13609 is inside the modified region, but the first change is before
13610 current window start, we must select a new window start.
13612 However, if this is the result of a down-mouse event (e.g. by
13613 extending the mouse-drag-overlay), we don't want to select a
13614 new window start, since that would change the position under
13615 the mouse, resulting in an unwanted mouse-movement rather
13616 than a simple mouse-click. */
13617 if (NILP (w
->start_at_line_beg
)
13618 && NILP (do_mouse_tracking
)
13619 && CHARPOS (startp
) > BEGV
13620 && CHARPOS (startp
) > BEG
+ beg_unchanged
13621 && CHARPOS (startp
) <= Z
- end_unchanged
13622 /* Even if w->start_at_line_beg is nil, a new window may
13623 start at a line_beg, since that's how set_buffer_window
13624 sets it. So, we need to check the return value of
13625 compute_window_start_on_continuation_line. (See also
13627 && XMARKER (w
->start
)->buffer
== current_buffer
13628 && compute_window_start_on_continuation_line (w
))
13630 w
->force_start
= Qt
;
13631 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13636 debug_method_add (w
, "same window start");
13639 /* Try to redisplay starting at same place as before.
13640 If point has not moved off frame, accept the results. */
13641 if (!current_matrix_up_to_date_p
13642 /* Don't use try_window_reusing_current_matrix in this case
13643 because a window scroll function can have changed the
13645 || !NILP (Vwindow_scroll_functions
)
13646 || MINI_WINDOW_P (w
)
13647 || !(used_current_matrix_p
13648 = try_window_reusing_current_matrix (w
)))
13650 IF_DEBUG (debug_method_add (w
, "1"));
13651 if (try_window (window
, startp
, 1) < 0)
13652 /* -1 means we need to scroll.
13653 0 means we need new matrices, but fonts_changed_p
13654 is set in that case, so we will detect it below. */
13655 goto try_to_scroll
;
13658 if (fonts_changed_p
)
13659 goto need_larger_matrices
;
13661 if (w
->cursor
.vpos
>= 0)
13663 if (!just_this_one_p
13664 || current_buffer
->clip_changed
13665 || BEG_UNCHANGED
< CHARPOS (startp
))
13666 /* Forget any recorded base line for line number display. */
13667 w
->base_line_number
= Qnil
;
13669 if (!cursor_row_fully_visible_p (w
, 1, 0))
13671 clear_glyph_matrix (w
->desired_matrix
);
13672 last_line_misfit
= 1;
13674 /* Drop through and scroll. */
13679 clear_glyph_matrix (w
->desired_matrix
);
13684 w
->last_modified
= make_number (0);
13685 w
->last_overlay_modified
= make_number (0);
13687 /* Redisplay the mode line. Select the buffer properly for that. */
13688 if (!update_mode_line
)
13690 update_mode_line
= 1;
13691 w
->update_mode_line
= Qt
;
13694 /* Try to scroll by specified few lines. */
13695 if ((scroll_conservatively
13697 || temp_scroll_step
13698 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13699 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13700 && !current_buffer
->clip_changed
13701 && CHARPOS (startp
) >= BEGV
13702 && CHARPOS (startp
) <= ZV
)
13704 /* The function returns -1 if new fonts were loaded, 1 if
13705 successful, 0 if not successful. */
13706 int rc
= try_scrolling (window
, just_this_one_p
,
13707 scroll_conservatively
,
13709 temp_scroll_step
, last_line_misfit
);
13712 case SCROLLING_SUCCESS
:
13715 case SCROLLING_NEED_LARGER_MATRICES
:
13716 goto need_larger_matrices
;
13718 case SCROLLING_FAILED
:
13726 /* Finally, just choose place to start which centers point */
13729 if (centering_position
< 0)
13730 centering_position
= window_box_height (w
) / 2;
13733 debug_method_add (w
, "recenter");
13736 /* w->vscroll = 0; */
13738 /* Forget any previously recorded base line for line number display. */
13739 if (!buffer_unchanged_p
)
13740 w
->base_line_number
= Qnil
;
13742 /* Move backward half the height of the window. */
13743 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13744 it
.current_y
= it
.last_visible_y
;
13745 move_it_vertically_backward (&it
, centering_position
);
13746 xassert (IT_CHARPOS (it
) >= BEGV
);
13748 /* The function move_it_vertically_backward may move over more
13749 than the specified y-distance. If it->w is small, e.g. a
13750 mini-buffer window, we may end up in front of the window's
13751 display area. Start displaying at the start of the line
13752 containing PT in this case. */
13753 if (it
.current_y
<= 0)
13755 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13756 move_it_vertically_backward (&it
, 0);
13760 it
.current_x
= it
.hpos
= 0;
13762 /* Set startp here explicitly in case that helps avoid an infinite loop
13763 in case the window-scroll-functions functions get errors. */
13764 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13766 /* Run scroll hooks. */
13767 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13769 /* Redisplay the window. */
13770 if (!current_matrix_up_to_date_p
13771 || windows_or_buffers_changed
13772 || cursor_type_changed
13773 /* Don't use try_window_reusing_current_matrix in this case
13774 because it can have changed the buffer. */
13775 || !NILP (Vwindow_scroll_functions
)
13776 || !just_this_one_p
13777 || MINI_WINDOW_P (w
)
13778 || !(used_current_matrix_p
13779 = try_window_reusing_current_matrix (w
)))
13780 try_window (window
, startp
, 0);
13782 /* If new fonts have been loaded (due to fontsets), give up. We
13783 have to start a new redisplay since we need to re-adjust glyph
13785 if (fonts_changed_p
)
13786 goto need_larger_matrices
;
13788 /* If cursor did not appear assume that the middle of the window is
13789 in the first line of the window. Do it again with the next line.
13790 (Imagine a window of height 100, displaying two lines of height
13791 60. Moving back 50 from it->last_visible_y will end in the first
13793 if (w
->cursor
.vpos
< 0)
13795 if (!NILP (w
->window_end_valid
)
13796 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13798 clear_glyph_matrix (w
->desired_matrix
);
13799 move_it_by_lines (&it
, 1, 0);
13800 try_window (window
, it
.current
.pos
, 0);
13802 else if (PT
< IT_CHARPOS (it
))
13804 clear_glyph_matrix (w
->desired_matrix
);
13805 move_it_by_lines (&it
, -1, 0);
13806 try_window (window
, it
.current
.pos
, 0);
13810 /* Not much we can do about it. */
13814 /* Consider the following case: Window starts at BEGV, there is
13815 invisible, intangible text at BEGV, so that display starts at
13816 some point START > BEGV. It can happen that we are called with
13817 PT somewhere between BEGV and START. Try to handle that case. */
13818 if (w
->cursor
.vpos
< 0)
13820 struct glyph_row
*row
= w
->current_matrix
->rows
;
13821 if (row
->mode_line_p
)
13823 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13826 if (!cursor_row_fully_visible_p (w
, 0, 0))
13828 /* If vscroll is enabled, disable it and try again. */
13832 clear_glyph_matrix (w
->desired_matrix
);
13836 /* If centering point failed to make the whole line visible,
13837 put point at the top instead. That has to make the whole line
13838 visible, if it can be done. */
13839 if (centering_position
== 0)
13842 clear_glyph_matrix (w
->desired_matrix
);
13843 centering_position
= 0;
13849 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13850 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13851 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13854 /* Display the mode line, if we must. */
13855 if ((update_mode_line
13856 /* If window not full width, must redo its mode line
13857 if (a) the window to its side is being redone and
13858 (b) we do a frame-based redisplay. This is a consequence
13859 of how inverted lines are drawn in frame-based redisplay. */
13860 || (!just_this_one_p
13861 && !FRAME_WINDOW_P (f
)
13862 && !WINDOW_FULL_WIDTH_P (w
))
13863 /* Line number to display. */
13864 || INTEGERP (w
->base_line_pos
)
13865 /* Column number is displayed and different from the one displayed. */
13866 || (!NILP (w
->column_number_displayed
)
13867 && (XFASTINT (w
->column_number_displayed
)
13868 != (int) current_column ()))) /* iftc */
13869 /* This means that the window has a mode line. */
13870 && (WINDOW_WANTS_MODELINE_P (w
)
13871 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13873 display_mode_lines (w
);
13875 /* If mode line height has changed, arrange for a thorough
13876 immediate redisplay using the correct mode line height. */
13877 if (WINDOW_WANTS_MODELINE_P (w
)
13878 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13880 fonts_changed_p
= 1;
13881 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13882 = DESIRED_MODE_LINE_HEIGHT (w
);
13885 /* If header line height has changed, arrange for a thorough
13886 immediate redisplay using the correct header line height. */
13887 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13888 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13890 fonts_changed_p
= 1;
13891 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13892 = DESIRED_HEADER_LINE_HEIGHT (w
);
13895 if (fonts_changed_p
)
13896 goto need_larger_matrices
;
13899 if (!line_number_displayed
13900 && !BUFFERP (w
->base_line_pos
))
13902 w
->base_line_pos
= Qnil
;
13903 w
->base_line_number
= Qnil
;
13908 /* When we reach a frame's selected window, redo the frame's menu bar. */
13909 if (update_mode_line
13910 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13912 int redisplay_menu_p
= 0;
13913 int redisplay_tool_bar_p
= 0;
13915 if (FRAME_WINDOW_P (f
))
13917 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13918 || defined (HAVE_NS) || defined (USE_GTK)
13919 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13921 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13925 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13927 if (redisplay_menu_p
)
13928 display_menu_bar (w
);
13930 #ifdef HAVE_WINDOW_SYSTEM
13931 if (FRAME_WINDOW_P (f
))
13933 #if defined (USE_GTK) || defined (HAVE_NS)
13934 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13936 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13937 && (FRAME_TOOL_BAR_LINES (f
) > 0
13938 || !NILP (Vauto_resize_tool_bars
));
13941 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13943 extern int ignore_mouse_drag_p
;
13944 ignore_mouse_drag_p
= 1;
13950 #ifdef HAVE_WINDOW_SYSTEM
13951 if (FRAME_WINDOW_P (f
)
13952 && update_window_fringes (w
, (just_this_one_p
13953 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13954 || w
->pseudo_window_p
)))
13958 if (draw_window_fringes (w
, 1))
13959 x_draw_vertical_border (w
);
13963 #endif /* HAVE_WINDOW_SYSTEM */
13965 /* We go to this label, with fonts_changed_p nonzero,
13966 if it is necessary to try again using larger glyph matrices.
13967 We have to redeem the scroll bar even in this case,
13968 because the loop in redisplay_internal expects that. */
13969 need_larger_matrices
:
13971 finish_scroll_bars
:
13973 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13975 /* Set the thumb's position and size. */
13976 set_vertical_scroll_bar (w
);
13978 /* Note that we actually used the scroll bar attached to this
13979 window, so it shouldn't be deleted at the end of redisplay. */
13980 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13981 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13984 /* Restore current_buffer and value of point in it. */
13985 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13986 set_buffer_internal_1 (old
);
13987 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13988 shorter. This can be caused by log truncation in *Messages*. */
13989 if (CHARPOS (lpoint
) <= ZV
)
13990 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13992 unbind_to (count
, Qnil
);
13996 /* Build the complete desired matrix of WINDOW with a window start
13997 buffer position POS.
13999 Value is 1 if successful. It is zero if fonts were loaded during
14000 redisplay which makes re-adjusting glyph matrices necessary, and -1
14001 if point would appear in the scroll margins.
14002 (We check that only if CHECK_MARGINS is nonzero. */
14005 try_window (window
, pos
, check_margins
)
14006 Lisp_Object window
;
14007 struct text_pos pos
;
14010 struct window
*w
= XWINDOW (window
);
14012 struct glyph_row
*last_text_row
= NULL
;
14013 struct frame
*f
= XFRAME (w
->frame
);
14015 /* Make POS the new window start. */
14016 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14018 /* Mark cursor position as unknown. No overlay arrow seen. */
14019 w
->cursor
.vpos
= -1;
14020 overlay_arrow_seen
= 0;
14022 /* Initialize iterator and info to start at POS. */
14023 start_display (&it
, w
, pos
);
14025 /* Display all lines of W. */
14026 while (it
.current_y
< it
.last_visible_y
)
14028 if (display_line (&it
))
14029 last_text_row
= it
.glyph_row
- 1;
14030 if (fonts_changed_p
)
14034 /* Don't let the cursor end in the scroll margins. */
14036 && !MINI_WINDOW_P (w
))
14038 int this_scroll_margin
;
14040 if (scroll_margin
> 0)
14042 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14043 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14046 this_scroll_margin
= 0;
14048 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14049 && w
->cursor
.y
< this_scroll_margin
14050 && CHARPOS (pos
) > BEGV
14051 && IT_CHARPOS (it
) < ZV
)
14052 /* rms: considering make_cursor_line_fully_visible_p here
14053 seems to give wrong results. We don't want to recenter
14054 when the last line is partly visible, we want to allow
14055 that case to be handled in the usual way. */
14056 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14058 w
->cursor
.vpos
= -1;
14059 clear_glyph_matrix (w
->desired_matrix
);
14064 /* If bottom moved off end of frame, change mode line percentage. */
14065 if (XFASTINT (w
->window_end_pos
) <= 0
14066 && Z
!= IT_CHARPOS (it
))
14067 w
->update_mode_line
= Qt
;
14069 /* Set window_end_pos to the offset of the last character displayed
14070 on the window from the end of current_buffer. Set
14071 window_end_vpos to its row number. */
14074 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14075 w
->window_end_bytepos
14076 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14078 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14080 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14081 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14082 ->displays_text_p
);
14086 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14087 w
->window_end_pos
= make_number (Z
- ZV
);
14088 w
->window_end_vpos
= make_number (0);
14091 /* But that is not valid info until redisplay finishes. */
14092 w
->window_end_valid
= Qnil
;
14098 /************************************************************************
14099 Window redisplay reusing current matrix when buffer has not changed
14100 ************************************************************************/
14102 /* Try redisplay of window W showing an unchanged buffer with a
14103 different window start than the last time it was displayed by
14104 reusing its current matrix. Value is non-zero if successful.
14105 W->start is the new window start. */
14108 try_window_reusing_current_matrix (w
)
14111 struct frame
*f
= XFRAME (w
->frame
);
14112 struct glyph_row
*row
, *bottom_row
;
14115 struct text_pos start
, new_start
;
14116 int nrows_scrolled
, i
;
14117 struct glyph_row
*last_text_row
;
14118 struct glyph_row
*last_reused_text_row
;
14119 struct glyph_row
*start_row
;
14120 int start_vpos
, min_y
, max_y
;
14123 if (inhibit_try_window_reusing
)
14127 if (/* This function doesn't handle terminal frames. */
14128 !FRAME_WINDOW_P (f
)
14129 /* Don't try to reuse the display if windows have been split
14131 || windows_or_buffers_changed
14132 || cursor_type_changed
)
14135 /* Can't do this if region may have changed. */
14136 if ((!NILP (Vtransient_mark_mode
)
14137 && !NILP (current_buffer
->mark_active
))
14138 || !NILP (w
->region_showing
)
14139 || !NILP (Vshow_trailing_whitespace
))
14142 /* If top-line visibility has changed, give up. */
14143 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14144 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14147 /* Give up if old or new display is scrolled vertically. We could
14148 make this function handle this, but right now it doesn't. */
14149 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14150 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14153 /* The variable new_start now holds the new window start. The old
14154 start `start' can be determined from the current matrix. */
14155 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14156 start
= start_row
->start
.pos
;
14157 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14159 /* Clear the desired matrix for the display below. */
14160 clear_glyph_matrix (w
->desired_matrix
);
14162 if (CHARPOS (new_start
) <= CHARPOS (start
))
14166 /* Don't use this method if the display starts with an ellipsis
14167 displayed for invisible text. It's not easy to handle that case
14168 below, and it's certainly not worth the effort since this is
14169 not a frequent case. */
14170 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14173 IF_DEBUG (debug_method_add (w
, "twu1"));
14175 /* Display up to a row that can be reused. The variable
14176 last_text_row is set to the last row displayed that displays
14177 text. Note that it.vpos == 0 if or if not there is a
14178 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14179 start_display (&it
, w
, new_start
);
14180 first_row_y
= it
.current_y
;
14181 w
->cursor
.vpos
= -1;
14182 last_text_row
= last_reused_text_row
= NULL
;
14184 while (it
.current_y
< it
.last_visible_y
14185 && !fonts_changed_p
)
14187 /* If we have reached into the characters in the START row,
14188 that means the line boundaries have changed. So we
14189 can't start copying with the row START. Maybe it will
14190 work to start copying with the following row. */
14191 while (IT_CHARPOS (it
) > CHARPOS (start
))
14193 /* Advance to the next row as the "start". */
14195 start
= start_row
->start
.pos
;
14196 /* If there are no more rows to try, or just one, give up. */
14197 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14198 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14199 || CHARPOS (start
) == ZV
)
14201 clear_glyph_matrix (w
->desired_matrix
);
14205 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14207 /* If we have reached alignment,
14208 we can copy the rest of the rows. */
14209 if (IT_CHARPOS (it
) == CHARPOS (start
))
14212 if (display_line (&it
))
14213 last_text_row
= it
.glyph_row
- 1;
14216 /* A value of current_y < last_visible_y means that we stopped
14217 at the previous window start, which in turn means that we
14218 have at least one reusable row. */
14219 if (it
.current_y
< it
.last_visible_y
)
14221 /* IT.vpos always starts from 0; it counts text lines. */
14222 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14224 /* Find PT if not already found in the lines displayed. */
14225 if (w
->cursor
.vpos
< 0)
14227 int dy
= it
.current_y
- start_row
->y
;
14229 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14230 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14232 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14233 dy
, nrows_scrolled
);
14236 clear_glyph_matrix (w
->desired_matrix
);
14241 /* Scroll the display. Do it before the current matrix is
14242 changed. The problem here is that update has not yet
14243 run, i.e. part of the current matrix is not up to date.
14244 scroll_run_hook will clear the cursor, and use the
14245 current matrix to get the height of the row the cursor is
14247 run
.current_y
= start_row
->y
;
14248 run
.desired_y
= it
.current_y
;
14249 run
.height
= it
.last_visible_y
- it
.current_y
;
14251 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14254 FRAME_RIF (f
)->update_window_begin_hook (w
);
14255 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14256 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14257 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14261 /* Shift current matrix down by nrows_scrolled lines. */
14262 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14263 rotate_matrix (w
->current_matrix
,
14265 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14268 /* Disable lines that must be updated. */
14269 for (i
= 0; i
< nrows_scrolled
; ++i
)
14270 (start_row
+ i
)->enabled_p
= 0;
14272 /* Re-compute Y positions. */
14273 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14274 max_y
= it
.last_visible_y
;
14275 for (row
= start_row
+ nrows_scrolled
;
14279 row
->y
= it
.current_y
;
14280 row
->visible_height
= row
->height
;
14282 if (row
->y
< min_y
)
14283 row
->visible_height
-= min_y
- row
->y
;
14284 if (row
->y
+ row
->height
> max_y
)
14285 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14286 row
->redraw_fringe_bitmaps_p
= 1;
14288 it
.current_y
+= row
->height
;
14290 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14291 last_reused_text_row
= row
;
14292 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14296 /* Disable lines in the current matrix which are now
14297 below the window. */
14298 for (++row
; row
< bottom_row
; ++row
)
14299 row
->enabled_p
= row
->mode_line_p
= 0;
14302 /* Update window_end_pos etc.; last_reused_text_row is the last
14303 reused row from the current matrix containing text, if any.
14304 The value of last_text_row is the last displayed line
14305 containing text. */
14306 if (last_reused_text_row
)
14308 w
->window_end_bytepos
14309 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14311 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14313 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14314 w
->current_matrix
));
14316 else if (last_text_row
)
14318 w
->window_end_bytepos
14319 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14321 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14323 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14327 /* This window must be completely empty. */
14328 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14329 w
->window_end_pos
= make_number (Z
- ZV
);
14330 w
->window_end_vpos
= make_number (0);
14332 w
->window_end_valid
= Qnil
;
14334 /* Update hint: don't try scrolling again in update_window. */
14335 w
->desired_matrix
->no_scrolling_p
= 1;
14338 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14342 else if (CHARPOS (new_start
) > CHARPOS (start
))
14344 struct glyph_row
*pt_row
, *row
;
14345 struct glyph_row
*first_reusable_row
;
14346 struct glyph_row
*first_row_to_display
;
14348 int yb
= window_text_bottom_y (w
);
14350 /* Find the row starting at new_start, if there is one. Don't
14351 reuse a partially visible line at the end. */
14352 first_reusable_row
= start_row
;
14353 while (first_reusable_row
->enabled_p
14354 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14355 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14356 < CHARPOS (new_start
)))
14357 ++first_reusable_row
;
14359 /* Give up if there is no row to reuse. */
14360 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14361 || !first_reusable_row
->enabled_p
14362 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14363 != CHARPOS (new_start
)))
14366 /* We can reuse fully visible rows beginning with
14367 first_reusable_row to the end of the window. Set
14368 first_row_to_display to the first row that cannot be reused.
14369 Set pt_row to the row containing point, if there is any. */
14371 for (first_row_to_display
= first_reusable_row
;
14372 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14373 ++first_row_to_display
)
14375 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14376 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14377 pt_row
= first_row_to_display
;
14380 /* Start displaying at the start of first_row_to_display. */
14381 xassert (first_row_to_display
->y
< yb
);
14382 init_to_row_start (&it
, w
, first_row_to_display
);
14384 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14386 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14388 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14389 + WINDOW_HEADER_LINE_HEIGHT (w
));
14391 /* Display lines beginning with first_row_to_display in the
14392 desired matrix. Set last_text_row to the last row displayed
14393 that displays text. */
14394 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14395 if (pt_row
== NULL
)
14396 w
->cursor
.vpos
= -1;
14397 last_text_row
= NULL
;
14398 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14399 if (display_line (&it
))
14400 last_text_row
= it
.glyph_row
- 1;
14402 /* If point is in a reused row, adjust y and vpos of the cursor
14406 w
->cursor
.vpos
-= nrows_scrolled
;
14407 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14410 /* Give up if point isn't in a row displayed or reused. (This
14411 also handles the case where w->cursor.vpos < nrows_scrolled
14412 after the calls to display_line, which can happen with scroll
14413 margins. See bug#1295.) */
14414 if (w
->cursor
.vpos
< 0)
14416 clear_glyph_matrix (w
->desired_matrix
);
14420 /* Scroll the display. */
14421 run
.current_y
= first_reusable_row
->y
;
14422 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14423 run
.height
= it
.last_visible_y
- run
.current_y
;
14424 dy
= run
.current_y
- run
.desired_y
;
14429 FRAME_RIF (f
)->update_window_begin_hook (w
);
14430 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14431 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14432 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14436 /* Adjust Y positions of reused rows. */
14437 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14438 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14439 max_y
= it
.last_visible_y
;
14440 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14443 row
->visible_height
= row
->height
;
14444 if (row
->y
< min_y
)
14445 row
->visible_height
-= min_y
- row
->y
;
14446 if (row
->y
+ row
->height
> max_y
)
14447 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14448 row
->redraw_fringe_bitmaps_p
= 1;
14451 /* Scroll the current matrix. */
14452 xassert (nrows_scrolled
> 0);
14453 rotate_matrix (w
->current_matrix
,
14455 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14458 /* Disable rows not reused. */
14459 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14460 row
->enabled_p
= 0;
14462 /* Point may have moved to a different line, so we cannot assume that
14463 the previous cursor position is valid; locate the correct row. */
14466 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14467 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14471 w
->cursor
.y
= row
->y
;
14473 if (row
< bottom_row
)
14475 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14476 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14479 && (!BUFFERP (glyph
->object
)
14480 || glyph
->charpos
< PT
);
14484 w
->cursor
.x
+= glyph
->pixel_width
;
14489 /* Adjust window end. A null value of last_text_row means that
14490 the window end is in reused rows which in turn means that
14491 only its vpos can have changed. */
14494 w
->window_end_bytepos
14495 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14497 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14499 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14504 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14507 w
->window_end_valid
= Qnil
;
14508 w
->desired_matrix
->no_scrolling_p
= 1;
14511 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14521 /************************************************************************
14522 Window redisplay reusing current matrix when buffer has changed
14523 ************************************************************************/
14525 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14526 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14528 static struct glyph_row
*
14529 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14530 struct glyph_row
*));
14533 /* Return the last row in MATRIX displaying text. If row START is
14534 non-null, start searching with that row. IT gives the dimensions
14535 of the display. Value is null if matrix is empty; otherwise it is
14536 a pointer to the row found. */
14538 static struct glyph_row
*
14539 find_last_row_displaying_text (matrix
, it
, start
)
14540 struct glyph_matrix
*matrix
;
14542 struct glyph_row
*start
;
14544 struct glyph_row
*row
, *row_found
;
14546 /* Set row_found to the last row in IT->w's current matrix
14547 displaying text. The loop looks funny but think of partially
14550 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14551 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14553 xassert (row
->enabled_p
);
14555 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14564 /* Return the last row in the current matrix of W that is not affected
14565 by changes at the start of current_buffer that occurred since W's
14566 current matrix was built. Value is null if no such row exists.
14568 BEG_UNCHANGED us the number of characters unchanged at the start of
14569 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14570 first changed character in current_buffer. Characters at positions <
14571 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14572 when the current matrix was built. */
14574 static struct glyph_row
*
14575 find_last_unchanged_at_beg_row (w
)
14578 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14579 struct glyph_row
*row
;
14580 struct glyph_row
*row_found
= NULL
;
14581 int yb
= window_text_bottom_y (w
);
14583 /* Find the last row displaying unchanged text. */
14584 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14585 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14586 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14589 if (/* If row ends before first_changed_pos, it is unchanged,
14590 except in some case. */
14591 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14592 /* When row ends in ZV and we write at ZV it is not
14594 && !row
->ends_at_zv_p
14595 /* When first_changed_pos is the end of a continued line,
14596 row is not unchanged because it may be no longer
14598 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14599 && (row
->continued_p
14600 || row
->exact_window_width_line_p
)))
14603 /* Stop if last visible row. */
14604 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14612 /* Find the first glyph row in the current matrix of W that is not
14613 affected by changes at the end of current_buffer since the
14614 time W's current matrix was built.
14616 Return in *DELTA the number of chars by which buffer positions in
14617 unchanged text at the end of current_buffer must be adjusted.
14619 Return in *DELTA_BYTES the corresponding number of bytes.
14621 Value is null if no such row exists, i.e. all rows are affected by
14624 static struct glyph_row
*
14625 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14627 int *delta
, *delta_bytes
;
14629 struct glyph_row
*row
;
14630 struct glyph_row
*row_found
= NULL
;
14632 *delta
= *delta_bytes
= 0;
14634 /* Display must not have been paused, otherwise the current matrix
14635 is not up to date. */
14636 eassert (!NILP (w
->window_end_valid
));
14638 /* A value of window_end_pos >= END_UNCHANGED means that the window
14639 end is in the range of changed text. If so, there is no
14640 unchanged row at the end of W's current matrix. */
14641 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14644 /* Set row to the last row in W's current matrix displaying text. */
14645 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14647 /* If matrix is entirely empty, no unchanged row exists. */
14648 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14650 /* The value of row is the last glyph row in the matrix having a
14651 meaningful buffer position in it. The end position of row
14652 corresponds to window_end_pos. This allows us to translate
14653 buffer positions in the current matrix to current buffer
14654 positions for characters not in changed text. */
14655 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14656 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14657 int last_unchanged_pos
, last_unchanged_pos_old
;
14658 struct glyph_row
*first_text_row
14659 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14661 *delta
= Z
- Z_old
;
14662 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14664 /* Set last_unchanged_pos to the buffer position of the last
14665 character in the buffer that has not been changed. Z is the
14666 index + 1 of the last character in current_buffer, i.e. by
14667 subtracting END_UNCHANGED we get the index of the last
14668 unchanged character, and we have to add BEG to get its buffer
14670 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14671 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14673 /* Search backward from ROW for a row displaying a line that
14674 starts at a minimum position >= last_unchanged_pos_old. */
14675 for (; row
> first_text_row
; --row
)
14677 /* This used to abort, but it can happen.
14678 It is ok to just stop the search instead here. KFS. */
14679 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14682 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14687 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14693 /* Make sure that glyph rows in the current matrix of window W
14694 reference the same glyph memory as corresponding rows in the
14695 frame's frame matrix. This function is called after scrolling W's
14696 current matrix on a terminal frame in try_window_id and
14697 try_window_reusing_current_matrix. */
14700 sync_frame_with_window_matrix_rows (w
)
14703 struct frame
*f
= XFRAME (w
->frame
);
14704 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14706 /* Preconditions: W must be a leaf window and full-width. Its frame
14707 must have a frame matrix. */
14708 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14709 xassert (WINDOW_FULL_WIDTH_P (w
));
14710 xassert (!FRAME_WINDOW_P (f
));
14712 /* If W is a full-width window, glyph pointers in W's current matrix
14713 have, by definition, to be the same as glyph pointers in the
14714 corresponding frame matrix. Note that frame matrices have no
14715 marginal areas (see build_frame_matrix). */
14716 window_row
= w
->current_matrix
->rows
;
14717 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14718 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14719 while (window_row
< window_row_end
)
14721 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14722 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14724 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14725 frame_row
->glyphs
[TEXT_AREA
] = start
;
14726 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14727 frame_row
->glyphs
[LAST_AREA
] = end
;
14729 /* Disable frame rows whose corresponding window rows have
14730 been disabled in try_window_id. */
14731 if (!window_row
->enabled_p
)
14732 frame_row
->enabled_p
= 0;
14734 ++window_row
, ++frame_row
;
14739 /* Find the glyph row in window W containing CHARPOS. Consider all
14740 rows between START and END (not inclusive). END null means search
14741 all rows to the end of the display area of W. Value is the row
14742 containing CHARPOS or null. */
14745 row_containing_pos (w
, charpos
, start
, end
, dy
)
14748 struct glyph_row
*start
, *end
;
14751 struct glyph_row
*row
= start
;
14754 /* If we happen to start on a header-line, skip that. */
14755 if (row
->mode_line_p
)
14758 if ((end
&& row
>= end
) || !row
->enabled_p
)
14761 last_y
= window_text_bottom_y (w
) - dy
;
14765 /* Give up if we have gone too far. */
14766 if (end
&& row
>= end
)
14768 /* This formerly returned if they were equal.
14769 I think that both quantities are of a "last plus one" type;
14770 if so, when they are equal, the row is within the screen. -- rms. */
14771 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14774 /* If it is in this row, return this row. */
14775 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14776 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14777 /* The end position of a row equals the start
14778 position of the next row. If CHARPOS is there, we
14779 would rather display it in the next line, except
14780 when this line ends in ZV. */
14781 && !row
->ends_at_zv_p
14782 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14783 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14790 /* Try to redisplay window W by reusing its existing display. W's
14791 current matrix must be up to date when this function is called,
14792 i.e. window_end_valid must not be nil.
14796 1 if display has been updated
14797 0 if otherwise unsuccessful
14798 -1 if redisplay with same window start is known not to succeed
14800 The following steps are performed:
14802 1. Find the last row in the current matrix of W that is not
14803 affected by changes at the start of current_buffer. If no such row
14806 2. Find the first row in W's current matrix that is not affected by
14807 changes at the end of current_buffer. Maybe there is no such row.
14809 3. Display lines beginning with the row + 1 found in step 1 to the
14810 row found in step 2 or, if step 2 didn't find a row, to the end of
14813 4. If cursor is not known to appear on the window, give up.
14815 5. If display stopped at the row found in step 2, scroll the
14816 display and current matrix as needed.
14818 6. Maybe display some lines at the end of W, if we must. This can
14819 happen under various circumstances, like a partially visible line
14820 becoming fully visible, or because newly displayed lines are displayed
14821 in smaller font sizes.
14823 7. Update W's window end information. */
14829 struct frame
*f
= XFRAME (w
->frame
);
14830 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14831 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14832 struct glyph_row
*last_unchanged_at_beg_row
;
14833 struct glyph_row
*first_unchanged_at_end_row
;
14834 struct glyph_row
*row
;
14835 struct glyph_row
*bottom_row
;
14838 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14839 struct text_pos start_pos
;
14841 int first_unchanged_at_end_vpos
= 0;
14842 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14843 struct text_pos start
;
14844 int first_changed_charpos
, last_changed_charpos
;
14847 if (inhibit_try_window_id
)
14851 /* This is handy for debugging. */
14853 #define GIVE_UP(X) \
14855 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14859 #define GIVE_UP(X) return 0
14862 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14864 /* Don't use this for mini-windows because these can show
14865 messages and mini-buffers, and we don't handle that here. */
14866 if (MINI_WINDOW_P (w
))
14869 /* This flag is used to prevent redisplay optimizations. */
14870 if (windows_or_buffers_changed
|| cursor_type_changed
)
14873 /* Verify that narrowing has not changed.
14874 Also verify that we were not told to prevent redisplay optimizations.
14875 It would be nice to further
14876 reduce the number of cases where this prevents try_window_id. */
14877 if (current_buffer
->clip_changed
14878 || current_buffer
->prevent_redisplay_optimizations_p
)
14881 /* Window must either use window-based redisplay or be full width. */
14882 if (!FRAME_WINDOW_P (f
)
14883 && (!FRAME_LINE_INS_DEL_OK (f
)
14884 || !WINDOW_FULL_WIDTH_P (w
)))
14887 /* Give up if point is known NOT to appear in W. */
14888 if (PT
< CHARPOS (start
))
14891 /* Another way to prevent redisplay optimizations. */
14892 if (XFASTINT (w
->last_modified
) == 0)
14895 /* Verify that window is not hscrolled. */
14896 if (XFASTINT (w
->hscroll
) != 0)
14899 /* Verify that display wasn't paused. */
14900 if (NILP (w
->window_end_valid
))
14903 /* Can't use this if highlighting a region because a cursor movement
14904 will do more than just set the cursor. */
14905 if (!NILP (Vtransient_mark_mode
)
14906 && !NILP (current_buffer
->mark_active
))
14909 /* Likewise if highlighting trailing whitespace. */
14910 if (!NILP (Vshow_trailing_whitespace
))
14913 /* Likewise if showing a region. */
14914 if (!NILP (w
->region_showing
))
14917 /* Can't use this if overlay arrow position and/or string have
14919 if (overlay_arrows_changed_p ())
14922 /* When word-wrap is on, adding a space to the first word of a
14923 wrapped line can change the wrap position, altering the line
14924 above it. It might be worthwhile to handle this more
14925 intelligently, but for now just redisplay from scratch. */
14926 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14929 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14930 only if buffer has really changed. The reason is that the gap is
14931 initially at Z for freshly visited files. The code below would
14932 set end_unchanged to 0 in that case. */
14933 if (MODIFF
> SAVE_MODIFF
14934 /* This seems to happen sometimes after saving a buffer. */
14935 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14937 if (GPT
- BEG
< BEG_UNCHANGED
)
14938 BEG_UNCHANGED
= GPT
- BEG
;
14939 if (Z
- GPT
< END_UNCHANGED
)
14940 END_UNCHANGED
= Z
- GPT
;
14943 /* The position of the first and last character that has been changed. */
14944 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14945 last_changed_charpos
= Z
- END_UNCHANGED
;
14947 /* If window starts after a line end, and the last change is in
14948 front of that newline, then changes don't affect the display.
14949 This case happens with stealth-fontification. Note that although
14950 the display is unchanged, glyph positions in the matrix have to
14951 be adjusted, of course. */
14952 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14953 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14954 && ((last_changed_charpos
< CHARPOS (start
)
14955 && CHARPOS (start
) == BEGV
)
14956 || (last_changed_charpos
< CHARPOS (start
) - 1
14957 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14959 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14960 struct glyph_row
*r0
;
14962 /* Compute how many chars/bytes have been added to or removed
14963 from the buffer. */
14964 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14965 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14967 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14969 /* Give up if PT is not in the window. Note that it already has
14970 been checked at the start of try_window_id that PT is not in
14971 front of the window start. */
14972 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14975 /* If window start is unchanged, we can reuse the whole matrix
14976 as is, after adjusting glyph positions. No need to compute
14977 the window end again, since its offset from Z hasn't changed. */
14978 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14979 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14980 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14981 /* PT must not be in a partially visible line. */
14982 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14983 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14985 /* Adjust positions in the glyph matrix. */
14986 if (delta
|| delta_bytes
)
14988 struct glyph_row
*r1
14989 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14990 increment_matrix_positions (w
->current_matrix
,
14991 MATRIX_ROW_VPOS (r0
, current_matrix
),
14992 MATRIX_ROW_VPOS (r1
, current_matrix
),
14993 delta
, delta_bytes
);
14996 /* Set the cursor. */
14997 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14999 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15006 /* Handle the case that changes are all below what is displayed in
15007 the window, and that PT is in the window. This shortcut cannot
15008 be taken if ZV is visible in the window, and text has been added
15009 there that is visible in the window. */
15010 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15011 /* ZV is not visible in the window, or there are no
15012 changes at ZV, actually. */
15013 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15014 || first_changed_charpos
== last_changed_charpos
))
15016 struct glyph_row
*r0
;
15018 /* Give up if PT is not in the window. Note that it already has
15019 been checked at the start of try_window_id that PT is not in
15020 front of the window start. */
15021 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15024 /* If window start is unchanged, we can reuse the whole matrix
15025 as is, without changing glyph positions since no text has
15026 been added/removed in front of the window end. */
15027 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15028 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15029 /* PT must not be in a partially visible line. */
15030 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15031 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15033 /* We have to compute the window end anew since text
15034 can have been added/removed after it. */
15036 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15037 w
->window_end_bytepos
15038 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15040 /* Set the cursor. */
15041 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15043 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15050 /* Give up if window start is in the changed area.
15052 The condition used to read
15054 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15056 but why that was tested escapes me at the moment. */
15057 if (CHARPOS (start
) >= first_changed_charpos
15058 && CHARPOS (start
) <= last_changed_charpos
)
15061 /* Check that window start agrees with the start of the first glyph
15062 row in its current matrix. Check this after we know the window
15063 start is not in changed text, otherwise positions would not be
15065 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15066 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15069 /* Give up if the window ends in strings. Overlay strings
15070 at the end are difficult to handle, so don't try. */
15071 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15072 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15075 /* Compute the position at which we have to start displaying new
15076 lines. Some of the lines at the top of the window might be
15077 reusable because they are not displaying changed text. Find the
15078 last row in W's current matrix not affected by changes at the
15079 start of current_buffer. Value is null if changes start in the
15080 first line of window. */
15081 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15082 if (last_unchanged_at_beg_row
)
15084 /* Avoid starting to display in the moddle of a character, a TAB
15085 for instance. This is easier than to set up the iterator
15086 exactly, and it's not a frequent case, so the additional
15087 effort wouldn't really pay off. */
15088 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15089 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15090 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15091 --last_unchanged_at_beg_row
;
15093 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15096 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15098 start_pos
= it
.current
.pos
;
15100 /* Start displaying new lines in the desired matrix at the same
15101 vpos we would use in the current matrix, i.e. below
15102 last_unchanged_at_beg_row. */
15103 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15105 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15106 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15108 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15112 /* There are no reusable lines at the start of the window.
15113 Start displaying in the first text line. */
15114 start_display (&it
, w
, start
);
15115 it
.vpos
= it
.first_vpos
;
15116 start_pos
= it
.current
.pos
;
15119 /* Find the first row that is not affected by changes at the end of
15120 the buffer. Value will be null if there is no unchanged row, in
15121 which case we must redisplay to the end of the window. delta
15122 will be set to the value by which buffer positions beginning with
15123 first_unchanged_at_end_row have to be adjusted due to text
15125 first_unchanged_at_end_row
15126 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15127 IF_DEBUG (debug_delta
= delta
);
15128 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15130 /* Set stop_pos to the buffer position up to which we will have to
15131 display new lines. If first_unchanged_at_end_row != NULL, this
15132 is the buffer position of the start of the line displayed in that
15133 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15134 that we don't stop at a buffer position. */
15136 if (first_unchanged_at_end_row
)
15138 xassert (last_unchanged_at_beg_row
== NULL
15139 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15141 /* If this is a continuation line, move forward to the next one
15142 that isn't. Changes in lines above affect this line.
15143 Caution: this may move first_unchanged_at_end_row to a row
15144 not displaying text. */
15145 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15146 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15147 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15148 < it
.last_visible_y
))
15149 ++first_unchanged_at_end_row
;
15151 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15152 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15153 >= it
.last_visible_y
))
15154 first_unchanged_at_end_row
= NULL
;
15157 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15159 first_unchanged_at_end_vpos
15160 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15161 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15164 else if (last_unchanged_at_beg_row
== NULL
)
15170 /* Either there is no unchanged row at the end, or the one we have
15171 now displays text. This is a necessary condition for the window
15172 end pos calculation at the end of this function. */
15173 xassert (first_unchanged_at_end_row
== NULL
15174 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15176 debug_last_unchanged_at_beg_vpos
15177 = (last_unchanged_at_beg_row
15178 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15180 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15182 #endif /* GLYPH_DEBUG != 0 */
15185 /* Display new lines. Set last_text_row to the last new line
15186 displayed which has text on it, i.e. might end up as being the
15187 line where the window_end_vpos is. */
15188 w
->cursor
.vpos
= -1;
15189 last_text_row
= NULL
;
15190 overlay_arrow_seen
= 0;
15191 while (it
.current_y
< it
.last_visible_y
15192 && !fonts_changed_p
15193 && (first_unchanged_at_end_row
== NULL
15194 || IT_CHARPOS (it
) < stop_pos
))
15196 if (display_line (&it
))
15197 last_text_row
= it
.glyph_row
- 1;
15200 if (fonts_changed_p
)
15204 /* Compute differences in buffer positions, y-positions etc. for
15205 lines reused at the bottom of the window. Compute what we can
15207 if (first_unchanged_at_end_row
15208 /* No lines reused because we displayed everything up to the
15209 bottom of the window. */
15210 && it
.current_y
< it
.last_visible_y
)
15213 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15215 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15216 run
.current_y
= first_unchanged_at_end_row
->y
;
15217 run
.desired_y
= run
.current_y
+ dy
;
15218 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15222 delta
= delta_bytes
= dvpos
= dy
15223 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15224 first_unchanged_at_end_row
= NULL
;
15226 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15229 /* Find the cursor if not already found. We have to decide whether
15230 PT will appear on this window (it sometimes doesn't, but this is
15231 not a very frequent case.) This decision has to be made before
15232 the current matrix is altered. A value of cursor.vpos < 0 means
15233 that PT is either in one of the lines beginning at
15234 first_unchanged_at_end_row or below the window. Don't care for
15235 lines that might be displayed later at the window end; as
15236 mentioned, this is not a frequent case. */
15237 if (w
->cursor
.vpos
< 0)
15239 /* Cursor in unchanged rows at the top? */
15240 if (PT
< CHARPOS (start_pos
)
15241 && last_unchanged_at_beg_row
)
15243 row
= row_containing_pos (w
, PT
,
15244 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15245 last_unchanged_at_beg_row
+ 1, 0);
15247 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15250 /* Start from first_unchanged_at_end_row looking for PT. */
15251 else if (first_unchanged_at_end_row
)
15253 row
= row_containing_pos (w
, PT
- delta
,
15254 first_unchanged_at_end_row
, NULL
, 0);
15256 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15257 delta_bytes
, dy
, dvpos
);
15260 /* Give up if cursor was not found. */
15261 if (w
->cursor
.vpos
< 0)
15263 clear_glyph_matrix (w
->desired_matrix
);
15268 /* Don't let the cursor end in the scroll margins. */
15270 int this_scroll_margin
, cursor_height
;
15272 this_scroll_margin
= max (0, scroll_margin
);
15273 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15274 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15275 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15277 if ((w
->cursor
.y
< this_scroll_margin
15278 && CHARPOS (start
) > BEGV
)
15279 /* Old redisplay didn't take scroll margin into account at the bottom,
15280 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15281 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15282 ? cursor_height
+ this_scroll_margin
15283 : 1)) > it
.last_visible_y
)
15285 w
->cursor
.vpos
= -1;
15286 clear_glyph_matrix (w
->desired_matrix
);
15291 /* Scroll the display. Do it before changing the current matrix so
15292 that xterm.c doesn't get confused about where the cursor glyph is
15294 if (dy
&& run
.height
)
15298 if (FRAME_WINDOW_P (f
))
15300 FRAME_RIF (f
)->update_window_begin_hook (w
);
15301 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15302 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15303 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15307 /* Terminal frame. In this case, dvpos gives the number of
15308 lines to scroll by; dvpos < 0 means scroll up. */
15309 int first_unchanged_at_end_vpos
15310 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15311 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15312 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15313 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15314 + window_internal_height (w
));
15316 /* Perform the operation on the screen. */
15319 /* Scroll last_unchanged_at_beg_row to the end of the
15320 window down dvpos lines. */
15321 set_terminal_window (f
, end
);
15323 /* On dumb terminals delete dvpos lines at the end
15324 before inserting dvpos empty lines. */
15325 if (!FRAME_SCROLL_REGION_OK (f
))
15326 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15328 /* Insert dvpos empty lines in front of
15329 last_unchanged_at_beg_row. */
15330 ins_del_lines (f
, from
, dvpos
);
15332 else if (dvpos
< 0)
15334 /* Scroll up last_unchanged_at_beg_vpos to the end of
15335 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15336 set_terminal_window (f
, end
);
15338 /* Delete dvpos lines in front of
15339 last_unchanged_at_beg_vpos. ins_del_lines will set
15340 the cursor to the given vpos and emit |dvpos| delete
15342 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15344 /* On a dumb terminal insert dvpos empty lines at the
15346 if (!FRAME_SCROLL_REGION_OK (f
))
15347 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15350 set_terminal_window (f
, 0);
15356 /* Shift reused rows of the current matrix to the right position.
15357 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15359 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15360 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15363 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15364 bottom_vpos
, dvpos
);
15365 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15368 else if (dvpos
> 0)
15370 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15371 bottom_vpos
, dvpos
);
15372 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15373 first_unchanged_at_end_vpos
+ dvpos
, 0);
15376 /* For frame-based redisplay, make sure that current frame and window
15377 matrix are in sync with respect to glyph memory. */
15378 if (!FRAME_WINDOW_P (f
))
15379 sync_frame_with_window_matrix_rows (w
);
15381 /* Adjust buffer positions in reused rows. */
15382 if (delta
|| delta_bytes
)
15383 increment_matrix_positions (current_matrix
,
15384 first_unchanged_at_end_vpos
+ dvpos
,
15385 bottom_vpos
, delta
, delta_bytes
);
15387 /* Adjust Y positions. */
15389 shift_glyph_matrix (w
, current_matrix
,
15390 first_unchanged_at_end_vpos
+ dvpos
,
15393 if (first_unchanged_at_end_row
)
15395 first_unchanged_at_end_row
+= dvpos
;
15396 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15397 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15398 first_unchanged_at_end_row
= NULL
;
15401 /* If scrolling up, there may be some lines to display at the end of
15403 last_text_row_at_end
= NULL
;
15406 /* Scrolling up can leave for example a partially visible line
15407 at the end of the window to be redisplayed. */
15408 /* Set last_row to the glyph row in the current matrix where the
15409 window end line is found. It has been moved up or down in
15410 the matrix by dvpos. */
15411 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15412 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15414 /* If last_row is the window end line, it should display text. */
15415 xassert (last_row
->displays_text_p
);
15417 /* If window end line was partially visible before, begin
15418 displaying at that line. Otherwise begin displaying with the
15419 line following it. */
15420 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15422 init_to_row_start (&it
, w
, last_row
);
15423 it
.vpos
= last_vpos
;
15424 it
.current_y
= last_row
->y
;
15428 init_to_row_end (&it
, w
, last_row
);
15429 it
.vpos
= 1 + last_vpos
;
15430 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15434 /* We may start in a continuation line. If so, we have to
15435 get the right continuation_lines_width and current_x. */
15436 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15437 it
.hpos
= it
.current_x
= 0;
15439 /* Display the rest of the lines at the window end. */
15440 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15441 while (it
.current_y
< it
.last_visible_y
15442 && !fonts_changed_p
)
15444 /* Is it always sure that the display agrees with lines in
15445 the current matrix? I don't think so, so we mark rows
15446 displayed invalid in the current matrix by setting their
15447 enabled_p flag to zero. */
15448 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15449 if (display_line (&it
))
15450 last_text_row_at_end
= it
.glyph_row
- 1;
15454 /* Update window_end_pos and window_end_vpos. */
15455 if (first_unchanged_at_end_row
15456 && !last_text_row_at_end
)
15458 /* Window end line if one of the preserved rows from the current
15459 matrix. Set row to the last row displaying text in current
15460 matrix starting at first_unchanged_at_end_row, after
15462 xassert (first_unchanged_at_end_row
->displays_text_p
);
15463 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15464 first_unchanged_at_end_row
);
15465 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15467 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15468 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15470 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15471 xassert (w
->window_end_bytepos
>= 0);
15472 IF_DEBUG (debug_method_add (w
, "A"));
15474 else if (last_text_row_at_end
)
15477 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15478 w
->window_end_bytepos
15479 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15481 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15482 xassert (w
->window_end_bytepos
>= 0);
15483 IF_DEBUG (debug_method_add (w
, "B"));
15485 else if (last_text_row
)
15487 /* We have displayed either to the end of the window or at the
15488 end of the window, i.e. the last row with text is to be found
15489 in the desired matrix. */
15491 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15492 w
->window_end_bytepos
15493 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15495 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15496 xassert (w
->window_end_bytepos
>= 0);
15498 else if (first_unchanged_at_end_row
== NULL
15499 && last_text_row
== NULL
15500 && last_text_row_at_end
== NULL
)
15502 /* Displayed to end of window, but no line containing text was
15503 displayed. Lines were deleted at the end of the window. */
15504 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15505 int vpos
= XFASTINT (w
->window_end_vpos
);
15506 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15507 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15510 row
== NULL
&& vpos
>= first_vpos
;
15511 --vpos
, --current_row
, --desired_row
)
15513 if (desired_row
->enabled_p
)
15515 if (desired_row
->displays_text_p
)
15518 else if (current_row
->displays_text_p
)
15522 xassert (row
!= NULL
);
15523 w
->window_end_vpos
= make_number (vpos
+ 1);
15524 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15525 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15526 xassert (w
->window_end_bytepos
>= 0);
15527 IF_DEBUG (debug_method_add (w
, "C"));
15532 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15533 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15535 /* Record that display has not been completed. */
15536 w
->window_end_valid
= Qnil
;
15537 w
->desired_matrix
->no_scrolling_p
= 1;
15545 /***********************************************************************
15546 More debugging support
15547 ***********************************************************************/
15551 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15552 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15553 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15556 /* Dump the contents of glyph matrix MATRIX on stderr.
15558 GLYPHS 0 means don't show glyph contents.
15559 GLYPHS 1 means show glyphs in short form
15560 GLYPHS > 1 means show glyphs in long form. */
15563 dump_glyph_matrix (matrix
, glyphs
)
15564 struct glyph_matrix
*matrix
;
15568 for (i
= 0; i
< matrix
->nrows
; ++i
)
15569 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15573 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15574 the glyph row and area where the glyph comes from. */
15577 dump_glyph (row
, glyph
, area
)
15578 struct glyph_row
*row
;
15579 struct glyph
*glyph
;
15582 if (glyph
->type
== CHAR_GLYPH
)
15585 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15586 glyph
- row
->glyphs
[TEXT_AREA
],
15589 (BUFFERP (glyph
->object
)
15591 : (STRINGP (glyph
->object
)
15594 glyph
->pixel_width
,
15596 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15600 glyph
->left_box_line_p
,
15601 glyph
->right_box_line_p
);
15603 else if (glyph
->type
== STRETCH_GLYPH
)
15606 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15607 glyph
- row
->glyphs
[TEXT_AREA
],
15610 (BUFFERP (glyph
->object
)
15612 : (STRINGP (glyph
->object
)
15615 glyph
->pixel_width
,
15619 glyph
->left_box_line_p
,
15620 glyph
->right_box_line_p
);
15622 else if (glyph
->type
== IMAGE_GLYPH
)
15625 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15626 glyph
- row
->glyphs
[TEXT_AREA
],
15629 (BUFFERP (glyph
->object
)
15631 : (STRINGP (glyph
->object
)
15634 glyph
->pixel_width
,
15638 glyph
->left_box_line_p
,
15639 glyph
->right_box_line_p
);
15641 else if (glyph
->type
== COMPOSITE_GLYPH
)
15644 " %5d %4c %6d %c %3d 0x%05x",
15645 glyph
- row
->glyphs
[TEXT_AREA
],
15648 (BUFFERP (glyph
->object
)
15650 : (STRINGP (glyph
->object
)
15653 glyph
->pixel_width
,
15655 if (glyph
->u
.cmp
.automatic
)
15658 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
15659 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
15661 glyph
->left_box_line_p
,
15662 glyph
->right_box_line_p
);
15667 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15668 GLYPHS 0 means don't show glyph contents.
15669 GLYPHS 1 means show glyphs in short form
15670 GLYPHS > 1 means show glyphs in long form. */
15673 dump_glyph_row (row
, vpos
, glyphs
)
15674 struct glyph_row
*row
;
15679 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15680 fprintf (stderr
, "======================================================================\n");
15682 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15683 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15685 MATRIX_ROW_START_CHARPOS (row
),
15686 MATRIX_ROW_END_CHARPOS (row
),
15687 row
->used
[TEXT_AREA
],
15688 row
->contains_overlapping_glyphs_p
,
15690 row
->truncated_on_left_p
,
15691 row
->truncated_on_right_p
,
15693 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15694 row
->displays_text_p
,
15697 row
->ends_in_middle_of_char_p
,
15698 row
->starts_in_middle_of_char_p
,
15704 row
->visible_height
,
15707 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15708 row
->end
.overlay_string_index
,
15709 row
->continuation_lines_width
);
15710 fprintf (stderr
, "%9d %5d\n",
15711 CHARPOS (row
->start
.string_pos
),
15712 CHARPOS (row
->end
.string_pos
));
15713 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15714 row
->end
.dpvec_index
);
15721 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15723 struct glyph
*glyph
= row
->glyphs
[area
];
15724 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15726 /* Glyph for a line end in text. */
15727 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15730 if (glyph
< glyph_end
)
15731 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15733 for (; glyph
< glyph_end
; ++glyph
)
15734 dump_glyph (row
, glyph
, area
);
15737 else if (glyphs
== 1)
15741 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15743 char *s
= (char *) alloca (row
->used
[area
] + 1);
15746 for (i
= 0; i
< row
->used
[area
]; ++i
)
15748 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15749 if (glyph
->type
== CHAR_GLYPH
15750 && glyph
->u
.ch
< 0x80
15751 && glyph
->u
.ch
>= ' ')
15752 s
[i
] = glyph
->u
.ch
;
15758 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15764 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15765 Sdump_glyph_matrix
, 0, 1, "p",
15766 doc
: /* Dump the current matrix of the selected window to stderr.
15767 Shows contents of glyph row structures. With non-nil
15768 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15769 glyphs in short form, otherwise show glyphs in long form. */)
15771 Lisp_Object glyphs
;
15773 struct window
*w
= XWINDOW (selected_window
);
15774 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15776 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15777 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15778 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15779 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15780 fprintf (stderr
, "=============================================\n");
15781 dump_glyph_matrix (w
->current_matrix
,
15782 NILP (glyphs
) ? 0 : XINT (glyphs
));
15787 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15788 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15791 struct frame
*f
= XFRAME (selected_frame
);
15792 dump_glyph_matrix (f
->current_matrix
, 1);
15797 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15798 doc
: /* Dump glyph row ROW to stderr.
15799 GLYPH 0 means don't dump glyphs.
15800 GLYPH 1 means dump glyphs in short form.
15801 GLYPH > 1 or omitted means dump glyphs in long form. */)
15803 Lisp_Object row
, glyphs
;
15805 struct glyph_matrix
*matrix
;
15808 CHECK_NUMBER (row
);
15809 matrix
= XWINDOW (selected_window
)->current_matrix
;
15811 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15812 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15814 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15819 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15820 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15821 GLYPH 0 means don't dump glyphs.
15822 GLYPH 1 means dump glyphs in short form.
15823 GLYPH > 1 or omitted means dump glyphs in long form. */)
15825 Lisp_Object row
, glyphs
;
15827 struct frame
*sf
= SELECTED_FRAME ();
15828 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15831 CHECK_NUMBER (row
);
15833 if (vpos
>= 0 && vpos
< m
->nrows
)
15834 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15835 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15840 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15841 doc
: /* Toggle tracing of redisplay.
15842 With ARG, turn tracing on if and only if ARG is positive. */)
15847 trace_redisplay_p
= !trace_redisplay_p
;
15850 arg
= Fprefix_numeric_value (arg
);
15851 trace_redisplay_p
= XINT (arg
) > 0;
15858 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15859 doc
: /* Like `format', but print result to stderr.
15860 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15865 Lisp_Object s
= Fformat (nargs
, args
);
15866 fprintf (stderr
, "%s", SDATA (s
));
15870 #endif /* GLYPH_DEBUG */
15874 /***********************************************************************
15875 Building Desired Matrix Rows
15876 ***********************************************************************/
15878 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15879 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15881 static struct glyph_row
*
15882 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15884 Lisp_Object overlay_arrow_string
;
15886 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15887 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15888 struct buffer
*old
= current_buffer
;
15889 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15890 int arrow_len
= SCHARS (overlay_arrow_string
);
15891 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15892 const unsigned char *p
;
15895 int n_glyphs_before
;
15897 set_buffer_temp (buffer
);
15898 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15899 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15900 SET_TEXT_POS (it
.position
, 0, 0);
15902 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15904 while (p
< arrow_end
)
15906 Lisp_Object face
, ilisp
;
15908 /* Get the next character. */
15910 it
.c
= string_char_and_length (p
, &it
.len
);
15912 it
.c
= *p
, it
.len
= 1;
15915 /* Get its face. */
15916 ilisp
= make_number (p
- arrow_string
);
15917 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15918 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15920 /* Compute its width, get its glyphs. */
15921 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15922 SET_TEXT_POS (it
.position
, -1, -1);
15923 PRODUCE_GLYPHS (&it
);
15925 /* If this character doesn't fit any more in the line, we have
15926 to remove some glyphs. */
15927 if (it
.current_x
> it
.last_visible_x
)
15929 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15934 set_buffer_temp (old
);
15935 return it
.glyph_row
;
15939 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15940 glyphs are only inserted for terminal frames since we can't really
15941 win with truncation glyphs when partially visible glyphs are
15942 involved. Which glyphs to insert is determined by
15943 produce_special_glyphs. */
15946 insert_left_trunc_glyphs (it
)
15949 struct it truncate_it
;
15950 struct glyph
*from
, *end
, *to
, *toend
;
15952 xassert (!FRAME_WINDOW_P (it
->f
));
15954 /* Get the truncation glyphs. */
15956 truncate_it
.current_x
= 0;
15957 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15958 truncate_it
.glyph_row
= &scratch_glyph_row
;
15959 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15960 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15961 truncate_it
.object
= make_number (0);
15962 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15964 /* Overwrite glyphs from IT with truncation glyphs. */
15965 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15966 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15967 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15968 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15973 /* There may be padding glyphs left over. Overwrite them too. */
15974 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15976 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15982 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15986 /* Compute the pixel height and width of IT->glyph_row.
15988 Most of the time, ascent and height of a display line will be equal
15989 to the max_ascent and max_height values of the display iterator
15990 structure. This is not the case if
15992 1. We hit ZV without displaying anything. In this case, max_ascent
15993 and max_height will be zero.
15995 2. We have some glyphs that don't contribute to the line height.
15996 (The glyph row flag contributes_to_line_height_p is for future
15997 pixmap extensions).
15999 The first case is easily covered by using default values because in
16000 these cases, the line height does not really matter, except that it
16001 must not be zero. */
16004 compute_line_metrics (it
)
16007 struct glyph_row
*row
= it
->glyph_row
;
16010 if (FRAME_WINDOW_P (it
->f
))
16012 int i
, min_y
, max_y
;
16014 /* The line may consist of one space only, that was added to
16015 place the cursor on it. If so, the row's height hasn't been
16017 if (row
->height
== 0)
16019 if (it
->max_ascent
+ it
->max_descent
== 0)
16020 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16021 row
->ascent
= it
->max_ascent
;
16022 row
->height
= it
->max_ascent
+ it
->max_descent
;
16023 row
->phys_ascent
= it
->max_phys_ascent
;
16024 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16025 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16028 /* Compute the width of this line. */
16029 row
->pixel_width
= row
->x
;
16030 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16031 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16033 xassert (row
->pixel_width
>= 0);
16034 xassert (row
->ascent
>= 0 && row
->height
> 0);
16036 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16037 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16039 /* If first line's physical ascent is larger than its logical
16040 ascent, use the physical ascent, and make the row taller.
16041 This makes accented characters fully visible. */
16042 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16043 && row
->phys_ascent
> row
->ascent
)
16045 row
->height
+= row
->phys_ascent
- row
->ascent
;
16046 row
->ascent
= row
->phys_ascent
;
16049 /* Compute how much of the line is visible. */
16050 row
->visible_height
= row
->height
;
16052 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16053 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16055 if (row
->y
< min_y
)
16056 row
->visible_height
-= min_y
- row
->y
;
16057 if (row
->y
+ row
->height
> max_y
)
16058 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16062 row
->pixel_width
= row
->used
[TEXT_AREA
];
16063 if (row
->continued_p
)
16064 row
->pixel_width
-= it
->continuation_pixel_width
;
16065 else if (row
->truncated_on_right_p
)
16066 row
->pixel_width
-= it
->truncation_pixel_width
;
16067 row
->ascent
= row
->phys_ascent
= 0;
16068 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16069 row
->extra_line_spacing
= 0;
16072 /* Compute a hash code for this row. */
16074 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16075 for (i
= 0; i
< row
->used
[area
]; ++i
)
16076 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16077 + row
->glyphs
[area
][i
].u
.val
16078 + row
->glyphs
[area
][i
].face_id
16079 + row
->glyphs
[area
][i
].padding_p
16080 + (row
->glyphs
[area
][i
].type
<< 2));
16082 it
->max_ascent
= it
->max_descent
= 0;
16083 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16087 /* Append one space to the glyph row of iterator IT if doing a
16088 window-based redisplay. The space has the same face as
16089 IT->face_id. Value is non-zero if a space was added.
16091 This function is called to make sure that there is always one glyph
16092 at the end of a glyph row that the cursor can be set on under
16093 window-systems. (If there weren't such a glyph we would not know
16094 how wide and tall a box cursor should be displayed).
16096 At the same time this space let's a nicely handle clearing to the
16097 end of the line if the row ends in italic text. */
16100 append_space_for_newline (it
, default_face_p
)
16102 int default_face_p
;
16104 if (FRAME_WINDOW_P (it
->f
))
16106 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16108 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16109 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16111 /* Save some values that must not be changed.
16112 Must save IT->c and IT->len because otherwise
16113 ITERATOR_AT_END_P wouldn't work anymore after
16114 append_space_for_newline has been called. */
16115 enum display_element_type saved_what
= it
->what
;
16116 int saved_c
= it
->c
, saved_len
= it
->len
;
16117 int saved_x
= it
->current_x
;
16118 int saved_face_id
= it
->face_id
;
16119 struct text_pos saved_pos
;
16120 Lisp_Object saved_object
;
16123 saved_object
= it
->object
;
16124 saved_pos
= it
->position
;
16126 it
->what
= IT_CHARACTER
;
16127 bzero (&it
->position
, sizeof it
->position
);
16128 it
->object
= make_number (0);
16132 if (default_face_p
)
16133 it
->face_id
= DEFAULT_FACE_ID
;
16134 else if (it
->face_before_selective_p
)
16135 it
->face_id
= it
->saved_face_id
;
16136 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16137 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16139 PRODUCE_GLYPHS (it
);
16141 it
->override_ascent
= -1;
16142 it
->constrain_row_ascent_descent_p
= 0;
16143 it
->current_x
= saved_x
;
16144 it
->object
= saved_object
;
16145 it
->position
= saved_pos
;
16146 it
->what
= saved_what
;
16147 it
->face_id
= saved_face_id
;
16148 it
->len
= saved_len
;
16158 /* Extend the face of the last glyph in the text area of IT->glyph_row
16159 to the end of the display line. Called from display_line.
16160 If the glyph row is empty, add a space glyph to it so that we
16161 know the face to draw. Set the glyph row flag fill_line_p. */
16164 extend_face_to_end_of_line (it
)
16168 struct frame
*f
= it
->f
;
16170 /* If line is already filled, do nothing. */
16171 if (it
->current_x
>= it
->last_visible_x
)
16174 /* Face extension extends the background and box of IT->face_id
16175 to the end of the line. If the background equals the background
16176 of the frame, we don't have to do anything. */
16177 if (it
->face_before_selective_p
)
16178 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16180 face
= FACE_FROM_ID (f
, it
->face_id
);
16182 if (FRAME_WINDOW_P (f
)
16183 && it
->glyph_row
->displays_text_p
16184 && face
->box
== FACE_NO_BOX
16185 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16189 /* Set the glyph row flag indicating that the face of the last glyph
16190 in the text area has to be drawn to the end of the text area. */
16191 it
->glyph_row
->fill_line_p
= 1;
16193 /* If current character of IT is not ASCII, make sure we have the
16194 ASCII face. This will be automatically undone the next time
16195 get_next_display_element returns a multibyte character. Note
16196 that the character will always be single byte in unibyte
16198 if (!ASCII_CHAR_P (it
->c
))
16200 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16203 if (FRAME_WINDOW_P (f
))
16205 /* If the row is empty, add a space with the current face of IT,
16206 so that we know which face to draw. */
16207 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16209 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16210 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16211 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16216 /* Save some values that must not be changed. */
16217 int saved_x
= it
->current_x
;
16218 struct text_pos saved_pos
;
16219 Lisp_Object saved_object
;
16220 enum display_element_type saved_what
= it
->what
;
16221 int saved_face_id
= it
->face_id
;
16223 saved_object
= it
->object
;
16224 saved_pos
= it
->position
;
16226 it
->what
= IT_CHARACTER
;
16227 bzero (&it
->position
, sizeof it
->position
);
16228 it
->object
= make_number (0);
16231 it
->face_id
= face
->id
;
16233 PRODUCE_GLYPHS (it
);
16235 while (it
->current_x
<= it
->last_visible_x
)
16236 PRODUCE_GLYPHS (it
);
16238 /* Don't count these blanks really. It would let us insert a left
16239 truncation glyph below and make us set the cursor on them, maybe. */
16240 it
->current_x
= saved_x
;
16241 it
->object
= saved_object
;
16242 it
->position
= saved_pos
;
16243 it
->what
= saved_what
;
16244 it
->face_id
= saved_face_id
;
16249 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16250 trailing whitespace. */
16253 trailing_whitespace_p (charpos
)
16256 int bytepos
= CHAR_TO_BYTE (charpos
);
16259 while (bytepos
< ZV_BYTE
16260 && (c
= FETCH_CHAR (bytepos
),
16261 c
== ' ' || c
== '\t'))
16264 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16266 if (bytepos
!= PT_BYTE
)
16273 /* Highlight trailing whitespace, if any, in ROW. */
16276 highlight_trailing_whitespace (f
, row
)
16278 struct glyph_row
*row
;
16280 int used
= row
->used
[TEXT_AREA
];
16284 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16285 struct glyph
*glyph
= start
+ used
- 1;
16287 /* Skip over glyphs inserted to display the cursor at the
16288 end of a line, for extending the face of the last glyph
16289 to the end of the line on terminals, and for truncation
16290 and continuation glyphs. */
16291 while (glyph
>= start
16292 && glyph
->type
== CHAR_GLYPH
16293 && INTEGERP (glyph
->object
))
16296 /* If last glyph is a space or stretch, and it's trailing
16297 whitespace, set the face of all trailing whitespace glyphs in
16298 IT->glyph_row to `trailing-whitespace'. */
16300 && BUFFERP (glyph
->object
)
16301 && (glyph
->type
== STRETCH_GLYPH
16302 || (glyph
->type
== CHAR_GLYPH
16303 && glyph
->u
.ch
== ' '))
16304 && trailing_whitespace_p (glyph
->charpos
))
16306 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16310 while (glyph
>= start
16311 && BUFFERP (glyph
->object
)
16312 && (glyph
->type
== STRETCH_GLYPH
16313 || (glyph
->type
== CHAR_GLYPH
16314 && glyph
->u
.ch
== ' ')))
16315 (glyph
--)->face_id
= face_id
;
16321 /* Value is non-zero if glyph row ROW in window W should be
16322 used to hold the cursor. */
16325 cursor_row_p (w
, row
)
16327 struct glyph_row
*row
;
16329 int cursor_row_p
= 1;
16331 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16333 /* Suppose the row ends on a string.
16334 Unless the row is continued, that means it ends on a newline
16335 in the string. If it's anything other than a display string
16336 (e.g. a before-string from an overlay), we don't want the
16337 cursor there. (This heuristic seems to give the optimal
16338 behavior for the various types of multi-line strings.) */
16339 if (CHARPOS (row
->end
.string_pos
) >= 0)
16341 if (row
->continued_p
)
16345 /* Check for `display' property. */
16346 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16347 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16348 struct glyph
*glyph
;
16351 for (glyph
= end
; glyph
>= beg
; --glyph
)
16352 if (STRINGP (glyph
->object
))
16355 = Fget_char_property (make_number (PT
),
16359 && display_prop_string_p (prop
, glyph
->object
));
16364 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16366 /* If the row ends in middle of a real character,
16367 and the line is continued, we want the cursor here.
16368 That's because MATRIX_ROW_END_CHARPOS would equal
16369 PT if PT is before the character. */
16370 if (!row
->ends_in_ellipsis_p
)
16371 cursor_row_p
= row
->continued_p
;
16373 /* If the row ends in an ellipsis, then
16374 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16375 We want that position to be displayed after the ellipsis. */
16378 /* If the row ends at ZV, display the cursor at the end of that
16379 row instead of at the start of the row below. */
16380 else if (row
->ends_at_zv_p
)
16386 return cursor_row_p
;
16391 /* Push the display property PROP so that it will be rendered at the
16392 current position in IT. Return 1 if PROP was successfully pushed,
16396 push_display_prop (struct it
*it
, Lisp_Object prop
)
16400 if (STRINGP (prop
))
16402 if (SCHARS (prop
) == 0)
16409 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16410 it
->current
.overlay_string_index
= -1;
16411 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16412 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16413 it
->method
= GET_FROM_STRING
;
16414 it
->stop_charpos
= 0;
16416 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16418 it
->method
= GET_FROM_STRETCH
;
16421 #ifdef HAVE_WINDOW_SYSTEM
16422 else if (IMAGEP (prop
))
16424 it
->what
= IT_IMAGE
;
16425 it
->image_id
= lookup_image (it
->f
, prop
);
16426 it
->method
= GET_FROM_IMAGE
;
16428 #endif /* HAVE_WINDOW_SYSTEM */
16431 pop_it (it
); /* bogus display property, give up */
16438 /* Return the character-property PROP at the current position in IT. */
16441 get_it_property (it
, prop
)
16445 Lisp_Object position
;
16447 if (STRINGP (it
->object
))
16448 position
= make_number (IT_STRING_CHARPOS (*it
));
16449 else if (BUFFERP (it
->object
))
16450 position
= make_number (IT_CHARPOS (*it
));
16454 return Fget_char_property (position
, prop
, it
->object
);
16457 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16460 handle_line_prefix (struct it
*it
)
16462 Lisp_Object prefix
;
16463 if (it
->continuation_lines_width
> 0)
16465 prefix
= get_it_property (it
, Qwrap_prefix
);
16467 prefix
= Vwrap_prefix
;
16471 prefix
= get_it_property (it
, Qline_prefix
);
16473 prefix
= Vline_prefix
;
16475 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
16477 /* If the prefix is wider than the window, and we try to wrap
16478 it, it would acquire its own wrap prefix, and so on till the
16479 iterator stack overflows. So, don't wrap the prefix. */
16480 it
->line_wrap
= TRUNCATE
;
16481 it
->avoid_cursor_p
= 1;
16487 /* Construct the glyph row IT->glyph_row in the desired matrix of
16488 IT->w from text at the current position of IT. See dispextern.h
16489 for an overview of struct it. Value is non-zero if
16490 IT->glyph_row displays text, as opposed to a line displaying ZV
16497 struct glyph_row
*row
= it
->glyph_row
;
16498 Lisp_Object overlay_arrow_string
;
16500 int may_wrap
= 0, wrap_x
;
16501 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16502 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16503 int wrap_row_extra_line_spacing
;
16505 /* We always start displaying at hpos zero even if hscrolled. */
16506 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16508 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16509 >= it
->w
->desired_matrix
->nrows
)
16511 it
->w
->nrows_scale_factor
++;
16512 fonts_changed_p
= 1;
16516 /* Is IT->w showing the region? */
16517 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16519 /* Clear the result glyph row and enable it. */
16520 prepare_desired_row (row
);
16522 row
->y
= it
->current_y
;
16523 row
->start
= it
->start
;
16524 row
->continuation_lines_width
= it
->continuation_lines_width
;
16525 row
->displays_text_p
= 1;
16526 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16527 it
->starts_in_middle_of_char_p
= 0;
16529 /* Arrange the overlays nicely for our purposes. Usually, we call
16530 display_line on only one line at a time, in which case this
16531 can't really hurt too much, or we call it on lines which appear
16532 one after another in the buffer, in which case all calls to
16533 recenter_overlay_lists but the first will be pretty cheap. */
16534 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16536 /* Move over display elements that are not visible because we are
16537 hscrolled. This may stop at an x-position < IT->first_visible_x
16538 if the first glyph is partially visible or if we hit a line end. */
16539 if (it
->current_x
< it
->first_visible_x
)
16541 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16542 MOVE_TO_POS
| MOVE_TO_X
);
16546 /* We only do this when not calling `move_it_in_display_line_to'
16547 above, because move_it_in_display_line_to calls
16548 handle_line_prefix itself. */
16549 handle_line_prefix (it
);
16552 /* Get the initial row height. This is either the height of the
16553 text hscrolled, if there is any, or zero. */
16554 row
->ascent
= it
->max_ascent
;
16555 row
->height
= it
->max_ascent
+ it
->max_descent
;
16556 row
->phys_ascent
= it
->max_phys_ascent
;
16557 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16558 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16560 /* Loop generating characters. The loop is left with IT on the next
16561 character to display. */
16564 int n_glyphs_before
, hpos_before
, x_before
;
16566 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16568 /* Retrieve the next thing to display. Value is zero if end of
16570 if (!get_next_display_element (it
))
16572 /* Maybe add a space at the end of this line that is used to
16573 display the cursor there under X. Set the charpos of the
16574 first glyph of blank lines not corresponding to any text
16576 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16577 row
->exact_window_width_line_p
= 1;
16578 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16579 || row
->used
[TEXT_AREA
] == 0)
16581 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16582 row
->displays_text_p
= 0;
16584 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16585 && (!MINI_WINDOW_P (it
->w
)
16586 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16587 row
->indicate_empty_line_p
= 1;
16590 it
->continuation_lines_width
= 0;
16591 row
->ends_at_zv_p
= 1;
16595 /* Now, get the metrics of what we want to display. This also
16596 generates glyphs in `row' (which is IT->glyph_row). */
16597 n_glyphs_before
= row
->used
[TEXT_AREA
];
16600 /* Remember the line height so far in case the next element doesn't
16601 fit on the line. */
16602 if (it
->line_wrap
!= TRUNCATE
)
16604 ascent
= it
->max_ascent
;
16605 descent
= it
->max_descent
;
16606 phys_ascent
= it
->max_phys_ascent
;
16607 phys_descent
= it
->max_phys_descent
;
16609 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16611 if (IT_DISPLAYING_WHITESPACE (it
))
16617 wrap_row_used
= row
->used
[TEXT_AREA
];
16618 wrap_row_ascent
= row
->ascent
;
16619 wrap_row_height
= row
->height
;
16620 wrap_row_phys_ascent
= row
->phys_ascent
;
16621 wrap_row_phys_height
= row
->phys_height
;
16622 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16628 PRODUCE_GLYPHS (it
);
16630 /* If this display element was in marginal areas, continue with
16632 if (it
->area
!= TEXT_AREA
)
16634 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16635 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16636 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16637 row
->phys_height
= max (row
->phys_height
,
16638 it
->max_phys_ascent
+ it
->max_phys_descent
);
16639 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16640 it
->max_extra_line_spacing
);
16641 set_iterator_to_next (it
, 1);
16645 /* Does the display element fit on the line? If we truncate
16646 lines, we should draw past the right edge of the window. If
16647 we don't truncate, we want to stop so that we can display the
16648 continuation glyph before the right margin. If lines are
16649 continued, there are two possible strategies for characters
16650 resulting in more than 1 glyph (e.g. tabs): Display as many
16651 glyphs as possible in this line and leave the rest for the
16652 continuation line, or display the whole element in the next
16653 line. Original redisplay did the former, so we do it also. */
16654 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16655 hpos_before
= it
->hpos
;
16658 if (/* Not a newline. */
16660 /* Glyphs produced fit entirely in the line. */
16661 && it
->current_x
< it
->last_visible_x
)
16663 it
->hpos
+= nglyphs
;
16664 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16665 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16666 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16667 row
->phys_height
= max (row
->phys_height
,
16668 it
->max_phys_ascent
+ it
->max_phys_descent
);
16669 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16670 it
->max_extra_line_spacing
);
16671 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16672 row
->x
= x
- it
->first_visible_x
;
16677 struct glyph
*glyph
;
16679 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16681 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16682 new_x
= x
+ glyph
->pixel_width
;
16684 if (/* Lines are continued. */
16685 it
->line_wrap
!= TRUNCATE
16686 && (/* Glyph doesn't fit on the line. */
16687 new_x
> it
->last_visible_x
16688 /* Or it fits exactly on a window system frame. */
16689 || (new_x
== it
->last_visible_x
16690 && FRAME_WINDOW_P (it
->f
))))
16692 /* End of a continued line. */
16695 || (new_x
== it
->last_visible_x
16696 && FRAME_WINDOW_P (it
->f
)))
16698 /* Current glyph is the only one on the line or
16699 fits exactly on the line. We must continue
16700 the line because we can't draw the cursor
16701 after the glyph. */
16702 row
->continued_p
= 1;
16703 it
->current_x
= new_x
;
16704 it
->continuation_lines_width
+= new_x
;
16706 if (i
== nglyphs
- 1)
16708 /* If line-wrap is on, check if a previous
16709 wrap point was found. */
16710 if (wrap_row_used
> 0
16711 /* Even if there is a previous wrap
16712 point, continue the line here as
16713 usual, if (i) the previous character
16714 was a space or tab AND (ii) the
16715 current character is not. */
16717 || IT_DISPLAYING_WHITESPACE (it
)))
16720 set_iterator_to_next (it
, 1);
16721 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16723 if (!get_next_display_element (it
))
16725 row
->exact_window_width_line_p
= 1;
16726 it
->continuation_lines_width
= 0;
16727 row
->continued_p
= 0;
16728 row
->ends_at_zv_p
= 1;
16730 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16732 row
->continued_p
= 0;
16733 row
->exact_window_width_line_p
= 1;
16738 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16739 && !FRAME_WINDOW_P (it
->f
))
16741 /* A padding glyph that doesn't fit on this line.
16742 This means the whole character doesn't fit
16744 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16746 /* Fill the rest of the row with continuation
16747 glyphs like in 20.x. */
16748 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16749 < row
->glyphs
[1 + TEXT_AREA
])
16750 produce_special_glyphs (it
, IT_CONTINUATION
);
16752 row
->continued_p
= 1;
16753 it
->current_x
= x_before
;
16754 it
->continuation_lines_width
+= x_before
;
16756 /* Restore the height to what it was before the
16757 element not fitting on the line. */
16758 it
->max_ascent
= ascent
;
16759 it
->max_descent
= descent
;
16760 it
->max_phys_ascent
= phys_ascent
;
16761 it
->max_phys_descent
= phys_descent
;
16763 else if (wrap_row_used
> 0)
16767 it
->continuation_lines_width
+= wrap_x
;
16768 row
->used
[TEXT_AREA
] = wrap_row_used
;
16769 row
->ascent
= wrap_row_ascent
;
16770 row
->height
= wrap_row_height
;
16771 row
->phys_ascent
= wrap_row_phys_ascent
;
16772 row
->phys_height
= wrap_row_phys_height
;
16773 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16774 row
->continued_p
= 1;
16775 row
->ends_at_zv_p
= 0;
16776 row
->exact_window_width_line_p
= 0;
16777 it
->continuation_lines_width
+= x
;
16779 /* Make sure that a non-default face is extended
16780 up to the right margin of the window. */
16781 extend_face_to_end_of_line (it
);
16783 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16785 /* A TAB that extends past the right edge of the
16786 window. This produces a single glyph on
16787 window system frames. We leave the glyph in
16788 this row and let it fill the row, but don't
16789 consume the TAB. */
16790 it
->continuation_lines_width
+= it
->last_visible_x
;
16791 row
->ends_in_middle_of_char_p
= 1;
16792 row
->continued_p
= 1;
16793 glyph
->pixel_width
= it
->last_visible_x
- x
;
16794 it
->starts_in_middle_of_char_p
= 1;
16798 /* Something other than a TAB that draws past
16799 the right edge of the window. Restore
16800 positions to values before the element. */
16801 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16803 /* Display continuation glyphs. */
16804 if (!FRAME_WINDOW_P (it
->f
))
16805 produce_special_glyphs (it
, IT_CONTINUATION
);
16806 row
->continued_p
= 1;
16808 it
->current_x
= x_before
;
16809 it
->continuation_lines_width
+= x
;
16810 extend_face_to_end_of_line (it
);
16812 if (nglyphs
> 1 && i
> 0)
16814 row
->ends_in_middle_of_char_p
= 1;
16815 it
->starts_in_middle_of_char_p
= 1;
16818 /* Restore the height to what it was before the
16819 element not fitting on the line. */
16820 it
->max_ascent
= ascent
;
16821 it
->max_descent
= descent
;
16822 it
->max_phys_ascent
= phys_ascent
;
16823 it
->max_phys_descent
= phys_descent
;
16828 else if (new_x
> it
->first_visible_x
)
16830 /* Increment number of glyphs actually displayed. */
16833 if (x
< it
->first_visible_x
)
16834 /* Glyph is partially visible, i.e. row starts at
16835 negative X position. */
16836 row
->x
= x
- it
->first_visible_x
;
16840 /* Glyph is completely off the left margin of the
16841 window. This should not happen because of the
16842 move_it_in_display_line at the start of this
16843 function, unless the text display area of the
16844 window is empty. */
16845 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16849 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16850 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16851 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16852 row
->phys_height
= max (row
->phys_height
,
16853 it
->max_phys_ascent
+ it
->max_phys_descent
);
16854 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16855 it
->max_extra_line_spacing
);
16857 /* End of this display line if row is continued. */
16858 if (row
->continued_p
|| row
->ends_at_zv_p
)
16863 /* Is this a line end? If yes, we're also done, after making
16864 sure that a non-default face is extended up to the right
16865 margin of the window. */
16866 if (ITERATOR_AT_END_OF_LINE_P (it
))
16868 int used_before
= row
->used
[TEXT_AREA
];
16870 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16872 /* Add a space at the end of the line that is used to
16873 display the cursor there. */
16874 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16875 append_space_for_newline (it
, 0);
16877 /* Extend the face to the end of the line. */
16878 extend_face_to_end_of_line (it
);
16880 /* Make sure we have the position. */
16881 if (used_before
== 0)
16882 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16884 /* Consume the line end. This skips over invisible lines. */
16885 set_iterator_to_next (it
, 1);
16886 it
->continuation_lines_width
= 0;
16890 /* Proceed with next display element. Note that this skips
16891 over lines invisible because of selective display. */
16892 set_iterator_to_next (it
, 1);
16894 /* If we truncate lines, we are done when the last displayed
16895 glyphs reach past the right margin of the window. */
16896 if (it
->line_wrap
== TRUNCATE
16897 && (FRAME_WINDOW_P (it
->f
)
16898 ? (it
->current_x
>= it
->last_visible_x
)
16899 : (it
->current_x
> it
->last_visible_x
)))
16901 /* Maybe add truncation glyphs. */
16902 if (!FRAME_WINDOW_P (it
->f
))
16906 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16907 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16910 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16912 row
->used
[TEXT_AREA
] = i
;
16913 produce_special_glyphs (it
, IT_TRUNCATION
);
16916 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16918 /* Don't truncate if we can overflow newline into fringe. */
16919 if (!get_next_display_element (it
))
16921 it
->continuation_lines_width
= 0;
16922 row
->ends_at_zv_p
= 1;
16923 row
->exact_window_width_line_p
= 1;
16926 if (ITERATOR_AT_END_OF_LINE_P (it
))
16928 row
->exact_window_width_line_p
= 1;
16929 goto at_end_of_line
;
16933 row
->truncated_on_right_p
= 1;
16934 it
->continuation_lines_width
= 0;
16935 reseat_at_next_visible_line_start (it
, 0);
16936 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16937 it
->hpos
= hpos_before
;
16938 it
->current_x
= x_before
;
16943 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16944 at the left window margin. */
16945 if (it
->first_visible_x
16946 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16948 if (!FRAME_WINDOW_P (it
->f
))
16949 insert_left_trunc_glyphs (it
);
16950 row
->truncated_on_left_p
= 1;
16953 /* If the start of this line is the overlay arrow-position, then
16954 mark this glyph row as the one containing the overlay arrow.
16955 This is clearly a mess with variable size fonts. It would be
16956 better to let it be displayed like cursors under X. */
16957 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16958 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16959 !NILP (overlay_arrow_string
)))
16961 /* Overlay arrow in window redisplay is a fringe bitmap. */
16962 if (STRINGP (overlay_arrow_string
))
16964 struct glyph_row
*arrow_row
16965 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16966 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16967 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16968 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16969 struct glyph
*p2
, *end
;
16971 /* Copy the arrow glyphs. */
16972 while (glyph
< arrow_end
)
16975 /* Throw away padding glyphs. */
16977 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16978 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16984 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16989 xassert (INTEGERP (overlay_arrow_string
));
16990 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16992 overlay_arrow_seen
= 1;
16995 /* Compute pixel dimensions of this line. */
16996 compute_line_metrics (it
);
16998 /* Remember the position at which this line ends. */
16999 row
->end
= it
->current
;
17001 /* Record whether this row ends inside an ellipsis. */
17002 row
->ends_in_ellipsis_p
17003 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17004 && it
->ellipsis_p
);
17006 /* Save fringe bitmaps in this row. */
17007 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17008 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17009 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17010 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17012 it
->left_user_fringe_bitmap
= 0;
17013 it
->left_user_fringe_face_id
= 0;
17014 it
->right_user_fringe_bitmap
= 0;
17015 it
->right_user_fringe_face_id
= 0;
17017 /* Maybe set the cursor. */
17018 if (it
->w
->cursor
.vpos
< 0
17019 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17020 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17021 && cursor_row_p (it
->w
, row
))
17022 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17024 /* Highlight trailing whitespace. */
17025 if (!NILP (Vshow_trailing_whitespace
))
17026 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17028 /* Prepare for the next line. This line starts horizontally at (X
17029 HPOS) = (0 0). Vertical positions are incremented. As a
17030 convenience for the caller, IT->glyph_row is set to the next
17032 it
->current_x
= it
->hpos
= 0;
17033 it
->current_y
+= row
->height
;
17036 it
->start
= it
->current
;
17037 return row
->displays_text_p
;
17042 /***********************************************************************
17044 ***********************************************************************/
17046 /* Redisplay the menu bar in the frame for window W.
17048 The menu bar of X frames that don't have X toolkit support is
17049 displayed in a special window W->frame->menu_bar_window.
17051 The menu bar of terminal frames is treated specially as far as
17052 glyph matrices are concerned. Menu bar lines are not part of
17053 windows, so the update is done directly on the frame matrix rows
17054 for the menu bar. */
17057 display_menu_bar (w
)
17060 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17065 /* Don't do all this for graphical frames. */
17067 if (FRAME_W32_P (f
))
17070 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17076 if (FRAME_NS_P (f
))
17078 #endif /* HAVE_NS */
17080 #ifdef USE_X_TOOLKIT
17081 xassert (!FRAME_WINDOW_P (f
));
17082 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17083 it
.first_visible_x
= 0;
17084 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17085 #else /* not USE_X_TOOLKIT */
17086 if (FRAME_WINDOW_P (f
))
17088 /* Menu bar lines are displayed in the desired matrix of the
17089 dummy window menu_bar_window. */
17090 struct window
*menu_w
;
17091 xassert (WINDOWP (f
->menu_bar_window
));
17092 menu_w
= XWINDOW (f
->menu_bar_window
);
17093 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17095 it
.first_visible_x
= 0;
17096 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17100 /* This is a TTY frame, i.e. character hpos/vpos are used as
17102 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17104 it
.first_visible_x
= 0;
17105 it
.last_visible_x
= FRAME_COLS (f
);
17107 #endif /* not USE_X_TOOLKIT */
17109 if (! mode_line_inverse_video
)
17110 /* Force the menu-bar to be displayed in the default face. */
17111 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17113 /* Clear all rows of the menu bar. */
17114 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17116 struct glyph_row
*row
= it
.glyph_row
+ i
;
17117 clear_glyph_row (row
);
17118 row
->enabled_p
= 1;
17119 row
->full_width_p
= 1;
17122 /* Display all items of the menu bar. */
17123 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17124 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17126 Lisp_Object string
;
17128 /* Stop at nil string. */
17129 string
= AREF (items
, i
+ 1);
17133 /* Remember where item was displayed. */
17134 ASET (items
, i
+ 3, make_number (it
.hpos
));
17136 /* Display the item, pad with one space. */
17137 if (it
.current_x
< it
.last_visible_x
)
17138 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17139 SCHARS (string
) + 1, 0, 0, -1);
17142 /* Fill out the line with spaces. */
17143 if (it
.current_x
< it
.last_visible_x
)
17144 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17146 /* Compute the total height of the lines. */
17147 compute_line_metrics (&it
);
17152 /***********************************************************************
17154 ***********************************************************************/
17156 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17157 FORCE is non-zero, redisplay mode lines unconditionally.
17158 Otherwise, redisplay only mode lines that are garbaged. Value is
17159 the number of windows whose mode lines were redisplayed. */
17162 redisplay_mode_lines (window
, force
)
17163 Lisp_Object window
;
17168 while (!NILP (window
))
17170 struct window
*w
= XWINDOW (window
);
17172 if (WINDOWP (w
->hchild
))
17173 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17174 else if (WINDOWP (w
->vchild
))
17175 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17177 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17178 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17180 struct text_pos lpoint
;
17181 struct buffer
*old
= current_buffer
;
17183 /* Set the window's buffer for the mode line display. */
17184 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17185 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17187 /* Point refers normally to the selected window. For any
17188 other window, set up appropriate value. */
17189 if (!EQ (window
, selected_window
))
17191 struct text_pos pt
;
17193 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17194 if (CHARPOS (pt
) < BEGV
)
17195 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17196 else if (CHARPOS (pt
) > (ZV
- 1))
17197 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17199 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17202 /* Display mode lines. */
17203 clear_glyph_matrix (w
->desired_matrix
);
17204 if (display_mode_lines (w
))
17207 w
->must_be_updated_p
= 1;
17210 /* Restore old settings. */
17211 set_buffer_internal_1 (old
);
17212 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17222 /* Display the mode and/or header line of window W. Value is the
17223 sum number of mode lines and header lines displayed. */
17226 display_mode_lines (w
)
17229 Lisp_Object old_selected_window
, old_selected_frame
;
17232 old_selected_frame
= selected_frame
;
17233 selected_frame
= w
->frame
;
17234 old_selected_window
= selected_window
;
17235 XSETWINDOW (selected_window
, w
);
17237 /* These will be set while the mode line specs are processed. */
17238 line_number_displayed
= 0;
17239 w
->column_number_displayed
= Qnil
;
17241 if (WINDOW_WANTS_MODELINE_P (w
))
17243 struct window
*sel_w
= XWINDOW (old_selected_window
);
17245 /* Select mode line face based on the real selected window. */
17246 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17247 current_buffer
->mode_line_format
);
17251 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17253 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17254 current_buffer
->header_line_format
);
17258 selected_frame
= old_selected_frame
;
17259 selected_window
= old_selected_window
;
17264 /* Display mode or header line of window W. FACE_ID specifies which
17265 line to display; it is either MODE_LINE_FACE_ID or
17266 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
17267 display. Value is the pixel height of the mode/header line
17271 display_mode_line (w
, face_id
, format
)
17273 enum face_id face_id
;
17274 Lisp_Object format
;
17278 int count
= SPECPDL_INDEX ();
17280 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17281 /* Don't extend on a previously drawn mode-line.
17282 This may happen if called from pos_visible_p. */
17283 it
.glyph_row
->enabled_p
= 0;
17284 prepare_desired_row (it
.glyph_row
);
17286 it
.glyph_row
->mode_line_p
= 1;
17288 if (! mode_line_inverse_video
)
17289 /* Force the mode-line to be displayed in the default face. */
17290 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17292 record_unwind_protect (unwind_format_mode_line
,
17293 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17295 mode_line_target
= MODE_LINE_DISPLAY
;
17297 /* Temporarily make frame's keyboard the current kboard so that
17298 kboard-local variables in the mode_line_format will get the right
17300 push_kboard (FRAME_KBOARD (it
.f
));
17301 record_unwind_save_match_data ();
17302 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17305 unbind_to (count
, Qnil
);
17307 /* Fill up with spaces. */
17308 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17310 compute_line_metrics (&it
);
17311 it
.glyph_row
->full_width_p
= 1;
17312 it
.glyph_row
->continued_p
= 0;
17313 it
.glyph_row
->truncated_on_left_p
= 0;
17314 it
.glyph_row
->truncated_on_right_p
= 0;
17316 /* Make a 3D mode-line have a shadow at its right end. */
17317 face
= FACE_FROM_ID (it
.f
, face_id
);
17318 extend_face_to_end_of_line (&it
);
17319 if (face
->box
!= FACE_NO_BOX
)
17321 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17322 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17323 last
->right_box_line_p
= 1;
17326 return it
.glyph_row
->height
;
17329 /* Move element ELT in LIST to the front of LIST.
17330 Return the updated list. */
17333 move_elt_to_front (elt
, list
)
17334 Lisp_Object elt
, list
;
17336 register Lisp_Object tail
, prev
;
17337 register Lisp_Object tem
;
17341 while (CONSP (tail
))
17347 /* Splice out the link TAIL. */
17349 list
= XCDR (tail
);
17351 Fsetcdr (prev
, XCDR (tail
));
17353 /* Now make it the first. */
17354 Fsetcdr (tail
, list
);
17359 tail
= XCDR (tail
);
17363 /* Not found--return unchanged LIST. */
17367 /* Contribute ELT to the mode line for window IT->w. How it
17368 translates into text depends on its data type.
17370 IT describes the display environment in which we display, as usual.
17372 DEPTH is the depth in recursion. It is used to prevent
17373 infinite recursion here.
17375 FIELD_WIDTH is the number of characters the display of ELT should
17376 occupy in the mode line, and PRECISION is the maximum number of
17377 characters to display from ELT's representation. See
17378 display_string for details.
17380 Returns the hpos of the end of the text generated by ELT.
17382 PROPS is a property list to add to any string we encounter.
17384 If RISKY is nonzero, remove (disregard) any properties in any string
17385 we encounter, and ignore :eval and :propertize.
17387 The global variable `mode_line_target' determines whether the
17388 output is passed to `store_mode_line_noprop',
17389 `store_mode_line_string', or `display_string'. */
17392 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17395 int field_width
, precision
;
17396 Lisp_Object elt
, props
;
17399 int n
= 0, field
, prec
;
17404 elt
= build_string ("*too-deep*");
17408 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17412 /* A string: output it and check for %-constructs within it. */
17416 if (SCHARS (elt
) > 0
17417 && (!NILP (props
) || risky
))
17419 Lisp_Object oprops
, aelt
;
17420 oprops
= Ftext_properties_at (make_number (0), elt
);
17422 /* If the starting string's properties are not what
17423 we want, translate the string. Also, if the string
17424 is risky, do that anyway. */
17426 if (NILP (Fequal (props
, oprops
)) || risky
)
17428 /* If the starting string has properties,
17429 merge the specified ones onto the existing ones. */
17430 if (! NILP (oprops
) && !risky
)
17434 oprops
= Fcopy_sequence (oprops
);
17436 while (CONSP (tem
))
17438 oprops
= Fplist_put (oprops
, XCAR (tem
),
17439 XCAR (XCDR (tem
)));
17440 tem
= XCDR (XCDR (tem
));
17445 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17446 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17448 /* AELT is what we want. Move it to the front
17449 without consing. */
17451 mode_line_proptrans_alist
17452 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17458 /* If AELT has the wrong props, it is useless.
17459 so get rid of it. */
17461 mode_line_proptrans_alist
17462 = Fdelq (aelt
, mode_line_proptrans_alist
);
17464 elt
= Fcopy_sequence (elt
);
17465 Fset_text_properties (make_number (0), Flength (elt
),
17467 /* Add this item to mode_line_proptrans_alist. */
17468 mode_line_proptrans_alist
17469 = Fcons (Fcons (elt
, props
),
17470 mode_line_proptrans_alist
);
17471 /* Truncate mode_line_proptrans_alist
17472 to at most 50 elements. */
17473 tem
= Fnthcdr (make_number (50),
17474 mode_line_proptrans_alist
);
17476 XSETCDR (tem
, Qnil
);
17485 prec
= precision
- n
;
17486 switch (mode_line_target
)
17488 case MODE_LINE_NOPROP
:
17489 case MODE_LINE_TITLE
:
17490 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17492 case MODE_LINE_STRING
:
17493 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17495 case MODE_LINE_DISPLAY
:
17496 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17497 0, prec
, 0, STRING_MULTIBYTE (elt
));
17504 /* Handle the non-literal case. */
17506 while ((precision
<= 0 || n
< precision
)
17507 && SREF (elt
, offset
) != 0
17508 && (mode_line_target
!= MODE_LINE_DISPLAY
17509 || it
->current_x
< it
->last_visible_x
))
17511 int last_offset
= offset
;
17513 /* Advance to end of string or next format specifier. */
17514 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17517 if (offset
- 1 != last_offset
)
17519 int nchars
, nbytes
;
17521 /* Output to end of string or up to '%'. Field width
17522 is length of string. Don't output more than
17523 PRECISION allows us. */
17526 prec
= c_string_width (SDATA (elt
) + last_offset
,
17527 offset
- last_offset
, precision
- n
,
17530 switch (mode_line_target
)
17532 case MODE_LINE_NOPROP
:
17533 case MODE_LINE_TITLE
:
17534 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17536 case MODE_LINE_STRING
:
17538 int bytepos
= last_offset
;
17539 int charpos
= string_byte_to_char (elt
, bytepos
);
17540 int endpos
= (precision
<= 0
17541 ? string_byte_to_char (elt
, offset
)
17542 : charpos
+ nchars
);
17544 n
+= store_mode_line_string (NULL
,
17545 Fsubstring (elt
, make_number (charpos
),
17546 make_number (endpos
)),
17550 case MODE_LINE_DISPLAY
:
17552 int bytepos
= last_offset
;
17553 int charpos
= string_byte_to_char (elt
, bytepos
);
17555 if (precision
<= 0)
17556 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17557 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17559 STRING_MULTIBYTE (elt
));
17564 else /* c == '%' */
17566 int percent_position
= offset
;
17568 /* Get the specified minimum width. Zero means
17571 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17572 field
= field
* 10 + c
- '0';
17574 /* Don't pad beyond the total padding allowed. */
17575 if (field_width
- n
> 0 && field
> field_width
- n
)
17576 field
= field_width
- n
;
17578 /* Note that either PRECISION <= 0 or N < PRECISION. */
17579 prec
= precision
- n
;
17582 n
+= display_mode_element (it
, depth
, field
, prec
,
17583 Vglobal_mode_string
, props
,
17588 int bytepos
, charpos
;
17589 unsigned char *spec
;
17590 Lisp_Object string
;
17592 bytepos
= percent_position
;
17593 charpos
= (STRING_MULTIBYTE (elt
)
17594 ? string_byte_to_char (elt
, bytepos
)
17596 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
17597 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
17599 switch (mode_line_target
)
17601 case MODE_LINE_NOPROP
:
17602 case MODE_LINE_TITLE
:
17603 n
+= store_mode_line_noprop (spec
, field
, prec
);
17605 case MODE_LINE_STRING
:
17607 int len
= strlen (spec
);
17608 Lisp_Object tem
= make_string (spec
, len
);
17609 props
= Ftext_properties_at (make_number (charpos
), elt
);
17610 /* Should only keep face property in props */
17611 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17614 case MODE_LINE_DISPLAY
:
17616 int nglyphs_before
, nwritten
;
17618 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17619 nwritten
= display_string (spec
, string
, elt
,
17624 /* Assign to the glyphs written above the
17625 string where the `%x' came from, position
17629 struct glyph
*glyph
17630 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17634 for (i
= 0; i
< nwritten
; ++i
)
17636 glyph
[i
].object
= elt
;
17637 glyph
[i
].charpos
= charpos
;
17654 /* A symbol: process the value of the symbol recursively
17655 as if it appeared here directly. Avoid error if symbol void.
17656 Special case: if value of symbol is a string, output the string
17659 register Lisp_Object tem
;
17661 /* If the variable is not marked as risky to set
17662 then its contents are risky to use. */
17663 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17666 tem
= Fboundp (elt
);
17669 tem
= Fsymbol_value (elt
);
17670 /* If value is a string, output that string literally:
17671 don't check for % within it. */
17675 if (!EQ (tem
, elt
))
17677 /* Give up right away for nil or t. */
17687 register Lisp_Object car
, tem
;
17689 /* A cons cell: five distinct cases.
17690 If first element is :eval or :propertize, do something special.
17691 If first element is a string or a cons, process all the elements
17692 and effectively concatenate them.
17693 If first element is a negative number, truncate displaying cdr to
17694 at most that many characters. If positive, pad (with spaces)
17695 to at least that many characters.
17696 If first element is a symbol, process the cadr or caddr recursively
17697 according to whether the symbol's value is non-nil or nil. */
17699 if (EQ (car
, QCeval
))
17701 /* An element of the form (:eval FORM) means evaluate FORM
17702 and use the result as mode line elements. */
17707 if (CONSP (XCDR (elt
)))
17710 spec
= safe_eval (XCAR (XCDR (elt
)));
17711 n
+= display_mode_element (it
, depth
, field_width
- n
,
17712 precision
- n
, spec
, props
,
17716 else if (EQ (car
, QCpropertize
))
17718 /* An element of the form (:propertize ELT PROPS...)
17719 means display ELT but applying properties PROPS. */
17724 if (CONSP (XCDR (elt
)))
17725 n
+= display_mode_element (it
, depth
, field_width
- n
,
17726 precision
- n
, XCAR (XCDR (elt
)),
17727 XCDR (XCDR (elt
)), risky
);
17729 else if (SYMBOLP (car
))
17731 tem
= Fboundp (car
);
17735 /* elt is now the cdr, and we know it is a cons cell.
17736 Use its car if CAR has a non-nil value. */
17739 tem
= Fsymbol_value (car
);
17746 /* Symbol's value is nil (or symbol is unbound)
17747 Get the cddr of the original list
17748 and if possible find the caddr and use that. */
17752 else if (!CONSP (elt
))
17757 else if (INTEGERP (car
))
17759 register int lim
= XINT (car
);
17763 /* Negative int means reduce maximum width. */
17764 if (precision
<= 0)
17767 precision
= min (precision
, -lim
);
17771 /* Padding specified. Don't let it be more than
17772 current maximum. */
17774 lim
= min (precision
, lim
);
17776 /* If that's more padding than already wanted, queue it.
17777 But don't reduce padding already specified even if
17778 that is beyond the current truncation point. */
17779 field_width
= max (lim
, field_width
);
17783 else if (STRINGP (car
) || CONSP (car
))
17785 Lisp_Object halftail
= elt
;
17789 && (precision
<= 0 || n
< precision
))
17791 n
+= display_mode_element (it
, depth
,
17792 /* Do padding only after the last
17793 element in the list. */
17794 (! CONSP (XCDR (elt
))
17797 precision
- n
, XCAR (elt
),
17801 if ((len
& 1) == 0)
17802 halftail
= XCDR (halftail
);
17803 /* Check for cycle. */
17804 if (EQ (halftail
, elt
))
17813 elt
= build_string ("*invalid*");
17817 /* Pad to FIELD_WIDTH. */
17818 if (field_width
> 0 && n
< field_width
)
17820 switch (mode_line_target
)
17822 case MODE_LINE_NOPROP
:
17823 case MODE_LINE_TITLE
:
17824 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17826 case MODE_LINE_STRING
:
17827 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17829 case MODE_LINE_DISPLAY
:
17830 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17839 /* Store a mode-line string element in mode_line_string_list.
17841 If STRING is non-null, display that C string. Otherwise, the Lisp
17842 string LISP_STRING is displayed.
17844 FIELD_WIDTH is the minimum number of output glyphs to produce.
17845 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17846 with spaces. FIELD_WIDTH <= 0 means don't pad.
17848 PRECISION is the maximum number of characters to output from
17849 STRING. PRECISION <= 0 means don't truncate the string.
17851 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17852 properties to the string.
17854 PROPS are the properties to add to the string.
17855 The mode_line_string_face face property is always added to the string.
17859 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17861 Lisp_Object lisp_string
;
17870 if (string
!= NULL
)
17872 len
= strlen (string
);
17873 if (precision
> 0 && len
> precision
)
17875 lisp_string
= make_string (string
, len
);
17877 props
= mode_line_string_face_prop
;
17878 else if (!NILP (mode_line_string_face
))
17880 Lisp_Object face
= Fplist_get (props
, Qface
);
17881 props
= Fcopy_sequence (props
);
17883 face
= mode_line_string_face
;
17885 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17886 props
= Fplist_put (props
, Qface
, face
);
17888 Fadd_text_properties (make_number (0), make_number (len
),
17889 props
, lisp_string
);
17893 len
= XFASTINT (Flength (lisp_string
));
17894 if (precision
> 0 && len
> precision
)
17897 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17900 if (!NILP (mode_line_string_face
))
17904 props
= Ftext_properties_at (make_number (0), lisp_string
);
17905 face
= Fplist_get (props
, Qface
);
17907 face
= mode_line_string_face
;
17909 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17910 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17912 lisp_string
= Fcopy_sequence (lisp_string
);
17915 Fadd_text_properties (make_number (0), make_number (len
),
17916 props
, lisp_string
);
17921 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17925 if (field_width
> len
)
17927 field_width
-= len
;
17928 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17930 Fadd_text_properties (make_number (0), make_number (field_width
),
17931 props
, lisp_string
);
17932 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17940 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17942 doc
: /* Format a string out of a mode line format specification.
17943 First arg FORMAT specifies the mode line format (see `mode-line-format'
17944 for details) to use.
17946 Optional second arg FACE specifies the face property to put
17947 on all characters for which no face is specified.
17948 The value t means whatever face the window's mode line currently uses
17949 \(either `mode-line' or `mode-line-inactive', depending).
17950 A value of nil means the default is no face property.
17951 If FACE is an integer, the value string has no text properties.
17953 Optional third and fourth args WINDOW and BUFFER specify the window
17954 and buffer to use as the context for the formatting (defaults
17955 are the selected window and the window's buffer). */)
17956 (format
, face
, window
, buffer
)
17957 Lisp_Object format
, face
, window
, buffer
;
17962 struct buffer
*old_buffer
= NULL
;
17964 int no_props
= INTEGERP (face
);
17965 int count
= SPECPDL_INDEX ();
17967 int string_start
= 0;
17970 window
= selected_window
;
17971 CHECK_WINDOW (window
);
17972 w
= XWINDOW (window
);
17975 buffer
= w
->buffer
;
17976 CHECK_BUFFER (buffer
);
17978 /* Make formatting the modeline a non-op when noninteractive, otherwise
17979 there will be problems later caused by a partially initialized frame. */
17980 if (NILP (format
) || noninteractive
)
17981 return empty_unibyte_string
;
17989 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17990 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17994 face_id
= DEFAULT_FACE_ID
;
17996 if (XBUFFER (buffer
) != current_buffer
)
17997 old_buffer
= current_buffer
;
17999 /* Save things including mode_line_proptrans_alist,
18000 and set that to nil so that we don't alter the outer value. */
18001 record_unwind_protect (unwind_format_mode_line
,
18002 format_mode_line_unwind_data
18003 (old_buffer
, selected_window
, 1));
18004 mode_line_proptrans_alist
= Qnil
;
18006 Fselect_window (window
, Qt
);
18008 set_buffer_internal_1 (XBUFFER (buffer
));
18010 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18014 mode_line_target
= MODE_LINE_NOPROP
;
18015 mode_line_string_face_prop
= Qnil
;
18016 mode_line_string_list
= Qnil
;
18017 string_start
= MODE_LINE_NOPROP_LEN (0);
18021 mode_line_target
= MODE_LINE_STRING
;
18022 mode_line_string_list
= Qnil
;
18023 mode_line_string_face
= face
;
18024 mode_line_string_face_prop
18025 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18028 push_kboard (FRAME_KBOARD (it
.f
));
18029 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18034 len
= MODE_LINE_NOPROP_LEN (string_start
);
18035 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18039 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18040 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18041 empty_unibyte_string
);
18044 unbind_to (count
, Qnil
);
18048 /* Write a null-terminated, right justified decimal representation of
18049 the positive integer D to BUF using a minimal field width WIDTH. */
18052 pint2str (buf
, width
, d
)
18053 register char *buf
;
18054 register int width
;
18057 register char *p
= buf
;
18065 *p
++ = d
% 10 + '0';
18070 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18081 /* Write a null-terminated, right justified decimal and "human
18082 readable" representation of the nonnegative integer D to BUF using
18083 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18085 static const char power_letter
[] =
18099 pint2hrstr (buf
, width
, d
)
18104 /* We aim to represent the nonnegative integer D as
18105 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18108 /* -1 means: do not use TENTHS. */
18112 /* Length of QUOTIENT.TENTHS as a string. */
18118 if (1000 <= quotient
)
18120 /* Scale to the appropriate EXPONENT. */
18123 remainder
= quotient
% 1000;
18127 while (1000 <= quotient
);
18129 /* Round to nearest and decide whether to use TENTHS or not. */
18132 tenths
= remainder
/ 100;
18133 if (50 <= remainder
% 100)
18140 if (quotient
== 10)
18148 if (500 <= remainder
)
18150 if (quotient
< 999)
18161 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18162 if (tenths
== -1 && quotient
<= 99)
18169 p
= psuffix
= buf
+ max (width
, length
);
18171 /* Print EXPONENT. */
18173 *psuffix
++ = power_letter
[exponent
];
18176 /* Print TENTHS. */
18179 *--p
= '0' + tenths
;
18183 /* Print QUOTIENT. */
18186 int digit
= quotient
% 10;
18187 *--p
= '0' + digit
;
18189 while ((quotient
/= 10) != 0);
18191 /* Print leading spaces. */
18196 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18197 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18198 type of CODING_SYSTEM. Return updated pointer into BUF. */
18200 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18203 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18204 Lisp_Object coding_system
;
18205 register char *buf
;
18209 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18210 const unsigned char *eol_str
;
18212 /* The EOL conversion we are using. */
18213 Lisp_Object eoltype
;
18215 val
= CODING_SYSTEM_SPEC (coding_system
);
18218 if (!VECTORP (val
)) /* Not yet decided. */
18223 eoltype
= eol_mnemonic_undecided
;
18224 /* Don't mention EOL conversion if it isn't decided. */
18229 Lisp_Object eolvalue
;
18231 attrs
= AREF (val
, 0);
18232 eolvalue
= AREF (val
, 2);
18235 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18239 /* The EOL conversion that is normal on this system. */
18241 if (NILP (eolvalue
)) /* Not yet decided. */
18242 eoltype
= eol_mnemonic_undecided
;
18243 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18244 eoltype
= eol_mnemonic_undecided
;
18245 else /* eolvalue is Qunix, Qdos, or Qmac. */
18246 eoltype
= (EQ (eolvalue
, Qunix
)
18247 ? eol_mnemonic_unix
18248 : (EQ (eolvalue
, Qdos
) == 1
18249 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18255 /* Mention the EOL conversion if it is not the usual one. */
18256 if (STRINGP (eoltype
))
18258 eol_str
= SDATA (eoltype
);
18259 eol_str_len
= SBYTES (eoltype
);
18261 else if (CHARACTERP (eoltype
))
18263 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18264 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18269 eol_str
= invalid_eol_type
;
18270 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18272 bcopy (eol_str
, buf
, eol_str_len
);
18273 buf
+= eol_str_len
;
18279 /* Return a string for the output of a mode line %-spec for window W,
18280 generated by character C. PRECISION >= 0 means don't return a
18281 string longer than that value. FIELD_WIDTH > 0 means pad the
18282 string returned with spaces to that value. Return a Lisp string in
18283 *STRING if the resulting string is taken from that Lisp string.
18285 Note we operate on the current buffer for most purposes,
18286 the exception being w->base_line_pos. */
18288 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18291 decode_mode_spec (w
, c
, field_width
, precision
, string
)
18294 int field_width
, precision
;
18295 Lisp_Object
*string
;
18298 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18299 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18300 struct buffer
*b
= current_buffer
;
18308 if (!NILP (b
->read_only
))
18310 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18315 /* This differs from %* only for a modified read-only buffer. */
18316 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18318 if (!NILP (b
->read_only
))
18323 /* This differs from %* in ignoring read-only-ness. */
18324 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18336 if (command_loop_level
> 5)
18338 p
= decode_mode_spec_buf
;
18339 for (i
= 0; i
< command_loop_level
; i
++)
18342 return decode_mode_spec_buf
;
18350 if (command_loop_level
> 5)
18352 p
= decode_mode_spec_buf
;
18353 for (i
= 0; i
< command_loop_level
; i
++)
18356 return decode_mode_spec_buf
;
18363 /* Let lots_of_dashes be a string of infinite length. */
18364 if (mode_line_target
== MODE_LINE_NOPROP
||
18365 mode_line_target
== MODE_LINE_STRING
)
18367 if (field_width
<= 0
18368 || field_width
> sizeof (lots_of_dashes
))
18370 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18371 decode_mode_spec_buf
[i
] = '-';
18372 decode_mode_spec_buf
[i
] = '\0';
18373 return decode_mode_spec_buf
;
18376 return lots_of_dashes
;
18384 /* %c and %l are ignored in `frame-title-format'.
18385 (In redisplay_internal, the frame title is drawn _before_ the
18386 windows are updated, so the stuff which depends on actual
18387 window contents (such as %l) may fail to render properly, or
18388 even crash emacs.) */
18389 if (mode_line_target
== MODE_LINE_TITLE
)
18393 int col
= (int) current_column (); /* iftc */
18394 w
->column_number_displayed
= make_number (col
);
18395 pint2str (decode_mode_spec_buf
, field_width
, col
);
18396 return decode_mode_spec_buf
;
18400 #ifndef SYSTEM_MALLOC
18402 if (NILP (Vmemory_full
))
18405 return "!MEM FULL! ";
18412 /* %F displays the frame name. */
18413 if (!NILP (f
->title
))
18414 return (char *) SDATA (f
->title
);
18415 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18416 return (char *) SDATA (f
->name
);
18425 int size
= ZV
- BEGV
;
18426 pint2str (decode_mode_spec_buf
, field_width
, size
);
18427 return decode_mode_spec_buf
;
18432 int size
= ZV
- BEGV
;
18433 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18434 return decode_mode_spec_buf
;
18439 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18440 int topline
, nlines
, junk
, height
;
18442 /* %c and %l are ignored in `frame-title-format'. */
18443 if (mode_line_target
== MODE_LINE_TITLE
)
18446 startpos
= XMARKER (w
->start
)->charpos
;
18447 startpos_byte
= marker_byte_position (w
->start
);
18448 height
= WINDOW_TOTAL_LINES (w
);
18450 /* If we decided that this buffer isn't suitable for line numbers,
18451 don't forget that too fast. */
18452 if (EQ (w
->base_line_pos
, w
->buffer
))
18454 /* But do forget it, if the window shows a different buffer now. */
18455 else if (BUFFERP (w
->base_line_pos
))
18456 w
->base_line_pos
= Qnil
;
18458 /* If the buffer is very big, don't waste time. */
18459 if (INTEGERP (Vline_number_display_limit
)
18460 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18462 w
->base_line_pos
= Qnil
;
18463 w
->base_line_number
= Qnil
;
18467 if (INTEGERP (w
->base_line_number
)
18468 && INTEGERP (w
->base_line_pos
)
18469 && XFASTINT (w
->base_line_pos
) <= startpos
)
18471 line
= XFASTINT (w
->base_line_number
);
18472 linepos
= XFASTINT (w
->base_line_pos
);
18473 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18478 linepos
= BUF_BEGV (b
);
18479 linepos_byte
= BUF_BEGV_BYTE (b
);
18482 /* Count lines from base line to window start position. */
18483 nlines
= display_count_lines (linepos
, linepos_byte
,
18487 topline
= nlines
+ line
;
18489 /* Determine a new base line, if the old one is too close
18490 or too far away, or if we did not have one.
18491 "Too close" means it's plausible a scroll-down would
18492 go back past it. */
18493 if (startpos
== BUF_BEGV (b
))
18495 w
->base_line_number
= make_number (topline
);
18496 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18498 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18499 || linepos
== BUF_BEGV (b
))
18501 int limit
= BUF_BEGV (b
);
18502 int limit_byte
= BUF_BEGV_BYTE (b
);
18504 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18506 if (startpos
- distance
> limit
)
18508 limit
= startpos
- distance
;
18509 limit_byte
= CHAR_TO_BYTE (limit
);
18512 nlines
= display_count_lines (startpos
, startpos_byte
,
18514 - (height
* 2 + 30),
18516 /* If we couldn't find the lines we wanted within
18517 line_number_display_limit_width chars per line,
18518 give up on line numbers for this window. */
18519 if (position
== limit_byte
&& limit
== startpos
- distance
)
18521 w
->base_line_pos
= w
->buffer
;
18522 w
->base_line_number
= Qnil
;
18526 w
->base_line_number
= make_number (topline
- nlines
);
18527 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18530 /* Now count lines from the start pos to point. */
18531 nlines
= display_count_lines (startpos
, startpos_byte
,
18532 PT_BYTE
, PT
, &junk
);
18534 /* Record that we did display the line number. */
18535 line_number_displayed
= 1;
18537 /* Make the string to show. */
18538 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18539 return decode_mode_spec_buf
;
18542 char* p
= decode_mode_spec_buf
;
18543 int pad
= field_width
- 2;
18549 return decode_mode_spec_buf
;
18555 obj
= b
->mode_name
;
18559 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18565 int pos
= marker_position (w
->start
);
18566 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18568 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18570 if (pos
<= BUF_BEGV (b
))
18575 else if (pos
<= BUF_BEGV (b
))
18579 if (total
> 1000000)
18580 /* Do it differently for a large value, to avoid overflow. */
18581 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18583 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18584 /* We can't normally display a 3-digit number,
18585 so get us a 2-digit number that is close. */
18588 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18589 return decode_mode_spec_buf
;
18593 /* Display percentage of size above the bottom of the screen. */
18596 int toppos
= marker_position (w
->start
);
18597 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18598 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18600 if (botpos
>= BUF_ZV (b
))
18602 if (toppos
<= BUF_BEGV (b
))
18609 if (total
> 1000000)
18610 /* Do it differently for a large value, to avoid overflow. */
18611 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18613 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18614 /* We can't normally display a 3-digit number,
18615 so get us a 2-digit number that is close. */
18618 if (toppos
<= BUF_BEGV (b
))
18619 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18621 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18622 return decode_mode_spec_buf
;
18627 /* status of process */
18628 obj
= Fget_buffer_process (Fcurrent_buffer ());
18630 return "no process";
18631 #ifdef subprocesses
18632 obj
= Fsymbol_name (Fprocess_status (obj
));
18638 int count
= inhibit_garbage_collection ();
18639 Lisp_Object val
= call1 (intern ("file-remote-p"),
18640 current_buffer
->directory
);
18641 unbind_to (count
, Qnil
);
18649 case 't': /* indicate TEXT or BINARY */
18650 #ifdef MODE_LINE_BINARY_TEXT
18651 return MODE_LINE_BINARY_TEXT (b
);
18657 /* coding-system (not including end-of-line format) */
18659 /* coding-system (including end-of-line type) */
18661 int eol_flag
= (c
== 'Z');
18662 char *p
= decode_mode_spec_buf
;
18664 if (! FRAME_WINDOW_P (f
))
18666 /* No need to mention EOL here--the terminal never needs
18667 to do EOL conversion. */
18668 p
= decode_mode_spec_coding (CODING_ID_NAME
18669 (FRAME_KEYBOARD_CODING (f
)->id
),
18671 p
= decode_mode_spec_coding (CODING_ID_NAME
18672 (FRAME_TERMINAL_CODING (f
)->id
),
18675 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18678 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18679 #ifdef subprocesses
18680 obj
= Fget_buffer_process (Fcurrent_buffer ());
18681 if (PROCESSP (obj
))
18683 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18685 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18688 #endif /* subprocesses */
18691 return decode_mode_spec_buf
;
18698 return (char *) SDATA (obj
);
18705 /* Count up to COUNT lines starting from START / START_BYTE.
18706 But don't go beyond LIMIT_BYTE.
18707 Return the number of lines thus found (always nonnegative).
18709 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18712 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18713 int start
, start_byte
, limit_byte
, count
;
18716 register unsigned char *cursor
;
18717 unsigned char *base
;
18719 register int ceiling
;
18720 register unsigned char *ceiling_addr
;
18721 int orig_count
= count
;
18723 /* If we are not in selective display mode,
18724 check only for newlines. */
18725 int selective_display
= (!NILP (current_buffer
->selective_display
)
18726 && !INTEGERP (current_buffer
->selective_display
));
18730 while (start_byte
< limit_byte
)
18732 ceiling
= BUFFER_CEILING_OF (start_byte
);
18733 ceiling
= min (limit_byte
- 1, ceiling
);
18734 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18735 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18738 if (selective_display
)
18739 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18742 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18745 if (cursor
!= ceiling_addr
)
18749 start_byte
+= cursor
- base
+ 1;
18750 *byte_pos_ptr
= start_byte
;
18754 if (++cursor
== ceiling_addr
)
18760 start_byte
+= cursor
- base
;
18765 while (start_byte
> limit_byte
)
18767 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18768 ceiling
= max (limit_byte
, ceiling
);
18769 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18770 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18773 if (selective_display
)
18774 while (--cursor
!= ceiling_addr
18775 && *cursor
!= '\n' && *cursor
!= 015)
18778 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18781 if (cursor
!= ceiling_addr
)
18785 start_byte
+= cursor
- base
+ 1;
18786 *byte_pos_ptr
= start_byte
;
18787 /* When scanning backwards, we should
18788 not count the newline posterior to which we stop. */
18789 return - orig_count
- 1;
18795 /* Here we add 1 to compensate for the last decrement
18796 of CURSOR, which took it past the valid range. */
18797 start_byte
+= cursor
- base
+ 1;
18801 *byte_pos_ptr
= limit_byte
;
18804 return - orig_count
+ count
;
18805 return orig_count
- count
;
18811 /***********************************************************************
18813 ***********************************************************************/
18815 /* Display a NUL-terminated string, starting with index START.
18817 If STRING is non-null, display that C string. Otherwise, the Lisp
18818 string LISP_STRING is displayed. There's a case that STRING is
18819 non-null and LISP_STRING is not nil. It means STRING is a string
18820 data of LISP_STRING. In that case, we display LISP_STRING while
18821 ignoring its text properties.
18823 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18824 FACE_STRING. Display STRING or LISP_STRING with the face at
18825 FACE_STRING_POS in FACE_STRING:
18827 Display the string in the environment given by IT, but use the
18828 standard display table, temporarily.
18830 FIELD_WIDTH is the minimum number of output glyphs to produce.
18831 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18832 with spaces. If STRING has more characters, more than FIELD_WIDTH
18833 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18835 PRECISION is the maximum number of characters to output from
18836 STRING. PRECISION < 0 means don't truncate the string.
18838 This is roughly equivalent to printf format specifiers:
18840 FIELD_WIDTH PRECISION PRINTF
18841 ----------------------------------------
18847 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18848 display them, and < 0 means obey the current buffer's value of
18849 enable_multibyte_characters.
18851 Value is the number of columns displayed. */
18854 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18855 start
, it
, field_width
, precision
, max_x
, multibyte
)
18856 unsigned char *string
;
18857 Lisp_Object lisp_string
;
18858 Lisp_Object face_string
;
18859 EMACS_INT face_string_pos
;
18862 int field_width
, precision
, max_x
;
18865 int hpos_at_start
= it
->hpos
;
18866 int saved_face_id
= it
->face_id
;
18867 struct glyph_row
*row
= it
->glyph_row
;
18869 /* Initialize the iterator IT for iteration over STRING beginning
18870 with index START. */
18871 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
18872 precision
, field_width
, multibyte
);
18873 if (string
&& STRINGP (lisp_string
))
18874 /* LISP_STRING is the one returned by decode_mode_spec. We should
18875 ignore its text properties. */
18876 it
->stop_charpos
= -1;
18878 /* If displaying STRING, set up the face of the iterator
18879 from LISP_STRING, if that's given. */
18880 if (STRINGP (face_string
))
18886 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18887 0, it
->region_beg_charpos
,
18888 it
->region_end_charpos
,
18889 &endptr
, it
->base_face_id
, 0);
18890 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18891 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18894 /* Set max_x to the maximum allowed X position. Don't let it go
18895 beyond the right edge of the window. */
18897 max_x
= it
->last_visible_x
;
18899 max_x
= min (max_x
, it
->last_visible_x
);
18901 /* Skip over display elements that are not visible. because IT->w is
18903 if (it
->current_x
< it
->first_visible_x
)
18904 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18905 MOVE_TO_POS
| MOVE_TO_X
);
18907 row
->ascent
= it
->max_ascent
;
18908 row
->height
= it
->max_ascent
+ it
->max_descent
;
18909 row
->phys_ascent
= it
->max_phys_ascent
;
18910 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18911 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18913 /* This condition is for the case that we are called with current_x
18914 past last_visible_x. */
18915 while (it
->current_x
< max_x
)
18917 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18919 /* Get the next display element. */
18920 if (!get_next_display_element (it
))
18923 /* Produce glyphs. */
18924 x_before
= it
->current_x
;
18925 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18926 PRODUCE_GLYPHS (it
);
18928 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18931 while (i
< nglyphs
)
18933 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18935 if (it
->line_wrap
!= TRUNCATE
18936 && x
+ glyph
->pixel_width
> max_x
)
18938 /* End of continued line or max_x reached. */
18939 if (CHAR_GLYPH_PADDING_P (*glyph
))
18941 /* A wide character is unbreakable. */
18942 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18943 it
->current_x
= x_before
;
18947 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18952 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18954 /* Glyph is at least partially visible. */
18956 if (x
< it
->first_visible_x
)
18957 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18961 /* Glyph is off the left margin of the display area.
18962 Should not happen. */
18966 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18967 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18968 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18969 row
->phys_height
= max (row
->phys_height
,
18970 it
->max_phys_ascent
+ it
->max_phys_descent
);
18971 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18972 it
->max_extra_line_spacing
);
18973 x
+= glyph
->pixel_width
;
18977 /* Stop if max_x reached. */
18981 /* Stop at line ends. */
18982 if (ITERATOR_AT_END_OF_LINE_P (it
))
18984 it
->continuation_lines_width
= 0;
18988 set_iterator_to_next (it
, 1);
18990 /* Stop if truncating at the right edge. */
18991 if (it
->line_wrap
== TRUNCATE
18992 && it
->current_x
>= it
->last_visible_x
)
18994 /* Add truncation mark, but don't do it if the line is
18995 truncated at a padding space. */
18996 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18998 if (!FRAME_WINDOW_P (it
->f
))
19002 if (it
->current_x
> it
->last_visible_x
)
19004 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19005 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19007 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19009 row
->used
[TEXT_AREA
] = i
;
19010 produce_special_glyphs (it
, IT_TRUNCATION
);
19013 produce_special_glyphs (it
, IT_TRUNCATION
);
19015 it
->glyph_row
->truncated_on_right_p
= 1;
19021 /* Maybe insert a truncation at the left. */
19022 if (it
->first_visible_x
19023 && IT_CHARPOS (*it
) > 0)
19025 if (!FRAME_WINDOW_P (it
->f
))
19026 insert_left_trunc_glyphs (it
);
19027 it
->glyph_row
->truncated_on_left_p
= 1;
19030 it
->face_id
= saved_face_id
;
19032 /* Value is number of columns displayed. */
19033 return it
->hpos
- hpos_at_start
;
19038 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19039 appears as an element of LIST or as the car of an element of LIST.
19040 If PROPVAL is a list, compare each element against LIST in that
19041 way, and return 1/2 if any element of PROPVAL is found in LIST.
19042 Otherwise return 0. This function cannot quit.
19043 The return value is 2 if the text is invisible but with an ellipsis
19044 and 1 if it's invisible and without an ellipsis. */
19047 invisible_p (propval
, list
)
19048 register Lisp_Object propval
;
19051 register Lisp_Object tail
, proptail
;
19053 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19055 register Lisp_Object tem
;
19057 if (EQ (propval
, tem
))
19059 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19060 return NILP (XCDR (tem
)) ? 1 : 2;
19063 if (CONSP (propval
))
19065 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19067 Lisp_Object propelt
;
19068 propelt
= XCAR (proptail
);
19069 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19071 register Lisp_Object tem
;
19073 if (EQ (propelt
, tem
))
19075 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19076 return NILP (XCDR (tem
)) ? 1 : 2;
19084 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19085 doc
: /* Non-nil if the property makes the text invisible.
19086 POS-OR-PROP can be a marker or number, in which case it is taken to be
19087 a position in the current buffer and the value of the `invisible' property
19088 is checked; or it can be some other value, which is then presumed to be the
19089 value of the `invisible' property of the text of interest.
19090 The non-nil value returned can be t for truly invisible text or something
19091 else if the text is replaced by an ellipsis. */)
19093 Lisp_Object pos_or_prop
;
19096 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19097 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19099 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19100 return (invis
== 0 ? Qnil
19102 : make_number (invis
));
19105 /* Calculate a width or height in pixels from a specification using
19106 the following elements:
19109 NUM - a (fractional) multiple of the default font width/height
19110 (NUM) - specifies exactly NUM pixels
19111 UNIT - a fixed number of pixels, see below.
19112 ELEMENT - size of a display element in pixels, see below.
19113 (NUM . SPEC) - equals NUM * SPEC
19114 (+ SPEC SPEC ...) - add pixel values
19115 (- SPEC SPEC ...) - subtract pixel values
19116 (- SPEC) - negate pixel value
19119 INT or FLOAT - a number constant
19120 SYMBOL - use symbol's (buffer local) variable binding.
19123 in - pixels per inch *)
19124 mm - pixels per 1/1000 meter *)
19125 cm - pixels per 1/100 meter *)
19126 width - width of current font in pixels.
19127 height - height of current font in pixels.
19129 *) using the ratio(s) defined in display-pixels-per-inch.
19133 left-fringe - left fringe width in pixels
19134 right-fringe - right fringe width in pixels
19136 left-margin - left margin width in pixels
19137 right-margin - right margin width in pixels
19139 scroll-bar - scroll-bar area width in pixels
19143 Pixels corresponding to 5 inches:
19146 Total width of non-text areas on left side of window (if scroll-bar is on left):
19147 '(space :width (+ left-fringe left-margin scroll-bar))
19149 Align to first text column (in header line):
19150 '(space :align-to 0)
19152 Align to middle of text area minus half the width of variable `my-image'
19153 containing a loaded image:
19154 '(space :align-to (0.5 . (- text my-image)))
19156 Width of left margin minus width of 1 character in the default font:
19157 '(space :width (- left-margin 1))
19159 Width of left margin minus width of 2 characters in the current font:
19160 '(space :width (- left-margin (2 . width)))
19162 Center 1 character over left-margin (in header line):
19163 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19165 Different ways to express width of left fringe plus left margin minus one pixel:
19166 '(space :width (- (+ left-fringe left-margin) (1)))
19167 '(space :width (+ left-fringe left-margin (- (1))))
19168 '(space :width (+ left-fringe left-margin (-1)))
19172 #define NUMVAL(X) \
19173 ((INTEGERP (X) || FLOATP (X)) \
19178 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19183 int width_p
, *align_to
;
19187 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19188 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19191 return OK_PIXELS (0);
19193 xassert (FRAME_LIVE_P (it
->f
));
19195 if (SYMBOLP (prop
))
19197 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19199 char *unit
= SDATA (SYMBOL_NAME (prop
));
19201 if (unit
[0] == 'i' && unit
[1] == 'n')
19203 else if (unit
[0] == 'm' && unit
[1] == 'm')
19205 else if (unit
[0] == 'c' && unit
[1] == 'm')
19212 #ifdef HAVE_WINDOW_SYSTEM
19213 if (FRAME_WINDOW_P (it
->f
)
19215 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19216 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19218 return OK_PIXELS (ppi
/ pixels
);
19221 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19222 || (CONSP (Vdisplay_pixels_per_inch
)
19224 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19225 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19227 return OK_PIXELS (ppi
/ pixels
);
19233 #ifdef HAVE_WINDOW_SYSTEM
19234 if (EQ (prop
, Qheight
))
19235 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19236 if (EQ (prop
, Qwidth
))
19237 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19239 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19240 return OK_PIXELS (1);
19243 if (EQ (prop
, Qtext
))
19244 return OK_PIXELS (width_p
19245 ? window_box_width (it
->w
, TEXT_AREA
)
19246 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19248 if (align_to
&& *align_to
< 0)
19251 if (EQ (prop
, Qleft
))
19252 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19253 if (EQ (prop
, Qright
))
19254 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19255 if (EQ (prop
, Qcenter
))
19256 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19257 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19258 if (EQ (prop
, Qleft_fringe
))
19259 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19260 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19261 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19262 if (EQ (prop
, Qright_fringe
))
19263 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19264 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19265 : window_box_right_offset (it
->w
, TEXT_AREA
));
19266 if (EQ (prop
, Qleft_margin
))
19267 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19268 if (EQ (prop
, Qright_margin
))
19269 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19270 if (EQ (prop
, Qscroll_bar
))
19271 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19273 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19274 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19275 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19280 if (EQ (prop
, Qleft_fringe
))
19281 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19282 if (EQ (prop
, Qright_fringe
))
19283 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19284 if (EQ (prop
, Qleft_margin
))
19285 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19286 if (EQ (prop
, Qright_margin
))
19287 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19288 if (EQ (prop
, Qscroll_bar
))
19289 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19292 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19295 if (INTEGERP (prop
) || FLOATP (prop
))
19297 int base_unit
= (width_p
19298 ? FRAME_COLUMN_WIDTH (it
->f
)
19299 : FRAME_LINE_HEIGHT (it
->f
));
19300 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19305 Lisp_Object car
= XCAR (prop
);
19306 Lisp_Object cdr
= XCDR (prop
);
19310 #ifdef HAVE_WINDOW_SYSTEM
19311 if (FRAME_WINDOW_P (it
->f
)
19312 && valid_image_p (prop
))
19314 int id
= lookup_image (it
->f
, prop
);
19315 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19317 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19320 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19326 while (CONSP (cdr
))
19328 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19329 font
, width_p
, align_to
))
19332 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19337 if (EQ (car
, Qminus
))
19339 return OK_PIXELS (pixels
);
19342 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19345 if (INTEGERP (car
) || FLOATP (car
))
19348 pixels
= XFLOATINT (car
);
19350 return OK_PIXELS (pixels
);
19351 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19352 font
, width_p
, align_to
))
19353 return OK_PIXELS (pixels
* fact
);
19364 /***********************************************************************
19366 ***********************************************************************/
19368 #ifdef HAVE_WINDOW_SYSTEM
19373 dump_glyph_string (s
)
19374 struct glyph_string
*s
;
19376 fprintf (stderr
, "glyph string\n");
19377 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19378 s
->x
, s
->y
, s
->width
, s
->height
);
19379 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19380 fprintf (stderr
, " hl = %d\n", s
->hl
);
19381 fprintf (stderr
, " left overhang = %d, right = %d\n",
19382 s
->left_overhang
, s
->right_overhang
);
19383 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19384 fprintf (stderr
, " extends to end of line = %d\n",
19385 s
->extends_to_end_of_line_p
);
19386 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19387 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19390 #endif /* GLYPH_DEBUG */
19392 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19393 of XChar2b structures for S; it can't be allocated in
19394 init_glyph_string because it must be allocated via `alloca'. W
19395 is the window on which S is drawn. ROW and AREA are the glyph row
19396 and area within the row from which S is constructed. START is the
19397 index of the first glyph structure covered by S. HL is a
19398 face-override for drawing S. */
19401 #define OPTIONAL_HDC(hdc) hdc,
19402 #define DECLARE_HDC(hdc) HDC hdc;
19403 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19404 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19407 #ifndef OPTIONAL_HDC
19408 #define OPTIONAL_HDC(hdc)
19409 #define DECLARE_HDC(hdc)
19410 #define ALLOCATE_HDC(hdc, f)
19411 #define RELEASE_HDC(hdc, f)
19415 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19416 struct glyph_string
*s
;
19420 struct glyph_row
*row
;
19421 enum glyph_row_area area
;
19423 enum draw_glyphs_face hl
;
19425 bzero (s
, sizeof *s
);
19427 s
->f
= XFRAME (w
->frame
);
19431 s
->display
= FRAME_X_DISPLAY (s
->f
);
19432 s
->window
= FRAME_X_WINDOW (s
->f
);
19433 s
->char2b
= char2b
;
19437 s
->first_glyph
= row
->glyphs
[area
] + start
;
19438 s
->height
= row
->height
;
19439 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19440 s
->ybase
= s
->y
+ row
->ascent
;
19444 /* Append the list of glyph strings with head H and tail T to the list
19445 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19448 append_glyph_string_lists (head
, tail
, h
, t
)
19449 struct glyph_string
**head
, **tail
;
19450 struct glyph_string
*h
, *t
;
19464 /* Prepend the list of glyph strings with head H and tail T to the
19465 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19469 prepend_glyph_string_lists (head
, tail
, h
, t
)
19470 struct glyph_string
**head
, **tail
;
19471 struct glyph_string
*h
, *t
;
19485 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19486 Set *HEAD and *TAIL to the resulting list. */
19489 append_glyph_string (head
, tail
, s
)
19490 struct glyph_string
**head
, **tail
;
19491 struct glyph_string
*s
;
19493 s
->next
= s
->prev
= NULL
;
19494 append_glyph_string_lists (head
, tail
, s
, s
);
19498 /* Get face and two-byte form of character C in face FACE_ID on frame
19499 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19500 means we want to display multibyte text. DISPLAY_P non-zero means
19501 make sure that X resources for the face returned are allocated.
19502 Value is a pointer to a realized face that is ready for display if
19503 DISPLAY_P is non-zero. */
19505 static INLINE
struct face
*
19506 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19510 int multibyte_p
, display_p
;
19512 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19516 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19518 if (code
!= FONT_INVALID_CODE
)
19519 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19521 STORE_XCHAR2B (char2b
, 0, 0);
19524 /* Make sure X resources of the face are allocated. */
19525 #ifdef HAVE_X_WINDOWS
19529 xassert (face
!= NULL
);
19530 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19537 /* Get face and two-byte form of character glyph GLYPH on frame F.
19538 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19539 a pointer to a realized face that is ready for display. */
19541 static INLINE
struct face
*
19542 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19544 struct glyph
*glyph
;
19550 xassert (glyph
->type
== CHAR_GLYPH
);
19551 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19558 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19560 if (code
!= FONT_INVALID_CODE
)
19561 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19563 STORE_XCHAR2B (char2b
, 0, 0);
19566 /* Make sure X resources of the face are allocated. */
19567 xassert (face
!= NULL
);
19568 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19573 /* Fill glyph string S with composition components specified by S->cmp.
19575 BASE_FACE is the base face of the composition.
19576 S->cmp_from is the index of the first component for S.
19578 OVERLAPS non-zero means S should draw the foreground only, and use
19579 its physical height for clipping. See also draw_glyphs.
19581 Value is the index of a component not in S. */
19584 fill_composite_glyph_string (s
, base_face
, overlaps
)
19585 struct glyph_string
*s
;
19586 struct face
*base_face
;
19590 /* For all glyphs of this composition, starting at the offset
19591 S->cmp_from, until we reach the end of the definition or encounter a
19592 glyph that requires the different face, add it to S. */
19597 s
->for_overlaps
= overlaps
;
19600 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
19602 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19606 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19609 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19610 s
->char2b
+ i
, 1, 1);
19616 s
->font
= s
->face
->font
;
19618 else if (s
->face
!= face
)
19626 /* All glyph strings for the same composition has the same width,
19627 i.e. the width set for the first component of the composition. */
19628 s
->width
= s
->first_glyph
->pixel_width
;
19630 /* If the specified font could not be loaded, use the frame's
19631 default font, but record the fact that we couldn't load it in
19632 the glyph string so that we can draw rectangles for the
19633 characters of the glyph string. */
19634 if (s
->font
== NULL
)
19636 s
->font_not_found_p
= 1;
19637 s
->font
= FRAME_FONT (s
->f
);
19640 /* Adjust base line for subscript/superscript text. */
19641 s
->ybase
+= s
->first_glyph
->voffset
;
19643 /* This glyph string must always be drawn with 16-bit functions. */
19650 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
19651 struct glyph_string
*s
;
19653 int start
, end
, overlaps
;
19655 struct glyph
*glyph
, *last
;
19656 Lisp_Object lgstring
;
19659 s
->for_overlaps
= overlaps
;
19660 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19661 last
= s
->row
->glyphs
[s
->area
] + end
;
19662 s
->cmp_id
= glyph
->u
.cmp
.id
;
19663 s
->cmp_from
= glyph
->u
.cmp
.from
;
19664 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
19665 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19666 lgstring
= composition_gstring_from_id (s
->cmp_id
);
19667 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
19669 while (glyph
< last
19670 && glyph
->u
.cmp
.automatic
19671 && glyph
->u
.cmp
.id
== s
->cmp_id
19672 && s
->cmp_to
== glyph
->u
.cmp
.from
)
19673 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
19675 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
19677 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
19678 unsigned code
= LGLYPH_CODE (lglyph
);
19680 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
19682 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
19683 return glyph
- s
->row
->glyphs
[s
->area
];
19687 /* Fill glyph string S from a sequence of character glyphs.
19689 FACE_ID is the face id of the string. START is the index of the
19690 first glyph to consider, END is the index of the last + 1.
19691 OVERLAPS non-zero means S should draw the foreground only, and use
19692 its physical height for clipping. See also draw_glyphs.
19694 Value is the index of the first glyph not in S. */
19697 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19698 struct glyph_string
*s
;
19700 int start
, end
, overlaps
;
19702 struct glyph
*glyph
, *last
;
19704 int glyph_not_available_p
;
19706 xassert (s
->f
== XFRAME (s
->w
->frame
));
19707 xassert (s
->nchars
== 0);
19708 xassert (start
>= 0 && end
> start
);
19710 s
->for_overlaps
= overlaps
;
19711 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19712 last
= s
->row
->glyphs
[s
->area
] + end
;
19713 voffset
= glyph
->voffset
;
19714 s
->padding_p
= glyph
->padding_p
;
19715 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19717 while (glyph
< last
19718 && glyph
->type
== CHAR_GLYPH
19719 && glyph
->voffset
== voffset
19720 /* Same face id implies same font, nowadays. */
19721 && glyph
->face_id
== face_id
19722 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19726 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19727 s
->char2b
+ s
->nchars
,
19729 s
->two_byte_p
= two_byte_p
;
19731 xassert (s
->nchars
<= end
- start
);
19732 s
->width
+= glyph
->pixel_width
;
19733 if (glyph
++->padding_p
!= s
->padding_p
)
19737 s
->font
= s
->face
->font
;
19739 /* If the specified font could not be loaded, use the frame's font,
19740 but record the fact that we couldn't load it in
19741 S->font_not_found_p so that we can draw rectangles for the
19742 characters of the glyph string. */
19743 if (s
->font
== NULL
|| glyph_not_available_p
)
19745 s
->font_not_found_p
= 1;
19746 s
->font
= FRAME_FONT (s
->f
);
19749 /* Adjust base line for subscript/superscript text. */
19750 s
->ybase
+= voffset
;
19752 xassert (s
->face
&& s
->face
->gc
);
19753 return glyph
- s
->row
->glyphs
[s
->area
];
19757 /* Fill glyph string S from image glyph S->first_glyph. */
19760 fill_image_glyph_string (s
)
19761 struct glyph_string
*s
;
19763 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19764 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19766 s
->slice
= s
->first_glyph
->slice
;
19767 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19768 s
->font
= s
->face
->font
;
19769 s
->width
= s
->first_glyph
->pixel_width
;
19771 /* Adjust base line for subscript/superscript text. */
19772 s
->ybase
+= s
->first_glyph
->voffset
;
19776 /* Fill glyph string S from a sequence of stretch glyphs.
19778 ROW is the glyph row in which the glyphs are found, AREA is the
19779 area within the row. START is the index of the first glyph to
19780 consider, END is the index of the last + 1.
19782 Value is the index of the first glyph not in S. */
19785 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19786 struct glyph_string
*s
;
19787 struct glyph_row
*row
;
19788 enum glyph_row_area area
;
19791 struct glyph
*glyph
, *last
;
19792 int voffset
, face_id
;
19794 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19796 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19797 last
= s
->row
->glyphs
[s
->area
] + end
;
19798 face_id
= glyph
->face_id
;
19799 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19800 s
->font
= s
->face
->font
;
19801 s
->width
= glyph
->pixel_width
;
19803 voffset
= glyph
->voffset
;
19807 && glyph
->type
== STRETCH_GLYPH
19808 && glyph
->voffset
== voffset
19809 && glyph
->face_id
== face_id
);
19811 s
->width
+= glyph
->pixel_width
;
19813 /* Adjust base line for subscript/superscript text. */
19814 s
->ybase
+= voffset
;
19816 /* The case that face->gc == 0 is handled when drawing the glyph
19817 string by calling PREPARE_FACE_FOR_DISPLAY. */
19819 return glyph
- s
->row
->glyphs
[s
->area
];
19822 static struct font_metrics
*
19823 get_per_char_metric (f
, font
, char2b
)
19828 static struct font_metrics metrics
;
19829 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19831 if (! font
|| code
== FONT_INVALID_CODE
)
19833 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19838 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19839 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19840 assumed to be zero. */
19843 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19844 struct glyph
*glyph
;
19848 *left
= *right
= 0;
19850 if (glyph
->type
== CHAR_GLYPH
)
19854 struct font_metrics
*pcm
;
19856 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19857 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19859 if (pcm
->rbearing
> pcm
->width
)
19860 *right
= pcm
->rbearing
- pcm
->width
;
19861 if (pcm
->lbearing
< 0)
19862 *left
= -pcm
->lbearing
;
19865 else if (glyph
->type
== COMPOSITE_GLYPH
)
19867 if (! glyph
->u
.cmp
.automatic
)
19869 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
19871 if (cmp
->rbearing
> cmp
->pixel_width
)
19872 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19873 if (cmp
->lbearing
< 0)
19874 *left
= - cmp
->lbearing
;
19878 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
19879 struct font_metrics metrics
;
19881 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
19882 glyph
->u
.cmp
.to
+ 1, &metrics
);
19883 if (metrics
.rbearing
> metrics
.width
)
19884 *right
= metrics
.rbearing
- metrics
.width
;
19885 if (metrics
.lbearing
< 0)
19886 *left
= - metrics
.lbearing
;
19892 /* Return the index of the first glyph preceding glyph string S that
19893 is overwritten by S because of S's left overhang. Value is -1
19894 if no glyphs are overwritten. */
19897 left_overwritten (s
)
19898 struct glyph_string
*s
;
19902 if (s
->left_overhang
)
19905 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19906 int first
= s
->first_glyph
- glyphs
;
19908 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19909 x
-= glyphs
[i
].pixel_width
;
19920 /* Return the index of the first glyph preceding glyph string S that
19921 is overwriting S because of its right overhang. Value is -1 if no
19922 glyph in front of S overwrites S. */
19925 left_overwriting (s
)
19926 struct glyph_string
*s
;
19929 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19930 int first
= s
->first_glyph
- glyphs
;
19934 for (i
= first
- 1; i
>= 0; --i
)
19937 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19940 x
-= glyphs
[i
].pixel_width
;
19947 /* Return the index of the last glyph following glyph string S that is
19948 overwritten by S because of S's right overhang. Value is -1 if
19949 no such glyph is found. */
19952 right_overwritten (s
)
19953 struct glyph_string
*s
;
19957 if (s
->right_overhang
)
19960 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19961 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19962 int end
= s
->row
->used
[s
->area
];
19964 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19965 x
+= glyphs
[i
].pixel_width
;
19974 /* Return the index of the last glyph following glyph string S that
19975 overwrites S because of its left overhang. Value is negative
19976 if no such glyph is found. */
19979 right_overwriting (s
)
19980 struct glyph_string
*s
;
19983 int end
= s
->row
->used
[s
->area
];
19984 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19985 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19989 for (i
= first
; i
< end
; ++i
)
19992 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19995 x
+= glyphs
[i
].pixel_width
;
20002 /* Set background width of glyph string S. START is the index of the
20003 first glyph following S. LAST_X is the right-most x-position + 1
20004 in the drawing area. */
20007 set_glyph_string_background_width (s
, start
, last_x
)
20008 struct glyph_string
*s
;
20012 /* If the face of this glyph string has to be drawn to the end of
20013 the drawing area, set S->extends_to_end_of_line_p. */
20015 if (start
== s
->row
->used
[s
->area
]
20016 && s
->area
== TEXT_AREA
20017 && ((s
->row
->fill_line_p
20018 && (s
->hl
== DRAW_NORMAL_TEXT
20019 || s
->hl
== DRAW_IMAGE_RAISED
20020 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20021 || s
->hl
== DRAW_MOUSE_FACE
))
20022 s
->extends_to_end_of_line_p
= 1;
20024 /* If S extends its face to the end of the line, set its
20025 background_width to the distance to the right edge of the drawing
20027 if (s
->extends_to_end_of_line_p
)
20028 s
->background_width
= last_x
- s
->x
+ 1;
20030 s
->background_width
= s
->width
;
20034 /* Compute overhangs and x-positions for glyph string S and its
20035 predecessors, or successors. X is the starting x-position for S.
20036 BACKWARD_P non-zero means process predecessors. */
20039 compute_overhangs_and_x (s
, x
, backward_p
)
20040 struct glyph_string
*s
;
20048 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20049 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20059 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20060 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20070 /* The following macros are only called from draw_glyphs below.
20071 They reference the following parameters of that function directly:
20072 `w', `row', `area', and `overlap_p'
20073 as well as the following local variables:
20074 `s', `f', and `hdc' (in W32) */
20077 /* On W32, silently add local `hdc' variable to argument list of
20078 init_glyph_string. */
20079 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20080 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20082 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20083 init_glyph_string (s, char2b, w, row, area, start, hl)
20086 /* Add a glyph string for a stretch glyph to the list of strings
20087 between HEAD and TAIL. START is the index of the stretch glyph in
20088 row area AREA of glyph row ROW. END is the index of the last glyph
20089 in that glyph row area. X is the current output position assigned
20090 to the new glyph string constructed. HL overrides that face of the
20091 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20092 is the right-most x-position of the drawing area. */
20094 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20095 and below -- keep them on one line. */
20096 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20099 s = (struct glyph_string *) alloca (sizeof *s); \
20100 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20101 START = fill_stretch_glyph_string (s, row, area, START, END); \
20102 append_glyph_string (&HEAD, &TAIL, s); \
20108 /* Add a glyph string for an image glyph to the list of strings
20109 between HEAD and TAIL. START is the index of the image glyph in
20110 row area AREA of glyph row ROW. END is the index of the last glyph
20111 in that glyph row area. X is the current output position assigned
20112 to the new glyph string constructed. HL overrides that face of the
20113 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20114 is the right-most x-position of the drawing area. */
20116 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20119 s = (struct glyph_string *) alloca (sizeof *s); \
20120 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20121 fill_image_glyph_string (s); \
20122 append_glyph_string (&HEAD, &TAIL, s); \
20129 /* Add a glyph string for a sequence of character glyphs to the list
20130 of strings between HEAD and TAIL. START is the index of the first
20131 glyph in row area AREA of glyph row ROW that is part of the new
20132 glyph string. END is the index of the last glyph in that glyph row
20133 area. X is the current output position assigned to the new glyph
20134 string constructed. HL overrides that face of the glyph; e.g. it
20135 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20136 right-most x-position of the drawing area. */
20138 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20144 face_id = (row)->glyphs[area][START].face_id; \
20146 s = (struct glyph_string *) alloca (sizeof *s); \
20147 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20148 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20149 append_glyph_string (&HEAD, &TAIL, s); \
20151 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20156 /* Add a glyph string for a composite sequence to the list of strings
20157 between HEAD and TAIL. START is the index of the first glyph in
20158 row area AREA of glyph row ROW that is part of the new glyph
20159 string. END is the index of the last glyph in that glyph row area.
20160 X is the current output position assigned to the new glyph string
20161 constructed. HL overrides that face of the glyph; e.g. it is
20162 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20163 x-position of the drawing area. */
20165 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20167 int face_id = (row)->glyphs[area][START].face_id; \
20168 struct face *base_face = FACE_FROM_ID (f, face_id); \
20169 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20170 struct composition *cmp = composition_table[cmp_id]; \
20172 struct glyph_string *first_s; \
20175 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20177 /* Make glyph_strings for each glyph sequence that is drawable by \
20178 the same face, and append them to HEAD/TAIL. */ \
20179 for (n = 0; n < cmp->glyph_len;) \
20181 s = (struct glyph_string *) alloca (sizeof *s); \
20182 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20183 append_glyph_string (&(HEAD), &(TAIL), s); \
20189 n = fill_composite_glyph_string (s, base_face, overlaps); \
20197 /* Add a glyph string for a glyph-string sequence to the list of strings
20198 between HEAD and TAIL. */
20200 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20204 Lisp_Object gstring; \
20206 face_id = (row)->glyphs[area][START].face_id; \
20207 gstring = (composition_gstring_from_id \
20208 ((row)->glyphs[area][START].u.cmp.id)); \
20209 s = (struct glyph_string *) alloca (sizeof *s); \
20210 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20211 * LGSTRING_GLYPH_LEN (gstring)); \
20212 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20213 append_glyph_string (&(HEAD), &(TAIL), s); \
20215 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20219 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20220 of AREA of glyph row ROW on window W between indices START and END.
20221 HL overrides the face for drawing glyph strings, e.g. it is
20222 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20223 x-positions of the drawing area.
20225 This is an ugly monster macro construct because we must use alloca
20226 to allocate glyph strings (because draw_glyphs can be called
20227 asynchronously). */
20229 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20232 HEAD = TAIL = NULL; \
20233 while (START < END) \
20235 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20236 switch (first_glyph->type) \
20239 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20243 case COMPOSITE_GLYPH: \
20244 if (first_glyph->u.cmp.automatic) \
20245 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20248 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20252 case STRETCH_GLYPH: \
20253 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20257 case IMAGE_GLYPH: \
20258 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20268 set_glyph_string_background_width (s, START, LAST_X); \
20275 /* Draw glyphs between START and END in AREA of ROW on window W,
20276 starting at x-position X. X is relative to AREA in W. HL is a
20277 face-override with the following meaning:
20279 DRAW_NORMAL_TEXT draw normally
20280 DRAW_CURSOR draw in cursor face
20281 DRAW_MOUSE_FACE draw in mouse face.
20282 DRAW_INVERSE_VIDEO draw in mode line face
20283 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20284 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20286 If OVERLAPS is non-zero, draw only the foreground of characters and
20287 clip to the physical height of ROW. Non-zero value also defines
20288 the overlapping part to be drawn:
20290 OVERLAPS_PRED overlap with preceding rows
20291 OVERLAPS_SUCC overlap with succeeding rows
20292 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20293 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20295 Value is the x-position reached, relative to AREA of W. */
20298 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20301 struct glyph_row
*row
;
20302 enum glyph_row_area area
;
20303 EMACS_INT start
, end
;
20304 enum draw_glyphs_face hl
;
20307 struct glyph_string
*head
, *tail
;
20308 struct glyph_string
*s
;
20309 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20310 int i
, j
, x_reached
, last_x
, area_left
= 0;
20311 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20314 ALLOCATE_HDC (hdc
, f
);
20316 /* Let's rather be paranoid than getting a SEGV. */
20317 end
= min (end
, row
->used
[area
]);
20318 start
= max (0, start
);
20319 start
= min (end
, start
);
20321 /* Translate X to frame coordinates. Set last_x to the right
20322 end of the drawing area. */
20323 if (row
->full_width_p
)
20325 /* X is relative to the left edge of W, without scroll bars
20327 area_left
= WINDOW_LEFT_EDGE_X (w
);
20328 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20332 area_left
= window_box_left (w
, area
);
20333 last_x
= area_left
+ window_box_width (w
, area
);
20337 /* Build a doubly-linked list of glyph_string structures between
20338 head and tail from what we have to draw. Note that the macro
20339 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20340 the reason we use a separate variable `i'. */
20342 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20344 x_reached
= tail
->x
+ tail
->background_width
;
20348 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20349 the row, redraw some glyphs in front or following the glyph
20350 strings built above. */
20351 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20353 struct glyph_string
*h
, *t
;
20354 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20355 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20358 /* If mouse highlighting is on, we may need to draw adjacent
20359 glyphs using mouse-face highlighting. */
20360 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20362 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20364 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20365 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20367 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20369 check_mouse_face
= 1;
20370 mouse_beg_col
= (row
== mouse_beg_row
)
20371 ? dpyinfo
->mouse_face_beg_col
: 0;
20372 mouse_end_col
= (row
== mouse_end_row
)
20373 ? dpyinfo
->mouse_face_end_col
20374 : row
->used
[TEXT_AREA
];
20378 /* Compute overhangs for all glyph strings. */
20379 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20380 for (s
= head
; s
; s
= s
->next
)
20381 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20383 /* Prepend glyph strings for glyphs in front of the first glyph
20384 string that are overwritten because of the first glyph
20385 string's left overhang. The background of all strings
20386 prepended must be drawn because the first glyph string
20388 i
= left_overwritten (head
);
20391 enum draw_glyphs_face overlap_hl
;
20393 /* If this row contains mouse highlighting, attempt to draw
20394 the overlapped glyphs with the correct highlight. This
20395 code fails if the overlap encompasses more than one glyph
20396 and mouse-highlight spans only some of these glyphs.
20397 However, making it work perfectly involves a lot more
20398 code, and I don't know if the pathological case occurs in
20399 practice, so we'll stick to this for now. --- cyd */
20400 if (check_mouse_face
20401 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20402 overlap_hl
= DRAW_MOUSE_FACE
;
20404 overlap_hl
= DRAW_NORMAL_TEXT
;
20407 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20408 overlap_hl
, dummy_x
, last_x
);
20410 compute_overhangs_and_x (t
, head
->x
, 1);
20411 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20415 /* Prepend glyph strings for glyphs in front of the first glyph
20416 string that overwrite that glyph string because of their
20417 right overhang. For these strings, only the foreground must
20418 be drawn, because it draws over the glyph string at `head'.
20419 The background must not be drawn because this would overwrite
20420 right overhangs of preceding glyphs for which no glyph
20422 i
= left_overwriting (head
);
20425 enum draw_glyphs_face overlap_hl
;
20427 if (check_mouse_face
20428 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20429 overlap_hl
= DRAW_MOUSE_FACE
;
20431 overlap_hl
= DRAW_NORMAL_TEXT
;
20434 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20435 overlap_hl
, dummy_x
, last_x
);
20436 for (s
= h
; s
; s
= s
->next
)
20437 s
->background_filled_p
= 1;
20438 compute_overhangs_and_x (t
, head
->x
, 1);
20439 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20442 /* Append glyphs strings for glyphs following the last glyph
20443 string tail that are overwritten by tail. The background of
20444 these strings has to be drawn because tail's foreground draws
20446 i
= right_overwritten (tail
);
20449 enum draw_glyphs_face overlap_hl
;
20451 if (check_mouse_face
20452 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20453 overlap_hl
= DRAW_MOUSE_FACE
;
20455 overlap_hl
= DRAW_NORMAL_TEXT
;
20457 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20458 overlap_hl
, x
, last_x
);
20459 /* Because BUILD_GLYPH_STRINGS updates the first argument,
20460 we don't have `end = i;' here. */
20461 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20462 append_glyph_string_lists (&head
, &tail
, h
, t
);
20466 /* Append glyph strings for glyphs following the last glyph
20467 string tail that overwrite tail. The foreground of such
20468 glyphs has to be drawn because it writes into the background
20469 of tail. The background must not be drawn because it could
20470 paint over the foreground of following glyphs. */
20471 i
= right_overwriting (tail
);
20474 enum draw_glyphs_face overlap_hl
;
20475 if (check_mouse_face
20476 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20477 overlap_hl
= DRAW_MOUSE_FACE
;
20479 overlap_hl
= DRAW_NORMAL_TEXT
;
20482 i
++; /* We must include the Ith glyph. */
20483 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20484 overlap_hl
, x
, last_x
);
20485 for (s
= h
; s
; s
= s
->next
)
20486 s
->background_filled_p
= 1;
20487 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20488 append_glyph_string_lists (&head
, &tail
, h
, t
);
20490 if (clip_head
|| clip_tail
)
20491 for (s
= head
; s
; s
= s
->next
)
20493 s
->clip_head
= clip_head
;
20494 s
->clip_tail
= clip_tail
;
20498 /* Draw all strings. */
20499 for (s
= head
; s
; s
= s
->next
)
20500 FRAME_RIF (f
)->draw_glyph_string (s
);
20503 /* When focus a sole frame and move horizontally, this sets on_p to 0
20504 causing a failure to erase prev cursor position. */
20505 if (area
== TEXT_AREA
20506 && !row
->full_width_p
20507 /* When drawing overlapping rows, only the glyph strings'
20508 foreground is drawn, which doesn't erase a cursor
20512 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20513 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20514 : (tail
? tail
->x
+ tail
->background_width
: x
));
20518 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20519 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20523 /* Value is the x-position up to which drawn, relative to AREA of W.
20524 This doesn't include parts drawn because of overhangs. */
20525 if (row
->full_width_p
)
20526 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20528 x_reached
-= area_left
;
20530 RELEASE_HDC (hdc
, f
);
20535 /* Expand row matrix if too narrow. Don't expand if area
20538 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20540 if (!fonts_changed_p \
20541 && (it->glyph_row->glyphs[area] \
20542 < it->glyph_row->glyphs[area + 1])) \
20544 it->w->ncols_scale_factor++; \
20545 fonts_changed_p = 1; \
20549 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20550 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20556 struct glyph
*glyph
;
20557 enum glyph_row_area area
= it
->area
;
20559 xassert (it
->glyph_row
);
20560 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20562 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20563 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20565 glyph
->charpos
= CHARPOS (it
->position
);
20566 glyph
->object
= it
->object
;
20567 if (it
->pixel_width
> 0)
20569 glyph
->pixel_width
= it
->pixel_width
;
20570 glyph
->padding_p
= 0;
20574 /* Assure at least 1-pixel width. Otherwise, cursor can't
20575 be displayed correctly. */
20576 glyph
->pixel_width
= 1;
20577 glyph
->padding_p
= 1;
20579 glyph
->ascent
= it
->ascent
;
20580 glyph
->descent
= it
->descent
;
20581 glyph
->voffset
= it
->voffset
;
20582 glyph
->type
= CHAR_GLYPH
;
20583 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20584 glyph
->multibyte_p
= it
->multibyte_p
;
20585 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20586 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20587 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20588 || it
->phys_descent
> it
->descent
);
20589 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20590 glyph
->face_id
= it
->face_id
;
20591 glyph
->u
.ch
= it
->char_to_display
;
20592 glyph
->slice
= null_glyph_slice
;
20593 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20594 ++it
->glyph_row
->used
[area
];
20597 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20600 /* Store one glyph for the composition IT->cmp_it.id in
20601 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
20605 append_composite_glyph (it
)
20608 struct glyph
*glyph
;
20609 enum glyph_row_area area
= it
->area
;
20611 xassert (it
->glyph_row
);
20613 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20614 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20616 glyph
->charpos
= CHARPOS (it
->position
);
20617 glyph
->object
= it
->object
;
20618 glyph
->pixel_width
= it
->pixel_width
;
20619 glyph
->ascent
= it
->ascent
;
20620 glyph
->descent
= it
->descent
;
20621 glyph
->voffset
= it
->voffset
;
20622 glyph
->type
= COMPOSITE_GLYPH
;
20623 if (it
->cmp_it
.ch
< 0)
20625 glyph
->u
.cmp
.automatic
= 0;
20626 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20630 glyph
->u
.cmp
.automatic
= 1;
20631 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20632 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
20633 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
20635 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20636 glyph
->multibyte_p
= it
->multibyte_p
;
20637 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20638 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20639 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20640 || it
->phys_descent
> it
->descent
);
20641 glyph
->padding_p
= 0;
20642 glyph
->glyph_not_available_p
= 0;
20643 glyph
->face_id
= it
->face_id
;
20644 glyph
->slice
= null_glyph_slice
;
20645 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20646 ++it
->glyph_row
->used
[area
];
20649 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20653 /* Change IT->ascent and IT->height according to the setting of
20657 take_vertical_position_into_account (it
)
20662 if (it
->voffset
< 0)
20663 /* Increase the ascent so that we can display the text higher
20665 it
->ascent
-= it
->voffset
;
20667 /* Increase the descent so that we can display the text lower
20669 it
->descent
+= it
->voffset
;
20674 /* Produce glyphs/get display metrics for the image IT is loaded with.
20675 See the description of struct display_iterator in dispextern.h for
20676 an overview of struct display_iterator. */
20679 produce_image_glyph (it
)
20684 int glyph_ascent
, crop
;
20685 struct glyph_slice slice
;
20687 xassert (it
->what
== IT_IMAGE
);
20689 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20691 /* Make sure X resources of the face is loaded. */
20692 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20694 if (it
->image_id
< 0)
20696 /* Fringe bitmap. */
20697 it
->ascent
= it
->phys_ascent
= 0;
20698 it
->descent
= it
->phys_descent
= 0;
20699 it
->pixel_width
= 0;
20704 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20706 /* Make sure X resources of the image is loaded. */
20707 prepare_image_for_display (it
->f
, img
);
20709 slice
.x
= slice
.y
= 0;
20710 slice
.width
= img
->width
;
20711 slice
.height
= img
->height
;
20713 if (INTEGERP (it
->slice
.x
))
20714 slice
.x
= XINT (it
->slice
.x
);
20715 else if (FLOATP (it
->slice
.x
))
20716 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20718 if (INTEGERP (it
->slice
.y
))
20719 slice
.y
= XINT (it
->slice
.y
);
20720 else if (FLOATP (it
->slice
.y
))
20721 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20723 if (INTEGERP (it
->slice
.width
))
20724 slice
.width
= XINT (it
->slice
.width
);
20725 else if (FLOATP (it
->slice
.width
))
20726 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20728 if (INTEGERP (it
->slice
.height
))
20729 slice
.height
= XINT (it
->slice
.height
);
20730 else if (FLOATP (it
->slice
.height
))
20731 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20733 if (slice
.x
>= img
->width
)
20734 slice
.x
= img
->width
;
20735 if (slice
.y
>= img
->height
)
20736 slice
.y
= img
->height
;
20737 if (slice
.x
+ slice
.width
>= img
->width
)
20738 slice
.width
= img
->width
- slice
.x
;
20739 if (slice
.y
+ slice
.height
> img
->height
)
20740 slice
.height
= img
->height
- slice
.y
;
20742 if (slice
.width
== 0 || slice
.height
== 0)
20745 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20747 it
->descent
= slice
.height
- glyph_ascent
;
20749 it
->descent
+= img
->vmargin
;
20750 if (slice
.y
+ slice
.height
== img
->height
)
20751 it
->descent
+= img
->vmargin
;
20752 it
->phys_descent
= it
->descent
;
20754 it
->pixel_width
= slice
.width
;
20756 it
->pixel_width
+= img
->hmargin
;
20757 if (slice
.x
+ slice
.width
== img
->width
)
20758 it
->pixel_width
+= img
->hmargin
;
20760 /* It's quite possible for images to have an ascent greater than
20761 their height, so don't get confused in that case. */
20762 if (it
->descent
< 0)
20767 if (face
->box
!= FACE_NO_BOX
)
20769 if (face
->box_line_width
> 0)
20772 it
->ascent
+= face
->box_line_width
;
20773 if (slice
.y
+ slice
.height
== img
->height
)
20774 it
->descent
+= face
->box_line_width
;
20777 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20778 it
->pixel_width
+= eabs (face
->box_line_width
);
20779 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20780 it
->pixel_width
+= eabs (face
->box_line_width
);
20783 take_vertical_position_into_account (it
);
20785 /* Automatically crop wide image glyphs at right edge so we can
20786 draw the cursor on same display row. */
20787 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20788 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20790 it
->pixel_width
-= crop
;
20791 slice
.width
-= crop
;
20796 struct glyph
*glyph
;
20797 enum glyph_row_area area
= it
->area
;
20799 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20800 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20802 glyph
->charpos
= CHARPOS (it
->position
);
20803 glyph
->object
= it
->object
;
20804 glyph
->pixel_width
= it
->pixel_width
;
20805 glyph
->ascent
= glyph_ascent
;
20806 glyph
->descent
= it
->descent
;
20807 glyph
->voffset
= it
->voffset
;
20808 glyph
->type
= IMAGE_GLYPH
;
20809 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20810 glyph
->multibyte_p
= it
->multibyte_p
;
20811 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20812 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20813 glyph
->overlaps_vertically_p
= 0;
20814 glyph
->padding_p
= 0;
20815 glyph
->glyph_not_available_p
= 0;
20816 glyph
->face_id
= it
->face_id
;
20817 glyph
->u
.img_id
= img
->id
;
20818 glyph
->slice
= slice
;
20819 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20820 ++it
->glyph_row
->used
[area
];
20823 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20828 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20829 of the glyph, WIDTH and HEIGHT are the width and height of the
20830 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20833 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20835 Lisp_Object object
;
20839 struct glyph
*glyph
;
20840 enum glyph_row_area area
= it
->area
;
20842 xassert (ascent
>= 0 && ascent
<= height
);
20844 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20845 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20847 glyph
->charpos
= CHARPOS (it
->position
);
20848 glyph
->object
= object
;
20849 glyph
->pixel_width
= width
;
20850 glyph
->ascent
= ascent
;
20851 glyph
->descent
= height
- ascent
;
20852 glyph
->voffset
= it
->voffset
;
20853 glyph
->type
= STRETCH_GLYPH
;
20854 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20855 glyph
->multibyte_p
= it
->multibyte_p
;
20856 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20857 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20858 glyph
->overlaps_vertically_p
= 0;
20859 glyph
->padding_p
= 0;
20860 glyph
->glyph_not_available_p
= 0;
20861 glyph
->face_id
= it
->face_id
;
20862 glyph
->u
.stretch
.ascent
= ascent
;
20863 glyph
->u
.stretch
.height
= height
;
20864 glyph
->slice
= null_glyph_slice
;
20865 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20866 ++it
->glyph_row
->used
[area
];
20869 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20873 /* Produce a stretch glyph for iterator IT. IT->object is the value
20874 of the glyph property displayed. The value must be a list
20875 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20878 1. `:width WIDTH' specifies that the space should be WIDTH *
20879 canonical char width wide. WIDTH may be an integer or floating
20882 2. `:relative-width FACTOR' specifies that the width of the stretch
20883 should be computed from the width of the first character having the
20884 `glyph' property, and should be FACTOR times that width.
20886 3. `:align-to HPOS' specifies that the space should be wide enough
20887 to reach HPOS, a value in canonical character units.
20889 Exactly one of the above pairs must be present.
20891 4. `:height HEIGHT' specifies that the height of the stretch produced
20892 should be HEIGHT, measured in canonical character units.
20894 5. `:relative-height FACTOR' specifies that the height of the
20895 stretch should be FACTOR times the height of the characters having
20896 the glyph property.
20898 Either none or exactly one of 4 or 5 must be present.
20900 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20901 of the stretch should be used for the ascent of the stretch.
20902 ASCENT must be in the range 0 <= ASCENT <= 100. */
20905 produce_stretch_glyph (it
)
20908 /* (space :width WIDTH :height HEIGHT ...) */
20909 Lisp_Object prop
, plist
;
20910 int width
= 0, height
= 0, align_to
= -1;
20911 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20914 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20915 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20917 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20919 /* List should start with `space'. */
20920 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20921 plist
= XCDR (it
->object
);
20923 /* Compute the width of the stretch. */
20924 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20925 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20927 /* Absolute width `:width WIDTH' specified and valid. */
20928 zero_width_ok_p
= 1;
20931 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20934 /* Relative width `:relative-width FACTOR' specified and valid.
20935 Compute the width of the characters having the `glyph'
20938 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20941 if (it
->multibyte_p
)
20943 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20944 - IT_BYTEPOS (*it
));
20945 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
20948 it2
.c
= *p
, it2
.len
= 1;
20950 it2
.glyph_row
= NULL
;
20951 it2
.what
= IT_CHARACTER
;
20952 x_produce_glyphs (&it2
);
20953 width
= NUMVAL (prop
) * it2
.pixel_width
;
20955 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20956 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20958 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20959 align_to
= (align_to
< 0
20961 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20962 else if (align_to
< 0)
20963 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20964 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20965 zero_width_ok_p
= 1;
20968 /* Nothing specified -> width defaults to canonical char width. */
20969 width
= FRAME_COLUMN_WIDTH (it
->f
);
20971 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20974 /* Compute height. */
20975 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20976 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20979 zero_height_ok_p
= 1;
20981 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20983 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20985 height
= FONT_HEIGHT (font
);
20987 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20990 /* Compute percentage of height used for ascent. If
20991 `:ascent ASCENT' is present and valid, use that. Otherwise,
20992 derive the ascent from the font in use. */
20993 if (prop
= Fplist_get (plist
, QCascent
),
20994 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20995 ascent
= height
* NUMVAL (prop
) / 100.0;
20996 else if (!NILP (prop
)
20997 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20998 ascent
= min (max (0, (int)tem
), height
);
21000 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21002 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21003 && it
->current_x
+ width
> it
->last_visible_x
)
21004 width
= it
->last_visible_x
- it
->current_x
- 1;
21006 if (width
> 0 && height
> 0 && it
->glyph_row
)
21008 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21009 if (!STRINGP (object
))
21010 object
= it
->w
->buffer
;
21011 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21014 it
->pixel_width
= width
;
21015 it
->ascent
= it
->phys_ascent
= ascent
;
21016 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21017 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21019 take_vertical_position_into_account (it
);
21022 /* Calculate line-height and line-spacing properties.
21023 An integer value specifies explicit pixel value.
21024 A float value specifies relative value to current face height.
21025 A cons (float . face-name) specifies relative value to
21026 height of specified face font.
21028 Returns height in pixels, or nil. */
21032 calc_line_height_property (it
, val
, font
, boff
, override
)
21036 int boff
, override
;
21038 Lisp_Object face_name
= Qnil
;
21039 int ascent
, descent
, height
;
21041 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21046 face_name
= XCAR (val
);
21048 if (!NUMBERP (val
))
21049 val
= make_number (1);
21050 if (NILP (face_name
))
21052 height
= it
->ascent
+ it
->descent
;
21057 if (NILP (face_name
))
21059 font
= FRAME_FONT (it
->f
);
21060 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21062 else if (EQ (face_name
, Qt
))
21071 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21073 return make_number (-1);
21075 face
= FACE_FROM_ID (it
->f
, face_id
);
21078 return make_number (-1);
21079 boff
= font
->baseline_offset
;
21080 if (font
->vertical_centering
)
21081 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21084 ascent
= FONT_BASE (font
) + boff
;
21085 descent
= FONT_DESCENT (font
) - boff
;
21089 it
->override_ascent
= ascent
;
21090 it
->override_descent
= descent
;
21091 it
->override_boff
= boff
;
21094 height
= ascent
+ descent
;
21098 height
= (int)(XFLOAT_DATA (val
) * height
);
21099 else if (INTEGERP (val
))
21100 height
*= XINT (val
);
21102 return make_number (height
);
21107 Produce glyphs/get display metrics for the display element IT is
21108 loaded with. See the description of struct it in dispextern.h
21109 for an overview of struct it. */
21112 x_produce_glyphs (it
)
21115 int extra_line_spacing
= it
->extra_line_spacing
;
21117 it
->glyph_not_available_p
= 0;
21119 if (it
->what
== IT_CHARACTER
)
21123 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21124 struct font_metrics
*pcm
;
21125 int font_not_found_p
;
21126 int boff
; /* baseline offset */
21127 /* We may change it->multibyte_p upon unibyte<->multibyte
21128 conversion. So, save the current value now and restore it
21131 Note: It seems that we don't have to record multibyte_p in
21132 struct glyph because the character code itself tells whether
21133 or not the character is multibyte. Thus, in the future, we
21134 must consider eliminating the field `multibyte_p' in the
21136 int saved_multibyte_p
= it
->multibyte_p
;
21138 /* Maybe translate single-byte characters to multibyte, or the
21140 it
->char_to_display
= it
->c
;
21141 if (!ASCII_BYTE_P (it
->c
)
21142 && ! it
->multibyte_p
)
21144 if (SINGLE_BYTE_CHAR_P (it
->c
)
21145 && unibyte_display_via_language_environment
)
21147 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21149 /* get_next_display_element assures that this decoding
21151 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21152 it
->multibyte_p
= 1;
21153 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21155 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21159 /* Get font to use. Encode IT->char_to_display. */
21160 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21161 &char2b
, it
->multibyte_p
, 0);
21164 font_not_found_p
= font
== NULL
;
21165 if (font_not_found_p
)
21167 /* When no suitable font found, display an empty box based
21168 on the metrics of the font of the default face (or what
21170 struct face
*no_font_face
21171 = FACE_FROM_ID (it
->f
,
21172 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21173 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21174 font
= no_font_face
->font
;
21175 boff
= font
->baseline_offset
;
21179 boff
= font
->baseline_offset
;
21180 if (font
->vertical_centering
)
21181 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21184 if (it
->char_to_display
>= ' '
21185 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21187 /* Either unibyte or ASCII. */
21192 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21194 if (it
->override_ascent
>= 0)
21196 it
->ascent
= it
->override_ascent
;
21197 it
->descent
= it
->override_descent
;
21198 boff
= it
->override_boff
;
21202 it
->ascent
= FONT_BASE (font
) + boff
;
21203 it
->descent
= FONT_DESCENT (font
) - boff
;
21208 it
->phys_ascent
= pcm
->ascent
+ boff
;
21209 it
->phys_descent
= pcm
->descent
- boff
;
21210 it
->pixel_width
= pcm
->width
;
21214 it
->glyph_not_available_p
= 1;
21215 it
->phys_ascent
= it
->ascent
;
21216 it
->phys_descent
= it
->descent
;
21217 it
->pixel_width
= FONT_WIDTH (font
);
21220 if (it
->constrain_row_ascent_descent_p
)
21222 if (it
->descent
> it
->max_descent
)
21224 it
->ascent
+= it
->descent
- it
->max_descent
;
21225 it
->descent
= it
->max_descent
;
21227 if (it
->ascent
> it
->max_ascent
)
21229 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21230 it
->ascent
= it
->max_ascent
;
21232 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21233 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21234 extra_line_spacing
= 0;
21237 /* If this is a space inside a region of text with
21238 `space-width' property, change its width. */
21239 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21241 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21243 /* If face has a box, add the box thickness to the character
21244 height. If character has a box line to the left and/or
21245 right, add the box line width to the character's width. */
21246 if (face
->box
!= FACE_NO_BOX
)
21248 int thick
= face
->box_line_width
;
21252 it
->ascent
+= thick
;
21253 it
->descent
+= thick
;
21258 if (it
->start_of_box_run_p
)
21259 it
->pixel_width
+= thick
;
21260 if (it
->end_of_box_run_p
)
21261 it
->pixel_width
+= thick
;
21264 /* If face has an overline, add the height of the overline
21265 (1 pixel) and a 1 pixel margin to the character height. */
21266 if (face
->overline_p
)
21267 it
->ascent
+= overline_margin
;
21269 if (it
->constrain_row_ascent_descent_p
)
21271 if (it
->ascent
> it
->max_ascent
)
21272 it
->ascent
= it
->max_ascent
;
21273 if (it
->descent
> it
->max_descent
)
21274 it
->descent
= it
->max_descent
;
21277 take_vertical_position_into_account (it
);
21279 /* If we have to actually produce glyphs, do it. */
21284 /* Translate a space with a `space-width' property
21285 into a stretch glyph. */
21286 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21287 / FONT_HEIGHT (font
));
21288 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21289 it
->ascent
+ it
->descent
, ascent
);
21294 /* If characters with lbearing or rbearing are displayed
21295 in this line, record that fact in a flag of the
21296 glyph row. This is used to optimize X output code. */
21297 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21298 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21300 if (! stretched_p
&& it
->pixel_width
== 0)
21301 /* We assure that all visible glyphs have at least 1-pixel
21303 it
->pixel_width
= 1;
21305 else if (it
->char_to_display
== '\n')
21307 /* A newline has no width, but we need the height of the
21308 line. But if previous part of the line sets a height,
21309 don't increase that height */
21311 Lisp_Object height
;
21312 Lisp_Object total_height
= Qnil
;
21314 it
->override_ascent
= -1;
21315 it
->pixel_width
= 0;
21318 height
= get_it_property(it
, Qline_height
);
21319 /* Split (line-height total-height) list */
21321 && CONSP (XCDR (height
))
21322 && NILP (XCDR (XCDR (height
))))
21324 total_height
= XCAR (XCDR (height
));
21325 height
= XCAR (height
);
21327 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21329 if (it
->override_ascent
>= 0)
21331 it
->ascent
= it
->override_ascent
;
21332 it
->descent
= it
->override_descent
;
21333 boff
= it
->override_boff
;
21337 it
->ascent
= FONT_BASE (font
) + boff
;
21338 it
->descent
= FONT_DESCENT (font
) - boff
;
21341 if (EQ (height
, Qt
))
21343 if (it
->descent
> it
->max_descent
)
21345 it
->ascent
+= it
->descent
- it
->max_descent
;
21346 it
->descent
= it
->max_descent
;
21348 if (it
->ascent
> it
->max_ascent
)
21350 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21351 it
->ascent
= it
->max_ascent
;
21353 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21354 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21355 it
->constrain_row_ascent_descent_p
= 1;
21356 extra_line_spacing
= 0;
21360 Lisp_Object spacing
;
21362 it
->phys_ascent
= it
->ascent
;
21363 it
->phys_descent
= it
->descent
;
21365 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21366 && face
->box
!= FACE_NO_BOX
21367 && face
->box_line_width
> 0)
21369 it
->ascent
+= face
->box_line_width
;
21370 it
->descent
+= face
->box_line_width
;
21373 && XINT (height
) > it
->ascent
+ it
->descent
)
21374 it
->ascent
= XINT (height
) - it
->descent
;
21376 if (!NILP (total_height
))
21377 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21380 spacing
= get_it_property(it
, Qline_spacing
);
21381 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21383 if (INTEGERP (spacing
))
21385 extra_line_spacing
= XINT (spacing
);
21386 if (!NILP (total_height
))
21387 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21391 else if (it
->char_to_display
== '\t')
21393 if (font
->space_width
> 0)
21395 int tab_width
= it
->tab_width
* font
->space_width
;
21396 int x
= it
->current_x
+ it
->continuation_lines_width
;
21397 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21399 /* If the distance from the current position to the next tab
21400 stop is less than a space character width, use the
21401 tab stop after that. */
21402 if (next_tab_x
- x
< font
->space_width
)
21403 next_tab_x
+= tab_width
;
21405 it
->pixel_width
= next_tab_x
- x
;
21407 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21408 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21412 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21413 it
->ascent
+ it
->descent
, it
->ascent
);
21418 it
->pixel_width
= 0;
21424 /* A multi-byte character. Assume that the display width of the
21425 character is the width of the character multiplied by the
21426 width of the font. */
21428 /* If we found a font, this font should give us the right
21429 metrics. If we didn't find a font, use the frame's
21430 default font and calculate the width of the character by
21431 multiplying the width of font by the width of the
21434 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21436 if (font_not_found_p
|| !pcm
)
21438 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21440 if (char_width
== 0)
21441 /* This is a non spacing character. But, as we are
21442 going to display an empty box, the box must occupy
21443 at least one column. */
21445 it
->glyph_not_available_p
= 1;
21446 it
->pixel_width
= font
->space_width
* char_width
;
21447 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21448 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21452 it
->pixel_width
= pcm
->width
;
21453 it
->phys_ascent
= pcm
->ascent
+ boff
;
21454 it
->phys_descent
= pcm
->descent
- boff
;
21456 && (pcm
->lbearing
< 0
21457 || pcm
->rbearing
> pcm
->width
))
21458 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21461 it
->ascent
= FONT_BASE (font
) + boff
;
21462 it
->descent
= FONT_DESCENT (font
) - boff
;
21463 if (face
->box
!= FACE_NO_BOX
)
21465 int thick
= face
->box_line_width
;
21469 it
->ascent
+= thick
;
21470 it
->descent
+= thick
;
21475 if (it
->start_of_box_run_p
)
21476 it
->pixel_width
+= thick
;
21477 if (it
->end_of_box_run_p
)
21478 it
->pixel_width
+= thick
;
21481 /* If face has an overline, add the height of the overline
21482 (1 pixel) and a 1 pixel margin to the character height. */
21483 if (face
->overline_p
)
21484 it
->ascent
+= overline_margin
;
21486 take_vertical_position_into_account (it
);
21488 if (it
->ascent
< 0)
21490 if (it
->descent
< 0)
21495 if (it
->pixel_width
== 0)
21496 /* We assure that all visible glyphs have at least 1-pixel
21498 it
->pixel_width
= 1;
21500 it
->multibyte_p
= saved_multibyte_p
;
21502 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
21504 /* A static composition.
21506 Note: A composition is represented as one glyph in the
21507 glyph matrix. There are no padding glyphs.
21509 Important note: pixel_width, ascent, and descent are the
21510 values of what is drawn by draw_glyphs (i.e. the values of
21511 the overall glyphs composed). */
21512 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21513 int boff
; /* baseline offset */
21514 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
21515 int glyph_len
= cmp
->glyph_len
;
21516 struct font
*font
= face
->font
;
21520 /* If we have not yet calculated pixel size data of glyphs of
21521 the composition for the current face font, calculate them
21522 now. Theoretically, we have to check all fonts for the
21523 glyphs, but that requires much time and memory space. So,
21524 here we check only the font of the first glyph. This may
21525 lead to incorrect display, but it's very rare, and C-l
21526 (recenter-top-bottom) can correct the display anyway. */
21527 if (! cmp
->font
|| cmp
->font
!= font
)
21529 /* Ascent and descent of the font of the first character
21530 of this composition (adjusted by baseline offset).
21531 Ascent and descent of overall glyphs should not be less
21532 than these, respectively. */
21533 int font_ascent
, font_descent
, font_height
;
21534 /* Bounding box of the overall glyphs. */
21535 int leftmost
, rightmost
, lowest
, highest
;
21536 int lbearing
, rbearing
;
21537 int i
, width
, ascent
, descent
;
21538 int left_padded
= 0, right_padded
= 0;
21541 struct font_metrics
*pcm
;
21542 int font_not_found_p
;
21545 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21546 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21548 if (glyph_len
< cmp
->glyph_len
)
21550 for (i
= 0; i
< glyph_len
; i
++)
21552 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21554 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21559 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21560 : IT_CHARPOS (*it
));
21561 /* If no suitable font is found, use the default font. */
21562 font_not_found_p
= font
== NULL
;
21563 if (font_not_found_p
)
21565 face
= face
->ascii_face
;
21568 boff
= font
->baseline_offset
;
21569 if (font
->vertical_centering
)
21570 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21571 font_ascent
= FONT_BASE (font
) + boff
;
21572 font_descent
= FONT_DESCENT (font
) - boff
;
21573 font_height
= FONT_HEIGHT (font
);
21575 cmp
->font
= (void *) font
;
21578 if (! font_not_found_p
)
21580 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21581 &char2b
, it
->multibyte_p
, 0);
21582 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21585 /* Initialize the bounding box. */
21588 width
= pcm
->width
;
21589 ascent
= pcm
->ascent
;
21590 descent
= pcm
->descent
;
21591 lbearing
= pcm
->lbearing
;
21592 rbearing
= pcm
->rbearing
;
21596 width
= FONT_WIDTH (font
);
21597 ascent
= FONT_BASE (font
);
21598 descent
= FONT_DESCENT (font
);
21605 lowest
= - descent
+ boff
;
21606 highest
= ascent
+ boff
;
21608 if (! font_not_found_p
21609 && font
->default_ascent
21610 && CHAR_TABLE_P (Vuse_default_ascent
)
21611 && !NILP (Faref (Vuse_default_ascent
,
21612 make_number (it
->char_to_display
))))
21613 highest
= font
->default_ascent
+ boff
;
21615 /* Draw the first glyph at the normal position. It may be
21616 shifted to right later if some other glyphs are drawn
21618 cmp
->offsets
[i
* 2] = 0;
21619 cmp
->offsets
[i
* 2 + 1] = boff
;
21620 cmp
->lbearing
= lbearing
;
21621 cmp
->rbearing
= rbearing
;
21623 /* Set cmp->offsets for the remaining glyphs. */
21624 for (i
++; i
< glyph_len
; i
++)
21626 int left
, right
, btm
, top
;
21627 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21629 struct face
*this_face
;
21634 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21635 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21636 font
= this_face
->font
;
21642 this_boff
= font
->baseline_offset
;
21643 if (font
->vertical_centering
)
21644 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21645 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21646 &char2b
, it
->multibyte_p
, 0);
21647 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21650 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21653 width
= pcm
->width
;
21654 ascent
= pcm
->ascent
;
21655 descent
= pcm
->descent
;
21656 lbearing
= pcm
->lbearing
;
21657 rbearing
= pcm
->rbearing
;
21658 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21660 /* Relative composition with or without
21661 alternate chars. */
21662 left
= (leftmost
+ rightmost
- width
) / 2;
21663 btm
= - descent
+ boff
;
21664 if (font
->relative_compose
21665 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21666 || NILP (Faref (Vignore_relative_composition
,
21667 make_number (ch
)))))
21670 if (- descent
>= font
->relative_compose
)
21671 /* One extra pixel between two glyphs. */
21673 else if (ascent
<= 0)
21674 /* One extra pixel between two glyphs. */
21675 btm
= lowest
- 1 - ascent
- descent
;
21680 /* A composition rule is specified by an integer
21681 value that encodes global and new reference
21682 points (GREF and NREF). GREF and NREF are
21683 specified by numbers as below:
21685 0---1---2 -- ascent
21689 9--10--11 -- center
21691 ---3---4---5--- baseline
21693 6---7---8 -- descent
21695 int rule
= COMPOSITION_RULE (cmp
, i
);
21696 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21698 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21699 grefx
= gref
% 3, nrefx
= nref
% 3;
21700 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21702 xoff
= font_height
* (xoff
- 128) / 256;
21704 yoff
= font_height
* (yoff
- 128) / 256;
21707 + grefx
* (rightmost
- leftmost
) / 2
21708 - nrefx
* width
/ 2
21711 btm
= ((grefy
== 0 ? highest
21713 : grefy
== 2 ? lowest
21714 : (highest
+ lowest
) / 2)
21715 - (nrefy
== 0 ? ascent
+ descent
21716 : nrefy
== 1 ? descent
- boff
21718 : (ascent
+ descent
) / 2)
21722 cmp
->offsets
[i
* 2] = left
;
21723 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21725 /* Update the bounding box of the overall glyphs. */
21728 right
= left
+ width
;
21729 if (left
< leftmost
)
21731 if (right
> rightmost
)
21734 top
= btm
+ descent
+ ascent
;
21740 if (cmp
->lbearing
> left
+ lbearing
)
21741 cmp
->lbearing
= left
+ lbearing
;
21742 if (cmp
->rbearing
< left
+ rbearing
)
21743 cmp
->rbearing
= left
+ rbearing
;
21747 /* If there are glyphs whose x-offsets are negative,
21748 shift all glyphs to the right and make all x-offsets
21752 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21753 cmp
->offsets
[i
* 2] -= leftmost
;
21754 rightmost
-= leftmost
;
21755 cmp
->lbearing
-= leftmost
;
21756 cmp
->rbearing
-= leftmost
;
21759 if (left_padded
&& cmp
->lbearing
< 0)
21761 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21762 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21763 rightmost
-= cmp
->lbearing
;
21764 cmp
->rbearing
-= cmp
->lbearing
;
21767 if (right_padded
&& rightmost
< cmp
->rbearing
)
21769 rightmost
= cmp
->rbearing
;
21772 cmp
->pixel_width
= rightmost
;
21773 cmp
->ascent
= highest
;
21774 cmp
->descent
= - lowest
;
21775 if (cmp
->ascent
< font_ascent
)
21776 cmp
->ascent
= font_ascent
;
21777 if (cmp
->descent
< font_descent
)
21778 cmp
->descent
= font_descent
;
21782 && (cmp
->lbearing
< 0
21783 || cmp
->rbearing
> cmp
->pixel_width
))
21784 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21786 it
->pixel_width
= cmp
->pixel_width
;
21787 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21788 it
->descent
= it
->phys_descent
= cmp
->descent
;
21789 if (face
->box
!= FACE_NO_BOX
)
21791 int thick
= face
->box_line_width
;
21795 it
->ascent
+= thick
;
21796 it
->descent
+= thick
;
21801 if (it
->start_of_box_run_p
)
21802 it
->pixel_width
+= thick
;
21803 if (it
->end_of_box_run_p
)
21804 it
->pixel_width
+= thick
;
21807 /* If face has an overline, add the height of the overline
21808 (1 pixel) and a 1 pixel margin to the character height. */
21809 if (face
->overline_p
)
21810 it
->ascent
+= overline_margin
;
21812 take_vertical_position_into_account (it
);
21813 if (it
->ascent
< 0)
21815 if (it
->descent
< 0)
21819 append_composite_glyph (it
);
21821 else if (it
->what
== IT_COMPOSITION
)
21823 /* A dynamic (automatic) composition. */
21824 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21825 Lisp_Object gstring
;
21826 struct font_metrics metrics
;
21828 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
21830 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
21833 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
21834 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21835 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
21836 it
->descent
= it
->phys_descent
= metrics
.descent
;
21837 if (face
->box
!= FACE_NO_BOX
)
21839 int thick
= face
->box_line_width
;
21843 it
->ascent
+= thick
;
21844 it
->descent
+= thick
;
21849 if (it
->start_of_box_run_p
)
21850 it
->pixel_width
+= thick
;
21851 if (it
->end_of_box_run_p
)
21852 it
->pixel_width
+= thick
;
21854 /* If face has an overline, add the height of the overline
21855 (1 pixel) and a 1 pixel margin to the character height. */
21856 if (face
->overline_p
)
21857 it
->ascent
+= overline_margin
;
21858 take_vertical_position_into_account (it
);
21859 if (it
->ascent
< 0)
21861 if (it
->descent
< 0)
21865 append_composite_glyph (it
);
21867 else if (it
->what
== IT_IMAGE
)
21868 produce_image_glyph (it
);
21869 else if (it
->what
== IT_STRETCH
)
21870 produce_stretch_glyph (it
);
21872 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21873 because this isn't true for images with `:ascent 100'. */
21874 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21875 if (it
->area
== TEXT_AREA
)
21876 it
->current_x
+= it
->pixel_width
;
21878 if (extra_line_spacing
> 0)
21880 it
->descent
+= extra_line_spacing
;
21881 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21882 it
->max_extra_line_spacing
= extra_line_spacing
;
21885 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21886 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21887 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21888 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21892 Output LEN glyphs starting at START at the nominal cursor position.
21893 Advance the nominal cursor over the text. The global variable
21894 updated_window contains the window being updated, updated_row is
21895 the glyph row being updated, and updated_area is the area of that
21896 row being updated. */
21899 x_write_glyphs (start
, len
)
21900 struct glyph
*start
;
21905 xassert (updated_window
&& updated_row
);
21908 /* Write glyphs. */
21910 hpos
= start
- updated_row
->glyphs
[updated_area
];
21911 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21912 updated_row
, updated_area
,
21914 DRAW_NORMAL_TEXT
, 0);
21916 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21917 if (updated_area
== TEXT_AREA
21918 && updated_window
->phys_cursor_on_p
21919 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21920 && updated_window
->phys_cursor
.hpos
>= hpos
21921 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21922 updated_window
->phys_cursor_on_p
= 0;
21926 /* Advance the output cursor. */
21927 output_cursor
.hpos
+= len
;
21928 output_cursor
.x
= x
;
21933 Insert LEN glyphs from START at the nominal cursor position. */
21936 x_insert_glyphs (start
, len
)
21937 struct glyph
*start
;
21942 int line_height
, shift_by_width
, shifted_region_width
;
21943 struct glyph_row
*row
;
21944 struct glyph
*glyph
;
21945 int frame_x
, frame_y
;
21948 xassert (updated_window
&& updated_row
);
21950 w
= updated_window
;
21951 f
= XFRAME (WINDOW_FRAME (w
));
21953 /* Get the height of the line we are in. */
21955 line_height
= row
->height
;
21957 /* Get the width of the glyphs to insert. */
21958 shift_by_width
= 0;
21959 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21960 shift_by_width
+= glyph
->pixel_width
;
21962 /* Get the width of the region to shift right. */
21963 shifted_region_width
= (window_box_width (w
, updated_area
)
21968 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21969 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21971 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21972 line_height
, shift_by_width
);
21974 /* Write the glyphs. */
21975 hpos
= start
- row
->glyphs
[updated_area
];
21976 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21978 DRAW_NORMAL_TEXT
, 0);
21980 /* Advance the output cursor. */
21981 output_cursor
.hpos
+= len
;
21982 output_cursor
.x
+= shift_by_width
;
21988 Erase the current text line from the nominal cursor position
21989 (inclusive) to pixel column TO_X (exclusive). The idea is that
21990 everything from TO_X onward is already erased.
21992 TO_X is a pixel position relative to updated_area of
21993 updated_window. TO_X == -1 means clear to the end of this area. */
21996 x_clear_end_of_line (to_x
)
22000 struct window
*w
= updated_window
;
22001 int max_x
, min_y
, max_y
;
22002 int from_x
, from_y
, to_y
;
22004 xassert (updated_window
&& updated_row
);
22005 f
= XFRAME (w
->frame
);
22007 if (updated_row
->full_width_p
)
22008 max_x
= WINDOW_TOTAL_WIDTH (w
);
22010 max_x
= window_box_width (w
, updated_area
);
22011 max_y
= window_text_bottom_y (w
);
22013 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22014 of window. For TO_X > 0, truncate to end of drawing area. */
22020 to_x
= min (to_x
, max_x
);
22022 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22024 /* Notice if the cursor will be cleared by this operation. */
22025 if (!updated_row
->full_width_p
)
22026 notice_overwritten_cursor (w
, updated_area
,
22027 output_cursor
.x
, -1,
22029 MATRIX_ROW_BOTTOM_Y (updated_row
));
22031 from_x
= output_cursor
.x
;
22033 /* Translate to frame coordinates. */
22034 if (updated_row
->full_width_p
)
22036 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22037 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22041 int area_left
= window_box_left (w
, updated_area
);
22042 from_x
+= area_left
;
22046 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22047 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22048 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22050 /* Prevent inadvertently clearing to end of the X window. */
22051 if (to_x
> from_x
&& to_y
> from_y
)
22054 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22055 to_x
- from_x
, to_y
- from_y
);
22060 #endif /* HAVE_WINDOW_SYSTEM */
22064 /***********************************************************************
22066 ***********************************************************************/
22068 /* Value is the internal representation of the specified cursor type
22069 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22070 of the bar cursor. */
22072 static enum text_cursor_kinds
22073 get_specified_cursor_type (arg
, width
)
22077 enum text_cursor_kinds type
;
22082 if (EQ (arg
, Qbox
))
22083 return FILLED_BOX_CURSOR
;
22085 if (EQ (arg
, Qhollow
))
22086 return HOLLOW_BOX_CURSOR
;
22088 if (EQ (arg
, Qbar
))
22095 && EQ (XCAR (arg
), Qbar
)
22096 && INTEGERP (XCDR (arg
))
22097 && XINT (XCDR (arg
)) >= 0)
22099 *width
= XINT (XCDR (arg
));
22103 if (EQ (arg
, Qhbar
))
22106 return HBAR_CURSOR
;
22110 && EQ (XCAR (arg
), Qhbar
)
22111 && INTEGERP (XCDR (arg
))
22112 && XINT (XCDR (arg
)) >= 0)
22114 *width
= XINT (XCDR (arg
));
22115 return HBAR_CURSOR
;
22118 /* Treat anything unknown as "hollow box cursor".
22119 It was bad to signal an error; people have trouble fixing
22120 .Xdefaults with Emacs, when it has something bad in it. */
22121 type
= HOLLOW_BOX_CURSOR
;
22126 /* Set the default cursor types for specified frame. */
22128 set_frame_cursor_types (f
, arg
)
22135 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22136 FRAME_CURSOR_WIDTH (f
) = width
;
22138 /* By default, set up the blink-off state depending on the on-state. */
22140 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22143 FRAME_BLINK_OFF_CURSOR (f
)
22144 = get_specified_cursor_type (XCDR (tem
), &width
);
22145 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22148 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22152 /* Return the cursor we want to be displayed in window W. Return
22153 width of bar/hbar cursor through WIDTH arg. Return with
22154 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22155 (i.e. if the `system caret' should track this cursor).
22157 In a mini-buffer window, we want the cursor only to appear if we
22158 are reading input from this window. For the selected window, we
22159 want the cursor type given by the frame parameter or buffer local
22160 setting of cursor-type. If explicitly marked off, draw no cursor.
22161 In all other cases, we want a hollow box cursor. */
22163 static enum text_cursor_kinds
22164 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22166 struct glyph
*glyph
;
22168 int *active_cursor
;
22170 struct frame
*f
= XFRAME (w
->frame
);
22171 struct buffer
*b
= XBUFFER (w
->buffer
);
22172 int cursor_type
= DEFAULT_CURSOR
;
22173 Lisp_Object alt_cursor
;
22174 int non_selected
= 0;
22176 *active_cursor
= 1;
22179 if (cursor_in_echo_area
22180 && FRAME_HAS_MINIBUF_P (f
)
22181 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22183 if (w
== XWINDOW (echo_area_window
))
22185 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22187 *width
= FRAME_CURSOR_WIDTH (f
);
22188 return FRAME_DESIRED_CURSOR (f
);
22191 return get_specified_cursor_type (b
->cursor_type
, width
);
22194 *active_cursor
= 0;
22198 /* Detect a nonselected window or nonselected frame. */
22199 else if (w
!= XWINDOW (f
->selected_window
)
22200 #ifdef HAVE_WINDOW_SYSTEM
22201 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22205 *active_cursor
= 0;
22207 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22213 /* Never display a cursor in a window in which cursor-type is nil. */
22214 if (NILP (b
->cursor_type
))
22217 /* Get the normal cursor type for this window. */
22218 if (EQ (b
->cursor_type
, Qt
))
22220 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22221 *width
= FRAME_CURSOR_WIDTH (f
);
22224 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22226 /* Use cursor-in-non-selected-windows instead
22227 for non-selected window or frame. */
22230 alt_cursor
= b
->cursor_in_non_selected_windows
;
22231 if (!EQ (Qt
, alt_cursor
))
22232 return get_specified_cursor_type (alt_cursor
, width
);
22233 /* t means modify the normal cursor type. */
22234 if (cursor_type
== FILLED_BOX_CURSOR
)
22235 cursor_type
= HOLLOW_BOX_CURSOR
;
22236 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22238 return cursor_type
;
22241 /* Use normal cursor if not blinked off. */
22242 if (!w
->cursor_off_p
)
22244 #ifdef HAVE_WINDOW_SYSTEM
22245 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22247 if (cursor_type
== FILLED_BOX_CURSOR
)
22249 /* Using a block cursor on large images can be very annoying.
22250 So use a hollow cursor for "large" images.
22251 If image is not transparent (no mask), also use hollow cursor. */
22252 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22253 if (img
!= NULL
&& IMAGEP (img
->spec
))
22255 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22256 where N = size of default frame font size.
22257 This should cover most of the "tiny" icons people may use. */
22259 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22260 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22261 cursor_type
= HOLLOW_BOX_CURSOR
;
22264 else if (cursor_type
!= NO_CURSOR
)
22266 /* Display current only supports BOX and HOLLOW cursors for images.
22267 So for now, unconditionally use a HOLLOW cursor when cursor is
22268 not a solid box cursor. */
22269 cursor_type
= HOLLOW_BOX_CURSOR
;
22273 return cursor_type
;
22276 /* Cursor is blinked off, so determine how to "toggle" it. */
22278 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22279 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22280 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22282 /* Then see if frame has specified a specific blink off cursor type. */
22283 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22285 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22286 return FRAME_BLINK_OFF_CURSOR (f
);
22290 /* Some people liked having a permanently visible blinking cursor,
22291 while others had very strong opinions against it. So it was
22292 decided to remove it. KFS 2003-09-03 */
22294 /* Finally perform built-in cursor blinking:
22295 filled box <-> hollow box
22296 wide [h]bar <-> narrow [h]bar
22297 narrow [h]bar <-> no cursor
22298 other type <-> no cursor */
22300 if (cursor_type
== FILLED_BOX_CURSOR
)
22301 return HOLLOW_BOX_CURSOR
;
22303 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22306 return cursor_type
;
22314 #ifdef HAVE_WINDOW_SYSTEM
22316 /* Notice when the text cursor of window W has been completely
22317 overwritten by a drawing operation that outputs glyphs in AREA
22318 starting at X0 and ending at X1 in the line starting at Y0 and
22319 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22320 the rest of the line after X0 has been written. Y coordinates
22321 are window-relative. */
22324 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22326 enum glyph_row_area area
;
22327 int x0
, y0
, x1
, y1
;
22329 int cx0
, cx1
, cy0
, cy1
;
22330 struct glyph_row
*row
;
22332 if (!w
->phys_cursor_on_p
)
22334 if (area
!= TEXT_AREA
)
22337 if (w
->phys_cursor
.vpos
< 0
22338 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22339 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22340 !(row
->enabled_p
&& row
->displays_text_p
)))
22343 if (row
->cursor_in_fringe_p
)
22345 row
->cursor_in_fringe_p
= 0;
22346 draw_fringe_bitmap (w
, row
, 0);
22347 w
->phys_cursor_on_p
= 0;
22351 cx0
= w
->phys_cursor
.x
;
22352 cx1
= cx0
+ w
->phys_cursor_width
;
22353 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22356 /* The cursor image will be completely removed from the
22357 screen if the output area intersects the cursor area in
22358 y-direction. When we draw in [y0 y1[, and some part of
22359 the cursor is at y < y0, that part must have been drawn
22360 before. When scrolling, the cursor is erased before
22361 actually scrolling, so we don't come here. When not
22362 scrolling, the rows above the old cursor row must have
22363 changed, and in this case these rows must have written
22364 over the cursor image.
22366 Likewise if part of the cursor is below y1, with the
22367 exception of the cursor being in the first blank row at
22368 the buffer and window end because update_text_area
22369 doesn't draw that row. (Except when it does, but
22370 that's handled in update_text_area.) */
22372 cy0
= w
->phys_cursor
.y
;
22373 cy1
= cy0
+ w
->phys_cursor_height
;
22374 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22377 w
->phys_cursor_on_p
= 0;
22380 #endif /* HAVE_WINDOW_SYSTEM */
22383 /************************************************************************
22385 ************************************************************************/
22387 #ifdef HAVE_WINDOW_SYSTEM
22390 Fix the display of area AREA of overlapping row ROW in window W
22391 with respect to the overlapping part OVERLAPS. */
22394 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22396 struct glyph_row
*row
;
22397 enum glyph_row_area area
;
22405 for (i
= 0; i
< row
->used
[area
];)
22407 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22409 int start
= i
, start_x
= x
;
22413 x
+= row
->glyphs
[area
][i
].pixel_width
;
22416 while (i
< row
->used
[area
]
22417 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22419 draw_glyphs (w
, start_x
, row
, area
,
22421 DRAW_NORMAL_TEXT
, overlaps
);
22425 x
+= row
->glyphs
[area
][i
].pixel_width
;
22435 Draw the cursor glyph of window W in glyph row ROW. See the
22436 comment of draw_glyphs for the meaning of HL. */
22439 draw_phys_cursor_glyph (w
, row
, hl
)
22441 struct glyph_row
*row
;
22442 enum draw_glyphs_face hl
;
22444 /* If cursor hpos is out of bounds, don't draw garbage. This can
22445 happen in mini-buffer windows when switching between echo area
22446 glyphs and mini-buffer. */
22447 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22449 int on_p
= w
->phys_cursor_on_p
;
22451 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22452 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22454 w
->phys_cursor_on_p
= on_p
;
22456 if (hl
== DRAW_CURSOR
)
22457 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22458 /* When we erase the cursor, and ROW is overlapped by other
22459 rows, make sure that these overlapping parts of other rows
22461 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22463 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22465 if (row
> w
->current_matrix
->rows
22466 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22467 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22468 OVERLAPS_ERASED_CURSOR
);
22470 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22471 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22472 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22473 OVERLAPS_ERASED_CURSOR
);
22480 Erase the image of a cursor of window W from the screen. */
22483 erase_phys_cursor (w
)
22486 struct frame
*f
= XFRAME (w
->frame
);
22487 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22488 int hpos
= w
->phys_cursor
.hpos
;
22489 int vpos
= w
->phys_cursor
.vpos
;
22490 int mouse_face_here_p
= 0;
22491 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22492 struct glyph_row
*cursor_row
;
22493 struct glyph
*cursor_glyph
;
22494 enum draw_glyphs_face hl
;
22496 /* No cursor displayed or row invalidated => nothing to do on the
22498 if (w
->phys_cursor_type
== NO_CURSOR
)
22499 goto mark_cursor_off
;
22501 /* VPOS >= active_glyphs->nrows means that window has been resized.
22502 Don't bother to erase the cursor. */
22503 if (vpos
>= active_glyphs
->nrows
)
22504 goto mark_cursor_off
;
22506 /* If row containing cursor is marked invalid, there is nothing we
22508 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22509 if (!cursor_row
->enabled_p
)
22510 goto mark_cursor_off
;
22512 /* If line spacing is > 0, old cursor may only be partially visible in
22513 window after split-window. So adjust visible height. */
22514 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22515 window_text_bottom_y (w
) - cursor_row
->y
);
22517 /* If row is completely invisible, don't attempt to delete a cursor which
22518 isn't there. This can happen if cursor is at top of a window, and
22519 we switch to a buffer with a header line in that window. */
22520 if (cursor_row
->visible_height
<= 0)
22521 goto mark_cursor_off
;
22523 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22524 if (cursor_row
->cursor_in_fringe_p
)
22526 cursor_row
->cursor_in_fringe_p
= 0;
22527 draw_fringe_bitmap (w
, cursor_row
, 0);
22528 goto mark_cursor_off
;
22531 /* This can happen when the new row is shorter than the old one.
22532 In this case, either draw_glyphs or clear_end_of_line
22533 should have cleared the cursor. Note that we wouldn't be
22534 able to erase the cursor in this case because we don't have a
22535 cursor glyph at hand. */
22536 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22537 goto mark_cursor_off
;
22539 /* If the cursor is in the mouse face area, redisplay that when
22540 we clear the cursor. */
22541 if (! NILP (dpyinfo
->mouse_face_window
)
22542 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22543 && (vpos
> dpyinfo
->mouse_face_beg_row
22544 || (vpos
== dpyinfo
->mouse_face_beg_row
22545 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22546 && (vpos
< dpyinfo
->mouse_face_end_row
22547 || (vpos
== dpyinfo
->mouse_face_end_row
22548 && hpos
< dpyinfo
->mouse_face_end_col
))
22549 /* Don't redraw the cursor's spot in mouse face if it is at the
22550 end of a line (on a newline). The cursor appears there, but
22551 mouse highlighting does not. */
22552 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22553 mouse_face_here_p
= 1;
22555 /* Maybe clear the display under the cursor. */
22556 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22559 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22562 cursor_glyph
= get_phys_cursor_glyph (w
);
22563 if (cursor_glyph
== NULL
)
22564 goto mark_cursor_off
;
22566 width
= cursor_glyph
->pixel_width
;
22567 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22568 x
= w
->phys_cursor
.x
;
22570 width
-= left_x
- x
;
22571 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22572 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22573 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22576 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22579 /* Erase the cursor by redrawing the character underneath it. */
22580 if (mouse_face_here_p
)
22581 hl
= DRAW_MOUSE_FACE
;
22583 hl
= DRAW_NORMAL_TEXT
;
22584 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22587 w
->phys_cursor_on_p
= 0;
22588 w
->phys_cursor_type
= NO_CURSOR
;
22593 Display or clear cursor of window W. If ON is zero, clear the
22594 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22595 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22598 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22600 int on
, hpos
, vpos
, x
, y
;
22602 struct frame
*f
= XFRAME (w
->frame
);
22603 int new_cursor_type
;
22604 int new_cursor_width
;
22606 struct glyph_row
*glyph_row
;
22607 struct glyph
*glyph
;
22609 /* This is pointless on invisible frames, and dangerous on garbaged
22610 windows and frames; in the latter case, the frame or window may
22611 be in the midst of changing its size, and x and y may be off the
22613 if (! FRAME_VISIBLE_P (f
)
22614 || FRAME_GARBAGED_P (f
)
22615 || vpos
>= w
->current_matrix
->nrows
22616 || hpos
>= w
->current_matrix
->matrix_w
)
22619 /* If cursor is off and we want it off, return quickly. */
22620 if (!on
&& !w
->phys_cursor_on_p
)
22623 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22624 /* If cursor row is not enabled, we don't really know where to
22625 display the cursor. */
22626 if (!glyph_row
->enabled_p
)
22628 w
->phys_cursor_on_p
= 0;
22633 if (!glyph_row
->exact_window_width_line_p
22634 || hpos
< glyph_row
->used
[TEXT_AREA
])
22635 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22637 xassert (interrupt_input_blocked
);
22639 /* Set new_cursor_type to the cursor we want to be displayed. */
22640 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22641 &new_cursor_width
, &active_cursor
);
22643 /* If cursor is currently being shown and we don't want it to be or
22644 it is in the wrong place, or the cursor type is not what we want,
22646 if (w
->phys_cursor_on_p
22648 || w
->phys_cursor
.x
!= x
22649 || w
->phys_cursor
.y
!= y
22650 || new_cursor_type
!= w
->phys_cursor_type
22651 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22652 && new_cursor_width
!= w
->phys_cursor_width
)))
22653 erase_phys_cursor (w
);
22655 /* Don't check phys_cursor_on_p here because that flag is only set
22656 to zero in some cases where we know that the cursor has been
22657 completely erased, to avoid the extra work of erasing the cursor
22658 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22659 still not be visible, or it has only been partly erased. */
22662 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22663 w
->phys_cursor_height
= glyph_row
->height
;
22665 /* Set phys_cursor_.* before x_draw_.* is called because some
22666 of them may need the information. */
22667 w
->phys_cursor
.x
= x
;
22668 w
->phys_cursor
.y
= glyph_row
->y
;
22669 w
->phys_cursor
.hpos
= hpos
;
22670 w
->phys_cursor
.vpos
= vpos
;
22673 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22674 new_cursor_type
, new_cursor_width
,
22675 on
, active_cursor
);
22679 /* Switch the display of W's cursor on or off, according to the value
22686 update_window_cursor (w
, on
)
22690 /* Don't update cursor in windows whose frame is in the process
22691 of being deleted. */
22692 if (w
->current_matrix
)
22695 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22696 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22702 /* Call update_window_cursor with parameter ON_P on all leaf windows
22703 in the window tree rooted at W. */
22706 update_cursor_in_window_tree (w
, on_p
)
22712 if (!NILP (w
->hchild
))
22713 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22714 else if (!NILP (w
->vchild
))
22715 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22717 update_window_cursor (w
, on_p
);
22719 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22725 Display the cursor on window W, or clear it, according to ON_P.
22726 Don't change the cursor's position. */
22729 x_update_cursor (f
, on_p
)
22733 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22738 Clear the cursor of window W to background color, and mark the
22739 cursor as not shown. This is used when the text where the cursor
22740 is about to be rewritten. */
22746 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22747 update_window_cursor (w
, 0);
22752 Display the active region described by mouse_face_* according to DRAW. */
22755 show_mouse_face (dpyinfo
, draw
)
22756 Display_Info
*dpyinfo
;
22757 enum draw_glyphs_face draw
;
22759 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22760 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22762 if (/* If window is in the process of being destroyed, don't bother
22764 w
->current_matrix
!= NULL
22765 /* Don't update mouse highlight if hidden */
22766 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22767 /* Recognize when we are called to operate on rows that don't exist
22768 anymore. This can happen when a window is split. */
22769 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22771 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22772 struct glyph_row
*row
, *first
, *last
;
22774 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22775 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22777 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22779 int start_hpos
, end_hpos
, start_x
;
22781 /* For all but the first row, the highlight starts at column 0. */
22784 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22785 start_x
= dpyinfo
->mouse_face_beg_x
;
22794 end_hpos
= dpyinfo
->mouse_face_end_col
;
22797 end_hpos
= row
->used
[TEXT_AREA
];
22798 if (draw
== DRAW_NORMAL_TEXT
)
22799 row
->fill_line_p
= 1; /* Clear to end of line */
22802 if (end_hpos
> start_hpos
)
22804 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22805 start_hpos
, end_hpos
,
22809 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22813 /* When we've written over the cursor, arrange for it to
22814 be displayed again. */
22815 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22818 display_and_set_cursor (w
, 1,
22819 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22820 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22825 /* Change the mouse cursor. */
22826 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22827 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22828 else if (draw
== DRAW_MOUSE_FACE
)
22829 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22831 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22835 Clear out the mouse-highlighted active region.
22836 Redraw it un-highlighted first. Value is non-zero if mouse
22837 face was actually drawn unhighlighted. */
22840 clear_mouse_face (dpyinfo
)
22841 Display_Info
*dpyinfo
;
22845 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22847 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22851 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22852 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22853 dpyinfo
->mouse_face_window
= Qnil
;
22854 dpyinfo
->mouse_face_overlay
= Qnil
;
22860 Non-zero if physical cursor of window W is within mouse face. */
22863 cursor_in_mouse_face_p (w
)
22866 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22867 int in_mouse_face
= 0;
22869 if (WINDOWP (dpyinfo
->mouse_face_window
)
22870 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22872 int hpos
= w
->phys_cursor
.hpos
;
22873 int vpos
= w
->phys_cursor
.vpos
;
22875 if (vpos
>= dpyinfo
->mouse_face_beg_row
22876 && vpos
<= dpyinfo
->mouse_face_end_row
22877 && (vpos
> dpyinfo
->mouse_face_beg_row
22878 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22879 && (vpos
< dpyinfo
->mouse_face_end_row
22880 || hpos
< dpyinfo
->mouse_face_end_col
22881 || dpyinfo
->mouse_face_past_end
))
22885 return in_mouse_face
;
22891 /* This function sets the mouse_face_* elements of DPYINFO, assuming
22892 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
22893 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
22894 for the overlay or run of text properties specifying the mouse
22895 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
22896 before-string and after-string that must also be highlighted.
22897 DISPLAY_STRING, if non-nil, is a display string that may cover some
22898 or all of the highlighted text. */
22901 mouse_face_from_buffer_pos (Lisp_Object window
,
22902 Display_Info
*dpyinfo
,
22903 EMACS_INT mouse_charpos
,
22904 EMACS_INT start_charpos
,
22905 EMACS_INT end_charpos
,
22906 Lisp_Object before_string
,
22907 Lisp_Object after_string
,
22908 Lisp_Object display_string
)
22910 struct window
*w
= XWINDOW (window
);
22911 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22912 struct glyph_row
*row
;
22913 struct glyph
*glyph
, *end
;
22917 xassert (NILP (display_string
) || STRINGP (display_string
));
22918 xassert (NILP (before_string
) || STRINGP (before_string
));
22919 xassert (NILP (after_string
) || STRINGP (after_string
));
22921 /* Find the first highlighted glyph. */
22922 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
22924 dpyinfo
->mouse_face_beg_col
= 0;
22925 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22926 dpyinfo
->mouse_face_beg_x
= first
->x
;
22927 dpyinfo
->mouse_face_beg_y
= first
->y
;
22931 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
22933 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22935 /* If the before-string or display-string contains newlines,
22936 row_containing_pos skips to its last row. Move back. */
22937 if (!NILP (before_string
) || !NILP (display_string
))
22939 struct glyph_row
*prev
;
22940 while ((prev
= row
- 1, prev
>= first
)
22941 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
22942 && prev
->used
[TEXT_AREA
] > 0)
22944 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22945 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22946 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
22948 || !(EQ (glyph
->object
, before_string
)
22949 || EQ (glyph
->object
, display_string
)))
22955 glyph
= row
->glyphs
[TEXT_AREA
];
22956 end
= glyph
+ row
->used
[TEXT_AREA
];
22958 dpyinfo
->mouse_face_beg_y
= row
->y
;
22959 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22961 /* Skip truncation glyphs at the start of the glyph row. */
22962 if (row
->displays_text_p
)
22964 && INTEGERP (glyph
->object
)
22965 && glyph
->charpos
< 0;
22967 x
+= glyph
->pixel_width
;
22969 /* Scan the glyph row, stopping before BEFORE_STRING or
22970 DISPLAY_STRING or START_CHARPOS. */
22972 && !INTEGERP (glyph
->object
)
22973 && !EQ (glyph
->object
, before_string
)
22974 && !EQ (glyph
->object
, display_string
)
22975 && !(BUFFERP (glyph
->object
)
22976 && glyph
->charpos
>= start_charpos
);
22978 x
+= glyph
->pixel_width
;
22980 dpyinfo
->mouse_face_beg_x
= x
;
22981 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22984 /* Find the last highlighted glyph. */
22985 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
22988 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22989 dpyinfo
->mouse_face_past_end
= 1;
22991 else if (!NILP (after_string
))
22993 /* If the after-string has newlines, advance to its last row. */
22994 struct glyph_row
*next
;
22995 struct glyph_row
*last
22996 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22998 for (next
= row
+ 1;
23000 && next
->used
[TEXT_AREA
] > 0
23001 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23006 glyph
= row
->glyphs
[TEXT_AREA
];
23007 end
= glyph
+ row
->used
[TEXT_AREA
];
23009 dpyinfo
->mouse_face_end_y
= row
->y
;
23010 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23012 /* Skip truncation glyphs at the start of the row. */
23013 if (row
->displays_text_p
)
23015 && INTEGERP (glyph
->object
)
23016 && glyph
->charpos
< 0;
23018 x
+= glyph
->pixel_width
;
23020 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23023 && !INTEGERP (glyph
->object
)
23024 && !EQ (glyph
->object
, after_string
)
23025 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23027 x
+= glyph
->pixel_width
;
23029 /* If we found AFTER_STRING, consume it and stop. */
23030 if (EQ (glyph
->object
, after_string
))
23032 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23033 x
+= glyph
->pixel_width
;
23037 /* If there's no after-string, we must check if we overshot,
23038 which might be the case if we stopped after a string glyph.
23039 That glyph may belong to a before-string or display-string
23040 associated with the end position, which must not be
23042 Lisp_Object prev_object
;
23045 while (glyph
> row
->glyphs
[TEXT_AREA
])
23047 prev_object
= (glyph
- 1)->object
;
23048 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23051 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23052 if (pos
&& pos
< end_charpos
)
23055 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23056 && EQ ((glyph
- 1)->object
, prev_object
);
23058 x
-= (glyph
- 1)->pixel_width
;
23062 dpyinfo
->mouse_face_end_x
= x
;
23063 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23064 dpyinfo
->mouse_face_window
= window
;
23065 dpyinfo
->mouse_face_face_id
23066 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23068 !dpyinfo
->mouse_face_hidden
, -1);
23069 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23073 /* Find the position of the glyph for position POS in OBJECT in
23074 window W's current matrix, and return in *X, *Y the pixel
23075 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23077 RIGHT_P non-zero means return the position of the right edge of the
23078 glyph, RIGHT_P zero means return the left edge position.
23080 If no glyph for POS exists in the matrix, return the position of
23081 the glyph with the next smaller position that is in the matrix, if
23082 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23083 exists in the matrix, return the position of the glyph with the
23084 next larger position in OBJECT.
23086 Value is non-zero if a glyph was found. */
23089 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23092 Lisp_Object object
;
23093 int *hpos
, *vpos
, *x
, *y
;
23096 int yb
= window_text_bottom_y (w
);
23097 struct glyph_row
*r
;
23098 struct glyph
*best_glyph
= NULL
;
23099 struct glyph_row
*best_row
= NULL
;
23102 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23103 r
->enabled_p
&& r
->y
< yb
;
23106 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23107 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23110 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23111 if (EQ (g
->object
, object
))
23113 if (g
->charpos
== pos
)
23120 else if (best_glyph
== NULL
23121 || ((eabs (g
->charpos
- pos
)
23122 < eabs (best_glyph
->charpos
- pos
))
23125 : g
->charpos
> pos
)))
23139 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23143 *x
+= best_glyph
->pixel_width
;
23148 *vpos
= best_row
- w
->current_matrix
->rows
;
23151 return best_glyph
!= NULL
;
23155 /* See if position X, Y is within a hot-spot of an image. */
23158 on_hot_spot_p (hot_spot
, x
, y
)
23159 Lisp_Object hot_spot
;
23162 if (!CONSP (hot_spot
))
23165 if (EQ (XCAR (hot_spot
), Qrect
))
23167 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23168 Lisp_Object rect
= XCDR (hot_spot
);
23172 if (!CONSP (XCAR (rect
)))
23174 if (!CONSP (XCDR (rect
)))
23176 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23178 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23180 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23182 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23186 else if (EQ (XCAR (hot_spot
), Qcircle
))
23188 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23189 Lisp_Object circ
= XCDR (hot_spot
);
23190 Lisp_Object lr
, lx0
, ly0
;
23192 && CONSP (XCAR (circ
))
23193 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23194 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23195 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23197 double r
= XFLOATINT (lr
);
23198 double dx
= XINT (lx0
) - x
;
23199 double dy
= XINT (ly0
) - y
;
23200 return (dx
* dx
+ dy
* dy
<= r
* r
);
23203 else if (EQ (XCAR (hot_spot
), Qpoly
))
23205 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23206 if (VECTORP (XCDR (hot_spot
)))
23208 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23209 Lisp_Object
*poly
= v
->contents
;
23213 Lisp_Object lx
, ly
;
23216 /* Need an even number of coordinates, and at least 3 edges. */
23217 if (n
< 6 || n
& 1)
23220 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23221 If count is odd, we are inside polygon. Pixels on edges
23222 may or may not be included depending on actual geometry of the
23224 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23225 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23227 x0
= XINT (lx
), y0
= XINT (ly
);
23228 for (i
= 0; i
< n
; i
+= 2)
23230 int x1
= x0
, y1
= y0
;
23231 if ((lx
= poly
[i
], !INTEGERP (lx
))
23232 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23234 x0
= XINT (lx
), y0
= XINT (ly
);
23236 /* Does this segment cross the X line? */
23244 if (y
> y0
&& y
> y1
)
23246 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23256 find_hot_spot (map
, x
, y
)
23260 while (CONSP (map
))
23262 if (CONSP (XCAR (map
))
23263 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23271 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23273 doc
: /* Lookup in image map MAP coordinates X and Y.
23274 An image map is an alist where each element has the format (AREA ID PLIST).
23275 An AREA is specified as either a rectangle, a circle, or a polygon:
23276 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23277 pixel coordinates of the upper left and bottom right corners.
23278 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23279 and the radius of the circle; r may be a float or integer.
23280 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23281 vector describes one corner in the polygon.
23282 Returns the alist element for the first matching AREA in MAP. */)
23293 return find_hot_spot (map
, XINT (x
), XINT (y
));
23297 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23299 define_frame_cursor1 (f
, cursor
, pointer
)
23302 Lisp_Object pointer
;
23304 /* Do not change cursor shape while dragging mouse. */
23305 if (!NILP (do_mouse_tracking
))
23308 if (!NILP (pointer
))
23310 if (EQ (pointer
, Qarrow
))
23311 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23312 else if (EQ (pointer
, Qhand
))
23313 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23314 else if (EQ (pointer
, Qtext
))
23315 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23316 else if (EQ (pointer
, intern ("hdrag")))
23317 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23318 #ifdef HAVE_X_WINDOWS
23319 else if (EQ (pointer
, intern ("vdrag")))
23320 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23322 else if (EQ (pointer
, intern ("hourglass")))
23323 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23324 else if (EQ (pointer
, Qmodeline
))
23325 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23327 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23330 if (cursor
!= No_Cursor
)
23331 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23334 /* Take proper action when mouse has moved to the mode or header line
23335 or marginal area AREA of window W, x-position X and y-position Y.
23336 X is relative to the start of the text display area of W, so the
23337 width of bitmap areas and scroll bars must be subtracted to get a
23338 position relative to the start of the mode line. */
23341 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23342 Lisp_Object window
;
23344 enum window_part area
;
23346 struct window
*w
= XWINDOW (window
);
23347 struct frame
*f
= XFRAME (w
->frame
);
23348 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23349 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23350 Lisp_Object pointer
= Qnil
;
23351 int charpos
, dx
, dy
, width
, height
;
23352 Lisp_Object string
, object
= Qnil
;
23353 Lisp_Object pos
, help
;
23355 Lisp_Object mouse_face
;
23356 int original_x_pixel
= x
;
23357 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23358 struct glyph_row
*row
;
23360 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23365 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23366 &object
, &dx
, &dy
, &width
, &height
);
23368 row
= (area
== ON_MODE_LINE
23369 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23370 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23373 if (row
->mode_line_p
&& row
->enabled_p
)
23375 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23376 end
= glyph
+ row
->used
[TEXT_AREA
];
23378 for (x0
= original_x_pixel
;
23379 glyph
< end
&& x0
>= glyph
->pixel_width
;
23381 x0
-= glyph
->pixel_width
;
23389 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23390 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23391 &object
, &dx
, &dy
, &width
, &height
);
23396 if (IMAGEP (object
))
23398 Lisp_Object image_map
, hotspot
;
23399 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23401 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23403 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23405 Lisp_Object area_id
, plist
;
23407 area_id
= XCAR (hotspot
);
23408 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23409 If so, we could look for mouse-enter, mouse-leave
23410 properties in PLIST (and do something...). */
23411 hotspot
= XCDR (hotspot
);
23412 if (CONSP (hotspot
)
23413 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23415 pointer
= Fplist_get (plist
, Qpointer
);
23416 if (NILP (pointer
))
23418 help
= Fplist_get (plist
, Qhelp_echo
);
23421 help_echo_string
= help
;
23422 /* Is this correct? ++kfs */
23423 XSETWINDOW (help_echo_window
, w
);
23424 help_echo_object
= w
->buffer
;
23425 help_echo_pos
= charpos
;
23429 if (NILP (pointer
))
23430 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23433 if (STRINGP (string
))
23435 pos
= make_number (charpos
);
23436 /* If we're on a string with `help-echo' text property, arrange
23437 for the help to be displayed. This is done by setting the
23438 global variable help_echo_string to the help string. */
23441 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23444 help_echo_string
= help
;
23445 XSETWINDOW (help_echo_window
, w
);
23446 help_echo_object
= string
;
23447 help_echo_pos
= charpos
;
23451 if (NILP (pointer
))
23452 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23454 /* Change the mouse pointer according to what is under X/Y. */
23455 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23458 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23459 if (!KEYMAPP (map
))
23460 map
= Fget_text_property (pos
, Qkeymap
, string
);
23461 if (!KEYMAPP (map
))
23462 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23465 /* Change the mouse face according to what is under X/Y. */
23466 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23467 if (!NILP (mouse_face
)
23468 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23473 struct glyph
* tmp_glyph
;
23477 int total_pixel_width
;
23482 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23483 Qmouse_face
, string
, Qnil
);
23485 b
= make_number (0);
23487 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23489 e
= make_number (SCHARS (string
));
23491 /* Calculate the position(glyph position: GPOS) of GLYPH in
23492 displayed string. GPOS is different from CHARPOS.
23494 CHARPOS is the position of glyph in internal string
23495 object. A mode line string format has structures which
23496 is converted to a flatten by emacs lisp interpreter.
23497 The internal string is an element of the structures.
23498 The displayed string is the flatten string. */
23500 if (glyph
> row_start_glyph
)
23502 tmp_glyph
= glyph
- 1;
23503 while (tmp_glyph
>= row_start_glyph
23504 && tmp_glyph
->charpos
>= XINT (b
)
23505 && EQ (tmp_glyph
->object
, glyph
->object
))
23512 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23513 displayed string holding GLYPH.
23515 GSEQ_LENGTH is different from SCHARS (STRING).
23516 SCHARS (STRING) returns the length of the internal string. */
23517 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23518 tmp_glyph
->charpos
< XINT (e
);
23519 tmp_glyph
++, gseq_length
++)
23521 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23525 total_pixel_width
= 0;
23526 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23527 total_pixel_width
+= tmp_glyph
->pixel_width
;
23529 /* Pre calculation of re-rendering position */
23531 hpos
= (area
== ON_MODE_LINE
23532 ? (w
->current_matrix
)->nrows
- 1
23535 /* If the re-rendering position is included in the last
23536 re-rendering area, we should do nothing. */
23537 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23538 && dpyinfo
->mouse_face_beg_col
<= vpos
23539 && vpos
< dpyinfo
->mouse_face_end_col
23540 && dpyinfo
->mouse_face_beg_row
== hpos
)
23543 if (clear_mouse_face (dpyinfo
))
23544 cursor
= No_Cursor
;
23546 dpyinfo
->mouse_face_beg_col
= vpos
;
23547 dpyinfo
->mouse_face_beg_row
= hpos
;
23549 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23550 dpyinfo
->mouse_face_beg_y
= 0;
23552 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23553 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23555 dpyinfo
->mouse_face_end_x
= 0;
23556 dpyinfo
->mouse_face_end_y
= 0;
23558 dpyinfo
->mouse_face_past_end
= 0;
23559 dpyinfo
->mouse_face_window
= window
;
23561 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23564 glyph
->face_id
, 1);
23565 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23567 if (NILP (pointer
))
23570 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23571 clear_mouse_face (dpyinfo
);
23573 define_frame_cursor1 (f
, cursor
, pointer
);
23578 Take proper action when the mouse has moved to position X, Y on
23579 frame F as regards highlighting characters that have mouse-face
23580 properties. Also de-highlighting chars where the mouse was before.
23581 X and Y can be negative or out of range. */
23584 note_mouse_highlight (f
, x
, y
)
23588 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23589 enum window_part part
;
23590 Lisp_Object window
;
23592 Cursor cursor
= No_Cursor
;
23593 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23596 /* When a menu is active, don't highlight because this looks odd. */
23597 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23598 if (popup_activated ())
23602 if (NILP (Vmouse_highlight
)
23603 || !f
->glyphs_initialized_p
)
23606 dpyinfo
->mouse_face_mouse_x
= x
;
23607 dpyinfo
->mouse_face_mouse_y
= y
;
23608 dpyinfo
->mouse_face_mouse_frame
= f
;
23610 if (dpyinfo
->mouse_face_defer
)
23613 if (gc_in_progress
)
23615 dpyinfo
->mouse_face_deferred_gc
= 1;
23619 /* Which window is that in? */
23620 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23622 /* If we were displaying active text in another window, clear that.
23623 Also clear if we move out of text area in same window. */
23624 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23625 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23626 && !NILP (dpyinfo
->mouse_face_window
)))
23627 clear_mouse_face (dpyinfo
);
23629 /* Not on a window -> return. */
23630 if (!WINDOWP (window
))
23633 /* Reset help_echo_string. It will get recomputed below. */
23634 help_echo_string
= Qnil
;
23636 /* Convert to window-relative pixel coordinates. */
23637 w
= XWINDOW (window
);
23638 frame_to_window_pixel_xy (w
, &x
, &y
);
23640 /* Handle tool-bar window differently since it doesn't display a
23642 if (EQ (window
, f
->tool_bar_window
))
23644 note_tool_bar_highlight (f
, x
, y
);
23648 /* Mouse is on the mode, header line or margin? */
23649 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23650 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23652 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23656 if (part
== ON_VERTICAL_BORDER
)
23658 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23659 help_echo_string
= build_string ("drag-mouse-1: resize");
23661 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23662 || part
== ON_SCROLL_BAR
)
23663 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23665 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23667 /* Are we in a window whose display is up to date?
23668 And verify the buffer's text has not changed. */
23669 b
= XBUFFER (w
->buffer
);
23670 if (part
== ON_TEXT
23671 && EQ (w
->window_end_valid
, w
->buffer
)
23672 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23673 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23675 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23676 struct glyph
*glyph
;
23677 Lisp_Object object
;
23678 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23679 Lisp_Object
*overlay_vec
= NULL
;
23681 struct buffer
*obuf
;
23682 int obegv
, ozv
, same_region
;
23684 /* Find the glyph under X/Y. */
23685 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23687 /* Look for :pointer property on image. */
23688 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23690 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23691 if (img
!= NULL
&& IMAGEP (img
->spec
))
23693 Lisp_Object image_map
, hotspot
;
23694 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23696 && (hotspot
= find_hot_spot (image_map
,
23697 glyph
->slice
.x
+ dx
,
23698 glyph
->slice
.y
+ dy
),
23700 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23702 Lisp_Object area_id
, plist
;
23704 area_id
= XCAR (hotspot
);
23705 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23706 If so, we could look for mouse-enter, mouse-leave
23707 properties in PLIST (and do something...). */
23708 hotspot
= XCDR (hotspot
);
23709 if (CONSP (hotspot
)
23710 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23712 pointer
= Fplist_get (plist
, Qpointer
);
23713 if (NILP (pointer
))
23715 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23716 if (!NILP (help_echo_string
))
23718 help_echo_window
= window
;
23719 help_echo_object
= glyph
->object
;
23720 help_echo_pos
= glyph
->charpos
;
23724 if (NILP (pointer
))
23725 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23729 /* Clear mouse face if X/Y not over text. */
23731 || area
!= TEXT_AREA
23732 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23734 if (clear_mouse_face (dpyinfo
))
23735 cursor
= No_Cursor
;
23736 if (NILP (pointer
))
23738 if (area
!= TEXT_AREA
)
23739 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23741 pointer
= Vvoid_text_area_pointer
;
23746 pos
= glyph
->charpos
;
23747 object
= glyph
->object
;
23748 if (!STRINGP (object
) && !BUFFERP (object
))
23751 /* If we get an out-of-range value, return now; avoid an error. */
23752 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23755 /* Make the window's buffer temporarily current for
23756 overlays_at and compute_char_face. */
23757 obuf
= current_buffer
;
23758 current_buffer
= b
;
23764 /* Is this char mouse-active or does it have help-echo? */
23765 position
= make_number (pos
);
23767 if (BUFFERP (object
))
23769 /* Put all the overlays we want in a vector in overlay_vec. */
23770 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23771 /* Sort overlays into increasing priority order. */
23772 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23777 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23778 && vpos
>= dpyinfo
->mouse_face_beg_row
23779 && vpos
<= dpyinfo
->mouse_face_end_row
23780 && (vpos
> dpyinfo
->mouse_face_beg_row
23781 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23782 && (vpos
< dpyinfo
->mouse_face_end_row
23783 || hpos
< dpyinfo
->mouse_face_end_col
23784 || dpyinfo
->mouse_face_past_end
));
23787 cursor
= No_Cursor
;
23789 /* Check mouse-face highlighting. */
23791 /* If there exists an overlay with mouse-face overlapping
23792 the one we are currently highlighting, we have to
23793 check if we enter the overlapping overlay, and then
23794 highlight only that. */
23795 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23796 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23798 /* Find the highest priority overlay with a mouse-face. */
23800 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23802 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23803 if (!NILP (mouse_face
))
23804 overlay
= overlay_vec
[i
];
23807 /* If we're highlighting the same overlay as before, there's
23808 no need to do that again. */
23809 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23810 goto check_help_echo
;
23811 dpyinfo
->mouse_face_overlay
= overlay
;
23813 /* Clear the display of the old active region, if any. */
23814 if (clear_mouse_face (dpyinfo
))
23815 cursor
= No_Cursor
;
23817 /* If no overlay applies, get a text property. */
23818 if (NILP (overlay
))
23819 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23821 /* Next, compute the bounds of the mouse highlighting and
23823 if (!NILP (mouse_face
) && STRINGP (object
))
23825 /* The mouse-highlighting comes from a display string
23826 with a mouse-face. */
23830 b
= Fprevious_single_property_change
23831 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
23832 e
= Fnext_single_property_change
23833 (position
, Qmouse_face
, object
, Qnil
);
23835 b
= make_number (0);
23837 e
= make_number (SCHARS (object
) - 1);
23839 fast_find_string_pos (w
, XINT (b
), object
,
23840 &dpyinfo
->mouse_face_beg_col
,
23841 &dpyinfo
->mouse_face_beg_row
,
23842 &dpyinfo
->mouse_face_beg_x
,
23843 &dpyinfo
->mouse_face_beg_y
, 0);
23844 fast_find_string_pos (w
, XINT (e
), object
,
23845 &dpyinfo
->mouse_face_end_col
,
23846 &dpyinfo
->mouse_face_end_row
,
23847 &dpyinfo
->mouse_face_end_x
,
23848 &dpyinfo
->mouse_face_end_y
, 1);
23849 dpyinfo
->mouse_face_past_end
= 0;
23850 dpyinfo
->mouse_face_window
= window
;
23851 dpyinfo
->mouse_face_face_id
23852 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23853 glyph
->face_id
, 1);
23854 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23855 cursor
= No_Cursor
;
23859 /* The mouse-highlighting, if any, comes from an overlay
23860 or text property in the buffer. */
23861 Lisp_Object buffer
, display_string
;
23863 if (STRINGP (object
))
23865 /* If we are on a display string with no mouse-face,
23866 check if the text under it has one. */
23867 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23868 int start
= MATRIX_ROW_START_CHARPOS (r
);
23869 pos
= string_buffer_position (w
, object
, start
);
23872 mouse_face
= get_char_property_and_overlay
23873 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
23874 buffer
= w
->buffer
;
23875 display_string
= object
;
23881 display_string
= Qnil
;
23884 if (!NILP (mouse_face
))
23886 Lisp_Object before
, after
;
23887 Lisp_Object before_string
, after_string
;
23889 if (NILP (overlay
))
23891 /* Handle the text property case. */
23892 before
= Fprevious_single_property_change
23893 (make_number (pos
+ 1), Qmouse_face
, buffer
,
23894 Fmarker_position (w
->start
));
23895 after
= Fnext_single_property_change
23896 (make_number (pos
), Qmouse_face
, buffer
,
23897 make_number (BUF_Z (XBUFFER (buffer
))
23898 - XFASTINT (w
->window_end_pos
)));
23899 before_string
= after_string
= Qnil
;
23903 /* Handle the overlay case. */
23904 before
= Foverlay_start (overlay
);
23905 after
= Foverlay_end (overlay
);
23906 before_string
= Foverlay_get (overlay
, Qbefore_string
);
23907 after_string
= Foverlay_get (overlay
, Qafter_string
);
23909 if (!STRINGP (before_string
)) before_string
= Qnil
;
23910 if (!STRINGP (after_string
)) after_string
= Qnil
;
23913 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
23916 before_string
, after_string
,
23918 cursor
= No_Cursor
;
23925 /* Look for a `help-echo' property. */
23926 if (NILP (help_echo_string
)) {
23927 Lisp_Object help
, overlay
;
23929 /* Check overlays first. */
23930 help
= overlay
= Qnil
;
23931 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23933 overlay
= overlay_vec
[i
];
23934 help
= Foverlay_get (overlay
, Qhelp_echo
);
23939 help_echo_string
= help
;
23940 help_echo_window
= window
;
23941 help_echo_object
= overlay
;
23942 help_echo_pos
= pos
;
23946 Lisp_Object object
= glyph
->object
;
23947 int charpos
= glyph
->charpos
;
23949 /* Try text properties. */
23950 if (STRINGP (object
)
23952 && charpos
< SCHARS (object
))
23954 help
= Fget_text_property (make_number (charpos
),
23955 Qhelp_echo
, object
);
23958 /* If the string itself doesn't specify a help-echo,
23959 see if the buffer text ``under'' it does. */
23960 struct glyph_row
*r
23961 = MATRIX_ROW (w
->current_matrix
, vpos
);
23962 int start
= MATRIX_ROW_START_CHARPOS (r
);
23963 int pos
= string_buffer_position (w
, object
, start
);
23966 help
= Fget_char_property (make_number (pos
),
23967 Qhelp_echo
, w
->buffer
);
23971 object
= w
->buffer
;
23976 else if (BUFFERP (object
)
23979 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23984 help_echo_string
= help
;
23985 help_echo_window
= window
;
23986 help_echo_object
= object
;
23987 help_echo_pos
= charpos
;
23992 /* Look for a `pointer' property. */
23993 if (NILP (pointer
))
23995 /* Check overlays first. */
23996 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23997 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23999 if (NILP (pointer
))
24001 Lisp_Object object
= glyph
->object
;
24002 int charpos
= glyph
->charpos
;
24004 /* Try text properties. */
24005 if (STRINGP (object
)
24007 && charpos
< SCHARS (object
))
24009 pointer
= Fget_text_property (make_number (charpos
),
24011 if (NILP (pointer
))
24013 /* If the string itself doesn't specify a pointer,
24014 see if the buffer text ``under'' it does. */
24015 struct glyph_row
*r
24016 = MATRIX_ROW (w
->current_matrix
, vpos
);
24017 int start
= MATRIX_ROW_START_CHARPOS (r
);
24018 int pos
= string_buffer_position (w
, object
, start
);
24020 pointer
= Fget_char_property (make_number (pos
),
24021 Qpointer
, w
->buffer
);
24024 else if (BUFFERP (object
)
24027 pointer
= Fget_text_property (make_number (charpos
),
24034 current_buffer
= obuf
;
24039 define_frame_cursor1 (f
, cursor
, pointer
);
24044 Clear any mouse-face on window W. This function is part of the
24045 redisplay interface, and is called from try_window_id and similar
24046 functions to ensure the mouse-highlight is off. */
24049 x_clear_window_mouse_face (w
)
24052 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24053 Lisp_Object window
;
24056 XSETWINDOW (window
, w
);
24057 if (EQ (window
, dpyinfo
->mouse_face_window
))
24058 clear_mouse_face (dpyinfo
);
24064 Just discard the mouse face information for frame F, if any.
24065 This is used when the size of F is changed. */
24068 cancel_mouse_face (f
)
24071 Lisp_Object window
;
24072 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24074 window
= dpyinfo
->mouse_face_window
;
24075 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24077 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24078 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24079 dpyinfo
->mouse_face_window
= Qnil
;
24084 #endif /* HAVE_WINDOW_SYSTEM */
24087 /***********************************************************************
24089 ***********************************************************************/
24091 #ifdef HAVE_WINDOW_SYSTEM
24093 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24094 which intersects rectangle R. R is in window-relative coordinates. */
24097 expose_area (w
, row
, r
, area
)
24099 struct glyph_row
*row
;
24101 enum glyph_row_area area
;
24103 struct glyph
*first
= row
->glyphs
[area
];
24104 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24105 struct glyph
*last
;
24106 int first_x
, start_x
, x
;
24108 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24109 /* If row extends face to end of line write the whole line. */
24110 draw_glyphs (w
, 0, row
, area
,
24111 0, row
->used
[area
],
24112 DRAW_NORMAL_TEXT
, 0);
24115 /* Set START_X to the window-relative start position for drawing glyphs of
24116 AREA. The first glyph of the text area can be partially visible.
24117 The first glyphs of other areas cannot. */
24118 start_x
= window_box_left_offset (w
, area
);
24120 if (area
== TEXT_AREA
)
24123 /* Find the first glyph that must be redrawn. */
24125 && x
+ first
->pixel_width
< r
->x
)
24127 x
+= first
->pixel_width
;
24131 /* Find the last one. */
24135 && x
< r
->x
+ r
->width
)
24137 x
+= last
->pixel_width
;
24143 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24144 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24145 DRAW_NORMAL_TEXT
, 0);
24150 /* Redraw the parts of the glyph row ROW on window W intersecting
24151 rectangle R. R is in window-relative coordinates. Value is
24152 non-zero if mouse-face was overwritten. */
24155 expose_line (w
, row
, r
)
24157 struct glyph_row
*row
;
24160 xassert (row
->enabled_p
);
24162 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24163 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24164 0, row
->used
[TEXT_AREA
],
24165 DRAW_NORMAL_TEXT
, 0);
24168 if (row
->used
[LEFT_MARGIN_AREA
])
24169 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24170 if (row
->used
[TEXT_AREA
])
24171 expose_area (w
, row
, r
, TEXT_AREA
);
24172 if (row
->used
[RIGHT_MARGIN_AREA
])
24173 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24174 draw_row_fringe_bitmaps (w
, row
);
24177 return row
->mouse_face_p
;
24181 /* Redraw those parts of glyphs rows during expose event handling that
24182 overlap other rows. Redrawing of an exposed line writes over parts
24183 of lines overlapping that exposed line; this function fixes that.
24185 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24186 row in W's current matrix that is exposed and overlaps other rows.
24187 LAST_OVERLAPPING_ROW is the last such row. */
24190 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24192 struct glyph_row
*first_overlapping_row
;
24193 struct glyph_row
*last_overlapping_row
;
24196 struct glyph_row
*row
;
24198 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24199 if (row
->overlapping_p
)
24201 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24204 if (row
->used
[LEFT_MARGIN_AREA
])
24205 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24207 if (row
->used
[TEXT_AREA
])
24208 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24210 if (row
->used
[RIGHT_MARGIN_AREA
])
24211 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24217 /* Return non-zero if W's cursor intersects rectangle R. */
24220 phys_cursor_in_rect_p (w
, r
)
24224 XRectangle cr
, result
;
24225 struct glyph
*cursor_glyph
;
24226 struct glyph_row
*row
;
24228 if (w
->phys_cursor
.vpos
>= 0
24229 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24230 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24232 && row
->cursor_in_fringe_p
)
24234 /* Cursor is in the fringe. */
24235 cr
.x
= window_box_right_offset (w
,
24236 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24237 ? RIGHT_MARGIN_AREA
24240 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24241 cr
.height
= row
->height
;
24242 return x_intersect_rectangles (&cr
, r
, &result
);
24245 cursor_glyph
= get_phys_cursor_glyph (w
);
24248 /* r is relative to W's box, but w->phys_cursor.x is relative
24249 to left edge of W's TEXT area. Adjust it. */
24250 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24251 cr
.y
= w
->phys_cursor
.y
;
24252 cr
.width
= cursor_glyph
->pixel_width
;
24253 cr
.height
= w
->phys_cursor_height
;
24254 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24255 I assume the effect is the same -- and this is portable. */
24256 return x_intersect_rectangles (&cr
, r
, &result
);
24258 /* If we don't understand the format, pretend we're not in the hot-spot. */
24264 Draw a vertical window border to the right of window W if W doesn't
24265 have vertical scroll bars. */
24268 x_draw_vertical_border (w
)
24271 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24273 /* We could do better, if we knew what type of scroll-bar the adjacent
24274 windows (on either side) have... But we don't :-(
24275 However, I think this works ok. ++KFS 2003-04-25 */
24277 /* Redraw borders between horizontally adjacent windows. Don't
24278 do it for frames with vertical scroll bars because either the
24279 right scroll bar of a window, or the left scroll bar of its
24280 neighbor will suffice as a border. */
24281 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24284 if (!WINDOW_RIGHTMOST_P (w
)
24285 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24287 int x0
, x1
, y0
, y1
;
24289 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24292 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24295 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24297 else if (!WINDOW_LEFTMOST_P (w
)
24298 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24300 int x0
, x1
, y0
, y1
;
24302 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24305 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24308 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24313 /* Redraw the part of window W intersection rectangle FR. Pixel
24314 coordinates in FR are frame-relative. Call this function with
24315 input blocked. Value is non-zero if the exposure overwrites
24319 expose_window (w
, fr
)
24323 struct frame
*f
= XFRAME (w
->frame
);
24325 int mouse_face_overwritten_p
= 0;
24327 /* If window is not yet fully initialized, do nothing. This can
24328 happen when toolkit scroll bars are used and a window is split.
24329 Reconfiguring the scroll bar will generate an expose for a newly
24331 if (w
->current_matrix
== NULL
)
24334 /* When we're currently updating the window, display and current
24335 matrix usually don't agree. Arrange for a thorough display
24337 if (w
== updated_window
)
24339 SET_FRAME_GARBAGED (f
);
24343 /* Frame-relative pixel rectangle of W. */
24344 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24345 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24346 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24347 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24349 if (x_intersect_rectangles (fr
, &wr
, &r
))
24351 int yb
= window_text_bottom_y (w
);
24352 struct glyph_row
*row
;
24353 int cursor_cleared_p
;
24354 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24356 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24357 r
.x
, r
.y
, r
.width
, r
.height
));
24359 /* Convert to window coordinates. */
24360 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24361 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24363 /* Turn off the cursor. */
24364 if (!w
->pseudo_window_p
24365 && phys_cursor_in_rect_p (w
, &r
))
24367 x_clear_cursor (w
);
24368 cursor_cleared_p
= 1;
24371 cursor_cleared_p
= 0;
24373 /* Update lines intersecting rectangle R. */
24374 first_overlapping_row
= last_overlapping_row
= NULL
;
24375 for (row
= w
->current_matrix
->rows
;
24380 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24382 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24383 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24384 || (r
.y
>= y0
&& r
.y
< y1
)
24385 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24387 /* A header line may be overlapping, but there is no need
24388 to fix overlapping areas for them. KFS 2005-02-12 */
24389 if (row
->overlapping_p
&& !row
->mode_line_p
)
24391 if (first_overlapping_row
== NULL
)
24392 first_overlapping_row
= row
;
24393 last_overlapping_row
= row
;
24397 if (expose_line (w
, row
, &r
))
24398 mouse_face_overwritten_p
= 1;
24401 else if (row
->overlapping_p
)
24403 /* We must redraw a row overlapping the exposed area. */
24405 ? y0
+ row
->phys_height
> r
.y
24406 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24408 if (first_overlapping_row
== NULL
)
24409 first_overlapping_row
= row
;
24410 last_overlapping_row
= row
;
24418 /* Display the mode line if there is one. */
24419 if (WINDOW_WANTS_MODELINE_P (w
)
24420 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24422 && row
->y
< r
.y
+ r
.height
)
24424 if (expose_line (w
, row
, &r
))
24425 mouse_face_overwritten_p
= 1;
24428 if (!w
->pseudo_window_p
)
24430 /* Fix the display of overlapping rows. */
24431 if (first_overlapping_row
)
24432 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24435 /* Draw border between windows. */
24436 x_draw_vertical_border (w
);
24438 /* Turn the cursor on again. */
24439 if (cursor_cleared_p
)
24440 update_window_cursor (w
, 1);
24444 return mouse_face_overwritten_p
;
24449 /* Redraw (parts) of all windows in the window tree rooted at W that
24450 intersect R. R contains frame pixel coordinates. Value is
24451 non-zero if the exposure overwrites mouse-face. */
24454 expose_window_tree (w
, r
)
24458 struct frame
*f
= XFRAME (w
->frame
);
24459 int mouse_face_overwritten_p
= 0;
24461 while (w
&& !FRAME_GARBAGED_P (f
))
24463 if (!NILP (w
->hchild
))
24464 mouse_face_overwritten_p
24465 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24466 else if (!NILP (w
->vchild
))
24467 mouse_face_overwritten_p
24468 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24470 mouse_face_overwritten_p
|= expose_window (w
, r
);
24472 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24475 return mouse_face_overwritten_p
;
24480 Redisplay an exposed area of frame F. X and Y are the upper-left
24481 corner of the exposed rectangle. W and H are width and height of
24482 the exposed area. All are pixel values. W or H zero means redraw
24483 the entire frame. */
24486 expose_frame (f
, x
, y
, w
, h
)
24491 int mouse_face_overwritten_p
= 0;
24493 TRACE ((stderr
, "expose_frame "));
24495 /* No need to redraw if frame will be redrawn soon. */
24496 if (FRAME_GARBAGED_P (f
))
24498 TRACE ((stderr
, " garbaged\n"));
24502 /* If basic faces haven't been realized yet, there is no point in
24503 trying to redraw anything. This can happen when we get an expose
24504 event while Emacs is starting, e.g. by moving another window. */
24505 if (FRAME_FACE_CACHE (f
) == NULL
24506 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24508 TRACE ((stderr
, " no faces\n"));
24512 if (w
== 0 || h
== 0)
24515 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24516 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24526 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24527 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24529 if (WINDOWP (f
->tool_bar_window
))
24530 mouse_face_overwritten_p
24531 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24533 #ifdef HAVE_X_WINDOWS
24535 #ifndef USE_X_TOOLKIT
24536 if (WINDOWP (f
->menu_bar_window
))
24537 mouse_face_overwritten_p
24538 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24539 #endif /* not USE_X_TOOLKIT */
24543 /* Some window managers support a focus-follows-mouse style with
24544 delayed raising of frames. Imagine a partially obscured frame,
24545 and moving the mouse into partially obscured mouse-face on that
24546 frame. The visible part of the mouse-face will be highlighted,
24547 then the WM raises the obscured frame. With at least one WM, KDE
24548 2.1, Emacs is not getting any event for the raising of the frame
24549 (even tried with SubstructureRedirectMask), only Expose events.
24550 These expose events will draw text normally, i.e. not
24551 highlighted. Which means we must redo the highlight here.
24552 Subsume it under ``we love X''. --gerd 2001-08-15 */
24553 /* Included in Windows version because Windows most likely does not
24554 do the right thing if any third party tool offers
24555 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24556 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24558 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24559 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24561 int x
= dpyinfo
->mouse_face_mouse_x
;
24562 int y
= dpyinfo
->mouse_face_mouse_y
;
24563 clear_mouse_face (dpyinfo
);
24564 note_mouse_highlight (f
, x
, y
);
24571 Determine the intersection of two rectangles R1 and R2. Return
24572 the intersection in *RESULT. Value is non-zero if RESULT is not
24576 x_intersect_rectangles (r1
, r2
, result
)
24577 XRectangle
*r1
, *r2
, *result
;
24579 XRectangle
*left
, *right
;
24580 XRectangle
*upper
, *lower
;
24581 int intersection_p
= 0;
24583 /* Rearrange so that R1 is the left-most rectangle. */
24585 left
= r1
, right
= r2
;
24587 left
= r2
, right
= r1
;
24589 /* X0 of the intersection is right.x0, if this is inside R1,
24590 otherwise there is no intersection. */
24591 if (right
->x
<= left
->x
+ left
->width
)
24593 result
->x
= right
->x
;
24595 /* The right end of the intersection is the minimum of the
24596 the right ends of left and right. */
24597 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24600 /* Same game for Y. */
24602 upper
= r1
, lower
= r2
;
24604 upper
= r2
, lower
= r1
;
24606 /* The upper end of the intersection is lower.y0, if this is inside
24607 of upper. Otherwise, there is no intersection. */
24608 if (lower
->y
<= upper
->y
+ upper
->height
)
24610 result
->y
= lower
->y
;
24612 /* The lower end of the intersection is the minimum of the lower
24613 ends of upper and lower. */
24614 result
->height
= (min (lower
->y
+ lower
->height
,
24615 upper
->y
+ upper
->height
)
24617 intersection_p
= 1;
24621 return intersection_p
;
24624 #endif /* HAVE_WINDOW_SYSTEM */
24627 /***********************************************************************
24629 ***********************************************************************/
24634 Vwith_echo_area_save_vector
= Qnil
;
24635 staticpro (&Vwith_echo_area_save_vector
);
24637 Vmessage_stack
= Qnil
;
24638 staticpro (&Vmessage_stack
);
24640 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
24641 staticpro (&Qinhibit_redisplay
);
24643 message_dolog_marker1
= Fmake_marker ();
24644 staticpro (&message_dolog_marker1
);
24645 message_dolog_marker2
= Fmake_marker ();
24646 staticpro (&message_dolog_marker2
);
24647 message_dolog_marker3
= Fmake_marker ();
24648 staticpro (&message_dolog_marker3
);
24651 defsubr (&Sdump_frame_glyph_matrix
);
24652 defsubr (&Sdump_glyph_matrix
);
24653 defsubr (&Sdump_glyph_row
);
24654 defsubr (&Sdump_tool_bar_row
);
24655 defsubr (&Strace_redisplay
);
24656 defsubr (&Strace_to_stderr
);
24658 #ifdef HAVE_WINDOW_SYSTEM
24659 defsubr (&Stool_bar_lines_needed
);
24660 defsubr (&Slookup_image_map
);
24662 defsubr (&Sformat_mode_line
);
24663 defsubr (&Sinvisible_p
);
24665 staticpro (&Qmenu_bar_update_hook
);
24666 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
24668 staticpro (&Qoverriding_terminal_local_map
);
24669 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
24671 staticpro (&Qoverriding_local_map
);
24672 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
24674 staticpro (&Qwindow_scroll_functions
);
24675 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
24677 staticpro (&Qwindow_text_change_functions
);
24678 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
24680 staticpro (&Qredisplay_end_trigger_functions
);
24681 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
24683 staticpro (&Qinhibit_point_motion_hooks
);
24684 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
24686 Qeval
= intern_c_string ("eval");
24687 staticpro (&Qeval
);
24689 QCdata
= intern_c_string (":data");
24690 staticpro (&QCdata
);
24691 Qdisplay
= intern_c_string ("display");
24692 staticpro (&Qdisplay
);
24693 Qspace_width
= intern_c_string ("space-width");
24694 staticpro (&Qspace_width
);
24695 Qraise
= intern_c_string ("raise");
24696 staticpro (&Qraise
);
24697 Qslice
= intern_c_string ("slice");
24698 staticpro (&Qslice
);
24699 Qspace
= intern_c_string ("space");
24700 staticpro (&Qspace
);
24701 Qmargin
= intern_c_string ("margin");
24702 staticpro (&Qmargin
);
24703 Qpointer
= intern_c_string ("pointer");
24704 staticpro (&Qpointer
);
24705 Qleft_margin
= intern_c_string ("left-margin");
24706 staticpro (&Qleft_margin
);
24707 Qright_margin
= intern_c_string ("right-margin");
24708 staticpro (&Qright_margin
);
24709 Qcenter
= intern_c_string ("center");
24710 staticpro (&Qcenter
);
24711 Qline_height
= intern_c_string ("line-height");
24712 staticpro (&Qline_height
);
24713 QCalign_to
= intern_c_string (":align-to");
24714 staticpro (&QCalign_to
);
24715 QCrelative_width
= intern_c_string (":relative-width");
24716 staticpro (&QCrelative_width
);
24717 QCrelative_height
= intern_c_string (":relative-height");
24718 staticpro (&QCrelative_height
);
24719 QCeval
= intern_c_string (":eval");
24720 staticpro (&QCeval
);
24721 QCpropertize
= intern_c_string (":propertize");
24722 staticpro (&QCpropertize
);
24723 QCfile
= intern_c_string (":file");
24724 staticpro (&QCfile
);
24725 Qfontified
= intern_c_string ("fontified");
24726 staticpro (&Qfontified
);
24727 Qfontification_functions
= intern_c_string ("fontification-functions");
24728 staticpro (&Qfontification_functions
);
24729 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
24730 staticpro (&Qtrailing_whitespace
);
24731 Qescape_glyph
= intern_c_string ("escape-glyph");
24732 staticpro (&Qescape_glyph
);
24733 Qnobreak_space
= intern_c_string ("nobreak-space");
24734 staticpro (&Qnobreak_space
);
24735 Qimage
= intern_c_string ("image");
24736 staticpro (&Qimage
);
24737 QCmap
= intern_c_string (":map");
24738 staticpro (&QCmap
);
24739 QCpointer
= intern_c_string (":pointer");
24740 staticpro (&QCpointer
);
24741 Qrect
= intern_c_string ("rect");
24742 staticpro (&Qrect
);
24743 Qcircle
= intern_c_string ("circle");
24744 staticpro (&Qcircle
);
24745 Qpoly
= intern_c_string ("poly");
24746 staticpro (&Qpoly
);
24747 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
24748 staticpro (&Qmessage_truncate_lines
);
24749 Qgrow_only
= intern_c_string ("grow-only");
24750 staticpro (&Qgrow_only
);
24751 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
24752 staticpro (&Qinhibit_menubar_update
);
24753 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
24754 staticpro (&Qinhibit_eval_during_redisplay
);
24755 Qposition
= intern_c_string ("position");
24756 staticpro (&Qposition
);
24757 Qbuffer_position
= intern_c_string ("buffer-position");
24758 staticpro (&Qbuffer_position
);
24759 Qobject
= intern_c_string ("object");
24760 staticpro (&Qobject
);
24761 Qbar
= intern_c_string ("bar");
24763 Qhbar
= intern_c_string ("hbar");
24764 staticpro (&Qhbar
);
24765 Qbox
= intern_c_string ("box");
24767 Qhollow
= intern_c_string ("hollow");
24768 staticpro (&Qhollow
);
24769 Qhand
= intern_c_string ("hand");
24770 staticpro (&Qhand
);
24771 Qarrow
= intern_c_string ("arrow");
24772 staticpro (&Qarrow
);
24773 Qtext
= intern_c_string ("text");
24774 staticpro (&Qtext
);
24775 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
24776 staticpro (&Qrisky_local_variable
);
24777 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
24778 staticpro (&Qinhibit_free_realized_faces
);
24780 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
24781 Fcons (intern_c_string ("void-variable"), Qnil
)),
24783 staticpro (&list_of_error
);
24785 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
24786 staticpro (&Qlast_arrow_position
);
24787 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
24788 staticpro (&Qlast_arrow_string
);
24790 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
24791 staticpro (&Qoverlay_arrow_string
);
24792 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
24793 staticpro (&Qoverlay_arrow_bitmap
);
24795 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24796 staticpro (&echo_buffer
[0]);
24797 staticpro (&echo_buffer
[1]);
24799 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24800 staticpro (&echo_area_buffer
[0]);
24801 staticpro (&echo_area_buffer
[1]);
24803 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
24804 staticpro (&Vmessages_buffer_name
);
24806 mode_line_proptrans_alist
= Qnil
;
24807 staticpro (&mode_line_proptrans_alist
);
24808 mode_line_string_list
= Qnil
;
24809 staticpro (&mode_line_string_list
);
24810 mode_line_string_face
= Qnil
;
24811 staticpro (&mode_line_string_face
);
24812 mode_line_string_face_prop
= Qnil
;
24813 staticpro (&mode_line_string_face_prop
);
24814 Vmode_line_unwind_vector
= Qnil
;
24815 staticpro (&Vmode_line_unwind_vector
);
24817 help_echo_string
= Qnil
;
24818 staticpro (&help_echo_string
);
24819 help_echo_object
= Qnil
;
24820 staticpro (&help_echo_object
);
24821 help_echo_window
= Qnil
;
24822 staticpro (&help_echo_window
);
24823 previous_help_echo_string
= Qnil
;
24824 staticpro (&previous_help_echo_string
);
24825 help_echo_pos
= -1;
24827 #ifdef HAVE_WINDOW_SYSTEM
24828 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24829 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24830 For example, if a block cursor is over a tab, it will be drawn as
24831 wide as that tab on the display. */);
24832 x_stretch_cursor_p
= 0;
24835 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24836 doc
: /* *Non-nil means highlight trailing whitespace.
24837 The face used for trailing whitespace is `trailing-whitespace'. */);
24838 Vshow_trailing_whitespace
= Qnil
;
24840 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24841 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24842 A value of t means highlight the character itself (for nobreak space,
24843 use face `nobreak-space').
24844 A value of nil means no highlighting.
24845 Other values mean display the escape glyph followed by an ordinary
24846 space or ordinary hyphen. */);
24847 Vnobreak_char_display
= Qt
;
24849 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24850 doc
: /* *The pointer shape to show in void text areas.
24851 A value of nil means to show the text pointer. Other options are `arrow',
24852 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24853 Vvoid_text_area_pointer
= Qarrow
;
24855 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24856 doc
: /* Non-nil means don't actually do any redisplay.
24857 This is used for internal purposes. */);
24858 Vinhibit_redisplay
= Qnil
;
24860 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24861 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24862 Vglobal_mode_string
= Qnil
;
24864 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24865 doc
: /* Marker for where to display an arrow on top of the buffer text.
24866 This must be the beginning of a line in order to work.
24867 See also `overlay-arrow-string'. */);
24868 Voverlay_arrow_position
= Qnil
;
24870 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24871 doc
: /* String to display as an arrow in non-window frames.
24872 See also `overlay-arrow-position'. */);
24873 Voverlay_arrow_string
= make_pure_c_string ("=>");
24875 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24876 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24877 The symbols on this list are examined during redisplay to determine
24878 where to display overlay arrows. */);
24879 Voverlay_arrow_variable_list
24880 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
24882 DEFVAR_INT ("scroll-step", &scroll_step
,
24883 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24884 If that fails to bring point back on frame, point is centered instead.
24885 If this is zero, point is always centered after it moves off frame.
24886 If you want scrolling to always be a line at a time, you should set
24887 `scroll-conservatively' to a large value rather than set this to 1. */);
24889 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24890 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24891 If point moves off-screen, redisplay will scroll by up to
24892 `scroll-conservatively' lines in order to bring point just barely
24893 onto the screen again. If that cannot be done, then redisplay
24894 recenters point as usual.
24896 A value of zero means always recenter point if it moves off screen. */);
24897 scroll_conservatively
= 0;
24899 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24900 doc
: /* *Number of lines of margin at the top and bottom of a window.
24901 Recenter the window whenever point gets within this many lines
24902 of the top or bottom of the window. */);
24905 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24906 doc
: /* Pixels per inch value for non-window system displays.
24907 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24908 Vdisplay_pixels_per_inch
= make_float (72.0);
24911 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24914 DEFVAR_LISP ("truncate-partial-width-windows",
24915 &Vtruncate_partial_width_windows
,
24916 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
24917 For an integer value, truncate lines in each window narrower than the
24918 full frame width, provided the window width is less than that integer;
24919 otherwise, respect the value of `truncate-lines'.
24921 For any other non-nil value, truncate lines in all windows that do
24922 not span the full frame width.
24924 A value of nil means to respect the value of `truncate-lines'.
24926 If `word-wrap' is enabled, you might want to reduce this. */);
24927 Vtruncate_partial_width_windows
= make_number (50);
24929 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24930 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24931 Any other value means to use the appropriate face, `mode-line',
24932 `header-line', or `menu' respectively. */);
24933 mode_line_inverse_video
= 1;
24935 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24936 doc
: /* *Maximum buffer size for which line number should be displayed.
24937 If the buffer is bigger than this, the line number does not appear
24938 in the mode line. A value of nil means no limit. */);
24939 Vline_number_display_limit
= Qnil
;
24941 DEFVAR_INT ("line-number-display-limit-width",
24942 &line_number_display_limit_width
,
24943 doc
: /* *Maximum line width (in characters) for line number display.
24944 If the average length of the lines near point is bigger than this, then the
24945 line number may be omitted from the mode line. */);
24946 line_number_display_limit_width
= 200;
24948 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24949 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24950 highlight_nonselected_windows
= 0;
24952 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24953 doc
: /* Non-nil if more than one frame is visible on this display.
24954 Minibuffer-only frames don't count, but iconified frames do.
24955 This variable is not guaranteed to be accurate except while processing
24956 `frame-title-format' and `icon-title-format'. */);
24958 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24959 doc
: /* Template for displaying the title bar of visible frames.
24960 \(Assuming the window manager supports this feature.)
24962 This variable has the same structure as `mode-line-format', except that
24963 the %c and %l constructs are ignored. It is used only on frames for
24964 which no explicit name has been set \(see `modify-frame-parameters'). */);
24966 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24967 doc
: /* Template for displaying the title bar of an iconified frame.
24968 \(Assuming the window manager supports this feature.)
24969 This variable has the same structure as `mode-line-format' (which see),
24970 and is used only on frames for which no explicit name has been set
24971 \(see `modify-frame-parameters'). */);
24973 = Vframe_title_format
24974 = pure_cons (intern_c_string ("multiple-frames"),
24975 pure_cons (make_pure_c_string ("%b"),
24976 pure_cons (pure_cons (empty_unibyte_string
,
24977 pure_cons (intern_c_string ("invocation-name"),
24978 pure_cons (make_pure_c_string ("@"),
24979 pure_cons (intern_c_string ("system-name"),
24983 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24984 doc
: /* Maximum number of lines to keep in the message log buffer.
24985 If nil, disable message logging. If t, log messages but don't truncate
24986 the buffer when it becomes large. */);
24987 Vmessage_log_max
= make_number (100);
24989 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24990 doc
: /* Functions called before redisplay, if window sizes have changed.
24991 The value should be a list of functions that take one argument.
24992 Just before redisplay, for each frame, if any of its windows have changed
24993 size since the last redisplay, or have been split or deleted,
24994 all the functions in the list are called, with the frame as argument. */);
24995 Vwindow_size_change_functions
= Qnil
;
24997 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24998 doc
: /* List of functions to call before redisplaying a window with scrolling.
24999 Each function is called with two arguments, the window and its new
25000 display-start position. Note that these functions are also called by
25001 `set-window-buffer'. Also note that the value of `window-end' is not
25002 valid when these functions are called. */);
25003 Vwindow_scroll_functions
= Qnil
;
25005 DEFVAR_LISP ("window-text-change-functions",
25006 &Vwindow_text_change_functions
,
25007 doc
: /* Functions to call in redisplay when text in the window might change. */);
25008 Vwindow_text_change_functions
= Qnil
;
25010 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25011 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25012 Each function is called with two arguments, the window and the end trigger value.
25013 See `set-window-redisplay-end-trigger'. */);
25014 Vredisplay_end_trigger_functions
= Qnil
;
25016 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25017 doc
: /* *Non-nil means autoselect window with mouse pointer.
25018 If nil, do not autoselect windows.
25019 A positive number means delay autoselection by that many seconds: a
25020 window is autoselected only after the mouse has remained in that
25021 window for the duration of the delay.
25022 A negative number has a similar effect, but causes windows to be
25023 autoselected only after the mouse has stopped moving. \(Because of
25024 the way Emacs compares mouse events, you will occasionally wait twice
25025 that time before the window gets selected.\)
25026 Any other value means to autoselect window instantaneously when the
25027 mouse pointer enters it.
25029 Autoselection selects the minibuffer only if it is active, and never
25030 unselects the minibuffer if it is active.
25032 When customizing this variable make sure that the actual value of
25033 `focus-follows-mouse' matches the behavior of your window manager. */);
25034 Vmouse_autoselect_window
= Qnil
;
25036 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25037 doc
: /* *Non-nil means automatically resize tool-bars.
25038 This dynamically changes the tool-bar's height to the minimum height
25039 that is needed to make all tool-bar items visible.
25040 If value is `grow-only', the tool-bar's height is only increased
25041 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25042 Vauto_resize_tool_bars
= Qt
;
25044 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25045 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25046 auto_raise_tool_bar_buttons_p
= 1;
25048 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25049 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25050 make_cursor_line_fully_visible_p
= 1;
25052 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25053 doc
: /* *Border below tool-bar in pixels.
25054 If an integer, use it as the height of the border.
25055 If it is one of `internal-border-width' or `border-width', use the
25056 value of the corresponding frame parameter.
25057 Otherwise, no border is added below the tool-bar. */);
25058 Vtool_bar_border
= Qinternal_border_width
;
25060 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25061 doc
: /* *Margin around tool-bar buttons in pixels.
25062 If an integer, use that for both horizontal and vertical margins.
25063 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25064 HORZ specifying the horizontal margin, and VERT specifying the
25065 vertical margin. */);
25066 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25068 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25069 doc
: /* *Relief thickness of tool-bar buttons. */);
25070 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25072 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25073 doc
: /* List of functions to call to fontify regions of text.
25074 Each function is called with one argument POS. Functions must
25075 fontify a region starting at POS in the current buffer, and give
25076 fontified regions the property `fontified'. */);
25077 Vfontification_functions
= Qnil
;
25078 Fmake_variable_buffer_local (Qfontification_functions
);
25080 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25081 &unibyte_display_via_language_environment
,
25082 doc
: /* *Non-nil means display unibyte text according to language environment.
25083 Specifically, this means that raw bytes in the range 160-255 decimal
25084 are displayed by converting them to the equivalent multibyte characters
25085 according to the current language environment. As a result, they are
25086 displayed according to the current fontset.
25088 Note that this variable affects only how these bytes are displayed,
25089 but does not change the fact they are interpreted as raw bytes. */);
25090 unibyte_display_via_language_environment
= 0;
25092 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25093 doc
: /* *Maximum height for resizing mini-windows.
25094 If a float, it specifies a fraction of the mini-window frame's height.
25095 If an integer, it specifies a number of lines. */);
25096 Vmax_mini_window_height
= make_float (0.25);
25098 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25099 doc
: /* *How to resize mini-windows.
25100 A value of nil means don't automatically resize mini-windows.
25101 A value of t means resize them to fit the text displayed in them.
25102 A value of `grow-only', the default, means let mini-windows grow
25103 only, until their display becomes empty, at which point the windows
25104 go back to their normal size. */);
25105 Vresize_mini_windows
= Qgrow_only
;
25107 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25108 doc
: /* Alist specifying how to blink the cursor off.
25109 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25110 `cursor-type' frame-parameter or variable equals ON-STATE,
25111 comparing using `equal', Emacs uses OFF-STATE to specify
25112 how to blink it off. ON-STATE and OFF-STATE are values for
25113 the `cursor-type' frame parameter.
25115 If a frame's ON-STATE has no entry in this list,
25116 the frame's other specifications determine how to blink the cursor off. */);
25117 Vblink_cursor_alist
= Qnil
;
25119 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25120 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25121 automatic_hscrolling_p
= 1;
25122 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
25123 staticpro (&Qauto_hscroll_mode
);
25125 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25126 doc
: /* *How many columns away from the window edge point is allowed to get
25127 before automatic hscrolling will horizontally scroll the window. */);
25128 hscroll_margin
= 5;
25130 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25131 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25132 When point is less than `hscroll-margin' columns from the window
25133 edge, automatic hscrolling will scroll the window by the amount of columns
25134 determined by this variable. If its value is a positive integer, scroll that
25135 many columns. If it's a positive floating-point number, it specifies the
25136 fraction of the window's width to scroll. If it's nil or zero, point will be
25137 centered horizontally after the scroll. Any other value, including negative
25138 numbers, are treated as if the value were zero.
25140 Automatic hscrolling always moves point outside the scroll margin, so if
25141 point was more than scroll step columns inside the margin, the window will
25142 scroll more than the value given by the scroll step.
25144 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25145 and `scroll-right' overrides this variable's effect. */);
25146 Vhscroll_step
= make_number (0);
25148 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25149 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25150 Bind this around calls to `message' to let it take effect. */);
25151 message_truncate_lines
= 0;
25153 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25154 doc
: /* Normal hook run to update the menu bar definitions.
25155 Redisplay runs this hook before it redisplays the menu bar.
25156 This is used to update submenus such as Buffers,
25157 whose contents depend on various data. */);
25158 Vmenu_bar_update_hook
= Qnil
;
25160 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25161 doc
: /* Frame for which we are updating a menu.
25162 The enable predicate for a menu binding should check this variable. */);
25163 Vmenu_updating_frame
= Qnil
;
25165 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25166 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25167 inhibit_menubar_update
= 0;
25169 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25170 doc
: /* Prefix prepended to all continuation lines at display time.
25171 The value may be a string, an image, or a stretch-glyph; it is
25172 interpreted in the same way as the value of a `display' text property.
25174 This variable is overridden by any `wrap-prefix' text or overlay
25177 To add a prefix to non-continuation lines, use `line-prefix'. */);
25178 Vwrap_prefix
= Qnil
;
25179 staticpro (&Qwrap_prefix
);
25180 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25181 Fmake_variable_buffer_local (Qwrap_prefix
);
25183 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25184 doc
: /* Prefix prepended to all non-continuation lines at display time.
25185 The value may be a string, an image, or a stretch-glyph; it is
25186 interpreted in the same way as the value of a `display' text property.
25188 This variable is overridden by any `line-prefix' text or overlay
25191 To add a prefix to continuation lines, use `wrap-prefix'. */);
25192 Vline_prefix
= Qnil
;
25193 staticpro (&Qline_prefix
);
25194 Qline_prefix
= intern_c_string ("line-prefix");
25195 Fmake_variable_buffer_local (Qline_prefix
);
25197 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25198 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25199 inhibit_eval_during_redisplay
= 0;
25201 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25202 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25203 inhibit_free_realized_faces
= 0;
25206 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25207 doc
: /* Inhibit try_window_id display optimization. */);
25208 inhibit_try_window_id
= 0;
25210 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25211 doc
: /* Inhibit try_window_reusing display optimization. */);
25212 inhibit_try_window_reusing
= 0;
25214 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25215 doc
: /* Inhibit try_cursor_movement display optimization. */);
25216 inhibit_try_cursor_movement
= 0;
25217 #endif /* GLYPH_DEBUG */
25219 DEFVAR_INT ("overline-margin", &overline_margin
,
25220 doc
: /* *Space between overline and text, in pixels.
25221 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25222 margin to the caracter height. */);
25223 overline_margin
= 2;
25225 DEFVAR_INT ("underline-minimum-offset",
25226 &underline_minimum_offset
,
25227 doc
: /* Minimum distance between baseline and underline.
25228 This can improve legibility of underlined text at small font sizes,
25229 particularly when using variable `x-use-underline-position-properties'
25230 with fonts that specify an UNDERLINE_POSITION relatively close to the
25231 baseline. The default value is 1. */);
25232 underline_minimum_offset
= 1;
25234 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25235 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25236 display_hourglass_p
= 1;
25238 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25239 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25240 Value must be an integer or float. */);
25241 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25243 hourglass_atimer
= NULL
;
25244 hourglass_shown_p
= 0;
25248 /* Initialize this module when Emacs starts. */
25253 Lisp_Object root_window
;
25254 struct window
*mini_w
;
25256 current_header_line_height
= current_mode_line_height
= -1;
25258 CHARPOS (this_line_start_pos
) = 0;
25260 mini_w
= XWINDOW (minibuf_window
);
25261 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25263 if (!noninteractive
)
25265 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25268 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25269 set_window_height (root_window
,
25270 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25272 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25273 set_window_height (minibuf_window
, 1, 0);
25275 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25276 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25278 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25279 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25280 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25282 /* The default ellipsis glyphs `...'. */
25283 for (i
= 0; i
< 3; ++i
)
25284 default_invis_vector
[i
] = make_number ('.');
25288 /* Allocate the buffer for frame titles.
25289 Also used for `format-mode-line'. */
25291 mode_line_noprop_buf
= (char *) xmalloc (size
);
25292 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25293 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25294 mode_line_target
= MODE_LINE_DISPLAY
;
25297 help_echo_showing_p
= 0;
25300 /* Since w32 does not support atimers, it defines its own implementation of
25301 the following three functions in w32fns.c. */
25304 /* Platform-independent portion of hourglass implementation. */
25306 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25308 hourglass_started ()
25310 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25313 /* Cancel a currently active hourglass timer, and start a new one. */
25317 #if defined (HAVE_WINDOW_SYSTEM)
25319 int secs
, usecs
= 0;
25321 cancel_hourglass ();
25323 if (INTEGERP (Vhourglass_delay
)
25324 && XINT (Vhourglass_delay
) > 0)
25325 secs
= XFASTINT (Vhourglass_delay
);
25326 else if (FLOATP (Vhourglass_delay
)
25327 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25330 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25331 secs
= XFASTINT (tem
);
25332 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25335 secs
= DEFAULT_HOURGLASS_DELAY
;
25337 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25338 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25339 show_hourglass
, NULL
);
25344 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25347 cancel_hourglass ()
25349 #if defined (HAVE_WINDOW_SYSTEM)
25350 if (hourglass_atimer
)
25352 cancel_atimer (hourglass_atimer
);
25353 hourglass_atimer
= NULL
;
25356 if (hourglass_shown_p
)
25360 #endif /* ! WINDOWSNT */
25362 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25363 (do not change this comment) */